ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
Kessler Class Reference

#include <ERF_Kessler.H>

Inheritance diagram for Kessler:
Collaboration diagram for Kessler:

Public Member Functions

 Kessler ()
 
virtual ~Kessler ()=default
 
void AdvanceKessler (const SolverChoice &solverChoice)
 
void Define (SolverChoice &sc) override
 
void Init (const amrex::MultiFab &cons_in, const amrex::BoxArray &grids, const amrex::Geometry &geom, const amrex::Real &dt_advance, std::unique_ptr< amrex::MultiFab > &z_phys_nd, std::unique_ptr< amrex::MultiFab > &detJ_cc) override
 
void Set_dzmin (const amrex::Real dz_min) override
 
void Copy_State_to_Micro (const amrex::MultiFab &cons_in) override
 
void Copy_Micro_to_State (amrex::MultiFab &cons_in) override
 
void Update_Micro_Vars (amrex::MultiFab &cons_in) override
 
void Update_State_Vars (amrex::MultiFab &cons_in) override
 
void Advance (const amrex::Real &dt_advance, const SolverChoice &solverChoice) override
 
amrex::MultiFab * Qmoist_Ptr (const int &varIdx) override
 
int Qmoist_Size () override
 
int Qstate_Moist_Size () override
 
void Qmoist_Restart_Vars (const SolverChoice &, std::vector< int > &a_idx, std::vector< std::string > &a_names) const override
 
- Public Member Functions inherited from NullMoist
 NullMoist ()
 
virtual ~NullMoist ()=default
 
virtual int Qstate_NonMoist_Size ()
 
virtual void GetPlotVarNames (amrex::Vector< std::string > &a_vec) const
 
virtual void GetPlotVar (const std::string &, amrex::MultiFab &) const
 

Private Types

using FabPtr = std::shared_ptr< amrex::MultiFab >
 

Private Attributes

int m_qmoist_size = 1
 
int n_qstate_moist_size = 3
 
amrex::Vector< int > MicVarMap
 
amrex::Geometry m_geom
 
amrex::BoxArray m_gtoe
 
amrex::Real dt
 
amrex::Real m_dzmin
 
int nlev
 
int zlo
 
int zhi
 
int m_axis
 
amrex::Real m_fac_cond
 
amrex::Real m_fac_fus
 
amrex::Real m_fac_sub
 
bool m_do_cond
 
amrex::MultiFab * m_z_phys_nd
 
amrex::MultiFab * m_detJ_cc
 
amrex::Array< FabPtr, MicVar_Kess::NumVarsmic_fab_vars
 

Static Private Attributes

static constexpr amrex::Real CFL_MAX = 0.5
 

Member Typedef Documentation

◆ FabPtr

using Kessler::FabPtr = std::shared_ptr<amrex::MultiFab>
private

Constructor & Destructor Documentation

◆ Kessler()

Kessler::Kessler ( )
inline
44 {}

◆ ~Kessler()

virtual Kessler::~Kessler ( )
virtualdefault

Member Function Documentation

◆ Advance()

void Kessler::Advance ( const amrex::Real dt_advance,
const SolverChoice solverChoice 
)
inlineoverridevirtual

Reimplemented from NullMoist.

105  {
106  dt = dt_advance;
107 
108  this->AdvanceKessler(solverChoice);
109  }
amrex::Real dt
Definition: ERF_Kessler.H:156
void AdvanceKessler(const SolverChoice &solverChoice)
Definition: ERF_Kessler.cpp:11
Here is the call graph for this function:

◆ AdvanceKessler()

void Kessler::AdvanceKessler ( const SolverChoice solverChoice)

Compute Precipitation-related Microphysics quantities.

12 {
13  bool do_cond = m_do_cond;
15  if (solverChoice.moisture_type == MoistureType::Kessler)
16  {
17  auto domain = m_geom.Domain();
18  int k_lo = domain.smallEnd(2);
19  int k_hi = domain.bigEnd(2);
20 
21  MultiFab fz;
22  auto ba = tabs->boxArray();
23  auto dm = tabs->DistributionMap();
24  fz.define(convert(ba, IntVect(0,0,1)), dm, 1, 0); // No ghost cells
25 
26  Real dtn = dt;
27  Real coef = dtn/m_dzmin;
28 
29  // Saturation and evaporation calculations go first
30  for ( MFIter mfi(*tabs,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
31  auto qv_array = mic_fab_vars[MicVar_Kess::qv]->array(mfi);
32  auto qc_array = mic_fab_vars[MicVar_Kess::qcl]->array(mfi);
33  auto qp_array = mic_fab_vars[MicVar_Kess::qp]->array(mfi);
34  auto qt_array = mic_fab_vars[MicVar_Kess::qt]->array(mfi);
35  auto tabs_array = mic_fab_vars[MicVar_Kess::tabs]->array(mfi);
36  auto pres_array = mic_fab_vars[MicVar_Kess::pres]->array(mfi);
37  auto theta_array = mic_fab_vars[MicVar_Kess::theta]->array(mfi);
38  auto rho_array = mic_fab_vars[MicVar_Kess::rho]->array(mfi);
39 
40  const auto& tbx = mfi.tilebox();
41 
42  // Expose for GPU
43  Real d_fac_cond = m_fac_cond;
44 
45  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
46  {
47  qv_array(i,j,k) = std::max(0.0, qv_array(i,j,k));
48  qc_array(i,j,k) = std::max(0.0, qc_array(i,j,k));
49  qp_array(i,j,k) = std::max(0.0, qp_array(i,j,k));
50 
51  //------- Autoconversion/accretion
52  Real qcc, auto_r, accrr;
53  Real qsat, dtqsat;
54  Real dq_clwater_to_rain, dq_rain_to_vapor, dq_clwater_to_vapor, dq_vapor_to_clwater;
55 
56  Real pressure = pres_array(i,j,k);
57  erf_qsatw(tabs_array(i,j,k), pressure, qsat);
58  erf_dtqsatw(tabs_array(i,j,k), pressure, dtqsat);
59 
60  if (qsat <= 0.0) {
61  amrex::Warning("qsat computed as non-positive; setting to 0.!");
62  qsat = 0.0;
63  }
64 
65  // If there is precipitating water (i.e. rain), and the cell is not saturated
66  // then the rain water can evaporate leading to extraction of latent heat, hence
67  // reducing temperature and creating negative buoyancy
68 
69  dq_clwater_to_rain = 0.0;
70  dq_rain_to_vapor = 0.0;
71  dq_vapor_to_clwater = 0.0;
72  dq_clwater_to_vapor = 0.0;
73 
74  //Real fac = qsat*4093.0*L_v/(Cp_d*std::pow(tabs_array(i,j,k)-36.0,2));
75  //Real fac = qsat*L_v*L_v/(Cp_d*R_v*tabs_array(i,j,k)*tabs_array(i,j,k));
76  Real fac = (L_v/Cp_d)*dtqsat;
77 
78  // If water vapor content exceeds saturation value, then vapor condenses to water and latent heat is released, increasing temperature
79  if ( (qv_array(i,j,k) > qsat) && do_cond ) {
80  dq_vapor_to_clwater = std::min(qv_array(i,j,k), (qv_array(i,j,k)-qsat)/(1.0 + fac));
81  }
82 
83  // If water vapor is less than the saturated value, then the cloud water can evaporate,
84  // leading to evaporative cooling and reducing temperature
85  if ( (qv_array(i,j,k) < qsat) && (qc_array(i,j,k) > 0.0) && do_cond ) {
86  dq_clwater_to_vapor = std::min(qc_array(i,j,k), (qsat - qv_array(i,j,k))/(1.0 + fac));
87  }
88 
89  if (( qp_array(i,j,k) > 0.0) && (qv_array(i,j,k) < qsat) ) {
90  Real C = 1.6 + 124.9*std::pow(0.001*rho_array(i,j,k)*qp_array(i,j,k),0.2046);
91  dq_rain_to_vapor = 1.0/(0.001*rho_array(i,j,k))*(1.0 - qv_array(i,j,k)/qsat)*C*std::pow(0.001*rho_array(i,j,k)*qp_array(i,j,k),0.525)/
92  (5.4e5 + 2.55e6/(pressure*qsat))*dtn;
93  // The negative sign is to make this variable (vapor formed from evaporation)
94  // a positive quantity (as qv/qs < 1)
95  dq_rain_to_vapor = std::min({qp_array(i,j,k), dq_rain_to_vapor});
96 
97  // Removing latent heat due to evaporation from rain water to water vapor, reduces the (potential) temperature
98  }
99 
100  // If there is cloud water present then do accretion and autoconversion to rain
101  if (qc_array(i,j,k) > 0.0) {
102  qcc = qc_array(i,j,k);
103 
104  auto_r = 0.0;
105  if (qcc > qcw0) {
106  auto_r = alphaelq;
107  }
108 
109  accrr = 0.0;
110  accrr = 2.2 * std::pow(qp_array(i,j,k) , 0.875);
111  dq_clwater_to_rain = dtn *(accrr*qcc + auto_r*(qcc - qcw0));
112 
113  // If the amount of change is more than the amount of qc present, then dq = qc
114  dq_clwater_to_rain = std::min(dq_clwater_to_rain, qc_array(i,j,k));
115  }
116 
117  qv_array(i,j,k) += -dq_vapor_to_clwater + dq_clwater_to_vapor + dq_rain_to_vapor;
118  qc_array(i,j,k) += dq_vapor_to_clwater - dq_clwater_to_vapor - dq_clwater_to_rain;
119  qp_array(i,j,k) += dq_clwater_to_rain - dq_rain_to_vapor;
120 
121  Real theta_over_T = theta_array(i,j,k)/tabs_array(i,j,k);
122  theta_array(i,j,k) += theta_over_T * d_fac_cond * (dq_vapor_to_clwater - dq_clwater_to_vapor - dq_rain_to_vapor);
123 
124  qv_array(i,j,k) = std::max(0.0, qv_array(i,j,k));
125  qc_array(i,j,k) = std::max(0.0, qc_array(i,j,k));
126  qp_array(i,j,k) = std::max(0.0, qp_array(i,j,k));
127 
128  qt_array(i,j,k) = qv_array(i,j,k) + qc_array(i,j,k);
129  });
130  }
131 
132  // Precompute terminal velocity for substepping
133  for ( MFIter mfi(fz, TilingIfNotGPU()); mfi.isValid(); ++mfi ){
134  auto rho_array = mic_fab_vars[MicVar_Kess::rho]->array(mfi);
135  auto qp_array = mic_fab_vars[MicVar_Kess::qp]->array(mfi);
136 
137  auto fz_array = fz.array(mfi);
138  const Box& tbz = mfi.tilebox();
139 
140  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
141  {
142  Real rho_avg, qp_avg;
143 
144  if (k==k_lo) {
145  rho_avg = rho_array(i,j,k);
146  qp_avg = qp_array(i,j,k);
147  } else if (k==k_hi+1) {
148  rho_avg = rho_array(i,j,k-1);
149  qp_avg = qp_array(i,j,k-1);
150  } else {
151  rho_avg = 0.5*(rho_array(i,j,k-1) + rho_array(i,j,k)); // Convert to g/cm^3
152  qp_avg = 0.5*(qp_array(i,j,k-1) + qp_array(i,j,k));
153  }
154 
155  qp_avg = std::max(0.0, qp_avg);
156 
157  Real V_terminal = 36.34*std::pow(rho_avg*0.001*qp_avg, 0.1346)*std::pow(rho_avg/1.16, -0.5); // in m/s
158 
159  // NOTE: Fz is the sedimentation flux from the advective operator.
160  // In the terrain-following coordinate system, the z-deriv in
161  // the divergence uses the normal velocity (Omega). However,
162  // there are no u/v components to the sedimentation velocity.
163  // Therefore, we simply end up with a division by detJ when
164  // evaluating the source term: dJinv * (flux_hi - flux_lo) * dzinv.
165  fz_array(i,j,k) = rho_avg*V_terminal*qp_avg;
166  });
167  } // mfi
168 
169  // Compute number of substeps from maximum terminal velocity
170  Real wt_max;
171  int n_substep;
172  auto const& ma_fz_arr = fz.const_arrays();
173  GpuTuple<Real> max = ParReduce(TypeList<ReduceOpMax>{},
174  TypeList<Real>{},
175  fz, IntVect(0),
176  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) noexcept
177  -> GpuTuple<Real>
178  {
179  return { ma_fz_arr[box_no](i,j,k) };
180  });
181  wt_max = get<0>(max) + std::numeric_limits<Real>::epsilon();
182  n_substep = int( std::ceil(wt_max * coef / CFL_MAX) );
183  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(n_substep >= 1,
184  "Kessler: Number of precipitation substeps must be greater than 0!");
185  coef /= Real(n_substep);
186  dtn /= Real(n_substep);
187 
188  // Substep the vertical advection
189  for (int nsub(0); nsub<n_substep; ++nsub) {
190  for ( MFIter mfi(*tabs, TilingIfNotGPU()); mfi.isValid(); ++mfi ){
191  auto rho_array = mic_fab_vars[MicVar_Kess::rho]->array(mfi);
192  auto qp_array = mic_fab_vars[MicVar_Kess::qp]->array(mfi);
193  auto rain_accum_array = mic_fab_vars[MicVar_Kess::rain_accum]->array(mfi);
194  auto fz_array = fz.array(mfi);
195 
196  const auto dJ_array = (m_detJ_cc) ? m_detJ_cc->const_array(mfi) : Array4<const Real>{};
197 
198  const Box& tbx = mfi.tilebox();
199  const Box& tbz = mfi.tilebox(IntVect(0,0,1),IntVect(0));
200 
201  // Update vertical flux every substep
202  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
203  {
204  Real rho_avg, qp_avg;
205  if (k==k_lo) {
206  rho_avg = rho_array(i,j,k);
207  qp_avg = qp_array(i,j,k);
208  } else if (k==k_hi+1) {
209  rho_avg = rho_array(i,j,k-1);
210  qp_avg = qp_array(i,j,k-1);
211  } else {
212  rho_avg = 0.5*(rho_array(i,j,k-1) + rho_array(i,j,k)); // Convert to g/cm^3
213  qp_avg = 0.5*(qp_array(i,j,k-1) + qp_array(i,j,k));
214  }
215 
216  qp_avg = std::max(0.0, qp_avg);
217 
218  Real V_terminal = 36.34*std::pow(rho_avg*0.001*qp_avg, 0.1346)*std::pow(rho_avg/1.16, -0.5); // in m/s
219 
220  // NOTE: Fz is the sedimentation flux from the advective operator.
221  // In the terrain-following coordinate system, the z-deriv in
222  // the divergence uses the normal velocity (Omega). However,
223  // there are no u/v components to the sedimentation velocity.
224  // Therefore, we simply end up with a division by detJ when
225  // evaluating the source term: dJinv * (flux_hi - flux_lo) * dzinv.
226  fz_array(i,j,k) = rho_avg*V_terminal*qp_avg;
227 
228  if(k==k_lo){
229  rain_accum_array(i,j,k) = rain_accum_array(i,j,k) + rho_avg*qp_avg*V_terminal*dtn/1000.0*1000.0; // Divide by rho_water and convert to mm
230  }
231  });
232 
233  // Update precip every substep
234  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
235  {
236  // Jacobian determinant
237  Real dJinv = (dJ_array) ? 1.0/dJ_array(i,j,k) : 1.0;
238 
239  if(std::fabs(fz_array(i,j,k+1)) < 1e-14) fz_array(i,j,k+1) = 0.0;
240  if(std::fabs(fz_array(i,j,k )) < 1e-14) fz_array(i,j,k ) = 0.0;
241  Real dq_sed = dJinv * (1.0/rho_array(i,j,k)) * (fz_array(i,j,k+1) - fz_array(i,j,k)) * coef;
242  if(std::fabs(dq_sed) < 1e-14) dq_sed = 0.0;
243 
244  qp_array(i,j,k) += dq_sed;
245  qp_array(i,j,k) = std::max(0.0, qp_array(i,j,k));
246  });
247  } // mfi
248  } // nsub
249  }
250 
251 
252  if (solverChoice.moisture_type == MoistureType::Kessler_NoRain) {
253  if (!do_cond) { return; }
254  // get the temperature, density, theta, qt and qc from input
255  for ( MFIter mfi(*tabs,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
256  auto qv_array = mic_fab_vars[MicVar_Kess::qv]->array(mfi);
257  auto qc_array = mic_fab_vars[MicVar_Kess::qcl]->array(mfi);
258  auto qt_array = mic_fab_vars[MicVar_Kess::qt]->array(mfi);
259  auto tabs_array = mic_fab_vars[MicVar_Kess::tabs]->array(mfi);
260  auto theta_array = mic_fab_vars[MicVar_Kess::theta]->array(mfi);
261  auto pres_array = mic_fab_vars[MicVar_Kess::pres]->array(mfi);
262 
263  const auto& box3d = mfi.tilebox();
264 
265  // Expose for GPU
266  Real d_fac_cond = m_fac_cond;
267 
268  ParallelFor(box3d, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
269  {
270  qc_array(i,j,k) = std::max(0.0, qc_array(i,j,k));
271 
272  //------- Autoconversion/accretion
273  Real qsat, dtqsat;
274  Real dq_clwater_to_vapor, dq_vapor_to_clwater;
275 
276  Real pressure = pres_array(i,j,k);
277  erf_qsatw(tabs_array(i,j,k), pressure, qsat);
278  erf_dtqsatw(tabs_array(i,j,k), pressure, dtqsat);
279 
280  // If there is precipitating water (i.e. rain), and the cell is not saturated
281  // then the rain water can evaporate leading to extraction of latent heat, hence
282  // reducing temperature and creating negative buoyancy
283 
284  dq_vapor_to_clwater = 0.0;
285  dq_clwater_to_vapor = 0.0;
286 
287  //Real fac = qsat*4093.0*L_v/(Cp_d*std::pow(tabs_array(i,j,k)-36.0,2));
288  //Real fac = qsat*L_v*L_v/(Cp_d*R_v*tabs_array(i,j,k)*tabs_array(i,j,k));
289  Real fac = (L_v/Cp_d)*dtqsat;
290 
291  // If water vapor content exceeds saturation value, then vapor condenses to water and latent heat is released, increasing temperature
292  if (qv_array(i,j,k) > qsat){
293  dq_vapor_to_clwater = std::min(qv_array(i,j,k), (qv_array(i,j,k)-qsat)/(1.0 + fac));
294  }
295  // If water vapor is less than the saturated value, then the cloud water can evaporate, leading to evaporative cooling and
296  // reducing temperature
297  if (qv_array(i,j,k) < qsat && qc_array(i,j,k) > 0.0){
298  dq_clwater_to_vapor = std::min(qc_array(i,j,k), (qsat - qv_array(i,j,k))/(1.0 + fac));
299  }
300 
301  qv_array(i,j,k) += -dq_vapor_to_clwater + dq_clwater_to_vapor;
302  qc_array(i,j,k) += dq_vapor_to_clwater - dq_clwater_to_vapor;
303 
304  Real theta_over_T = theta_array(i,j,k)/tabs_array(i,j,k);
305 
306  theta_array(i,j,k) += theta_over_T * d_fac_cond * (dq_vapor_to_clwater - dq_clwater_to_vapor);
307 
308  qv_array(i,j,k) = std::max(0.0, qv_array(i,j,k));
309  qc_array(i,j,k) = std::max(0.0, qc_array(i,j,k));
310 
311  qt_array(i,j,k) = qv_array(i,j,k) + qc_array(i,j,k);
312  });
313  }
314  }
315 }
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:12
constexpr amrex::Real alphaelq
Definition: ERF_Constants.H:48
constexpr amrex::Real qcw0
Definition: ERF_Constants.H:46
constexpr amrex::Real L_v
Definition: ERF_Constants.H:16
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_dtqsatw(amrex::Real t, amrex::Real p, amrex::Real &dtqsatw)
Definition: ERF_MicrophysicsUtils.H:181
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsatw(amrex::Real t, amrex::Real p, amrex::Real &qsatw)
Definition: ERF_MicrophysicsUtils.H:166
amrex::Real Real
Definition: ERF_ShocInterface.H:19
amrex::Geometry m_geom
Definition: ERF_Kessler.H:150
amrex::MultiFab * m_detJ_cc
Definition: ERF_Kessler.H:175
amrex::Real m_dzmin
Definition: ERF_Kessler.H:159
amrex::Real m_fac_cond
Definition: ERF_Kessler.H:168
bool m_do_cond
Definition: ERF_Kessler.H:171
amrex::Array< FabPtr, MicVar_Kess::NumVars > mic_fab_vars
Definition: ERF_Kessler.H:178
static constexpr amrex::Real CFL_MAX
Definition: ERF_Kessler.H:144
@ qp
Definition: ERF_Kessler.H:31
@ qcl
Definition: ERF_Kessler.H:29
@ tabs
Definition: ERF_Kessler.H:24
@ pres
Definition: ERF_Kessler.H:25
@ rho
Definition: ERF_Kessler.H:22
@ theta
Definition: ERF_Kessler.H:23
@ qt
Definition: ERF_Kessler.H:27
@ rain_accum
Definition: ERF_Kessler.H:33
@ qv
Definition: ERF_Kessler.H:28
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
MoistureType moisture_type
Definition: ERF_DataStruct.H:1140

Referenced by Advance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Copy_Micro_to_State()

void Kessler::Copy_Micro_to_State ( amrex::MultiFab &  cons_in)
overridevirtual

Updates conserved and microphysics variables in the provided MultiFabs from the internal MultiFabs that store Microphysics module data.

Parameters
[out]consConserved variables
[out]qmoistqv, qc, qi, qr, qs, qg

Reimplemented from NullMoist.

15 {
16  // Get the temperature, density, theta, qt and qp from input
17  for ( MFIter mfi(cons,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
18  const auto& box3d = mfi.tilebox();
19 
20  auto states_arr = cons.array(mfi);
21 
22  auto rho_arr = mic_fab_vars[MicVar_Kess::rho]->array(mfi);
23  auto theta_arr = mic_fab_vars[MicVar_Kess::theta]->array(mfi);
24  auto qv_arr = mic_fab_vars[MicVar_Kess::qv]->array(mfi);
25  auto qc_arr = mic_fab_vars[MicVar_Kess::qcl]->array(mfi);
26  auto qp_arr = mic_fab_vars[MicVar_Kess::qp]->array(mfi);
27 
28  // get potential total density, temperature, qt, qp
29  ParallelFor( box3d, [=] AMREX_GPU_DEVICE (int i, int j, int k)
30  {
31  states_arr(i,j,k,RhoTheta_comp) = rho_arr(i,j,k)*theta_arr(i,j,k);
32  states_arr(i,j,k,RhoQ1_comp) = rho_arr(i,j,k)*qv_arr(i,j,k);
33  states_arr(i,j,k,RhoQ2_comp) = rho_arr(i,j,k)*qc_arr(i,j,k);
34  states_arr(i,j,k,RhoQ3_comp) = rho_arr(i,j,k)*qp_arr(i,j,k);
35  });
36  }
37 
38  // Fill interior ghost cells and periodic boundaries
39  cons.FillBoundary(m_geom.periodicity());
40 }
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:43
#define RhoQ3_comp
Definition: ERF_IndexDefines.H:44
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:42
@ cons
Definition: ERF_IndexDefines.H:140

Referenced by Update_State_Vars().

Here is the caller graph for this function:

◆ Copy_State_to_Micro()

void Kessler::Copy_State_to_Micro ( const amrex::MultiFab &  cons_in)
overridevirtual

Initializes the Microphysics module.

Parameters
[in]cons_inConserved variables input

Reimplemented from NullMoist.

65 {
66  // Get the temperature, density, theta, qt and qp from input
67  for ( MFIter mfi(cons_in); mfi.isValid(); ++mfi) {
68  const auto& box3d = mfi.tilebox();
69 
70  auto states_array = cons_in.array(mfi);
71 
72  auto qt_array = mic_fab_vars[MicVar_Kess::qt]->array(mfi);
73  auto qv_array = mic_fab_vars[MicVar_Kess::qv]->array(mfi);
74  auto qc_array = mic_fab_vars[MicVar_Kess::qcl]->array(mfi);
75 
76  auto qp_array = mic_fab_vars[MicVar_Kess::qp]->array(mfi);
77 
78  auto rho_array = mic_fab_vars[MicVar_Kess::rho]->array(mfi);
79  auto theta_array = mic_fab_vars[MicVar_Kess::theta]->array(mfi);
80  auto tabs_array = mic_fab_vars[MicVar_Kess::tabs]->array(mfi);
81  auto pres_array = mic_fab_vars[MicVar_Kess::pres]->array(mfi);
82 
83  // Get pressure, theta, temperature, density, and qt, qp
84  ParallelFor( box3d, [=] AMREX_GPU_DEVICE (int i, int j, int k)
85  {
86  rho_array(i,j,k) = states_array(i,j,k,Rho_comp);
87  theta_array(i,j,k) = states_array(i,j,k,RhoTheta_comp)/states_array(i,j,k,Rho_comp);
88  qv_array(i,j,k) = states_array(i,j,k,RhoQ1_comp)/states_array(i,j,k,Rho_comp);
89  qc_array(i,j,k) = states_array(i,j,k,RhoQ2_comp)/states_array(i,j,k,Rho_comp);
90  qp_array(i,j,k) = states_array(i,j,k,RhoQ3_comp)/states_array(i,j,k,Rho_comp);
91  qt_array(i,j,k) = qv_array(i,j,k) + qc_array(i,j,k);
92 
93  tabs_array(i,j,k) = getTgivenRandRTh(states_array(i,j,k,Rho_comp),
94  states_array(i,j,k,RhoTheta_comp),
95  qv_array(i,j,k));
96  pres_array(i,j,k) = getPgivenRTh(states_array(i,j,k,RhoTheta_comp), qv_array(i,j,k)) * 0.01;
97  });
98  }
99 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=0.)
Definition: ERF_EOS.H:81
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenRandRTh(const amrex::Real rho, const amrex::Real rhotheta, const amrex::Real qv=0.0)
Definition: ERF_EOS.H:46
#define Rho_comp
Definition: ERF_IndexDefines.H:36

Referenced by Update_Micro_Vars().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Define()

void Kessler::Define ( SolverChoice sc)
inlineoverridevirtual

Reimplemented from NullMoist.

55  {
56  m_fac_cond = lcond / sc.c_p;
57  m_fac_fus = lfus / sc.c_p;
58  m_fac_sub = lsub / sc.c_p;
59  m_axis = sc.ave_plane;
60  m_do_cond = (!sc.use_shoc);
61  }
constexpr amrex::Real lfus
Definition: ERF_Constants.H:67
constexpr amrex::Real lsub
Definition: ERF_Constants.H:68
constexpr amrex::Real lcond
Definition: ERF_Constants.H:66
amrex::Real m_fac_sub
Definition: ERF_Kessler.H:170
amrex::Real m_fac_fus
Definition: ERF_Kessler.H:169
int m_axis
Definition: ERF_Kessler.H:165
amrex::Real c_p
Definition: ERF_DataStruct.H:1096
bool use_shoc
Definition: ERF_DataStruct.H:1124
int ave_plane
Definition: ERF_DataStruct.H:1155

◆ Init()

void Kessler::Init ( const amrex::MultiFab &  cons_in,
const amrex::BoxArray &  grids,
const amrex::Geometry &  geom,
const amrex::Real dt_advance,
std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
std::unique_ptr< amrex::MultiFab > &  detJ_cc 
)
overridevirtual

Initializes the Microphysics module.

Parameters
[in]cons_inConserved variables input
[in]qc_inCloud variables input
[in,out]qv_inVapor variables input
[in]qi_inIce variables input
[in]gridsThe boxes on which we will evolve the solution
[in]geomGeometry associated with these MultiFabs and grids
[in]dt_advanceTimestep for the advance

Reimplemented from NullMoist.

27 {
28  dt = dt_advance;
29  m_geom = geom;
30  m_gtoe = grids;
31 
32  m_z_phys_nd = z_phys_nd.get();
33  m_detJ_cc = detJ_cc.get();
34 
35  MicVarMap.resize(m_qmoist_size);
37 
38  // initialize microphysics variables
39  for (auto ivar = 0; ivar < MicVar_Kess::NumVars; ++ivar) {
40  mic_fab_vars[ivar] = std::make_shared<MultiFab>(cons_in.boxArray(), cons_in.DistributionMap(),
41  1, cons_in.nGrowVect());
42  mic_fab_vars[ivar]->setVal(0.);
43  }
44 
45  // Set class data members
46  for ( MFIter mfi(cons_in, TileNoZ()); mfi.isValid(); ++mfi) {
47  const auto& box3d = mfi.tilebox();
48 
49  const auto& lo = lbound(box3d);
50  const auto& hi = ubound(box3d);
51 
52  nlev = box3d.length(2);
53  zlo = lo.z;
54  zhi = hi.z;
55  }
56 }
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
int zlo
Definition: ERF_Kessler.H:162
amrex::Vector< int > MicVarMap
Definition: ERF_Kessler.H:147
int zhi
Definition: ERF_Kessler.H:162
int nlev
Definition: ERF_Kessler.H:162
amrex::MultiFab * m_z_phys_nd
Definition: ERF_Kessler.H:174
amrex::BoxArray m_gtoe
Definition: ERF_Kessler.H:153
int m_qmoist_size
Definition: ERF_Kessler.H:138
@ NumVars
Definition: ERF_Kessler.H:34
Here is the call graph for this function:

◆ Qmoist_Ptr()

amrex::MultiFab* Kessler::Qmoist_Ptr ( const int &  varIdx)
inlineoverridevirtual

Reimplemented from NullMoist.

113  {
114  AMREX_ALWAYS_ASSERT(varIdx < m_qmoist_size);
115  return mic_fab_vars[MicVarMap[varIdx]].get();
116  }

◆ Qmoist_Restart_Vars()

void Kessler::Qmoist_Restart_Vars ( const SolverChoice ,
std::vector< int > &  a_idx,
std::vector< std::string > &  a_names 
) const
inlineoverridevirtual

Reimplemented from NullMoist.

128  {
129  a_idx.clear();
130  a_names.clear();
131 
132  // NOTE: These are the indices to access into qmoist (not mic_fab_vars)
133  a_idx.push_back(0); a_names.push_back("RainAccum");
134  }

◆ Qmoist_Size()

int Kessler::Qmoist_Size ( )
inlineoverridevirtual

Reimplemented from NullMoist.

119 { return Kessler::m_qmoist_size; }

◆ Qstate_Moist_Size()

int Kessler::Qstate_Moist_Size ( )
inlineoverridevirtual

Reimplemented from NullMoist.

int n_qstate_moist_size
Definition: ERF_Kessler.H:141

◆ Set_dzmin()

void Kessler::Set_dzmin ( const amrex::Real  dz_min)
inlineoverridevirtual

Reimplemented from NullMoist.

75  {
76  m_dzmin = dz_min;
77  }

◆ Update_Micro_Vars()

void Kessler::Update_Micro_Vars ( amrex::MultiFab &  cons_in)
inlineoverridevirtual

Reimplemented from NullMoist.

90  {
91  this->Copy_State_to_Micro(cons_in);
92  }
void Copy_State_to_Micro(const amrex::MultiFab &cons_in) override
Definition: ERF_InitKessler.cpp:64
Here is the call graph for this function:

◆ Update_State_Vars()

void Kessler::Update_State_Vars ( amrex::MultiFab &  cons_in)
inlineoverridevirtual

Reimplemented from NullMoist.

97  {
98  this->Copy_Micro_to_State(cons_in);
99  }
void Copy_Micro_to_State(amrex::MultiFab &cons_in) override
Definition: ERF_UpdateKessler.cpp:14
Here is the call graph for this function:

Member Data Documentation

◆ CFL_MAX

constexpr amrex::Real Kessler::CFL_MAX = 0.5
staticconstexprprivate

◆ dt

amrex::Real Kessler::dt
private

Referenced by Advance().

◆ m_axis

int Kessler::m_axis
private

Referenced by Define().

◆ m_detJ_cc

amrex::MultiFab* Kessler::m_detJ_cc
private

◆ m_do_cond

bool Kessler::m_do_cond
private

Referenced by Define().

◆ m_dzmin

amrex::Real Kessler::m_dzmin
private

Referenced by Set_dzmin().

◆ m_fac_cond

amrex::Real Kessler::m_fac_cond
private

Referenced by Define().

◆ m_fac_fus

amrex::Real Kessler::m_fac_fus
private

Referenced by Define().

◆ m_fac_sub

amrex::Real Kessler::m_fac_sub
private

Referenced by Define().

◆ m_geom

amrex::Geometry Kessler::m_geom
private

◆ m_gtoe

amrex::BoxArray Kessler::m_gtoe
private

◆ m_qmoist_size

int Kessler::m_qmoist_size = 1
private

Referenced by Qmoist_Ptr(), and Qmoist_Size().

◆ m_z_phys_nd

amrex::MultiFab* Kessler::m_z_phys_nd
private

◆ mic_fab_vars

amrex::Array<FabPtr, MicVar_Kess::NumVars> Kessler::mic_fab_vars
private

Referenced by Qmoist_Ptr().

◆ MicVarMap

amrex::Vector<int> Kessler::MicVarMap
private

Referenced by Qmoist_Ptr().

◆ n_qstate_moist_size

int Kessler::n_qstate_moist_size = 3
private

Referenced by Qstate_Moist_Size().

◆ nlev

int Kessler::nlev
private

◆ zhi

int Kessler::zhi
private

◆ zlo

int Kessler::zlo
private

The documentation for this class was generated from the following files: