1 #ifndef AMREX_MULTIFAB_UTIL_2D_C_H_
2 #define AMREX_MULTIFAB_UTIL_2D_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,0,n+cccomp) = Real(0.25)*( nd(i,j ,0,n+ndcomp) + nd(i+1,j ,0,n+ndcomp)
19 + nd(i,j+1,0,n+ndcomp) + nd(i+1,j+1,0,n+ndcomp));
29 cc(i,j,0,0+cccomp) = Real(0.5) * ( Ex(i,j,0) + Ex(i,j+1,0) );
30 cc(i,j,0,1+cccomp) = Real(0.5) * ( Ey(i,j,0) + Ey(i+1,j,0) );
33 template <
typename CT,
typename FT>
41 cc(i,j,0,0+cccomp) = CT(0.5) * CT( fx(i,j,0) + fx(i+1,j,0) );
42 cc(i,j,0,1+cccomp) = CT(0.5) * CT( fy(i,j,0) + fy(i,j+1,0) );
50 if (use_harmonic_averaging)
52 if (xbx.contains(i,j,0)) {
53 if (cc(i-1,j,0,n) == Real(0.0) || cc(i,j,0,n) == Real(0.0)) {
54 fx(i,j,0,n) = Real(0.0);
56 fx(i,j,0,n) = Real(2.0) / (Real(1.0) / cc(i-1,j,0,n) + Real(1.0) / cc(i,j,0,n));
59 if (ybx.contains(i,j,0)) {
60 if (cc(i,j-1,0,n) == Real(0.0) || cc(i,j,0,n) == Real(0.0)) {
61 fy(i,j,0,n) = Real(0.0);
63 fy(i,j,0,n) = Real(2.0) / (Real(1.0) / cc(i,j-1,0,n) + Real(1.0) / cc(i,j,0,n));
67 if (xbx.contains(i,j,0)) {
68 fx(i,j,0,n) = Real(0.5)*(cc(i-1,j,0,n) + cc(i,j,0,n));
70 if (ybx.contains(i,j,0)) {
71 fy(i,j,0,n) = Real(0.5)*(cc(i,j-1,0,n) + cc(i,j,0,n));
79 Array4<T const>
const&
fine,
80 int ccomp,
int fcomp,
int ncomp,
83 const auto clo =
lbound(bx);
84 const auto chi =
ubound(bx);
85 const int facx = ratio[0];
86 const int facy = ratio[1];
91 T facInv = T(1.0) /
static_cast<T
>(facy);
92 for (
int n = 0; n < ncomp; ++n) {
93 for (
int j = clo.y; j <= chi.y; ++j) {
94 for (
int i = clo.x; i <= chi.x; ++i) {
98 for (
int jref = 0; jref < facy; ++jref) {
99 c +=
fine(ii,jj+jref,0,n+fcomp);
101 crse(i,j,0,n+ccomp) = c * facInv;
108 T facInv = T(1.0) /
static_cast<T
>(facx);
109 for (
int n = 0; n < ncomp; ++n) {
110 for (
int j = clo.y; j <= chi.y; ++j) {
111 for (
int i = clo.x; i <= chi.x; ++i) {
115 for (
int iref = 0; iref < facx; ++iref) {
116 c +=
fine(ii+iref,jj,0,n+fcomp);
118 crse(i,j,0,n+ccomp) = c * facInv;
127 template <
typename T>
130 Array4<T const>
const&
fine,
131 int ccomp,
int fcomp,
IntVect const& ratio,
int idir) noexcept
133 const int facx = ratio[0];
134 const int facy = ratio[1];
139 const T facInv = T(1.0) /
static_cast<T
>(facy);
140 const int ii = i*facx;
141 const int jj = j*facy;
143 for (
int jref = 0; jref < facy; ++jref) {
144 c +=
fine(ii,jj+jref,0,n+fcomp);
146 crse(i,j,0,n+ccomp) = c * facInv;
151 const T facInv = T(1.0) /
static_cast<T
>(facx);
152 const int ii = i*facx;
153 const int jj = j*facy;
155 for (
int iref = 0; iref < facx; ++iref) {
156 c +=
fine(ii+iref,jj,0,n+fcomp);
158 crse(i,j,0,n+ccomp) = c * facInv;
167 Array4<Real const>
const&
fine,
168 int ccomp,
int fcomp,
int ncomp,
171 const auto clo =
lbound(bx);
172 const auto chi =
ubound(bx);
173 const int facx = ratio[0];
174 const int facy = ratio[1];
179 Real facInv = Real(1.0) /
static_cast<Real
>(facx);
180 for (
int n = 0; n < ncomp; ++n) {
181 for (
int j = clo.y; j <= chi.y; ++j) {
182 for (
int i = clo.x; i <= chi.x; ++i) {
186 for (
int iref = 0; iref < facx; ++iref) {
187 c +=
fine(ii+iref,jj,0,n+fcomp);
189 crse(i,j,0,n+ccomp) = c * facInv;
196 Real facInv = Real(1.0) /
static_cast<Real
>(facy);
197 for (
int n = 0; n < ncomp; ++n) {
198 for (
int j = clo.y; j <= chi.y; ++j) {
199 for (
int i = clo.x; i <= chi.x; ++i) {
203 for (
int jref = 0; jref < facx; ++jref) {
204 c +=
fine(ii,jj+jref,0,n+fcomp);
206 crse(i,j,0,n+ccomp) = c * facInv;
217 Array4<Real const>
const&
fine,
218 int ccomp,
int fcomp,
IntVect const& ratio,
int idir) noexcept
220 const int facx = ratio[0];
221 const int facy = ratio[1];
226 const Real facInv = Real(1.0) /
static_cast<Real
>(facx);
227 const int ii = i*facx;
228 const int jj = j*facy;
230 for (
int iref = 0; iref < facx; ++iref) {
231 c +=
fine(ii+iref,jj,0,n+fcomp);
233 crse(i,j,0,n+ccomp) = c * facInv;
238 const Real facInv = Real(1.0) /
static_cast<Real
>(facy);
239 const int ii = i*facx;
240 const int jj = j*facy;
242 for (
int jref = 0; jref < facx; ++jref) {
243 c +=
fine(ii,jj+jref,0,n+fcomp);
245 crse(i,j,0,n+ccomp) = c * facInv;
252 template <
typename T>
255 Array4<T const>
const&
fine,
256 int ccomp,
int fcomp,
int ncomp,
259 const auto clo =
lbound(bx);
260 const auto chi =
ubound(bx);
261 const int facx = ratio[0];
262 const int facy = ratio[1];
263 const T volfrac = T(1.0)/T(facx*facy);
265 for (
int n = 0; n < ncomp; ++n) {
266 for (
int j = clo.y; j <= chi.y; ++j) {
267 for (
int i = clo.x; i <= chi.x; ++i) {
271 for (
int jref = 0; jref < facy; ++jref) {
272 for (
int iref = 0; iref < facx; ++iref) {
273 c +=
fine(ii+iref,jj+jref,0,n+fcomp);
275 crse(i,j,0,n+ccomp) = volfrac * c;
280 template <
typename T>
283 Array4<T const>
const&
fine,
284 int ccomp,
int fcomp,
IntVect const& ratio) noexcept
286 const int facx = ratio[0];
287 const int facy = ratio[1];
288 const T volfrac = T(1.0)/T(facx*facy);
289 const int ii = i*facx;
290 const int jj = j*facy;
292 for (
int jref = 0; jref < facy; ++jref) {
293 for (
int iref = 0; iref < facx; ++iref) {
294 c +=
fine(ii+iref,jj+jref,0,n+fcomp);
296 crse(i,j,0,n+ccomp) = volfrac * c;
299 template <
typename T>
302 Array4<T const>
const&
fine,
303 int ccomp,
int fcomp,
int ncomp,
306 const auto clo =
lbound(bx);
307 const auto chi =
ubound(bx);
308 const int facx = ratio[0];
309 const int facy = ratio[1];
311 for (
int n = 0; n < ncomp; ++n) {
312 for (
int j = clo.y; j <= chi.y; ++j) {
315 for (
int i = clo.x; i <= chi.x; ++i) {
316 crse(i,j,0,n+ccomp) =
fine(i*facx,jj,0,n+fcomp);
322 template <
typename T>
325 Array4<T const>
const&
fine,
326 int ccomp,
int fcomp,
IntVect const& ratio) noexcept
328 crse(i,j,0,n+ccomp) =
fine(i*ratio[0],j*ratio[1],0,n+fcomp);
335 int ccomp,
int fcomp,
IntVect const& ratio) noexcept
337 const int facx = ratio[0];
338 const int facy = ratio[1];
339 const int ii = i*facx;
340 const int jj = j*facy;
341 Real cd = 0.0, cv = 0.0;
342 for (
int jref = 0; jref < facy; ++jref) {
343 for (
int iref = 0; iref < facx; ++iref) {
344 cv += fv(ii+iref,jj+jref,0);
345 cd +=
fine(ii+iref,jj+jref,0,n+fcomp)*fv(ii+iref,jj+jref,0);
347 crse(i,j,0,n+ccomp) = cd/cv;
357 const auto lo =
lbound(bx);
358 const auto hi =
ubound(bx);
359 const Real dxi = dxinv[0];
360 const Real dyi = dxinv[1];
362 for (
int n = 0; n < divu.ncomp; ++n) {
363 for (
int j = lo.y; j <= hi.y; ++j) {
365 for (
int i = lo.x; i <= hi.x; ++i) {
366 divu(i,j,0,n) = dxi * (u(i+1,j,0,n)-u(i,j,0,n))
367 + dyi * (v(i,j+1,0,n)-v(i,j,0,n));
380 const auto lo =
lbound(bx);
381 const auto hi =
ubound(bx);
382 const Real dxi = dxinv[0];
383 const Real dyi = dxinv[1];
385 for (
int j = lo.y; j <= hi.y; ++j) {
387 for (
int i = lo.x; i <= hi.x; ++i) {
388 grad(i,j,0,0) = dxi * (u(i+1,j,0)-u(i,j,0));
389 grad(i,j,0,1) = dyi * (v(i,j+1,0)-v(i,j,0));
403 const auto lo =
lbound(bx);
404 const auto hi =
ubound(bx);
405 const Real dxi = dxinv[0];
406 const Real dyi = dxinv[1];
408 for (
int n = 0; n < diff.ncomp; ++n) {
409 for (
int j = lo.y; j <= hi.y; ++j) {
411 for (
int i = lo.x; i <= hi.x; ++i) {
412 diff(i,j,n) = Real(0.5)*dxi * (u_face(i+1,j,0,0)+u_face(i,j,0,0)) *
413 (s_on_x_face(i+1,j,0,n)-s_on_x_face(i,j,0,n))
414 + Real(0.5)*dyi * (v_face(i,j+1,0,0)+v_face(i,j,0,0)) *
415 (s_on_y_face(i,j+1,0,n)-s_on_y_face(i,j,0,n));
430 const auto lo =
lbound(bx);
431 const auto hi =
ubound(bx);
433 for (
int n = 0; n < divu.ncomp; ++n) {
434 for (
int j = lo.y; j <= hi.y; ++j) {
436 for (
int i = lo.x; i <= hi.x; ++i) {
437 divu(i,j,0,n) = (ax(i+1,j,0,0)*u(i+1,j,0,n)-ax(i,j,0,0)*u(i,j,0,n))
438 + (ay(i,j+1,0,0)*v(i,j+1,0,n)-ay(i,j,0,0)*v(i,j,0,n));
439 divu(i,j,0,n) /= vol(i,j,0,0);
454 const auto lo =
lbound(bx);
455 const auto hi =
ubound(bx);
457 for (
int j = lo.y; j <= hi.y; ++j) {
459 for (
int i = lo.x; i <= hi.x; ++i) {
460 grad(i,j,0,0) = (ax(i+1,j,0,0)*u(i+1,j,0)-ax(i,j,0,0)*u(i,j,0))/vol(i,j,0,0);
461 grad(i,j,0,1) = (ay(i,j+1,0,0)*v(i,j+1,0)-ay(i,j,0,0)*v(i,j,0))/vol(i,j,0,0);
#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
AMREX_GPU_HOST_DEVICE void amrex_compute_gradient_rz(Box const &bx, Array4< Real > const &grad, Array4< Real const > const &u, Array4< Real const > const &v, Array4< Real const > const &ax, Array4< Real const > const &ay, Array4< Real const > const &vol) noexcept
Definition: AMReX_MultiFabUtil_2D_C.H:447
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 void amrex_compute_divergence_rz(Box const &bx, Array4< Real > const &divu, Array4< Real const > const &u, Array4< Real const > const &v, Array4< Real const > const &ax, Array4< Real const > const &ay, Array4< Real const > const &vol) noexcept
Definition: AMReX_MultiFabUtil_2D_C.H:423
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