1 #ifndef AMREX_INTERP_2D_C_H_
2 #define AMREX_INTERP_2D_C_H_
3 #include <AMReX_Config.H>
12 Array4<Real>
const&
fine,
const int fcomp,
const int ncomp,
13 Array4<Real const>
const&
crse,
const int ccomp,
19 for (
int n = 0; n < ncomp; ++n) {
20 for (
int j = lo.y; j <= hi.y; ++j) {
23 for (
int i = lo.x; i <= hi.x; ++i) {
25 fine(i,j,0,n+fcomp) =
crse(ic,jc,0,n+ccomp);
31 namespace interp_detail {
34 constexpr
int ixy = 2;
40 const int icomp,
const int ncomp,
IntVect const& ratio) noexcept
42 using namespace interp_detail;
47 const Real rx = Real(1.)/Real(ratio[0]);
48 const Real ry = Real(1.)/Real(ratio[1]);
50 for (
int n = 0; n < ncomp; ++n) {
51 for (
int j = lo.y; j <= hi.y; ++j) {
53 for (
int i = lo.x; i <= hi.x; ++i) {
54 T dx0 = u(i+1,j,0,n+icomp) - u(i,j,0,n+icomp);
55 T d0x = u(i,j+1,0,n+icomp) - u(i,j,0,n+icomp);
56 T dx1 = u(i+1,j+1,0,n+icomp) - u(i,j+1,0,n+icomp);
58 slope(i,j,0,n+ncomp*
ix ) = rx*dx0;
59 slope(i,j,0,n+ncomp*
iy ) = ry*d0x;
60 slope(i,j,0,n+ncomp*
ixy) = rx*ry*(dx1 - dx0);
69 Array4<T const>
const&
slope, Array4<T const>
const&
crse,
70 const int ccomp,
IntVect const& ratio) noexcept
72 using namespace interp_detail;
78 for (
int n = 0; n < ncomp; ++n) {
79 for (
int j = lo.y; j <= hi.y; ++j) {
81 const Real fy = j - jc*ratio[1];
83 for (
int i = lo.x; i <= hi.x; ++i) {
85 const Real fx = i - ic*ratio[0];
86 fine(i,j,0,n+fcomp) =
crse(ic,jc,0,n+ccomp)
98 int nc,
int nf,
int idir,
99 Array4<T const>
const&
crse,
100 Array4<T>
const&
fine,
101 Array4<int const>
const&
mask,
105 if (!
mask(ci, cj, 0, nc))
109 const int fi = ci*ratio[0];
110 const int fj = cj*ratio[1];
115 const Real neg =
crse(ci, cj-1, 0, nc);
116 const Real cen =
crse(ci, cj , 0, nc);
117 const Real pos =
crse(ci, cj+1, 0, nc);
119 fine(
fi, fj , 0, nf) = Real(0.125)*(8*cen + neg - pos);
120 fine(
fi, fj+1, 0, nf) = Real(0.125)*(8*cen + pos - neg);
126 const Real neg =
crse(ci-1, cj, 0, nc);
127 const Real cen =
crse(ci , cj, 0, nc);
128 const Real pos =
crse(ci+1, cj, 0, nc);
130 fine(
fi , fj, 0, nf) = Real(0.125)*(8*cen + neg - pos);
131 fine(
fi+1, fj, 0, nf) = Real(0.125)*(8*cen + pos - neg);
142 GpuArray<Array4<T>, AMREX_SPACEDIM>
const&
fine,
144 GpuArray<Real, AMREX_SPACEDIM>
const& cellSize) noexcept
146 const int fi = ci*ratio[0];
147 const int fj = cj*ratio[1];
150 const Real umm =
fine[0](
fi, fj, 0, nf);
151 const Real ump =
fine[0](
fi, fj+1, 0, nf);
152 const Real upm =
fine[0](
fi+2, fj, 0, nf);
153 const Real upp =
fine[0](
fi+2, fj+1, 0, nf);
155 const Real vmm =
fine[1](
fi, fj, 0, nf);
156 const Real vmp =
fine[1](
fi+1, fj, 0, nf);
157 const Real vpm =
fine[1](
fi, fj+2, 0, nf);
158 const Real vpp =
fine[1](
fi+1, fj+2, 0, nf);
160 const Real dxdy = cellSize[0]/cellSize[1];
161 const Real x_corr = Real(0.25)*dxdy * (vpp+vmm-vmp-vpm);
162 const Real y_corr = Real(0.25)/dxdy * (upp+umm-ump-upm);
165 fine[0](
fi+1,fj ,0,nf) = Real(0.5)*(umm+upm) + x_corr;
166 fine[0](
fi+1,fj+1,0,nf) = Real(0.5)*(ump+upp) + x_corr;
167 fine[1](
fi, fj+1,0,nf) = Real(0.5)*(vmm+vpm) + y_corr;
168 fine[1](
fi+1,fj+1,0,nf) = Real(0.5)*(vmp+vpp) + y_corr;
175 Array4<T const>
const&
crse,
IntVect const& ratio) noexcept
179 if (i-ii*ratio[0] == 0) {
182 Real
const w =
static_cast<Real
>(i-ii*ratio[0]) * (Real(1.)/Real(ratio[0]));
183 fine(i,j,0,n) = (Real(1.)-w) *
crse(ii,jj,0,n) + w *
crse(ii+1,jj,0,n);
194 if (j-jj*ratio[1] == 0) {
197 Real
const w =
static_cast<Real
>(j-jj*ratio[1]) * (Real(1.)/Real(ratio[1]));
198 fine(i,j,0,n) = (Real(1.)-w) *
crse(ii,jj,0,n) + w *
crse(ii,jj+1,0,n);
202 template <
typename T>
216 int ihi =
amrex::min(ratio[0]*ic+(ratio[0]-1), fnbxhi.
x);
218 int jhi =
amrex::min(ratio[1]*jc+(ratio[1]-1), fnbxhi.
y);
223 for (
int n = 1; n < nvar-1; ++n) {
225 bool redo_me =
false;
226 for (
int j = jlo; j <= jhi; ++j) {
227 for (
int i = ilo; i <= ihi; ++i) {
228 if ((fine_state(i,j,0,n) +
fine(i,j,0,n)) < 0.0) {
248 const Real* cs_dx = cs_geomdata.CellSize();
251 cvol = cs_dx[0] * cs_dx[1];
254 const Real* cs_problo = cs_geomdata.ProbLo();
255 Real rp = cs_problo[0] + (ic+0.5_rt)*cs_dx[0];
256 Real rm = cs_problo[0] + (ic-0.5_rt)*cs_dx[0];
257 cvol = (rp*rp - rm*rm) * cs_dx[1];
274 for (
int j = jlo; j <= jhi; ++j) {
275 for (
int i = ilo; i <= ihi; ++i) {
279 const Real* fn_dx = fn_geomdata.CellSize();
282 fvol = fn_dx[0] * fn_dx[1];
285 const Real* fn_problo = fn_geomdata.ProbLo();
286 Real rp = fn_problo[0] + (i+0.5_rt)*fn_dx[0];
287 Real rm = fn_problo[0] + (i-0.5_rt)*fn_dx[0];
288 fvol = (rp*rp - rm*rm) * fn_dx[1];
292 crseTot += fvol *
fine(i,j,0,n);
293 if (fine_state(i,j,0,n) <= 0.0) {
294 SumN += fvol * fine_state(i,j,0,n);
296 SumP += fvol * fine_state(i,j,0,n);
301 if ( (crseTot > 0) && (crseTot >
std::abs(SumN)) ) {
313 for (
int j = jlo; j <= jhi; ++j) {
314 for (
int i = ilo; i <= ihi; ++i) {
317 if (fine_state(i,j,0,n) < 0.0) {
318 fine(i,j,0,n) = -fine_state(i,j,0,n);
323 if (fine_state(i,j,0,n) > 0.0) {
324 Real alpha = (crseTot -
std::abs(SumN)) / SumP;
325 fine(i,j,0,n) = alpha * fine_state(i,j,0,n);
328 Real posVal = (crseTot -
std::abs(SumN)) / cvol;
329 fine(i,j,0,n) += posVal;
335 }
else if ( (crseTot > 0) && (crseTot <
std::abs(SumN)) ) {
347 for (
int j = jlo; j <= jhi; ++j) {
348 for (
int i = ilo; i <= ihi; ++i) {
350 Real alpha = crseTot /
std::abs(SumN);
351 if (fine_state(i,j,0,n) < 0.0) {
362 }
else if ( (crseTot < 0) && (
std::abs(crseTot) > SumP) ) {
374 for (
int j = jlo; j <= jhi; ++j) {
375 for (
int i = ilo; i <= ihi; ++i) {
378 Real negVal = (SumP + SumN + crseTot) / cvol;
379 fine(i,j,0,n) = negVal - fine_state(i,j,0,n);
384 }
else if ( (crseTot < 0) && (
std::abs(crseTot) < SumP) &&
385 ((SumP+SumN+crseTot) > 0.0) ) {
395 for (
int j = jlo; j <= jhi; ++j) {
396 for (
int i = ilo; i <= ihi; ++i) {
398 if (fine_state(i,j,0,n) < 0.0) {
400 fine(i,j,0,n) = -fine_state(i,j,0,n);
403 Real alpha = (crseTot + SumN) / SumP;
404 fine(i,j,0,n) = alpha * fine_state(i,j,0,n);
410 }
else if ( (crseTot < 0) && (
std::abs(crseTot) < SumP) &&
411 ((SumP+SumN+crseTot) < 0.0) ) {
423 for (
int j = jlo; j <= jhi; ++j) {
424 for (
int i = ilo; i <= ihi; ++i) {
426 if (fine_state(i,j,0,n) > 0.0) {
428 fine(i,j,0,n) = -fine_state(i,j,0,n);
431 Real alpha = (crseTot + SumP) / SumN;
432 fine(i,j,0,n) = alpha * fine_state(i,j,0,n);
443 for (
int j = jlo; j <= jhi; ++j) {
444 for (
int i = ilo; i <= ihi; ++i) {
446 for (
int n = 1; n < nvar-1; ++n) {
456 Array4<Real const>
const&
crse,
457 Array4<Real>
const&
fine) noexcept
462 constexpr Array1D<Real, -2, 2> cL = { -0.01171875_rt, 0.0859375_rt, 0.5_rt, -0.0859375_rt, 0.01171875_rt };
469 Array1D<Real, -2, 2> ctmp;
470 for (
int ii = -2; ii <= 2; ++ii) {
471 ctmp(ii) = 2.0_rt * ( cL(-2)*
crse(ic+ii,jc-2,0,n)
472 + cL(-1)*
crse(ic+ii,jc-1,0,n)
473 + cL( 0)*
crse(ic+ii,jc, 0,n)
474 + cL( 1)*
crse(ic+ii,jc+1,0,n)
475 + cL( 2)*
crse(ic+ii,jc+2,0,n) );
477 ctmp(ii) = 2.0_rt *
crse(ic+ii,jc,0,n) - ctmp(ii);
481 Real ftmp = 2.0_rt * ( cL(-2)*ctmp(-2)
487 ftmp = 2.0_rt * ctmp(0) - ftmp;
490 fine(i,j,0,n) = ftmp;
#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< int const > mask
Definition: AMReX_InterpFaceRegister.cpp:93
Array4< Real > slope
Definition: AMReX_InterpFaceRegister.cpp:91
Array4< Real const > crse
Definition: AMReX_InterpFaceRegister.cpp:92
@ cartesian
Definition: AMReX_CoordSys.H:27
static int fi(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:49
constexpr int iy
Definition: AMReX_Interp_2D_C.H:33
constexpr int ix
Definition: AMReX_Interp_2D_C.H:32
constexpr int ixy
Definition: AMReX_Interp_2D_C.H:34
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ccprotect_2d(int ic, int jc, int, int nvar, Box const &fine_bx, IntVect const &ratio, GeometryData cs_geomdata, GeometryData fn_geomdata, Array4< T > const &fine, Array4< T const > const &fine_state) noexcept
Definition: AMReX_Interp_2D_C.H:204
BoxND< AMREX_SPACEDIM > Box
Definition: AMReX_BaseFwd.H:27
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 void nodebilin_interp(Box const &bx, Array4< T > const &fine, const int fcomp, const int ncomp, Array4< T const > const &slope, Array4< T const > const &crse, const int ccomp, IntVect const &ratio) noexcept
Definition: AMReX_Interp_1D_C.H:52
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 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 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 facediv_face_interp(int, int, int, int, int, int, Array4< T const > const &, Array4< T > const &, Array4< const int > const &, IntVect const &) noexcept
Definition: AMReX_Interp_1D_C.H:75
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void facediv_int(int, int, int, int, GpuArray< Array4< T >, AMREX_SPACEDIM > const &, IntVect const &, GpuArray< Real, AMREX_SPACEDIM > const &) noexcept
Definition: AMReX_Interp_1D_C.H:87
IntVectND< AMREX_SPACEDIM > IntVect
Definition: AMReX_BaseFwd.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ccquartic_interp(int i, int, int, int n, Array4< Real const > const &crse, Array4< Real > const &fine) noexcept
Definition: AMReX_Interp_1D_C.H:110
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void face_linear_interp_x(int i, int, int, int n, Array4< T > const &fine, Array4< T const > const &crse, IntVect const &ratio) noexcept
Definition: AMReX_Interp_1D_C.H:97
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void pcinterp_interp(Box const &bx, Array4< Real > const &fine, const int fcomp, const int ncomp, Array4< Real const > const &crse, const int ccomp, IntVect const &ratio) noexcept
Definition: AMReX_Interp_1D_C.H:14
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void face_linear_interp_y(int i, int j, int, int n, Array4< T > const &fine, Array4< T const > const &crse, IntVect const &ratio) noexcept
Definition: AMReX_Interp_2D_C.H:189
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void nodebilin_slopes(Box const &bx, Array4< T > const &slope, Array4< T const > const &u, const int icomp, const int ncomp, IntVect const &ratio) noexcept
Definition: AMReX_Interp_1D_C.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Coarsen BoxND by given (positive) refinement ratio. NOTE: if type(dir) = CELL centered: lo <- lo/rati...
Definition: AMReX_Box.H:1304
Definition: AMReX_Array4.H:61
Definition: AMReX_Dim3.H:12
int x
Definition: AMReX_Dim3.H:12
int y
Definition: AMReX_Dim3.H:12
Definition: AMReX_Geometry.H:25