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