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::SetXEdgeBCs(i,j,k,n,q,qmns,qpls,d_bcrec[n].lo(0),domlo,d_bcrec[n].hi(0),domhi,is_velocity);
49 
50  if ( (i==domlo) && (d_bcrec[n].lo(0) == amrex::BCType::foextrap || d_bcrec[n].lo(0) == amrex::BCType::hoextrap) )
51  {
52  if ( umac(i,j,k) >= 0. && n==XVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt);
53  qmns = qpls;
54  }
55  if ( (i==domhi+1) && (d_bcrec[n].hi(0) == amrex::BCType::foextrap || d_bcrec[n].hi(0) == amrex::BCType::hoextrap) )
56  {
57  if ( umac(i,j,k) <= 0. && n==XVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt);
58  qpls = qmns;
59  }
60 
61  if ( umac(i,j,k) > small_vel)
62  {
63  qs = qmns;
64  }
65  else if ( umac(i,j,k) < -small_vel)
66  {
67  qs = qpls;
68  }
69  else
70  {
71  qs = 0.5*(qmns+qpls);
72  }
73  }
74 
75  return qs;
76 }
77 
79 amrex::Real hydro_mol_xedge_state ( int i, int j, int k, int n,
82  amrex::BCRec const* const d_bcrec,
83  int domlo, int domhi, bool is_velocity) noexcept
84 {
85  //slope order
86  int order = 2;
87 
88  amrex::Real qs;
89  amrex::Real qpls = q(i ,j,k,n) - 0.5 * amrex_calc_xslope( i , j, k, n, order, q );
90  amrex::Real qmns = q(i-1,j,k,n) + 0.5 * amrex_calc_xslope( i-1, j, k, n, order, q );
91 
92  HydroBC::SetXEdgeBCs(i,j,k,n,q,qmns,qpls,d_bcrec[n].lo(0),domlo,d_bcrec[n].hi(0),domhi,is_velocity);
93 
94  if ( (i==domlo) && (d_bcrec[n].lo(0) == amrex::BCType::foextrap || d_bcrec[n].lo(0) == amrex::BCType::hoextrap) )
95  {
96  if ( umac(i,j,k) >= 0. && n==XVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt);
97  qmns = qpls;
98  }
99  if ( (i==domhi+1) && (d_bcrec[n].hi(0) == amrex::BCType::foextrap || d_bcrec[n].hi(0) == amrex::BCType::hoextrap) )
100  {
101  if ( umac(i,j,k) <= 0. && n==XVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt);
102  qpls = qmns;
103  }
104 
105  if ( umac(i,j,k) > small_vel)
106  {
107  qs = qmns;
108  }
109  else if ( umac(i,j,k) < -small_vel)
110  {
111  qs = qpls;
112  }
113  else
114  {
115  qs = 0.5*(qmns+qpls);
116  }
117 
118  return qs;
119 }
120 
121 
123 amrex::Real hydro_mol_yedge_state_extdir ( int i, int j, int k, int n,
126  amrex::BCRec const* const d_bcrec,
127  int domlo, int domhi, bool is_velocity) noexcept
128 {
129  //slope order
130  int order = 2;
131 
132  bool edlo = (d_bcrec[n].lo(1) == amrex::BCType::ext_dir);
133  bool edhi = (d_bcrec[n].hi(1) == amrex::BCType::ext_dir);
134 
135  bool extdir_or_ho_lo = (d_bcrec[n].lo(1) == amrex::BCType::ext_dir) || d_bcrec[n].lo(1) == amrex::BCType::hoextrap;
136  bool extdir_or_ho_hi = (d_bcrec[n].hi(1) == amrex::BCType::ext_dir) || d_bcrec[n].lo(1) == amrex::BCType::hoextrap;
137 
138  amrex::Real qs;
139 
140  if (edlo && j <= domlo)
141  {
142  qs = q(i,domlo-1,k,n);
143  }
144  else if ( edhi && j >= domhi+1)
145  {
146  qs = q(i,domhi+1,k,n);
147  }
148  else
149  {
150  amrex::Real qpls = q(i,j ,k,n) - 0.5 *
151  amrex_calc_yslope_extdir( i, j , k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
152  amrex::Real qmns = q(i,j-1,k,n) + 0.5 *
153  amrex_calc_yslope_extdir( i, j-1, k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
154 
155  HydroBC::SetYEdgeBCs(i,j,k,n,q,qmns,qpls,d_bcrec[n].lo(1),domlo,d_bcrec[n].hi(1),domhi,is_velocity);
156 
157  if ( (j==domlo) && (d_bcrec[n].lo(1) == amrex::BCType::foextrap || d_bcrec[n].lo(1) == amrex::BCType::hoextrap) )
158  {
159  if ( vmac(i,j,k) >= 0. && n==YVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt);
160  qmns = qpls;
161  }
162  if ( (j==domhi+1) && (d_bcrec[n].hi(1) == amrex::BCType::foextrap || d_bcrec[n].hi(1) == amrex::BCType::hoextrap) )
163  {
164  if ( vmac(i,j,k) <= 0. && n==YVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt);
165  qpls = qmns;
166  }
167 
168  if ( vmac(i,j,k) > small_vel)
169  {
170  qs = qmns;
171  }
172  else if ( vmac(i,j,k) < -small_vel)
173  {
174  qs = qpls;
175  }
176  else
177  {
178  qs = 0.5*(qmns+qpls);
179  }
180  }
181 
182  return qs;
183 }
184 
185 
186 
188 amrex::Real hydro_mol_yedge_state ( int i, int j, int k, int n,
191  amrex::BCRec const* const d_bcrec,
192  int domlo, int domhi, bool is_velocity) noexcept
193 {
194  //slope order
195  int order = 2;
196 
197  amrex::Real qs;
198  amrex::Real qpls = q(i,j ,k,n) - 0.5 * amrex_calc_yslope( i, j , k, n, order, q );
199  amrex::Real qmns = q(i,j-1,k,n) + 0.5 * amrex_calc_yslope( i, j-1, k, n, order, q );
200 
201  HydroBC::SetYEdgeBCs(i,j,k,n,q,qmns,qpls,d_bcrec[n].lo(1),domlo,d_bcrec[n].hi(1),domhi,is_velocity);
202 
203  if ( (j==domlo) && (d_bcrec[n].lo(1) == amrex::BCType::foextrap || d_bcrec[n].lo(1) == amrex::BCType::hoextrap) )
204  {
205  if ( vmac(i,j,k) >= 0. && n==YVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt);
206  qmns = qpls;
207  }
208  if ( (j==domhi+1) && (d_bcrec[n].hi(1) == amrex::BCType::foextrap || d_bcrec[n].hi(1) == amrex::BCType::hoextrap) )
209  {
210  if ( vmac(i,j,k) <= 0. && n==YVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt);
211  qpls = qmns;
212  }
213 
214  if ( vmac(i,j,k) > small_vel)
215  {
216  qs = qmns;
217  }
218  else if ( vmac(i,j,k) < -small_vel)
219  {
220  qs = qpls;
221  }
222  else
223  {
224  qs = 0.5*(qmns+qpls);
225  }
226 
227  return qs;
228 
229 }
230 
231 #if (AMREX_SPACEDIM==3)
232 
234 amrex::Real hydro_mol_zedge_state_extdir ( int i, int j, int k, int n,
237  amrex::BCRec const* const d_bcrec,
238  int domlo, int domhi, bool is_velocity) noexcept
239 {
240  //slope order
241  int order = 2;
242 
243  amrex::Real qs;
244 
245  bool edlo = (d_bcrec[n].lo(2) == amrex::BCType::ext_dir);
246  bool edhi = (d_bcrec[n].hi(2) == amrex::BCType::ext_dir);
247 
248  bool extdir_or_ho_lo = (d_bcrec[n].lo(2) == amrex::BCType::ext_dir) || d_bcrec[n].lo(2) == amrex::BCType::hoextrap;
249  bool extdir_or_ho_hi = (d_bcrec[n].hi(2) == amrex::BCType::ext_dir) || d_bcrec[n].lo(2) == amrex::BCType::hoextrap;
250 
251  if (edlo && k <= domlo)
252  {
253  qs = q(i,j,domlo-1,n);
254  }
255  else if ( edhi && k >= domhi+1)
256  {
257  qs = q(i,j,domhi+1,n);
258  }
259  else
260  {
261  amrex::Real qpls = q(i,j,k ,n) - 0.5 *
262  amrex_calc_zslope_extdir( i, j, k , n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
263  amrex::Real qmns = q(i,j,k-1,n) + 0.5 *
264  amrex_calc_zslope_extdir( i, j, k-1, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi );
265 
266  HydroBC::SetZEdgeBCs(i,j,k,n,q,qmns,qpls,d_bcrec[n].lo(2),domlo,d_bcrec[n].hi(2),domhi,is_velocity);
267 
268  if ( (k==domlo) && (d_bcrec[n].lo(2) == amrex::BCType::foextrap || d_bcrec[n].lo(2) == amrex::BCType::hoextrap) )
269  {
270  if ( wmac(i,j,k) >= 0. && n==ZVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt);
271  qmns = qpls;
272  }
273  if ( (k==domhi+1) && (d_bcrec[n].hi(2) == amrex::BCType::foextrap || d_bcrec[n].hi(2) == amrex::BCType::hoextrap) )
274  {
275  if ( wmac(i,j,k) <= 0. && n==ZVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt);
276  qpls = qmns;
277  }
278 
279  if ( wmac(i,j,k) > small_vel)
280  {
281  qs = qmns;
282  }
283  else if ( wmac(i,j,k) < -small_vel)
284  {
285  qs = qpls;
286  }
287  else
288  {
289  qs = 0.5*(qmns+qpls);
290  }
291  }
292 
293  return qs;
294 }
295 
296 
297 
299 amrex::Real hydro_mol_zedge_state ( int i, int j, int k, int n,
302  amrex::BCRec const* const d_bcrec,
303  int domlo, int domhi, bool is_velocity) noexcept
304 {
305  //slope order
306  int order = 2;
307 
308  amrex::Real qs;
309  amrex::Real qpls = q(i,j,k ,n) - 0.5 * amrex_calc_zslope( i, j, k , n, order, q );
310  amrex::Real qmns = q(i,j,k-1,n) + 0.5 * amrex_calc_zslope( i, j, k-1, n, order, q );
311 
312  HydroBC::SetZEdgeBCs(i,j,k,n,q,qmns,qpls,d_bcrec[n].lo(2),domlo,d_bcrec[n].hi(2),domhi,is_velocity);
313 
314  if ( (k==domlo) && (d_bcrec[n].lo(2) == amrex::BCType::foextrap || d_bcrec[n].lo(2) == amrex::BCType::hoextrap) )
315  {
316  if ( wmac(i,j,k) >= 0. && n==ZVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt);
317  qmns = qpls;
318  }
319  if ( (k==domhi+1) && (d_bcrec[n].hi(2) == amrex::BCType::foextrap || d_bcrec[n].hi(2) == amrex::BCType::hoextrap) )
320  {
321  if ( wmac(i,j,k) <= 0. && n==ZVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt);
322  qpls = qmns;
323  }
324 
325  if ( wmac(i,j,k) > small_vel)
326  {
327  qs = qmns;
328  }
329  else if ( wmac(i,j,k) < -small_vel)
330  {
331  qs = qpls;
332  }
333  else
334  {
335  qs = 0.5*(qmns+qpls);
336  }
337 
338  return qs;
339 
340 }
341 
342 #endif
343 
344 
345 }
346 
347 #endif
348 /** @}*/
#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 SetXEdgeBCs(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, int bchi, int domhi, bool is_velocity)
Boundary condition effects.
Definition: hydro_bcs_K.H:45
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void SetYEdgeBCs(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, int bchi, int domhi, bool is_velocity)
Boundary condition effects.
Definition: hydro_bcs_K.H:112
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:79
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:123
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:188
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