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

#include <ERF_SAM.H>

Inheritance diagram for SAM:
Collaboration diagram for SAM:

Public Member Functions

 SAM ()
 
virtual ~SAM ()=default
 
void Cloud (const SolverChoice &sc)
 
void IceFall (const SolverChoice &sc)
 
void Precip (const SolverChoice &sc)
 
void PrecipFall (const SolverChoice &sc)
 
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 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 &sc) override
 
amrex::MultiFab * Qmoist_Ptr (const int &varIdx) override
 
void Compute_Coefficients ()
 
int Qmoist_Size () override
 
int Qstate_Size () override
 
void Qmoist_Restart_Vars (const SolverChoice &a_sc, std::vector< int > &a_idx, std::vector< std::string > &a_names) const override
 
- Public Member Functions inherited from NullMoist
 NullMoist ()
 
virtual ~NullMoist ()=default
 

Static Public Member Functions

AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real NewtonIterSat (int &i, int &j, int &k, const int &SAM_moisture_type, const amrex::Real &fac_cond, const amrex::Real &fac_fus, const amrex::Real &fac_sub, const amrex::Real &an, const amrex::Real &bn, const amrex::Array4< amrex::Real > &tabs_array, const amrex::Array4< amrex::Real > &pres_array, const amrex::Array4< amrex::Real > &qv_array, const amrex::Array4< amrex::Real > &qc_array, const amrex::Array4< amrex::Real > &qi_array, const amrex::Array4< amrex::Real > &qn_array, const amrex::Array4< amrex::Real > &qt_array)
 

Private Types

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

Private Attributes

int m_qmoist_size = 11
 
int m_qstate_size = 6
 
amrex::Vector< int > MicVarMap
 
amrex::Geometry m_geom
 
amrex::BoxArray m_gtoe
 
amrex::Real dt
 
int nlev
 
int zlo
 
int zhi
 
int m_axis
 
bool docloud
 
bool doprecip
 
amrex::Real m_fac_cond
 
amrex::Real m_fac_fus
 
amrex::Real m_fac_sub
 
amrex::Real m_gOcp
 
amrex::Real m_rdOcp
 
amrex::MultiFab * m_z_phys_nd
 
amrex::MultiFab * m_detJ_cc
 
amrex::Array< FabPtr, MicVar::NumVarsmic_fab_vars
 
amrex::TableData< amrex::Real, 1 > accrrc
 
amrex::TableData< amrex::Real, 1 > accrsi
 
amrex::TableData< amrex::Real, 1 > accrsc
 
amrex::TableData< amrex::Real, 1 > coefice
 
amrex::TableData< amrex::Real, 1 > evaps1
 
amrex::TableData< amrex::Real, 1 > evaps2
 
amrex::TableData< amrex::Real, 1 > accrgi
 
amrex::TableData< amrex::Real, 1 > accrgc
 
amrex::TableData< amrex::Real, 1 > evapg1
 
amrex::TableData< amrex::Real, 1 > evapg2
 
amrex::TableData< amrex::Real, 1 > evapr1
 
amrex::TableData< amrex::Real, 1 > evapr2
 
amrex::TableData< amrex::Real, 1 > rho1d
 
amrex::TableData< amrex::Real, 1 > pres1d
 
amrex::TableData< amrex::Real, 1 > tabs1d
 
amrex::TableData< amrex::Real, 1 > qt1d
 
amrex::TableData< amrex::Real, 1 > qv1d
 
amrex::TableData< amrex::Real, 1 > qn1d
 
amrex::TableData< amrex::Real, 1 > gamaz
 
amrex::TableData< amrex::Real, 1 > zmid
 

Static Private Attributes

static constexpr amrex::Real CFL_MAX = 0.5
 

Member Typedef Documentation

◆ FabPtr

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

Constructor & Destructor Documentation

◆ SAM()

SAM::SAM ( )
inline
60 {}

◆ ~SAM()

virtual SAM::~SAM ( )
virtualdefault

Member Function Documentation

◆ Advance()

void SAM::Advance ( const amrex::Real &  dt_advance,
const SolverChoice sc 
)
inlineoverridevirtual

Reimplemented from NullMoist.

125  {
126  dt = dt_advance;
127 
128  this->Cloud(sc);
129  this->IceFall(sc);
130  this->Precip(sc);
131  this->PrecipFall(sc);
132  }
void Precip(const SolverChoice &sc)
Definition: ERF_Precip.cpp:10
void IceFall(const SolverChoice &sc)
Definition: ERF_IceFall.cpp:11
void Cloud(const SolverChoice &sc)
Definition: ERF_CloudSAM.cpp:12
void PrecipFall(const SolverChoice &sc)
Definition: ERF_PrecipFall.cpp:16
amrex::Real dt
Definition: ERF_SAM.H:302
Here is the call graph for this function:

◆ Cloud()

void SAM::Cloud ( const SolverChoice sc)

Split cloud components according to saturation pressures; source theta from latent heat.

13 {
14 
15  constexpr Real an = 1.0/(tbgmax-tbgmin);
16  constexpr Real bn = tbgmin*an;
17 
18  Real fac_cond = m_fac_cond;
19  Real fac_sub = m_fac_sub;
20  Real fac_fus = m_fac_fus;
21  Real rdOcp = m_rdOcp;
22 
23  int SAM_moisture_type = 1;
24  if (sc.moisture_type == MoistureType::SAM_NoIce ||
25  sc.moisture_type == MoistureType::SAM_NoPrecip_NoIce) {
26  SAM_moisture_type = 2;
27  }
28 
29  for ( MFIter mfi(*(mic_fab_vars[MicVar::tabs]), TilingIfNotGPU()); mfi.isValid(); ++mfi) {
30  auto qt_array = mic_fab_vars[MicVar::qt]->array(mfi);
31  auto qn_array = mic_fab_vars[MicVar::qn]->array(mfi);
32  auto qv_array = mic_fab_vars[MicVar::qv]->array(mfi);
33  auto qcl_array = mic_fab_vars[MicVar::qcl]->array(mfi);
34  auto qci_array = mic_fab_vars[MicVar::qci]->array(mfi);
35 
36  auto rho_array = mic_fab_vars[MicVar::rho]->array(mfi);
37  auto tabs_array = mic_fab_vars[MicVar::tabs]->array(mfi);
38  auto theta_array = mic_fab_vars[MicVar::theta]->array(mfi);
39  auto pres_array = mic_fab_vars[MicVar::pres]->array(mfi);
40 
41  const auto& box3d = mfi.tilebox();
42 
43  ParallelFor(box3d, [=] AMREX_GPU_DEVICE (int i, int j, int k)
44  {
45  // Saturation moisture fractions
46  Real omn;
47  Real qsat;
48  Real qsatw;
49  Real qsati;
50 
51  // Newton iteration vars
52  Real delta_qv, delta_qc, delta_qi;
53 
54  // NOTE: Conversion before iterations is necessary to
55  // convert cloud water to ice or vice versa.
56  // This ensures the omn splitting is enforced
57  // before the Newton iteration, which assumes it is.
58 
59  omn = 1.0;
60  if (SAM_moisture_type == 1){
61  // Cloud ice not permitted (melt to form water)
62  if (tabs_array(i,j,k) >= tbgmax) {
63  omn = 1.0;
64  delta_qi = qci_array(i,j,k);
65  qci_array(i,j,k) = 0.0;
66  qcl_array(i,j,k) += delta_qi;
67  tabs_array(i,j,k) -= fac_fus * delta_qi;
68  pres_array(i,j,k) = rho_array(i,j,k) * R_d * tabs_array(i,j,k)
69  * (1.0 + R_v/R_d * qv_array(i,j,k));
70  theta_array(i,j,k) = getThgivenPandT(tabs_array(i,j,k), pres_array(i,j,k), rdOcp);
71  pres_array(i,j,k) *= 0.01;
72  }
73  // Cloud water not permitted (freeze to form ice)
74  else if (tabs_array(i,j,k) <= tbgmin) {
75  omn = 0.0;
76  delta_qc = qcl_array(i,j,k);
77  qcl_array(i,j,k) = 0.0;
78  qci_array(i,j,k) += delta_qc;
79  tabs_array(i,j,k) += fac_fus * delta_qc;
80  pres_array(i,j,k) = rho_array(i,j,k) * R_d * tabs_array(i,j,k)
81  * (1.0 + R_v/R_d * qv_array(i,j,k));
82  theta_array(i,j,k) = getThgivenPandT(tabs_array(i,j,k), pres_array(i,j,k), rdOcp);
83  pres_array(i,j,k) *= 0.01;
84  }
85  // Mixed cloud phase (split according to omn)
86  else {
87  omn = an*tabs_array(i,j,k)-bn;
88  delta_qc = qcl_array(i,j,k) - qn_array(i,j,k) * omn;
89  delta_qi = qci_array(i,j,k) - qn_array(i,j,k) * (1.0 - omn);
90  qcl_array(i,j,k) = qn_array(i,j,k) * omn;
91  qci_array(i,j,k) = qn_array(i,j,k) * (1.0 - omn);
92  tabs_array(i,j,k) += fac_fus * delta_qc;
93  pres_array(i,j,k) = rho_array(i,j,k) * R_d * tabs_array(i,j,k)
94  * (1.0 + R_v/R_d * qv_array(i,j,k));
95  theta_array(i,j,k) = getThgivenPandT(tabs_array(i,j,k), pres_array(i,j,k), rdOcp);
96  pres_array(i,j,k) *= 0.01;
97  }
98  }
99  else if (SAM_moisture_type == 2)
100  {
101  // No ice. ie omn = 1.0
102  delta_qc = qcl_array(i,j,k) - qn_array(i,j,k);
103  delta_qi = 0.0;
104  qcl_array(i,j,k) = qn_array(i,j,k);
105  qci_array(i,j,k) = 0.0;
106  tabs_array(i,j,k) += fac_cond * delta_qc;
107  pres_array(i,j,k) = rho_array(i,j,k) * R_d * tabs_array(i,j,k)
108  * (1.0 + R_v/R_d * qv_array(i,j,k));
109  theta_array(i,j,k) = getThgivenPandT(tabs_array(i,j,k), pres_array(i,j,k), rdOcp);
110  pres_array(i,j,k) *= 0.01;
111  }
112 
113  // Saturation moisture fractions
114  erf_qsatw(tabs_array(i,j,k), pres_array(i,j,k), qsatw);
115  erf_qsati(tabs_array(i,j,k), pres_array(i,j,k), qsati);
116  qsat = omn * qsatw + (1.0-omn) * qsati;
117 
118  // We have enough total moisture to relax to equilibrium
119  if (qt_array(i,j,k) > qsat) {
120 
121  // Update temperature
122  tabs_array(i,j,k) = NewtonIterSat(i, j, k , SAM_moisture_type ,
123  fac_cond , fac_fus , fac_sub ,
124  an , bn ,
125  tabs_array, pres_array,
126  qv_array , qcl_array , qci_array,
127  qn_array , qt_array);
128 
129  // Update theta
130  theta_array(i,j,k) = getThgivenPandT(tabs_array(i,j,k), 100.0*pres_array(i,j,k), rdOcp);
131 
132  //
133  // We cannot blindly relax to qsat, but we can convert qc/qi -> qv.
134  // The concept here is that if we put all the moisture into qv and modify
135  // the temperature, we can then check if qv > qsat occurs (for final T/P/qv).
136  // If the reduction in T/qsat and increase in qv does trigger the
137  // aforementioned condition, we can do Newton iteration to drive qv = qsat.
138  //
139  } else {
140  // Changes in each component
141  delta_qv = qcl_array(i,j,k) + qci_array(i,j,k);
142  delta_qc = qcl_array(i,j,k);
143  delta_qi = qci_array(i,j,k);
144 
145  // Partition the change in non-precipitating q
146  qv_array(i,j,k) += delta_qv;
147  qcl_array(i,j,k) = 0.0;
148  qci_array(i,j,k) = 0.0;
149  qn_array(i,j,k) = 0.0;
150  qt_array(i,j,k) = qv_array(i,j,k);
151 
152  // Update temperature (endothermic since we evap/sublime)
153  tabs_array(i,j,k) -= fac_cond * delta_qc + fac_sub * delta_qi;
154 
155  // Update theta
156  theta_array(i,j,k) = getThgivenPandT(tabs_array(i,j,k), 100.0*pres_array(i,j,k), rdOcp);
157 
158  // Verify assumption that qv > qsat does not occur
159  erf_qsatw(tabs_array(i,j,k), pres_array(i,j,k), qsatw);
160  erf_qsati(tabs_array(i,j,k), pres_array(i,j,k), qsati);
161  qsat = omn * qsatw + (1.0-omn) * qsati;
162  if (qt_array(i,j,k) > qsat) {
163 
164  // Update temperature
165  tabs_array(i,j,k) = NewtonIterSat(i, j, k , SAM_moisture_type ,
166  fac_cond , fac_fus , fac_sub ,
167  an , bn ,
168  tabs_array, pres_array,
169  qv_array , qcl_array , qci_array,
170  qn_array , qt_array);
171 
172  // Update theta
173  theta_array(i,j,k) = getThgivenPandT(tabs_array(i,j,k), 100.0*pres_array(i,j,k), rdOcp);
174 
175  }
176  }
177  });
178  } // mfi
179 }
constexpr amrex::Real R_v
Definition: ERF_Constants.H:11
constexpr amrex::Real tbgmax
Definition: ERF_Constants.H:32
constexpr amrex::Real tbgmin
Definition: ERF_Constants.H:31
constexpr amrex::Real R_d
Definition: ERF_Constants.H:10
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getThgivenPandT(const amrex::Real T, const amrex::Real P, const amrex::Real rdOcp)
Definition: ERF_EOS.H:18
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsatw(amrex::Real t, amrex::Real p, amrex::Real &qsatw)
Definition: ERF_MicrophysicsUtils.H:158
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsati(amrex::Real t, amrex::Real p, amrex::Real &qsati)
Definition: ERF_MicrophysicsUtils.H:151
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real NewtonIterSat(int &i, int &j, int &k, const int &SAM_moisture_type, const amrex::Real &fac_cond, const amrex::Real &fac_fus, const amrex::Real &fac_sub, const amrex::Real &an, const amrex::Real &bn, const amrex::Array4< amrex::Real > &tabs_array, const amrex::Array4< amrex::Real > &pres_array, const amrex::Array4< amrex::Real > &qv_array, const amrex::Array4< amrex::Real > &qc_array, const amrex::Array4< amrex::Real > &qi_array, const amrex::Array4< amrex::Real > &qn_array, const amrex::Array4< amrex::Real > &qt_array)
Definition: ERF_SAM.H:153
amrex::Array< FabPtr, MicVar::NumVars > mic_fab_vars
Definition: ERF_SAM.H:325
amrex::Real m_rdOcp
Definition: ERF_SAM.H:318
amrex::Real m_fac_fus
Definition: ERF_SAM.H:315
amrex::Real m_fac_cond
Definition: ERF_SAM.H:314
amrex::Real m_fac_sub
Definition: ERF_SAM.H:316
@ pres
Definition: ERF_SAM.H:33
@ qci
Definition: ERF_SAM.H:39
@ qv
Definition: ERF_SAM.H:37
@ rho
Definition: ERF_SAM.H:30
@ qt
Definition: ERF_SAM.H:35
@ qn
Definition: ERF_SAM.H:36
@ theta
Definition: ERF_SAM.H:31
@ qcl
Definition: ERF_SAM.H:38
@ tabs
Definition: ERF_SAM.H:32
MoistureType moisture_type
Definition: ERF_DataStruct.H:664

Referenced by Advance().

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

◆ Compute_Coefficients()

void SAM::Compute_Coefficients ( )
141 {
142  auto dz = m_geom.CellSize(2);
143  auto lowz = m_geom.ProbLo(2);
144 
145  auto accrrc_t = accrrc.table();
146  auto accrsi_t = accrsi.table();
147  auto accrsc_t = accrsc.table();
148  auto coefice_t = coefice.table();
149  auto evaps1_t = evaps1.table();
150  auto evaps2_t = evaps2.table();
151  auto accrgi_t = accrgi.table();
152  auto accrgc_t = accrgc.table();
153  auto evapg1_t = evapg1.table();
154  auto evapg2_t = evapg2.table();
155  auto evapr1_t = evapr1.table();
156  auto evapr2_t = evapr2.table();
157 
158  auto rho1d_t = rho1d.table();
159  auto pres1d_t = pres1d.table();
160  auto tabs1d_t = tabs1d.table();
161 
162  auto gamaz_t = gamaz.table();
163  auto zmid_t = zmid.table();
164 
165  Real gam3 = erf_gammafff(3.0 );
166  Real gamr1 = erf_gammafff(3.0+b_rain );
167  Real gamr2 = erf_gammafff((5.0+b_rain)/2.0);
168  Real gams1 = erf_gammafff(3.0+b_snow );
169  Real gams2 = erf_gammafff((5.0+b_snow)/2.0);
170  Real gamg1 = erf_gammafff(3.0+b_grau );
171  Real gamg2 = erf_gammafff((5.0+b_grau)/2.0);
172 
173  // calculate the plane average variables
177  rho_ave.compute_averages(ZDir(), rho_ave.field());
178  theta_ave.compute_averages(ZDir(), theta_ave.field());
179  qv_ave.compute_averages(ZDir(), qv_ave.field());
180 
181  // get host variable rho, and rhotheta
182  int ncell = rho_ave.ncell_line();
183 
184  Gpu::HostVector<Real> rho_h(ncell), theta_h(ncell), qv_h(ncell);
185  rho_ave.line_average(0, rho_h);
186  theta_ave.line_average(0, theta_h);
187  qv_ave.line_average(0, qv_h);
188 
189  // copy data to device
190  Gpu::DeviceVector<Real> rho_d(ncell), theta_d(ncell), qv_d(ncell);
191  Gpu::copyAsync(Gpu::hostToDevice, rho_h.begin(), rho_h.end(), rho_d.begin());
192  Gpu::copyAsync(Gpu::hostToDevice, theta_h.begin(), theta_h.end(), theta_d.begin());
193  Gpu::copyAsync(Gpu::hostToDevice, qv_h.begin(), qv_h.end(), qv_d.begin());
194  Gpu::streamSynchronize();
195 
196  Real* rho_dptr = rho_d.data();
197  Real* theta_dptr = theta_d.data();
198  Real* qv_dptr = qv_d.data();
199 
200  Real gOcp = m_gOcp;
201 
202  ParallelFor(nlev, [=] AMREX_GPU_DEVICE (int k) noexcept
203  {
204  Real RhoTheta = rho_dptr[k]*theta_dptr[k];
205  Real pressure = getPgivenRTh(RhoTheta, qv_dptr[k]);
206  rho1d_t(k) = rho_dptr[k];
207  pres1d_t(k) = pressure*0.01;
208  // NOTE: Limit the temperature to the melting point of ice to avoid a divide by
209  // 0 condition when computing the cold evaporation coefficients. This should
210  // not affect results since evporation requires snow/graupel to be present
211  // and thus T<273.16
212  tabs1d_t(k) = std::min(getTgivenRandRTh(rho_dptr[k], RhoTheta, qv_dptr[k]),273.16);
213  zmid_t(k) = lowz + (k+0.5)*dz;
214  gamaz_t(k) = gOcp*zmid_t(k);
215  });
216 
217  if(round(gam3) != 2) {
218  std::cout << "cannot compute gamma-function in Microphysics::Init" << std::endl;
219  std::exit(-1);
220  }
221 
222  // Populate all the coefficients
223  ParallelFor(nlev, [=] AMREX_GPU_DEVICE (int k) noexcept
224  {
225  Real Prefactor;
226  Real pratio = sqrt(1.29 / rho1d_t(k));
227  //Real rrr1 = 393.0/(tabs1d_t(k)+120.0)*std::pow((tabs1d_t(k)/273.0),1.5);
228  //Real rrr2 = std::pow((tabs1d_t(k)/273.0),1.94)*(1000.0/pres1d_t(k));
229  Real estw = 100.0*erf_esatw(tabs1d_t(k));
230  Real esti = 100.0*erf_esati(tabs1d_t(k));
231 
232  // accretion by snow:
233  Real coef1 = 0.25 * PI * nzeros * a_snow * gams1 * pratio/pow((PI * rhos * nzeros/rho1d_t(k) ) , ((3.0+b_snow)/4.0));
234  Real coef2 = exp(0.025*(tabs1d_t(k) - 273.15));
235  accrsi_t(k) = coef1 * coef2 * esicoef;
236  accrsc_t(k) = coef1 * esccoef;
237  coefice_t(k) = coef2;
238 
239  // evaporation of snow:
240  coef1 = (lsub/(tabs1d_t(k)*R_v)-1.0)*lsub/(therco*tabs1d_t(k));
241  coef2 = R_v * R_d / (diffelq * esti);
242  Prefactor = 2.0 * PI * nzeros / (rho1d_t(k) * (coef1 + coef2));
243  Prefactor *= (2.0/PI); // Shape factor snow
244  evaps1_t(k) = Prefactor * 0.65 * sqrt(rho1d_t(k) / (PI * rhos * nzeros));
245  evaps2_t(k) = Prefactor * 0.44 * sqrt(a_snow * rho1d_t(k) / muelq) * gams2
246  * sqrt(pratio) * pow(rho1d_t(k) / (PI * rhos * nzeros) , ((5.0+b_snow)/8.0));
247 
248  // accretion by graupel:
249  coef1 = 0.25*PI*nzerog*a_grau*gamg1*pratio/pow((PI*rhog*nzerog/rho1d_t(k)) , ((3.0+b_grau)/4.0));
250  coef2 = exp(0.025*(tabs1d_t(k) - 273.15));
251  accrgi_t(k) = coef1 * coef2 * egicoef;
252  accrgc_t(k) = coef1 * egccoef;
253 
254  // evaporation of graupel:
255  coef1 = (lsub/(tabs1d_t(k)*R_v)-1.0)*lsub/(therco*tabs1d_t(k));
256  coef2 = R_v * R_d / (diffelq * esti);
257  Prefactor = 2.0 * PI * nzerog / (rho1d_t(k) * (coef1 + coef2)); // Shape factor for graupel is 1
258  evapg1_t(k) = Prefactor * 0.78 * sqrt(rho1d_t(k) / (PI * rhog * nzerog));
259  evapg2_t(k) = Prefactor * 0.31 * sqrt(a_grau * rho1d_t(k) / muelq) * gamg2
260  * sqrt(pratio) * pow(rho1d_t(k) / (PI * rhog * nzerog) , ((5.0+b_grau)/8.0));
261 
262  // accretion by rain:
263  accrrc_t(k) = 0.25 * PI * nzeror * a_rain * gamr1 * pratio/pow((PI * rhor * nzeror / rho1d_t(k)) , ((3.0+b_rain)/4.))* erccoef;
264 
265  // evaporation of rain:
266  coef1 = (lcond/(tabs1d_t(k)*R_v)-1.0)*lcond/(therco*tabs1d_t(k));
267  coef2 = R_v * R_d / (diffelq * estw);
268  Prefactor = 2.0 * PI * nzeror / (rho1d_t(k) * (coef1 + coef2)); // Shape factor for rain is 1
269  evapr1_t(k) = Prefactor * 0.78 * sqrt(rho1d_t(k) / (PI * rhor * nzeror));
270  evapr2_t(k) = Prefactor * 0.31 * sqrt(a_rain * rho1d_t(k) / muelq) * gamr2
271  * sqrt(pratio) * pow(rho1d_t(k) / (PI * rhor * nzeror) , ((5.0+b_rain)/8.0));
272  });
273 }
constexpr amrex::Real rhog
Definition: ERF_Constants.H:30
constexpr amrex::Real muelq
Definition: ERF_Constants.H:75
constexpr amrex::Real nzerog
Definition: ERF_Constants.H:59
constexpr amrex::Real a_grau
Definition: ERF_Constants.H:42
constexpr amrex::Real lsub
Definition: ERF_Constants.H:68
constexpr amrex::Real esicoef
Definition: ERF_Constants.H:53
constexpr amrex::Real diffelq
Definition: ERF_Constants.H:73
constexpr amrex::Real therco
Definition: ERF_Constants.H:74
constexpr amrex::Real b_grau
Definition: ERF_Constants.H:43
constexpr amrex::Real egccoef
Definition: ERF_Constants.H:54
constexpr amrex::Real egicoef
Definition: ERF_Constants.H:55
constexpr amrex::Real b_rain
Definition: ERF_Constants.H:39
constexpr amrex::Real lcond
Definition: ERF_Constants.H:66
constexpr amrex::Real PI
Definition: ERF_Constants.H:6
constexpr amrex::Real nzeror
Definition: ERF_Constants.H:57
constexpr amrex::Real rhos
Definition: ERF_Constants.H:29
constexpr amrex::Real esccoef
Definition: ERF_Constants.H:52
constexpr amrex::Real rhor
Definition: ERF_Constants.H:28
constexpr amrex::Real a_rain
Definition: ERF_Constants.H:38
constexpr amrex::Real nzeros
Definition: ERF_Constants.H:58
constexpr amrex::Real a_snow
Definition: ERF_Constants.H:40
constexpr amrex::Real b_snow
Definition: ERF_Constants.H:41
constexpr amrex::Real erccoef
Definition: ERF_Constants.H:51
DirectionSelector< 2 > ZDir
Definition: ERF_DirectionSelector.H:38
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=0.)
Definition: ERF_EOS.H:84
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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:64
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esati(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:24
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_gammafff(amrex::Real x)
Definition: ERF_MicrophysicsUtils.H:15
Definition: ERF_PlaneAverage.H:14
amrex::TableData< amrex::Real, 1 > rho1d
Definition: ERF_SAM.H:342
amrex::TableData< amrex::Real, 1 > evapr2
Definition: ERF_SAM.H:339
amrex::TableData< amrex::Real, 1 > evapg1
Definition: ERF_SAM.H:336
amrex::TableData< amrex::Real, 1 > accrgi
Definition: ERF_SAM.H:334
amrex::TableData< amrex::Real, 1 > evapg2
Definition: ERF_SAM.H:337
int m_axis
Definition: ERF_SAM.H:308
amrex::Real m_gOcp
Definition: ERF_SAM.H:317
amrex::TableData< amrex::Real, 1 > evaps1
Definition: ERF_SAM.H:332
amrex::TableData< amrex::Real, 1 > zmid
Definition: ERF_SAM.H:350
amrex::TableData< amrex::Real, 1 > accrsi
Definition: ERF_SAM.H:329
amrex::TableData< amrex::Real, 1 > accrrc
Definition: ERF_SAM.H:328
amrex::TableData< amrex::Real, 1 > pres1d
Definition: ERF_SAM.H:343
int nlev
Definition: ERF_SAM.H:305
amrex::Geometry m_geom
Definition: ERF_SAM.H:296
amrex::TableData< amrex::Real, 1 > evapr1
Definition: ERF_SAM.H:338
amrex::TableData< amrex::Real, 1 > evaps2
Definition: ERF_SAM.H:333
amrex::TableData< amrex::Real, 1 > accrgc
Definition: ERF_SAM.H:335
amrex::TableData< amrex::Real, 1 > accrsc
Definition: ERF_SAM.H:330
amrex::TableData< amrex::Real, 1 > coefice
Definition: ERF_SAM.H:331
amrex::TableData< amrex::Real, 1 > tabs1d
Definition: ERF_SAM.H:344
amrex::TableData< amrex::Real, 1 > gamaz
Definition: ERF_SAM.H:349

Referenced by Update_Micro_Vars().

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

◆ Copy_Micro_to_State()

void SAM::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.

16 {
17  // Get the temperature, density, theta, qt and qp from input
18  for ( MFIter mfi(cons,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
19  const auto& box3d = mfi.tilebox();
20 
21  auto states_arr = cons.array(mfi);
22 
23  auto rho_arr = mic_fab_vars[MicVar::rho]->array(mfi);
24  auto theta_arr = mic_fab_vars[MicVar::theta]->array(mfi);
25 
26  auto qv_arr = mic_fab_vars[MicVar::qv]->array(mfi);
27  auto qc_arr = mic_fab_vars[MicVar::qcl]->array(mfi);
28  auto qi_arr = mic_fab_vars[MicVar::qci]->array(mfi);
29 
30  auto qpr_arr = mic_fab_vars[MicVar::qpr]->array(mfi);
31  auto qps_arr = mic_fab_vars[MicVar::qps]->array(mfi);
32  auto qpg_arr = mic_fab_vars[MicVar::qpg]->array(mfi);
33 
34  // get potential total density, temperature, qt, qp
35  ParallelFor( box3d, [=] AMREX_GPU_DEVICE (int i, int j, int k)
36  {
37  states_arr(i,j,k,RhoTheta_comp) = rho_arr(i,j,k)*theta_arr(i,j,k);
38 
39  states_arr(i,j,k,RhoQ1_comp) = rho_arr(i,j,k)*std::max(0.0,qv_arr(i,j,k));
40  states_arr(i,j,k,RhoQ2_comp) = rho_arr(i,j,k)*std::max(0.0,qc_arr(i,j,k));
41  states_arr(i,j,k,RhoQ3_comp) = rho_arr(i,j,k)*std::max(0.0,qi_arr(i,j,k));
42 
43  states_arr(i,j,k,RhoQ4_comp) = rho_arr(i,j,k)*std::max(0.0,qpr_arr(i,j,k));
44  states_arr(i,j,k,RhoQ5_comp) = rho_arr(i,j,k)*std::max(0.0,qps_arr(i,j,k));
45  states_arr(i,j,k,RhoQ6_comp) = rho_arr(i,j,k)*std::max(0.0,qpg_arr(i,j,k));
46  });
47  }
48 
49  // Fill interior ghost cells and periodic boundaries
50  cons.FillBoundary(m_geom.periodicity());
51 }
#define RhoQ4_comp
Definition: ERF_IndexDefines.H:45
#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
#define RhoQ6_comp
Definition: ERF_IndexDefines.H:47
#define RhoQ5_comp
Definition: ERF_IndexDefines.H:46
@ qpr
Definition: ERF_SAM.H:42
@ qpg
Definition: ERF_SAM.H:44
@ qps
Definition: ERF_SAM.H:43
@ cons
Definition: ERF_IndexDefines.H:129

Referenced by Update_State_Vars().

Here is the caller graph for this function:

◆ Copy_State_to_Micro()

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

Initializes the Microphysics module.

Parameters
[in]cons_inConserved variables input

Reimplemented from NullMoist.

89 {
90  // Get the temperature, density, theta, qt and qp from input
91  for ( MFIter mfi(cons_in); mfi.isValid(); ++mfi) {
92  const auto& box3d = mfi.growntilebox();
93 
94  auto states_array = cons_in.array(mfi);
95 
96  // Non-precipitating
97  auto qv_array = mic_fab_vars[MicVar::qv]->array(mfi);
98  auto qc_array = mic_fab_vars[MicVar::qcl]->array(mfi);
99  auto qi_array = mic_fab_vars[MicVar::qci]->array(mfi);
100  auto qn_array = mic_fab_vars[MicVar::qn]->array(mfi);
101  auto qt_array = mic_fab_vars[MicVar::qt]->array(mfi);
102 
103  // Precipitating
104  auto qpr_array = mic_fab_vars[MicVar::qpr]->array(mfi);
105  auto qps_array = mic_fab_vars[MicVar::qps]->array(mfi);
106  auto qpg_array = mic_fab_vars[MicVar::qpg]->array(mfi);
107  auto qp_array = mic_fab_vars[MicVar::qp]->array(mfi);
108 
109  auto rho_array = mic_fab_vars[MicVar::rho]->array(mfi);
110  auto theta_array = mic_fab_vars[MicVar::theta]->array(mfi);
111  auto tabs_array = mic_fab_vars[MicVar::tabs]->array(mfi);
112  auto pres_array = mic_fab_vars[MicVar::pres]->array(mfi);
113 
114  // Get pressure, theta, temperature, density, and qt, qp
115  ParallelFor( box3d, [=] AMREX_GPU_DEVICE (int i, int j, int k)
116  {
117  rho_array(i,j,k) = states_array(i,j,k,Rho_comp);
118  theta_array(i,j,k) = states_array(i,j,k,RhoTheta_comp)/states_array(i,j,k,Rho_comp);
119 
120  qv_array(i,j,k) = std::max(0.0,states_array(i,j,k,RhoQ1_comp)/states_array(i,j,k,Rho_comp));
121  qc_array(i,j,k) = std::max(0.0,states_array(i,j,k,RhoQ2_comp)/states_array(i,j,k,Rho_comp));
122  qi_array(i,j,k) = std::max(0.0,states_array(i,j,k,RhoQ3_comp)/states_array(i,j,k,Rho_comp));
123  qn_array(i,j,k) = qc_array(i,j,k) + qi_array(i,j,k);
124  qt_array(i,j,k) = qv_array(i,j,k) + qn_array(i,j,k);
125 
126  qpr_array(i,j,k) = std::max(0.0,states_array(i,j,k,RhoQ4_comp)/states_array(i,j,k,Rho_comp));
127  qps_array(i,j,k) = std::max(0.0,states_array(i,j,k,RhoQ5_comp)/states_array(i,j,k,Rho_comp));
128  qpg_array(i,j,k) = std::max(0.0,states_array(i,j,k,RhoQ6_comp)/states_array(i,j,k,Rho_comp));
129  qp_array(i,j,k) = qpr_array(i,j,k) + qps_array(i,j,k) + qpg_array(i,j,k);
130 
131  tabs_array(i,j,k) = getTgivenRandRTh(states_array(i,j,k,Rho_comp),
132  states_array(i,j,k,RhoTheta_comp),
133  qv_array(i,j,k));
134  pres_array(i,j,k) = getPgivenRTh(states_array(i,j,k,RhoTheta_comp), qv_array(i,j,k)) * 0.01;
135  });
136  }
137 }
#define Rho_comp
Definition: ERF_IndexDefines.H:36
@ qp
Definition: ERF_SAM.H:41

Referenced by Update_Micro_Vars().

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

◆ Define()

void SAM::Define ( SolverChoice sc)
inlineoverridevirtual

Reimplemented from NullMoist.

80  {
81  docloud = sc.do_cloud;
82  doprecip = sc.do_precip;
83  m_fac_cond = lcond / sc.c_p;
84  m_fac_fus = lfus / sc.c_p;
85  m_fac_sub = lsub / sc.c_p;
86  m_gOcp = CONST_GRAV / sc.c_p;
87  m_axis = sc.ave_plane;
88  m_rdOcp = sc.rdOcp;
89  }
constexpr amrex::Real lfus
Definition: ERF_Constants.H:67
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:21
bool doprecip
Definition: ERF_SAM.H:311
bool docloud
Definition: ERF_SAM.H:311
amrex::Real rdOcp
Definition: ERF_DataStruct.H:619
amrex::Real c_p
Definition: ERF_DataStruct.H:618
bool do_precip
Definition: ERF_DataStruct.H:678
bool do_cloud
Definition: ERF_DataStruct.H:677
int ave_plane
Definition: ERF_DataStruct.H:675

◆ IceFall()

void SAM::IceFall ( const SolverChoice sc)

Sedimentation of cloud ice (A32)

11  {
12 
13  if(sc.moisture_type == MoistureType::SAM_NoIce ||
14  sc.moisture_type == MoistureType::SAM_NoPrecip_NoIce)
15  return;
16 
17  Real dz = m_geom.CellSize(2);
18  Real dtn = dt;
19  Real coef = dtn/dz;
20 
21  auto domain = m_geom.Domain();
22  int k_lo = domain.smallEnd(2);
23  int k_hi = domain.bigEnd(2);
24 
27  auto qn = mic_fab_vars[MicVar::qn];
28  auto qt = mic_fab_vars[MicVar::qt];
31 
32  MultiFab fz;
33  IntVect ng = qcl->nGrowVect();
34  BoxArray ba = qcl->boxArray();
35  DistributionMapping dm = qcl->DistributionMap();
36  fz.define(convert(ba, IntVect(0,0,1)), dm, 1, ng);
37  fz.setVal(0.);
38 
39  for (MFIter mfi(fz, TileNoZ()); mfi.isValid(); ++mfi) {
40  auto qci_array = qci->array(mfi);
41  auto rho_array = rho->array(mfi);
42  auto fz_array = fz.array(mfi);
43 
44  const auto& box3d = mfi.tilebox();
45 
46  ParallelFor(box3d, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
47  {
48  Real rho_avg, qci_avg;
49  if (k==k_lo) {
50  rho_avg = rho_array(i,j,k);
51  qci_avg = qci_array(i,j,k);
52  } else if (k==k_hi+1) {
53  rho_avg = rho_array(i,j,k-1);
54  qci_avg = qci_array(i,j,k-1);
55  } else {
56  rho_avg = 0.5*(rho_array(i,j,k-1) + rho_array(i,j,k));
57  qci_avg = 0.5*(qci_array(i,j,k-1) + qci_array(i,j,k));
58  }
59  Real vt_ice = min( 0.4 , 8.66 * pow( (std::max(0.,qci_avg)+1.e-10) , 0.24) );
60 
61  // NOTE: Fz is the sedimentation flux from the advective operator.
62  // In the terrain-following coordinate system, the z-deriv in
63  // the divergence uses the normal velocity (Omega). However,
64  // there are no u/v components to the sedimentation velocity.
65  // Therefore, we simply end up with a division by detJ when
66  // evaluating the source term: dJinv * (flux_hi - flux_lo) * dzinv.
67  fz_array(i,j,k) = rho_avg*vt_ice*qci_avg;
68  });
69  }
70 
71  // Compute number of substeps from maximum terminal velocity
72  Real wt_max;
73  int n_substep;
74  auto const& ma_fz_arr = fz.const_arrays();
75  GpuTuple<Real> max = ParReduce(TypeList<ReduceOpMax>{},
76  TypeList<Real>{},
77  fz, IntVect(0),
78  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) noexcept
79  -> GpuTuple<Real>
80  {
81  return { ma_fz_arr[box_no](i,j,k) };
82  });
83  wt_max = get<0>(max) + std::numeric_limits<Real>::epsilon();
84  n_substep = int( std::ceil(wt_max * coef / CFL_MAX) );
85  AMREX_ALWAYS_ASSERT(n_substep >= 1);
86  coef /= Real(n_substep);
87  dtn /= Real(n_substep);
88 
89  // Substep the vertical advection
90  for (int nsub(0); nsub<n_substep; ++nsub) {
91  for (MFIter mfi(*qci, TileNoZ()); mfi.isValid(); ++mfi) {
92  auto qci_array = qci->array(mfi);
93  auto qn_array = qn->array(mfi);
94  auto qt_array = qt->array(mfi);
95  auto rho_array = rho->array(mfi);
96  auto fz_array = fz.array(mfi);
97 
98  const auto dJ_array = (m_detJ_cc) ? m_detJ_cc->const_array(mfi) : Array4<const Real>{};
99 
100  const auto& tbx = mfi.tilebox();
101  const auto& tbz = mfi.tilebox(IntVect(0,0,1),IntVect(0));
102 
103  // Update vertical flux every substep
104  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
105  {
106  Real rho_avg, qci_avg;
107  if (k==k_lo) {
108  rho_avg = rho_array(i,j,k);
109  qci_avg = qci_array(i,j,k);
110  } else if (k==k_hi+1) {
111  rho_avg = rho_array(i,j,k-1);
112  qci_avg = qci_array(i,j,k-1);
113  } else {
114  rho_avg = 0.5*(rho_array(i,j,k-1) + rho_array(i,j,k));
115  qci_avg = 0.5*(qci_array(i,j,k-1) + qci_array(i,j,k));
116  }
117  Real vt_ice = min( 0.4 , 8.66 * pow( (std::max(0.,qci_avg)+1.e-10) , 0.24) );
118 
119  // NOTE: Fz is the sedimentation flux from the advective operator.
120  // In the terrain-following coordinate system, the z-deriv in
121  // the divergence uses the normal velocity (Omega). However,
122  // there are no u/v components to the sedimentation velocity.
123  // Therefore, we simply end up with a division by detJ when
124  // evaluating the source term: dJinv * (flux_hi - flux_lo) * dzinv.
125  fz_array(i,j,k) = rho_avg*vt_ice*qci_avg;
126  });
127 
128  // Update precip every substep
129  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
130  {
131  // Jacobian determinant
132  Real dJinv = (dJ_array) ? 1.0/dJ_array(i,j,k) : 1.0;
133 
134  //==================================================
135  // Cloud ice sedimentation (A32)
136  //==================================================
137  Real dqi = dJinv * (1.0/rho_array(i,j,k)) * ( fz_array(i,j,k+1) - fz_array(i,j,k) ) * coef;
138  dqi = std::max(-qci_array(i,j,k), dqi);
139 
140  // Add this increment to both non-precipitating and total water.
141  qci_array(i,j,k) += dqi;
142  qn_array(i,j,k) += dqi;
143  qt_array(i,j,k) += dqi;
144 
145  // NOTE: Sedimentation does not affect the potential temperature,
146  // but it does affect the liquid/ice static energy.
147  // No source to Theta occurs here.
148  });
149  } // mfi
150  } // nsub
151 }
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
amrex::MultiFab * m_detJ_cc
Definition: ERF_SAM.H:322
static constexpr amrex::Real CFL_MAX
Definition: ERF_SAM.H:290
@ qcl
Definition: ERF_Kessler.H:37
@ tabs
Definition: ERF_Kessler.H:32
@ rho
Definition: ERF_Kessler.H:30
@ qt
Definition: ERF_Kessler.H:35

Referenced by Advance().

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

◆ Init()

void SAM::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.

28 {
29  dt = dt_advance;
30  m_geom = geom;
31  m_gtoe = grids;
32 
33  m_z_phys_nd = z_phys_nd.get();
34  m_detJ_cc = detJ_cc.get();
35 
36  MicVarMap.resize(m_qmoist_size);
39 
40  // initialize microphysics variables
41  for (auto ivar = 0; ivar < MicVar::NumVars; ++ivar) {
42  mic_fab_vars[ivar] = std::make_shared<MultiFab>(cons_in.boxArray(), cons_in.DistributionMap(),
43  1, cons_in.nGrowVect());
44  mic_fab_vars[ivar]->setVal(0.);
45  }
46 
47  // Set class data members
48  for ( MFIter mfi(cons_in, TileNoZ()); mfi.isValid(); ++mfi) {
49  const auto& box3d = mfi.tilebox();
50 
51  const auto& lo = lbound(box3d);
52  const auto& hi = ubound(box3d);
53 
54  nlev = box3d.length(2);
55  zlo = lo.z;
56  zhi = hi.z;
57 
58  // parameters
59  accrrc.resize({zlo}, {zhi});
60  accrsi.resize({zlo}, {zhi});
61  accrsc.resize({zlo}, {zhi});
62  coefice.resize({zlo}, {zhi});
63  evaps1.resize({zlo}, {zhi});
64  evaps2.resize({zlo}, {zhi});
65  accrgi.resize({zlo}, {zhi});
66  accrgc.resize({zlo}, {zhi});
67  evapg1.resize({zlo}, {zhi});
68  evapg2.resize({zlo}, {zhi});
69  evapr1.resize({zlo}, {zhi});
70  evapr2.resize({zlo}, {zhi});
71 
72  // data (input)
73  rho1d.resize({zlo}, {zhi});
74  pres1d.resize({zlo}, {zhi});
75  tabs1d.resize({zlo}, {zhi});
76  gamaz.resize({zlo}, {zhi});
77  zmid.resize({zlo}, {zhi});
78  }
79 }
int zlo
Definition: ERF_SAM.H:305
int m_qmoist_size
Definition: ERF_SAM.H:284
amrex::MultiFab * m_z_phys_nd
Definition: ERF_SAM.H:321
amrex::BoxArray m_gtoe
Definition: ERF_SAM.H:299
amrex::Vector< int > MicVarMap
Definition: ERF_SAM.H:293
int zhi
Definition: ERF_SAM.H:305
@ NumVars
Definition: ERF_SAM.H:50
@ snow_accum
Definition: ERF_SAM.H:47
@ rain_accum
Definition: ERF_SAM.H:46
@ graup_accum
Definition: ERF_SAM.H:48
Here is the call graph for this function:

◆ NewtonIterSat()

AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real SAM::NewtonIterSat ( int &  i,
int &  j,
int &  k,
const int &  SAM_moisture_type,
const amrex::Real &  fac_cond,
const amrex::Real &  fac_fus,
const amrex::Real &  fac_sub,
const amrex::Real &  an,
const amrex::Real &  bn,
const amrex::Array4< amrex::Real > &  tabs_array,
const amrex::Array4< amrex::Real > &  pres_array,
const amrex::Array4< amrex::Real > &  qv_array,
const amrex::Array4< amrex::Real > &  qc_array,
const amrex::Array4< amrex::Real > &  qi_array,
const amrex::Array4< amrex::Real > &  qn_array,
const amrex::Array4< amrex::Real > &  qt_array 
)
inlinestatic
167  {
168  // Solution tolerance
169  amrex::Real tol = 1.0e-4;
170 
171  // Saturation moisture fractions
172  amrex::Real omn, domn;
173  amrex::Real qsat, dqsat;
174  amrex::Real qsatw, dqsatw;
175  amrex::Real qsati, dqsati;
176 
177  // Newton iteration vars
178  int niter;
179  amrex::Real fff, dfff, dtabs;
180  amrex::Real lstar, dlstar;
181  amrex::Real lstarw, lstari;
182  amrex::Real delta_qv, delta_qc, delta_qi;
183 
184  // Initial guess for temperature & pressure
185  amrex::Real tabs = tabs_array(i,j,k);
186  amrex::Real pres = pres_array(i,j,k);
187 
188  niter = 0;
189  dtabs = 1;
190  //==================================================
191  // Newton iteration to qv=qsat (cloud phase only)
192  //==================================================
193  do {
194  // Latent heats and their derivatives wrt to T
195  lstarw = fac_cond;
196  lstari = fac_fus;
197  domn = 0.0;
198 
199  // Saturation moisture fractions
200  erf_qsatw(tabs, pres, qsatw);
201  erf_qsati(tabs, pres, qsati);
202  erf_dtqsatw(tabs, pres, dqsatw);
203  erf_dtqsati(tabs, pres, dqsati);
204 
205  if (SAM_moisture_type == 1) {
206  // Cloud ice not permitted (condensation & fusion)
207  if(tabs >= tbgmax) {
208  omn = 1.0;
209  }
210  // Cloud water not permitted (sublimation & fusion)
211  else if(tabs <= tbgmin) {
212  omn = 0.0;
213  lstarw = fac_sub;
214  }
215  // Mixed cloud phase (condensation & fusion)
216  else {
217  omn = an*tabs-bn;
218  domn = an;
219  }
220  } else if (SAM_moisture_type == 2) {
221  omn = 1.0;
222  domn = 0.0;
223  }
224 
225  // Linear combination of each component
226  qsat = omn * qsatw + (1.0-omn) * qsati;
227  dqsat = omn * dqsatw + (1.0-omn) * dqsati
228  + domn * qsatw - domn * qsati;
229  lstar = omn * lstarw + (1.0-omn) * lstari;
230  dlstar = domn * lstarw - domn * lstari;
231 
232  // Function for root finding:
233  // 0 = -T_new + T_old + L_eff/C_p * (qv - qsat)
234  fff = -tabs + tabs_array(i,j,k) + lstar*(qv_array(i,j,k) - qsat);
235 
236  // Derivative of function (T_new iterated on)
237  dfff = -1.0 + dlstar*(qv_array(i,j,k) - qsat) - lstar*dqsat;
238 
239  // Update the temperature
240  dtabs = -fff/dfff;
241  tabs += dtabs;
242 
243  // Update iteration
244  niter = niter+1;
245  } while(std::abs(dtabs) > tol && niter < 20);
246 
247  // Update qsat from last iteration (dq = dq/dt * dt)
248  qsat += dqsat*dtabs;
249 
250  // Changes in each component
251  delta_qv = qv_array(i,j,k) - qsat;
252  delta_qc = std::max(-qc_array(i,j,k), delta_qv * omn);
253  delta_qi = std::max(-qi_array(i,j,k), delta_qv * (1.0-omn));
254 
255  // Partition the change in non-precipitating q
256  qv_array(i,j,k) = qsat;
257  qc_array(i,j,k) += delta_qc;
258  qi_array(i,j,k) += delta_qi;
259  qn_array(i,j,k) = qc_array(i,j,k) + qi_array(i,j,k);
260  qt_array(i,j,k) = qv_array(i,j,k) + qn_array(i,j,k);
261 
262  // Return to temperature
263  return tabs;
264  }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_dtqsatw(amrex::Real t, amrex::Real p, amrex::Real &dtqsatw)
Definition: ERF_MicrophysicsUtils.H:170
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_dtqsati(amrex::Real t, amrex::Real p, amrex::Real &dtqsati)
Definition: ERF_MicrophysicsUtils.H:165
Here is the call graph for this function:

◆ Precip()

void SAM::Precip ( const SolverChoice sc)

Autoconversion (A30), Accretion (A28), Evaporation (A24)

11 {
12 
13  if (sc.moisture_type == MoistureType::SAM_NoPrecip_NoIce) return;
14 
15  Real powr1 = (3.0 + b_rain) / 4.0;
16  Real powr2 = (5.0 + b_rain) / 8.0;
17  Real pows1 = (3.0 + b_snow) / 4.0;
18  Real pows2 = (5.0 + b_snow) / 8.0;
19  Real powg1 = (3.0 + b_grau) / 4.0;
20  Real powg2 = (5.0 + b_grau) / 8.0;
21 
22  auto accrrc_t = accrrc.table();
23  auto accrsc_t = accrsc.table();
24  auto accrsi_t = accrsi.table();
25  auto accrgc_t = accrgc.table();
26  auto accrgi_t = accrgi.table();
27  auto coefice_t = coefice.table();
28  auto evapr1_t = evapr1.table();
29  auto evapr2_t = evapr2.table();
30  auto evaps1_t = evaps1.table();
31  auto evaps2_t = evaps2.table();
32  auto evapg1_t = evapg1.table();
33  auto evapg2_t = evapg2.table();
34 
35  Real fac_cond = m_fac_cond;
36  Real fac_sub = m_fac_sub;
37  Real fac_fus = m_fac_fus;
38  Real rdOcp = m_rdOcp;
39 
40  Real eps = std::numeric_limits<Real>::epsilon();
41 
42  Real dtn = dt;
43 
44  int SAM_moisture_type = 1;
45  if (sc.moisture_type == MoistureType::SAM_NoIce) {
46  SAM_moisture_type = 2;
47  }
48 
49  // get the temperature, dentisy, theta, qt and qp from input
50  for ( MFIter mfi(*(mic_fab_vars[MicVar::tabs]),TilingIfNotGPU()); mfi.isValid(); ++mfi) {
51  auto theta_array = mic_fab_vars[MicVar::theta]->array(mfi);
52  auto tabs_array = mic_fab_vars[MicVar::tabs]->array(mfi);
53  auto pres_array = mic_fab_vars[MicVar::pres]->array(mfi);
54 
55  // Non-precipitating
56  auto qv_array = mic_fab_vars[MicVar::qv]->array(mfi);
57  auto qcl_array = mic_fab_vars[MicVar::qcl]->array(mfi);
58  auto qci_array = mic_fab_vars[MicVar::qci]->array(mfi);
59  auto qn_array = mic_fab_vars[MicVar::qn]->array(mfi);
60  auto qt_array = mic_fab_vars[MicVar::qt]->array(mfi);
61 
62  // Precipitating
63  auto qpr_array = mic_fab_vars[MicVar::qpr]->array(mfi);
64  auto qps_array = mic_fab_vars[MicVar::qps]->array(mfi);
65  auto qpg_array = mic_fab_vars[MicVar::qpg]->array(mfi);
66  auto qp_array = mic_fab_vars[MicVar::qp]->array(mfi);
67 
68  const auto& box3d = mfi.tilebox();
69 
70  ParallelFor(box3d, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
71  {
72  //------- Autoconversion/accretion
73  Real omn, omp, omg;
74  Real qsat, qsatw, qsati;
75 
76  Real qcc, qii, qpr, qps, qpg;
77  Real dprc, dpsc, dpgc;
78  Real dpsi, dpgi;
79 
80  Real dqc, dqca, dqi, dqia, dqp;
81  Real dqpr, dqps, dqpg;
82 
83  Real auto_r, autos;
84  Real accrcr, accrcs, accris, accrcg, accrig;
85 
86  // Work to be done for autoc/accr or evap
87  if (qn_array(i,j,k)+qp_array(i,j,k) > 0.0) {
88  if (SAM_moisture_type == 2) {
89  omn = 1.0;
90  omp = 1.0;
91  omg = 0.0;
92  } else {
93  omn = std::max(0.0,std::min(1.0,(tabs_array(i,j,k)-tbgmin)*a_bg));
94  omp = std::max(0.0,std::min(1.0,(tabs_array(i,j,k)-tprmin)*a_pr));
95  omg = std::max(0.0,std::min(1.0,(tabs_array(i,j,k)-tgrmin)*a_gr));
96  }
97 
98  qcc = qcl_array(i,j,k);
99  qii = qci_array(i,j,k);
100 
101  qpr = qpr_array(i,j,k);
102  qps = qps_array(i,j,k);
103  qpg = qpg_array(i,j,k);
104 
105  //==================================================
106  // Autoconversion (A30/A31) and accretion (A27)
107  //==================================================
108  if (qn_array(i,j,k) > 0.0) {
109  accrcr = 0.0;
110  accrcs = 0.0;
111  accris = 0.0;
112  accrcg = 0.0;
113  accrig = 0.0;
114 
115  if (qcc > qcw0) {
116  auto_r = alphaelq;
117  } else {
118  auto_r = 0.0;
119  }
120 
121  if (qii > qci0) {
122  autos = betaelq*coefice_t(k);
123  } else {
124  autos = 0.0;
125  }
126 
127  if (omp > 0.001) {
128  accrcr = accrrc_t(k);
129  }
130 
131  if (omp < 0.999 && omg < 0.999) {
132  accrcs = accrsc_t(k);
133  accris = accrsi_t(k);
134  }
135 
136  if (omp < 0.999 && omg > 0.001) {
137  accrcg = accrgc_t(k);
138  accrig = accrgi_t(k);
139  }
140 
141  // Autoconversion & accretion (sink for cloud comps)
142  dqca = dtn * auto_r * (qcc-qcw0);
143  dprc = dtn * accrcr * qcc * std::pow(qpr, powr1);
144  dpsc = dtn * accrcs * qcc * std::pow(qps, pows1);
145  dpgc = dtn * accrcg * qcc * std::pow(qpg, powg1);
146 
147  dqia = dtn * autos * (qii-qci0);
148  dpsi = dtn * accris * qii * std::pow(qps, pows1);
149  dpgi = dtn * accrig * qii * std::pow(qpg, powg1);
150 
151  // Rescale sinks to avoid negative cloud fractions
152  dqc = dqca + dprc + dpsc + dpgc;
153  dqi = dqia + dpsi + dpgi;
154  Real scalec = std::min(qcl_array(i,j,k),dqc) / (dqc + eps);
155  Real scalei = std::min(qci_array(i,j,k),dqi) / (dqi + eps);
156  dqca *= scalec; dprc *= scalec; dpsc *= scalec; dpgc *= scalec;
157  dqia *= scalei; dpsi *= scalei; dpgi *= scalei;
158  dqc = dqca + dprc + dpsc + dpgc;
159  dqi = dqia + dpsi + dpgi;
160 
161  // NOTE: Autoconversion of cloud water and ice are sources
162  // to qp, while accretion is a source to an individual
163  // precipitating component (e.g., qpr/qps/qpg). So we
164  // only split autoconversion with omega. The omega
165  // splitting does imply a latent heat source.
166 
167  // Partition formed precip componentss
168  dqpr = (dqca + dqia) * omp + dprc;
169  dqps = (dqca + dqia) * (1.0 - omp) * (1.0 - omg) + dpsc + dpsi;
170  dqpg = (dqca + dqia) * (1.0 - omp) * omg + dpgc + dpgi;
171 
172  // Update the primitive state variables
173  qcl_array(i,j,k) -= dqc;
174  qci_array(i,j,k) -= dqi;
175  qpr_array(i,j,k) += dqpr;
176  qps_array(i,j,k) += dqps;
177  qpg_array(i,j,k) += dqpg;
178 
179  // Update the primitive derived vars
180  qn_array(i,j,k) = qcl_array(i,j,k) + qci_array(i,j,k);
181  qt_array(i,j,k) = qv_array(i,j,k) + qn_array(i,j,k);
182  qp_array(i,j,k) = qpr_array(i,j,k) + qps_array(i,j,k) + qpg_array(i,j,k);
183 
184  // Update temperature
185  tabs_array(i,j,k) += fac_fus * ( dqca * (1.0 - omp) - dqia * omp );
186 
187  // Update theta
188  theta_array(i,j,k) = getThgivenPandT(tabs_array(i,j,k), 100.0*pres_array(i,j,k), rdOcp);
189  }
190 
191  //==================================================
192  // Evaporation (A24)
193  //==================================================
194  erf_qsatw(tabs_array(i,j,k),pres_array(i,j,k),qsatw);
195  erf_qsati(tabs_array(i,j,k),pres_array(i,j,k),qsati);
196  qsat = qsatw * omn + qsati * (1.0-omn);
197  if((qp_array(i,j,k) > 0.0) && (qv_array(i,j,k) < qsat)) {
198 
199  dqpr = evapr1_t(k)*sqrt(qpr) + evapr2_t(k)*pow(qpr,powr2);
200  dqps = evaps1_t(k)*sqrt(qps) + evaps2_t(k)*pow(qps,pows2);
201  dqpg = evapg1_t(k)*sqrt(qpg) + evapg2_t(k)*pow(qpg,powg2);
202 
203  // NOTE: This is always a sink for precipitating comps
204  // since qv<qsat and thus (1 - qv/qsat)>0. If we are
205  // in a super-saturated state (qv>qsat) the Newton
206  // iterations in Cloud() will have handled condensation.
207  dqpr *= dtn * (1.0 - qv_array(i,j,k)/qsat);
208  dqps *= dtn * (1.0 - qv_array(i,j,k)/qsat);
209  dqpg *= dtn * (1.0 - qv_array(i,j,k)/qsat);
210 
211  // Limit to avoid negative moisture fractions
212  dqpr = std::min(qpr_array(i,j,k),dqpr);
213  dqps = std::min(qps_array(i,j,k),dqps);
214  dqpg = std::min(qpg_array(i,j,k),dqpg);
215  dqp = dqpr + dqps + dqpg;
216 
217  // Update the primitive state variables
218  qv_array(i,j,k) += dqp;
219  qpr_array(i,j,k) -= dqpr;
220  qps_array(i,j,k) -= dqps;
221  qpg_array(i,j,k) -= dqpg;
222 
223  // Update the primitive derived vars
224  qt_array(i,j,k) = qv_array(i,j,k) + qn_array(i,j,k);
225  qp_array(i,j,k) = qpr_array(i,j,k) + qps_array(i,j,k) + qpg_array(i,j,k);
226 
227  // Update temperature
228  tabs_array(i,j,k) -= fac_cond * dqpr + fac_sub * (dqps + dqpg);
229 
230  // Update theta
231  theta_array(i,j,k) = getThgivenPandT(tabs_array(i,j,k), 100.0*pres_array(i,j,k), rdOcp);
232  }
233  }
234  });
235  }
236 }
constexpr amrex::Real a_bg
Definition: ERF_Constants.H:77
constexpr amrex::Real a_gr
Definition: ERF_Constants.H:79
constexpr amrex::Real qci0
Definition: ERF_Constants.H:47
constexpr amrex::Real betaelq
Definition: ERF_Constants.H:49
constexpr amrex::Real alphaelq
Definition: ERF_Constants.H:48
constexpr amrex::Real qcw0
Definition: ERF_Constants.H:46
constexpr amrex::Real tprmin
Definition: ERF_Constants.H:33
constexpr amrex::Real tgrmin
Definition: ERF_Constants.H:35
constexpr amrex::Real a_pr
Definition: ERF_Constants.H:78

Referenced by Advance().

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

◆ PrecipFall()

void SAM::PrecipFall ( const SolverChoice sc)

Precipitation fluxes P_{r/s/g} (A19)

Code modified from SAMXX, the C++ version of the SAM code.

Parameters
[in]hydro_typeType selection for the precipitation advection hydrodynamics scheme (0-3)
17 {
18  if(sc.moisture_type == MoistureType::SAM_NoPrecip_NoIce) return;
19 
20  Real rho_0 = 1.29;
21 
22  Real gamr3 = erf_gammafff(4.0+b_rain);
23  Real gams3 = erf_gammafff(4.0+b_snow);
24  Real gamg3 = erf_gammafff(4.0+b_grau);
25 
26  Real vrain = (a_rain*gamr3/6.0)*pow((PI*rhor*nzeror),-crain);
27  Real vsnow = (a_snow*gams3/6.0)*pow((PI*rhos*nzeros),-csnow);
28  Real vgrau = (a_grau*gamg3/6.0)*pow((PI*rhog*nzerog),-cgrau);
29 
30  auto dz = m_geom.CellSize(2);
31  Real dtn = dt;
32  Real coef = dtn/dz;
33 
34  auto domain = m_geom.Domain();
35  int k_lo = domain.smallEnd(2);
36  int k_hi = domain.bigEnd(2);
37 
41  auto qp = mic_fab_vars[MicVar::qp];
48 
49  auto ba = tabs->boxArray();
50  auto dm = tabs->DistributionMap();
51  auto ngrow = tabs->nGrowVect();
52 
53  MultiFab fz;
54  fz.define(convert(ba, IntVect(0,0,1)), dm, 1, ngrow);
55 
56  int SAM_moisture_type = 1;
57  if (sc.moisture_type == MoistureType::SAM_NoIce) {
58  SAM_moisture_type = 2;
59  }
60 
61  // Precompute the vertical fluxes for CFL constraint
62  for (MFIter mfi(fz, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
63  auto qp_array = qp->array(mfi);
64  auto rho_array = rho->array(mfi);
65  auto tabs_array = tabs->array(mfi);
66  auto fz_array = fz.array(mfi);
67 
68  const auto& box3d = mfi.tilebox();
69 
70  ParallelFor(box3d, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
71  {
72  Real rho_avg, tab_avg, qp_avg;
73  if (k==k_lo) {
74  rho_avg = rho_array(i,j,k);
75  tab_avg = tabs_array(i,j,k);
76  qp_avg = qp_array(i,j,k);
77  } else if (k==k_hi+1) {
78  rho_avg = rho_array(i,j,k-1);
79  tab_avg = tabs_array(i,j,k-1);
80  qp_avg = qp_array(i,j,k-1);
81  } else {
82  rho_avg = 0.5*( rho_array(i,j,k-1) + rho_array(i,j,k));
83  tab_avg = 0.5*(tabs_array(i,j,k-1) + tabs_array(i,j,k));
84  qp_avg = 0.5*( qp_array(i,j,k-1) + qp_array(i,j,k));
85  }
86 
87  Real Pprecip = 0.0;
88  if(qp_avg > qp_threshold) {
89  Real omp, omg;
90  if (SAM_moisture_type == 2) {
91  omp = 1.0;
92  omg = 0.0;
93  } else {
94  omp = std::max(0.0,std::min(1.0,(tab_avg-tprmin)*a_pr));
95  omg = std::max(0.0,std::min(1.0,(tab_avg-tgrmin)*a_gr));
96  }
97  Real qrr = omp*qp_avg;
98  Real qss = (1.0-omp)*(1.0-omg)*qp_avg;
99  Real qgg = (1.0-omp)*(omg)*qp_avg;
100  Pprecip = omp*vrain*std::pow(rho_avg*qrr,1.0+crain)
101  + (1.0-omp)*( (1.0-omg)*vsnow*std::pow(rho_avg*qss,1.0+csnow)
102  + omg *vgrau*std::pow(rho_avg*qgg,1.0+cgrau) );
103  }
104 
105  // NOTE: Fz is the sedimentation flux from the advective operator.
106  // In the terrain-following coordinate system, the z-deriv in
107  // the divergence uses the normal velocity (Omega). However,
108  // there are no u/v components to the sedimentation velocity.
109  // Therefore, we simply end up with a division by detJ when
110  // evaluating the source term: dJinv * (flux_hi - flux_lo) * dzinv.
111  fz_array(i,j,k) = Pprecip * std::sqrt(rho_0/rho_avg);
112  });
113  }
114 
115  // Compute number of substeps from maximum terminal velocity
116  Real wt_max;
117  int n_substep;
118  auto const& ma_fz_arr = fz.const_arrays();
119  GpuTuple<Real> max = ParReduce(TypeList<ReduceOpMax>{},
120  TypeList<Real>{},
121  fz, IntVect(0),
122  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) noexcept
123  -> GpuTuple<Real>
124  {
125  return { ma_fz_arr[box_no](i,j,k) };
126  });
127  wt_max = get<0>(max) + std::numeric_limits<Real>::epsilon();
128  n_substep = int( std::ceil(wt_max * coef / CFL_MAX) );
129  AMREX_ALWAYS_ASSERT(n_substep >= 1);
130  coef /= Real(n_substep);
131  dtn /= Real(n_substep);
132 
133  // Substep the vertical advection
134  for (int nsub(0); nsub<n_substep; ++nsub) {
135  for (MFIter mfi(*qp, TileNoZ()); mfi.isValid(); ++mfi) {
136  auto qpr_array = qpr->array(mfi);
137  auto qps_array = qps->array(mfi);
138  auto qpg_array = qpg->array(mfi);
139  auto qp_array = qp->array(mfi);
140  auto rho_array = rho->array(mfi);
141  auto tabs_array = tabs->array(mfi);
142  auto fz_array = fz.array(mfi);
143 
144  auto rain_accum_array = rain_accum->array(mfi);
145  auto snow_accum_array = snow_accum->array(mfi);
146  auto graup_accum_array = graup_accum->array(mfi);
147 
148  const auto dJ_array = (m_detJ_cc) ? m_detJ_cc->const_array(mfi) : Array4<const Real>{};
149 
150  const auto& tbx = mfi.tilebox();
151  const auto& tbz = mfi.tilebox(IntVect(0,0,1),IntVect(0));
152 
153  // Update vertical flux every substep
154  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
155  {
156  Real rho_avg, tab_avg, qp_avg;
157  if (k==k_lo) {
158  rho_avg = rho_array(i,j,k);
159  tab_avg = tabs_array(i,j,k);
160  qp_avg = qp_array(i,j,k);
161  } else if (k==k_hi+1) {
162  rho_avg = rho_array(i,j,k-1);
163  tab_avg = tabs_array(i,j,k-1);
164  qp_avg = qp_array(i,j,k-1);
165  } else {
166  rho_avg = 0.5*( rho_array(i,j,k-1) + rho_array(i,j,k));
167  tab_avg = 0.5*(tabs_array(i,j,k-1) + tabs_array(i,j,k));
168  qp_avg = 0.5*( qp_array(i,j,k-1) + qp_array(i,j,k));
169  }
170 
171  Real Pprecip = 0.0;
172  if(qp_avg > qp_threshold) {
173  Real omp, omg;
174  if (SAM_moisture_type == 2) {
175  omp = 1.0;
176  omg = 0.0;
177  } else {
178  omp = std::max(0.0,std::min(1.0,(tab_avg-tprmin)*a_pr));
179  omg = std::max(0.0,std::min(1.0,(tab_avg-tgrmin)*a_gr));
180  }
181  Real qrr = omp*qp_avg;
182  Real qss = (1.0-omp)*(1.0-omg)*qp_avg;
183  Real qgg = (1.0-omp)*(omg)*qp_avg;
184  Pprecip = omp*vrain*std::pow(rho_avg*qrr,1.0+crain)
185  + (1.0-omp)*( (1.0-omg)*vsnow*std::pow(rho_avg*qss,1.0+csnow)
186  + omg *vgrau*std::pow(rho_avg*qgg,1.0+cgrau) );
187  }
188 
189  // NOTE: Fz is the sedimentation flux from the advective operator.
190  // In the terrain-following coordinate system, the z-deriv in
191  // the divergence uses the normal velocity (Omega). However,
192  // there are no u/v components to the sedimentation velocity.
193  // Therefore, we simply end up with a division by detJ when
194  // evaluating the source term: dJinv * (flux_hi - flux_lo) * dzinv.
195  fz_array(i,j,k) = Pprecip * std::sqrt(rho_0/rho_avg);
196 
197  if(k==k_lo){
198  Real omp, omg;
199  if (SAM_moisture_type == 2) {
200  omp = 1.0;
201  omg = 0.0;
202  } else {
203  omp = std::max(0.0,std::min(1.0,(tab_avg-tprmin)*a_pr));
204  omg = std::max(0.0,std::min(1.0,(tab_avg-tgrmin)*a_gr));
205  }
206  rain_accum_array(i,j,k) = rain_accum_array(i,j,k) + rho_avg*(omp*qp_avg)*vrain*dtn/rhor*1000.0; // Divide by rho_water and convert to mm
207  snow_accum_array(i,j,k) = snow_accum_array(i,j,k) + rho_avg*(1.0-omp)*(1.0-omg)*qp_avg*vrain*dtn/rhos*1000.0; // Divide by rho_snow and convert to mm
208  graup_accum_array(i,j,k) = graup_accum_array(i,j,k) + rho_avg*(1.0-omp)*(omg)*qp_avg*vrain*dtn/rhog*1000.0; // Divide by rho_graupel and convert to mm
209  }
210  });
211 
212  // Update precip every substep
213  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
214  {
215  // Jacobian determinant
216  Real dJinv = (dJ_array) ? 1.0/dJ_array(i,j,k) : 1.0;
217 
218  //==================================================
219  // Precipitating sedimentation (A19)
220  //==================================================
221  Real dqp = dJinv * (1.0/rho_array(i,j,k)) * ( fz_array(i,j,k+1) - fz_array(i,j,k) ) * coef;
222  Real omp, omg;
223  if (SAM_moisture_type == 2) {
224  omp = 1.0;
225  omg = 0.0;
226  } else {
227  omp = std::max(0.0,std::min(1.0,(tabs_array(i,j,k)-tprmin)*a_pr));
228  omg = std::max(0.0,std::min(1.0,(tabs_array(i,j,k)-tgrmin)*a_gr));
229  }
230 
231  qpr_array(i,j,k) = std::max(0.0, qpr_array(i,j,k) + dqp*omp);
232  qps_array(i,j,k) = std::max(0.0, qps_array(i,j,k) + dqp*(1.0-omp)*(1.0-omg));
233  qpg_array(i,j,k) = std::max(0.0, qpg_array(i,j,k) + dqp*(1.0-omp)*omg);
234  qp_array(i,j,k) = qpr_array(i,j,k) + qps_array(i,j,k) + qpg_array(i,j,k);
235 
236  // NOTE: Sedimentation does not affect the potential temperature,
237  // but it does affect the liquid/ice static energy.
238  // No source to Theta occurs here.
239  });
240  } // mfi
241  } // nsub
242 }
constexpr amrex::Real csnow
Definition: ERF_Constants.H:82
constexpr amrex::Real cgrau
Definition: ERF_Constants.H:83
constexpr amrex::Real qp_threshold
Definition: ERF_Constants.H:60
constexpr amrex::Real crain
Definition: ERF_Constants.H:81
@ theta
Definition: ERF_MM5.H:20
@ qp
Definition: ERF_Kessler.H:39
@ rain_accum
Definition: ERF_Kessler.H:41

Referenced by Advance().

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

◆ Qmoist_Ptr()

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

Reimplemented from NullMoist.

136  {
137  AMREX_ALWAYS_ASSERT(varIdx < m_qmoist_size);
138  return mic_fab_vars[MicVarMap[varIdx]].get();
139  }

◆ Qmoist_Restart_Vars()

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

Reimplemented from NullMoist.

270  {
271  a_idx.clear();
272  a_names.clear();
273  if (a_sc.moisture_type == MoistureType::SAM) {
274  a_idx.push_back( 8); a_names.push_back("RainAccum");
275  a_idx.push_back( 9); a_names.push_back("SnowAccum");
276  a_idx.push_back(10); a_names.push_back("GraupAccum");
277  } else if (a_sc.moisture_type == MoistureType::SAM_NoIce) {
278  a_idx.push_back( 8); a_names.push_back("RainAccum");
279  }
280  }

◆ Qmoist_Size()

int SAM::Qmoist_Size ( )
inlineoverridevirtual

Reimplemented from NullMoist.

145 { return SAM::m_qmoist_size; }

◆ Qstate_Size()

int SAM::Qstate_Size ( )
inlineoverridevirtual

Reimplemented from NullMoist.

148 { return SAM::m_qstate_size; }
int m_qstate_size
Definition: ERF_SAM.H:287

◆ Update_Micro_Vars()

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

Reimplemented from NullMoist.

110  {
111  this->Copy_State_to_Micro(cons_in);
112  this->Compute_Coefficients();
113  }
void Copy_State_to_Micro(const amrex::MultiFab &cons_in) override
Definition: ERF_InitSAM.cpp:88
void Compute_Coefficients()
Definition: ERF_InitSAM.cpp:140
Here is the call graph for this function:

◆ Update_State_Vars()

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

Reimplemented from NullMoist.

117  {
118  this->Copy_Micro_to_State(cons_in);
119  }
void Copy_Micro_to_State(amrex::MultiFab &cons_in) override
Definition: ERF_UpdateSAM.cpp:15
Here is the call graph for this function:

Member Data Documentation

◆ accrgc

amrex::TableData<amrex::Real, 1> SAM::accrgc
private

◆ accrgi

amrex::TableData<amrex::Real, 1> SAM::accrgi
private

◆ accrrc

amrex::TableData<amrex::Real, 1> SAM::accrrc
private

◆ accrsc

amrex::TableData<amrex::Real, 1> SAM::accrsc
private

◆ accrsi

amrex::TableData<amrex::Real, 1> SAM::accrsi
private

◆ CFL_MAX

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

◆ coefice

amrex::TableData<amrex::Real, 1> SAM::coefice
private

◆ docloud

bool SAM::docloud
private

Referenced by Define().

◆ doprecip

bool SAM::doprecip
private

Referenced by Define().

◆ dt

amrex::Real SAM::dt
private

Referenced by Advance().

◆ evapg1

amrex::TableData<amrex::Real, 1> SAM::evapg1
private

◆ evapg2

amrex::TableData<amrex::Real, 1> SAM::evapg2
private

◆ evapr1

amrex::TableData<amrex::Real, 1> SAM::evapr1
private

◆ evapr2

amrex::TableData<amrex::Real, 1> SAM::evapr2
private

◆ evaps1

amrex::TableData<amrex::Real, 1> SAM::evaps1
private

◆ evaps2

amrex::TableData<amrex::Real, 1> SAM::evaps2
private

◆ gamaz

amrex::TableData<amrex::Real, 1> SAM::gamaz
private

◆ m_axis

int SAM::m_axis
private

Referenced by Define().

◆ m_detJ_cc

amrex::MultiFab* SAM::m_detJ_cc
private

◆ m_fac_cond

amrex::Real SAM::m_fac_cond
private

Referenced by Define().

◆ m_fac_fus

amrex::Real SAM::m_fac_fus
private

Referenced by Define().

◆ m_fac_sub

amrex::Real SAM::m_fac_sub
private

Referenced by Define().

◆ m_geom

amrex::Geometry SAM::m_geom
private

◆ m_gOcp

amrex::Real SAM::m_gOcp
private

Referenced by Define().

◆ m_gtoe

amrex::BoxArray SAM::m_gtoe
private

◆ m_qmoist_size

int SAM::m_qmoist_size = 11
private

Referenced by Qmoist_Ptr(), and Qmoist_Size().

◆ m_qstate_size

int SAM::m_qstate_size = 6
private

Referenced by Qstate_Size().

◆ m_rdOcp

amrex::Real SAM::m_rdOcp
private

Referenced by Define().

◆ m_z_phys_nd

amrex::MultiFab* SAM::m_z_phys_nd
private

◆ mic_fab_vars

amrex::Array<FabPtr, MicVar::NumVars> SAM::mic_fab_vars
private

Referenced by Qmoist_Ptr().

◆ MicVarMap

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

Referenced by Qmoist_Ptr().

◆ nlev

int SAM::nlev
private

◆ pres1d

amrex::TableData<amrex::Real, 1> SAM::pres1d
private

◆ qn1d

amrex::TableData<amrex::Real, 1> SAM::qn1d
private

◆ qt1d

amrex::TableData<amrex::Real, 1> SAM::qt1d
private

◆ qv1d

amrex::TableData<amrex::Real, 1> SAM::qv1d
private

◆ rho1d

amrex::TableData<amrex::Real, 1> SAM::rho1d
private

◆ tabs1d

amrex::TableData<amrex::Real, 1> SAM::tabs1d
private

◆ zhi

int SAM::zhi
private

◆ zlo

int SAM::zlo
private

◆ zmid

amrex::TableData<amrex::Real, 1> SAM::zmid
private

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