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_SuperDropletsMoist.H"
15 #include "ERF_Microphysics.H"
16 
17 /* forward declaration */
18 class ERFPC;
19 
20 /*! \brief Eulerian microphysics interface
21  *
22  * One key difference from #EulerianMicrophysics is that only the base AMR
23  * level has the moisture model. Thus, for higher AMR levels, the microphysics
24  * interface need not do anything. The number of conserved state variables for
25  * moisture (RhoQ1, RhoQ2, ...) are the same for all AMR levels; however, for
26  * levels other than the base, they just contain and evolve zeros. */
27 class LagrangianMicrophysics : public Microphysics {
28 
29 public:
30 
31  /*! \brief Null constructor */
32  LagrangianMicrophysics () { }
33 
34  /*! \brief default destructor */
35  ~LagrangianMicrophysics () = default;
36 
37  /*! \brief Constructor: create the moisture model */
38  LagrangianMicrophysics (const int& /* nlev */, /*!< Number of AMR levels */
39  const MoistureType& a_model_type /*!< moisture model */ )
40  {
41  AMREX_ASSERT( Microphysics::modelType(a_model_type) == MoistureModelType::Lagrangian );
42  if (a_model_type == MoistureType::SuperDroplets) {
43  SetModel<SuperDropletsMoist>();
44  amrex::Print() << "Super-Droplets moisture model!\n";
45  } else {
46  amrex::Abort("Unknown Lagrangian moisture model!") ;
47  }
48  }
49 
50  /*! \brief Define the moisture model */
51  void Define (const int& lev, /*!< AMR level */
52  SolverChoice& sc /*!< Solver choice object */) override
53  {
54  if (lev > 0) return;
55  m_moist_model->Define(sc);
56  }
57 
58  /*! \brief Initialize the moisture model */
59  void Init (const int& lev, /*!< AMR level */
60  const amrex::MultiFab& cons_in, /*!< Conserved state variables */
61  const amrex::BoxArray& grids, /*!< Grids */
62  const amrex::Geometry& geom, /*!< Geometry */
63  const amrex::Real& dt_advance, /*!< Time step */
64  std::unique_ptr<amrex::MultiFab>& z_phys_nd,/*< Nodal z heights */
65  std::unique_ptr<amrex::MultiFab>& detJ_cc /*< CC Jacobian determinants */) override
66  {
67  if (lev > 0) return;
68  m_moist_model->Init(cons_in, grids, geom, dt_advance,
69  z_phys_nd, detJ_cc);
70  }
71 
72  /*! \brief finish initializations steps that require flow variables */
73  void FinishInit (const int& lev, /*!< AMR level */
74  amrex::MultiFab& cons_in, /*!< Conserved state variable */
75  const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& z_phys_nd /*!< terrain */) override
76  {
77  if (lev > 0) return;
78  m_moist_model->FinishInit( lev, cons_in, z_phys_nd );
79  }
80 
81  /*! \brief Advance the moisture model for one time step */
82  void Advance (const int& lev, /*!< AMR level */
83  const amrex::Real& dt_advance, /*!< Time step */
84  const int& iter, /*!< iteration number */
85  const amrex::Real& time, /*!< current time */
86  const SolverChoice& /*solverChoice*/, /*!< Solver choice object */
87  amrex::Vector<amrex::Vector<amrex::MultiFab>>& a_vars, /*!< Dycore state variables */
88  const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& a_z/*!< terrain */,
89  const amrex::GpuArray<ERF_BC, AMREX_SPACEDIM*2>& a_phys_bc_types ) override
90  {
91  if (lev > 0) return;
92  m_moist_model->Advance(dt_advance, iter, time, a_vars, a_z, a_phys_bc_types);
93  }
94 
95  /*! \brief update microphysics variables from ERF state variables */
96  void Update_Micro_Vars_Lev (const int& lev, /*! AMR level */
97  amrex::MultiFab& cons_in /*!< Conserved state variables */) override
98  {
99  if (lev > 0) return;
100  m_moist_model->Update_Micro_Vars(cons_in);
101  }
102 
103  /*! \brief update ERF state variables from microphysics variables */
104  void Update_State_Vars_Lev (const int& lev, /*!< AMR level */
105  amrex::MultiFab& cons_in /*!< Conserved state variables */) override
106  {
107  if (lev > 0) return;
108  m_moist_model->Update_State_Vars(cons_in);
109  }
110 
111  /*! \brief get pointer to a moisture variable */
112  amrex::MultiFab* Get_Qmoist_Ptr (const int& lev, /*!< AMR level */
113  const int& varIdx /*!< moisture variable index */) override
114  {
115  return (lev > 0 ? nullptr : m_moist_model->Qmoist_Ptr(varIdx));
116  }
117 
118  /*! \brief get the number of moisture model variables */
119  int Get_Qmoist_Size (const int& a_lev /*!< AMR level */) override
120  {
121  return (a_lev > 0 ? 0 : m_moist_model->Qmoist_Size());
122  }
123 
124  /*! \brief get the number of microphysics conserved moist (water-related) state variables */
125  int Get_Qstate_Moist_Size () override
126  {
127  return m_moist_model->Qstate_Moist_Size();
128  }
129 
130  /*! \brief get the number of microphysics conserved non-moist (non-water, i.e., other vapor/condensed species) state variables */
131  int Get_Qstate_NonMoist_Size () override
132  {
133  return m_moist_model->Qstate_NonMoist_Size();
134  }
135 
136  /*! \brief initialize particles in particle container */
137  inline void initParticles ( std::unique_ptr<amrex::MultiFab>& z_phys_nd /*!< Nodal z heights */ )
138  {
139  m_moist_model->InitParticles(z_phys_nd);
140  }
141 
142  /*! \brief restart particles in particle container */
143  inline void restartParticles ( amrex::ParGDBBase* a_gdb, const std::string& a_fname)
144  {
145  m_moist_model->RestartParticles(a_gdb, a_fname);
146  }
147 
148  /*! \brief get the particle container from the moisture model */
149  inline ERFPC* getParticleContainer () const
150  {
151  return m_moist_model->getParticleContainer();
152  }
153 
154  /*! \brief get the name of the moisture model's particle container */
155  inline const std::string& getName () const
156  {
157  return m_moist_model->getName();
158  }
159 
160  /*! \brief get the indices and names of moisture model variables for restart
161  at a given level */
162  void Get_Qmoist_Restart_Vars ( const int a_lev, /*!< level */
163  const SolverChoice& a_sc, /*!< Solver choice object */
164  std::vector<int>& a_idx, /*!< indices */
165  std::vector<std::string>& a_names /*!< names */ ) const override
166  {
167  if (a_lev == 0) {
168  m_moist_model->Qmoist_Restart_Vars( a_sc, a_idx, a_names );
169  } else {
170  a_idx.clear();
171  a_names.clear();
172  }
173  }
174 
175  /*! \brief Returns a list of additional plot variable names */
176  virtual void GetPlotVarNames (amrex::Vector<std::string>& a_vec) const override
177  {
178  m_moist_model->GetPlotVarNames(a_vec);
179  }
180 
181  /*! \brief Fills in a MultiFab for plotting */
182  virtual void GetPlotVar (const std::string& a_name,
183  amrex::MultiFab& a_mf,
184  const int /* a_lev */) const override
185  {
186  m_moist_model->GetPlotVar(a_name, a_mf);
187  }
188 
189  /*! \brief Populates dz_min in micro model for precipitation */
190  virtual void Set_dzmin (const int /*a_lev*/,
191  const amrex::Real dz_min) const override
192  {
193  m_moist_model->Set_dzmin(dz_min);
194  }
195 
196  /*! \brief Populates real_width in micro model for box limiting */
197  virtual void Set_RealWidth (const int /*a_lev*/,
198  const int real_width) const override
199  {
200  m_moist_model->Set_RealWidth(real_width);
201  }
202 
203 protected:
204 
205  /*! \brief Create and set the specified moisture model */
206  template<class NewMoistModel>
207  void SetModel ()
208  {
209  m_moist_model = std::make_unique<NewMoistModel>();
210  }
211 
212  std::unique_ptr<NullMoistLagrangian> m_moist_model; /*!< moisture model */
213 };
214 
215 #endif
216 #endif
Contains the base class for microphysics.
Contains the Lagrangian moisture model base class.
amrex::Real Real
Definition: ERF_ShocInterface.H:19
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 int Get_Qstate_NonMoist_Size()=0
get the number of microphysics conserved non-moist (non-water, i.e., other vapor/condensed species) s...
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 int Get_Qstate_Moist_Size()=0
get the number of microphysics conserved moist (water-related) state variables
virtual void Update_Micro_Vars_Lev(const int &, amrex::MultiFab &)=0
update microphysics variables from ERF state variables
virtual amrex::MultiFab * Get_Qmoist_Ptr(const int &, const int &)=0
get pointer to a moisture variable
virtual void GetPlotVarNames(amrex::Vector< std::string > &a_vec) const =0
Returns a list of additional plot variable names.
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
virtual void Set_dzmin(const int lev, const amrex::Real dz_min) const =0
Import minimum dz at this level.
static MoistureModelType modelType(const MoistureType a_moisture_type)
query if a specified moisture model is Eulerian or Lagrangian
Definition: ERF_Microphysics.H:99
virtual void FinishInit(const int &, amrex::MultiFab &, const amrex::Vector< std::unique_ptr< amrex::MultiFab >> &)=0
finish initializations steps that require flow variables
virtual void GetPlotVar(const std::string &a_name, amrex::MultiFab &a_mf, const int a_lev) const =0
Fills in a MultiFab for plotting.
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
virtual void Set_RealWidth(const int lev, const int real_width) const =0
Define the nudging+set width for real BCs.
Definition: ERF_DataStruct.H:129