Skip to content

Commit

Permalink
make init_type an InitType enum (#1894)
Browse files Browse the repository at this point in the history
  • Loading branch information
asalmgren authored Oct 17, 2024
1 parent 966119d commit fd923ad
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 49 deletions.
4 changes: 2 additions & 2 deletions Source/BoundaryConditions/ERF_FillPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ ERF::FillPatch (int lev, Real time,

if (m_r2d) fill_from_bndryregs(mfs_vel,time);

// We call these even if init_type == real because these will fill the vertical bcs
// We call these even if init_type == InitType::Real because these will fill the vertical bcs
// Note that we call FillBoundary inside the physbcs call
(*physbcs_cons[lev])(*mfs_vel[Vars::cons],icomp_cons,ncomp_cons,ngvect_cons,time,BCVars::cons_bc, do_fb);
if (!cons_only) {
Expand Down Expand Up @@ -418,7 +418,7 @@ ERF::FillIntermediatePatch (int lev, Real time,

if (m_r2d) fill_from_bndryregs(mfs_vel,time);

// We call this even if init_type == real because this routine will fill the vertical bcs
// We call this even if init_type == InitType::Real because this routine will fill the vertical bcs
(*physbcs_cons[lev])(*mfs_vel[Vars::cons],icomp_cons,ncomp_cons,ngvect_cons,time,BCVars::cons_bc, do_fb);
if (!cons_only) {
(*physbcs_u[lev])(*mfs_vel[Vars::xvel],0,1,ngvect_vels,time,BCVars::xvel_bc, do_fb);
Expand Down
14 changes: 10 additions & 4 deletions Source/ERF.H
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@
class MultiBlockContainer;
#endif

/**
* Enum of possible initialization types
*/
AMREX_ENUM(InitType,
None, Input_Sounding, Ideal, Real, Metgrid, Uniform
);

/**
* Enum of possible coarse/fine interpolation options
*/
Expand Down Expand Up @@ -956,13 +963,12 @@ private:
// Native or NetCDF
static std::string plotfile_type;

// init_type: "ideal", "real", "input_sounding", "metgrid" or ""
static std::string init_type;
static InitType init_type;

// sponge_type: "input_sponge"
static std::string sponge_type;

// use_real_bcs: only true if 1) ( (init_type == real) or (init_type == metgrid) )
// use_real_bcs: only true if 1) ( (init_type == InitType::Real) or (init_type == InitType::Metgrid) )
// AND 2) we want to use the bc's from the WRF bdy file
static bool use_real_bcs;

Expand All @@ -975,7 +981,7 @@ private:
int real_set_width{0};

// Flag to trigger initialization from input_sounding like WRF's ideal.exe
// used with init_type == "input_sounding"
// used with init_type == InitType::Input_Sounding
static bool init_sounding_ideal;

// 1D CDF output (for ingestion in AMR-Wind)
Expand Down
43 changes: 16 additions & 27 deletions Source/ERF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ int ERF::pert_interval = -1;
// Native AMReX vs NetCDF
std::string ERF::plotfile_type = "amrex";

// init_type: "uniform", "ideal", "real", "input_sounding", "metgrid" or ""
std::string ERF::init_type;
InitType ERF::init_type;

// use_real_bcs: only true if 1) ( (init_type == real) or (init_type == metgrid) )
// use_real_bcs: only true if 1) ( (init_type == InitType::Real) or (init_type == InitGrid::Metgrid) )
// AND 2) we want to use the bc's from the WRF bdy file
bool ERF::use_real_bcs;

Expand Down Expand Up @@ -610,7 +609,7 @@ ERF::InitData_post ()
{
if (restart_chkfile.empty()) {
if (solverChoice.use_terrain) {
if (init_type == "ideal") {
if (init_type == InitType::Ideal) {
Abort("We do not currently support init_type = ideal with terrain");
}
}
Expand Down Expand Up @@ -818,7 +817,7 @@ ERF::InitData_post ()
solverChoice.rayleigh_damp_W ||solverChoice.rayleigh_damp_T)
{
initRayleigh();
if (init_type == "input_sounding")
if (init_type == InitType::Input_Sounding)
{
// Overwrite ubar, vbar, and thetabar with input profiles;
// wbar is assumed to be 0. Note: the tau coefficient set by
Expand Down Expand Up @@ -1250,7 +1249,7 @@ ERF::init_only (int lev, Real time)
// Map the words in the inputs file to BC types, then translate
// those types into what they mean for each variable
// This must be called before initHSE (where the base state is initialized)
if (lev == 0 && init_type != "ideal") {
if (lev == 0 && init_type != InitType::Ideal) {
init_bcs();
}

Expand All @@ -1267,7 +1266,7 @@ ERF::init_only (int lev, Real time)
lev_new[Vars::zvel].setVal(0.0); lev_old[Vars::zvel].setVal(0.0);

// Initialize background flow (optional)
if (init_type == "input_sounding") {
if (init_type == InitType::Input_Sounding) {
// The base state is initialized by integrating vertically through the
// input sounding, if the init_sounding_ideal flag is set; otherwise
// it is set by initHSE()
Expand All @@ -1288,23 +1287,23 @@ ERF::init_only (int lev, Real time)
}

#ifdef ERF_USE_NETCDF
} else if (init_type == "ideal" || init_type == "real") {
} else if (init_type == InitType::Ideal || init_type == InitType::Real) {
// The base state is initialized from WRF wrfinput data, output by
// ideal.exe or real.exe
init_from_wrfinput(lev);

// The physbc's need the terrain but are needed for initHSE
if (init_type == "ideal") {
if (init_type == InitType::Ideal) {
make_physbcs(lev);
initHSE(lev);
}

} else if (init_type == "metgrid") {
} else if (init_type == InitType::Metgrid) {
// The base state is initialized from data output by WPS metgrid;
// we will rebalance after interpolation
init_from_metgrid(lev);
#endif
} else if (init_type == "uniform") {
} else if (init_type == InitType::Uniform) {
// Initialize a uniform background field and base state based on the
// problem-specified reference density and temperature

Expand Down Expand Up @@ -1419,11 +1418,12 @@ ERF::ReadParameters ()
pp.query("fixed_mri_dt_ratio", fixed_mri_dt_ratio);

// How to initialize
pp.query("init_type",init_type);
init_type = InitType::None;
pp.query_enum_case_insensitive("init_type",init_type);

// Should we use the bcs we've read in from wrfbdy or metgrid files?
// We default to yes if we have them, but the user can override that option
use_real_bcs = ( (init_type == "real") || (init_type == "metgrid") );
use_real_bcs = ( (init_type == InitType::Real) || (init_type == InitType::Metgrid) );
pp.query("use_real_bcs",use_real_bcs);

// We use this to keep track of how many boxes we read in from WRF initialization
Expand Down Expand Up @@ -1530,7 +1530,7 @@ ERF::ReadParameters ()

// No moving terrain with init real (we must do this after init_params
// because that is where we set terrain_type
if (init_type == "real" && solverChoice.terrain_type == TerrainType::Moving) {
if (init_type == InitType::Real && solverChoice.terrain_type == TerrainType::Moving) {
Abort("Moving terrain is not supported with init real");
}

Expand Down Expand Up @@ -1562,8 +1562,8 @@ ERF::ParameterSanityChecks ()
{
AMREX_ALWAYS_ASSERT(cfl > 0. || fixed_dt[0] > 0.);

// We don't allow use_real_bcs to be true if init_type is not either real or metgrid
AMREX_ALWAYS_ASSERT(!use_real_bcs || ((init_type == "real") || (init_type == "metgrid")) );
// We don't allow use_real_bcs to be true if init_type is not either InitType::Rreal or InitType::Metgrid
AMREX_ALWAYS_ASSERT(!use_real_bcs || ((init_type == InitType::Real) || (init_type == InitType::Metgrid)) );

AMREX_ALWAYS_ASSERT(real_width >= 0);
AMREX_ALWAYS_ASSERT(real_set_width >= 0);
Expand All @@ -1590,17 +1590,6 @@ ERF::ParameterSanityChecks ()
Abort("Dont know this plotfile_type");
}

// Enforce the init_type is one we know
if (!init_type.empty() &&
init_type != "uniform" &&
init_type != "ideal" &&
init_type != "real" &&
init_type != "metgrid" &&
init_type != "input_sounding")
{
Error("if specified, init_type must be uniform, ideal, real, metgrid or input_sounding");
}

// If fixed_mri_dt_ratio is set, it must be even
if (fixed_mri_dt_ratio > 0 && (fixed_mri_dt_ratio%2 != 0) )
{
Expand Down
4 changes: 2 additions & 2 deletions Source/ERF_Tagging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ ERF::refinement_criteria_setup ()
boxes_at_level[lev_for_box].push_back(bx);
Print() << "Saving in 'boxes at level' as " << bx << std::endl;
} // lev
if (init_type == "real" || init_type == "metgrid") {
if (init_type == InitType::Real || init_type == InitType::Metgrid) {
if (num_boxes_at_level[lev_for_box] != num_files_at_level[lev_for_box]) {
amrex::Error("Number of boxes doesn't match number of input files");

Expand Down Expand Up @@ -261,7 +261,7 @@ ERF::refinement_criteria_setup ()
boxes_at_level[lev_for_box].push_back(bx);
Print() << "Saving in 'boxes at level' as " << bx << std::endl;
} // lev
if (init_type == "real" || init_type == "metgrid") {
if (init_type == InitType::Real || init_type == InitType::Metgrid) {
if (num_boxes_at_level[lev_for_box] != num_files_at_level[lev_for_box]) {
amrex::Error("Number of boxes doesn't match number of input files");

Expand Down
2 changes: 1 addition & 1 deletion Source/ERF_make_new_arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ ERF::init_zphys (int lev, Real time)
{
if (solverChoice.use_terrain)
{
if (init_type != "real" && init_type != "metgrid")
if (init_type != InitType::Real && init_type != InitType::Metgrid)
{
if (lev > 0) {
//
Expand Down
16 changes: 8 additions & 8 deletions Source/ERF_make_new_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void ERF::MakeNewLevelFromScratch (int lev, Real time, const BoxArray& ba_in,
// Define dmap[lev] to be dm
SetDistributionMap(lev, dm);

// amrex::Print() <<" BA FROM SCRATCH AT LEVEL " << lev << " " << ba << std::endl;
amrex::Print() <<" BA FROM SCRATCH AT LEVEL " << lev << " " << ba << std::endl;

if (lev == 0) init_bcs();

Expand Down Expand Up @@ -113,22 +113,22 @@ void ERF::MakeNewLevelFromScratch (int lev, Real time, const BoxArray& ba_in,

// ********************************************************************************************
// Initialize the data itself
// If (init_type == "real") then we are initializing terrain and the initial data in
// the same call so we must call init_only before update_terrain_arrays
// If (init_type != "real") then we want to initialize the terrain before the initial data
// since we may need to use the grid information before constructing
// initial idealized data
// If (init_type == InitType::Real) then we are initializing terrain and the initial data in
// the same call so we must call init_only before update_terrain_arrays
// If (init_type != InitType::Real) then we want to initialize the terrain before the initial data
// since we may need to use the grid information before constructing
// initial idealized data
// ********************************************************************************************
if (restart_chkfile.empty()) {
if ((init_type == "real") || (init_type == "metgrid")) {
if ((init_type == InitType::Real) || (init_type == InitType::Metgrid)) {
init_only(lev, start_time);
init_zphys(lev, time);
update_terrain_arrays(lev);
make_physbcs(lev);
} else {
init_zphys(lev, time);
update_terrain_arrays(lev);
// Note that for init_type != real or metgrid,
// Note that for init_type != InitType::Real or InitType::Metgrid,
// make_physbcs is called inside init_only
init_only(lev, start_time);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/ERF_prob_common.H
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ protected:

/**
* Function to update default base parameters, currently only used for
* init_type=='uniform'
* init_type == InitType::Uniform
*/
void init_base_parms (amrex::Real rho_0, amrex::Real T_0) {
base_parms.rho_0 = rho_0;
Expand Down
4 changes: 2 additions & 2 deletions Source/IO/ERF_Checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ ERF::WriteCheckpointFile () const

#ifdef ERF_USE_NETCDF
// Write bdy_data files
if (ParallelDescriptor::IOProcessor() && ((init_type=="real") || (init_type=="metgrid"))) {
if (ParallelDescriptor::IOProcessor() && ((init_type==InitType::Real) || (init_type==InitType::Metgrid))) {

// Vector dimensions
int num_time = bdy_data_xlo.size();
Expand Down Expand Up @@ -462,7 +462,7 @@ ERF::ReadCheckpointFile ()

#ifdef ERF_USE_NETCDF
// Read bdy_data files
if ((init_type=="real") || (init_type=="metgrid")) {
if ((init_type==InitType::Real) || (init_type==InitType::Metgrid)) {
int ioproc = ParallelDescriptor::IOProcessorNumber(); // I/O rank
int num_time;
int num_var;
Expand Down
4 changes: 2 additions & 2 deletions Source/Initialization/ERF_init_from_wrfinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ ERF::init_from_wrfinput (int lev)
IntVect ng = p_hse.nGrowVect();
const Real l_rdOcp = solverChoice.rdOcp;

if (init_type == "real") {
if (init_type == InitType::Real) {
for ( MFIter mfi(lev_new[Vars::cons], TilingIfNotGPU()); mfi.isValid(); ++mfi )
{
FArrayBox& cons_fab = lev_new[Vars::cons][mfi];
Expand All @@ -297,7 +297,7 @@ ERF::init_from_wrfinput (int lev)
pi_hse.FillBoundary(geom[lev].periodicity());
}

if (init_type == "real" && (lev == 0)) {
if (init_type == InitType::Real && (lev == 0)) {
if (nc_bdy_file.empty()) {
amrex::Error("NetCDF boundary file name must be provided via input");
}
Expand Down

0 comments on commit fd923ad

Please sign in to comment.