From 65e1558908e6fa7757cc3deaf2958e76839a2944 Mon Sep 17 00:00:00 2001 From: Ann Almgren Date: Mon, 10 Jul 2023 09:53:57 -0700 Subject: [PATCH 1/6] generalize interpolaters to not need or use extra values in a direction for which the refinement ratio is 1 --- Src/AmrCore/AMReX_Interpolater.cpp | 19 ++++- Src/AmrCore/AMReX_MFInterp_2D_C.H | 77 ++++++++++++------- Src/AmrCore/AMReX_MFInterp_3D_C.H | 114 +++++++++++++++++++---------- 3 files changed, 142 insertions(+), 68 deletions(-) diff --git a/Src/AmrCore/AMReX_Interpolater.cpp b/Src/AmrCore/AMReX_Interpolater.cpp index 5ad0f440eff..0af9babd89e 100644 --- a/Src/AmrCore/AMReX_Interpolater.cpp +++ b/Src/AmrCore/AMReX_Interpolater.cpp @@ -411,7 +411,11 @@ CellConservativeLinear::CoarseBox (const Box& fine, const IntVect& ratio) { Box crse = amrex::coarsen(fine,ratio); - crse.grow(1); + for (int dim = 0; dim < AMREX_SPACEDIM; dim++) { + if (ratio[dim] > 1) { + crse.grow(dim,1); + } + } return crse; } @@ -454,7 +458,12 @@ CellConservativeLinear::interp (const FArrayBox& crse, Array4 const& finearr = fine.array(); const Box& crse_region = CoarseBox(fine_region,ratio); - const Box& cslope_bx = amrex::grow(crse_region,-1); + Box cslope_bx(crse_region); + for (int dim = 0; dim < AMREX_SPACEDIM; dim++) { + if (ratio[dim] > 1) { + cslope_bx.grow(dim,-1); + } + } FArrayBox ccfab(cslope_bx, ncomp*AMREX_SPACEDIM); Array4 const& tmp = ccfab.array(); @@ -551,7 +560,11 @@ CellQuadratic::CoarseBox (const Box& fine, const IntVect& ratio) { Box crse = amrex::coarsen(fine,ratio); - crse.grow(1); + for (int dim = 0; dim < AMREX_SPACEDIM; dim++) { + if (ratio[dim] > 1) { + crse.grow(dim,1); + } + } return crse; } diff --git a/Src/AmrCore/AMReX_MFInterp_2D_C.H b/Src/AmrCore/AMReX_MFInterp_2D_C.H index 4c6fa85768c..9fc5371d0e8 100644 --- a/Src/AmrCore/AMReX_MFInterp_2D_C.H +++ b/Src/AmrCore/AMReX_MFInterp_2D_C.H @@ -13,24 +13,38 @@ void mf_cell_cons_lin_interp_limit_minmax_llslope (int i, int j, int, Array4= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sx = std::copysign(Real(1.),dcx)*amrex::min(sx,std::abs(dcx)); - slope(i,j,0,ns ) = dcx; + if (ratio[0] > 1) { + dcx = mf_compute_slopes_x(i, j, 0, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i+1,j,0,nu) - u(i ,j,0,nu)); + Real db = Real(2.0) * (u(i ,j,0,nu) - u(i-1,j,0,nu)); + sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sx = std::copysign(Real(1.),dcx)*amrex::min(sx,std::abs(dcx)); + slope(i,j,0,ns ) = dcx; + } else { + slope(i,j,0,ns ) = Real(0.0); + } // y-direction - Real dcy = mf_compute_slopes_y(i, j, 0, u, nu, domain, bc[ns]); - df = Real(2.0) * (u(i,j+1,0,nu) - u(i,j ,0,nu)); - db = Real(2.0) * (u(i,j ,0,nu) - u(i,j-1,0,nu)); - Real sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sy = std::copysign(Real(1.),dcy)*amrex::min(sy,std::abs(dcy)); - slope(i,j,0,ns+ ncomp) = dcy; + if (ratio[1] > 1) { + dcy = mf_compute_slopes_y(i, j, 0, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i,j+1,0,nu) - u(i,j ,0,nu)); + Real db = Real(2.0) * (u(i,j ,0,nu) - u(i,j-1,0,nu)); + sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sy = std::copysign(Real(1.),dcy)*amrex::min(sy,std::abs(dcy)); + slope(i,j,0,ns+ ncomp) = dcy; + } else { + slope(i,j,0,ns+ ncomp) = Real(0.0); + } // adjust limited slopes to prevent new min/max for this component Real alpha = Real(1.0); @@ -39,8 +53,10 @@ void mf_cell_cons_lin_interp_limit_minmax_llslope (int i, int j, int, Array4 1 ? 1 : 0; + int jlim = ratio[1] > 1 ? 1 : 0; + for (int joff = -jlim; joff <= jlim; ++joff) { + for (int ioff = -ilim; ioff <= ilim; ++ioff) { umin = amrex::min(umin, u(i+ioff,j+joff,0,nu)); umax = amrex::max(umax, u(i+ioff,j+joff,0,nu)); }} @@ -118,19 +134,26 @@ void mf_cell_cons_lin_interp_mcslope (int i, int j, int /*k*/, int ns, Array4= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc)); + if (ratio[0] > 1) { + Real dc = mf_compute_slopes_x(i, j, 0, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i+1,j,0,nu) - u(i ,j,0,nu)); + Real db = Real(2.0) * (u(i ,j,0,nu) - u(i-1,j,0,nu)); + sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc)); + } // y-direction - dc = mf_compute_slopes_y(i, j, 0, u, nu, domain, bc[ns]); - df = Real(2.0) * (u(i,j+1,0,nu) - u(i,j ,0,nu)); - db = Real(2.0) * (u(i,j ,0,nu) - u(i,j-1,0,nu)); - Real sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc)); + if (ratio[1] > 1) { + Real dc = mf_compute_slopes_y(i, j, 0, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i,j+1,0,nu) - u(i,j ,0,nu)); + Real db = Real(2.0) * (u(i,j ,0,nu) - u(i,j-1,0,nu)); + sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc)); + } Real alpha = Real(1.0); if (sx != Real(0.0) || sy != Real(0.0)) { @@ -138,8 +161,10 @@ void mf_cell_cons_lin_interp_mcslope (int i, int j, int /*k*/, int ns, Array4 1 ? 1 : 0; + int jlim = ratio[1] > 1 ? 1 : 0; + for (int joff = -jlim; joff <= jlim; ++joff) { + for (int ioff = -ilim; ioff <= ilim; ++ioff) { umin = amrex::min(umin, u(i+ioff,j+joff,0,nu)); umax = amrex::max(umax, u(i+ioff,j+joff,0,nu)); }} diff --git a/Src/AmrCore/AMReX_MFInterp_3D_C.H b/Src/AmrCore/AMReX_MFInterp_3D_C.H index db18e1adb6e..3d599888972 100644 --- a/Src/AmrCore/AMReX_MFInterp_3D_C.H +++ b/Src/AmrCore/AMReX_MFInterp_3D_C.H @@ -12,32 +12,52 @@ void mf_cell_cons_lin_interp_limit_minmax_llslope (int i, int j, int k, Array4= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sx = std::copysign(Real(1.),dcx)*amrex::min(sx,std::abs(dcx)); - slope(i,j,k,ns ) = dcx; // unlimited slope + if (ratio[0] > 1) { + dcx = mf_compute_slopes_x(i, j, k, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i+1,j,k,nu) - u(i ,j,k,nu)); + Real db = Real(2.0) * (u(i ,j,k,nu) - u(i-1,j,k,nu)); + sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sx = std::copysign(Real(1.),dcx)*amrex::min(sx,std::abs(dcx)); + slope(i,j,k,ns ) = dcx; // unlimited slope + } else { + slope(i,j,k,ns ) = Real(0.0); + } // y-direction - Real dcy = mf_compute_slopes_y(i, j, k, u, nu, domain, bc[ns]); - df = Real(2.0) * (u(i,j+1,k,nu) - u(i,j ,k,nu)); - db = Real(2.0) * (u(i,j ,k,nu) - u(i,j-1,k,nu)); - Real sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sy = std::copysign(Real(1.),dcy)*amrex::min(sy,std::abs(dcy)); - slope(i,j,k,ns+ ncomp) = dcy; // unlimited slope + if (ratio[1] > 1) { + dcy = mf_compute_slopes_y(i, j, k, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i,j+1,k,nu) - u(i,j ,k,nu)); + Real db = Real(2.0) * (u(i,j ,k,nu) - u(i,j-1,k,nu)); + sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sy = std::copysign(Real(1.),dcy)*amrex::min(sy,std::abs(dcy)); + slope(i,j,k,ns+ ncomp) = dcy; // unlimited slope + } else { + slope(i,j,k,ns+ ncomp) = Real(0.0); + } // z-direction - Real dcz = mf_compute_slopes_z(i, j, k, u, nu, domain, bc[ns]); - df = Real(2.0) * (u(i,j,k+1,nu) - u(i,j,k ,nu)); - db = Real(2.0) * (u(i,j,k ,nu) - u(i,j,k-1,nu)); - Real sz = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sz = std::copysign(Real(1.),dcz)*amrex::min(sz,std::abs(dcz)); - slope(i,j,k,ns+2*ncomp) = dcz; // unlimited slope + if (ratio[2] > 1) { + dcz = mf_compute_slopes_z(i, j, k, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i,j,k+1,nu) - u(i,j,k ,nu)); + Real db = Real(2.0) * (u(i,j,k ,nu) - u(i,j,k-1,nu)); + sz = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sz = std::copysign(Real(1.),dcz)*amrex::min(sz,std::abs(dcz)); + slope(i,j,k,ns+2*ncomp) = dcz; // unlimited slope + } else { + slope(i,j,k,ns+2*ncomp) = Real(0.0); + } // adjust limited slopes to prevent new min/max for this component Real alpha = 1.0; @@ -47,9 +67,12 @@ void mf_cell_cons_lin_interp_limit_minmax_llslope (int i, int j, int k, Array4 1 ? 1 : 0; + int jlim = ratio[1] > 1 ? 1 : 0; + int klim = ratio[2] > 1 ? 1 : 0; + for (int koff = -klim; koff <= klim; ++koff) { + for (int joff = -jlim; joff <= jlim; ++joff) { + for (int ioff = -ilim; ioff <= ilim; ++ioff) { umin = amrex::min(umin, u(i+ioff,j+joff,k+koff,nu)); umax = amrex::max(umax, u(i+ioff,j+joff,k+koff,nu)); }}} @@ -145,26 +168,36 @@ void mf_cell_cons_lin_interp_mcslope (int i, int j, int k, int ns, Array4 { int nu = ns + scomp; + Real sx = Real(0.); + Real sy = Real(0.); + Real sz = Real(0.); + // x-direction - Real dc = mf_compute_slopes_x(i, j, k, u, nu, domain, bc[ns]); - Real df = Real(2.0) * (u(i+1,j,k,nu) - u(i ,j,k,nu)); - Real db = Real(2.0) * (u(i ,j,k,nu) - u(i-1,j,k,nu)); - Real sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc)); + if (ratio[0] > 1) { + Real dc = mf_compute_slopes_x(i, j, k, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i+1,j,k,nu) - u(i ,j,k,nu)); + Real db = Real(2.0) * (u(i ,j,k,nu) - u(i-1,j,k,nu)); + sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc)); + } // y-direction - dc = mf_compute_slopes_y(i, j, k, u, nu, domain, bc[ns]); - df = Real(2.0) * (u(i,j+1,k,nu) - u(i,j ,k,nu)); - db = Real(2.0) * (u(i,j ,k,nu) - u(i,j-1,k,nu)); - Real sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc)); + if (ratio[1] > 1) { + Real dc = mf_compute_slopes_y(i, j, k, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i,j+1,k,nu) - u(i,j ,k,nu)); + Real db = Real(2.0) * (u(i,j ,k,nu) - u(i,j-1,k,nu)); + sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc)); + } // z-direction - dc = mf_compute_slopes_z(i, j, k, u, nu, domain, bc[ns]); - df = Real(2.0) * (u(i,j,k+1,nu) - u(i,j,k ,nu)); - db = Real(2.0) * (u(i,j,k ,nu) - u(i,j,k-1,nu)); - Real sz = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sz = std::copysign(Real(1.),dc)*amrex::min(sz,std::abs(dc)); + if (ratio[2] > 1) { + Real dc = mf_compute_slopes_z(i, j, k, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i,j,k+1,nu) - u(i,j,k ,nu)); + Real db = Real(2.0) * (u(i,j,k ,nu) - u(i,j,k-1,nu)); + sz = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sz = std::copysign(Real(1.),dc)*amrex::min(sz,std::abs(dc)); + } Real alpha = 1.0; if (sx != Real(0.0) || sy != Real(0.0) || sz != Real(0.0)) { @@ -173,9 +206,12 @@ void mf_cell_cons_lin_interp_mcslope (int i, int j, int k, int ns, Array4 + std::abs(sz) * Real(ratio[2]-1)/Real(2*ratio[2]); Real umax = u(i,j,k,nu); Real umin = u(i,j,k,nu); - for (int koff = -1; koff <= 1; ++koff) { - for (int joff = -1; joff <= 1; ++joff) { - for (int ioff = -1; ioff <= 1; ++ioff) { + int ilim = ratio[0] > 1 ? 1 : 0; + int jlim = ratio[1] > 1 ? 1 : 0; + int klim = ratio[2] > 1 ? 1 : 0; + for (int koff = -klim; koff <= klim; ++koff) { + for (int joff = -jlim; joff <= jlim; ++joff) { + for (int ioff = -ilim; ioff <= ilim; ++ioff) { umin = amrex::min(umin, u(i+ioff,j+joff,k+koff,nu)); umax = amrex::max(umax, u(i+ioff,j+joff,k+koff,nu)); }}} From 6396ac13fb7e6544f00802f8851d2b8fb53efb0f Mon Sep 17 00:00:00 2001 From: Ann Almgren Date: Tue, 11 Jul 2023 17:24:19 -0700 Subject: [PATCH 2/6] more protection for when ratio == 1 in some direction --- Src/AmrCore/AMReX_Interpolater.cpp | 66 +++++++++++++++++------- Src/AmrCore/AMReX_MFInterp_2D_C.H | 75 +++++++++++++++++----------- Src/AmrCore/AMReX_MFInterp_3D_C.H | 64 ++++++++++++++---------- Src/AmrCore/AMReX_MFInterpolater.cpp | 28 +++++++---- 4 files changed, 152 insertions(+), 81 deletions(-) diff --git a/Src/AmrCore/AMReX_Interpolater.cpp b/Src/AmrCore/AMReX_Interpolater.cpp index 0af9babd89e..06c8fb399e6 100644 --- a/Src/AmrCore/AMReX_Interpolater.cpp +++ b/Src/AmrCore/AMReX_Interpolater.cpp @@ -14,7 +14,10 @@ namespace amrex { * PCInterp, NodeBilinear, FaceLinear, CellConservativeLinear, and * CellBilinear are supported for all dimensions on cpu and gpu. * - * CellConservativeProtected only works in 2D and 3D on cpu and gpu. + * FaceLinear assumes that ratio > 1 in all directions + * + * CellConservativeProtected only works in 2D and 3D on cpu and gpu + * and assumes that ratio > 1 in all directions * * CellQuadratic only works in 2D and 3D on cpu and gpu. * @@ -167,6 +170,14 @@ FaceLinear::interp_face (const FArrayBox& crse, { BL_PROFILE("FaceLinear::interp_face()"); + AMREX_ALWAYS_ASSERT(ratio[0] > 1); +#if (AMREX_SPACEDIM >= 2) + AMREX_ALWAYS_ASSERT(ratio[1] > 1); +#endif +#if (AMREX_SPACEDIM == 3) + AMREX_ALWAYS_ASSERT(ratio[2] > 1); +#endif + AMREX_ASSERT(AMREX_D_TERM(fine_region.type(0),+fine_region.type(1),+fine_region.type(2)) == 1); Array4 const& fine_arr = fine.array(fine_comp); @@ -257,6 +268,14 @@ void FaceLinear::interp_arr (Array const& crse, { BL_PROFILE("FaceLinear::interp_arr()"); + AMREX_ALWAYS_ASSERT(ratio[0] > 1); +#if (AMREX_SPACEDIM >= 2) + AMREX_ALWAYS_ASSERT(ratio[1] > 1); +#endif +#if (AMREX_SPACEDIM == 3) + AMREX_ALWAYS_ASSERT(ratio[2] > 1); +#endif + Array types; for (int d=0; d 1 && ((lo[i]-clo[i]*ratio[i])*2 < ratio[i]) ) { crse.growLo(i,1); } - if ((hi[i]-chi[i]*ratio[i])*2 >= ratio[i]) { + if ( ratio[i] > 1 && ((hi[i]-chi[i]*ratio[i])*2 >= ratio[i]) ) { crse.growHi(i,1); } } @@ -444,7 +463,7 @@ CellConservativeLinear::interp (const FArrayBox& crse, RunOn runon) { BL_PROFILE("CellConservativeLinear::interp()"); - BL_ASSERT(bcr.size() >= ncomp); + AMREX_ASSERT(bcr.size() >= ncomp); AMREX_ASSERT(fine.box().contains(fine_region)); @@ -487,7 +506,7 @@ CellConservativeLinear::interp (const FArrayBox& crse, AMREX_HOST_DEVICE_PARALLEL_FOR_3D_FLAG(runon, cslope_bx, i, j, k, { mf_cell_cons_lin_interp_llslope(i,j,k, tmp, crsearr, crse_comp, ncomp, - cdomain, bcrp); + cdomain, ratio, bcrp); }); } else { AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(runon, cslope_bx, ncomp, i, j, k, n, @@ -513,7 +532,7 @@ CellConservativeLinear::interp (const FArrayBox& crse, AMREX_HOST_DEVICE_PARALLEL_FOR_3D_FLAG(runon, cslope_bx, i, j, k, { mf_cell_cons_lin_interp_llslope(i,j,k, tmp, crsearr, crse_comp, ncomp, - cdomain, bcrp); + cdomain, ratio, bcrp); }); } else { AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(runon, cslope_bx, ncomp, i, j, k, n, @@ -537,7 +556,7 @@ CellConservativeLinear::interp (const FArrayBox& crse, AMREX_HOST_DEVICE_PARALLEL_FOR_3D_FLAG(runon, cslope_bx, i, j, k, { mf_cell_cons_lin_interp_llslope(i,j,k, tmp, crsearr, crse_comp, ncomp, - cdomain, bcrp); + cdomain, ratio, bcrp); }); } else { AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(runon, cslope_bx, ncomp, i, j, k, n, @@ -599,7 +618,7 @@ CellQuadratic::interp (const FArrayBox& crse, #else BL_PROFILE("CellQuadratic::interp()"); - BL_ASSERT(bcr.size() >= ncomp); + AMREX_ASSERT(bcr.size() >= ncomp); // // Make box which is intersection of fine_region and domain of fine. @@ -608,7 +627,7 @@ CellQuadratic::interp (const FArrayBox& crse, // Make Box for slopes. Box cslope_bx = amrex::coarsen(target_fine_region,ratio); - BL_ASSERT(crse.box().contains(cslope_bx)); + AMREX_ASSERT(crse.box().contains(cslope_bx)); // Are we running on GPU? bool run_on_gpu = (runon == RunOn::Gpu && Gpu::inLaunchRegion()); @@ -752,6 +771,14 @@ CellConservativeProtected::protect (const FArrayBox& /*crse*/, Vector& /*bcr*/, RunOn runon) { + AMREX_ALWAYS_ASSERT(ratio[0] > 1); +#if (AMREX_SPACEDIM >= 2) + AMREX_ALWAYS_ASSERT(ratio[1] > 1); +#endif +#if (AMREX_SPACEDIM == 3) + AMREX_ALWAYS_ASSERT(ratio[2] > 1); +#endif + #if (AMREX_SPACEDIM == 1) amrex::ignore_unused(fine,fine_state, ncomp,fine_region,ratio, @@ -851,12 +878,12 @@ CellConservativeQuartic::interp (const FArrayBox& crse, RunOn runon) { BL_PROFILE("CellConservativeQuartic::interp()"); - BL_ASSERT(ratio[0] == 2); + AMREX_ASSERT(ratio[0] == 2); #if (AMREX_SPACEDIM >= 2) - BL_ASSERT(ratio[0] == ratio[1]); + AMREX_ASSERT(ratio[0] == ratio[1]); #endif #if (AMREX_SPACEDIM == 3) - BL_ASSERT(ratio[1] == ratio[2]); + AMREX_ASSERT(ratio[1] == ratio[2]); #endif amrex::ignore_unused(ratio); @@ -880,16 +907,21 @@ Box FaceDivFree::CoarseBox (const Box& fine, int ratio) { - Box b = amrex::coarsen(fine,ratio).grow(1); - return b; + Box crse = amrex::coarsen(fine,ratio).grow(1); + return crse; } Box FaceDivFree::CoarseBox (const Box& fine, const IntVect& ratio) { - Box b = amrex::coarsen(fine,ratio).grow(1); - return b; + Box crse = amrex::coarsen(fine,ratio); + for (int dim = 0; dim < AMREX_SPACEDIM; dim++) { + if (ratio[dim] > 1) { + crse.grow(dim,1); + } + } + return crse; } void @@ -907,7 +939,7 @@ FaceDivFree::interp (const FArrayBox& /*crse*/, int /*actual_state*/, RunOn /*runon*/) { - amrex::Abort("FaceDivFree does not work on a single MultiFab. Call 'interp_arr' instead."); + amrex::Abort("FaceDivFree does not work on a single FArrayBox. Call 'interp_arr' instead."); } void diff --git a/Src/AmrCore/AMReX_MFInterp_2D_C.H b/Src/AmrCore/AMReX_MFInterp_2D_C.H index 9fc5371d0e8..c51c37e4419 100644 --- a/Src/AmrCore/AMReX_MFInterp_2D_C.H +++ b/Src/AmrCore/AMReX_MFInterp_2D_C.H @@ -89,7 +89,7 @@ void mf_cell_cons_lin_interp_limit_minmax_llslope (int i, int j, int, Array4 const& slope, Array4 const& u, int scomp, int ncomp, - Box const& domain, BCRec const* bc) noexcept + Box const& domain, IntVect const& ratio, BCRec const* bc) noexcept { Real sfx = Real(1.0); Real sfy = Real(1.0); @@ -98,26 +98,34 @@ void mf_cell_cons_lin_interp_llslope (int i, int j, int, Array4 const& slo int nu = ns + scomp; // x-direction - Real dc = mf_compute_slopes_x(i, j, 0, u, nu, domain, bc[ns]); - Real df = Real(2.0) * (u(i+1,j,0,nu) - u(i ,j,0,nu)); - Real db = Real(2.0) * (u(i ,j,0,nu) - u(i-1,j,0,nu)); - Real sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc)); - if (dc != Real(0.0)) { - sfx = amrex::min(sfx, sx / dc); + if (ratio[0] > 1) { + Real dc = mf_compute_slopes_x(i, j, 0, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i+1,j,0,nu) - u(i ,j,0,nu)); + Real db = Real(2.0) * (u(i ,j,0,nu) - u(i-1,j,0,nu)); + Real sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc)); + if (dc != Real(0.0)) { + sfx = amrex::min(sfx, sx / dc); + } + slope(i,j,0,ns ) = dc; + } else { + slope(i,j,0,ns ) = Real(0.0); } - slope(i,j,0,ns ) = dc; // y-direction - dc = mf_compute_slopes_y(i, j, 0, u, nu, domain, bc[ns]); - df = Real(2.0) * (u(i,j+1,0,nu) - u(i,j ,0,nu)); - db = Real(2.0) * (u(i,j ,0,nu) - u(i,j-1,0,nu)); - Real sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc)); - if (dc != Real(0.0)) { - sfy = amrex::min(sfy, sy / dc); + if (ratio[1] > 1) { + Real dc = mf_compute_slopes_y(i, j, 0, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i,j+1,0,nu) - u(i,j ,0,nu)); + Real db = Real(2.0) * (u(i,j ,0,nu) - u(i,j-1,0,nu)); + Real sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc)); + if (dc != Real(0.0)) { + sfy = amrex::min(sfy, sy / dc); + } + slope(i,j,0,ns+ ncomp) = dc; + } else { + slope(i,j,0,ns+ ncomp) = Real(0.0); } - slope(i,j,0,ns+ ncomp) = dc; } for (int ns = 0; ns < ncomp; ++ns) { @@ -202,19 +210,26 @@ void mf_cell_cons_lin_interp_mcslope_rz (int i, int j, int ns, Array4 cons { int nu = ns + scomp; + Real sx = Real(0.0); + Real sy = Real(0.0); + // x-direction - Real dc = mf_compute_slopes_x(i, j, 0, u, nu, domain, bc[ns]); - Real df = Real(2.0) * (u(i+1,j,0,nu) - u(i ,j,0,nu)); - Real db = Real(2.0) * (u(i ,j,0,nu) - u(i-1,j,0,nu)); - Real sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc)); + if (ratio[0] > 1) { + Real dc = mf_compute_slopes_x(i, j, 0, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i+1,j,0,nu) - u(i ,j,0,nu)); + Real db = Real(2.0) * (u(i ,j,0,nu) - u(i-1,j,0,nu)); + sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc)); + } // y-direction - dc = mf_compute_slopes_y(i, j, 0, u, nu, domain, bc[ns]); - df = Real(2.0) * (u(i,j+1,0,nu) - u(i,j ,0,nu)); - db = Real(2.0) * (u(i,j ,0,nu) - u(i,j-1,0,nu)); - Real sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc)); + if (ratio[1] > 1) { + Real dc = mf_compute_slopes_y(i, j, 0, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i,j+1,0,nu) - u(i,j ,0,nu)); + Real db = Real(2.0) * (u(i,j ,0,nu) - u(i,j-1,0,nu)); + sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc)); + } Real alpha = Real(1.0); if (sx != Real(0.0) || sy != Real(0.0)) { @@ -239,8 +254,10 @@ void mf_cell_cons_lin_interp_mcslope_rz (int i, int j, int ns, Array4 cons + std::abs(sy) * Real(ratio[1]-1)/Real(2*ratio[1]); Real umax = u(i,j,0,nu); Real umin = u(i,j,0,nu); - for (int joff = -1; joff <= 1; ++joff) { - for (int ioff = -1; ioff <= 1; ++ioff) { + int ilim = ratio[0] > 1 ? 1 : 0; + int jlim = ratio[1] > 1 ? 1 : 0; + for (int joff = -jlim; joff <= jlim; ++joff) { + for (int ioff = -ilim; ioff <= ilim; ++ioff) { umin = amrex::min(umin, u(i+ioff,j+joff,0,nu)); umax = amrex::max(umax, u(i+ioff,j+joff,0,nu)); }} diff --git a/Src/AmrCore/AMReX_MFInterp_3D_C.H b/Src/AmrCore/AMReX_MFInterp_3D_C.H index 3d599888972..4d2e92ae3ed 100644 --- a/Src/AmrCore/AMReX_MFInterp_3D_C.H +++ b/Src/AmrCore/AMReX_MFInterp_3D_C.H @@ -110,7 +110,7 @@ void mf_cell_cons_lin_interp_limit_minmax_llslope (int i, int j, int k, Array4 const& slope, Array4 const& u, int scomp, int ncomp, - Box const& domain, BCRec const* bc) noexcept + Box const& domain, IntVect const& ratio, BCRec const* bc) noexcept { Real sfx = Real(1.0); Real sfy = Real(1.0); @@ -120,37 +120,51 @@ void mf_cell_cons_lin_interp_llslope (int i, int j, int k, Array4 const& s int nu = ns + scomp; // x-direction - Real dc = mf_compute_slopes_x(i, j, k, u, nu, domain, bc[ns]); - Real df = Real(2.0) * (u(i+1,j,k,nu) - u(i ,j,k,nu)); - Real db = Real(2.0) * (u(i ,j,k,nu) - u(i-1,j,k,nu)); - Real sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc)); - if (dc != Real(0.0)) { - sfx = amrex::min(sfx, sx / dc); + if (ratio[0] > 1) { + Real dc = mf_compute_slopes_x(i, j, k, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i+1,j,k,nu) - u(i ,j,k,nu)); + Real db = Real(2.0) * (u(i ,j,k,nu) - u(i-1,j,k,nu)); + Real sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc)); + if (dc != Real(0.0)) { + sfx = amrex::min(sfx, sx / dc); + } + slope(i,j,k,ns ) = dc; + } else { + slope(i,j,k,ns ) = Real(0.0); } - slope(i,j,k,ns ) = dc; // y-direction - dc = mf_compute_slopes_y(i, j, k, u, nu, domain, bc[ns]); - df = Real(2.0) * (u(i,j+1,k,nu) - u(i,j ,k,nu)); - db = Real(2.0) * (u(i,j ,k,nu) - u(i,j-1,k,nu)); - Real sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc)); - if (dc != Real(0.0)) { - sfy = amrex::min(sfy, sy / dc); + if (ratio[1] > 1) { + Real dc = mf_compute_slopes_y(i, j, k, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i,j+1,k,nu) - u(i,j ,k,nu)); + Real db = Real(2.0) * (u(i,j ,k,nu) - u(i,j-1,k,nu)); + Real sy = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc)); + if (dc != Real(0.0)) { + sfy = amrex::min(sfy, sy / dc); + } + slope(i,j,k,ns+ ncomp) = dc; + } else { + slope(i,j,k,ns+ ncomp) = Real(0.0); } - slope(i,j,k,ns+ ncomp) = dc; + // z-direction - dc = mf_compute_slopes_z(i, j, k, u, nu, domain, bc[ns]); - df = Real(2.0) * (u(i,j,k+1,nu) - u(i,j,k ,nu)); - db = Real(2.0) * (u(i,j,k ,nu) - u(i,j,k-1,nu)); - Real sz = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); - sz = std::copysign(Real(1.),dc)*amrex::min(sz,std::abs(dc)); - if (dc != Real(0.0)) { - sfz = amrex::min(sfz, sz / dc); + if (ratio[2] > 1) { + Real dc = mf_compute_slopes_z(i, j, k, u, nu, domain, bc[ns]); + Real df = Real(2.0) * (u(i,j,k+1,nu) - u(i,j,k ,nu)); + Real db = Real(2.0) * (u(i,j,k ,nu) - u(i,j,k-1,nu)); + Real sz = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.); + sz = std::copysign(Real(1.),dc)*amrex::min(sz,std::abs(dc)); + if (dc != Real(0.0)) { + sfz = amrex::min(sfz, sz / dc); + } + slope(i,j,k,ns+2*ncomp) = dc; + } else { + slope(i,j,k,ns+2*ncomp) = Real(0.0); } - slope(i,j,k,ns+2*ncomp) = dc; + } for (int ns = 0; ns < ncomp; ++ns) { diff --git a/Src/AmrCore/AMReX_MFInterpolater.cpp b/Src/AmrCore/AMReX_MFInterpolater.cpp index 12025c0747a..a8789c815b0 100644 --- a/Src/AmrCore/AMReX_MFInterpolater.cpp +++ b/Src/AmrCore/AMReX_MFInterpolater.cpp @@ -72,7 +72,11 @@ Box MFCellConsLinInterp::CoarseBox (const Box& fine, const IntVect& ratio) { Box crse = amrex::coarsen(fine,ratio); - crse.grow(1); + for (int dim = 0; dim < AMREX_SPACEDIM; dim++) { + if (ratio[dim] > 1) { + crse.grow(dim,1); + } + } return crse; } @@ -116,7 +120,7 @@ MFCellConsLinInterp::interp (MultiFab const& crsemf, int ccomp, MultiFab& finemf [=] AMREX_GPU_DEVICE (int box_no, int i, int, int) noexcept { mf_cell_cons_lin_interp_llslope(i,0,0, tmp[box_no], crse[box_no], ccomp, nc, - cdomain, pbc); + cdomain, ratio, pbc); }); } else { ParallelFor(crsemf, IntVect(-1), nc, @@ -145,7 +149,7 @@ MFCellConsLinInterp::interp (MultiFab const& crsemf, int ccomp, MultiFab& finemf [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int) noexcept { mf_cell_cons_lin_interp_llslope(i,j,0, tmp[box_no], crse[box_no], ccomp, nc, - cdomain, pbc); + cdomain, ratio, pbc); }); } else { ParallelFor(crsemf, IntVect(-1), nc, @@ -172,7 +176,7 @@ MFCellConsLinInterp::interp (MultiFab const& crsemf, int ccomp, MultiFab& finemf [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) noexcept { mf_cell_cons_lin_interp_llslope(i,j,k, tmp[box_no], crse[box_no], ccomp, nc, - cdomain, pbc); + cdomain, ratio, pbc); }); } else { ParallelFor(crsemf, IntVect(-1), nc, @@ -224,7 +228,7 @@ MFCellConsLinInterp::interp (MultiFab const& crsemf, int ccomp, MultiFab& finemf [&] (int i, int, int) noexcept { mf_cell_cons_lin_interp_llslope(i,0,0, tmp, crse, ccomp, nc, - cdomain, pbc); + cdomain, ratio, pbc); }); } else { amrex::LoopConcurrentOnCpu(cbox, nc, @@ -251,7 +255,7 @@ MFCellConsLinInterp::interp (MultiFab const& crsemf, int ccomp, MultiFab& finemf [&] (int i, int j, int) noexcept { mf_cell_cons_lin_interp_llslope(i,j,0, tmp, crse, ccomp, nc, - cdomain, pbc); + cdomain, ratio, pbc); }); } else { amrex::LoopConcurrentOnCpu(cbox, nc, @@ -276,7 +280,7 @@ MFCellConsLinInterp::interp (MultiFab const& crsemf, int ccomp, MultiFab& finemf [&] (int i, int j, int k) noexcept { mf_cell_cons_lin_interp_llslope(i,j,k, tmp, crse, ccomp, nc, - cdomain, pbc); + cdomain, ratio, pbc); }); } else { amrex::LoopConcurrentOnCpu(cbox, nc, @@ -304,7 +308,11 @@ Box MFCellConsLinMinmaxLimitInterp::CoarseBox (const Box& fine, const IntVect& ratio) { Box crse = amrex::coarsen(fine,ratio); - crse.grow(1); + for (int dim = 0; dim < AMREX_SPACEDIM; dim++) { + if (ratio[dim] > 1) { + crse.grow(dim,1); + } + } return crse; } @@ -406,10 +414,10 @@ MFCellBilinear::CoarseBox (const Box& fine, const IntVect& ratio) const int* chi = crse.hiVect(); for (int i = 0; i < AMREX_SPACEDIM; i++) { - if ((lo[i]-clo[i]*ratio[i])*2 < ratio[i]) { + if ( ratio[i] > 1 && ((lo[i]-clo[i]*ratio[i])*2 < ratio[i]) ) { crse.growLo(i,1); } - if ((hi[i]-chi[i]*ratio[i])*2 >= ratio[i]) { + if ( ratio[i] > 1 && ((hi[i]-chi[i]*ratio[i])*2 >= ratio[i]) ) { crse.growHi(i,1); } } From 7d24eb90fe8f45281c99c3718e5b8ff2d373c8ee Mon Sep 17 00:00:00 2001 From: Ann Almgren Date: Tue, 11 Jul 2023 18:10:17 -0700 Subject: [PATCH 3/6] fix 1d interface for interpolater --- Src/AmrCore/AMReX_MFInterp_1D_C.H | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/AmrCore/AMReX_MFInterp_1D_C.H b/Src/AmrCore/AMReX_MFInterp_1D_C.H index d1ab2765d12..2d52ca6d57f 100644 --- a/Src/AmrCore/AMReX_MFInterp_1D_C.H +++ b/Src/AmrCore/AMReX_MFInterp_1D_C.H @@ -38,7 +38,7 @@ void mf_cell_cons_lin_interp_limit_minmax_llslope (int i, int, int, Array4 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mf_cell_cons_lin_interp_llslope (int i, int, int, Array4 const& slope, Array4 const& u, int scomp, int ncomp, - Box const& domain, BCRec const* bc) noexcept + Box const& domain, IntVect const& /*ratio*/, BCRec const* bc) noexcept { Real sfx = Real(1.0); From 9fe3ff0d0d6497f6ad72932ad13b1eff493c244c Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Sat, 15 Jul 2023 19:02:11 -0700 Subject: [PATCH 4/6] minor change --- Src/AmrCore/AMReX_Interpolater.cpp | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/Src/AmrCore/AMReX_Interpolater.cpp b/Src/AmrCore/AMReX_Interpolater.cpp index 06c8fb399e6..f2864d3108d 100644 --- a/Src/AmrCore/AMReX_Interpolater.cpp +++ b/Src/AmrCore/AMReX_Interpolater.cpp @@ -170,14 +170,7 @@ FaceLinear::interp_face (const FArrayBox& crse, { BL_PROFILE("FaceLinear::interp_face()"); - AMREX_ALWAYS_ASSERT(ratio[0] > 1); -#if (AMREX_SPACEDIM >= 2) - AMREX_ALWAYS_ASSERT(ratio[1] > 1); -#endif -#if (AMREX_SPACEDIM == 3) - AMREX_ALWAYS_ASSERT(ratio[2] > 1); -#endif - + AMREX_ALWAYS_ASSERT(ratio.allGT(IntVect(1))); AMREX_ASSERT(AMREX_D_TERM(fine_region.type(0),+fine_region.type(1),+fine_region.type(2)) == 1); Array4 const& fine_arr = fine.array(fine_comp); @@ -268,13 +261,7 @@ void FaceLinear::interp_arr (Array const& crse, { BL_PROFILE("FaceLinear::interp_arr()"); - AMREX_ALWAYS_ASSERT(ratio[0] > 1); -#if (AMREX_SPACEDIM >= 2) - AMREX_ALWAYS_ASSERT(ratio[1] > 1); -#endif -#if (AMREX_SPACEDIM == 3) - AMREX_ALWAYS_ASSERT(ratio[2] > 1); -#endif + AMREX_ALWAYS_ASSERT(ratio.allGT(IntVect(1))); Array types; for (int d=0; d& /*bcr*/, RunOn runon) { - AMREX_ALWAYS_ASSERT(ratio[0] > 1); -#if (AMREX_SPACEDIM >= 2) - AMREX_ALWAYS_ASSERT(ratio[1] > 1); -#endif -#if (AMREX_SPACEDIM == 3) - AMREX_ALWAYS_ASSERT(ratio[2] > 1); -#endif + AMREX_ALWAYS_ASSERT(ratio.allGT(IntVect(1))); #if (AMREX_SPACEDIM == 1) amrex::ignore_unused(fine,fine_state, From 86ff579c37b574e75d86d3133baf137725b3e869 Mon Sep 17 00:00:00 2001 From: Ann Almgren Date: Sat, 15 Jul 2023 19:44:51 -0700 Subject: [PATCH 5/6] remove some restrictions on ratio for interpolation --- Src/AmrCore/AMReX_Interpolater.cpp | 35 ++++------------------------ Src/AmrCore/AMReX_MFInterpolater.cpp | 4 ++-- 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/Src/AmrCore/AMReX_Interpolater.cpp b/Src/AmrCore/AMReX_Interpolater.cpp index 06c8fb399e6..db627d373d5 100644 --- a/Src/AmrCore/AMReX_Interpolater.cpp +++ b/Src/AmrCore/AMReX_Interpolater.cpp @@ -14,8 +14,6 @@ namespace amrex { * PCInterp, NodeBilinear, FaceLinear, CellConservativeLinear, and * CellBilinear are supported for all dimensions on cpu and gpu. * - * FaceLinear assumes that ratio > 1 in all directions - * * CellConservativeProtected only works in 2D and 3D on cpu and gpu * and assumes that ratio > 1 in all directions * @@ -170,14 +168,6 @@ FaceLinear::interp_face (const FArrayBox& crse, { BL_PROFILE("FaceLinear::interp_face()"); - AMREX_ALWAYS_ASSERT(ratio[0] > 1); -#if (AMREX_SPACEDIM >= 2) - AMREX_ALWAYS_ASSERT(ratio[1] > 1); -#endif -#if (AMREX_SPACEDIM == 3) - AMREX_ALWAYS_ASSERT(ratio[2] > 1); -#endif - AMREX_ASSERT(AMREX_D_TERM(fine_region.type(0),+fine_region.type(1),+fine_region.type(2)) == 1); Array4 const& fine_arr = fine.array(fine_comp); @@ -268,14 +258,6 @@ void FaceLinear::interp_arr (Array const& crse, { BL_PROFILE("FaceLinear::interp_arr()"); - AMREX_ALWAYS_ASSERT(ratio[0] > 1); -#if (AMREX_SPACEDIM >= 2) - AMREX_ALWAYS_ASSERT(ratio[1] > 1); -#endif -#if (AMREX_SPACEDIM == 3) - AMREX_ALWAYS_ASSERT(ratio[2] > 1); -#endif - Array types; for (int d=0; d 1 && ((lo[i]-clo[i]*ratio[i])*2 < ratio[i]) ) { + if ((lo[i]-clo[i]*ratio[i])*2 < ratio[i]) { crse.growLo(i,1); } - if ( ratio[i] > 1 && ((hi[i]-chi[i]*ratio[i])*2 >= ratio[i]) ) { + if ((hi[i]-chi[i]*ratio[i])*2 >= ratio[i]) { crse.growHi(i,1); } } @@ -579,11 +561,7 @@ CellQuadratic::CoarseBox (const Box& fine, const IntVect& ratio) { Box crse = amrex::coarsen(fine,ratio); - for (int dim = 0; dim < AMREX_SPACEDIM; dim++) { - if (ratio[dim] > 1) { - crse.grow(dim,1); - } - } + crse.grow(1); return crse; } @@ -915,12 +893,7 @@ Box FaceDivFree::CoarseBox (const Box& fine, const IntVect& ratio) { - Box crse = amrex::coarsen(fine,ratio); - for (int dim = 0; dim < AMREX_SPACEDIM; dim++) { - if (ratio[dim] > 1) { - crse.grow(dim,1); - } - } + Box crse = amrex::coarsen(fine,ratio).grow(1); return crse; } diff --git a/Src/AmrCore/AMReX_MFInterpolater.cpp b/Src/AmrCore/AMReX_MFInterpolater.cpp index a8789c815b0..512462d9e78 100644 --- a/Src/AmrCore/AMReX_MFInterpolater.cpp +++ b/Src/AmrCore/AMReX_MFInterpolater.cpp @@ -414,10 +414,10 @@ MFCellBilinear::CoarseBox (const Box& fine, const IntVect& ratio) const int* chi = crse.hiVect(); for (int i = 0; i < AMREX_SPACEDIM; i++) { - if ( ratio[i] > 1 && ((lo[i]-clo[i]*ratio[i])*2 < ratio[i]) ) { + if ((lo[i]-clo[i]*ratio[i])*2 < ratio[i]) { crse.growLo(i,1); } - if ( ratio[i] > 1 && ((hi[i]-chi[i]*ratio[i])*2 >= ratio[i]) ) { + if ((hi[i]-chi[i]*ratio[i])*2 >= ratio[i]) { crse.growHi(i,1); } } From 04ad7f3cd8e3bd7993e5f9e1a7f8c84dc0b1ece6 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Sat, 15 Jul 2023 20:36:40 -0700 Subject: [PATCH 6/6] Fix MFInterpolater --- Src/AmrCore/AMReX_Interpolater.cpp | 8 +------- Src/AmrCore/AMReX_MFInterpolater.cpp | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Src/AmrCore/AMReX_Interpolater.cpp b/Src/AmrCore/AMReX_Interpolater.cpp index b03faa175cb..80c00a24175 100644 --- a/Src/AmrCore/AMReX_Interpolater.cpp +++ b/Src/AmrCore/AMReX_Interpolater.cpp @@ -850,13 +850,7 @@ CellConservativeQuartic::interp (const FArrayBox& crse, RunOn runon) { BL_PROFILE("CellConservativeQuartic::interp()"); - AMREX_ASSERT(ratio[0] == 2); -#if (AMREX_SPACEDIM >= 2) - AMREX_ASSERT(ratio[0] == ratio[1]); -#endif -#if (AMREX_SPACEDIM == 3) - AMREX_ASSERT(ratio[1] == ratio[2]); -#endif + AMREX_ASSERT(ratio == 2); amrex::ignore_unused(ratio); // diff --git a/Src/AmrCore/AMReX_MFInterpolater.cpp b/Src/AmrCore/AMReX_MFInterpolater.cpp index 512462d9e78..21e99e760f2 100644 --- a/Src/AmrCore/AMReX_MFInterpolater.cpp +++ b/Src/AmrCore/AMReX_MFInterpolater.cpp @@ -99,6 +99,11 @@ MFCellConsLinInterp::interp (MultiFab const& crsemf, int ccomp, MultiFab& finemf Box const& cdomain = cgeom.Domain(); + IntVect minus1; + for (int dim = 0; dim < AMREX_SPACEDIM; dim++) { + minus1[dim] = (ratio[dim] > 1) ? -1 : 0; + } + #ifdef AMREX_USE_GPU if (Gpu::inLaunchRegion()) { MultiFab crse_tmp(crsemf.boxArray(), crsemf.DistributionMap(), AMREX_SPACEDIM*nc, 0); @@ -116,14 +121,14 @@ MFCellConsLinInterp::interp (MultiFab const& crsemf, int ccomp, MultiFab& finemf Real drf = fgeom.CellSize(0); Real rlo = fgeom.Offset(0); if (do_linear_limiting) { - ParallelFor(crsemf, IntVect(-1), + ParallelFor(crsemf, minus1, [=] AMREX_GPU_DEVICE (int box_no, int i, int, int) noexcept { mf_cell_cons_lin_interp_llslope(i,0,0, tmp[box_no], crse[box_no], ccomp, nc, cdomain, ratio, pbc); }); } else { - ParallelFor(crsemf, IntVect(-1), nc, + ParallelFor(crsemf, minus1, nc, [=] AMREX_GPU_DEVICE (int box_no, int i, int, int, int n) noexcept { mf_cell_cons_lin_interp_mcslope_sph(i, n, tmp[box_no], crse[box_no], ccomp, nc, @@ -145,14 +150,14 @@ MFCellConsLinInterp::interp (MultiFab const& crsemf, int ccomp, MultiFab& finemf Real drf = fgeom.CellSize(0); Real rlo = fgeom.Offset(0); if (do_linear_limiting) { - ParallelFor(crsemf, IntVect(-1), + ParallelFor(crsemf, minus1, [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int) noexcept { mf_cell_cons_lin_interp_llslope(i,j,0, tmp[box_no], crse[box_no], ccomp, nc, cdomain, ratio, pbc); }); } else { - ParallelFor(crsemf, IntVect(-1), nc, + ParallelFor(crsemf, minus1, nc, [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int, int n) noexcept { mf_cell_cons_lin_interp_mcslope_rz(i,j,n, tmp[box_no], crse[box_no], ccomp, nc, @@ -172,14 +177,14 @@ MFCellConsLinInterp::interp (MultiFab const& crsemf, int ccomp, MultiFab& finemf #endif { if (do_linear_limiting) { - ParallelFor(crsemf, IntVect(-1), + ParallelFor(crsemf, minus1, [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) noexcept { mf_cell_cons_lin_interp_llslope(i,j,k, tmp[box_no], crse[box_no], ccomp, nc, cdomain, ratio, pbc); }); } else { - ParallelFor(crsemf, IntVect(-1), nc, + ParallelFor(crsemf, minus1, nc, [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept { mf_cell_cons_lin_interp_mcslope(i,j,k,n, tmp[box_no], crse[box_no], ccomp, nc, @@ -212,7 +217,7 @@ MFCellConsLinInterp::interp (MultiFab const& crsemf, int ccomp, MultiFab& finemf auto const& fine = finemf.array(mfi); auto const& crse = crsemf.const_array(mfi); - Box const& cbox = amrex::grow(crsemf[mfi].box(), -1); + Box const& cbox = amrex::grow(crsemf[mfi].box(), minus1); tmpfab.resize(cbox, AMREX_SPACEDIM*nc); auto const& tmp = tmpfab.array(); auto const& ctmp = tmpfab.const_array(); @@ -335,6 +340,11 @@ MFCellConsLinMinmaxLimitInterp::interp (MultiFab const& crsemf, int ccomp, Multi Box const& cdomain = cgeom.Domain(); + IntVect minus1; + for (int dim = 0; dim < AMREX_SPACEDIM; dim++) { + minus1[dim] = (ratio[dim] > 1) ? -1 : 0; + } + #ifdef AMREX_USE_GPU if (Gpu::inLaunchRegion()) { MultiFab crse_tmp(crsemf.boxArray(), crsemf.DistributionMap(), AMREX_SPACEDIM*nc, 0); @@ -347,7 +357,7 @@ MFCellConsLinMinmaxLimitInterp::interp (MultiFab const& crsemf, int ccomp, Multi BCRec const* pbc = d_bc.data(); Gpu::copyAsync(Gpu::hostToDevice, bcs.begin()+bcomp, bcs.begin()+bcomp+nc, d_bc.begin()); - ParallelFor(crsemf, IntVect(-1), + ParallelFor(crsemf, minus1, [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) noexcept { mf_cell_cons_lin_interp_limit_minmax_llslope(i,j,k, tmp[box_no], crse[box_no], ccomp, nc, @@ -378,7 +388,7 @@ MFCellConsLinMinmaxLimitInterp::interp (MultiFab const& crsemf, int ccomp, Multi auto const& fine = finemf.array(mfi); auto const& crse = crsemf.const_array(mfi); - Box const& cbox = amrex::grow(crsemf[mfi].box(), -1); + Box const& cbox = amrex::grow(crsemf[mfi].box(), minus1); tmpfab.resize(cbox, AMREX_SPACEDIM*nc); auto const& tmp = tmpfab.array(); auto const& ctmp = tmpfab.const_array();