1 #ifndef AMREX_MULTIFAB_UTIL_3D_C_H_
2 #define AMREX_MULTIFAB_UTIL_3D_C_H_
3 #include <AMReX_Config.H>
14 Array4<Real >
const& cc,
15 Array4<Real const>
const& nd,
16 int cccomp,
int ndcomp) noexcept
18 cc(i,j,k,n+cccomp) = Real(0.125)*( nd(i,j ,k ,n+ndcomp) + nd(i+1,j ,k ,n+ndcomp)
19 + nd(i,j+1,k ,n+ndcomp) + nd(i+1,j+1,k ,n+ndcomp)
20 + nd(i,j ,k+1,n+ndcomp) + nd(i+1,j ,k+1,n+ndcomp)
21 + nd(i,j+1,k+1,n+ndcomp) + nd(i+1,j+1,k+1,n+ndcomp));
32 cc(i,j,k,0+cccomp) = Real(0.25) * ( Ex(i,j,k) + Ex(i,j+1,k) + Ex(i,j,k+1) + Ex(i,j+1,k+1) );
33 cc(i,j,k,1+cccomp) = Real(0.25) * ( Ey(i,j,k) + Ey(i+1,j,k) + Ey(i,j,k+1) + Ey(i+1,j,k+1) );
34 cc(i,j,k,2+cccomp) = Real(0.25) * ( Ez(i,j,k) + Ez(i+1,j,k) + Ez(i,j+1,k) + Ez(i+1,j+1,k) );
37 template <
typename CT,
typename FT>
46 cc(i,j,k,0+cccomp) = CT(0.5) * CT( fx(i,j,k) + fx(i+1,j,k) );
47 cc(i,j,k,1+cccomp) = CT(0.5) * CT( fy(i,j,k) + fy(i,j+1,k) );
48 cc(i,j,k,2+cccomp) = CT(0.5) * CT( fz(i,j,k) + fz(i,j,k+1) );
55 bool use_harmonic_averaging) noexcept
57 if (use_harmonic_averaging)
59 if (xbx.contains(i,j,k)) {
60 if (cc(i-1,j,k,n) == Real(0.0) || cc(i,j,k,n) == Real(0.0)) {
61 fx(i,j,k,n) = Real(0.0);
63 fx(i,j,k,n) = Real(2.0) / (Real(1.0)/cc(i-1,j,k,n) + Real(1.0)/cc(i,j,k,n));
66 if (ybx.contains(i,j,k)) {
67 if (cc(i,j-1,k,n) == Real(0.0) || cc(i,j,k,n) == Real(0.0)) {
68 fy(i,j,k,n) = Real(0.0);
70 fy(i,j,k,n) = Real(2.0) / (Real(1.0)/cc(i,j-1,k,n) + Real(1.0)/cc(i,j,k,n));
73 if (zbx.contains(i,j,k)) {
74 if (cc(i,j,k-1,n) == Real(0.0) || cc(i,j,k,n) == Real(0.0)) {
75 fz(i,j,k,n) = Real(0.0);
77 fz(i,j,k,n) = Real(2.0) / (Real(1.0)/cc(i,j,k-1,n) + Real(1.0)/cc(i,j,k,n));
81 if (xbx.contains(i,j,k)) {
82 fx(i,j,k,n) = Real(0.5)*(cc(i-1,j,k,n) + cc(i,j,k,n));
84 if (ybx.contains(i,j,k)) {
85 fy(i,j,k,n) = Real(0.5)*(cc(i,j-1,k,n) + cc(i,j,k,n));
87 if (zbx.contains(i,j,k)) {
88 fz(i,j,k,n) = Real(0.5)*(cc(i,j,k-1,n) + cc(i,j,k,n));
96 Array4<T const>
const&
fine,
97 int ccomp,
int fcomp,
int ncomp,
100 const auto clo =
lbound(bx);
101 const auto chi =
ubound(bx);
102 const int facx = ratio[0];
103 const int facy = ratio[1];
104 const int facz = ratio[2];
109 T facInv = T(1.0) / (facy*facz);
110 for (
int n = 0; n < ncomp; ++n) {
111 for (
int k = clo.z; k <= chi.z; ++k) {
112 for (
int j = clo.y; j <= chi.y; ++j) {
113 for (
int i = clo.x; i <= chi.x; ++i) {
118 for (
int kref = 0; kref < facz; ++kref) {
119 for (
int jref = 0; jref < facy; ++jref) {
120 c +=
fine(ii,jj+jref,kk+kref,n+fcomp);
122 crse(i,j,k,n+ccomp) = c * facInv;
129 T facInv = T(1.0) / (facx*facz);
130 for (
int n = 0; n < ncomp; ++n) {
131 for (
int k = clo.z; k <= chi.z; ++k) {
132 for (
int j = clo.y; j <= chi.y; ++j) {
133 for (
int i = clo.x; i <= chi.x; ++i) {
138 for (
int kref = 0; kref < facz; ++kref) {
139 for (
int iref = 0; iref < facx; ++iref) {
140 c +=
fine(ii+iref,jj,kk+kref,n+fcomp);
142 crse(i,j,k,n+ccomp) = c * facInv;
149 T facInv = T(1.0) / (facx*facy);
150 for (
int n = 0; n < ncomp; ++n) {
151 for (
int k = clo.z; k <= chi.z; ++k) {
152 for (
int j = clo.y; j <= chi.y; ++j) {
153 for (
int i = clo.x; i <= chi.x; ++i) {
158 for (
int jref = 0; jref < facy; ++jref) {
159 for (
int iref = 0; iref < facx; ++iref) {
160 c +=
fine(ii+iref,jj+jref,kk,n+fcomp);
162 crse(i,j,k,n+ccomp) = c * facInv;
171 template <
typename T>
174 Array4<T const>
const&
fine,
175 int ccomp,
int fcomp,
IntVect const& ratio,
int idir) noexcept
177 const int facx = ratio[0];
178 const int facy = ratio[1];
179 const int facz = ratio[2];
180 const int ii = i*facx;
181 const int jj = j*facy;
182 const int kk = k*facz;
187 const T facInv = T(1.0) / (facy*facz);
189 for (
int kref = 0; kref < facz; ++kref) {
190 for (
int jref = 0; jref < facy; ++jref) {
191 c +=
fine(ii,jj+jref,kk+kref,n+fcomp);
193 crse(i,j,k,n+ccomp) = c * facInv;
198 const T facInv = T(1.0) / (facx*facz);
200 for (
int kref = 0; kref < facz; ++kref) {
201 for (
int iref = 0; iref < facx; ++iref) {
202 c +=
fine(ii+iref,jj,kk+kref,n+fcomp);
204 crse(i,j,k,n+ccomp) = c * facInv;
209 const T facInv = T(1.0) / (facx*facy);
211 for (
int jref = 0; jref < facy; ++jref) {
212 for (
int iref = 0; iref < facx; ++iref) {
213 c +=
fine(ii+iref,jj+jref,kk,n+fcomp);
215 crse(i,j,k,n+ccomp) = c * facInv;
224 Array4<Real const>
const&
fine,
225 int ccomp,
int fcomp,
int ncomp,
228 const auto clo =
lbound(bx);
229 const auto chi =
ubound(bx);
230 const int facx = ratio[0];
231 const int facy = ratio[1];
232 const int facz = ratio[2];
237 Real facInv = Real(1.0) /
static_cast<Real
>(facx);
238 for (
int n = 0; n < ncomp; ++n) {
239 for (
int k = clo.z; k <= chi.z; ++k) {
240 for (
int j = clo.y; j <= chi.y; ++j) {
241 for (
int i = clo.x; i <= chi.x; ++i) {
246 for (
int iref = 0; iref < facx; ++iref) {
247 c +=
fine(ii+iref,jj,kk,n+fcomp);
249 crse(i,j,k,n+ccomp) = c * facInv;
256 Real facInv = Real(1.0) /
static_cast<Real
>(facy);
257 for (
int n = 0; n < ncomp; ++n) {
258 for (
int k = clo.z; k <= chi.z; ++k) {
259 for (
int j = clo.y; j <= chi.y; ++j) {
260 for (
int i = clo.x; i <= chi.x; ++i) {
265 for (
int jref = 0; jref < facy; ++jref) {
266 c +=
fine(ii,jj+jref,kk,n+fcomp);
268 crse(i,j,k,n+ccomp) = c * facInv;
275 Real facInv = Real(1.0) /
static_cast<Real
>(facz);
276 for (
int n = 0; n < ncomp; ++n) {
277 for (
int k = clo.z; k <= chi.z; ++k) {
278 for (
int j = clo.y; j <= chi.y; ++j) {
279 for (
int i = clo.x; i <= chi.x; ++i) {
284 for (
int kref = 0; kref < facz; ++kref) {
285 c +=
fine(ii,jj,kk+kref,n+fcomp);
287 crse(i,j,k,n+ccomp) = c * facInv;
298 Array4<Real const>
const&
fine,
299 int ccomp,
int fcomp,
IntVect const& ratio,
int idir) noexcept
301 const int facx = ratio[0];
302 const int facy = ratio[1];
303 const int facz = ratio[2];
304 const int ii = i*facx;
305 const int jj = j*facy;
306 const int kk = k*facz;
311 const Real facInv = Real(1.0) /
static_cast<Real
>(facx);
313 for (
int iref = 0; iref < facx; ++iref) {
314 c +=
fine(ii+iref,jj,kk,n+fcomp);
316 crse(i,j,k,n+ccomp) = c * facInv;
321 const Real facInv = Real(1.0) /
static_cast<Real
>(facy);
323 for (
int jref = 0; jref < facy; ++jref) {
324 c +=
fine(ii,jj+jref,kk,n+fcomp);
326 crse(i,j,k,n+ccomp) = c * facInv;
331 const Real facInv = Real(1.0) /
static_cast<Real
>(facz);
333 for (
int kref = 0; kref < facz; ++kref) {
334 c +=
fine(ii,jj,kk+kref,n+fcomp);
336 crse(i,j,k,n+ccomp) = c * facInv;
343 template <
typename T>
346 Array4<T const>
const&
fine,
347 int ccomp,
int fcomp,
int ncomp,
350 const auto clo =
lbound(bx);
351 const auto chi =
ubound(bx);
352 const int facx = ratio[0];
353 const int facy = ratio[1];
354 const int facz = ratio[2];
355 const T volfrac = T(1.0)/T(facx*facy*facz);
357 for (
int n = 0; n < ncomp; ++n) {
358 for (
int k = clo.z; k <= chi.z; ++k) {
359 for (
int j = clo.y; j <= chi.y; ++j) {
360 for (
int i = clo.x; i <= chi.x; ++i) {
365 for (
int kref = 0; kref < facz; ++kref) {
366 for (
int jref = 0; jref < facy; ++jref) {
367 for (
int iref = 0; iref < facx; ++iref) {
368 c +=
fine(ii+iref,jj+jref,kk+kref,n+fcomp);
370 crse(i,j,k,n+ccomp) = volfrac * c;
375 template <
typename T>
378 Array4<T const>
const&
fine,
379 int ccomp,
int fcomp,
IntVect const& ratio) noexcept
381 const int facx = ratio[0];
382 const int facy = ratio[1];
383 const int facz = ratio[2];
384 const T volfrac = T(1.0)/T(facx*facy*facz);
385 const int ii = i*facx;
386 const int jj = j*facy;
387 const int kk = k*facz;
389 for (
int kref = 0; kref < facz; ++kref) {
390 for (
int jref = 0; jref < facy; ++jref) {
391 for (
int iref = 0; iref < facx; ++iref) {
392 c +=
fine(ii+iref,jj+jref,kk+kref,n+fcomp);
394 crse(i,j,k,n+ccomp) = volfrac * c;
399 Array4<Real const>
const&
fine,
400 Array4<Real const>
const& fv,
401 int ccomp,
int fcomp,
IntVect const& ratio) noexcept
403 const int facx = ratio[0];
404 const int facy = ratio[1];
405 const int facz = ratio[2];
406 const int ii = i*facx;
407 const int jj = j*facy;
408 const int kk = k*facz;
409 Real cd = 0.0, cv = 0.0;
410 for (
int kref = 0; kref < facz; ++kref) {
411 for (
int jref = 0; jref < facy; ++jref) {
412 for (
int iref = 0; iref < facx; ++iref) {
413 cv += fv(ii+iref,jj+jref,kk+kref);
414 cd +=
fine(ii+iref,jj+jref,kk+kref,n+fcomp)*fv(ii+iref,jj+jref,kk+kref);
416 crse(i,j,k,n+ccomp) = cd/cv;
419 template <
typename T>
422 Array4<T const>
const&
fine,
423 int ccomp,
int fcomp,
int ncomp,
426 const auto clo =
lbound(bx);
427 const auto chi =
ubound(bx);
428 const int facx = ratio[0];
429 const int facy = ratio[1];
430 const int facz = ratio[2];
432 for (
int n = 0; n < ncomp; ++n) {
433 for (
int k = clo.z; k <= chi.z; ++k) {
435 for (
int j = clo.y; j <= chi.y; ++j) {
438 for (
int i = clo.x; i <= chi.x; ++i) {
439 crse(i,j,k,n+ccomp) =
fine(i*facx,jj,kk,n+fcomp);
449 Array4<T const>
const&
fine,
450 int ccomp,
int fcomp,
IntVect const& ratio) noexcept
452 crse(i,j,k,n+ccomp) =
fine(i*ratio[0],j*ratio[1],k*ratio[2],n+fcomp);
463 const auto lo =
lbound(bx);
464 const auto hi =
ubound(bx);
465 const Real dxi = dxinv[0];
466 const Real dyi = dxinv[1];
467 const Real dzi = dxinv[2];
469 for (
int n = 0; n < divu.ncomp; ++n) {
470 for (
int k = lo.z; k <= hi.z; ++k) {
471 for (
int j = lo.y; j <= hi.y; ++j) {
473 for (
int i = lo.x; i <= hi.x; ++i) {
474 divu(i,j,k,n) = dxi * (u(i+1,j,k,n)-u(i,j,k,n))
475 + dyi * (v(i,j+1,k,n)-v(i,j,k,n))
476 + dzi * (w(i,j,k+1,n)-w(i,j,k,n));
491 const auto lo =
lbound(bx);
492 const auto hi =
ubound(bx);
493 const Real dxi = dxinv[0];
494 const Real dyi = dxinv[1];
495 const Real dzi = dxinv[2];
497 for (
int k = lo.z; k <= hi.z; ++k) {
498 for (
int j = lo.y; j <= hi.y; ++j) {
500 for (
int i = lo.x; i <= hi.x; ++i) {
501 grad(i,j,k,0) = dxi * (u(i+1,j,k,0)-u(i,j,k,0));
502 grad(i,j,k,1) = dyi * (v(i,j+1,k,0)-v(i,j,k,0));
503 grad(i,j,k,2) = dzi * (w(i,j,k+1,0)-w(i,j,k,0));
520 const auto lo =
lbound(bx);
521 const auto hi =
ubound(bx);
522 const Real dxi = dxinv[0];
523 const Real dyi = dxinv[1];
524 const Real dzi = dxinv[2];
526 for (
int n = 0; n < diff.ncomp; ++n) {
527 for (
int k = lo.z; k <= hi.z; ++k) {
528 for (
int j = lo.y; j <= hi.y; ++j) {
530 for (
int i = lo.x; i <= hi.x; ++i) {
531 diff(i,j,k,n) = Real(0.5)*dxi * (u_face(i+1,j,k)+u_face(i,j,k)) *
532 (s_on_x_face(i+1,j,k,n)-s_on_x_face(i,j,k,n))
533 + Real(0.5)*dyi * (v_face(i,j+1,k)+v_face(i,j,k)) *
534 (s_on_y_face(i,j+1,k,n)-s_on_y_face(i,j,k,n))
535 + Real(0.5)*dzi * (w_face(i,j,k+1)+w_face(i,j,k)) *
536 (s_on_z_face(i,j,k+1,n)-s_on_z_face(i,j,k,n));
#define AMREX_PRAGMA_SIMD
Definition: AMReX_Extension.H:80
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
int idir
Definition: AMReX_HypreMLABecLap.cpp:1093
Array4< Real > fine
Definition: AMReX_InterpFaceRegister.cpp:90
Array4< Real const > crse
Definition: AMReX_InterpFaceRegister.cpp:92
Definition: AMReX_Amr.cpp:49
BoxND< AMREX_SPACEDIM > Box
Definition: AMReX_BaseFwd.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_avg_fc_to_cc(int i, int, int, Array4< CT > const &cc, Array4< FT const > const &fx, int cccomp, GeometryData const &gd) noexcept
Definition: AMReX_MultiFabUtil_1D_C.H:33
AMREX_GPU_HOST_DEVICE void amrex_compute_convective_difference(Box const &bx, Array4< amrex::Real > const &diff, Array4< Real const > const &u_face, Array4< Real const > const &v_face, Array4< Real const > const &s_on_x_face, Array4< Real const > const &s_on_y_face, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MultiFabUtil_2D_C.H:396
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_avgdown_faces(Box const &bx, Array4< T > const &crse, Array4< T const > const &fine, int ccomp, int fcomp, int ncomp, IntVect const &ratio, int) noexcept
Definition: AMReX_MultiFabUtil_1D_C.H:130
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_avg_cc_to_fc(int i, int, int, int n, Box const &xbx, Array4< Real > const &fx, Array4< Real const > const &cc, GeometryData const &gd, bool use_harmonic_averaging) noexcept
Definition: AMReX_MultiFabUtil_1D_C.H:75
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 ubound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:315
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 lbound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:308
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_avgdown_with_vol(int i, int, int, int n, Array4< T > const &crse, Array4< T const > const &fine, Array4< T const > const &fv, int ccomp, int fcomp, IntVect const &ratio) noexcept
Definition: AMReX_MultiFabUtil_1D_C.H:236
IntVectND< AMREX_SPACEDIM > IntVect
Definition: AMReX_BaseFwd.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_avg_nd_to_cc(int i, int, int, int n, Array4< Real > const &cc, Array4< Real const > const &nd, int cccomp, int ndcomp) noexcept
Definition: AMReX_MultiFabUtil_1D_C.H:14
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_avgdown_edges(Box const &bx, Array4< Real > const &crse, Array4< Real const > const &fine, int ccomp, int fcomp, int ncomp, IntVect const &ratio, int) noexcept
Definition: AMReX_MultiFabUtil_1D_C.H:157
AMREX_GPU_HOST_DEVICE void amrex_compute_divergence(Box const &bx, Array4< Real > const &divu, Array4< Real const > const &u, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MultiFabUtil_1D_C.H:282
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_avg_eg_to_cc(int i, int, int, Array4< Real > const &cc, Array4< Real const > const &Ex, int cccomp) noexcept
Definition: AMReX_MultiFabUtil_1D_C.H:23
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_avgdown(Box const &bx, Array4< T > const &crse, Array4< T const > const &fine, int ccomp, int fcomp, int ncomp, IntVect const &ratio) noexcept
Definition: AMReX_MultiFabUtil_1D_C.H:195
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_avgdown_nodes(Box const &bx, Array4< T > const &crse, Array4< T const > const &fine, int ccomp, int fcomp, int ncomp, IntVect const &ratio) noexcept
Definition: AMReX_MultiFabUtil_1D_C.H:253
AMREX_GPU_HOST_DEVICE void amrex_compute_gradient(Box const &bx, Array4< Real > const &grad, Array4< Real const > const &u, GpuArray< Real, AMREX_SPACEDIM > const &dxinv) noexcept
Definition: AMReX_MultiFabUtil_1D_C.H:300
Definition: AMReX_Array4.H:61