ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitDensityHSE.H File Reference
#include "ERF_HSEUtils.H"
Include dependency graph for ERF_InitDensityHSE.H:

Go to the source code of this file.

Functions

void erf_init_dens_hse_dry (amrex::MultiFab &rho_hse, std::unique_ptr< amrex::MultiFab > &, std::unique_ptr< amrex::MultiFab > &z_phys_cc, amrex::Geometry const &geom, const amrex::Vector< amrex::Real > &stretched_dz_h, bool is_constant_dz, bool is_stretched_dz) override
 
void erf_init_dens_hse_moist (amrex::MultiFab &rho_hse, std::unique_ptr< amrex::MultiFab > &, amrex::Geometry const &geom) override
 
void erf_init_const_dens_hse (amrex::MultiFab &rho_hse) override
 
void erf_init_const_dens_and_th_hse (amrex::MultiFab &rho_hse, amrex::MultiFab &p_hse, amrex::MultiFab &pi_hse, amrex::MultiFab &th_hse, amrex::MultiFab &qv_hse, amrex::Real l_rdOcp) override
 
void erf_init_const_dens_and_linear_th_hse (amrex::MultiFab &rho_hse, amrex::MultiFab &p_hse, amrex::MultiFab &pi_hse, amrex::MultiFab &th_hse, amrex::MultiFab &qv_hse, amrex::Real l_rdOcp, std::unique_ptr< amrex::MultiFab > &z_phys_cc) override
 

Function Documentation

◆ erf_init_const_dens_and_linear_th_hse()

void erf_init_const_dens_and_linear_th_hse ( amrex::MultiFab &  rho_hse,
amrex::MultiFab &  p_hse,
amrex::MultiFab &  pi_hse,
amrex::MultiFab &  th_hse,
amrex::MultiFab &  qv_hse,
amrex::Real  l_rdOcp,
std::unique_ptr< amrex::MultiFab > &  z_phys_cc 
)
override
228 {
229  amrex::Real rho_0 = base_parms.rho_0;
230  amrex::Real T_0 = base_parms.T_0;
231 
232  amrex::ParmParse pp_prob("prob");
233  amrex::Real dtheta_dz = zero; pp_prob.query("dtheta_dz",dtheta_dz);
234 
235  rho_hse.setVal(rho_0);
236 
237  for ( amrex::MFIter mfi(th_hse, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi )
238  {
239  amrex::Array4<amrex::Real> th_hse_arr = th_hse.array(mfi);
240  amrex::Array4<amrex::Real> p_hse_arr = p_hse.array(mfi);
241  amrex::Array4<amrex::Real> pi_hse_arr = pi_hse.array(mfi);
242  amrex::Array4<amrex::Real const> z_arr = z_phys_cc->array(mfi);
243  const amrex::Box& gbx = mfi.growntilebox(1);
244  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
245  {
246  th_hse_arr(i,j,k) = T_0 + dtheta_dz * (z_arr(i,j,k)- z_arr(i,j,0));
247  p_hse_arr(i,j,k) = getPgivenRTh(rho_0*th_hse_arr(i,j,k));
248  pi_hse_arr(i,j,k) = getExnergivenRTh(rho_0*th_hse_arr(i,j,k), l_rdOcp);
249  });
250  } // mfi
251 
252  // Default to zero background moisture
253  qv_hse.setVal(0.0);
254 }
constexpr amrex::Real zero
Definition: ERF_Constants.H:6
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getExnergivenRTh(const amrex::Real rhotheta, const amrex::Real rdOcp, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:156
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:81
Real rho_0
Definition: ERF_InitCustomPert_ABL.H:4
Real T_0
Definition: ERF_InitCustomPert_ABL.H:5
ParmParse pp_prob("prob")
ParallelFor(grown_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Here is the call graph for this function:

◆ erf_init_const_dens_and_th_hse()

void erf_init_const_dens_and_th_hse ( amrex::MultiFab &  rho_hse,
amrex::MultiFab &  p_hse,
amrex::MultiFab &  pi_hse,
amrex::MultiFab &  th_hse,
amrex::MultiFab &  qv_hse,
amrex::Real  l_rdOcp 
)
override
200 {
201  amrex::Real rho_0 = base_parms.rho_0;
202  amrex::Real T_0 = base_parms.T_0;
203 
204  amrex::ParmParse pp_prob("prob");
205  amrex::Real dtheta_dz = zero; pp_prob.query("dtheta_dz",dtheta_dz);
206 
207  rho_hse.setVal(rho_0);
208  th_hse.setVal(T_0);
209 
210  amrex::Real rt0 = rho_0 * T_0;
211 
212  amrex::Real p0 = getPgivenRTh(rt0);
213  p_hse.setVal(p0);
214 
215  amrex::Real pi0 = getExnergivenRTh(rt0, l_rdOcp);
216 
217  pi_hse.setVal(pi0);
218 
219  // Default to zero background moisture
220  qv_hse.setVal(0.0);
221 }
real(c_double), parameter p0
Definition: ERF_module_model_constants.F90:40
Here is the call graph for this function:

◆ erf_init_const_dens_hse()

void erf_init_const_dens_hse ( amrex::MultiFab &  rho_hse)
override
184 {
185  amrex::Real rho_0 = base_parms.rho_0;
186  for ( amrex::MFIter mfi(rho_hse, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi )
187  {
188  amrex::Array4<amrex::Real> rho_hse_arr = rho_hse.array(mfi);
189  const amrex::Box& gbx = mfi.growntilebox(1);
190  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
191  {
192  rho_hse_arr(i,j,k) = rho_0;
193  });
194  }
195 }
Here is the call graph for this function:

◆ erf_init_dens_hse_dry()

void erf_init_dens_hse_dry ( amrex::MultiFab &  rho_hse,
std::unique_ptr< amrex::MultiFab > &  ,
std::unique_ptr< amrex::MultiFab > &  z_phys_cc,
amrex::Geometry const &  geom,
const amrex::Vector< amrex::Real > &  stretched_dz_h,
bool  is_constant_dz,
bool  is_stretched_dz 
)
override

Initialize hydrostatically balanced density

Calls init_isentropic_hse_terrain() or init_isentropic_hse() for cases with and without terrain, respectively. Hydrostatic equilibrium (HSE) is satisfied discretely. Note that these routines presume that qv==0 when evaluating the EOS. Both density and pressure in HSE are calculated but only the density is used at this point.

20 {
21  const amrex::Real T_sfc = amrex::Real(300.);
22  const amrex::Real rho_sfc = p_0 / (R_d*T_sfc);
23  const amrex::Real Thetabar = T_sfc;
24 
25  if (!is_constant_dz && !is_stretched_dz) {
26 
27  const int domlo_z = geom.Domain().smallEnd(2);
28  const int domhi_z = geom.Domain().bigEnd(2);
29  if (domhi_z > 255) amrex::Abort("1D Arrays are hard-wired to only 256 high");
30 
31  for ( amrex::MFIter mfi(rho_hse, TileNoZ()); mfi.isValid(); ++mfi )
32  {
33  amrex::Array4<amrex::Real > rho_arr = rho_hse.array(mfi);
34  amrex::Array4<amrex::Real const> z_cc_arr = z_phys_cc->const_array(mfi);
35 
36  // Create a flat box with same horizontal extent but only one cell in vertical
37  const amrex::Box& tbz = mfi.nodaltilebox(2);
38  amrex::Box b2d = tbz; // Copy constructor
39  b2d.grow(0,1); b2d.grow(1,1); // Grow by one in the lateral directions
40  b2d.setRange(2,0);
41 
42  const int ilo = tbz.smallEnd(0);
43  const int jlo = tbz.smallEnd(1);
44  const int klo = tbz.smallEnd(2);
45  const int khi = tbz.bigEnd(2)-1;
46 
47  amrex::Real rho_local_sfc;
48  if (klo == 0) {
49  rho_local_sfc = rho_sfc;
50  } else {
51  rho_local_sfc = rho_arr(ilo,jlo,klo-1);
52  }
53 
54  amrex::ParallelFor(b2d, [=] AMREX_GPU_DEVICE (int i, int j, int)
55  {
56  amrex::Array1D<amrex::Real,0,255> r;
57  amrex::Array1D<amrex::Real,0,255> p;
58  HSEutils::init_isentropic_hse_terrain(i,j,rho_local_sfc,Thetabar,&(r(0)),&(p(0)),z_cc_arr,klo,khi);
59 
60  for (int k = klo; k <= khi; k++) {
61  rho_arr(i,j,k) = r(k);
62  }
63 
64  // Impose Neumann conditions at bottom and top of domain boundary
65  if (klo == domlo_z) {
66  rho_arr(i,j,domlo_z-1) = rho_arr(i,j,domlo_z);
67  }
68  if (khi == domhi_z) {
69  rho_arr(i,j,domhi_z+1) = rho_arr(i,j,domhi_z);
70  }
71  });
72  } // mfi
73 
74  } else {
75 
76 
77  // Note that this integrates over the entire domain height,
78  // but only copies into each box as appropriate.
79  // There is no assumption that any one box spans the whole vertical height.
80  const int klo = geom.Domain().smallEnd(2);
81  const int khi = geom.Domain().bigEnd(2);
82 
83  // These are at cell centers (unstaggered)
84  amrex::Vector<amrex::Real> h_r(khi+2);
85  amrex::Vector<amrex::Real> h_p(khi+2);
86 
87  amrex::Gpu::DeviceVector<amrex::Real> d_r(khi+2);
88  amrex::Gpu::DeviceVector<amrex::Real> d_p(khi+2);
89 
90  if (is_constant_dz) {
91  const amrex::Real dz = geom.CellSize()[2];
92  HSEutils::init_isentropic_hse_constant_dz(rho_sfc,Thetabar,h_r.data(),h_p.data(),dz,klo,khi);
93  } else { // stretched_dz
94  HSEutils::init_isentropic_hse_stretched_dz(rho_sfc,Thetabar,h_r.data(),h_p.data(),stretched_dz_h.data(),klo,khi);
95  }
96 
97  amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, h_r.begin(), h_r.end(), d_r.begin());
98  amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, h_p.begin(), h_p.end(), d_p.begin());
99 
100  amrex::Real* r = d_r.data();
101 
102 #ifdef _OPENMP
103 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
104 #endif
105  for ( amrex::MFIter mfi(rho_hse, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi )
106  {
107  const amrex::Box& bx = mfi.growntilebox(1);
108  const amrex::Array4<amrex::Real> rho_hse_arr = rho_hse[mfi].array();
109  amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
110  {
111  int kk = std::max(k,0);
112  rho_hse_arr(i,j,k) = r[kk];
113  });
114  } // mfi
115  }
116 }
constexpr amrex::Real p_0
Definition: ERF_Constants.H:37
constexpr amrex::Real R_d
Definition: ERF_Constants.H:29
const int khi
Definition: ERF_InitCustomPert_Bubble.H:21
Gpu::DeviceVector< Real > d_p(khi+2)
Vector< Real > h_r(khi+2)
Vector< Real > h_p(khi+2)
Gpu::DeviceVector< Real > d_r(khi+2)
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
auto rho_arr
Definition: ERF_UpdateWSubsidence_SineMassFlux.H:3
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void init_isentropic_hse_stretched_dz(const amrex::Real &r_sfc, const amrex::Real &theta, amrex::Real *r, amrex::Real *p, const amrex::Real *stretched_dz, const int klo, const int khi)
Definition: ERF_HSEUtils.H:206
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void init_isentropic_hse_constant_dz(const amrex::Real &r_sfc, const amrex::Real &theta, amrex::Real *r, amrex::Real *p, const amrex::Real &dz, const int klo, const int khi)
Definition: ERF_HSEUtils.H:96
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void init_isentropic_hse_terrain(int i, int j, const amrex::Real &r_sfc, const amrex::Real &theta, amrex::Real *r, amrex::Real *p, const amrex::Array4< amrex::Real const > z_cc, const int &klo, const int &khi)
Definition: ERF_HSEUtils.H:318
@ p
Definition: ERF_WSM6.H:176
@ dz
Definition: ERF_AdvanceWSM6.cpp:104
Here is the call graph for this function:

◆ erf_init_dens_hse_moist()

void erf_init_dens_hse_moist ( amrex::MultiFab &  rho_hse,
std::unique_ptr< amrex::MultiFab > &  ,
amrex::Geometry const &  geom 
)
override
122 {
123  const amrex::Real dz = geom.CellSize()[2];
124  const int khi = geom.Domain().bigEnd()[2];
125 
126  // These are at cell centers (unstaggered)
127  amrex::Vector<amrex::Real> h_r(khi+2);
128  amrex::Vector<amrex::Real> h_p(khi+2);
129  amrex::Vector<amrex::Real> h_t(khi+2);
130  amrex::Vector<amrex::Real> h_q_v(khi+2);
131 
132  amrex::ParmParse pp("prob");
133  amrex::Real q_t = amrex::Real(0.02);
134  pp.query("qt_init",q_t);
135 
137  pp.query("eq_pot_temp",eq_pot_temp);
138 
139  bool use_empirical = false;
140  pp.query("use_empirical_psat",use_empirical);
141 
142  amrex::Real z_tr_1 = -one;
143  amrex::Real z_tr_2 = -one;
144  pp.query("height", z_tr_1);
145  pp.query("z_tr", z_tr_2);
146 
147  // We only set them to zero to make sure they are initialized
149 
150  bool T_from_theta = false;
151  pp.query("T_from_theta_in_moist_init", T_from_theta);
152 
153  if (T_from_theta) {
154  pp.get("theta_tr",theta_tr); pp.get("theta_0",theta_0);
155  pp.get("T_tr",T_tr);
156  }
157 
158  HSEutils::init_isentropic_hse_no_terrain( h_t.data(), h_r.data(), h_p.data(),
159  h_q_v.data(), dz, khi, q_t, eq_pot_temp, use_empirical,
160  T_from_theta, z_tr_1, z_tr_2,
161  theta_0, theta_tr, T_tr);
162 
163  amrex::Gpu::DeviceVector<amrex::Real> d_r(khi+2);
164  amrex::Gpu::copy(amrex::Gpu::hostToDevice, h_r.begin(), h_r.end(), d_r.begin());
165  amrex::Real* r = d_r.data();
166 
167 #ifdef _OPENMP
168 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
169 #endif
170  for ( amrex::MFIter mfi(rho_hse,amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
171  {
172  const amrex::Box& bx = mfi.growntilebox(1);
173  const amrex::Array4<amrex::Real> rho_hse_arr = rho_hse[mfi].array();
174  amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
175  {
176  int kk = std::max(k,0);
177  rho_hse_arr(i,j,k) = r[kk];
178  });
179  } // mfi
180 }
constexpr amrex::Real one
Definition: ERF_Constants.H:7
ParmParse pp("prob")
Real eq_pot_temp
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:23
bool use_empirical
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:25
Vector< Real > h_t(khi+2)
Real T_tr
Definition: ERF_InitCustomPert_SquallLine.H:43
Real q_t
Definition: ERF_InitCustomPert_SquallLine.H:24
Vector< Real > h_q_v(khi+2)
Real theta_tr
Definition: ERF_InitCustomPert_SquallLine.H:47
Real theta_0
Definition: ERF_InitCustomPert_SquallLine.H:46
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE void init_isentropic_hse_no_terrain(Real *theta, Real *r, Real *p, Real *q_v, const Real &dz, const int &khi, const Real q_t, const Real eq_pot_temp, const bool use_empirical, const bool T_from_theta=false, const Real z_tr_1=-one, const Real z_tr_2=-one, const Real theta_0=amrex::Real(0), const Real theta_tr=amrex::Real(0), const Real T_tr=amrex::Real(0))
Definition: ERF_HSEUtils.H:626
Here is the call graph for this function: