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 the velocity to faces. s is the velocity
85 // array and n runs over every component, normal and tangential alike.
86 //
87
88 GpuArray<int,3> iv = {i,j,k};
89
90 if (iv[edge_dir] == domlo)
91 {
92 iv[edge_dir] = domlo-1;
93 Real s_ext = s(iv[0],iv[1],iv[2],n);
94
95 // Whether the face is inflow or outflow is a property of the face, not of the
96 // component being filled, so test the normal component of the ghost velocity.
97 // A zero normal velocity counts as inflow, matching the (EB)Godunov and PPM
98 // kernels and the in/out solvability mask.
99 Real vel_n = s(iv[0],iv[1],iv[2],edge_dir);
100
101 bool is_vel_in_dir = (n == edge_dir);
102
103 if ( (bclo == BCType::ext_dir) ||
104 (bclo == BCType::direction_dependent && vel_n >= amrex::Real(0.0)) )
105 {
106 if (is_vel_in_dir) {
107 lo = s_ext;
108 hi = s_ext;
109 } else {
110 lo = s_ext;
111 }
112 }
113 else if (bclo == BCType::reflect_odd)
114 {
115 hi = Real(0.);
116 lo = Real(0.);
117 }
118 else if ( bclo == BCType::foextrap || bclo == BCType::hoextrap ||
119 bclo == BCType::reflect_even ||
120 (bclo == BCType::direction_dependent && vel_n < amrex::Real(0.0)))
121 {
122 lo = hi;
123 }
124 }
125}
126
127/**
128 *
129 * <A ID="SetExtrapVelBCsHi"></A>
130 *
131 * \brief Boundary condition effects
132 *
133 *
134 * For a detailed discussion see the AMReX-Hydro Guide
135 * <A HREF="https://amrex-fluids.github.io/amrex-hydro/docs_html"></A>.
136 *
137 */
138
140void SetExtrapVelBCsHi (int edge_dir, int i, int j, int k, int n,
142 amrex::Real &lo, amrex::Real &hi,
143 int bchi, int domhi)
144{
145 using namespace amrex;
146
147 //
148 // This is called in the extrapolation of the velocity to faces. s is the velocity
149 // array and n runs over every component, normal and tangential alike.
150 //
151
152 GpuArray<int,3> iv = {i,j,k};
153
154 if (iv[edge_dir] == domhi+1)
155 {
156 iv[edge_dir] = domhi+1;
157 Real s_ext = s(iv[0],iv[1],iv[2],n);
158
159 // Whether the face is inflow or outflow is a property of the face, not of the
160 // component being filled, so test the normal component of the ghost velocity.
161 // A zero normal velocity counts as inflow, matching the (EB)Godunov and PPM
162 // kernels and the in/out solvability mask.
163 Real vel_n = s(iv[0],iv[1],iv[2],edge_dir);
164
165 bool is_vel_in_dir = (n == edge_dir);
166
167 if ( (bchi == BCType::ext_dir) ||
168 (bchi == BCType::direction_dependent && vel_n <= amrex::Real(0.0)) )
169 {
170 if (is_vel_in_dir) {
171 hi = s_ext;
172 lo = s_ext;
173 } else {
174 hi = s_ext;
175 }
176 }
177 else if (bchi == BCType::reflect_odd)
178 {
179 lo = Real(0.);
180 hi = Real(0.);
181 }
182 else if ( bchi == BCType::foextrap || bchi == BCType::hoextrap ||
183 bchi == BCType::reflect_even ||
184 (bchi == BCType::direction_dependent && vel_n > amrex::Real(0.0)))
185 {
186 hi = lo;
187 }
188 }
189}
190
191/**
192 *
193 * <A ID="SetEdgeBCsLo"></A>
194 *
195 * \brief Boundary condition effects
196 *
197 *
198 * For a detailed discussion see the AMReX-Hydro Guide
199 * <A HREF="https://amrex-fluids.github.io/amrex-hydro/docs_html"></A>.
200 *
201 */
202
204void SetEdgeBCsLo (int edge_dir, int i, int j, int k, int n,
206 amrex::Real &lo, amrex::Real &hi,
207 amrex::Real macvel,
208 int bclo, int domlo,
209 bool is_velocity )
210{
211 using namespace amrex;
212
213 //
214 // This is called for all quantities in the construction of edge states
215 //
216
217 GpuArray<int,3> iv = {i,j,k};
218
219 if (iv[edge_dir] == domlo)
220 {
221 iv[edge_dir] = domlo-1;
222 Real s_ext = s(iv[0],iv[1],iv[2],n);
223
224 bool is_vel_in_dir = is_velocity && (n == edge_dir);
225
226 // For direction_dependent, a zero face velocity counts as inflow,
227 // matching the (EB)Godunov and PPM kernels and the in/out solvability mask.
228 if (bclo == BCType::direction_dependent && macvel >= amrex::Real(0.0))
229 {
230 lo = s_ext;
231 hi = s_ext;
232 }
233 else if (bclo == BCType::ext_dir)
234 {
235 lo = s_ext;
236
237 // For turbulent inflow, there are times when the inflow face
238 // may have a predicted outflowing velocity. Here, we preserve
239 // the normal component of the Dirichlet BC, but allow the
240 // tangential components to transport values from the interior.
241 if (is_vel_in_dir) {
242 hi = s_ext;
243 }
244 }
245 else if (bclo == BCType::reflect_odd)
246 {
247 hi = Real(0.);
248 lo = Real(0.);
249 }
250 else if ( bclo == BCType::foextrap || bclo == BCType::hoextrap ||
251 bclo == BCType::reflect_even ||
252 (bclo == BCType::direction_dependent && macvel < amrex::Real(0.0)))
253 {
254 lo = hi;
255 }
256 }
257}
258
259/**
260 *
261 * <A ID="SetEdgeBCsHi"></A>
262 *
263 * \brief Boundary condition effects
264 *
265 *
266 * For a detailed discussion see the AMReX-Hydro Guide
267 * <A HREF="https://amrex-fluids.github.io/amrex-hydro/docs_html"></A>.
268 *
269 */
270
272void SetEdgeBCsHi (int edge_dir, int i, int j, int k, int n,
274 amrex::Real &lo, amrex::Real &hi,
275 amrex::Real macvel,
276 int bchi, int domhi,
277 bool is_velocity )
278{
279 using namespace amrex;
280
281 //
282 // This is called for all quantities in the construction of edge states
283 //
284
285 GpuArray<int,3> iv = {i,j,k};
286
287 if (iv[edge_dir] == domhi+1)
288 {
289 iv[edge_dir] = domhi+1;
290 Real s_ext = s(iv[0],iv[1],iv[2],n);
291
292 bool is_vel_in_dir = is_velocity && (n == edge_dir);
293
294 // For direction_dependent, a zero face velocity counts as inflow,
295 // matching the (EB)Godunov and PPM kernels and the in/out solvability mask.
296 if (bchi == BCType::direction_dependent && macvel <= amrex::Real(0.0))
297 {
298 hi = s_ext;
299 lo = s_ext;
300 }
301 else if (bchi == BCType::ext_dir)
302 {
303 hi = s_ext;
304
305 // For turbulent inflow, there are times when the inflow face
306 // may have a predicted outflowing velocity. Here, we preserve
307 // the normal component of the Dirichlet BC, but allow the
308 // tangential components to transport values from the interior.
309 if (is_vel_in_dir) {
310 lo = s_ext;
311 }
312 }
313 else if (bchi == BCType::reflect_odd)
314 {
315 lo = Real(0.);
316 hi = Real(0.);
317 }
318 else if ( bchi == BCType::foextrap || bchi == BCType::hoextrap ||
319 bchi == BCType::reflect_even ||
320 (bchi == BCType::direction_dependent && macvel > amrex::Real(0.0)))
321 {
322 hi = lo;
323 }
324 }
325}
326
327} // namespace
328#endif
329/** @}*/
#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_real Real
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:272
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:140
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:204
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__ constexpr bool contains(idx... i) const noexcept