ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitCustomPert_Bubble.H
Go to the documentation of this file.
1  ParmParse pp_prob("prob");
2 
3  Real T_0 = 300.0; pp_prob.query("T_0", T_0);
4  Real x_c = 0.0; pp_prob.query("x_c", x_c);
5  Real y_c = 0.0; pp_prob.query("y_c", y_c);
6  Real z_c = 0.0; pp_prob.query("z_c", z_c);
7  Real x_r = 0.0; pp_prob.query("x_r", x_r);
8  Real y_r = 0.0; pp_prob.query("y_r", y_r);
9  Real z_r = 0.0; pp_prob.query("z_r", z_r);
10 
11  Real T_pert = -15.0; pp_prob.query("T_pert", T_pert);
12 
13  bool T_pert_is_airtemp = true; pp_prob.query("T_pert_is_airtemp", T_pert_is_airtemp);
14  bool perturb_rho = true; pp_prob.query("perturb_rho", perturb_rho);
15 
16  bool do_moist_bubble = false; pp_prob.query("do_moist_bubble", do_moist_bubble);
17  do_moist_bubble &= (sc.moisture_type != MoistureType::None);
18 
19  Real theta_pert = 2.0; pp_prob.query("theta_pert", theta_pert);
20 
21  const int khi = geomdata.Domain().bigEnd()[2];
22 
23  AMREX_ALWAYS_ASSERT(bx.length()[2] == khi+1);
24 
25  const Real dz = geomdata.CellSize()[2];
26  const Real rdOcp = sc.rdOcp;
27 
28  amrex::Print() << "Bubble delta T = " << T_pert << " K" << std::endl;
29  amrex::Print() << " centered at ("
30  << x_c << " " << y_c << " " << z_c << ")" << std::endl;
31  amrex::Print() << " with extent ("
32  << x_r << " " << y_r << " " << z_r << ")" << std::endl;
33 
34  if (T_0 <= 0)
35  {
36  amrex::Print() << "Ignoring T_0 = " << T_0
37  << ", background fields should have been initialized with erf.init_type"
38  << std::endl;
39  }
40 
41  Real qt_init = 0.02; pp_prob.query("qt_init", qt_init);
42 
43  Real eq_pot_temp = 320.0; pp_prob.query("eq_pot_temp",eq_pot_temp);
44 
45  bool use_empirical = false;
46  pp_prob.query("use_empircal_psat",use_empirical);
47 
48  if (do_moist_bubble) {
49  Vector<Real> h_r(khi+2);
50  Vector<Real> h_p(khi+2);
51  Vector<Real> h_t(khi+2);
52  Vector<Real> h_q_v(khi+2);
53 
54  Gpu::DeviceVector<Real> d_r(khi+2);
55  Gpu::DeviceVector<Real> d_p(khi+2);
56  Gpu::DeviceVector<Real> d_t(khi+2);
57  Gpu::DeviceVector<Real> d_q_v(khi+2);
58 
59  HSEutils::init_isentropic_hse_no_terrain(h_t.data(), h_r.data(),h_p.data(),h_q_v.data(),dz,khi,
61 
62  Gpu::copyAsync(Gpu::hostToDevice, h_r.begin(), h_r.end(), d_r.begin());
63  Gpu::copyAsync(Gpu::hostToDevice, h_p.begin(), h_p.end(), d_p.begin());
64  Gpu::copyAsync(Gpu::hostToDevice, h_t.begin(), h_t.end(), d_t.begin());
65  Gpu::copyAsync(Gpu::hostToDevice, h_q_v.begin(), h_q_v.end(), d_q_v.begin());
66 
67  Real* theta_back = d_t.data();
68  Real* p_back = d_p.data();
69  Real* q_v_back = d_q_v.data();
70 
71  int moisture_type = 1;
72 
73  if (sc.moisture_type == MoistureType::SAM) {
74  moisture_type = 1;
75  } else if (sc.moisture_type == MoistureType::SAM_NoIce ||
76  sc.moisture_type == MoistureType::SAM_NoPrecip_NoIce) {
77  moisture_type = 2;
78  }
79 
80  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
81  {
82  // Geometry (note we must include these here to get the data on device)
83  const auto prob_lo = geomdata.ProbLo();
84  const auto dx = geomdata.CellSize();
85  const Real x = prob_lo[0] + (i + 0.5) * dx[0];
86  const Real y = prob_lo[1] + (j + 0.5) * dx[1];
87  const Real z = prob_lo[2] + (k + 0.5) * dx[2];
88 
89  Real rad, delta_theta, theta_total, rho, RH;
90 
91  // Introduce the warm bubble. Assume that the bubble is pressure matched with the background
92  rad = 0.0;
93  if (x_r > 0) rad += std::pow((x - x_c)/x_r, 2);
94  if (y_r > 0) rad += std::pow((y - y_c)/y_r, 2);
95  if (z_r > 0) rad += std::pow((z - z_c)/z_r, 2);
96  rad = std::sqrt(rad);
97 
98  if (rad <= 1.0) {
99  delta_theta = theta_pert*std::pow(cos(PI*rad/2.0),2);
100  } else {
101  delta_theta = 0.0;
102  }
103 
104  theta_total = theta_back[k]*(delta_theta/300.0 + 1);
106  rho = p_back[k]/(R_d*T*(1.0 + (R_v/R_d)*q_v_back[k]));
109 
110  // Compute background quantities
111  Real T_back = getTgivenPandTh(p_back[k], theta_back[k], (R_d/Cp_d));
112  Real rho_back = p_back[k]/(R_d*T_back*(1.0 + (R_v/R_d)*q_v_back[k]));
113 
114  // This version perturbs rho but not p
115  state_pert(i, j, k, RhoTheta_comp) = rho*theta_total - rho_back*theta_back[k]*(1.0 + (R_v/R_d)*q_v_back[k]);
116  state_pert(i, j, k, Rho_comp) = rho - rho_back*(1.0 + qt_init);
117 
118  // Set scalar = 0 everywhere
119  state_pert(i, j, k, RhoScalar_comp) = 0.0;
120 
121  // mean states
124 
125  // Cold microphysics are present
126  int nstate = state_pert.nComp();
127  if (nstate == NVAR_max) {
128  Real omn;
129  if(moisture_type == 1) {
130  omn = std::max(0.0,std::min(1.0,(T-tbgmin)*a_bg));
131  } else if(moisture_type == 2) {
132  omn = 1.0;
133  } else {
134  omn = 0.0;
135  Abort("Invalid moisture type specified");
136  }
137  Real qn = state_pert(i, j, k, RhoQ2_comp);
138  state_pert(i, j, k, RhoQ2_comp) = qn * omn;
139  state_pert(i, j, k, RhoQ3_comp) = qn * (1.0-omn);
140  }
141  });
142  } else {
143  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
144  {
145  // Geometry (note we must include these here to get the data on device)
146  const auto prob_lo = geomdata.ProbLo();
147  const auto dx = geomdata.CellSize();
148 
149  const Real x = prob_lo[0] + (i + 0.5) * dx[0];
150  const Real y = prob_lo[1] + (j + 0.5) * dx[1];
151  const Real z = prob_lo[2] + (k + 0.5) * dx[2];
152 
153  //perturb_rho_theta(x, y, z, p_hse(i,j,k), r_hse(i,j,k), rdOcp,
154  // state_pert(i, j, k, Rho_comp),
155  // state_pert(i, j, k, RhoTheta_comp));
156 
157  // Perturbation air temperature
158  // - The bubble is either cylindrical (for 2-D problems, if two
159  // radial extents are specified) or an ellipsoid (if all three
160  // radial extents are specified).
161  Real L = 0.0;
162  if (x_r > 0) L += std::pow((x - x_c)/x_r, 2);
163  if (y_r > 0) L += std::pow((y - y_c)/y_r, 2);
164  if (z_r > 0) L += std::pow((z - z_c)/z_r, 2);
165  L = std::sqrt(L);
166  Real dT;
167  if (L > 1.0) {
168  dT = 0.0;
169  } else {
170  dT = T_pert * std::pow(cos(PI*L/2.0),2);
171  }
172 
173  // Temperature that satisfies the EOS given the hydrostatically balanced (r,p)
174  const Real Tbar_hse = p_hse(i,j,k) / (R_d * r_hse(i,j,k));
175 
176  // Note: theta_perturbed is theta PLUS perturbation in theta
177  Real theta_perturbed;
178  if (T_pert_is_airtemp) {
179  // dT is air temperature
180  theta_perturbed = (Tbar_hse + dT)*std::pow(p_0/p_hse(i,j,k), rdOcp);
181  } else {
182  // dT is potential temperature
183  theta_perturbed = Tbar_hse*std::pow(p_0/p_hse(i,j,k), rdOcp) + dT;
184  }
185 
186  if (perturb_rho)
187  {
188  // this version perturbs rho but not p (i.e., rho*theta)
189  // - hydrostatic rebalance is needed (TODO: is this true?)
190  // - this is the approach taken in the density current problem
191  state_pert(i,j,k,Rho_comp) = getRhoThetagivenP(p_hse(i,j,k)) / theta_perturbed - r_hse(i,j,k);
192  state_pert(i,j,k,RhoTheta_comp) = 0.0; // i.e., hydrostatically balanced pressure stays const
193  }
194  else
195  {
196  // this version perturbs rho*theta (i.e., p) but not rho
197  state_pert(i,j,k,Rho_comp) = 0.0; // i.e., hydrostatically balanced density stays const
198  state_pert(i,j,k,RhoTheta_comp) = r_hse(i,j,k) * theta_perturbed - getRhoThetagivenP(p_hse(i,j,k));
199  }
200  });
201  } // do_moist_bubble
constexpr amrex::Real a_bg
Definition: ERF_Constants.H:77
constexpr amrex::Real R_v
Definition: ERF_Constants.H:11
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:12
constexpr amrex::Real PI
Definition: ERF_Constants.H:6
constexpr amrex::Real p_0
Definition: ERF_Constants.H:18
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 getRhoThetagivenP(const amrex::Real p, const amrex::Real qv=0.0)
Definition: ERF_EOS.H:172
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenPandTh(const amrex::Real P, const amrex::Real th, const amrex::Real rdOcp)
Definition: ERF_EOS.H:32
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:40
#define Rho_comp
Definition: ERF_IndexDefines.H:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:43
#define NVAR_max
Definition: ERF_IndexDefines.H:24
#define RhoQ3_comp
Definition: ERF_IndexDefines.H:44
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:42
const Real dx
Definition: ERF_InitCustomPert_ABL.H:23
const int khi
Definition: ERF_InitCustomPert_Bubble.H:21
state_pert(i, j, k, RhoTheta_comp)
Real T_back
Definition: ERF_InitCustomPert_Bubble.H:111
Real z_c
Definition: ERF_InitCustomPert_Bubble.H:6
Real rho_back
Definition: ERF_InitCustomPert_Bubble.H:112
bool T_pert_is_airtemp
Definition: ERF_InitCustomPert_Bubble.H:13
Real x_r
Definition: ERF_InitCustomPert_Bubble.H:7
bool do_moist_bubble
Definition: ERF_InitCustomPert_Bubble.H:16
const Real rdOcp
Definition: ERF_InitCustomPert_Bubble.H:26
Real x_c
Definition: ERF_InitCustomPert_Bubble.H:4
ParmParse pp_prob("prob")
Real T
Definition: ERF_InitCustomPert_Bubble.H:105
background fields should have been initialized with erf init_type<< std::endl;} Real qt_init=0.02;pp_prob.query("qt_init", qt_init);Real eq_pot_temp=320.0;pp_prob.query("eq_pot_temp", eq_pot_temp);bool use_empirical=false;pp_prob.query("use_empircal_psat", use_empirical);if(do_moist_bubble) { Vector< Real > h_r(khi+2);Vector< Real > h_p(khi+2);Vector< Real > h_t(khi+2);Vector< Real > h_q_v(khi+2);Gpu::DeviceVector< Real > d_r(khi+2);Gpu::DeviceVector< Real > d_p(khi+2);Gpu::DeviceVector< Real > d_t(khi+2);Gpu::DeviceVector< Real > d_q_v(khi+2);HSEutils::init_isentropic_hse_no_terrain(h_t.data(), h_r.data(), h_p.data(), h_q_v.data(), dz, khi, qt_init, eq_pot_temp, use_empirical, false);Gpu::copyAsync(Gpu::hostToDevice, h_r.begin(), h_r.end(), d_r.begin());Gpu::copyAsync(Gpu::hostToDevice, h_p.begin(), h_p.end(), d_p.begin());Gpu::copyAsync(Gpu::hostToDevice, h_t.begin(), h_t.end(), d_t.begin());Gpu::copyAsync(Gpu::hostToDevice, h_q_v.begin(), h_q_v.end(), d_q_v.begin());Real *theta_back=d_t.data();Real *p_back=d_p.data();Real *q_v_back=d_q_v.data();int moisture_type=1;if(sc.moisture_type==MoistureType::SAM) { moisture_type=1;} else if(sc.moisture_type==MoistureType::SAM_NoIce||sc.moisture_type==MoistureType::SAM_NoPrecip_NoIce) { moisture_type=2;} ParallelFor(bx,[=] AMREX_GPU_DEVICE(int i, int j, int k) { const auto prob_lo=geomdata.ProbLo();const auto dx=geomdata.CellSize();const Real x=prob_lo[0]+(i+0.5) *dx[0];const Real y=prob_lo[1]+(j+0.5) *dx[1];const Real z=prob_lo[2]+(k+0.5) *dx[2];Real rad, delta_theta, theta_total, rho, RH;rad=0.0;if(x_r > rad
Definition: ERF_InitCustomPert_Bubble.H:93
do_moist_bubble &Real theta_pert
Definition: ERF_InitCustomPert_Bubble.H:19
Real q_v_hot
Definition: ERF_InitCustomPert_Bubble.H:108
theta_total
Definition: ERF_InitCustomPert_Bubble.H:104
Real T_0
Definition: ERF_InitCustomPert_Bubble.H:3
Real z_r
Definition: ERF_InitCustomPert_Bubble.H:9
Real y_c
Definition: ERF_InitCustomPert_Bubble.H:5
bool perturb_rho
Definition: ERF_InitCustomPert_Bubble.H:14
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
RH
Definition: ERF_InitCustomPert_Bubble.H:107
Real T_pert
Definition: ERF_InitCustomPert_Bubble.H:11
rho
Definition: ERF_InitCustomPert_Bubble.H:106
const Real dz
Definition: ERF_InitCustomPert_Bubble.H:25
Real y_r
Definition: ERF_InitCustomPert_Bubble.H:8
int nstate
Definition: ERF_InitCustomPert_Bubble.H:126
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { const auto prob_lo=geomdata.ProbLo();const auto dx=geomdata.CellSize();const Real x=(prob_lo[0]+(i+0.5) *dx[0])/mf_m(i, j, 0);const Real z=z_cc(i, j, k);Real L=std::sqrt(std::pow((x - x_c)/x_r, 2)+std::pow((z - z_c)/z_r, 2));if(L<=1.0) { Real dT=T_pert *(std::cos(PI *L)+1.0)/2.0;Real Tbar_hse=p_hse(i, j, k)/(R_d *r_hse(i, j, k));Real theta_perturbed=(Tbar_hse+dT) *std::pow(p_0/p_hse(i, j, k), rdOcp);Real theta_0=(Tbar_hse) *std::pow(p_0/p_hse(i, j, k), rdOcp);if(const_rho) { state_pert(i, j, k, RhoTheta_comp)=r_hse(i, j, k) *(theta_perturbed - theta_0);} else { state_pert(i, j, k, Rho_comp)=getRhoThetagivenP(p_hse(i, j, k))/theta_perturbed - r_hse(i, j, k);} } })
const amrex::Real * prob_lo
Definition: ERF_InitCustomPert_IsentropicVortex.H:16
Real eq_pot_temp
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:23
bool use_empirical
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:25
Real qt_init
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:24
Vector< Real > h_t(khi+2)
Gpu::DeviceVector< Real > d_t(khi+2)
Vector< Real > h_q_v(khi+2)
Gpu::DeviceVector< Real > d_p(khi+2)
Gpu::DeviceVector< Real > d_q_v(khi+2)
Vector< Real > h_r(khi+2)
Vector< Real > h_p(khi+2)
Gpu::DeviceVector< Real > d_r(khi+2)
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real vapor_mixing_ratio(const Real p_b, const Real T_b, const Real RH, const bool use_empirical, int which_zone)
Definition: ERF_HSEUtils.H:337
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=-1., const Real z_tr_2=-1., const Real theta_0=0., const Real theta_tr=0., const Real T_tr=0.)
Definition: ERF_HSEUtils.H:504
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real compute_relative_humidity(const Real p_b, const Real T_b, const bool use_empirical, const int which_zone, const Real scaled_height)
Definition: ERF_HSEUtils.H:317
@ qn
Definition: ERF_Morrison.H:33