ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitCustomPert_SDMCongestus3DCold.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 Q_0_Pert_Mag = zero; pp.query("Q_0_Pert_Mag", Q_0_Pert_Mag);
17  Real pert_ref_height = amrex::Real(100.0); pp.query("pert_ref_height", pert_ref_height);
18 
19  Real pert_deltaT = zero; pp.query("pert_deltaT", pert_deltaT);
20  Real pert_deltaQV = zero; pp.query("pert_deltaQV", pert_deltaQV);
21  // The periods default to 5, as pert_periods_U/V do: a zero period would make
22  // cos(cval*(x-xc)) identically one, a uniform bias rather than a zero-mean wave
23  Real pert_periods_T = amrex::Real(5.0); pp.query("pert_periods_T", pert_periods_T);
24  Real pert_periods_QV = amrex::Real(5.0); pp.query("pert_periods_QV", pert_periods_QV);
25 
26  auto problo_arr = geomdata.ProbLo();
27  auto probhi_arr = geomdata.ProbHi();
28 
33 
34  const bool use_moisture = (sc.moisture_type != MoistureType::None);
35 
36  const Real rdOcp = sc.rdOcp;
37 
38  ParallelForRNG(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept {
39  // Geometry
40  const Real* prob_lo = geomdata.ProbLo();
41  const Real* prob_hi = geomdata.ProbHi();
42  const Real* dx = geomdata.CellSize();
43  const Real x = prob_lo[0] + (i + myhalf) * dx[0];
44  const Real y = prob_lo[1] + (j + myhalf) * dx[1];
45  const Real z = use_z_phys ? z_cc(i,j,k) : prob_lo[2] + (k + myhalf) * dx[2];
46  const Real z_agl = z - erf_prob_heights::z_ground_cc(i,j,z_sfc_nd); // height above the ground
47 
48  // Define a point (xc,yc,zc) at the center of the domain
49  const Real xc = myhalf * (prob_lo[0] + prob_hi[0]);
50  const Real yc = myhalf * (prob_lo[1] + prob_hi[1]);
51  const Real zc = myhalf * (phys_z_lo + phys_z_hi);
52 
53  const Real r = std::sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc) + (z-zc)*(z-zc));
54 
55  // Add temperature perturbations
56  if ((z_agl <= pert_ref_height) && (T_0_Pert_Mag != zero)) {
57  Real rand_double = amrex::Random(engine); // Between zero and one
58  state_pert(i, j, k, RhoTheta_comp) = (rand_double*two - one)*T_0_Pert_Mag;
59  }
60  if (use_moisture && (z_agl <= pert_ref_height) && (Q_0_Pert_Mag != zero)) {
61  Real rand_double = amrex::Random(engine); // Between zero and one
62  state_pert(i, j, k, RhoQ1_comp) = (rand_double*two - one)*Q_0_Pert_Mag;
63  }
64 
65  // Set scalar = A_0*exp(-10r^2), where r is distance from center of domain
66  state_pert(i, j, k, RhoScalar_comp) = A_0 * exp(-amrex::Real(10.)*r*r);
67 
68  // Set an initial value for KE
69  state_pert(i, j, k, RhoKE_comp) = KE_0;
70 
71  // sinusoidal variation of theta and qv for regression tests
72  if (pert_deltaT != zero)
73  {
74  const Real zl = z_agl / pert_ref_height;
75  const Real damp = std::exp(-myhalf * zl * zl);
76 
77  Real rhotheta = state(i,j,k,RhoTheta_comp);
78  Real rho = state(i,j,k,Rho_comp);
79  Real qv = (use_moisture) ? state(i,j,k,RhoQ1_comp) / rho : zero;
80  Real Told = getTgivenRandRTh(rho,rhotheta,qv);
81  Real P = getPgivenRTh(rhotheta,qv);
82 
83  Real Tpert = tfac * damp * z_agl * std::cos(cval * (x - xc));
84  Real Tnew = Told + Tpert;
85 
86  Real theta_new = getThgivenTandP(Tnew,P,rdOcp);
87  Real rhonew = getRhogivenThetaPress(theta_new,P,rdOcp,qv);
88 
89  state_pert(i, j, k, Rho_comp) = rhonew - rho;
90  state_pert(i, j, k, RhoTheta_comp) = zero;
91  }
92 
93  if (use_moisture && pert_deltaQV != zero)
94  {
95  const Real zl = z_agl / pert_ref_height;
96  const Real damp = std::exp(-myhalf * zl * zl);
97 
98  Real rhoold = state(i,j,k,Rho_comp);
99  Real rhonew = rhoold + state_pert(i,j,k,Rho_comp);
100 
101  Real qvold = state(i,j,k,RhoQ1_comp) / rhoold;
102  Real qvnew = qvold + qvfac * damp * z_agl * std::cos(dval * (x - xc));
103 
104  state_pert(i, j, k, RhoQ1_comp) = rhonew * qvnew - rhoold * qvold;
105  }
106  });
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getRhogivenThetaPress(const amrex::Real th, const amrex::Real p, const amrex::Real rdOcp, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:96
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenRandRTh(const amrex::Real rho, const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:46
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getThgivenTandP(const amrex::Real T, const amrex::Real P, const amrex::Real rdOcp)
Definition: ERF_EOS.H:18
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
#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 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_SDMCongestus3DCold.H:4
Real pert_periods_QV
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:24
amrex::Real A_0
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:12
Real T_0_Pert_Mag
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:15
Real pert_ref_height
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:17
const bool use_moisture
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:34
Real dval
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:30
const Real rdOcp
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:36
const Real phys_z_hi
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:6
Real Q_0_Pert_Mag
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:16
ParmParse pp("prob")
amrex::Real rho_0
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:10
auto probhi_arr
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:27
Real tfac
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:31
amrex::Real KE_0
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:13
auto problo_arr
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:26
Real pert_deltaQV
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:20
Real pert_periods_T
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:23
Real qvfac
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:32
ParallelForRNG(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::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));if((z_agl<=pert_ref_height) &&(T_0_Pert_Mag !=zero)) { Real rand_double=amrex::Random(engine);state_pert(i, j, k, RhoTheta_comp)=(rand_double *two - one) *T_0_Pert_Mag;} if(use_moisture &&(z_agl<=pert_ref_height) &&(Q_0_Pert_Mag !=zero)) { Real rand_double=amrex::Random(engine);state_pert(i, j, k, RhoQ1_comp)=(rand_double *two - one) *Q_0_Pert_Mag;} state_pert(i, j, k, RhoScalar_comp)=A_0 *exp(-amrex::Real(10.) *r *r);state_pert(i, j, k, RhoKE_comp)=KE_0;if(pert_deltaT !=zero) { const Real zl=z_agl/pert_ref_height;const Real damp=std::exp(-myhalf *zl *zl);Real rhotheta=state(i, j, k, RhoTheta_comp);Real rho=state(i, j, k, Rho_comp);Real qv=(use_moisture) ? state(i, j, k, RhoQ1_comp)/rho :zero;Real Told=getTgivenRandRTh(rho, rhotheta, qv);Real P=getPgivenRTh(rhotheta, qv);Real Tpert=tfac *damp *z_agl *std::cos(cval *(x - xc));Real Tnew=Told+Tpert;Real theta_new=getThgivenTandP(Tnew, P, rdOcp);Real rhonew=getRhogivenThetaPress(theta_new, P, rdOcp, qv);state_pert(i, j, k, Rho_comp)=rhonew - rho;state_pert(i, j, k, RhoTheta_comp)=zero;} if(use_moisture &&pert_deltaQV !=zero) { const Real zl=z_agl/pert_ref_height;const Real damp=std::exp(-myhalf *zl *zl);Real rhoold=state(i, j, k, Rho_comp);Real rhonew=rhoold+state_pert(i, j, k, Rho_comp);Real qvold=state(i, j, k, RhoQ1_comp)/rhoold;Real qvnew=qvold+qvfac *damp *z_agl *std::cos(dval *(x - xc));state_pert(i, j, k, RhoQ1_comp)=rhonew *qvnew - rhoold *qvold;} })
Real pert_deltaT
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:19
amrex::Real T_0
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:11
Real cval
Definition: ERF_InitCustomPert_SDMCongestus3DCold.H:29
const Real phys_z_lo
Definition: ERF_InitCustomPert_SDMCongestus3DCold.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
@ P
Definition: ERF_IndexDefines.H:244
@ rho
Definition: ERF_Kessler.H:25
@ qv
Definition: ERF_Kessler.H:31
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