diff --git a/Source/IO/ERF_Checkpoint.cpp b/Source/IO/ERF_Checkpoint.cpp index 49603d1cf..3ce29c8b4 100644 --- a/Source/IO/ERF_Checkpoint.cpp +++ b/Source/IO/ERF_Checkpoint.cpp @@ -3,6 +3,8 @@ #include #include +#include +#include using namespace amrex; @@ -143,33 +145,18 @@ ERF::WriteCheckpointFile () const } // We must read and write qmoist with ghost cells because we don't directly impose BCs on these vars - // Write the precipitation accumulation component only - if (solverChoice.moisture_type == MoistureType::Kessler) { - ng = qmoist[lev][4]->nGrowVect(); - int nvar = 1; - MultiFab moist_vars(grids[lev],dmap[lev],nvar,ng); - MultiFab::Copy(moist_vars,*(qmoist[lev][4]),0,0,nvar,ng); - VisMF::Write(moist_vars, amrex::MultiFabFileFullPrefix(lev, checkpointname, "Level_", "RainAccum")); - } - - if(solverChoice.moisture_type == MoistureType::SAM){ - ng = qmoist[lev][8]->nGrowVect(); - int nvar = 1; - MultiFab rain_accum(grids[lev],dmap[lev],nvar,ng); - MultiFab::Copy(rain_accum,*(qmoist[lev][8]),0,0,nvar,ng); - VisMF::Write(rain_accum, amrex::MultiFabFileFullPrefix(lev, checkpointname, "Level_", "RainAccum")); - - ng = qmoist[lev][9]->nGrowVect(); - MultiFab snow_accum(grids[lev],dmap[lev],nvar,ng); - MultiFab::Copy(snow_accum,*(qmoist[lev][9]),0,0,nvar,ng); - VisMF::Write(snow_accum, amrex::MultiFabFileFullPrefix(lev, checkpointname, "Level_", "SnowAccum")); - - ng = qmoist[lev][10]->nGrowVect(); - MultiFab graup_accum(grids[lev],dmap[lev],nvar,ng); - MultiFab::Copy(graup_accum,*(qmoist[lev][10]),0,0,nvar,ng); - VisMF::Write(graup_accum, amrex::MultiFabFileFullPrefix(lev, checkpointname, "Level_", "GraupAccum")); - } - + // Write the moisture model restart variables + std::vector indices(0); + std::vector names(0); + micro->Get_Qmoist_Restart_Vars(lev, indices, names); + int nvar = indices.size(); + for (int var = 0; var < nvar; var++) { + ng = qmoist[lev][indices[var]]->nGrowVect(); + const int ncomp = 1; + MultiFab moist_vars(grids[lev],dmap[lev],ncomp,ng); + MultiFab::Copy(moist_vars,*(qmoist[lev][indices[var]]),0,0,ncomp,ng); + VisMF::Write(moist_vars, amrex::MultiFabFileFullPrefix(lev, checkpointname, "Level_", names[var])); + } #if defined(ERF_USE_WINDFARM) if(solverChoice.windfarm_type == WindFarmType::Fitch or @@ -408,32 +395,17 @@ ERF::ReadCheckpointFile () update_terrain_arrays(lev); } - // Read in the precipitation accumulation component - if (solverChoice.moisture_type == MoistureType::Kessler) { - ng = qmoist[lev][4]->nGrowVect(); - int nvar = 1; - MultiFab moist_vars(grids[lev],dmap[lev],nvar,ng); - VisMF::Read(moist_vars, amrex::MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "RainAccum")); - MultiFab::Copy(*(qmoist[lev][4]),moist_vars,0,0,nvar,ng); - } - - if (solverChoice.moisture_type == MoistureType::SAM) { - ng = qmoist[lev][8]->nGrowVect(); - int nvar = 1; - MultiFab rain_accum(grids[lev],dmap[lev],nvar,ng); - VisMF::Read(rain_accum, amrex::MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "RainAccum")); - MultiFab::Copy(*(qmoist[lev][8]),rain_accum,0,0,nvar,ng); - - ng = qmoist[lev][9]->nGrowVect(); - MultiFab snow_accum(grids[lev],dmap[lev],nvar,ng); - VisMF::Read(snow_accum, amrex::MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "SnowAccum")); - MultiFab::Copy(*(qmoist[lev][9]),snow_accum,0,0,nvar,ng); - - ng = qmoist[lev][10]->nGrowVect(); - MultiFab graup_accum(grids[lev],dmap[lev],nvar,ng); - VisMF::Read(graup_accum, amrex::MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "GraupAccum")); - MultiFab::Copy(*(qmoist[lev][10]),graup_accum,0,0,nvar,ng); - + // Read in the moisture model restart variables + std::vector indices(0); + std::vector names(0); + micro->Get_Qmoist_Restart_Vars(lev, indices, names); + int nvar = indices.size(); + for (int var = 0; var < nvar; var++) { + ng = qmoist[lev][indices[var]]->nGrowVect(); + const int ncomp = 1; + MultiFab moist_vars(grids[lev],dmap[lev],ncomp,ng); + VisMF::Read(moist_vars, amrex::MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", names[var])); + MultiFab::Copy(*(qmoist[lev][indices[var]]),moist_vars,0,0,ncomp,ng); } #if defined(ERF_USE_WINDFARM) diff --git a/Source/Microphysics/ERF_EulerianMicrophysics.H b/Source/Microphysics/ERF_EulerianMicrophysics.H index 3ac22d487..37554b851 100644 --- a/Source/Microphysics/ERF_EulerianMicrophysics.H +++ b/Source/Microphysics/ERF_EulerianMicrophysics.H @@ -109,6 +109,15 @@ public: return m_moist_model[0]->Qstate_Size(); } + /*! \brief get the indices and names of moisture model variables for restart + at a given level */ + void Get_Qmoist_Restart_Vars ( const int a_lev, /*!< level */ + std::vector& a_idx, /*!< indices */ + std::vector& a_names /*!< names */ ) const override + { + m_moist_model[a_lev]->Qmoist_Restart_Vars( a_idx, a_names ); + } + protected: /*! \brief Create and set the specified moisture model */ diff --git a/Source/Microphysics/ERF_LagrangianMicrophysics.H b/Source/Microphysics/ERF_LagrangianMicrophysics.H index d38073c98..9d1113d6c 100644 --- a/Source/Microphysics/ERF_LagrangianMicrophysics.H +++ b/Source/Microphysics/ERF_LagrangianMicrophysics.H @@ -123,6 +123,20 @@ public: return m_moist_model->getName(); } + /*! \brief get the indices and names of moisture model variables for restart + at a given level */ + void Get_Qmoist_Restart_Vars ( const int a_lev, /*!< level */ + std::vector& a_idx, /*!< indices */ + std::vector& a_names /*!< names */ ) const override + { + if (a_lev == 0) { + m_moist_model->Qmoist_Restart_Vars( a_idx, a_names ); + } else { + a_idx.clear(); + a_names.clear(); + } + } + protected: /*! \brief Create and set the specified moisture model */ diff --git a/Source/Microphysics/ERF_Microphysics.H b/Source/Microphysics/ERF_Microphysics.H index aa45bca4f..e778261f6 100644 --- a/Source/Microphysics/ERF_Microphysics.H +++ b/Source/Microphysics/ERF_Microphysics.H @@ -5,6 +5,8 @@ #ifndef ERF_MICROPHYSICS_H #define ERF_MICROPHYSICS_H +#include +#include #include "ERF_DataStruct.H" /*! \brief Base class for microphysics interface */ @@ -54,6 +56,10 @@ public: /*! \brief get the number of moisture-model-related conserved state variables */ virtual int Get_Qstate_Size () = 0; + /*! \brief get the indices and names of moisture model variables for restart + at a given level */ + virtual void Get_Qmoist_Restart_Vars ( int, std::vector&, std::vector& ) const = 0; + /*! \brief query if a specified moisture model is Eulerian or Lagrangian */ static MoistureModelType modelType (const MoistureType a_moisture_type) { diff --git a/Source/Microphysics/Kessler/ERF_Kessler.H b/Source/Microphysics/Kessler/ERF_Kessler.H index 1766cd7d0..d2d55178a 100644 --- a/Source/Microphysics/Kessler/ERF_Kessler.H +++ b/Source/Microphysics/Kessler/ERF_Kessler.H @@ -124,6 +124,15 @@ public: int Qstate_Size () override { return Kessler::m_qstate_size; } + void + Qmoist_Restart_Vars ( std::vector& a_idx, + std::vector& a_names) const override + { + a_idx.clear(); + a_names.clear(); + a_idx.push_back(4); a_names.push_back("RainAccum"); + } + private: // Number of qmoist variables (qt, qv, qcl, qp) int m_qmoist_size = 5; diff --git a/Source/Microphysics/Null/ERF_NullMoist.H b/Source/Microphysics/Null/ERF_NullMoist.H index c3734c62c..a99ba43bf 100644 --- a/Source/Microphysics/Null/ERF_NullMoist.H +++ b/Source/Microphysics/Null/ERF_NullMoist.H @@ -57,6 +57,14 @@ public: int Qstate_Size () { return NullMoist::m_qstate_size; } + virtual + void + Qmoist_Restart_Vars ( std::vector& a_idx, std::vector& a_names) const + { + a_idx.clear(); + a_names.clear(); + } + private: int m_qmoist_size = 1; int m_qstate_size = 0; diff --git a/Source/Microphysics/SAM/ERF_SAM.H b/Source/Microphysics/SAM/ERF_SAM.H index 2a62c99ca..83a42185b 100644 --- a/Source/Microphysics/SAM/ERF_SAM.H +++ b/Source/Microphysics/SAM/ERF_SAM.H @@ -263,6 +263,17 @@ public: return tabs; } + void + Qmoist_Restart_Vars ( std::vector& a_idx, + std::vector& a_names) const override + { + a_idx.clear(); + a_names.clear(); + a_idx.push_back( 8); a_names.push_back("RainAccum"); + a_idx.push_back( 9); a_names.push_back("SnowAccum"); + a_idx.push_back(10); a_names.push_back("GraupAccum"); + } + private: // Number of qmoist variables (qt, qv, qcl, qci, qp, qpr, qps, qpg) int m_qmoist_size = 11;