AMReX-Hydro
AMReX-based hydro routines for low Mach number flows
 
Loading...
Searching...
No Matches
hydro_bcs_K.H
Go to the documentation of this file.
1/**
2 * \file hydro_bcs_K.H
3 *
4 * This header file contains the inlined __host__ __device__ functions required for
5 * the boundary condition routines for Godunov and MOL. It also contains function declarations
6 * for controlling host functions.
7 *
8 */
9
10/** \addtogroup Utilities
11 * @{
12 */
13
14
15#ifndef HYDRO_BCS_K_H
16#define HYDRO_BCS_K_H
17
18#include <AMReX_Gpu.H>
19#include <AMReX_BCRec.H>
20#include <AMReX_BC_TYPES.H>
21#include <AMReX_Array.H>
22#include <iomanip>
23#include <hydro_constants.H>
24
25/**
26 * \namespace HydroBC
27 *
28 */
29namespace HydroBC{
30//
31// Choose between single BC per domain face or position dependent BC array
32//
34amrex::BCRec getBC (const int i, const int j, const int k, const int n,
35 const amrex::Box& m_domain, const amrex::BCRec* bcr,
36 amrex::Array4<int const> const& bca)
37{
38 if ( !bca ) { return bcr[n]; }
39
40 int lo[AMREX_SPACEDIM];
41 int hi[AMREX_SPACEDIM];
42 for (int dir = 0; dir < AMREX_SPACEDIM; dir++) {
43 int index[] = {i,j,k};
44
45 for ( int dim = 0; dim < AMREX_SPACEDIM; dim++){
46 if (index[dim] < m_domain.smallEnd(dim)) { index[dim] = m_domain.smallEnd(dim); }
47 if (index[dim] > m_domain.bigEnd(dim)) { index[dim] = m_domain.bigEnd(dim); }
48 if (dim == dir) { index[dim] = m_domain.smallEnd(dim)-1; }
49 }
50 lo[dir] = bca.contains(index[0], index[1], index[2]) ?
51 bca(index[0], index[1], index[2], n) : 0;
52// FIXME?? if we don't contain (i,j,k) then it doesn't matter what the bc is there, because we don't touch it
53
54 index[dir] = m_domain.bigEnd(dir)+1;
55 hi[dir] = bca.contains(index[0], index[1], index[2]) ?
56 bca(index[0], index[1], index[2], n) : 0;
57 }
58
59 amrex::BCRec bc(lo, hi);
60 return bc;
61}
62
63/**
64 *
65 * <A ID="SetExtrapVelBCsLo"></A>
66 *
67 * \brief Boundary condition effects
68 *
69 *
70 * For a detailed discussion see the AMReX-Hydro Guide
71 * <A HREF="https://amrex-fluids.github.io/amrex-hydro/docs_html"></A>.
72 *
73 */
74
76void SetExtrapVelBCsLo (int edge_dir, int i, int j, int k, int n,
78 amrex::Real &lo, amrex::Real &hi,
79 int bclo, int domlo)
80{
81 using namespace amrex;
82
83 //
84 // This is called in the extrapolation of normal velocity components only
85 //
86
87 GpuArray<int,3> iv = {i,j,k};
88
89 if (iv[edge_dir] == domlo)
90 {
91 iv[edge_dir] = domlo-1;
92 Real s_ext = s(iv[0],iv[1],iv[2],n);
93
94 bool is_vel_in_dir = (n == edge_dir);
95
96 if ( (bclo == BCType::ext_dir) ||
97 (bclo == BCType::direction_dependent && s_ext > 0.0) )
98 {
99 if (is_vel_in_dir) {
100 lo = s_ext;
101 hi = s_ext;
102 } else {
103 lo = s_ext;
104 }
105 }
106 else if (bclo == BCType::reflect_odd)
107 {
108 hi = Real(0.);
109 lo = Real(0.);
110 }
111 else if ( bclo == BCType::foextrap || bclo == BCType::hoextrap ||
112 bclo == BCType::reflect_even ||
113 (bclo == BCType::direction_dependent && s_ext <= 0.0))
114 {
115 lo = hi;
116 }
117 }
118}
119
120/**
121 *
122 * <A ID="SetExtrapVelBCsHi"></A>
123 *
124 * \brief Boundary condition effects
125 *
126 *
127 * For a detailed discussion see the AMReX-Hydro Guide
128 * <A HREF="https://amrex-fluids.github.io/amrex-hydro/docs_html"></A>.
129 *
130 */
131
133void SetExtrapVelBCsHi (int edge_dir, int i, int j, int k, int n,
135 amrex::Real &lo, amrex::Real &hi,
136 int bchi, int domhi)
137{
138 using namespace amrex;
139
140 //
141 // This is called in the extrapolation of normal velocity components only
142 //
143
144 GpuArray<int,3> iv = {i,j,k};
145
146 if (iv[edge_dir] == domhi+1)
147 {
148 iv[edge_dir] = domhi+1;
149 Real s_ext = s(iv[0],iv[1],iv[2],n);
150
151 bool is_vel_in_dir = (n == edge_dir);
152
153 if ( (bchi == BCType::ext_dir) ||
154 (bchi == BCType::direction_dependent && s_ext < 0.0) )
155 {
156 if (is_vel_in_dir) {
157 hi = s_ext;
158 lo = s_ext;
159 } else {
160 hi = s_ext;
161 }
162 }
163 else if (bchi == BCType::reflect_odd)
164 {
165 lo = Real(0.);
166 hi = Real(0.);
167 }
168 else if ( bchi == BCType::foextrap || bchi == BCType::hoextrap ||
169 bchi == BCType::reflect_even ||
170 (bchi == BCType::direction_dependent && s_ext >= 0.0))
171 {
172 hi = lo;
173 }
174 }
175}
176
177/**
178 *
179 * <A ID="SetEdgeBCsLo"></A>
180 *
181 * \brief Boundary condition effects
182 *
183 *
184 * For a detailed discussion see the AMReX-Hydro Guide
185 * <A HREF="https://amrex-fluids.github.io/amrex-hydro/docs_html"></A>.
186 *
187 */
188
190void SetEdgeBCsLo (int edge_dir, int i, int j, int k, int n,
192 amrex::Real &lo, amrex::Real &hi,
193 amrex::Real macvel,
194 int bclo, int domlo,
195 bool is_velocity )
196{
197 using namespace amrex;
198
199 //
200 // This is called for all quantities in the construction of edge states
201 //
202
203 GpuArray<int,3> iv = {i,j,k};
204
205 if (iv[edge_dir] == domlo)
206 {
207 iv[edge_dir] = domlo-1;
208 Real s_ext = s(iv[0],iv[1],iv[2],n);
209
210 bool is_vel_in_dir = is_velocity && (n == edge_dir);
211
212 if (bclo == BCType::direction_dependent && macvel > 0.0)
213 {
214 lo = s_ext;
215 hi = s_ext;
216 }
217 else if (bclo == BCType::ext_dir)
218 {
219 lo = s_ext;
220
221 // For turbulent inflow, there are times when the inflow face
222 // may have a predicted outflowing velocity. Here, we preserve
223 // the normal component of the Dirichlet BC, but allow the
224 // tangential components to transport values from the interior.
225 if (is_vel_in_dir) {
226 hi = s_ext;
227 }
228 }
229 else if (bclo == BCType::reflect_odd)
230 {
231 hi = Real(0.);
232 lo = Real(0.);
233 }
234 else if ( bclo == BCType::foextrap || bclo == BCType::hoextrap ||
235 bclo == BCType::reflect_even ||
236 (bclo == BCType::direction_dependent && macvel <= 0.0))
237 {
238 lo = hi;
239 }
240 }
241}
242
243/**
244 *
245 * <A ID="SetEdgeBCsHi"></A>
246 *
247 * \brief Boundary condition effects
248 *
249 *
250 * For a detailed discussion see the AMReX-Hydro Guide
251 * <A HREF="https://amrex-fluids.github.io/amrex-hydro/docs_html"></A>.
252 *
253 */
254
256void SetEdgeBCsHi (int edge_dir, int i, int j, int k, int n,
258 amrex::Real &lo, amrex::Real &hi,
259 amrex::Real macvel,
260 int bchi, int domhi,
261 bool is_velocity )
262{
263 using namespace amrex;
264
265 //
266 // This is called for all quantities in the construction of edge states
267 //
268
269 GpuArray<int,3> iv = {i,j,k};
270
271 if (iv[edge_dir] == domhi+1)
272 {
273 iv[edge_dir] = domhi+1;
274 Real s_ext = s(iv[0],iv[1],iv[2],n);
275
276 bool is_vel_in_dir = is_velocity && (n == edge_dir);
277
278 if (bchi == BCType::direction_dependent && macvel < 0.0)
279 {
280 hi = s_ext;
281 lo = s_ext;
282 }
283 else if (bchi == BCType::ext_dir)
284 {
285 hi = s_ext;
286
287 // For turbulent inflow, there are times when the inflow face
288 // may have a predicted outflowing velocity. Here, we preserve
289 // the normal component of the Dirichlet BC, but allow the
290 // tangential components to transport values from the interior.
291 if (is_vel_in_dir) {
292 lo = s_ext;
293 }
294 }
295 else if (bchi == BCType::reflect_odd)
296 {
297 lo = Real(0.);
298 hi = Real(0.);
299 }
300 else if ( bchi == BCType::foextrap || bchi == BCType::hoextrap ||
301 bchi == BCType::reflect_even ||
302 (bchi == BCType::direction_dependent && macvel >= 0.0))
303 {
304 hi = lo;
305 }
306 }
307}
308
309} // namespace
310#endif
311/** @}*/
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
__host__ __device__ const IntVectND< dim > & bigEnd() const &noexcept
__host__ __device__ const IntVectND< dim > & smallEnd() const &noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void SetEdgeBCsHi(int edge_dir, int i, int j, int k, int n, const amrex::Array4< const amrex::Real > &s, amrex::Real &lo, amrex::Real &hi, amrex::Real macvel, int bchi, int domhi, bool is_velocity)
Boundary condition effects.
Definition hydro_bcs_K.H:256
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void SetExtrapVelBCsLo(int edge_dir, int i, int j, int k, int n, const amrex::Array4< const amrex::Real > &s, amrex::Real &lo, amrex::Real &hi, int bclo, int domlo)
Boundary condition effects.
Definition hydro_bcs_K.H:76
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void SetExtrapVelBCsHi(int edge_dir, int i, int j, int k, int n, const amrex::Array4< const amrex::Real > &s, amrex::Real &lo, amrex::Real &hi, int bchi, int domhi)
Boundary condition effects.
Definition hydro_bcs_K.H:133
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void SetEdgeBCsLo(int edge_dir, int i, int j, int k, int n, const amrex::Array4< const amrex::Real > &s, amrex::Real &lo, amrex::Real &hi, amrex::Real macvel, int bclo, int domlo, bool is_velocity)
Boundary condition effects.
Definition hydro_bcs_K.H:190
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::BCRec getBC(const int i, const int j, const int k, const int n, const amrex::Box &m_domain, const amrex::BCRec *bcr, amrex::Array4< int const > const &bca)
Definition hydro_bcs_K.H:34
__host__ __device__ bool contains(int i, int j, int k) const noexcept