Skip to content

Commit

Permalink
Moisture w/ terrain (#1512)
Browse files Browse the repository at this point in the history
* Pass z_phys and detJ to micro classes.

* Remove diagnose files from cmake compilation.
  • Loading branch information
AMLattanzi authored Mar 19, 2024
1 parent b2318a6 commit ac7b231
Show file tree
Hide file tree
Showing 20 changed files with 352 additions and 334 deletions.
2 changes: 0 additions & 2 deletions CMake/BuildERFExe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,9 @@ function(build_erf_lib erf_lib_name)
${SRC_DIR}/Microphysics/SAM/IceFall.cpp
${SRC_DIR}/Microphysics/SAM/Precip.cpp
${SRC_DIR}/Microphysics/SAM/PrecipFall.cpp
${SRC_DIR}/Microphysics/SAM/Diagnose_SAM.cpp
${SRC_DIR}/Microphysics/SAM/Update_SAM.cpp
${SRC_DIR}/Microphysics/Kessler/Init_Kessler.cpp
${SRC_DIR}/Microphysics/Kessler/Kessler.cpp
${SRC_DIR}/Microphysics/Kessler/Diagnose_Kessler.cpp
${SRC_DIR}/Microphysics/Kessler/Update_Kessler.cpp
${SRC_DIR}/LandSurfaceModel/SLM/SLM.cpp
${SRC_DIR}/LandSurfaceModel/MM5/MM5.cpp
Expand Down
16 changes: 8 additions & 8 deletions Source/ERF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ Real ERF::fixed_dt = -1.0;
Real ERF::fixed_fast_dt = -1.0;
Real ERF::init_shrink = 1.0;
Real ERF::change_max = 1.1;
int ERF::fixed_mri_dt_ratio = 0;
int ERF::fixed_mri_dt_ratio = 0;

// Dictate verbosity in screen output
int ERF::verbose = 0;
int ERF::verbose = 0;

// Frequency of diagnostic output
int ERF::sum_interval = -1;
int ERF::sum_interval = -1;
Real ERF::sum_per = -1.0;

// Native AMReX vs NetCDF
Expand All @@ -66,21 +66,21 @@ std::string ERF::input_sounding_file = "input_sounding";
bool ERF::init_sounding_ideal = false;

// 1D NetCDF output (for ingestion by AMR-Wind)
int ERF::output_1d_column = 0;
int ERF::column_interval = -1;
int ERF::output_1d_column = 0;
int ERF::column_interval = -1;
Real ERF::column_per = -1.0;
Real ERF::column_loc_x = 0.0;
Real ERF::column_loc_y = 0.0;
std::string ERF::column_file_name = "column_data.nc";

// 2D BndryRegister output (for ingestion by AMR-Wind)
int ERF::output_bndry_planes = 0;
int ERF::bndry_output_planes_interval = -1;
int ERF::output_bndry_planes = 0;
int ERF::bndry_output_planes_interval = -1;
Real ERF::bndry_output_planes_per = -1.0;
Real ERF::bndry_output_planes_start_time = 0.0;

// 2D BndryRegister input
int ERF::input_bndry_planes = 0;
int ERF::input_bndry_planes = 0;

Vector<std::string> BCNames = {"xlo", "ylo", "zlo", "xhi", "yhi", "zhi"};

Expand Down
106 changes: 57 additions & 49 deletions Source/ERF_make_new_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,6 @@ void ERF::MakeNewLevelFromScratch (int lev, Real time, const BoxArray& ba,
lev_new[Vars::zvel].define(convert(ba, IntVect(0,0,1)), dm, 1, IntVect(ngrow_vels,ngrow_vels,0));
lev_old[Vars::zvel].define(convert(ba, IntVect(0,0,1)), dm, 1, IntVect(ngrow_vels,ngrow_vels,0));

//********************************************************************************************
// Microphysics
// *******************************************************************************************
int q_size = micro->Get_Qmoist_Size(lev);
qmoist[lev].resize(q_size);
micro->Define(lev, solverChoice);
if (solverChoice.moisture_type != MoistureType::None)
{
micro->Init(lev, vars_new[lev][Vars::cons], grids[lev], Geom(lev), 0.0); // dummy dt value
}
for (int mvar(0); mvar<qmoist[lev].size(); ++mvar) {
qmoist[lev][mvar] = micro->Get_Qmoist_Ptr(lev,mvar);
}

//********************************************************************************************
// Land Surface Model
// *******************************************************************************************
Expand Down Expand Up @@ -145,6 +131,22 @@ void ERF::MakeNewLevelFromScratch (int lev, Real time, const BoxArray& ba,
sst_lev[lev].resize(1); sst_lev[lev][0] = nullptr;
lmask_lev[lev].resize(1); lmask_lev[lev][0] = nullptr;

//********************************************************************************************
// Microphysics
// *******************************************************************************************
int q_size = micro->Get_Qmoist_Size(lev);
qmoist[lev].resize(q_size);
micro->Define(lev, solverChoice);
if (solverChoice.moisture_type != MoistureType::None)
{
micro->Init(lev, vars_new[lev][Vars::cons],
grids[lev], Geom(lev), 0.0,
z_phys_nd[lev], detJ_cc[lev]); // dummy dt value
}
for (int mvar(0); mvar<qmoist[lev].size(); ++mvar) {
qmoist[lev][mvar] = micro->Get_Qmoist_Ptr(lev,mvar);
}

// ********************************************************************************************
// Create the ERFFillPatcher object
// ********************************************************************************************
Expand Down Expand Up @@ -236,6 +238,26 @@ ERF::MakeNewLevelFromCoarse (int lev, Real time, const BoxArray& ba,
lev_new[Vars::zvel].define(convert(ba, IntVect(0,0,1)), dm, 1, crse_new[Vars::zvel].nGrowVect());
lev_old[Vars::zvel].define(convert(ba, IntVect(0,0,1)), dm, 1, crse_new[Vars::zvel].nGrowVect());

init_stuff(lev, ba, dm);

t_new[lev] = time;
t_old[lev] = time - 1.e200;

// ********************************************************************************************
// Build the data structures for terrain-related quantities
// ********************************************************************************************
update_terrain_arrays(lev, time);

//
// Make sure that detJ and z_phys_cc are the average of the data on a finer level if there is one
//
if (solverChoice.use_terrain != 0) {
for (int crse_lev = lev-1; crse_lev >= 0; crse_lev--) {
average_down( *detJ_cc[crse_lev+1], *detJ_cc[crse_lev], 0, 1, refRatio(crse_lev));
average_down(*z_phys_cc[crse_lev+1], *z_phys_cc[crse_lev], 0, 1, refRatio(crse_lev));
}
}

//********************************************************************************************
// Microphysics
// *******************************************************************************************
Expand All @@ -244,22 +266,14 @@ ERF::MakeNewLevelFromCoarse (int lev, Real time, const BoxArray& ba,
micro->Define(lev, solverChoice);
if (solverChoice.moisture_type != MoistureType::None)
{
micro->Init(lev, vars_new[lev][Vars::cons], grids[lev], Geom(lev), 0.0); // dummy dt value
micro->Init(lev, vars_new[lev][Vars::cons],
grids[lev], Geom(lev), 0.0,
z_phys_nd[lev], detJ_cc[lev]); // dummy dt value
}
for (int mvar(0); mvar<qmoist[lev].size(); ++mvar) {
qmoist[lev][mvar] = micro->Get_Qmoist_Ptr(lev,mvar);
}

init_stuff(lev, ba, dm);

t_new[lev] = time;
t_old[lev] = time - 1.e200;

// ********************************************************************************************
// Build the data structures for terrain-related quantities
// ********************************************************************************************
update_terrain_arrays(lev, time);

// ********************************************************************************************
// Update the base state at this level
// ********************************************************************************************
Expand Down Expand Up @@ -323,16 +337,6 @@ ERF::MakeNewLevelFromCoarse (int lev, Real time, const BoxArray& ba,
Construct_ERFFillPatchers(lev);
Define_ERFFillPatchers(lev);
}

//
// Make sure that detJ and z_phys_cc are the average of the data on a finer level if there is one
//
if (solverChoice.use_terrain != 0) {
for (int crse_lev = lev-1; crse_lev >= 0; crse_lev--) {
average_down( *detJ_cc[crse_lev+1], *detJ_cc[crse_lev], 0, 1, refRatio(crse_lev));
average_down(*z_phys_cc[crse_lev+1], *z_phys_cc[crse_lev], 0, 1, refRatio(crse_lev));
}
}
}

// Remake an existing level using provided BoxArray and DistributionMapping and
Expand Down Expand Up @@ -373,19 +377,7 @@ ERF::RemakeLevel (int lev, Real time, const BoxArray& ba, const DistributionMapp
ref_ratio[lev-1], lev, ncomp_cons);
}

//********************************************************************************************
// Microphysics
// *******************************************************************************************
int q_size = micro->Get_Qmoist_Size(lev);
qmoist[lev].resize(q_size);
micro->Define(lev, solverChoice);
if (solverChoice.moisture_type != MoistureType::None)
{
micro->Init(lev, vars_new[lev][Vars::cons], grids[lev], Geom(lev), 0.0); // dummy dt value
}
for (int mvar(0); mvar<qmoist[lev].size(); ++mvar) {
qmoist[lev][mvar] = micro->Get_Qmoist_Ptr(lev,mvar);
}


init_stuff(lev, ba, dm);

Expand Down Expand Up @@ -435,6 +427,22 @@ ERF::RemakeLevel (int lev, Real time, const BoxArray& ba, const DistributionMapp
}
}

//********************************************************************************************
// Microphysics
// *******************************************************************************************
int q_size = micro->Get_Qmoist_Size(lev);
qmoist[lev].resize(q_size);
micro->Define(lev, solverChoice);
if (solverChoice.moisture_type != MoistureType::None)
{
micro->Init(lev, vars_new[lev][Vars::cons],
grids[lev], Geom(lev), 0.0,
z_phys_nd[lev], detJ_cc[lev]); // dummy dt value
}
for (int mvar(0); mvar<qmoist[lev].size(); ++mvar) {
qmoist[lev][mvar] = micro->Get_Qmoist_Ptr(lev,mvar);
}

// ********************************************************************************************
// Update the base state at this level
// ********************************************************************************************
Expand Down Expand Up @@ -608,7 +616,7 @@ ERF::initialize_integrator (int lev, MultiFab& cons_mf, MultiFab& vel_mf)
mri_integrator_mem[lev]->setForceFirstStageSingleSubstep(solverChoice.force_stage1_single_substep);
}

void ERF::init_stuff(int lev, const BoxArray& ba, const DistributionMapping& dm)
void ERF::init_stuff (int lev, const BoxArray& ba, const DistributionMapping& dm)
{
if (lev == 0) {
min_k_at_level[lev] = 0;
Expand Down
35 changes: 16 additions & 19 deletions Source/Microphysics/EulerianMicrophysics.H
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public:
~EulerianMicrophysics () = default;

/*! \brief Constructor: create the moisture model */
EulerianMicrophysics ( const int& nlev, /*!< Number of AMR levels */
const MoistureType& a_model_type /*!< moisture model */)
EulerianMicrophysics (const int& nlev, /*!< Number of AMR levels */
const MoistureType& a_model_type /*!< moisture model */)
{
AMREX_ASSERT( Microphysics::modelType(a_model_type) == MoistureModelType::Eulerian );
m_moist_model.resize(nlev);
Expand All @@ -50,31 +50,28 @@ public:
}

/*! \brief Initialize the moisture model */
void Init ( const int& lev, /*!< AMR level */
const amrex::MultiFab& cons_in, /*!< Conserved state variables */
const amrex::BoxArray& grids, /*!< Grids */
const amrex::Geometry& geom, /*!< Geometry */
const amrex::Real& dt_advance /*!< Time step */ ) override
void Init (const int& lev, /*!< AMR level */
const amrex::MultiFab& cons_in, /*!< Conserved state variables */
const amrex::BoxArray& grids, /*!< Grids */
const amrex::Geometry& geom, /*!< Geometry */
const amrex::Real& dt_advance, /*!< Time step */
std::unique_ptr<amrex::MultiFab>& z_phys_nd, /*< Nodal z heights */
std::unique_ptr<amrex::MultiFab>& detJ_cc /*< CC Jacobian determinants */) override
{
m_moist_model[lev]->Init(cons_in, grids, geom, dt_advance);
m_moist_model[lev]->Init(cons_in, grids, geom, dt_advance,
z_phys_nd, detJ_cc);
}

/*! \brief Advance the moisture model for one time step */
void Advance ( const int& lev, /*!< AMR level */
const amrex::Real& dt_advance, /*!< Time step */
const SolverChoice &solverChoice, /*!< Solver choice object */
amrex::Vector<amrex::Vector<amrex::MultiFab>>&, /*!< Dycore state variables */
const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& /*!< terrain */) override
void Advance (const int& lev, /*!< AMR level */
const amrex::Real& dt_advance, /*!< Time step */
const SolverChoice &solverChoice, /*!< Solver choice object */
amrex::Vector<amrex::Vector<amrex::MultiFab>>&, /*!< Dycore state variables */
const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& /*!< terrain */) override
{
m_moist_model[lev]->Advance(dt_advance, solverChoice);
}

/*! \brief compute diagnostics */
void Diagnose (const int& lev /*!< AMR level */) override
{
m_moist_model[lev]->Diagnose();
}

/*! \brief update microphysics variables from ERF state variables */
void Update_Micro_Vars_Lev (const int& lev, /*! AMR level */
amrex::MultiFab& cons_in /*!< Conserved state variables */) override
Expand Down
10 changes: 0 additions & 10 deletions Source/Microphysics/Kessler/Diagnose_Kessler.cpp

This file was deleted.

7 changes: 6 additions & 1 deletion Source/Microphysics/Kessler/Init_Kessler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ using namespace amrex;
void Kessler::Init (const MultiFab& cons_in,
const BoxArray& grids,
const Geometry& geom,
const Real& dt_advance)
const Real& dt_advance,
std::unique_ptr<MultiFab>& z_phys_nd,
std::unique_ptr<MultiFab>& detJ_cc)
{
dt = dt_advance;
m_geom = geom;
m_gtoe = grids;

m_z_phys_nd = z_phys_nd.get();
m_detJ_cc = detJ_cc.get();

MicVarMap.resize(m_qmoist_size);
MicVarMap = {MicVar_Kess::rain_accum, MicVar_Kess::qt, MicVar_Kess::qv, MicVar_Kess::qcl, MicVar_Kess::qp};

Expand Down
13 changes: 7 additions & 6 deletions Source/Microphysics/Kessler/Kessler.H
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ public:
// cloud physics
void AdvanceKessler (const SolverChoice &solverChoice);

// diagnose
void Diagnose () override;

// Set up for first time
void
Define (SolverChoice& sc) override
Expand All @@ -78,7 +75,9 @@ public:
Init (const amrex::MultiFab& cons_in,
const amrex::BoxArray& grids,
const amrex::Geometry& geom,
const amrex::Real& dt_advance) override;
const amrex::Real& dt_advance,
std::unique_ptr<amrex::MultiFab>& z_phys_nd,
std::unique_ptr<amrex::MultiFab>& detJ_cc) override;

// Copy state into micro vars
void
Expand All @@ -93,7 +92,6 @@ public:
Update_Micro_Vars (amrex::MultiFab& cons_in) override
{
this->Copy_State_to_Micro(cons_in);
this->Diagnose();
}

// update state vars
Expand All @@ -111,7 +109,6 @@ public:
dt = dt_advance;

this->AdvanceKessler(solverChoice);
this->Diagnose();
}

amrex::MultiFab*
Expand Down Expand Up @@ -161,6 +158,10 @@ private:
amrex::Real m_fac_sub;
amrex::Real m_gOcp;

// Pointer to terrain data
amrex::MultiFab* m_z_phys_nd;
amrex::MultiFab* m_detJ_cc;

// independent variables
amrex::Array<FabPtr, MicVar_Kess::NumVars> mic_fab_vars;
};
Expand Down
Loading

0 comments on commit ac7b231

Please sign in to comment.