ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_LagrangianMicrophysics.H
Go to the documentation of this file.
1 /*! @file ERF_LagrangianMicrophysics.H
2  * \brief Contains the Lagrangian microphysics class
3  */
4 
5 #ifndef ERF_LAGRANGIANMICROPHYSICS_H
6 #define ERF_LAGRANGIANMICROPHYSICS_H
7 
8 #ifdef ERF_USE_PARTICLES
9 
10 #include <utility>
11 #include <string>
12 
14 #include "ERF_Microphysics.H"
15 
16 /* forward declaration */
17 class ERFPC;
18 
19 /*! \brief Eulerian microphysics interface
20  *
21  * One key difference from #EulerianMicrophysics is that only the base AMR
22  * level has the moisture model. Thus, for higher AMR levels, the microphysics
23  * interface need not do anything. The number of conserved state variables for
24  * moisture (RhoQ1, RhoQ2, ...) are the same for all AMR levels; however, for
25  * levels other than the base, they just contain and evolve zeros. */
26 class LagrangianMicrophysics : public Microphysics {
27 
28 public:
29 
30  /*! \brief Null constructor */
31  LagrangianMicrophysics () { }
32 
33  /*! \brief default destructor */
34  ~LagrangianMicrophysics () = default;
35 
36  /*! \brief Constructor: create the moisture model */
37  LagrangianMicrophysics (const int& /* nlev */, /*!< Number of AMR levels */
38  const MoistureType& a_model_type /*!< moisture model */ )
39  {
40  AMREX_ASSERT( Microphysics::modelType(a_model_type) == MoistureModelType::Lagrangian );
41  amrex::Abort("No Lagrangian moisture model implemented yet!") ;
42  }
43 
44  /*! \brief Define the moisture model */
45  void Define (const int& lev, /*!< AMR level */
46  SolverChoice& sc /*!< Solver choice object */) override
47  {
48  if (lev > 0) return;
49  m_moist_model->Define(sc);
50  }
51 
52  /*! \brief Initialize the moisture model */
53  void Init (const int& lev, /*!< AMR level */
54  const amrex::MultiFab& cons_in, /*!< Conserved state variables */
55  const amrex::BoxArray& grids, /*!< Grids */
56  const amrex::Geometry& geom, /*!< Geometry */
57  const amrex::Real& dt_advance, /*!< Time step */
58  std::unique_ptr<amrex::MultiFab>& z_phys_nd,/*< Nodal z heights */
59  std::unique_ptr<amrex::MultiFab>& detJ_cc /*< CC Jacobian determinants */) override
60  {
61  if (lev > 0) return;
62  m_moist_model->Init(cons_in, grids, geom, dt_advance,
63  z_phys_nd, detJ_cc);
64  }
65 
66  /*! \brief Advance the moisture model for one time step */
67  void Advance (const int& lev, /*!< AMR level */
68  const amrex::Real& dt_advance, /*!< Time step */
69  const int& iter, /*!< iteration number */
70  const amrex::Real& time, /*!< current time */
71  const SolverChoice& /*solverChoice*/, /*!< Solver choice object */
72  amrex::Vector<amrex::Vector<amrex::MultiFab>>& a_vars, /*!< Dycore state variables */
73  const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& a_z/*!< terrain */,
74  const amrex::GpuArray<ERF_BC, AMREX_SPACEDIM*2>& a_phys_bc_types ) override
75  {
76  if (lev > 0) return;
77  m_moist_model->Advance(dt_advance, iter, time, a_vars, a_z, a_phys_bc_types);
78  }
79 
80  /*! \brief update microphysics variables from ERF state variables */
81  void Update_Micro_Vars_Lev (const int& lev, /*! AMR level */
82  amrex::MultiFab& cons_in /*!< Conserved state variables */) override
83  {
84  if (lev > 0) return;
85  m_moist_model->Update_Micro_Vars(cons_in);
86  }
87 
88  /*! \brief update ERF state variables from microphysics variables */
89  void Update_State_Vars_Lev (const int& lev, /*!< AMR level */
90  amrex::MultiFab& cons_in /*!< Conserved state variables */) override
91  {
92  if (lev > 0) return;
93  m_moist_model->Update_State_Vars(cons_in);
94  }
95 
96  /*! \brief get pointer to a moisture variable */
97  amrex::MultiFab* Get_Qmoist_Ptr (const int& lev, /*!< AMR level */
98  const int& varIdx /*!< moisture variable index */) override
99  {
100  return (lev > 0 ? nullptr : m_moist_model->Qmoist_Ptr(varIdx));
101  }
102 
103  /*! \brief get the number of moisture model variables */
104  int Get_Qmoist_Size (const int& a_lev /*!< AMR level */) override
105  {
106  return (a_lev > 0 ? 0 : m_moist_model->Qmoist_Size());
107  }
108 
109  /*! \brief get the number of moisture-model-related conserved state variables */
110  int Get_Qstate_Size () override
111  {
112  return m_moist_model->Qstate_Size();
113  }
114 
115  /*! \brief initialize particles in particle container */
116  inline void initParticles ( std::unique_ptr<amrex::MultiFab>& z_phys_nd /*!< Nodal z heights */ )
117  {
118  m_moist_model->InitParticles(z_phys_nd);
119  }
120 
121  /*! \brief restart particles in particle container */
122  inline void restartParticles ( amrex::ParGDBBase* a_gdb, const std::string& a_fname)
123  {
124  m_moist_model->RestartParticles(a_gdb, a_fname);
125  }
126 
127  /*! \brief get the particle container from the moisture model */
128  inline ERFPC* getParticleContainer () const
129  {
130  return m_moist_model->getParticleContainer();
131  }
132 
133  /*! \brief get the name of the moisture model's particle container */
134  inline const std::string& getName () const
135  {
136  return m_moist_model->getName();
137  }
138 
139  /*! \brief get the indices and names of moisture model variables for restart
140  at a given level */
141  void Get_Qmoist_Restart_Vars ( const int a_lev, /*!< level */
142  const SolverChoice& a_sc, /*!< Solver choice object */
143  std::vector<int>& a_idx, /*!< indices */
144  std::vector<std::string>& a_names /*!< names */ ) const override
145  {
146  if (a_lev == 0) {
147  m_moist_model->Qmoist_Restart_Vars( a_sc, a_idx, a_names );
148  } else {
149  a_idx.clear();
150  a_names.clear();
151  }
152  }
153 
154 protected:
155 
156  /*! \brief Create and set the specified moisture model */
157  template<class NewMoistModel>
158  void SetModel ()
159  {
160  m_moist_model = std::make_unique<NewMoistModel>();
161  }
162 
163  std::unique_ptr<NullMoistLagrangian> m_moist_model; /*!< moisture model */
164 };
165 
166 #endif
167 #endif
Contains the base class for microphysics.
Contains the Lagrangian moisture model base class.
Base class for microphysics interface.
Definition: ERF_Microphysics.H:14
virtual int Get_Qmoist_Size(const int &)=0
get the number of moisture model variables
virtual void Define(const int &, SolverChoice &)=0
define the microphysics object
virtual void Init(const int &, const amrex::MultiFab &, const amrex::BoxArray &, const amrex::Geometry &, const amrex::Real &, std::unique_ptr< amrex::MultiFab > &, std::unique_ptr< amrex::MultiFab > &)=0
initialize the microphysics object
virtual void Update_State_Vars_Lev(const int &, amrex::MultiFab &)=0
update ERF state variables from microphysics variables
virtual void Update_Micro_Vars_Lev(const int &, amrex::MultiFab &)=0
update microphysics variables from ERF state variables
virtual int Get_Qstate_Size()=0
get the number of moisture-model-related conserved state variables
virtual amrex::MultiFab * Get_Qmoist_Ptr(const int &, const int &)=0
get pointer to a moisture variable
virtual void Get_Qmoist_Restart_Vars(int, const SolverChoice &, std::vector< int > &, std::vector< std::string > &) const =0
get the indices and names of moisture model variables for restart at a given level
static MoistureModelType modelType(const MoistureType a_moisture_type)
query if a specified moisture model is Eulerian or Lagrangian
Definition: ERF_Microphysics.H:69
virtual void Advance(const int &, const amrex::Real &, const int &, const amrex::Real &, const SolverChoice &, amrex::Vector< amrex::Vector< amrex::MultiFab >> &, const amrex::Vector< std::unique_ptr< amrex::MultiFab >> &, const amrex::GpuArray< ERF_BC, AMREX_SPACEDIM *2 > &)=0
advance microphysics for one time step
Definition: ERF_DataStruct.H:82