Skip to content

Commit

Permalink
add use_real_bcs as input (#1380)
Browse files Browse the repository at this point in the history
  • Loading branch information
asalmgren authored Jan 12, 2024
1 parent 7422c18 commit 22d31af
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 51 deletions.
46 changes: 26 additions & 20 deletions Docs/sphinx_doc/Inputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -791,26 +791,32 @@ advantage of this option, the code must be built with ``USE_POISSON_SOLVE = TRUE
List of Parameters
------------------

+----------------------------------+-------------------+--------------------+------------+
| Parameter | Definition | Acceptable | Default |
| | | Values | |
+==================================+===================+====================+============+
| **erf.init_type** | Initialization | “custom”, | “*custom*” |
| | type | “ideal”, | |
| | | "real", | |
| | |"input_sounding" | |
+----------------------------------+-------------------+--------------------+------------+
| **erf.nc_init_file** | NetCDF file with | String | NONE |
| | initial mesoscale | | |
| | data | | |
+----------------------------------+-------------------+--------------------+------------+
| **erf.nc_bdy_file** | NetCDF file with | String | NONE |
| | mesoscale data at | | |
| | lateral boundaries| | |
+----------------------------------+-------------------+--------------------+------------+
| **erf.project_initial_velocity** | project initial | Integer | 1 |
| | velocity? | | |
+----------------------------------+-------------------+--------------------+------------+
+----------------------------------+-------------------+--------------------+--------------+
| Parameter | Definition | Acceptable | Default |
| | | Values | |
+==================================+===================+====================+==============+
| **erf.init_type** | Initialization | “custom”, | “*custom*” |
| | type | “ideal”, | |
| | | "real", | |
| | |"input_sounding" | |
+----------------------------------+-------------------+--------------------+--------------+
| **erf.use_real_bcs** | If init_type is | true or false | true if |
| | real or metgrid, | | if init_type |
| | do we want to use | | is real or |
| | these bcs? | | metgrid; |
| | | | else false |
+----------------------------------+-------------------+--------------------+--------------+
| **erf.nc_init_file** | NetCDF file with | String | NONE |
| | initial mesoscale | | |
| | data | | |
+----------------------------------+-------------------+--------------------+--------------+
| **erf.nc_bdy_file** | NetCDF file with | String | NONE |
| | mesoscale data at | | |
| | lateral boundaries| | |
+----------------------------------+-------------------+--------------------+--------------+
| **erf.project_initial_velocity** | project initial | Integer | 1 |
| | velocity? | | |
+----------------------------------+-------------------+--------------------+--------------+

Notes
-----------------
Expand Down
16 changes: 9 additions & 7 deletions Source/BoundaryConditions/ERF_FillPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ ERF::FillPatch (int lev, Real time, const Vector<MultiFab*>& mfs, bool fillset)

#ifdef ERF_USE_NETCDF
// We call this here because it is an ERF routine
if (init_type == "real" && lev==0) fill_from_wrfbdy (mfs,time,false,0,ncomp_cons);
if (init_type == "metgrid" && lev==0) fill_from_metgrid(mfs,time,false,0,ncomp_cons);
if (use_real_bcs) {
if (init_type == "real" && lev==0) fill_from_wrfbdy (mfs,time,false,0,ncomp_cons);
if (init_type == "metgrid" && lev==0) fill_from_metgrid(mfs,time,false,0,ncomp_cons);
}
#endif

if (m_r2d) fill_from_bndryregs(mfs,time);
Expand Down Expand Up @@ -132,7 +134,7 @@ ERF::FillPatchMoistVars (int lev, MultiFab& mf)
IntVect ngvect_cons = mf.nGrowVect();
IntVect ngvect_vels = {0,0,0};

if ((init_type != "real") and (init_type != "metgrid")) {
if ((init_type != "real") && (init_type != "metgrid")) {
(*physbcs[lev])({&mf},icomp_cons,ncomp_cons,ngvect_cons,ngvect_vels,init_type,cons_only,bccomp_cons);
}

Expand Down Expand Up @@ -248,10 +250,10 @@ ERF::FillIntermediatePatch (int lev, Real time,
#ifdef ERF_USE_NETCDF
// NOTE: This routine needs to be aware of what FillIntermediatePatch is operating on
// --- i.e., cons_only and which cons indices (icomp_cons & ncomp_cons)

// We call this here because it is an ERF routine
if (init_type == "real" && lev==0) fill_from_wrfbdy(mfs,time, cons_only, icomp_cons, ncomp_cons);
if (init_type == "metgrid" && lev==0) fill_from_metgrid(mfs,time, cons_only, icomp_cons, ncomp_cons);
if (use_real_bcs) {
if (init_type == "real" && lev==0) fill_from_wrfbdy(mfs,time, cons_only, icomp_cons, ncomp_cons);
if (init_type == "metgrid" && lev==0) fill_from_metgrid(mfs,time, cons_only, icomp_cons, ncomp_cons);
}
#endif

if (m_r2d) fill_from_bndryregs(mfs,time);
Expand Down
4 changes: 2 additions & 2 deletions Source/BoundaryConditions/ERF_PhysBCFunct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void ERFPhysBCFunct::operator() (const Vector<MultiFab*>& mfs, int icomp_cons, i
z_nd_arr = m_z_phys_nd->const_array(mfi);
}

if ((init_type != "real") and (init_type != "metgrid"))
if ((init_type != "real") && (init_type != "metgrid"))
{

//! If there are cells not in the valid + periodic grown box
Expand All @@ -109,7 +109,7 @@ void ERFPhysBCFunct::operator() (const Vector<MultiFab*>& mfs, int icomp_cons, i

impose_lateral_zvel_bcs(velz_arr,velx_arr,vely_arr,zbx,domain,z_nd_arr,dxInv,BCVars::zvel_bc);
} // !cons_only
} // init_type != "real" and init_type != "metgrid"
} // init_type != "real" && init_type != "metgrid"

// Every grid touches the bottom and top domain boundary so we call the vertical bcs
// for every box -- and we need to call these even if init_type == real
Expand Down
4 changes: 4 additions & 0 deletions Source/ERF.H
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ private:
// init_type: "ideal", "real", "input_sounding", "metgrid" or ""
static std::string init_type;

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

// NetCDF initialization (wrfinput) file
static amrex::Vector<amrex::Vector<std::string>> nc_init_file;

Expand Down
9 changes: 9 additions & 0 deletions Source/ERF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ std::string ERF::plotfile_type = "amrex";
// init_type: "uniform", "ideal", "real", "input_sounding", "metgrid" or ""
std::string ERF::init_type;

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

// NetCDF wrfinput (initialization) file(s)
amrex::Vector<amrex::Vector<std::string>> ERF::nc_init_file = {{""}}; // Must provide via input

Expand Down Expand Up @@ -1007,6 +1011,11 @@ ERF::ReadParameters ()
amrex::Error("if specified, init_type must be uniform, ideal, real, metgrid or input_sounding");
}

// 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") );
pp.query("use_real_bcs",use_real_bcs);

// No moving terrain with init real
if (init_type == "real" && solverChoice.terrain_type != TerrainType::Static) {
amrex::Abort("Moving terrain is not supported with init real");
Expand Down
31 changes: 17 additions & 14 deletions Source/TimeIntegration/TI_slow_rhs_fun.H
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,22 @@
}

#ifdef ERF_USE_NETCDF
// Populate RHS for relaxation zones
if (((init_type == "real") || (init_type == "metgrid")) && level == 0) {
int width, set_width;
if (init_type == "real") {
width = wrfbdy_width;
set_width = wrfbdy_set_width;
} else if (init_type == "metgrid") {
width = metgrid_bdy_width;
set_width = metgrid_bdy_set_width;
// Populate RHS for relaxation zones if using real bcs
if (use_real_bcs) {
if (((init_type == "real") || (init_type == "metgrid")) && level == 0) {
int width, set_width;
if (init_type == "real") {
width = wrfbdy_width;
set_width = wrfbdy_set_width;
} else if (init_type == "metgrid") {
width = metgrid_bdy_width;
set_width = metgrid_bdy_set_width;
}
wrfbdy_compute_interior_ghost_rhs(init_type, bdy_time_interval, start_bdy_time, new_stage_time, slow_dt,
width-1, set_width, fine_geom,
S_rhs, S_data, bdy_data_xlo, bdy_data_xhi,
bdy_data_ylo, bdy_data_yhi);
}
wrfbdy_compute_interior_ghost_rhs(init_type, bdy_time_interval, start_bdy_time, new_stage_time, slow_dt,
width-1, set_width, fine_geom,
S_rhs, S_data, bdy_data_xlo, bdy_data_xhi,
bdy_data_ylo, bdy_data_yhi);
}
#endif

Expand Down Expand Up @@ -273,7 +275,8 @@

#if defined(ERF_USE_NETCDF)
bool moist_zero = false;
if (solverChoice.moisture_type != MoistureType::None && level==0) {
if ( use_real_bcs && (solverChoice.moisture_type != MoistureType::None) && (level==0) )
{
// Flag for moisture relaxation zone
if (init_type=="real" && wrfbdy_set_width > 0) moist_zero = true;
if (init_type=="metgrid" && metgrid_bdy_set_width > 0) moist_zero = true;
Expand Down
16 changes: 8 additions & 8 deletions Source/Utils/InteriorGhostCells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ wrfbdy_compute_interior_ghost_rhs (const std::string& init_type,
int BdyEnd, ivarU, ivarV, ivarR, ivarT;
if (init_type == "real") {
BdyEnd = WRFBdyVars::NumTypes-3;
ivarU = WRFBdyVars::U;
ivarV = WRFBdyVars::V;
ivarR = WRFBdyVars::R;
ivarT = WRFBdyVars::T;
ivarU = WRFBdyVars::U;
ivarV = WRFBdyVars::V;
ivarR = WRFBdyVars::R;
ivarT = WRFBdyVars::T;
} else if (init_type == "metgrid") {
BdyEnd = MetGridBdyVars::NumTypes-1;
ivarU = MetGridBdyVars::U;
ivarV = MetGridBdyVars::V;
ivarR = MetGridBdyVars::R;
ivarT = MetGridBdyVars::T;
ivarU = MetGridBdyVars::U;
ivarV = MetGridBdyVars::V;
ivarR = MetGridBdyVars::R;
ivarT = MetGridBdyVars::T;
}

// Size the FABs
Expand Down

0 comments on commit 22d31af

Please sign in to comment.