Block-Structured AMR Software Framework
AMReX_MLMG_2D_K.H
Go to the documentation of this file.
1 #ifndef AMREX_MLMG_2D_K_H_
2 #define AMREX_MLMG_2D_K_H_
3 #include <AMReX_Config.H>
4 
5 namespace amrex::TwoD {
6 
7 template <typename T>
9 void mlmg_lin_cc_interp_r2 (Box const& bx, Array4<T> const& ff,
10  Array4<T const> const& cc, int nc) noexcept
11 {
12  const auto lo = amrex::lbound(bx);
13  const auto hi = amrex::ubound(bx);
14 
15  for (int n = 0; n < nc; ++n) {
16  for (int j = lo.y; j <= hi.y; ++j) {
17  const int jc = j/2;
18  const int joff = 2*(j-jc*2)-1;
20  for (int i = lo.x; i <= hi.x; ++i) {
21  const int ic = i/2;
22  const int ioff = 2*(i-ic*2)-1;
23  ff(i,j,0,n) = T(0.5625)*cc(ic ,jc ,0,n)
24  + T(0.1875)*cc(ic+ioff,jc ,0,n)
25  + T(0.1875)*cc(ic ,jc+joff,0,n)
26  + T(0.0625)*cc(ic+ioff,jc+joff,0,n);
27 
28  }
29  }
30  }
31 }
32 
33 template <typename T>
35 void mlmg_lin_cc_interp_r4 (Box const& bx, Array4<T> const& ff,
36  Array4<T const> const& cc, int nc) noexcept
37 {
38  const auto lo = amrex::lbound(bx);
39  const auto hi = amrex::ubound(bx);
40 
41  for (int n = 0; n < nc; ++n) {
42  for (int j = lo.y; j <= hi.y; ++j) {
43  const int jc = j/4;
45  for (int i = lo.x; i <= hi.x; ++i) {
46  const int ic = i/4;
47  ff(i,j,0,n) = cc(ic,jc,0,n);
48  }
49  }
50  }
51 }
52 
53 #ifdef AMREX_USE_EB
54 template <int R, typename T>
56 void mlmg_eb_cc_interp_r (Box const& bx, Array4<T> const& ff, Array4<T const> const& cc,
57  Array4<EBCellFlag const> const& flag, int nc) noexcept
58 {
59  const auto lo = amrex::lbound(bx);
60  const auto hi = amrex::ubound(bx);
61 
62  for (int n = 0; n < nc; ++n) {
63  for (int j = lo.y; j <= hi.y; ++j) {
64  const int jc = j/R;
66  for (int i = lo.x; i <= hi.x; ++i) {
67  const int ic = i/R;
68  if (flag(i,j,0).isCovered()) {
69  ff(i,j,0,n) = T(0.0);
70  } else {
71  ff(i,j,0,n) = cc(ic,jc,0,n);
72  }
73  }
74  }
75  }
76 }
77 #endif
78 
79 template <typename T>
81 void mlmg_lin_nd_interp_r2 (int i, int j, int, int n, Array4<T> const& fine,
82  Array4<T const> const& crse) noexcept
83 {
84  int ic = amrex::coarsen(i,2);
85  int jc = amrex::coarsen(j,2);
86  bool i_is_odd = (ic*2 != i);
87  bool j_is_odd = (jc*2 != j);
88  if (i_is_odd && j_is_odd) {
89  // Fine node at center of cell
90  fine(i,j,0,n) = T(0.25)*(crse(ic,jc,0,n) + crse(ic+1,jc,0,n) +
91  crse(ic,jc+1,0,n) + crse(ic+1,jc+1,0,n));
92  } else if (j_is_odd) {
93  // Fine node along a vertical cell edge
94  fine(i,j,0,n) = T(0.5)*(crse(ic,jc,0,n) + crse(ic,jc+1,0,n));
95  } else if (i_is_odd) {
96  // Fine node along a horizontal cell edge
97  fine(i,j,0,n) = T(0.5)*(crse(ic,jc,0,n) + crse(ic+1,jc,0,n));
98  } else {
99  // Fine node coincident with coarse node
100  fine(i,j,0,n) = crse(ic,jc,0,n);
101  }
102 }
103 
104 template <typename T>
106 void mlmg_lin_nd_interp_r4 (int i, int j, int, int n, Array4<T> const& fine,
107  Array4<T const> const& crse) noexcept
108 {
109  int ic = amrex::coarsen(i,4);
110  int jc = amrex::coarsen(j,4);
111  bool i_injection = (ic*4 == i);
112  bool j_injection = (jc*4 == j);
113 
114 #define I_LO (4*(ic+1)-i)
115 #define J_LO (4*(jc+1)-j)
116 #define I_HI (i-4*ic)
117 #define J_HI (j-4*jc)
118 
119  if (i_injection && j_injection) {
120  fine(i,j,0,n) = crse(ic,jc,0,n);
121  } else if (i_injection) {
122  fine(i,j,0,n) = T(0.25)*(crse(ic,jc ,0,n)*T(J_LO)
123  + crse(ic,jc+1,0,n)*T(J_HI));
124  } else if (j_injection) {
125  fine(i,j,0,n) = T(0.25)*(crse(ic ,jc,0,n)*T(I_LO)
126  + crse(ic+1,jc,0,n)*T(I_HI));
127  } else {
128  fine(i,j,0,n) = T(0.0625)*(crse(ic ,jc ,0,n)*T(I_LO*J_LO)
129  + crse(ic+1,jc ,0,n)*T(I_HI*J_LO)
130  + crse(ic ,jc+1,0,n)*T(I_LO*J_HI)
131  + crse(ic+1,jc+1,0,n)*T(I_HI*J_HI));
132  }
133 
134 #undef I_LO
135 #undef J_LO
136 #undef I_HI
137 #undef J_HI
138 }
139 
140 }
141 
142 #if (AMREX_SPACEDIM == 2)
143 namespace amrex {
144  using namespace TwoD;
145 }
146 #endif
147 
148 #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
Array4< Real > fine
Definition: AMReX_InterpFaceRegister.cpp:90
Array4< Real const > crse
Definition: AMReX_InterpFaceRegister.cpp:92
#define I_LO
#define J_LO
#define I_HI
#define J_HI
static int ff(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:59
Definition: AMReX_MLALap_2D_K.H:5
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlmg_lin_cc_interp_r4(Box const &bx, Array4< T > const &ff, Array4< T const > const &cc, int nc) noexcept
Definition: AMReX_MLMG_2D_K.H:35
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlmg_lin_nd_interp_r4(int i, int j, int, int n, Array4< T > const &fine, Array4< T const > const &crse) noexcept
Definition: AMReX_MLMG_2D_K.H:106
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlmg_lin_nd_interp_r2(int i, int j, int, int n, Array4< T > const &fine, Array4< T const > const &crse) noexcept
Definition: AMReX_MLMG_2D_K.H:81
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlmg_lin_cc_interp_r2(Box const &bx, Array4< T > const &ff, Array4< T const > const &cc, int nc) noexcept
Definition: AMReX_MLMG_2D_K.H:9
Definition: AMReX_Amr.cpp:49
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 BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Coarsen BoxND by given (positive) refinement ratio. NOTE: if type(dir) = CELL centered: lo <- lo/rati...
Definition: AMReX_Box.H:1304
Definition: AMReX_Array4.H:61