Block-Structured AMR Software Framework
AMReX_MLMG_3D_K.H
Go to the documentation of this file.
1 #ifndef AMREX_MLMG_3D_K_H_
2 #define AMREX_MLMG_3D_K_H_
3 #include <AMReX_Config.H>
4 
5 namespace amrex {
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 k = lo.z; k <= hi.z; ++k) {
17  const int kc = k/2;
18  const int koff = 2*(k-kc*2)-1;
19  for (int j = lo.y; j <= hi.y; ++j) {
20  const int jc = j/2;
21  const int joff = 2*(j-jc*2)-1;
23  for (int i = lo.x; i <= hi.x; ++i) {
24  const int ic = i/2;
25  const int ioff = 2*(i-ic*2)-1;
26  ff(i,j,k,n) = T(0.421875)*cc(ic ,jc ,kc ,n)
27  + T(0.140625)*cc(ic+ioff,jc ,kc ,n)
28  + T(0.140625)*cc(ic ,jc+joff,kc ,n)
29  + T(0.140625)*cc(ic ,jc ,kc+koff,n)
30  + T(0.046875)*cc(ic ,jc+joff,kc+koff,n)
31  + T(0.046875)*cc(ic+ioff,jc ,kc+koff,n)
32  + T(0.046875)*cc(ic+ioff,jc+joff,kc ,n)
33  + T(0.015625)*cc(ic+ioff,jc+joff,kc+koff,n);
34  }
35  }
36  }
37  }
38 }
39 
40 template <typename T>
42 void mlmg_lin_cc_interp_r4 (Box const& bx, Array4<T> const& ff,
43  Array4<T const> const& cc, int nc) noexcept
44 {
45  const auto lo = amrex::lbound(bx);
46  const auto hi = amrex::ubound(bx);
47 
48  for (int n = 0; n < nc; ++n) {
49  for (int k = lo.z; k <= hi.z; ++k) {
50  const int kc = k/4;
51  for (int j = lo.y; j <= hi.y; ++j) {
52  const int jc = j/4;
54  for (int i = lo.x; i <= hi.x; ++i) {
55  const int ic = i/4;
56  ff(i,j,k,n) = cc(ic,jc,kc,n);
57  }
58  }
59  }
60  }
61 }
62 
63 #ifdef AMREX_USE_EB
64 template <int R, typename T>
66 void mlmg_eb_cc_interp_r (Box const& bx, Array4<T> const& ff, Array4<T const> const& cc,
67  Array4<EBCellFlag const> const& flag, int nc) noexcept
68 {
69  const auto lo = amrex::lbound(bx);
70  const auto hi = amrex::ubound(bx);
71 
72  for (int n = 0; n < nc; ++n) {
73  for (int k = lo.z; k <= hi.z; ++k) {
74  const int kc = k/R;
75  for (int j = lo.y; j <= hi.y; ++j) {
76  const int jc = j/R;
78  for (int i = lo.x; i <= hi.x; ++i) {
79  const int ic = i/R;
80  if (flag(i,j,k).isCovered()) {
81  ff(i,j,k,n) = T(0.0);
82  } else {
83  ff(i,j,k,n) = cc(ic,jc,kc,n);
84  }
85  }
86  }
87  }
88  }
89 }
90 #endif
91 
92 template <typename T>
94 void mlmg_lin_nd_interp_r2 (int i, int j, int k, int n, Array4<T> const& fine,
95  Array4<T const> const& crse) noexcept
96 {
97  int ic = amrex::coarsen(i,2);
98  int jc = amrex::coarsen(j,2);
99  int kc = amrex::coarsen(k,2);
100  bool i_is_odd = (ic*2 != i);
101  bool j_is_odd = (jc*2 != j);
102  bool k_is_odd = (kc*2 != k);
103  if (i_is_odd && j_is_odd && k_is_odd) {
104  // Fine node at center of cell
105  fine(i,j,k,n) = T(0.125)*(crse(ic, jc, kc,n) + crse(ic, jc, kc+1,n) +
106  crse(ic, jc+1,kc,n) + crse(ic, jc+1,kc+1,n) +
107  crse(ic+1,jc, kc,n) + crse(ic+1,jc, kc+1,n) +
108  crse(ic+1,jc+1,kc,n) + crse(ic+1,jc+1,kc+1,n));
109  } else if (j_is_odd && k_is_odd) {
110  // Node on a Y-Z face
111  fine(i,j,k,n) = T(0.25)*(crse(ic, jc, kc,n) + crse(ic, jc, kc+1,n) +
112  crse(ic, jc+1,kc,n) + crse(ic, jc+1,kc+1,n));
113  } else if (i_is_odd && k_is_odd) {
114  // Node on a Z-X face
115  fine(i,j,k,n) = T(0.25)*(crse(ic, jc,kc,n) + crse(ic, jc,kc+1,n) +
116  crse(ic+1,jc,kc,n) + crse(ic+1,jc,kc+1,n));
117  } else if (i_is_odd && j_is_odd) {
118  // Node on a X-Y face
119  fine(i,j,k,n) = T(0.25)*(crse(ic ,jc,kc,n) + crse(ic ,jc+1,kc,n) +
120  crse(ic+1,jc,kc,n) + crse(ic+1,jc+1,kc,n));
121  } else if (i_is_odd) {
122  // Node on X line
123  fine(i,j,k,n) = T(0.5)*(crse(ic,jc,kc,n) + crse(ic+1,jc,kc,n));
124  } else if (j_is_odd) {
125  // Node on Y line
126  fine(i,j,k,n) = T(0.5)*(crse(ic,jc,kc,n) + crse(ic,jc+1,kc,n));
127  } else if (k_is_odd) {
128  // Node on Z line
129  fine(i,j,k,n) = T(0.5)*(crse(ic,jc,kc,n) + crse(ic,jc,kc+1,n));
130  } else {
131  // Node coincident with coarse node
132  fine(i,j,k,n) = crse(ic,jc,kc,n);
133  }
134 }
135 
136 template <typename T>
138 void mlmg_lin_nd_interp_r4 (int i, int j, int k, int n, Array4<T> const& fine,
139  Array4<T const> const& crse) noexcept
140 {
141  int ic = amrex::coarsen(i,4);
142  int jc = amrex::coarsen(j,4);
143  int kc = amrex::coarsen(k,4);
144  bool i_injection = (ic*4 == i);
145  bool j_injection = (jc*4 == j);
146  bool k_injection = (kc*4 == k);
147 
148 #define I_LO (4*(ic+1)-i)
149 #define J_LO (4*(jc+1)-j)
150 #define K_LO (4*(kc+1)-k)
151 #define I_HI (i-4*ic)
152 #define J_HI (j-4*jc)
153 #define K_HI (k-4*kc)
154 
155  if (i_injection && j_injection && k_injection)
156  {
157  fine(i,j,k,n) = crse(ic,jc,kc,n);
158  }
159  else if (i_injection && j_injection)
160  {
161  fine(i,j,k,n) = T(0.25)*(crse(ic,jc,kc ,n)*T(K_LO)
162  + crse(ic,jc,kc+1,n)*T(K_HI));
163  }
164  else if (i_injection && k_injection)
165  {
166  fine(i,j,k,n) = T(0.25)*(crse(ic,jc ,kc,n)*T(J_LO)
167  + crse(ic,jc+1,kc,n)*T(J_HI));
168  }
169  else if (j_injection && k_injection)
170  {
171  fine(i,j,k,n) = T(0.25)*(crse(ic ,jc,kc,n)*T(I_LO)
172  + crse(ic+1,jc,kc,n)*T(I_HI));
173  }
174  else if (i_injection)
175  {
176  fine(i,j,k,n) = T(0.0625)*(crse(ic,jc ,kc ,n)*T(J_LO*K_LO)
177  + crse(ic,jc+1,kc ,n)*T(J_HI*K_LO)
178  + crse(ic,jc ,kc+1,n)*T(J_LO*K_HI)
179  + crse(ic,jc+1,kc+1,n)*T(J_HI*K_HI));
180  }
181  else if (j_injection)
182  {
183  fine(i,j,k,n) = T(0.0625)*(crse(ic ,jc,kc ,n)*T(I_LO*K_LO)
184  + crse(ic+1,jc,kc ,n)*T(I_HI*K_LO)
185  + crse(ic ,jc,kc+1,n)*T(I_LO*K_HI)
186  + crse(ic+1,jc,kc+1,n)*T(I_HI*K_HI));
187 
188  } else if (k_injection) {
189  fine(i,j,k,n) = T(0.0625)*(crse(ic ,jc ,kc,n)*T(I_LO*J_LO)
190  + crse(ic+1,jc ,kc,n)*T(I_HI*J_LO)
191  + crse(ic ,jc+1,kc,n)*T(I_LO*J_HI)
192  + crse(ic+1,jc+1,kc,n)*T(I_HI*J_HI));
193  }
194  else
195  {
196  fine(i,j,k,n) = T(0.015625)*(crse(ic ,jc ,kc ,n)*T(I_LO*J_LO*K_LO)
197  + crse(ic+1,jc ,kc ,n)*T(I_HI*J_LO*K_LO)
198  + crse(ic ,jc+1,kc ,n)*T(I_LO*J_HI*K_LO)
199  + crse(ic+1,jc+1,kc ,n)*T(I_HI*J_HI*K_LO)
200  + crse(ic ,jc ,kc+1,n)*T(I_LO*J_LO*K_HI)
201  + crse(ic+1,jc ,kc+1,n)*T(I_HI*J_LO*K_HI)
202  + crse(ic ,jc+1,kc+1,n)*T(I_LO*J_HI*K_HI)
203  + crse(ic+1,jc+1,kc+1,n)*T(I_HI*J_HI*K_HI));
204  }
205 
206 #undef I_LO
207 #undef J_LO
208 #undef K_LO
209 #undef I_HI
210 #undef J_HI
211 #undef K_HI
212 }
213 
214 }
215 #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 K_HI
#define J_HI
#define K_LO
static int ff(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:59
Definition: AMReX_Amr.cpp:49
BoxND< AMREX_SPACEDIM > Box
Definition: AMReX_BaseFwd.H:27
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_1D_K.H:9
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_1D_K.H:27
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 mlmg_lin_nd_interp_r2(int i, int, int, int n, Array4< T > const &fine, Array4< T const > const &crse) noexcept
Definition: AMReX_MLMG_1D_K.H:44
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlmg_lin_nd_interp_r4(int i, int, int, int n, Array4< T > const &fine, Array4< T const > const &crse) noexcept
Definition: AMReX_MLMG_1D_K.H:60
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