AMReX-Hydro
AMReX-based hydro routines for low Mach number flows
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 
11 using namespace amrex::literals;
12 
13 namespace MOL {
14 
16 amrex::Real hydro_mol_xedge_state_extdir ( int i, int j, int k, int n,
19  amrex::BCRec const* const d_bcrec,
20  int domlo, int domhi, bool is_velocity) noexcept
21 {
22  amrex::Real qs;
23 
24  //slope order
25  int order = 2;
26 
27  bool edlo = (d_bcrec[n].lo(0) == amrex::BCType::ext_dir);
28  bool edhi = (d_bcrec[n].hi(0) == amrex::BCType::ext_dir);
29 
30  bool extdir_or_ho_lo = (d_bcrec[n].lo(0) == amrex::BCType::ext_dir) || d_bcrec[n].lo(0) == amrex::BCType::hoextrap;
31  bool extdir_or_ho_hi = (d_bcrec[n].hi(0) == amrex::BCType::ext_dir) || d_bcrec[n].lo(0) == amrex::BCType::hoextrap;
32 
33  if (edlo && i <= domlo)
34  {
35  qs = q(domlo-1,j,k,n);
36  }
37  else if ( edhi && i >= domhi+1)
38  {
39  qs = q(domhi+1,j,k,n);
40  }
41  else
42  {
43  amrex::Real qpls = q(i ,j,k,n) - 0.5 *
44  amrex_calc_xslope_extdir( i , j, k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
45  amrex::Real qmns = q(i-1,j,k,n) + 0.5 *
46  amrex_calc_xslope_extdir( i-1, j, k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
47 
48  HydroBC::SetEdgeBCsLo(0,i,j,k,n,q,qmns,qpls,umac(i,j,k),d_bcrec[n].lo(0),domlo,is_velocity);
49  HydroBC::SetEdgeBCsHi(0,i,j,k,n,q,qmns,qpls,umac(i,j,k),d_bcrec[n].hi(0),domhi,is_velocity);
50 
51  if ( (i==domlo) && (d_bcrec[n].lo(0) == amrex::BCType::foextrap || d_bcrec[n].lo(0) == amrex::BCType::hoextrap) )
52  {
53  if ( umac(i,j,k) >= 0. && n==XVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt);
54  qmns = qpls;
55  }
56  if ( (i==domhi+1) && (d_bcrec[n].hi(0) == amrex::BCType::foextrap || d_bcrec[n].hi(0) == amrex::BCType::hoextrap) )
57  {
58  if ( umac(i,j,k) <= 0. && n==XVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt);
59  qpls = qmns;
60  }
61 
62  if ( umac(i,j,k) > small_vel)
63  {
64  qs = qmns;
65  }
66  else if ( umac(i,j,k) < -small_vel)
67  {
68  qs = qpls;
69  }
70  else
71  {
72  qs = 0.5*(qmns+qpls);
73  }
74  }
75 
76  return qs;
77 }
78 
80 amrex::Real hydro_mol_xedge_state ( int i, int j, int k, int n,
83  amrex::BCRec const* const d_bcrec,
84  int domlo, int domhi, bool is_velocity) noexcept
85 {
86  //slope order
87  int order = 2;
88 
89  amrex::Real qs;
90  amrex::Real qpls = q(i ,j,k,n) - 0.5 * amrex_calc_xslope( i , j, k, n, order, q );
91  amrex::Real qmns = q(i-1,j,k,n) + 0.5 * amrex_calc_xslope( i-1, j, k, n, order, q );
92 
93  HydroBC::SetEdgeBCsLo(0,i,j,k,n,q,qmns,qpls,umac(i,j,k),d_bcrec[n].lo(0),domlo,is_velocity);
94  HydroBC::SetEdgeBCsHi(0,i,j,k,n,q,qmns,qpls,umac(i,j,k),d_bcrec[n].hi(0),domhi,is_velocity);
95 
96  if ( (i==domlo) && (d_bcrec[n].lo(0) == amrex::BCType::foextrap || d_bcrec[n].lo(0) == amrex::BCType::hoextrap) )
97  {
98  if ( umac(i,j,k) >= 0. && n==XVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt);
99  qmns = qpls;
100  }
101  if ( (i==domhi+1) && (d_bcrec[n].hi(0) == amrex::BCType::foextrap || d_bcrec[n].hi(0) == amrex::BCType::hoextrap) )
102  {
103  if ( umac(i,j,k) <= 0. && n==XVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt);
104  qpls = qmns;
105  }
106 
107  if ( umac(i,j,k) > small_vel)
108  {
109  qs = qmns;
110  }
111  else if ( umac(i,j,k) < -small_vel)
112  {
113  qs = qpls;
114  }
115  else
116  {
117  qs = 0.5*(qmns+qpls);
118  }
119 
120  return qs;
121 }
122 
123 
125 amrex::Real hydro_mol_yedge_state_extdir ( int i, int j, int k, int n,
128  amrex::BCRec const* const d_bcrec,
129  int domlo, int domhi, bool is_velocity) noexcept
130 {
131  //slope order
132  int order = 2;
133 
134  bool edlo = (d_bcrec[n].lo(1) == amrex::BCType::ext_dir);
135  bool edhi = (d_bcrec[n].hi(1) == amrex::BCType::ext_dir);
136 
137  bool extdir_or_ho_lo = (d_bcrec[n].lo(1) == amrex::BCType::ext_dir) || d_bcrec[n].lo(1) == amrex::BCType::hoextrap;
138  bool extdir_or_ho_hi = (d_bcrec[n].hi(1) == amrex::BCType::ext_dir) || d_bcrec[n].lo(1) == amrex::BCType::hoextrap;
139 
140  amrex::Real qs;
141 
142  if (edlo && j <= domlo)
143  {
144  qs = q(i,domlo-1,k,n);
145  }
146  else if ( edhi && j >= domhi+1)
147  {
148  qs = q(i,domhi+1,k,n);
149  }
150  else
151  {
152  amrex::Real qpls = q(i,j ,k,n) - 0.5 *
153  amrex_calc_yslope_extdir( i, j , k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
154  amrex::Real qmns = q(i,j-1,k,n) + 0.5 *
155  amrex_calc_yslope_extdir( i, j-1, k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
156 
157  HydroBC::SetEdgeBCsLo(1,i,j,k,n,q,qmns,qpls,vmac(i,j,k),d_bcrec[n].lo(1),domlo,is_velocity);
158  HydroBC::SetEdgeBCsHi(1,i,j,k,n,q,qmns,qpls,vmac(i,j,k),d_bcrec[n].hi(1),domhi,is_velocity);
159 
160  if ( (j==domlo) && (d_bcrec[n].lo(1) == amrex::BCType::foextrap || d_bcrec[n].lo(1) == amrex::BCType::hoextrap) )
161  {
162  if ( vmac(i,j,k) >= 0. && n==YVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt);
163  qmns = qpls;
164  }
165  if ( (j==domhi+1) && (d_bcrec[n].hi(1) == amrex::BCType::foextrap || d_bcrec[n].hi(1) == amrex::BCType::hoextrap) )
166  {
167  if ( vmac(i,j,k) <= 0. && n==YVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt);
168  qpls = qmns;
169  }
170 
171  if ( vmac(i,j,k) > small_vel)
172  {
173  qs = qmns;
174  }
175  else if ( vmac(i,j,k) < -small_vel)
176  {
177  qs = qpls;
178  }
179  else
180  {
181  qs = 0.5*(qmns+qpls);
182  }
183  }
184 
185  return qs;
186 }
187 
188 
189 
191 amrex::Real hydro_mol_yedge_state ( int i, int j, int k, int n,
194  amrex::BCRec const* const d_bcrec,
195  int domlo, int domhi, bool is_velocity) noexcept
196 {
197  //slope order
198  int order = 2;
199 
200  amrex::Real qs;
201  amrex::Real qpls = q(i,j ,k,n) - 0.5 * amrex_calc_yslope( i, j , k, n, order, q );
202  amrex::Real qmns = q(i,j-1,k,n) + 0.5 * amrex_calc_yslope( i, j-1, k, n, order, q );
203 
204  HydroBC::SetEdgeBCsLo(1,i,j,k,n,q,qmns,qpls,vmac(i,j,k), d_bcrec[n].lo(1),domlo,is_velocity);
205  HydroBC::SetEdgeBCsHi(1,i,j,k,n,q,qmns,qpls,vmac(i,j,k), d_bcrec[n].hi(1),domhi,is_velocity);
206 
207  if ( (j==domlo) && (d_bcrec[n].lo(1) == amrex::BCType::foextrap || d_bcrec[n].lo(1) == amrex::BCType::hoextrap) )
208  {
209  if ( vmac(i,j,k) >= 0. && n==YVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt);
210  qmns = qpls;
211  }
212  if ( (j==domhi+1) && (d_bcrec[n].hi(1) == amrex::BCType::foextrap || d_bcrec[n].hi(1) == amrex::BCType::hoextrap) )
213  {
214  if ( vmac(i,j,k) <= 0. && n==YVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt);
215  qpls = qmns;
216  }
217 
218  if ( vmac(i,j,k) > small_vel)
219  {
220  qs = qmns;
221  }
222  else if ( vmac(i,j,k) < -small_vel)
223  {
224  qs = qpls;
225  }
226  else
227  {
228  qs = 0.5*(qmns+qpls);
229  }
230 
231  return qs;
232 
233 }
234 
235 #if (AMREX_SPACEDIM==3)
236 
238 amrex::Real hydro_mol_zedge_state_extdir ( int i, int j, int k, int n,
241  amrex::BCRec const* const d_bcrec,
242  int domlo, int domhi, bool is_velocity) noexcept
243 {
244  //slope order
245  int order = 2;
246 
247  amrex::Real qs;
248 
249  bool edlo = (d_bcrec[n].lo(2) == amrex::BCType::ext_dir);
250  bool edhi = (d_bcrec[n].hi(2) == amrex::BCType::ext_dir);
251 
252  bool extdir_or_ho_lo = (d_bcrec[n].lo(2) == amrex::BCType::ext_dir) || d_bcrec[n].lo(2) == amrex::BCType::hoextrap;
253  bool extdir_or_ho_hi = (d_bcrec[n].hi(2) == amrex::BCType::ext_dir) || d_bcrec[n].lo(2) == amrex::BCType::hoextrap;
254 
255  if (edlo && k <= domlo)
256  {
257  qs = q(i,j,domlo-1,n);
258  }
259  else if ( edhi && k >= domhi+1)
260  {
261  qs = q(i,j,domhi+1,n);
262  }
263  else
264  {
265  amrex::Real qpls = q(i,j,k ,n) - 0.5 *
266  amrex_calc_zslope_extdir( i, j, k , n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
267  amrex::Real qmns = q(i,j,k-1,n) + 0.5 *
268  amrex_calc_zslope_extdir( i, j, k-1, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
269 
270  HydroBC::SetEdgeBCsLo(2,i,j,k,n,q,qmns,qpls,wmac(i,j,k),d_bcrec[n].lo(2),domlo,is_velocity);
271  HydroBC::SetEdgeBCsHi(2,i,j,k,n,q,qmns,qpls,wmac(i,j,k),d_bcrec[n].hi(2),domhi,is_velocity);
272 
273  if ( (k==domlo) && (d_bcrec[n].lo(2) == amrex::BCType::foextrap || d_bcrec[n].lo(2) == amrex::BCType::hoextrap) )
274  {
275  if ( wmac(i,j,k) >= 0. && n==ZVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt);
276  qmns = qpls;
277  }
278  if ( (k==domhi+1) && (d_bcrec[n].hi(2) == amrex::BCType::foextrap || d_bcrec[n].hi(2) == amrex::BCType::hoextrap) )
279  {
280  if ( wmac(i,j,k) <= 0. && n==ZVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt);
281  qpls = qmns;
282  }
283 
284  if ( wmac(i,j,k) > small_vel)
285  {
286  qs = qmns;
287  }
288  else if ( wmac(i,j,k) < -small_vel)
289  {
290  qs = qpls;
291  }
292  else
293  {
294  qs = 0.5*(qmns+qpls);
295  }
296  }
297 
298  return qs;
299 }
300 
301 
302 
304 amrex::Real hydro_mol_zedge_state ( int i, int j, int k, int n,
307  amrex::BCRec const* const d_bcrec,
308  int domlo, int domhi, bool is_velocity) noexcept
309 {
310  //slope order
311  int order = 2;
312 
313  amrex::Real qs;
314  amrex::Real qpls = q(i,j,k ,n) - 0.5 * amrex_calc_zslope( i, j, k , n, order, q );
315  amrex::Real qmns = q(i,j,k-1,n) + 0.5 * amrex_calc_zslope( i, j, k-1, n, order, q );
316 
317  HydroBC::SetEdgeBCsLo(2,i,j,k,n,q,qmns,qpls,wmac(i,j,k),d_bcrec[n].lo(2),domlo,is_velocity);
318  HydroBC::SetEdgeBCsHi(2,i,j,k,n,q,qmns,qpls,wmac(i,j,k),d_bcrec[n].hi(2),domhi,is_velocity);
319 
320  if ( (k==domlo) && (d_bcrec[n].lo(2) == amrex::BCType::foextrap || d_bcrec[n].lo(2) == amrex::BCType::hoextrap) )
321  {
322  if ( wmac(i,j,k) >= 0. && n==ZVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt);
323  qmns = qpls;
324  }
325  if ( (k==domhi+1) && (d_bcrec[n].hi(2) == amrex::BCType::foextrap || d_bcrec[n].hi(2) == amrex::BCType::hoextrap) )
326  {
327  if ( wmac(i,j,k) <= 0. && n==ZVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt);
328  qpls = qmns;
329  }
330 
331  if ( wmac(i,j,k) > small_vel)
332  {
333  qs = qmns;
334  }
335  else if ( wmac(i,j,k) < -small_vel)
336  {
337  qs = qpls;
338  }
339  else
340  {
341  qs = 0.5*(qmns+qpls);
342  }
343 
344  return qs;
345 
346 }
347 
348 #endif
349 
350 }
351 
352 #endif
353 /** @}*/
#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_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 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_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) noexcept
Definition: hydro_mol_edge_state_K.H:80
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) noexcept
Definition: hydro_mol_edge_state_K.H:125
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) noexcept
Definition: hydro_mol_edge_state_K.H:191
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) noexcept
Definition: hydro_mol_edge_state_K.H:16
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real amrex_calc_yslope_extdir(int i, int j, int k, int n, int order, amrex::Array4< Real const > const &q, bool edlo, bool edhi, int domlo, int domhi) noexcept
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & max(const T &a, const T &b) noexcept
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real amrex_calc_yslope(int i, int j, int k, int n, int order, amrex::Array4< Real const > const &q) noexcept
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & min(const T &a, const T &b) noexcept
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real amrex_calc_xslope_extdir(int i, int j, int k, int n, int order, amrex::Array4< Real const > const &q, bool edlo, bool edhi, int domlo, int domhi) noexcept
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real amrex_calc_xslope(int i, int j, int k, int n, int order, amrex::Array4< Real const > const &q) noexcept