AMReX-Hydro
AMReX-based hydro routines for low Mach number flows
 
Loading...
Searching...
No Matches
hydro_mol_edge_state_K.H
Go to the documentation of this file.
1/** \addtogroup MOL
2 * @{
3 */
4
5#ifndef HYDRO_MOL_EDGE_STATE_K_H_
6#define HYDRO_MOL_EDGE_STATE_K_H_
7#include <AMReX_Slopes_K.H>
8#include <hydro_bcs_K.H>
9#include <hydro_constants.H>
10
11namespace MOL {
12
14amrex::Real hydro_mol_xedge_state_extdir ( int i, int j, int k, int n,
17 amrex::BCRec const* const d_bcrec,
18 int domlo, int domhi, bool is_velocity, bool allow_inflow_on_outflow) noexcept
19{
20 amrex::Real qs;
21
22 //slope order
23 int order = 2;
24
25 bool edlo = (d_bcrec[n].lo(0) == amrex::BCType::ext_dir);
26 bool edhi = (d_bcrec[n].hi(0) == amrex::BCType::ext_dir);
27
28 bool extdir_or_ho_lo = (d_bcrec[n].lo(0) == amrex::BCType::ext_dir) || (d_bcrec[n].lo(0) == amrex::BCType::hoextrap);
29 bool extdir_or_ho_hi = (d_bcrec[n].hi(0) == amrex::BCType::ext_dir) || (d_bcrec[n].hi(0) == amrex::BCType::hoextrap);
30
31 // Only short-circuit on faces outside the domain. On the domain face itself we
32 // fall through to SetEdgeBCsLo/Hi, which keeps the Dirichlet value for the
33 // inflowing state but lets the interior state be transported out, so that an
34 // ext_dir face with local backflow upwinds the same way (EB)Godunov does.
35 if (edlo && i < domlo)
36 {
37 qs = q(domlo-1,j,k,n);
38 }
39 else if ( edhi && i > domhi+1)
40 {
41 qs = q(domhi+1,j,k,n);
42 }
43 else
44 {
45 amrex::Real qpls = q(i ,j,k,n) - amrex::Real(0.5) *
46 amrex_calc_xslope_extdir( i , j, k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
47 amrex::Real qmns = q(i-1,j,k,n) + amrex::Real(0.5) *
48 amrex_calc_xslope_extdir( i-1, j, k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
49
50 HydroBC::SetEdgeBCsLo(0,i,j,k,n,q,qmns,qpls,umac(i,j,k),d_bcrec[n].lo(0),domlo,is_velocity);
51 HydroBC::SetEdgeBCsHi(0,i,j,k,n,q,qmns,qpls,umac(i,j,k),d_bcrec[n].hi(0),domhi,is_velocity);
52
53 // The clamp below forces the normal velocity to be outflowing at an outflow
54 // face. allow_inflow_on_outflow lets the caller keep an inflowing MAC
55 // velocity there, so the state must not be clamped against it.
56 if (!allow_inflow_on_outflow)
57 {
58 if ( (i==domlo) && (d_bcrec[n].lo(0) == amrex::BCType::foextrap || d_bcrec[n].lo(0) == amrex::BCType::hoextrap) )
59 {
60 if ( umac(i,j,k) >= amrex::Real(0.) && n==XVEL && is_velocity ) qpls = amrex::min(qpls,amrex::Real(0));
61 qmns = qpls;
62 }
63 if ( (i==domhi+1) && (d_bcrec[n].hi(0) == amrex::BCType::foextrap || d_bcrec[n].hi(0) == amrex::BCType::hoextrap) )
64 {
65 if ( umac(i,j,k) <= amrex::Real(0.) && n==XVEL && is_velocity ) qmns = amrex::max(qmns,amrex::Real(0));
66 qpls = qmns;
67 }
68 }
69
70 if ( umac(i,j,k) > small_vel)
71 {
72 qs = qmns;
73 }
74 else if ( umac(i,j,k) < -small_vel)
75 {
76 qs = qpls;
77 }
78 else
79 {
80 qs = amrex::Real(0.5)*(qmns+qpls);
81 }
82 }
83
84 return qs;
85}
86
88amrex::Real hydro_mol_xedge_state ( int i, int j, int k, int n,
91 amrex::BCRec const* const d_bcrec,
92 int domlo, int domhi, bool is_velocity, bool allow_inflow_on_outflow) noexcept
93{
94 //slope order
95 int order = 2;
96
97 amrex::Real qs;
98 amrex::Real qpls = q(i ,j,k,n) - amrex::Real(0.5) * amrex_calc_xslope( i , j, k, n, order, q );
99 amrex::Real qmns = q(i-1,j,k,n) + amrex::Real(0.5) * amrex_calc_xslope( i-1, j, k, n, order, q );
100
101 HydroBC::SetEdgeBCsLo(0,i,j,k,n,q,qmns,qpls,umac(i,j,k),d_bcrec[n].lo(0),domlo,is_velocity);
102 HydroBC::SetEdgeBCsHi(0,i,j,k,n,q,qmns,qpls,umac(i,j,k),d_bcrec[n].hi(0),domhi,is_velocity);
103
104 // The clamp below forces the normal velocity to be outflowing at an outflow
105 // face. allow_inflow_on_outflow lets the caller keep an inflowing MAC
106 // velocity there, so the state must not be clamped against it.
107 if (!allow_inflow_on_outflow)
108 {
109 if ( (i==domlo) && (d_bcrec[n].lo(0) == amrex::BCType::foextrap || d_bcrec[n].lo(0) == amrex::BCType::hoextrap) )
110 {
111 if ( umac(i,j,k) >= amrex::Real(0.) && n==XVEL && is_velocity ) qpls = amrex::min(qpls,amrex::Real(0));
112 qmns = qpls;
113 }
114 if ( (i==domhi+1) && (d_bcrec[n].hi(0) == amrex::BCType::foextrap || d_bcrec[n].hi(0) == amrex::BCType::hoextrap) )
115 {
116 if ( umac(i,j,k) <= amrex::Real(0.) && n==XVEL && is_velocity ) qmns = amrex::max(qmns,amrex::Real(0));
117 qpls = qmns;
118 }
119 }
120
121 if ( umac(i,j,k) > small_vel)
122 {
123 qs = qmns;
124 }
125 else if ( umac(i,j,k) < -small_vel)
126 {
127 qs = qpls;
128 }
129 else
130 {
131 qs = amrex::Real(0.5)*(qmns+qpls);
132 }
133
134 return qs;
135}
136
137
139amrex::Real hydro_mol_yedge_state_extdir ( int i, int j, int k, int n,
142 amrex::BCRec const* const d_bcrec,
143 int domlo, int domhi, bool is_velocity, bool allow_inflow_on_outflow) noexcept
144{
145 //slope order
146 int order = 2;
147
148 bool edlo = (d_bcrec[n].lo(1) == amrex::BCType::ext_dir);
149 bool edhi = (d_bcrec[n].hi(1) == amrex::BCType::ext_dir);
150
151 bool extdir_or_ho_lo = (d_bcrec[n].lo(1) == amrex::BCType::ext_dir) || (d_bcrec[n].lo(1) == amrex::BCType::hoextrap);
152 bool extdir_or_ho_hi = (d_bcrec[n].hi(1) == amrex::BCType::ext_dir) || (d_bcrec[n].hi(1) == amrex::BCType::hoextrap);
153
154 amrex::Real qs;
155
156 // Only short-circuit on faces outside the domain. On the domain face itself we
157 // fall through to SetEdgeBCsLo/Hi, which keeps the Dirichlet value for the
158 // inflowing state but lets the interior state be transported out, so that an
159 // ext_dir face with local backflow upwinds the same way (EB)Godunov does.
160 if (edlo && j < domlo)
161 {
162 qs = q(i,domlo-1,k,n);
163 }
164 else if ( edhi && j > domhi+1)
165 {
166 qs = q(i,domhi+1,k,n);
167 }
168 else
169 {
170 amrex::Real qpls = q(i,j ,k,n) - amrex::Real(0.5) *
171 amrex_calc_yslope_extdir( i, j , k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
172 amrex::Real qmns = q(i,j-1,k,n) + amrex::Real(0.5) *
173 amrex_calc_yslope_extdir( i, j-1, k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
174
175 HydroBC::SetEdgeBCsLo(1,i,j,k,n,q,qmns,qpls,vmac(i,j,k),d_bcrec[n].lo(1),domlo,is_velocity);
176 HydroBC::SetEdgeBCsHi(1,i,j,k,n,q,qmns,qpls,vmac(i,j,k),d_bcrec[n].hi(1),domhi,is_velocity);
177
178 // The clamp below forces the normal velocity to be outflowing at an outflow
179 // face. allow_inflow_on_outflow lets the caller keep an inflowing MAC
180 // velocity there, so the state must not be clamped against it.
181 if (!allow_inflow_on_outflow)
182 {
183 if ( (j==domlo) && (d_bcrec[n].lo(1) == amrex::BCType::foextrap || d_bcrec[n].lo(1) == amrex::BCType::hoextrap) )
184 {
185 if ( vmac(i,j,k) >= amrex::Real(0.) && n==YVEL && is_velocity ) qpls = amrex::min(qpls,amrex::Real(0));
186 qmns = qpls;
187 }
188 if ( (j==domhi+1) && (d_bcrec[n].hi(1) == amrex::BCType::foextrap || d_bcrec[n].hi(1) == amrex::BCType::hoextrap) )
189 {
190 if ( vmac(i,j,k) <= amrex::Real(0.) && n==YVEL && is_velocity ) qmns = amrex::max(qmns,amrex::Real(0));
191 qpls = qmns;
192 }
193 }
194
195 if ( vmac(i,j,k) > small_vel)
196 {
197 qs = qmns;
198 }
199 else if ( vmac(i,j,k) < -small_vel)
200 {
201 qs = qpls;
202 }
203 else
204 {
205 qs = amrex::Real(0.5)*(qmns+qpls);
206 }
207 }
208
209 return qs;
210}
211
212
213
215amrex::Real hydro_mol_yedge_state ( int i, int j, int k, int n,
218 amrex::BCRec const* const d_bcrec,
219 int domlo, int domhi, bool is_velocity, bool allow_inflow_on_outflow) noexcept
220{
221 //slope order
222 int order = 2;
223
224 amrex::Real qs;
225 amrex::Real qpls = q(i,j ,k,n) - amrex::Real(0.5) * amrex_calc_yslope( i, j , k, n, order, q );
226 amrex::Real qmns = q(i,j-1,k,n) + amrex::Real(0.5) * amrex_calc_yslope( i, j-1, k, n, order, q );
227
228 HydroBC::SetEdgeBCsLo(1,i,j,k,n,q,qmns,qpls,vmac(i,j,k), d_bcrec[n].lo(1),domlo,is_velocity);
229 HydroBC::SetEdgeBCsHi(1,i,j,k,n,q,qmns,qpls,vmac(i,j,k), d_bcrec[n].hi(1),domhi,is_velocity);
230
231 // The clamp below forces the normal velocity to be outflowing at an outflow
232 // face. allow_inflow_on_outflow lets the caller keep an inflowing MAC
233 // velocity there, so the state must not be clamped against it.
234 if (!allow_inflow_on_outflow)
235 {
236 if ( (j==domlo) && (d_bcrec[n].lo(1) == amrex::BCType::foextrap || d_bcrec[n].lo(1) == amrex::BCType::hoextrap) )
237 {
238 if ( vmac(i,j,k) >= amrex::Real(0.) && n==YVEL && is_velocity ) qpls = amrex::min(qpls,amrex::Real(0));
239 qmns = qpls;
240 }
241 if ( (j==domhi+1) && (d_bcrec[n].hi(1) == amrex::BCType::foextrap || d_bcrec[n].hi(1) == amrex::BCType::hoextrap) )
242 {
243 if ( vmac(i,j,k) <= amrex::Real(0.) && n==YVEL && is_velocity ) qmns = amrex::max(qmns,amrex::Real(0));
244 qpls = qmns;
245 }
246 }
247
248 if ( vmac(i,j,k) > small_vel)
249 {
250 qs = qmns;
251 }
252 else if ( vmac(i,j,k) < -small_vel)
253 {
254 qs = qpls;
255 }
256 else
257 {
258 qs = amrex::Real(0.5)*(qmns+qpls);
259 }
260
261 return qs;
262
263}
264
265#if (AMREX_SPACEDIM==3)
266
268amrex::Real hydro_mol_zedge_state_extdir ( int i, int j, int k, int n,
271 amrex::BCRec const* const d_bcrec,
272 int domlo, int domhi, bool is_velocity, bool allow_inflow_on_outflow) noexcept
273{
274 //slope order
275 int order = 2;
276
277 amrex::Real qs;
278
279 bool edlo = (d_bcrec[n].lo(2) == amrex::BCType::ext_dir);
280 bool edhi = (d_bcrec[n].hi(2) == amrex::BCType::ext_dir);
281
282 bool extdir_or_ho_lo = (d_bcrec[n].lo(2) == amrex::BCType::ext_dir) || (d_bcrec[n].lo(2) == amrex::BCType::hoextrap);
283 bool extdir_or_ho_hi = (d_bcrec[n].hi(2) == amrex::BCType::ext_dir) || (d_bcrec[n].hi(2) == amrex::BCType::hoextrap);
284
285 // Only short-circuit on faces outside the domain. On the domain face itself we
286 // fall through to SetEdgeBCsLo/Hi, which keeps the Dirichlet value for the
287 // inflowing state but lets the interior state be transported out, so that an
288 // ext_dir face with local backflow upwinds the same way (EB)Godunov does.
289 if (edlo && k < domlo)
290 {
291 qs = q(i,j,domlo-1,n);
292 }
293 else if ( edhi && k > domhi+1)
294 {
295 qs = q(i,j,domhi+1,n);
296 }
297 else
298 {
299 amrex::Real qpls = q(i,j,k ,n) - amrex::Real(0.5) *
300 amrex_calc_zslope_extdir( i, j, k , n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
301 amrex::Real qmns = q(i,j,k-1,n) + amrex::Real(0.5) *
302 amrex_calc_zslope_extdir( i, j, k-1, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
303
304 HydroBC::SetEdgeBCsLo(2,i,j,k,n,q,qmns,qpls,wmac(i,j,k),d_bcrec[n].lo(2),domlo,is_velocity);
305 HydroBC::SetEdgeBCsHi(2,i,j,k,n,q,qmns,qpls,wmac(i,j,k),d_bcrec[n].hi(2),domhi,is_velocity);
306
307 // The clamp below forces the normal velocity to be outflowing at an outflow
308 // face. allow_inflow_on_outflow lets the caller keep an inflowing MAC
309 // velocity there, so the state must not be clamped against it.
310 if (!allow_inflow_on_outflow)
311 {
312 if ( (k==domlo) && (d_bcrec[n].lo(2) == amrex::BCType::foextrap || d_bcrec[n].lo(2) == amrex::BCType::hoextrap) )
313 {
314 if ( wmac(i,j,k) >= amrex::Real(0.) && n==ZVEL && is_velocity ) qpls = amrex::min(qpls,amrex::Real(0));
315 qmns = qpls;
316 }
317 if ( (k==domhi+1) && (d_bcrec[n].hi(2) == amrex::BCType::foextrap || d_bcrec[n].hi(2) == amrex::BCType::hoextrap) )
318 {
319 if ( wmac(i,j,k) <= amrex::Real(0.) && n==ZVEL && is_velocity ) qmns = amrex::max(qmns,amrex::Real(0));
320 qpls = qmns;
321 }
322 }
323
324 if ( wmac(i,j,k) > small_vel)
325 {
326 qs = qmns;
327 }
328 else if ( wmac(i,j,k) < -small_vel)
329 {
330 qs = qpls;
331 }
332 else
333 {
334 qs = amrex::Real(0.5)*(qmns+qpls);
335 }
336 }
337
338 return qs;
339}
340
341
342
344amrex::Real hydro_mol_zedge_state ( int i, int j, int k, int n,
347 amrex::BCRec const* const d_bcrec,
348 int domlo, int domhi, bool is_velocity, bool allow_inflow_on_outflow) noexcept
349{
350 //slope order
351 int order = 2;
352
353 amrex::Real qs;
354 amrex::Real qpls = q(i,j,k ,n) - amrex::Real(0.5) * amrex_calc_zslope( i, j, k , n, order, q );
355 amrex::Real qmns = q(i,j,k-1,n) + amrex::Real(0.5) * amrex_calc_zslope( i, j, k-1, n, order, q );
356
357 HydroBC::SetEdgeBCsLo(2,i,j,k,n,q,qmns,qpls,wmac(i,j,k),d_bcrec[n].lo(2),domlo,is_velocity);
358 HydroBC::SetEdgeBCsHi(2,i,j,k,n,q,qmns,qpls,wmac(i,j,k),d_bcrec[n].hi(2),domhi,is_velocity);
359
360 // The clamp below forces the normal velocity to be outflowing at an outflow
361 // face. allow_inflow_on_outflow lets the caller keep an inflowing MAC
362 // velocity there, so the state must not be clamped against it.
363 if (!allow_inflow_on_outflow)
364 {
365 if ( (k==domlo) && (d_bcrec[n].lo(2) == amrex::BCType::foextrap || d_bcrec[n].lo(2) == amrex::BCType::hoextrap) )
366 {
367 if ( wmac(i,j,k) >= amrex::Real(0.) && n==ZVEL && is_velocity ) qpls = amrex::min(qpls,amrex::Real(0));
368 qmns = qpls;
369 }
370 if ( (k==domhi+1) && (d_bcrec[n].hi(2) == amrex::BCType::foextrap || d_bcrec[n].hi(2) == amrex::BCType::hoextrap) )
371 {
372 if ( wmac(i,j,k) <= amrex::Real(0.) && n==ZVEL && is_velocity ) qmns = amrex::max(qmns,amrex::Real(0));
373 qpls = qmns;
374 }
375 }
376
377 if ( wmac(i,j,k) > small_vel)
378 {
379 qs = qmns;
380 }
381 else if ( wmac(i,j,k) < -small_vel)
382 {
383 qs = qpls;
384 }
385 else
386 {
387 qs = amrex::Real(0.5)*(qmns+qpls);
388 }
389
390 return qs;
391
392}
393
394#endif
395
396}
397
398#endif
399/** @}*/
#define AMREX_FORCE_INLINE
#define AMREX_GPU_DEVICE
#define YVEL
Definition hydro_constants.H:29
static constexpr amrex::Real small_vel
Definition hydro_constants.H:37
#define XVEL
Definition hydro_constants.H:28
#define ZVEL
Definition hydro_constants.H:30
amrex_real Real
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
__host__ __device__ constexpr const T & max(const T &a, const T &b) 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:272
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_DEVICE AMREX_FORCE_INLINE amrex::Real hydro_mol_yedge_state_extdir(int i, int j, int k, int n, amrex::Array4< amrex::Real const > const &q, amrex::Array4< amrex::Real const > const &vmac, amrex::BCRec const *const d_bcrec, int domlo, int domhi, bool is_velocity, bool allow_inflow_on_outflow) noexcept
Definition hydro_mol_edge_state_K.H:139
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real hydro_mol_yedge_state(int i, int j, int k, int n, amrex::Array4< amrex::Real const > const &q, amrex::Array4< amrex::Real const > const &vmac, amrex::BCRec const *const d_bcrec, int domlo, int domhi, bool is_velocity, bool allow_inflow_on_outflow) noexcept
Definition hydro_mol_edge_state_K.H:215
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real hydro_mol_xedge_state(int i, int j, int k, int n, amrex::Array4< amrex::Real const > const &q, amrex::Array4< amrex::Real const > const &umac, amrex::BCRec const *const d_bcrec, int domlo, int domhi, bool is_velocity, bool allow_inflow_on_outflow) noexcept
Definition hydro_mol_edge_state_K.H:88
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real hydro_mol_xedge_state_extdir(int i, int j, int k, int n, amrex::Array4< amrex::Real const > const &q, amrex::Array4< amrex::Real const > const &umac, amrex::BCRec const *const d_bcrec, int domlo, int domhi, bool is_velocity, bool allow_inflow_on_outflow) noexcept
Definition hydro_mol_edge_state_K.H:14