1 #ifndef AMREX_MLABECLAP_2D_K_H_
2 #define AMREX_MLABECLAP_2D_K_H_
3 #include <AMReX_Config.H>
15 T alpha, T beta) noexcept
17 const T dhx = beta*dxinv[0]*dxinv[0];
18 const T dhy = beta*dxinv[1]*dxinv[1];
19 y(i,j,0,n) = alpha*a(i,j,0)*
x(i,j,0,n)
20 - dhx * (bX(i+1,j,0,n)*(
x(i+1,j,0,n) -
x(i ,j,0,n))
21 - bX(i ,j,0,n)*(
x(i ,j,0,n) -
x(i-1,j,0,n)))
22 - dhy * (bY(i,j+1,0,n)*(
x(i,j+1,0,n) -
x(i,j ,0,n))
23 - bY(i,j ,0,n)*(
x(i,j ,0,n) -
x(i,j-1,0,n)));
35 T alpha, T beta) noexcept
37 const T dhx = beta*dxinv[0]*dxinv[0];
38 const T dhy = beta*dxinv[1]*dxinv[1];
39 if (osm(i,j,0) == 0) {
42 y(i,j,0,n) = alpha*a(i,j,0)*
x(i,j,0,n)
43 - dhx * (bX(i+1,j,0,n)*(
x(i+1,j,0,n) -
x(i ,j,0,n))
44 - bX(i ,j,0,n)*(
x(i ,j,0,n) -
x(i-1,j,0,n)))
45 - dhy * (bY(i,j+1,0,n)*(
x(i,j+1,0,n) -
x(i,j ,0,n))
46 - bY(i,j ,0,n)*(
x(i,j ,0,n) -
x(i,j-1,0,n)));
57 T alpha, T beta) noexcept
59 const T dhx = beta*dxinv[0]*dxinv[0];
60 const T dhy = beta*dxinv[1]*dxinv[1];
61 x(i,j,0,n) /= alpha*a(i,j,0)
62 + dhx*(bX(i,j,0,n)+bX(i+1,j,0,n))
63 + dhy*(bY(i,j,0,n)+bY(i,j+1,0,n));
69 Array4<T const>
const& bx, T fac,
int ncomp) noexcept
74 for (
int n = 0; n < ncomp; ++n) {
75 for (
int j = lo.y; j <= hi.y; ++j) {
77 for (
int i = lo.x; i <= hi.x; ++i) {
78 fx(i,j,0,n) = -fac*bx(i,j,0,n)*(sol(i,j,0,n)-sol(i-1,j,0,n));
87 Array4<T const>
const& bx, T fac,
int xlen,
int ncomp) noexcept
92 for (
int n = 0; n < ncomp; ++n) {
93 for (
int j = lo.y; j <= hi.y; ++j) {
95 fx(i,j,0,n) = -fac*bx(i,j,0,n)*(sol(i,j,0,n)-sol(i-1,j,0,n));
97 fx(i,j,0,n) = -fac*bx(i,j,0,n)*(sol(i,j,0,n)-sol(i-1,j,0,n));
102 template <
typename T>
110 for (
int n = 0; n < ncomp; ++n) {
111 for (
int j = lo.y; j <= hi.y; ++j) {
113 for (
int i = lo.x; i <= hi.x; ++i) {
114 fy(i,j,0,n) = -fac*by(i,j,0,n)*(sol(i,j,0,n)-sol(i,j-1,0,n));
120 template <
typename T>
128 for (
int n = 0; n < ncomp; ++n) {
131 for (
int i = lo.x; i <= hi.x; ++i) {
132 fy(i,j,0,n) = -fac*by(i,j,0,n)*(sol(i,j,0,n)-sol(i,j-1,0,n));
136 for (
int i = lo.x; i <= hi.x; ++i) {
137 fy(i,j,0,n) = -fac*by(i,j,0,n)*(sol(i,j,0,n)-sol(i,j-1,0,n));
142 template <
typename T>
152 Box const& vbox,
int redblack) noexcept
154 if ((i+j+redblack)%2 == 0) {
158 T cf0 = (i == vlo.x && m0(vlo.x-1,j,0) > 0)
159 ? f0(vlo.x,j,0,n) : T(0.0);
160 T cf1 = (j == vlo.y && m1(i,vlo.y-1,0) > 0)
161 ? f1(i,vlo.y,0,n) : T(0.0);
162 T cf2 = (i == vhi.x && m2(vhi.x+1,j,0) > 0)
163 ? f2(vhi.x,j,0,n) : T(0.0);
164 T cf3 = (j == vhi.y && m3(i,vhi.y+1,0) > 0)
165 ? f3(i,vhi.y,0,n) : T(0.0);
167 T delta = dhx*(bX(i,j,0,n)*cf0 + bX(i+1,j,0,n)*cf2)
168 + dhy*(bY(i,j,0,n)*cf1 + bY(i,j+1,0,n)*cf3);
170 T gamma = alpha*a(i,j,0)
171 + dhx*( bX(i,j,0,n) + bX(i+1,j,0,n) )
172 + dhy*( bY(i,j,0,n) + bY(i,j+1,0,n) );
174 T rho = dhx*(bX(i ,j ,0,n)*phi(i-1,j ,0,n)
175 + bX(i+1,j ,0,n)*phi(i+1,j ,0,n))
176 +dhy*(bY(i ,j ,0,n)*phi(i ,j-1,0,n)
177 + bY(i ,j+1,0,n)*phi(i ,j+1,0,n));
179 phi(i,j,0,n) = (rhs(i,j,0,n) + rho - phi(i,j,0,n)*delta)
184 template <
typename T>
195 Box const& vbox,
int redblack) noexcept
197 if ((i+j+redblack)%2 == 0) {
198 if (osm(i,j,0) == 0) {
199 phi(i,j,0,n) = T(0.0);
204 T cf0 = (i == vlo.x && m0(vlo.x-1,j,0) > 0)
205 ? f0(vlo.x,j,0,n) : T(0.0);
206 T cf1 = (j == vlo.y && m1(i,vlo.y-1,0) > 0)
207 ? f1(i,vlo.y,0,n) : T(0.0);
208 T cf2 = (i == vhi.x && m2(vhi.x+1,j,0) > 0)
209 ? f2(vhi.x,j,0,n) : T(0.0);
210 T cf3 = (j == vhi.y && m3(i,vhi.y+1,0) > 0)
211 ? f3(i,vhi.y,0,n) : T(0.0);
213 T delta = dhx*(bX(i,j,0,n)*cf0 + bX(i+1,j,0,n)*cf2)
214 + dhy*(bY(i,j,0,n)*cf1 + bY(i,j+1,0,n)*cf3);
216 T gamma = alpha*a(i,j,0)
217 + dhx*( bX(i,j,0,n) + bX(i+1,j,0,n) )
218 + dhy*( bY(i,j,0,n) + bY(i,j+1,0,n) );
220 T rho = dhx*(bX(i ,j ,0,n)*phi(i-1,j ,0,n)
221 + bX(i+1,j ,0,n)*phi(i+1,j ,0,n))
222 +dhy*(bY(i ,j ,0,n)*phi(i ,j-1,0,n)
223 + bY(i ,j+1,0,n)*phi(i ,j+1,0,n));
225 phi(i,j,0,n) = (rhs(i,j,0,n) + rho - phi(i,j,0,n)*delta)
231 template <
typename T>
242 Box const& vbox) noexcept
247 T cf0 = (i == vlo.x && m0(vlo.x-1,j,0) > 0)
248 ? f0(vlo.x,j,0,n) : T(0.0);
249 T cf1 = (j == vlo.y && m1(i,vlo.y-1,0) > 0)
250 ? f1(i,vlo.y,0,n) : T(0.0);
251 T cf2 = (i == vhi.x && m2(vhi.x+1,j,0) > 0)
252 ? f2(vhi.x,j,0,n) : T(0.0);
253 T cf3 = (j == vhi.y && m3(i,vhi.y+1,0) > 0)
254 ? f3(i,vhi.y,0,n) : T(0.0);
256 T delta = dhx*(bX(i,j,0,n)*cf0 + bX(i+1,j,0,n)*cf2)
257 + dhy*(bY(i,j,0,n)*cf1 + bY(i,j+1,0,n)*cf3);
259 T gamma = alpha*a(i,j,0)
260 + dhx*( bX(i,j,0,n) + bX(i+1,j,0,n) )
261 + dhy*( bY(i,j,0,n) + bY(i,j+1,0,n) );
263 phi(i,j,0,n) += T(2.0/3.0) * (rhs(i,j,0,n) - Ax(i,j,0,n)) / (gamma - delta);
266 template <
typename T>
278 Box const& vbox) noexcept
280 if (osm(i,j,0) == 0) {
281 phi(i,j,0,n) = T(0.0);
286 T cf0 = (i == vlo.x && m0(vlo.x-1,j,0) > 0)
287 ? f0(vlo.x,j,0,n) : T(0.0);
288 T cf1 = (j == vlo.y && m1(i,vlo.y-1,0) > 0)
289 ? f1(i,vlo.y,0,n) : T(0.0);
290 T cf2 = (i == vhi.x && m2(vhi.x+1,j,0) > 0)
291 ? f2(vhi.x,j,0,n) : T(0.0);
292 T cf3 = (j == vhi.y && m3(i,vhi.y+1,0) > 0)
293 ? f3(i,vhi.y,0,n) : T(0.0);
295 T delta = dhx*(bX(i,j,0,n)*cf0 + bX(i+1,j,0,n)*cf2)
296 + dhy*(bY(i,j,0,n)*cf1 + bY(i,j+1,0,n)*cf3);
298 T gamma = alpha*a(i,j,0)
299 + dhx*( bX(i,j,0,n) + bX(i+1,j,0,n) )
300 + dhy*( bY(i,j,0,n) + bY(i,j+1,0,n) );
302 phi(i,j,0,n) += T(2.0/3.0) * (rhs(i,j,0,n) - Ax(i,j,0,n)) / (gamma - delta);
306 template <
typename T>
317 Box const& vbox,
int redblack,
int nc) noexcept
331 if (dhy <= dhx) {
amrex::Abort(
"dhy is supposed to be much larger than dhx"); }
333 int ilen = hi.y - lo.y + 1;
336 if (ilen > 32) {
amrex::Abort(
"abec_gsrb_with_line_solve is hard-wired to be no longer than 32"); }
345 for (
int n = 0; n < nc; ++n) {
347 for (
int i = lo.x; i <= hi.x; ++i) {
348 if ((i+redblack)%2 == 0) {
349 for (
int j = lo.y; j <= hi.y; ++j) {
350 T gamma = alpha*a(i,j,0)
351 + dhx*(bX(i,j,0,n)+bX(i+1,j,0,n))
352 + dhy*(bY(i,j,0,n)+bY(i,j+1,0,n));
354 T cf0 = (i == vlo.x && m0(vlo.x-1,j,0) > 0)
355 ? f0(vlo.x,j,0,n) : T(0.0);
356 T cf1 = (j == vlo.y && m1(i,vlo.y-1,0) > 0)
357 ? f1(i,vlo.y,0,n) : T(0.0);
358 T cf2 = (i == vhi.x && m2(vhi.x+1,j,0) > 0)
359 ? f2(vhi.x,j,0,n) : T(0.0);
360 T cf3 = (j == vhi.y && m3(i,vhi.y+1,0) > 0)
361 ? f3(i,vhi.y,0,n) : T(0.0);
364 - (dhx*(bX(i,j,0,n)*cf0 + bX(i+1,j,0,n)*cf2)
365 + dhy*(bY(i,j,0,n)*cf1 + bY(i,j+1,0,n)*cf3));
367 T rho = dhx*( bX(i ,j,0,n)*phi(i-1,j,0,n)
368 + bX(i+1,j,0,n)*phi(i+1,j,0,n) );
371 if (i == vlo.x && m0(vlo.x-1,j,0) > 0) {
372 rho -= dhx*bX(i ,j,0,n)*phi(i-1,j,0,n);
374 if (i == vhi.x && m3(vhi.x+1,j,0) > 0) {
375 rho -= dhx*bX(i+1,j,0,n)*phi(i+1,j,0,n);
378 a_ls(j-lo.y) = -dhy*bY(i,j,0,n);
379 b_ls(j-lo.y) = g_m_d;
380 c_ls(j-lo.y) = -dhy*bY(i,j+1,0,n);
381 u_ls(j-lo.y) = T(0.);
382 r_ls(j-lo.y) = rhs(i,j,0,n) + rho;
385 a_ls(j-lo.y) = T(0.);
386 if (!(m1(i,vlo.y-1,0) > 0)) { r_ls(j-lo.y) += dhy*bY(i,j,0,n)*phi(i,j-1,0,n); }
389 c_ls(j-lo.y) = T(0.);
390 if (!(m3(i,vhi.y+1,0) > 0)) { r_ls(j-lo.y) += dhy*bY(i,j+1,0,n)*phi(i,j+1,0,n); }
396 u_ls(0) = r_ls(0) / bet;
398 for (
int jj = 1; jj <= ilen-1; jj++) {
399 gam(jj) = c_ls(jj-1) / bet;
400 bet = b_ls(jj) - a_ls(jj)*gam(jj);
402 u_ls(jj) = (r_ls(jj)-a_ls(jj)*u_ls(jj-1)) / bet;
405 for (
int jj = ilen-2; jj >= 0; jj--) {
406 u_ls(jj) = u_ls(jj) - gam(jj+1)*u_ls(jj+1);
410 for (
int j = lo.y; j <= hi.y; ++j) {
411 phi(i,j,0,n) = u_ls(j-lo.y);
418 template <
typename T>
421 int ncomp, T osfac) noexcept
425 for (
int n = 0; n < ncomp; ++n) {
426 for (
int j = lo.y; j <= hi.y; ++j) {
427 for (
int i = lo.x; i <= hi.x; ++i) {
428 if ((osm(i-1,j,0)+osm(i,j,0)) == 1) {
429 bX(i,j,0,n) *= osfac;
435 template <
typename T>
438 int ncomp, T osfac) noexcept
442 for (
int n = 0; n < ncomp; ++n) {
443 for (
int j = lo.y; j <= hi.y; ++j) {
444 for (
int i = lo.x; i <= hi.x; ++i) {
445 if ((osm(i,j-1,0)+osm(i,j,0)) == 1) {
446 bY(i,j,0,n) *= osfac;
#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 overset_rescale_bcoef_x(Box const &box, Array4< T > const &bX, Array4< int const > const &osm, int ncomp, T osfac) noexcept
Definition: AMReX_MLABecLap_1D_K.H:239
BoxND< AMREX_SPACEDIM > Box
Definition: AMReX_BaseFwd.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlabeclap_adotx_os(int i, int, int, int n, Array4< T > const &y, Array4< T const > const &x, Array4< T const > const &a, Array4< T const > const &bX, Array4< int const > const &osm, GpuArray< T, AMREX_SPACEDIM > const &dxinv, T alpha, T beta) noexcept
Definition: AMReX_MLABecLap_1D_K.H:24
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlabeclap_flux_x(Box const &box, Array4< T > const &fx, Array4< T const > const &sol, Array4< T const > const &bx, T fac, int ncomp) noexcept
Definition: AMReX_MLABecLap_1D_K.H:56
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlabeclap_flux_y(Box const &box, Array4< T > const &fy, Array4< T const > const &sol, Array4< T const > const &by, T fac, int ncomp) noexcept
Definition: AMReX_MLABecLap_2D_K.H:104
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void abec_gsrb_os(int i, int, int, int n, Array4< T > const &phi, Array4< T const > const &rhs, T alpha, Array4< T const > const &a, T dhx, Array4< T const > const &bX, Array4< int const > const &m0, Array4< int const > const &m1, Array4< T const > const &f0, Array4< T const > const &f1, Array4< int const > const &osm, Box const &vbox, int redblack) noexcept
Definition: AMReX_MLABecLap_1D_K.H:121
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 overset_rescale_bcoef_y(Box const &box, Array4< T > const &bY, Array4< int const > const &osm, int ncomp, T osfac) noexcept
Definition: AMReX_MLABecLap_2D_K.H:437
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void abec_jacobi(int i, int, int, int n, Array4< T > const &phi, Array4< T const > const &rhs, Array4< T const > const &Ax, T alpha, Array4< T const > const &a, T dhx, Array4< T const > const &bX, Array4< int const > const &m0, Array4< int const > const &m1, Array4< T const > const &f0, Array4< T const > const &f1, Box const &vbox) noexcept
Definition: AMReX_MLABecLap_1D_K.H:160
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void abec_gsrb(int i, int, int, int n, Array4< T > const &phi, Array4< T const > const &rhs, T alpha, Array4< T const > const &a, T dhx, Array4< T const > const &bX, Array4< int const > const &m0, Array4< int const > const &m1, Array4< T const > const &f0, Array4< T const > const &f1, Box const &vbox, int redblack) noexcept
Definition: AMReX_MLABecLap_1D_K.H:87
AMREX_FORCE_INLINE void abec_gsrb_with_line_solve(Box const &, Array4< T > const &, Array4< T const > const &, T, Array4< T const > const &, T, Array4< T const > const &, Array4< int const > const &, Array4< int const > const &, Array4< T const > const &, Array4< T const > const &, Box const &, int, int) noexcept
Definition: AMReX_MLABecLap_1D_K.H:223
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlabeclap_flux_yface(Box const &box, Array4< T > const &fy, Array4< T const > const &sol, Array4< T const > const &by, T fac, int ylen, int ncomp) noexcept
Definition: AMReX_MLABecLap_2D_K.H:122
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlabeclap_normalize(int i, int, int, int n, Array4< T > const &x, Array4< T const > const &a, Array4< T const > const &bX, GpuArray< T, AMREX_SPACEDIM > const &dxinv, T alpha, T beta) noexcept
Definition: AMReX_MLABecLap_1D_K.H:44
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void abec_jacobi_os(int i, int, int, int n, Array4< T > const &phi, Array4< T const > const &rhs, Array4< T const > const &Ax, T alpha, Array4< T const > const &a, T dhx, Array4< T const > const &bX, Array4< int const > const &m0, Array4< int const > const &m1, Array4< T const > const &f0, Array4< T const > const &f1, Array4< int const > const &osm, Box const &vbox) noexcept
Definition: AMReX_MLABecLap_1D_K.H:189
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlabeclap_flux_xface(Box const &box, Array4< T > const &fx, Array4< T const > const &sol, Array4< T const > const &bx, T fac, int xlen, int ncomp) noexcept
Definition: AMReX_MLABecLap_1D_K.H:72
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlabeclap_adotx(int i, int, int, int n, Array4< T > const &y, Array4< T const > const &x, Array4< T const > const &a, Array4< T const > const &bX, GpuArray< T, AMREX_SPACEDIM > const &dxinv, T alpha, T beta) noexcept
Definition: AMReX_MLABecLap_1D_K.H:9
Definition: AMReX_Array.H:161
Definition: AMReX_Array4.H:61
Definition: AMReX_Array.H:34