ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitCustomPert_GATE.H
Go to the documentation of this file.
1 
2  // On a mesh other than ConstantDz, heights come from z_cc and the vertical levels,
3  // not from geomdata's prob_lo[2], prob_hi[2] and CellSize(2)
4  const bool use_z_phys = use_physical_z();
5  const Real phys_z_lo = phys_zlo(geomdata, lev);
6  const Real phys_z_hi = phys_zhi(geomdata, lev);
7 
8  ParmParse pp("prob");
9 
10  amrex::Real rho_0 = zero; pp.query("rho_0", rho_0);
11  amrex::Real T_0 = zero; pp.query("T_0" , T_0);
12  amrex::Real A_0 = one; pp.query("A_0" , A_0);
13  amrex::Real KE_0 = amrex::Real(0.1); pp.query("KE_0" , KE_0);
14 
15  Real T_0_Pert_Mag = zero; pp.query("T_0_Pert_Mag", T_0_Pert_Mag);
16  Real qv_0_Pert_Mag = zero; pp.query("qv_0_Pert_Mag", qv_0_Pert_Mag);
17  Real pert_ref_height = amrex::Real(100.0); pp.query("pert_ref_height", pert_ref_height);
18  bool custom_TKE = false; pp.query("custom_TKE", custom_TKE);
19 
20  Real pert_deltaT = zero; pp.query("pert_deltaT", pert_deltaT);
21  Real pert_deltaQV = zero; pp.query("pert_deltaQV", pert_deltaQV);
22  // The periods default to 5, as pert_periods_U/V do: a zero period would make
23  // cos(cval*(x-xc)) identically one, a uniform bias rather than a zero-mean wave
24  Real pert_periods_T = amrex::Real(5.0); pp.query("pert_periods_T", pert_periods_T);
25  Real pert_periods_QV = amrex::Real(5.0); pp.query("pert_periods_QV", pert_periods_QV);
26 
27  auto problo_arr = geomdata.ProbLo();
28  auto probhi_arr = geomdata.ProbHi();
29 
34 
35  const bool use_moisture = (sc.moisture_type != MoistureType::None);
36 
37  const Real rdOcp = sc.rdOcp;
38 
39  ParallelForRNG(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const RandomEngine& engine) noexcept
40  {
41  // Geometry
42  const Real* prob_lo = geomdata.ProbLo();
43  const Real* prob_hi = geomdata.ProbHi();
44  const Real* dx = geomdata.CellSize();
45  const Real x = prob_lo[0] + (i + myhalf) * dx[0];
46  const Real y = prob_lo[1] + (j + myhalf) * dx[1];
47  const Real z = use_z_phys ? z_cc(i,j,k) : prob_lo[2] + (k + myhalf) * dx[2];
48  const Real z_agl = z - erf_prob_heights::z_ground_cc(i,j,z_sfc_nd); // height above the ground
49 
50  // Define a point (xc,yc,zc) at the center of the domain
51  const Real xc = myhalf * (prob_lo[0] + prob_hi[0]);
52  const Real yc = myhalf * (prob_lo[1] + prob_hi[1]);
53  const Real zc = myhalf * (phys_z_lo + phys_z_hi);
54 
55  const Real r = std::sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc) + (z-zc)*(z-zc));
56 
57  // Temperature and qv perturbations: the random ones (T_0_Pert_Mag, qv_0_Pert_Mag)
58  // and the sinusoidal ones for regression tests (pert_deltaT, pert_deltaQV) are
59  // summed, then applied once, so that turning on one does not discard the other
60  const bool rand_T = (z_agl <= pert_ref_height) && (T_0_Pert_Mag != zero);
61  const bool rand_qv = use_moisture && (z_agl <= pert_ref_height) && (qv_0_Pert_Mag != zero);
62  const bool sin_T = (pert_deltaT != zero);
63  const bool sin_qv = use_moisture && (pert_deltaQV != zero);
64 
65  // The random numbers are drawn in the same order as when each was applied on its own
66  Real dT = zero;
67  Real dqv = zero;
68  if (rand_T) {
69  Real rand_double = amrex::Random(engine); // Between zero and one
70  dT += (rand_double*two - one)*T_0_Pert_Mag;
71  }
72  if (rand_qv) {
73  Real rand_double = amrex::Random(engine); // Between zero and one
74  dqv += (rand_double*two - one)*qv_0_Pert_Mag;
75  }
76  if (sin_T || sin_qv) {
77  const Real zl = z_agl / pert_ref_height;
78  const Real damp = std::exp(-myhalf * zl * zl);
79  if (sin_T) { dT += tfac * damp * z_agl * std::cos(cval * (x - xc)); }
80  if (sin_qv) { dqv += qvfac * damp * z_agl * std::cos(dval * (x - xc)); }
81  }
82 
83  // Apply both at once (ERF_MoistPerturbation.H): the temperature perturbation at
84  // fixed pressure ends up as a density perturbation (rho*theta is held), and qv
85  // becomes qv + dqv on the new density, so a temperature perturbation alone
86  // leaves qv, and the pressure, as they were
87  if (rand_T || sin_T || rand_qv || sin_qv) {
88  Real drho, drhoqv;
90  state(i,j,k,Rho_comp), state(i,j,k,RhoTheta_comp),
91  use_moisture ? state(i,j,k,RhoQ1_comp) : zero, dT, dqv,
92  rand_T || sin_T, use_moisture, rdOcp, drho, drhoqv);
93  if (rand_T || sin_T) {
94  state_pert(i, j, k, Rho_comp) = drho;
95  // Note we do not perturb this
96  state_pert(i, j, k, RhoTheta_comp) = zero;
97  }
98  if (use_moisture) { state_pert(i, j, k, RhoQ1_comp) = drhoqv; }
99  }
100 
101  // Set scalar = A_0*exp(-10r^2), where r is distance from center of domain
102  state_pert(i, j, k, RhoScalar_comp) = A_0 * std::exp(-amrex::Real(10.)*r*r);
103 
104  // Set an initial value for KE
105  if (custom_TKE) {
106  state_pert(i, j, k, RhoKE_comp) = (one - z/phys_z_hi) * r_hse(i,j,k);
107  } else {
108  state_pert(i, j, k, RhoKE_comp) = KE_0;
109  }
110 
111  if (use_moisture) {
112  // The density change above would change qc with it; rescale rho*qc so the
113  // cloud-water mixing ratio is held, as in Aaron Lattanzi's #4772 for BOMEX
114  state_pert(i, j, k, RhoQ2_comp) = state_pert(i,j,k,Rho_comp)
115  * state(i,j,k,RhoQ2_comp) / state(i,j,k,Rho_comp);
116  }
117  });
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:57
#define Rho_comp
Definition: ERF_IndexDefines.H:53
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:54
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:67
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:66
#define RhoKE_comp
Definition: ERF_IndexDefines.H:55
const Real zc
Definition: ERF_InitCustomPert_ABL.H:56
const Real yc
Definition: ERF_InitCustomPert_ABL.H:55
const Real xc
Definition: ERF_InitCustomPert_ABL.H:54
const Real dx
Definition: ERF_InitCustomPert_ABL.H:44
const GpuArray< Real, AMREX_SPACEDIM > prob_lo
Definition: ERF_InitCustomPert_CloudChamber.H:33
const amrex::Real * prob_hi
Definition: ERF_InitCustomPert_DataAssimilation_ISV.H:17
const bool use_z_phys
Definition: ERF_InitCustomPert_GATE.H:4
Real pert_periods_QV
Definition: ERF_InitCustomPert_GATE.H:25
amrex::Real A_0
Definition: ERF_InitCustomPert_GATE.H:12
Real T_0_Pert_Mag
Definition: ERF_InitCustomPert_GATE.H:15
Real pert_ref_height
Definition: ERF_InitCustomPert_GATE.H:17
const bool use_moisture
Definition: ERF_InitCustomPert_GATE.H:35
Real dval
Definition: ERF_InitCustomPert_GATE.H:31
const Real rdOcp
Definition: ERF_InitCustomPert_GATE.H:37
const Real phys_z_hi
Definition: ERF_InitCustomPert_GATE.H:6
ParmParse pp("prob")
amrex::Real rho_0
Definition: ERF_InitCustomPert_GATE.H:10
auto probhi_arr
Definition: ERF_InitCustomPert_GATE.H:28
Real tfac
Definition: ERF_InitCustomPert_GATE.H:32
amrex::Real KE_0
Definition: ERF_InitCustomPert_GATE.H:13
auto problo_arr
Definition: ERF_InitCustomPert_GATE.H:27
Real pert_deltaQV
Definition: ERF_InitCustomPert_GATE.H:21
Real pert_periods_T
Definition: ERF_InitCustomPert_GATE.H:24
Real qvfac
Definition: ERF_InitCustomPert_GATE.H:33
ParallelForRNG(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const RandomEngine &engine) noexcept { const Real *prob_lo=geomdata.ProbLo();const Real *prob_hi=geomdata.ProbHi();const Real *dx=geomdata.CellSize();const Real x=prob_lo[0]+(i+myhalf) *dx[0];const Real y=prob_lo[1]+(j+myhalf) *dx[1];const Real z=use_z_phys ? z_cc(i, j, k) :prob_lo[2]+(k+myhalf) *dx[2];const Real z_agl=z - erf_prob_heights::z_ground_cc(i, j, z_sfc_nd);const Real xc=myhalf *(prob_lo[0]+prob_hi[0]);const Real yc=myhalf *(prob_lo[1]+prob_hi[1]);const Real zc=myhalf *(phys_z_lo+phys_z_hi);const Real r=std::sqrt((x-xc) *(x-xc)+(y-yc) *(y-yc)+(z-zc) *(z-zc));const bool rand_T=(z_agl<=pert_ref_height) &&(T_0_Pert_Mag !=zero);const bool rand_qv=use_moisture &&(z_agl<=pert_ref_height) &&(qv_0_Pert_Mag !=zero);const bool sin_T=(pert_deltaT !=zero);const bool sin_qv=use_moisture &&(pert_deltaQV !=zero);Real dT=zero;Real dqv=zero;if(rand_T) { Real rand_double=amrex::Random(engine);dT+=(rand_double *two - one) *T_0_Pert_Mag;} if(rand_qv) { Real rand_double=amrex::Random(engine);dqv+=(rand_double *two - one) *qv_0_Pert_Mag;} if(sin_T||sin_qv) { const Real zl=z_agl/pert_ref_height;const Real damp=std::exp(-myhalf *zl *zl);if(sin_T) { dT+=tfac *damp *z_agl *std::cos(cval *(x - xc));} if(sin_qv) { dqv+=qvfac *damp *z_agl *std::cos(dval *(x - xc));} } if(rand_T||sin_T||rand_qv||sin_qv) { Real drho, drhoqv;erf_moist_perturbation::perturb_temperature_and_vapour(state(i, j, k, Rho_comp), state(i, j, k, RhoTheta_comp), use_moisture ? state(i, j, k, RhoQ1_comp) :zero, dT, dqv, rand_T||sin_T, use_moisture, rdOcp, drho, drhoqv);if(rand_T||sin_T) { state_pert(i, j, k, Rho_comp)=drho;state_pert(i, j, k, RhoTheta_comp)=zero;} if(use_moisture) { state_pert(i, j, k, RhoQ1_comp)=drhoqv;} } state_pert(i, j, k, RhoScalar_comp)=A_0 *std::exp(-amrex::Real(10.) *r *r);if(custom_TKE) { state_pert(i, j, k, RhoKE_comp)=(one - z/phys_z_hi) *r_hse(i, j, k);} else { state_pert(i, j, k, RhoKE_comp)=KE_0;} if(use_moisture) { state_pert(i, j, k, RhoQ2_comp)=state_pert(i, j, k, Rho_comp) *state(i, j, k, RhoQ2_comp)/state(i, j, k, Rho_comp);} })
Real qv_0_Pert_Mag
Definition: ERF_InitCustomPert_GATE.H:16
Real pert_deltaT
Definition: ERF_InitCustomPert_GATE.H:20
amrex::Real T_0
Definition: ERF_InitCustomPert_GATE.H:11
Real cval
Definition: ERF_InitCustomPert_GATE.H:30
bool custom_TKE
Definition: ERF_InitCustomPert_GATE.H:18
const Real phys_z_lo
Definition: ERF_InitCustomPert_GATE.H:5
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
constexpr amrex::Real PI
Definition: ERF_NumericalConstants.H:46
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ None
Definition: ERF_LSM_Types.H:6
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void perturb_temperature_and_vapour(const amrex::Real rho, const amrex::Real rhotheta, const amrex::Real rhoqv, const amrex::Real dT, const amrex::Real dqv, const bool perturb_T, const bool moist, const amrex::Real rdOcp, amrex::Real &drho, amrex::Real &drhoqv) noexcept
Definition: ERF_MoistPerturbation.H:39
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real z_ground_cc(int i, int j, amrex::Array4< amrex::Real const > const &z_sfc_nd) noexcept
Definition: ERF_ProbHeights.H:49