1 #ifndef AMREX_ML_NODE_LINOP_3D_K_H_
2 #define AMREX_ML_NODE_LINOP_3D_K_H_
3 #include <AMReX_Config.H>
9 GpuArray<bool,AMREX_SPACEDIM>
const& bflo,
10 GpuArray<bool,AMREX_SPACEDIM>
const& bfhi) noexcept
13 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
14 if (! bflo[idim]) { gdomain.
growLo(idim,1); }
15 if (! bfhi[idim]) { gdomain.
growHi(idim,1); }
18 if (gdomain.strictly_contains(vbx)) {
return; }
20 const int offset = domain.cellCentered() ? 0 : 1;
28 if (! gdomain.contains(
IntVect(i,j,k))) {
30 if (i == dlo.x-1 && j == dlo.y-1 && k == dlo.z-1 && (bflo[0] || bflo[1] || bflo[2]))
32 if (bflo[0] && bflo[1] && bflo[2])
34 a(i,j,k) = a(i+1+offset, j+1+offset, k+1+offset);
36 else if (bflo[0] && bflo[1])
40 else if (bflo[0] && bflo[2])
44 else if (bflo[1] && bflo[2])
50 a(i,j,k) = a(i+1+
offset, j, k);
54 a(i,j,k) = a(i, j+1+
offset, k);
58 a(i,j,k) = a(i, j, k+1+
offset);
62 else if (i == dhi.x+1 && j == dlo.y-1 && k == dlo.z-1 && (bfhi[0] || bflo[1] || bflo[2]))
64 if (bfhi[0] && bflo[1] && bflo[2])
68 else if (bfhi[0] && bflo[1])
72 else if (bfhi[0] && bflo[2])
76 else if (bflo[1] && bflo[2])
82 a(i,j,k) = a(i-1-
offset, j, k);
86 a(i,j,k) = a(i, j+1+
offset, k);
90 a(i,j,k) = a(i, j, k+1+
offset);
94 else if (i == dlo.x-1 && j == dhi.y+1 && k == dlo.z-1 && (bflo[0] || bfhi[1] || bflo[2]))
96 if (bflo[0] && bfhi[1] && bflo[2])
100 else if (bflo[0] && bfhi[1])
104 else if (bflo[0] && bflo[2])
108 else if (bfhi[1] && bflo[2])
114 a(i,j,k) = a(i+1+
offset, j, k);
118 a(i,j,k) = a(i, j-1-
offset, k);
122 a(i,j,k) = a(i, j, k+1+
offset);
126 else if (i == dhi.x+1 && j == dhi.y+1 && k == dlo.z-1 && (bfhi[0] || bfhi[1] || bflo[2]))
128 if (bfhi[0] && bfhi[1] && bflo[2])
132 else if (bfhi[0] && bfhi[1])
136 else if (bfhi[0] && bflo[2])
140 else if (bfhi[1] && bflo[2])
146 a(i,j,k) = a(i-1-
offset, j, k);
150 a(i,j,k) = a(i, j-1-
offset, k);
154 a(i,j,k) = a(i, j, k+1+
offset);
158 else if (i == dlo.x-1 && j == dlo.y-1 && k == dhi.z+1 && (bflo[0] || bflo[1] || bfhi[2]))
160 if (bflo[0] && bflo[1] && bfhi[2])
164 else if (bflo[0] && bflo[1])
168 else if (bflo[0] && bfhi[2])
172 else if (bflo[1] && bfhi[2])
178 a(i,j,k) = a(i+1+
offset, j, k);
182 a(i,j,k) = a(i, j+1+
offset, k);
186 a(i,j,k) = a(i, j, k-1-
offset);
190 else if (i == dhi.x+1 && j == dlo.y-1 && k == dhi.z+1 && (bfhi[0] || bflo[1] || bfhi[2]))
192 if (bfhi[0] && bflo[1] && bfhi[2])
196 else if (bfhi[0] && bflo[1])
200 else if (bfhi[0] && bfhi[2])
204 else if (bflo[1] && bfhi[2])
210 a(i,j,k) = a(i-1-
offset, j, k);
214 a(i,j,k) = a(i, j+1+
offset, k);
218 a(i,j,k) = a(i, j, k-1-
offset);
222 else if (i == dlo.x-1 && j == dhi.y+1 && k == dhi.z+1 && (bflo[0] || bfhi[1] || bfhi[2]))
224 if (bflo[0] && bfhi[1] && bfhi[2])
228 else if (bflo[0] && bfhi[1])
232 else if (bflo[0] && bfhi[2])
236 else if (bfhi[1] && bfhi[2])
242 a(i,j,k) = a(i+1+
offset, j, k);
246 a(i,j,k) = a(i, j-1-
offset, k);
250 a(i,j,k) = a(i, j, k-1-
offset);
254 else if (i == dhi.x+1 && j == dhi.y+1 && k == dhi.z+1 && (bfhi[0] || bfhi[1] || bfhi[2]))
256 if (bfhi[0] && bfhi[1] && bfhi[2])
260 else if (bfhi[0] && bfhi[1])
264 else if (bfhi[0] && bfhi[2])
268 else if (bfhi[1] && bfhi[2])
274 a(i,j,k) = a(i-1-
offset, j, k);
278 a(i,j,k) = a(i, j-1-
offset, k);
282 a(i,j,k) = a(i, j, k-1-
offset);
286 else if (i == dlo.x-1 && j == dlo.y-1 && (bflo[0] || bflo[1]))
288 if (bflo[0] && bflo[1])
294 a(i,j,k) = a(i+1+
offset, j, k);
298 a(i,j,k) = a(i, j+1+
offset, k);
302 else if (i == dhi.x+1 && j == dlo.y-1 && (bfhi[0] || bflo[1]))
304 if (bfhi[0] && bflo[1])
310 a(i,j,k) = a(i-1-
offset, j, k);
314 a(i,j,k) = a(i, j+1+
offset, k);
318 else if (i == dlo.x-1 && j == dhi.y+1 && (bflo[0] || bfhi[1]))
320 if (bflo[0] && bfhi[1])
326 a(i,j,k) = a(i+1+
offset, j, k);
330 a(i,j,k) = a(i, j-1-
offset, k);
334 else if (i == dhi.x+1 && j == dhi.y+1 && (bfhi[0] || bfhi[1]))
336 if (bfhi[0] && bfhi[1])
342 a(i,j,k) = a(i-1-
offset, j, k);
346 a(i,j,k) = a(i, j-1-
offset, k);
350 else if (i == dlo.x-1 && k == dlo.z-1 && (bflo[0] || bflo[2]))
352 if (bflo[0] && bflo[2])
358 a(i,j,k) = a(i+1+
offset, j, k);
362 a(i,j,k) = a(i, j, k+1+
offset);
366 else if (i == dhi.x+1 && k == dlo.z-1 && (bfhi[0] || bflo[2]))
368 if (bfhi[0] && bflo[2])
374 a(i,j,k) = a(i-1-
offset, j, k);
378 a(i,j,k) = a(i, j, k+1+
offset);
382 else if (i == dlo.x-1 && k == dhi.z+1 && (bflo[0] || bfhi[2]))
384 if (bflo[0] && bfhi[2])
390 a(i,j,k) = a(i+1+
offset, j, k);
394 a(i,j,k) = a(i, j, k-1-
offset);
398 else if (i == dhi.x+1 && k == dhi.z+1 && (bfhi[0] || bfhi[2]))
400 if (bfhi[0] && bfhi[2])
406 a(i,j,k) = a(i-1-
offset, j, k);
410 a(i,j,k) = a(i, j, k-1-
offset);
414 else if (j == dlo.y-1 && k == dlo.z-1 && (bflo[1] || bflo[2]))
416 if (bflo[1] && bflo[2])
422 a(i,j,k) = a(i, j+1+
offset, k);
426 a(i,j,k) = a(i, j, k+1+
offset);
430 else if (j == dhi.y+1 && k == dlo.z-1 && (bfhi[1] || bflo[2]))
432 if (bfhi[1] && bflo[2])
438 a(i,j,k) = a(i, j-1-
offset, k);
442 a(i,j,k) = a(i, j, k+1+
offset);
446 else if (j == dlo.y-1 && k == dhi.z+1 && (bflo[1] || bfhi[2]))
448 if (bflo[1] && bfhi[2])
454 a(i,j,k) = a(i, j+1+
offset, k);
458 a(i,j,k) = a(i, j, k-1-
offset);
462 else if (j == dhi.y+1 && k == dhi.z+1 && (bfhi[1] || bfhi[2]))
464 if (bfhi[1] && bfhi[2])
470 a(i,j,k) = a(i, j-1-
offset, k);
474 a(i,j,k) = a(i, j, k-1-
offset);
477 else if (i == dlo.x-1 && bflo[0])
479 a(i,j,k) = a(i+1+
offset, j, k);
481 else if (i == dhi.x+1 && bfhi[0])
483 a(i,j,k) = a(i-1-
offset, j, k);
485 else if (j == dlo.y-1 && bflo[1])
487 a(i,j,k) = a(i, j+1+
offset, k);
489 else if (j == dhi.y+1 && bfhi[1])
491 a(i,j,k) = a(i, j-1-
offset, k);
493 else if (k == dlo.z-1 && bflo[2])
495 a(i,j,k) = a(i, j, k+1+
offset);
497 else if (k == dhi.z+1 && bfhi[2])
499 a(i,j,k) = a(i, j, k-1-
offset);
511 Array4<Real const>
const&
fine, Array4<int const>
const& msk) noexcept
517 crse(i,j,k) = Real(0.0);
519 crse(i,j,k) = Real(1./64.)*(
fine(ii-1,jj-1,kk-1)+
fine(ii+1,jj-1,kk-1)
520 +
fine(ii-1,jj+1,kk-1)+
fine(ii+1,jj+1,kk-1)
521 +
fine(ii-1,jj-1,kk+1)+
fine(ii+1,jj-1,kk+1)
522 +
fine(ii-1,jj+1,kk+1)+
fine(ii+1,jj+1,kk+1))
523 + Real(1./32.)*(
fine(ii ,jj-1,kk-1)+
fine(ii ,jj+1,kk-1)
524 +
fine(ii ,jj-1,kk+1)+
fine(ii ,jj+1,kk+1)
525 +
fine(ii-1,jj ,kk-1)+
fine(ii+1,jj ,kk-1)
526 +
fine(ii-1,jj ,kk+1)+
fine(ii+1,jj ,kk+1)
527 +
fine(ii-1,jj-1,kk )+
fine(ii+1,jj-1,kk )
528 +
fine(ii-1,jj+1,kk )+
fine(ii+1,jj+1,kk ))
529 + Real(1./16.)*(
fine(ii-1,jj,kk)+
fine(ii+1,jj,kk)
532 + Real(1./8.)*
fine(ii,jj,kk);
539 Array4<Real const>
const&
fine, Array4<int const>
const& msk,
541 GpuArray<LinOpBCType, AMREX_SPACEDIM>
const& bclo,
542 GpuArray<LinOpBCType, AMREX_SPACEDIM>
const& bchi) noexcept
548 crse(i,j,k) = Real(0.0);
552 Real tmp = Real(0.0);
553 for (
int koff = -rr+1; koff <= rr-1; ++koff) {
555 for (
int joff = -rr+1; joff <= rr-1; ++joff) {
557 for (
int ioff = -rr+1; ioff <= rr-1; ++ioff) {
559 int itmp = ii + ioff;
560 int jtmp = jj + joff;
561 int ktmp = kk + koff;
562 if ((itmp < ndlo.x && (bclo[0] == LinOpBCType::Neumann ||
563 bclo[0] == LinOpBCType::inflow)) ||
564 (itmp > ndhi.x && (bchi[0] == LinOpBCType::Neumann ||
565 bchi[0] == LinOpBCType::inflow))) {
568 if ((jtmp < ndlo.y && (bclo[1] == LinOpBCType::Neumann ||
569 bclo[1] == LinOpBCType::inflow)) ||
570 (jtmp > ndhi.y && (bchi[1] == LinOpBCType::Neumann ||
571 bchi[1] == LinOpBCType::inflow))) {
574 if ((ktmp < ndlo.z && (bclo[2] == LinOpBCType::Neumann ||
575 bclo[2] == LinOpBCType::inflow)) ||
576 (ktmp > ndhi.z && (bchi[2] == LinOpBCType::Neumann ||
577 bchi[2] == LinOpBCType::inflow))) {
580 tmp += wx*wy*wz*
fine(itmp,jtmp,ktmp);
584 crse(i,j,k) = tmp/Real(rr*rr*rr*rr*rr*rr);
590 Array4<Real const>
const&
fine, Array4<int const>
const& msk,
int idir) noexcept
598 crse(i,j,k) = Real(0.0);
600 crse(i,j,k) = Real(1./16.)*(
fine(ii-1,jj-1,kk) + Real(2.)*
fine(ii ,jj-1,kk) +
fine(ii+1,jj-1,kk)
601 + Real(2.)*
fine(ii-1,jj ,kk) + Real(4.)*
fine(ii ,jj ,kk) + Real(2.)*
fine(ii+1,jj ,kk)
602 +
fine(ii-1,jj+1,kk) + Real(2.)*
fine(ii ,jj+1,kk) +
fine(ii+1,jj+1,kk));
611 crse(i,j,k) = Real(0.0);
613 crse(i,j,k) = Real(1./16.)*(
fine(ii-1,jj,kk-1) + Real(2.)*
fine(ii ,jj,kk-1) +
fine(ii+1,jj,kk-1)
614 + Real(2.)*
fine(ii-1,jj ,kk) + Real(4.)*
fine(ii ,jj,kk ) + Real(2.)*
fine(ii+1,jj,kk )
615 +
fine(ii-1,jj,kk+1) + Real(2.)*
fine(ii ,jj,kk+1) +
fine(ii+1,jj,kk+1));
624 crse(i,j,k) = Real(0.0);
626 crse(i,j,k) = Real(1./16.)*(
fine(ii,jj-1,kk-1) + Real(2.)*
fine(ii ,jj,kk-1) +
fine(ii,jj+1,kk-1)
627 + Real(2.)*
fine(ii,jj-1 ,kk) + Real(4.)*
fine(ii ,jj,kk ) + Real(2.)*
fine(ii,jj+1,kk )
628 +
fine(ii,jj-1,kk+1) + Real(2.)*
fine(ii ,jj,kk+1) +
fine(ii,jj+1,kk+1));
633 amrex::Abort(
"mlndlap_semi_restriction semi direction wrong semi-direction. ");
643 Array4<int const>
const& cmsk) noexcept
645 using namespace nodelap_detail;
647 int s = cmsk(i-1,j-1,k-1) + cmsk(i ,j-1,k-1)
648 + cmsk(i-1,j ,k-1) + cmsk(i ,j ,k-1)
649 + cmsk(i-1,j-1,k ) + cmsk(i ,j-1,k )
650 + cmsk(i-1,j ,k ) + cmsk(i ,j ,k );
663 Array4<int const>
const& omsk,
Box const& dom,
664 GpuArray<LinOpBCType, AMREX_SPACEDIM>
const& bclo,
665 GpuArray<LinOpBCType, AMREX_SPACEDIM>
const& bchi) noexcept
669 for (
int k = lo.z; k <= hi.z; ++k) {
670 for (
int j = lo.y; j <= hi.y; ++j) {
672 for (
int i = lo.x; i <= hi.x; ++i) {
674 dmsk(i,j,k) = (omsk(i-1,j-1,k-1) == 1 || omsk(i,j-1,k-1) == 1 ||
675 omsk(i-1,j ,k-1) == 1 || omsk(i,j ,k-1) == 1 ||
676 omsk(i-1,j-1,k ) == 1 || omsk(i,j-1,k ) == 1 ||
677 omsk(i-1,j ,k ) == 1 || omsk(i,j ,k ) == 1);
684 if (bclo[0] == LinOpBCType::Dirichlet && lo.x == domlo.x) {
685 for (
int k = lo.z; k <= hi.z; ++k) {
686 for (
int j = lo.y; j <= hi.y; ++j) {
691 if (bchi[0] == LinOpBCType::Dirichlet && hi.x == domhi.x) {
692 for (
int k = lo.z; k <= hi.z; ++k) {
693 for (
int j = lo.y; j <= hi.y; ++j) {
698 if (bclo[1] == LinOpBCType::Dirichlet && lo.y == domlo.y) {
699 for (
int k = lo.z; k <= hi.z; ++k) {
701 for (
int i = lo.x; i <= hi.x; ++i) {
706 if (bchi[1] == LinOpBCType::Dirichlet && hi.y == domhi.y) {
707 for (
int k = lo.z; k <= hi.z; ++k) {
709 for (
int i = lo.x; i <= hi.x; ++i) {
714 if (bclo[2] == LinOpBCType::Dirichlet && lo.z == domlo.z) {
715 for (
int j = lo.y; j <= hi.y; ++j) {
717 for (
int i = lo.x; i <= hi.x; ++i) {
722 if (bchi[2] == LinOpBCType::Dirichlet && hi.z == domhi.z) {
723 for (
int j = lo.y; j <= hi.y; ++j) {
725 for (
int i = lo.x; i <= hi.x; ++i) {
733 Array4<int const>
const& omsk,
Box const& dom,
734 GpuArray<LinOpBCType, AMREX_SPACEDIM>
const& bclo,
735 GpuArray<LinOpBCType, AMREX_SPACEDIM>
const& bchi) noexcept
739 for (
int k = lo.z; k <= hi.z; ++k) {
740 for (
int j = lo.y; j <= hi.y; ++j) {
742 for (
int i = lo.x; i <= hi.x; ++i) {
743 dmsk(i,j,k) =
static_cast<Real
>(omsk(i,j,k));
749 if ((bclo[0] == LinOpBCType::Neumann || bclo[0] == LinOpBCType::inflow)
752 for (
int k = lo.z; k <= hi.z; ++k) {
753 for (
int j = lo.y; j <= hi.y; ++j) {
754 dmsk(lo.x,j,k) *= Real(0.5);
758 if ((bchi[0] == LinOpBCType::Neumann || bchi[0] == LinOpBCType::inflow)
761 for (
int k = lo.z; k <= hi.z; ++k) {
762 for (
int j = lo.y; j <= hi.y; ++j) {
763 dmsk(hi.x,j,k) *= Real(0.5);
767 if ((bclo[1] == LinOpBCType::Neumann || bclo[1] == LinOpBCType::inflow)
770 for (
int k = lo.z; k <= hi.z; ++k) {
772 for (
int i = lo.x; i <= hi.x; ++i) {
773 dmsk(i,lo.y,k) *= Real(0.5);
777 if ((bchi[1] == LinOpBCType::Neumann || bchi[1] == LinOpBCType::inflow)
780 for (
int k = lo.z; k <= hi.z; ++k) {
782 for (
int i = lo.x; i <= hi.x; ++i) {
783 dmsk(i,hi.y,k) *= Real(0.5);
787 if ((bclo[2] == LinOpBCType::Neumann || bclo[2] == LinOpBCType::inflow)
790 for (
int j = lo.y; j <= hi.y; ++j) {
792 for (
int i = lo.x; i <= hi.x; ++i) {
793 dmsk(i,j,lo.z) *= Real(0.5);
797 if ((bchi[2] == LinOpBCType::Neumann || bchi[2] == LinOpBCType::inflow)
800 for (
int j = lo.y; j <= hi.y; ++j) {
802 for (
int i = lo.x; i <= hi.x; ++i) {
803 dmsk(i,j,hi.z) *= Real(0.5);
#define AMREX_PRAGMA_SIMD
Definition: AMReX_Extension.H:80
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_HOST_DEVICE_FOR_3D(...)
Definition: AMReX_GpuLaunch.nolint.H:50
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
int idir
Definition: AMReX_HypreMLABecLap.cpp:1093
Array4< int const > offset
Definition: AMReX_HypreMLABecLap.cpp:1089
Array4< Real > fine
Definition: AMReX_InterpFaceRegister.cpp:90
Array4< Real const > crse
Definition: AMReX_InterpFaceRegister.cpp:92
if(!(yy_init))
Definition: amrex_iparser.lex.nolint.H:935
AMREX_GPU_HOST_DEVICE BoxND & growHi(int idir, int n_cell=1) noexcept
Grow the BoxND on the high end by n_cell cells in direction idir. NOTE: n_cell negative shrinks the B...
Definition: AMReX_Box.H:659
AMREX_GPU_HOST_DEVICE BoxND & growLo(int idir, int n_cell=1) noexcept
Grow the BoxND on the low end by n_cell cells in direction idir. NOTE: n_cell negative shrinks the Bo...
Definition: AMReX_Box.H:648
constexpr int fine_node
Definition: AMReX_MLNodeLinOp_K.H:58
constexpr int crse_node
Definition: AMReX_MLNodeLinOp_K.H:56
constexpr int crse_fine_node
Definition: AMReX_MLNodeLinOp_K.H:57
integer, parameter crse_cell
Definition: AMReX_EBFluxRegister_nd.F90:7
integer, parameter fine_cell
Definition: AMReX_EBFluxRegister_nd.F90:9
Definition: AMReX_Amr.cpp:49
void mlndlap_bc_doit(Box const &vbx, Array4< T > const &a, Box const &domain, GpuArray< bool, AMREX_SPACEDIM > const &bflo, GpuArray< bool, AMREX_SPACEDIM > const &bfhi) noexcept
Definition: AMReX_MLNodeLinOp_1D_K.H:8
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_set_nodal_mask(int i, int, int, Array4< int > const &nmsk, Array4< int const > const &cmsk) noexcept
Definition: AMReX_MLNodeLinOp_1D_K.H:93
BoxND< AMREX_SPACEDIM > Box
Definition: AMReX_BaseFwd.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Grow BoxND in all directions by given amount.
Definition: AMReX_Box.H:1211
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T abs(const GpuComplex< T > &a_z) noexcept
Return the absolute value of a complex number.
Definition: AMReX_GpuComplex.H:356
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_restriction(int i, int, int, Array4< Real > const &crse, Array4< Real const > const &fine, Array4< int const > const &msk) noexcept
Definition: AMReX_MLNodeLinOp_1D_K.H:41
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 mlndlap_semi_restriction(int, int, int, Array4< Real > const &, Array4< Real const > const &, Array4< int const > const &, int) noexcept
Definition: AMReX_MLNodeLinOp_1D_K.H:86
IntVectND< AMREX_SPACEDIM > IntVect
Definition: AMReX_BaseFwd.H:30
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 mlndlap_set_dirichlet_mask(Box const &bx, Array4< int > const &dmsk, Array4< int const > const &omsk, Box const &dom, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &bclo, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &bchi) noexcept
Definition: AMReX_MLNodeLinOp_1D_K.H:109
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_set_dot_mask(Box const &bx, Array4< Real > const &dmsk, Array4< int const > const &omsk, Box const &dom, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &bclo, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &bchi) noexcept
Definition: AMReX_MLNodeLinOp_1D_K.H:136