Block-Structured AMR Software Framework
AMReX_MFInterp_C.H
Go to the documentation of this file.
1 #ifndef AMREX_MF_INTERP_C_H_
2 #define AMREX_MF_INTERP_C_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_Array4.H>
6 #include <AMReX_BCRec.H>
7 
8 namespace amrex {
9 
11 Real mf_compute_slopes_x (int i, int j, int k, Array4<Real const> const& u, int nu,
12  Box const& domain, BCRec const& bc)
13 {
14  Real dc = Real(0.5) * (u(i+1,j,k,nu) - u(i-1,j,k,nu));
15  if (i == domain.smallEnd(0) && (bc.lo(0) == BCType::ext_dir ||
16  bc.lo(0) == BCType::hoextrap)) {
17  if (i+2 < u.end.x) {
18  dc = -Real(16./15.)*u(i-1,j,k,nu) + Real(0.5)*u(i,j,k,nu)
19  + Real(2./3.)*u(i+1,j,k,nu) - Real(0.1)*u(i+2,j,k,nu);
20  } else {
21  dc = Real(0.25)*(u(i+1,j,k,nu)+Real(5.)*u(i,j,k,nu)-Real(6.)*u(i-1,j,k,nu));
22  }
23  }
24  if (i == domain.bigEnd(0) && (bc.hi(0) == BCType::ext_dir ||
25  bc.hi(0) == BCType::hoextrap)) {
26  if (i-2 >= u.begin.x) {
27  dc = Real(16./15.)*u(i+1,j,k,nu) - Real(0.5)*u(i,j,k,nu)
28  - Real(2./3.)*u(i-1,j,k,nu) + Real(0.1)*u(i-2,j,k,nu);
29  } else {
30  dc = -Real(0.25)*(u(i-1,j,k,nu)+Real(5.)*u(i,j,k,nu)-Real(6.)*u(i+1,j,k,nu));
31  }
32  }
33  return dc;
34 }
35 
37 Real mf_compute_slopes_y (int i, int j, int k, Array4<Real const> const& u, int nu,
38  Box const& domain, BCRec const& bc)
39 {
40  Real dc = Real(0.5) * (u(i,j+1,k,nu) - u(i,j-1,k,nu));
41  if (j == domain.smallEnd(1) && (bc.lo(1) == BCType::ext_dir ||
42  bc.lo(1) == BCType::hoextrap)) {
43  if (j+2 < u.end.y) {
44  dc = -Real(16./15.)*u(i,j-1,k,nu) + Real(0.5)*u(i,j,k,nu)
45  + Real(2./3.)*u(i,j+1,k,nu) - Real(0.1)*u(i,j+2,k,nu);
46  } else {
47  dc = Real(0.25)*(u(i,j+1,k,nu)+Real(5.)*u(i,j,k,nu)-Real(6.)*u(i,j-1,k,nu));
48  }
49  }
50  if (j == domain.bigEnd(1) && (bc.hi(1) == BCType::ext_dir ||
51  bc.hi(1) == BCType::hoextrap)) {
52  if (j-2 >= u.begin.y) {
53  dc = Real(16./15.)*u(i,j+1,k,nu) - Real(0.5)*u(i,j,k,nu)
54  - Real(2./3.)*u(i,j-1,k,nu) + Real(0.1)*u(i,j-2,k,nu);
55  } else {
56  dc = -Real(0.25)*(u(i,j-1,k,nu)+Real(5.)*u(i,j,k,nu)-Real(6.)*u(i,j+1,k,nu));
57  }
58  }
59  return dc;
60 }
61 
63 Real mf_compute_slopes_z (int i, int j, int k, Array4<Real const> const& u, int nu,
64  Box const& domain, BCRec const& bc)
65 {
66  Real dc = Real(0.5) * (u(i,j,k+1,nu) - u(i,j,k-1,nu));
67  if (k == domain.smallEnd(2) && (bc.lo(2) == BCType::ext_dir ||
68  bc.lo(2) == BCType::hoextrap)) {
69  if (k+2 < u.end.z) {
70  dc = -Real(16./15.)*u(i,j,k-1,nu) + Real(0.5)*u(i,j,k,nu)
71  + Real(2./3.)*u(i,j,k+1,nu) - Real(0.1)*u(i,j,k+2,nu);
72  } else {
73  dc = Real(0.25)*(u(i,j,k+1,nu)+Real(5.)*u(i,j,k,nu)-Real(6.)*u(i,j,k-1,nu));
74  }
75  }
76  if (k == domain.bigEnd(2) && (bc.hi(2) == BCType::ext_dir ||
77  bc.hi(2) == BCType::hoextrap)) {
78  if (k-2 >= u.begin.z) {
79  dc = Real(16./15.)*u(i,j,k+1,nu) - Real(0.5)*u(i,j,k,nu)
80  - Real(2./3.)*u(i,j,k-1,nu) + Real(0.1)*u(i,j,k-2,nu);
81  } else {
82  dc = -Real(0.25)*(u(i,j,k-1,nu)+Real(5.)*u(i,j,k,nu)-Real(6.)*u(i,j,k+1,nu));
83  }
84  }
85  return dc;
86 }
87 
89 Real mf_cell_quadratic_compute_slopes_xx (int i, int j, int k,
90  Array4<Real const> const& u, int nu,
91  Box const& domain, BCRec const& bc)
92 {
93  Real xx = u(i-1,j,k,nu) - 2.0_rt * u(i,j,k,nu) + u(i+1,j,k,nu);
94  if (i == domain.smallEnd(0) && (bc.lo(0) == BCType::ext_dir ||
95  bc.lo(0) == BCType::hoextrap)) {
96  if (i+2 < u.end.x) {
97  xx = 0._rt;
98  }
99  }
100  if (i == domain.bigEnd(0) && (bc.hi(0) == BCType::ext_dir ||
101  bc.hi(0) == BCType::hoextrap)) {
102  if (i-2 >= u.begin.x) {
103  xx = 0._rt;
104  }
105  }
106  return xx;
107 }
108 
110 Real mf_cell_quadratic_compute_slopes_yy (int i, int j, int k,
111  Array4<Real const> const& u, int nu,
112  Box const& domain, BCRec const& bc)
113 {
114  Real yy = u(i,j-1,k,nu) - 2.0_rt * u(i,j,k,nu) + u(i,j+1,k,nu);
115  if (j == domain.smallEnd(1) && (bc.lo(1) == BCType::ext_dir ||
116  bc.lo(1) == BCType::hoextrap)) {
117  if (j+2 < u.end.y) {
118  yy = 0._rt;
119  }
120  }
121  if (j == domain.bigEnd(1) && (bc.hi(1) == BCType::ext_dir ||
122  bc.hi(1) == BCType::hoextrap)) {
123  if (j-2 >= u.begin.y) {
124  yy = 0._rt;
125  }
126  }
127  return yy;
128 }
129 
131 Real mf_cell_quadratic_compute_slopes_zz (int i, int j, int k,
132  Array4<Real const> const& u, int nu,
133  Box const& domain, BCRec const& bc)
134 {
135  Real zz = u(i,j,k-1,nu) - 2.0_rt * u(i,j,k,nu) + u(i,j,k+1,nu);
136  if (k == domain.smallEnd(2) && (bc.lo(2) == BCType::ext_dir ||
137  bc.lo(2) == BCType::hoextrap)) {
138  if (k+2 < u.end.z) {
139  zz = 0._rt;
140  }
141  }
142  if (k == domain.bigEnd(1) && (bc.hi(2) == BCType::ext_dir ||
143  bc.hi(2) == BCType::hoextrap)) {
144  if (k-2 >= u.begin.z) {
145  zz = 0._rt;
146  }
147  }
148  return zz;
149 }
150 
152 Real mf_cell_quadratic_compute_slopes_xy (int i, int j, int k,
153  Array4<Real const> const& u, int nu,
154  Box const& domain, BCRec const& bc)
155 {
156  Real xy = (1._rt/4._rt) * ( u(i-1,j-1,k,nu) - u(i+1,j-1,k,nu)
157  - u(i-1,j+1,k,nu) + u(i+1,j+1,k,nu) );
158  if (i == domain.smallEnd(0) && (bc.lo(0) == BCType::ext_dir ||
159  bc.lo(0) == BCType::hoextrap)) {
160  if (i+2 < u.end.x) {
161  xy = 0._rt;
162  }
163  }
164  if (i == domain.bigEnd(0) && (bc.hi(0) == BCType::ext_dir ||
165  bc.hi(0) == BCType::hoextrap)) {
166  if (i-2 >= u.begin.x) {
167  xy = 0._rt;
168  }
169  }
170  if (j == domain.smallEnd(1) && (bc.lo(1) == BCType::ext_dir ||
171  bc.lo(1) == BCType::hoextrap)) {
172  if (j+2 < u.end.y) {
173  xy = 0._rt;
174  }
175  }
176  if (j == domain.bigEnd(1) && (bc.hi(1) == BCType::ext_dir ||
177  bc.hi(1) == BCType::hoextrap)) {
178  if (j-2 >= u.begin.y) {
179  xy = 0._rt;
180  }
181  }
182  return xy;
183 }
184 
186 Real mf_cell_quadratic_compute_slopes_xz (int i, int j, int k,
187  Array4<Real const> const& u, int nu,
188  Box const& domain, BCRec const& bc)
189 {
190  Real xz = (1._rt/4._rt) * ( u(i-1,j,k-1,nu) - u(i+1,j,k-1,nu)
191  - u(i-1,j,k+1,nu) + u(i+1,j,k+1,nu) );
192  if (i == domain.smallEnd(0) && (bc.lo(0) == BCType::ext_dir ||
193  bc.lo(0) == BCType::hoextrap)) {
194  if (i+2 < u.end.x) {
195  xz = 0._rt;
196  }
197  }
198  if (i == domain.bigEnd(0) && (bc.hi(0) == BCType::ext_dir ||
199  bc.hi(0) == BCType::hoextrap)) {
200  if (i-2 >= u.begin.x) {
201  xz = 0._rt;
202  }
203  }
204  if (k == domain.smallEnd(2) && (bc.lo(2) == BCType::ext_dir ||
205  bc.lo(2) == BCType::hoextrap)) {
206  if (k+2 < u.end.z) {
207  xz = 0._rt;
208  }
209  }
210  if (k == domain.bigEnd(1) && (bc.hi(2) == BCType::ext_dir ||
211  bc.hi(2) == BCType::hoextrap)) {
212  if (k-2 >= u.begin.z) {
213  xz = 0._rt;
214  }
215  }
216  return xz;
217 }
218 
220 Real mf_cell_quadratic_compute_slopes_yz (int i, int j, int k,
221  Array4<Real const> const& u, int nu,
222  Box const& domain, BCRec const& bc)
223 {
224  Real yz = (1._rt/4._rt) * ( u(i,j-1,k-1,nu) - u(i,j-1,k+1,nu)
225  - u(i,j+1,k-1,nu) + u(i,j+1,k+1,nu) );
226  if (j == domain.smallEnd(1) && (bc.lo(1) == BCType::ext_dir ||
227  bc.lo(1) == BCType::hoextrap)) {
228  if (j+2 < u.end.y) {
229  yz = 0._rt;
230  }
231  }
232  if (j == domain.bigEnd(1) && (bc.hi(1) == BCType::ext_dir ||
233  bc.hi(1) == BCType::hoextrap)) {
234  if (j-2 >= u.begin.y) {
235  yz = 0._rt;
236  }
237  }
238  if (k == domain.smallEnd(2) && (bc.lo(2) == BCType::ext_dir ||
239  bc.lo(2) == BCType::hoextrap)) {
240  if (k+2 < u.end.z) {
241  yz = 0._rt;
242  }
243  }
244  if (k == domain.bigEnd(1) && (bc.hi(2) == BCType::ext_dir ||
245  bc.hi(2) == BCType::hoextrap)) {
246  if (k-2 >= u.begin.z) {
247  yz = 0._rt;
248  }
249  }
250  return yz;
251 }
252 
253 } // namespace amrex
254 
255 #if (AMREX_SPACEDIM == 1)
256 #include <AMReX_MFInterp_1D_C.H>
257 #elif (AMREX_SPACEDIM == 2)
258 #include <AMReX_MFInterp_2D_C.H>
259 #else
260 #include <AMReX_MFInterp_3D_C.H>
261 #endif
262 
263 #endif
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
Boundary Condition Records. Necessary information and functions for computing boundary conditions.
Definition: AMReX_BCRec.H:17
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const int * hi() const &noexcept
Return high-end boundary data.
Definition: AMReX_BCRec.H:106
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const int * lo() const &noexcept
Return low-end boundary data.
Definition: AMReX_BCRec.H:100
AMREX_GPU_HOST_DEVICE const IntVectND< dim > & smallEnd() const &noexcept
Get the smallend of the BoxND.
Definition: AMReX_Box.H:105
AMREX_GPU_HOST_DEVICE const IntVectND< dim > & bigEnd() const &noexcept
Get the bigend.
Definition: AMReX_Box.H:116
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mf_compute_slopes_y(int i, int j, int k, Array4< Real const > const &u, int nu, Box const &domain, BCRec const &bc)
Definition: AMReX_MFInterp_C.H:37
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mf_cell_quadratic_compute_slopes_yy(int i, int j, int k, Array4< Real const > const &u, int nu, Box const &domain, BCRec const &bc)
Definition: AMReX_MFInterp_C.H:110
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mf_cell_quadratic_compute_slopes_xy(int i, int j, int k, Array4< Real const > const &u, int nu, Box const &domain, BCRec const &bc)
Definition: AMReX_MFInterp_C.H:152
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mf_cell_quadratic_compute_slopes_yz(int i, int j, int k, Array4< Real const > const &u, int nu, Box const &domain, BCRec const &bc)
Definition: AMReX_MFInterp_C.H:220
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mf_cell_quadratic_compute_slopes_zz(int i, int j, int k, Array4< Real const > const &u, int nu, Box const &domain, BCRec const &bc)
Definition: AMReX_MFInterp_C.H:131
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mf_cell_quadratic_compute_slopes_xx(int i, int j, int k, Array4< Real const > const &u, int nu, Box const &domain, BCRec const &bc)
Definition: AMReX_MFInterp_C.H:89
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mf_cell_quadratic_compute_slopes_xz(int i, int j, int k, Array4< Real const > const &u, int nu, Box const &domain, BCRec const &bc)
Definition: AMReX_MFInterp_C.H:186
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mf_compute_slopes_x(int i, int j, int k, Array4< Real const > const &u, int nu, Box const &domain, BCRec const &bc)
Definition: AMReX_MFInterp_C.H:11
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mf_compute_slopes_z(int i, int j, int k, Array4< Real const > const &u, int nu, Box const &domain, BCRec const &bc)
Definition: AMReX_MFInterp_C.H:63
Definition: AMReX_Array4.H:61
Dim3 begin
Definition: AMReX_Array4.H:66
Dim3 end
Definition: AMReX_Array4.H:67
int x
Definition: AMReX_Dim3.H:12
int z
Definition: AMReX_Dim3.H:12
int y
Definition: AMReX_Dim3.H:12