Block-Structured AMR Software Framework
AMReX_MLPoisson_3D_K.H
Go to the documentation of this file.
1 #ifndef AMREX_MLPOISSON_3D_K_H_
2 #define AMREX_MLPOISSON_3D_K_H_
3 #include <AMReX_Config.H>
4 
5 namespace amrex {
6 
7 template <typename T>
9 void mlpoisson_adotx (int i, int j, int k, Array4<T> const& y,
10  Array4<T const> const& x,
11  T dhx, T dhy, T dhz) noexcept
12 {
13  y(i,j,k) = dhx * (x(i-1,j,k) - T(2.0)*x(i,j,k) + x(i+1,j,k))
14  + dhy * (x(i,j-1,k) - T(2.0)*x(i,j,k) + x(i,j+1,k))
15  + dhz * (x(i,j,k-1) - T(2.0)*x(i,j,k) + x(i,j,k+1));
16 }
17 
18 template <typename T>
20 void mlpoisson_adotx_os (int i, int j, int k, Array4<T> const& y,
21  Array4<T const> const& x,
22  Array4<int const> const& osm,
23  T dhx, T dhy, T dhz) noexcept
24 {
25  if (osm(i,j,k) == 0) {
26  y(i,j,k) = T(0.0);
27  } else {
28  y(i,j,k) = dhx * (x(i-1,j,k) - T(2.0)*x(i,j,k) + x(i+1,j,k))
29  + dhy * (x(i,j-1,k) - T(2.0)*x(i,j,k) + x(i,j+1,k))
30  + dhz * (x(i,j,k-1) - T(2.0)*x(i,j,k) + x(i,j,k+1));
31  }
32 }
33 
34 template <typename T>
36 void mlpoisson_flux_x (Box const& box, Array4<T> const& fx,
37  Array4<T const> const& sol, T dxinv) noexcept
38 {
39  const auto lo = amrex::lbound(box);
40  const auto hi = amrex::ubound(box);
41 
42  for (int k = lo.z; k <= hi.z; ++k) {
43  for (int j = lo.y; j <= hi.y; ++j) {
45  for (int i = lo.x; i <= hi.x; ++i) {
46  fx(i,j,k) = dxinv*(sol(i,j,k)-sol(i-1,j,k));
47  }
48  }
49  }
50 }
51 
52 template <typename T>
54 void mlpoisson_flux_xface (Box const& box, Array4<T> const& fx,
55  Array4<T const> const& sol, T dxinv, int xlen) noexcept
56 {
57  const auto lo = amrex::lbound(box);
58  const auto hi = amrex::ubound(box);
59 
60  for (int k = lo.z; k <= hi.z; ++k) {
61  for (int j = lo.y; j <= hi.y; ++j) {
62  int i = lo.x;
63  fx(i,j,k) = dxinv*(sol(i,j,k)-sol(i-1,j,k));
64  i += xlen;
65  fx(i,j,k) = dxinv*(sol(i,j,k)-sol(i-1,j,k));
66  }
67  }
68 }
69 
70 template <typename T>
72 void mlpoisson_flux_y (Box const& box, Array4<T> const& fy,
73  Array4<T const> const& sol, T dyinv) noexcept
74 {
75  const auto lo = amrex::lbound(box);
76  const auto hi = amrex::ubound(box);
77 
78  for (int k = lo.z; k <= hi.z; ++k) {
79  for (int j = lo.y; j <= hi.y; ++j) {
81  for (int i = lo.x; i <= hi.x; ++i) {
82  fy(i,j,k) = dyinv*(sol(i,j,k)-sol(i,j-1,k));
83  }
84  }
85  }
86 }
87 
88 template <typename T>
90 void mlpoisson_flux_yface (Box const& box, Array4<T> const& fy,
91  Array4<T const> const& sol, T dyinv, int ylen) noexcept
92 {
93  const auto lo = amrex::lbound(box);
94  const auto hi = amrex::ubound(box);
95 
96  for (int k = lo.z; k <= hi.z; ++k) {
97  int j = lo.y;
99  for (int i = lo.x; i <= hi.x; ++i) {
100  fy(i,j,k) = dyinv*(sol(i,j,k)-sol(i,j-1,k));
101  }
102  j += ylen;
104  for (int i = lo.x; i <= hi.x; ++i) {
105  fy(i,j,k) = dyinv*(sol(i,j,k)-sol(i,j-1,k));
106  }
107  }
108 }
109 
110 template <typename T>
112 void mlpoisson_flux_z (Box const& box, Array4<T> const& fz,
113  Array4<T const> const& sol, T dzinv) noexcept
114 {
115  const auto lo = amrex::lbound(box);
116  const auto hi = amrex::ubound(box);
117 
118  for (int k = lo.z; k <= hi.z; ++k) {
119  for (int j = lo.y; j <= hi.y; ++j) {
121  for (int i = lo.x; i <= hi.x; ++i) {
122  fz(i,j,k) = dzinv*(sol(i,j,k)-sol(i,j,k-1));
123  }
124  }
125  }
126 }
127 
128 template <typename T>
130 void mlpoisson_flux_zface (Box const& box, Array4<T> const& fz,
131  Array4<T const> const& sol, T dzinv, int zlen) noexcept
132 {
133  const auto lo = amrex::lbound(box);
134  const auto hi = amrex::ubound(box);
135 
136  int k = lo.z;
137  for (int j = lo.y; j <= hi.y; ++j) {
139  for (int i = lo.x; i <= hi.x; ++i) {
140  fz(i,j,k) = dzinv*(sol(i,j,k)-sol(i,j,k-1));
141  }
142  }
143 
144  k += zlen;
145  for (int j = lo.y; j <= hi.y; ++j) {
147  for (int i = lo.x; i <= hi.x; ++i) {
148  fz(i,j,k) = dzinv*(sol(i,j,k)-sol(i,j,k-1));
149  }
150  }
151 }
152 
153 template <typename T>
155 void mlpoisson_gsrb (int i, int j, int k, Array4<T> const& phi,
156  Array4<T const> const& rhs,
157  T dhx, T dhy, T dhz,
158  Array4<T const> const& f0, Array4<int const> const& m0,
159  Array4<T const> const& f1, Array4<int const> const& m1,
160  Array4<T const> const& f2, Array4<int const> const& m2,
161  Array4<T const> const& f3, Array4<int const> const& m3,
162  Array4<T const> const& f4, Array4<int const> const& m4,
163  Array4<T const> const& f5, Array4<int const> const& m5,
164  Box const& vbox, int redblack) noexcept
165 {
166  const auto vlo = amrex::lbound(vbox);
167  const auto vhi = amrex::ubound(vbox);
168 
169  constexpr T omega = T(1.15);
170 
171  const T gamma = T(-2.)*(dhx+dhy+dhz);
172 
173  if ((i+j+k+redblack)%2 == 0) {
174  T cf0 = (i == vlo.x && m0(vlo.x-1,j,k) > 0)
175  ? f0(vlo.x,j,k) : T(0.0);
176  T cf1 = (j == vlo.y && m1(i,vlo.y-1,k) > 0)
177  ? f1(i,vlo.y,k) : T(0.0);
178  T cf2 = (k == vlo.z && m2(i,j,vlo.z-1) > 0)
179  ? f2(i,j,vlo.z) : T(0.0);
180  T cf3 = (i == vhi.x && m3(vhi.x+1,j,k) > 0)
181  ? f3(vhi.x,j,k) : T(0.0);
182  T cf4 = (j == vhi.y && m4(i,vhi.y+1,k) > 0)
183  ? f4(i,vhi.y,k) : T(0.0);
184  T cf5 = (k == vhi.z && m5(i,j,vhi.z+1) > 0)
185  ? f5(i,j,vhi.z) : T(0.0);
186 
187  T g_m_d = gamma + dhx*(cf0+cf3) + dhy*(cf1+cf4) + dhz*(cf2+cf5);
188 
189  T res = rhs(i,j,k) - gamma*phi(i,j,k)
190  - dhx*(phi(i-1,j,k) + phi(i+1,j,k))
191  - dhy*(phi(i,j-1,k) + phi(i,j+1,k))
192  - dhz*(phi(i,j,k-1) + phi(i,j,k+1));
193 
194  phi(i,j,k) = phi(i,j,k) + omega/g_m_d * res;
195  }
196 }
197 
198 template <typename T>
200 void mlpoisson_gsrb_os (int i, int j, int k, Array4<T> const& phi,
201  Array4<T const> const& rhs,
202  Array4<int const> const& osm,
203  T dhx, T dhy, T dhz,
204  Array4<T const> const& f0, Array4<int const> const& m0,
205  Array4<T const> const& f1, Array4<int const> const& m1,
206  Array4<T const> const& f2, Array4<int const> const& m2,
207  Array4<T const> const& f3, Array4<int const> const& m3,
208  Array4<T const> const& f4, Array4<int const> const& m4,
209  Array4<T const> const& f5, Array4<int const> const& m5,
210  Box const& vbox, int redblack) noexcept
211 {
212  const auto vlo = amrex::lbound(vbox);
213  const auto vhi = amrex::ubound(vbox);
214 
215  constexpr T omega = T(1.15);
216 
217  const T gamma = T(-2.)*(dhx+dhy+dhz);
218 
219  if ((i+j+k+redblack)%2 == 0) {
220  if (osm(i,j,k) == 0) {
221  phi(i,j,k) = T(0.0);
222  } else {
223  T cf0 = (i == vlo.x && m0(vlo.x-1,j,k) > 0)
224  ? f0(vlo.x,j,k) : T(0.0);
225  T cf1 = (j == vlo.y && m1(i,vlo.y-1,k) > 0)
226  ? f1(i,vlo.y,k) : T(0.0);
227  T cf2 = (k == vlo.z && m2(i,j,vlo.z-1) > 0)
228  ? f2(i,j,vlo.z) : T(0.0);
229  T cf3 = (i == vhi.x && m3(vhi.x+1,j,k) > 0)
230  ? f3(vhi.x,j,k) : T(0.0);
231  T cf4 = (j == vhi.y && m4(i,vhi.y+1,k) > 0)
232  ? f4(i,vhi.y,k) : T(0.0);
233  T cf5 = (k == vhi.z && m5(i,j,vhi.z+1) > 0)
234  ? f5(i,j,vhi.z) : T(0.0);
235 
236  T g_m_d = gamma + dhx*(cf0+cf3) + dhy*(cf1+cf4) + dhz*(cf2+cf5);
237 
238  T res = rhs(i,j,k) - gamma*phi(i,j,k)
239  - dhx*(phi(i-1,j,k) + phi(i+1,j,k))
240  - dhy*(phi(i,j-1,k) + phi(i,j+1,k))
241  - dhz*(phi(i,j,k-1) + phi(i,j,k+1));
242 
243  phi(i,j,k) = phi(i,j,k) + omega/g_m_d * res;
244  }
245  }
246 }
247 
248 template <typename T>
250 void mlpoisson_jacobi (int i, int j, int k, Array4<T> const& phi,
251  Array4<T const> const& rhs, Array4<T const> const& Ax,
252  T dhx, T dhy, T dhz,
253  Array4<T const> const& f0, Array4<int const> const& m0,
254  Array4<T const> const& f1, Array4<int const> const& m1,
255  Array4<T const> const& f2, Array4<int const> const& m2,
256  Array4<T const> const& f3, Array4<int const> const& m3,
257  Array4<T const> const& f4, Array4<int const> const& m4,
258  Array4<T const> const& f5, Array4<int const> const& m5,
259  Box const& vbox) noexcept
260 {
261  const auto vlo = amrex::lbound(vbox);
262  const auto vhi = amrex::ubound(vbox);
263 
264  const T gamma = T(-2.)*(dhx+dhy+dhz);
265 
266  T cf0 = (i == vlo.x && m0(vlo.x-1,j,k) > 0)
267  ? f0(vlo.x,j,k) : T(0.0);
268  T cf1 = (j == vlo.y && m1(i,vlo.y-1,k) > 0)
269  ? f1(i,vlo.y,k) : T(0.0);
270  T cf2 = (k == vlo.z && m2(i,j,vlo.z-1) > 0)
271  ? f2(i,j,vlo.z) : T(0.0);
272  T cf3 = (i == vhi.x && m3(vhi.x+1,j,k) > 0)
273  ? f3(vhi.x,j,k) : T(0.0);
274  T cf4 = (j == vhi.y && m4(i,vhi.y+1,k) > 0)
275  ? f4(i,vhi.y,k) : T(0.0);
276  T cf5 = (k == vhi.z && m5(i,j,vhi.z+1) > 0)
277  ? f5(i,j,vhi.z) : T(0.0);
278 
279  T g_m_d = gamma + dhx*(cf0+cf3) + dhy*(cf1+cf4) + dhz*(cf2+cf5);
280 
281  phi(i,j,k) += T(2.0/3.0) * (rhs(i,j,k) - Ax(i,j,k)) / g_m_d;
282 }
283 
284 template <typename T>
286 void mlpoisson_jacobi_os (int i, int j, int k, Array4<T> const& phi,
287  Array4<T const> const& rhs,
288  Array4<T const> const& Ax,
289  Array4<int const> const& osm,
290  T dhx, T dhy, T dhz,
291  Array4<T const> const& f0, Array4<int const> const& m0,
292  Array4<T const> const& f1, Array4<int const> const& m1,
293  Array4<T const> const& f2, Array4<int const> const& m2,
294  Array4<T const> const& f3, Array4<int const> const& m3,
295  Array4<T const> const& f4, Array4<int const> const& m4,
296  Array4<T const> const& f5, Array4<int const> const& m5,
297  Box const& vbox) noexcept
298 {
299  const auto vlo = amrex::lbound(vbox);
300  const auto vhi = amrex::ubound(vbox);
301 
302  const T gamma = T(-2.)*(dhx+dhy+dhz);
303 
304  if (osm(i,j,k) == 0) {
305  phi(i,j,k) = T(0.0);
306  } else {
307  T cf0 = (i == vlo.x && m0(vlo.x-1,j,k) > 0)
308  ? f0(vlo.x,j,k) : T(0.0);
309  T cf1 = (j == vlo.y && m1(i,vlo.y-1,k) > 0)
310  ? f1(i,vlo.y,k) : T(0.0);
311  T cf2 = (k == vlo.z && m2(i,j,vlo.z-1) > 0)
312  ? f2(i,j,vlo.z) : T(0.0);
313  T cf3 = (i == vhi.x && m3(vhi.x+1,j,k) > 0)
314  ? f3(vhi.x,j,k) : T(0.0);
315  T cf4 = (j == vhi.y && m4(i,vhi.y+1,k) > 0)
316  ? f4(i,vhi.y,k) : T(0.0);
317  T cf5 = (k == vhi.z && m5(i,j,vhi.z+1) > 0)
318  ? f5(i,j,vhi.z) : T(0.0);
319 
320  T g_m_d = gamma + dhx*(cf0+cf3) + dhy*(cf1+cf4) + dhz*(cf2+cf5);
321 
322  phi(i,j,k) += T(2.0/3.0) * (rhs(i,j,k) - Ax(i,j,k)) / g_m_d;
323  }
324 }
325 
326 }
327 
328 #endif
#define AMREX_PRAGMA_SIMD
Definition: AMReX_Extension.H:80
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlpoisson_flux_yface(Box const &box, Array4< T > const &fy, Array4< T const > const &sol, T dyinv, int ylen) noexcept
Definition: AMReX_MLPoisson_3D_K.H:90
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlpoisson_jacobi(int i, int, int, Array4< T > const &phi, Array4< T const > const &rhs, Array4< T const > const &Ax, T dhx, Array4< T const > const &f0, Array4< int const > const &m0, Array4< T const > const &f1, Array4< int const > const &m1, Box const &vbox) noexcept
Definition: AMReX_MLPoisson_1D_K.H:193
BoxND< AMREX_SPACEDIM > Box
Definition: AMReX_BaseFwd.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlpoisson_flux_x(Box const &box, Array4< T > const &fx, Array4< T const > const &sol, T dxinv) noexcept
Definition: AMReX_MLPoisson_1D_K.H:43
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlpoisson_adotx(int i, Array4< T > const &y, Array4< T const > const &x, T dhx) noexcept
Definition: AMReX_MLPoisson_1D_K.H:9
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlpoisson_flux_y(Box const &box, Array4< T > const &fy, Array4< T const > const &sol, T dyinv) noexcept
Definition: AMReX_MLPoisson_3D_K.H:72
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlpoisson_jacobi_os(int i, int, int, Array4< T > const &phi, Array4< T const > const &rhs, Array4< T const > const &Ax, Array4< int const > const &osm, T dhx, Array4< T const > const &f0, Array4< int const > const &m0, Array4< T const > const &f1, Array4< int const > const &m1, Box const &vbox) noexcept
Definition: AMReX_MLPoisson_1D_K.H:216
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlpoisson_gsrb(int i, int, int, Array4< T > const &phi, Array4< T const > const &rhs, T dhx, Array4< T const > const &f0, Array4< int const > const &m0, Array4< T const > const &f1, Array4< int const > const &m1, Box const &vbox, int redblack) noexcept
Definition: AMReX_MLPoisson_1D_K.H:102
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 ubound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:315
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 lbound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:308
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlpoisson_flux_xface(Box const &box, Array4< T > const &fx, Array4< T const > const &sol, T dxinv, int xlen) noexcept
Definition: AMReX_MLPoisson_1D_K.H:73
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlpoisson_gsrb_os(int i, int, int, Array4< T > const &phi, Array4< T const > const &rhs, Array4< int const > const &osm, T dhx, Array4< T const > const &f0, Array4< int const > const &m0, Array4< T const > const &f1, Array4< int const > const &m1, Box const &vbox, int redblack) noexcept
Definition: AMReX_MLPoisson_1D_K.H:130
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlpoisson_flux_zface(Box const &box, Array4< T > const &fz, Array4< T const > const &sol, T dzinv, int zlen) noexcept
Definition: AMReX_MLPoisson_3D_K.H:130
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlpoisson_adotx_os(int i, Array4< T > const &y, Array4< T const > const &x, Array4< int const > const &osm, T dhx) noexcept
Definition: AMReX_MLPoisson_1D_K.H:18
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlpoisson_flux_z(Box const &box, Array4< T > const &fz, Array4< T const > const &sol, T dzinv) noexcept
Definition: AMReX_MLPoisson_3D_K.H:112
Definition: AMReX_Array4.H:61