Block-Structured AMR Software Framework
AMReX_MLNodeLap_3D_K.H
Go to the documentation of this file.
1 #ifndef AMREX_MLNODELAP_3D_K_H_
2 #define AMREX_MLNODELAP_3D_K_H_
3 #include <AMReX_Config.H>
4 
5 namespace amrex {
6 
8 void mlndlap_zero_fine (int i, int j, int k, Array4<Real> const& phi,
9  Array4<int const> const& msk, int fine_flag) noexcept
10 {
11  // Testing if the node is covered by a fine level in computing
12  // coarse sync residual
13  if (msk(i-1,j-1,k-1) == fine_flag &&
14  msk(i ,j-1,k-1) == fine_flag &&
15  msk(i-1,j ,k-1) == fine_flag &&
16  msk(i ,j ,k-1) == fine_flag &&
17  msk(i-1,j-1,k ) == fine_flag &&
18  msk(i ,j-1,k ) == fine_flag &&
19  msk(i-1,j ,k ) == fine_flag &&
20  msk(i ,j ,k ) == fine_flag)
21  {
22  phi(i,j,k) = Real(0.0);
23  }
24 }
25 
26 //
27 // coeffs
28 //
29 
31 void mlndlap_avgdown_coeff_x (int i, int j, int k, Array4<Real> const& crse,
32  Array4<Real const> const& fine) noexcept
33 {
34  Real cl = fine(2*i ,2*j,2*k )+fine(2*i ,2*j+1,2*k )+
35  fine(2*i ,2*j,2*k+1)+fine(2*i ,2*j+1,2*k+1);
36  Real cr = fine(2*i+1,2*j,2*k )+fine(2*i+1,2*j+1,2*k )+
37  fine(2*i+1,2*j,2*k+1)+fine(2*i+1,2*j+1,2*k+1);
38  crse(i,j,k) = Real(0.5)*cl*cr/(cl+cr);
39 }
40 
42 void mlndlap_avgdown_coeff_y (int i, int j, int k, Array4<Real> const& crse,
43  Array4<Real const> const& fine) noexcept
44 {
45  Real cl = fine(2*i,2*j ,2*k )+fine(2*i+1,2*j ,2*k )+
46  fine(2*i,2*j ,2*k+1)+fine(2*i+1,2*j ,2*k+1);
47  Real cr = fine(2*i,2*j+1,2*k )+fine(2*i+1,2*j+1,2*k )+
48  fine(2*i,2*j+1,2*k+1)+fine(2*i+1,2*j+1,2*k+1);
49  crse(i,j,k) = Real(0.5)*cl*cr/(cl+cr);
50 }
51 
53 void mlndlap_avgdown_coeff_z (int i, int j, int k, Array4<Real> const& crse,
54  Array4<Real const> const& fine) noexcept
55 {
56  Real cl = fine(2*i,2*j ,2*k )+fine(2*i+1,2*j ,2*k )+
57  fine(2*i,2*j+1,2*k )+fine(2*i+1,2*j+1,2*k );
58  Real cr = fine(2*i,2*j ,2*k+1)+fine(2*i+1,2*j ,2*k+1)+
59  fine(2*i,2*j+1,2*k+1)+fine(2*i+1,2*j+1,2*k+1);
60  crse(i,j,k) = Real(0.5)*cl*cr/(cl+cr);
61 }
62 
64 void mlndlap_semi_avgdown_coeff (int i, int j, int k, Array4<Real> const& crse,
65  Array4<Real const> const& fine, int idir) noexcept
66 {
67  if (idir == 2) {
68  Real cl = fine(2*i ,2*j,k) + fine(2*i ,2*j+1,k);
69  Real cr = fine(2*i+1,2*j,k) + fine(2*i+1,2*j+1,k);
70  crse(i,j,k) = cl*cr/(cl+cr);
71  } else if (idir == 1) {
72  Real cl = fine(2*i ,j,2*k) + fine(2*i ,j,2*k+1);
73  Real cr = fine(2*i+1,j,2*k) + fine(2*i+1,j,2*k+1);
74  crse(i,j,k) = cl*cr/(cl+cr);
75  } else {
76  Real cl = fine(i,2*j ,2*k) + fine(i,2*j ,2*k+1);
77  Real cr = fine(i,2*j+1,2*k) + fine(i,2*j+1,2*k+1);
78  crse(i,j,k) = cl*cr/(cl+cr);
79  }
80 }
81 
82 //
83 // operator
84 //
85 
87 Real mlndlap_adotx_ha (int i, int j, int k, Array4<Real const> const& x,
88  Array4<Real const> const& sx, Array4<Real const> const& sy,
89  Array4<Real const> const& sz, Array4<int const> const& msk,
90  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
91 {
92  if (msk(i,j,k)) {
93  return Real(0.0);
94  } else {
95  Real facx = Real(1./36.)*dxinv[0]*dxinv[0];
96  Real facy = Real(1./36.)*dxinv[1]*dxinv[1];
97  Real facz = Real(1./36.)*dxinv[2]*dxinv[2];
98  Real y = x(i,j,k)*Real(-4.0)*(facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1)+sx(i-1,j,k-1)+sx(i,j,k-1)
99  +sx(i-1,j-1,k )+sx(i,j-1,k )+sx(i-1,j,k )+sx(i,j,k ))
100  +facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1)+sy(i-1,j,k-1)+sy(i,j,k-1)
101  +sy(i-1,j-1,k )+sy(i,j-1,k )+sy(i-1,j,k )+sy(i,j,k ))
102  +facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)+sz(i-1,j,k-1)+sz(i,j,k-1)
103  +sz(i-1,j-1,k )+sz(i,j-1,k )+sz(i-1,j,k )+sz(i,j,k )));
104  y += x(i-1,j-1,k-1)*(facx*sx(i-1,j-1,k-1)
105  +facy*sy(i-1,j-1,k-1)
106  +facz*sz(i-1,j-1,k-1))
107  + x(i+1,j-1,k-1)*(facx*sx(i ,j-1,k-1)
108  +facy*sy(i ,j-1,k-1)
109  +facz*sz(i ,j-1,k-1))
110  + x(i-1,j+1,k-1)*(facx*sx(i-1,j ,k-1)
111  +facy*sy(i-1,j ,k-1)
112  +facz*sz(i-1,j ,k-1))
113  + x(i+1,j+1,k-1)*(facx*sx(i ,j ,k-1)
114  +facy*sy(i ,j ,k-1)
115  +facz*sz(i ,j ,k-1))
116  + x(i-1,j-1,k+1)*(facx*sx(i-1,j-1,k )
117  +facy*sy(i-1,j-1,k )
118  +facz*sz(i-1,j-1,k ))
119  + x(i+1,j-1,k+1)*(facx*sx(i ,j-1,k )
120  +facy*sy(i ,j-1,k )
121  +facz*sz(i ,j-1,k ))
122  + x(i-1,j+1,k+1)*(facx*sx(i-1,j ,k )
123  +facy*sy(i-1,j ,k )
124  +facz*sz(i-1,j ,k ))
125  + x(i+1,j+1,k+1)*(facx*sx(i ,j ,k )
126  +facy*sy(i ,j ,k )
127  +facz*sz(i ,j ,k ));
128  y += x(i ,j-1,k-1)*( -facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1))
129  +Real(2.0)*facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1))
130  +Real(2.0)*facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)))
131  + x(i ,j+1,k-1)*( -facx*(sx(i-1,j ,k-1)+sx(i,j ,k-1))
132  +Real(2.0)*facy*(sy(i-1,j ,k-1)+sy(i,j ,k-1))
133  +Real(2.0)*facz*(sz(i-1,j ,k-1)+sz(i,j ,k-1)))
134  + x(i ,j-1,k+1)*( -facx*(sx(i-1,j-1,k )+sx(i,j-1,k ))
135  +Real(2.0)*facy*(sy(i-1,j-1,k )+sy(i,j-1,k ))
136  +Real(2.0)*facz*(sz(i-1,j-1,k )+sz(i,j-1,k )))
137  + x(i ,j+1,k+1)*( -facx*(sx(i-1,j ,k )+sx(i,j ,k ))
138  +Real(2.0)*facy*(sy(i-1,j ,k )+sy(i,j ,k ))
139  +Real(2.0)*facz*(sz(i-1,j ,k )+sz(i,j ,k )))
140  + x(i-1,j ,k-1)*( Real(2.0)*facx*(sx(i-1,j-1,k-1)+sx(i-1,j,k-1))
141  -facy*(sy(i-1,j-1,k-1)+sy(i-1,j,k-1))
142  +Real(2.0)*facz*(sz(i-1,j-1,k-1)+sz(i-1,j,k-1)))
143  + x(i+1,j ,k-1)*( Real(2.0)*facx*(sx(i ,j-1,k-1)+sx(i ,j,k-1))
144  -facy*(sy(i ,j-1,k-1)+sy(i ,j,k-1))
145  +Real(2.0)*facz*(sz(i ,j-1,k-1)+sz(i ,j,k-1)))
146  + x(i-1,j ,k+1)*( Real(2.0)*facx*(sx(i-1,j-1,k )+sx(i-1,j,k ))
147  -facy*(sy(i-1,j-1,k )+sy(i-1,j,k ))
148  +Real(2.0)*facz*(sz(i-1,j-1,k )+sz(i-1,j,k )))
149  + x(i+1,j ,k+1)*( Real(2.0)*facx*(sx(i ,j-1,k )+sx(i ,j,k ))
150  -facy*(sy(i ,j-1,k )+sy(i ,j,k ))
151  +Real(2.0)*facz*(sz(i ,j-1,k )+sz(i ,j,k )))
152  + x(i-1,j-1,k )*( Real(2.0)*facx*(sx(i-1,j-1,k-1)+sx(i-1,j-1,k))
153  +Real(2.0)*facy*(sy(i-1,j-1,k-1)+sy(i-1,j-1,k))
154  -facz*(sz(i-1,j-1,k-1)+sz(i-1,j-1,k)))
155  + x(i+1,j-1,k )*( Real(2.0)*facx*(sx(i ,j-1,k-1)+sx(i ,j-1,k))
156  +Real(2.0)*facy*(sy(i ,j-1,k-1)+sy(i ,j-1,k))
157  -facz*(sz(i ,j-1,k-1)+sz(i ,j-1,k)))
158  + x(i-1,j+1,k )*( Real(2.0)*facx*(sx(i-1,j ,k-1)+sx(i-1,j ,k))
159  +Real(2.0)*facy*(sy(i-1,j ,k-1)+sy(i-1,j ,k))
160  -facz*(sz(i-1,j ,k-1)+sz(i-1,j ,k)))
161  + x(i+1,j+1,k )*( Real(2.0)*facx*(sx(i ,j ,k-1)+sx(i ,j ,k))
162  +Real(2.0)*facy*(sy(i ,j ,k-1)+sy(i ,j ,k))
163  -facz*(sz(i ,j ,k-1)+sz(i ,j ,k)));
164  y += Real(2.0)*x(i-1,j,k)*( Real(2.0)*facx*(sx(i-1,j-1,k-1)+sx(i-1,j,k-1)+sx(i-1,j-1,k)+sx(i-1,j,k))
165  -facy*(sy(i-1,j-1,k-1)+sy(i-1,j,k-1)+sy(i-1,j-1,k)+sy(i-1,j,k))
166  -facz*(sz(i-1,j-1,k-1)+sz(i-1,j,k-1)+sz(i-1,j-1,k)+sz(i-1,j,k)))
167  + Real(2.0)*x(i+1,j,k)*( Real(2.0)*facx*(sx(i ,j-1,k-1)+sx(i ,j,k-1)+sx(i ,j-1,k)+sx(i ,j,k))
168  -facy*(sy(i ,j-1,k-1)+sy(i ,j,k-1)+sy(i ,j-1,k)+sy(i ,j,k))
169  -facz*(sz(i ,j-1,k-1)+sz(i ,j,k-1)+sz(i ,j-1,k)+sz(i ,j,k)))
170  + Real(2.0)*x(i,j-1,k)*( -facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1)+sx(i-1,j-1,k)+sx(i,j-1,k))
171  +Real(2.0)*facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1)+sy(i-1,j-1,k)+sy(i,j-1,k))
172  -facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)+sz(i-1,j-1,k)+sz(i,j-1,k)))
173  + Real(2.0)*x(i,j+1,k)*( -facx*(sx(i-1,j ,k-1)+sx(i,j ,k-1)+sx(i-1,j ,k)+sx(i,j ,k))
174  +Real(2.0)*facy*(sy(i-1,j ,k-1)+sy(i,j ,k-1)+sy(i-1,j ,k)+sy(i,j ,k))
175  -facz*(sz(i-1,j ,k-1)+sz(i,j ,k-1)+sz(i-1,j ,k)+sz(i,j ,k)))
176  + Real(2.0)*x(i,j,k-1)*( -facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1)+sx(i-1,j,k-1)+sx(i,j,k-1))
177  -facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1)+sy(i-1,j,k-1)+sy(i,j,k-1))
178  +Real(2.0)*facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)+sz(i-1,j,k-1)+sz(i,j,k-1)))
179  + Real(2.0)*x(i,j,k+1)*( -facx*(sx(i-1,j-1,k )+sx(i,j-1,k )+sx(i-1,j,k )+sx(i,j,k ))
180  -facy*(sy(i-1,j-1,k )+sy(i,j-1,k )+sy(i-1,j,k )+sy(i,j,k ))
181  +Real(2.0)*facz*(sz(i-1,j-1,k )+sz(i,j-1,k )+sz(i-1,j,k )+sz(i,j,k )));
182  return y;
183  }
184 }
185 
187 Real mlndlap_adotx_aa (int i, int j, int k, Array4<Real const> const& x,
188  Array4<Real const> const& sig, Array4<int const> const& msk,
189  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
190 {
191  if (msk(i,j,k)) {
192  return Real(0.0);
193  } else {
194  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
195  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
196  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
197  Real fxyz = facx + facy + facz;
198  Real fmx2y2z = -facx + Real(2.0)*facy + Real(2.0)*facz;
199  Real f2xmy2z = Real(2.0)*facx - facy + Real(2.0)*facz;
200  Real f2x2ymz = Real(2.0)*facx + Real(2.0)*facy - facz;
201  Real f4xm2ym2z = Real(4.0)*facx - Real(2.0)*facy - Real(2.0)*facz;
202  Real fm2x4ym2z = -Real(2.0)*facx + Real(4.0)*facy - Real(2.0)*facz;
203  Real fm2xm2y4z = -Real(2.0)*facx - Real(2.0)*facy + Real(4.0)*facz;
204  return x(i,j,k)*Real(-4.0)*fxyz*
205  (sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1)
206  +sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k ))
207  + fxyz*(x(i-1,j-1,k-1)*sig(i-1,j-1,k-1)
208  + x(i+1,j-1,k-1)*sig(i ,j-1,k-1)
209  + x(i-1,j+1,k-1)*sig(i-1,j ,k-1)
210  + x(i+1,j+1,k-1)*sig(i ,j ,k-1)
211  + x(i-1,j-1,k+1)*sig(i-1,j-1,k )
212  + x(i+1,j-1,k+1)*sig(i ,j-1,k )
213  + x(i-1,j+1,k+1)*sig(i-1,j ,k )
214  + x(i+1,j+1,k+1)*sig(i ,j ,k ))
215  + fmx2y2z*(x(i ,j-1,k-1)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1))
216  + x(i ,j+1,k-1)*(sig(i-1,j ,k-1)+sig(i,j ,k-1))
217  + x(i ,j-1,k+1)*(sig(i-1,j-1,k )+sig(i,j-1,k ))
218  + x(i ,j+1,k+1)*(sig(i-1,j ,k )+sig(i,j ,k )))
219  + f2xmy2z*(x(i-1,j ,k-1)*(sig(i-1,j-1,k-1)+sig(i-1,j,k-1))
220  + x(i+1,j ,k-1)*(sig(i ,j-1,k-1)+sig(i ,j,k-1))
221  + x(i-1,j ,k+1)*(sig(i-1,j-1,k )+sig(i-1,j,k ))
222  + x(i+1,j ,k+1)*(sig(i ,j-1,k )+sig(i ,j,k )))
223  + f2x2ymz*(x(i-1,j-1,k )*(sig(i-1,j-1,k-1)+sig(i-1,j-1,k))
224  + x(i+1,j-1,k )*(sig(i ,j-1,k-1)+sig(i ,j-1,k))
225  + x(i-1,j+1,k )*(sig(i-1,j ,k-1)+sig(i-1,j ,k))
226  + x(i+1,j+1,k )*(sig(i ,j ,k-1)+sig(i ,j ,k)))
227  + f4xm2ym2z*(x(i-1,j,k)*(sig(i-1,j-1,k-1)+sig(i-1,j,k-1)+sig(i-1,j-1,k)+sig(i-1,j,k))
228  + x(i+1,j,k)*(sig(i ,j-1,k-1)+sig(i ,j,k-1)+sig(i ,j-1,k)+sig(i ,j,k)))
229  + fm2x4ym2z*(x(i,j-1,k)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j-1,k)+sig(i,j-1,k))
230  + x(i,j+1,k)*(sig(i-1,j ,k-1)+sig(i,j ,k-1)+sig(i-1,j ,k)+sig(i,j ,k)))
231  + fm2xm2y4z*(x(i,j,k-1)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1))
232  + x(i,j,k+1)*(sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k )));
233  }
234 }
235 
237 Real mlndlap_adotx_c (int i, int j, int k, Array4<Real const> const& x,
238  Real sig, Array4<int const> const& msk,
239  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
240 {
241  if (msk(i,j,k)) {
242  return Real(0.0);
243  } else {
244  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
245  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
246  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
247  Real fxyz = facx + facy + facz;
248  Real fmx2y2z = -facx + Real(2.0)*facy + Real(2.0)*facz;
249  Real f2xmy2z = Real(2.0)*facx - facy + Real(2.0)*facz;
250  Real f2x2ymz = Real(2.0)*facx + Real(2.0)*facy - facz;
251  Real f4xm2ym2z = Real(4.0)*facx - Real(2.0)*facy - Real(2.0)*facz;
252  Real fm2x4ym2z = -Real(2.0)*facx + Real(4.0)*facy - Real(2.0)*facz;
253  Real fm2xm2y4z = -Real(2.0)*facx - Real(2.0)*facy + Real(4.0)*facz;
254  return sig * (x(i,j,k)*Real(-4.0)*fxyz*Real(8.)
255  + fxyz*(x(i-1,j-1,k-1)
256  + x(i+1,j-1,k-1)
257  + x(i-1,j+1,k-1)
258  + x(i+1,j+1,k-1)
259  + x(i-1,j-1,k+1)
260  + x(i+1,j-1,k+1)
261  + x(i-1,j+1,k+1)
262  + x(i+1,j+1,k+1))
263  + fmx2y2z*(x(i ,j-1,k-1)*Real(2.)
264  + x(i ,j+1,k-1)*Real(2.)
265  + x(i ,j-1,k+1)*Real(2.)
266  + x(i ,j+1,k+1)*Real(2.))
267  + f2xmy2z*(x(i-1,j ,k-1)*Real(2.)
268  + x(i+1,j ,k-1)*Real(2.)
269  + x(i-1,j ,k+1)*Real(2.)
270  + x(i+1,j ,k+1)*Real(2.))
271  + f2x2ymz*(x(i-1,j-1,k )*Real(2.)
272  + x(i+1,j-1,k )*Real(2.)
273  + x(i-1,j+1,k )*Real(2.)
274  + x(i+1,j+1,k )*Real(2.))
275  + f4xm2ym2z*(x(i-1,j,k)*Real(4.)
276  + x(i+1,j,k)*Real(4.))
277  + fm2x4ym2z*(x(i,j-1,k)*Real(4.)
278  + x(i,j+1,k)*Real(4.))
279  + fm2xm2y4z*(x(i,j,k-1)*Real(4.)
280  + x(i,j,k+1)*Real(4.)));
281  }
282 }
283 
285 void mlndlap_normalize_ha (int i, int j, int k, Array4<Real> const& x, Array4<Real const> const& sx,
286  Array4<Real const> const& sy, Array4<Real const> const& sz,
287  Array4<int const> const& msk, GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
288 {
289  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
290  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
291  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
292 
293  if (!msk(i,j,k)) {
294  x(i,j,k) = x(i,j,k)/(Real(-4.0)*(facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1)+sx(i-1,j,k-1)+sx(i,j,k-1)
295  +sx(i-1,j-1,k )+sx(i,j-1,k )+sx(i-1,j,k )+sx(i,j,k ))
296  +facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1)+sy(i-1,j,k-1)+sy(i,j,k-1)
297  +sy(i-1,j-1,k )+sy(i,j-1,k )+sy(i-1,j,k )+sy(i,j,k ))
298  +facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)+sz(i-1,j,k-1)+sz(i,j,k-1)
299  +sz(i-1,j-1,k )+sz(i,j-1,k )+sz(i-1,j,k )+sz(i,j,k ))));
300  }
301 }
302 
304 void mlndlap_normalize_aa (int i, int j, int k, Array4<Real> const& x, Array4<Real const> const& sig,
305  Array4<int const> const& msk, GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
306 {
307  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
308  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
309  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
310  Real fxyz = facx + facy + facz;
311 
312  if (!msk(i,j,k)) {
313  x(i,j,k) = x(i,j,k) /
314  (Real(-4.0)*fxyz*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1)
315  +sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k )));
316  }
317 }
318 
320 void mlndlap_jacobi_ha (int i, int j, int k, Array4<Real> const& sol, Real Ax,
321  Array4<Real const> const& rhs, Array4<Real const> const& sx,
322  Array4<Real const> const& sy, Array4<Real const> const& sz,
323  Array4<int const> const& msk, GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
324 {
325  Real facx = Real(-4.0 / 36.0)*dxinv[0]*dxinv[0];
326  Real facy = Real(-4.0 / 36.0)*dxinv[1]*dxinv[1];
327  Real facz = Real(-4.0 / 36.0)*dxinv[2]*dxinv[2];
328 
329  if (msk(i,j,k)) {
330  sol(i,j,k) = Real(0.0);
331  } else {
332  sol(i,j,k) += Real(2.0/3.0) * (rhs(i,j,k) - Ax)
333  / (facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1)+sx(i-1,j,k-1)+sx(i,j,k-1)
334  +sx(i-1,j-1,k )+sx(i,j-1,k )+sx(i-1,j,k )+sx(i,j,k ))
335  +facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1)+sy(i-1,j,k-1)+sy(i,j,k-1)
336  +sy(i-1,j-1,k )+sy(i,j-1,k )+sy(i-1,j,k )+sy(i,j,k ))
337  +facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)+sz(i-1,j,k-1)+sz(i,j,k-1)
338  +sz(i-1,j-1,k )+sz(i,j-1,k )+sz(i-1,j,k )+sz(i,j,k )));
339  }
340 }
341 
342 inline
343 void mlndlap_jacobi_ha (Box const& bx, Array4<Real> const& sol, Array4<Real const> const& Ax,
344  Array4<Real const> const& rhs, Array4<Real const> const& sx,
345  Array4<Real const> const& sy, Array4<Real const> const& sz,
346  Array4<int const> const& msk, GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
347 {
348  Real facx = Real(-4.0 / 36.0)*dxinv[0]*dxinv[0];
349  Real facy = Real(-4.0 / 36.0)*dxinv[1]*dxinv[1];
350  Real facz = Real(-4.0 / 36.0)*dxinv[2]*dxinv[2];
351 
352  amrex::LoopConcurrentOnCpu(bx, [&] (int i, int j, int k) noexcept
353  {
354  if (msk(i,j,k)) {
355  sol(i,j,k) = Real(0.0);
356  } else {
357  sol(i,j,k) += Real(2.0/3.0) * (rhs(i,j,k) - Ax(i,j,k))
358  / (facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1)+sx(i-1,j,k-1)+sx(i,j,k-1)
359  +sx(i-1,j-1,k )+sx(i,j-1,k )+sx(i-1,j,k )+sx(i,j,k ))
360  +facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1)+sy(i-1,j,k-1)+sy(i,j,k-1)
361  +sy(i-1,j-1,k )+sy(i,j-1,k )+sy(i-1,j,k )+sy(i,j,k ))
362  +facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)+sz(i-1,j,k-1)+sz(i,j,k-1)
363  +sz(i-1,j-1,k )+sz(i,j-1,k )+sz(i-1,j,k )+sz(i,j,k )));
364  }
365  });
366 }
367 
369 void mlndlap_jacobi_aa (int i, int j, int k, Array4<Real> const& sol, Real Ax,
370  Array4<Real const> const& rhs, Array4<Real const> const& sig,
371  Array4<int const> const& msk, GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
372 {
373  Real fxyz = Real(-4.0 / 36.0)*(dxinv[0]*dxinv[0] +
374  dxinv[1]*dxinv[1] +
375  dxinv[2]*dxinv[2]);
376 
377  if (msk(i,j,k)) {
378  sol(i,j,k) = Real(0.0);
379  } else {
380  sol(i,j,k) += Real(2.0/3.0) * (rhs(i,j,k) - Ax)
381  / (fxyz*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1)
382  +sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k )));
383  }
384 }
385 
387 void mlndlap_jacobi_c (int i, int j, int k, Array4<Real> const& sol, Real Ax,
388  Array4<Real const> const& rhs, Real sig,
389  Array4<int const> const& msk, GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
390 {
391  Real fxyz = Real(-4.0 / 36.0)*(dxinv[0]*dxinv[0] +
392  dxinv[1]*dxinv[1] +
393  dxinv[2]*dxinv[2]);
394 
395  if (msk(i,j,k)) {
396  sol(i,j,k) = Real(0.0);
397  } else {
398  sol(i,j,k) += Real(2.0/3.0) * (rhs(i,j,k) - Ax)
399  / (fxyz*Real(8.)*sig);
400  }
401 }
402 
403 inline
404 void mlndlap_jacobi_aa (Box const& bx, Array4<Real> const& sol, Array4<Real const> const& Ax,
405  Array4<Real const> const& rhs, Array4<Real const> const& sig,
406  Array4<int const> const& msk, GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
407 {
408  Real fxyz = Real(-4.0 / 36.0)*(dxinv[0]*dxinv[0] +
409  dxinv[1]*dxinv[1] +
410  dxinv[2]*dxinv[2]);
411 
412  amrex::LoopConcurrentOnCpu(bx, [&] (int i, int j, int k) noexcept
413  {
414  if (msk(i,j,k)) {
415  sol(i,j,k) = Real(0.0);
416  } else {
417  sol(i,j,k) += Real(2.0/3.0) * (rhs(i,j,k) - Ax(i,j,k))
418  / (fxyz*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1)
419  +sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k )));
420  }
421  });
422 }
423 
424 inline
425 void mlndlap_jacobi_c (Box const& bx, Array4<Real> const& sol, Array4<Real const> const& Ax,
426  Array4<Real const> const& rhs, Real sig,
427  Array4<int const> const& msk, GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
428 {
429  Real fxyz = Real(-4.0 / 36.0)*(dxinv[0]*dxinv[0] +
430  dxinv[1]*dxinv[1] +
431  dxinv[2]*dxinv[2]);
432 
433  amrex::LoopConcurrentOnCpu(bx, [&] (int i, int j, int k) noexcept
434  {
435  if (msk(i,j,k)) {
436  sol(i,j,k) = Real(0.0);
437  } else {
438  sol(i,j,k) += Real(2.0/3.0) * (rhs(i,j,k) - Ax(i,j,k))
439  / (fxyz*Real(8.)*sig);
440  }
441  });
442 }
443 
444 inline
445 void mlndlap_gauss_seidel_ha (Box const& bx, Array4<Real> const& sol,
446  Array4<Real const> const& rhs, Array4<Real const> const& sx,
447  Array4<Real const> const& sy, Array4<Real const> const& sz,
448  Array4<int const> const& msk,
449  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
450 {
451  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
452  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
453  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
454 
455  amrex::LoopOnCpu(bx, [&] (int i, int j, int k) noexcept
456  {
457  if (msk(i,j,k)) {
458  sol(i,j,k) = Real(0.0);
459  } else {
460  Real s0 = Real(-4.0)*(facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1)+sx(i-1,j,k-1)+sx(i,j,k-1)
461  +sx(i-1,j-1,k )+sx(i,j-1,k )+sx(i-1,j,k )+sx(i,j,k ))
462  +facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1)+sy(i-1,j,k-1)+sy(i,j,k-1)
463  +sy(i-1,j-1,k )+sy(i,j-1,k )+sy(i-1,j,k )+sy(i,j,k ))
464  +facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)+sz(i-1,j,k-1)+sz(i,j,k-1)
465  +sz(i-1,j-1,k )+sz(i,j-1,k )+sz(i-1,j,k )+sz(i,j,k )));
466  Real Ax = sol(i,j,k)*s0
467  + sol(i-1,j-1,k-1)*(facx*sx(i-1,j-1,k-1)
468  +facy*sy(i-1,j-1,k-1)
469  +facz*sz(i-1,j-1,k-1))
470  + sol(i+1,j-1,k-1)*(facx*sx(i ,j-1,k-1)
471  +facy*sy(i ,j-1,k-1)
472  +facz*sz(i ,j-1,k-1))
473  + sol(i-1,j+1,k-1)*(facx*sx(i-1,j ,k-1)
474  +facy*sy(i-1,j ,k-1)
475  +facz*sz(i-1,j ,k-1))
476  + sol(i+1,j+1,k-1)*(facx*sx(i ,j ,k-1)
477  +facy*sy(i ,j ,k-1)
478  +facz*sz(i ,j ,k-1))
479  + sol(i-1,j-1,k+1)*(facx*sx(i-1,j-1,k )
480  +facy*sy(i-1,j-1,k )
481  +facz*sz(i-1,j-1,k ))
482  + sol(i+1,j-1,k+1)*(facx*sx(i ,j-1,k )
483  +facy*sy(i ,j-1,k )
484  +facz*sz(i ,j-1,k ))
485  + sol(i-1,j+1,k+1)*(facx*sx(i-1,j ,k )
486  +facy*sy(i-1,j ,k )
487  +facz*sz(i-1,j ,k ))
488  + sol(i+1,j+1,k+1)*(facx*sx(i ,j ,k )
489  +facy*sy(i ,j ,k )
490  +facz*sz(i ,j ,k ))
491  +sol(i ,j-1,k-1)*( -facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1))
492  +Real(2.0)*facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1))
493  +Real(2.0)*facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)))
494  +sol(i ,j+1,k-1)*( -facx*(sx(i-1,j ,k-1)+sx(i,j ,k-1))
495  +Real(2.0)*facy*(sy(i-1,j ,k-1)+sy(i,j ,k-1))
496  +Real(2.0)*facz*(sz(i-1,j ,k-1)+sz(i,j ,k-1)))
497  +sol(i ,j-1,k+1)*( -facx*(sx(i-1,j-1,k )+sx(i,j-1,k ))
498  +Real(2.0)*facy*(sy(i-1,j-1,k )+sy(i,j-1,k ))
499  +Real(2.0)*facz*(sz(i-1,j-1,k )+sz(i,j-1,k )))
500  +sol(i ,j+1,k+1)*( -facx*(sx(i-1,j ,k )+sx(i,j ,k ))
501  +Real(2.0)*facy*(sy(i-1,j ,k )+sy(i,j ,k ))
502  +Real(2.0)*facz*(sz(i-1,j ,k )+sz(i,j ,k )))
503  +sol(i-1,j ,k-1)*( Real(2.0)*facx*(sx(i-1,j-1,k-1)+sx(i-1,j,k-1))
504  -facy*(sy(i-1,j-1,k-1)+sy(i-1,j,k-1))
505  +Real(2.0)*facz*(sz(i-1,j-1,k-1)+sz(i-1,j,k-1)))
506  +sol(i+1,j ,k-1)*( Real(2.0)*facx*(sx(i ,j-1,k-1)+sx(i ,j,k-1))
507  -facy*(sy(i ,j-1,k-1)+sy(i ,j,k-1))
508  +Real(2.0)*facz*(sz(i ,j-1,k-1)+sz(i ,j,k-1)))
509  +sol(i-1,j ,k+1)*( Real(2.0)*facx*(sx(i-1,j-1,k )+sx(i-1,j,k ))
510  -facy*(sy(i-1,j-1,k )+sy(i-1,j,k ))
511  +Real(2.0)*facz*(sz(i-1,j-1,k )+sz(i-1,j,k )))
512  +sol(i+1,j ,k+1)*( Real(2.0)*facx*(sx(i ,j-1,k )+sx(i ,j,k ))
513  -facy*(sy(i ,j-1,k )+sy(i ,j,k ))
514  +Real(2.0)*facz*(sz(i ,j-1,k )+sz(i ,j,k )))
515  +sol(i-1,j-1,k )*( Real(2.0)*facx*(sx(i-1,j-1,k-1)+sx(i-1,j-1,k))
516  +Real(2.0)*facy*(sy(i-1,j-1,k-1)+sy(i-1,j-1,k))
517  -facz*(sz(i-1,j-1,k-1)+sz(i-1,j-1,k)))
518  +sol(i+1,j-1,k )*( Real(2.0)*facx*(sx(i ,j-1,k-1)+sx(i ,j-1,k))
519  +Real(2.0)*facy*(sy(i ,j-1,k-1)+sy(i ,j-1,k))
520  -facz*(sz(i ,j-1,k-1)+sz(i ,j-1,k)))
521  +sol(i-1,j+1,k )*( Real(2.0)*facx*(sx(i-1,j ,k-1)+sx(i-1,j ,k))
522  +Real(2.0)*facy*(sy(i-1,j ,k-1)+sy(i-1,j ,k))
523  -facz*(sz(i-1,j ,k-1)+sz(i-1,j ,k)))
524  +sol(i+1,j+1,k )*( Real(2.0)*facx*(sx(i ,j ,k-1)+sx(i ,j ,k))
525  +Real(2.0)*facy*(sy(i ,j ,k-1)+sy(i ,j ,k))
526  -facz*(sz(i ,j ,k-1)+sz(i ,j ,k)))
527  + Real(2.0)*sol(i-1,j,k)*(Real(2.0)*facx*(sx(i-1,j-1,k-1)+sx(i-1,j,k-1)+sx(i-1,j-1,k)+sx(i-1,j,k))
528  -facy*(sy(i-1,j-1,k-1)+sy(i-1,j,k-1)+sy(i-1,j-1,k)+sy(i-1,j,k))
529  -facz*(sz(i-1,j-1,k-1)+sz(i-1,j,k-1)+sz(i-1,j-1,k)+sz(i-1,j,k)))
530  + Real(2.0)*sol(i+1,j,k)*(Real(2.0)*facx*(sx(i ,j-1,k-1)+sx(i ,j,k-1)+sx(i ,j-1,k)+sx(i ,j,k))
531  -facy*(sy(i ,j-1,k-1)+sy(i ,j,k-1)+sy(i ,j-1,k)+sy(i ,j,k))
532  -facz*(sz(i ,j-1,k-1)+sz(i ,j,k-1)+sz(i ,j-1,k)+sz(i ,j,k)))
533  + Real(2.0)*sol(i,j-1,k)*( -facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1)+sx(i-1,j-1,k)+sx(i,j-1,k))
534  +Real(2.0)*facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1)+sy(i-1,j-1,k)+sy(i,j-1,k))
535  -facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)+sz(i-1,j-1,k)+sz(i,j-1,k)))
536  + Real(2.0)*sol(i,j+1,k)*( -facx*(sx(i-1,j ,k-1)+sx(i,j ,k-1)+sx(i-1,j ,k)+sx(i,j ,k))
537  +Real(2.0)*facy*(sy(i-1,j ,k-1)+sy(i,j ,k-1)+sy(i-1,j ,k)+sy(i,j ,k))
538  -facz*(sz(i-1,j ,k-1)+sz(i,j ,k-1)+sz(i-1,j ,k)+sz(i,j ,k)))
539  + Real(2.0)*sol(i,j,k-1)*( -facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1)+sx(i-1,j,k-1)+sx(i,j,k-1))
540  -facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1)+sy(i-1,j,k-1)+sy(i,j,k-1))
541  +Real(2.0)*facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)+sz(i-1,j,k-1)+sz(i,j,k-1)))
542  + Real(2.0)*sol(i,j,k+1)*( -facx*(sx(i-1,j-1,k )+sx(i,j-1,k )+sx(i-1,j,k )+sx(i,j,k ))
543  -facy*(sy(i-1,j-1,k )+sy(i,j-1,k )+sy(i-1,j,k )+sy(i,j,k ))
544  +Real(2.0)*facz*(sz(i-1,j-1,k )+sz(i,j-1,k )+sz(i-1,j,k )+sz(i,j,k )));
545 
546  sol(i,j,k) += (rhs(i,j,k) - Ax) / s0;
547  }
548  });
549 }
550 
551 inline
552 void mlndlap_gauss_seidel_aa (Box const& bx, Array4<Real> const& sol,
553  Array4<Real const> const& rhs, Array4<Real const> const& sig,
554  Array4<int const> const& msk,
555  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
556 {
557  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
558  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
559  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
560  Real fxyz = facx + facy + facz;
561  Real fmx2y2z = -facx + Real(2.0)*facy + Real(2.0)*facz;
562  Real f2xmy2z = Real(2.0)*facx - facy + Real(2.0)*facz;
563  Real f2x2ymz = Real(2.0)*facx + Real(2.0)*facy - facz;
564  Real f4xm2ym2z = Real(4.0)*facx - Real(2.0)*facy - Real(2.0)*facz;
565  Real fm2x4ym2z = -Real(2.0)*facx + Real(4.0)*facy - Real(2.0)*facz;
566  Real fm2xm2y4z = -Real(2.0)*facx - Real(2.0)*facy + Real(4.0)*facz;
567 
568  amrex::LoopOnCpu(bx, [&] (int i, int j, int k) noexcept
569  {
570  if (msk(i,j,k)) {
571  sol(i,j,k) = Real(0.0);
572  } else {
573  Real s0 = Real(-4.0)*fxyz*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1)
574  +sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k ));
575  Real Ax = sol(i,j,k)*s0
576  + fxyz*(sol(i-1,j-1,k-1)*sig(i-1,j-1,k-1)
577  + sol(i+1,j-1,k-1)*sig(i ,j-1,k-1)
578  + sol(i-1,j+1,k-1)*sig(i-1,j ,k-1)
579  + sol(i+1,j+1,k-1)*sig(i ,j ,k-1)
580  + sol(i-1,j-1,k+1)*sig(i-1,j-1,k )
581  + sol(i+1,j-1,k+1)*sig(i ,j-1,k )
582  + sol(i-1,j+1,k+1)*sig(i-1,j ,k )
583  + sol(i+1,j+1,k+1)*sig(i ,j ,k ))
584  + fmx2y2z*(sol(i ,j-1,k-1)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1))
585  + sol(i ,j+1,k-1)*(sig(i-1,j ,k-1)+sig(i,j ,k-1))
586  + sol(i ,j-1,k+1)*(sig(i-1,j-1,k )+sig(i,j-1,k ))
587  + sol(i ,j+1,k+1)*(sig(i-1,j ,k )+sig(i,j ,k )))
588  + f2xmy2z*(sol(i-1,j ,k-1)*(sig(i-1,j-1,k-1)+sig(i-1,j,k-1))
589  + sol(i+1,j ,k-1)*(sig(i ,j-1,k-1)+sig(i ,j,k-1))
590  + sol(i-1,j ,k+1)*(sig(i-1,j-1,k )+sig(i-1,j,k ))
591  + sol(i+1,j ,k+1)*(sig(i ,j-1,k )+sig(i ,j,k )))
592  + f2x2ymz*(sol(i-1,j-1,k )*(sig(i-1,j-1,k-1)+sig(i-1,j-1,k))
593  + sol(i+1,j-1,k )*(sig(i ,j-1,k-1)+sig(i ,j-1,k))
594  + sol(i-1,j+1,k )*(sig(i-1,j ,k-1)+sig(i-1,j ,k))
595  + sol(i+1,j+1,k )*(sig(i ,j ,k-1)+sig(i ,j ,k)))
596  + f4xm2ym2z*(sol(i-1,j,k)*(sig(i-1,j-1,k-1)+sig(i-1,j,k-1)+sig(i-1,j-1,k)+sig(i-1,j,k))
597  + sol(i+1,j,k)*(sig(i ,j-1,k-1)+sig(i ,j,k-1)+sig(i ,j-1,k)+sig(i ,j,k)))
598  + fm2x4ym2z*(sol(i,j-1,k)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j-1,k)+sig(i,j-1,k))
599  + sol(i,j+1,k)*(sig(i-1,j ,k-1)+sig(i,j ,k-1)+sig(i-1,j ,k)+sig(i,j ,k)))
600  + fm2xm2y4z*(sol(i,j,k-1)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1))
601  + sol(i,j,k+1)*(sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k )));
602 
603  sol(i,j,k) += (rhs(i,j,k) - Ax) / s0;
604  }
605  });
606 }
607 
608 inline
609 void mlndlap_gauss_seidel_c (Box const& bx, Array4<Real> const& sol,
610  Array4<Real const> const& rhs, Real sig,
611  Array4<int const> const& msk,
612  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
613 {
614  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
615  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
616  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
617  Real fxyz = facx + facy + facz;
618  Real fmx2y2z = -facx + Real(2.0)*facy + Real(2.0)*facz;
619  Real f2xmy2z = Real(2.0)*facx - facy + Real(2.0)*facz;
620  Real f2x2ymz = Real(2.0)*facx + Real(2.0)*facy - facz;
621  Real f4xm2ym2z = Real(4.0)*facx - Real(2.0)*facy - Real(2.0)*facz;
622  Real fm2x4ym2z = -Real(2.0)*facx + Real(4.0)*facy - Real(2.0)*facz;
623  Real fm2xm2y4z = -Real(2.0)*facx - Real(2.0)*facy + Real(4.0)*facz;
624 
625  amrex::LoopOnCpu(bx, [&] (int i, int j, int k) noexcept
626  {
627  if (msk(i,j,k)) {
628  sol(i,j,k) = Real(0.0);
629  } else {
630  Real s0 = Real(-4.0)*fxyz*Real(8.);
631  Real Ax = sol(i,j,k)*s0
632  + fxyz*(sol(i-1,j-1,k-1)
633  + sol(i+1,j-1,k-1)
634  + sol(i-1,j+1,k-1)
635  + sol(i+1,j+1,k-1)
636  + sol(i-1,j-1,k+1)
637  + sol(i+1,j-1,k+1)
638  + sol(i-1,j+1,k+1)
639  + sol(i+1,j+1,k+1))
640  + fmx2y2z*(sol(i ,j-1,k-1)*Real(2.)
641  + sol(i ,j+1,k-1)*Real(2.)
642  + sol(i ,j-1,k+1)*Real(2.)
643  + sol(i ,j+1,k+1)*Real(2.))
644  + f2xmy2z*(sol(i-1,j ,k-1)*Real(2.)
645  + sol(i+1,j ,k-1)*Real(2.)
646  + sol(i-1,j ,k+1)*Real(2.)
647  + sol(i+1,j ,k+1)*Real(2.))
648  + f2x2ymz*(sol(i-1,j-1,k )*Real(2.)
649  + sol(i+1,j-1,k )*Real(2.)
650  + sol(i-1,j+1,k )*Real(2.)
651  + sol(i+1,j+1,k )*Real(2.))
652  + f4xm2ym2z*(sol(i-1,j,k)*Real(4.)
653  + sol(i+1,j,k)*Real(4.))
654  + fm2x4ym2z*(sol(i,j-1,k)*Real(4.)
655  + sol(i,j+1,k)*Real(4.))
656  + fm2xm2y4z*(sol(i,j,k-1)*Real(4.)
657  + sol(i,j,k+1)*Real(4.));
658 
659  sol(i,j,k) += (rhs(i,j,k) - Ax*sig) / (s0*sig);
660  }
661  });
662 }
663 
665 void tridiagonal_solve (Array1D<Real,0,31>& a_ls, Array1D<Real,0,31>& b_ls, Array1D<Real,0,31>& c_ls,
666  Array1D<Real,0,31>& r_ls, Array1D<Real,0,31>& u_ls, Array1D<Real,0,31>& gam,
667  int ilen ) noexcept
668 {
669  Real bet = b_ls(0);
670  u_ls(0) = r_ls(0) / bet;
671 
672  for (int i = 1; i <= ilen - 1; i++) {
673  gam(i) = c_ls(i-1) / bet;
674  bet = b_ls(i) - a_ls(i)*gam(i);
675  if (bet == 0) { amrex::Abort(">>>TRIDIAG FAILED"); }
676  u_ls(i) = (r_ls(i)-a_ls(i)*u_ls(i-1)) / bet;
677  }
678  for (int i = ilen-2; i >= 0; i--) {
679  u_ls(i) = u_ls(i) - gam(i+1)*u_ls(i+1);
680  }
681 }
682 
683 inline
684 void mlndlap_gauss_seidel_with_line_solve_aa (Box const& bx, Array4<Real> const& sol,
685  Array4<Real const> const& rhs, Array4<Real const> const& sig,
686  Array4<int const> const& msk,
687  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
688 {
689  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
690  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
691  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
692  Real fxyz = facx + facy + facz;
693  Real fmx2y2z = -facx + Real(2.0)*facy + Real(2.0)*facz;
694  Real f2xmy2z = Real(2.0)*facx - facy + Real(2.0)*facz;
695  Real f2x2ymz = Real(2.0)*facx + Real(2.0)*facy - facz;
696  Real f4xm2ym2z = Real(4.0)*facx - Real(2.0)*facy - Real(2.0)*facz;
697  Real fm2x4ym2z = -Real(2.0)*facx + Real(4.0)*facy - Real(2.0)*facz;
698  Real fm2xm2y4z = -Real(2.0)*facx - Real(2.0)*facy + Real(4.0)*facz;
699 
700  const auto lo = amrex::lbound(bx);
701  const auto hi = amrex::ubound(bx);
702 
703  int idir = -1;
704  int ilen = 33;
705 
706  if ( (dxinv[0] <= dxinv[2]) && (dxinv[1] <= dxinv[2]) ) {
707  idir = 2;
708  ilen = hi.z - lo.z + 1;
709  }
710  if ( (dxinv[0] <= dxinv[1]) && (dxinv[2] <= dxinv[1]) ) {
711  idir = 1;
712  ilen = hi.y - lo.y + 1;
713  }
714  if ( (dxinv[1] <= dxinv[0]) && (dxinv[2] <= dxinv[0]) ) {
715  idir = 0;
716  ilen = hi.x - lo.x + 1;
717  }
718 
719  if (ilen > 32) {
720  amrex::Abort("mlndlap_gauss_seidel_with_line_solve_aa is hard-wired to be no longer than 32");
721  }
722 
723  Array1D<Real,0,31> a_ls,b_ls,c_ls,u_ls,r_ls,gam;
724 
725 
726  if ( idir == 2 )
727  {
728  for (int j = lo.y; j <= hi.y; ++j)
729  {
730  for (int i = lo.x; i <= hi.x; ++i)
731  {
732  for (int k = lo.z; k <= hi.z; ++k)
733  {
734  if (msk(i,j,k))
735  {
736  a_ls(k-lo.z) = Real(0.);
737  b_ls(k-lo.z) = Real(1.);
738  c_ls(k-lo.z) = Real(0.);
739  u_ls(k-lo.z) = Real(0.);
740  r_ls(k-lo.z) = Real(0.);
741  }
742  else
743  {
744  Real s0 = Real(-4.0)*fxyz*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1)
745  + sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k ));
746 
747  Real Ax = fxyz*(sol(i-1,j-1,k-1)*sig(i-1,j-1,k-1)
748  + sol(i+1,j-1,k-1)*sig(i ,j-1,k-1)
749  + sol(i-1,j+1,k-1)*sig(i-1,j ,k-1)
750  + sol(i+1,j+1,k-1)*sig(i ,j ,k-1)
751  + sol(i-1,j-1,k+1)*sig(i-1,j-1,k )
752  + sol(i+1,j-1,k+1)*sig(i ,j-1,k )
753  + sol(i-1,j+1,k+1)*sig(i-1,j ,k )
754  + sol(i+1,j+1,k+1)*sig(i ,j ,k ))
755  + fmx2y2z*(sol(i ,j-1,k-1)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1))
756  + sol(i ,j+1,k-1)*(sig(i-1,j ,k-1)+sig(i,j ,k-1))
757  + sol(i ,j-1,k+1)*(sig(i-1,j-1,k )+sig(i,j-1,k ))
758  + sol(i ,j+1,k+1)*(sig(i-1,j ,k )+sig(i,j ,k )))
759  + f2xmy2z*(sol(i-1,j ,k-1)*(sig(i-1,j-1,k-1)+sig(i-1,j,k-1))
760  + sol(i+1,j ,k-1)*(sig(i ,j-1,k-1)+sig(i ,j,k-1))
761  + sol(i-1,j ,k+1)*(sig(i-1,j-1,k )+sig(i-1,j,k ))
762  + sol(i+1,j ,k+1)*(sig(i ,j-1,k )+sig(i ,j,k )))
763  + f2x2ymz*(sol(i-1,j-1,k )*(sig(i-1,j-1,k-1)+sig(i-1,j-1,k))
764  + sol(i+1,j-1,k )*(sig(i ,j-1,k-1)+sig(i ,j-1,k))
765  + sol(i-1,j+1,k )*(sig(i-1,j ,k-1)+sig(i-1,j ,k))
766  + sol(i+1,j+1,k )*(sig(i ,j ,k-1)+sig(i ,j ,k)))
767  + f4xm2ym2z*(sol(i-1,j,k)*(sig(i-1,j-1,k-1)+sig(i-1,j,k-1)+sig(i-1,j-1,k)+sig(i-1,j,k))
768  + sol(i+1,j,k)*(sig(i ,j-1,k-1)+sig(i ,j,k-1)+sig(i ,j-1,k)+sig(i ,j,k)))
769  + fm2x4ym2z*(sol(i,j-1,k)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j-1,k)+sig(i,j-1,k))
770  + sol(i,j+1,k)*(sig(i-1,j ,k-1)+sig(i,j ,k-1)+sig(i-1,j ,k)+sig(i,j ,k)));
771 
772  a_ls(k-lo.z) = fm2xm2y4z*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1));
773  b_ls(k-lo.z) = s0;
774  c_ls(k-lo.z) = fm2xm2y4z*(sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k ));
775  u_ls(k-lo.z) = Real(0.);
776  r_ls(k-lo.z) = rhs(i,j,k) - Ax;
777  }
778  }
779  tridiagonal_solve(a_ls, b_ls, c_ls, r_ls, u_ls, gam, ilen);
780 
781  for (int k = lo.z; k <= hi.z; ++k)
782  {
783  sol(i,j,k) = u_ls(k-lo.z);
784  }
785  }
786  }
787  }
788  else if (idir == 1)
789  {
790  for (int k = lo.z; k <= hi.z; ++k)
791  {
792  for (int i = lo.x; i <= hi.x; ++i)
793  {
794  for (int j = lo.y; j <= hi.y; ++j)
795  {
796  if (msk(i,j,k)) {
797  a_ls(j-lo.y) = Real(0.);
798  b_ls(j-lo.y) = Real(1.);
799  c_ls(j-lo.y) = Real(0.);
800  u_ls(j-lo.y) = Real(0.);
801  r_ls(j-lo.y) = Real(0.);
802  }
803  else
804  {
805  Real s0 = Real(-4.0)*fxyz*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1)
806  + sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k ));
807 
808  Real Ax = fxyz*(sol(i-1,j-1,k-1)*sig(i-1,j-1,k-1)
809  + sol(i+1,j-1,k-1)*sig(i ,j-1,k-1)
810  + sol(i-1,j+1,k-1)*sig(i-1,j ,k-1)
811  + sol(i+1,j+1,k-1)*sig(i ,j ,k-1)
812  + sol(i-1,j-1,k+1)*sig(i-1,j-1,k )
813  + sol(i+1,j-1,k+1)*sig(i ,j-1,k )
814  + sol(i-1,j+1,k+1)*sig(i-1,j ,k )
815  + sol(i+1,j+1,k+1)*sig(i ,j ,k ))
816  + fmx2y2z*(sol(i ,j-1,k-1)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1))
817  + sol(i ,j+1,k-1)*(sig(i-1,j ,k-1)+sig(i,j ,k-1))
818  + sol(i ,j-1,k+1)*(sig(i-1,j-1,k )+sig(i,j-1,k ))
819  + sol(i ,j+1,k+1)*(sig(i-1,j ,k )+sig(i,j ,k )))
820  + f2xmy2z*(sol(i-1,j ,k-1)*(sig(i-1,j-1,k-1)+sig(i-1,j,k-1))
821  + sol(i+1,j ,k-1)*(sig(i ,j-1,k-1)+sig(i ,j,k-1))
822  + sol(i-1,j ,k+1)*(sig(i-1,j-1,k )+sig(i-1,j,k ))
823  + sol(i+1,j ,k+1)*(sig(i ,j-1,k )+sig(i ,j,k )))
824  + f2x2ymz*(sol(i-1,j-1,k )*(sig(i-1,j-1,k-1)+sig(i-1,j-1,k))
825  + sol(i+1,j-1,k )*(sig(i ,j-1,k-1)+sig(i ,j-1,k))
826  + sol(i-1,j+1,k )*(sig(i-1,j ,k-1)+sig(i-1,j ,k))
827  + sol(i+1,j+1,k )*(sig(i ,j ,k-1)+sig(i ,j ,k)))
828  + f4xm2ym2z*(sol(i-1,j,k)*(sig(i-1,j-1,k-1)+sig(i-1,j,k-1)+sig(i-1,j-1,k)+sig(i-1,j,k))
829  + sol(i+1,j,k)*(sig(i ,j-1,k-1)+sig(i ,j,k-1)+sig(i ,j-1,k)+sig(i ,j,k)))
830  + fm2xm2y4z*(sol(i,j,k-1)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1))
831  + sol(i,j,k+1)*(sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k )));
832 
833  a_ls(j-lo.y) = fm2x4ym2z*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j-1,k)+sig(i,j-1,k));
834  b_ls(j-lo.y) = s0;
835  c_ls(j-lo.y) = fm2x4ym2z*(sig(i-1,j ,k-1)+sig(i,j ,k-1)+sig(i-1,j ,k)+sig(i,j ,k));
836  u_ls(j-lo.y) = Real(0.);
837  r_ls(j-lo.y) = rhs(i,j,k) - Ax;
838 
839  }
840  }
841  tridiagonal_solve(a_ls, b_ls, c_ls, r_ls, u_ls, gam, ilen);
842 
843  for (int j = lo.y; j <= hi.y; ++j)
844  {
845  sol(i,j,k) = u_ls(j-lo.y);
846  }
847  }
848  }
849  }
850  else if (idir == 0)
851  {
852  for (int j = lo.y; j <= hi.y; ++j)
853  {
854  for (int k = lo.z; k <= hi.z; ++k)
855  {
856  for (int i = lo.x; i <= hi.x; ++i)
857  {
858  if (msk(i,j,k))
859  {
860  a_ls(i-lo.x) = Real(0.);
861  b_ls(i-lo.x) = Real(1.);
862  c_ls(i-lo.x) = Real(0.);
863  u_ls(i-lo.x) = Real(0.);
864  r_ls(i-lo.x) = Real(0.);
865  }
866  else
867  {
868  Real s0 = Real(-4.0)*fxyz*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1)
869  + sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k ));
870 
871  Real Ax = fxyz*(sol(i-1,j-1,k-1)*sig(i-1,j-1,k-1)
872  + sol(i+1,j-1,k-1)*sig(i ,j-1,k-1)
873  + sol(i-1,j+1,k-1)*sig(i-1,j ,k-1)
874  + sol(i+1,j+1,k-1)*sig(i ,j ,k-1)
875  + sol(i-1,j-1,k+1)*sig(i-1,j-1,k )
876  + sol(i+1,j-1,k+1)*sig(i ,j-1,k )
877  + sol(i-1,j+1,k+1)*sig(i-1,j ,k )
878  + sol(i+1,j+1,k+1)*sig(i ,j ,k ))
879  + fmx2y2z*(sol(i ,j-1,k-1)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1))
880  + sol(i ,j+1,k-1)*(sig(i-1,j ,k-1)+sig(i,j ,k-1))
881  + sol(i ,j-1,k+1)*(sig(i-1,j-1,k )+sig(i,j-1,k ))
882  + sol(i ,j+1,k+1)*(sig(i-1,j ,k )+sig(i,j ,k )))
883  + f2xmy2z*(sol(i-1,j ,k-1)*(sig(i-1,j-1,k-1)+sig(i-1,j,k-1))
884  + sol(i+1,j ,k-1)*(sig(i ,j-1,k-1)+sig(i ,j,k-1))
885  + sol(i-1,j ,k+1)*(sig(i-1,j-1,k )+sig(i-1,j,k ))
886  + sol(i+1,j ,k+1)*(sig(i ,j-1,k )+sig(i ,j,k )))
887  + f2x2ymz*(sol(i-1,j-1,k )*(sig(i-1,j-1,k-1)+sig(i-1,j-1,k))
888  + sol(i+1,j-1,k )*(sig(i ,j-1,k-1)+sig(i ,j-1,k))
889  + sol(i-1,j+1,k )*(sig(i-1,j ,k-1)+sig(i-1,j ,k))
890  + sol(i+1,j+1,k )*(sig(i ,j ,k-1)+sig(i ,j ,k)))
891  + fm2x4ym2z*(sol(i,j-1,k)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j-1,k)+sig(i,j-1,k))
892  + sol(i,j+1,k)*(sig(i-1,j ,k-1)+sig(i,j ,k-1)+sig(i-1,j ,k)+sig(i,j ,k)))
893  + fm2xm2y4z*(sol(i,j,k-1)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1))
894  + sol(i,j,k+1)*(sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k )));
895 
896  a_ls(i-lo.x) = f4xm2ym2z*(sig(i-1,j-1,k-1)+sig(i-1,j,k-1)+sig(i-1,j-1,k)+sig(i-1,j,k));
897  b_ls(i-lo.x) = s0;
898  c_ls(i-lo.x) = f4xm2ym2z*(sig(i ,j-1,k-1)+sig(i ,j,k-1)+sig(i ,j-1,k)+sig(i ,j,k));
899  u_ls(i-lo.x) = Real(0.);
900  r_ls(i-lo.x) = rhs(i,j,k) - Ax;
901  }
902  }
903  tridiagonal_solve(a_ls, b_ls, c_ls, r_ls, u_ls, gam, ilen);
904 
905  for (int i = lo.x; i <= hi.x; ++i)
906  {
907  sol(i,j,k) = u_ls(i-lo.x);
908  }
909  }
910  }
911  }
912  else
913  {
914  amrex::Abort("mlndlap_gauss_seidel_with_line_solve_aa is wrong direction.");
915  }
916 }
917 
918 //
919 // interpolation
920 //
921 
924  int i, int j, int k, int ic, int jc, int kc) noexcept
925  {
926  Real w1 = sig(i-1,j-1,k-1) + sig(i-1,j,k-1) + sig(i-1,j-1,k) + sig(i-1,j,k);
927  Real w2 = sig(i ,j-1,k-1) + sig(i ,j,k-1) + sig(i ,j-1,k) + sig(i ,j,k);
928  return (w1*crse(ic,jc,kc)+w2*crse(ic+1,jc,kc))/(w1+w2);
929  }
930 
933  int i, int j, int k, int ic, int jc, int kc) noexcept
934  {
935  Real w1 = sig(i-1,j-1,k-1) + sig(i,j-1,k-1) + sig(i-1,j-1,k) + sig(i,j-1,k);
936  Real w2 = sig(i-1,j ,k-1) + sig(i,j ,k-1) + sig(i-1,j ,k) + sig(i,j ,k);
937  return (w1*crse(ic,jc,kc)+w2*crse(ic,jc+1,kc))/(w1+w2);
938  }
939 
942  int i, int j, int k, int ic, int jc, int kc) noexcept
943  {
944  Real w1 = sig(i-1,j-1,k-1) + sig(i,j-1,k-1) + sig(i-1,j,k-1) + sig(i,j,k-1);
945  Real w2 = sig(i-1,j-1,k ) + sig(i,j-1,k ) + sig(i-1,j,k ) + sig(i,j,k );
946  return (w1*crse(ic,jc,kc)+w2*crse(ic,jc,kc+1))/(w1+w2);
947  }
948 
951  int i, int j, int k, int ic, int jc, int kc) noexcept
952  {
953  Real w1 = sig(i-1,j-1,k-1) + sig(i-1,j,k-1) + sig(i-1,j-1,k) + sig(i-1,j,k);
954  Real w2 = sig(i ,j-1,k-1) + sig(i ,j,k-1) + sig(i ,j-1,k) + sig(i ,j,k);
955  Real w3 = sig(i-1,j-1,k-1) + sig(i,j-1,k-1) + sig(i-1,j-1,k) + sig(i,j-1,k);
956  Real w4 = sig(i-1,j ,k-1) + sig(i,j ,k-1) + sig(i-1,j ,k) + sig(i,j ,k);
957  return (w1 * aa_interp_line_y(crse,sig,i-1,j ,k,ic ,jc ,kc) +
958  w2 * aa_interp_line_y(crse,sig,i+1,j ,k,ic+1,jc ,kc) +
959  w3 * aa_interp_line_x(crse,sig,i ,j-1,k,ic ,jc ,kc) +
960  w4 * aa_interp_line_x(crse,sig,i ,j+1,k,ic ,jc+1,kc)) / (w1+w2+w3+w4);
961  }
962 
965  int i, int j, int k, int ic, int jc, int kc) noexcept
966  {
967  Real w1 = sig(i-1,j-1,k-1) + sig(i-1,j,k-1) + sig(i-1,j-1,k) + sig(i-1,j,k);
968  Real w2 = sig(i ,j-1,k-1) + sig(i ,j,k-1) + sig(i ,j-1,k) + sig(i ,j,k);
969  Real w3 = sig(i-1,j-1,k-1) + sig(i,j-1,k-1) + sig(i-1,j,k-1) + sig(i,j,k-1);
970  Real w4 = sig(i-1,j-1,k ) + sig(i,j-1,k ) + sig(i-1,j,k ) + sig(i,j,k );
971  return (w1 * aa_interp_line_z(crse,sig,i-1,j,k ,ic ,jc,kc ) +
972  w2 * aa_interp_line_z(crse,sig,i+1,j,k ,ic+1,jc,kc ) +
973  w3 * aa_interp_line_x(crse,sig,i ,j,k-1,ic ,jc,kc ) +
974  w4 * aa_interp_line_x(crse,sig,i ,j,k+1,ic ,jc,kc+1)) / (w1+w2+w3+w4);
975  }
976 
979  int i, int j, int k, int ic, int jc, int kc) noexcept
980  {
981  Real w1 = sig(i-1,j-1,k-1) + sig(i,j-1,k-1) + sig(i-1,j-1,k) + sig(i,j-1,k);
982  Real w2 = sig(i-1,j ,k-1) + sig(i,j ,k-1) + sig(i-1,j ,k) + sig(i,j ,k);
983  Real w3 = sig(i-1,j-1,k-1) + sig(i,j-1,k-1) + sig(i-1,j,k-1) + sig(i,j,k-1);
984  Real w4 = sig(i-1,j-1,k ) + sig(i,j-1,k ) + sig(i-1,j,k ) + sig(i,j,k );
985  return (w1 * aa_interp_line_z(crse,sig,i,j-1,k ,ic,jc ,kc ) +
986  w2 * aa_interp_line_z(crse,sig,i,j+1,k ,ic,jc+1,kc ) +
987  w3 * aa_interp_line_y(crse,sig,i,j ,k-1,ic,jc ,kc ) +
988  w4 * aa_interp_line_y(crse,sig,i,j ,k+1,ic,jc ,kc+1)) / (w1+w2+w3+w4);
989  }
990 
992 void mlndlap_interpadd_c (int i, int j, int k, Array4<Real> const& fine,
993  Array4<Real const> const& crse,
994  Array4<int const> const& msk) noexcept
995 {
996  if (!msk(i,j,k)) {
997  int ic = amrex::coarsen(i,2);
998  int jc = amrex::coarsen(j,2);
999  int kc = amrex::coarsen(k,2);
1000  bool i_is_odd = (ic*2 != i);
1001  bool j_is_odd = (jc*2 != j);
1002  bool k_is_odd = (kc*2 != k);
1003  if (i_is_odd && j_is_odd && k_is_odd) {
1004  // Fine node at center of cell
1005  fine(i,j,k) += Real(0.125) *
1006  (crse(ic,jc ,kc ) + crse(ic+1,jc ,kc ) +
1007  crse(ic,jc+1,kc ) + crse(ic+1,jc+1,kc ) +
1008  crse(ic,jc ,kc+1) + crse(ic+1,jc ,kc+1) +
1009  crse(ic,jc+1,kc+1) + crse(ic+1,jc+1,kc+1));
1010  } else if (j_is_odd && k_is_odd) {
1011  // Node on a Y-Z face
1012  fine(i,j,k) += Real(0.25) *
1013  (crse(ic,jc,kc ) + crse(ic,jc+1,kc ) +
1014  crse(ic,jc,kc+1) + crse(ic,jc+1,kc+1));
1015  } else if (i_is_odd && k_is_odd) {
1016  // Node on a Z-X face
1017  fine(i,j,k) += Real(0.25) *
1018  (crse(ic,jc,kc ) + crse(ic+1,jc,kc ) +
1019  crse(ic,jc,kc+1) + crse(ic+1,jc,kc+1));
1020  } else if (i_is_odd && j_is_odd) {
1021  // Node on a X-Y face
1022  fine(i,j,k) += Real(0.25) *
1023  (crse(ic,jc ,kc) + crse(ic+1,jc ,kc) +
1024  crse(ic,jc+1,kc) + crse(ic+1,jc+1,kc));
1025  } else if (i_is_odd) {
1026  // Node on X line
1027  fine(i,j,k) += Real(0.5)*(crse(ic,jc,kc)+crse(ic+1,jc,kc));
1028  } else if (j_is_odd) {
1029  // Node on Y line
1030  fine(i,j,k) += Real(0.5)*(crse(ic,jc,kc)+crse(ic,jc+1,kc));
1031  } else if (k_is_odd) {
1032  // Node on Z line
1033  fine(i,j,k) += Real(0.5)*(crse(ic,jc,kc)+crse(ic,jc,kc+1));
1034  } else {
1035  // Node coincident with coarse node
1036  fine(i,j,k) += crse(ic,jc,kc);
1037  }
1038  }
1039 }
1040 
1042 void mlndlap_interpadd_aa (int i, int j, int k, Array4<Real> const& fine,
1043  Array4<Real const> const& crse, Array4<Real const> const& sig,
1044  Array4<int const> const& msk) noexcept
1045 {
1046  if (!msk(i,j,k)) {
1047  int ic = amrex::coarsen(i,2);
1048  int jc = amrex::coarsen(j,2);
1049  int kc = amrex::coarsen(k,2);
1050  bool i_is_odd = (ic*2 != i);
1051  bool j_is_odd = (jc*2 != j);
1052  bool k_is_odd = (kc*2 != k);
1053  if (i_is_odd && j_is_odd && k_is_odd) {
1054  // Fine node at center of cell
1055  Real w1 = sig(i-1,j-1,k-1) + sig(i-1,j,k-1) + sig(i-1,j-1,k) + sig(i-1,j,k);
1056  Real w2 = sig(i ,j-1,k-1) + sig(i ,j,k-1) + sig(i ,j-1,k) + sig(i ,j,k);
1057  Real w3 = sig(i-1,j-1,k-1) + sig(i,j-1,k-1) + sig(i-1,j-1,k) + sig(i,j-1,k);
1058  Real w4 = sig(i-1,j ,k-1) + sig(i,j ,k-1) + sig(i-1,j ,k) + sig(i,j ,k);
1059  Real w5 = sig(i-1,j-1,k-1) + sig(i,j-1,k-1) + sig(i-1,j,k-1) + sig(i,j,k-1);
1060  Real w6 = sig(i-1,j-1,k ) + sig(i,j-1,k ) + sig(i-1,j,k ) + sig(i,j,k );
1061  fine(i,j,k) += (w1 * aa_interp_face_yz(crse,sig,i-1,j ,k ,ic ,jc ,kc ) +
1062  w2 * aa_interp_face_yz(crse,sig,i+1,j ,k ,ic+1,jc ,kc ) +
1063  w3 * aa_interp_face_xz(crse,sig,i ,j-1,k ,ic ,jc ,kc ) +
1064  w4 * aa_interp_face_xz(crse,sig,i ,j+1,k ,ic ,jc+1,kc ) +
1065  w5 * aa_interp_face_xy(crse,sig,i ,j ,k-1,ic ,jc ,kc ) +
1066  w6 * aa_interp_face_xy(crse,sig,i ,j ,k+1,ic ,jc ,kc+1))
1067  / (w1+w2+w3+w4+w5+w6);
1068  } else if (j_is_odd && k_is_odd) {
1069  // Node on a Y-Z face
1070  fine(i,j,k) += aa_interp_face_yz(crse,sig,i,j,k,ic,jc,kc);
1071  } else if (i_is_odd && k_is_odd) {
1072  // Node on a Z-X face
1073  fine(i,j,k) += aa_interp_face_xz(crse,sig,i,j,k,ic,jc,kc);
1074  } else if (i_is_odd && j_is_odd) {
1075  // Node on a X-Y face
1076  fine(i,j,k) += aa_interp_face_xy(crse,sig,i,j,k,ic,jc,kc);
1077  } else if (i_is_odd) {
1078  // Node on X line
1079  fine(i,j,k) += aa_interp_line_x(crse,sig,i,j,k,ic,jc,kc);
1080  } else if (j_is_odd) {
1081  // Node on Y line
1082  fine(i,j,k) += aa_interp_line_y(crse,sig,i,j,k,ic,jc,kc);
1083  } else if (k_is_odd) {
1084  // Node on Z line
1085  fine(i,j,k) += aa_interp_line_z(crse,sig,i,j,k,ic,jc,kc);
1086  } else {
1087  // Node coincident with coarse node
1088  fine(i,j,k) += crse(ic,jc,kc);
1089  }
1090  }
1091 }
1092 
1094 void mlndlap_semi_interpadd_aa (int i, int j, int k, Array4<Real> const& fine,
1095  Array4<Real const> const& crse, Array4<Real const> const& sig,
1096  Array4<int const> const& msk, int idir) noexcept
1097 {
1098  if (idir == 2 )
1099  {
1100  if (!msk(i,j,k)) {
1101  int ic = amrex::coarsen(i,2);
1102  int jc = amrex::coarsen(j,2);
1103  int kc = k;
1104  bool i_is_odd = (ic*2 != i);
1105  bool j_is_odd = (jc*2 != j);
1106 
1107  if (i_is_odd && j_is_odd) {
1108  // Node on a X-Y face
1109  fine(i,j,k) += aa_interp_face_xy(crse,sig,i,j,k,ic,jc,kc);
1110  } else if (i_is_odd) {
1111  // Node on X line
1112  fine(i,j,k) += aa_interp_line_x(crse,sig,i,j,k,ic,jc,kc);
1113  } else if (j_is_odd) {
1114  // Node on Y line
1115  fine(i,j,k) += aa_interp_line_y(crse,sig,i,j,k,ic,jc,kc);
1116  } else {
1117  // Node coincident with coarse node
1118  fine(i,j,k) += crse(ic,jc,kc);
1119  }
1120  }
1121  } else if (idir ==1 ){
1122  if (!msk(i,j,k)) {
1123  int ic = amrex::coarsen(i,2);
1124  int jc = j;
1125  int kc = amrex::coarsen(k,2);
1126  bool i_is_odd = (ic*2 != i);
1127  bool k_is_odd = (kc*2 != k);
1128 
1129  if (i_is_odd && k_is_odd) {
1130  // Node on a X-Z face
1131  fine(i,j,k) += aa_interp_face_xz(crse,sig,i,j,k,ic,jc,kc);
1132  } else if (i_is_odd) {
1133  // Node on X line
1134  fine(i,j,k) += aa_interp_line_x(crse,sig,i,j,k,ic,jc,kc);
1135  } else if (k_is_odd) {
1136  // Node on Z line
1137  fine(i,j,k) += aa_interp_line_z(crse,sig,i,j,k,ic,jc,kc);
1138  } else {
1139  // Node coincident with coarse node
1140  fine(i,j,k) += crse(ic,jc,kc);
1141  }
1142  }
1143  } else if (idir == 0 ) {
1144  if (!msk(i,j,k)) {
1145  int ic = i;
1146  int jc = amrex::coarsen(j,2);
1147  int kc = amrex::coarsen(k,2);
1148  bool j_is_odd = (jc*2 != j);
1149  bool k_is_odd = (kc*2 != k);
1150 
1151  if (j_is_odd && k_is_odd) {
1152  // Node on a Y-Z face
1153  fine(i,j,k) += aa_interp_face_yz(crse,sig,i,j,k,ic,jc,kc);
1154  } else if (j_is_odd) {
1155  // Node on Y line
1156  fine(i,j,k) += aa_interp_line_y(crse,sig,i,j,k,ic,jc,kc);
1157  } else if (k_is_odd) {
1158  // Node on Z line
1159  fine(i,j,k) += aa_interp_line_z(crse,sig,i,j,k,ic,jc,kc);
1160  } else {
1161  // Node coincident with coarse node
1162  fine(i,j,k) += crse(ic,jc,kc);
1163  }
1164  }
1165  } else {
1166  amrex::Abort("mlndlap_semi_interpolation semi direction wrong semi-direction. ");
1167  }
1168 }
1169 
1170 
1173  Array4<Real const> const& sigx, Array4<Real const> const& sigy,
1174  int i, int j, int k, int ic, int jc, int kc) noexcept
1175  {
1176  Real w1 = sigx(i-1,j-1,k-1) + sigx(i-1,j,k-1) + sigx(i-1,j-1,k) + sigx(i-1,j,k);
1177  Real w2 = sigx(i ,j-1,k-1) + sigx(i ,j,k-1) + sigx(i ,j-1,k) + sigx(i ,j,k);
1178  Real w3 = sigy(i-1,j-1,k-1) + sigy(i,j-1,k-1) + sigy(i-1,j-1,k) + sigy(i,j-1,k);
1179  Real w4 = sigy(i-1,j ,k-1) + sigy(i,j ,k-1) + sigy(i-1,j ,k) + sigy(i,j ,k);
1180  return (w1 * aa_interp_line_y(crse,sigy,i-1,j ,k,ic ,jc ,kc) +
1181  w2 * aa_interp_line_y(crse,sigy,i+1,j ,k,ic+1,jc ,kc) +
1182  w3 * aa_interp_line_x(crse,sigx,i ,j-1,k,ic ,jc ,kc) +
1183  w4 * aa_interp_line_x(crse,sigx,i ,j+1,k,ic ,jc+1,kc)) / (w1+w2+w3+w4);
1184  }
1185 
1188  Array4<Real const> const& sigx, Array4<Real const> const& sigz,
1189  int i, int j, int k, int ic, int jc, int kc) noexcept
1190  {
1191  Real w1 = sigx(i-1,j-1,k-1) + sigx(i-1,j,k-1) + sigx(i-1,j-1,k) + sigx(i-1,j,k);
1192  Real w2 = sigx(i ,j-1,k-1) + sigx(i ,j,k-1) + sigx(i ,j-1,k) + sigx(i ,j,k);
1193  Real w3 = sigz(i-1,j-1,k-1) + sigz(i,j-1,k-1) + sigz(i-1,j,k-1) + sigz(i,j,k-1);
1194  Real w4 = sigz(i-1,j-1,k ) + sigz(i,j-1,k ) + sigz(i-1,j,k ) + sigz(i,j,k );
1195  return (w1 * aa_interp_line_z(crse,sigz,i-1,j,k ,ic ,jc,kc ) +
1196  w2 * aa_interp_line_z(crse,sigz,i+1,j,k ,ic+1,jc,kc ) +
1197  w3 * aa_interp_line_x(crse,sigx,i ,j,k-1,ic ,jc,kc ) +
1198  w4 * aa_interp_line_x(crse,sigx,i ,j,k+1,ic ,jc,kc+1)) / (w1+w2+w3+w4);
1199  }
1200 
1203  Array4<Real const> const& sigy, Array4<Real const> const& sigz,
1204  int i, int j, int k, int ic, int jc, int kc) noexcept
1205  {
1206  Real w1 = sigy(i-1,j-1,k-1) + sigy(i,j-1,k-1) + sigy(i-1,j-1,k) + sigy(i,j-1,k);
1207  Real w2 = sigy(i-1,j ,k-1) + sigy(i,j ,k-1) + sigy(i-1,j ,k) + sigy(i,j ,k);
1208  Real w3 = sigz(i-1,j-1,k-1) + sigz(i,j-1,k-1) + sigz(i-1,j,k-1) + sigz(i,j,k-1);
1209  Real w4 = sigz(i-1,j-1,k ) + sigz(i,j-1,k ) + sigz(i-1,j,k ) + sigz(i,j,k );
1210  return (w1 * aa_interp_line_z(crse,sigz,i,j-1,k ,ic,jc ,kc ) +
1211  w2 * aa_interp_line_z(crse,sigz,i,j+1,k ,ic,jc+1,kc ) +
1212  w3 * aa_interp_line_y(crse,sigy,i,j ,k-1,ic,jc ,kc ) +
1213  w4 * aa_interp_line_y(crse,sigy,i,j ,k+1,ic,jc ,kc+1)) / (w1+w2+w3+w4);
1214  }
1215 
1217 void mlndlap_interpadd_ha (int i, int j, int k, Array4<Real> const& fine,
1218  Array4<Real const> const& crse, Array4<Real const> const& sigx,
1219  Array4<Real const> const& sigy, Array4<Real const> const& sigz,
1220  Array4<int const> const& msk) noexcept
1221 {
1222  if (!msk(i,j,k)) {
1223  int ic = amrex::coarsen(i,2);
1224  int jc = amrex::coarsen(j,2);
1225  int kc = amrex::coarsen(k,2);
1226  bool i_is_odd = (ic*2 != i);
1227  bool j_is_odd = (jc*2 != j);
1228  bool k_is_odd = (kc*2 != k);
1229  if (i_is_odd && j_is_odd && k_is_odd) {
1230  // Fine node at center of cell
1231  Real w1 = sigx(i-1,j-1,k-1) + sigx(i-1,j,k-1) + sigx(i-1,j-1,k) + sigx(i-1,j,k);
1232  Real w2 = sigx(i ,j-1,k-1) + sigx(i ,j,k-1) + sigx(i ,j-1,k) + sigx(i ,j,k);
1233  Real w3 = sigy(i-1,j-1,k-1) + sigy(i,j-1,k-1) + sigy(i-1,j-1,k) + sigy(i,j-1,k);
1234  Real w4 = sigy(i-1,j ,k-1) + sigy(i,j ,k-1) + sigy(i-1,j ,k) + sigy(i,j ,k);
1235  Real w5 = sigz(i-1,j-1,k-1) + sigz(i,j-1,k-1) + sigz(i-1,j,k-1) + sigz(i,j,k-1);
1236  Real w6 = sigz(i-1,j-1,k ) + sigz(i,j-1,k ) + sigz(i-1,j,k ) + sigz(i,j,k );
1237  fine(i,j,k) += (w1 * ha_interp_face_yz(crse,sigy,sigz,i-1,j ,k ,ic ,jc ,kc ) +
1238  w2 * ha_interp_face_yz(crse,sigy,sigz,i+1,j ,k ,ic+1,jc ,kc ) +
1239  w3 * ha_interp_face_xz(crse,sigx,sigz,i ,j-1,k ,ic ,jc ,kc ) +
1240  w4 * ha_interp_face_xz(crse,sigx,sigz,i ,j+1,k ,ic ,jc+1,kc ) +
1241  w5 * ha_interp_face_xy(crse,sigx,sigy,i ,j ,k-1,ic ,jc ,kc ) +
1242  w6 * ha_interp_face_xy(crse,sigx,sigy,i ,j ,k+1,ic ,jc ,kc+1))
1243  / (w1+w2+w3+w4+w5+w6);
1244  } else if (j_is_odd && k_is_odd) {
1245  // Node on a Y-Z face
1246  fine(i,j,k) += ha_interp_face_yz(crse,sigy,sigz,i,j,k,ic,jc,kc);
1247  } else if (i_is_odd && k_is_odd) {
1248  // Node on a Z-X face
1249  fine(i,j,k) += ha_interp_face_xz(crse,sigx,sigz,i,j,k,ic,jc,kc);
1250  } else if (i_is_odd && j_is_odd) {
1251  // Node on a X-Y face
1252  fine(i,j,k) += ha_interp_face_xy(crse,sigx,sigy,i,j,k,ic,jc,kc);
1253  } else if (i_is_odd) {
1254  // Node on X line
1255  fine(i,j,k) += aa_interp_line_x(crse,sigx,i,j,k,ic,jc,kc);
1256  } else if (j_is_odd) {
1257  // Node on Y line
1258  fine(i,j,k) += aa_interp_line_y(crse,sigy,i,j,k,ic,jc,kc);
1259  } else if (k_is_odd) {
1260  // Node on Z line
1261  fine(i,j,k) += aa_interp_line_z(crse,sigz,i,j,k,ic,jc,kc);
1262  } else {
1263  // Node coincident with coarse node
1264  fine(i,j,k) += crse(ic,jc,kc);
1265  }
1266  }
1267 }
1268 
1269 //
1270 // rhs & u
1271 //
1272 
1274 void mlndlap_divu (int i, int j, int k, Array4<Real> const& rhs, Array4<Real const> const& vel,
1275  Array4<int const> const& msk,
1276  GpuArray<Real,AMREX_SPACEDIM> const& dxinv,
1277  Box const& nodal_domain,
1278  GpuArray<LinOpBCType, AMREX_SPACEDIM> const& bclo,
1279  GpuArray<LinOpBCType, AMREX_SPACEDIM> const& bchi) noexcept
1280 {
1281  Real facx = Real(0.25)*dxinv[0];
1282  Real facy = Real(0.25)*dxinv[1];
1283  Real facz = Real(0.25)*dxinv[2];
1284 
1285  const auto domlo = amrex::lbound(nodal_domain);
1286  const auto domhi = amrex::ubound(nodal_domain);
1287 
1288  if (msk(i,j,k)) {
1289  rhs(i,j,k) = Real(0.0);
1290  } else {
1291 
1292  Real zero_ilo = Real(1.0);
1293  Real zero_ihi = Real(1.0);
1294  Real zero_jlo = Real(1.0);
1295  Real zero_jhi = Real(1.0);
1296  Real zero_klo = Real(1.0);
1297  Real zero_khi = Real(1.0);
1298 
1299  // The nodal divergence operator should not see the tangential velocity
1300  // at an inflow face
1301  if ((bclo[0] == LinOpBCType::Neumann || bclo[0] == LinOpBCType::inflow)
1302  && i == domlo.x)
1303  {
1304  zero_ilo = Real(0.0);
1305  }
1306  if ((bchi[0] == LinOpBCType::Neumann || bchi[0] == LinOpBCType::inflow)
1307  && i == domhi.x)
1308  {
1309  zero_ihi = Real(0.0);
1310  }
1311  if ((bclo[1] == LinOpBCType::Neumann || bclo[1] == LinOpBCType::inflow)
1312  && j == domlo.y)
1313  {
1314  zero_jlo = Real(0.0);
1315  }
1316  if ((bchi[1] == LinOpBCType::Neumann || bchi[1] == LinOpBCType::inflow)
1317  && j == domhi.y)
1318  {
1319  zero_jhi = Real(0.0);
1320  }
1321  if ((bclo[2] == LinOpBCType::Neumann || bclo[2] == LinOpBCType::inflow)
1322  && k == domlo.z)
1323  {
1324  zero_klo = Real(0.0);
1325  }
1326  if ((bchi[2] == LinOpBCType::Neumann || bchi[2] == LinOpBCType::inflow)
1327  && k == domhi.z)
1328  {
1329  zero_khi = Real(0.0);
1330  }
1331 
1332  rhs(i,j,k) = facx*(-vel(i-1,j-1,k-1,0)*zero_jlo*zero_klo+vel(i,j-1,k-1,0)*zero_jlo*zero_klo
1333  -vel(i-1,j ,k-1,0)*zero_jhi*zero_klo+vel(i,j ,k-1,0)*zero_jhi*zero_klo
1334  -vel(i-1,j-1,k ,0)*zero_jlo*zero_khi+vel(i,j-1,k ,0)*zero_jlo*zero_khi
1335  -vel(i-1,j ,k ,0)*zero_jhi*zero_khi+vel(i,j ,k ,0)*zero_jhi*zero_khi)
1336 
1337  + facy*(-vel(i-1,j-1,k-1,1)*zero_ilo*zero_klo-vel(i,j-1,k-1,1)*zero_ihi*zero_klo
1338  +vel(i-1,j ,k-1,1)*zero_ilo*zero_klo+vel(i,j ,k-1,1)*zero_ihi*zero_klo
1339  -vel(i-1,j-1,k ,1)*zero_ilo*zero_khi-vel(i,j-1,k ,1)*zero_ihi*zero_khi
1340  +vel(i-1,j ,k ,1)*zero_ilo*zero_khi+vel(i,j ,k ,1)*zero_ihi*zero_khi)
1341 
1342  + facz*(-vel(i-1,j-1,k-1,2)*zero_ilo*zero_jlo-vel(i,j-1,k-1,2)*zero_ihi*zero_jlo
1343  -vel(i-1,j ,k-1,2)*zero_ilo*zero_jhi-vel(i,j ,k-1,2)*zero_ihi*zero_jhi
1344  +vel(i-1,j-1,k ,2)*zero_ilo*zero_jlo+vel(i,j-1,k ,2)*zero_ihi*zero_jlo
1345  +vel(i-1,j ,k ,2)*zero_ilo*zero_jhi+vel(i,j ,k ,2)*zero_ihi*zero_jhi);
1346  }
1347 }
1348 
1350 Real mlndlap_rhcc (int i, int j, int k, Array4<Real const> const& rhcc,
1351  Array4<int const> const& msk) noexcept
1352 {
1353  Real r;
1354  if (msk(i,j,k)) {
1355  r = Real(0.0);
1356  } else {
1357  r = Real(0.125) * (rhcc(i-1,j-1,k-1)+rhcc(i,j-1,k-1)+rhcc(i-1,j,k-1)+rhcc(i,j,k-1) +
1358  rhcc(i-1,j-1,k )+rhcc(i,j-1,k )+rhcc(i-1,j,k )+rhcc(i,j,k ));
1359  }
1360  return r;
1361 }
1362 
1364 void mlndlap_mknewu (int i, int j, int k, Array4<Real> const& u, Array4<Real const> const& p,
1365  Array4<Real const> const& sig, GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
1366 {
1367  Real facx = Real(0.25)*dxinv[0];
1368  Real facy = Real(0.25)*dxinv[1];
1369  Real facz = Real(0.25)*dxinv[2];
1370  u(i,j,k,0) -= sig(i,j,k)*facx
1371  * (-p(i,j,k )+p(i+1,j,k )-p(i,j+1,k )+p(i+1,j+1,k )
1372  -p(i,j,k+1)+p(i+1,j,k+1)-p(i,j+1,k+1)+p(i+1,j+1,k+1));
1373  u(i,j,k,1) -= sig(i,j,k)*facy
1374  * (-p(i,j,k )-p(i+1,j,k )+p(i,j+1,k )+p(i+1,j+1,k )
1375  -p(i,j,k+1)-p(i+1,j,k+1)+p(i,j+1,k+1)+p(i+1,j+1,k+1));
1376  u(i,j,k,2) -= sig(i,j,k)*facz
1377  * (-p(i,j,k )-p(i+1,j,k )-p(i,j+1,k )-p(i+1,j+1,k )
1378  +p(i,j,k+1)+p(i+1,j,k+1)+p(i,j+1,k+1)+p(i+1,j+1,k+1));
1379 }
1380 
1382 void mlndlap_mknewu_c (int i, int j, int k, Array4<Real> const& u, Array4<Real const> const& p,
1383  Real sig, GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
1384 {
1385  Real facx = Real(0.25)*dxinv[0];
1386  Real facy = Real(0.25)*dxinv[1];
1387  Real facz = Real(0.25)*dxinv[2];
1388  u(i,j,k,0) -= sig*facx
1389  * (-p(i,j,k )+p(i+1,j,k )-p(i,j+1,k )+p(i+1,j+1,k )
1390  -p(i,j,k+1)+p(i+1,j,k+1)-p(i,j+1,k+1)+p(i+1,j+1,k+1));
1391  u(i,j,k,1) -= sig*facy
1392  * (-p(i,j,k )-p(i+1,j,k )+p(i,j+1,k )+p(i+1,j+1,k )
1393  -p(i,j,k+1)-p(i+1,j,k+1)+p(i,j+1,k+1)+p(i+1,j+1,k+1));
1394  u(i,j,k,2) -= sig*facz
1395  * (-p(i,j,k )-p(i+1,j,k )-p(i,j+1,k )-p(i+1,j+1,k )
1396  +p(i,j,k+1)+p(i+1,j,k+1)+p(i,j+1,k+1)+p(i+1,j+1,k+1));
1397 }
1398 
1400  Real mlndlap_sum_Df (int ii, int jj, int kk, Real facx, Real facy, Real facz,
1401  Array4<Real const> const& vel, Box const& velbx) noexcept
1402  {
1403  Real Df = Real(0.0);
1404  if (velbx.contains(ii-1,jj-1,kk-1)) {
1405  Df += -facx*vel(ii-1,jj-1,kk-1,0) - facy*vel(ii-1,jj-1,kk-1,1) - facz*vel(ii-1,jj-1,kk-1,2);
1406  }
1407  if (velbx.contains(ii,jj-1,kk-1)) {
1408  Df += facx*vel(ii,jj-1,kk-1,0) - facy*vel(ii,jj-1,kk-1,1) - facz*vel(ii,jj-1,kk-1,2);
1409  }
1410  if (velbx.contains(ii-1,jj,kk-1)) {
1411  Df += -facx*vel(ii-1,jj,kk-1,0) + facy*vel(ii-1,jj,kk-1,1) - facz*vel(ii-1,jj,kk-1,2);
1412  }
1413  if (velbx.contains(ii,jj,kk-1)) {
1414  Df += facx*vel(ii,jj,kk-1,0) + facy*vel(ii,jj,kk-1,1) - facz*vel(ii,jj,kk-1,2);
1415  }
1416  if (velbx.contains(ii-1,jj-1,kk)) {
1417  Df += -facx*vel(ii-1,jj-1,kk,0) - facy*vel(ii-1,jj-1,kk,1) + facz*vel(ii-1,jj-1,kk,2);
1418  }
1419  if (velbx.contains(ii,jj-1,kk)) {
1420  Df += facx*vel(ii,jj-1,kk,0) - facy*vel(ii,jj-1,kk,1) + facz*vel(ii,jj-1,kk,2);
1421  }
1422  if (velbx.contains(ii-1,jj,kk)) {
1423  Df += -facx*vel(ii-1,jj,kk,0) + facy*vel(ii-1,jj,kk,1) + facz*vel(ii-1,jj,kk,2);
1424  }
1425  if (velbx.contains(ii,jj,kk)) {
1426  Df += facx*vel(ii,jj,kk,0) + facy*vel(ii,jj,kk,1) + facz*vel(ii,jj,kk,2);
1427  }
1428  return Df;
1429  }
1430 
1431 template <int rr>
1433 void mlndlap_divu_fine_contrib (int i, int j, int k, Box const& fvbx, Box const& velbx,
1434  Array4<Real> const& rhs, Array4<Real const> const& vel,
1435  Array4<Real const> const& frhs, Array4<int const> const& msk,
1436  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
1437 {
1438  const int ii = rr*i;
1439  const int jj = rr*j;
1440  const int kk = rr*k;
1441  if (msk(ii,jj,kk)) {
1442  const Real facx = Real(0.25)*dxinv[0];
1443  const Real facy = Real(0.25)*dxinv[1];
1444  const Real facz = Real(0.25)*dxinv[2];
1445 
1446  Real Df = Real(0.0);
1447 
1448  const int ilo = amrex::max(ii-rr+1, fvbx.smallEnd(0));
1449  const int ihi = amrex::min(ii+rr-1, fvbx.bigEnd (0));
1450  const int jlo = amrex::max(jj-rr+1, fvbx.smallEnd(1));
1451  const int jhi = amrex::min(jj+rr-1, fvbx.bigEnd (1));
1452  const int klo = amrex::max(kk-rr+1, fvbx.smallEnd(2));
1453  const int khi = amrex::min(kk+rr-1, fvbx.bigEnd (2));
1454 
1455  for (int koff = klo; koff <= khi; ++koff) {
1456  for (int joff = jlo; joff <= jhi; ++joff) {
1457  for (int ioff = ilo; ioff <= ihi; ++ioff) {
1458  Real scale = static_cast<Real>((rr-std::abs(ii-ioff)) *
1459  (rr-std::abs(jj-joff)) *
1460  (rr-std::abs(kk-koff)));
1461  if (fvbx.strictly_contains(ioff,joff,koff)) {
1462  Df += scale * frhs(ioff,joff,koff);
1463  } else {
1464  Df += scale * mlndlap_sum_Df(ioff, joff, koff, facx, facy, facz, vel, velbx);
1465  }
1466  }}}
1467 
1468  rhs(i,j,k) = Df * (Real(1.0)/static_cast<Real>(rr*rr*rr*rr*rr*rr));
1469  } else {
1470  rhs(i,j,k) = Real(0.0);
1471  }
1472 }
1473 
1474 template<int rr>
1476 void mlndlap_rhcc_fine_contrib (int i, int j, int k, Box const& ccbx,
1477  Array4<Real> const& rhs, Array4<Real const> const& cc,
1478  Array4<int const> const& msk) noexcept
1479 {
1480  const int ii = rr*i;
1481  const int jj = rr*j;
1482  const int kk = rr*k;
1483  if (msk(ii,jj,kk)) {
1484  Real tmp = Real(0.0);
1485 
1486  const int ilo = amrex::max(ii-rr , ccbx.smallEnd(0));
1487  const int ihi = amrex::min(ii+rr-1, ccbx.bigEnd (0));
1488  const int jlo = amrex::max(jj-rr , ccbx.smallEnd(1));
1489  const int jhi = amrex::min(jj+rr-1, ccbx.bigEnd (1));
1490  const int klo = amrex::max(kk-rr , ccbx.smallEnd(2));
1491  const int khi = amrex::min(kk+rr-1, ccbx.bigEnd (2));
1492 
1493  for (int koff = klo; koff <= khi; ++koff) {
1494  for (int joff = jlo; joff <= jhi; ++joff) {
1495  for (int ioff = ilo; ioff <= ihi; ++ioff) {
1496  Real scale = (static_cast<Real>(rr)-std::abs(static_cast<Real>(ioff-ii)+Real(0.5)))
1497  * (static_cast<Real>(rr)-std::abs(static_cast<Real>(joff-jj)+Real(0.5)))
1498  * (static_cast<Real>(rr)-std::abs(static_cast<Real>(koff-kk)+Real(0.5)));
1499  tmp += cc(ioff,joff,koff) * scale;
1500  }}}
1501 
1502  rhs(i,j,k) += tmp * (Real(1.0)/Real(rr*rr*rr*rr*rr*rr));
1503  }
1504 }
1505 
1507  Real neumann_scale (int i, int j, int k, Box const& nddom,
1509  GpuArray<LinOpBCType,AMREX_SPACEDIM> const& bchi) noexcept
1510  {
1511  Real val = Real(1.0);
1512 
1513  const auto ndlo = amrex::lbound(nddom);
1514  const auto ndhi = amrex::ubound(nddom);
1515 
1516  if ((i == ndlo.x && ( bclo[0] == LinOpBCType::Neumann ||
1517  bclo[0] == LinOpBCType::inflow)) ||
1518  (i == ndhi.x && ( bchi[0] == LinOpBCType::Neumann ||
1519  bchi[0] == LinOpBCType::inflow))) {
1520  val *= Real(2.);
1521  }
1522 
1523  if ((j == ndlo.y && ( bclo[1] == LinOpBCType::Neumann ||
1524  bclo[1] == LinOpBCType::inflow)) ||
1525  (j == ndhi.y && ( bchi[1] == LinOpBCType::Neumann ||
1526  bchi[1] == LinOpBCType::inflow))) {
1527  val *= Real(2.);
1528  }
1529 
1530  if ((k == ndlo.z && ( bclo[2] == LinOpBCType::Neumann ||
1531  bclo[2] == LinOpBCType::inflow)) ||
1532  (k == ndhi.z && ( bchi[2] == LinOpBCType::Neumann ||
1533  bchi[2] == LinOpBCType::inflow))) {
1534  val *= Real(2.);
1535  }
1536 
1537  return val;
1538  }
1539 
1541 void mlndlap_divu_cf_contrib (int i, int j, int k, Array4<Real> const& rhs,
1542  Array4<Real const> const& vel, Array4<Real const> const& fc,
1543  Array4<Real const> const& rhcc, Array4<int const> const& dmsk,
1544  Array4<int const> const& ndmsk, Array4<int const> const& ccmsk,
1545  GpuArray<Real,AMREX_SPACEDIM> const& dxinv,
1546  Box const& ccdom_p, Box const& veldom, Box const& nddom,
1548  GpuArray<LinOpBCType,AMREX_SPACEDIM> const& bchi) noexcept
1549 {
1550  using namespace nodelap_detail;
1551 
1552  if (!dmsk(i,j,k) && ndmsk(i,j,k) == crse_fine_node) {
1553  Real facx = Real(0.25) * dxinv[0];
1554  Real facy = Real(0.25) * dxinv[1];
1555  Real facz = Real(0.25) * dxinv[2];
1556  Real tmp = fc(i,j,k);
1557 
1558  // Where there is inflow, veldom there is bigger than ccdom_p by one cell.
1559  // ccdom_p is cc domain grown at periodic boundaries.
1560 
1561  if (ccmsk(i-1,j-1,k-1) == crse_cell && veldom.contains(i-1,j-1,k-1)) {
1562  tmp += -facx*vel(i-1,j-1,k-1,0) - facy*vel(i-1,j-1,k-1,1) - facz*vel(i-1,j-1,k-1,2);
1563  if (rhcc && ccdom_p.contains(i-1,j-1,k-1)) {
1564  tmp += Real(0.125) * rhcc(i-1,j-1,k-1);
1565  }
1566  }
1567 
1568  if (ccmsk(i,j-1,k-1) == crse_cell && veldom.contains(i,j-1,k-1)) {
1569  tmp += facx*vel(i,j-1,k-1,0) - facy*vel(i,j-1,k-1,1) - facz*vel(i,j-1,k-1,2);
1570  if (rhcc && ccdom_p.contains(i,j-1,k-1)) {
1571  tmp += Real(0.125) * rhcc(i,j-1,k-1);
1572  }
1573  }
1574 
1575  if (ccmsk(i-1,j,k-1) == crse_cell && veldom.contains(i-1,j,k-1)) {
1576  tmp += -facx*vel(i-1,j,k-1,0) + facy*vel(i-1,j,k-1,1) - facz*vel(i-1,j,k-1,2);
1577  if (rhcc && ccdom_p.contains(i-1,j,k-1)) {
1578  tmp += Real(0.125) * rhcc(i-1,j,k-1);
1579  }
1580  }
1581 
1582  if (ccmsk(i,j,k-1) == crse_cell && veldom.contains(i,j,k-1)) {
1583  tmp += facx*vel(i,j,k-1,0) + facy*vel(i,j,k-1,1) - facz*vel(i,j,k-1,2);
1584  if (rhcc && ccdom_p.contains(i,j,k-1)) {
1585  tmp += Real(0.125) * rhcc(i,j,k-1);
1586  }
1587  }
1588 
1589  if (ccmsk(i-1,j-1,k) == crse_cell && veldom.contains(i-1,j-1,k)) {
1590  tmp += -facx*vel(i-1,j-1,k,0) - facy*vel(i-1,j-1,k,1) + facz*vel(i-1,j-1,k,2);
1591  if (rhcc && ccdom_p.contains(i-1,j-1,k)) {
1592  tmp += Real(0.125) * rhcc(i-1,j-1,k);
1593  }
1594  }
1595 
1596  if (ccmsk(i,j-1,k) == crse_cell && veldom.contains(i,j-1,k)) {
1597  tmp += facx*vel(i,j-1,k,0) - facy*vel(i,j-1,k,1) + facz*vel(i,j-1,k,2);
1598  if (rhcc && ccdom_p.contains(i,j-1,k)) {
1599  tmp += Real(0.125) * rhcc(i,j-1,k);
1600  }
1601  }
1602 
1603  if (ccmsk(i-1,j,k) == crse_cell && veldom.contains(i-1,j,k)) {
1604  tmp += -facx*vel(i-1,j,k,0) + facy*vel(i-1,j,k,1) + facz*vel(i-1,j,k,2);
1605  if (rhcc && ccdom_p.contains(i-1,j,k)) {
1606  tmp += Real(0.125) * rhcc(i-1,j,k);
1607  }
1608  }
1609 
1610  if (ccmsk(i,j,k) == crse_cell && veldom.contains(i,j,k)) {
1611  tmp += facx*vel(i,j,k,0) + facy*vel(i,j,k,1) + facz*vel(i,j,k,2);
1612  if (rhcc && ccdom_p.contains(i,j,k)) {
1613  tmp += Real(0.125) * rhcc(i,j,k);
1614  }
1615  }
1616 
1617  rhs(i,j,k) = tmp * neumann_scale(i, j, k, nddom, bclo, bchi);
1618  }
1619 }
1620 
1621 //
1622 // residual
1623 //
1624 
1626 void mlndlap_crse_resid (int i, int j, int k, Array4<Real> const& resid,
1627  Array4<Real const> const& rhs, Array4<int const> const& msk,
1628  Box const& nddom, GpuArray<LinOpBCType,AMREX_SPACEDIM> const& bclo,
1629  GpuArray<LinOpBCType,AMREX_SPACEDIM> const& bchi,
1630  bool neumann_doubling) noexcept
1631 {
1632  if ( msk(i-1,j-1,k-1) == 0 ||
1633  msk(i ,j-1,k-1) == 0 ||
1634  msk(i-1,j ,k-1) == 0 ||
1635  msk(i ,j ,k-1) == 0 ||
1636  msk(i-1,j-1,k ) == 0 ||
1637  msk(i ,j-1,k ) == 0 ||
1638  msk(i-1,j ,k ) == 0 ||
1639  msk(i ,j ,k ) == 0 )
1640  {
1641  Real fac = Real(1.0);
1642  if (neumann_doubling) {
1643  const auto ndlo = amrex::lbound(nddom);
1644  const auto ndhi = amrex::ubound(nddom);
1645  if ((i == ndlo.x && ( bclo[0] == LinOpBCType::Neumann ||
1646  bclo[0] == LinOpBCType::inflow)) ||
1647  (i == ndhi.x && ( bchi[0] == LinOpBCType::Neumann ||
1648  bchi[0] == LinOpBCType::inflow))) {
1649  fac *= Real(2.);
1650  }
1651  if ((j == ndlo.y && ( bclo[1] == LinOpBCType::Neumann ||
1652  bclo[1] == LinOpBCType::inflow)) ||
1653  (j == ndhi.y && ( bchi[1] == LinOpBCType::Neumann ||
1654  bchi[1] == LinOpBCType::inflow))) {
1655  fac *= Real(2.);
1656  }
1657  if ((k == ndlo.z && ( bclo[2] == LinOpBCType::Neumann ||
1658  bclo[2] == LinOpBCType::inflow)) ||
1659  (k == ndhi.z && ( bchi[2] == LinOpBCType::Neumann ||
1660  bchi[2] == LinOpBCType::inflow))) {
1661  fac *= Real(2.);
1662  }
1663  }
1664  resid(i,j,k) = (rhs(i,j,k) - resid(i,j,k)) * fac;
1665  } else {
1666  resid(i,j,k) = Real(0.);
1667  }
1668 }
1669 
1670 //
1671 // sync residual
1672 //
1673 
1674  template <typename P, typename S>
1676  Real mlndlap_sum_Ax (P const& pred, S const& sig,
1677  int i, int j, int k, Real facx, Real facy, Real facz,
1678  Array4<Real const> const& phi) noexcept
1679  {
1680  Real Ax = Real(0.0);
1681  if (pred(i-1,j-1,k-1)) {
1682  Ax += sig(i-1,j-1,k-1)*(facx*(Real(4.)*(phi(i-1,j ,k )-phi(i ,j ,k ))
1683  +Real(2.)*(phi(i-1,j-1,k )-phi(i ,j-1,k ))
1684  +Real(2.)*(phi(i-1,j ,k-1)-phi(i ,j ,k-1))
1685  + (phi(i-1,j-1,k-1)-phi(i ,j-1,k-1)))
1686  + facy*(Real(4.)*(phi(i ,j-1,k )-phi(i ,j ,k ))
1687  +Real(2.)*(phi(i-1,j-1,k )-phi(i-1,j ,k ))
1688  +Real(2.)*(phi(i ,j-1,k-1)-phi(i ,j ,k-1))
1689  + (phi(i-1,j-1,k-1)-phi(i-1,j ,k-1)))
1690  + facz*(Real(4.)*(phi(i ,j ,k-1)-phi(i ,j ,k ))
1691  +Real(2.)*(phi(i-1,j ,k-1)-phi(i-1,j ,k ))
1692  +Real(2.)*(phi(i ,j-1,k-1)-phi(i ,j-1,k ))
1693  + (phi(i-1,j-1,k-1)-phi(i-1,j-1,k ))));
1694  }
1695  if (pred(i,j-1,k-1)) {
1696  Ax += sig(i,j-1,k-1)*(facx*(Real(4.)*(phi(i+1,j ,k )-phi(i ,j ,k ))
1697  +Real(2.)*(phi(i+1,j-1,k )-phi(i ,j-1,k ))
1698  +Real(2.)*(phi(i+1,j ,k-1)-phi(i ,j ,k-1))
1699  + (phi(i+1,j-1,k-1)-phi(i ,j-1,k-1)))
1700  + facy*(Real(4.)*(phi(i ,j-1,k )-phi(i ,j ,k ))
1701  +Real(2.)*(phi(i+1,j-1,k )-phi(i+1,j ,k ))
1702  +Real(2.)*(phi(i ,j-1,k-1)-phi(i ,j ,k-1))
1703  + (phi(i+1,j-1,k-1)-phi(i+1,j ,k-1)))
1704  + facz*(Real(4.)*(phi(i ,j ,k-1)-phi(i ,j ,k ))
1705  +Real(2.)*(phi(i+1,j ,k-1)-phi(i+1,j ,k ))
1706  +Real(2.)*(phi(i ,j-1,k-1)-phi(i ,j-1,k ))
1707  + (phi(i+1,j-1,k-1)-phi(i+1,j-1,k ))));
1708  }
1709  if (pred(i-1,j,k-1)) {
1710  Ax += sig(i-1,j,k-1)*(facx*(Real(4.)*(phi(i-1,j ,k )-phi(i ,j ,k ))
1711  +Real(2.)*(phi(i-1,j+1,k )-phi(i ,j+1,k ))
1712  +Real(2.)*(phi(i-1,j ,k-1)-phi(i ,j ,k-1))
1713  + (phi(i-1,j+1,k-1)-phi(i ,j+1,k-1)))
1714  + facy*(Real(4.)*(phi(i ,j+1,k )-phi(i ,j ,k ))
1715  +Real(2.)*(phi(i-1,j+1,k )-phi(i-1,j ,k ))
1716  +Real(2.)*(phi(i ,j+1,k-1)-phi(i ,j ,k-1))
1717  + (phi(i-1,j+1,k-1)-phi(i-1,j ,k-1)))
1718  + facz*(Real(4.)*(phi(i ,j ,k-1)-phi(i ,j ,k ))
1719  +Real(2.)*(phi(i-1,j ,k-1)-phi(i-1,j ,k ))
1720  +Real(2.)*(phi(i ,j+1,k-1)-phi(i ,j+1,k ))
1721  + (phi(i-1,j+1,k-1)-phi(i-1,j+1,k ))));
1722  }
1723  if (pred(i,j,k-1)) {
1724  Ax += sig(i,j,k-1)*(facx*(Real(4.)*(phi(i+1,j ,k )-phi(i ,j ,k ))
1725  +Real(2.)*(phi(i+1,j+1,k )-phi(i ,j+1,k ))
1726  +Real(2.)*(phi(i+1,j ,k-1)-phi(i ,j ,k-1))
1727  + (phi(i+1,j+1,k-1)-phi(i ,j+1,k-1)))
1728  + facy*(Real(4.)*(phi(i ,j+1,k )-phi(i ,j ,k ))
1729  +Real(2.)*(phi(i+1,j+1,k )-phi(i+1,j ,k ))
1730  +Real(2.)*(phi(i ,j+1,k-1)-phi(i ,j ,k-1))
1731  + (phi(i+1,j+1,k-1)-phi(i+1,j ,k-1)))
1732  + facz*(Real(4.)*(phi(i ,j ,k-1)-phi(i ,j ,k ))
1733  +Real(2.)*(phi(i+1,j ,k-1)-phi(i+1,j ,k ))
1734  +Real(2.)*(phi(i ,j+1,k-1)-phi(i ,j+1,k ))
1735  + (phi(i+1,j+1,k-1)-phi(i+1,j+1,k ))));
1736  }
1737  if (pred(i-1,j-1,k)) {
1738  Ax += sig(i-1,j-1,k)*(facx*(Real(4.)*(phi(i-1,j ,k )-phi(i ,j ,k ))
1739  +Real(2.)*(phi(i-1,j-1,k )-phi(i ,j-1,k ))
1740  +Real(2.)*(phi(i-1,j ,k+1)-phi(i ,j ,k+1))
1741  + (phi(i-1,j-1,k+1)-phi(i ,j-1,k+1)))
1742  + facy*(Real(4.)*(phi(i ,j-1,k )-phi(i ,j ,k ))
1743  +Real(2.)*(phi(i-1,j-1,k )-phi(i-1,j ,k ))
1744  +Real(2.)*(phi(i ,j-1,k+1)-phi(i ,j ,k+1))
1745  + (phi(i-1,j-1,k+1)-phi(i-1,j ,k+1)))
1746  + facz*(Real(4.)*(phi(i ,j ,k+1)-phi(i ,j ,k ))
1747  +Real(2.)*(phi(i-1,j ,k+1)-phi(i-1,j ,k ))
1748  +Real(2.)*(phi(i ,j-1,k+1)-phi(i ,j-1,k ))
1749  + (phi(i-1,j-1,k+1)-phi(i-1,j-1,k ))));
1750  }
1751  if (pred(i,j-1,k)) {
1752  Ax += sig(i,j-1,k)*(facx*(Real(4.)*(phi(i+1,j ,k )-phi(i ,j ,k ))
1753  +Real(2.)*(phi(i+1,j-1,k )-phi(i ,j-1,k ))
1754  +Real(2.)*(phi(i+1,j ,k+1)-phi(i ,j ,k+1))
1755  + (phi(i+1,j-1,k+1)-phi(i ,j-1,k+1)))
1756  + facy*(Real(4.)*(phi(i ,j-1,k )-phi(i ,j ,k ))
1757  +Real(2.)*(phi(i+1,j-1,k )-phi(i+1,j ,k ))
1758  +Real(2.)*(phi(i ,j-1,k+1)-phi(i ,j ,k+1))
1759  + (phi(i+1,j-1,k+1)-phi(i+1,j ,k+1)))
1760  + facz*(Real(4.)*(phi(i ,j ,k+1)-phi(i ,j ,k ))
1761  +Real(2.)*(phi(i+1,j ,k+1)-phi(i+1,j ,k ))
1762  +Real(2.)*(phi(i ,j-1,k+1)-phi(i ,j-1,k ))
1763  + (phi(i+1,j-1,k+1)-phi(i+1,j-1,k ))));
1764  }
1765  if (pred(i-1,j,k)) {
1766  Ax += sig(i-1,j,k)*(facx*(Real(4.)*(phi(i-1,j ,k )-phi(i ,j ,k ))
1767  +Real(2.)*(phi(i-1,j+1,k )-phi(i ,j+1,k ))
1768  +Real(2.)*(phi(i-1,j ,k+1)-phi(i ,j ,k+1))
1769  + (phi(i-1,j+1,k+1)-phi(i ,j+1,k+1)))
1770  + facy*(Real(4.)*(phi(i ,j+1,k )-phi(i ,j ,k ))
1771  +Real(2.)*(phi(i-1,j+1,k )-phi(i-1,j ,k ))
1772  +Real(2.)*(phi(i ,j+1,k+1)-phi(i ,j ,k+1))
1773  + (phi(i-1,j+1,k+1)-phi(i-1,j ,k+1)))
1774  + facz*(Real(4.)*(phi(i ,j ,k+1)-phi(i ,j ,k ))
1775  +Real(2.)*(phi(i-1,j ,k+1)-phi(i-1,j ,k ))
1776  +Real(2.)*(phi(i ,j+1,k+1)-phi(i ,j+1,k ))
1777  + (phi(i-1,j+1,k+1)-phi(i-1,j+1,k ))));
1778  }
1779  if (pred(i,j,k)) {
1780  Ax += sig(i,j,k)*(facx*(Real(4.)*(phi(i+1,j ,k )-phi(i ,j ,k ))
1781  +Real(2.)*(phi(i+1,j+1,k )-phi(i ,j+1,k ))
1782  +Real(2.)*(phi(i+1,j ,k+1)-phi(i ,j ,k+1))
1783  + (phi(i+1,j+1,k+1)-phi(i ,j+1,k+1)))
1784  + facy*(Real(4.)*(phi(i ,j+1,k )-phi(i ,j ,k ))
1785  +Real(2.)*(phi(i+1,j+1,k )-phi(i+1,j ,k ))
1786  +Real(2.)*(phi(i ,j+1,k+1)-phi(i ,j ,k+1))
1787  + (phi(i+1,j+1,k+1)-phi(i+1,j ,k+1)))
1788  + facz*(Real(4.)*(phi(i ,j ,k+1)-phi(i ,j ,k ))
1789  +Real(2.)*(phi(i+1,j ,k+1)-phi(i+1,j ,k ))
1790  +Real(2.)*(phi(i ,j+1,k+1)-phi(i ,j+1,k ))
1791  + (phi(i+1,j+1,k+1)-phi(i+1,j+1,k ))));
1792  }
1793  return Ax;
1794  }
1795 
1796  template <int rr, typename S>
1798  void mlndlap_Ax_fine_contrib_doit (S const& sig,
1799  int i, int j, int k, Box const& ndbx, Box const& ccbx,
1800  Array4<Real> const& f, Array4<Real const> const& res,
1801  Array4<Real const> const& rhs,
1802  Array4<Real const> const& phi,
1803  Array4<int const> const& msk,
1804  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
1805  {
1806  const int ii = rr*i;
1807  const int jj = rr*j;
1808  const int kk = rr*k;
1809  if (msk(ii,jj,kk)) {
1810  Real facx = Real(1./36.)*dxinv[0]*dxinv[0];
1811  Real facy = Real(1./36.)*dxinv[1]*dxinv[1];
1812  Real facz = Real(1./36.)*dxinv[2]*dxinv[2];
1813 
1814  auto is_fine = [&ccbx] (int ix, int iy, int iz) -> bool {
1815  return ccbx.contains(ix,iy,iz);
1816  };
1817 
1818  Real Df = Real(0.0);
1819 
1820  const int ilo = amrex::max(ii-rr+1, ndbx.smallEnd(0));
1821  const int ihi = amrex::min(ii+rr-1, ndbx.bigEnd (0));
1822  const int jlo = amrex::max(jj-rr+1, ndbx.smallEnd(1));
1823  const int jhi = amrex::min(jj+rr-1, ndbx.bigEnd (1));
1824  const int klo = amrex::max(kk-rr+1, ndbx.smallEnd(2));
1825  const int khi = amrex::min(kk+rr-1, ndbx.bigEnd (2));
1826 
1827  for (int koff = klo; koff <= khi; ++koff) {
1828  for (int joff = jlo; joff <= jhi; ++joff) {
1829  for (int ioff = ilo; ioff <= ihi; ++ioff) {
1830  Real scale = static_cast<Real>((rr-std::abs(ii-ioff)) *
1831  (rr-std::abs(jj-joff)) *
1832  (rr-std::abs(kk-koff)));
1833  if (ndbx.strictly_contains(ioff,joff,koff)) {
1834  Df += scale * (rhs(ioff,joff,koff)-res(ioff,joff,koff));
1835  } else {
1836  Df += scale * mlndlap_sum_Ax
1837  (is_fine, sig, ioff, joff, koff, facx, facy, facz, phi);
1838  }
1839  }}}
1840 
1841  f(i,j,k) = Df * (Real(1.0)/static_cast<Real>(rr*rr*rr*rr*rr*rr));
1842  } else {
1843  f(i,j,k) = Real(0.0);
1844  }
1845  }
1846 
1847 template <int rr>
1849 void mlndlap_Ax_fine_contrib (int i, int j, int k, Box const& ndbx, Box const& ccbx,
1850  Array4<Real> const& f, Array4<Real const> const& res,
1851  Array4<Real const> const& rhs, Array4<Real const> const& phi,
1852  Array4<Real const> const& sig, Array4<int const> const& msk,
1853  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
1854 {
1855  mlndlap_Ax_fine_contrib_doit<rr>
1856  ([&sig] (int ix, int iy, int iz) -> Real const& { return sig(ix,iy,iz); },
1857  i,j,k,ndbx,ccbx,f,res,rhs,phi,msk,dxinv);
1858 }
1859 
1860 template <int rr>
1862 void mlndlap_Ax_fine_contrib_cs (int i, int j, int k, Box const& ndbx, Box const& ccbx,
1863  Array4<Real> const& f, Array4<Real const> const& res,
1864  Array4<Real const> const& rhs, Array4<Real const> const& phi,
1865  Real const sig, Array4<int const> const& msk,
1866  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
1867 {
1868  mlndlap_Ax_fine_contrib_doit<rr>
1869  ([=] (int, int, int) -> Real { return sig; },
1870  i,j,k,ndbx,ccbx,f,res,rhs,phi,msk,dxinv);
1871 }
1872 
1874 void mlndlap_res_cf_contrib (int i, int j, int k, Array4<Real> const& res,
1875  Array4<Real const> const& phi, Array4<Real const> const& rhs,
1876  Array4<Real const> const& sig, Array4<int const> const& dmsk,
1877  Array4<int const> const& ndmsk, Array4<int const> const& ccmsk,
1878  Array4<Real const> const& fc,
1879  GpuArray<Real,AMREX_SPACEDIM> const& dxinv,
1880  Box const& ccdom_p, Box const& nddom,
1883  bool neumann_doubling) noexcept
1884 {
1885  using namespace nodelap_detail;
1886 
1887  if (!dmsk(i,j,k) && ndmsk(i,j,k) == crse_fine_node) {
1888  Real facx = Real(1./36.)*dxinv[0]*dxinv[0];
1889  Real facy = Real(1./36.)*dxinv[1]*dxinv[1];
1890  Real facz = Real(1./36.)*dxinv[2]*dxinv[2];
1891 
1892  Real Ax = mlndlap_sum_Ax([&ccmsk, &ccdom_p] (int ix, int iy, int iz) -> bool
1893  {
1894  return ccdom_p.contains(ix,iy,iz)
1895  && (ccmsk(ix,iy,iz) == crse_cell);
1896  },
1897  [&sig] (int ix, int iy, int iz) -> Real const&
1898  {
1899  return sig(ix,iy,iz);
1900  },
1901  i, j, k, facx, facy, facz, phi);
1902  Ax += fc(i,j,k);
1903  Real const ns = (neumann_doubling) ? neumann_scale(i,j,k,nddom,bclo,bchi) : Real(1.0);
1904  res(i,j,k) = rhs(i,j,k) - Ax*ns;
1905  }
1906 }
1907 
1909 void mlndlap_res_cf_contrib_cs (int i, int j, int k, Array4<Real> const& res,
1910  Array4<Real const> const& phi, Array4<Real const> const& rhs,
1911  Real const sig, Array4<int const> const& dmsk,
1912  Array4<int const> const& ndmsk, Array4<int const> const& ccmsk,
1913  Array4<Real const> const& fc,
1914  GpuArray<Real,AMREX_SPACEDIM> const& dxinv,
1915  Box const& ccdom_p, Box const& nddom,
1918  bool neumann_doubling) noexcept
1919 {
1920  using namespace nodelap_detail;
1921 
1922  if (!dmsk(i,j,k) && ndmsk(i,j,k) == crse_fine_node) {
1923  Real facx = Real(1./36.)*dxinv[0]*dxinv[0];
1924  Real facy = Real(1./36.)*dxinv[1]*dxinv[1];
1925  Real facz = Real(1./36.)*dxinv[2]*dxinv[2];
1926 
1927  Real Ax = mlndlap_sum_Ax([&ccmsk, &ccdom_p] (int ix, int iy, int iz) -> bool
1928  {
1929  return ccdom_p.contains(ix,iy,iz)
1930  && (ccmsk(ix,iy,iz) == crse_cell);
1931  },
1932  [=] (int, int, int) -> Real
1933  {
1934  return sig;
1935  },
1936  i, j, k, facx, facy, facz, phi);
1937  Ax += fc(i,j,k);
1938  Real const ns = (neumann_doubling) ? neumann_scale(i,j,k,nddom,bclo,bchi) : Real(1.0);
1939  res(i,j,k) = rhs(i,j,k) - Ax*ns;
1940  }
1941 }
1942 
1943 //
1944 // RAP
1945 //
1946 
1947 namespace nodelap_detail {
1948 
1949  constexpr int ist_000 = 0;
1950  constexpr int ist_p00 = 1;
1951  constexpr int ist_0p0 = 2;
1952  constexpr int ist_00p = 3;
1953  constexpr int ist_pp0 = 4;
1954  constexpr int ist_p0p = 5;
1955  constexpr int ist_0pp = 6;
1956  constexpr int ist_ppp = 7;
1957  constexpr int ist_inv = 8;
1958  constexpr int n_sten = 9;
1959 }
1960 
1962 void mlndlap_set_stencil (Box const& bx, Array4<Real> const& sten,
1963  Array4<Real const> const& sig,
1964  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
1965 {
1966  using namespace nodelap_detail;
1967 
1968  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
1969  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
1970  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
1971  Real fxyz = facx + facy + facz;
1972  Real fmx2y2z = -facx + Real(2.0)*facy + Real(2.0)*facz;
1973  Real f2xmy2z = Real(2.0)*facx - facy + Real(2.0)*facz;
1974  Real f2x2ymz = Real(2.0)*facx + Real(2.0)*facy - facz;
1975  Real f4xm2ym2z = Real(4.0)*facx - Real(2.0)*facy - Real(2.0)*facz;
1976  Real fm2x4ym2z = -Real(2.0)*facx + Real(4.0)*facy - Real(2.0)*facz;
1977  Real fm2xm2y4z = -Real(2.0)*facx - Real(2.0)*facy + Real(4.0)*facz;
1978 
1979  amrex::LoopConcurrent(bx, [=] (int i, int j, int k) noexcept
1980  {
1981  // i+1,j,k
1982  sten(i,j,k,ist_p00) = f4xm2ym2z * (sig(i,j-1,k-1)+sig(i,j,k-1)+sig(i,j-1,k)+sig(i,j,k));
1983  // i-1,j,k: sten(i-1,j,k,ist_p00)
1984 
1985  // i,j+1,k
1986  sten(i,j,k,ist_0p0) = fm2x4ym2z * (sig(i-1,j,k-1)+sig(i,j,k-1)+sig(i-1,j,k)+sig(i,j,k));
1987  // i,j-1,k: sten(i,j-1,k,ist_0p0)
1988 
1989  // i,j,k+1
1990  sten(i,j,k,ist_00p) = fm2xm2y4z * (sig(i-1,j-1,k)+sig(i,j-1,k)+sig(i-1,j,k)+sig(i,j,k));
1991  // i,j,k-1: sten(i,j,k-1,ist_00p)
1992 
1993  // i+1,j+1,k
1994  sten(i,j,k,ist_pp0) = f2x2ymz * (sig(i,j,k-1)+sig(i,j,k));
1995  // i-1,j-1,k: sten(i-1,j-1,k,ist_pp0)
1996  // i+1,j-1,k: sten(i ,j-1,k,ist_pp0)
1997  // i-1,j+1,k: sten(i-1,j ,k,ist_pp0)
1998 
1999  // i+1,j,k+1
2000  sten(i,j,k,ist_p0p) = f2xmy2z * (sig(i,j-1,k)+sig(i,j,k));
2001  // i-1,j,k-1: sten(i-1,j,k-1,ist_p0p)
2002  // i+1,j,k-1: sten(i ,j,k-1,ist_p0p)
2003  // i-1,j,k+1: sten(i-1,j,k ,ist_p0p)
2004 
2005  // i,j+1,k+1
2006  sten(i,j,k,ist_0pp) = fmx2y2z * (sig(i-1,j,k)+sig(i,j,k));
2007  // i,j-1,k-1: sten(i,j-1,k-1,ist_0pp)
2008  // i,j+1,k-1: sten(i,j ,k-1,ist_0pp)
2009  // i,j-1,k+1: sten(i,j-1,k ,ist_0pp)
2010 
2011  // i+1,j+1,k+1
2012  sten(i,j,k,ist_ppp) = fxyz * sig(i,j,k);
2013  // i-1,j-1,k-1: sten(i-1,j-1,k-1,ist_ppp)
2014  // i+1,j-1,k-1: sten(i ,j-1,k-1,ist_ppp)
2015  // i-1,j+1,k-1: sten(i-1,j ,k-1,ist_ppp)
2016  // i+1,j+1,k-1: sten(i ,j ,k-1,ist_ppp)
2017  // i-1,j-1,k+1: sten(i-1,j-1,k ,ist_ppp)
2018  // i+1,j-1,k+1: sten(i ,j-1,k ,ist_ppp)
2019  // i-1,j+1,k+1: sten(i-1,j ,k ,ist_ppp)
2020  });
2021 }
2022 
2024 void mlndlap_set_stencil_s0 (int i, int j, int k, Array4<Real> const& sten) noexcept
2025 {
2026  using namespace nodelap_detail;
2027 
2028  sten(i,j,k,ist_000) = -(sten(i-1,j,k,ist_p00) + sten(i,j,k,ist_p00)
2029  + sten(i,j-1,k,ist_0p0) + sten(i,j,k,ist_0p0)
2030  + sten(i,j,k-1,ist_00p) + sten(i,j,k,ist_00p)
2031  + sten(i-1,j-1,k,ist_pp0) + sten(i,j-1,k,ist_pp0)
2032  + sten(i-1,j,k,ist_pp0) + sten(i,j,k,ist_pp0)
2033  + sten(i-1,j,k-1,ist_p0p) + sten(i,j,k-1,ist_p0p)
2034  + sten(i-1,j,k,ist_p0p) + sten(i,j,k,ist_p0p)
2035  + sten(i,j-1,k-1,ist_0pp) + sten(i,j,k-1,ist_0pp)
2036  + sten(i,j-1,k,ist_0pp) + sten(i,j,k,ist_0pp)
2037  + sten(i-1,j-1,k-1,ist_ppp) + sten(i,j-1,k-1,ist_ppp)
2038  + sten(i-1,j,k-1,ist_ppp) + sten(i,j,k-1,ist_ppp)
2039  + sten(i-1,j-1,k,ist_ppp) + sten(i,j-1,k,ist_ppp)
2040  + sten(i-1,j,k,ist_ppp) + sten(i,j,k,ist_ppp));
2041  sten(i,j,k,ist_inv) = Real(1.0) /
2042  ( std::abs(sten(i-1,j,k,ist_p00)) + std::abs(sten(i,j,k,ist_p00))
2043  + std::abs(sten(i,j-1,k,ist_0p0)) + std::abs(sten(i,j,k,ist_0p0))
2044  + std::abs(sten(i,j,k-1,ist_00p)) + std::abs(sten(i,j,k,ist_00p))
2045  + std::abs(sten(i-1,j-1,k,ist_pp0)) + std::abs(sten(i,j-1,k,ist_pp0))
2046  + std::abs(sten(i-1,j,k,ist_pp0)) + std::abs(sten(i,j,k,ist_pp0))
2047  + std::abs(sten(i-1,j,k-1,ist_p0p)) + std::abs(sten(i,j,k-1,ist_p0p))
2048  + std::abs(sten(i-1,j,k,ist_p0p)) + std::abs(sten(i,j,k,ist_p0p))
2049  + std::abs(sten(i,j-1,k-1,ist_0pp)) + std::abs(sten(i,j,k-1,ist_0pp))
2050  + std::abs(sten(i,j-1,k,ist_0pp)) + std::abs(sten(i,j,k,ist_0pp))
2051  + std::abs(sten(i-1,j-1,k-1,ist_ppp)) + std::abs(sten(i,j-1,k-1,ist_ppp))
2052  + std::abs(sten(i-1,j,k-1,ist_ppp)) + std::abs(sten(i,j,k-1,ist_ppp))
2053  + std::abs(sten(i-1,j-1,k,ist_ppp)) + std::abs(sten(i,j-1,k,ist_ppp))
2054  + std::abs(sten(i-1,j,k,ist_ppp)) + std::abs(sten(i,j,k,ist_ppp)) + eps);
2055 }
2056 
2058 void mlndlap_stencil_rap (int i, int j, int k, Array4<Real> const& csten,
2059  Array4<Real const> const& fsten) noexcept
2060 {
2061  using namespace nodelap_detail;
2062 
2063  auto interp_from_mmm_to = [&fsten] (int i_, int j_, int k_) -> Real {
2064  Real p = Real(1.);
2065  p += std::abs(fsten(i_-1,j_ ,k_ ,ist_p00)) /
2066  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2067  + std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2068  + std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp))
2069  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp)) + eps);
2070  p += std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0)) /
2071  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2072  + std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2073  + std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp))
2074  + std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp)) + eps);
2075  p += std::abs(fsten(i_ ,j_ ,k_-1,ist_00p)) /
2076  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2077  + std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2078  + std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2079  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp)) + eps);
2080  p += std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0)) /
2081  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2082  + std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp)) + eps);
2083  p += std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p)) /
2084  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2085  + std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp)) + eps);
2086  p += std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp)) /
2087  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2088  + std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp)) + eps);
2089  p *= std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp)) * fsten(i_,j_,k_,ist_inv);
2090  return p;
2091  };
2092  amrex::ignore_unused(interp_from_mmm_to);
2093 
2094  auto interp_from_pmm_to = [&fsten] (int i_, int j_, int k_) -> Real {
2095  Real p = Real(1.);
2096  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_p00)) /
2097  ( std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2098  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp))
2099  + std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp))
2100  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2101  p += std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0)) /
2102  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2103  + std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2104  + std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp))
2105  + std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp)) + eps);
2106  p += std::abs(fsten(i_ ,j_ ,k_-1,ist_00p)) /
2107  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2108  + std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2109  + std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2110  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp)) + eps);
2111  p += std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0)) /
2112  ( std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2113  + std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp)) + eps);
2114  p += std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p)) /
2115  ( std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2116  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp)) + eps);
2117  p += std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp)) /
2118  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2119  + std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp)) + eps);
2120  p *= std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp)) * fsten(i_,j_,k_,ist_inv);
2121  return p;
2122  };
2123 
2124  auto interp_from_mpm_to = [&fsten] (int i_, int j_, int k_) -> Real {
2125  Real p = Real(1.);
2126  p += std::abs(fsten(i_-1,j_ ,k_ ,ist_p00)) /
2127  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2128  + std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2129  + std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp))
2130  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp)) + eps);
2131  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0)) /
2132  ( std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2133  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp))
2134  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp))
2135  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2136  p += std::abs(fsten(i_ ,j_ ,k_-1,ist_00p)) /
2137  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2138  + std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2139  + std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2140  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp)) + eps);
2141  p += std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0)) /
2142  ( std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2143  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp)) + eps);
2144  p += std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p)) /
2145  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2146  + std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp)) + eps);
2147  p += std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp)) /
2148  ( std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2149  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp)) + eps);
2150  p *= std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp)) * fsten(i_,j_,k_,ist_inv);
2151  return p;
2152  };
2153 
2154  auto interp_from_ppm_to = [&fsten] (int i_, int j_, int k_) -> Real {
2155  Real p = Real(1.);
2156  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_p00)) /
2157  ( std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2158  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp))
2159  + std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp))
2160  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2161  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0)) /
2162  ( std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2163  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp))
2164  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp))
2165  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2166  p += std::abs(fsten(i_ ,j_ ,k_-1,ist_00p)) /
2167  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2168  + std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2169  + std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2170  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp)) + eps);
2171  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) /
2172  ( std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp))
2173  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2174  p += std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p)) /
2175  ( std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2176  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp)) + eps);
2177  p += std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp)) /
2178  ( std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2179  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp)) + eps);
2180  p *= std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp)) * fsten(i_,j_,k_,ist_inv);
2181  return p;
2182  };
2183 
2184  auto interp_from_mmp_to = [&fsten] (int i_, int j_, int k_) -> Real {
2185  Real p = Real(1.);
2186  p += std::abs(fsten(i_-1,j_ ,k_ ,ist_p00)) /
2187  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2188  + std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2189  + std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp))
2190  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp)) + eps);
2191  p += std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0)) /
2192  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2193  + std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2194  + std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp))
2195  + std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp)) + eps);
2196  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_00p)) /
2197  ( std::abs(fsten(i_-1,j_-1,k_,ist_ppp))
2198  + std::abs(fsten(i_ ,j_-1,k_,ist_ppp))
2199  + std::abs(fsten(i_-1,j_ ,k_,ist_ppp))
2200  + std::abs(fsten(i_ ,j_ ,k_,ist_ppp)) + eps);
2201  p += std::abs(fsten(i_-1,j_-1,k_,ist_pp0)) /
2202  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2203  + std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp)) + eps);
2204  p += std::abs(fsten(i_-1,j_ ,k_,ist_p0p)) /
2205  ( std::abs(fsten(i_-1,j_-1,k_,ist_ppp))
2206  + std::abs(fsten(i_-1,j_ ,k_,ist_ppp)) + eps);
2207  p += std::abs(fsten(i_ ,j_-1,k_,ist_0pp)) /
2208  ( std::abs(fsten(i_-1,j_-1,k_,ist_ppp))
2209  + std::abs(fsten(i_ ,j_-1,k_,ist_ppp)) + eps);
2210  p *= std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp)) * fsten(i_,j_,k_,ist_inv);
2211  return p;
2212  };
2213 
2214  auto interp_from_pmp_to = [&fsten] (int i_, int j_, int k_) -> Real {
2215  Real p = Real(1.);
2216  p += std::abs(fsten(i_ ,j_ ,k_,ist_p00)) /
2217  ( std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2218  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp))
2219  + std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp))
2220  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2221  p += std::abs(fsten(i_ ,j_-1,k_,ist_0p0)) /
2222  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2223  + std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2224  + std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp))
2225  + std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp)) + eps);
2226  p += std::abs(fsten(i_ ,j_ ,k_,ist_00p)) /
2227  ( std::abs(fsten(i_-1,j_-1,k_,ist_ppp))
2228  + std::abs(fsten(i_ ,j_-1,k_,ist_ppp))
2229  + std::abs(fsten(i_-1,j_ ,k_,ist_ppp))
2230  + std::abs(fsten(i_ ,j_ ,k_,ist_ppp)) + eps);
2231  p += std::abs(fsten(i_ ,j_-1,k_,ist_pp0)) /
2232  ( std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2233  + std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp)) + eps);
2234  p += std::abs(fsten(i_ ,j_ ,k_,ist_p0p)) /
2235  ( std::abs(fsten(i_ ,j_-1,k_,ist_ppp))
2236  + std::abs(fsten(i_ ,j_ ,k_,ist_ppp)) + eps);
2237  p += std::abs(fsten(i_ ,j_-1,k_,ist_0pp)) /
2238  ( std::abs(fsten(i_-1,j_-1,k_,ist_ppp))
2239  + std::abs(fsten(i_ ,j_-1,k_,ist_ppp)) + eps);
2240  p *= std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp)) * fsten(i_,j_ ,k_,ist_inv);
2241  return p;
2242  };
2243 
2244  auto interp_from_mpp_to = [&fsten] (int i_, int j_, int k_) -> Real {
2245  Real p = Real(1.);
2246  p += std::abs(fsten(i_-1,j_ ,k_ ,ist_p00)) /
2247  ( std::abs(fsten(i_-1,j_-1,k_-1,ist_ppp))
2248  + std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2249  + std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp))
2250  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp)) + eps);
2251  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0)) /
2252  ( std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2253  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp))
2254  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp))
2255  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2256  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_00p)) /
2257  ( std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp))
2258  + std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp))
2259  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp))
2260  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2261  p += std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0)) /
2262  ( std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2263  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp)) + eps);
2264  p += std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p)) /
2265  ( std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp))
2266  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp)) + eps);
2267  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) /
2268  ( std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp))
2269  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2270  p *= std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp)) * fsten(i_,j_,k_,ist_inv);
2271  return p;
2272  };
2273 
2274  auto interp_from_ppp_to = [&fsten] (int i_, int j_, int k_) -> Real {
2275  Real p = Real(1.);
2276  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_p00)) /
2277  ( std::abs(fsten(i_ ,j_-1,k_-1,ist_ppp))
2278  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp))
2279  + std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp))
2280  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2281  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0)) /
2282  ( std::abs(fsten(i_-1,j_ ,k_-1,ist_ppp))
2283  + std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp))
2284  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp))
2285  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2286  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_00p)) /
2287  ( std::abs(fsten(i_-1,j_-1,k_ ,ist_ppp))
2288  + std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp))
2289  + std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp))
2290  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2291  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) /
2292  ( std::abs(fsten(i_ ,j_ ,k_-1,ist_ppp))
2293  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2294  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) /
2295  ( std::abs(fsten(i_ ,j_-1,k_ ,ist_ppp))
2296  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2297  p += std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) /
2298  ( std::abs(fsten(i_-1,j_ ,k_ ,ist_ppp))
2299  + std::abs(fsten(i_ ,j_ ,k_ ,ist_ppp)) + eps);
2300  p *= std::abs(fsten(i_ ,j_ ,k_,ist_ppp)) * fsten(i_,j_,k_,ist_inv);
2301  return p;
2302  };
2303 
2304  auto interp_from_0mm_to = [&fsten] (int i_, int j_, int k_) -> Real {
2305  Real w1m = std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0)) / (std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp))
2306  +std::abs(fsten(i_ ,j_-1,k_ ,ist_0pp)) + eps);
2307  Real w1p = std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0)) / (std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp))
2308  +std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) + eps);
2309  Real w2m = std::abs(fsten(i_ ,j_ ,k_-1,ist_00p)) / (std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp))
2310  +std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp)) + eps);
2311  Real w2p = std::abs(fsten(i_ ,j_ ,k_ ,ist_00p)) / (std::abs(fsten(i_ ,j_-1,k_ ,ist_0pp))
2312  +std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) + eps);
2313  Real wmm = std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp)) * (Real(1.) + w1m + w2m);
2314  Real wpm = std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp)) * (Real(1.) + w1p + w2m);
2315  Real wmp = std::abs(fsten(i_ ,j_-1,k_ ,ist_0pp)) * (Real(1.) + w1m + w2p);
2316  Real wpp = std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) * (Real(1.) + w1p + w2p);
2317  return wmm / (wmm+wpm+wmp+wpp+eps);
2318  };
2319 
2320  auto interp_from_0mp_to = [&fsten] (int i_, int j_, int k_) -> Real {
2321  Real w1m = std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0)) / (std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp))
2322  +std::abs(fsten(i_ ,j_-1,k_ ,ist_0pp)) + eps);
2323  Real w1p = std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0)) / (std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp))
2324  +std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) + eps);
2325  Real w2m = std::abs(fsten(i_ ,j_ ,k_-1,ist_00p)) / (std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp))
2326  +std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp)) + eps);
2327  Real w2p = std::abs(fsten(i_ ,j_ ,k_ ,ist_00p)) / (std::abs(fsten(i_ ,j_-1,k_ ,ist_0pp))
2328  +std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) + eps);
2329  Real wmm = std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp)) * (Real(1.) + w1m + w2m);
2330  Real wpm = std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp)) * (Real(1.) + w1p + w2m);
2331  Real wmp = std::abs(fsten(i_ ,j_-1,k_ ,ist_0pp)) * (Real(1.) + w1m + w2p);
2332  Real wpp = std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) * (Real(1.) + w1p + w2p);
2333  return wmp / (wmm+wpm+wmp+wpp+eps);
2334  };
2335 
2336  auto interp_from_0pm_to = [&fsten] (int i_, int j_, int k_) -> Real {
2337  Real w1m = std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0)) / (std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp))
2338  +std::abs(fsten(i_ ,j_-1,k_ ,ist_0pp)) + eps);
2339  Real w1p = std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0)) / (std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp))
2340  +std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) + eps);
2341  Real w2m = std::abs(fsten(i_ ,j_ ,k_-1,ist_00p)) / (std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp))
2342  +std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp)) + eps);
2343  Real w2p = std::abs(fsten(i_ ,j_ ,k_ ,ist_00p)) / (std::abs(fsten(i_ ,j_-1,k_ ,ist_0pp))
2344  +std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) + eps);
2345  Real wmm = std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp)) * (Real(1.) + w1m + w2m);
2346  Real wpm = std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp)) * (Real(1.) + w1p + w2m);
2347  Real wmp = std::abs(fsten(i_ ,j_-1,k_ ,ist_0pp)) * (Real(1.) + w1m + w2p);
2348  Real wpp = std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) * (Real(1.) + w1p + w2p);
2349  return wpm / (wmm+wpm+wmp+wpp+eps);
2350  };
2351 
2352  auto interp_from_0pp_to = [&fsten] (int i_, int j_, int k_) -> Real {
2353  Real w1m = std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0)) / (std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp))
2354  +std::abs(fsten(i_ ,j_-1,k_ ,ist_0pp)) + eps);
2355  Real w1p = std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0)) / (std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp))
2356  +std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) + eps);
2357  Real w2m = std::abs(fsten(i_ ,j_ ,k_-1,ist_00p)) / (std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp))
2358  +std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp)) + eps);
2359  Real w2p = std::abs(fsten(i_ ,j_ ,k_ ,ist_00p)) / (std::abs(fsten(i_ ,j_-1,k_ ,ist_0pp))
2360  +std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) + eps);
2361  Real wmm = std::abs(fsten(i_ ,j_-1,k_-1,ist_0pp)) * (Real(1.) + w1m + w2m);
2362  Real wpm = std::abs(fsten(i_ ,j_ ,k_-1,ist_0pp)) * (Real(1.) + w1p + w2m);
2363  Real wmp = std::abs(fsten(i_ ,j_-1,k_ ,ist_0pp)) * (Real(1.) + w1m + w2p);
2364  Real wpp = std::abs(fsten(i_ ,j_ ,k_ ,ist_0pp)) * (Real(1.) + w1p + w2p);
2365  return wpp / (wmm+wpm+wmp+wpp+eps);
2366  };
2367 
2368  auto interp_from_m0m_to = [&fsten] (int i_, int j_, int k_) -> Real {
2369  Real w1m = std::abs(fsten(i_-1,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p))
2370  +std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p)) + eps);
2371  Real w1p = std::abs(fsten(i_ ,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p))
2372  +std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) + eps);
2373  Real w2m = std::abs(fsten(i_ ,j_ ,k_-1,ist_00p)) / (std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p))
2374  +std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p)) + eps);
2375  Real w2p = std::abs(fsten(i_ ,j_ ,k_ ,ist_00p)) / (std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p))
2376  +std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) + eps);
2377  Real wmm = std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p)) * (Real(1.) + w1m + w2m);
2378  Real wpm = std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p)) * (Real(1.) + w1p + w2m);
2379  Real wmp = std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p)) * (Real(1.) + w1m + w2p);
2380  Real wpp = std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) * (Real(1.) + w1p + w2p);
2381  return wmm / (wmm+wpm+wmp+wpp+eps);
2382  };
2383 
2384  auto interp_from_p0m_to = [&fsten] (int i_, int j_, int k_) -> Real {
2385  Real w1m = std::abs(fsten(i_-1,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p))
2386  +std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p)) + eps);
2387  Real w1p = std::abs(fsten(i_ ,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p))
2388  +std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) + eps);
2389  Real w2m = std::abs(fsten(i_ ,j_ ,k_-1,ist_00p)) / (std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p))
2390  +std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p)) + eps);
2391  Real w2p = std::abs(fsten(i_ ,j_ ,k_ ,ist_00p)) / (std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p))
2392  +std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) + eps);
2393  Real wmm = std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p)) * (Real(1.) + w1m + w2m);
2394  Real wpm = std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p)) * (Real(1.) + w1p + w2m);
2395  Real wmp = std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p)) * (Real(1.) + w1m + w2p);
2396  Real wpp = std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) * (Real(1.) + w1p + w2p);
2397  return wpm / (wmm+wpm+wmp+wpp+eps);
2398  };
2399 
2400  auto interp_from_m0p_to = [&fsten] (int i_, int j_, int k_) -> Real {
2401  Real w1m = std::abs(fsten(i_-1,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p))
2402  +std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p)) + eps);
2403  Real w1p = std::abs(fsten(i_ ,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p))
2404  +std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) + eps);
2405  Real w2m = std::abs(fsten(i_ ,j_ ,k_-1,ist_00p)) / (std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p))
2406  +std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p)) + eps);
2407  Real w2p = std::abs(fsten(i_ ,j_ ,k_ ,ist_00p)) / (std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p))
2408  +std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) + eps);
2409  Real wmm = std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p)) * (Real(1.) + w1m + w2m);
2410  Real wpm = std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p)) * (Real(1.) + w1p + w2m);
2411  Real wmp = std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p)) * (Real(1.) + w1m + w2p);
2412  Real wpp = std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) * (Real(1.) + w1p + w2p);
2413  return wmp / (wmm+wpm+wmp+wpp+eps);
2414  };
2415 
2416  auto interp_from_p0p_to = [&fsten] (int i_, int j_, int k_) -> Real {
2417  Real w1m = std::abs(fsten(i_-1,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p))
2418  +std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p)) + eps);
2419  Real w1p = std::abs(fsten(i_ ,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p))
2420  +std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) + eps);
2421  Real w2m = std::abs(fsten(i_ ,j_ ,k_-1,ist_00p)) / (std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p))
2422  +std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p)) + eps);
2423  Real w2p = std::abs(fsten(i_ ,j_ ,k_ ,ist_00p)) / (std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p))
2424  +std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) + eps);
2425  Real wmm = std::abs(fsten(i_-1,j_ ,k_-1,ist_p0p)) * (Real(1.) + w1m + w2m);
2426  Real wpm = std::abs(fsten(i_ ,j_ ,k_-1,ist_p0p)) * (Real(1.) + w1p + w2m);
2427  Real wmp = std::abs(fsten(i_-1,j_ ,k_ ,ist_p0p)) * (Real(1.) + w1m + w2p);
2428  Real wpp = std::abs(fsten(i_ ,j_ ,k_ ,ist_p0p)) * (Real(1.) + w1p + w2p);
2429  return wpp / (wmm+wpm+wmp+wpp+eps);
2430  };
2431 
2432  auto interp_from_mm0_to = [&fsten] (int i_, int j_, int k_) -> Real {
2433  Real w1m = std::abs(fsten(i_-1,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0))
2434  +std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0)) + eps);
2435  Real w1p = std::abs(fsten(i_ ,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0))
2436  +std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) + eps);
2437  Real w2m = std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0)) / (std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0))
2438  +std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0)) + eps);
2439  Real w2p = std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0)) / (std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0))
2440  +std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) + eps);
2441  Real wmm = std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0)) * (Real(1.) + w1m + w2m);
2442  Real wpm = std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0)) * (Real(1.) + w1p + w2m);
2443  Real wmp = std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0)) * (Real(1.) + w1m + w2p);
2444  Real wpp = std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) * (Real(1.) + w1p + w2p);
2445  return wmm / (wmm+wpm+wmp+wpp+eps);
2446  };
2447 
2448  auto interp_from_mp0_to = [&fsten] (int i_, int j_, int k_) -> Real {
2449  Real w1m = std::abs(fsten(i_-1,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0))
2450  +std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0)) + eps);
2451  Real w1p = std::abs(fsten(i_ ,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0))
2452  +std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) + eps);
2453  Real w2m = std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0)) / (std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0))
2454  +std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0)) + eps);
2455  Real w2p = std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0)) / (std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0))
2456  +std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) + eps);
2457  Real wmm = std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0)) * (Real(1.) + w1m + w2m);
2458  Real wpm = std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0)) * (Real(1.) + w1p + w2m);
2459  Real wmp = std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0)) * (Real(1.) + w1m + w2p);
2460  Real wpp = std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) * (Real(1.) + w1p + w2p);
2461  return wmp / (wmm+wpm+wmp+wpp+eps);
2462  };
2463 
2464  auto interp_from_pm0_to = [&fsten] (int i_, int j_, int k_) -> Real {
2465  Real w1m = std::abs(fsten(i_-1,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0))
2466  +std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0)) + eps);
2467  Real w1p = std::abs(fsten(i_ ,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0))
2468  +std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) + eps);
2469  Real w2m = std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0)) / (std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0))
2470  +std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0)) + eps);
2471  Real w2p = std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0)) / (std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0))
2472  +std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) + eps);
2473  Real wmm = std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0)) * (Real(1.) + w1m + w2m);
2474  Real wpm = std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0)) * (Real(1.) + w1p + w2m);
2475  Real wmp = std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0)) * (Real(1.) + w1m + w2p);
2476  Real wpp = std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) * (Real(1.) + w1p + w2p);
2477  return wpm / (wmm+wpm+wmp+wpp+eps);
2478  };
2479 
2480  auto interp_from_pp0_to = [&fsten] (int i_, int j_, int k_) -> Real {
2481  Real w1m = std::abs(fsten(i_-1,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0))
2482  +std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0)) + eps);
2483  Real w1p = std::abs(fsten(i_ ,j_ ,k_ ,ist_p00)) / (std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0))
2484  +std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) + eps);
2485  Real w2m = std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0)) / (std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0))
2486  +std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0)) + eps);
2487  Real w2p = std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0)) / (std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0))
2488  +std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) + eps);
2489  Real wmm = std::abs(fsten(i_-1,j_-1,k_ ,ist_pp0)) * (Real(1.) + w1m + w2m);
2490  Real wpm = std::abs(fsten(i_ ,j_-1,k_ ,ist_pp0)) * (Real(1.) + w1p + w2m);
2491  Real wmp = std::abs(fsten(i_-1,j_ ,k_ ,ist_pp0)) * (Real(1.) + w1m + w2p);
2492  Real wpp = std::abs(fsten(i_ ,j_ ,k_ ,ist_pp0)) * (Real(1.) + w1p + w2p);
2493  return wpp / (wmm+wpm+wmp+wpp+eps);
2494  };
2495 
2496  auto interp_from_00m_to = [&fsten] (int i_, int j_, int k_) -> Real {
2497  Real w1 = std::abs(fsten(i_ ,j_ ,k_-1,ist_00p));
2498  Real w2 = std::abs(fsten(i_ ,j_ ,k_ ,ist_00p));
2499  if (w1 == Real(0.) && w2 == Real(0.)) {
2500  return Real(0.5);
2501  } else {
2502  return w1 / (w1+w2);
2503  }
2504  };
2505 
2506  auto interp_from_00p_to = [&fsten] (int i_, int j_, int k_) -> Real {
2507  Real w1 = std::abs(fsten(i_ ,j_ ,k_-1,ist_00p));
2508  Real w2 = std::abs(fsten(i_ ,j_ ,k_ ,ist_00p));
2509  if (w1 == Real(0.) && w2 == Real(0.)) {
2510  return Real(0.5);
2511  } else {
2512  return w2 / (w1+w2);
2513  }
2514  };
2515 
2516  auto interp_from_0m0_to = [&fsten] (int i_, int j_, int k_) -> Real {
2517  Real w1 = std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0));
2518  Real w2 = std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0));
2519  if (w1 == Real(0.) && w2 == Real(0.)) {
2520  return Real(0.5);
2521  } else {
2522  return w1 / (w1+w2);
2523  }
2524  };
2525 
2526  auto interp_from_0p0_to = [&fsten] (int i_, int j_, int k_) -> Real {
2527  Real w1 = std::abs(fsten(i_ ,j_-1,k_ ,ist_0p0));
2528  Real w2 = std::abs(fsten(i_ ,j_ ,k_ ,ist_0p0));
2529  if (w1 == Real(0.) && w2 == Real(0.)) {
2530  return Real(0.5);
2531  } else {
2532  return w2 / (w1+w2);
2533  }
2534  };
2535 
2536  auto interp_from_m00_to = [&fsten] (int i_, int j_, int k_) -> Real {
2537  Real w1 = std::abs(fsten(i_-1,j_ ,k_ ,ist_p00));
2538  Real w2 = std::abs(fsten(i_ ,j_ ,k_ ,ist_p00));
2539  if (w1 == Real(0.) && w2 == Real(0.)) {
2540  return Real(0.5);
2541  } else {
2542  return w1 / (w1+w2);
2543  }
2544  };
2545 
2546  auto interp_from_p00_to = [&fsten] (int i_, int j_, int k_) -> Real {
2547  Real w1 = std::abs(fsten(i_-1,j_ ,k_ ,ist_p00));
2548  Real w2 = std::abs(fsten(i_ ,j_ ,k_ ,ist_p00));
2549  if (w1 == Real(0.) && w2 == Real(0.)) {
2550  return Real(0.5);
2551  } else {
2552  return w2 / (w1+w2);
2553  }
2554  };
2555 
2556  auto Ammm = [&fsten] (int i_, int j_, int k_) -> Real {
2557  return fsten(i_-1,j_-1,k_-1,ist_ppp);
2558  };
2559  amrex::ignore_unused(Ammm);
2560 
2561  auto A0mm = [&fsten] (int i_, int j_, int k_) -> Real {
2562  return fsten(i_ ,j_-1,k_-1,ist_0pp);
2563  };
2564 
2565  auto Apmm = [&fsten] (int i_, int j_, int k_) -> Real {
2566  return fsten(i_ ,j_-1,k_-1,ist_ppp);
2567  };
2568 
2569  auto Am0m = [&fsten] (int i_, int j_, int k_) -> Real {
2570  return fsten(i_-1,j_ ,k_-1,ist_p0p);
2571  };
2572 
2573  auto A00m = [&fsten] (int i_, int j_, int k_) -> Real {
2574  return fsten(i_ ,j_ ,k_-1,ist_00p);
2575  };
2576 
2577  auto Ap0m = [&fsten] (int i_, int j_, int k_) -> Real {
2578  return fsten(i_ ,j_ ,k_-1,ist_p0p);
2579  };
2580 
2581  auto Ampm = [&fsten] (int i_, int j_, int k_) -> Real {
2582  return fsten(i_-1,j_ ,k_-1,ist_ppp);
2583  };
2584 
2585  auto A0pm = [&fsten] (int i_, int j_, int k_) -> Real {
2586  return fsten(i_ ,j_ ,k_-1,ist_0pp);
2587  };
2588 
2589  auto Appm = [&fsten] (int i_, int j_, int k_) -> Real {
2590  return fsten(i_ ,j_ ,k_-1,ist_ppp);
2591  };
2592 
2593  auto Amm0 = [&fsten] (int i_, int j_, int k_) -> Real {
2594  return fsten(i_-1,j_-1,k_ ,ist_pp0);
2595  };
2596 
2597  auto A0m0 = [&fsten] (int i_, int j_, int k_) -> Real {
2598  return fsten(i_ ,j_-1,k_ ,ist_0p0);
2599  };
2600 
2601  auto Apm0 = [&fsten] (int i_, int j_, int k_) -> Real {
2602  return fsten(i_ ,j_-1,k_ ,ist_pp0);
2603  };
2604 
2605  auto Am00 = [&fsten] (int i_, int j_, int k_) -> Real {
2606  return fsten(i_-1,j_ ,k_ ,ist_p00);
2607  };
2608 
2609  auto A000 = [&fsten] (int i_, int j_, int k_) -> Real {
2610  return fsten(i_ ,j_ ,k_ ,ist_000);
2611  };
2612 
2613  auto Ap00 = [&fsten] (int i_, int j_, int k_) -> Real {
2614  return fsten(i_ ,j_ ,k_ ,ist_p00);
2615  };
2616 
2617  auto Amp0 = [&fsten] (int i_, int j_, int k_) -> Real {
2618  return fsten(i_-1,j_ ,k_ ,ist_pp0);
2619  };
2620 
2621  auto A0p0 = [&fsten] (int i_, int j_, int k_) -> Real {
2622  return fsten(i_ ,j_ ,k_ ,ist_0p0);
2623  };
2624 
2625  auto App0 = [&fsten] (int i_, int j_, int k_) -> Real {
2626  return fsten(i_ ,j_ ,k_ ,ist_pp0);
2627  };
2628 
2629  auto Ammp = [&fsten] (int i_, int j_, int k_) -> Real {
2630  return fsten(i_-1,j_-1,k_ ,ist_ppp);
2631  };
2632 
2633  auto A0mp = [&fsten] (int i_, int j_, int k_) -> Real {
2634  return fsten(i_ ,j_-1,k_ ,ist_0pp);
2635  };
2636 
2637  auto Apmp = [&fsten] (int i_, int j_, int k_) -> Real {
2638  return fsten(i_ ,j_-1,k_ ,ist_ppp);
2639  };
2640 
2641  auto Am0p = [&fsten] (int i_, int j_, int k_) -> Real {
2642  return fsten(i_-1,j_ ,k_ ,ist_p0p);
2643  };
2644 
2645  auto A00p = [&fsten] (int i_, int j_, int k_) -> Real {
2646  return fsten(i_ ,j_ ,k_ ,ist_00p);
2647  };
2648 
2649  auto Ap0p = [&fsten] (int i_, int j_, int k_) -> Real {
2650  return fsten(i_ ,j_ ,k_ ,ist_p0p);
2651  };
2652 
2653  auto Ampp = [&fsten] (int i_, int j_, int k_) -> Real {
2654  return fsten(i_-1,j_ ,k_ ,ist_ppp);
2655  };
2656 
2657  auto A0pp = [&fsten] (int i_, int j_, int k_) -> Real {
2658  return fsten(i_ ,j_ ,k_ ,ist_0pp);
2659  };
2660 
2661  auto Appp = [&fsten] (int i_, int j_, int k_) -> Real {
2662  return fsten(i_ ,j_ ,k_ ,ist_ppp);
2663  };
2664 
2665  auto restrict_from_mmm_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2666  Real r = Real(1.);
2667  r += std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_p00)) /
2668  ( std::abs(fsten(ii_-1,jj_-2,kk_-2,ist_ppp))
2669  + std::abs(fsten(ii_-1,jj_-1,kk_-2,ist_ppp))
2670  + std::abs(fsten(ii_-1,jj_-2,kk_-1,ist_ppp))
2671  + std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_ppp)) + eps);
2672  r += std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_0p0)) /
2673  ( std::abs(fsten(ii_-2,jj_-1,kk_-2,ist_ppp))
2674  + std::abs(fsten(ii_-1,jj_-1,kk_-2,ist_ppp))
2675  + std::abs(fsten(ii_-2,jj_-1,kk_-1,ist_ppp))
2676  + std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_ppp)) + eps);
2677  r += std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_00p)) /
2678  ( std::abs(fsten(ii_-2,jj_-2,kk_-1,ist_ppp))
2679  + std::abs(fsten(ii_-1,jj_-2,kk_-1,ist_ppp))
2680  + std::abs(fsten(ii_-2,jj_-1,kk_-1,ist_ppp))
2681  + std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_ppp)) + eps);
2682  r += std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_pp0)) /
2683  ( std::abs(fsten(ii_-1,jj_-1,kk_-2,ist_ppp))
2684  + std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_ppp)) + eps);
2685  r += std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_p0p)) /
2686  ( std::abs(fsten(ii_-1,jj_-2,kk_-1,ist_ppp))
2687  + std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_ppp)) + eps);
2688  r += std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_0pp)) /
2689  ( std::abs(fsten(ii_-2,jj_-1,kk_-1,ist_ppp))
2690  + std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_ppp)) + eps);
2691  r *= std::abs(fsten(ii_-1,jj_-1,kk_-1,ist_ppp)) * fsten(ii_-1,jj_-1,kk_-1,ist_inv);
2692  return r;
2693  };
2694  amrex::ignore_unused(restrict_from_mmm_to);
2695 
2696  auto restrict_from_0mm_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2697  Real w1m = std::abs(fsten(ii_,jj_-2,kk_-1,ist_0p0)) / (std::abs(fsten(ii_,jj_-2,kk_-2,ist_0pp))
2698  +std::abs(fsten(ii_,jj_-2,kk_-1,ist_0pp)) + eps);
2699  Real w1p = std::abs(fsten(ii_,jj_-1,kk_-1,ist_0p0)) / (std::abs(fsten(ii_,jj_-1,kk_-2,ist_0pp))
2700  +std::abs(fsten(ii_,jj_-1,kk_-1,ist_0pp)) + eps);
2701  Real w2m = std::abs(fsten(ii_,jj_-1,kk_-2,ist_00p)) / (std::abs(fsten(ii_,jj_-2,kk_-2,ist_0pp))
2702  +std::abs(fsten(ii_,jj_-1,kk_-2,ist_0pp)) + eps);
2703  Real w2p = std::abs(fsten(ii_,jj_-1,kk_-1,ist_00p)) / (std::abs(fsten(ii_,jj_-2,kk_-1,ist_0pp))
2704  +std::abs(fsten(ii_,jj_-1,kk_-1,ist_0pp)) + eps);
2705  Real wmm = std::abs(fsten(ii_,jj_-2,kk_-2,ist_0pp)) * (Real(1.) + w1m + w2m);
2706  Real wpm = std::abs(fsten(ii_,jj_-1,kk_-2,ist_0pp)) * (Real(1.) + w1p + w2m);
2707  Real wmp = std::abs(fsten(ii_,jj_-2,kk_-1,ist_0pp)) * (Real(1.) + w1m + w2p);
2708  Real wpp = std::abs(fsten(ii_,jj_-1,kk_-1,ist_0pp)) * (Real(1.) + w1p + w2p);
2709  return wpp / (wmm+wpm+wmp+wpp+eps);
2710  };
2711 
2712  auto restrict_from_pmm_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2713  Real r = Real(1.);
2714  r += std::abs(fsten(ii_ ,jj_-1,kk_-1,ist_p00)) /
2715  ( std::abs(fsten(ii_ ,jj_-2,kk_-2,ist_ppp))
2716  + std::abs(fsten(ii_ ,jj_-1,kk_-2,ist_ppp))
2717  + std::abs(fsten(ii_ ,jj_-2,kk_-1,ist_ppp))
2718  + std::abs(fsten(ii_ ,jj_-1,kk_-1,ist_ppp)) + eps);
2719  r += std::abs(fsten(ii_+1,jj_-1,kk_-1,ist_0p0)) /
2720  ( std::abs(fsten(ii_ ,jj_-1,kk_-2,ist_ppp))
2721  + std::abs(fsten(ii_+1,jj_-1,kk_-2,ist_ppp))
2722  + std::abs(fsten(ii_ ,jj_-1,kk_-1,ist_ppp))
2723  + std::abs(fsten(ii_+1,jj_-1,kk_-1,ist_ppp)) + eps);
2724  r += std::abs(fsten(ii_+1,jj_-1,kk_-1,ist_00p)) /
2725  ( std::abs(fsten(ii_ ,jj_-2,kk_-1,ist_ppp))
2726  + std::abs(fsten(ii_+1,jj_-2,kk_-1,ist_ppp))
2727  + std::abs(fsten(ii_ ,jj_-1,kk_-1,ist_ppp))
2728  + std::abs(fsten(ii_+1,jj_-1,kk_-1,ist_ppp)) + eps);
2729  r += std::abs(fsten(ii_ ,jj_-1,kk_-1,ist_pp0)) /
2730  ( std::abs(fsten(ii_ ,jj_-1,kk_-2,ist_ppp))
2731  + std::abs(fsten(ii_ ,jj_-1,kk_-1,ist_ppp)) + eps);
2732  r += std::abs(fsten(ii_ ,jj_-1,kk_-1,ist_p0p)) /
2733  ( std::abs(fsten(ii_ ,jj_-2,kk_-1,ist_ppp))
2734  + std::abs(fsten(ii_ ,jj_-1,kk_-1,ist_ppp)) + eps);
2735  r += std::abs(fsten(ii_+1,jj_-1,kk_-1,ist_0pp)) /
2736  ( std::abs(fsten(ii_ ,jj_-1,kk_-1,ist_ppp))
2737  + std::abs(fsten(ii_+1,jj_-1,kk_-1,ist_ppp)) + eps);
2738  r *= std::abs(fsten(ii_ ,jj_-1,kk_-1,ist_ppp)) * fsten(ii_+1,jj_-1,kk_-1,ist_inv);
2739  return r;
2740  };
2741 
2742  auto restrict_from_m0m_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2743  Real w1m = std::abs(fsten(ii_-2,jj_,kk_-1,ist_p00)) / (std::abs(fsten(ii_-2,jj_,kk_-2,ist_p0p))
2744  +std::abs(fsten(ii_-2,jj_,kk_-1,ist_p0p)) + eps);
2745  Real w1p = std::abs(fsten(ii_-1,jj_,kk_-1,ist_p00)) / (std::abs(fsten(ii_-1,jj_,kk_-2,ist_p0p))
2746  +std::abs(fsten(ii_-1,jj_,kk_-1,ist_p0p)) + eps);
2747  Real w2m = std::abs(fsten(ii_-1,jj_,kk_-2,ist_00p)) / (std::abs(fsten(ii_-2,jj_,kk_-2,ist_p0p))
2748  +std::abs(fsten(ii_-1,jj_,kk_-2,ist_p0p)) + eps);
2749  Real w2p = std::abs(fsten(ii_-1,jj_,kk_-1,ist_00p)) / (std::abs(fsten(ii_-2,jj_,kk_-1,ist_p0p))
2750  +std::abs(fsten(ii_-1,jj_,kk_-1,ist_p0p)) + eps);
2751  Real wmm = std::abs(fsten(ii_-2,jj_,kk_-2,ist_p0p)) * (Real(1.) + w1m + w2m);
2752  Real wpm = std::abs(fsten(ii_-1,jj_,kk_-2,ist_p0p)) * (Real(1.) + w1p + w2m);
2753  Real wmp = std::abs(fsten(ii_-2,jj_,kk_-1,ist_p0p)) * (Real(1.) + w1m + w2p);
2754  Real wpp = std::abs(fsten(ii_-1,jj_,kk_-1,ist_p0p)) * (Real(1.) + w1p + w2p);
2755  return wpp / (wmm+wpm+wmp+wpp+eps);
2756  };
2757 
2758  auto restrict_from_00m_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2759  Real w1 = std::abs(fsten(ii_,jj_,kk_-2,ist_00p));
2760  Real w2 = std::abs(fsten(ii_,jj_,kk_-1,ist_00p));
2761  if (w1 == Real(0.) && w2 == Real(0.)) {
2762  return Real(0.5);
2763  } else {
2764  return w2 / (w1+w2);
2765  }
2766  };
2767 
2768  auto restrict_from_p0m_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2769  Real w1m = std::abs(fsten(ii_ ,jj_,kk_-1,ist_p00)) / (std::abs(fsten(ii_ ,jj_,kk_-2,ist_p0p))
2770  +std::abs(fsten(ii_ ,jj_,kk_-1,ist_p0p)) + eps);
2771  Real w1p = std::abs(fsten(ii_+1,jj_,kk_-1,ist_p00)) / (std::abs(fsten(ii_+1,jj_,kk_-2,ist_p0p))
2772  +std::abs(fsten(ii_+1,jj_,kk_-1,ist_p0p)) + eps);
2773  Real w2m = std::abs(fsten(ii_+1,jj_,kk_-2,ist_00p)) / (std::abs(fsten(ii_ ,jj_,kk_-2,ist_p0p))
2774  +std::abs(fsten(ii_+1,jj_,kk_-2,ist_p0p)) + eps);
2775  Real w2p = std::abs(fsten(ii_+1,jj_,kk_-1,ist_00p)) / (std::abs(fsten(ii_ ,jj_,kk_-1,ist_p0p))
2776  +std::abs(fsten(ii_+1,jj_,kk_-1,ist_p0p)) + eps);
2777  Real wmm = std::abs(fsten(ii_ ,jj_,kk_-2,ist_p0p)) * (Real(1.) + w1m + w2m);
2778  Real wpm = std::abs(fsten(ii_+1,jj_,kk_-2,ist_p0p)) * (Real(1.) + w1p + w2m);
2779  Real wmp = std::abs(fsten(ii_ ,jj_,kk_-1,ist_p0p)) * (Real(1.) + w1m + w2p);
2780  Real wpp = std::abs(fsten(ii_+1,jj_,kk_-1,ist_p0p)) * (Real(1.) + w1p + w2p);
2781  return wmp / (wmm+wpm+wmp+wpp+eps);
2782  };
2783 
2784  auto restrict_from_mpm_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2785  Real r = Real(1.);
2786  r += std::abs(fsten(ii_-1,jj_+1,kk_-1,ist_p00)) /
2787  ( std::abs(fsten(ii_-1,jj_ ,kk_-2,ist_ppp))
2788  + std::abs(fsten(ii_-1,jj_+1,kk_-2,ist_ppp))
2789  + std::abs(fsten(ii_-1,jj_ ,kk_-1,ist_ppp))
2790  + std::abs(fsten(ii_-1,jj_+1,kk_-1,ist_ppp)) + eps);
2791  r += std::abs(fsten(ii_-1,jj_ ,kk_-1,ist_0p0)) /
2792  ( std::abs(fsten(ii_-2,jj_ ,kk_-2,ist_ppp))
2793  + std::abs(fsten(ii_-1,jj_ ,kk_-2,ist_ppp))
2794  + std::abs(fsten(ii_-2,jj_ ,kk_-1,ist_ppp))
2795  + std::abs(fsten(ii_-1,jj_ ,kk_-1,ist_ppp)) + eps);
2796  r += std::abs(fsten(ii_-1,jj_+1,kk_-1,ist_00p)) /
2797  ( std::abs(fsten(ii_-2,jj_ ,kk_-1,ist_ppp))
2798  + std::abs(fsten(ii_-1,jj_ ,kk_-1,ist_ppp))
2799  + std::abs(fsten(ii_-2,jj_+1,kk_-1,ist_ppp))
2800  + std::abs(fsten(ii_-1,jj_+1,kk_-1,ist_ppp)) + eps);
2801  r += std::abs(fsten(ii_-1,jj_ ,kk_-1,ist_pp0)) /
2802  ( std::abs(fsten(ii_-1,jj_ ,kk_-2,ist_ppp))
2803  + std::abs(fsten(ii_-1,jj_ ,kk_-1,ist_ppp)) + eps);
2804  r += std::abs(fsten(ii_-1,jj_+1,kk_-1,ist_p0p)) /
2805  ( std::abs(fsten(ii_-1,jj_ ,kk_-1,ist_ppp))
2806  + std::abs(fsten(ii_-1,jj_+1,kk_-1,ist_ppp)) + eps);
2807  r += std::abs(fsten(ii_-1,jj_ ,kk_-1,ist_0pp)) /
2808  ( std::abs(fsten(ii_-2,jj_ ,kk_-1,ist_ppp))
2809  + std::abs(fsten(ii_-1,jj_ ,kk_-1,ist_ppp)) + eps);
2810  r *= std::abs(fsten(ii_-1,jj_ ,kk_-1,ist_ppp)) * fsten(ii_-1,jj_+1,kk_-1,ist_inv);
2811  return r;
2812  };
2813 
2814  auto restrict_from_0pm_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2815  Real w1m = std::abs(fsten(ii_,jj_ ,kk_-1,ist_0p0)) / (std::abs(fsten(ii_,jj_ ,kk_-2,ist_0pp))
2816  +std::abs(fsten(ii_,jj_ ,kk_-1,ist_0pp)) + eps);
2817  Real w1p = std::abs(fsten(ii_,jj_+1,kk_-1,ist_0p0)) / (std::abs(fsten(ii_,jj_+1,kk_-2,ist_0pp))
2818  +std::abs(fsten(ii_,jj_+1,kk_-1,ist_0pp)) + eps);
2819  Real w2m = std::abs(fsten(ii_,jj_+1,kk_-2,ist_00p)) / (std::abs(fsten(ii_,jj_ ,kk_-2,ist_0pp))
2820  +std::abs(fsten(ii_,jj_+1,kk_-2,ist_0pp)) + eps);
2821  Real w2p = std::abs(fsten(ii_,jj_+1,kk_-1,ist_00p)) / (std::abs(fsten(ii_,jj_ ,kk_-1,ist_0pp))
2822  +std::abs(fsten(ii_,jj_+1,kk_-1,ist_0pp)) + eps);
2823  Real wmm = std::abs(fsten(ii_,jj_ ,kk_-2,ist_0pp)) * (Real(1.) + w1m + w2m);
2824  Real wpm = std::abs(fsten(ii_,jj_+1,kk_-2,ist_0pp)) * (Real(1.) + w1p + w2m);
2825  Real wmp = std::abs(fsten(ii_,jj_ ,kk_-1,ist_0pp)) * (Real(1.) + w1m + w2p);
2826  Real wpp = std::abs(fsten(ii_,jj_+1,kk_-1,ist_0pp)) * (Real(1.) + w1p + w2p);
2827  return wmp / (wmm+wpm+wmp+wpp+eps);
2828  };
2829 
2830  auto restrict_from_ppm_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2831  Real r = Real(1.);
2832  r += std::abs(fsten(ii_ ,jj_+1,kk_-1,ist_p00)) /
2833  ( std::abs(fsten(ii_ ,jj_ ,kk_-2,ist_ppp))
2834  + std::abs(fsten(ii_ ,jj_+1,kk_-2,ist_ppp))
2835  + std::abs(fsten(ii_ ,jj_ ,kk_-1,ist_ppp))
2836  + std::abs(fsten(ii_ ,jj_+1,kk_-1,ist_ppp)) + eps);
2837  r += std::abs(fsten(ii_+1,jj_ ,kk_-1,ist_0p0)) /
2838  ( std::abs(fsten(ii_ ,jj_ ,kk_-2,ist_ppp))
2839  + std::abs(fsten(ii_+1,jj_ ,kk_-2,ist_ppp))
2840  + std::abs(fsten(ii_ ,jj_ ,kk_-1,ist_ppp))
2841  + std::abs(fsten(ii_+1,jj_ ,kk_-1,ist_ppp)) + eps);
2842  r += std::abs(fsten(ii_+1,jj_+1,kk_-1,ist_00p)) /
2843  ( std::abs(fsten(ii_ ,jj_ ,kk_-1,ist_ppp))
2844  + std::abs(fsten(ii_+1,jj_ ,kk_-1,ist_ppp))
2845  + std::abs(fsten(ii_ ,jj_+1,kk_-1,ist_ppp))
2846  + std::abs(fsten(ii_+1,jj_+1,kk_-1,ist_ppp)) + eps);
2847  r += std::abs(fsten(ii_ ,jj_ ,kk_-1,ist_pp0)) /
2848  ( std::abs(fsten(ii_ ,jj_ ,kk_-2,ist_ppp))
2849  + std::abs(fsten(ii_ ,jj_ ,kk_-1,ist_ppp)) + eps);
2850  r += std::abs(fsten(ii_ ,jj_+1,kk_-1,ist_p0p)) /
2851  ( std::abs(fsten(ii_ ,jj_ ,kk_-1,ist_ppp))
2852  + std::abs(fsten(ii_ ,jj_+1,kk_-1,ist_ppp)) + eps);
2853  r += std::abs(fsten(ii_+1,jj_ ,kk_-1,ist_0pp)) /
2854  ( std::abs(fsten(ii_ ,jj_ ,kk_-1,ist_ppp))
2855  + std::abs(fsten(ii_+1,jj_ ,kk_-1,ist_ppp)) + eps);
2856  r *= std::abs(fsten(ii_ ,jj_ ,kk_-1,ist_ppp)) * fsten(ii_+1,jj_+1,kk_-1,ist_inv);
2857  return r;
2858  };
2859 
2860  auto restrict_from_mm0_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2861  Real w1m = std::abs(fsten(ii_-2,jj_-1,kk_,ist_p00)) / (std::abs(fsten(ii_-2,jj_-2,kk_,ist_pp0))
2862  +std::abs(fsten(ii_-2,jj_-1,kk_,ist_pp0)) + eps);
2863  Real w1p = std::abs(fsten(ii_-1,jj_-1,kk_,ist_p00)) / (std::abs(fsten(ii_-1,jj_-2,kk_,ist_pp0))
2864  +std::abs(fsten(ii_-1,jj_-1,kk_,ist_pp0)) + eps);
2865  Real w2m = std::abs(fsten(ii_-1,jj_-2,kk_,ist_0p0)) / (std::abs(fsten(ii_-2,jj_-2,kk_,ist_pp0))
2866  +std::abs(fsten(ii_-1,jj_-2,kk_,ist_pp0)) + eps);
2867  Real w2p = std::abs(fsten(ii_-1,jj_-1,kk_,ist_0p0)) / (std::abs(fsten(ii_-2,jj_-1,kk_,ist_pp0))
2868  +std::abs(fsten(ii_-1,jj_-1,kk_,ist_pp0)) + eps);
2869  Real wmm = std::abs(fsten(ii_-2,jj_-2,kk_,ist_pp0)) * (Real(1.) + w1m + w2m);
2870  Real wpm = std::abs(fsten(ii_-1,jj_-2,kk_,ist_pp0)) * (Real(1.) + w1p + w2m);
2871  Real wmp = std::abs(fsten(ii_-2,jj_-1,kk_,ist_pp0)) * (Real(1.) + w1m + w2p);
2872  Real wpp = std::abs(fsten(ii_-1,jj_-1,kk_,ist_pp0)) * (Real(1.) + w1p + w2p);
2873  return wpp / (wmm+wpm+wmp+wpp+eps);
2874  };
2875 
2876  auto restrict_from_0m0_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2877  Real w1 = std::abs(fsten(ii_,jj_-2,kk_,ist_0p0));
2878  Real w2 = std::abs(fsten(ii_,jj_-1,kk_,ist_0p0));
2879  if (w1 == Real(0.) && w2 == Real(0.)) {
2880  return Real(0.5);
2881  } else {
2882  return w2 / (w1+w2);
2883  }
2884  };
2885 
2886  auto restrict_from_pm0_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2887  Real w1m = std::abs(fsten(ii_ ,jj_-1,kk_,ist_p00)) / (std::abs(fsten(ii_ ,jj_-2,kk_,ist_pp0))
2888  +std::abs(fsten(ii_ ,jj_-1,kk_,ist_pp0)) + eps);
2889  Real w1p = std::abs(fsten(ii_+1,jj_-1,kk_,ist_p00)) / (std::abs(fsten(ii_+1,jj_-2,kk_,ist_pp0))
2890  +std::abs(fsten(ii_+1,jj_-1,kk_,ist_pp0)) + eps);
2891  Real w2m = std::abs(fsten(ii_+1,jj_-2,kk_,ist_0p0)) / (std::abs(fsten(ii_ ,jj_-2,kk_,ist_pp0))
2892  +std::abs(fsten(ii_+1,jj_-2,kk_,ist_pp0)) + eps);
2893  Real w2p = std::abs(fsten(ii_+1,jj_-1,kk_,ist_0p0)) / (std::abs(fsten(ii_ ,jj_-1,kk_,ist_pp0))
2894  +std::abs(fsten(ii_+1,jj_-1,kk_,ist_pp0)) + eps);
2895  Real wmm = std::abs(fsten(ii_ ,jj_-2,kk_,ist_pp0)) * (Real(1.) + w1m + w2m);
2896  Real wpm = std::abs(fsten(ii_+1,jj_-2,kk_,ist_pp0)) * (Real(1.) + w1p + w2m);
2897  Real wmp = std::abs(fsten(ii_ ,jj_-1,kk_,ist_pp0)) * (Real(1.) + w1m + w2p);
2898  Real wpp = std::abs(fsten(ii_+1,jj_-1,kk_,ist_pp0)) * (Real(1.) + w1p + w2p);
2899  return wmp / (wmm+wpm+wmp+wpp+eps);
2900  };
2901 
2902  auto restrict_from_m00_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2903  Real w1 = std::abs(fsten(ii_-2,jj_,kk_,ist_p00));
2904  Real w2 = std::abs(fsten(ii_-1,jj_,kk_,ist_p00));
2905  if (w1 == Real(0.) && w2 == Real(0.)) {
2906  return Real(0.5);
2907  } else {
2908  return w2 / (w1+w2);
2909  }
2910  };
2911 
2912  auto restrict_from_000_to = [] (int /*ii_*/, int /*jj_*/, int /*kk_*/) -> Real {
2913  return Real(1.);
2914  };
2915 
2916  auto restrict_from_p00_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2917  Real w1 = std::abs(fsten(ii_ ,jj_,kk_,ist_p00));
2918  Real w2 = std::abs(fsten(ii_+1,jj_,kk_,ist_p00));
2919  if (w1 == Real(0.) && w2 == Real(0.)) {
2920  return Real(0.5);
2921  } else {
2922  return w1 / (w1+w2);
2923  }
2924  };
2925 
2926  auto restrict_from_mp0_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2927  Real w1m = std::abs(fsten(ii_-2,jj_+1,kk_,ist_p00)) / (std::abs(fsten(ii_-2,jj_ ,kk_,ist_pp0))
2928  +std::abs(fsten(ii_-2,jj_+1,kk_,ist_pp0)) + eps);
2929  Real w1p = std::abs(fsten(ii_-1,jj_+1,kk_,ist_p00)) / (std::abs(fsten(ii_-1,jj_ ,kk_,ist_pp0))
2930  +std::abs(fsten(ii_-1,jj_+1,kk_,ist_pp0)) + eps);
2931  Real w2m = std::abs(fsten(ii_-1,jj_ ,kk_,ist_0p0)) / (std::abs(fsten(ii_-2,jj_ ,kk_,ist_pp0))
2932  +std::abs(fsten(ii_-1,jj_ ,kk_,ist_pp0)) + eps);
2933  Real w2p = std::abs(fsten(ii_-1,jj_+1,kk_,ist_0p0)) / (std::abs(fsten(ii_-2,jj_+1,kk_,ist_pp0))
2934  +std::abs(fsten(ii_-1,jj_+1,kk_,ist_pp0)) + eps);
2935  Real wmm = std::abs(fsten(ii_-2,jj_ ,kk_,ist_pp0)) * (Real(1.) + w1m + w2m);
2936  Real wpm = std::abs(fsten(ii_-1,jj_ ,kk_,ist_pp0)) * (Real(1.) + w1p + w2m);
2937  Real wmp = std::abs(fsten(ii_-2,jj_+1,kk_,ist_pp0)) * (Real(1.) + w1m + w2p);
2938  Real wpp = std::abs(fsten(ii_-1,jj_+1,kk_,ist_pp0)) * (Real(1.) + w1p + w2p);
2939  return wpm / (wmm+wpm+wmp+wpp+eps);
2940  };
2941 
2942  auto restrict_from_0p0_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2943  Real w1 = std::abs(fsten(ii_,jj_ ,kk_,ist_0p0));
2944  Real w2 = std::abs(fsten(ii_,jj_+1,kk_,ist_0p0));
2945  if (w1 == Real(0.) && w2 == Real(0.)) {
2946  return Real(0.5);
2947  } else {
2948  return w1 / (w1+w2);
2949  }
2950  };
2951 
2952  auto restrict_from_pp0_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2953  Real w1m = std::abs(fsten(ii_ ,jj_+1,kk_,ist_p00)) / (std::abs(fsten(ii_ ,jj_ ,kk_,ist_pp0))
2954  +std::abs(fsten(ii_ ,jj_+1,kk_,ist_pp0)) + eps);
2955  Real w1p = std::abs(fsten(ii_+1,jj_+1,kk_,ist_p00)) / (std::abs(fsten(ii_+1,jj_ ,kk_,ist_pp0))
2956  +std::abs(fsten(ii_+1,jj_+1,kk_,ist_pp0)) + eps);
2957  Real w2m = std::abs(fsten(ii_+1,jj_ ,kk_,ist_0p0)) / (std::abs(fsten(ii_ ,jj_ ,kk_,ist_pp0))
2958  +std::abs(fsten(ii_+1,jj_ ,kk_,ist_pp0)) + eps);
2959  Real w2p = std::abs(fsten(ii_+1,jj_+1,kk_,ist_0p0)) / (std::abs(fsten(ii_ ,jj_+1,kk_,ist_pp0))
2960  +std::abs(fsten(ii_+1,jj_+1,kk_,ist_pp0)) + eps);
2961  Real wmm = std::abs(fsten(ii_ ,jj_ ,kk_,ist_pp0)) * (Real(1.) + w1m + w2m);
2962  Real wpm = std::abs(fsten(ii_+1,jj_ ,kk_,ist_pp0)) * (Real(1.) + w1p + w2m);
2963  Real wmp = std::abs(fsten(ii_ ,jj_+1,kk_,ist_pp0)) * (Real(1.) + w1m + w2p);
2964  Real wpp = std::abs(fsten(ii_+1,jj_+1,kk_,ist_pp0)) * (Real(1.) + w1p + w2p);
2965  return wmm / (wmm+wpm+wmp+wpp+eps);
2966  };
2967 
2968  auto restrict_from_mmp_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2969  Real r = Real(1.);
2970  r += std::abs(fsten(ii_-1,jj_-1,kk_+1,ist_p00)) /
2971  ( std::abs(fsten(ii_-1,jj_-2,kk_ ,ist_ppp))
2972  + std::abs(fsten(ii_-1,jj_-1,kk_ ,ist_ppp))
2973  + std::abs(fsten(ii_-1,jj_-2,kk_+1,ist_ppp))
2974  + std::abs(fsten(ii_-1,jj_-1,kk_+1,ist_ppp)) + eps);
2975  r += std::abs(fsten(ii_-1,jj_-1,kk_+1,ist_0p0)) /
2976  ( std::abs(fsten(ii_-2,jj_-1,kk_ ,ist_ppp))
2977  + std::abs(fsten(ii_-1,jj_-1,kk_ ,ist_ppp))
2978  + std::abs(fsten(ii_-2,jj_-1,kk_+1,ist_ppp))
2979  + std::abs(fsten(ii_-1,jj_-1,kk_+1,ist_ppp)) + eps);
2980  r += std::abs(fsten(ii_-1,jj_-1,kk_ ,ist_00p)) /
2981  ( std::abs(fsten(ii_-2,jj_-2,kk_ ,ist_ppp))
2982  + std::abs(fsten(ii_-1,jj_-2,kk_ ,ist_ppp))
2983  + std::abs(fsten(ii_-2,jj_-1,kk_ ,ist_ppp))
2984  + std::abs(fsten(ii_-1,jj_-1,kk_ ,ist_ppp)) + eps);
2985  r += std::abs(fsten(ii_-1,jj_-1,kk_+1,ist_pp0)) /
2986  ( std::abs(fsten(ii_-1,jj_-1,kk_ ,ist_ppp))
2987  + std::abs(fsten(ii_-1,jj_-1,kk_+1,ist_ppp)) + eps);
2988  r += std::abs(fsten(ii_-1,jj_-1,kk_ ,ist_p0p)) /
2989  ( std::abs(fsten(ii_-1,jj_-2,kk_ ,ist_ppp))
2990  + std::abs(fsten(ii_-1,jj_-1,kk_ ,ist_ppp)) + eps);
2991  r += std::abs(fsten(ii_-1,jj_-1,kk_ ,ist_0pp)) /
2992  ( std::abs(fsten(ii_-2,jj_-1,kk_ ,ist_ppp))
2993  + std::abs(fsten(ii_-1,jj_-1,kk_ ,ist_ppp)) + eps);
2994  r *= std::abs(fsten(ii_-1,jj_-1,kk_ ,ist_ppp)) * fsten(ii_-1,jj_-1,kk_+1,ist_inv);
2995  return r;
2996  };
2997 
2998  auto restrict_from_0mp_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
2999  Real w1m = std::abs(fsten(ii_,jj_-2,kk_+1,ist_0p0)) / (std::abs(fsten(ii_,jj_-2,kk_ ,ist_0pp))
3000  +std::abs(fsten(ii_,jj_-2,kk_+1,ist_0pp)) + eps);
3001  Real w1p = std::abs(fsten(ii_,jj_-1,kk_+1,ist_0p0)) / (std::abs(fsten(ii_,jj_-1,kk_ ,ist_0pp))
3002  +std::abs(fsten(ii_,jj_-1,kk_+1,ist_0pp)) + eps);
3003  Real w2m = std::abs(fsten(ii_,jj_-1,kk_ ,ist_00p)) / (std::abs(fsten(ii_,jj_-2,kk_ ,ist_0pp))
3004  +std::abs(fsten(ii_,jj_-1,kk_ ,ist_0pp)) + eps);
3005  Real w2p = std::abs(fsten(ii_,jj_-1,kk_+1,ist_00p)) / (std::abs(fsten(ii_,jj_-2,kk_+1,ist_0pp))
3006  +std::abs(fsten(ii_,jj_-1,kk_+1,ist_0pp)) + eps);
3007  Real wmm = std::abs(fsten(ii_,jj_-2,kk_ ,ist_0pp)) * (Real(1.) + w1m + w2m);
3008  Real wpm = std::abs(fsten(ii_,jj_-1,kk_ ,ist_0pp)) * (Real(1.) + w1p + w2m);
3009  Real wmp = std::abs(fsten(ii_,jj_-2,kk_+1,ist_0pp)) * (Real(1.) + w1m + w2p);
3010  Real wpp = std::abs(fsten(ii_,jj_-1,kk_+1,ist_0pp)) * (Real(1.) + w1p + w2p);
3011  return wpm / (wmm+wpm+wmp+wpp+eps);
3012  };
3013 
3014  auto restrict_from_pmp_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
3015  Real r = Real(1.);
3016  r += std::abs(fsten(ii_ ,jj_-1,kk_+1,ist_p00)) /
3017  ( std::abs(fsten(ii_ ,jj_-2,kk_ ,ist_ppp))
3018  + std::abs(fsten(ii_ ,jj_-1,kk_ ,ist_ppp))
3019  + std::abs(fsten(ii_ ,jj_-2,kk_+1,ist_ppp))
3020  + std::abs(fsten(ii_ ,jj_-1,kk_+1,ist_ppp)) + eps);
3021  r += std::abs(fsten(ii_+1,jj_-1,kk_+1,ist_0p0)) /
3022  ( std::abs(fsten(ii_ ,jj_-1,kk_ ,ist_ppp))
3023  + std::abs(fsten(ii_+1,jj_-1,kk_ ,ist_ppp))
3024  + std::abs(fsten(ii_ ,jj_-1,kk_+1,ist_ppp))
3025  + std::abs(fsten(ii_+1,jj_-1,kk_+1,ist_ppp)) + eps);
3026  r += std::abs(fsten(ii_+1,jj_-1,kk_ ,ist_00p)) /
3027  ( std::abs(fsten(ii_ ,jj_-2,kk_ ,ist_ppp))
3028  + std::abs(fsten(ii_+1,jj_-2,kk_ ,ist_ppp))
3029  + std::abs(fsten(ii_ ,jj_-1,kk_ ,ist_ppp))
3030  + std::abs(fsten(ii_+1,jj_-1,kk_ ,ist_ppp)) + eps);
3031  r += std::abs(fsten(ii_ ,jj_-1,kk_+1,ist_pp0)) /
3032  ( std::abs(fsten(ii_ ,jj_-1,kk_ ,ist_ppp))
3033  + std::abs(fsten(ii_ ,jj_-1,kk_+1,ist_ppp)) + eps);
3034  r += std::abs(fsten(ii_ ,jj_-1,kk_ ,ist_p0p)) /
3035  ( std::abs(fsten(ii_ ,jj_-2,kk_ ,ist_ppp))
3036  + std::abs(fsten(ii_ ,jj_-1,kk_ ,ist_ppp)) + eps);
3037  r += std::abs(fsten(ii_+1,jj_-1,kk_ ,ist_0pp)) /
3038  ( std::abs(fsten(ii_ ,jj_-1,kk_ ,ist_ppp))
3039  + std::abs(fsten(ii_+1,jj_-1,kk_ ,ist_ppp)) + eps);
3040  r *= std::abs(fsten(ii_ ,jj_-1,kk_ ,ist_ppp)) * fsten(ii_+1,jj_-1,kk_+1,ist_inv);
3041  return r;
3042  };
3043 
3044  auto restrict_from_m0p_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
3045  Real w1m = std::abs(fsten(ii_-2,jj_,kk_+1,ist_p00)) / (std::abs(fsten(ii_-2,jj_,kk_ ,ist_p0p))
3046  +std::abs(fsten(ii_-2,jj_,kk_+1,ist_p0p)) + eps);
3047  Real w1p = std::abs(fsten(ii_-1,jj_,kk_+1,ist_p00)) / (std::abs(fsten(ii_-1,jj_,kk_ ,ist_p0p))
3048  +std::abs(fsten(ii_-1,jj_,kk_+1,ist_p0p)) + eps);
3049  Real w2m = std::abs(fsten(ii_-1,jj_,kk_ ,ist_00p)) / (std::abs(fsten(ii_-2,jj_,kk_ ,ist_p0p))
3050  +std::abs(fsten(ii_-1,jj_,kk_ ,ist_p0p)) + eps);
3051  Real w2p = std::abs(fsten(ii_-1,jj_,kk_+1,ist_00p)) / (std::abs(fsten(ii_-2,jj_,kk_+1,ist_p0p))
3052  +std::abs(fsten(ii_-1,jj_,kk_+1,ist_p0p)) + eps);
3053  Real wmm = std::abs(fsten(ii_-2,jj_,kk_ ,ist_p0p)) * (Real(1.) + w1m + w2m);
3054  Real wpm = std::abs(fsten(ii_-1,jj_,kk_ ,ist_p0p)) * (Real(1.) + w1p + w2m);
3055  Real wmp = std::abs(fsten(ii_-2,jj_,kk_+1,ist_p0p)) * (Real(1.) + w1m + w2p);
3056  Real wpp = std::abs(fsten(ii_-1,jj_,kk_+1,ist_p0p)) * (Real(1.) + w1p + w2p);
3057  return wpm / (wmm+wpm+wmp+wpp+eps);
3058  };
3059 
3060  auto restrict_from_00p_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
3061  Real w1 = std::abs(fsten(ii_,jj_,kk_ ,ist_00p));
3062  Real w2 = std::abs(fsten(ii_,jj_,kk_+1,ist_00p));
3063  if (w1 == Real(0.) && w2 == Real(0.)) {
3064  return Real(0.5);
3065  } else {
3066  return w1 / (w1+w2);
3067  }
3068  };
3069 
3070  auto restrict_from_p0p_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
3071  Real w1m = std::abs(fsten(ii_ ,jj_,kk_+1,ist_p00)) / (std::abs(fsten(ii_ ,jj_,kk_ ,ist_p0p))
3072  +std::abs(fsten(ii_ ,jj_,kk_+1,ist_p0p)) + eps);
3073  Real w1p = std::abs(fsten(ii_+1,jj_,kk_+1,ist_p00)) / (std::abs(fsten(ii_+1,jj_,kk_ ,ist_p0p))
3074  +std::abs(fsten(ii_+1,jj_,kk_+1,ist_p0p)) + eps);
3075  Real w2m = std::abs(fsten(ii_+1,jj_,kk_ ,ist_00p)) / (std::abs(fsten(ii_ ,jj_,kk_ ,ist_p0p))
3076  +std::abs(fsten(ii_+1,jj_,kk_ ,ist_p0p)) + eps);
3077  Real w2p = std::abs(fsten(ii_+1,jj_,kk_+1,ist_00p)) / (std::abs(fsten(ii_ ,jj_,kk_+1,ist_p0p))
3078  +std::abs(fsten(ii_+1,jj_,kk_+1,ist_p0p)) + eps);
3079  Real wmm = std::abs(fsten(ii_ ,jj_,kk_ ,ist_p0p)) * (Real(1.) + w1m + w2m);
3080  Real wpm = std::abs(fsten(ii_+1,jj_,kk_ ,ist_p0p)) * (Real(1.) + w1p + w2m);
3081  Real wmp = std::abs(fsten(ii_ ,jj_,kk_+1,ist_p0p)) * (Real(1.) + w1m + w2p);
3082  Real wpp = std::abs(fsten(ii_+1,jj_,kk_+1,ist_p0p)) * (Real(1.) + w1p + w2p);
3083  return wmm / (wmm+wpm+wmp+wpp+eps);
3084  };
3085 
3086  auto restrict_from_mpp_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
3087  Real r = Real(1.);
3088  r += std::abs(fsten(ii_-1,jj_+1,kk_+1,ist_p00)) /
3089  ( std::abs(fsten(ii_-1,jj_ ,kk_ ,ist_ppp))
3090  + std::abs(fsten(ii_-1,jj_+1,kk_ ,ist_ppp))
3091  + std::abs(fsten(ii_-1,jj_ ,kk_+1,ist_ppp))
3092  + std::abs(fsten(ii_-1,jj_+1,kk_+1,ist_ppp)) + eps);
3093  r += std::abs(fsten(ii_-1,jj_ ,kk_+1,ist_0p0)) /
3094  ( std::abs(fsten(ii_-2,jj_ ,kk_ ,ist_ppp))
3095  + std::abs(fsten(ii_-1,jj_ ,kk_ ,ist_ppp))
3096  + std::abs(fsten(ii_-2,jj_ ,kk_+1,ist_ppp))
3097  + std::abs(fsten(ii_-1,jj_ ,kk_+1,ist_ppp)) + eps);
3098  r += std::abs(fsten(ii_-1,jj_+1,kk_ ,ist_00p)) /
3099  ( std::abs(fsten(ii_-2,jj_ ,kk_ ,ist_ppp))
3100  + std::abs(fsten(ii_-1,jj_ ,kk_ ,ist_ppp))
3101  + std::abs(fsten(ii_-2,jj_+1,kk_ ,ist_ppp))
3102  + std::abs(fsten(ii_-1,jj_+1,kk_ ,ist_ppp)) + eps);
3103  r += std::abs(fsten(ii_-1,jj_ ,kk_+1,ist_pp0)) /
3104  ( std::abs(fsten(ii_-1,jj_ ,kk_ ,ist_ppp))
3105  + std::abs(fsten(ii_-1,jj_ ,kk_+1,ist_ppp)) + eps);
3106  r += std::abs(fsten(ii_-1,jj_+1,kk_ ,ist_p0p)) /
3107  ( std::abs(fsten(ii_-1,jj_ ,kk_ ,ist_ppp))
3108  + std::abs(fsten(ii_-1,jj_+1,kk_ ,ist_ppp)) + eps);
3109  r += std::abs(fsten(ii_-1,jj_ ,kk_ ,ist_0pp)) /
3110  ( std::abs(fsten(ii_-2,jj_ ,kk_ ,ist_ppp))
3111  + std::abs(fsten(ii_-1,jj_ ,kk_ ,ist_ppp)) + eps);
3112  r *= std::abs(fsten(ii_-1,jj_ ,kk_ ,ist_ppp)) * fsten(ii_-1,jj_+1,kk_+1,ist_inv);
3113  return r;
3114  };
3115 
3116  auto restrict_from_0pp_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
3117  Real w1m = std::abs(fsten(ii_,jj_ ,kk_+1,ist_0p0)) / (std::abs(fsten(ii_,jj_ ,kk_ ,ist_0pp))
3118  +std::abs(fsten(ii_,jj_ ,kk_+1,ist_0pp)) + eps);
3119  Real w1p = std::abs(fsten(ii_,jj_+1,kk_+1,ist_0p0)) / (std::abs(fsten(ii_,jj_+1,kk_ ,ist_0pp))
3120  +std::abs(fsten(ii_,jj_+1,kk_+1,ist_0pp)) + eps);
3121  Real w2m = std::abs(fsten(ii_,jj_+1,kk_ ,ist_00p)) / (std::abs(fsten(ii_,jj_ ,kk_ ,ist_0pp))
3122  +std::abs(fsten(ii_,jj_+1,kk_ ,ist_0pp)) + eps);
3123  Real w2p = std::abs(fsten(ii_,jj_+1,kk_+1,ist_00p)) / (std::abs(fsten(ii_,jj_ ,kk_+1,ist_0pp))
3124  +std::abs(fsten(ii_,jj_+1,kk_+1,ist_0pp)) + eps);
3125  Real wmm = std::abs(fsten(ii_,jj_ ,kk_ ,ist_0pp)) * (Real(1.) + w1m + w2m);
3126  Real wpm = std::abs(fsten(ii_,jj_+1,kk_ ,ist_0pp)) * (Real(1.) + w1p + w2m);
3127  Real wmp = std::abs(fsten(ii_,jj_ ,kk_+1,ist_0pp)) * (Real(1.) + w1m + w2p);
3128  Real wpp = std::abs(fsten(ii_,jj_+1,kk_+1,ist_0pp)) * (Real(1.) + w1p + w2p);
3129  return wmm / (wmm+wpm+wmp+wpp+eps);
3130  };
3131 
3132  auto restrict_from_ppp_to = [&fsten] (int ii_, int jj_, int kk_) -> Real {
3133  Real r = Real(1.);
3134  r += std::abs(fsten(ii_ ,jj_+1,kk_+1,ist_p00)) /
3135  ( std::abs(fsten(ii_ ,jj_ ,kk_ ,ist_ppp))
3136  + std::abs(fsten(ii_ ,jj_+1,kk_ ,ist_ppp))
3137  + std::abs(fsten(ii_ ,jj_ ,kk_+1,ist_ppp))
3138  + std::abs(fsten(ii_ ,jj_+1,kk_+1,ist_ppp)) + eps);
3139  r += std::abs(fsten(ii_+1,jj_ ,kk_+1,ist_0p0)) /
3140  ( std::abs(fsten(ii_ ,jj_ ,kk_ ,ist_ppp))
3141  + std::abs(fsten(ii_+1,jj_ ,kk_ ,ist_ppp))
3142  + std::abs(fsten(ii_ ,jj_ ,kk_+1,ist_ppp))
3143  + std::abs(fsten(ii_+1,jj_ ,kk_+1,ist_ppp)) + eps);
3144  r += std::abs(fsten(ii_+1,jj_+1,kk_ ,ist_00p)) /
3145  ( std::abs(fsten(ii_ ,jj_ ,kk_ ,ist_ppp))
3146  + std::abs(fsten(ii_+1,jj_ ,kk_ ,ist_ppp))
3147  + std::abs(fsten(ii_ ,jj_+1,kk_ ,ist_ppp))
3148  + std::abs(fsten(ii_+1,jj_+1,kk_ ,ist_ppp)) + eps);
3149  r += std::abs(fsten(ii_ ,jj_ ,kk_+1,ist_pp0)) /
3150  ( std::abs(fsten(ii_ ,jj_ ,kk_ ,ist_ppp))
3151  + std::abs(fsten(ii_ ,jj_ ,kk_+1,ist_ppp)) + eps);
3152  r += std::abs(fsten(ii_ ,jj_+1,kk_ ,ist_p0p)) /
3153  ( std::abs(fsten(ii_ ,jj_ ,kk_ ,ist_ppp))
3154  + std::abs(fsten(ii_ ,jj_+1,kk_ ,ist_ppp)) + eps);
3155  r += std::abs(fsten(ii_+1,jj_ ,kk_ ,ist_0pp)) /
3156  ( std::abs(fsten(ii_ ,jj_ ,kk_ ,ist_ppp))
3157  + std::abs(fsten(ii_+1,jj_ ,kk_ ,ist_ppp)) + eps);
3158  r *= std::abs(fsten(ii_ ,jj_ ,kk_ ,ist_ppp)) * fsten(ii_+1,jj_+1,kk_+1,ist_inv);
3159  return r;
3160  };
3161 
3162  int ii = 2*i;
3163  int jj = 2*j;
3164  int kk = 2*k;
3165  Array3D<Real,-1,1,-1,1,-1,1> p;
3166  Array3D<Real,-1,1,-1,1,-1,1> ap;
3167  Real cs1, cs2, cs3, cs4;
3168 
3169  // csten(i,j,k,ist_p00)
3170  int iii = ii;
3171  int jjj = jj;
3172  int kkk = kk;;
3173  p(-1,-1,-1) = interp_from_ppp_to(iii+1,jjj-1,kkk-1);
3174  p( 0,-1,-1) = interp_from_0pp_to(iii+2,jjj-1,kkk-1);
3175  p(-1, 0,-1) = interp_from_p0p_to(iii+1,jjj ,kkk-1);
3176  p( 0, 0,-1) = interp_from_00p_to(iii+2,jjj ,kkk-1);
3177  p(-1,+1,-1) = interp_from_pmp_to(iii+1,jjj+1,kkk-1);
3178  p( 0,+1,-1) = interp_from_0mp_to(iii+2,jjj+1,kkk-1);
3179  p(-1,-1, 0) = interp_from_pp0_to(iii+1,jjj-1,kkk );
3180  p( 0,-1, 0) = interp_from_0p0_to(iii+2,jjj-1,kkk );
3181  p(-1, 0, 0) = interp_from_p00_to(iii+1,jjj ,kkk );
3182  p( 0, 0, 0) = Real(1.);
3183  p(-1,+1, 0) = interp_from_pm0_to(iii+1,jjj+1,kkk );
3184  p( 0,+1, 0) = interp_from_0m0_to(iii+2,jjj+1,kkk );
3185  p(-1,-1,+1) = interp_from_ppm_to(iii+1,jjj-1,kkk+1);
3186  p( 0,-1,+1) = interp_from_0pm_to(iii+2,jjj-1,kkk+1);
3187  p(-1, 0,+1) = interp_from_p0m_to(iii+1,jjj ,kkk+1);
3188  p( 0, 0,+1) = interp_from_00m_to(iii+2,jjj ,kkk+1);
3189  p(-1,+1,+1) = interp_from_pmm_to(iii+1,jjj+1,kkk+1);
3190  p( 0,+1,+1) = interp_from_0mm_to(iii+2,jjj+1,kkk+1);
3191  ap(0,-1,-1) =
3192  Ap00(iii,jjj-1,kkk-1) * p(-1,-1,-1)
3193  + App0(iii,jjj-1,kkk-1) * p(-1, 0,-1)
3194  + Ap0p(iii,jjj-1,kkk-1) * p(-1,-1, 0)
3195  + Appp(iii,jjj-1,kkk-1) * p(-1, 0, 0);
3196  ap(1,-1,-1) =
3197  A000(iii+1,jjj-1,kkk-1) * p(-1,-1,-1)
3198  + Ap00(iii+1,jjj-1,kkk-1) * p( 0,-1,-1)
3199  + A0p0(iii+1,jjj-1,kkk-1) * p(-1, 0,-1)
3200  + App0(iii+1,jjj-1,kkk-1) * p( 0, 0,-1)
3201  + A00p(iii+1,jjj-1,kkk-1) * p(-1,-1, 0)
3202  + Ap0p(iii+1,jjj-1,kkk-1) * p( 0,-1, 0)
3203  + A0pp(iii+1,jjj-1,kkk-1) * p(-1, 0, 0)
3204  + Appp(iii+1,jjj-1,kkk-1) * p( 0, 0, 0);
3205  ap(0,0,-1) =
3206  Apm0(iii,jjj,kkk-1) * p(-1,-1,-1)
3207  + Ap00(iii,jjj,kkk-1) * p(-1, 0,-1)
3208  + App0(iii,jjj,kkk-1) * p(-1,+1,-1)
3209  + Apmp(iii,jjj,kkk-1) * p(-1,-1, 0)
3210  + Ap0p(iii,jjj,kkk-1) * p(-1, 0, 0)
3211  + Appp(iii,jjj,kkk-1) * p(-1,+1, 0);
3212  ap(1,0,-1) =
3213  A0m0(iii+1,jjj,kkk-1) * p(-1,-1,-1)
3214  + Apm0(iii+1,jjj,kkk-1) * p( 0,-1,-1)
3215  + A000(iii+1,jjj,kkk-1) * p(-1, 0,-1)
3216  + Ap00(iii+1,jjj,kkk-1) * p( 0, 0,-1)
3217  + A0p0(iii+1,jjj,kkk-1) * p(-1,+1,-1)
3218  + App0(iii+1,jjj,kkk-1) * p( 0,+1,-1)
3219  + A0mp(iii+1,jjj,kkk-1) * p(-1,-1, 0)
3220  + Apmp(iii+1,jjj,kkk-1) * p( 0,-1, 0)
3221  + A00p(iii+1,jjj,kkk-1) * p(-1, 0, 0)
3222  + Ap0p(iii+1,jjj,kkk-1) * p( 0, 0, 0)
3223  + A0pp(iii+1,jjj,kkk-1) * p(-1,+1, 0)
3224  + Appp(iii+1,jjj,kkk-1) * p( 0,+1, 0);
3225  ap(0,1,-1) =
3226  Apm0(iii,jjj+1,kkk-1) * p(-1, 0,-1)
3227  + Ap00(iii,jjj+1,kkk-1) * p(-1,+1,-1)
3228  + Apmp(iii,jjj+1,kkk-1) * p(-1, 0, 0)
3229  + Ap0p(iii,jjj+1,kkk-1) * p(-1,+1, 0);
3230  ap(1,1,-1) =
3231  A0m0(iii+1,jjj+1,kkk-1) * p(-1, 0,-1)
3232  + Apm0(iii+1,jjj+1,kkk-1) * p( 0, 0,-1)
3233  + A000(iii+1,jjj+1,kkk-1) * p(-1,+1,-1)
3234  + Ap00(iii+1,jjj+1,kkk-1) * p( 0,+1,-1)
3235  + A0mp(iii+1,jjj+1,kkk-1) * p(-1, 0, 0)
3236  + Apmp(iii+1,jjj+1,kkk-1) * p( 0, 0, 0)
3237  + A00p(iii+1,jjj+1,kkk-1) * p(-1,+1, 0)
3238  + Ap0p(iii+1,jjj+1,kkk-1) * p( 0,+1, 0);
3239  ap(0,-1,0) =
3240  Ap0m(iii,jjj-1,kkk) * p(-1,-1,-1)
3241  + Appm(iii,jjj-1,kkk) * p(-1, 0,-1)
3242  + Ap00(iii,jjj-1,kkk) * p(-1,-1, 0)
3243  + App0(iii,jjj-1,kkk) * p(-1, 0, 0)
3244  + Ap0p(iii,jjj-1,kkk) * p(-1,-1,+1)
3245  + Appp(iii,jjj-1,kkk) * p(-1, 0,+1);
3246  ap(1,-1,0) =
3247  A00m(iii+1,jjj-1,kkk) * p(-1,-1,-1)
3248  + Ap0m(iii+1,jjj-1,kkk) * p( 0,-1,-1)
3249  + A0pm(iii+1,jjj-1,kkk) * p(-1, 0,-1)
3250  + Appm(iii+1,jjj-1,kkk) * p( 0, 0,-1)
3251  + A000(iii+1,jjj-1,kkk) * p(-1,-1, 0)
3252  + Ap00(iii+1,jjj-1,kkk) * p( 0,-1, 0)
3253  + A0p0(iii+1,jjj-1,kkk) * p(-1, 0, 0)
3254  + App0(iii+1,jjj-1,kkk) * p( 0, 0, 0)
3255  + A00p(iii+1,jjj-1,kkk) * p(-1,-1,+1)
3256  + Ap0p(iii+1,jjj-1,kkk) * p( 0,-1,+1)
3257  + A0pp(iii+1,jjj-1,kkk) * p(-1, 0,+1)
3258  + Appp(iii+1,jjj-1,kkk) * p( 0, 0,+1);
3259  ap(0,0,0) =
3260  Apmm(iii,jjj,kkk) * p(-1,-1,-1)
3261  + Ap0m(iii,jjj,kkk) * p(-1, 0,-1)
3262  + Appm(iii,jjj,kkk) * p(-1,+1,-1)
3263  + Apm0(iii,jjj,kkk) * p(-1,-1, 0)
3264  + Ap00(iii,jjj,kkk) * p(-1, 0, 0)
3265  + App0(iii,jjj,kkk) * p(-1,+1, 0)
3266  + Apmp(iii,jjj,kkk) * p(-1,-1,+1)
3267  + Ap0p(iii,jjj,kkk) * p(-1, 0,+1)
3268  + Appp(iii,jjj,kkk) * p(-1,+1,+1);
3269  ap(1,0,0) =
3270  A0mm(iii+1,jjj,kkk) * p(-1,-1,-1)
3271  + Apmm(iii+1,jjj,kkk) * p( 0,-1,-1)
3272  + A00m(iii+1,jjj,kkk) * p(-1, 0,-1)
3273  + Ap0m(iii+1,jjj,kkk) * p( 0, 0,-1)
3274  + A0pm(iii+1,jjj,kkk) * p(-1,+1,-1)
3275  + Appm(iii+1,jjj,kkk) * p( 0,+1,-1)
3276  + A0m0(iii+1,jjj,kkk) * p(-1,-1, 0)
3277  + Apm0(iii+1,jjj,kkk) * p( 0,-1, 0)
3278  + A000(iii+1,jjj,kkk) * p(-1, 0, 0)
3279  + Ap00(iii+1,jjj,kkk) * p( 0, 0, 0)
3280  + A0p0(iii+1,jjj,kkk) * p(-1,+1, 0)
3281  + App0(iii+1,jjj,kkk) * p( 0,+1, 0)
3282  + A0mp(iii+1,jjj,kkk) * p(-1,-1,+1)
3283  + Apmp(iii+1,jjj,kkk) * p( 0,-1,+1)
3284  + A00p(iii+1,jjj,kkk) * p(-1, 0,+1)
3285  + Ap0p(iii+1,jjj,kkk) * p( 0, 0,+1)
3286  + A0pp(iii+1,jjj,kkk) * p(-1,+1,+1)
3287  + Appp(iii+1,jjj,kkk) * p( 0,+1,+1);
3288  ap(0,1,0) =
3289  Apmm(iii,jjj+1,kkk) * p(-1, 0,-1)
3290  + Ap0m(iii,jjj+1,kkk) * p(-1,+1,-1)
3291  + Apm0(iii,jjj+1,kkk) * p(-1, 0, 0)
3292  + Ap00(iii,jjj+1,kkk) * p(-1,+1, 0)
3293  + Apmp(iii,jjj+1,kkk) * p(-1, 0,+1)
3294  + Ap0p(iii,jjj+1,kkk) * p(-1,+1,+1);
3295  ap(1,1,0) =
3296  A0mm(iii+1,jjj+1,kkk) * p(-1, 0,-1)
3297  + Apmm(iii+1,jjj+1,kkk) * p( 0, 0,-1)
3298  + A00m(iii+1,jjj+1,kkk) * p(-1,+1,-1)
3299  + Ap0m(iii+1,jjj+1,kkk) * p( 0,+1,-1)
3300  + A0m0(iii+1,jjj+1,kkk) * p(-1, 0, 0)
3301  + Apm0(iii+1,jjj+1,kkk) * p( 0, 0, 0)
3302  + A000(iii+1,jjj+1,kkk) * p(-1,+1, 0)
3303  + Ap00(iii+1,jjj+1,kkk) * p( 0,+1, 0)
3304  + A0mp(iii+1,jjj+1,kkk) * p(-1, 0,+1)
3305  + Apmp(iii+1,jjj+1,kkk) * p( 0, 0,+1)
3306  + A00p(iii+1,jjj+1,kkk) * p(-1,+1,+1)
3307  + Ap0p(iii+1,jjj+1,kkk) * p( 0,+1,+1);
3308  ap(0,-1,1) =
3309  Ap0m(iii,jjj-1,kkk+1) * p(-1,-1, 0)
3310  + Appm(iii,jjj-1,kkk+1) * p(-1, 0, 0)
3311  + Ap00(iii,jjj-1,kkk+1) * p(-1,-1,+1)
3312  + App0(iii,jjj-1,kkk+1) * p(-1, 0,+1);
3313  ap(1,-1,1) =
3314  A00m(iii+1,jjj-1,kkk+1) * p(-1,-1, 0)
3315  + Ap0m(iii+1,jjj-1,kkk+1) * p( 0,-1, 0)
3316  + A0pm(iii+1,jjj-1,kkk+1) * p(-1, 0, 0)
3317  + Appm(iii+1,jjj-1,kkk+1) * p( 0, 0, 0)
3318  + A000(iii+1,jjj-1,kkk+1) * p(-1,-1,+1)
3319  + Ap00(iii+1,jjj-1,kkk+1) * p( 0,-1,+1)
3320  + A0p0(iii+1,jjj-1,kkk+1) * p(-1, 0,+1)
3321  + App0(iii+1,jjj-1,kkk+1) * p( 0, 0,+1);
3322  ap(0,0,1) =
3323  Apmm(iii,jjj,kkk+1) * p(-1,-1, 0)
3324  + Ap0m(iii,jjj,kkk+1) * p(-1, 0, 0)
3325  + Appm(iii,jjj,kkk+1) * p(-1,+1, 0)
3326  + Apm0(iii,jjj,kkk+1) * p(-1,-1,+1)
3327  + Ap00(iii,jjj,kkk+1) * p(-1, 0,+1)
3328  + App0(iii,jjj,kkk+1) * p(-1,+1,+1);
3329  ap(1,0,1) =
3330  A0mm(iii+1,jjj,kkk+1) * p(-1,-1, 0)
3331  + Apmm(iii+1,jjj,kkk+1) * p( 0,-1, 0)
3332  + A00m(iii+1,jjj,kkk+1) * p(-1, 0, 0)
3333  + Ap0m(iii+1,jjj,kkk+1) * p( 0, 0, 0)
3334  + A0pm(iii+1,jjj,kkk+1) * p(-1,+1, 0)
3335  + Appm(iii+1,jjj,kkk+1) * p( 0,+1, 0)
3336  + A0m0(iii+1,jjj,kkk+1) * p(-1,-1,+1)
3337  + Apm0(iii+1,jjj,kkk+1) * p( 0,-1,+1)
3338  + A000(iii+1,jjj,kkk+1) * p(-1, 0,+1)
3339  + Ap00(iii+1,jjj,kkk+1) * p( 0, 0,+1)
3340  + A0p0(iii+1,jjj,kkk+1) * p(-1,+1,+1)
3341  + App0(iii+1,jjj,kkk+1) * p( 0,+1,+1);
3342  ap(0,1,1) =
3343  Apmm(iii,jjj+1,kkk+1) * p(-1, 0, 0)
3344  + Ap0m(iii,jjj+1,kkk+1) * p(-1,+1, 0)
3345  + Apm0(iii,jjj+1,kkk+1) * p(-1, 0,+1)
3346  + Ap00(iii,jjj+1,kkk+1) * p(-1,+1,+1);
3347  ap(1,1,1) =
3348  A0mm(iii+1,jjj+1,kkk+1) * p(-1, 0, 0)
3349  + Apmm(iii+1,jjj+1,kkk+1) * p( 0, 0, 0)
3350  + A00m(iii+1,jjj+1,kkk+1) * p(-1,+1, 0)
3351  + Ap0m(iii+1,jjj+1,kkk+1) * p( 0,+1, 0)
3352  + A0m0(iii+1,jjj+1,kkk+1) * p(-1, 0,+1)
3353  + Apm0(iii+1,jjj+1,kkk+1) * p( 0, 0,+1)
3354  + A000(iii+1,jjj+1,kkk+1) * p(-1,+1,+1)
3355  + Ap00(iii+1,jjj+1,kkk+1) * p( 0,+1,+1);
3356  csten(i,j,k,ist_p00) = Real(0.125) *
3357  ( restrict_from_0mm_to(iii,jjj,kkk) * ap( 0,-1,-1)
3358  + restrict_from_pmm_to(iii,jjj,kkk) * ap(+1,-1,-1)
3359  + restrict_from_00m_to(iii,jjj,kkk) * ap( 0, 0,-1)
3360  + restrict_from_p0m_to(iii,jjj,kkk) * ap(+1, 0,-1)
3361  + restrict_from_0pm_to(iii,jjj,kkk) * ap( 0,+1,-1)
3362  + restrict_from_ppm_to(iii,jjj,kkk) * ap(+1,+1,-1)
3363  + restrict_from_0m0_to(iii,jjj,kkk) * ap( 0,-1, 0)
3364  + restrict_from_pm0_to(iii,jjj,kkk) * ap(+1,-1, 0)
3365  + restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
3366  + restrict_from_p00_to(iii,jjj,kkk) * ap(+1, 0, 0)
3367  + restrict_from_0p0_to(iii,jjj,kkk) * ap( 0,+1, 0)
3368  + restrict_from_pp0_to(iii,jjj,kkk) * ap(+1,+1, 0)
3369  + restrict_from_0mp_to(iii,jjj,kkk) * ap( 0,-1,+1)
3370  + restrict_from_pmp_to(iii,jjj,kkk) * ap(+1,-1,+1)
3371  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1)
3372  + restrict_from_p0p_to(iii,jjj,kkk) * ap(+1, 0,+1)
3373  + restrict_from_0pp_to(iii,jjj,kkk) * ap( 0,+1,+1)
3374  + restrict_from_ppp_to(iii,jjj,kkk) * ap(+1,+1,+1));
3375 
3376  // csten(i,j,k,ist_0p0)
3377  iii = ii;
3378  jjj = jj;
3379  kkk = kk;
3380  p(-1,-1,-1) = interp_from_ppp_to(iii-1,jjj+1,kkk-1);
3381  p( 0,-1,-1) = interp_from_0pp_to(iii ,jjj+1,kkk-1);
3382  p(+1,-1,-1) = interp_from_mpp_to(iii+1,jjj+1,kkk-1);
3383  p(-1, 0,-1) = interp_from_p0p_to(iii-1,jjj+2,kkk-1);
3384  p( 0, 0,-1) = interp_from_00p_to(iii ,jjj+2,kkk-1);
3385  p(+1, 0,-1) = interp_from_m0p_to(iii+1,jjj+2,kkk-1);
3386  p(-1,-1, 0) = interp_from_pp0_to(iii-1,jjj+1,kkk );
3387  p( 0,-1, 0) = interp_from_0p0_to(iii ,jjj+1,kkk );
3388  p(+1,-1, 0) = interp_from_mp0_to(iii+1,jjj+1,kkk );
3389  p(-1, 0, 0) = interp_from_p00_to(iii-1,jjj+2,kkk );
3390  p( 0, 0, 0) = Real(1.);
3391  p(+1, 0, 0) = interp_from_m00_to(iii+1,jjj+2,kkk );
3392  p(-1,-1,+1) = interp_from_ppm_to(iii-1,jjj+1,kkk+1);
3393  p( 0,-1,+1) = interp_from_0pm_to(iii ,jjj+1,kkk+1);
3394  p(+1,-1,+1) = interp_from_mpm_to(iii+1,jjj+1,kkk+1);
3395  p(-1, 0,+1) = interp_from_p0m_to(iii-1,jjj+2,kkk+1);
3396  p( 0, 0,+1) = interp_from_00m_to(iii ,jjj+2,kkk+1);
3397  p(+1, 0,+1) = interp_from_m0m_to(iii+1,jjj+2,kkk+1);
3398  ap(-1,0,-1) =
3399  A0p0(iii-1,jjj,kkk-1) * p(-1,-1,-1)
3400  + App0(iii-1,jjj,kkk-1) * p( 0,-1,-1)
3401  + A0pp(iii-1,jjj,kkk-1) * p(-1,-1, 0)
3402  + Appp(iii-1,jjj,kkk-1) * p( 0,-1, 0);
3403  ap(0,0,-1) =
3404  Amp0(iii,jjj,kkk-1) * p(-1,-1,-1)
3405  + A0p0(iii,jjj,kkk-1) * p( 0,-1,-1)
3406  + App0(iii,jjj,kkk-1) * p(+1,-1,-1)
3407  + Ampp(iii,jjj,kkk-1) * p(-1,-1, 0)
3408  + A0pp(iii,jjj,kkk-1) * p( 0,-1, 0)
3409  + Appp(iii,jjj,kkk-1) * p(+1,-1, 0);
3410  ap(1,0,-1) =
3411  Amp0(iii+1,jjj,kkk-1) * p( 0,-1,-1)
3412  + A0p0(iii+1,jjj,kkk-1) * p(+1,-1,-1)
3413  + Ampp(iii+1,jjj,kkk-1) * p( 0,-1, 0)
3414  + A0pp(iii+1,jjj,kkk-1) * p(+1,-1, 0);
3415  ap(-1,1,-1) =
3416  A000(iii-1,jjj+1,kkk-1) * p(-1,-1,-1)
3417  + Ap00(iii-1,jjj+1,kkk-1) * p( 0,-1,-1)
3418  + A0p0(iii-1,jjj+1,kkk-1) * p(-1, 0,-1)
3419  + App0(iii-1,jjj+1,kkk-1) * p( 0, 0,-1)
3420  + A00p(iii-1,jjj+1,kkk-1) * p(-1,-1, 0)
3421  + Ap0p(iii-1,jjj+1,kkk-1) * p( 0,-1, 0)
3422  + A0pp(iii-1,jjj+1,kkk-1) * p(-1, 0, 0)
3423  + Appp(iii-1,jjj+1,kkk-1) * p( 0, 0, 0);
3424  ap(0,1,-1) =
3425  Am00(iii,jjj+1,kkk-1) * p(-1,-1,-1)
3426  + A000(iii,jjj+1,kkk-1) * p( 0,-1,-1)
3427  + Ap00(iii,jjj+1,kkk-1) * p(+1,-1,-1)
3428  + Amp0(iii,jjj+1,kkk-1) * p(-1, 0,-1)
3429  + A0p0(iii,jjj+1,kkk-1) * p( 0, 0,-1)
3430  + App0(iii,jjj+1,kkk-1) * p(+1, 0,-1)
3431  + Am0p(iii,jjj+1,kkk-1) * p(-1,-1, 0)
3432  + A00p(iii,jjj+1,kkk-1) * p( 0,-1, 0)
3433  + Ap0p(iii,jjj+1,kkk-1) * p(+1,-1, 0)
3434  + Ampp(iii,jjj+1,kkk-1) * p(-1, 0, 0)
3435  + A0pp(iii,jjj+1,kkk-1) * p( 0, 0, 0)
3436  + Appp(iii,jjj+1,kkk-1) * p(+1, 0, 0);
3437  ap(1,1,-1) =
3438  Am00(iii+1,jjj+1,kkk-1) * p( 0,-1,-1)
3439  + A000(iii+1,jjj+1,kkk-1) * p(+1,-1,-1)
3440  + Amp0(iii+1,jjj+1,kkk-1) * p( 0, 0,-1)
3441  + A0p0(iii+1,jjj+1,kkk-1) * p(+1, 0,-1)
3442  + Am0p(iii+1,jjj+1,kkk-1) * p( 0,-1, 0)
3443  + A00p(iii+1,jjj+1,kkk-1) * p(+1,-1, 0)
3444  + Ampp(iii+1,jjj+1,kkk-1) * p( 0, 0, 0)
3445  + A0pp(iii+1,jjj+1,kkk-1) * p(+1, 0, 0);
3446  ap(-1,0,0) =
3447  A0pm(iii-1,jjj,kkk) * p(-1,-1,-1)
3448  + Appm(iii-1,jjj,kkk) * p( 0,-1,-1)
3449  + A0p0(iii-1,jjj,kkk) * p(-1,-1, 0)
3450  + App0(iii-1,jjj,kkk) * p( 0,-1, 0)
3451  + A0pp(iii-1,jjj,kkk) * p(-1,-1,+1)
3452  + Appp(iii-1,jjj,kkk) * p( 0,-1,+1);
3453  ap(0,0,0) =
3454  Ampm(iii,jjj,kkk) * p(-1,-1,-1)
3455  + A0pm(iii,jjj,kkk) * p( 0,-1,-1)
3456  + Appm(iii,jjj,kkk) * p(+1,-1,-1)
3457  + Amp0(iii,jjj,kkk) * p(-1,-1, 0)
3458  + A0p0(iii,jjj,kkk) * p( 0,-1, 0)
3459  + App0(iii,jjj,kkk) * p(+1,-1, 0)
3460  + Ampp(iii,jjj,kkk) * p(-1,-1,+1)
3461  + A0pp(iii,jjj,kkk) * p( 0,-1,+1)
3462  + Appp(iii,jjj,kkk) * p(+1,-1,+1);
3463  ap(1,0,0) =
3464  Ampm(iii+1,jjj,kkk) * p( 0,-1,-1)
3465  + A0pm(iii+1,jjj,kkk) * p(+1,-1,-1)
3466  + Amp0(iii+1,jjj,kkk) * p( 0,-1, 0)
3467  + A0p0(iii+1,jjj,kkk) * p(+1,-1, 0)
3468  + Ampp(iii+1,jjj,kkk) * p( 0,-1,+1)
3469  + A0pp(iii+1,jjj,kkk) * p(+1,-1,+1);
3470  ap(-1,1,0) =
3471  A00m(iii-1,jjj+1,kkk) * p(-1,-1,-1)
3472  + Ap0m(iii-1,jjj+1,kkk) * p( 0,-1,-1)
3473  + A0pm(iii-1,jjj+1,kkk) * p(-1, 0,-1)
3474  + Appm(iii-1,jjj+1,kkk) * p( 0, 0,-1)
3475  + A000(iii-1,jjj+1,kkk) * p(-1,-1, 0)
3476  + Ap00(iii-1,jjj+1,kkk) * p( 0,-1, 0)
3477  + A0p0(iii-1,jjj+1,kkk) * p(-1, 0, 0)
3478  + App0(iii-1,jjj+1,kkk) * p( 0, 0, 0)
3479  + A00p(iii-1,jjj+1,kkk) * p(-1,-1,+1)
3480  + Ap0p(iii-1,jjj+1,kkk) * p( 0,-1,+1)
3481  + A0pp(iii-1,jjj+1,kkk) * p(-1, 0,+1)
3482  + Appp(iii-1,jjj+1,kkk) * p( 0, 0,+1);
3483  ap(0,1,0) =
3484  Am0m(iii,jjj+1,kkk) * p(-1,-1,-1)
3485  + A00m(iii,jjj+1,kkk) * p( 0,-1,-1)
3486  + Ap0m(iii,jjj+1,kkk) * p(+1,-1,-1)
3487  + Ampm(iii,jjj+1,kkk) * p(-1, 0,-1)
3488  + A0pm(iii,jjj+1,kkk) * p( 0, 0,-1)
3489  + Appm(iii,jjj+1,kkk) * p(+1, 0,-1)
3490  + Am00(iii,jjj+1,kkk) * p(-1,-1, 0)
3491  + A000(iii,jjj+1,kkk) * p( 0,-1, 0)
3492  + Ap00(iii,jjj+1,kkk) * p(+1,-1, 0)
3493  + Amp0(iii,jjj+1,kkk) * p(-1, 0, 0)
3494  + A0p0(iii,jjj+1,kkk) * p( 0, 0, 0)
3495  + App0(iii,jjj+1,kkk) * p(+1, 0, 0)
3496  + Am0p(iii,jjj+1,kkk) * p(-1,-1,+1)
3497  + A00p(iii,jjj+1,kkk) * p( 0,-1,+1)
3498  + Ap0p(iii,jjj+1,kkk) * p(+1,-1,+1)
3499  + Ampp(iii,jjj+1,kkk) * p(-1, 0,+1)
3500  + A0pp(iii,jjj+1,kkk) * p( 0, 0,+1)
3501  + Appp(iii,jjj+1,kkk) * p(+1, 0,+1);
3502  ap(1,1,0) =
3503  Am0m(iii+1,jjj+1,kkk) * p( 0,-1,-1)
3504  + A00m(iii+1,jjj+1,kkk) * p(+1,-1,-1)
3505  + Ampm(iii+1,jjj+1,kkk) * p( 0, 0,-1)
3506  + A0pm(iii+1,jjj+1,kkk) * p(+1, 0,-1)
3507  + Am00(iii+1,jjj+1,kkk) * p( 0,-1, 0)
3508  + A000(iii+1,jjj+1,kkk) * p(+1,-1, 0)
3509  + Amp0(iii+1,jjj+1,kkk) * p( 0, 0, 0)
3510  + A0p0(iii+1,jjj+1,kkk) * p(+1, 0, 0)
3511  + Am0p(iii+1,jjj+1,kkk) * p( 0,-1,+1)
3512  + A00p(iii+1,jjj+1,kkk) * p(+1,-1,+1)
3513  + Ampp(iii+1,jjj+1,kkk) * p( 0, 0,+1)
3514  + A0pp(iii+1,jjj+1,kkk) * p(+1, 0,+1);
3515  ap(-1,0,1) =
3516  A0pm(iii-1,jjj,kkk+1) * p(-1,-1, 0)
3517  + Appm(iii-1,jjj,kkk+1) * p( 0,-1, 0)
3518  + A0p0(iii-1,jjj,kkk+1) * p(-1,-1,+1)
3519  + App0(iii-1,jjj,kkk+1) * p( 0,-1,+1);
3520  ap(0,0,1) =
3521  Ampm(iii,jjj,kkk+1) * p(-1,-1, 0)
3522  + A0pm(iii,jjj,kkk+1) * p( 0,-1, 0)
3523  + Appm(iii,jjj,kkk+1) * p(+1,-1, 0)
3524  + Amp0(iii,jjj,kkk+1) * p(-1,-1,+1)
3525  + A0p0(iii,jjj,kkk+1) * p( 0,-1,+1)
3526  + App0(iii,jjj,kkk+1) * p(+1,-1,+1);
3527  ap(1,0,1) =
3528  Ampm(iii+1,jjj,kkk+1) * p( 0,-1, 0)
3529  + A0pm(iii+1,jjj,kkk+1) * p(+1,-1, 0)
3530  + Amp0(iii+1,jjj,kkk+1) * p( 0,-1,+1)
3531  + A0p0(iii+1,jjj,kkk+1) * p(+1,-1,+1);
3532  ap(-1,1,1) =
3533  A00m(iii-1,jjj+1,kkk+1) * p(-1,-1, 0)
3534  + Ap0m(iii-1,jjj+1,kkk+1) * p( 0,-1, 0)
3535  + A0pm(iii-1,jjj+1,kkk+1) * p(-1, 0, 0)
3536  + Appm(iii-1,jjj+1,kkk+1) * p( 0, 0, 0)
3537  + A000(iii-1,jjj+1,kkk+1) * p(-1,-1,+1)
3538  + Ap00(iii-1,jjj+1,kkk+1) * p( 0,-1,+1)
3539  + A0p0(iii-1,jjj+1,kkk+1) * p(-1, 0,+1)
3540  + App0(iii-1,jjj+1,kkk+1) * p( 0, 0,+1);
3541  ap(0,1,1) =
3542  Am0m(iii,jjj+1,kkk+1) * p(-1,-1, 0)
3543  + A00m(iii,jjj+1,kkk+1) * p( 0,-1, 0)
3544  + Ap0m(iii,jjj+1,kkk+1) * p(+1,-1, 0)
3545  + Ampm(iii,jjj+1,kkk+1) * p(-1, 0, 0)
3546  + A0pm(iii,jjj+1,kkk+1) * p( 0, 0, 0)
3547  + Appm(iii,jjj+1,kkk+1) * p(+1, 0, 0)
3548  + Am00(iii,jjj+1,kkk+1) * p(-1,-1,+1)
3549  + A000(iii,jjj+1,kkk+1) * p( 0,-1,+1)
3550  + Ap00(iii,jjj+1,kkk+1) * p(+1,-1,+1)
3551  + Amp0(iii,jjj+1,kkk+1) * p(-1, 0,+1)
3552  + A0p0(iii,jjj+1,kkk+1) * p( 0, 0,+1)
3553  + App0(iii,jjj+1,kkk+1) * p(+1, 0,+1);
3554  ap(1,1,1) =
3555  Am0m(iii+1,jjj+1,kkk+1) * p( 0,-1, 0)
3556  + A00m(iii+1,jjj+1,kkk+1) * p(+1,-1, 0)
3557  + Ampm(iii+1,jjj+1,kkk+1) * p( 0, 0, 0)
3558  + A0pm(iii+1,jjj+1,kkk+1) * p(+1, 0, 0)
3559  + Am00(iii+1,jjj+1,kkk+1) * p( 0,-1,+1)
3560  + A000(iii+1,jjj+1,kkk+1) * p(+1,-1,+1)
3561  + Amp0(iii+1,jjj+1,kkk+1) * p( 0, 0,+1)
3562  + A0p0(iii+1,jjj+1,kkk+1) * p(+1, 0,+1);
3563  csten(i,j,k,ist_0p0) = Real(0.125) *
3564  ( restrict_from_m0m_to(iii,jjj,kkk) * ap(-1, 0,-1)
3565  + restrict_from_00m_to(iii,jjj,kkk) * ap( 0, 0,-1)
3566  + restrict_from_p0m_to(iii,jjj,kkk) * ap(+1, 0,-1)
3567  + restrict_from_mpm_to(iii,jjj,kkk) * ap(-1,+1,-1)
3568  + restrict_from_0pm_to(iii,jjj,kkk) * ap( 0,+1,-1)
3569  + restrict_from_ppm_to(iii,jjj,kkk) * ap(+1,+1,-1)
3570  + restrict_from_m00_to(iii,jjj,kkk) * ap(-1, 0, 0)
3571  + restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
3572  + restrict_from_p00_to(iii,jjj,kkk) * ap(+1, 0, 0)
3573  + restrict_from_mp0_to(iii,jjj,kkk) * ap(-1,+1, 0)
3574  + restrict_from_0p0_to(iii,jjj,kkk) * ap( 0,+1, 0)
3575  + restrict_from_pp0_to(iii,jjj,kkk) * ap(+1,+1, 0)
3576  + restrict_from_m0p_to(iii,jjj,kkk) * ap(-1, 0,+1)
3577  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1)
3578  + restrict_from_p0p_to(iii,jjj,kkk) * ap(+1, 0,+1)
3579  + restrict_from_mpp_to(iii,jjj,kkk) * ap(-1,+1,+1)
3580  + restrict_from_0pp_to(iii,jjj,kkk) * ap( 0,+1,+1)
3581  + restrict_from_ppp_to(iii,jjj,kkk) * ap(+1,+1,+1));
3582 
3583  // csten(i,j,k,ist_00p)
3584  iii = ii;
3585  jjj = jj;
3586  kkk = kk;
3587  p(-1,-1,-1) = interp_from_ppp_to(iii-1,jjj-1,kkk+1);
3588  p( 0,-1,-1) = interp_from_0pp_to(iii ,jjj-1,kkk+1);
3589  p(+1,-1,-1) = interp_from_mpp_to(iii+1,jjj-1,kkk+1);
3590  p(-1, 0,-1) = interp_from_p0p_to(iii-1,jjj ,kkk+1);
3591  p( 0, 0,-1) = interp_from_00p_to(iii ,jjj ,kkk+1);
3592  p(+1, 0,-1) = interp_from_m0p_to(iii+1,jjj ,kkk+1);
3593  p(-1,+1,-1) = interp_from_pmp_to(iii-1,jjj+1,kkk+1);
3594  p( 0,+1,-1) = interp_from_0mp_to(iii ,jjj+1,kkk+1);
3595  p(+1,+1,-1) = interp_from_mmp_to(iii+1,jjj+1,kkk+1);
3596  p(-1,-1, 0) = interp_from_pp0_to(iii-1,jjj-1,kkk+2);
3597  p( 0,-1, 0) = interp_from_0p0_to(iii ,jjj-1,kkk+2);
3598  p(+1,-1, 0) = interp_from_mp0_to(iii+1,jjj-1,kkk+2);
3599  p(-1, 0, 0) = interp_from_p00_to(iii-1,jjj ,kkk+2);
3600  p( 0, 0, 0) = Real(1.);
3601  p(+1, 0, 0) = interp_from_m00_to(iii+1,jjj ,kkk+2);
3602  p(-1,+1, 0) = interp_from_pm0_to(iii-1,jjj+1,kkk+2);
3603  p( 0,+1, 0) = interp_from_0m0_to(iii ,jjj+1,kkk+2);
3604  p(+1,+1, 0) = interp_from_mm0_to(iii+1,jjj+1,kkk+2);
3605  ap(-1,-1,0) =
3606  A00p(iii-1,jjj-1,kkk) * p(-1,-1,-1)
3607  + Ap0p(iii-1,jjj-1,kkk) * p( 0,-1,-1)
3608  + A0pp(iii-1,jjj-1,kkk) * p(-1, 0,-1)
3609  + Appp(iii-1,jjj-1,kkk) * p( 0, 0,-1);
3610  ap(0,-1,0) =
3611  Am0p(iii,jjj-1,kkk) * p(-1,-1,-1)
3612  + A00p(iii,jjj-1,kkk) * p( 0,-1,-1)
3613  + Ap0p(iii,jjj-1,kkk) * p(+1,-1,-1)
3614  + Ampp(iii,jjj-1,kkk) * p(-1, 0,-1)
3615  + A0pp(iii,jjj-1,kkk) * p( 0, 0,-1)
3616  + Appp(iii,jjj-1,kkk) * p(+1, 0,-1);
3617  ap(1,-1,0) =
3618  Am0p(iii+1,jjj-1,kkk) * p( 0,-1,-1)
3619  + A00p(iii+1,jjj-1,kkk) * p(+1,-1,-1)
3620  + Ampp(iii+1,jjj-1,kkk) * p( 0, 0,-1)
3621  + A0pp(iii+1,jjj-1,kkk) * p(+1, 0,-1);
3622  ap(-1,0,0) =
3623  A0mp(iii-1,jjj,kkk) * p(-1,-1,-1)
3624  + Apmp(iii-1,jjj,kkk) * p( 0,-1,-1)
3625  + A00p(iii-1,jjj,kkk) * p(-1, 0,-1)
3626  + Ap0p(iii-1,jjj,kkk) * p( 0, 0,-1)
3627  + A0pp(iii-1,jjj,kkk) * p(-1,+1,-1)
3628  + Appp(iii-1,jjj,kkk) * p( 0,+1,-1);
3629  ap(0,0,0) =
3630  Ammp(iii,jjj,kkk) * p(-1,-1,-1)
3631  + A0mp(iii,jjj,kkk) * p( 0,-1,-1)
3632  + Apmp(iii,jjj,kkk) * p(+1,-1,-1)
3633  + Am0p(iii,jjj,kkk) * p(-1, 0,-1)
3634  + A00p(iii,jjj,kkk) * p( 0, 0,-1)
3635  + Ap0p(iii,jjj,kkk) * p(+1, 0,-1)
3636  + Ampp(iii,jjj,kkk) * p(-1,+1,-1)
3637  + A0pp(iii,jjj,kkk) * p( 0,+1,-1)
3638  + Appp(iii,jjj,kkk) * p(+1,+1,-1);
3639  ap(1,0,0) =
3640  Ammp(iii+1,jjj,kkk) * p( 0,-1,-1)
3641  + A0mp(iii+1,jjj,kkk) * p(+1,-1,-1)
3642  + Am0p(iii+1,jjj,kkk) * p( 0, 0,-1)
3643  + A00p(iii+1,jjj,kkk) * p(+1, 0,-1)
3644  + Ampp(iii+1,jjj,kkk) * p( 0,+1,-1)
3645  + A0pp(iii+1,jjj,kkk) * p(+1,+1,-1);
3646  ap(-1,1,0) =
3647  A0mp(iii-1,jjj+1,kkk) * p(-1, 0,-1)
3648  + Apmp(iii-1,jjj+1,kkk) * p( 0, 0,-1)
3649  + A00p(iii-1,jjj+1,kkk) * p(-1,+1,-1)
3650  + Ap0p(iii-1,jjj+1,kkk) * p( 0,+1,-1);
3651  ap(0,1,0) =
3652  Ammp(iii,jjj+1,kkk) * p(-1, 0,-1)
3653  + A0mp(iii,jjj+1,kkk) * p( 0, 0,-1)
3654  + Apmp(iii,jjj+1,kkk) * p(+1, 0,-1)
3655  + Am0p(iii,jjj+1,kkk) * p(-1,+1,-1)
3656  + A00p(iii,jjj+1,kkk) * p( 0,+1,-1)
3657  + Ap0p(iii,jjj+1,kkk) * p(+1,+1,-1);
3658  ap(1,1,0) =
3659  Ammp(iii+1,jjj+1,kkk) * p( 0, 0,-1)
3660  + A0mp(iii+1,jjj+1,kkk) * p(+1, 0,-1)
3661  + Am0p(iii+1,jjj+1,kkk) * p( 0,+1,-1)
3662  + A00p(iii+1,jjj+1,kkk) * p(+1,+1,-1);
3663  ap(-1,-1,1) =
3664  A000(iii-1,jjj-1,kkk+1) * p(-1,-1,-1)
3665  + Ap00(iii-1,jjj-1,kkk+1) * p( 0,-1,-1)
3666  + A0p0(iii-1,jjj-1,kkk+1) * p(-1, 0,-1)
3667  + App0(iii-1,jjj-1,kkk+1) * p( 0, 0,-1)
3668  + A00p(iii-1,jjj-1,kkk+1) * p(-1,-1, 0)
3669  + Ap0p(iii-1,jjj-1,kkk+1) * p( 0,-1, 0)
3670  + A0pp(iii-1,jjj-1,kkk+1) * p(-1, 0, 0)
3671  + Appp(iii-1,jjj-1,kkk+1) * p( 0, 0, 0);
3672  ap(0,-1,1) =
3673  Am00(iii,jjj-1,kkk+1) * p(-1,-1,-1)
3674  + A000(iii,jjj-1,kkk+1) * p( 0,-1,-1)
3675  + Ap00(iii,jjj-1,kkk+1) * p(+1,-1,-1)
3676  + Amp0(iii,jjj-1,kkk+1) * p(-1, 0,-1)
3677  + A0p0(iii,jjj-1,kkk+1) * p( 0, 0,-1)
3678  + App0(iii,jjj-1,kkk+1) * p(+1, 0,-1)
3679  + Am0p(iii,jjj-1,kkk+1) * p(-1,-1, 0)
3680  + A00p(iii,jjj-1,kkk+1) * p( 0,-1, 0)
3681  + Ap0p(iii,jjj-1,kkk+1) * p(+1,-1, 0)
3682  + Ampp(iii,jjj-1,kkk+1) * p(-1, 0, 0)
3683  + A0pp(iii,jjj-1,kkk+1) * p( 0, 0, 0)
3684  + Appp(iii,jjj-1,kkk+1) * p(+1, 0, 0);
3685  ap(1,-1,1) =
3686  Am00(iii+1,jjj-1,kkk+1) * p( 0,-1,-1)
3687  + A000(iii+1,jjj-1,kkk+1) * p(+1,-1,-1)
3688  + Amp0(iii+1,jjj-1,kkk+1) * p( 0, 0,-1)
3689  + A0p0(iii+1,jjj-1,kkk+1) * p(+1, 0,-1)
3690  + Am0p(iii+1,jjj-1,kkk+1) * p( 0,-1, 0)
3691  + A00p(iii+1,jjj-1,kkk+1) * p(+1,-1, 0)
3692  + Ampp(iii+1,jjj-1,kkk+1) * p( 0, 0, 0)
3693  + A0pp(iii+1,jjj-1,kkk+1) * p(+1, 0, 0);
3694  ap(-1,0,1) =
3695  A0m0(iii-1,jjj,kkk+1) * p(-1,-1,-1)
3696  + Apm0(iii-1,jjj,kkk+1) * p( 0,-1,-1)
3697  + A000(iii-1,jjj,kkk+1) * p(-1, 0,-1)
3698  + Ap00(iii-1,jjj,kkk+1) * p( 0, 0,-1)
3699  + A0p0(iii-1,jjj,kkk+1) * p(-1,+1,-1)
3700  + App0(iii-1,jjj,kkk+1) * p( 0,+1,-1)
3701  + A0mp(iii-1,jjj,kkk+1) * p(-1,-1, 0)
3702  + Apmp(iii-1,jjj,kkk+1) * p( 0,-1, 0)
3703  + A00p(iii-1,jjj,kkk+1) * p(-1, 0, 0)
3704  + Ap0p(iii-1,jjj,kkk+1) * p( 0, 0, 0)
3705  + A0pp(iii-1,jjj,kkk+1) * p(-1,+1, 0)
3706  + Appp(iii-1,jjj,kkk+1) * p( 0,+1, 0);
3707  ap(0,0,1) =
3708  Amm0(iii,jjj,kkk+1) * p(-1,-1,-1)
3709  + A0m0(iii,jjj,kkk+1) * p( 0,-1,-1)
3710  + Apm0(iii,jjj,kkk+1) * p(+1,-1,-1)
3711  + Am00(iii,jjj,kkk+1) * p(-1, 0,-1)
3712  + A000(iii,jjj,kkk+1) * p( 0, 0,-1)
3713  + Ap00(iii,jjj,kkk+1) * p(+1, 0,-1)
3714  + Amp0(iii,jjj,kkk+1) * p(-1,+1,-1)
3715  + A0p0(iii,jjj,kkk+1) * p( 0,+1,-1)
3716  + App0(iii,jjj,kkk+1) * p(+1,+1,-1)
3717  + Ammp(iii,jjj,kkk+1) * p(-1,-1, 0)
3718  + A0mp(iii,jjj,kkk+1) * p( 0,-1, 0)
3719  + Apmp(iii,jjj,kkk+1) * p(+1,-1, 0)
3720  + Am0p(iii,jjj,kkk+1) * p(-1, 0, 0)
3721  + A00p(iii,jjj,kkk+1) * p( 0, 0, 0)
3722  + Ap0p(iii,jjj,kkk+1) * p(+1, 0, 0)
3723  + Ampp(iii,jjj,kkk+1) * p(-1,+1, 0)
3724  + A0pp(iii,jjj,kkk+1) * p( 0,+1, 0)
3725  + Appp(iii,jjj,kkk+1) * p(+1,+1, 0);
3726  ap(1,0,1) =
3727  Amm0(iii+1,jjj,kkk+1) * p( 0,-1,-1)
3728  + A0m0(iii+1,jjj,kkk+1) * p(+1,-1,-1)
3729  + Am00(iii+1,jjj,kkk+1) * p( 0, 0,-1)
3730  + A000(iii+1,jjj,kkk+1) * p(+1, 0,-1)
3731  + Amp0(iii+1,jjj,kkk+1) * p( 0,+1,-1)
3732  + A0p0(iii+1,jjj,kkk+1) * p(+1,+1,-1)
3733  + Ammp(iii+1,jjj,kkk+1) * p( 0,-1, 0)
3734  + A0mp(iii+1,jjj,kkk+1) * p(+1,-1, 0)
3735  + Am0p(iii+1,jjj,kkk+1) * p( 0, 0, 0)
3736  + A00p(iii+1,jjj,kkk+1) * p(+1, 0, 0)
3737  + Ampp(iii+1,jjj,kkk+1) * p( 0,+1, 0)
3738  + A0pp(iii+1,jjj,kkk+1) * p(+1,+1, 0);
3739  ap(-1,1,1) =
3740  A0m0(iii-1,jjj+1,kkk+1) * p(-1, 0,-1)
3741  + Apm0(iii-1,jjj+1,kkk+1) * p( 0, 0,-1)
3742  + A000(iii-1,jjj+1,kkk+1) * p(-1,+1,-1)
3743  + Ap00(iii-1,jjj+1,kkk+1) * p( 0,+1,-1)
3744  + A0mp(iii-1,jjj+1,kkk+1) * p(-1, 0, 0)
3745  + Apmp(iii-1,jjj+1,kkk+1) * p( 0, 0, 0)
3746  + A00p(iii-1,jjj+1,kkk+1) * p(-1,+1, 0)
3747  + Ap0p(iii-1,jjj+1,kkk+1) * p( 0,+1, 0);
3748  ap(0,1,1) =
3749  Amm0(iii,jjj+1,kkk+1) * p(-1, 0,-1)
3750  + A0m0(iii,jjj+1,kkk+1) * p( 0, 0,-1)
3751  + Apm0(iii,jjj+1,kkk+1) * p(+1, 0,-1)
3752  + Am00(iii,jjj+1,kkk+1) * p(-1,+1,-1)
3753  + A000(iii,jjj+1,kkk+1) * p( 0,+1,-1)
3754  + Ap00(iii,jjj+1,kkk+1) * p(+1,+1,-1)
3755  + Ammp(iii,jjj+1,kkk+1) * p(-1, 0, 0)
3756  + A0mp(iii,jjj+1,kkk+1) * p( 0, 0, 0)
3757  + Apmp(iii,jjj+1,kkk+1) * p(+1, 0, 0)
3758  + Am0p(iii,jjj+1,kkk+1) * p(-1,+1, 0)
3759  + A00p(iii,jjj+1,kkk+1) * p( 0,+1, 0)
3760  + Ap0p(iii,jjj+1,kkk+1) * p(+1,+1, 0);
3761  ap(1,1,1) =
3762  Amm0(iii+1,jjj+1,kkk+1) * p( 0, 0,-1)
3763  + A0m0(iii+1,jjj+1,kkk+1) * p(+1, 0,-1)
3764  + Am00(iii+1,jjj+1,kkk+1) * p( 0,+1,-1)
3765  + A000(iii+1,jjj+1,kkk+1) * p(+1,+1,-1)
3766  + Ammp(iii+1,jjj+1,kkk+1) * p( 0, 0, 0)
3767  + A0mp(iii+1,jjj+1,kkk+1) * p(+1, 0, 0)
3768  + Am0p(iii+1,jjj+1,kkk+1) * p( 0,+1, 0)
3769  + A00p(iii+1,jjj+1,kkk+1) * p(+1,+1, 0);
3770  csten(i,j,k,ist_00p) = Real(0.125) *
3771  ( restrict_from_mm0_to(iii,jjj,kkk) * ap(-1,-1, 0)
3772  + restrict_from_0m0_to(iii,jjj,kkk) * ap( 0,-1, 0)
3773  + restrict_from_pm0_to(iii,jjj,kkk) * ap(+1,-1, 0)
3774  + restrict_from_m00_to(iii,jjj,kkk) * ap(-1, 0, 0)
3775  + restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
3776  + restrict_from_p00_to(iii,jjj,kkk) * ap(+1, 0, 0)
3777  + restrict_from_mp0_to(iii,jjj,kkk) * ap(-1,+1, 0)
3778  + restrict_from_0p0_to(iii,jjj,kkk) * ap( 0,+1, 0)
3779  + restrict_from_pp0_to(iii,jjj,kkk) * ap(+1,+1, 0)
3780  + restrict_from_mmp_to(iii,jjj,kkk) * ap(-1,-1,+1)
3781  + restrict_from_0mp_to(iii,jjj,kkk) * ap( 0,-1,+1)
3782  + restrict_from_pmp_to(iii,jjj,kkk) * ap(+1,-1,+1)
3783  + restrict_from_m0p_to(iii,jjj,kkk) * ap(-1, 0,+1)
3784  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1)
3785  + restrict_from_p0p_to(iii,jjj,kkk) * ap(+1, 0,+1)
3786  + restrict_from_mpp_to(iii,jjj,kkk) * ap(-1,+1,+1)
3787  + restrict_from_0pp_to(iii,jjj,kkk) * ap( 0,+1,+1)
3788  + restrict_from_ppp_to(iii,jjj,kkk) * ap(+1,+1,+1));
3789 
3790  // csten(i,j,k,ist_pp0)
3791  iii = ii;
3792  jjj = jj;
3793  kkk = kk;
3794  p(-1,-1,-1) = interp_from_ppp_to(iii+1,jjj+1,kkk-1);
3795  p( 0,-1,-1) = interp_from_0pp_to(iii+2,jjj+1,kkk-1);
3796  p(-1, 0,-1) = interp_from_p0p_to(iii+1,jjj+2,kkk-1);
3797  p( 0, 0,-1) = interp_from_00p_to(iii+2,jjj+2,kkk-1);
3798  p(-1,-1, 0) = interp_from_pp0_to(iii+1,jjj+1,kkk );
3799  p( 0,-1, 0) = interp_from_0p0_to(iii+2,jjj+1,kkk );
3800  p(-1, 0, 0) = interp_from_p00_to(iii+1,jjj+2,kkk );
3801  p( 0, 0, 0) = Real(1.);
3802  p(-1,-1,+1) = interp_from_ppm_to(iii+1,jjj+1,kkk+1);
3803  p( 0,-1,+1) = interp_from_0pm_to(iii+2,jjj+1,kkk+1);
3804  p(-1, 0,+1) = interp_from_p0m_to(iii+1,jjj+2,kkk+1);
3805  p( 0, 0,+1) = interp_from_00m_to(iii+2,jjj+2,kkk+1);
3806  ap(0,0,-1) =
3807  App0(iii,jjj,kkk-1) * p(-1,-1,-1)
3808  + Appp(iii,jjj,kkk-1) * p(-1,-1, 0);
3809  ap(1,0,-1) =
3810  A0p0(iii+1,jjj,kkk-1) * p(-1,-1,-1)
3811  + App0(iii+1,jjj,kkk-1) * p( 0,-1,-1)
3812  + A0pp(iii+1,jjj,kkk-1) * p(-1,-1, 0)
3813  + Appp(iii+1,jjj,kkk-1) * p( 0,-1, 0);
3814  ap(0,1,-1) =
3815  Ap00(iii,jjj+1,kkk-1) * p(-1,-1,-1)
3816  + App0(iii,jjj+1,kkk-1) * p(-1, 0,-1)
3817  + Ap0p(iii,jjj+1,kkk-1) * p(-1,-1, 0)
3818  + Appp(iii,jjj+1,kkk-1) * p(-1, 0, 0);
3819  ap(1,1,-1) =
3820  A000(iii+1,jjj+1,kkk-1) * p(-1,-1,-1)
3821  + Ap00(iii+1,jjj+1,kkk-1) * p( 0,-1,-1)
3822  + A0p0(iii+1,jjj+1,kkk-1) * p(-1, 0,-1)
3823  + App0(iii+1,jjj+1,kkk-1) * p( 0, 0,-1)
3824  + A00p(iii+1,jjj+1,kkk-1) * p(-1,-1, 0)
3825  + Ap0p(iii+1,jjj+1,kkk-1) * p( 0,-1, 0)
3826  + A0pp(iii+1,jjj+1,kkk-1) * p(-1, 0, 0)
3827  + Appp(iii+1,jjj+1,kkk-1) * p( 0, 0, 0);
3828  ap(0,0,0) =
3829  Appm(iii,jjj,kkk) * p(-1,-1,-1)
3830  + App0(iii,jjj,kkk) * p(-1,-1, 0)
3831  + Appp(iii,jjj,kkk) * p(-1,-1,+1);
3832  ap(1,0,0) =
3833  A0pm(iii+1,jjj,kkk) * p(-1,-1,-1)
3834  + Appm(iii+1,jjj,kkk) * p( 0,-1,-1)
3835  + A0p0(iii+1,jjj,kkk) * p(-1,-1, 0)
3836  + App0(iii+1,jjj,kkk) * p( 0,-1, 0)
3837  + A0pp(iii+1,jjj,kkk) * p(-1,-1,+1)
3838  + Appp(iii+1,jjj,kkk) * p( 0,-1,+1);
3839  ap(0,1,0) =
3840  Ap0m(iii,jjj+1,kkk) * p(-1,-1,-1)
3841  + Appm(iii,jjj+1,kkk) * p(-1, 0,-1)
3842  + Ap00(iii,jjj+1,kkk) * p(-1,-1, 0)
3843  + App0(iii,jjj+1,kkk) * p(-1, 0, 0)
3844  + Ap0p(iii,jjj+1,kkk) * p(-1,-1,+1)
3845  + Appp(iii,jjj+1,kkk) * p(-1, 0,+1);
3846  ap(1,1,0) =
3847  A00m(iii+1,jjj+1,kkk) * p(-1,-1,-1)
3848  + Ap0m(iii+1,jjj+1,kkk) * p( 0,-1,-1)
3849  + A0pm(iii+1,jjj+1,kkk) * p(-1, 0,-1)
3850  + Appm(iii+1,jjj+1,kkk) * p( 0, 0,-1)
3851  + A000(iii+1,jjj+1,kkk) * p(-1,-1, 0)
3852  + Ap00(iii+1,jjj+1,kkk) * p( 0,-1, 0)
3853  + A0p0(iii+1,jjj+1,kkk) * p(-1, 0, 0)
3854  + App0(iii+1,jjj+1,kkk) * p( 0, 0, 0)
3855  + A00p(iii+1,jjj+1,kkk) * p(-1,-1,+1)
3856  + Ap0p(iii+1,jjj+1,kkk) * p( 0,-1,+1)
3857  + A0pp(iii+1,jjj+1,kkk) * p(-1, 0,+1)
3858  + Appp(iii+1,jjj+1,kkk) * p( 0, 0,+1);
3859  ap(0,0,1) =
3860  Appm(iii,jjj,kkk+1) * p(-1,-1, 0)
3861  + App0(iii,jjj,kkk+1) * p(-1,-1,+1);
3862  ap(1,0,1) =
3863  A0pm(iii+1,jjj,kkk+1) * p(-1,-1, 0)
3864  + Appm(iii+1,jjj,kkk+1) * p( 0,-1, 0)
3865  + A0p0(iii+1,jjj,kkk+1) * p(-1,-1,+1)
3866  + App0(iii+1,jjj,kkk+1) * p( 0,-1,+1);
3867  ap(0,1,1) =
3868  Ap0m(iii,jjj+1,kkk+1) * p(-1,-1, 0)
3869  + Appm(iii,jjj+1,kkk+1) * p(-1, 0, 0)
3870  + Ap00(iii,jjj+1,kkk+1) * p(-1,-1,+1)
3871  + App0(iii,jjj+1,kkk+1) * p(-1, 0,+1);
3872  ap(1,1,1) =
3873  A00m(iii+1,jjj+1,kkk+1) * p(-1,-1, 0)
3874  + Ap0m(iii+1,jjj+1,kkk+1) * p( 0,-1, 0)
3875  + A0pm(iii+1,jjj+1,kkk+1) * p(-1, 0, 0)
3876  + Appm(iii+1,jjj+1,kkk+1) * p( 0, 0, 0)
3877  + A000(iii+1,jjj+1,kkk+1) * p(-1,-1,+1)
3878  + Ap00(iii+1,jjj+1,kkk+1) * p( 0,-1,+1)
3879  + A0p0(iii+1,jjj+1,kkk+1) * p(-1, 0,+1)
3880  + App0(iii+1,jjj+1,kkk+1) * p( 0, 0,+1);
3881  cs1 = Real(0.125) *
3882  ( restrict_from_00m_to(iii,jjj,kkk) * ap( 0, 0,-1)
3883  + restrict_from_p0m_to(iii,jjj,kkk) * ap(+1, 0,-1)
3884  + restrict_from_0pm_to(iii,jjj,kkk) * ap( 0,+1,-1)
3885  + restrict_from_ppm_to(iii,jjj,kkk) * ap(+1,+1,-1)
3886  + restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
3887  + restrict_from_p00_to(iii,jjj,kkk) * ap(+1, 0, 0)
3888  + restrict_from_0p0_to(iii,jjj,kkk) * ap( 0,+1, 0)
3889  + restrict_from_pp0_to(iii,jjj,kkk) * ap(+1,+1, 0)
3890  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1)
3891  + restrict_from_p0p_to(iii,jjj,kkk) * ap(+1, 0,+1)
3892  + restrict_from_0pp_to(iii,jjj,kkk) * ap( 0,+1,+1)
3893  + restrict_from_ppp_to(iii,jjj,kkk) * ap(+1,+1,+1));
3894 
3895  // alternative: csten(i+1,j,k,ist_mp0)
3896  iii = ii+2;
3897  jjj = jj;
3898  kkk = kk;
3899  p( 0,-1,-1) = interp_from_0pp_to(iii-2,jjj+1,kkk-1);
3900  p(+1,-1,-1) = interp_from_mpp_to(iii-1,jjj+1,kkk-1);
3901  p( 0, 0,-1) = interp_from_00p_to(iii-2,jjj+2,kkk-1);
3902  p(+1, 0,-1) = interp_from_m0p_to(iii-1,jjj+2,kkk-1);
3903  p( 0,-1, 0) = interp_from_0p0_to(iii-2,jjj+1,kkk );
3904  p(+1,-1, 0) = interp_from_mp0_to(iii-1,jjj+1,kkk );
3905  p( 0, 0, 0) = Real(1.);
3906  p(+1, 0, 0) = interp_from_m00_to(iii-1,jjj+2,kkk );
3907  p( 0,-1,+1) = interp_from_0pm_to(iii-2,jjj+1,kkk+1);
3908  p(+1,-1,+1) = interp_from_mpm_to(iii-1,jjj+1,kkk+1);
3909  p( 0, 0,+1) = interp_from_00m_to(iii-2,jjj+2,kkk+1);
3910  p(+1, 0,+1) = interp_from_m0m_to(iii-1,jjj+2,kkk+1);
3911  ap(-1,0,-1) =
3912  Amp0(iii-1,jjj,kkk-1) * p( 0,-1,-1)
3913  + A0p0(iii-1,jjj,kkk-1) * p(+1,-1,-1)
3914  + Ampp(iii-1,jjj,kkk-1) * p( 0,-1, 0)
3915  + A0pp(iii-1,jjj,kkk-1) * p(+1,-1, 0);
3916  ap(0,0,-1) =
3917  Amp0(iii,jjj,kkk-1) * p(+1,-1,-1)
3918  + Ampp(iii,jjj,kkk-1) * p(+1,-1, 0);
3919  ap(-1,1,-1) =
3920  Am00(iii-1,jjj+1,kkk-1) * p( 0,-1,-1)
3921  + A000(iii-1,jjj+1,kkk-1) * p(+1,-1,-1)
3922  + Amp0(iii-1,jjj+1,kkk-1) * p( 0, 0,-1)
3923  + A0p0(iii-1,jjj+1,kkk-1) * p(+1, 0,-1)
3924  + Am0p(iii-1,jjj+1,kkk-1) * p( 0,-1, 0)
3925  + A00p(iii-1,jjj+1,kkk-1) * p(+1,-1, 0)
3926  + Ampp(iii-1,jjj+1,kkk-1) * p( 0, 0, 0)
3927  + A0pp(iii-1,jjj+1,kkk-1) * p(+1, 0, 0);
3928  ap(0,1,-1) =
3929  Am00(iii,jjj+1,kkk-1) * p(+1,-1,-1)
3930  + Amp0(iii,jjj+1,kkk-1) * p(+1, 0,-1)
3931  + Am0p(iii,jjj+1,kkk-1) * p(+1,-1, 0)
3932  + Ampp(iii,jjj+1,kkk-1) * p(+1, 0, 0);
3933  ap(-1,0,0) =
3934  Ampm(iii-1,jjj,kkk) * p( 0,-1,-1)
3935  + A0pm(iii-1,jjj,kkk) * p(+1,-1,-1)
3936  + Amp0(iii-1,jjj,kkk) * p( 0,-1, 0)
3937  + A0p0(iii-1,jjj,kkk) * p(+1,-1, 0)
3938  + Ampp(iii-1,jjj,kkk) * p( 0,-1,+1)
3939  + A0pp(iii-1,jjj,kkk) * p(+1,-1,+1);
3940  ap(0,0,0) =
3941  Ampm(iii,jjj,kkk) * p(+1,-1,-1)
3942  + Amp0(iii,jjj,kkk) * p(+1,-1, 0)
3943  + Ampp(iii,jjj,kkk) * p(+1,-1,+1);
3944  ap(-1,1,0) =
3945  Am0m(iii-1,jjj+1,kkk) * p( 0,-1,-1)
3946  + A00m(iii-1,jjj+1,kkk) * p(+1,-1,-1)
3947  + Ampm(iii-1,jjj+1,kkk) * p( 0, 0,-1)
3948  + A0pm(iii-1,jjj+1,kkk) * p(+1, 0,-1)
3949  + Am00(iii-1,jjj+1,kkk) * p( 0,-1, 0)
3950  + A000(iii-1,jjj+1,kkk) * p(+1,-1, 0)
3951  + Amp0(iii-1,jjj+1,kkk) * p( 0, 0, 0)
3952  + A0p0(iii-1,jjj+1,kkk) * p(+1, 0, 0)
3953  + Am0p(iii-1,jjj+1,kkk) * p( 0,-1,+1)
3954  + A00p(iii-1,jjj+1,kkk) * p(+1,-1,+1)
3955  + Ampp(iii-1,jjj+1,kkk) * p( 0, 0,+1)
3956  + A0pp(iii-1,jjj+1,kkk) * p(+1, 0,+1);
3957  ap(0,1,0) =
3958  Am0m(iii,jjj+1,kkk) * p(+1,-1,-1)
3959  + Ampm(iii,jjj+1,kkk) * p(+1, 0,-1)
3960  + Am00(iii,jjj+1,kkk) * p(+1,-1, 0)
3961  + Amp0(iii,jjj+1,kkk) * p(+1, 0, 0)
3962  + Am0p(iii,jjj+1,kkk) * p(+1,-1,+1)
3963  + Ampp(iii,jjj+1,kkk) * p(+1, 0,+1);
3964  ap(-1,0,1) =
3965  Ampm(iii-1,jjj,kkk+1) * p( 0,-1, 0)
3966  + A0pm(iii-1,jjj,kkk+1) * p(+1,-1, 0)
3967  + Amp0(iii-1,jjj,kkk+1) * p( 0,-1,+1)
3968  + A0p0(iii-1,jjj,kkk+1) * p(+1,-1,+1);
3969  ap(0,0,1) =
3970  Ampm(iii,jjj,kkk+1) * p(+1,-1, 0)
3971  + Amp0(iii,jjj,kkk+1) * p(+1,-1,+1);
3972  ap(-1,1,1) =
3973  Am0m(iii-1,jjj+1,kkk+1) * p( 0,-1, 0)
3974  + A00m(iii-1,jjj+1,kkk+1) * p(+1,-1, 0)
3975  + Ampm(iii-1,jjj+1,kkk+1) * p( 0, 0, 0)
3976  + A0pm(iii-1,jjj+1,kkk+1) * p(+1, 0, 0)
3977  + Am00(iii-1,jjj+1,kkk+1) * p( 0,-1,+1)
3978  + A000(iii-1,jjj+1,kkk+1) * p(+1,-1,+1)
3979  + Amp0(iii-1,jjj+1,kkk+1) * p( 0, 0,+1)
3980  + A0p0(iii-1,jjj+1,kkk+1) * p(+1, 0,+1);
3981  ap(0,1,1) =
3982  Am0m(iii,jjj+1,kkk+1) * p(+1,-1, 0)
3983  + Ampm(iii,jjj+1,kkk+1) * p(+1, 0, 0)
3984  + Am00(iii,jjj+1,kkk+1) * p(+1,-1,+1)
3985  + Amp0(iii,jjj+1,kkk+1) * p(+1, 0,+1);
3986  cs2 = Real(0.125) *
3987  ( restrict_from_m0m_to(iii,jjj,kkk) * ap(-1, 0,-1)
3988  + restrict_from_00m_to(iii,jjj,kkk) * ap( 0, 0,-1)
3989  + restrict_from_mpm_to(iii,jjj,kkk) * ap(-1,+1,-1)
3990  + restrict_from_0pm_to(iii,jjj,kkk) * ap( 0,+1,-1)
3991  + restrict_from_m00_to(iii,jjj,kkk) * ap(-1, 0, 0)
3992  + restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
3993  + restrict_from_mp0_to(iii,jjj,kkk) * ap(-1,+1, 0)
3994  + restrict_from_0p0_to(iii,jjj,kkk) * ap( 0,+1, 0)
3995  + restrict_from_m0p_to(iii,jjj,kkk) * ap(-1, 0,+1)
3996  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1)
3997  + restrict_from_mpp_to(iii,jjj,kkk) * ap(-1,+1,+1)
3998  + restrict_from_0pp_to(iii,jjj,kkk) * ap( 0,+1,+1));
3999 
4000  csten(i,j,k,ist_pp0) = Real(0.5)*(cs1 + cs2);
4001 
4002  // csten(i,j,k,ist_p0p)
4003  iii = ii;
4004  jjj = jj;
4005  kkk = kk;
4006  p(-1,-1,-1) = interp_from_ppp_to(iii+1,jjj-1,kkk+1);
4007  p( 0,-1,-1) = interp_from_0pp_to(iii+2,jjj-1,kkk+1);
4008  p(-1, 0,-1) = interp_from_p0p_to(iii+1,jjj ,kkk+1);
4009  p( 0, 0,-1) = interp_from_00p_to(iii+2,jjj ,kkk+1);
4010  p(-1,+1,-1) = interp_from_pmp_to(iii+1,jjj+1,kkk+1);
4011  p( 0,+1,-1) = interp_from_0mp_to(iii+2,jjj+1,kkk+1);
4012  p(-1,-1, 0) = interp_from_pp0_to(iii+1,jjj-1,kkk+2);
4013  p( 0,-1, 0) = interp_from_0p0_to(iii+2,jjj-1,kkk+2);
4014  p(-1, 0, 0) = interp_from_p00_to(iii+1,jjj ,kkk+2);
4015  p( 0, 0, 0) = Real(1.);
4016  p(-1,+1, 0) = interp_from_pm0_to(iii+1,jjj+1,kkk+2);
4017  p( 0,+1, 0) = interp_from_0m0_to(iii+2,jjj+1,kkk+2);
4018  ap(0,-1,0) =
4019  Ap0p(iii,jjj-1,kkk) * p(-1,-1,-1)
4020  + Appp(iii,jjj-1,kkk) * p(-1, 0,-1);
4021  ap(1,-1,0) =
4022  A00p(iii+1,jjj-1,kkk) * p(-1,-1,-1)
4023  + Ap0p(iii+1,jjj-1,kkk) * p( 0,-1,-1)
4024  + A0pp(iii+1,jjj-1,kkk) * p(-1, 0,-1)
4025  + Appp(iii+1,jjj-1,kkk) * p( 0, 0,-1);
4026  ap(0,0,0) =
4027  Apmp(iii,jjj,kkk) * p(-1,-1,-1)
4028  + Ap0p(iii,jjj,kkk) * p(-1, 0,-1)
4029  + Appp(iii,jjj,kkk) * p(-1,+1,-1);
4030  ap(1,0,0) =
4031  A0mp(iii+1,jjj,kkk) * p(-1,-1,-1)
4032  + Apmp(iii+1,jjj,kkk) * p( 0,-1,-1)
4033  + A00p(iii+1,jjj,kkk) * p(-1, 0,-1)
4034  + Ap0p(iii+1,jjj,kkk) * p( 0, 0,-1)
4035  + A0pp(iii+1,jjj,kkk) * p(-1,+1,-1)
4036  + Appp(iii+1,jjj,kkk) * p( 0,+1,-1);
4037  ap(0,1,0) =
4038  Apmp(iii,jjj+1,kkk) * p(-1, 0,-1)
4039  + Ap0p(iii,jjj+1,kkk) * p(-1,+1,-1);
4040  ap(1,1,0) =
4041  A0mp(iii+1,jjj+1,kkk) * p(-1, 0,-1)
4042  + Apmp(iii+1,jjj+1,kkk) * p( 0, 0,-1)
4043  + A00p(iii+1,jjj+1,kkk) * p(-1,+1,-1)
4044  + Ap0p(iii+1,jjj+1,kkk) * p( 0,+1,-1);
4045  ap(0,-1,1) =
4046  Ap00(iii,jjj-1,kkk+1) * p(-1,-1,-1)
4047  + App0(iii,jjj-1,kkk+1) * p(-1, 0,-1)
4048  + Ap0p(iii,jjj-1,kkk+1) * p(-1,-1, 0)
4049  + Appp(iii,jjj-1,kkk+1) * p(-1, 0, 0);
4050  ap(1,-1,1) =
4051  A000(iii+1,jjj-1,kkk+1) * p(-1,-1,-1)
4052  + Ap00(iii+1,jjj-1,kkk+1) * p( 0,-1,-1)
4053  + A0p0(iii+1,jjj-1,kkk+1) * p(-1, 0,-1)
4054  + App0(iii+1,jjj-1,kkk+1) * p( 0, 0,-1)
4055  + A00p(iii+1,jjj-1,kkk+1) * p(-1,-1, 0)
4056  + Ap0p(iii+1,jjj-1,kkk+1) * p( 0,-1, 0)
4057  + A0pp(iii+1,jjj-1,kkk+1) * p(-1, 0, 0)
4058  + Appp(iii+1,jjj-1,kkk+1) * p( 0, 0, 0);
4059  ap(0,0,1) =
4060  Apm0(iii,jjj,kkk+1) * p(-1,-1,-1)
4061  + Ap00(iii,jjj,kkk+1) * p(-1, 0,-1)
4062  + App0(iii,jjj,kkk+1) * p(-1,+1,-1)
4063  + Apmp(iii,jjj,kkk+1) * p(-1,-1, 0)
4064  + Ap0p(iii,jjj,kkk+1) * p(-1, 0, 0)
4065  + Appp(iii,jjj,kkk+1) * p(-1,+1, 0);
4066  ap(1,0,1) =
4067  A0m0(iii+1,jjj,kkk+1) * p(-1,-1,-1)
4068  + Apm0(iii+1,jjj,kkk+1) * p( 0,-1,-1)
4069  + A000(iii+1,jjj,kkk+1) * p(-1, 0,-1)
4070  + Ap00(iii+1,jjj,kkk+1) * p( 0, 0,-1)
4071  + A0p0(iii+1,jjj,kkk+1) * p(-1,+1,-1)
4072  + App0(iii+1,jjj,kkk+1) * p( 0,+1,-1)
4073  + A0mp(iii+1,jjj,kkk+1) * p(-1,-1, 0)
4074  + Apmp(iii+1,jjj,kkk+1) * p( 0,-1, 0)
4075  + A00p(iii+1,jjj,kkk+1) * p(-1, 0, 0)
4076  + Ap0p(iii+1,jjj,kkk+1) * p( 0, 0, 0)
4077  + A0pp(iii+1,jjj,kkk+1) * p(-1,+1, 0)
4078  + Appp(iii+1,jjj,kkk+1) * p( 0,+1, 0);
4079  ap(0,1,1) =
4080  Apm0(iii,jjj+1,kkk+1) * p(-1, 0,-1)
4081  + Ap00(iii,jjj+1,kkk+1) * p(-1,+1,-1)
4082  + Apmp(iii,jjj+1,kkk+1) * p(-1, 0, 0)
4083  + Ap0p(iii,jjj+1,kkk+1) * p(-1,+1, 0);
4084  ap(1,1,1) =
4085  A0m0(iii+1,jjj+1,kkk+1) * p(-1, 0,-1)
4086  + Apm0(iii+1,jjj+1,kkk+1) * p( 0, 0,-1)
4087  + A000(iii+1,jjj+1,kkk+1) * p(-1,+1,-1)
4088  + Ap00(iii+1,jjj+1,kkk+1) * p( 0,+1,-1)
4089  + A0mp(iii+1,jjj+1,kkk+1) * p(-1, 0, 0)
4090  + Apmp(iii+1,jjj+1,kkk+1) * p( 0, 0, 0)
4091  + A00p(iii+1,jjj+1,kkk+1) * p(-1,+1, 0)
4092  + Ap0p(iii+1,jjj+1,kkk+1) * p( 0,+1, 0);
4093  cs1 = Real(0.125) *
4094  ( restrict_from_0m0_to(iii,jjj,kkk) * ap( 0,-1, 0)
4095  + restrict_from_pm0_to(iii,jjj,kkk) * ap(+1,-1, 0)
4096  + restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
4097  + restrict_from_p00_to(iii,jjj,kkk) * ap(+1, 0, 0)
4098  + restrict_from_0p0_to(iii,jjj,kkk) * ap( 0,+1, 0)
4099  + restrict_from_pp0_to(iii,jjj,kkk) * ap(+1,+1, 0)
4100  + restrict_from_0mp_to(iii,jjj,kkk) * ap( 0,-1,+1)
4101  + restrict_from_pmp_to(iii,jjj,kkk) * ap(+1,-1,+1)
4102  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1)
4103  + restrict_from_p0p_to(iii,jjj,kkk) * ap(+1, 0,+1)
4104  + restrict_from_0pp_to(iii,jjj,kkk) * ap( 0,+1,+1)
4105  + restrict_from_ppp_to(iii,jjj,kkk) * ap(+1,+1,+1));
4106 
4107  // alternative: csten(i+1,j,k,ist_m0p)
4108  iii = ii+2;
4109  jjj = jj;
4110  kkk = kk;
4111  p( 0,-1,-1) = interp_from_0pp_to(iii-2,jjj-1,kkk+1);
4112  p(+1,-1,-1) = interp_from_mpp_to(iii-1,jjj-1,kkk+1);
4113  p( 0, 0,-1) = interp_from_00p_to(iii-2,jjj ,kkk+1);
4114  p(+1, 0,-1) = interp_from_m0p_to(iii-1,jjj ,kkk+1);
4115  p( 0,+1,-1) = interp_from_0mp_to(iii-2,jjj+1,kkk+1);
4116  p(+1,+1,-1) = interp_from_mmp_to(iii-1,jjj+1,kkk+1);
4117  p( 0,-1, 0) = interp_from_0p0_to(iii-2,jjj-1,kkk+2);
4118  p(+1,-1, 0) = interp_from_mp0_to(iii-1,jjj-1,kkk+2);
4119  p( 0, 0, 0) = Real(1.);
4120  p(+1, 0, 0) = interp_from_m00_to(iii-1,jjj ,kkk+2);
4121  p( 0,+1, 0) = interp_from_0m0_to(iii-2,jjj+1,kkk+2);
4122  p(+1,+1, 0) = interp_from_mm0_to(iii-1,jjj+1,kkk+2);
4123 
4124  ap(-1,-1,0) =
4125  Am0p(iii-1,jjj-1,kkk) * p( 0,-1,-1)
4126  + A00p(iii-1,jjj-1,kkk) * p(+1,-1,-1)
4127  + Ampp(iii-1,jjj-1,kkk) * p( 0, 0,-1)
4128  + A0pp(iii-1,jjj-1,kkk) * p(+1, 0,-1);
4129  ap(0,-1,0) =
4130  Am0p(iii,jjj-1,kkk) * p(+1,-1,-1)
4131  + Ampp(iii,jjj-1,kkk) * p(+1, 0,-1);
4132  ap(-1,0,0) =
4133  Ammp(iii-1,jjj,kkk) * p( 0,-1,-1)
4134  + A0mp(iii-1,jjj,kkk) * p(+1,-1,-1)
4135  + Am0p(iii-1,jjj,kkk) * p( 0, 0,-1)
4136  + A00p(iii-1,jjj,kkk) * p(+1, 0,-1)
4137  + Ampp(iii-1,jjj,kkk) * p( 0,+1,-1)
4138  + A0pp(iii-1,jjj,kkk) * p(+1,+1,-1);
4139  ap(0,0,0) =
4140  Ammp(iii,jjj,kkk) * p(+1,-1,-1)
4141  + Am0p(iii,jjj,kkk) * p(+1, 0,-1)
4142  + Ampp(iii,jjj,kkk) * p(+1,+1,-1);
4143  ap(-1,1,0) =
4144  Ammp(iii-1,jjj+1,kkk) * p( 0, 0,-1)
4145  + A0mp(iii-1,jjj+1,kkk) * p(+1, 0,-1)
4146  + Am0p(iii-1,jjj+1,kkk) * p( 0,+1,-1)
4147  + A00p(iii-1,jjj+1,kkk) * p(+1,+1,-1);
4148  ap(0,1,0) =
4149  Ammp(iii,jjj+1,kkk) * p(+1, 0,-1)
4150  + Am0p(iii,jjj+1,kkk) * p(+1,+1,-1);
4151  ap(-1,-1,1) =
4152  Am00(iii-1,jjj-1,kkk+1) * p( 0,-1,-1)
4153  + A000(iii-1,jjj-1,kkk+1) * p(+1,-1,-1)
4154  + Amp0(iii-1,jjj-1,kkk+1) * p( 0, 0,-1)
4155  + A0p0(iii-1,jjj-1,kkk+1) * p(+1, 0,-1)
4156  + Am0p(iii-1,jjj-1,kkk+1) * p( 0,-1, 0)
4157  + A00p(iii-1,jjj-1,kkk+1) * p(+1,-1, 0)
4158  + Ampp(iii-1,jjj-1,kkk+1) * p( 0, 0, 0)
4159  + A0pp(iii-1,jjj-1,kkk+1) * p(+1, 0, 0);
4160  ap(0,-1,1) =
4161  Am00(iii,jjj-1,kkk+1) * p(+1,-1,-1)
4162  + Amp0(iii,jjj-1,kkk+1) * p(+1, 0,-1)
4163  + Am0p(iii,jjj-1,kkk+1) * p(+1,-1, 0)
4164  + Ampp(iii,jjj-1,kkk+1) * p(+1, 0, 0);
4165  ap(-1,0,1) =
4166  Amm0(iii-1,jjj,kkk+1) * p( 0,-1,-1)
4167  + A0m0(iii-1,jjj,kkk+1) * p(+1,-1,-1)
4168  + Am00(iii-1,jjj,kkk+1) * p( 0, 0,-1)
4169  + A000(iii-1,jjj,kkk+1) * p(+1, 0,-1)
4170  + Amp0(iii-1,jjj,kkk+1) * p( 0,+1,-1)
4171  + A0p0(iii-1,jjj,kkk+1) * p(+1,+1,-1)
4172  + Ammp(iii-1,jjj,kkk+1) * p( 0,-1, 0)
4173  + A0mp(iii-1,jjj,kkk+1) * p(+1,-1, 0)
4174  + Am0p(iii-1,jjj,kkk+1) * p( 0, 0, 0)
4175  + A00p(iii-1,jjj,kkk+1) * p(+1, 0, 0)
4176  + Ampp(iii-1,jjj,kkk+1) * p( 0,+1, 0)
4177  + A0pp(iii-1,jjj,kkk+1) * p(+1,+1, 0);
4178  ap(0,0,1) =
4179  Amm0(iii,jjj,kkk+1) * p(+1,-1,-1)
4180  + Am00(iii,jjj,kkk+1) * p(+1, 0,-1)
4181  + Amp0(iii,jjj,kkk+1) * p(+1,+1,-1)
4182  + Ammp(iii,jjj,kkk+1) * p(+1,-1, 0)
4183  + Am0p(iii,jjj,kkk+1) * p(+1, 0, 0)
4184  + Ampp(iii,jjj,kkk+1) * p(+1,+1, 0);
4185  ap(-1,1,1) =
4186  Amm0(iii-1,jjj+1,kkk+1) * p( 0, 0,-1)
4187  + A0m0(iii-1,jjj+1,kkk+1) * p(+1, 0,-1)
4188  + Am00(iii-1,jjj+1,kkk+1) * p( 0,+1,-1)
4189  + A000(iii-1,jjj+1,kkk+1) * p(+1,+1,-1)
4190  + Ammp(iii-1,jjj+1,kkk+1) * p( 0, 0, 0)
4191  + A0mp(iii-1,jjj+1,kkk+1) * p(+1, 0, 0)
4192  + Am0p(iii-1,jjj+1,kkk+1) * p( 0,+1, 0)
4193  + A00p(iii-1,jjj+1,kkk+1) * p(+1,+1, 0);
4194  ap(0,1,1) =
4195  Amm0(iii,jjj+1,kkk+1) * p(+1, 0,-1)
4196  + Am00(iii,jjj+1,kkk+1) * p(+1,+1,-1)
4197  + Ammp(iii,jjj+1,kkk+1) * p(+1, 0, 0)
4198  + Am0p(iii,jjj+1,kkk+1) * p(+1,+1, 0);
4199  cs2 = Real(0.125) *
4200  ( restrict_from_mm0_to(iii,jjj,kkk) * ap(-1,-1, 0)
4201  + restrict_from_0m0_to(iii,jjj,kkk) * ap( 0,-1, 0)
4202  + restrict_from_m00_to(iii,jjj,kkk) * ap(-1, 0, 0)
4203  + restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
4204  + restrict_from_mp0_to(iii,jjj,kkk) * ap(-1,+1, 0)
4205  + restrict_from_0p0_to(iii,jjj,kkk) * ap( 0,+1, 0)
4206  + restrict_from_mmp_to(iii,jjj,kkk) * ap(-1,-1,+1)
4207  + restrict_from_0mp_to(iii,jjj,kkk) * ap( 0,-1,+1)
4208  + restrict_from_m0p_to(iii,jjj,kkk) * ap(-1, 0,+1)
4209  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1)
4210  + restrict_from_mpp_to(iii,jjj,kkk) * ap(-1,+1,+1)
4211  + restrict_from_0pp_to(iii,jjj,kkk) * ap( 0,+1,+1));
4212 
4213  csten(i,j,k,ist_p0p) = Real(0.5)*(cs1+cs2);
4214 
4215  // csten(i,j,k,ist_0pp)
4216  iii = ii;
4217  jjj = jj;
4218  kkk = kk;
4219  p(-1,-1,-1) = interp_from_ppp_to(iii-1,jjj+1,kkk+1);
4220  p( 0,-1,-1) = interp_from_0pp_to(iii ,jjj+1,kkk+1);
4221  p(+1,-1,-1) = interp_from_mpp_to(iii+1,jjj+1,kkk+1);
4222  p(-1, 0,-1) = interp_from_p0p_to(iii-1,jjj+2,kkk+1);
4223  p( 0, 0,-1) = interp_from_00p_to(iii ,jjj+2,kkk+1);
4224  p(+1, 0,-1) = interp_from_m0p_to(iii+1,jjj+2,kkk+1);
4225  p(-1,-1, 0) = interp_from_pp0_to(iii-1,jjj+1,kkk+2);
4226  p( 0,-1, 0) = interp_from_0p0_to(iii ,jjj+1,kkk+2);
4227  p(+1,-1, 0) = interp_from_mp0_to(iii+1,jjj+1,kkk+2);
4228  p(-1, 0, 0) = interp_from_p00_to(iii-1,jjj+2,kkk+2);
4229  p( 0, 0, 0) = Real(1.);
4230  p(+1, 0, 0) = interp_from_m00_to(iii+1,jjj+2,kkk+2);
4231  ap(-1,0,0) =
4232  A0pp(iii-1,jjj,kkk) * p(-1,-1,-1)
4233  + Appp(iii-1,jjj,kkk) * p( 0,-1,-1);
4234  ap(0,0,0) =
4235  Ampp(iii,jjj,kkk) * p(-1,-1,-1)
4236  + A0pp(iii,jjj,kkk) * p( 0,-1,-1)
4237  + Appp(iii,jjj,kkk) * p(+1,-1,-1);
4238  ap(1,0,0) =
4239  Ampp(iii+1,jjj,kkk) * p( 0,-1,-1)
4240  + A0pp(iii+1,jjj,kkk) * p(+1,-1,-1);
4241  ap(-1,1,0) =
4242  A00p(iii-1,jjj+1,kkk) * p(-1,-1,-1)
4243  + Ap0p(iii-1,jjj+1,kkk) * p( 0,-1,-1)
4244  + A0pp(iii-1,jjj+1,kkk) * p(-1, 0,-1)
4245  + Appp(iii-1,jjj+1,kkk) * p( 0, 0,-1);
4246  ap(0,1,0) =
4247  Am0p(iii,jjj+1,kkk) * p(-1,-1,-1)
4248  + A00p(iii,jjj+1,kkk) * p( 0,-1,-1)
4249  + Ap0p(iii,jjj+1,kkk) * p(+1,-1,-1)
4250  + Ampp(iii,jjj+1,kkk) * p(-1, 0,-1)
4251  + A0pp(iii,jjj+1,kkk) * p( 0, 0,-1)
4252  + Appp(iii,jjj+1,kkk) * p(+1, 0,-1);
4253  ap(1,1,0) =
4254  Am0p(iii+1,jjj+1,kkk) * p( 0,-1,-1)
4255  + A00p(iii+1,jjj+1,kkk) * p(+1,-1,-1)
4256  + Ampp(iii+1,jjj+1,kkk) * p( 0, 0,-1)
4257  + A0pp(iii+1,jjj+1,kkk) * p(+1, 0,-1);
4258  ap(-1,0,1) =
4259  A0p0(iii-1,jjj,kkk+1) * p(-1,-1,-1)
4260  + App0(iii-1,jjj,kkk+1) * p( 0,-1,-1)
4261  + A0pp(iii-1,jjj,kkk+1) * p(-1,-1, 0)
4262  + Appp(iii-1,jjj,kkk+1) * p( 0,-1, 0);
4263  ap(0,0,1) =
4264  Amp0(iii,jjj,kkk+1) * p(-1,-1,-1)
4265  + A0p0(iii,jjj,kkk+1) * p( 0,-1,-1)
4266  + App0(iii,jjj,kkk+1) * p(+1,-1,-1)
4267  + Ampp(iii,jjj,kkk+1) * p(-1,-1, 0)
4268  + A0pp(iii,jjj,kkk+1) * p( 0,-1, 0)
4269  + Appp(iii,jjj,kkk+1) * p(+1,-1, 0);
4270  ap(1,0,1) =
4271  Amp0(iii+1,jjj,kkk+1) * p( 0,-1,-1)
4272  + A0p0(iii+1,jjj,kkk+1) * p(+1,-1,-1)
4273  + Ampp(iii+1,jjj,kkk+1) * p( 0,-1, 0)
4274  + A0pp(iii+1,jjj,kkk+1) * p(+1,-1, 0);
4275  ap(-1,1,1) =
4276  A000(iii-1,jjj+1,kkk+1) * p(-1,-1,-1)
4277  + Ap00(iii-1,jjj+1,kkk+1) * p( 0,-1,-1)
4278  + A0p0(iii-1,jjj+1,kkk+1) * p(-1, 0,-1)
4279  + App0(iii-1,jjj+1,kkk+1) * p( 0, 0,-1)
4280  + A00p(iii-1,jjj+1,kkk+1) * p(-1,-1, 0)
4281  + Ap0p(iii-1,jjj+1,kkk+1) * p( 0,-1, 0)
4282  + A0pp(iii-1,jjj+1,kkk+1) * p(-1, 0, 0)
4283  + Appp(iii-1,jjj+1,kkk+1) * p( 0, 0, 0);
4284  ap(0,1,1) =
4285  Am00(iii,jjj+1,kkk+1) * p(-1,-1,-1)
4286  + A000(iii,jjj+1,kkk+1) * p( 0,-1,-1)
4287  + Ap00(iii,jjj+1,kkk+1) * p(+1,-1,-1)
4288  + Amp0(iii,jjj+1,kkk+1) * p(-1, 0,-1)
4289  + A0p0(iii,jjj+1,kkk+1) * p( 0, 0,-1)
4290  + App0(iii,jjj+1,kkk+1) * p(+1, 0,-1)
4291  + Am0p(iii,jjj+1,kkk+1) * p(-1,-1, 0)
4292  + A00p(iii,jjj+1,kkk+1) * p( 0,-1, 0)
4293  + Ap0p(iii,jjj+1,kkk+1) * p(+1,-1, 0)
4294  + Ampp(iii,jjj+1,kkk+1) * p(-1, 0, 0)
4295  + A0pp(iii,jjj+1,kkk+1) * p( 0, 0, 0)
4296  + Appp(iii,jjj+1,kkk+1) * p(+1, 0, 0);
4297  ap(1,1,1) =
4298  Am00(iii+1,jjj+1,kkk+1) * p( 0,-1,-1)
4299  + A000(iii+1,jjj+1,kkk+1) * p(+1,-1,-1)
4300  + Amp0(iii+1,jjj+1,kkk+1) * p( 0, 0,-1)
4301  + A0p0(iii+1,jjj+1,kkk+1) * p(+1, 0,-1)
4302  + Am0p(iii+1,jjj+1,kkk+1) * p( 0,-1, 0)
4303  + A00p(iii+1,jjj+1,kkk+1) * p(+1,-1, 0)
4304  + Ampp(iii+1,jjj+1,kkk+1) * p( 0, 0, 0)
4305  + A0pp(iii+1,jjj+1,kkk+1) * p(+1, 0, 0);
4306  cs1 = Real(0.125) *
4307  ( restrict_from_m00_to(iii,jjj,kkk) * ap(-1, 0, 0)
4308  + restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
4309  + restrict_from_p00_to(iii,jjj,kkk) * ap(+1, 0, 0)
4310  + restrict_from_mp0_to(iii,jjj,kkk) * ap(-1,+1, 0)
4311  + restrict_from_0p0_to(iii,jjj,kkk) * ap( 0,+1, 0)
4312  + restrict_from_pp0_to(iii,jjj,kkk) * ap(+1,+1, 0)
4313  + restrict_from_m0p_to(iii,jjj,kkk) * ap(-1, 0,+1)
4314  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1)
4315  + restrict_from_p0p_to(iii,jjj,kkk) * ap(+1, 0,+1)
4316  + restrict_from_mpp_to(iii,jjj,kkk) * ap(-1,+1,+1)
4317  + restrict_from_0pp_to(iii,jjj,kkk) * ap( 0,+1,+1)
4318  + restrict_from_ppp_to(iii,jjj,kkk) * ap(+1,+1,+1));
4319 
4320  // alternative: csten(i,j+1,k,ist_0mp)
4321  iii = ii;
4322  jjj = jj+2;
4323  kkk = kk;
4324  p(-1, 0,-1) = interp_from_p0p_to(iii-1,jjj-2,kkk+1);
4325  p( 0, 0,-1) = interp_from_00p_to(iii ,jjj-2,kkk+1);
4326  p(+1, 0,-1) = interp_from_m0p_to(iii+1,jjj-2,kkk+1);
4327  p(-1,+1,-1) = interp_from_pmp_to(iii-1,jjj-1,kkk+1);
4328  p( 0,+1,-1) = interp_from_0mp_to(iii ,jjj-1,kkk+1);
4329  p(+1,+1,-1) = interp_from_mmp_to(iii+1,jjj-1,kkk+1);
4330  p(-1, 0, 0) = interp_from_p00_to(iii-1,jjj-2,kkk+2);
4331  p( 0, 0, 0) = Real(1.);
4332  p(+1, 0, 0) = interp_from_m00_to(iii+1,jjj-2,kkk+2);
4333  p(-1,+1, 0) = interp_from_pm0_to(iii-1,jjj-1,kkk+2);
4334  p( 0,+1, 0) = interp_from_0m0_to(iii ,jjj-1,kkk+2);
4335  p(+1,+1, 0) = interp_from_mm0_to(iii+1,jjj-1,kkk+2);
4336  ap(-1,-1,0) =
4337  A0mp(iii-1,jjj-1,kkk) * p(-1, 0,-1)
4338  + Apmp(iii-1,jjj-1,kkk) * p( 0, 0,-1)
4339  + A00p(iii-1,jjj-1,kkk) * p(-1,+1,-1)
4340  + Ap0p(iii-1,jjj-1,kkk) * p( 0,+1,-1);
4341  ap(0,-1,0) =
4342  Ammp(iii,jjj-1,kkk) * p(-1, 0,-1)
4343  + A0mp(iii,jjj-1,kkk) * p( 0, 0,-1)
4344  + Apmp(iii,jjj-1,kkk) * p(+1, 0,-1)
4345  + Am0p(iii,jjj-1,kkk) * p(-1,+1,-1)
4346  + A00p(iii,jjj-1,kkk) * p( 0,+1,-1)
4347  + Ap0p(iii,jjj-1,kkk) * p(+1,+1,-1);
4348  ap(1,-1,0) =
4349  Ammp(iii+1,jjj-1,kkk) * p( 0, 0,-1)
4350  + A0mp(iii+1,jjj-1,kkk) * p(+1, 0,-1)
4351  + Am0p(iii+1,jjj-1,kkk) * p( 0,+1,-1)
4352  + A00p(iii+1,jjj-1,kkk) * p(+1,+1,-1);
4353  ap(-1,0,0) =
4354  A0mp(iii-1,jjj,kkk) * p(-1,+1,-1)
4355  + Apmp(iii-1,jjj,kkk) * p( 0,+1,-1);
4356  ap(0,0,0) =
4357  Ammp(iii,jjj,kkk) * p(-1,+1,-1)
4358  + A0mp(iii,jjj,kkk) * p( 0,+1,-1)
4359  + Apmp(iii,jjj,kkk) * p(+1,+1,-1);
4360  ap(1,0,0) =
4361  Ammp(iii+1,jjj,kkk) * p( 0,+1,-1)
4362  + A0mp(iii+1,jjj,kkk) * p(+1,+1,-1);
4363  ap(-1,-1,1) =
4364  A0m0(iii-1,jjj-1,kkk+1) * p(-1, 0,-1)
4365  + Apm0(iii-1,jjj-1,kkk+1) * p( 0, 0,-1)
4366  + A000(iii-1,jjj-1,kkk+1) * p(-1,+1,-1)
4367  + Ap00(iii-1,jjj-1,kkk+1) * p( 0,+1,-1)
4368  + A0mp(iii-1,jjj-1,kkk+1) * p(-1, 0, 0)
4369  + Apmp(iii-1,jjj-1,kkk+1) * p( 0, 0, 0)
4370  + A00p(iii-1,jjj-1,kkk+1) * p(-1,+1, 0)
4371  + Ap0p(iii-1,jjj-1,kkk+1) * p( 0,+1, 0);
4372  ap(0,-1,1) =
4373  Amm0(iii,jjj-1,kkk+1) * p(-1, 0,-1)
4374  + A0m0(iii,jjj-1,kkk+1) * p( 0, 0,-1)
4375  + Apm0(iii,jjj-1,kkk+1) * p(+1, 0,-1)
4376  + Am00(iii,jjj-1,kkk+1) * p(-1,+1,-1)
4377  + A000(iii,jjj-1,kkk+1) * p( 0,+1,-1)
4378  + Ap00(iii,jjj-1,kkk+1) * p(+1,+1,-1)
4379  + Ammp(iii,jjj-1,kkk+1) * p(-1, 0, 0)
4380  + A0mp(iii,jjj-1,kkk+1) * p( 0, 0, 0)
4381  + Apmp(iii,jjj-1,kkk+1) * p(+1, 0, 0)
4382  + Am0p(iii,jjj-1,kkk+1) * p(-1,+1, 0)
4383  + A00p(iii,jjj-1,kkk+1) * p( 0,+1, 0)
4384  + Ap0p(iii,jjj-1,kkk+1) * p(+1,+1, 0);
4385  ap(1,-1,1) =
4386  Amm0(iii+1,jjj-1,kkk+1) * p( 0, 0,-1)
4387  + A0m0(iii+1,jjj-1,kkk+1) * p(+1, 0,-1)
4388  + Am00(iii+1,jjj-1,kkk+1) * p( 0,+1,-1)
4389  + A000(iii+1,jjj-1,kkk+1) * p(+1,+1,-1)
4390  + Ammp(iii+1,jjj-1,kkk+1) * p( 0, 0, 0)
4391  + A0mp(iii+1,jjj-1,kkk+1) * p(+1, 0, 0)
4392  + Am0p(iii+1,jjj-1,kkk+1) * p( 0,+1, 0)
4393  + A00p(iii+1,jjj-1,kkk+1) * p(+1,+1, 0);
4394  ap(-1,0,1) =
4395  A0m0(iii-1,jjj,kkk+1) * p(-1,+1,-1)
4396  + Apm0(iii-1,jjj,kkk+1) * p( 0,+1,-1)
4397  + A0mp(iii-1,jjj,kkk+1) * p(-1,+1, 0)
4398  + Apmp(iii-1,jjj,kkk+1) * p( 0,+1, 0);
4399  ap(0,0,1) =
4400  Amm0(iii,jjj,kkk+1) * p(-1,+1,-1)
4401  + A0m0(iii,jjj,kkk+1) * p( 0,+1,-1)
4402  + Apm0(iii,jjj,kkk+1) * p(+1,+1,-1)
4403  + Ammp(iii,jjj,kkk+1) * p(-1,+1, 0)
4404  + A0mp(iii,jjj,kkk+1) * p( 0,+1, 0)
4405  + Apmp(iii,jjj,kkk+1) * p(+1,+1, 0);
4406  ap(1,0,1) =
4407  Amm0(iii+1,jjj,kkk+1) * p( 0,+1,-1)
4408  + A0m0(iii+1,jjj,kkk+1) * p(+1,+1,-1)
4409  + Ammp(iii+1,jjj,kkk+1) * p( 0,+1, 0)
4410  + A0mp(iii+1,jjj,kkk+1) * p(+1,+1, 0);
4411  cs2 = Real(0.125) *
4412  ( restrict_from_mm0_to(iii,jjj,kkk) * ap(-1,-1, 0)
4413  + restrict_from_0m0_to(iii,jjj,kkk) * ap( 0,-1, 0)
4414  + restrict_from_pm0_to(iii,jjj,kkk) * ap(+1,-1, 0)
4415  + restrict_from_m00_to(iii,jjj,kkk) * ap(-1, 0, 0)
4416  + restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
4417  + restrict_from_p00_to(iii,jjj,kkk) * ap(+1, 0, 0)
4418  + restrict_from_mmp_to(iii,jjj,kkk) * ap(-1,-1,+1)
4419  + restrict_from_0mp_to(iii,jjj,kkk) * ap( 0,-1,+1)
4420  + restrict_from_pmp_to(iii,jjj,kkk) * ap(+1,-1,+1)
4421  + restrict_from_m0p_to(iii,jjj,kkk) * ap(-1, 0,+1)
4422  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1)
4423  + restrict_from_p0p_to(iii,jjj,kkk) * ap(+1, 0,+1));
4424 
4425  csten(i,j,k,ist_0pp) = Real(0.5)*(cs1+cs2);
4426 
4427  // csten(i,j,k,ist_ppp)
4428  iii = ii;
4429  jjj = jj;
4430  kkk = kk;
4431  p(-1,-1,-1) = interp_from_ppp_to(iii+1,jjj+1,kkk+1);
4432  p( 0,-1,-1) = interp_from_0pp_to(iii+2,jjj+1,kkk+1);
4433  p(-1, 0,-1) = interp_from_p0p_to(iii+1,jjj+2,kkk+1);
4434  p( 0, 0,-1) = interp_from_00p_to(iii+2,jjj+2,kkk+1);
4435  p(-1,-1, 0) = interp_from_pp0_to(iii+1,jjj+1,kkk+2);
4436  p( 0,-1, 0) = interp_from_0p0_to(iii+2,jjj+1,kkk+2);
4437  p(-1, 0, 0) = interp_from_p00_to(iii+1,jjj+2,kkk+2);
4438  p( 0, 0, 0) = Real(1.);
4439  ap(0,0,0) =
4440  Appp(iii,jjj,kkk) * p(-1,-1,-1);
4441  ap(1,0,0) =
4442  A0pp(iii+1,jjj,kkk) * p(-1,-1,-1)
4443  + Appp(iii+1,jjj,kkk) * p( 0,-1,-1);
4444  ap(0,1,0) =
4445  Ap0p(iii,jjj+1,kkk) * p(-1,-1,-1)
4446  + Appp(iii,jjj+1,kkk) * p(-1, 0,-1);
4447  ap(1,1,0) =
4448  A00p(iii+1,jjj+1,kkk) * p(-1,-1,-1)
4449  + Ap0p(iii+1,jjj+1,kkk) * p( 0,-1,-1)
4450  + A0pp(iii+1,jjj+1,kkk) * p(-1, 0,-1)
4451  + Appp(iii+1,jjj+1,kkk) * p( 0, 0,-1);
4452  ap(0,0,1) =
4453  App0(iii,jjj,kkk+1) * p(-1,-1,-1)
4454  + Appp(iii,jjj,kkk+1) * p(-1,-1, 0);
4455  ap(1,0,1) =
4456  A0p0(iii+1,jjj,kkk+1) * p(-1,-1,-1)
4457  + App0(iii+1,jjj,kkk+1) * p( 0,-1,-1)
4458  + A0pp(iii+1,jjj,kkk+1) * p(-1,-1, 0)
4459  + Appp(iii+1,jjj,kkk+1) * p( 0,-1, 0);
4460  ap(0,1,1) =
4461  Ap00(iii,jjj+1,kkk+1) * p(-1,-1,-1)
4462  + App0(iii,jjj+1,kkk+1) * p(-1, 0,-1)
4463  + Ap0p(iii,jjj+1,kkk+1) * p(-1,-1, 0)
4464  + Appp(iii,jjj+1,kkk+1) * p(-1, 0, 0);
4465  ap(1,1,1) =
4466  A000(iii+1,jjj+1,kkk+1) * p(-1,-1,-1)
4467  + Ap00(iii+1,jjj+1,kkk+1) * p( 0,-1,-1)
4468  + A0p0(iii+1,jjj+1,kkk+1) * p(-1, 0,-1)
4469  + App0(iii+1,jjj+1,kkk+1) * p( 0, 0,-1)
4470  + A00p(iii+1,jjj+1,kkk+1) * p(-1,-1, 0)
4471  + Ap0p(iii+1,jjj+1,kkk+1) * p( 0,-1, 0)
4472  + A0pp(iii+1,jjj+1,kkk+1) * p(-1, 0, 0)
4473  + Appp(iii+1,jjj+1,kkk+1) * p( 0, 0, 0);
4474  cs1 = Real(0.125) *
4475  ( restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
4476  + restrict_from_p00_to(iii,jjj,kkk) * ap(+1, 0, 0)
4477  + restrict_from_0p0_to(iii,jjj,kkk) * ap( 0,+1, 0)
4478  + restrict_from_pp0_to(iii,jjj,kkk) * ap(+1,+1, 0)
4479  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1)
4480  + restrict_from_p0p_to(iii,jjj,kkk) * ap(+1, 0,+1)
4481  + restrict_from_0pp_to(iii,jjj,kkk) * ap( 0,+1,+1)
4482  + restrict_from_ppp_to(iii,jjj,kkk) * ap(+1,+1,+1));
4483 
4484  // alternative: csten(i+1,j,k,ist_mpp)
4485  iii = ii+2;
4486  jjj = jj;
4487  kkk = kk;
4488  p( 0,-1,-1) = interp_from_0pp_to(iii-2,jjj+1,kkk+1);
4489  p(+1,-1,-1) = interp_from_mpp_to(iii-1,jjj+1,kkk+1);
4490  p( 0, 0,-1) = interp_from_00p_to(iii-2,jjj+2,kkk+1);
4491  p(+1, 0,-1) = interp_from_m0p_to(iii-1,jjj+2,kkk+1);
4492  p( 0,-1, 0) = interp_from_0p0_to(iii-2,jjj+1,kkk+2);
4493  p(+1,-1, 0) = interp_from_mp0_to(iii-1,jjj+1,kkk+2);
4494  p( 0, 0, 0) = Real(1.);
4495  p(+1, 0, 0) = interp_from_m00_to(iii-1,jjj+2,kkk+2);
4496  ap(-1,0,0) =
4497  Ampp(iii-1,jjj,kkk) * p( 0,-1,-1)
4498  + A0pp(iii-1,jjj,kkk) * p(+1,-1,-1);
4499  ap(0,0,0) =
4500  Ampp(iii,jjj,kkk) * p(+1,-1,-1);
4501  ap(-1,1,0) =
4502  Am0p(iii-1,jjj+1,kkk) * p( 0,-1,-1)
4503  + A00p(iii-1,jjj+1,kkk) * p(+1,-1,-1)
4504  + Ampp(iii-1,jjj+1,kkk) * p( 0, 0,-1)
4505  + A0pp(iii-1,jjj+1,kkk) * p(+1, 0,-1);
4506  ap(0,1,0) =
4507  Am0p(iii,jjj+1,kkk) * p(+1,-1,-1)
4508  + Ampp(iii,jjj+1,kkk) * p(+1, 0,-1);
4509  ap(-1,0,1) =
4510  Amp0(iii-1,jjj,kkk+1) * p( 0,-1,-1)
4511  + A0p0(iii-1,jjj,kkk+1) * p(+1,-1,-1)
4512  + Ampp(iii-1,jjj,kkk+1) * p( 0,-1, 0)
4513  + A0pp(iii-1,jjj,kkk+1) * p(+1,-1, 0);
4514  ap(0,0,1) =
4515  Amp0(iii,jjj,kkk+1) * p(+1,-1,-1)
4516  + Ampp(iii,jjj,kkk+1) * p(+1,-1, 0);
4517  ap(-1,1,1) =
4518  Am00(iii-1,jjj+1,kkk+1) * p( 0,-1,-1)
4519  + A000(iii-1,jjj+1,kkk+1) * p(+1,-1,-1)
4520  + Amp0(iii-1,jjj+1,kkk+1) * p( 0, 0,-1)
4521  + A0p0(iii-1,jjj+1,kkk+1) * p(+1, 0,-1)
4522  + Am0p(iii-1,jjj+1,kkk+1) * p( 0,-1, 0)
4523  + A00p(iii-1,jjj+1,kkk+1) * p(+1,-1, 0)
4524  + Ampp(iii-1,jjj+1,kkk+1) * p( 0, 0, 0)
4525  + A0pp(iii-1,jjj+1,kkk+1) * p(+1, 0, 0);
4526  ap(0,1,1) =
4527  Am00(iii,jjj+1,kkk+1) * p(+1,-1,-1)
4528  + Amp0(iii,jjj+1,kkk+1) * p(+1, 0,-1)
4529  + Am0p(iii,jjj+1,kkk+1) * p(+1,-1, 0)
4530  + Ampp(iii,jjj+1,kkk+1) * p(+1, 0, 0);
4531  cs2 = Real(0.125) *
4532  ( restrict_from_m00_to(iii,jjj,kkk) * ap(-1, 0, 0)
4533  + restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
4534  + restrict_from_mp0_to(iii,jjj,kkk) * ap(-1,+1, 0)
4535  + restrict_from_0p0_to(iii,jjj,kkk) * ap( 0,+1, 0)
4536  + restrict_from_m0p_to(iii,jjj,kkk) * ap(-1, 0,+1)
4537  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1)
4538  + restrict_from_mpp_to(iii,jjj,kkk) * ap(-1,+1,+1)
4539  + restrict_from_0pp_to(iii,jjj,kkk) * ap( 0,+1,+1));
4540 
4541  // alternative: csten(i,j+1,k,ist_pmp)
4542  iii = ii;
4543  jjj = jj+2;
4544  kkk = kk;
4545  p(-1, 0,-1) = interp_from_p0p_to(iii+1,jjj-2,kkk+1);
4546  p( 0, 0,-1) = interp_from_00p_to(iii+2,jjj-2,kkk+1);
4547  p(-1,+1,-1) = interp_from_pmp_to(iii+1,jjj-1,kkk+1);
4548  p( 0,+1,-1) = interp_from_0mp_to(iii+2,jjj-1,kkk+1);
4549  p(-1, 0, 0) = interp_from_p00_to(iii+1,jjj-2,kkk+2);
4550  p( 0, 0, 0) = Real(1.);
4551  p(-1,+1, 0) = interp_from_pm0_to(iii+1,jjj-1,kkk+2);
4552  p( 0,+1, 0) = interp_from_0m0_to(iii+2,jjj-1,kkk+2);
4553  ap(0,-1,0) =
4554  Apmp(iii,jjj-1,kkk) * p(-1, 0,-1)
4555  + Ap0p(iii,jjj-1,kkk) * p(-1,+1,-1);
4556  ap(1,-1,0) =
4557  A0mp(iii+1,jjj-1,kkk) * p(-1, 0,-1)
4558  + Apmp(iii+1,jjj-1,kkk) * p( 0, 0,-1)
4559  + A00p(iii+1,jjj-1,kkk) * p(-1,+1,-1)
4560  + Ap0p(iii+1,jjj-1,kkk) * p( 0,+1,-1);
4561  ap(0,0,0) =
4562  Apmp(iii,jjj,kkk) * p(-1,+1,-1);
4563  ap(1,0,0) =
4564  A0mp(iii+1,jjj,kkk) * p(-1,+1,-1)
4565  + Apmp(iii+1,jjj,kkk) * p( 0,+1,-1);
4566  ap(0,-1,1) =
4567  Apm0(iii,jjj-1,kkk+1) * p(-1, 0,-1)
4568  + Ap00(iii,jjj-1,kkk+1) * p(-1,+1,-1)
4569  + Apmp(iii,jjj-1,kkk+1) * p(-1, 0, 0)
4570  + Ap0p(iii,jjj-1,kkk+1) * p(-1,+1, 0);
4571  ap(1,-1,1) =
4572  A0m0(iii+1,jjj-1,kkk+1) * p(-1, 0,-1)
4573  + Apm0(iii+1,jjj-1,kkk+1) * p( 0, 0,-1)
4574  + A000(iii+1,jjj-1,kkk+1) * p(-1,+1,-1)
4575  + Ap00(iii+1,jjj-1,kkk+1) * p( 0,+1,-1)
4576  + A0mp(iii+1,jjj-1,kkk+1) * p(-1, 0, 0)
4577  + Apmp(iii+1,jjj-1,kkk+1) * p( 0, 0, 0)
4578  + A00p(iii+1,jjj-1,kkk+1) * p(-1,+1, 0)
4579  + Ap0p(iii+1,jjj-1,kkk+1) * p( 0,+1, 0);
4580  ap(0,0,1) =
4581  Apm0(iii,jjj,kkk+1) * p(-1,+1,-1)
4582  + Apmp(iii,jjj,kkk+1) * p(-1,+1, 0);
4583  ap(1,0,1) =
4584  A0m0(iii+1,jjj,kkk+1) * p(-1,+1,-1)
4585  + Apm0(iii+1,jjj,kkk+1) * p( 0,+1,-1)
4586  + A0mp(iii+1,jjj,kkk+1) * p(-1,+1, 0)
4587  + Apmp(iii+1,jjj,kkk+1) * p( 0,+1, 0);
4588  cs3 = Real(0.125) *
4589  ( restrict_from_0m0_to(iii,jjj,kkk) * ap( 0,-1, 0)
4590  + restrict_from_pm0_to(iii,jjj,kkk) * ap(+1,-1, 0)
4591  + restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
4592  + restrict_from_p00_to(iii,jjj,kkk) * ap(+1, 0, 0)
4593  + restrict_from_0mp_to(iii,jjj,kkk) * ap( 0,-1,+1)
4594  + restrict_from_pmp_to(iii,jjj,kkk) * ap(+1,-1,+1)
4595  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1)
4596  + restrict_from_p0p_to(iii,jjj,kkk) * ap(+1, 0,+1));
4597 
4598  // alternative: csten(i+1,j+1,k,ist_mmp)
4599  iii = ii+2;
4600  jjj = jj+2;
4601  kkk = kk;
4602  p( 0, 0,-1) = interp_from_00p_to(iii-2,jjj-2,kkk+1);
4603  p(+1, 0,-1) = interp_from_m0p_to(iii-1,jjj-2,kkk+1);
4604  p( 0,+1,-1) = interp_from_0mp_to(iii-2,jjj-1,kkk+1);
4605  p(+1,+1,-1) = interp_from_mmp_to(iii-1,jjj-1,kkk+1);
4606  p( 0, 0, 0) = Real(1.);
4607  p(+1, 0, 0) = interp_from_m00_to(iii-1,jjj-2,kkk+2);
4608  p( 0,+1, 0) = interp_from_0m0_to(iii-2,jjj-1,kkk+2);
4609  p(+1,+1, 0) = interp_from_mm0_to(iii-1,jjj-1,kkk+2);
4610  ap(-1,-1,0) =
4611  Ammp(iii-1,jjj-1,kkk) * p( 0, 0,-1)
4612  + A0mp(iii-1,jjj-1,kkk) * p(+1, 0,-1)
4613  + Am0p(iii-1,jjj-1,kkk) * p( 0,+1,-1)
4614  + A00p(iii-1,jjj-1,kkk) * p(+1,+1,-1);
4615  ap(0,-1,0) =
4616  Ammp(iii,jjj-1,kkk) * p(+1, 0,-1)
4617  + Am0p(iii,jjj-1,kkk) * p(+1,+1,-1);
4618  ap(-1,0,0) =
4619  Ammp(iii-1,jjj,kkk) * p( 0,+1,-1)
4620  + A0mp(iii-1,jjj,kkk) * p(+1,+1,-1);
4621  ap(0,0,0) =
4622  Ammp(iii,jjj,kkk) * p(+1,+1,-1);
4623  ap(-1,-1,1) =
4624  Amm0(iii-1,jjj-1,kkk+1) * p( 0, 0,-1)
4625  + A0m0(iii-1,jjj-1,kkk+1) * p(+1, 0,-1)
4626  + Am00(iii-1,jjj-1,kkk+1) * p( 0,+1,-1)
4627  + A000(iii-1,jjj-1,kkk+1) * p(+1,+1,-1)
4628  + Ammp(iii-1,jjj-1,kkk+1) * p( 0, 0, 0)
4629  + A0mp(iii-1,jjj-1,kkk+1) * p(+1, 0, 0)
4630  + Am0p(iii-1,jjj-1,kkk+1) * p( 0,+1, 0)
4631  + A00p(iii-1,jjj-1,kkk+1) * p(+1,+1, 0);
4632  ap(0,-1,1) =
4633  Amm0(iii,jjj-1,kkk+1) * p(+1, 0,-1)
4634  + Am00(iii,jjj-1,kkk+1) * p(+1,+1,-1)
4635  + Ammp(iii,jjj-1,kkk+1) * p(+1, 0, 0)
4636  + Am0p(iii,jjj-1,kkk+1) * p(+1,+1, 0);
4637  ap(-1,0,1) =
4638  Amm0(iii-1,jjj,kkk+1) * p( 0,+1,-1)
4639  + A0m0(iii-1,jjj,kkk+1) * p(+1,+1,-1)
4640  + Ammp(iii-1,jjj,kkk+1) * p( 0,+1, 0)
4641  + A0mp(iii-1,jjj,kkk+1) * p(+1,+1, 0);
4642  ap(0,0,1) =
4643  Amm0(iii,jjj,kkk+1) * p(+1,+1,-1)
4644  + Ammp(iii,jjj,kkk+1) * p(+1,+1, 0);
4645  cs4 = Real(0.125) *
4646  ( restrict_from_mm0_to(iii,jjj,kkk) * ap(-1,-1, 0)
4647  + restrict_from_0m0_to(iii,jjj,kkk) * ap( 0,-1, 0)
4648  + restrict_from_m00_to(iii,jjj,kkk) * ap(-1, 0, 0)
4649  + restrict_from_000_to(iii,jjj,kkk) * ap( 0, 0, 0)
4650  + restrict_from_mmp_to(iii,jjj,kkk) * ap(-1,-1,+1)
4651  + restrict_from_0mp_to(iii,jjj,kkk) * ap( 0,-1,+1)
4652  + restrict_from_m0p_to(iii,jjj,kkk) * ap(-1, 0,+1)
4653  + restrict_from_00p_to(iii,jjj,kkk) * ap( 0, 0,+1));
4654 
4655  csten(i,j,k,ist_ppp) = Real(0.25)*(cs1+cs2+cs3+cs4);
4656 }
4657 
4659 Real mlndlap_adotx_sten_doit (int i, int j, int k, Array4<Real const> const& x,
4660  Array4<Real const> const& sten) noexcept
4661 {
4662  using namespace nodelap_detail;
4663 
4664  return x(i ,j ,k ) * sten(i ,j ,k ,ist_000)
4665  //
4666  + x(i-1,j ,k ) * sten(i-1,j ,k ,ist_p00)
4667  + x(i+1,j ,k ) * sten(i ,j ,k ,ist_p00)
4668  //
4669  + x(i ,j-1,k ) * sten(i ,j-1,k ,ist_0p0)
4670  + x(i ,j+1,k ) * sten(i ,j ,k ,ist_0p0)
4671  //
4672  + x(i ,j ,k-1) * sten(i ,j ,k-1,ist_00p)
4673  + x(i ,j ,k+1) * sten(i ,j ,k ,ist_00p)
4674  //
4675  + x(i-1,j-1,k ) * sten(i-1,j-1,k ,ist_pp0)
4676  + x(i+1,j-1,k ) * sten(i ,j-1,k ,ist_pp0)
4677  + x(i-1,j+1,k ) * sten(i-1,j ,k ,ist_pp0)
4678  + x(i+1,j+1,k ) * sten(i ,j ,k ,ist_pp0)
4679  //
4680  + x(i-1,j ,k-1) * sten(i-1,j ,k-1,ist_p0p)
4681  + x(i+1,j ,k-1) * sten(i ,j ,k-1,ist_p0p)
4682  + x(i-1,j ,k+1) * sten(i-1,j ,k ,ist_p0p)
4683  + x(i+1,j ,k+1) * sten(i ,j ,k ,ist_p0p)
4684  //
4685  + x(i ,j-1,k-1) * sten(i ,j-1,k-1,ist_0pp)
4686  + x(i ,j+1,k-1) * sten(i ,j ,k-1,ist_0pp)
4687  + x(i ,j-1,k+1) * sten(i ,j-1,k ,ist_0pp)
4688  + x(i ,j+1,k+1) * sten(i ,j ,k ,ist_0pp)
4689  //
4690  + x(i-1,j-1,k-1) * sten(i-1,j-1,k-1,ist_ppp)
4691  + x(i+1,j-1,k-1) * sten(i ,j-1,k-1,ist_ppp)
4692  + x(i-1,j+1,k-1) * sten(i-1,j ,k-1,ist_ppp)
4693  + x(i+1,j+1,k-1) * sten(i ,j ,k-1,ist_ppp)
4694  + x(i-1,j-1,k+1) * sten(i-1,j-1,k ,ist_ppp)
4695  + x(i+1,j-1,k+1) * sten(i ,j-1,k ,ist_ppp)
4696  + x(i-1,j+1,k+1) * sten(i-1,j ,k ,ist_ppp)
4697  + x(i+1,j+1,k+1) * sten(i ,j ,k ,ist_ppp);
4698 }
4699 
4701 Real mlndlap_adotx_sten (int i, int j, int k, Array4<Real const> const& x,
4702  Array4<Real const> const& sten, Array4<int const> const& msk) noexcept
4703 {
4704  if (msk(i,j,k)) {
4705  return Real(0.0);
4706  } else {
4707  return mlndlap_adotx_sten_doit(i,j,k,x,sten);
4708  }
4709 }
4710 
4712 void mlndlap_gauss_seidel_sten (int i, int j, int k, Array4<Real> const& sol,
4713  Array4<Real const> const& rhs,
4714  Array4<Real const> const& sten,
4715  Array4<int const> const& msk) noexcept
4716 {
4717  using namespace nodelap_detail;
4718 
4719  if (msk(i,j,k)) {
4720  sol(i,j,k) = Real(0.0);
4721  } else if (sten(i,j,k,ist_000) != Real(0.0)) {
4722  Real Ax = mlndlap_adotx_sten_doit(i,j,k,sol,sten);
4723  sol(i,j,k) += (rhs(i,j,k) - Ax) / sten(i,j,k,ist_000);
4724  }
4725 }
4726 
4727 inline
4728 void mlndlap_gauss_seidel_sten (Box const& bx, Array4<Real> const& sol,
4729  Array4<Real const> const& rhs,
4730  Array4<Real const> const& sten,
4731  Array4<int const> const& msk) noexcept
4732 {
4733  AMREX_LOOP_3D(bx, i, j, k,
4734  {
4735  mlndlap_gauss_seidel_sten(i,j,k,sol,rhs,sten,msk);
4736  });
4737 }
4738 
4740 void mlndlap_interpadd_rap (int i, int j, int k, Array4<Real> const& fine,
4741  Array4<Real const> const& crse, Array4<Real const> const& sten,
4742  Array4<int const> const& msk) noexcept
4743 {
4744  using namespace nodelap_detail;
4745 
4746  if (!msk(i,j,k) && sten(i,j,k,ist_000) != Real(0.0)) {
4747  int ic = amrex::coarsen(i,2);
4748  int jc = amrex::coarsen(j,2);
4749  int kc = amrex::coarsen(k,2);
4750  bool ieven = ic*2 == i;
4751  bool jeven = jc*2 == j;
4752  bool keven = kc*2 == k;
4753  Real fv;
4754  if (ieven && jeven && keven) {
4755  fv = crse(ic,jc,kc);
4756  } else if (ieven && jeven) {
4757  Real w1 = std::abs(sten(i,j,k-1,ist_00p));
4758  Real w2 = std::abs(sten(i,j,k ,ist_00p));
4759  if (w1 == Real(0.0) && w2 == Real(0.0)) {
4760  fv = Real(0.5)*(crse(ic,jc,kc)+crse(ic,jc,kc+1));
4761  } else {
4762  fv = (w1*crse(ic,jc,kc) + w2*crse(ic,jc,kc+1)) / (w1+w2);
4763  }
4764  } else if (ieven && keven) {
4765  Real w1 = std::abs(sten(i,j-1,k,ist_0p0));
4766  Real w2 = std::abs(sten(i,j ,k,ist_0p0));
4767  if (w1 == Real(0.0) && w2 == Real(0.0)) {
4768  fv = Real(0.5)*(crse(ic,jc,kc)+crse(ic,jc+1,kc));
4769  } else {
4770  fv = (w1*crse(ic,jc,kc) + w2*crse(ic,jc+1,kc)) / (w1+w2);
4771  }
4772  } else if (jeven && keven) {
4773  Real w1 = std::abs(sten(i-1,j,k,ist_p00));
4774  Real w2 = std::abs(sten(i ,j,k,ist_p00));
4775  if (w1 == Real(0.0) && w2 == Real(0.0)) {
4776  fv = Real(0.5)*(crse(ic,jc,kc)+crse(ic+1,jc,kc));
4777  } else {
4778  fv = (w1*crse(ic,jc,kc) + w2*crse(ic+1,jc,kc)) / (w1+w2);
4779  }
4780  } else if (ieven) {
4781  Real w1m = std::abs(sten(i,j-1,k,ist_0p0)) / (std::abs(sten(i,j-1,k-1,ist_0pp))
4782  +std::abs(sten(i,j-1,k ,ist_0pp)) + eps);
4783  Real w1p = std::abs(sten(i,j ,k,ist_0p0)) / (std::abs(sten(i,j ,k-1,ist_0pp))
4784  +std::abs(sten(i,j ,k ,ist_0pp)) + eps);
4785  Real w2m = std::abs(sten(i,j,k-1,ist_00p)) / (std::abs(sten(i,j-1,k-1,ist_0pp))
4786  +std::abs(sten(i,j ,k-1,ist_0pp)) + eps);
4787  Real w2p = std::abs(sten(i,j,k ,ist_00p)) / (std::abs(sten(i,j-1,k ,ist_0pp))
4788  +std::abs(sten(i,j ,k ,ist_0pp)) + eps);
4789  Real wmm = std::abs(sten(i,j-1,k-1,ist_0pp)) * (Real(1.0) + w1m + w2m);
4790  Real wpm = std::abs(sten(i,j ,k-1,ist_0pp)) * (Real(1.0) + w1p + w2m);
4791  Real wmp = std::abs(sten(i,j-1,k ,ist_0pp)) * (Real(1.0) + w1m + w2p);
4792  Real wpp = std::abs(sten(i,j ,k ,ist_0pp)) * (Real(1.0) + w1p + w2p);
4793  fv = (wmm*crse(ic,jc,kc) + wpm*crse(ic,jc+1,kc)
4794  + wmp*crse(ic,jc,kc+1) + wpp*crse(ic,jc+1,kc+1))
4795  / (wmm+wpm+wmp+wpp+eps);
4796  } else if (jeven) {
4797  Real w1m = std::abs(sten(i-1,j,k,ist_p00)) / (std::abs(sten(i-1,j,k-1,ist_p0p))
4798  +std::abs(sten(i-1,j,k ,ist_p0p)) + eps);
4799  Real w1p = std::abs(sten(i ,j,k,ist_p00)) / (std::abs(sten(i ,j,k-1,ist_p0p))
4800  +std::abs(sten(i ,j,k ,ist_p0p)) + eps);
4801  Real w2m = std::abs(sten(i,j,k-1,ist_00p)) / (std::abs(sten(i-1,j,k-1,ist_p0p))
4802  +std::abs(sten(i ,j,k-1,ist_p0p)) + eps);
4803  Real w2p = std::abs(sten(i,j,k ,ist_00p)) / (std::abs(sten(i-1,j,k ,ist_p0p))
4804  +std::abs(sten(i ,j,k ,ist_p0p)) + eps);
4805  Real wmm = std::abs(sten(i-1,j,k-1,ist_p0p)) * (Real(1.0) + w1m + w2m);
4806  Real wpm = std::abs(sten(i ,j,k-1,ist_p0p)) * (Real(1.0) + w1p + w2m);
4807  Real wmp = std::abs(sten(i-1,j,k ,ist_p0p)) * (Real(1.0) + w1m + w2p);
4808  Real wpp = std::abs(sten(i ,j,k ,ist_p0p)) * (Real(1.0) + w1p + w2p);
4809  fv = (wmm*crse(ic,jc,kc) + wpm*crse(ic+1,jc,kc)
4810  + wmp*crse(ic,jc,kc+1) + wpp*crse(ic+1,jc,kc+1))
4811  / (wmm+wpm+wmp+wpp+eps);
4812  } else if (keven) {
4813  Real w1m = std::abs(sten(i-1,j,k,ist_p00)) / (std::abs(sten(i-1,j-1,k,ist_pp0))
4814  +std::abs(sten(i-1,j ,k,ist_pp0)) + eps);
4815  Real w1p = std::abs(sten(i ,j,k,ist_p00)) / (std::abs(sten(i ,j-1,k,ist_pp0))
4816  +std::abs(sten(i ,j ,k,ist_pp0)) + eps);
4817  Real w2m = std::abs(sten(i,j-1,k,ist_0p0)) / (std::abs(sten(i-1,j-1,k,ist_pp0))
4818  +std::abs(sten(i ,j-1,k,ist_pp0)) + eps);
4819  Real w2p = std::abs(sten(i,j ,k,ist_0p0)) / (std::abs(sten(i-1,j ,k,ist_pp0))
4820  +std::abs(sten(i ,j ,k,ist_pp0)) + eps);
4821  Real wmm = std::abs(sten(i-1,j-1,k,ist_pp0)) * (Real(1.0) + w1m + w2m);
4822  Real wpm = std::abs(sten(i ,j-1,k,ist_pp0)) * (Real(1.0) + w1p + w2m);
4823  Real wmp = std::abs(sten(i-1,j ,k,ist_pp0)) * (Real(1.0) + w1m + w2p);
4824  Real wpp = std::abs(sten(i ,j ,k,ist_pp0)) * (Real(1.0) + w1p + w2p);
4825  fv = (wmm*crse(ic,jc,kc) + wpm*crse(ic+1,jc,kc)
4826  + wmp*crse(ic,jc+1,kc) + wpp*crse(ic+1,jc+1,kc))
4827  / (wmm+wpm+wmp+wpp+eps);
4828  } else {
4829  Real wmmm = Real(1.0);
4830  Real wpmm = Real(1.0);
4831  Real wmpm = Real(1.0);
4832  Real wppm = Real(1.0);
4833  Real wmmp = Real(1.0);
4834  Real wpmp = Real(1.0);
4835  Real wmpp = Real(1.0);
4836  Real wppp = Real(1.0);
4837 
4838  Real wtmp = std::abs(sten(i-1,j,k,ist_p00)) /
4839  ( std::abs(sten(i-1,j-1,k-1,ist_ppp))
4840  + std::abs(sten(i-1,j ,k-1,ist_ppp))
4841  + std::abs(sten(i-1,j-1,k ,ist_ppp))
4842  + std::abs(sten(i-1,j ,k ,ist_ppp)) + eps);
4843  wmmm += wtmp;
4844  wmpm += wtmp;
4845  wmmp += wtmp;
4846  wmpp += wtmp;
4847 
4848  wtmp = std::abs(sten(i,j,k,ist_p00)) /
4849  ( std::abs(sten(i,j-1,k-1,ist_ppp))
4850  + std::abs(sten(i,j ,k-1,ist_ppp))
4851  + std::abs(sten(i,j-1,k ,ist_ppp))
4852  + std::abs(sten(i,j ,k ,ist_ppp)) + eps);
4853  wpmm += wtmp;
4854  wppm += wtmp;
4855  wpmp += wtmp;
4856  wppp += wtmp;
4857 
4858  wtmp = std::abs(sten(i,j-1,k,ist_0p0)) /
4859  ( std::abs(sten(i-1,j-1,k-1,ist_ppp))
4860  + std::abs(sten(i ,j-1,k-1,ist_ppp))
4861  + std::abs(sten(i-1,j-1,k ,ist_ppp))
4862  + std::abs(sten(i ,j-1,k ,ist_ppp)) + eps);
4863  wmmm += wtmp;
4864  wpmm += wtmp;
4865  wmmp += wtmp;
4866  wpmp += wtmp;
4867 
4868  wtmp = std::abs(sten(i,j,k,ist_0p0)) /
4869  ( std::abs(sten(i-1,j,k-1,ist_ppp))
4870  + std::abs(sten(i ,j,k-1,ist_ppp))
4871  + std::abs(sten(i-1,j,k ,ist_ppp))
4872  + std::abs(sten(i ,j,k ,ist_ppp)) + eps);
4873  wmpm += wtmp;
4874  wppm += wtmp;
4875  wmpp += wtmp;
4876  wppp += wtmp;
4877 
4878  wtmp = std::abs(sten(i,j,k-1,ist_00p)) /
4879  ( std::abs(sten(i-1,j-1,k-1,ist_ppp))
4880  + std::abs(sten(i ,j-1,k-1,ist_ppp))
4881  + std::abs(sten(i-1,j ,k-1,ist_ppp))
4882  + std::abs(sten(i ,j ,k-1,ist_ppp)) + eps);
4883  wmmm += wtmp;
4884  wpmm += wtmp;
4885  wmpm += wtmp;
4886  wppm += wtmp;
4887 
4888  wtmp = std::abs(sten(i,j,k,ist_00p)) /
4889  ( std::abs(sten(i-1,j-1,k,ist_ppp))
4890  + std::abs(sten(i ,j-1,k,ist_ppp))
4891  + std::abs(sten(i-1,j ,k,ist_ppp))
4892  + std::abs(sten(i ,j ,k,ist_ppp)) + eps);
4893  wmmp += wtmp;
4894  wpmp += wtmp;
4895  wmpp += wtmp;
4896  wppp += wtmp;
4897 
4898  wtmp = std::abs(sten(i-1,j-1,k,ist_pp0)) /
4899  ( std::abs(sten(i-1,j-1,k-1,ist_ppp))
4900  + std::abs(sten(i-1,j-1,k ,ist_ppp)) + eps);
4901  wmmm += wtmp;
4902  wmmp += wtmp;
4903 
4904  wtmp = std::abs(sten(i,j-1,k,ist_pp0)) /
4905  ( std::abs(sten(i,j-1,k-1,ist_ppp))
4906  + std::abs(sten(i,j-1,k ,ist_ppp)) + eps);
4907  wpmm += wtmp;
4908  wpmp += wtmp;
4909 
4910  wtmp = std::abs(sten(i-1,j,k,ist_pp0)) /
4911  ( std::abs(sten(i-1,j,k-1,ist_ppp))
4912  + std::abs(sten(i-1,j,k ,ist_ppp)) + eps);
4913  wmpm += wtmp;
4914  wmpp += wtmp;
4915 
4916  wtmp = std::abs(sten(i,j,k,ist_pp0)) /
4917  ( std::abs(sten(i,j,k-1,ist_ppp))
4918  + std::abs(sten(i,j,k ,ist_ppp)) + eps);
4919  wppm += wtmp;
4920  wppp += wtmp;
4921 
4922  wtmp = std::abs(sten(i-1,j,k-1,ist_p0p)) /
4923  ( std::abs(sten(i-1,j-1,k-1,ist_ppp))
4924  + std::abs(sten(i-1,j ,k-1,ist_ppp)) + eps);
4925  wmmm += wtmp;
4926  wmpm += wtmp;
4927 
4928  wtmp = std::abs(sten(i,j,k-1,ist_p0p)) /
4929  ( std::abs(sten(i,j-1,k-1,ist_ppp))
4930  + std::abs(sten(i,j ,k-1,ist_ppp)) + eps);
4931  wpmm += wtmp;
4932  wppm += wtmp;
4933 
4934  wtmp = std::abs(sten(i-1,j,k,ist_p0p)) /
4935  ( std::abs(sten(i-1,j-1,k,ist_ppp))
4936  + std::abs(sten(i-1,j ,k,ist_ppp)) + eps);
4937  wmmp += wtmp;
4938  wmpp += wtmp;
4939 
4940  wtmp = std::abs(sten(i,j,k,ist_p0p)) /
4941  ( std::abs(sten(i,j-1,k,ist_ppp))
4942  + std::abs(sten(i,j ,k,ist_ppp)) + eps);
4943  wpmp += wtmp;
4944  wppp += wtmp;
4945 
4946  wtmp = std::abs(sten(i,j-1,k-1,ist_0pp)) /
4947  ( std::abs(sten(i-1,j-1,k-1,ist_ppp))
4948  + std::abs(sten(i ,j-1,k-1,ist_ppp)) + eps);
4949  wmmm += wtmp;
4950  wpmm += wtmp;
4951 
4952  wtmp = std::abs(sten(i,j,k-1,ist_0pp)) /
4953  ( std::abs(sten(i-1,j,k-1,ist_ppp))
4954  + std::abs(sten(i ,j,k-1,ist_ppp)) + eps);
4955  wmpm += wtmp;
4956  wppm += wtmp;
4957 
4958  wtmp = std::abs(sten(i,j-1,k,ist_0pp)) /
4959  ( std::abs(sten(i-1,j-1,k,ist_ppp))
4960  + std::abs(sten(i ,j-1,k,ist_ppp)) + eps);
4961  wmmp += wtmp;
4962  wpmp += wtmp;
4963 
4964  wtmp = std::abs(sten(i,j,k,ist_0pp)) /
4965  ( std::abs(sten(i-1,j,k,ist_ppp))
4966  + std::abs(sten(i ,j,k,ist_ppp)) + eps);
4967  wmpp += wtmp;
4968  wppp += wtmp;
4969 
4970  wmmm *= std::abs(sten(i-1,j-1,k-1,ist_ppp));
4971  wpmm *= std::abs(sten(i ,j-1,k-1,ist_ppp));
4972  wmpm *= std::abs(sten(i-1,j ,k-1,ist_ppp));
4973  wppm *= std::abs(sten(i ,j ,k-1,ist_ppp));
4974  wmmp *= std::abs(sten(i-1,j-1,k ,ist_ppp));
4975  wpmp *= std::abs(sten(i ,j-1,k ,ist_ppp));
4976  wmpp *= std::abs(sten(i-1,j ,k ,ist_ppp));
4977  wppp *= std::abs(sten(i ,j ,k ,ist_ppp));
4978  fv = (wmmm*crse(ic,jc ,kc ) + wpmm*crse(ic+1,jc ,kc )
4979  + wmpm*crse(ic,jc+1,kc ) + wppm*crse(ic+1,jc+1,kc )
4980  + wmmp*crse(ic,jc ,kc+1) + wpmp*crse(ic+1,jc ,kc+1)
4981  + wmpp*crse(ic,jc+1,kc+1) + wppp*crse(ic+1,jc+1,kc+1))
4982  / (wmmm + wpmm + wmpm + wppm + wmmp + wpmp + wmpp + wppp + eps);
4983  }
4984 
4985  fine(i,j,k) += fv;
4986  }
4987 }
4988 
4990 void mlndlap_restriction_rap (int i, int j, int k, Array4<Real> const& crse,
4991  Array4<Real const> const& fine, Array4<Real const> const& sten,
4992  Array4<int const> const& msk) noexcept
4993 {
4994  using namespace nodelap_detail;
4995 
4996  int ii = i*2;
4997  int jj = j*2;
4998  int kk = k*2;
4999  if (msk(ii,jj,kk)) {
5000  crse(i,j,k) = Real(0.0);
5001  } else {
5002 
5003  Real cv = fine(ii,jj,kk);
5004 
5005  // ************************************
5006  // Adding fine(ii-1,jj,kk)
5007  // ************************************
5008 
5009  Real sten_lo = std::abs(sten(ii-2,jj,kk,ist_p00));
5010  Real sten_hi = std::abs(sten(ii-1,jj,kk,ist_p00));
5011 
5012  if (sten_lo == Real(0.0) && sten_hi == Real(0.0)) {
5013  cv += Real(0.5)*fine(ii-1,jj,kk);
5014  } else {
5015  cv += fine(ii-1,jj,kk) * sten_hi / (sten_lo + sten_hi);
5016  }
5017 
5018  // ************************************
5019  // Adding fine(ii+1,jj,kk)
5020  // ************************************
5021 
5022  sten_lo = std::abs(sten(ii ,jj,kk,ist_p00));
5023  sten_hi = std::abs(sten(ii+1,jj,kk,ist_p00));
5024 
5025  if (sten_lo == Real(0.0) && sten_hi == Real(0.0)) {
5026  cv += Real(0.5)*fine(ii+1,jj,kk);
5027  } else {
5028  cv += fine(ii+1,jj,kk) * sten_lo / (sten_lo + sten_hi);
5029  }
5030 
5031  // ************************************
5032  // Adding fine(ii,jj-1,kk)
5033  // ************************************
5034 
5035  sten_lo = std::abs(sten(ii,jj-2,kk,ist_0p0));
5036  sten_hi = std::abs(sten(ii,jj-1,kk,ist_0p0));
5037 
5038  if (sten_lo == Real(0.0) && sten_hi == Real(0.0)) {
5039  cv += Real(0.5)*fine(ii,jj-1,kk);
5040  } else {
5041  cv += fine(ii,jj-1,kk) * sten_hi / (sten_lo + sten_hi);
5042  }
5043 
5044  // ************************************
5045  // Adding fine(ii,jj+1,kk)
5046  // ************************************
5047 
5048  sten_lo = std::abs(sten(ii,jj ,kk,ist_0p0));
5049  sten_hi = std::abs(sten(ii,jj+1,kk,ist_0p0));
5050 
5051  if (sten_lo == Real(0.0) && sten_hi == Real(0.0)) {
5052  cv += Real(0.5)*fine(ii,jj+1,kk);
5053  } else {
5054  cv += fine(ii,jj+1,kk) * sten_lo / (sten_lo + sten_hi);
5055  }
5056 
5057  // ************************************
5058  // Adding fine(ii,jj,kk-1)
5059  // ************************************
5060 
5061  sten_lo = std::abs(sten(ii,jj,kk-2,ist_00p));
5062  sten_hi = std::abs(sten(ii,jj,kk-1,ist_00p));
5063 
5064  if (sten_lo == Real(0.0) && sten_hi == Real(0.0)) {
5065  cv += Real(0.5)*fine(ii,jj,kk-1);
5066  } else {
5067  cv += fine(ii,jj,kk-1)*sten_hi / (sten_lo + sten_hi);
5068  }
5069 
5070  // ************************************
5071  // Adding fine(ii,jj,kk+1)
5072  // ************************************
5073 
5074  sten_lo = std::abs(sten(ii,jj,kk ,ist_00p));
5075  sten_hi = std::abs(sten(ii,jj,kk+1,ist_00p));
5076 
5077  if (sten_lo == Real(0.0) && sten_hi == Real(0.0)) {
5078  cv += Real(0.5)*fine(ii,jj,kk+1);
5079  } else {
5080  cv += fine(ii,jj,kk+1)*sten_lo / (sten_lo + sten_hi);
5081  }
5082 
5083  // ************************************
5084  // Adding fine(ii-1,jj-1,kk)
5085  // ************************************
5086 
5087  // keven
5088  Real w1m = std::abs(sten(ii-2,jj-1,kk,ist_p00))
5089  / ( std::abs(sten(ii-2,jj-2,kk,ist_pp0))
5090  +std::abs(sten(ii-2,jj-1,kk,ist_pp0)) + eps);
5091  Real w1p = std::abs(sten(ii-1,jj-1,kk,ist_p00))
5092  / ( std::abs(sten(ii-1,jj-2,kk,ist_pp0))
5093  +std::abs(sten(ii-1,jj-1,kk,ist_pp0)) + eps);
5094  Real w2m = std::abs(sten(ii-1,jj-2,kk,ist_0p0))
5095  / ( std::abs(sten(ii-2,jj-2,kk,ist_pp0))
5096  +std::abs(sten(ii-1,jj-2,kk,ist_pp0)) + eps);
5097  Real w2p = std::abs(sten(ii-1,jj-1,kk,ist_0p0))
5098  / ( std::abs(sten(ii-2,jj-1,kk,ist_pp0))
5099  +std::abs(sten(ii-1,jj-1,kk,ist_pp0)) + eps);
5100  Real wmm = std::abs(sten(ii-2,jj-2,kk,ist_pp0)) * (Real(1.0) + w1m + w2m);
5101  Real wpm = std::abs(sten(ii-1,jj-2,kk,ist_pp0)) * (Real(1.0) + w1p + w2m);
5102  Real wmp = std::abs(sten(ii-2,jj-1,kk,ist_pp0)) * (Real(1.0) + w1m + w2p);
5103  Real wpp = std::abs(sten(ii-1,jj-1,kk,ist_pp0)) * (Real(1.0) + w1p + w2p);
5104  cv += fine(ii-1,jj-1,kk)*wpp/(wmm+wpm+wmp+wpp+eps);
5105 
5106  // ************************************
5107  // Adding fine(ii+1,jj-1,kk)
5108  // ************************************
5109 
5110  w1m = std::abs(sten(ii ,jj-1,kk,ist_p00))
5111  / (std::abs(sten(ii ,jj-2,kk,ist_pp0))
5112  +std::abs(sten(ii ,jj-1,kk,ist_pp0)) + eps);
5113  w1p = std::abs(sten(ii+1,jj-1,kk,ist_p00))
5114  / (std::abs(sten(ii+1,jj-2,kk,ist_pp0))
5115  +std::abs(sten(ii+1,jj-1,kk,ist_pp0)) + eps);
5116  w2m = std::abs(sten(ii+1,jj-2,kk,ist_0p0))
5117  / (std::abs(sten(ii ,jj-2,kk,ist_pp0))
5118  +std::abs(sten(ii+1,jj-2,kk,ist_pp0)) + eps);
5119  w2p = std::abs(sten(ii+1,jj-1,kk,ist_0p0))
5120  / (std::abs(sten(ii ,jj-1,kk,ist_pp0))
5121  +std::abs(sten(ii+1,jj-1,kk,ist_pp0)) + eps);
5122  wmm = std::abs(sten(ii ,jj-2,kk,ist_pp0)) * (Real(1.0) + w1m + w2m);
5123  wpm = std::abs(sten(ii+1,jj-2,kk,ist_pp0)) * (Real(1.0) + w1p + w2m);
5124  wmp = std::abs(sten(ii ,jj-1,kk,ist_pp0)) * (Real(1.0) + w1m + w2p);
5125  wpp = std::abs(sten(ii+1,jj-1,kk,ist_pp0)) * (Real(1.0) + w1p + w2p);
5126  cv += fine(ii+1,jj-1,kk)*wmp/(wmm+wpm+wmp+wpp+eps);
5127 
5128  // ************************************
5129  // Adding fine(ii-1,jj+1,kk)
5130  // ************************************
5131 
5132  w1m = std::abs(sten(ii-2,jj+1,kk,ist_p00))
5133  / (std::abs(sten(ii-2,jj ,kk,ist_pp0))
5134  +std::abs(sten(ii-2,jj+1,kk,ist_pp0)) + eps);
5135  w1p = std::abs(sten(ii-1,jj+1,kk,ist_p00))
5136  / (std::abs(sten(ii-1,jj ,kk,ist_pp0))
5137  +std::abs(sten(ii-1,jj+1,kk,ist_pp0)) + eps);
5138  w2m = std::abs(sten(ii-1,jj ,kk,ist_0p0))
5139  / (std::abs(sten(ii-2,jj ,kk,ist_pp0))
5140  +std::abs(sten(ii-1,jj ,kk,ist_pp0)) + eps);
5141  w2p = std::abs(sten(ii-1,jj+1,kk,ist_0p0))
5142  / (std::abs(sten(ii-2,jj+1,kk,ist_pp0))
5143  +std::abs(sten(ii-1,jj+1,kk,ist_pp0)) + eps);
5144  wmm = std::abs(sten(ii-2,jj ,kk,ist_pp0)) * (Real(1.0) + w1m + w2m);
5145  wpm = std::abs(sten(ii-1,jj ,kk,ist_pp0)) * (Real(1.0) + w1p + w2m);
5146  wmp = std::abs(sten(ii-2,jj+1,kk,ist_pp0)) * (Real(1.0) + w1m + w2p);
5147  wpp = std::abs(sten(ii-1,jj+1,kk,ist_pp0)) * (Real(1.0) + w1p + w2p);
5148  cv += fine(ii-1,jj+1,kk)*wpm/(wmm+wpm+wmp+wpp+eps);
5149 
5150  // ************************************
5151  // Adding fine(ii+1,jj+1,kk)
5152  // ************************************
5153 
5154  w1m = std::abs(sten(ii ,jj+1,kk,ist_p00))
5155  / (std::abs(sten(ii ,jj+1,kk,ist_pp0))
5156  +std::abs(sten(ii ,jj ,kk,ist_pp0)) + eps);
5157  w1p = std::abs(sten(ii+1,jj+1,kk,ist_p00))
5158  / (std::abs(sten(ii+1,jj+1,kk,ist_pp0))
5159  +std::abs(sten(ii+1,jj ,kk,ist_pp0)) + eps);
5160  w2m = std::abs(sten(ii+1,jj ,kk,ist_0p0))
5161  / (std::abs(sten(ii+1,jj ,kk,ist_pp0))
5162  +std::abs(sten(ii ,jj ,kk,ist_pp0)) + eps);
5163  w2p = std::abs(sten(ii+1,jj+1,kk,ist_0p0))
5164  / (std::abs(sten(ii+1,jj+1,kk,ist_pp0))
5165  +std::abs(sten(ii ,jj+1,kk,ist_pp0)) + eps);
5166  wmm = std::abs(sten(ii ,jj ,kk,ist_pp0)) * (Real(1.0) + w1m + w2m);
5167  wpm = std::abs(sten(ii+1,jj ,kk,ist_pp0)) * (Real(1.0) + w1p + w2m);
5168  wmp = std::abs(sten(ii ,jj+1,kk,ist_pp0)) * (Real(1.0) + w1m + w2p);
5169  wpp = std::abs(sten(ii+1,jj+1,kk,ist_pp0)) * (Real(1.0) + w1p + w2p);
5170  cv += fine(ii+1,jj+1,kk)*wmm/(wmm+wpm+wmp+wpp+eps);
5171 
5172  // ************************************
5173  // Adding fine(ii-1,jj,kk-1)
5174  // ************************************
5175 
5176  // jeven
5177  w1m = std::abs(sten(ii-2,jj,kk-1,ist_p00))
5178  / (std::abs(sten(ii-2,jj,kk-2,ist_p0p))
5179  +std::abs(sten(ii-2,jj,kk-1,ist_p0p)) + eps);
5180  w1p = std::abs(sten(ii-1,jj,kk-1,ist_p00))
5181  / (std::abs(sten(ii-1,jj,kk-2,ist_p0p))
5182  +std::abs(sten(ii-1,jj,kk-1,ist_p0p)) + eps);
5183  w2m = std::abs(sten(ii-1,jj,kk-2,ist_00p))
5184  / (std::abs(sten(ii-2,jj,kk-2,ist_p0p))
5185  +std::abs(sten(ii-1,jj,kk-2,ist_p0p)) + eps);
5186  w2p = std::abs(sten(ii-1,jj,kk-1,ist_00p))
5187  / (std::abs(sten(ii-2,jj,kk-1,ist_p0p))
5188  +std::abs(sten(ii-1,jj,kk-1,ist_p0p)) + eps);
5189  wmm = std::abs(sten(ii-2,jj,kk-2,ist_p0p)) * (Real(1.0) + w1m + w2m);
5190  wpm = std::abs(sten(ii-1,jj,kk-2,ist_p0p)) * (Real(1.0) + w1p + w2m);
5191  wmp = std::abs(sten(ii-2,jj,kk-1,ist_p0p)) * (Real(1.0) + w1m + w2p);
5192  wpp = std::abs(sten(ii-1,jj,kk-1,ist_p0p)) * (Real(1.0) + w1p + w2p);
5193  cv += fine(ii-1,jj,kk-1)*wpp/(wmm+wpm+wmp+wpp+eps);
5194 
5195  // ************************************
5196  // Adding fine(ii+1,jj,kk-1)
5197  // ************************************
5198 
5199  w1m = std::abs(sten(ii ,jj,kk-1,ist_p00))
5200  / (std::abs(sten(ii ,jj,kk-2,ist_p0p))
5201  +std::abs(sten(ii ,jj,kk-1,ist_p0p)) + eps);
5202  w1p = std::abs(sten(ii+1,jj,kk-1,ist_p00))
5203  / (std::abs(sten(ii+1,jj,kk-2,ist_p0p))
5204  +std::abs(sten(ii+1,jj,kk-1,ist_p0p)) + eps);
5205  w2m = std::abs(sten(ii+1,jj,kk-2,ist_00p))
5206  / (std::abs(sten(ii+1,jj,kk-2,ist_p0p))
5207  +std::abs(sten(ii ,jj,kk-2,ist_p0p)) + eps);
5208  w2p = std::abs(sten(ii+1,jj,kk-1,ist_00p))
5209  / (std::abs(sten(ii+1,jj,kk-1,ist_p0p))
5210  +std::abs(sten(ii ,jj,kk-1,ist_p0p)) + eps);
5211  wmm = std::abs(sten(ii ,jj,kk-2,ist_p0p)) * (Real(1.0) + w1m + w2m);
5212  wpm = std::abs(sten(ii+1,jj,kk-2,ist_p0p)) * (Real(1.0) + w1p + w2m);
5213  wmp = std::abs(sten(ii ,jj,kk-1,ist_p0p)) * (Real(1.0) + w1m + w2p);
5214  wpp = std::abs(sten(ii+1,jj,kk-1,ist_p0p)) * (Real(1.0) + w1p + w2p);
5215  cv += fine(ii+1,jj,kk-1)*wmp/(wmm+wpm+wmp+wpp+eps);
5216 
5217  // ************************************
5218  // Adding fine(ii-1,jj,kk+1)
5219  // ************************************
5220 
5221  w1m = std::abs(sten(ii-2,jj,kk+1,ist_p00))
5222  / (std::abs(sten(ii-2,jj,kk+1,ist_p0p))
5223  +std::abs(sten(ii-2,jj,kk ,ist_p0p)) + eps);
5224  w1p = std::abs(sten(ii-1,jj,kk+1,ist_p00))
5225  / (std::abs(sten(ii-1,jj,kk+1,ist_p0p))
5226  +std::abs(sten(ii-1,jj,kk ,ist_p0p)) + eps);
5227  w2m = std::abs(sten(ii-1,jj,kk ,ist_00p))
5228  / (std::abs(sten(ii-2,jj,kk ,ist_p0p))
5229  +std::abs(sten(ii-1,jj,kk ,ist_p0p)) + eps);
5230  w2p = std::abs(sten(ii-1,jj,kk+1,ist_00p))
5231  / (std::abs(sten(ii-2,jj,kk+1,ist_p0p))
5232  +std::abs(sten(ii-1,jj,kk+1,ist_p0p)) + eps);
5233  wmm = std::abs(sten(ii-2,jj,kk ,ist_p0p)) * (Real(1.0) + w1m + w2m);
5234  wpm = std::abs(sten(ii-1,jj,kk ,ist_p0p)) * (Real(1.0) + w1p + w2m);
5235  wmp = std::abs(sten(ii-2,jj,kk+1,ist_p0p)) * (Real(1.0) + w1m + w2p);
5236  wpp = std::abs(sten(ii-1,jj,kk+1,ist_p0p)) * (Real(1.0) + w1p + w2p);
5237  cv += fine(ii-1,jj,kk+1)*wpm/(wmm+wpm+wmp+wpp+eps);
5238 
5239  // ************************************
5240  // Adding fine(ii+1,jj,kk+1)
5241  // ************************************
5242 
5243  w1m = std::abs(sten(ii ,jj,kk+1,ist_p00))
5244  / (std::abs(sten(ii ,jj,kk+1,ist_p0p))
5245  +std::abs(sten(ii ,jj,kk ,ist_p0p)) + eps);
5246  w1p = std::abs(sten(ii+1,jj,kk+1,ist_p00))
5247  / (std::abs(sten(ii+1,jj,kk+1,ist_p0p))
5248  +std::abs(sten(ii+1,jj,kk ,ist_p0p)) + eps);
5249  w2m = std::abs(sten(ii+1,jj,kk ,ist_00p))
5250  / (std::abs(sten(ii+1,jj,kk ,ist_p0p))
5251  +std::abs(sten(ii ,jj,kk ,ist_p0p)) + eps);
5252  w2p = std::abs(sten(ii+1,jj,kk+1,ist_00p))
5253  / (std::abs(sten(ii+1,jj,kk+1,ist_p0p))
5254  +std::abs(sten(ii ,jj,kk+1,ist_p0p)) + eps);
5255  wmm = std::abs(sten(ii ,jj,kk ,ist_p0p)) * (Real(1.0) + w1m + w2m);
5256  wpm = std::abs(sten(ii+1,jj,kk ,ist_p0p)) * (Real(1.0) + w1p + w2m);
5257  wmp = std::abs(sten(ii ,jj,kk+1,ist_p0p)) * (Real(1.0) + w1m + w2p);
5258  wpp = std::abs(sten(ii+1,jj,kk+1,ist_p0p)) * (Real(1.0) + w1p + w2p);
5259  cv += fine(ii+1,jj,kk+1)*wmm/(wmm+wpm+wmp+wpp+eps);
5260 
5261  // ************************************
5262  // Adding fine(ii,jj-1,kk-1)
5263  // ************************************
5264 
5265  // ieven
5266  w1m = std::abs(sten(ii,jj-2,kk-1,ist_0p0))
5267  / (std::abs(sten(ii,jj-2,kk-2,ist_0pp))
5268  +std::abs(sten(ii,jj-2,kk-1,ist_0pp)) + eps);
5269  w2m = std::abs(sten(ii,jj-1,kk-2,ist_00p))
5270  / (std::abs(sten(ii,jj-2,kk-2,ist_0pp))
5271  +std::abs(sten(ii,jj-1,kk-2,ist_0pp)) + eps);
5272  w1p = std::abs(sten(ii,jj-1,kk-1,ist_0p0))
5273  / (std::abs(sten(ii,jj-1,kk-2,ist_0pp))
5274  +std::abs(sten(ii,jj-1,kk-1,ist_0pp)) + eps);
5275  w2p = std::abs(sten(ii,jj-1,kk-1,ist_00p))
5276  / (std::abs(sten(ii,jj-2,kk-1,ist_0pp))
5277  +std::abs(sten(ii,jj-1,kk-1,ist_0pp)) + eps);
5278  wmm = std::abs(sten(ii,jj-2,kk-2,ist_0pp)) * (Real(1.0) + w1m + w2m);
5279  wpm = std::abs(sten(ii,jj-1,kk-2,ist_0pp)) * (Real(1.0) + w1p + w2m);
5280  wmp = std::abs(sten(ii,jj-2,kk-1,ist_0pp)) * (Real(1.0) + w1m + w2p);
5281  wpp = std::abs(sten(ii,jj-1,kk-1,ist_0pp)) * (Real(1.0) + w1p + w2p);
5282  cv += fine(ii,jj-1,kk-1)*wpp/(wmm+wpm+wmp+wpp+eps);
5283 
5284  // ************************************
5285  // Adding fine(ii,jj+1,kk-1)
5286  // ************************************
5287 
5288  w1m = std::abs(sten(ii,jj ,kk-1,ist_0p0))
5289  / (std::abs(sten(ii,jj ,kk-2,ist_0pp))
5290  +std::abs(sten(ii,jj ,kk-1,ist_0pp)) + eps);
5291  w1p = std::abs(sten(ii,jj+1,kk-1,ist_0p0))
5292  / (std::abs(sten(ii,jj+1,kk-2,ist_0pp))
5293  +std::abs(sten(ii,jj+1,kk-1,ist_0pp)) + eps);
5294  w2m = std::abs(sten(ii,jj+1,kk-2,ist_00p))
5295  / (std::abs(sten(ii,jj+1,kk-2,ist_0pp))
5296  +std::abs(sten(ii,jj ,kk-2,ist_0pp)) + eps);
5297  w2p = std::abs(sten(ii,jj+1,kk-1,ist_00p))
5298  / (std::abs(sten(ii,jj+1,kk-1,ist_0pp))
5299  +std::abs(sten(ii,jj ,kk-1,ist_0pp)) + eps);
5300  wmm = std::abs(sten(ii,jj ,kk-2,ist_0pp)) * (Real(1.0) + w1m + w2m);
5301  wpm = std::abs(sten(ii,jj+1,kk-2,ist_0pp)) * (Real(1.0) + w1p + w2m);
5302  wmp = std::abs(sten(ii,jj ,kk-1,ist_0pp)) * (Real(1.0) + w1m + w2p);
5303  wpp = std::abs(sten(ii,jj+1,kk-1,ist_0pp)) * (Real(1.0) + w1p + w2p);
5304  cv += fine(ii,jj+1,kk-1)*wmp/(wmm+wpm+wmp+wpp+eps);
5305 
5306  // ************************************
5307  // Adding fine(ii,jj-1,kk+1)
5308  // ************************************
5309 
5310  w1m = std::abs(sten(ii,jj-2,kk+1,ist_0p0))
5311  / (std::abs(sten(ii,jj-2,kk+1,ist_0pp))
5312  +std::abs(sten(ii,jj-2,kk ,ist_0pp)) + eps);
5313  w1p = std::abs(sten(ii,jj-1,kk+1,ist_0p0))
5314  / (std::abs(sten(ii,jj-1,kk+1,ist_0pp))
5315  +std::abs(sten(ii,jj-1,kk ,ist_0pp)) + eps);
5316  w2m = std::abs(sten(ii,jj-1,kk ,ist_00p))
5317  / (std::abs(sten(ii,jj-2,kk ,ist_0pp))
5318  +std::abs(sten(ii,jj-1,kk ,ist_0pp)) + eps);
5319  w2p = std::abs(sten(ii,jj-1,kk+1,ist_00p))
5320  / (std::abs(sten(ii,jj-2,kk+1,ist_0pp))
5321  +std::abs(sten(ii,jj-1,kk+1,ist_0pp)) + eps);
5322  wmm = std::abs(sten(ii,jj-2,kk ,ist_0pp)) * (Real(1.0) + w1m + w2m);
5323  wpm = std::abs(sten(ii,jj-1,kk ,ist_0pp)) * (Real(1.0) + w1p + w2m);
5324  wmp = std::abs(sten(ii,jj-2,kk+1,ist_0pp)) * (Real(1.0) + w1m + w2p);
5325  wpp = std::abs(sten(ii,jj-1,kk+1,ist_0pp)) * (Real(1.0) + w1p + w2p);
5326  cv += fine(ii,jj-1,kk+1)*wpm/(wmm+wpm+wmp+wpp+eps);
5327 
5328  // ************************************
5329  // Adding fine(ii,jj+1,kk+1)
5330  // ************************************
5331 
5332  w1m = std::abs(sten(ii,jj ,kk+1,ist_0p0))
5333  / (std::abs(sten(ii,jj ,kk+1,ist_0pp))
5334  +std::abs(sten(ii,jj ,kk ,ist_0pp)) + eps);
5335  w1p = std::abs(sten(ii,jj+1,kk+1,ist_0p0))
5336  / (std::abs(sten(ii,jj+1,kk+1,ist_0pp))
5337  +std::abs(sten(ii,jj+1,kk ,ist_0pp)) + eps);
5338  w2m = std::abs(sten(ii,jj+1,kk ,ist_00p))
5339  / (std::abs(sten(ii,jj+1,kk ,ist_0pp))
5340  +std::abs(sten(ii,jj ,kk ,ist_0pp)) + eps);
5341  w2p = std::abs(sten(ii,jj+1,kk+1,ist_00p))
5342  / (std::abs(sten(ii,jj+1,kk+1,ist_0pp))
5343  +std::abs(sten(ii,jj ,kk+1,ist_0pp)) + eps);
5344  wmm = std::abs(sten(ii,jj ,kk ,ist_0pp)) * (Real(1.0) + w1m + w2m);
5345  wpm = std::abs(sten(ii,jj+1,kk ,ist_0pp)) * (Real(1.0) + w1p + w2m);
5346  wmp = std::abs(sten(ii,jj ,kk+1,ist_0pp)) * (Real(1.0) + w1m + w2p);
5347  wpp = std::abs(sten(ii,jj+1,kk+1,ist_0pp)) * (Real(1.0) + w1p + w2p);
5348  cv += fine(ii,jj+1,kk+1)*wmm/(wmm+wpm+wmp+wpp+eps);
5349 
5350  // ************************************
5351  // Adding fine at corners
5352  // ************************************
5353 
5354  Real wmmm = Real(1.0)
5355  + std::abs(sten(ii ,jj+1,kk+1,ist_p00)) /
5356  ( std::abs(sten(ii ,jj ,kk ,ist_ppp))
5357  + std::abs(sten(ii ,jj+1,kk ,ist_ppp))
5358  + std::abs(sten(ii ,jj ,kk+1,ist_ppp))
5359  + std::abs(sten(ii ,jj+1,kk+1,ist_ppp)) + eps)
5360  + std::abs(sten(ii+1,jj ,kk+1,ist_0p0)) /
5361  ( std::abs(sten(ii ,jj ,kk ,ist_ppp))
5362  + std::abs(sten(ii+1,jj ,kk ,ist_ppp))
5363  + std::abs(sten(ii ,jj ,kk+1,ist_ppp))
5364  + std::abs(sten(ii+1,jj ,kk+1,ist_ppp)) + eps)
5365  + std::abs(sten(ii+1,jj+1,kk ,ist_00p)) /
5366  ( std::abs(sten(ii ,jj ,kk ,ist_ppp))
5367  + std::abs(sten(ii+1,jj ,kk ,ist_ppp))
5368  + std::abs(sten(ii ,jj+1,kk ,ist_ppp))
5369  + std::abs(sten(ii+1,jj+1,kk ,ist_ppp)) + eps)
5370  + std::abs(sten(ii ,jj ,kk+1,ist_pp0)) /
5371  ( std::abs(sten(ii ,jj ,kk ,ist_ppp))
5372  + std::abs(sten(ii ,jj ,kk+1,ist_ppp)) + eps)
5373  + std::abs(sten(ii ,jj+1,kk ,ist_p0p)) /
5374  ( std::abs(sten(ii ,jj ,kk ,ist_ppp))
5375  + std::abs(sten(ii ,jj+1,kk ,ist_ppp)) + eps)
5376  + std::abs(sten(ii+1,jj ,kk ,ist_0pp)) /
5377  ( std::abs(sten(ii ,jj ,kk ,ist_ppp))
5378  + std::abs(sten(ii+1,jj ,kk ,ist_ppp)) + eps);
5379  wmmm *= std::abs(sten(ii,jj,kk,ist_ppp));
5380  cv += wmmm*fine(ii+1,jj+1,kk+1)*sten(ii+1,jj+1,kk+1,ist_inv);
5381 
5382  Real wpmm = Real(1.0)
5383  + std::abs(sten(ii-1,jj+1,kk+1,ist_p00)) /
5384  ( std::abs(sten(ii-1,jj ,kk ,ist_ppp))
5385  + std::abs(sten(ii-1,jj+1,kk ,ist_ppp))
5386  + std::abs(sten(ii-1,jj ,kk+1,ist_ppp))
5387  + std::abs(sten(ii-1,jj+1,kk+1,ist_ppp)) + eps)
5388  + std::abs(sten(ii-1,jj ,kk+1,ist_0p0)) /
5389  ( std::abs(sten(ii-2,jj ,kk ,ist_ppp))
5390  + std::abs(sten(ii-1,jj ,kk ,ist_ppp))
5391  + std::abs(sten(ii-2,jj ,kk+1,ist_ppp))
5392  + std::abs(sten(ii-1,jj ,kk+1,ist_ppp)) + eps)
5393  + std::abs(sten(ii-1,jj+1,kk ,ist_00p)) /
5394  ( std::abs(sten(ii-2,jj ,kk ,ist_ppp))
5395  + std::abs(sten(ii-1,jj ,kk ,ist_ppp))
5396  + std::abs(sten(ii-2,jj+1,kk ,ist_ppp))
5397  + std::abs(sten(ii-1,jj+1,kk ,ist_ppp)) + eps)
5398  + std::abs(sten(ii-1,jj ,kk+1,ist_pp0)) /
5399  ( std::abs(sten(ii-1,jj ,kk ,ist_ppp))
5400  + std::abs(sten(ii-1,jj ,kk+1,ist_ppp)) + eps)
5401  + std::abs(sten(ii-1,jj+1,kk ,ist_p0p)) /
5402  ( std::abs(sten(ii-1,jj ,kk ,ist_ppp))
5403  + std::abs(sten(ii-1,jj+1,kk ,ist_ppp)) + eps)
5404  + std::abs(sten(ii-1,jj ,kk ,ist_0pp)) /
5405  ( std::abs(sten(ii-2,jj ,kk ,ist_ppp))
5406  + std::abs(sten(ii-1,jj ,kk ,ist_ppp)) + eps);
5407  wpmm *= std::abs(sten(ii-1,jj,kk,ist_ppp));
5408  cv += wpmm*fine(ii-1,jj+1,kk+1)*sten(ii-1,jj+1,kk+1,ist_inv);
5409 
5410  Real wmpm = Real(1.0)
5411  + std::abs(sten(ii ,jj-1,kk+1,ist_p00)) /
5412  ( std::abs(sten(ii ,jj-2,kk ,ist_ppp))
5413  + std::abs(sten(ii ,jj-1,kk ,ist_ppp))
5414  + std::abs(sten(ii ,jj-2,kk+1,ist_ppp))
5415  + std::abs(sten(ii ,jj-1,kk+1,ist_ppp)) + eps)
5416  + std::abs(sten(ii+1,jj-1,kk+1,ist_0p0)) /
5417  ( std::abs(sten(ii ,jj-1,kk ,ist_ppp))
5418  + std::abs(sten(ii+1,jj-1,kk ,ist_ppp))
5419  + std::abs(sten(ii ,jj-1,kk+1,ist_ppp))
5420  + std::abs(sten(ii+1,jj-1,kk+1,ist_ppp)) + eps)
5421  + std::abs(sten(ii+1,jj-1,kk ,ist_00p)) /
5422  ( std::abs(sten(ii ,jj-2,kk ,ist_ppp))
5423  + std::abs(sten(ii+1,jj-2,kk ,ist_ppp))
5424  + std::abs(sten(ii ,jj-1,kk ,ist_ppp))
5425  + std::abs(sten(ii+1,jj-1,kk ,ist_ppp)) + eps)
5426  + std::abs(sten(ii ,jj-1,kk+1,ist_pp0)) /
5427  ( std::abs(sten(ii ,jj-1,kk ,ist_ppp))
5428  + std::abs(sten(ii ,jj-1,kk+1,ist_ppp)) + eps)
5429  + std::abs(sten(ii ,jj-1,kk ,ist_p0p)) /
5430  ( std::abs(sten(ii ,jj-2,kk ,ist_ppp))
5431  + std::abs(sten(ii ,jj-1,kk ,ist_ppp)) + eps)
5432  + std::abs(sten(ii+1,jj-1,kk ,ist_0pp)) /
5433  ( std::abs(sten(ii ,jj-1,kk ,ist_ppp))
5434  + std::abs(sten(ii+1,jj-1,kk ,ist_ppp)) + eps);
5435  wmpm *= std::abs(sten(ii ,jj-1,kk ,ist_ppp));
5436  cv += wmpm*fine(ii+1,jj-1,kk+1)*sten(ii+1,jj-1,kk+1,ist_inv);
5437 
5438  Real wppm = Real(1.0)
5439  + std::abs(sten(ii-1,jj-1,kk+1,ist_p00)) /
5440  ( std::abs(sten(ii-1,jj-2,kk ,ist_ppp))
5441  + std::abs(sten(ii-1,jj-1,kk ,ist_ppp))
5442  + std::abs(sten(ii-1,jj-2,kk+1,ist_ppp))
5443  + std::abs(sten(ii-1,jj-1,kk+1,ist_ppp)) + eps)
5444  + std::abs(sten(ii-1,jj-1,kk+1,ist_0p0)) /
5445  ( std::abs(sten(ii-2,jj-1,kk ,ist_ppp))
5446  + std::abs(sten(ii-1,jj-1,kk ,ist_ppp))
5447  + std::abs(sten(ii-2,jj-1,kk+1,ist_ppp))
5448  + std::abs(sten(ii-1,jj-1,kk+1,ist_ppp)) + eps)
5449  + std::abs(sten(ii-1,jj-1,kk ,ist_00p)) /
5450  ( std::abs(sten(ii-2,jj-2,kk ,ist_ppp))
5451  + std::abs(sten(ii-1,jj-2,kk ,ist_ppp))
5452  + std::abs(sten(ii-2,jj-1,kk ,ist_ppp))
5453  + std::abs(sten(ii-1,jj-1,kk ,ist_ppp)) + eps)
5454  + std::abs(sten(ii-1,jj-1,kk+1,ist_pp0)) /
5455  ( std::abs(sten(ii-1,jj-1,kk ,ist_ppp))
5456  + std::abs(sten(ii-1,jj-1,kk+1,ist_ppp)) + eps)
5457  + std::abs(sten(ii-1,jj-1,kk ,ist_p0p)) /
5458  ( std::abs(sten(ii-1,jj-2,kk ,ist_ppp))
5459  + std::abs(sten(ii-1,jj-1,kk ,ist_ppp)) + eps)
5460  + std::abs(sten(ii-1,jj-1,kk ,ist_0pp)) /
5461  ( std::abs(sten(ii-2,jj-1,kk ,ist_ppp))
5462  + std::abs(sten(ii-1,jj-1,kk ,ist_ppp)) + eps);
5463  wppm *= std::abs(sten(ii-1,jj-1,kk ,ist_ppp));
5464  cv += wppm*fine(ii-1,jj-1,kk+1)*sten(ii-1,jj-1,kk+1,ist_inv);
5465 
5466  Real wmmp = Real(1.0)
5467  + std::abs(sten(ii ,jj+1,kk-1,ist_p00)) /
5468  ( std::abs(sten(ii ,jj ,kk-2,ist_ppp))
5469  + std::abs(sten(ii ,jj+1,kk-2,ist_ppp))
5470  + std::abs(sten(ii ,jj ,kk-1,ist_ppp))
5471  + std::abs(sten(ii ,jj+1,kk-1,ist_ppp)) + eps)
5472  + std::abs(sten(ii+1,jj ,kk-1,ist_0p0)) /
5473  ( std::abs(sten(ii ,jj ,kk-2,ist_ppp))
5474  + std::abs(sten(ii+1,jj ,kk-2,ist_ppp))
5475  + std::abs(sten(ii ,jj ,kk-1,ist_ppp))
5476  + std::abs(sten(ii+1,jj ,kk-1,ist_ppp)) + eps)
5477  + std::abs(sten(ii+1,jj+1,kk-1,ist_00p)) /
5478  ( std::abs(sten(ii ,jj ,kk-1,ist_ppp))
5479  + std::abs(sten(ii+1,jj ,kk-1,ist_ppp))
5480  + std::abs(sten(ii ,jj+1,kk-1,ist_ppp))
5481  + std::abs(sten(ii+1,jj+1,kk-1,ist_ppp)) + eps)
5482  + std::abs(sten(ii ,jj ,kk-1,ist_pp0)) /
5483  ( std::abs(sten(ii ,jj ,kk-2,ist_ppp))
5484  + std::abs(sten(ii ,jj ,kk-1,ist_ppp)) + eps)
5485  + std::abs(sten(ii ,jj+1,kk-1,ist_p0p)) /
5486  ( std::abs(sten(ii ,jj ,kk-1,ist_ppp))
5487  + std::abs(sten(ii ,jj+1,kk-1,ist_ppp)) + eps)
5488  + std::abs(sten(ii+1,jj ,kk-1,ist_0pp)) /
5489  ( std::abs(sten(ii ,jj ,kk-1,ist_ppp))
5490  + std::abs(sten(ii+1,jj ,kk-1,ist_ppp)) + eps);
5491  wmmp *= std::abs(sten(ii ,jj ,kk-1,ist_ppp));
5492  cv += wmmp*fine(ii+1,jj+1,kk-1)*sten(ii+1,jj+1,kk-1,ist_inv);
5493 
5494  Real wpmp = Real(1.0)
5495  + std::abs(sten(ii-1,jj+1,kk-1,ist_p00)) /
5496  ( std::abs(sten(ii-1,jj ,kk-2,ist_ppp))
5497  + std::abs(sten(ii-1,jj+1,kk-2,ist_ppp))
5498  + std::abs(sten(ii-1,jj ,kk-1,ist_ppp))
5499  + std::abs(sten(ii-1,jj+1,kk-1,ist_ppp)) + eps)
5500  + std::abs(sten(ii-1,jj ,kk-1,ist_0p0)) /
5501  ( std::abs(sten(ii-2,jj ,kk-2,ist_ppp))
5502  + std::abs(sten(ii-1,jj ,kk-2,ist_ppp))
5503  + std::abs(sten(ii-2,jj ,kk-1,ist_ppp))
5504  + std::abs(sten(ii-1,jj ,kk-1,ist_ppp)) + eps)
5505  + std::abs(sten(ii-1,jj+1,kk-1,ist_00p)) /
5506  ( std::abs(sten(ii-2,jj ,kk-1,ist_ppp))
5507  + std::abs(sten(ii-1,jj ,kk-1,ist_ppp))
5508  + std::abs(sten(ii-2,jj+1,kk-1,ist_ppp))
5509  + std::abs(sten(ii-1,jj+1,kk-1,ist_ppp)) + eps)
5510  + std::abs(sten(ii-1,jj ,kk-1,ist_pp0)) /
5511  ( std::abs(sten(ii-1,jj ,kk-2,ist_ppp))
5512  + std::abs(sten(ii-1,jj ,kk-1,ist_ppp)) + eps)
5513  + std::abs(sten(ii-1,jj+1,kk-1,ist_p0p)) /
5514  ( std::abs(sten(ii-1,jj ,kk-1,ist_ppp))
5515  + std::abs(sten(ii-1,jj+1,kk-1,ist_ppp)) + eps)
5516  + std::abs(sten(ii-1,jj ,kk-1,ist_0pp)) /
5517  ( std::abs(sten(ii-2,jj ,kk-1,ist_ppp))
5518  + std::abs(sten(ii-1,jj ,kk-1,ist_ppp)) + eps);
5519  wpmp *= std::abs(sten(ii-1,jj ,kk-1,ist_ppp));
5520  cv += wpmp*fine(ii-1,jj+1,kk-1)*sten(ii-1,jj+1,kk-1,ist_inv);
5521 
5522  Real wmpp = Real(1.0)
5523  + std::abs(sten(ii ,jj-1,kk-1,ist_p00)) /
5524  ( std::abs(sten(ii ,jj-2,kk-2,ist_ppp))
5525  + std::abs(sten(ii ,jj-1,kk-2,ist_ppp))
5526  + std::abs(sten(ii ,jj-2,kk-1,ist_ppp))
5527  + std::abs(sten(ii ,jj-1,kk-1,ist_ppp)) + eps)
5528  + std::abs(sten(ii+1,jj-1,kk-1,ist_0p0)) /
5529  ( std::abs(sten(ii ,jj-1,kk-2,ist_ppp))
5530  + std::abs(sten(ii+1,jj-1,kk-2,ist_ppp))
5531  + std::abs(sten(ii ,jj-1,kk-1,ist_ppp))
5532  + std::abs(sten(ii+1,jj-1,kk-1,ist_ppp)) + eps)
5533  + std::abs(sten(ii+1,jj-1,kk-1,ist_00p)) /
5534  ( std::abs(sten(ii ,jj-2,kk-1,ist_ppp))
5535  + std::abs(sten(ii+1,jj-2,kk-1,ist_ppp))
5536  + std::abs(sten(ii ,jj-1,kk-1,ist_ppp))
5537  + std::abs(sten(ii+1,jj-1,kk-1,ist_ppp)) + eps)
5538  + std::abs(sten(ii ,jj-1,kk-1,ist_pp0)) /
5539  ( std::abs(sten(ii ,jj-1,kk-2,ist_ppp))
5540  + std::abs(sten(ii ,jj-1,kk-1,ist_ppp)) + eps)
5541  + std::abs(sten(ii ,jj-1,kk-1,ist_p0p)) /
5542  ( std::abs(sten(ii ,jj-2,kk-1,ist_ppp))
5543  + std::abs(sten(ii ,jj-1,kk-1,ist_ppp)) + eps)
5544  + std::abs(sten(ii+1,jj-1,kk-1,ist_0pp)) /
5545  ( std::abs(sten(ii ,jj-1,kk-1,ist_ppp))
5546  + std::abs(sten(ii+1,jj-1,kk-1,ist_ppp)) + eps);
5547  wmpp *= std::abs(sten(ii ,jj-1,kk-1,ist_ppp));
5548  cv += wmpp*fine(ii+1,jj-1,kk-1)*sten(ii+1,jj-1,kk-1,ist_inv);
5549 
5550  Real wppp = Real(1.0)
5551  + std::abs(sten(ii-1,jj-1,kk-1,ist_p00)) /
5552  ( std::abs(sten(ii-1,jj-2,kk-2,ist_ppp))
5553  + std::abs(sten(ii-1,jj-1,kk-2,ist_ppp))
5554  + std::abs(sten(ii-1,jj-2,kk-1,ist_ppp))
5555  + std::abs(sten(ii-1,jj-1,kk-1,ist_ppp)) + eps)
5556  + std::abs(sten(ii-1,jj-1,kk-1,ist_0p0)) /
5557  ( std::abs(sten(ii-2,jj-1,kk-2,ist_ppp))
5558  + std::abs(sten(ii-1,jj-1,kk-2,ist_ppp))
5559  + std::abs(sten(ii-2,jj-1,kk-1,ist_ppp))
5560  + std::abs(sten(ii-1,jj-1,kk-1,ist_ppp)) + eps)
5561  + std::abs(sten(ii-1,jj-1,kk-1,ist_00p)) /
5562  ( std::abs(sten(ii-2,jj-2,kk-1,ist_ppp))
5563  + std::abs(sten(ii-1,jj-2,kk-1,ist_ppp))
5564  + std::abs(sten(ii-2,jj-1,kk-1,ist_ppp))
5565  + std::abs(sten(ii-1,jj-1,kk-1,ist_ppp)) + eps)
5566  + std::abs(sten(ii-1,jj-1,kk-1,ist_pp0)) /
5567  ( std::abs(sten(ii-1,jj-1,kk-2,ist_ppp))
5568  + std::abs(sten(ii-1,jj-1,kk-1,ist_ppp)) + eps)
5569  + std::abs(sten(ii-1,jj-1,kk-1,ist_p0p)) /
5570  ( std::abs(sten(ii-1,jj-2,kk-1,ist_ppp))
5571  + std::abs(sten(ii-1,jj-1,kk-1,ist_ppp)) + eps)
5572  + std::abs(sten(ii-1,jj-1,kk-1,ist_0pp)) /
5573  ( std::abs(sten(ii-2,jj-1,kk-1,ist_ppp))
5574  + std::abs(sten(ii-1,jj-1,kk-1,ist_ppp)) + eps);
5575  wppp *= std::abs(sten(ii-1,jj-1,kk-1,ist_ppp));
5576  cv += wppp*fine(ii-1,jj-1,kk-1)*sten(ii-1,jj-1,kk-1,ist_inv);
5577 
5578  crse(i,j,k) = cv * Real(0.125);
5579  }
5580 }
5581 
5582 #ifdef AMREX_USE_EB
5583 
5584 namespace nodelap_detail {
5585 
5586  constexpr int i_S_x = 0;
5587  constexpr int i_S_y = 1;
5588  constexpr int i_S_z = 2;
5589  constexpr int i_S_x2 = 3;
5590  constexpr int i_S_y2 = 4;
5591  constexpr int i_S_z2 = 5;
5592  constexpr int i_S_x_y = 6;
5593  constexpr int i_S_x_z = 7;
5594  constexpr int i_S_y_z = 8;
5595  constexpr int i_S_x2_y = 9;
5596  constexpr int i_S_x2_z = 10;
5597  constexpr int i_S_x_y2 = 11;
5598  constexpr int i_S_y2_z = 12;
5599  constexpr int i_S_x_z2 = 13;
5600  constexpr int i_S_y_z2 = 14;
5601  constexpr int i_S_x2_y2 = 15;
5602  constexpr int i_S_x2_z2 = 16;
5603  constexpr int i_S_y2_z2 = 17;
5604  constexpr int i_S_xyz = 18;
5605  constexpr int n_Sintg = 19;
5606 
5607  constexpr int i_c_xmym = 0;
5608  constexpr int i_c_xmyb = 1;
5609  constexpr int i_c_xmyp = 2;
5610  constexpr int i_c_xbym = 3;
5611  constexpr int i_c_xbyb = 4;
5612  constexpr int i_c_xbyp = 5;
5613  constexpr int i_c_xpym = 6;
5614  constexpr int i_c_xpyb = 7;
5615  constexpr int i_c_xpyp = 8;
5616  constexpr int i_c_xmzm = 9;
5617  constexpr int i_c_xmzb = 10;
5618  constexpr int i_c_xmzp = 11;
5619  constexpr int i_c_xbzm = 12;
5620  constexpr int i_c_xbzb = 13;
5621  constexpr int i_c_xbzp = 14;
5622  constexpr int i_c_xpzm = 15;
5623  constexpr int i_c_xpzb = 16;
5624  constexpr int i_c_xpzp = 17;
5625  constexpr int i_c_ymzm = 18;
5626  constexpr int i_c_ymzb = 19;
5627  constexpr int i_c_ymzp = 20;
5628  constexpr int i_c_ybzm = 21;
5629  constexpr int i_c_ybzb = 22;
5630  constexpr int i_c_ybzp = 23;
5631  constexpr int i_c_ypzm = 24;
5632  constexpr int i_c_ypzb = 25;
5633  constexpr int i_c_ypzp = 26;
5634  constexpr int n_conn = 27;
5635 
5636  constexpr int i_B_x = 0;
5637  constexpr int i_B_y = 1;
5638  constexpr int i_B_z = 2;
5639  constexpr int i_B_x_y = 3;
5640  constexpr int i_B_x_z = 4;
5641  constexpr int i_B_y_z = 5;
5642  constexpr int i_B_xyz = 6;
5643  constexpr int numSurfIntgs = 7;
5644 
5645 }
5646 
5648 void mlndlap_set_connection (int i, int j, int k, Array4<Real> const& conn,
5649  Array4<Real const> const& intg, Array4<Real const> const& vol,
5650  Array4<EBCellFlag const> const& flag) noexcept
5651 {
5652  using namespace nodelap_detail;
5653 
5654  if (flag(i,j,k).isCovered()) {
5655  for (int n = 0; n < n_conn; ++n) { conn(i,j,k,n) = Real(0.); }
5656  } else if (flag(i,j,k).isRegular() || vol(i,j,k) >= almostone) {
5657  for (int n = 0; n < n_conn; ++n) { conn(i,j,k,n) = Real(1.); }
5658  } else {
5659  // Scaled by 9
5660  conn(i,j,k,i_c_xmym) = Real(0.5625)*vol(i,j,k)
5661  + Real(2.25)*(-intg(i,j,k,i_S_x ) - intg(i,j,k,i_S_y)
5662  +intg(i,j,k,i_S_x2) + intg(i,j,k,i_S_y2))
5663  + Real(9.)*( intg(i,j,k,i_S_x_y ) - intg(i,j,k,i_S_x2_y)
5664  -intg(i,j,k,i_S_x_y2) + intg(i,j,k,i_S_x2_y2));
5665 
5666  // Scaled by 18
5667  conn(i,j,k,i_c_xmyb) = Real(1.125)*vol(i,j,k)
5668  + Real(4.5)*(-intg(i,j,k,i_S_x) + intg(i,j,k,i_S_x2) - intg(i,j,k,i_S_y2))
5669  + Real(18.)*( intg(i,j,k,i_S_x_y2) - intg(i,j,k,i_S_x2_y2));
5670 
5671  // Scaled by 9
5672  conn(i,j,k,i_c_xmyp) = Real(0.5625)*vol(i,j,k)
5673  + Real(2.25)*(-intg(i,j,k,i_S_x ) + intg(i,j,k,i_S_y)
5674  +intg(i,j,k,i_S_x2) + intg(i,j,k,i_S_y2))
5675  + Real(9.)*(-intg(i,j,k,i_S_x_y ) + intg(i,j,k,i_S_x2_y)
5676  -intg(i,j,k,i_S_x_y2) + intg(i,j,k,i_S_x2_y2));
5677 
5678  // Scaled by 18
5679  conn(i,j,k,i_c_xbym) = Real(1.125)*vol(i,j,k)
5680  + Real(4.5)*(-intg(i,j,k,i_S_y) - intg(i,j,k,i_S_x2) + intg(i,j,k,i_S_y2))
5681  + Real(18.)*(intg(i,j,k,i_S_x2_y) - intg(i,j,k,i_S_x2_y2));
5682 
5683  // Scaled by 36
5684  conn(i,j,k,i_c_xbyb) = Real(2.25)*vol(i,j,k)
5685  + Real(9.)*(-intg(i,j,k,i_S_x2) - intg(i,j,k,i_S_y2))
5686  + Real(36.)*intg(i,j,k,i_S_x2_y2);
5687 
5688  // Scaled by 18
5689  conn(i,j,k,i_c_xbyp) = Real(1.125)*vol(i,j,k)
5690  + Real(4.5)*( intg(i,j,k,i_S_y) - intg(i,j,k,i_S_x2) + intg(i,j,k,i_S_y2))
5691  + Real(18.)*(-intg(i,j,k,i_S_x2_y) - intg(i,j,k,i_S_x2_y2));
5692 
5693  // Scaled by 9
5694  conn(i,j,k,i_c_xpym) = Real(0.5625)*vol(i,j,k)
5695  + Real(2.25)*( intg(i,j,k,i_S_x ) - intg(i,j,k,i_S_y)
5696  +intg(i,j,k,i_S_x2) + intg(i,j,k,i_S_y2))
5697  + Real(9.)*(-intg(i,j,k,i_S_x_y ) - intg(i,j,k,i_S_x2_y)
5698  +intg(i,j,k,i_S_x_y2) + intg(i,j,k,i_S_x2_y2));
5699 
5700  // Scaled by 18
5701  conn(i,j,k,i_c_xpyb) = Real(1.125)*vol(i,j,k)
5702  + Real(4.5)*( intg(i,j,k,i_S_x) + intg(i,j,k,i_S_x2) - intg(i,j,k,i_S_y2))
5703  + Real(18.)*(-intg(i,j,k,i_S_x_y2) - intg(i,j,k,i_S_x2_y2));
5704 
5705  // Scaled by 9
5706  conn(i,j,k,i_c_xpyp) = Real(0.5625)*vol(i,j,k)
5707  + Real(2.25)*( intg(i,j,k,i_S_x ) + intg(i,j,k,i_S_y)
5708  +intg(i,j,k,i_S_x2) + intg(i,j,k,i_S_y2))
5709  + Real(9.)*( intg(i,j,k,i_S_x_y ) + intg(i,j,k,i_S_x2_y)
5710  +intg(i,j,k,i_S_x_y2) + intg(i,j,k,i_S_x2_y2));
5711 
5712  // Scaled by 9
5713  conn(i,j,k,i_c_xmzm) = Real(0.5625)*vol(i,j,k)
5714  + Real(2.25)*(-intg(i,j,k,i_S_x) - intg(i,j,k,i_S_z)
5715  +intg(i,j,k,i_S_x2) + intg(i,j,k,i_S_z2))
5716  + Real(9.)*(intg(i,j,k,i_S_x_z) - intg(i,j,k,i_S_x2_z)
5717  -intg(i,j,k,i_S_x_z2) + intg(i,j,k,i_S_x2_z2));
5718 
5719  // Scaled by 18
5720  conn(i,j,k,i_c_xmzb) = Real(1.125)*vol(i,j,k)
5721  + Real(4.5)*(-intg(i,j,k,i_S_x) + intg(i,j,k,i_S_x2) - intg(i,j,k,i_S_z2))
5722  + Real(18.)*(intg(i,j,k,i_S_x_z2) - intg(i,j,k,i_S_x2_z2));
5723 
5724  // Scaled by 9
5725  conn(i,j,k,i_c_xmzp) = Real(0.5625)*vol(i,j,k)
5726  + Real(2.25)*(-intg(i,j,k,i_S_x ) + intg(i,j,k,i_S_z)
5727  +intg(i,j,k,i_S_x2) + intg(i,j,k,i_S_z2))
5728  + Real(9.)*(-intg(i,j,k,i_S_x_z ) + intg(i,j,k,i_S_x2_z)
5729  -intg(i,j,k,i_S_x_z2) + intg(i,j,k,i_S_x2_z2));
5730 
5731  // Scaled by 18
5732  conn(i,j,k,i_c_xbzm) = Real(1.125)*vol(i,j,k)
5733  + Real(4.5)*(-intg(i,j,k,i_S_z) - intg(i,j,k,i_S_x2) + intg(i,j,k,i_S_z2))
5734  + Real(18.)*(intg(i,j,k,i_S_x2_z) - intg(i,j,k,i_S_x2_z2));
5735 
5736  // Scaled by 18
5737  conn(i,j,k,i_c_xbzb) = Real(2.25)*vol(i,j,k)
5738  + Real(9.)*(-intg(i,j,k,i_S_x2) - intg(i,j,k,i_S_z2))
5739  + Real(36.)*intg(i,j,k,i_S_x2_z2);
5740 
5741  // Scaled by 18
5742  conn(i,j,k,i_c_xbzp) = Real(1.125)*vol(i,j,k)
5743  + Real(4.5)*( intg(i,j,k,i_S_z) - intg(i,j,k,i_S_x2) + intg(i,j,k,i_S_z2))
5744  + Real(18.)*(-intg(i,j,k,i_S_x2_z) - intg(i,j,k,i_S_x2_z2));
5745 
5746  // Scaled by 9
5747  conn(i,j,k,i_c_xpzm) = Real(0.5625)*vol(i,j,k)
5748  + Real(2.25)*( intg(i,j,k,i_S_x ) - intg(i,j,k,i_S_z)
5749  +intg(i,j,k,i_S_x2) + intg(i,j,k,i_S_z2))
5750  + Real(9.)*(-intg(i,j,k,i_S_x_z ) - intg(i,j,k,i_S_x2_z)
5751  +intg(i,j,k,i_S_x_z2) + intg(i,j,k,i_S_x2_z2));
5752 
5753  // Scaled by 18
5754  conn(i,j,k,i_c_xpzb) = Real(1.125)*vol(i,j,k)
5755  + Real(4.5)*( intg(i,j,k,i_S_x ) + intg(i,j,k,i_S_x2 ) - intg(i,j,k,i_S_z2))
5756  + Real(18.)*(-intg(i,j,k,i_S_x_z2) - intg(i,j,k,i_S_x2_z2));
5757 
5758  // Scaled by 9
5759  conn(i,j,k,i_c_xpzp) = Real(0.5625)*vol(i,j,k)
5760  + Real(2.25)*( intg(i,j,k,i_S_x ) + intg(i,j,k,i_S_z)
5761  +intg(i,j,k,i_S_x2) + intg(i,j,k,i_S_z2))
5762  + Real(9.)*( intg(i,j,k,i_S_x_z ) + intg(i,j,k,i_S_x2_z)
5763  +intg(i,j,k,i_S_x_z2) + intg(i,j,k,i_S_x2_z2));
5764 
5765  // Scaled by 9
5766  conn(i,j,k,i_c_ymzm) = Real(0.5625)*vol(i,j,k)
5767  + Real(2.25)*(-intg(i,j,k,i_S_y) - intg(i,j,k,i_S_z)
5768  +intg(i,j,k,i_S_y2) + intg(i,j,k,i_S_z2))
5769  + Real(9.)*(intg(i,j,k,i_S_y_z) - intg(i,j,k,i_S_y2_z)
5770  -intg(i,j,k,i_S_y_z2) + intg(i,j,k,i_S_y2_z2));
5771 
5772  // Scaled by 18
5773  conn(i,j,k,i_c_ymzb) = Real(1.125)*vol(i,j,k)
5774  + Real(4.5)*(-intg(i,j,k,i_S_y) + intg(i,j,k,i_S_y2) - intg(i,j,k,i_S_z2))
5775  + Real(18.)*(intg(i,j,k,i_S_y_z2) - intg(i,j,k,i_S_y2_z2));
5776 
5777  // Scaled by 9
5778  conn(i,j,k,i_c_ymzp) = Real(0.5625)*vol(i,j,k)
5779  + Real(2.25)*(-intg(i,j,k,i_S_y ) + intg(i,j,k,i_S_z)
5780  +intg(i,j,k,i_S_y2) + intg(i,j,k,i_S_z2))
5781  + Real(9.)*(-intg(i,j,k,i_S_y_z ) + intg(i,j,k,i_S_y2_z)
5782  -intg(i,j,k,i_S_y_z2) + intg(i,j,k,i_S_y2_z2));
5783 
5784  // Scaled by 18
5785  conn(i,j,k,i_c_ybzm) = Real(1.125)*vol(i,j,k)
5786  + Real(4.5)*(-intg(i,j,k,i_S_z) - intg(i,j,k,i_S_y2) + intg(i,j,k,i_S_z2))
5787  + Real(18.)*(intg(i,j,k,i_S_y2_z) - intg(i,j,k,i_S_y2_z2));
5788 
5789  // Scaled by 36
5790  conn(i,j,k,i_c_ybzb) = Real(2.25)*vol(i,j,k)
5791  + Real(9.)*(-intg(i,j,k,i_S_y2) - intg(i,j,k,i_S_z2))
5792  + Real(36.)*intg(i,j,k,i_S_y2_z2);
5793 
5794  // Scaled by 18
5795  conn(i,j,k,i_c_ybzp) = Real(1.125)*vol(i,j,k)
5796  + Real(4.5)*( intg(i,j,k,i_S_z) - intg(i,j,k,i_S_y2) + intg(i,j,k,i_S_z2))
5797  + Real(18.)*(-intg(i,j,k,i_S_y2_z) - intg(i,j,k,i_S_y2_z2));
5798 
5799  // Scaled by 9
5800  conn(i,j,k,i_c_ypzm) = Real(0.5625)*vol(i,j,k)
5801  + Real(2.25)*( intg(i,j,k,i_S_y ) - intg(i,j,k,i_S_z)
5802  +intg(i,j,k,i_S_y2) + intg(i,j,k,i_S_z2))
5803  + Real(9.)*(-intg(i,j,k,i_S_y_z ) - intg(i,j,k,i_S_y2_z)
5804  +intg(i,j,k,i_S_y_z2) + intg(i,j,k,i_S_y2_z2));
5805 
5806  // Scaled by 18
5807  conn(i,j,k,i_c_ypzb) = Real(1.125)*vol(i,j,k)
5808  + Real(4.5)*( intg(i,j,k,i_S_y ) + intg(i,j,k,i_S_y2) - intg(i,j,k,i_S_z2))
5809  + Real(18.)*(-intg(i,j,k,i_S_y_z2) - intg(i,j,k,i_S_y2_z2));
5810 
5811  // Scaled by 9
5812  conn(i,j,k,i_c_ypzp) = Real(0.5625)*vol(i,j,k)
5813  + Real(2.25)*( intg(i,j,k,i_S_y ) + intg(i,j,k,i_S_z)
5814  +intg(i,j,k,i_S_y2) + intg(i,j,k,i_S_z2))
5815  + Real(9.)*( intg(i,j,k,i_S_y_z ) + intg(i,j,k,i_S_y2_z)
5816  +intg(i,j,k,i_S_y_z2) + intg(i,j,k,i_S_y2_z2));
5817  }
5818 }
5819 
5821 void mlndlap_set_stencil_eb (int i, int j, int k, Array4<Real> const& sten,
5822  Array4<Real const> const& sig, Array4<Real const> const& conn,
5823  GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
5824 {
5825  using namespace nodelap_detail;
5826 
5827  Real facx = Real(1./36.)*dxinv[0]*dxinv[0];
5828  Real facy = Real(1./36.)*dxinv[1]*dxinv[1];
5829  Real facz = Real(1./36.)*dxinv[2]*dxinv[2];
5830 
5831  // i+1,j,k
5832  sten(i,j,k,ist_p00) = (
5833  sig(i,j ,k )*(Real(4.)*facx*conn(i,j ,k ,i_c_ymzm) - Real(2.)*facy*conn(i,j ,k ,i_c_xbzm) - Real(2.)*facz*conn(i,j ,k ,i_c_xbym) ) +
5834  sig(i,j-1,k )*(Real(4.)*facx*conn(i,j-1,k ,i_c_ypzm) - Real(2.)*facy*conn(i,j-1,k ,i_c_xbzm) - Real(2.)*facz*conn(i,j-1,k ,i_c_xbyp) ) +
5835  sig(i,j ,k-1)*(Real(4.)*facx*conn(i,j ,k-1,i_c_ymzp) - Real(2.)*facy*conn(i,j ,k-1,i_c_xbzp) - Real(2.)*facz*conn(i,j ,k-1,i_c_xbym) ) +
5836  sig(i,j-1,k-1)*(Real(4.)*facx*conn(i,j-1,k-1,i_c_ypzp) - Real(2.)*facy*conn(i,j-1,k-1,i_c_xbzp) - Real(2.)*facz*conn(i,j-1,k-1,i_c_xbyp) ) );
5837 
5838  // i,j+1,k
5839  sten(i,j,k,ist_0p0) = (
5840  sig(i ,j,k )*(Real(-2.)*facx*conn(i ,j,k ,i_c_ybzm) + Real(4.)*facy*conn(i ,j,k ,i_c_xmzm) - Real(2.)*facz*conn(i ,j,k ,i_c_xmyb) ) +
5841  sig(i-1,j,k )*(Real(-2.)*facx*conn(i-1,j,k ,i_c_ybzm) + Real(4.)*facy*conn(i-1,j,k ,i_c_xpzm) - Real(2.)*facz*conn(i-1,j,k ,i_c_xpyb) ) +
5842  sig(i ,j,k-1)*(Real(-2.)*facx*conn(i ,j,k-1,i_c_ybzp) + Real(4.)*facy*conn(i ,j,k-1,i_c_xmzp) - Real(2.)*facz*conn(i ,j,k-1,i_c_xmyb) ) +
5843  sig(i-1,j,k-1)*(Real(-2.)*facx*conn(i-1,j,k-1,i_c_ybzp) + Real(4.)*facy*conn(i-1,j,k-1,i_c_xpzp) - Real(2.)*facz*conn(i-1,j,k-1,i_c_xpyb) ) );
5844 
5845  // i,j,k+1
5846  sten(i,j,k,ist_00p) = (
5847  sig(i ,j ,k)*(Real(-2.)*facx*conn(i ,j ,k,i_c_ymzb) - Real(2.)*facy*conn(i ,j ,k,i_c_xmzb) + Real(4.)*facz*conn(i ,j ,k,i_c_xmym) ) +
5848  sig(i-1,j ,k)*(Real(-2.)*facx*conn(i-1,j ,k,i_c_ymzb) - Real(2.)*facy*conn(i-1,j ,k,i_c_xpzb) + Real(4.)*facz*conn(i-1,j ,k,i_c_xpym) ) +
5849  sig(i ,j-1,k)*(Real(-2.)*facx*conn(i ,j-1,k,i_c_ypzb) - Real(2.)*facy*conn(i ,j-1,k,i_c_xmzb) + Real(4.)*facz*conn(i ,j-1,k,i_c_xmyp) ) +
5850  sig(i-1,j-1,k)*(Real(-2.)*facx*conn(i-1,j-1,k,i_c_ypzb) - Real(2.)*facy*conn(i-1,j-1,k,i_c_xpzb) + Real(4.)*facz*conn(i-1,j-1,k,i_c_xpyp) ) );
5851 
5852  // i+1,j+1,k
5853  sten(i,j,k,ist_pp0) = (
5854  sig(i,j,k )*(Real(2.)*facx*conn(i,j,k ,i_c_ybzm) + Real(2.)*facy*conn(i,j,k ,i_c_xbzm) - facz*conn(i,j,k ,i_c_xbyb) ) +
5855  sig(i,j,k-1)*(Real(2.)*facx*conn(i,j,k-1,i_c_ybzp) + Real(2.)*facy*conn(i,j,k-1,i_c_xbzp) - facz*conn(i,j,k-1,i_c_xbyb) ) );
5856 
5857  // i+1,j,k+1
5858  sten(i,j,k,ist_p0p) = (
5859  sig(i,j,k )*(Real(2.)*facx*conn(i,j,k ,i_c_ymzb) - facy*conn(i,j,k ,i_c_xbzb) + Real(2.)*facz*conn(i,j,k ,i_c_xbym) ) +
5860  sig(i,j-1,k)*(Real(2.)*facx*conn(i,j-1,k,i_c_ypzb) - facy*conn(i,j-1,k,i_c_xbzb) + Real(2.)*facz*conn(i,j-1,k,i_c_xbyp) ) );
5861 
5862  // i,j+1,k+1
5863  sten(i,j,k,ist_0pp) = (
5864  sig(i ,j,k)*(-facx*conn(i ,j,k,i_c_ybzb) + Real(2.)*facy*conn(i ,j,k,i_c_xmzb) + Real(2.)*facz*conn(i ,j,k,i_c_xmyb) ) +
5865  sig(i-1,j,k)*(-facx*conn(i-1,j,k,i_c_ybzb) + Real(2.)*facy*conn(i-1,j,k,i_c_xpzb) + Real(2.)*facz*conn(i-1,j,k,i_c_xpyb) ) );
5866 
5867  // i+1,j+1,k+1
5868  sten(i,j,k,ist_ppp) = sig(i,j,k) * (facx*conn(i,j,k,i_c_ybzb) + facy*conn(i,j,k,i_c_xbzb) + facz*conn(i,j,k,i_c_xbyb) );
5869 }
5870 
5872 void mlndlap_divu_eb (int i, int j, int k, Array4<Real> const& rhs, Array4<Real const> const& vel,
5873  Array4<Real const> const& vfrac, Array4<Real const> const& intg,
5874  Array4<int const> const& msk, GpuArray<Real,AMREX_SPACEDIM> const& dxinv,
5875  Box const& nodal_domain,
5876  GpuArray<LinOpBCType, AMREX_SPACEDIM> const& bclo,
5877  GpuArray<LinOpBCType, AMREX_SPACEDIM> const& bchi) noexcept
5878 {
5879  using namespace nodelap_detail;
5880 
5881  Real facx = Real(0.25)*dxinv[0];
5882  Real facy = Real(0.25)*dxinv[1];
5883  Real facz = Real(0.25)*dxinv[2];
5884 
5885  const auto domlo = amrex::lbound(nodal_domain);
5886  const auto domhi = amrex::ubound(nodal_domain);
5887 
5888  if (!msk(i,j,k)) {
5889 
5890  Real zero_ilo = Real(1.0);
5891  Real zero_ihi = Real(1.0);
5892  Real zero_jlo = Real(1.0);
5893  Real zero_jhi = Real(1.0);
5894  Real zero_klo = Real(1.0);
5895  Real zero_khi = Real(1.0);
5896 
5897  // The nodal divergence operator should not see the tangential velocity
5898  // at an inflow face
5899  if ((bclo[0] == LinOpBCType::Neumann || bclo[0] == LinOpBCType::inflow)
5900  && i == domlo.x)
5901  {
5902  zero_ilo = Real(0.0);
5903  }
5904  if ((bchi[0] == LinOpBCType::Neumann || bchi[0] == LinOpBCType::inflow)
5905  && i == domhi.x)
5906  {
5907  zero_ihi = Real(0.0);
5908  }
5909  if ((bclo[1] == LinOpBCType::Neumann || bclo[1] == LinOpBCType::inflow)
5910  && j == domlo.y)
5911  {
5912  zero_jlo = Real(0.0);
5913  }
5914  if ((bchi[1] == LinOpBCType::Neumann || bchi[1] == LinOpBCType::inflow)
5915  && j == domhi.y)
5916  {
5917  zero_jhi = Real(0.0);
5918  }
5919  if ((bclo[2] == LinOpBCType::Neumann || bclo[2] == LinOpBCType::inflow)
5920  && k == domlo.z)
5921  {
5922  zero_klo = Real(0.0);
5923  }
5924  if ((bchi[2] == LinOpBCType::Neumann || bchi[2] == LinOpBCType::inflow)
5925  && k == domhi.z)
5926  {
5927  zero_khi = Real(0.0);
5928  }
5929 
5930  rhs(i,j,k) = facx*(
5931  vel(i-1,j-1,k ,0)*( -vfrac(i-1,j-1,k )
5932  -Real(2.)*intg(i-1,j-1,k ,i_S_y)
5933  +Real(2.)*intg(i-1,j-1,k ,i_S_z)
5934  +Real(4.)*intg(i-1,j-1,k ,i_S_y_z))*zero_jlo*zero_khi
5935  +vel(i ,j-1,k ,0)*( vfrac(i ,j-1,k )
5936  +Real(2.)*intg(i ,j-1,k ,i_S_y)
5937  -Real(2.)*intg(i ,j-1,k ,i_S_z)
5938  -Real(4.)*intg(i ,j-1,k ,i_S_y_z))*zero_jlo*zero_khi
5939  +vel(i-1,j ,k ,0)*( -vfrac(i-1,j ,k )
5940  +Real(2.)*intg(i-1,j ,k ,i_S_y)
5941  +Real(2.)*intg(i-1,j ,k ,i_S_z)
5942  -Real(4.)*intg(i-1,j ,k ,i_S_y_z))*zero_jhi*zero_khi
5943  +vel(i ,j ,k ,0)*( vfrac(i ,j ,k )
5944  -Real(2.)*intg(i ,j ,k ,i_S_y)
5945  -Real(2.)*intg(i ,j ,k ,i_S_z)
5946  +Real(4.)*intg(i ,j ,k ,i_S_y_z))*zero_jhi*zero_khi
5947  +vel(i-1,j-1,k-1,0)*( -vfrac(i-1,j-1,k-1)
5948  -Real(2.)*intg(i-1,j-1,k-1,i_S_y)
5949  -Real(2.)*intg(i-1,j-1,k-1,i_S_z)
5950  -Real(4.)*intg(i-1,j-1,k-1,i_S_y_z))*zero_jlo*zero_klo
5951  +vel(i ,j-1,k-1,0)*( vfrac(i ,j-1,k-1)
5952  +Real(2.)*intg(i ,j-1,k-1,i_S_y)
5953  +Real(2.)*intg(i ,j-1,k-1,i_S_z)
5954  +Real(4.)*intg(i ,j-1,k-1,i_S_y_z))*zero_jlo*zero_klo
5955  +vel(i-1,j ,k-1,0)*( -vfrac(i-1,j ,k-1)
5956  +Real(2.)*intg(i-1,j ,k-1,i_S_y)
5957  -Real(2.)*intg(i-1,j ,k-1,i_S_z)
5958  +Real(4.)*intg(i-1,j ,k-1,i_S_y_z))*zero_jhi*zero_klo
5959  +vel(i ,j ,k-1,0)*( vfrac(i ,j ,k-1)
5960  -Real(2.)*intg(i ,j ,k-1,i_S_y)
5961  +Real(2.)*intg(i ,j ,k-1,i_S_z)
5962  -Real(4.)*intg(i ,j ,k-1,i_S_y_z))*zero_jhi*zero_klo )
5963  + facy*(
5964  vel(i-1,j-1,k ,1)*( -vfrac(i-1,j-1,k )
5965  -Real(2.)*intg(i-1,j-1,k ,i_S_x)
5966  +Real(2.)*intg(i-1,j-1,k ,i_S_z)
5967  +Real(4.)*intg(i-1,j-1,k ,i_S_x_z))*zero_ilo*zero_khi
5968  +vel(i ,j-1,k ,1)*( -vfrac(i ,j-1,k )
5969  +Real(2.)*intg(i ,j-1,k ,i_S_x)
5970  +Real(2.)*intg(i ,j-1,k ,i_S_z)
5971  -Real(4.)*intg(i ,j-1,k ,i_S_x_z))*zero_ihi*zero_khi
5972  +vel(i-1,j ,k ,1)*( vfrac(i-1,j ,k )
5973  +Real(2.)*intg(i-1,j ,k ,i_S_x)
5974  -Real(2.)*intg(i-1,j ,k ,i_S_z)
5975  -Real(4.)*intg(i-1,j ,k ,i_S_x_z))*zero_ilo*zero_khi
5976  +vel(i ,j ,k ,1)*( vfrac(i ,j ,k )
5977  -Real(2.)*intg(i ,j ,k ,i_S_x)
5978  -Real(2.)*intg(i ,j ,k ,i_S_z)
5979  +Real(4.)*intg(i ,j ,k ,i_S_x_z))*zero_ihi*zero_khi
5980  +vel(i-1,j-1,k-1,1)*( -vfrac(i-1,j-1,k-1)
5981  -Real(2.)*intg(i-1,j-1,k-1,i_S_x)
5982  -Real(2.)*intg(i-1,j-1,k-1,i_S_z)
5983  -Real(4.)*intg(i-1,j-1,k-1,i_S_x_z))*zero_ilo*zero_klo
5984  +vel(i ,j-1,k-1,1)*( -vfrac(i ,j-1,k-1)
5985  +Real(2.)*intg(i ,j-1,k-1,i_S_x)
5986  -Real(2.)*intg(i ,j-1,k-1,i_S_z)
5987  +Real(4.)*intg(i ,j-1,k-1,i_S_x_z))*zero_ihi*zero_klo
5988  +vel(i-1,j ,k-1,1)*( vfrac(i-1,j ,k-1)
5989  +Real(2.)*intg(i-1,j ,k-1,i_S_x)
5990  +Real(2.)*intg(i-1,j ,k-1,i_S_z)
5991  +Real(4.)*intg(i-1,j ,k-1,i_S_x_z))*zero_ilo*zero_klo
5992  +vel(i ,j ,k-1,1)*( vfrac(i ,j ,k-1)
5993  -Real(2.)*intg(i ,j ,k-1,i_S_x)
5994  +Real(2.)*intg(i ,j ,k-1,i_S_z)
5995  -Real(4.)*intg(i ,j ,k-1,i_S_x_z))*zero_ihi*zero_klo )
5996  + facz*(
5997  vel(i-1,j-1,k ,2)*( vfrac(i-1,j-1,k )
5998  +Real(2.)*intg(i-1,j-1,k ,i_S_x)
5999  +Real(2.)*intg(i-1,j-1,k ,i_S_y)
6000  +Real(4.)*intg(i-1,j-1,k ,i_S_x_y))*zero_ilo*zero_jlo
6001  +vel(i ,j-1,k ,2)*( vfrac(i ,j-1,k )
6002  -Real(2.)*intg(i ,j-1,k ,i_S_x)
6003  +Real(2.)*intg(i ,j-1,k ,i_S_y)
6004  -Real(4.)*intg(i ,j-1,k ,i_S_x_y))*zero_ihi*zero_jlo
6005  +vel(i-1,j ,k ,2)*( vfrac(i-1,j ,k )
6006  +Real(2.)*intg(i-1,j ,k ,i_S_x)
6007  -Real(2.)*intg(i-1,j ,k ,i_S_y)
6008  -Real(4.)*intg(i-1,j ,k ,i_S_x_y))*zero_ilo*zero_jhi
6009  +vel(i ,j ,k ,2)*( vfrac(i ,j ,k )
6010  -Real(2.)*intg(i ,j ,k ,i_S_x)
6011  -Real(2.)*intg(i ,j ,k ,i_S_y)
6012  +Real(4.)*intg(i ,j ,k ,i_S_x_y))*zero_ihi*zero_jhi
6013  +vel(i-1,j-1,k-1,2)*( -vfrac(i-1,j-1,k-1)
6014  -Real(2.)*intg(i-1,j-1,k-1,i_S_x)
6015  -Real(2.)*intg(i-1,j-1,k-1,i_S_y)
6016  -Real(4.)*intg(i-1,j-1,k-1,i_S_x_y))*zero_ilo*zero_jlo
6017  +vel(i ,j-1,k-1,2)*( -vfrac(i ,j-1,k-1)
6018  +Real(2.)*intg(i ,j-1,k-1,i_S_x)
6019  -Real(2.)*intg(i ,j-1,k-1,i_S_y)
6020  +Real(4.)*intg(i ,j-1,k-1,i_S_x_y))*zero_ihi*zero_jlo
6021  +vel(i-1,j ,k-1,2)*( -vfrac(i-1,j ,k-1)
6022  -Real(2.)*intg(i-1,j ,k-1,i_S_x)
6023  +Real(2.)*intg(i-1,j ,k-1,i_S_y)
6024  +Real(4.)*intg(i-1,j ,k-1,i_S_x_y))*zero_ilo*zero_jhi
6025  +vel(i ,j ,k-1,2)*( -vfrac(i ,j ,k-1)
6026  +Real(2.)*intg(i ,j ,k-1,i_S_x)
6027  +Real(2.)*intg(i ,j ,k-1,i_S_y)
6028  -Real(4.)*intg(i ,j ,k-1,i_S_x_y))*zero_ihi*zero_jhi );
6029  } else {
6030  rhs(i,j,k) = Real(0.);
6031  }
6032 }
6033 
6035 void add_eb_flow_contribution (int i, int j, int k, Array4<Real> const& rhs,
6036  Array4<int const> const& msk, GpuArray<Real,AMREX_SPACEDIM> const& dxinv,
6037  Array4<Real const> const& bareaarr,
6038  Array4<Real const> const& sintg,
6039  Array4<Real const> const& eb_vel_dot_n) noexcept
6040 {
6041  using namespace nodelap_detail;
6042 
6043  Real fac_eb = Real(0.125) * dxinv[0];
6044 
6045  if (!msk(i,j,k)) {
6046  rhs(i,j,k) += fac_eb*(
6047  eb_vel_dot_n(i-1,j-1,k )*( bareaarr(i-1,j-1,k)
6048  +Real(2.)*sintg(i-1,j-1,k ,i_B_x)
6049  +Real(2.)*sintg(i-1,j-1,k ,i_B_y)
6050  +Real(4.)*sintg(i-1,j-1,k ,i_B_x_y)
6051  -Real(2.)*sintg(i-1,j-1,k ,i_B_z)
6052  -Real(4.)*sintg(i-1,j-1,k ,i_B_y_z)
6053  -Real(4.)*sintg(i-1,j-1,k ,i_B_x_z)
6054  -Real(8.)*sintg(i-1,j-1,k ,i_B_xyz))
6055  +eb_vel_dot_n(i ,j-1,k )*( bareaarr(i ,j-1,k)
6056  -Real(2.)*sintg(i ,j-1,k ,i_B_x)
6057  +Real(2.)*sintg(i ,j-1,k ,i_B_y)
6058  -Real(4.)*sintg(i ,j-1,k ,i_B_x_y)
6059  -Real(2.)*sintg(i ,j-1,k ,i_B_z)
6060  -Real(4.)*sintg(i ,j-1,k ,i_B_y_z)
6061  +Real(4.)*sintg(i ,j-1,k ,i_B_x_z)
6062  +Real(8.)*sintg(i ,j-1,k ,i_B_xyz))
6063  +eb_vel_dot_n(i-1,j ,k )*( bareaarr(i-1,j ,k)
6064  +Real(2.)*sintg(i-1,j ,k ,i_B_x)
6065  -Real(2.)*sintg(i-1,j ,k ,i_B_y)
6066  -Real(4.)*sintg(i-1,j ,k ,i_B_x_y)
6067  -Real(2.)*sintg(i-1,j ,k ,i_B_z)
6068  +Real(4.)*sintg(i-1,j ,k ,i_B_y_z)
6069  -Real(4.)*sintg(i-1,j ,k ,i_B_x_z)
6070  +Real(8.)*sintg(i-1,j ,k ,i_B_xyz))
6071  +eb_vel_dot_n(i ,j ,k )*( bareaarr(i ,j ,k)
6072  -Real(2.)*sintg(i ,j ,k ,i_B_x)
6073  -Real(2.)*sintg(i ,j ,k ,i_B_y)
6074  +Real(4.)*sintg(i ,j ,k ,i_B_x_y)
6075  -Real(2.)*sintg(i ,j ,k ,i_B_z)
6076  +Real(4.)*sintg(i ,j ,k ,i_B_y_z)
6077  +Real(4.)*sintg(i ,j ,k ,i_B_x_z)
6078  -Real(8.)*sintg(i ,j ,k ,i_B_xyz))
6079  +eb_vel_dot_n(i-1,j-1,k-1)*( bareaarr(i-1,j-1,k-1)
6080  +Real(2.)*sintg(i-1,j-1,k-1,i_B_x)
6081  +Real(2.)*sintg(i-1,j-1,k-1,i_B_y)
6082  +Real(4.)*sintg(i-1,j-1,k-1,i_B_x_y)
6083  +Real(2.)*sintg(i-1,j-1,k-1,i_B_z)
6084  +Real(4.)*sintg(i-1,j-1,k-1,i_B_y_z)
6085  +Real(4.)*sintg(i-1,j-1,k-1,i_B_x_z)
6086  +Real(8.)*sintg(i-1,j-1,k-1,i_B_xyz))
6087  +eb_vel_dot_n(i ,j-1,k-1)*( bareaarr(i ,j-1,k-1)
6088  -Real(2.)*sintg(i ,j-1,k-1,i_B_x)
6089  +Real(2.)*sintg(i ,j-1,k-1,i_B_y)
6090  -Real(4.)*sintg(i ,j-1,k-1,i_B_x_y)
6091  +Real(2.)*sintg(i ,j-1,k-1,i_B_z)
6092  +Real(4.)*sintg(i ,j-1,k-1,i_B_y_z)
6093  -Real(4.)*sintg(i ,j-1,k-1,i_B_x_z)
6094  -Real(8.)*sintg(i ,j-1,k-1,i_B_xyz))
6095  +eb_vel_dot_n(i-1,j ,k-1)*( bareaarr(i-1,j ,k-1)
6096  +Real(2.)*sintg(i-1,j ,k-1,i_B_x)
6097  -Real(2.)*sintg(i-1,j ,k-1,i_B_y)
6098  -Real(4.)*sintg(i-1,j ,k-1,i_B_x_y)
6099  +Real(2.)*sintg(i-1,j ,k-1,i_B_z)
6100  -Real(4.)*sintg(i-1,j ,k-1,i_B_y_z)
6101  +Real(4.)*sintg(i-1,j ,k-1,i_B_x_z)
6102  -Real(8.)*sintg(i-1,j ,k-1,i_B_xyz))
6103  +eb_vel_dot_n(i ,j ,k-1)*( bareaarr(i ,j ,k-1)
6104  -Real(2.)*sintg(i ,j ,k-1,i_B_x)
6105  -Real(2.)*sintg(i ,j ,k-1,i_B_y)
6106  +Real(4.)*sintg(i ,j ,k-1,i_B_x_y)
6107  +Real(2.)*sintg(i ,j ,k-1,i_B_z)
6108  -Real(4.)*sintg(i ,j ,k-1,i_B_y_z)
6109  -Real(4.)*sintg(i ,j ,k-1,i_B_x_z)
6110  +Real(8.)*sintg(i ,j ,k-1,i_B_xyz)));
6111  }
6112 }
6113 
6115 void mlndlap_mknewu_eb (int i, int j, int k, Array4<Real> const& u, Array4<Real const> const& p,
6116  Array4<Real const> const& sig, Array4<Real const> const& vfrac,
6117  Array4<Real const> const& intg, GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
6118 {
6119  using namespace nodelap_detail;
6120 
6121  if (vfrac(i,j,k) == Real(0.)) {
6122  u(i,j,k,0) = u(i,j,k,1) = u(i,j,k,2) = Real(0.);
6123  } else {
6124  Real dpdx = Real(0.25)*(-p(i,j,k )+p(i+1,j,k )-p(i,j+1,k )+p(i+1,j+1,k )
6125  -p(i,j,k+1)+p(i+1,j,k+1)-p(i,j+1,k+1)+p(i+1,j+1,k+1));
6126  Real dpdy = Real(0.25)*(-p(i,j,k )-p(i+1,j,k )+p(i,j+1,k )+p(i+1,j+1,k )
6127  -p(i,j,k+1)-p(i+1,j,k+1)+p(i,j+1,k+1)+p(i+1,j+1,k+1));
6128  Real dpdz = Real(0.25)*(-p(i,j,k )-p(i+1,j,k )-p(i,j+1,k )-p(i+1,j+1,k )
6129  +p(i,j,k+1)+p(i+1,j,k+1)+p(i,j+1,k+1)+p(i+1,j+1,k+1));
6130 
6131  Real dpp_xy = (p(i+1,j+1,k+1) - p(i,j+1,k+1) - p(i+1,j,k+1) + p(i,j,k+1)
6132  +p(i+1,j+1,k ) - p(i,j+1,k ) - p(i+1,j,k ) + p(i,j,k ) ) / vfrac(i,j,k);
6133 
6134  Real dpp_xz = (p(i+1,j+1,k+1) - p(i,j+1,k+1) + p(i+1,j,k+1) - p(i,j,k+1)
6135  -p(i+1,j+1,k ) + p(i,j+1,k ) - p(i+1,j,k ) + p(i,j,k ) ) / vfrac(i,j,k);
6136 
6137  Real dpp_yz = (p(i+1,j+1,k+1) + p(i,j+1,k+1) - p(i+1,j,k+1) - p(i,j,k+1)
6138  -p(i+1,j+1,k ) - p(i,j+1,k ) + p(i+1,j,k ) + p(i,j,k ) ) / vfrac(i,j,k);
6139 
6140  Real dpp_xyz = (p(i+1,j+1,k+1) - p(i,j+1,k+1) - p(i+1,j,k+1) + p(i,j,k+1)
6141  -p(i+1,j+1,k ) + p(i,j+1,k ) + p(i+1,j,k ) - p(i,j,k ) ) / vfrac(i,j,k);
6142 
6143  u(i,j,k,0) -= sig(i,j,k)*dxinv[0]*(dpdx + Real(0.5)*intg(i,j,k,i_S_y )*dpp_xy +
6144  Real(0.5)*intg(i,j,k,i_S_z )*dpp_xz +
6145  intg(i,j,k,i_S_y_z)*dpp_xyz );
6146  u(i,j,k,1) -= sig(i,j,k)*dxinv[1]*(dpdy + Real(0.5)*intg(i,j,k,i_S_x )*dpp_xy +
6147  Real(0.5)*intg(i,j,k,i_S_z )*dpp_yz +
6148  intg(i,j,k,i_S_x_z)*dpp_xyz );
6149  u(i,j,k,2) -= sig(i,j,k)*dxinv[2]*(dpdz + Real(0.5)*intg(i,j,k,i_S_x )*dpp_xz +
6150  Real(0.5)*intg(i,j,k,i_S_y )*dpp_yz +
6151  intg(i,j,k,i_S_x_y)*dpp_xyz );
6152  }
6153 }
6154 
6156 void mlndlap_mknewu_eb_c (int i, int j, int k, Array4<Real> const& u, Array4<Real const> const& p,
6157  Real sig, Array4<Real const> const& vfrac,
6158  Array4<Real const> const& intg, GpuArray<Real,AMREX_SPACEDIM> const& dxinv) noexcept
6159 {
6160  using namespace nodelap_detail;
6161 
6162  if (vfrac(i,j,k) == Real(0.)) {
6163  u(i,j,k,0) = u(i,j,k,1) = u(i,j,k,2) = Real(0.);
6164  } else {
6165  Real dpdx = Real(0.25)*(-p(i,j,k )+p(i+1,j,k )-p(i,j+1,k )+p(i+1,j+1,k )
6166  -p(i,j,k+1)+p(i+1,j,k+1)-p(i,j+1,k+1)+p(i+1,j+1,k+1));
6167  Real dpdy = Real(0.25)*(-p(i,j,k )-p(i+1,j,k )+p(i,j+1,k )+p(i+1,j+1,k )
6168  -p(i,j,k+1)-p(i+1,j,k+1)+p(i,j+1,k+1)+p(i+1,j+1,k+1));
6169  Real dpdz = Real(0.25)*(-p(i,j,k )-p(i+1,j,k )-p(i,j+1,k )-p(i+1,j+1,k )
6170  +p(i,j,k+1)+p(i+1,j,k+1)+p(i,j+1,k+1)+p(i+1,j+1,k+1));
6171 
6172  Real dpp_xy = (p(i+1,j+1,k+1) - p(i,j+1,k+1) - p(i+1,j,k+1) + p(i,j,k+1)
6173  +p(i+1,j+1,k ) - p(i,j+1,k ) - p(i+1,j,k ) + p(i,j,k ) ) / vfrac(i,j,k);
6174 
6175  Real dpp_xz = (p(i+1,j+1,k+1) - p(i,j+1,k+1) + p(i+1,j,k+1) - p(i,j,k+1)
6176  -p(i+1,j+1,k ) + p(i,j+1,k ) - p(i+1,j,k ) + p(i,j,k ) ) / vfrac(i,j,k);
6177 
6178  Real dpp_yz = (p(i+1,j+1,k+1) + p(i,j+1,k+1) - p(i+1,j,k+1) - p(i,j,k+1)
6179  -p(i+1,j+1,k ) - p(i,j+1,k ) + p(i+1,j,k ) + p(i,j,k ) ) / vfrac(i,j,k);
6180 
6181  Real dpp_xyz = (p(i+1,j+1,k+1) - p(i,j+1,k+1) - p(i+1,j,k+1) + p(i,j,k+1)
6182  -p(i+1,j+1,k ) + p(i,j+1,k ) + p(i+1,j,k ) - p(i,j,k ) ) / vfrac(i,j,k);
6183 
6184  u(i,j,k,0) -= sig*dxinv[0]*(dpdx + Real(0.5)*intg(i,j,k,i_S_y )*dpp_xy +
6185  Real(0.5)*intg(i,j,k,i_S_z )*dpp_xz +
6186  intg(i,j,k,i_S_y_z)*dpp_xyz );
6187  u(i,j,k,1) -= sig*dxinv[1]*(dpdy + Real(0.5)*intg(i,j,k,i_S_x )*dpp_xy +
6188  Real(0.5)*intg(i,j,k,i_S_z )*dpp_yz +
6189  intg(i,j,k,i_S_x_z)*dpp_xyz );
6190  u(i,j,k,2) -= sig*dxinv[2]*(dpdz + Real(0.5)*intg(i,j,k,i_S_x )*dpp_xz +
6191  Real(0.5)*intg(i,j,k,i_S_y )*dpp_yz +
6192  intg(i,j,k,i_S_x_y)*dpp_xyz );
6193  }
6194 }
6195 
6197 Real mlndlap_rhcc_eb (int i, int j, int k, Array4<Real const> const& rhcc,
6198  Array4<Real const> const& vfrac, Array4<Real const> const& intg,
6199  Array4<int const> const& msk) noexcept
6200 {
6201  using namespace nodelap_detail;
6202 
6203  if (!msk(i,j,k)) {
6204  return
6205  rhcc(i ,j ,k ) *
6206  ( Real(0.125) * vfrac(i ,j ,k )
6207  + Real(0.25) * (-intg(i ,j ,k ,i_S_x)
6208  -intg(i ,j ,k ,i_S_y)
6209  -intg(i ,j ,k ,i_S_z))
6210  + Real(0.5) * ( intg(i ,j ,k ,i_S_x_y)
6211  +intg(i ,j ,k ,i_S_x_z)
6212  +intg(i ,j ,k ,i_S_y_z))
6213  + ( -intg(i ,j ,k ,i_S_xyz)))
6214  //
6215  + rhcc(i-1,j ,k ) *
6216  ( Real(0.125) * vfrac(i-1,j ,k )
6217  + Real(0.25) * ( intg(i-1,j ,k ,i_S_x)
6218  -intg(i-1,j ,k ,i_S_y)
6219  -intg(i-1,j ,k ,i_S_z))
6220  + Real(0.5) * ( -intg(i-1,j ,k ,i_S_x_y)
6221  -intg(i-1,j ,k ,i_S_x_z)
6222  +intg(i-1,j ,k ,i_S_y_z))
6223  + ( intg(i-1,j ,k ,i_S_xyz)))
6224  //
6225  + rhcc(i ,j-1,k ) *
6226  ( Real(0.125) * vfrac(i ,j-1,k )
6227  + Real(0.25) * (-intg(i ,j-1,k ,i_S_x)
6228  +intg(i ,j-1,k ,i_S_y)
6229  -intg(i ,j-1,k ,i_S_z))
6230  + Real(0.5) * ( -intg(i ,j-1,k ,i_S_x_y)
6231  +intg(i ,j-1,k ,i_S_x_z)
6232  -intg(i ,j-1,k ,i_S_y_z))
6233  + ( intg(i ,j-1,k ,i_S_xyz)))
6234  //
6235  + rhcc(i-1,j-1,k ) *
6236  ( Real(0.125) * vfrac(i-1,j-1,k )
6237  + Real(0.25) * ( intg(i-1,j-1,k ,i_S_x)
6238  +intg(i-1,j-1,k ,i_S_y)
6239  -intg(i-1,j-1,k ,i_S_z))
6240  + Real(0.5) * ( intg(i-1,j-1,k ,i_S_x_y)
6241  -intg(i-1,j-1,k ,i_S_x_z)
6242  -intg(i-1,j-1,k ,i_S_y_z))
6243  + ( -intg(i-1,j-1,k ,i_S_xyz)))
6244  //
6245  + rhcc(i ,j ,k-1) *
6246  ( Real(0.125) * vfrac(i ,j ,k-1)
6247  + Real(0.25) * (-intg(i ,j ,k-1,i_S_x)
6248  -intg(i ,j ,k-1,i_S_y)
6249  +intg(i ,j ,k-1,i_S_z))
6250  + Real(0.5) * ( intg(i ,j ,k-1,i_S_x_y)
6251  -intg(i ,j ,k-1,i_S_x_z)
6252  -intg(i ,j ,k-1,i_S_y_z))
6253  + ( intg(i ,j ,k-1,i_S_xyz)))
6254  //
6255  + rhcc(i-1,j ,k-1) *
6256  ( Real(0.125) * vfrac(i-1,j ,k-1)
6257  + Real(0.25) * ( intg(i-1,j ,k-1,i_S_x)
6258  -intg(i-1,j ,k-1,i_S_y)
6259  +intg(i-1,j ,k-1,i_S_z))
6260  + Real(0.5) * ( -intg(i-1,j ,k-1,i_S_x_y)
6261  +intg(i-1,j ,k-1,i_S_x_z)
6262  -intg(i-1,j ,k-1,i_S_y_z))
6263  + ( -intg(i-1,j ,k-1,i_S_xyz)))
6264  //
6265  + rhcc(i ,j-1,k-1) *
6266  ( Real(0.125) * vfrac(i ,j-1,k-1)
6267  + Real(0.25) * (-intg(i ,j-1,k-1,i_S_x)
6268  +intg(i ,j-1,k-1,i_S_y)
6269  +intg(i ,j-1,k-1,i_S_z))
6270  + Real(0.5) * ( -intg(i ,j-1,k-1,i_S_x_y)
6271  -intg(i ,j-1,k-1,i_S_x_z)
6272  +intg(i ,j-1,k-1,i_S_y_z))
6273  + ( -intg(i ,j-1,k-1,i_S_xyz)))
6274  //
6275  + rhcc(i-1,j-1,k-1) *
6276  ( Real(0.125) * vfrac(i-1,j-1,k-1)
6277  + Real(0.25) * ( intg(i-1,j-1,k-1,i_S_x)
6278  +intg(i-1,j-1,k-1,i_S_y)
6279  +intg(i-1,j-1,k-1,i_S_z))
6280  + Real(0.5) * ( intg(i-1,j-1,k-1,i_S_x_y)
6281  +intg(i-1,j-1,k-1,i_S_x_z)
6282  +intg(i-1,j-1,k-1,i_S_y_z))
6283  + ( intg(i-1,j-1,k-1,i_S_xyz)));
6284  } else {
6285  return Real(0.);
6286  }
6287 }
6288 
6289 #endif
6290 
6291 #if defined(AMREX_USE_HYPRE)
6292 
6293 template <typename HypreInt, typename AtomicInt>
6294 void mlndlap_fillijmat_sten_cpu (Box const& ndbx,
6295  Array4<AtomicInt const> const& gid,
6296  Array4<int const> const& lid,
6297  HypreInt* ncols, HypreInt* cols,
6298  Real* mat, // NOLINT(readability-non-const-parameter)
6299  Array4<Real const> const& sten) noexcept
6300 {
6301  constexpr int ist_000 = 1-1;
6302  constexpr int ist_p00 = 2-1;
6303  constexpr int ist_0p0 = 3-1;
6304  constexpr int ist_00p = 4-1;
6305  constexpr int ist_pp0 = 5-1;
6306  constexpr int ist_p0p = 6-1;
6307  constexpr int ist_0pp = 7-1;
6308  constexpr int ist_ppp = 8-1;
6309 
6310  constexpr auto gidmax = std::numeric_limits<AtomicInt>::max();
6311  HypreInt nelems = 0;
6312  amrex::LoopOnCpu(ndbx, [&] (int i, int j, int k) noexcept
6313  {
6314  if (lid(i,j,k) >= 0)
6315  {
6316  cols[nelems] = gid(i,j,k);
6317  mat[nelems] = sten(i,j,k,ist_000);
6318  HypreNodeLap::Int nelems_old = nelems;
6319  ++nelems;
6320 
6321  if (gid(i-1,j-1,k-1) < gidmax) {
6322  cols[nelems] = gid(i-1,j-1,k-1);
6323  mat[nelems] = sten(i-1,j-1,k-1,ist_ppp);
6324  ++nelems;
6325  }
6326 
6327  if (gid(i,j-1,k-1) < gidmax) {
6328  cols[nelems] = gid(i,j-1,k-1);
6329  mat[nelems] = sten(i,j-1,k-1,ist_0pp);
6330  ++nelems;
6331  }
6332 
6333  if (gid(i+1,j-1,k-1) < gidmax) {
6334  cols[nelems] = gid(i+1,j-1,k-1);
6335  mat[nelems] = sten(i,j-1,k-1,ist_ppp);
6336  ++nelems;
6337  }
6338 
6339  if (gid(i-1,j,k-1) < gidmax) {
6340  cols[nelems] = gid(i-1,j,k-1);
6341  mat[nelems] = sten(i-1,j,k-1,ist_p0p);
6342  ++nelems;
6343  }
6344 
6345  if (gid(i,j,k-1) < gidmax) {
6346  cols[nelems] = gid(i,j,k-1);
6347  mat[nelems] = sten(i,j,k-1,ist_00p);
6348  ++nelems;
6349  }
6350 
6351  if (gid(i+1,j,k-1) < gidmax) {
6352  cols[nelems] = gid(i+1,j,k-1);
6353  mat[nelems] = sten(i,j,k-1,ist_p0p);
6354  ++nelems;
6355  }
6356 
6357  if (gid(i-1,j+1,k-1) < gidmax) {
6358  cols[nelems] = gid(i-1,j+1,k-1);
6359  mat[nelems] = sten(i-1,j,k-1,ist_ppp);
6360  ++nelems;
6361  }
6362 
6363  if (gid(i,j+1,k-1) < gidmax) {
6364  cols[nelems] = gid(i,j+1,k-1);
6365  mat[nelems] = sten(i,j,k-1,ist_0pp);
6366  ++nelems;
6367  }
6368 
6369  if (gid(i+1,j+1,k-1) < gidmax) {
6370  cols[nelems] = gid(i+1,j+1,k-1);
6371  mat[nelems] = sten(i,j,k-1,ist_ppp);
6372  ++nelems;
6373  }
6374 
6375  if (gid(i-1,j-1,k) < gidmax) {
6376  cols[nelems] = gid(i-1,j-1,k);
6377  mat[nelems] = sten(i-1,j-1,k,ist_pp0);
6378  ++nelems;
6379  }
6380 
6381  if (gid(i,j-1,k) < gidmax) {
6382  cols[nelems] = gid(i,j-1,k);
6383  mat[nelems] = sten(i,j-1,k,ist_0p0);
6384  ++nelems;
6385  }
6386 
6387  if (gid(i+1,j-1,k) < gidmax) {
6388  cols[nelems] = gid(i+1,j-1,k);
6389  mat[nelems] = sten(i,j-1,k,ist_pp0);
6390  ++nelems;
6391  }
6392 
6393  if (gid(i-1,j,k) < gidmax) {
6394  cols[nelems] = gid(i-1,j,k);
6395  mat[nelems] = sten(i-1,j,k,ist_p00);
6396  ++nelems;
6397  }
6398 
6399  if (gid(i+1,j,k) < gidmax) {
6400  cols[nelems] = gid(i+1,j,k);
6401  mat[nelems] = sten(i,j,k,ist_p00);
6402  ++nelems;
6403  }
6404 
6405  if (gid(i-1,j+1,k) < gidmax) {
6406  cols[nelems] = gid(i-1,j+1,k);
6407  mat[nelems] = sten(i-1,j,k,ist_pp0);
6408  ++nelems;
6409  }
6410 
6411  if (gid(i,j+1,k) < gidmax) {
6412  cols[nelems] = gid(i,j+1,k);
6413  mat[nelems] = sten(i,j,k,ist_0p0);
6414  ++nelems;
6415  }
6416 
6417  if (gid(i+1,j+1,k) < gidmax) {
6418  cols[nelems] = gid(i+1,j+1,k);
6419  mat[nelems] = sten(i,j,k,ist_pp0);
6420  ++nelems;
6421  }
6422 
6423  if (gid(i-1,j-1,k+1) < gidmax) {
6424  cols[nelems] = gid(i-1,j-1,k+1);
6425  mat[nelems] = sten(i-1,j-1,k,ist_ppp);
6426  ++nelems;
6427  }
6428 
6429  if (gid(i,j-1,k+1) < gidmax) {
6430  cols[nelems] = gid(i,j-1,k+1);
6431  mat[nelems] = sten(i,j-1,k,ist_0pp);
6432  ++nelems;
6433  }
6434 
6435  if (gid(i+1,j-1,k+1) < gidmax) {
6436  cols[nelems] = gid(i+1,j-1,k+1);
6437  mat[nelems] = sten(i,j-1,k,ist_ppp);
6438  ++nelems;
6439  }
6440 
6441  if (gid(i-1,j,k+1) < gidmax) {
6442  cols[nelems] = gid(i-1,j,k+1);
6443  mat[nelems] = sten(i-1,j,k,ist_p0p);
6444  ++nelems;
6445  }
6446 
6447  if (gid(i,j,k+1) < gidmax) {
6448  cols[nelems] = gid(i,j,k+1);
6449  mat[nelems] = sten(i,j,k,ist_00p);
6450  ++nelems;
6451  }
6452 
6453  if (gid(i+1,j,k+1) < gidmax) {
6454  cols[nelems] = gid(i+1,j,k+1);
6455  mat[nelems] = sten(i,j,k,ist_p0p);
6456  ++nelems;
6457  }
6458 
6459  if (gid(i-1,j+1,k+1) < gidmax) {
6460  cols[nelems] = gid(i-1,j+1,k+1);
6461  mat[nelems] = sten(i-1,j,k,ist_ppp);
6462  ++nelems;
6463  }
6464 
6465  if (gid(i,j+1,k+1) < gidmax) {
6466  cols[nelems] = gid(i,j+1,k+1);
6467  mat[nelems] = sten(i,j,k,ist_0pp);
6468  ++nelems;
6469  }
6470 
6471  if (gid(i+1,j+1,k+1) < gidmax) {
6472  cols[nelems] = gid(i+1,j+1,k+1);
6473  mat[nelems] = sten(i,j,k,ist_ppp);
6474  ++nelems;
6475  }
6476 
6477  ncols[lid(i,j,k)] = nelems - nelems_old;
6478  }
6479  });
6480 }
6481 
6482 template <typename HypreInt, typename AtomicInt>
6483 void mlndlap_fillijmat_aa_cpu (Box const& ndbx,
6484  Array4<AtomicInt const> const& gid,
6485  Array4<int const> const& lid,
6486  HypreInt* ncols, HypreInt* cols,
6487  Real* mat, // NOLINT(readability-non-const-parameter)
6488  Array4<Real const> const& sig,
6489  GpuArray<Real,AMREX_SPACEDIM> const& dxinv,
6490  Box const& ccdom) noexcept
6491 {
6492  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
6493  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
6494  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
6495  Real fxyz = facx + facy + facz;
6496  Real fmx2y2z = -facx + Real(2.0)*facy + Real(2.0)*facz;
6497  Real f2xmy2z = Real(2.0)*facx - facy + Real(2.0)*facz;
6498  Real f2x2ymz = Real(2.0)*facx + Real(2.0)*facy - facz;
6499  Real f4xm2ym2z = Real(4.0)*facx - Real(2.0)*facy - Real(2.0)*facz;
6500  Real fm2x4ym2z = -Real(2.0)*facx + Real(4.0)*facy - Real(2.0)*facz;
6501  Real fm2xm2y4z = -Real(2.0)*facx - Real(2.0)*facy + Real(4.0)*facz;
6502 
6503  const Box& nddom = amrex::surroundingNodes(ccdom);
6504 
6505  constexpr auto gidmax = std::numeric_limits<AtomicInt>::max();
6506  HypreInt nelems = 0;
6507  amrex::LoopOnCpu(ndbx, [&] (int i, int j, int k) noexcept
6508  {
6509  if (lid(i,j,k) >= 0)
6510  {
6511  HypreInt nelems_old = nelems;
6512  cols[nelems_old] = gid(i,j,k);
6513  Real m0 = Real(0.);
6514  ++nelems;
6515 
6516  if (nddom.contains(i-1,j-1,k-1)) {
6517  Real tmp = sig(i-1,j-1,k-1) * fxyz;
6518  m0 -= tmp;
6519  if ( gid(i-1,j-1,k-1) < gidmax) {
6520  cols[nelems] = gid(i-1,j-1,k-1);
6521  mat[nelems] = tmp;
6522  ++nelems;
6523  }
6524  }
6525 
6526  if (nddom.contains(i,j-1,k-1)) {
6527  Real tmp = Real(0.);
6528  if (ccdom.contains(i-1,j-1,k-1)) {
6529  tmp += sig(i-1,j-1,k-1) * fmx2y2z;
6530  }
6531  if (ccdom.contains(i,j-1,k-1)) {
6532  tmp += sig(i,j-1,k-1) * fmx2y2z;
6533  }
6534  m0 -= tmp;
6535  if (gid(i,j-1,k-1) < gidmax) {
6536  cols[nelems] = gid(i,j-1,k-1);
6537  mat[nelems] = tmp;
6538  ++nelems;
6539  }
6540  }
6541 
6542  if (nddom.contains(i+1,j-1,k-1)) {
6543  Real tmp = sig(i ,j-1,k-1) * fxyz;
6544  m0 -= tmp;
6545  if (gid(i+1,j-1,k-1) < gidmax) {
6546  cols[nelems] = gid(i+1,j-1,k-1);
6547  mat[nelems] = tmp;
6548  ++nelems;
6549  }
6550  }
6551 
6552  if (nddom.contains(i-1,j,k-1)) {
6553  Real tmp = Real(0.);
6554  if (ccdom.contains(i-1,j-1,k-1)) {
6555  tmp += sig(i-1,j-1,k-1) * f2xmy2z;
6556  }
6557  if (ccdom.contains(i-1,j,k-1)) {
6558  tmp += sig(i-1,j,k-1) * f2xmy2z;
6559  }
6560  m0 -= tmp;
6561  if (gid(i-1,j,k-1) < gidmax) {
6562  cols[nelems] = gid(i-1,j,k-1);
6563  mat[nelems] = tmp;
6564  ++nelems;
6565  }
6566  }
6567 
6568  if (nddom.contains(i,j,k-1) && fm2xm2y4z != Real(0.0)) {
6569  Real tmp = Real(0.);
6570  if (ccdom.contains(i-1,j-1,k-1)) {
6571  tmp += sig(i-1,j-1,k-1) * fm2xm2y4z;
6572  }
6573  if (ccdom.contains(i,j-1,k-1)) {
6574  tmp += sig(i,j-1,k-1) * fm2xm2y4z;
6575  }
6576  if (ccdom.contains(i-1,j,k-1)) {
6577  tmp += sig(i-1,j,k-1) * fm2xm2y4z;
6578  }
6579  if (ccdom.contains(i,j,k-1)) {
6580  tmp += sig(i,j,k-1) * fm2xm2y4z;
6581  }
6582  m0 -= tmp;
6583  if (gid(i,j,k-1) < gidmax) {
6584  cols[nelems] = gid(i,j,k-1);
6585  mat[nelems] = tmp;
6586  ++nelems;
6587  }
6588  }
6589 
6590  if (nddom.contains(i+1,j,k-1)) {
6591  Real tmp = Real(0.);
6592  if (ccdom.contains(i ,j-1,k-1)) {
6593  tmp += sig(i ,j-1,k-1) * f2xmy2z;
6594  }
6595  if (ccdom.contains(i ,j,k-1)) {
6596  tmp += sig(i ,j,k-1) * f2xmy2z;
6597  }
6598  m0 -= tmp;
6599  if (gid(i+1,j,k-1) < gidmax) {
6600  cols[nelems] = gid(i+1,j,k-1);
6601  mat[nelems] = tmp;
6602  ++nelems;
6603  }
6604  }
6605 
6606  if (nddom.contains(i-1,j+1,k-1)) {
6607  Real tmp = sig(i-1,j ,k-1) * fxyz;
6608  m0 -= tmp;
6609  if (gid(i-1,j+1,k-1) < gidmax) {
6610  cols[nelems] = gid(i-1,j+1,k-1);
6611  mat[nelems] = tmp;
6612  ++nelems;
6613  }
6614  }
6615 
6616  if (nddom.contains(i,j+1,k-1)) {
6617  Real tmp = Real(0.);
6618  if (ccdom.contains(i-1,j ,k-1)) {
6619  tmp += sig(i-1,j ,k-1) * fmx2y2z;
6620  }
6621  if (ccdom.contains(i,j ,k-1)) {
6622  tmp += sig(i,j ,k-1) * fmx2y2z;
6623  }
6624  m0 -= tmp;
6625  if (gid(i,j+1,k-1) < gidmax) {
6626  cols[nelems] = gid(i,j+1,k-1);
6627  mat[nelems] = tmp;
6628  ++nelems;
6629  }
6630  }
6631 
6632  if (nddom.contains(i+1,j+1,k-1)) {
6633  Real tmp = sig(i ,j ,k-1) * fxyz;
6634  m0 -= tmp;
6635  if (gid(i+1,j+1,k-1) < gidmax) {
6636  cols[nelems] = gid(i+1,j+1,k-1);
6637  mat[nelems] = tmp;
6638  ++nelems;
6639  }
6640  }
6641 
6642  if (nddom.contains(i-1,j-1,k)) {
6643  Real tmp = Real(0.);
6644  if (ccdom.contains(i-1,j-1,k-1)) {
6645  tmp += sig(i-1,j-1,k-1) * f2x2ymz;
6646  }
6647  if (ccdom.contains(i-1,j-1,k)) {
6648  tmp += sig(i-1,j-1,k) * f2x2ymz;
6649  }
6650  m0 -= tmp;
6651  if (gid(i-1,j-1,k) < gidmax) {
6652  cols[nelems] = gid(i-1,j-1,k);
6653  mat[nelems] = tmp;
6654  ++nelems;
6655  }
6656  }
6657 
6658  if (nddom.contains(i,j-1,k) && fm2x4ym2z != Real(0.0)) {
6659  Real tmp = Real(0.);
6660  if (ccdom.contains(i-1,j-1,k-1)) {
6661  tmp += sig(i-1,j-1,k-1) * fm2x4ym2z;
6662  }
6663  if (ccdom.contains(i,j-1,k-1)) {
6664  tmp += sig(i,j-1,k-1) * fm2x4ym2z;
6665  }
6666  if (ccdom.contains(i-1,j-1,k)) {
6667  tmp += sig(i-1,j-1,k) * fm2x4ym2z;
6668  }
6669  if (ccdom.contains(i,j-1,k)) {
6670  tmp += sig(i,j-1,k) * fm2x4ym2z;
6671  }
6672  m0 -= tmp;
6673  if (gid(i,j-1,k) < gidmax) {
6674  cols[nelems] = gid(i,j-1,k);
6675  mat[nelems] = tmp;
6676  ++nelems;
6677  }
6678  }
6679 
6680  if (nddom.contains(i+1,j-1,k)) {
6681  Real tmp = Real(0.);
6682  if (ccdom.contains(i ,j-1,k-1)) {
6683  tmp += sig(i ,j-1,k-1) * f2x2ymz;
6684  }
6685  if (ccdom.contains(i ,j-1,k)) {
6686  tmp += sig(i ,j-1,k) * f2x2ymz;
6687  }
6688  m0 -= tmp;
6689  if (gid(i+1,j-1,k) < gidmax) {
6690  cols[nelems] = gid(i+1,j-1,k);
6691  mat[nelems] = tmp;
6692  ++nelems;
6693  }
6694  }
6695 
6696  if (nddom.contains(i-1,j,k) && f4xm2ym2z != Real(0.0)) {
6697  Real tmp = Real(0.);
6698  if (ccdom.contains(i-1,j-1,k-1)) {
6699  tmp += sig(i-1,j-1,k-1) * f4xm2ym2z;
6700  }
6701  if (ccdom.contains(i-1,j,k-1)) {
6702  tmp += sig(i-1,j,k-1) * f4xm2ym2z;
6703  }
6704  if (ccdom.contains(i-1,j-1,k)) {
6705  tmp += sig(i-1,j-1,k) * f4xm2ym2z;
6706  }
6707  if (ccdom.contains(i-1,j,k)) {
6708  tmp += sig(i-1,j,k) * f4xm2ym2z;
6709  }
6710  m0 -= tmp;
6711  if (gid(i-1,j,k) < gidmax) {
6712  cols[nelems] = gid(i-1,j,k);
6713  mat[nelems] = tmp;
6714  ++nelems;
6715  }
6716  }
6717 
6718  if (nddom.contains(i+1,j,k) && f4xm2ym2z != Real(0.0)) {
6719  Real tmp = Real(0.);
6720  if (ccdom.contains(i ,j-1,k-1)) {
6721  tmp += sig(i ,j-1,k-1) * f4xm2ym2z;
6722  }
6723  if (ccdom.contains(i ,j,k-1)) {
6724  tmp += sig(i ,j,k-1) * f4xm2ym2z;
6725  }
6726  if (ccdom.contains(i ,j-1,k)) {
6727  tmp += sig(i ,j-1,k) * f4xm2ym2z;
6728  }
6729  if (ccdom.contains(i ,j,k)) {
6730  tmp += sig(i ,j,k) * f4xm2ym2z;
6731  }
6732  m0 -= tmp;
6733  if (gid(i+1,j,k) < gidmax) {
6734  cols[nelems] = gid(i+1,j,k);
6735  mat[nelems] = tmp;
6736  ++nelems;
6737  }
6738  }
6739 
6740  if (nddom.contains(i-1,j+1,k)) {
6741  Real tmp = Real(0.);
6742  if (ccdom.contains(i-1,j ,k-1)) {
6743  tmp += sig(i-1,j ,k-1) * f2x2ymz;
6744  }
6745  if (ccdom.contains(i-1,j ,k)) {
6746  tmp += sig(i-1,j ,k) * f2x2ymz;
6747  }
6748  m0 -= tmp;
6749  if (gid(i-1,j+1,k) < gidmax) {
6750  cols[nelems] = gid(i-1,j+1,k);
6751  mat[nelems] = tmp;
6752  ++nelems;
6753  }
6754  }
6755 
6756  if (nddom.contains(i,j+1,k) && fm2x4ym2z != Real(0.0)) {
6757  Real tmp = Real(0.);
6758  if (ccdom.contains(i-1,j ,k-1)) {
6759  tmp += sig(i-1,j ,k-1) * fm2x4ym2z;
6760  }
6761  if (ccdom.contains(i,j ,k-1)) {
6762  tmp += sig(i,j ,k-1) * fm2x4ym2z;
6763  }
6764  if (ccdom.contains(i-1,j ,k)) {
6765  tmp += sig(i-1,j ,k) * fm2x4ym2z;
6766  }
6767  if (ccdom.contains(i,j ,k)) {
6768  tmp += sig(i,j ,k) * fm2x4ym2z;
6769  }
6770  m0 -= tmp;
6771  if (gid(i,j+1,k) < gidmax) {
6772  cols[nelems] = gid(i,j+1,k);
6773  mat[nelems] = tmp;
6774  ++nelems;
6775  }
6776  }
6777 
6778  if (nddom.contains(i+1,j+1,k)) {
6779  Real tmp = Real(0.);
6780  if (ccdom.contains(i ,j ,k-1)) {
6781  tmp += sig(i ,j ,k-1) * f2x2ymz;
6782  }
6783  if (ccdom.contains(i ,j ,k)) {
6784  tmp += sig(i ,j ,k) * f2x2ymz;
6785  }
6786  m0 -= tmp;
6787  if (gid(i+1,j+1,k) < gidmax) {
6788  cols[nelems] = gid(i+1,j+1,k);
6789  mat[nelems] = tmp;
6790  ++nelems;
6791  }
6792  }
6793 
6794  if (nddom.contains(i-1,j-1,k+1)) {
6795  Real tmp = sig(i-1,j-1,k ) * fxyz;
6796  m0 -= tmp;
6797  if (gid(i-1,j-1,k+1) < gidmax) {
6798  cols[nelems] = gid(i-1,j-1,k+1);
6799  mat[nelems] = tmp;
6800  ++nelems;
6801  }
6802  }
6803 
6804  if (nddom.contains(i,j-1,k+1)) {
6805  Real tmp = Real(0.);
6806  if (ccdom.contains(i-1,j-1,k )) {
6807  tmp += sig(i-1,j-1,k ) * fmx2y2z;
6808  }
6809  if (ccdom.contains(i,j-1,k )) {
6810  tmp += sig(i,j-1,k ) * fmx2y2z;
6811  }
6812  m0 -= tmp;
6813  if (gid(i,j-1,k+1) < gidmax) {
6814  cols[nelems] = gid(i,j-1,k+1);
6815  mat[nelems] = tmp;
6816  ++nelems;
6817  }
6818  }
6819 
6820  if (nddom.contains(i+1,j-1,k+1)) {
6821  Real tmp = sig(i ,j-1,k ) * fxyz;
6822  m0 -= tmp;
6823  if (gid(i+1,j-1,k+1) < gidmax) {
6824  cols[nelems] = gid(i+1,j-1,k+1);
6825  mat[nelems] = tmp;
6826  ++nelems;
6827  }
6828  }
6829 
6830  if (nddom.contains(i-1,j,k+1)) {
6831  Real tmp = Real(0.);
6832  if (ccdom.contains(i-1,j-1,k )) {
6833  tmp += sig(i-1,j-1,k ) * f2xmy2z;
6834  }
6835  if (ccdom.contains(i-1,j,k )) {
6836  tmp += sig(i-1,j,k ) * f2xmy2z;
6837  }
6838  m0 -= tmp;
6839  if (gid(i-1,j,k+1) < gidmax) {
6840  cols[nelems] = gid(i-1,j,k+1);
6841  mat[nelems] = tmp;
6842  ++nelems;
6843  }
6844  }
6845 
6846  if (nddom.contains(i,j,k+1) && fm2xm2y4z != Real(0.0)) {
6847  Real tmp = Real(0.);
6848  if (ccdom.contains(i-1,j-1,k )) {
6849  tmp += sig(i-1,j-1,k ) * fm2xm2y4z;
6850  }
6851  if (ccdom.contains(i,j-1,k )) {
6852  tmp += sig(i,j-1,k ) * fm2xm2y4z;
6853  }
6854  if (ccdom.contains(i-1,j,k )) {
6855  tmp += sig(i-1,j,k ) * fm2xm2y4z;
6856  }
6857  if (ccdom.contains(i,j,k )) {
6858  tmp += sig(i,j,k ) * fm2xm2y4z;
6859  }
6860  m0 -= tmp;
6861  if (gid(i,j,k+1) < gidmax) {
6862  cols[nelems] = gid(i,j,k+1);
6863  mat[nelems] = tmp;
6864  ++nelems;
6865  }
6866  }
6867 
6868  if (nddom.contains(i+1,j,k+1)) {
6869  Real tmp = Real(0.);
6870  if (ccdom.contains(i ,j-1,k )) {
6871  tmp += sig(i ,j-1,k ) * f2xmy2z;
6872  }
6873  if (ccdom.contains(i ,j,k )) {
6874  tmp += sig(i ,j,k ) * f2xmy2z;
6875  }
6876  m0 -= tmp;
6877  if (gid(i+1,j,k+1) < gidmax) {
6878  cols[nelems] = gid(i+1,j,k+1);
6879  mat[nelems] = tmp;
6880  ++nelems;
6881  }
6882  }
6883 
6884  if (nddom.contains(i-1,j+1,k+1)) {
6885  Real tmp = sig(i-1,j ,k ) * fxyz;
6886  m0 -= tmp;
6887  if (gid(i-1,j+1,k+1) < gidmax) {
6888  cols[nelems] = gid(i-1,j+1,k+1);
6889  mat[nelems] = tmp;
6890  ++nelems;
6891  }
6892  }
6893 
6894  if (nddom.contains(i,j+1,k+1)) {
6895  Real tmp = Real(0.);
6896  if (ccdom.contains(i-1,j ,k )) {
6897  tmp += sig(i-1,j ,k ) * fmx2y2z;
6898  }
6899  if (ccdom.contains(i,j ,k )) {
6900  tmp += sig(i,j ,k ) * fmx2y2z;
6901  }
6902  m0 -= tmp;
6903  if (gid(i,j+1,k+1) < gidmax) {
6904  cols[nelems] = gid(i,j+1,k+1);
6905  mat[nelems] = tmp;
6906  ++nelems;
6907  }
6908  }
6909 
6910  if (nddom.contains(i+1,j+1,k+1)) {
6911  Real tmp = sig(i ,j ,k ) * fxyz;
6912  m0 -= tmp;
6913  if (gid(i+1,j+1,k+1) < gidmax) {
6914  cols[nelems] = gid(i+1,j+1,k+1);
6915  mat[nelems] = tmp;
6916  ++nelems;
6917  }
6918  }
6919 
6920  mat[nelems_old] = m0;
6921  ncols[lid(i,j,k)] = nelems - nelems_old;
6922  }
6923  });
6924 }
6925 
6926 template <typename HypreInt, typename AtomicInt>
6927 void mlndlap_fillijmat_ha_cpu (Box const& ndbx,
6928  Array4<AtomicInt const> const& gid,
6929  Array4<int const> const& lid,
6930  HypreInt* ncols, HypreInt* cols,
6931  Real* mat, // NOLINT(readability-non-const-parameter)
6932  Array4<Real const> const& sx,
6933  Array4<Real const> const& sy,
6934  Array4<Real const> const& sz,
6935  GpuArray<Real,AMREX_SPACEDIM> const& dxinv,
6936  Box const& ccdom) noexcept
6937 {
6938  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
6939  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
6940  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
6941 
6942  const Box& nddom = amrex::surroundingNodes(ccdom);
6943 
6944  constexpr auto gidmax = std::numeric_limits<AtomicInt>::max();
6945  HypreInt nelems = 0;
6946  amrex::LoopOnCpu(ndbx, [&] (int i, int j, int k) noexcept
6947  {
6948  if (lid(i,j,k) >= 0)
6949  {
6950  HypreInt nelems_old = nelems;
6951  cols[nelems_old] = gid(i,j,k);
6952  Real m0 = Real(0.);
6953  ++nelems;
6954 
6955  if (nddom.contains(i-1,j-1,k-1)) {
6956  Real tmp = sx(i-1,j-1,k-1) * facx
6957  + sy(i-1,j-1,k-1) * facy
6958  + sz(i-1,j-1,k-1) * facz;
6959  m0 -= tmp;
6960  if ( gid(i-1,j-1,k-1) < gidmax) {
6961  cols[nelems] = gid(i-1,j-1,k-1);
6962  mat[nelems] = tmp;
6963  ++nelems;
6964  }
6965  }
6966 
6967  if (nddom.contains(i,j-1,k-1)) {
6968  Real tmp = Real(0.);
6969  if (ccdom.contains(i-1,j-1,k-1)) {
6970  tmp += - sx(i-1,j-1,k-1) * facx
6971  + sy(i-1,j-1,k-1) * facy * Real(2.0)
6972  + sz(i-1,j-1,k-1) * facz * Real(2.0);
6973  }
6974  if (ccdom.contains(i,j-1,k-1)) {
6975  tmp += - sx(i,j-1,k-1) * facx
6976  + sy(i,j-1,k-1) * facy * Real(2.0)
6977  + sz(i,j-1,k-1) * facz * Real(2.0);
6978  }
6979  m0 -= tmp;
6980  if (gid(i,j-1,k-1) < gidmax) {
6981  cols[nelems] = gid(i,j-1,k-1);
6982  mat[nelems] = tmp;
6983  ++nelems;
6984  }
6985  }
6986 
6987  if (nddom.contains(i+1,j-1,k-1)) {
6988  Real tmp = sx(i ,j-1,k-1) * facx
6989  + sy(i ,j-1,k-1) * facy
6990  + sz(i ,j-1,k-1) * facz;
6991  m0 -= tmp;
6992  if (gid(i+1,j-1,k-1) < gidmax) {
6993  cols[nelems] = gid(i+1,j-1,k-1);
6994  mat[nelems] = tmp;
6995  ++nelems;
6996  }
6997  }
6998 
6999  if (nddom.contains(i-1,j,k-1)) {
7000  Real tmp = Real(0.);
7001  if (ccdom.contains(i-1,j-1,k-1)) {
7002  tmp += sx(i-1,j-1,k-1) * facx * Real(2.0)
7003  - sy(i-1,j-1,k-1) * facy
7004  + sz(i-1,j-1,k-1) * facz * Real(2.0);
7005  }
7006  if (ccdom.contains(i-1,j,k-1)) {
7007  tmp += sx(i-1,j,k-1) * facx * Real(2.0)
7008  - sy(i-1,j,k-1) * facy
7009  + sz(i-1,j,k-1) * facz * Real(2.0);
7010  }
7011  m0 -= tmp;
7012  if (gid(i-1,j,k-1) < gidmax) {
7013  cols[nelems] = gid(i-1,j,k-1);
7014  mat[nelems] = tmp;
7015  ++nelems;
7016  }
7017  }
7018 
7019  if (nddom.contains(i,j,k-1)) {
7020  Real tmp = Real(0.);
7021  if (ccdom.contains(i-1,j-1,k-1)) {
7022  tmp += - sx(i-1,j-1,k-1) * facx * Real(2.0)
7023  - sy(i-1,j-1,k-1) * facy * Real(2.0)
7024  + sz(i-1,j-1,k-1) * facz * Real(4.0);
7025  }
7026  if (ccdom.contains(i,j-1,k-1)) {
7027  tmp += - sx(i,j-1,k-1) * facx * Real(2.0)
7028  - sy(i,j-1,k-1) * facy * Real(2.0)
7029  + sz(i,j-1,k-1) * facz * Real(4.0);
7030 
7031  }
7032  if (ccdom.contains(i-1,j,k-1)) {
7033  tmp += - sx(i-1,j,k-1) * facx * Real(2.0)
7034  - sy(i-1,j,k-1) * facy * Real(2.0)
7035  + sz(i-1,j,k-1) * facz * Real(4.0);
7036  }
7037  if (ccdom.contains(i,j,k-1)) {
7038  tmp += - sx(i,j,k-1) * facx * Real(2.0)
7039  - sy(i,j,k-1) * facy * Real(2.0)
7040  + sz(i,j,k-1) * facz * Real(4.0);
7041  }
7042  m0 -= tmp;
7043  if (gid(i,j,k-1) < gidmax && tmp != Real(0.0)) {
7044  cols[nelems] = gid(i,j,k-1);
7045  mat[nelems] = tmp;
7046  ++nelems;
7047  }
7048  }
7049 
7050  if (nddom.contains(i+1,j,k-1)) {
7051  Real tmp = Real(0.);
7052  if (ccdom.contains(i ,j-1,k-1)) {
7053  tmp += sx(i ,j-1,k-1) * facx * Real(2.0)
7054  - sy(i ,j-1,k-1) * facy
7055  + sz(i ,j-1,k-1) * facz * Real(2.0);
7056  }
7057  if (ccdom.contains(i ,j,k-1)) {
7058  tmp += sx(i ,j,k-1) * facx * Real(2.0)
7059  - sy(i ,j,k-1) * facy
7060  + sz(i ,j,k-1) * facz * Real(2.0);
7061  }
7062  m0 -= tmp;
7063  if (gid(i+1,j,k-1) < gidmax) {
7064  cols[nelems] = gid(i+1,j,k-1);
7065  mat[nelems] = tmp;
7066  ++nelems;
7067  }
7068  }
7069 
7070  if (nddom.contains(i-1,j+1,k-1)) {
7071  Real tmp = sx(i-1,j ,k-1) * facx
7072  + sy(i-1,j ,k-1) * facy
7073  + sz(i-1,j ,k-1) * facz;
7074  m0 -= tmp;
7075  if (gid(i-1,j+1,k-1) < gidmax) {
7076  cols[nelems] = gid(i-1,j+1,k-1);
7077  mat[nelems] = tmp;
7078  ++nelems;
7079  }
7080  }
7081 
7082  if (nddom.contains(i,j+1,k-1)) {
7083  Real tmp = Real(0.);
7084  if (ccdom.contains(i-1,j ,k-1)) {
7085  tmp += - sx(i-1,j ,k-1) * facx
7086  + sy(i-1,j ,k-1) * facy * Real(2.0)
7087  + sz(i-1,j ,k-1) * facz * Real(2.0);
7088  }
7089  if (ccdom.contains(i,j ,k-1)) {
7090  tmp += - sx(i,j ,k-1) * facx
7091  + sy(i,j ,k-1) * facy * Real(2.0)
7092  + sz(i,j ,k-1) * facz * Real(2.0);
7093  }
7094  m0 -= tmp;
7095  if (gid(i,j+1,k-1) < gidmax) {
7096  cols[nelems] = gid(i,j+1,k-1);
7097  mat[nelems] = tmp;
7098  ++nelems;
7099  }
7100  }
7101 
7102  if (nddom.contains(i+1,j+1,k-1)) {
7103  Real tmp = sx(i ,j ,k-1) * facx
7104  + sy(i ,j ,k-1) * facy
7105  + sz(i ,j ,k-1) * facz;
7106  m0 -= tmp;
7107  if (gid(i+1,j+1,k-1) < gidmax) {
7108  cols[nelems] = gid(i+1,j+1,k-1);
7109  mat[nelems] = tmp;
7110  ++nelems;
7111  }
7112  }
7113 
7114  if (nddom.contains(i-1,j-1,k)) {
7115  Real tmp = Real(0.);
7116  if (ccdom.contains(i-1,j-1,k-1)) {
7117  tmp += sx(i-1,j-1,k-1) * facx * Real(2.0)
7118  + sy(i-1,j-1,k-1) * facy * Real(2.0)
7119  - sz(i-1,j-1,k-1) * facz;
7120  }
7121  if (ccdom.contains(i-1,j-1,k)) {
7122  tmp += sx(i-1,j-1,k) * facx * Real(2.0)
7123  + sy(i-1,j-1,k) * facy * Real(2.0)
7124  - sz(i-1,j-1,k) * facz;
7125  }
7126  m0 -= tmp;
7127  if (gid(i-1,j-1,k) < gidmax) {
7128  cols[nelems] = gid(i-1,j-1,k);
7129  mat[nelems] = tmp;
7130  ++nelems;
7131  }
7132  }
7133 
7134  if (nddom.contains(i,j-1,k)) {
7135  Real tmp = Real(0.);
7136  if (ccdom.contains(i-1,j-1,k-1)) {
7137  tmp += - sx(i-1,j-1,k-1) * facx * Real(2.0)
7138  + sy(i-1,j-1,k-1) * facy * Real(4.0)
7139  - sz(i-1,j-1,k-1) * facz * Real(2.0);
7140  }
7141  if (ccdom.contains(i,j-1,k-1)) {
7142  tmp += - sx(i,j-1,k-1) * facx * Real(2.0)
7143  + sy(i,j-1,k-1) * facy * Real(4.0)
7144  - sz(i,j-1,k-1) * facz * Real(2.0);
7145  }
7146  if (ccdom.contains(i-1,j-1,k)) {
7147  tmp += - sx(i-1,j-1,k) * facx * Real(2.0)
7148  + sy(i-1,j-1,k) * facy * Real(4.0)
7149  - sz(i-1,j-1,k) * facz * Real(2.0);
7150  }
7151  if (ccdom.contains(i,j-1,k)) {
7152  tmp += - sx(i,j-1,k) * facx * Real(2.0)
7153  + sy(i,j-1,k) * facy * Real(4.0)
7154  - sz(i,j-1,k) * facz * Real(2.0);
7155  }
7156  m0 -= tmp;
7157  if (gid(i,j-1,k) < gidmax && tmp != Real(0.0)) {
7158  cols[nelems] = gid(i,j-1,k);
7159  mat[nelems] = tmp;
7160  ++nelems;
7161  }
7162  }
7163 
7164  if (nddom.contains(i+1,j-1,k)) {
7165  Real tmp = Real(0.);
7166  if (ccdom.contains(i ,j-1,k-1)) {
7167  tmp += sx(i ,j-1,k-1) * facx * Real(2.0)
7168  + sy(i ,j-1,k-1) * facy * Real(2.0)
7169  - sz(i ,j-1,k-1) * facz;
7170  }
7171  if (ccdom.contains(i ,j-1,k)) {
7172  tmp += sx(i ,j-1,k) * facx * Real(2.0)
7173  + sy(i ,j-1,k) * facy * Real(2.0)
7174  - sz(i ,j-1,k) * facz;
7175  }
7176  m0 -= tmp;
7177  if (gid(i+1,j-1,k) < gidmax) {
7178  cols[nelems] = gid(i+1,j-1,k);
7179  mat[nelems] = tmp;
7180  ++nelems;
7181  }
7182  }
7183 
7184  if (nddom.contains(i-1,j,k)) {
7185  Real tmp = Real(0.);
7186  if (ccdom.contains(i-1,j-1,k-1)) {
7187  tmp += sx(i-1,j-1,k-1) * facx * Real(4.0)
7188  - sy(i-1,j-1,k-1) * facy * Real(2.0)
7189  - sz(i-1,j-1,k-1) * facz * Real(2.0);
7190  }
7191  if (ccdom.contains(i-1,j,k-1)) {
7192  tmp += sx(i-1,j,k-1) * facx * Real(4.0)
7193  - sy(i-1,j,k-1) * facy * Real(2.0)
7194  - sz(i-1,j,k-1) * facz * Real(2.0);
7195  }
7196  if (ccdom.contains(i-1,j-1,k)) {
7197  tmp += sx(i-1,j-1,k) * facx * Real(4.0)
7198  - sy(i-1,j-1,k) * facy * Real(2.0)
7199  - sz(i-1,j-1,k) * facz * Real(2.0);
7200  }
7201  if (ccdom.contains(i-1,j,k)) {
7202  tmp += sx(i-1,j,k) * facx * Real(4.0)
7203  - sy(i-1,j,k) * facy * Real(2.0)
7204  - sz(i-1,j,k) * facz * Real(2.0);
7205  }
7206  m0 -= tmp;
7207  if (gid(i-1,j,k) < gidmax && tmp != Real(0.0)) {
7208  cols[nelems] = gid(i-1,j,k);
7209  mat[nelems] = tmp;
7210  ++nelems;
7211  }
7212  }
7213 
7214  if (nddom.contains(i+1,j,k)) {
7215  Real tmp = Real(0.);
7216  if (ccdom.contains(i ,j-1,k-1)) {
7217  tmp += sx(i ,j-1,k-1) * facx * Real(4.0)
7218  - sy(i ,j-1,k-1) * facy * Real(2.0)
7219  - sz(i ,j-1,k-1) * facz * Real(2.0);
7220  }
7221  if (ccdom.contains(i ,j,k-1)) {
7222  tmp += sx(i ,j,k-1) * facx * Real(4.0)
7223  - sy(i ,j,k-1) * facy * Real(2.0)
7224  - sz(i ,j,k-1) * facz * Real(2.0);
7225  }
7226  if (ccdom.contains(i ,j-1,k)) {
7227  tmp += sx(i ,j-1,k) * facx * Real(4.0)
7228  - sy(i ,j-1,k) * facy * Real(2.0)
7229  - sz(i ,j-1,k) * facz * Real(2.0);
7230  }
7231  if (ccdom.contains(i ,j,k)) {
7232  tmp += sx(i ,j,k) * facx * Real(4.0)
7233  - sy(i ,j,k) * facy * Real(2.0)
7234  - sz(i ,j,k) * facz * Real(2.0);
7235  }
7236  m0 -= tmp;
7237  if (gid(i+1,j,k) < gidmax && tmp != Real(0.0)) {
7238  cols[nelems] = gid(i+1,j,k);
7239  mat[nelems] = tmp;
7240  ++nelems;
7241  }
7242  }
7243 
7244  if (nddom.contains(i-1,j+1,k)) {
7245  Real tmp = Real(0.);
7246  if (ccdom.contains(i-1,j ,k-1)) {
7247  tmp += sx(i-1,j ,k-1) * facx * Real(2.0)
7248  + sy(i-1,j ,k-1) * facy * Real(2.0)
7249  - sz(i-1,j ,k-1) * facz;
7250  }
7251  if (ccdom.contains(i-1,j ,k)) {
7252  tmp += sx(i-1,j ,k) * facx * Real(2.0)
7253  + sy(i-1,j ,k) * facy * Real(2.0)
7254  - sz(i-1,j ,k) * facz;
7255  }
7256  m0 -= tmp;
7257  if (gid(i-1,j+1,k) < gidmax) {
7258  cols[nelems] = gid(i-1,j+1,k);
7259  mat[nelems] = tmp;
7260  ++nelems;
7261  }
7262  }
7263 
7264  if (nddom.contains(i,j+1,k)) {
7265  Real tmp = Real(0.);
7266  if (ccdom.contains(i-1,j ,k-1)) {
7267  tmp += - sx(i-1,j ,k-1) * facx * Real(2.0)
7268  + sy(i-1,j ,k-1) * facy * Real(4.0)
7269  - sz(i-1,j ,k-1) * facz * Real(2.0);
7270  }
7271  if (ccdom.contains(i,j ,k-1)) {
7272  tmp += - sx(i,j ,k-1) * facx * Real(2.0)
7273  + sy(i,j ,k-1) * facy * Real(4.0)
7274  - sz(i,j ,k-1) * facz * Real(2.0);
7275  }
7276  if (ccdom.contains(i-1,j ,k)) {
7277  tmp += - sx(i-1,j ,k) * facx * Real(2.0)
7278  + sy(i-1,j ,k) * facy * Real(4.0)
7279  - sz(i-1,j ,k) * facz * Real(2.0);
7280  }
7281  if (ccdom.contains(i,j ,k)) {
7282  tmp += - sx(i,j ,k) * facx * Real(2.0)
7283  + sy(i,j ,k) * facy * Real(4.0)
7284  - sz(i,j ,k) * facz * Real(2.0);
7285  }
7286  m0 -= tmp;
7287  if (gid(i,j+1,k) < gidmax && tmp != Real(0.0)) {
7288  cols[nelems] = gid(i,j+1,k);
7289  mat[nelems] = tmp;
7290  ++nelems;
7291  }
7292  }
7293 
7294  if (nddom.contains(i+1,j+1,k)) {
7295  Real tmp = Real(0.);
7296  if (ccdom.contains(i ,j ,k-1)) {
7297  tmp += sx(i ,j ,k-1) * facx * Real(2.0)
7298  + sy(i ,j ,k-1) * facy * Real(2.0)
7299  - sz(i ,j ,k-1) * facz;
7300  }
7301  if (ccdom.contains(i ,j ,k)) {
7302  tmp += sx(i ,j ,k) * facx * Real(2.0)
7303  + sy(i ,j ,k) * facy * Real(2.0)
7304  - sz(i ,j ,k) * facz;
7305  }
7306  m0 -= tmp;
7307  if (gid(i+1,j+1,k) < gidmax) {
7308  cols[nelems] = gid(i+1,j+1,k);
7309  mat[nelems] = tmp;
7310  ++nelems;
7311  }
7312  }
7313 
7314  if (nddom.contains(i-1,j-1,k+1)) {
7315  Real tmp = sx(i-1,j-1,k ) * facx
7316  + sy(i-1,j-1,k ) * facy
7317  + sz(i-1,j-1,k ) * facz;
7318  m0 -= tmp;
7319  if (gid(i-1,j-1,k+1) < gidmax) {
7320  cols[nelems] = gid(i-1,j-1,k+1);
7321  mat[nelems] = tmp;
7322  ++nelems;
7323  }
7324  }
7325 
7326  if (nddom.contains(i,j-1,k+1)) {
7327  Real tmp = Real(0.);
7328  if (ccdom.contains(i-1,j-1,k )) {
7329  tmp += - sx(i-1,j-1,k ) * facx
7330  + sy(i-1,j-1,k ) * facy * Real(2.0)
7331  + sz(i-1,j-1,k ) * facz * Real(2.0);
7332  }
7333  if (ccdom.contains(i,j-1,k )) {
7334  tmp += - sx(i,j-1,k ) * facx
7335  + sy(i,j-1,k ) * facy * Real(2.0)
7336  + sz(i,j-1,k ) * facz * Real(2.0);
7337  }
7338  m0 -= tmp;
7339  if (gid(i,j-1,k+1) < gidmax) {
7340  cols[nelems] = gid(i,j-1,k+1);
7341  mat[nelems] = tmp;
7342  ++nelems;
7343  }
7344  }
7345 
7346  if (nddom.contains(i+1,j-1,k+1)) {
7347  Real tmp = sx(i ,j-1,k ) * facx
7348  + sy(i ,j-1,k ) * facy
7349  + sz(i ,j-1,k ) * facz;
7350  m0 -= tmp;
7351  if (gid(i+1,j-1,k+1) < gidmax) {
7352  cols[nelems] = gid(i+1,j-1,k+1);
7353  mat[nelems] = tmp;
7354  ++nelems;
7355  }
7356  }
7357 
7358  if (nddom.contains(i-1,j,k+1)) {
7359  Real tmp = Real(0.);
7360  if (ccdom.contains(i-1,j-1,k )) {
7361  tmp += sx(i-1,j-1,k ) * facx * Real(2.0)
7362  - sy(i-1,j-1,k ) * facy
7363  + sz(i-1,j-1,k ) * facz * Real(2.0);
7364  }
7365  if (ccdom.contains(i-1,j,k )) {
7366  tmp += sx(i-1,j,k ) * facx * Real(2.0)
7367  - sy(i-1,j,k ) * facy
7368  + sz(i-1,j,k ) * facz * Real(2.0);
7369  }
7370  m0 -= tmp;
7371  if (gid(i-1,j,k+1) < gidmax) {
7372  cols[nelems] = gid(i-1,j,k+1);
7373  mat[nelems] = tmp;
7374  ++nelems;
7375  }
7376  }
7377 
7378  if (nddom.contains(i,j,k+1)) {
7379  Real tmp = Real(0.);
7380  if (ccdom.contains(i-1,j-1,k )) {
7381  tmp += - sx(i-1,j-1,k ) * facx * Real(2.0)
7382  - sy(i-1,j-1,k ) * facy * Real(2.0)
7383  + sz(i-1,j-1,k ) * facz * Real(4.0);
7384  }
7385  if (ccdom.contains(i,j-1,k )) {
7386  tmp += - sx(i,j-1,k ) * facx * Real(2.0)
7387  - sy(i,j-1,k ) * facy * Real(2.0)
7388  + sz(i,j-1,k ) * facz * Real(4.0);
7389  }
7390  if (ccdom.contains(i-1,j,k )) {
7391  tmp += - sx(i-1,j,k ) * facx * Real(2.0)
7392  - sy(i-1,j,k ) * facy * Real(2.0)
7393  + sz(i-1,j,k ) * facz * Real(4.0);
7394  }
7395  if (ccdom.contains(i,j,k )) {
7396  tmp += - sx(i,j,k ) * facx * Real(2.0)
7397  - sy(i,j,k ) * facy * Real(2.0)
7398  + sz(i,j,k ) * facz * Real(4.0);
7399  }
7400  m0 -= tmp;
7401  if (gid(i,j,k+1) < gidmax && tmp != Real(0.0)) {
7402  cols[nelems] = gid(i,j,k+1);
7403  mat[nelems] = tmp;
7404  ++nelems;
7405  }
7406  }
7407 
7408  if (nddom.contains(i+1,j,k+1)) {
7409  Real tmp = Real(0.);
7410  if (ccdom.contains(i ,j-1,k )) {
7411  tmp += sx(i ,j-1,k ) * facx * Real(2.0)
7412  - sy(i ,j-1,k ) * facy
7413  + sz(i ,j-1,k ) * facz * Real(2.0);
7414  }
7415  if (ccdom.contains(i ,j,k )) {
7416  tmp += sx(i ,j,k ) * facx * Real(2.0)
7417  - sy(i ,j,k ) * facy
7418  + sz(i ,j,k ) * facz * Real(2.0);
7419  }
7420  m0 -= tmp;
7421  if (gid(i+1,j,k+1) < gidmax) {
7422  cols[nelems] = gid(i+1,j,k+1);
7423  mat[nelems] = tmp;
7424  ++nelems;
7425  }
7426  }
7427 
7428  if (nddom.contains(i-1,j+1,k+1)) {
7429  Real tmp = sx(i-1,j ,k ) * facx
7430  + sy(i-1,j ,k ) * facy
7431  + sz(i-1,j ,k ) * facz;
7432  m0 -= tmp;
7433  if (gid(i-1,j+1,k+1) < gidmax) {
7434  cols[nelems] = gid(i-1,j+1,k+1);
7435  mat[nelems] = tmp;
7436  ++nelems;
7437  }
7438  }
7439 
7440  if (nddom.contains(i,j+1,k+1)) {
7441  Real tmp = Real(0.);
7442  if (ccdom.contains(i-1,j ,k )) {
7443  tmp += - sx(i-1,j ,k ) * facx
7444  + sy(i-1,j ,k ) * facy * Real(2.0)
7445  + sz(i-1,j ,k ) * facz * Real(2.0);
7446  }
7447  if (ccdom.contains(i,j ,k )) {
7448  tmp += - sx(i,j ,k ) * facx
7449  + sy(i,j ,k ) * facy * Real(2.0)
7450  + sz(i,j ,k ) * facz * Real(2.0);
7451  }
7452  m0 -= tmp;
7453  if (gid(i,j+1,k+1) < gidmax) {
7454  cols[nelems] = gid(i,j+1,k+1);
7455  mat[nelems] = tmp;
7456  ++nelems;
7457  }
7458  }
7459 
7460  if (nddom.contains(i+1,j+1,k+1)) {
7461  Real tmp = sx(i ,j ,k ) * facx
7462  + sy(i ,j ,k ) * facy
7463  + sz(i ,j ,k ) * facz;
7464  m0 -= tmp;
7465  if (gid(i+1,j+1,k+1) < gidmax) {
7466  cols[nelems] = gid(i+1,j+1,k+1);
7467  mat[nelems] = tmp;
7468  ++nelems;
7469  }
7470  }
7471 
7472  mat[nelems_old] = m0;
7473  ncols[lid(i,j,k)] = nelems - nelems_old;
7474  }
7475  });
7476 }
7477 
7478 template <typename HypreInt, typename AtomicInt>
7479 void mlndlap_fillijmat_cs_cpu (Box const& ndbx,
7480  Array4<AtomicInt const> const& gid,
7481  Array4<int const> const& lid,
7482  HypreInt* ncols, HypreInt* cols,
7483  Real* mat, // NOLINT(readability-non-const-parameter)
7484  Real sigma,
7485  GpuArray<Real,AMREX_SPACEDIM> const& dxinv,
7486  Box const& ccdom) noexcept
7487 {
7488  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0] * sigma;
7489  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1] * sigma;
7490  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2] * sigma;
7491  Real fxyz = facx + facy + facz;
7492  Real fmx2y2z = -facx + Real(2.0)*facy + Real(2.0)*facz;
7493  Real f2xmy2z = Real(2.0)*facx - facy + Real(2.0)*facz;
7494  Real f2x2ymz = Real(2.0)*facx + Real(2.0)*facy - facz;
7495  Real f4xm2ym2z = Real(4.0)*facx - Real(2.0)*facy - Real(2.0)*facz;
7496  Real fm2x4ym2z = -Real(2.0)*facx + Real(4.0)*facy - Real(2.0)*facz;
7497  Real fm2xm2y4z = -Real(2.0)*facx - Real(2.0)*facy + Real(4.0)*facz;
7498 
7499  const Box& nddom = amrex::surroundingNodes(ccdom);
7500 
7501  constexpr auto gidmax = std::numeric_limits<AtomicInt>::max();
7502  HypreInt nelems = 0;
7503  amrex::LoopOnCpu(ndbx, [&] (int i, int j, int k) noexcept
7504  {
7505  if (lid(i,j,k) >= 0)
7506  {
7507  HypreInt nelems_old = nelems;
7508  cols[nelems_old] = gid(i,j,k);
7509  Real m0 = Real(0.);
7510  ++nelems;
7511 
7512  if (nddom.contains(i-1,j-1,k-1)) {
7513  Real tmp = fxyz;
7514  m0 -= tmp;
7515  if ( gid(i-1,j-1,k-1) < gidmax) {
7516  cols[nelems] = gid(i-1,j-1,k-1);
7517  mat[nelems] = tmp;
7518  ++nelems;
7519  }
7520  }
7521 
7522  if (nddom.contains(i,j-1,k-1)) {
7523  Real tmp = Real(0.);
7524  if (ccdom.contains(i-1,j-1,k-1)) {
7525  tmp += fmx2y2z;
7526  }
7527  if (ccdom.contains(i,j-1,k-1)) {
7528  tmp += fmx2y2z;
7529  }
7530  m0 -= tmp;
7531  if (gid(i,j-1,k-1) < gidmax) {
7532  cols[nelems] = gid(i,j-1,k-1);
7533  mat[nelems] = tmp;
7534  ++nelems;
7535  }
7536  }
7537 
7538  if (nddom.contains(i+1,j-1,k-1)) {
7539  Real tmp = fxyz;
7540  m0 -= tmp;
7541  if (gid(i+1,j-1,k-1) < gidmax) {
7542  cols[nelems] = gid(i+1,j-1,k-1);
7543  mat[nelems] = tmp;
7544  ++nelems;
7545  }
7546  }
7547 
7548  if (nddom.contains(i-1,j,k-1)) {
7549  Real tmp = Real(0.);
7550  if (ccdom.contains(i-1,j-1,k-1)) {
7551  tmp += f2xmy2z;
7552  }
7553  if (ccdom.contains(i-1,j,k-1)) {
7554  tmp += f2xmy2z;
7555  }
7556  m0 -= tmp;
7557  if (gid(i-1,j,k-1) < gidmax) {
7558  cols[nelems] = gid(i-1,j,k-1);
7559  mat[nelems] = tmp;
7560  ++nelems;
7561  }
7562  }
7563 
7564  if (nddom.contains(i,j,k-1) && fm2xm2y4z != Real(0.0)) {
7565  Real tmp = Real(0.);
7566  if (ccdom.contains(i-1,j-1,k-1)) {
7567  tmp += fm2xm2y4z;
7568  }
7569  if (ccdom.contains(i,j-1,k-1)) {
7570  tmp += fm2xm2y4z;
7571  }
7572  if (ccdom.contains(i-1,j,k-1)) {
7573  tmp += fm2xm2y4z;
7574  }
7575  if (ccdom.contains(i,j,k-1)) {
7576  tmp += fm2xm2y4z;
7577  }
7578  m0 -= tmp;
7579  if (gid(i,j,k-1) < gidmax) {
7580  cols[nelems] = gid(i,j,k-1);
7581  mat[nelems] = tmp;
7582  ++nelems;
7583  }
7584  }
7585 
7586  if (nddom.contains(i+1,j,k-1)) {
7587  Real tmp = Real(0.);
7588  if (ccdom.contains(i ,j-1,k-1)) {
7589  tmp += f2xmy2z;
7590  }
7591  if (ccdom.contains(i ,j,k-1)) {
7592  tmp += f2xmy2z;
7593  }
7594  m0 -= tmp;
7595  if (gid(i+1,j,k-1) < gidmax) {
7596  cols[nelems] = gid(i+1,j,k-1);
7597  mat[nelems] = tmp;
7598  ++nelems;
7599  }
7600  }
7601 
7602  if (nddom.contains(i-1,j+1,k-1)) {
7603  Real tmp = fxyz;
7604  m0 -= tmp;
7605  if (gid(i-1,j+1,k-1) < gidmax) {
7606  cols[nelems] = gid(i-1,j+1,k-1);
7607  mat[nelems] = tmp;
7608  ++nelems;
7609  }
7610  }
7611 
7612  if (nddom.contains(i,j+1,k-1)) {
7613  Real tmp = Real(0.);
7614  if (ccdom.contains(i-1,j ,k-1)) {
7615  tmp += fmx2y2z;
7616  }
7617  if (ccdom.contains(i,j ,k-1)) {
7618  tmp += fmx2y2z;
7619  }
7620  m0 -= tmp;
7621  if (gid(i,j+1,k-1) < gidmax) {
7622  cols[nelems] = gid(i,j+1,k-1);
7623  mat[nelems] = tmp;
7624  ++nelems;
7625  }
7626  }
7627 
7628  if (nddom.contains(i+1,j+1,k-1)) {
7629  Real tmp = fxyz;
7630  m0 -= tmp;
7631  if (gid(i+1,j+1,k-1) < gidmax) {
7632  cols[nelems] = gid(i+1,j+1,k-1);
7633  mat[nelems] = tmp;
7634  ++nelems;
7635  }
7636  }
7637 
7638  if (nddom.contains(i-1,j-1,k)) {
7639  Real tmp = Real(0.);
7640  if (ccdom.contains(i-1,j-1,k-1)) {
7641  tmp += f2x2ymz;
7642  }
7643  if (ccdom.contains(i-1,j-1,k)) {
7644  tmp += f2x2ymz;
7645  }
7646  m0 -= tmp;
7647  if (gid(i-1,j-1,k) < gidmax) {
7648  cols[nelems] = gid(i-1,j-1,k);
7649  mat[nelems] = tmp;
7650  ++nelems;
7651  }
7652  }
7653 
7654  if (nddom.contains(i,j-1,k) && fm2x4ym2z != Real(0.0)) {
7655  Real tmp = Real(0.);
7656  if (ccdom.contains(i-1,j-1,k-1)) {
7657  tmp += fm2x4ym2z;
7658  }
7659  if (ccdom.contains(i,j-1,k-1)) {
7660  tmp += fm2x4ym2z;
7661  }
7662  if (ccdom.contains(i-1,j-1,k)) {
7663  tmp += fm2x4ym2z;
7664  }
7665  if (ccdom.contains(i,j-1,k)) {
7666  tmp += fm2x4ym2z;
7667  }
7668  m0 -= tmp;
7669  if (gid(i,j-1,k) < gidmax) {
7670  cols[nelems] = gid(i,j-1,k);
7671  mat[nelems] = tmp;
7672  ++nelems;
7673  }
7674  }
7675 
7676  if (nddom.contains(i+1,j-1,k)) {
7677  Real tmp = Real(0.);
7678  if (ccdom.contains(i ,j-1,k-1)) {
7679  tmp += f2x2ymz;
7680  }
7681  if (ccdom.contains(i ,j-1,k)) {
7682  tmp += f2x2ymz;
7683  }
7684  m0 -= tmp;
7685  if (gid(i+1,j-1,k) < gidmax) {
7686  cols[nelems] = gid(i+1,j-1,k);
7687  mat[nelems] = tmp;
7688  ++nelems;
7689  }
7690  }
7691 
7692  if (nddom.contains(i-1,j,k) && f4xm2ym2z != Real(0.0)) {
7693  Real tmp = Real(0.);
7694  if (ccdom.contains(i-1,j-1,k-1)) {
7695  tmp += f4xm2ym2z;
7696  }
7697  if (ccdom.contains(i-1,j,k-1)) {
7698  tmp += f4xm2ym2z;
7699  }
7700  if (ccdom.contains(i-1,j-1,k)) {
7701  tmp += f4xm2ym2z;
7702  }
7703  if (ccdom.contains(i-1,j,k)) {
7704  tmp += f4xm2ym2z;
7705  }
7706  m0 -= tmp;
7707  if (gid(i-1,j,k) < gidmax) {
7708  cols[nelems] = gid(i-1,j,k);
7709  mat[nelems] = tmp;
7710  ++nelems;
7711  }
7712  }
7713 
7714  if (nddom.contains(i+1,j,k) && f4xm2ym2z != Real(0.0)) {
7715  Real tmp = Real(0.);
7716  if (ccdom.contains(i ,j-1,k-1)) {
7717  tmp += f4xm2ym2z;
7718  }
7719  if (ccdom.contains(i ,j,k-1)) {
7720  tmp += f4xm2ym2z;
7721  }
7722  if (ccdom.contains(i ,j-1,k)) {
7723  tmp += f4xm2ym2z;
7724  }
7725  if (ccdom.contains(i ,j,k)) {
7726  tmp += f4xm2ym2z;
7727  }
7728  m0 -= tmp;
7729  if (gid(i+1,j,k) < gidmax) {
7730  cols[nelems] = gid(i+1,j,k);
7731  mat[nelems] = tmp;
7732  ++nelems;
7733  }
7734  }
7735 
7736  if (nddom.contains(i-1,j+1,k)) {
7737  Real tmp = Real(0.);
7738  if (ccdom.contains(i-1,j ,k-1)) {
7739  tmp += f2x2ymz;
7740  }
7741  if (ccdom.contains(i-1,j ,k)) {
7742  tmp += f2x2ymz;
7743  }
7744  m0 -= tmp;
7745  if (gid(i-1,j+1,k) < gidmax) {
7746  cols[nelems] = gid(i-1,j+1,k);
7747  mat[nelems] = tmp;
7748  ++nelems;
7749  }
7750  }
7751 
7752  if (nddom.contains(i,j+1,k) && fm2x4ym2z != Real(0.0)) {
7753  Real tmp = Real(0.);
7754  if (ccdom.contains(i-1,j ,k-1)) {
7755  tmp += fm2x4ym2z;
7756  }
7757  if (ccdom.contains(i,j ,k-1)) {
7758  tmp += fm2x4ym2z;
7759  }
7760  if (ccdom.contains(i-1,j ,k)) {
7761  tmp += fm2x4ym2z;
7762  }
7763  if (ccdom.contains(i,j ,k)) {
7764  tmp += fm2x4ym2z;
7765  }
7766  m0 -= tmp;
7767  if (gid(i,j+1,k) < gidmax) {
7768  cols[nelems] = gid(i,j+1,k);
7769  mat[nelems] = tmp;
7770  ++nelems;
7771  }
7772  }
7773 
7774  if (nddom.contains(i+1,j+1,k)) {
7775  Real tmp = Real(0.);
7776  if (ccdom.contains(i ,j ,k-1)) {
7777  tmp += f2x2ymz;
7778  }
7779  if (ccdom.contains(i ,j ,k)) {
7780  tmp += f2x2ymz;
7781  }
7782  m0 -= tmp;
7783  if (gid(i+1,j+1,k) < gidmax) {
7784  cols[nelems] = gid(i+1,j+1,k);
7785  mat[nelems] = tmp;
7786  ++nelems;
7787  }
7788  }
7789 
7790  if (nddom.contains(i-1,j-1,k+1)) {
7791  Real tmp = fxyz;
7792  m0 -= tmp;
7793  if (gid(i-1,j-1,k+1) < gidmax) {
7794  cols[nelems] = gid(i-1,j-1,k+1);
7795  mat[nelems] = tmp;
7796  ++nelems;
7797  }
7798  }
7799 
7800  if (nddom.contains(i,j-1,k+1)) {
7801  Real tmp = Real(0.);
7802  if (ccdom.contains(i-1,j-1,k )) {
7803  tmp += fmx2y2z;
7804  }
7805  if (ccdom.contains(i,j-1,k )) {
7806  tmp += fmx2y2z;
7807  }
7808  m0 -= tmp;
7809  if (gid(i,j-1,k+1) < gidmax) {
7810  cols[nelems] = gid(i,j-1,k+1);
7811  mat[nelems] = tmp;
7812  ++nelems;
7813  }
7814  }
7815 
7816  if (nddom.contains(i+1,j-1,k+1)) {
7817  Real tmp = fxyz;
7818  m0 -= tmp;
7819  if (gid(i+1,j-1,k+1) < gidmax) {
7820  cols[nelems] = gid(i+1,j-1,k+1);
7821  mat[nelems] = tmp;
7822  ++nelems;
7823  }
7824  }
7825 
7826  if (nddom.contains(i-1,j,k+1)) {
7827  Real tmp = Real(0.);
7828  if (ccdom.contains(i-1,j-1,k )) {
7829  tmp += f2xmy2z;
7830  }
7831  if (ccdom.contains(i-1,j,k )) {
7832  tmp += f2xmy2z;
7833  }
7834  m0 -= tmp;
7835  if (gid(i-1,j,k+1) < gidmax) {
7836  cols[nelems] = gid(i-1,j,k+1);
7837  mat[nelems] = tmp;
7838  ++nelems;
7839  }
7840  }
7841 
7842  if (nddom.contains(i,j,k+1) && fm2xm2y4z != Real(0.0)) {
7843  Real tmp = Real(0.);
7844  if (ccdom.contains(i-1,j-1,k )) {
7845  tmp += fm2xm2y4z;
7846  }
7847  if (ccdom.contains(i,j-1,k )) {
7848  tmp += fm2xm2y4z;
7849  }
7850  if (ccdom.contains(i-1,j,k )) {
7851  tmp += fm2xm2y4z;
7852  }
7853  if (ccdom.contains(i,j,k )) {
7854  tmp += fm2xm2y4z;
7855  }
7856  m0 -= tmp;
7857  if (gid(i,j,k+1) < gidmax) {
7858  cols[nelems] = gid(i,j,k+1);
7859  mat[nelems] = tmp;
7860  ++nelems;
7861  }
7862  }
7863 
7864  if (nddom.contains(i+1,j,k+1)) {
7865  Real tmp = Real(0.);
7866  if (ccdom.contains(i ,j-1,k )) {
7867  tmp += f2xmy2z;
7868  }
7869  if (ccdom.contains(i ,j,k )) {
7870  tmp += f2xmy2z;
7871  }
7872  m0 -= tmp;
7873  if (gid(i+1,j,k+1) < gidmax) {
7874  cols[nelems] = gid(i+1,j,k+1);
7875  mat[nelems] = tmp;
7876  ++nelems;
7877  }
7878  }
7879 
7880  if (nddom.contains(i-1,j+1,k+1)) {
7881  Real tmp = fxyz;
7882  m0 -= tmp;
7883  if (gid(i-1,j+1,k+1) < gidmax) {
7884  cols[nelems] = gid(i-1,j+1,k+1);
7885  mat[nelems] = tmp;
7886  ++nelems;
7887  }
7888  }
7889 
7890  if (nddom.contains(i,j+1,k+1)) {
7891  Real tmp = Real(0.);
7892  if (ccdom.contains(i-1,j ,k )) {
7893  tmp += fmx2y2z;
7894  }
7895  if (ccdom.contains(i,j ,k )) {
7896  tmp += fmx2y2z;
7897  }
7898  m0 -= tmp;
7899  if (gid(i,j+1,k+1) < gidmax) {
7900  cols[nelems] = gid(i,j+1,k+1);
7901  mat[nelems] = tmp;
7902  ++nelems;
7903  }
7904  }
7905 
7906  if (nddom.contains(i+1,j+1,k+1)) {
7907  Real tmp = fxyz;
7908  m0 -= tmp;
7909  if (gid(i+1,j+1,k+1) < gidmax) {
7910  cols[nelems] = gid(i+1,j+1,k+1);
7911  mat[nelems] = tmp;
7912  ++nelems;
7913  }
7914  }
7915 
7916  mat[nelems_old] = m0;
7917  ncols[lid(i,j,k)] = nelems - nelems_old;
7918  }
7919  });
7920 }
7921 
7922 #ifdef AMREX_USE_GPU
7923 
7924 template <typename HypreInt, typename AtomicInt>
7926 void mlndlap_fillijmat_sten_gpu (const int ps, const int i, const int j, const int k,
7927  const int offset,
7928  Array4<AtomicInt const> const& gid,
7929  Array4<int const> const& lid,
7930  HypreInt* ncols, HypreInt* cols,
7931  Real* mat, // NOLINT(readability-non-const-parameter)
7932  Array4<Real const> const& sten) noexcept
7933 {
7934  if (lid(i,j,k) >= 0)
7935  {
7936  constexpr int ist_000 = 1-1;
7937  constexpr int ist_p00 = 2-1;
7938  constexpr int ist_0p0 = 3-1;
7939  constexpr int ist_00p = 4-1;
7940  constexpr int ist_pp0 = 5-1;
7941  constexpr int ist_p0p = 6-1;
7942  constexpr int ist_0pp = 7-1;
7943  constexpr int ist_ppp = 8-1;
7944 
7945  constexpr auto gidmax = std::numeric_limits<AtomicInt>::max();
7946  int nelems = 0;
7947 
7948  if (offset == 1 || offset == 0) {
7949  if (gid(i-1,j-1,k-1) < gidmax) {
7950  if (offset != 0) {
7951  cols[ps] = gid(i-1,j-1,k-1);
7952  mat[ps] = sten(i-1,j-1,k-1,ist_ppp);
7953  }
7954  ++nelems;
7955  }
7956  if (offset != 0) { return; }
7957  }
7958 
7959  if (offset == 2 || offset == 0) {
7960  if (gid(i,j-1,k-1) < gidmax) {
7961  if (offset != 0) {
7962  cols[ps] = gid(i,j-1,k-1);
7963  mat[ps] = sten(i,j-1,k-1,ist_0pp);
7964  }
7965  ++nelems;
7966  }
7967  if (offset != 0) { return; }
7968  }
7969 
7970  if (offset == 3 || offset == 0) {
7971  if (gid(i+1,j-1,k-1) < gidmax) {
7972  if (offset != 0) {
7973  cols[ps] = gid(i+1,j-1,k-1);
7974  mat[ps] = sten(i,j-1,k-1,ist_ppp);
7975  }
7976  ++nelems;
7977  }
7978  if (offset != 0) { return; }
7979  }
7980 
7981  if (offset == 4 || offset == 0) {
7982  if (gid(i-1,j,k-1) < gidmax) {
7983  if (offset != 0) {
7984  cols[ps] = gid(i-1,j,k-1);
7985  mat[ps] = sten(i-1,j,k-1,ist_p0p);
7986  }
7987  ++nelems;
7988  }
7989  if (offset != 0) { return; }
7990  }
7991 
7992  if (offset == 5 || offset == 0) {
7993  if (gid(i,j,k-1) < gidmax) {
7994  if (offset != 0) {
7995  cols[ps] = gid(i,j,k-1);
7996  mat[ps] = sten(i,j,k-1,ist_00p);
7997  }
7998  ++nelems;
7999  }
8000  if (offset != 0) { return; }
8001  }
8002 
8003  if (offset == 6 || offset == 0) {
8004  if (gid(i+1,j,k-1) < gidmax) {
8005  if (offset != 0) {
8006  cols[ps] = gid(i+1,j,k-1);
8007  mat[ps] = sten(i,j,k-1,ist_p0p);
8008  }
8009  ++nelems;
8010  }
8011  if (offset != 0) { return; }
8012  }
8013 
8014  if (offset == 7 || offset == 0) {
8015  if (gid(i-1,j+1,k-1) < gidmax) {
8016  if (offset != 0) {
8017  cols[ps] = gid(i-1,j+1,k-1);
8018  mat[ps] = sten(i-1,j,k-1,ist_ppp);
8019  }
8020  ++nelems;
8021  }
8022  if (offset != 0) { return; }
8023  }
8024 
8025  if (offset == 8 || offset == 0) {
8026  if (gid(i,j+1,k-1) < gidmax) {
8027  if (offset != 0) {
8028  cols[ps] = gid(i,j+1,k-1);
8029  mat[ps] = sten(i,j,k-1,ist_0pp);
8030  }
8031  ++nelems;
8032  }
8033  if (offset != 0) { return; }
8034  }
8035 
8036  if (offset == 9 || offset == 0) {
8037  if (gid(i+1,j+1,k-1) < gidmax) {
8038  if (offset != 0) {
8039  cols[ps] = gid(i+1,j+1,k-1);
8040  mat[ps] = sten(i,j,k-1,ist_ppp);
8041  }
8042  ++nelems;
8043  }
8044  if (offset != 0) { return; }
8045  }
8046 
8047  if (offset == 10 || offset == 0) {
8048  if (gid(i-1,j-1,k) < gidmax) {
8049  if (offset != 0) {
8050  cols[ps] = gid(i-1,j-1,k);
8051  mat[ps] = sten(i-1,j-1,k,ist_pp0);
8052  }
8053  ++nelems;
8054  }
8055  if (offset != 0) { return; }
8056  }
8057 
8058  if (offset == 11 || offset == 0) {
8059  if (gid(i,j-1,k) < gidmax) {
8060  if (offset != 0) {
8061  cols[ps] = gid(i,j-1,k);
8062  mat[ps] = sten(i,j-1,k,ist_0p0);
8063  }
8064  ++nelems;
8065  }
8066  if (offset != 0) { return; }
8067  }
8068 
8069  if (offset == 12 || offset == 0) {
8070  if (gid(i+1,j-1,k) < gidmax) {
8071  if (offset != 0) {
8072  cols[ps] = gid(i+1,j-1,k);
8073  mat[ps] = sten(i,j-1,k,ist_pp0);
8074  }
8075  ++nelems;
8076  }
8077  if (offset != 0) { return; }
8078  }
8079 
8080  if (offset == 13 || offset == 0) {
8081  if (gid(i-1,j,k) < gidmax) {
8082  if (offset != 0) {
8083  cols[ps] = gid(i-1,j,k);
8084  mat[ps] = sten(i-1,j,k,ist_p00);
8085  }
8086  ++nelems;
8087  }
8088  if (offset != 0) { return; }
8089  }
8090 
8091  if (offset == 14 || offset == 0) {
8092  if (gid(i+1,j,k) < gidmax) {
8093  if (offset != 0) {
8094  cols[ps] = gid(i+1,j,k);
8095  mat[ps] = sten(i,j,k,ist_p00);
8096  }
8097  ++nelems;
8098  }
8099  if (offset != 0) { return; }
8100  }
8101 
8102  if (offset == 15 || offset == 0) {
8103  if (gid(i-1,j+1,k) < gidmax) {
8104  if (offset != 0) {
8105  cols[ps] = gid(i-1,j+1,k);
8106  mat[ps] = sten(i-1,j,k,ist_pp0);
8107  }
8108  ++nelems;
8109  }
8110  if (offset != 0) { return; }
8111  }
8112 
8113  if (offset == 16 || offset == 0) {
8114  if (gid(i,j+1,k) < gidmax) {
8115  if (offset != 0) {
8116  cols[ps] = gid(i,j+1,k);
8117  mat[ps] = sten(i,j,k,ist_0p0);
8118  }
8119  ++nelems;
8120  }
8121  if (offset != 0) { return; }
8122  }
8123 
8124  if (offset == 17 || offset == 0) {
8125  if (gid(i+1,j+1,k) < gidmax) {
8126  if (offset != 0) {
8127  cols[ps] = gid(i+1,j+1,k);
8128  mat[ps] = sten(i,j,k,ist_pp0);
8129  }
8130  ++nelems;
8131  }
8132  if (offset != 0) { return; }
8133  }
8134 
8135  if (offset == 18 || offset == 0) {
8136  if (gid(i-1,j-1,k+1) < gidmax) {
8137  if (offset != 0) {
8138  cols[ps] = gid(i-1,j-1,k+1);
8139  mat[ps] = sten(i-1,j-1,k,ist_ppp);
8140  }
8141  ++nelems;
8142  }
8143  if (offset != 0) { return; }
8144  }
8145 
8146  if (offset == 19 || offset == 0) {
8147  if (gid(i,j-1,k+1) < gidmax) {
8148  if (offset != 0) {
8149  cols[ps] = gid(i,j-1,k+1);
8150  mat[ps] = sten(i,j-1,k,ist_0pp);
8151  }
8152  ++nelems;
8153  }
8154  if (offset != 0) { return; }
8155  }
8156 
8157  if (offset == 20 || offset == 0) {
8158  if (gid(i+1,j-1,k+1) < gidmax) {
8159  if (offset != 0) {
8160  cols[ps] = gid(i+1,j-1,k+1);
8161  mat[ps] = sten(i,j-1,k,ist_ppp);
8162  }
8163  ++nelems;
8164  }
8165  if (offset != 0) { return; }
8166  }
8167 
8168  if (offset == 21 || offset == 0) {
8169  if (gid(i-1,j,k+1) < gidmax) {
8170  if (offset != 0) {
8171  cols[ps] = gid(i-1,j,k+1);
8172  mat[ps] = sten(i-1,j,k,ist_p0p);
8173  }
8174  ++nelems;
8175  }
8176  if (offset != 0) { return; }
8177  }
8178 
8179  if (offset == 22 || offset == 0) {
8180  if (gid(i,j,k+1) < gidmax) {
8181  if (offset != 0) {
8182  cols[ps] = gid(i,j,k+1);
8183  mat[ps] = sten(i,j,k,ist_00p);
8184  }
8185  ++nelems;
8186  }
8187  if (offset != 0) { return; }
8188  }
8189 
8190  if (offset == 23 || offset == 0) {
8191  if (gid(i+1,j,k+1) < gidmax) {
8192  if (offset != 0) {
8193  cols[ps] = gid(i+1,j,k+1);
8194  mat[ps] = sten(i,j,k,ist_p0p);
8195  }
8196  ++nelems;
8197  }
8198  if (offset != 0) { return; }
8199  }
8200 
8201  if (offset == 24 || offset == 0) {
8202  if (gid(i-1,j+1,k+1) < gidmax) {
8203  if (offset != 0) {
8204  cols[ps] = gid(i-1,j+1,k+1);
8205  mat[ps] = sten(i-1,j,k,ist_ppp);
8206  }
8207  ++nelems;
8208  }
8209  if (offset != 0) { return; }
8210  }
8211 
8212  if (offset == 25 || offset == 0) {
8213  if (gid(i,j+1,k+1) < gidmax) {
8214  if (offset != 0) {
8215  cols[ps] = gid(i,j+1,k+1);
8216  mat[ps] = sten(i,j,k,ist_0pp);
8217  }
8218  ++nelems;
8219  }
8220  if (offset != 0) { return; }
8221  }
8222 
8223  if (offset == 26 || offset == 0) {
8224  if (gid(i+1,j+1,k+1) < gidmax) {
8225  if (offset != 0) {
8226  cols[ps] = gid(i+1,j+1,k+1);
8227  mat[ps] = sten(i,j,k,ist_ppp);
8228  }
8229  ++nelems;
8230  }
8231  if (offset != 0) { return; }
8232  }
8233 
8234  // Only offset == 0 could get this far.
8235  cols[ps] = gid(i,j,k);
8236  mat[ps] = sten(i,j,k,ist_000);
8237  ncols[lid(i,j,k)] = nelems+1;
8238  }
8239 }
8240 
8241 template <typename HypreInt, typename AtomicInt>
8243 void mlndlap_fillijmat_aa_gpu (const int ps, const int i, const int j, const int k,
8244  const int offset,
8245  Box const& ndbx, Array4<AtomicInt const> const& gid,
8246  Array4<int const> const& lid,
8247  HypreInt* ncols, HypreInt* cols,
8248  Real* mat, // NOLINT(readability-non-const-parameter)
8249  Array4<Real const> const& sig,
8250  GpuArray<Real,AMREX_SPACEDIM> const& dxinv,
8251  Box const& ccdom) noexcept
8252 {
8253  if (lid(i,j,k) >= 0)
8254  {
8255  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
8256  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
8257  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
8258  Real fxyz = facx + facy + facz;
8259  Real fmx2y2z = -facx + Real(2.0)*facy + Real(2.0)*facz;
8260  Real f2xmy2z = Real(2.0)*facx - facy + Real(2.0)*facz;
8261  Real f2x2ymz = Real(2.0)*facx + Real(2.0)*facy - facz;
8262  Real f4xm2ym2z = Real(4.0)*facx - Real(2.0)*facy - Real(2.0)*facz;
8263  Real fm2x4ym2z = -Real(2.0)*facx + Real(4.0)*facy - Real(2.0)*facz;
8264  Real fm2xm2y4z = -Real(2.0)*facx - Real(2.0)*facy + Real(4.0)*facz;
8265 
8266  const Box& nddom = amrex::surroundingNodes(ccdom);
8267 
8268  constexpr auto gidmax = std::numeric_limits<AtomicInt>::max();
8269  int nelems = 0;
8270  Real m0 = Real(0.);
8271 
8272  if (offset == 1 || offset == 0) {
8273  if (nddom.contains(i-1,j-1,k-1)) {
8274  Real tmp = sig(i-1,j-1,k-1) * fxyz;
8275  m0 -= tmp;
8276  if ( gid(i-1,j-1,k-1) < gidmax) {
8277  if (offset != 0) {
8278  cols[ps] = gid(i-1,j-1,k-1);
8279  mat[ps] = tmp;
8280  }
8281  ++nelems;
8282  }
8283  }
8284  if (offset != 0) { return; }
8285  }
8286 
8287  if (offset == 2 || offset == 0) {
8288  if (nddom.contains(i,j-1,k-1)) {
8289  Real tmp = Real(0.);
8290  if (ccdom.contains(i-1,j-1,k-1)) {
8291  tmp += sig(i-1,j-1,k-1) * fmx2y2z;
8292  }
8293  if (ccdom.contains(i,j-1,k-1)) {
8294  tmp += sig(i,j-1,k-1) * fmx2y2z;
8295  }
8296  m0 -= tmp;
8297  if (gid(i,j-1,k-1) < gidmax) {
8298  if (offset != 0) {
8299  cols[ps] = gid(i,j-1,k-1);
8300  mat[ps] = tmp;
8301  }
8302  ++nelems;
8303  }
8304  }
8305  if (offset != 0) { return; }
8306  }
8307 
8308  if (offset == 3 || offset == 0) {
8309  if (nddom.contains(i+1,j-1,k-1)) {
8310  Real tmp = sig(i ,j-1,k-1) * fxyz;
8311  m0 -= tmp;
8312  if (gid(i+1,j-1,k-1) < gidmax) {
8313  if (offset != 0) {
8314  cols[ps] = gid(i+1,j-1,k-1);
8315  mat[ps] = tmp;
8316  }
8317  ++nelems;
8318  }
8319  }
8320  if (offset != 0) { return; }
8321  }
8322 
8323  if (offset == 4 || offset == 0) {
8324  if (nddom.contains(i-1,j,k-1)) {
8325  Real tmp = Real(0.);
8326  if (ccdom.contains(i-1,j-1,k-1)) {
8327  tmp += sig(i-1,j-1,k-1) * f2xmy2z;
8328  }
8329  if (ccdom.contains(i-1,j,k-1)) {
8330  tmp += sig(i-1,j,k-1) * f2xmy2z;
8331  }
8332  m0 -= tmp;
8333  if (gid(i-1,j,k-1) < gidmax) {
8334  if (offset != 0) {
8335  cols[ps] = gid(i-1,j,k-1);
8336  mat[ps] = tmp;
8337  }
8338  ++nelems;
8339  }
8340  }
8341  if (offset != 0) { return; }
8342  }
8343 
8344  if (offset == 5 || offset == 0) {
8345  if (nddom.contains(i,j,k-1)) {
8346  Real tmp = Real(0.);
8347  if (ccdom.contains(i-1,j-1,k-1)) {
8348  tmp += sig(i-1,j-1,k-1) * fm2xm2y4z;
8349  }
8350  if (ccdom.contains(i,j-1,k-1)) {
8351  tmp += sig(i,j-1,k-1) * fm2xm2y4z;
8352  }
8353  if (ccdom.contains(i-1,j,k-1)) {
8354  tmp += sig(i-1,j,k-1) * fm2xm2y4z;
8355  }
8356  if (ccdom.contains(i,j,k-1)) {
8357  tmp += sig(i,j,k-1) * fm2xm2y4z;
8358  }
8359  m0 -= tmp;
8360  if (gid(i,j,k-1) < gidmax) {
8361  if (offset != 0) {
8362  cols[ps] = gid(i,j,k-1);
8363  mat[ps] = tmp;
8364  }
8365  ++nelems;
8366  }
8367  }
8368  if (offset != 0) { return; }
8369  }
8370 
8371  if (offset == 6 || offset == 0) {
8372  if (nddom.contains(i+1,j,k-1)) {
8373  Real tmp = Real(0.);
8374  if (ccdom.contains(i ,j-1,k-1)) {
8375  tmp += sig(i ,j-1,k-1) * f2xmy2z;
8376  }
8377  if (ccdom.contains(i ,j,k-1)) {
8378  tmp += sig(i ,j,k-1) * f2xmy2z;
8379  }
8380  m0 -= tmp;
8381  if (gid(i+1,j,k-1) < gidmax) {
8382  if (offset != 0) {
8383  cols[ps] = gid(i+1,j,k-1);
8384  mat[ps] = tmp;
8385  }
8386  ++nelems;
8387  }
8388  }
8389  if (offset != 0) { return; }
8390  }
8391 
8392  if (offset == 7 || offset == 0) {
8393  if (nddom.contains(i-1,j+1,k-1)) {
8394  Real tmp = sig(i-1,j ,k-1) * fxyz;
8395  m0 -= tmp;
8396  if (gid(i-1,j+1,k-1) < gidmax) {
8397  if (offset != 0) {
8398  cols[ps] = gid(i-1,j+1,k-1);
8399  mat[ps] = tmp;
8400  }
8401  ++nelems;
8402  }
8403  }
8404  if (offset != 0) { return; }
8405  }
8406 
8407  if (offset == 8 || offset == 0) {
8408  if (nddom.contains(i,j+1,k-1)) {
8409  Real tmp = Real(0.);
8410  if (ccdom.contains(i-1,j ,k-1)) {
8411  tmp += sig(i-1,j ,k-1) * fmx2y2z;
8412  }
8413  if (ccdom.contains(i,j ,k-1)) {
8414  tmp += sig(i,j ,k-1) * fmx2y2z;
8415  }
8416  m0 -= tmp;
8417  if (gid(i,j+1,k-1) < gidmax) {
8418  if (offset != 0) {
8419  cols[ps] = gid(i,j+1,k-1);
8420  mat[ps] = tmp;
8421  }
8422  ++nelems;
8423  }
8424  }
8425  if (offset != 0) { return; }
8426  }
8427 
8428  if (offset == 9 || offset == 0) {
8429  if (nddom.contains(i+1,j+1,k-1)) {
8430  Real tmp = sig(i ,j ,k-1) * fxyz;
8431  m0 -= tmp;
8432  if (gid(i+1,j+1,k-1) < gidmax) {
8433  if (offset != 0) {
8434  cols[ps] = gid(i+1,j+1,k-1);
8435  mat[ps] = tmp;
8436  }
8437  ++nelems;
8438  }
8439  }
8440  if (offset != 0) { return; }
8441  }
8442 
8443  if (offset == 10 || offset == 0) {
8444  if (nddom.contains(i-1,j-1,k)) {
8445  Real tmp = Real(0.);
8446  if (ccdom.contains(i-1,j-1,k-1)) {
8447  tmp += sig(i-1,j-1,k-1) * f2x2ymz;
8448  }
8449  if (ccdom.contains(i-1,j-1,k)) {
8450  tmp += sig(i-1,j-1,k) * f2x2ymz;
8451  }
8452  m0 -= tmp;
8453  if (gid(i-1,j-1,k) < gidmax) {
8454  if (offset != 0) {
8455  cols[ps] = gid(i-1,j-1,k);
8456  mat[ps] = tmp;
8457  }
8458  ++nelems;
8459  }
8460  }
8461  if (offset != 0) { return; }
8462  }
8463 
8464  if (offset == 11 || offset == 0) {
8465  if (nddom.contains(i,j-1,k)) {
8466  Real tmp = Real(0.);
8467  if (ccdom.contains(i-1,j-1,k-1)) {
8468  tmp += sig(i-1,j-1,k-1) * fm2x4ym2z;
8469  }
8470  if (ccdom.contains(i,j-1,k-1)) {
8471  tmp += sig(i,j-1,k-1) * fm2x4ym2z;
8472  }
8473  if (ccdom.contains(i-1,j-1,k)) {
8474  tmp += sig(i-1,j-1,k) * fm2x4ym2z;
8475  }
8476  if (ccdom.contains(i,j-1,k)) {
8477  tmp += sig(i,j-1,k) * fm2x4ym2z;
8478  }
8479  m0 -= tmp;
8480  if (gid(i,j-1,k) < gidmax) {
8481  if (offset != 0) {
8482  cols[ps] = gid(i,j-1,k);
8483  mat[ps] = tmp;
8484  }
8485  ++nelems;
8486  }
8487  }
8488  if (offset != 0) { return; }
8489  }
8490 
8491  if (offset == 12 || offset == 0) {
8492  if (nddom.contains(i+1,j-1,k)) {
8493  Real tmp = Real(0.);
8494  if (ccdom.contains(i ,j-1,k-1)) {
8495  tmp += sig(i ,j-1,k-1) * f2x2ymz;
8496  }
8497  if (ccdom.contains(i ,j-1,k)) {
8498  tmp += sig(i ,j-1,k) * f2x2ymz;
8499  }
8500  m0 -= tmp;
8501  if (gid(i+1,j-1,k) < gidmax) {
8502  if (offset != 0) {
8503  cols[ps] = gid(i+1,j-1,k);
8504  mat[ps] = tmp;
8505  }
8506  ++nelems;
8507  }
8508  }
8509  if (offset != 0) { return; }
8510  }
8511 
8512  if (offset == 13 || offset == 0) {
8513  if (nddom.contains(i-1,j,k)) {
8514  Real tmp = Real(0.);
8515  if (ccdom.contains(i-1,j-1,k-1)) {
8516  tmp += sig(i-1,j-1,k-1) * f4xm2ym2z;
8517  }
8518  if (ccdom.contains(i-1,j,k-1)) {
8519  tmp += sig(i-1,j,k-1) * f4xm2ym2z;
8520  }
8521  if (ccdom.contains(i-1,j-1,k)) {
8522  tmp += sig(i-1,j-1,k) * f4xm2ym2z;
8523  }
8524  if (ccdom.contains(i-1,j,k)) {
8525  tmp += sig(i-1,j,k) * f4xm2ym2z;
8526  }
8527  m0 -= tmp;
8528  if (gid(i-1,j,k) < gidmax) {
8529  if (offset != 0) {
8530  cols[ps] = gid(i-1,j,k);
8531  mat[ps] = tmp;
8532  }
8533  ++nelems;
8534  }
8535  }
8536  if (offset != 0) { return; }
8537  }
8538 
8539  if (offset == 14 || offset == 0) {
8540  if (nddom.contains(i+1,j,k)) {
8541  Real tmp = Real(0.);
8542  if (ccdom.contains(i ,j-1,k-1)) {
8543  tmp += sig(i ,j-1,k-1) * f4xm2ym2z;
8544  }
8545  if (ccdom.contains(i ,j,k-1)) {
8546  tmp += sig(i ,j,k-1) * f4xm2ym2z;
8547  }
8548  if (ccdom.contains(i ,j-1,k)) {
8549  tmp += sig(i ,j-1,k) * f4xm2ym2z;
8550  }
8551  if (ccdom.contains(i ,j,k)) {
8552  tmp += sig(i ,j,k) * f4xm2ym2z;
8553  }
8554  m0 -= tmp;
8555  if (gid(i+1,j,k) < gidmax) {
8556  if (offset != 0) {
8557  cols[ps] = gid(i+1,j,k);
8558  mat[ps] = tmp;
8559  }
8560  ++nelems;
8561  }
8562  }
8563  if (offset != 0) { return; }
8564  }
8565 
8566  if (offset == 15 || offset == 0) {
8567  if (nddom.contains(i-1,j+1,k)) {
8568  Real tmp = Real(0.);
8569  if (ccdom.contains(i-1,j ,k-1)) {
8570  tmp += sig(i-1,j ,k-1) * f2x2ymz;
8571  }
8572  if (ccdom.contains(i-1,j ,k)) {
8573  tmp += sig(i-1,j ,k) * f2x2ymz;
8574  }
8575  m0 -= tmp;
8576  if (gid(i-1,j+1,k) < gidmax) {
8577  if (offset != 0) {
8578  cols[ps] = gid(i-1,j+1,k);
8579  mat[ps] = tmp;
8580  }
8581  ++nelems;
8582  }
8583  }
8584  if (offset != 0) { return; }
8585  }
8586 
8587  if (offset == 16 || offset == 0) {
8588  if (nddom.contains(i,j+1,k)) {
8589  Real tmp = Real(0.);
8590  if (ccdom.contains(i-1,j ,k-1)) {
8591  tmp += sig(i-1,j ,k-1) * fm2x4ym2z;
8592  }
8593  if (ccdom.contains(i,j ,k-1)) {
8594  tmp += sig(i,j ,k-1) * fm2x4ym2z;
8595  }
8596  if (ccdom.contains(i-1,j ,k)) {
8597  tmp += sig(i-1,j ,k) * fm2x4ym2z;
8598  }
8599  if (ccdom.contains(i,j ,k)) {
8600  tmp += sig(i,j ,k) * fm2x4ym2z;
8601  }
8602  m0 -= tmp;
8603  if (gid(i,j+1,k) < gidmax) {
8604  if (offset != 0) {
8605  cols[ps] = gid(i,j+1,k);
8606  mat[ps] = tmp;
8607  }
8608  ++nelems;
8609  }
8610  }
8611  if (offset != 0) { return; }
8612  }
8613 
8614  if (offset == 17 || offset == 0) {
8615  if (nddom.contains(i+1,j+1,k)) {
8616  Real tmp = Real(0.);
8617  if (ccdom.contains(i ,j ,k-1)) {
8618  tmp += sig(i ,j ,k-1) * f2x2ymz;
8619  }
8620  if (ccdom.contains(i ,j ,k)) {
8621  tmp += sig(i ,j ,k) * f2x2ymz;
8622  }
8623  m0 -= tmp;
8624  if (gid(i+1,j+1,k) < gidmax) {
8625  if (offset != 0) {
8626  cols[ps] = gid(i+1,j+1,k);
8627  mat[ps] = tmp;
8628  }
8629  ++nelems;
8630  }
8631  }
8632  if (offset != 0) { return; }
8633  }
8634 
8635  if (offset == 18 || offset == 0) {
8636  if (nddom.contains(i-1,j-1,k+1)) {
8637  Real tmp = sig(i-1,j-1,k ) * fxyz;
8638  m0 -= tmp;
8639  if (gid(i-1,j-1,k+1) < gidmax) {
8640  if (offset != 0) {
8641  cols[ps] = gid(i-1,j-1,k+1);
8642  mat[ps] = tmp;
8643  }
8644  ++nelems;
8645  }
8646  }
8647  if (offset != 0) { return; }
8648  }
8649 
8650  if (offset == 19 || offset == 0) {
8651  if (nddom.contains(i,j-1,k+1)) {
8652  Real tmp = Real(0.);
8653  if (ccdom.contains(i-1,j-1,k )) {
8654  tmp += sig(i-1,j-1,k ) * fmx2y2z;
8655  }
8656  if (ccdom.contains(i,j-1,k )) {
8657  tmp += sig(i,j-1,k ) * fmx2y2z;
8658  }
8659  m0 -= tmp;
8660  if (gid(i,j-1,k+1) < gidmax) {
8661  if (offset != 0) {
8662  cols[ps] = gid(i,j-1,k+1);
8663  mat[ps] = tmp;
8664  }
8665  ++nelems;
8666  }
8667  }
8668  if (offset != 0) { return; }
8669  }
8670 
8671  if (offset == 20 || offset == 0) {
8672  if (nddom.contains(i+1,j-1,k+1)) {
8673  Real tmp = sig(i ,j-1,k ) * fxyz;
8674  m0 -= tmp;
8675  if (gid(i+1,j-1,k+1) < gidmax) {
8676  if (offset != 0) {
8677  cols[ps] = gid(i+1,j-1,k+1);
8678  mat[ps] = tmp;
8679  }
8680  ++nelems;
8681  }
8682  }
8683  if (offset != 0) { return; }
8684  }
8685 
8686  if (offset == 21 || offset == 0) {
8687  if (nddom.contains(i-1,j,k+1)) {
8688  Real tmp = Real(0.);
8689  if (ccdom.contains(i-1,j-1,k )) {
8690  tmp += sig(i-1,j-1,k ) * f2xmy2z;
8691  }
8692  if (ccdom.contains(i-1,j,k )) {
8693  tmp += sig(i-1,j,k ) * f2xmy2z;
8694  }
8695  m0 -= tmp;
8696  if (gid(i-1,j,k+1) < gidmax) {
8697  if (offset != 0) {
8698  cols[ps] = gid(i-1,j,k+1);
8699  mat[ps] = tmp;
8700  }
8701  ++nelems;
8702  }
8703  }
8704  if (offset != 0) { return; }
8705  }
8706 
8707  if (offset == 22 || offset == 0) {
8708  if (nddom.contains(i,j,k+1)) {
8709  Real tmp = Real(0.);
8710  if (ccdom.contains(i-1,j-1,k )) {
8711  tmp += sig(i-1,j-1,k ) * fm2xm2y4z;
8712  }
8713  if (ccdom.contains(i,j-1,k )) {
8714  tmp += sig(i,j-1,k ) * fm2xm2y4z;
8715  }
8716  if (ccdom.contains(i-1,j,k )) {
8717  tmp += sig(i-1,j,k ) * fm2xm2y4z;
8718  }
8719  if (ccdom.contains(i,j,k )) {
8720  tmp += sig(i,j,k ) * fm2xm2y4z;
8721  }
8722  m0 -= tmp;
8723  if (gid(i,j,k+1) < gidmax) {
8724  if (offset != 0) {
8725  cols[ps] = gid(i,j,k+1);
8726  mat[ps] = tmp;
8727  }
8728  ++nelems;
8729  }
8730  }
8731  if (offset != 0) { return; }
8732  }
8733 
8734  if (offset == 23 || offset == 0) {
8735  if (nddom.contains(i+1,j,k+1)) {
8736  Real tmp = Real(0.);
8737  if (ccdom.contains(i ,j-1,k )) {
8738  tmp += sig(i ,j-1,k ) * f2xmy2z;
8739  }
8740  if (ccdom.contains(i ,j,k )) {
8741  tmp += sig(i ,j,k ) * f2xmy2z;
8742  }
8743  m0 -= tmp;
8744  if (gid(i+1,j,k+1) < gidmax) {
8745  if (offset != 0) {
8746  cols[ps] = gid(i+1,j,k+1);
8747  mat[ps] = tmp;
8748  }
8749  ++nelems;
8750  }
8751  }
8752  if (offset != 0) { return; }
8753  }
8754 
8755  if (offset == 24 || offset == 0) {
8756  if (nddom.contains(i-1,j+1,k+1)) {
8757  Real tmp = sig(i-1,j ,k ) * fxyz;
8758  m0 -= tmp;
8759  if (gid(i-1,j+1,k+1) < gidmax) {
8760  if (offset != 0) {
8761  cols[ps] = gid(i-1,j+1,k+1);
8762  mat[ps] = tmp;
8763  }
8764  ++nelems;
8765  }
8766  }
8767  if (offset != 0) { return; }
8768  }
8769 
8770  if (offset == 25 || offset == 0) {
8771  if (nddom.contains(i,j+1,k+1)) {
8772  Real tmp = Real(0.);
8773  if (ccdom.contains(i-1,j ,k )) {
8774  tmp += sig(i-1,j ,k ) * fmx2y2z;
8775  }
8776  if (ccdom.contains(i,j ,k )) {
8777  tmp += sig(i,j ,k ) * fmx2y2z;
8778  }
8779  m0 -= tmp;
8780  if (gid(i,j+1,k+1) < gidmax) {
8781  if (offset != 0) {
8782  cols[ps] = gid(i,j+1,k+1);
8783  mat[ps] = tmp;
8784  }
8785  ++nelems;
8786  }
8787  }
8788  if (offset != 0) { return; }
8789  }
8790 
8791  if (offset == 26 || offset == 0) {
8792  if (nddom.contains(i+1,j+1,k+1)) {
8793  Real tmp = sig(i ,j ,k ) * fxyz;
8794  m0 -= tmp;
8795  if (gid(i+1,j+1,k+1) < gidmax) {
8796  if (offset != 0) {
8797  cols[ps] = gid(i+1,j+1,k+1);
8798  mat[ps] = tmp;
8799  }
8800  ++nelems;
8801  }
8802  }
8803  if (offset != 0) { return; }
8804  }
8805 
8806  // Only offset == 0 could get this far.
8807  cols[ps] = gid(i,j,k);
8808  mat[ps] = m0;
8809  ncols[lid(i,j,k)] = nelems+1;
8810  }
8811 }
8812 
8813 template <typename HypreInt, typename AtomicInt>
8815 void mlndlap_fillijmat_ha_gpu (const int ps, const int i, const int j, const int k,
8816  const int offset,
8817  Box const& ndbx, Array4<AtomicInt const> const& gid,
8818  Array4<int const> const& lid,
8819  HypreInt* ncols, HypreInt* cols,
8820  Real* mat, // NOLINT(readability-non-const-parameter)
8821  Array4<Real const> const& sx,
8822  Array4<Real const> const& sy,
8823  Array4<Real const> const& sz,
8824  GpuArray<Real,AMREX_SPACEDIM> const& dxinv,
8825  Box const& ccdom) noexcept
8826 {
8827  if (lid(i,j,k) >= 0)
8828  {
8829  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
8830  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
8831  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
8832 
8833  const Box& nddom = amrex::surroundingNodes(ccdom);
8834 
8835  constexpr auto gidmax = std::numeric_limits<AtomicInt>::max();
8836  int nelems = 0;
8837  Real m0 = Real(0.);
8838 
8839  if (offset == 1 || offset == 0) {
8840  if (nddom.contains(i-1,j-1,k-1)) {
8841  Real tmp = sx(i-1,j-1,k-1) * facx
8842  + sy(i-1,j-1,k-1) * facy
8843  + sz(i-1,j-1,k-1) * facz;
8844  m0 -= tmp;
8845  if ( gid(i-1,j-1,k-1) < gidmax) {
8846  if (offset != 0) {
8847  cols[ps] = gid(i-1,j-1,k-1);
8848  mat[ps] = tmp;
8849  }
8850  ++nelems;
8851  }
8852  }
8853  if (offset != 0) { return; }
8854  }
8855 
8856  if (offset == 2 || offset == 0) {
8857  if (nddom.contains(i,j-1,k-1)) {
8858  Real tmp = Real(0.);
8859  if (ccdom.contains(i-1,j-1,k-1)) {
8860  tmp += - sx(i-1,j-1,k-1) * facx
8861  + sy(i-1,j-1,k-1) * facy * Real(2.0)
8862  + sz(i-1,j-1,k-1) * facz * Real(2.0);
8863  }
8864  if (ccdom.contains(i,j-1,k-1)) {
8865  tmp += - sx(i,j-1,k-1) * facx
8866  + sy(i,j-1,k-1) * facy * Real(2.0)
8867  + sz(i,j-1,k-1) * facz * Real(2.0);
8868  }
8869  m0 -= tmp;
8870  if (gid(i,j-1,k-1) < gidmax) {
8871  if (offset != 0) {
8872  cols[ps] = gid(i,j-1,k-1);
8873  mat[ps] = tmp;
8874  }
8875  ++nelems;
8876  }
8877  }
8878  if (offset != 0) { return; }
8879  }
8880 
8881  if (offset == 3 || offset == 0) {
8882  if (nddom.contains(i+1,j-1,k-1)) {
8883  Real tmp = sx(i ,j-1,k-1) * facx
8884  + sy(i ,j-1,k-1) * facy
8885  + sz(i ,j-1,k-1) * facz;
8886  m0 -= tmp;
8887  if (gid(i+1,j-1,k-1) < gidmax) {
8888  if (offset != 0) {
8889  cols[ps] = gid(i+1,j-1,k-1);
8890  mat[ps] = tmp;
8891  }
8892  ++nelems;
8893  }
8894  }
8895  if (offset != 0) { return; }
8896  }
8897 
8898  if (offset == 4 || offset == 0) {
8899  if (nddom.contains(i-1,j,k-1)) {
8900  Real tmp = Real(0.);
8901  if (ccdom.contains(i-1,j-1,k-1)) {
8902  tmp += sx(i-1,j-1,k-1) * facx * Real(2.0)
8903  - sy(i-1,j-1,k-1) * facy
8904  + sz(i-1,j-1,k-1) * facz * Real(2.0);
8905  }
8906  if (ccdom.contains(i-1,j,k-1)) {
8907  tmp += sx(i-1,j,k-1) * facx * Real(2.0)
8908  - sy(i-1,j,k-1) * facy
8909  + sz(i-1,j,k-1) * facz * Real(2.0);
8910  }
8911  m0 -= tmp;
8912  if (gid(i-1,j,k-1) < gidmax) {
8913  if (offset != 0) {
8914  cols[ps] = gid(i-1,j,k-1);
8915  mat[ps] = tmp;
8916  }
8917  ++nelems;
8918  }
8919  }
8920  if (offset != 0) { return; }
8921  }
8922 
8923  if (offset == 5 || offset == 0) {
8924  if (nddom.contains(i,j,k-1)) {
8925  Real tmp = Real(0.);
8926  if (ccdom.contains(i-1,j-1,k-1)) {
8927  tmp += - sx(i-1,j-1,k-1) * facx * Real(2.0)
8928  - sy(i-1,j-1,k-1) * facy * Real(2.0)
8929  + sz(i-1,j-1,k-1) * facz * Real(4.0);
8930  }
8931  if (ccdom.contains(i,j-1,k-1)) {
8932  tmp += - sx(i,j-1,k-1) * facx * Real(2.0)
8933  - sy(i,j-1,k-1) * facy * Real(2.0)
8934  + sz(i,j-1,k-1) * facz * Real(4.0);
8935 
8936  }
8937  if (ccdom.contains(i-1,j,k-1)) {
8938  tmp += - sx(i-1,j,k-1) * facx * Real(2.0)
8939  - sy(i-1,j,k-1) * facy * Real(2.0)
8940  + sz(i-1,j,k-1) * facz * Real(4.0);
8941  }
8942  if (ccdom.contains(i,j,k-1)) {
8943  tmp += - sx(i,j,k-1) * facx * Real(2.0)
8944  - sy(i,j,k-1) * facy * Real(2.0)
8945  + sz(i,j,k-1) * facz * Real(4.0);
8946  }
8947  m0 -= tmp;
8948  if (gid(i,j,k-1) < gidmax) {
8949  if (offset != 0) {
8950  cols[ps] = gid(i,j,k-1);
8951  mat[ps] = tmp;
8952  }
8953  ++nelems;
8954  }
8955  }
8956  if (offset != 0) { return; }
8957  }
8958 
8959  if (offset == 6 || offset == 0) {
8960  if (nddom.contains(i+1,j,k-1)) {
8961  Real tmp = Real(0.);
8962  if (ccdom.contains(i ,j-1,k-1)) {
8963  tmp += sx(i ,j-1,k-1) * facx * Real(2.0)
8964  - sy(i ,j-1,k-1) * facy
8965  + sz(i ,j-1,k-1) * facz * Real(2.0);
8966  }
8967  if (ccdom.contains(i ,j,k-1)) {
8968  tmp += sx(i ,j,k-1) * facx * Real(2.0)
8969  - sy(i ,j,k-1) * facy
8970  + sz(i ,j,k-1) * facz * Real(2.0);
8971  }
8972  m0 -= tmp;
8973  if (gid(i+1,j,k-1) < gidmax) {
8974  if (offset != 0) {
8975  cols[ps] = gid(i+1,j,k-1);
8976  mat[ps] = tmp;
8977  }
8978  ++nelems;
8979  }
8980  }
8981  if (offset != 0) { return; }
8982  }
8983 
8984  if (offset == 7 || offset == 0) {
8985  if (nddom.contains(i-1,j+1,k-1)) {
8986  Real tmp = sx(i-1,j ,k-1) * facx
8987  + sy(i-1,j ,k-1) * facy
8988  + sz(i-1,j ,k-1) * facz;
8989  m0 -= tmp;
8990  if (gid(i-1,j+1,k-1) < gidmax) {
8991  if (offset != 0) {
8992  cols[ps] = gid(i-1,j+1,k-1);
8993  mat[ps] = tmp;
8994  }
8995  ++nelems;
8996  }
8997  }
8998  if (offset != 0) { return; }
8999  }
9000 
9001  if (offset == 8 || offset == 0) {
9002  if (nddom.contains(i,j+1,k-1)) {
9003  Real tmp = Real(0.);
9004  if (ccdom.contains(i-1,j ,k-1)) {
9005  tmp += - sx(i-1,j ,k-1) * facx
9006  + sy(i-1,j ,k-1) * facy * Real(2.0)
9007  + sz(i-1,j ,k-1) * facz * Real(2.0);
9008  }
9009  if (ccdom.contains(i,j ,k-1)) {
9010  tmp += - sx(i,j ,k-1) * facx
9011  + sy(i,j ,k-1) * facy * Real(2.0)
9012  + sz(i,j ,k-1) * facz * Real(2.0);
9013  }
9014  m0 -= tmp;
9015  if (gid(i,j+1,k-1) < gidmax) {
9016  if (offset != 0) {
9017  cols[ps] = gid(i,j+1,k-1);
9018  mat[ps] = tmp;
9019  }
9020  ++nelems;
9021  }
9022  }
9023  if (offset != 0) { return; }
9024  }
9025 
9026  if (offset == 9 || offset == 0) {
9027  if (nddom.contains(i+1,j+1,k-1)) {
9028  Real tmp = sx(i ,j ,k-1) * facx
9029  + sy(i ,j ,k-1) * facy
9030  + sz(i ,j ,k-1) * facz;
9031  m0 -= tmp;
9032  if (gid(i+1,j+1,k-1) < gidmax) {
9033  if (offset != 0) {
9034  cols[ps] = gid(i+1,j+1,k-1);
9035  mat[ps] = tmp;
9036  }
9037  ++nelems;
9038  }
9039  }
9040  if (offset != 0) { return; }
9041  }
9042 
9043  if (offset == 10 || offset == 0) {
9044  if (nddom.contains(i-1,j-1,k)) {
9045  Real tmp = Real(0.);
9046  if (ccdom.contains(i-1,j-1,k-1)) {
9047  tmp += sx(i-1,j-1,k-1) * facx * Real(2.0)
9048  + sy(i-1,j-1,k-1) * facy * Real(2.0)
9049  - sz(i-1,j-1,k-1) * facz;
9050  }
9051  if (ccdom.contains(i-1,j-1,k)) {
9052  tmp += sx(i-1,j-1,k) * facx * Real(2.0)
9053  + sy(i-1,j-1,k) * facy * Real(2.0)
9054  - sz(i-1,j-1,k) * facz;
9055  }
9056  m0 -= tmp;
9057  if (gid(i-1,j-1,k) < gidmax) {
9058  if (offset != 0) {
9059  cols[ps] = gid(i-1,j-1,k);
9060  mat[ps] = tmp;
9061  }
9062  ++nelems;
9063  }
9064  }
9065  if (offset != 0) { return; }
9066  }
9067 
9068  if (offset == 11 || offset == 0) {
9069  if (nddom.contains(i,j-1,k)) {
9070  Real tmp = Real(0.);
9071  if (ccdom.contains(i-1,j-1,k-1)) {
9072  tmp += - sx(i-1,j-1,k-1) * facx * Real(2.0)
9073  + sy(i-1,j-1,k-1) * facy * Real(4.0)
9074  - sz(i-1,j-1,k-1) * facz * Real(2.0);
9075  }
9076  if (ccdom.contains(i,j-1,k-1)) {
9077  tmp += - sx(i,j-1,k-1) * facx * Real(2.0)
9078  + sy(i,j-1,k-1) * facy * Real(4.0)
9079  - sz(i,j-1,k-1) * facz * Real(2.0);
9080  }
9081  if (ccdom.contains(i-1,j-1,k)) {
9082  tmp += - sx(i-1,j-1,k) * facx * Real(2.0)
9083  + sy(i-1,j-1,k) * facy * Real(4.0)
9084  - sz(i-1,j-1,k) * facz * Real(2.0);
9085  }
9086  if (ccdom.contains(i,j-1,k)) {
9087  tmp += - sx(i,j-1,k) * facx * Real(2.0)
9088  + sy(i,j-1,k) * facy * Real(4.0)
9089  - sz(i,j-1,k) * facz * Real(2.0);
9090  }
9091  m0 -= tmp;
9092  if (gid(i,j-1,k) < gidmax) {
9093  if (offset != 0) {
9094  cols[ps] = gid(i,j-1,k);
9095  mat[ps] = tmp;
9096  }
9097  ++nelems;
9098  }
9099  }
9100  if (offset != 0) { return; }
9101  }
9102 
9103  if (offset == 12 || offset == 0) {
9104  if (nddom.contains(i+1,j-1,k)) {
9105  Real tmp = Real(0.);
9106  if (ccdom.contains(i ,j-1,k-1)) {
9107  tmp += sx(i ,j-1,k-1) * facx * Real(2.0)
9108  + sy(i ,j-1,k-1) * facy * Real(2.0)
9109  - sz(i ,j-1,k-1) * facz;
9110  }
9111  if (ccdom.contains(i ,j-1,k)) {
9112  tmp += sx(i ,j-1,k) * facx * Real(2.0)
9113  + sy(i ,j-1,k) * facy * Real(2.0)
9114  - sz(i ,j-1,k) * facz;
9115  }
9116  m0 -= tmp;
9117  if (gid(i+1,j-1,k) < gidmax) {
9118  if (offset != 0) {
9119  cols[ps] = gid(i+1,j-1,k);
9120  mat[ps] = tmp;
9121  }
9122  ++nelems;
9123  }
9124  }
9125  if (offset != 0) { return; }
9126  }
9127 
9128  if (offset == 13 || offset == 0) {
9129  if (nddom.contains(i-1,j,k)) {
9130  Real tmp = Real(0.);
9131  if (ccdom.contains(i-1,j-1,k-1)) {
9132  tmp += sx(i-1,j-1,k-1) * facx * Real(4.0)
9133  - sy(i-1,j-1,k-1) * facy * Real(2.0)
9134  - sz(i-1,j-1,k-1) * facz * Real(2.0);
9135  }
9136  if (ccdom.contains(i-1,j,k-1)) {
9137  tmp += sx(i-1,j,k-1) * facx * Real(4.0)
9138  - sy(i-1,j,k-1) * facy * Real(2.0)
9139  - sz(i-1,j,k-1) * facz * Real(2.0);
9140  }
9141  if (ccdom.contains(i-1,j-1,k)) {
9142  tmp += sx(i-1,j-1,k) * facx * Real(4.0)
9143  - sy(i-1,j-1,k) * facy * Real(2.0)
9144  - sz(i-1,j-1,k) * facz * Real(2.0);
9145  }
9146  if (ccdom.contains(i-1,j,k)) {
9147  tmp += sx(i-1,j,k) * facx * Real(4.0)
9148  - sy(i-1,j,k) * facy * Real(2.0)
9149  - sz(i-1,j,k) * facz * Real(2.0);
9150  }
9151  m0 -= tmp;
9152  if (gid(i-1,j,k) < gidmax) {
9153  if (offset != 0) {
9154  cols[ps] = gid(i-1,j,k);
9155  mat[ps] = tmp;
9156  }
9157  ++nelems;
9158  }
9159  }
9160  if (offset != 0) { return; }
9161  }
9162 
9163  if (offset == 14 || offset == 0) {
9164  if (nddom.contains(i+1,j,k)) {
9165  Real tmp = Real(0.);
9166  if (ccdom.contains(i ,j-1,k-1)) {
9167  tmp += sx(i ,j-1,k-1) * facx * Real(4.0)
9168  - sy(i ,j-1,k-1) * facy * Real(2.0)
9169  - sz(i ,j-1,k-1) * facz * Real(2.0);
9170  }
9171  if (ccdom.contains(i ,j,k-1)) {
9172  tmp += sx(i ,j,k-1) * facx * Real(4.0)
9173  - sy(i ,j,k-1) * facy * Real(2.0)
9174  - sz(i ,j,k-1) * facz * Real(2.0);
9175  }
9176  if (ccdom.contains(i ,j-1,k)) {
9177  tmp += sx(i ,j-1,k) * facx * Real(4.0)
9178  - sy(i ,j-1,k) * facy * Real(2.0)
9179  - sz(i ,j-1,k) * facz * Real(2.0);
9180  }
9181  if (ccdom.contains(i ,j,k)) {
9182  tmp += sx(i ,j,k) * facx * Real(4.0)
9183  - sy(i ,j,k) * facy * Real(2.0)
9184  - sz(i ,j,k) * facz * Real(2.0);
9185  }
9186  m0 -= tmp;
9187  if (gid(i+1,j,k) < gidmax) {
9188  if (offset != 0) {
9189  cols[ps] = gid(i+1,j,k);
9190  mat[ps] = tmp;
9191  }
9192  ++nelems;
9193  }
9194  }
9195  if (offset != 0) { return; }
9196  }
9197 
9198  if (offset == 15 || offset == 0) {
9199  if (nddom.contains(i-1,j+1,k)) {
9200  Real tmp = Real(0.);
9201  if (ccdom.contains(i-1,j ,k-1)) {
9202  tmp += sx(i-1,j ,k-1) * facx * Real(2.0)
9203  + sy(i-1,j ,k-1) * facy * Real(2.0)
9204  - sz(i-1,j ,k-1) * facz;
9205  }
9206  if (ccdom.contains(i-1,j ,k)) {
9207  tmp += sx(i-1,j ,k) * facx * Real(2.0)
9208  + sy(i-1,j ,k) * facy * Real(2.0)
9209  - sz(i-1,j ,k) * facz;
9210  }
9211  m0 -= tmp;
9212  if (gid(i-1,j+1,k) < gidmax) {
9213  if (offset != 0) {
9214  cols[ps] = gid(i-1,j+1,k);
9215  mat[ps] = tmp;
9216  }
9217  ++nelems;
9218  }
9219  }
9220  if (offset != 0) { return; }
9221  }
9222 
9223  if (offset == 16 || offset == 0) {
9224  if (nddom.contains(i,j+1,k)) {
9225  Real tmp = Real(0.);
9226  if (ccdom.contains(i-1,j ,k-1)) {
9227  tmp += - sx(i-1,j ,k-1) * facx * Real(2.0)
9228  + sy(i-1,j ,k-1) * facy * Real(4.0)
9229  - sz(i-1,j ,k-1) * facz * Real(2.0);
9230  }
9231  if (ccdom.contains(i,j ,k-1)) {
9232  tmp += - sx(i,j ,k-1) * facx * Real(2.0)
9233  + sy(i,j ,k-1) * facy * Real(4.0)
9234  - sz(i,j ,k-1) * facz * Real(2.0);
9235  }
9236  if (ccdom.contains(i-1,j ,k)) {
9237  tmp += - sx(i-1,j ,k) * facx * Real(2.0)
9238  + sy(i-1,j ,k) * facy * Real(4.0)
9239  - sz(i-1,j ,k) * facz * Real(2.0);
9240  }
9241  if (ccdom.contains(i,j ,k)) {
9242  tmp += - sx(i,j ,k) * facx * Real(2.0)
9243  + sy(i,j ,k) * facy * Real(4.0)
9244  - sz(i,j ,k) * facz * Real(2.0);
9245  }
9246  m0 -= tmp;
9247  if (gid(i,j+1,k) < gidmax) {
9248  if (offset != 0) {
9249  cols[ps] = gid(i,j+1,k);
9250  mat[ps] = tmp;
9251  }
9252  ++nelems;
9253  }
9254  }
9255  if (offset != 0) { return; }
9256  }
9257 
9258  if (offset == 17 || offset == 0) {
9259  if (nddom.contains(i+1,j+1,k)) {
9260  Real tmp = Real(0.);
9261  if (ccdom.contains(i ,j ,k-1)) {
9262  tmp += sx(i ,j ,k-1) * facx * Real(2.0)
9263  + sy(i ,j ,k-1) * facy * Real(2.0)
9264  - sz(i ,j ,k-1) * facz;
9265  }
9266  if (ccdom.contains(i ,j ,k)) {
9267  tmp += sx(i ,j ,k) * facx * Real(2.0)
9268  + sy(i ,j ,k) * facy * Real(2.0)
9269  - sz(i ,j ,k) * facz;
9270  }
9271  m0 -= tmp;
9272  if (gid(i+1,j+1,k) < gidmax) {
9273  if (offset != 0) {
9274  cols[ps] = gid(i+1,j+1,k);
9275  mat[ps] = tmp;
9276  }
9277  ++nelems;
9278  }
9279  }
9280  if (offset != 0) { return; }
9281  }
9282 
9283  if (offset == 18 || offset == 0) {
9284  if (nddom.contains(i-1,j-1,k+1)) {
9285  Real tmp = sx(i-1,j-1,k ) * facx
9286  + sy(i-1,j-1,k ) * facy
9287  + sz(i-1,j-1,k ) * facz;
9288  m0 -= tmp;
9289  if (gid(i-1,j-1,k+1) < gidmax) {
9290  if (offset != 0) {
9291  cols[ps] = gid(i-1,j-1,k+1);
9292  mat[ps] = tmp;
9293  }
9294  ++nelems;
9295  }
9296  }
9297  if (offset != 0) { return; }
9298  }
9299 
9300  if (offset == 19 || offset == 0) {
9301  if (nddom.contains(i,j-1,k+1)) {
9302  Real tmp = Real(0.);
9303  if (ccdom.contains(i-1,j-1,k )) {
9304  tmp += - sx(i-1,j-1,k ) * facx
9305  + sy(i-1,j-1,k ) * facy * Real(2.0)
9306  + sz(i-1,j-1,k ) * facz * Real(2.0);
9307  }
9308  if (ccdom.contains(i,j-1,k )) {
9309  tmp += - sx(i,j-1,k ) * facx
9310  + sy(i,j-1,k ) * facy * Real(2.0)
9311  + sz(i,j-1,k ) * facz * Real(2.0);
9312  }
9313  m0 -= tmp;
9314  if (gid(i,j-1,k+1) < gidmax) {
9315  if (offset != 0) {
9316  cols[ps] = gid(i,j-1,k+1);
9317  mat[ps] = tmp;
9318  }
9319  ++nelems;
9320  }
9321  }
9322  if (offset != 0) { return; }
9323  }
9324 
9325  if (offset == 20 || offset == 0) {
9326  if (nddom.contains(i+1,j-1,k+1)) {
9327  Real tmp = sx(i ,j-1,k ) * facx
9328  + sy(i ,j-1,k ) * facy
9329  + sz(i ,j-1,k ) * facz;
9330  m0 -= tmp;
9331  if (gid(i+1,j-1,k+1) < gidmax) {
9332  if (offset != 0) {
9333  cols[ps] = gid(i+1,j-1,k+1);
9334  mat[ps] = tmp;
9335  }
9336  ++nelems;
9337  }
9338  }
9339  if (offset != 0) { return; }
9340  }
9341 
9342  if (offset == 21 || offset == 0) {
9343  if (nddom.contains(i-1,j,k+1)) {
9344  Real tmp = Real(0.);
9345  if (ccdom.contains(i-1,j-1,k )) {
9346  tmp += sx(i-1,j-1,k ) * facx * Real(2.0)
9347  - sy(i-1,j-1,k ) * facy
9348  + sz(i-1,j-1,k ) * facz * Real(2.0);
9349  }
9350  if (ccdom.contains(i-1,j,k )) {
9351  tmp += sx(i-1,j,k ) * facx * Real(2.0)
9352  - sy(i-1,j,k ) * facy
9353  + sz(i-1,j,k ) * facz * Real(2.0);
9354  }
9355  m0 -= tmp;
9356  if (gid(i-1,j,k+1) < gidmax) {
9357  if (offset != 0) {
9358  cols[ps] = gid(i-1,j,k+1);
9359  mat[ps] = tmp;
9360  }
9361  ++nelems;
9362  }
9363  }
9364  if (offset != 0) { return; }
9365  }
9366 
9367  if (offset == 22 || offset == 0) {
9368  if (nddom.contains(i,j,k+1)) {
9369  Real tmp = Real(0.);
9370  if (ccdom.contains(i-1,j-1,k )) {
9371  tmp += - sx(i-1,j-1,k ) * facx * Real(2.0)
9372  - sy(i-1,j-1,k ) * facy * Real(2.0)
9373  + sz(i-1,j-1,k ) * facz * Real(4.0);
9374  }
9375  if (ccdom.contains(i,j-1,k )) {
9376  tmp += - sx(i,j-1,k ) * facx * Real(2.0)
9377  - sy(i,j-1,k ) * facy * Real(2.0)
9378  + sz(i,j-1,k ) * facz * Real(4.0);
9379  }
9380  if (ccdom.contains(i-1,j,k )) {
9381  tmp += - sx(i-1,j,k ) * facx * Real(2.0)
9382  - sy(i-1,j,k ) * facy * Real(2.0)
9383  + sz(i-1,j,k ) * facz * Real(4.0);
9384  }
9385  if (ccdom.contains(i,j,k )) {
9386  tmp += - sx(i,j,k ) * facx * Real(2.0)
9387  - sy(i,j,k ) * facy * Real(2.0)
9388  + sz(i,j,k ) * facz * Real(4.0);
9389  }
9390  m0 -= tmp;
9391  if (gid(i,j,k+1) < gidmax) {
9392  if (offset != 0) {
9393  cols[ps] = gid(i,j,k+1);
9394  mat[ps] = tmp;
9395  }
9396  ++nelems;
9397  }
9398  }
9399  if (offset != 0) { return; }
9400  }
9401 
9402  if (offset == 23 || offset == 0) {
9403  if (nddom.contains(i+1,j,k+1)) {
9404  Real tmp = Real(0.);
9405  if (ccdom.contains(i ,j-1,k )) {
9406  tmp += sx(i ,j-1,k ) * facx * Real(2.0)
9407  - sy(i ,j-1,k ) * facy
9408  + sz(i ,j-1,k ) * facz * Real(2.0);
9409  }
9410  if (ccdom.contains(i ,j,k )) {
9411  tmp += sx(i ,j,k ) * facx * Real(2.0)
9412  - sy(i ,j,k ) * facy
9413  + sz(i ,j,k ) * facz * Real(2.0);
9414  }
9415  m0 -= tmp;
9416  if (gid(i+1,j,k+1) < gidmax) {
9417  if (offset != 0) {
9418  cols[ps] = gid(i+1,j,k+1);
9419  mat[ps] = tmp;
9420  }
9421  ++nelems;
9422  }
9423  }
9424  if (offset != 0) { return; }
9425  }
9426 
9427  if (offset == 24 || offset == 0) {
9428  if (nddom.contains(i-1,j+1,k+1)) {
9429  Real tmp = sx(i-1,j ,k ) * facx
9430  + sy(i-1,j ,k ) * facy
9431  + sz(i-1,j ,k ) * facz;
9432  m0 -= tmp;
9433  if (gid(i-1,j+1,k+1) < gidmax) {
9434  if (offset != 0) {
9435  cols[ps] = gid(i-1,j+1,k+1);
9436  mat[ps] = tmp;
9437  }
9438  ++nelems;
9439  }
9440  }
9441  if (offset != 0) { return; }
9442  }
9443 
9444  if (offset == 25 || offset == 0) {
9445  if (nddom.contains(i,j+1,k+1)) {
9446  Real tmp = Real(0.);
9447  if (ccdom.contains(i-1,j ,k )) {
9448  tmp += - sx(i-1,j ,k ) * facx
9449  + sy(i-1,j ,k ) * facy * Real(2.0)
9450  + sz(i-1,j ,k ) * facz * Real(2.0);
9451  }
9452  if (ccdom.contains(i,j ,k )) {
9453  tmp += - sx(i,j ,k ) * facx
9454  + sy(i,j ,k ) * facy * Real(2.0)
9455  + sz(i,j ,k ) * facz * Real(2.0);
9456  }
9457  m0 -= tmp;
9458  if (gid(i,j+1,k+1) < gidmax) {
9459  if (offset != 0) {
9460  cols[ps] = gid(i,j+1,k+1);
9461  mat[ps] = tmp;
9462  }
9463  ++nelems;
9464  }
9465  }
9466  if (offset != 0) { return; }
9467  }
9468 
9469  if (offset == 26 || offset == 0) {
9470  if (nddom.contains(i+1,j+1,k+1)) {
9471  Real tmp = sx(i ,j ,k ) * facx
9472  + sy(i ,j ,k ) * facy
9473  + sz(i ,j ,k ) * facz;
9474  m0 -= tmp;
9475  if (gid(i+1,j+1,k+1) < gidmax) {
9476  if (offset != 0) {
9477  cols[ps] = gid(i+1,j+1,k+1);
9478  mat[ps] = tmp;
9479  }
9480  ++nelems;
9481  }
9482  }
9483  if (offset != 0) { return; }
9484  }
9485 
9486  // Only offset == 0 could get this far.
9487  cols[ps] = gid(i,j,k);
9488  mat[ps] = m0;
9489  ncols[lid(i,j,k)] = nelems+1;
9490  }
9491 }
9492 
9493 template <typename HypreInt, typename AtomicInt>
9495 void mlndlap_fillijmat_cs_gpu (const int ps, const int i, const int j, const int k,
9496  const int offset,
9497  Box const& ndbx, Array4<AtomicInt const> const& gid,
9498  Array4<int const> const& lid,
9499  HypreInt* ncols, HypreInt* cols,
9500  Real* mat, // NOLINT(readability-non-const-parameter)
9501  Real sigma, GpuArray<Real,AMREX_SPACEDIM> const& dxinv,
9502  Box const& ccdom) noexcept
9503 {
9504  if (lid(i,j,k) >= 0)
9505  {
9506  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0] * sigma;
9507  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1] * sigma;
9508  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2] * sigma;
9509  Real fxyz = facx + facy + facz;
9510  Real fmx2y2z = -facx + Real(2.0)*facy + Real(2.0)*facz;
9511  Real f2xmy2z = Real(2.0)*facx - facy + Real(2.0)*facz;
9512  Real f2x2ymz = Real(2.0)*facx + Real(2.0)*facy - facz;
9513  Real f4xm2ym2z = Real(4.0)*facx - Real(2.0)*facy - Real(2.0)*facz;
9514  Real fm2x4ym2z = -Real(2.0)*facx + Real(4.0)*facy - Real(2.0)*facz;
9515  Real fm2xm2y4z = -Real(2.0)*facx - Real(2.0)*facy + Real(4.0)*facz;
9516 
9517  const Box& nddom = amrex::surroundingNodes(ccdom);
9518 
9519  constexpr auto gidmax = std::numeric_limits<AtomicInt>::max();
9520  int nelems = 0;
9521  Real m0 = Real(0.);
9522 
9523  if (offset == 1 || offset == 0) {
9524  if (nddom.contains(i-1,j-1,k-1)) {
9525  Real tmp = fxyz;
9526  m0 -= tmp;
9527  if ( gid(i-1,j-1,k-1) < gidmax) {
9528  if (offset != 0) {
9529  cols[ps] = gid(i-1,j-1,k-1);
9530  mat[ps] = tmp;
9531  }
9532  ++nelems;
9533  }
9534  }
9535  if (offset != 0) { return; }
9536  }
9537 
9538  if (offset == 2 || offset == 0) {
9539  if (nddom.contains(i,j-1,k-1)) {
9540  Real tmp = Real(0.);
9541  if (ccdom.contains(i-1,j-1,k-1)) {
9542  tmp += fmx2y2z;
9543  }
9544  if (ccdom.contains(i,j-1,k-1)) {
9545  tmp += fmx2y2z;
9546  }
9547  m0 -= tmp;
9548  if (gid(i,j-1,k-1) < gidmax) {
9549  if (offset != 0) {
9550  cols[ps] = gid(i,j-1,k-1);
9551  mat[ps] = tmp;
9552  }
9553  ++nelems;
9554  }
9555  }
9556  if (offset != 0) { return; }
9557  }
9558 
9559  if (offset == 3 || offset == 0) {
9560  if (nddom.contains(i+1,j-1,k-1)) {
9561  Real tmp = fxyz;
9562  m0 -= tmp;
9563  if (gid(i+1,j-1,k-1) < gidmax) {
9564  if (offset != 0) {
9565  cols[ps] = gid(i+1,j-1,k-1);
9566  mat[ps] = tmp;
9567  }
9568  ++nelems;
9569  }
9570  }
9571  if (offset != 0) { return; }
9572  }
9573 
9574  if (offset == 4 || offset == 0) {
9575  if (nddom.contains(i-1,j,k-1)) {
9576  Real tmp = Real(0.);
9577  if (ccdom.contains(i-1,j-1,k-1)) {
9578  tmp += f2xmy2z;
9579  }
9580  if (ccdom.contains(i-1,j,k-1)) {
9581  tmp += f2xmy2z;
9582  }
9583  m0 -= tmp;
9584  if (gid(i-1,j,k-1) < gidmax) {
9585  if (offset != 0) {
9586  cols[ps] = gid(i-1,j,k-1);
9587  mat[ps] = tmp;
9588  }
9589  ++nelems;
9590  }
9591  }
9592  if (offset != 0) { return; }
9593  }
9594 
9595  if (offset == 5 || offset == 0) {
9596  if (nddom.contains(i,j,k-1)) {
9597  Real tmp = Real(0.);
9598  if (ccdom.contains(i-1,j-1,k-1)) {
9599  tmp += fm2xm2y4z;
9600  }
9601  if (ccdom.contains(i,j-1,k-1)) {
9602  tmp += fm2xm2y4z;
9603  }
9604  if (ccdom.contains(i-1,j,k-1)) {
9605  tmp += fm2xm2y4z;
9606  }
9607  if (ccdom.contains(i,j,k-1)) {
9608  tmp += fm2xm2y4z;
9609  }
9610  m0 -= tmp;
9611  if (gid(i,j,k-1) < gidmax) {
9612  if (offset != 0) {
9613  cols[ps] = gid(i,j,k-1);
9614  mat[ps] = tmp;
9615  }
9616  ++nelems;
9617  }
9618  }
9619  if (offset != 0) { return; }
9620  }
9621 
9622  if (offset == 6 || offset == 0) {
9623  if (nddom.contains(i+1,j,k-1)) {
9624  Real tmp = Real(0.);
9625  if (ccdom.contains(i ,j-1,k-1)) {
9626  tmp += f2xmy2z;
9627  }
9628  if (ccdom.contains(i ,j,k-1)) {
9629  tmp += f2xmy2z;
9630  }
9631  m0 -= tmp;
9632  if (gid(i+1,j,k-1) < gidmax) {
9633  if (offset != 0) {
9634  cols[ps] = gid(i+1,j,k-1);
9635  mat[ps] = tmp;
9636  }
9637  ++nelems;
9638  }
9639  }
9640  if (offset != 0) { return; }
9641  }
9642 
9643  if (offset == 7 || offset == 0) {
9644  if (nddom.contains(i-1,j+1,k-1)) {
9645  Real tmp = fxyz;
9646  m0 -= tmp;
9647  if (gid(i-1,j+1,k-1) < gidmax) {
9648  if (offset != 0) {
9649  cols[ps] = gid(i-1,j+1,k-1);
9650  mat[ps] = tmp;
9651  }
9652  ++nelems;
9653  }
9654  }
9655  if (offset != 0) { return; }
9656  }
9657 
9658  if (offset == 8 || offset == 0) {
9659  if (nddom.contains(i,j+1,k-1)) {
9660  Real tmp = Real(0.);
9661  if (ccdom.contains(i-1,j ,k-1)) {
9662  tmp += fmx2y2z;
9663  }
9664  if (ccdom.contains(i,j ,k-1)) {
9665  tmp += fmx2y2z;
9666  }
9667  m0 -= tmp;
9668  if (gid(i,j+1,k-1) < gidmax) {
9669  if (offset != 0) {
9670  cols[ps] = gid(i,j+1,k-1);
9671  mat[ps] = tmp;
9672  }
9673  ++nelems;
9674  }
9675  }
9676  if (offset != 0) { return; }
9677  }
9678 
9679  if (offset == 9 || offset == 0) {
9680  if (nddom.contains(i+1,j+1,k-1)) {
9681  Real tmp = fxyz;
9682  m0 -= tmp;
9683  if (gid(i+1,j+1,k-1) < gidmax) {
9684  if (offset != 0) {
9685  cols[ps] = gid(i+1,j+1,k-1);
9686  mat[ps] = tmp;
9687  }
9688  ++nelems;
9689  }
9690  }
9691  if (offset != 0) { return; }
9692  }
9693 
9694  if (offset == 10 || offset == 0) {
9695  if (nddom.contains(i-1,j-1,k)) {
9696  Real tmp = Real(0.);
9697  if (ccdom.contains(i-1,j-1,k-1)) {
9698  tmp += f2x2ymz;
9699  }
9700  if (ccdom.contains(i-1,j-1,k)) {
9701  tmp += f2x2ymz;
9702  }
9703  m0 -= tmp;
9704  if (gid(i-1,j-1,k) < gidmax) {
9705  if (offset != 0) {
9706  cols[ps] = gid(i-1,j-1,k);
9707  mat[ps] = tmp;
9708  }
9709  ++nelems;
9710  }
9711  }
9712  if (offset != 0) { return; }
9713  }
9714 
9715  if (offset == 11 || offset == 0) {
9716  if (nddom.contains(i,j-1,k)) {
9717  Real tmp = Real(0.);
9718  if (ccdom.contains(i-1,j-1,k-1)) {
9719  tmp += fm2x4ym2z;
9720  }
9721  if (ccdom.contains(i,j-1,k-1)) {
9722  tmp += fm2x4ym2z;
9723  }
9724  if (ccdom.contains(i-1,j-1,k)) {
9725  tmp += fm2x4ym2z;
9726  }
9727  if (ccdom.contains(i,j-1,k)) {
9728  tmp += fm2x4ym2z;
9729  }
9730  m0 -= tmp;
9731  if (gid(i,j-1,k) < gidmax) {
9732  if (offset != 0) {
9733  cols[ps] = gid(i,j-1,k);
9734  mat[ps] = tmp;
9735  }
9736  ++nelems;
9737  }
9738  }
9739  if (offset != 0) { return; }
9740  }
9741 
9742  if (offset == 12 || offset == 0) {
9743  if (nddom.contains(i+1,j-1,k)) {
9744  Real tmp = Real(0.);
9745  if (ccdom.contains(i ,j-1,k-1)) {
9746  tmp += f2x2ymz;
9747  }
9748  if (ccdom.contains(i ,j-1,k)) {
9749  tmp += f2x2ymz;
9750  }
9751  m0 -= tmp;
9752  if (gid(i+1,j-1,k) < gidmax) {
9753  if (offset != 0) {
9754  cols[ps] = gid(i+1,j-1,k);
9755  mat[ps] = tmp;
9756  }
9757  ++nelems;
9758  }
9759  }
9760  if (offset != 0) { return; }
9761  }
9762 
9763  if (offset == 13 || offset == 0) {
9764  if (nddom.contains(i-1,j,k)) {
9765  Real tmp = Real(0.);
9766  if (ccdom.contains(i-1,j-1,k-1)) {
9767  tmp += f4xm2ym2z;
9768  }
9769  if (ccdom.contains(i-1,j,k-1)) {
9770  tmp += f4xm2ym2z;
9771  }
9772  if (ccdom.contains(i-1,j-1,k)) {
9773  tmp += f4xm2ym2z;
9774  }
9775  if (ccdom.contains(i-1,j,k)) {
9776  tmp += f4xm2ym2z;
9777  }
9778  m0 -= tmp;
9779  if (gid(i-1,j,k) < gidmax) {
9780  if (offset != 0) {
9781  cols[ps] = gid(i-1,j,k);
9782  mat[ps] = tmp;
9783  }
9784  ++nelems;
9785  }
9786  }
9787  if (offset != 0) { return; }
9788  }
9789 
9790  if (offset == 14 || offset == 0) {
9791  if (nddom.contains(i+1,j,k)) {
9792  Real tmp = Real(0.);
9793  if (ccdom.contains(i ,j-1,k-1)) {
9794  tmp += f4xm2ym2z;
9795  }
9796  if (ccdom.contains(i ,j,k-1)) {
9797  tmp += f4xm2ym2z;
9798  }
9799  if (ccdom.contains(i ,j-1,k)) {
9800  tmp += f4xm2ym2z;
9801  }
9802  if (ccdom.contains(i ,j,k)) {
9803  tmp += f4xm2ym2z;
9804  }
9805  m0 -= tmp;
9806  if (gid(i+1,j,k) < gidmax) {
9807  if (offset != 0) {
9808  cols[ps] = gid(i+1,j,k);
9809  mat[ps] = tmp;
9810  }
9811  ++nelems;
9812  }
9813  }
9814  if (offset != 0) { return; }
9815  }
9816 
9817  if (offset == 15 || offset == 0) {
9818  if (nddom.contains(i-1,j+1,k)) {
9819  Real tmp = Real(0.);
9820  if (ccdom.contains(i-1,j ,k-1)) {
9821  tmp += f2x2ymz;
9822  }
9823  if (ccdom.contains(i-1,j ,k)) {
9824  tmp += f2x2ymz;
9825  }
9826  m0 -= tmp;
9827  if (gid(i-1,j+1,k) < gidmax) {
9828  if (offset != 0) {
9829  cols[ps] = gid(i-1,j+1,k);
9830  mat[ps] = tmp;
9831  }
9832  ++nelems;
9833  }
9834  }
9835  if (offset != 0) { return; }
9836  }
9837 
9838  if (offset == 16 || offset == 0) {
9839  if (nddom.contains(i,j+1,k)) {
9840  Real tmp = Real(0.);
9841  if (ccdom.contains(i-1,j ,k-1)) {
9842  tmp += fm2x4ym2z;
9843  }
9844  if (ccdom.contains(i,j ,k-1)) {
9845  tmp += fm2x4ym2z;
9846  }
9847  if (ccdom.contains(i-1,j ,k)) {
9848  tmp += fm2x4ym2z;
9849  }
9850  if (ccdom.contains(i,j ,k)) {
9851  tmp += fm2x4ym2z;
9852  }
9853  m0 -= tmp;
9854  if (gid(i,j+1,k) < gidmax) {
9855  if (offset != 0) {
9856  cols[ps] = gid(i,j+1,k);
9857  mat[ps] = tmp;
9858  }
9859  ++nelems;
9860  }
9861  }
9862  if (offset != 0) { return; }
9863  }
9864 
9865  if (offset == 17 || offset == 0) {
9866  if (nddom.contains(i+1,j+1,k)) {
9867  Real tmp = Real(0.);
9868  if (ccdom.contains(i ,j ,k-1)) {
9869  tmp += f2x2ymz;
9870  }
9871  if (ccdom.contains(i ,j ,k)) {
9872  tmp += f2x2ymz;
9873  }
9874  m0 -= tmp;
9875  if (gid(i+1,j+1,k) < gidmax) {
9876  if (offset != 0) {
9877  cols[ps] = gid(i+1,j+1,k);
9878  mat[ps] = tmp;
9879  }
9880  ++nelems;
9881  }
9882  }
9883  if (offset != 0) { return; }
9884  }
9885 
9886  if (offset == 18 || offset == 0) {
9887  if (nddom.contains(i-1,j-1,k+1)) {
9888  Real tmp = fxyz;
9889  m0 -= tmp;
9890  if (gid(i-1,j-1,k+1) < gidmax) {
9891  if (offset != 0) {
9892  cols[ps] = gid(i-1,j-1,k+1);
9893  mat[ps] = tmp;
9894  }
9895  ++nelems;
9896  }
9897  }
9898  if (offset != 0) { return; }
9899  }
9900 
9901  if (offset == 19 || offset == 0) {
9902  if (nddom.contains(i,j-1,k+1)) {
9903  Real tmp = Real(0.);
9904  if (ccdom.contains(i-1,j-1,k )) {
9905  tmp += fmx2y2z;
9906  }
9907  if (ccdom.contains(i,j-1,k )) {
9908  tmp += fmx2y2z;
9909  }
9910  m0 -= tmp;
9911  if (gid(i,j-1,k+1) < gidmax) {
9912  if (offset != 0) {
9913  cols[ps] = gid(i,j-1,k+1);
9914  mat[ps] = tmp;
9915  }
9916  ++nelems;
9917  }
9918  }
9919  if (offset != 0) { return; }
9920  }
9921 
9922  if (offset == 20 || offset == 0) {
9923  if (nddom.contains(i+1,j-1,k+1)) {
9924  Real tmp = fxyz;
9925  m0 -= tmp;
9926  if (gid(i+1,j-1,k+1) < gidmax) {
9927  if (offset != 0) {
9928  cols[ps] = gid(i+1,j-1,k+1);
9929  mat[ps] = tmp;
9930  }
9931  ++nelems;
9932  }
9933  }
9934  if (offset != 0) { return; }
9935  }
9936 
9937  if (offset == 21 || offset == 0) {
9938  if (nddom.contains(i-1,j,k+1)) {
9939  Real tmp = Real(0.);
9940  if (ccdom.contains(i-1,j-1,k )) {
9941  tmp += f2xmy2z;
9942  }
9943  if (ccdom.contains(i-1,j,k )) {
9944  tmp += f2xmy2z;
9945  }
9946  m0 -= tmp;
9947  if (gid(i-1,j,k+1) < gidmax) {
9948  if (offset != 0) {
9949  cols[ps] = gid(i-1,j,k+1);
9950  mat[ps] = tmp;
9951  }
9952  ++nelems;
9953  }
9954  }
9955  if (offset != 0) { return; }
9956  }
9957 
9958  if (offset == 22 || offset == 0) {
9959  if (nddom.contains(i,j,k+1)) {
9960  Real tmp = Real(0.);
9961  if (ccdom.contains(i-1,j-1,k )) {
9962  tmp += fm2xm2y4z;
9963  }
9964  if (ccdom.contains(i,j-1,k )) {
9965  tmp += fm2xm2y4z;
9966  }
9967  if (ccdom.contains(i-1,j,k )) {
9968  tmp += fm2xm2y4z;
9969  }
9970  if (ccdom.contains(i,j,k )) {
9971  tmp += fm2xm2y4z;
9972  }
9973  m0 -= tmp;
9974  if (gid(i,j,k+1) < gidmax) {
9975  if (offset != 0) {
9976  cols[ps] = gid(i,j,k+1);
9977  mat[ps] = tmp;
9978  }
9979  ++nelems;
9980  }
9981  }
9982  if (offset != 0) { return; }
9983  }
9984 
9985  if (offset == 23 || offset == 0) {
9986  if (nddom.contains(i+1,j,k+1)) {
9987  Real tmp = Real(0.);
9988  if (ccdom.contains(i ,j-1,k )) {
9989  tmp += f2xmy2z;
9990  }
9991  if (ccdom.contains(i ,j,k )) {
9992  tmp += f2xmy2z;
9993  }
9994  m0 -= tmp;
9995  if (gid(i+1,j,k+1) < gidmax) {
9996  if (offset != 0) {
9997  cols[ps] = gid(i+1,j,k+1);
9998  mat[ps] = tmp;
9999  }
10000  ++nelems;
10001  }
10002  }
10003  if (offset != 0) { return; }
10004  }
10005 
10006  if (offset == 24 || offset == 0) {
10007  if (nddom.contains(i-1,j+1,k+1)) {
10008  Real tmp = fxyz;
10009  m0 -= tmp;
10010  if (gid(i-1,j+1,k+1) < gidmax) {
10011  if (offset != 0) {
10012  cols[ps] = gid(i-1,j+1,k+1);
10013  mat[ps] = tmp;
10014  }
10015  ++nelems;
10016  }
10017  }
10018  if (offset != 0) { return; }
10019  }
10020 
10021  if (offset == 25 || offset == 0) {
10022  if (nddom.contains(i,j+1,k+1)) {
10023  Real tmp = Real(0.);
10024  if (ccdom.contains(i-1,j ,k )) {
10025  tmp += fmx2y2z;
10026  }
10027  if (ccdom.contains(i,j ,k )) {
10028  tmp += fmx2y2z;
10029  }
10030  m0 -= tmp;
10031  if (gid(i,j+1,k+1) < gidmax) {
10032  if (offset != 0) {
10033  cols[ps] = gid(i,j+1,k+1);
10034  mat[ps] = tmp;
10035  }
10036  ++nelems;
10037  }
10038  }
10039  if (offset != 0) { return; }
10040  }
10041 
10042  if (offset == 26 || offset == 0) {
10043  if (nddom.contains(i+1,j+1,k+1)) {
10044  Real tmp = fxyz;
10045  m0 -= tmp;
10046  if (gid(i+1,j+1,k+1) < gidmax) {
10047  if (offset != 0) {
10048  cols[ps] = gid(i+1,j+1,k+1);
10049  mat[ps] = tmp;
10050  }
10051  ++nelems;
10052  }
10053  }
10054  if (offset != 0) { return; }
10055  }
10056 
10057  // Only offset == 0 could get this far.
10058  cols[ps] = gid(i,j,k);
10059  mat[ps] = m0;
10060  ncols[lid(i,j,k)] = nelems+1;
10061  }
10062 }
10063 
10064 #endif
10065 
10066 #endif
10067 
10069 int mlndlap_color (int i, int j, int k)
10070 {
10071  return (i%2) + (j%2)*2 + (k%2)*4;
10072 }
10073 
10075 void mlndlap_gscolor_ha (int i, int j, int k, Array4<Real> const& sol,
10076  Array4<Real const> const& rhs, Array4<Real const> const& sx,
10077  Array4<Real const> const& sy, Array4<Real const> const& sz,
10078  Array4<int const> const& msk,
10079  GpuArray<Real,AMREX_SPACEDIM> const& dxinv, int color) noexcept
10080 {
10081  if (mlndlap_color(i,j,k) == color) {
10082  if (msk(i,j,k)) {
10083  sol(i,j,k) = Real(0.0);
10084  } else {
10085  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
10086  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
10087  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
10088 
10089  Real s0 = Real(-4.0)*(facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1)+sx(i-1,j,k-1)+sx(i,j,k-1)
10090  +sx(i-1,j-1,k )+sx(i,j-1,k )+sx(i-1,j,k )+sx(i,j,k ))
10091  +facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1)+sy(i-1,j,k-1)+sy(i,j,k-1)
10092  +sy(i-1,j-1,k )+sy(i,j-1,k )+sy(i-1,j,k )+sy(i,j,k ))
10093  +facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)+sz(i-1,j,k-1)+sz(i,j,k-1)
10094  +sz(i-1,j-1,k )+sz(i,j-1,k )+sz(i-1,j,k )+sz(i,j,k )));
10095  Real Ax = sol(i,j,k)*s0
10096  + sol(i-1,j-1,k-1)*(facx*sx(i-1,j-1,k-1)
10097  +facy*sy(i-1,j-1,k-1)
10098  +facz*sz(i-1,j-1,k-1))
10099  + sol(i+1,j-1,k-1)*(facx*sx(i ,j-1,k-1)
10100  +facy*sy(i ,j-1,k-1)
10101  +facz*sz(i ,j-1,k-1))
10102  + sol(i-1,j+1,k-1)*(facx*sx(i-1,j ,k-1)
10103  +facy*sy(i-1,j ,k-1)
10104  +facz*sz(i-1,j ,k-1))
10105  + sol(i+1,j+1,k-1)*(facx*sx(i ,j ,k-1)
10106  +facy*sy(i ,j ,k-1)
10107  +facz*sz(i ,j ,k-1))
10108  + sol(i-1,j-1,k+1)*(facx*sx(i-1,j-1,k )
10109  +facy*sy(i-1,j-1,k )
10110  +facz*sz(i-1,j-1,k ))
10111  + sol(i+1,j-1,k+1)*(facx*sx(i ,j-1,k )
10112  +facy*sy(i ,j-1,k )
10113  +facz*sz(i ,j-1,k ))
10114  + sol(i-1,j+1,k+1)*(facx*sx(i-1,j ,k )
10115  +facy*sy(i-1,j ,k )
10116  +facz*sz(i-1,j ,k ))
10117  + sol(i+1,j+1,k+1)*(facx*sx(i ,j ,k )
10118  +facy*sy(i ,j ,k )
10119  +facz*sz(i ,j ,k ))
10120  +sol(i ,j-1,k-1)*( -facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1))
10121  +Real(2.0)*facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1))
10122  +Real(2.0)*facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)))
10123  +sol(i ,j+1,k-1)*( -facx*(sx(i-1,j ,k-1)+sx(i,j ,k-1))
10124  +Real(2.0)*facy*(sy(i-1,j ,k-1)+sy(i,j ,k-1))
10125  +Real(2.0)*facz*(sz(i-1,j ,k-1)+sz(i,j ,k-1)))
10126  +sol(i ,j-1,k+1)*( -facx*(sx(i-1,j-1,k )+sx(i,j-1,k ))
10127  +Real(2.0)*facy*(sy(i-1,j-1,k )+sy(i,j-1,k ))
10128  +Real(2.0)*facz*(sz(i-1,j-1,k )+sz(i,j-1,k )))
10129  +sol(i ,j+1,k+1)*( -facx*(sx(i-1,j ,k )+sx(i,j ,k ))
10130  +Real(2.0)*facy*(sy(i-1,j ,k )+sy(i,j ,k ))
10131  +Real(2.0)*facz*(sz(i-1,j ,k )+sz(i,j ,k )))
10132  +sol(i-1,j ,k-1)*( Real(2.0)*facx*(sx(i-1,j-1,k-1)+sx(i-1,j,k-1))
10133  -facy*(sy(i-1,j-1,k-1)+sy(i-1,j,k-1))
10134  +Real(2.0)*facz*(sz(i-1,j-1,k-1)+sz(i-1,j,k-1)))
10135  +sol(i+1,j ,k-1)*( Real(2.0)*facx*(sx(i ,j-1,k-1)+sx(i ,j,k-1))
10136  -facy*(sy(i ,j-1,k-1)+sy(i ,j,k-1))
10137  +Real(2.0)*facz*(sz(i ,j-1,k-1)+sz(i ,j,k-1)))
10138  +sol(i-1,j ,k+1)*( Real(2.0)*facx*(sx(i-1,j-1,k )+sx(i-1,j,k ))
10139  -facy*(sy(i-1,j-1,k )+sy(i-1,j,k ))
10140  +Real(2.0)*facz*(sz(i-1,j-1,k )+sz(i-1,j,k )))
10141  +sol(i+1,j ,k+1)*( Real(2.0)*facx*(sx(i ,j-1,k )+sx(i ,j,k ))
10142  -facy*(sy(i ,j-1,k )+sy(i ,j,k ))
10143  +Real(2.0)*facz*(sz(i ,j-1,k )+sz(i ,j,k )))
10144  +sol(i-1,j-1,k )*( Real(2.0)*facx*(sx(i-1,j-1,k-1)+sx(i-1,j-1,k))
10145  +Real(2.0)*facy*(sy(i-1,j-1,k-1)+sy(i-1,j-1,k))
10146  -facz*(sz(i-1,j-1,k-1)+sz(i-1,j-1,k)))
10147  +sol(i+1,j-1,k )*( Real(2.0)*facx*(sx(i ,j-1,k-1)+sx(i ,j-1,k))
10148  +Real(2.0)*facy*(sy(i ,j-1,k-1)+sy(i ,j-1,k))
10149  -facz*(sz(i ,j-1,k-1)+sz(i ,j-1,k)))
10150  +sol(i-1,j+1,k )*( Real(2.0)*facx*(sx(i-1,j ,k-1)+sx(i-1,j ,k))
10151  +Real(2.0)*facy*(sy(i-1,j ,k-1)+sy(i-1,j ,k))
10152  -facz*(sz(i-1,j ,k-1)+sz(i-1,j ,k)))
10153  +sol(i+1,j+1,k )*( Real(2.0)*facx*(sx(i ,j ,k-1)+sx(i ,j ,k))
10154  +Real(2.0)*facy*(sy(i ,j ,k-1)+sy(i ,j ,k))
10155  -facz*(sz(i ,j ,k-1)+sz(i ,j ,k)))
10156  + Real(2.0)*sol(i-1,j,k)*(Real(2.0)*facx*(sx(i-1,j-1,k-1)+sx(i-1,j,k-1)+sx(i-1,j-1,k)+sx(i-1,j,k))
10157  -facy*(sy(i-1,j-1,k-1)+sy(i-1,j,k-1)+sy(i-1,j-1,k)+sy(i-1,j,k))
10158  -facz*(sz(i-1,j-1,k-1)+sz(i-1,j,k-1)+sz(i-1,j-1,k)+sz(i-1,j,k)))
10159  + Real(2.0)*sol(i+1,j,k)*(Real(2.0)*facx*(sx(i ,j-1,k-1)+sx(i ,j,k-1)+sx(i ,j-1,k)+sx(i ,j,k))
10160  -facy*(sy(i ,j-1,k-1)+sy(i ,j,k-1)+sy(i ,j-1,k)+sy(i ,j,k))
10161  -facz*(sz(i ,j-1,k-1)+sz(i ,j,k-1)+sz(i ,j-1,k)+sz(i ,j,k)))
10162  + Real(2.0)*sol(i,j-1,k)*( -facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1)+sx(i-1,j-1,k)+sx(i,j-1,k))
10163  +Real(2.0)*facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1)+sy(i-1,j-1,k)+sy(i,j-1,k))
10164  -facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)+sz(i-1,j-1,k)+sz(i,j-1,k)))
10165  + Real(2.0)*sol(i,j+1,k)*( -facx*(sx(i-1,j ,k-1)+sx(i,j ,k-1)+sx(i-1,j ,k)+sx(i,j ,k))
10166  +Real(2.0)*facy*(sy(i-1,j ,k-1)+sy(i,j ,k-1)+sy(i-1,j ,k)+sy(i,j ,k))
10167  -facz*(sz(i-1,j ,k-1)+sz(i,j ,k-1)+sz(i-1,j ,k)+sz(i,j ,k)))
10168  + Real(2.0)*sol(i,j,k-1)*( -facx*(sx(i-1,j-1,k-1)+sx(i,j-1,k-1)+sx(i-1,j,k-1)+sx(i,j,k-1))
10169  -facy*(sy(i-1,j-1,k-1)+sy(i,j-1,k-1)+sy(i-1,j,k-1)+sy(i,j,k-1))
10170  +Real(2.0)*facz*(sz(i-1,j-1,k-1)+sz(i,j-1,k-1)+sz(i-1,j,k-1)+sz(i,j,k-1)))
10171  + Real(2.0)*sol(i,j,k+1)*( -facx*(sx(i-1,j-1,k )+sx(i,j-1,k )+sx(i-1,j,k )+sx(i,j,k ))
10172  -facy*(sy(i-1,j-1,k )+sy(i,j-1,k )+sy(i-1,j,k )+sy(i,j,k ))
10173  +Real(2.0)*facz*(sz(i-1,j-1,k )+sz(i,j-1,k )+sz(i-1,j,k )+sz(i,j,k )));
10174 
10175  sol(i,j,k) += (rhs(i,j,k) - Ax) / s0;
10176  }
10177  }
10178 }
10179 
10181 void mlndlap_gscolor_aa (int i, int j, int k, Array4<Real> const& sol,
10182  Array4<Real const> const& rhs, Array4<Real const> const& sig,
10183  Array4<int const> const& msk,
10184  GpuArray<Real,AMREX_SPACEDIM> const& dxinv, int color) noexcept
10185 {
10186  if (mlndlap_color(i,j,k) == color) {
10187  if (msk(i,j,k)) {
10188  sol(i,j,k) = Real(0.0);
10189  } else {
10190  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
10191  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
10192  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
10193  Real fxyz = facx + facy + facz;
10194  Real fmx2y2z = -facx + Real(2.0)*facy + Real(2.0)*facz;
10195  Real f2xmy2z = Real(2.0)*facx - facy + Real(2.0)*facz;
10196  Real f2x2ymz = Real(2.0)*facx + Real(2.0)*facy - facz;
10197  Real f4xm2ym2z = Real(4.0)*facx - Real(2.0)*facy - Real(2.0)*facz;
10198  Real fm2x4ym2z = -Real(2.0)*facx + Real(4.0)*facy - Real(2.0)*facz;
10199  Real fm2xm2y4z = -Real(2.0)*facx - Real(2.0)*facy + Real(4.0)*facz;
10200 
10201  Real s0 = Real(-4.0)*fxyz*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1)
10202  +sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k ));
10203  Real Ax = sol(i,j,k)*s0
10204  + fxyz*(sol(i-1,j-1,k-1)*sig(i-1,j-1,k-1)
10205  + sol(i+1,j-1,k-1)*sig(i ,j-1,k-1)
10206  + sol(i-1,j+1,k-1)*sig(i-1,j ,k-1)
10207  + sol(i+1,j+1,k-1)*sig(i ,j ,k-1)
10208  + sol(i-1,j-1,k+1)*sig(i-1,j-1,k )
10209  + sol(i+1,j-1,k+1)*sig(i ,j-1,k )
10210  + sol(i-1,j+1,k+1)*sig(i-1,j ,k )
10211  + sol(i+1,j+1,k+1)*sig(i ,j ,k ))
10212  + fmx2y2z*(sol(i ,j-1,k-1)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1))
10213  + sol(i ,j+1,k-1)*(sig(i-1,j ,k-1)+sig(i,j ,k-1))
10214  + sol(i ,j-1,k+1)*(sig(i-1,j-1,k )+sig(i,j-1,k ))
10215  + sol(i ,j+1,k+1)*(sig(i-1,j ,k )+sig(i,j ,k )))
10216  + f2xmy2z*(sol(i-1,j ,k-1)*(sig(i-1,j-1,k-1)+sig(i-1,j,k-1))
10217  + sol(i+1,j ,k-1)*(sig(i ,j-1,k-1)+sig(i ,j,k-1))
10218  + sol(i-1,j ,k+1)*(sig(i-1,j-1,k )+sig(i-1,j,k ))
10219  + sol(i+1,j ,k+1)*(sig(i ,j-1,k )+sig(i ,j,k )))
10220  + f2x2ymz*(sol(i-1,j-1,k )*(sig(i-1,j-1,k-1)+sig(i-1,j-1,k))
10221  + sol(i+1,j-1,k )*(sig(i ,j-1,k-1)+sig(i ,j-1,k))
10222  + sol(i-1,j+1,k )*(sig(i-1,j ,k-1)+sig(i-1,j ,k))
10223  + sol(i+1,j+1,k )*(sig(i ,j ,k-1)+sig(i ,j ,k)))
10224  + f4xm2ym2z*(sol(i-1,j,k)*(sig(i-1,j-1,k-1)+sig(i-1,j,k-1)+sig(i-1,j-1,k)+sig(i-1,j,k))
10225  + sol(i+1,j,k)*(sig(i ,j-1,k-1)+sig(i ,j,k-1)+sig(i ,j-1,k)+sig(i ,j,k)))
10226  + fm2x4ym2z*(sol(i,j-1,k)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j-1,k)+sig(i,j-1,k))
10227  + sol(i,j+1,k)*(sig(i-1,j ,k-1)+sig(i,j ,k-1)+sig(i-1,j ,k)+sig(i,j ,k)))
10228  + fm2xm2y4z*(sol(i,j,k-1)*(sig(i-1,j-1,k-1)+sig(i,j-1,k-1)+sig(i-1,j,k-1)+sig(i,j,k-1))
10229  + sol(i,j,k+1)*(sig(i-1,j-1,k )+sig(i,j-1,k )+sig(i-1,j,k )+sig(i,j,k )));
10230 
10231  sol(i,j,k) += (rhs(i,j,k) - Ax) / s0;
10232  }
10233  }
10234 }
10235 
10237 void mlndlap_gscolor_c (int i, int j, int k, Array4<Real> const& sol,
10238  Array4<Real const> const& rhs, Real sig,
10239  Array4<int const> const& msk,
10240  GpuArray<Real,AMREX_SPACEDIM> const& dxinv, int color) noexcept
10241 {
10242  if (mlndlap_color(i,j,k) == color) {
10243  if (msk(i,j,k)) {
10244  sol(i,j,k) = Real(0.0);
10245  } else {
10246  Real facx = Real(1.0/36.0)*dxinv[0]*dxinv[0];
10247  Real facy = Real(1.0/36.0)*dxinv[1]*dxinv[1];
10248  Real facz = Real(1.0/36.0)*dxinv[2]*dxinv[2];
10249  Real fxyz = facx + facy + facz;
10250  Real fmx2y2z = -facx + Real(2.0)*facy + Real(2.0)*facz;
10251  Real f2xmy2z = Real(2.0)*facx - facy + Real(2.0)*facz;
10252  Real f2x2ymz = Real(2.0)*facx + Real(2.0)*facy - facz;
10253  Real f4xm2ym2z = Real(4.0)*facx - Real(2.0)*facy - Real(2.0)*facz;
10254  Real fm2x4ym2z = -Real(2.0)*facx + Real(4.0)*facy - Real(2.0)*facz;
10255  Real fm2xm2y4z = -Real(2.0)*facx - Real(2.0)*facy + Real(4.0)*facz;
10256 
10257  Real s0 = Real(-4.0)*fxyz*Real(8.);
10258  Real Ax = sol(i,j,k)*s0
10259  + fxyz*(sol(i-1,j-1,k-1)
10260  + sol(i+1,j-1,k-1)
10261  + sol(i-1,j+1,k-1)
10262  + sol(i+1,j+1,k-1)
10263  + sol(i-1,j-1,k+1)
10264  + sol(i+1,j-1,k+1)
10265  + sol(i-1,j+1,k+1)
10266  + sol(i+1,j+1,k+1))
10267  + fmx2y2z*(sol(i ,j-1,k-1)*Real(2.)
10268  + sol(i ,j+1,k-1)*Real(2.)
10269  + sol(i ,j-1,k+1)*Real(2.)
10270  + sol(i ,j+1,k+1)*Real(2.))
10271  + f2xmy2z*(sol(i-1,j ,k-1)*Real(2.)
10272  + sol(i+1,j ,k-1)*Real(2.)
10273  + sol(i-1,j ,k+1)*Real(2.)
10274  + sol(i+1,j ,k+1)*Real(2.))
10275  + f2x2ymz*(sol(i-1,j-1,k )*Real(2.)
10276  + sol(i+1,j-1,k )*Real(2.)
10277  + sol(i-1,j+1,k )*Real(2.)
10278  + sol(i+1,j+1,k )*Real(2.))
10279  + f4xm2ym2z*(sol(i-1,j,k)*Real(4.)
10280  + sol(i+1,j,k)*Real(4.))
10281  + fm2x4ym2z*(sol(i,j-1,k)*Real(4.)
10282  + sol(i,j+1,k)*Real(4.))
10283  + fm2xm2y4z*(sol(i,j,k-1)*Real(4.)
10284  + sol(i,j,k+1)*Real(4.));
10285 
10286  sol(i,j,k) += (rhs(i,j,k) - Ax*sig) / (s0*sig);
10287  }
10288  }
10289 }
10290 
10292 void mlndlap_gscolor_sten (int i, int j, int k, Array4<Real> const& sol,
10293  Array4<Real const> const& rhs,
10294  Array4<Real const> const& sten,
10295  Array4<int const> const& msk, int color) noexcept
10296 {
10297  if (mlndlap_color(i,j,k) == color) {
10298  mlndlap_gauss_seidel_sten(i,j,k,sol,rhs,sten,msk);
10299  }
10300 }
10301 
10302 }
10303 #endif
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_DEVICE
Definition: AMReX_GpuQualifiers.H:18
#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
#define AMREX_LOOP_3D(bx, i, j, k, block)
Definition: AMReX_Loop.nolint.H:4
HYPRE_Int Int
Definition: AMReX_HypreNodeLap.H:36
static int f(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:44
static constexpr int i_B_xyz
Definition: AMReX_algoim.H:42
static constexpr int i_S_y_z2
Definition: AMReX_algoim.H:26
static constexpr int i_S_y_z
Definition: AMReX_algoim.H:20
static constexpr int i_S_x2
Definition: AMReX_algoim.H:15
static constexpr int numSurfIntgs
Definition: AMReX_algoim.H:43
static constexpr int i_S_x_y
Definition: AMReX_algoim.H:18
static constexpr int i_S_y
Definition: AMReX_algoim.H:13
static constexpr int i_S_x_z
Definition: AMReX_algoim.H:19
static constexpr int i_B_z
Definition: AMReX_algoim.H:38
static constexpr int i_S_x_y2
Definition: AMReX_algoim.H:23
static constexpr int i_S_xyz
Definition: AMReX_algoim.H:30
static constexpr int i_S_y2_z2
Definition: AMReX_algoim.H:29
static constexpr int i_B_x_y
Definition: AMReX_algoim.H:39
static constexpr int i_B_x_z
Definition: AMReX_algoim.H:40
static constexpr int i_S_x2_y2
Definition: AMReX_algoim.H:27
static constexpr int i_S_x2_z2
Definition: AMReX_algoim.H:28
static constexpr int i_S_x
Definition: AMReX_algoim.H:12
static constexpr int i_S_y2_z
Definition: AMReX_algoim.H:24
static constexpr int i_S_x2_y
Definition: AMReX_algoim.H:21
static constexpr int i_B_y_z
Definition: AMReX_algoim.H:41
static constexpr int i_B_x
Definition: AMReX_algoim.H:36
static constexpr int i_S_z
Definition: AMReX_algoim.H:14
static constexpr int i_S_z2
Definition: AMReX_algoim.H:17
static constexpr int i_S_x_z2
Definition: AMReX_algoim.H:25
static constexpr int i_S_x2_z
Definition: AMReX_algoim.H:22
static constexpr int i_B_y
Definition: AMReX_algoim.H:37
static constexpr int i_S_y2
Definition: AMReX_algoim.H:16
@ max
Definition: AMReX_ParallelReduce.H:17
constexpr int iz
Definition: AMReX_Interp_3D_C.H:37
constexpr int iy
Definition: AMReX_Interp_2D_C.H:33
constexpr int ix
Definition: AMReX_Interp_2D_C.H:32
constexpr int ist_000
Definition: AMReX_MLNodeLap_3D_K.H:1949
constexpr int ist_pp0
Definition: AMReX_MLNodeLap_3D_K.H:1953
constexpr int ist_p00
Definition: AMReX_MLNodeLap_3D_K.H:1950
constexpr int ist_ppp
Definition: AMReX_MLNodeLap_3D_K.H:1956
constexpr int ist_00p
Definition: AMReX_MLNodeLap_3D_K.H:1952
constexpr int crse_cell
Definition: AMReX_MLNodeLinOp_K.H:54
constexpr int ist_p0p
Definition: AMReX_MLNodeLap_3D_K.H:1954
constexpr int ist_inv
Definition: AMReX_MLNodeLap_3D_K.H:1957
constexpr int ist_0p0
Definition: AMReX_MLNodeLap_3D_K.H:1951
constexpr int crse_fine_node
Definition: AMReX_MLNodeLinOp_K.H:57
constexpr double eps
Definition: AMReX_MLNodeLap_K.H:19
constexpr int n_sten
Definition: AMReX_MLNodeLap_3D_K.H:1958
constexpr int ist_0pp
Definition: AMReX_MLNodeLap_3D_K.H:1955
constexpr Real almostone
Definition: AMReX_MLNodeLap_K.H:21
static constexpr int P
Definition: AMReX_OpenBC.H:14
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mlndlap_adotx_ha(int i, int, int, Array4< Real const > const &x, Array4< Real const > const &sx, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:52
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void mlndlap_gscolor_ha(int i, int j, int k, Array4< Real > const &sol, Array4< Real const > const &rhs, Array4< Real const > const &sx, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv, int color) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:426
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real ha_interp_face_xz(Array4< Real const > const &crse, Array4< Real const > const &sigx, Array4< Real const > const &sigz, int i, int j, int k, int ic, int jc, int kc) noexcept
Definition: AMReX_MLNodeLap_3D_K.H:1187
AMREX_ATTRIBUTE_FLATTEN_FOR void LoopOnCpu(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition: AMReX_Loop.H:355
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_Ax_fine_contrib_cs(int i, int j, int, Box const &ndbx, Box const &ccbx, Array4< Real > const &f, Array4< Real const > const &res, Array4< Real const > const &rhs, Array4< Real const > const &phi, Real const sig, Array4< int const > const &msk, bool is_rz, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:1157
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_divu_fine_contrib(int i, int j, int, Box const &fvbx, Box const &velbx, Array4< Real > const &rhs, Array4< Real const > const &vel, Array4< Real const > const &frhs, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv, bool is_rz) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:867
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_avgdown_coeff_z(int i, int j, int k, Array4< Real > const &crse, Array4< Real const > const &fine) noexcept
Definition: AMReX_MLNodeLap_3D_K.H:53
BoxND< AMREX_SPACEDIM > Box
Definition: AMReX_BaseFwd.H:27
AMREX_ATTRIBUTE_FLATTEN_FOR void LoopConcurrentOnCpu(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition: AMReX_Loop.H:378
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real aa_interp_line_z(Array4< Real const > const &crse, Array4< Real const > const &sig, int i, int j, int k, int ic, int jc, int kc) noexcept
Definition: AMReX_MLNodeLap_3D_K.H:941
void mlndlap_gauss_seidel_with_line_solve_aa(Box const &, Array4< Real > const &, Array4< Real const > const &, Array4< Real const > const &, Array4< int const > const &, GpuArray< Real, AMREX_SPACEDIM > const &) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:225
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void mlndlap_jacobi_ha(int i, int, int, Array4< Real > const &sol, Real Ax, Array4< Real const > const &rhs, Array4< Real const > const &sx, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:92
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_semi_avgdown_coeff(int i, int j, int k, Array4< Real > const &crse, Array4< Real const > const &fine, int) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real ha_interp_face_yz(Array4< Real const > const &crse, Array4< Real const > const &sigy, Array4< Real const > const &sigz, int i, int j, int k, int ic, int jc, int kc) noexcept
Definition: AMReX_MLNodeLap_3D_K.H:1202
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_interpadd_rap(int, int, int, Array4< Real > const &, Array4< Real const > const &, Array4< Real const > const &, Array4< int const > const &) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:408
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_avgdown_coeff_y(int i, int j, int k, Array4< Real > const &crse, Array4< Real const > const &fine) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:36
void mlndlap_gauss_seidel_aa(Box const &bx, Array4< Real > const &sol, Array4< Real const > const &rhs, Array4< Real const > const &sx, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:193
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & max(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:35
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mlndlap_adotx_aa(int i, int j, int k, Array4< Real const > const &x, Array4< Real const > const &sx, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:66
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void mlndlap_jacobi_c(int i, int, int, Array4< Real > const &sol, Real Ax, Array4< Real const > const &rhs, Real sig, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:141
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void mlndlap_jacobi_aa(int i, int j, int k, Array4< Real > const &sol, Real Ax, Array4< Real const > const &rhs, Array4< Real const > const &sig, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:125
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mlndlap_adotx_sten(int, int, int, Array4< Real const > const &, Array4< Real const > const &, Array4< int const > const &) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:396
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & min(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:21
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_interpadd_c(int i, int, int, Array4< Real > const &fine, Array4< Real const > const &crse, Array4< int const > const &msk) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:233
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_set_stencil_s0(int, int, int, Array4< Real > const &) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:387
void mlndlap_gauss_seidel_ha(Box const &bx, Array4< Real > const &sol, Array4< Real const > const &rhs, Array4< Real const > const &sx, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:170
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_res_cf_contrib(int, int, int, Array4< Real > const &, Array4< Real const > const &, Array4< Real const > const &, Array4< Real const > const &, Array4< int const > const &, Array4< int const > const &, Array4< int const > const &, Array4< Real const > const &, GpuArray< Real, AMREX_SPACEDIM > const &, Box const &, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &, bool) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:357
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_normalize_aa(int i, int j, int k, Array4< Real > const &x, Array4< Real const > const &sx, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:84
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mlndlap_sum_Ax(P const &pred, S const &sig, int i, int j, Real facx, Real facy, Array4< Real const > const &phi, bool is_rz) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:1057
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 void mlndlap_rhcc_fine_contrib(int, int, int, Box const &, Array4< Real > const &, Array4< Real const > const &, Array4< int const > const &) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:332
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_semi_interpadd_aa(int, int, int, Array4< Real > const &, Array4< Real const > const &, Array4< Real const > const &, Array4< int const > const &, int) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:270
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_set_stencil(Box const &, Array4< Real > const &, Array4< Real const > const &, GpuArray< Real, AMREX_SPACEDIM > const &) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:381
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real aa_interp_line_y(Array4< Real const > const &crse, Array4< Real const > const &sig, int i, int j, int ic, int jc) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:582
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_zero_fine(int i, int, int, Array4< Real > const &phi, Array4< int const > const &msk, int fine_flag) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:8
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mlndlap_adotx_c(int i, int, int, Array4< Real const > const &x, Real sigma, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:37
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real ha_interp_face_xy(Array4< Real const > const &crse, Array4< Real const > const &sigx, Array4< Real const > const &sigy, int i, int j, int ic, int jc) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:694
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_interpadd_aa(int i, int, int, Array4< Real > const &fine, Array4< Real const > const &crse, Array4< Real const > const &sig, Array4< int const > const &msk) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:251
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_res_cf_contrib_cs(int, int, int, Array4< Real > const &, Array4< Real const > const &, Array4< Real const > const &, Real, Array4< int const > const &, Array4< int const > const &, Array4< int const > const &, Array4< Real const > const &, GpuArray< Real, AMREX_SPACEDIM > const &, Box const &, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &, bool) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:369
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_divu(int i, int, int, Array4< Real > const &rhs, Array4< Real const > const &vel, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv, Box const &, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:284
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_divu_cf_contrib(int, int, int, Array4< Real > const &, Array4< Real const > const &, Array4< Real const > const &, Array4< Real const > const &, Array4< int const > const &, Array4< int const > const &, Array4< int const > const &, GpuArray< Real, AMREX_SPACEDIM > const &, Box const &, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &, bool) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:338
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition: AMReX.H:111
void mlndlap_gauss_seidel_sten(Box const &, Array4< Real > const &, Array4< Real const > const &, Array4< Real const > const &, Array4< int const > const &) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:401
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_gscolor_sten(int, int, int, Array4< Real > const &, Array4< Real const > const &, Array4< Real const > const &, Array4< int const > const &, int) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:479
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE BoxND< dim > surroundingNodes(const BoxND< dim > &b, int dir) noexcept
Returns a BoxND with NODE based coordinates in direction dir that encloses BoxND b....
Definition: AMReX_Box.H:1399
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE IntVectND< dim > scale(const IntVectND< dim > &p, int s) noexcept
Returns a IntVectND obtained by multiplying each of the components of this IntVectND by s.
Definition: AMReX_IntVect.H:1006
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void mlndlap_gscolor_aa(int i, int j, int k, Array4< Real > const &sol, Array4< Real const > const &rhs, Array4< Real const > const &sx, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv, int color) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:448
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_mknewu(int i, int, int, Array4< Real > const &u, Array4< Real const > const &p, Array4< Real const > const &sig, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:312
AMREX_GPU_HOST_DEVICE AMREX_ATTRIBUTE_FLATTEN_FOR void LoopConcurrent(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition: AMReX_Loop.H:150
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_restriction_rap(int, int, int, Array4< Real > const &, Array4< Real const > const &, Array4< Real const > const &, Array4< int const > const &) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:414
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void mlndlap_gscolor_c(int i, int j, int k, Array4< Real > const &sol, Array4< Real const > const &rhs, Real sig, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv, int color) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:458
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real aa_interp_face_yz(Array4< Real const > const &crse, Array4< Real const > const &sig, int i, int j, int k, int ic, int jc, int kc) noexcept
Definition: AMReX_MLNodeLap_3D_K.H:978
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mlndlap_sum_Df(int ii, int jj, Real facx, Real facy, Array4< Real const > const &vel, Box const &velbx, bool is_rz) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:843
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_Ax_fine_contrib_doit(S const &sig, int i, int j, Box const &ndbx, Box const &ccbx, Array4< Real > const &f, Array4< Real const > const &res, Array4< Real const > const &rhs, Array4< Real const > const &phi, Array4< int const > const &msk, bool is_rz, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:1099
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real aa_interp_face_xy(Array4< Real const > const &crse, Array4< Real const > const &sig, int i, int j, int ic, int jc) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:591
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
AMREX_GPU_DEVICE AMREX_FORCE_INLINE int mlndlap_color(int i, int, int)
Definition: AMReX_MLNodeLap_1D_K.H:420
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
const int[]
Definition: AMReX_BLProfiler.cpp:1664
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_crse_resid(int, int, int, Array4< Real > const &, Array4< Real const > const &, Array4< int const > const &, Box const &, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &, bool) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:349
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_normalize_ha(int i, int, int, Array4< Real > const &x, Array4< Real const > const &sx, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:74
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_avgdown_coeff_x(int i, int, int, Array4< Real > const &crse, Array4< Real const > const &fine) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:21
void mlndlap_gauss_seidel_c(Box const &bx, Array4< Real > const &sol, Array4< Real const > const &rhs, Real sig, Array4< int const > const &msk, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:203
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_interpadd_ha(int i, int j, int k, Array4< Real > const &fine, Array4< Real const > const &crse, Array4< Real const > const &sig, Array4< int const > const &msk) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:276
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_Ax_fine_contrib(int i, int j, int, Box const &ndbx, Box const &ccbx, Array4< Real > const &f, Array4< Real const > const &res, Array4< Real const > const &rhs, Array4< Real const > const &phi, Array4< Real const > const &sig, Array4< int const > const &msk, bool is_rz, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:1143
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real aa_interp_line_x(Array4< Real const > const &crse, Array4< Real const > const &sig, int i, int j, int ic, int jc) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:573
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_stencil_rap(int, int, int, Array4< Real > const &, Array4< Real const > const &) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:391
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mlndlap_adotx_sten_doit(int i, int j, int k, Array4< Real const > const &x, Array4< Real const > const &sten) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:1507
AMREX_FORCE_INLINE void tridiagonal_solve(Array1D< T, 0, 31 > &a_ls, Array1D< T, 0, 31 > &b_ls, Array1D< T, 0, 31 > &c_ls, Array1D< T, 0, 31 > &r_ls, Array1D< T, 0, 31 > &u_ls, Array1D< T, 0, 31 > &gam, int ilen) noexcept
Definition: AMReX_MLABecLap_3D_K.H:432
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mlndlap_rhcc(int i, int, int, Array4< Real const > const &rhcc, Array4< int const > const &msk) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:299
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mlndlap_mknewu_c(int i, int, int, Array4< Real > const &u, Array4< Real const > const &p, Real sig, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MLNodeLap_1D_K.H:322
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real aa_interp_face_xz(Array4< Real const > const &crse, Array4< Real const > const &sig, int i, int j, int k, int ic, int jc, int kc) noexcept
Definition: AMReX_MLNodeLap_3D_K.H:964
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real neumann_scale(int i, int j, Box const &nddom, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &bclo, GpuArray< LinOpBCType, AMREX_SPACEDIM > const &bchi) noexcept
Definition: AMReX_MLNodeLap_2D_K.H:930
Definition: AMReX_Array4.H:61