Skip to content

Commit

Permalink
split ERF_FillPatch.cpp into four files
Browse files Browse the repository at this point in the history
  • Loading branch information
asalmgren committed Oct 23, 2024
1 parent 9618d13 commit 47109eb
Show file tree
Hide file tree
Showing 6 changed files with 501 additions and 469 deletions.
3 changes: 3 additions & 0 deletions CMake/BuildERFExe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ function(build_erf_lib erf_lib_name)
${SRC_DIR}/BoundaryConditions/ERF_BoundaryConditions_bndryreg.cpp
${SRC_DIR}/BoundaryConditions/ERF_BoundaryConditions_realbdy.cpp
${SRC_DIR}/BoundaryConditions/ERF_FillPatch.cpp
${SRC_DIR}/BoundaryConditions/ERF_FillCoarsePatch.cpp
${SRC_DIR}/BoundaryConditions/ERF_FillIntermediatePatch.cpp
${SRC_DIR}/BoundaryConditions/ERF_FillBdyCCVels.cpp
${SRC_DIR}/BoundaryConditions/ERF_FillPatcher.cpp
${SRC_DIR}/BoundaryConditions/ERF_PhysBCFunct.cpp
${SRC_DIR}/Diffusion/ERF_DiffusionSrcForMom_N.cpp
Expand Down
100 changes: 100 additions & 0 deletions Source/BoundaryConditions/ERF_FillBdyCCVels.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include <ERF.H>
#include <ERF_PhysBCFunct.H>
#include <ERF_IndexDefines.H>
#include <ERF_TimeInterpolatedData.H>
#include <ERF_FillPatcher.H>
#include <ERF_Utils.H>

using namespace amrex;

void
ERF::FillBdyCCVels (Vector<MultiFab>& mf_cc_vel)
{
// Impose bc's at domain boundaries
for (int lev = 0; lev <= finest_level; ++lev)
{
Box domain(Geom(lev).Domain());

int ihi = domain.bigEnd(0);
int jhi = domain.bigEnd(1);
int khi = domain.bigEnd(2);

// Impose periodicity first
mf_cc_vel[lev].FillBoundary(geom[lev].periodicity());

for (MFIter mfi(mf_cc_vel[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
// Note that we don't fill corners here -- only the cells that share a face
// with interior cells -- this is all that is needed to calculate vorticity
const Box& bx = mfi.tilebox();
const Array4<Real>& vel_arr = mf_cc_vel[lev].array(mfi);

if (!Geom(lev).isPeriodic(0)) {
// Low-x side
if (bx.smallEnd(0) <= domain.smallEnd(0)) {
Real mult = (phys_bc_type[0] == ERF_BC::no_slip_wall) ? -1. : 1.;
ParallelFor(makeSlab(bx,0,0), [=] AMREX_GPU_DEVICE(int , int j, int k) noexcept
{
vel_arr(-1,j,k,1) = mult*vel_arr(0,j,k,1); // v
vel_arr(-1,j,k,2) = mult*vel_arr(0,j,k,2); // w
});
}

// High-x side
if (bx.bigEnd(0) >= domain.bigEnd(0)) {
Real mult = (phys_bc_type[3] == ERF_BC::no_slip_wall) ? -1. : 1.;
ParallelFor(makeSlab(bx,0,0), [=] AMREX_GPU_DEVICE(int , int j, int k) noexcept
{
vel_arr(ihi+1,j,k,1) = mult*vel_arr(ihi,j,k,1); // v
vel_arr(ihi+1,j,k,2) = mult*vel_arr(ihi,j,k,2); // w
});
}
} // !periodic

if (!Geom(lev).isPeriodic(1)) {
// Low-y side
if (bx.smallEnd(1) <= domain.smallEnd(1)) {
Real mult = (phys_bc_type[1] == ERF_BC::no_slip_wall) ? -1. : 1.;
ParallelFor(makeSlab(bx,1,0), [=] AMREX_GPU_DEVICE(int i, int , int k) noexcept
{
vel_arr(i,-1,k,0) = mult*vel_arr(i,0,k,0); // u
vel_arr(i,-1,k,2) = mult*vel_arr(i,0,k,2); // w
});
}

// High-y side
if (bx.bigEnd(1) >= domain.bigEnd(1)) {
Real mult = (phys_bc_type[4] == ERF_BC::no_slip_wall) ? -1. : 1.;
ParallelFor(makeSlab(bx,1,0), [=] AMREX_GPU_DEVICE(int i, int , int k) noexcept
{
vel_arr(i,jhi+1,k,0) = mult*vel_arr(i,jhi,k,0); // u
vel_arr(i,jhi+1,k,2) = mult*-vel_arr(i,jhi,k,2); // w
});
}
} // !periodic

if (!Geom(lev).isPeriodic(2)) {
// Low-z side
if (bx.smallEnd(2) <= domain.smallEnd(2)) {
Real mult = (phys_bc_type[2] == ERF_BC::no_slip_wall) ? -1. : 1.;
ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE(int i, int j, int) noexcept
{
vel_arr(i,j,-1,0) = mult*vel_arr(i,j,0,0); // u
vel_arr(i,j,-1,1) = mult*vel_arr(i,j,0,1); // v
});
}

// High-z side
if (bx.bigEnd(2) >= domain.bigEnd(2)) {
Real mult = (phys_bc_type[5] == ERF_BC::no_slip_wall) ? -1. : 1.;
ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE(int i, int j, int) noexcept
{
vel_arr(i,j,khi+1,0) = mult*vel_arr(i,j,khi,0); // u
vel_arr(i,j,khi+1,1) = mult*vel_arr(i,j,khi,1); // v
});
}
} // !periodic
} // MFIter

} // lev
}
132 changes: 132 additions & 0 deletions Source/BoundaryConditions/ERF_FillCoarsePatch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#include <ERF.H>
#include <ERF_PhysBCFunct.H>
#include <ERF_IndexDefines.H>
#include <ERF_TimeInterpolatedData.H>
#include <ERF_FillPatcher.H>
#include <ERF_Utils.H>

using namespace amrex;

/*
* Fill valid and ghost data.
* This version fills an entire MultiFab by interpolating from the coarser level -- this is used
* only when a new level of refinement is being created during a run (i.e not at initialization)
* This will never be used with static refinement.
*
* @param[in] lev level of refinement at which to fill the data
* @param[in] time time at which the data should be filled
* @param[out] mfs Vector of MultiFabs to be filled containing, in order: cons, xvel, yvel, and zvel data
*/
void
ERF::FillCoarsePatch (int lev, Real time)
{
BL_PROFILE_VAR("FillCoarsePatch()",FillCoarsePatch);
AMREX_ASSERT(lev > 0);

//
//****************************************************************************************************************
// First fill velocities and density at the COARSE level so we can convert velocity to momenta at the COARSE level
//****************************************************************************************************************
//
bool cons_only = false;
FillPatch(lev-1, time, {&vars_new[lev-1][Vars::cons], &vars_new[lev-1][Vars::xvel],
&vars_new[lev-1][Vars::yvel], &vars_new[lev-1][Vars::zvel]},
{&vars_new[lev-1][Vars::cons],
&rU_new[lev-1], &rV_new[lev-1], &rW_new[lev-1]},
false, cons_only);

//
// ************************************************
// Convert velocity to momentum at the COARSE level
// ************************************************
//
VelocityToMomentum(vars_new[lev-1][Vars::xvel], IntVect{0},
vars_new[lev-1][Vars::yvel], IntVect{0},
vars_new[lev-1][Vars::zvel], IntVect{0},
vars_new[lev-1][Vars::cons],
rU_new[lev-1],
rV_new[lev-1],
rW_new[lev-1],
Geom(lev).Domain(),
domain_bcs_type);
//
// *****************************************************************
// Interpolate all cell-centered variables from coarse to fine level
// *****************************************************************
//
Interpolater* mapper_c = &cell_cons_interp;
Interpolater* mapper_f = &face_cons_linear_interp;

//
//************************************************************************************************
// Interpolate cell-centered data from coarse to fine level
// with InterpFromCoarseLevel which ASSUMES that all ghost cells have already been filled
// ************************************************************************************************
IntVect ngvect_cons = vars_new[lev][Vars::cons].nGrowVect();
int ncomp_cons = vars_new[lev][Vars::cons].nComp();

InterpFromCoarseLevel(vars_new[lev ][Vars::cons], ngvect_cons, IntVect(0,0,0),
vars_new[lev-1][Vars::cons], 0, 0, ncomp_cons,
geom[lev-1], geom[lev],
refRatio(lev-1), mapper_c, domain_bcs_type, BCVars::cons_bc);

//
//************************************************************************************************
// Interpolate x-momentum from coarse to fine level
// with InterpFromCoarseLevel which ASSUMES that all ghost cells have already been filled
// ************************************************************************************************
//
InterpFromCoarseLevel(rU_new[lev], IntVect{0}, IntVect{0}, rU_new[lev-1], 0, 0, 1,
geom[lev-1], geom[lev],
refRatio(lev-1), mapper_f, domain_bcs_type, BCVars::xvel_bc);

//
//************************************************************************************************
// Interpolate y-momentum from coarse to fine level
// with InterpFromCoarseLevel which ASSUMES that all ghost cells have already been filled
// ************************************************************************************************
//
InterpFromCoarseLevel(rV_new[lev], IntVect{0}, IntVect{0}, rV_new[lev-1], 0, 0, 1,
geom[lev-1], geom[lev],
refRatio(lev-1), mapper_f, domain_bcs_type, BCVars::yvel_bc);

//************************************************************************************************
// Interpolate z-momentum from coarse to fine level
// with InterpFromCoarseLevel which ASSUMES that all ghost cells have already been filled
// ************************************************************************************************
InterpFromCoarseLevel(rW_new[lev], IntVect{0}, IntVect{0}, rW_new[lev-1], 0, 0, 1,
geom[lev-1], geom[lev],
refRatio(lev-1), mapper_f, domain_bcs_type, BCVars::zvel_bc);
//
// *********************************************************
// After interpolation of momentum, convert back to velocity
// *********************************************************
//
for (int which_lev = lev-1; which_lev <= lev; which_lev++)
{
MomentumToVelocity(vars_new[which_lev][Vars::xvel],
vars_new[which_lev][Vars::yvel],
vars_new[which_lev][Vars::zvel],
vars_new[which_lev][Vars::cons],
rU_new[which_lev],
rV_new[which_lev],
rW_new[which_lev],
Geom(lev).Domain(),
domain_bcs_type);
}

// ***************************************************************************
// Physical bc's at domain boundary
// ***************************************************************************
IntVect ngvect_vels = vars_new[lev][Vars::xvel].nGrowVect();

(*physbcs_cons[lev])(vars_new[lev][Vars::cons],0,ncomp_cons,ngvect_cons,time,BCVars::cons_bc,true);
( *physbcs_u[lev])(vars_new[lev][Vars::xvel],0,1 ,ngvect_vels,time,BCVars::xvel_bc,true);
( *physbcs_v[lev])(vars_new[lev][Vars::yvel],0,1 ,ngvect_vels,time,BCVars::yvel_bc,true);
( *physbcs_w[lev])(vars_new[lev][Vars::zvel],vars_new[lev][Vars::xvel],vars_new[lev][Vars::yvel],
ngvect_vels,time,BCVars::zvel_bc,true);

// ***************************************************************************
// Since lev > 0 here we don't worry about m_r2d or wrfbdy data
// ***************************************************************************
}
Loading

0 comments on commit 47109eb

Please sign in to comment.