ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitCustomPert_GATE.H
Go to the documentation of this file.
1 
2  ParmParse pp("prob");
3 
4  amrex::Real rho_0 = 0.0; pp.query("rho_0", rho_0);
5  amrex::Real T_0 = 0.0; pp.query("T_0" , T_0);
6  amrex::Real A_0 = 1.0; pp.query("A_0" , A_0);
7  amrex::Real KE_0 = 0.1; pp.query("KE_0" , KE_0);
8 
9  Real T_0_Pert_Mag = 0.0; pp.query("T_0_Pert_Mag", T_0_Pert_Mag);
10  Real qv_0_Pert_Mag = 0.0; pp.query("qv_0_Pert_Mag", qv_0_Pert_Mag);
11  Real pert_ref_height = 100.0; pp.query("pert_ref_height", pert_ref_height);
12  bool custom_TKE = false; pp.query("custom_TKE", custom_TKE);
13 
14  Real pert_deltaT = 0.0; pp.query("pert_deltaT", pert_deltaT);
15  Real pert_deltaQV = 0.0; pp.query("pert_deltaQV", pert_deltaQV);
16  Real pert_periods_T = 0.0; pp.query("pert_periods_T", pert_periods_T);
17  Real pert_periods_QV = 0.0; pp.query("pert_periods_QV", pert_periods_QV);
18 
19  auto problo_arr = geomdata.ProbLo();
20  auto probhi_arr = geomdata.ProbHi();
21 
24  Real tfac = pert_deltaT * std::exp(0.5) / pert_ref_height;
25  Real qvfac = pert_deltaQV * std::exp(0.5) / pert_ref_height;
26 
27  const bool use_moisture = (sc.moisture_type != MoistureType::None);
28 
29  const Real rdOcp = sc.rdOcp;
30 
31  ParallelForRNG(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const RandomEngine& engine) noexcept
32  {
33  // Geometry
34  const Real* prob_lo = geomdata.ProbLo();
35  const Real* prob_hi = geomdata.ProbHi();
36  const Real* dx = geomdata.CellSize();
37  const Real x = prob_lo[0] + (i + 0.5) * dx[0];
38  const Real y = prob_lo[1] + (j + 0.5) * dx[1];
39  const Real z = prob_lo[2] + (k + 0.5) * dx[2];
40 
41  // Define a point (xc,yc,zc) at the center of the domain
42  const Real xc = 0.5 * (prob_lo[0] + prob_hi[0]);
43  const Real yc = 0.5 * (prob_lo[1] + prob_hi[1]);
44  const Real zc = 0.5 * (prob_lo[2] + prob_hi[2]);
45 
46  const Real r = std::sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc) + (z-zc)*(z-zc));
47 
48  // Add temperature perturbations -- we want to keep pressure constant
49  // so these effectively end up as density perturbations
50  if ((z <= pert_ref_height) && (T_0_Pert_Mag != 0.0)) {
51 
52  Real rhotheta = state(i,j,k,RhoTheta_comp);
53  Real rho = state(i,j,k,Rho_comp);
54  Real qv = state(i,j,k,RhoQ1_comp) / rho;
55  Real Told = getTgivenRandRTh(rho,rhotheta,qv);
56  Real P = getPgivenRTh(rhotheta,qv);
57 
58  Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
59  Real Tpert = (rand_double*2.0 - 1.0)*T_0_Pert_Mag;
60  Real Tnew = Told + Tpert;
61 
62  Real theta_new = getThgivenTandP(Tnew,P,rdOcp);
63  Real rhonew = getRhogivenThetaPress(theta_new,P,rdOcp,qv);
64  state_pert(i, j, k, Rho_comp) = rhonew - rho;
65 
66  // Note we do not perturb this
67  state_pert(i, j, k, RhoTheta_comp) = 0.0;
68  }
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 * exp(-10.*r*r);
72 
73  // Set an initial value for KE
74  if (custom_TKE) {
75  state_pert(i, j, k, RhoKE_comp) = (1.0 - z/prob_hi[2]) * r_hse(i,j,k);
76  } else {
77  state_pert(i, j, k, RhoKE_comp) = KE_0;
78  }
79 
80  if (use_moisture) {
81  state_pert(i, j, k, RhoQ1_comp) = 0.0;
82  state_pert(i, j, k, RhoQ2_comp) = 0.0;
83  if ((z <= pert_ref_height) && (qv_0_Pert_Mag != 0.0))
84  {
85  Real rhoold = state(i,j,k,Rho_comp);
86  Real rhonew = rhoold + state_pert(i,j,k,Rho_comp);
87 
88  Real qvold = state(i,j,k,RhoQ1_comp) / rhoold;
89 
90  Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
91  Real qvnew = qvold + (rand_double*2.0 - 1.0)*qv_0_Pert_Mag;
92 
93  state_pert(i, j, k, RhoQ1_comp) = rhonew * qvnew - rhoold * qvold;
94  }
95  }
96 
97  // sinusoidal variation of theta and qv for regression tests
98  if (pert_deltaT != 0.0)
99  {
100  const Real zl = z / pert_ref_height;
101  const Real damp = std::exp(-0.5 * zl * zl);
102 
103  Real rhotheta = state(i,j,k,RhoTheta_comp);
104  Real rho = state(i,j,k,Rho_comp);
105  Real qv = state(i,j,k,RhoQ1_comp) / rho;
106  Real Told = getTgivenRandRTh(rho,rhotheta,qv);
107  Real P = getPgivenRTh(rhotheta,qv);
108 
109  Real Tpert = tfac * damp * z * std::cos(cval * (x - xc));
110  Real Tnew = Told + Tpert;
111 
112  Real theta_new = getThgivenTandP(Tnew,P,rdOcp);
113  Real rhonew = getRhogivenThetaPress(theta_new,P,rdOcp,qv);
114 
115  state_pert(i, j, k, Rho_comp) = rhonew - rho;
116  state_pert(i, j, k, RhoTheta_comp) = 0.0;
117  }
118 
119  if (use_moisture && pert_deltaQV != 0.0)
120  {
121  const Real zl = z / pert_ref_height;
122  const Real damp = std::exp(-0.5 * zl * zl);
123 
124  Real rhoold = state(i,j,k,Rho_comp);
125  Real rhonew = rhoold + state_pert(i,j,k,Rho_comp);
126 
127  Real qvold = state(i,j,k,RhoQ1_comp) / rhoold;
128  Real qvnew = qvold + qvfac * damp * z * std::cos(dval * (x - xc));
129 
130  state_pert(i, j, k, RhoQ1_comp) = rhonew * qvnew - rhoold * qvold;
131  }
132  });
constexpr amrex::Real PI
Definition: ERF_Constants.H:42
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:43
#define Rho_comp
Definition: ERF_IndexDefines.H:39
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:40
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:46
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:45
#define RhoKE_comp
Definition: ERF_IndexDefines.H:41
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
Real pert_periods_QV
Definition: ERF_InitCustomPert_GATE.H:17
amrex::Real A_0
Definition: ERF_InitCustomPert_GATE.H:6
Real T_0_Pert_Mag
Definition: ERF_InitCustomPert_GATE.H:9
Real pert_ref_height
Definition: ERF_InitCustomPert_GATE.H:11
const bool use_moisture
Definition: ERF_InitCustomPert_GATE.H:27
Real dval
Definition: ERF_InitCustomPert_GATE.H:23
const Real rdOcp
Definition: ERF_InitCustomPert_GATE.H:29
ParmParse pp("prob")
amrex::Real rho_0
Definition: ERF_InitCustomPert_GATE.H:4
auto probhi_arr
Definition: ERF_InitCustomPert_GATE.H:20
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+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];const Real xc=0.5 *(prob_lo[0]+prob_hi[0]);const Real yc=0.5 *(prob_lo[1]+prob_hi[1]);const Real zc=0.5 *(prob_lo[2]+prob_hi[2]);const Real r=std::sqrt((x-xc) *(x-xc)+(y-yc) *(y-yc)+(z-zc) *(z-zc));if((z<=pert_ref_height) &&(T_0_Pert_Mag !=0.0)) { Real rhotheta=state(i, j, k, RhoTheta_comp);Real rho=state(i, j, k, Rho_comp);Real qv=state(i, j, k, RhoQ1_comp)/rho;Real Told=getTgivenRandRTh(rho, rhotheta, qv);Real P=getPgivenRTh(rhotheta, qv);Real rand_double=amrex::Random(engine);Real Tpert=(rand_double *2.0 - 1.0) *T_0_Pert_Mag;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)=0.0;} state_pert(i, j, k, RhoScalar_comp)=A_0 *exp(-10.*r *r);if(custom_TKE) { state_pert(i, j, k, RhoKE_comp)=(1.0 - z/prob_hi[2]) *r_hse(i, j, k);} else { state_pert(i, j, k, RhoKE_comp)=KE_0;} if(use_moisture) { state_pert(i, j, k, RhoQ1_comp)=0.0;state_pert(i, j, k, RhoQ2_comp)=0.0;if((z<=pert_ref_height) &&(qv_0_Pert_Mag !=0.0)) { 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 rand_double=amrex::Random(engine);Real qvnew=qvold+(rand_double *2.0 - 1.0) *qv_0_Pert_Mag;state_pert(i, j, k, RhoQ1_comp)=rhonew *qvnew - rhoold *qvold;} } if(pert_deltaT !=0.0) { const Real zl=z/pert_ref_height;const Real damp=std::exp(-0.5 *zl *zl);Real rhotheta=state(i, j, k, RhoTheta_comp);Real rho=state(i, j, k, Rho_comp);Real qv=state(i, j, k, RhoQ1_comp)/rho;Real Told=getTgivenRandRTh(rho, rhotheta, qv);Real P=getPgivenRTh(rhotheta, qv);Real Tpert=tfac *damp *z *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)=0.0;} if(use_moisture &&pert_deltaQV !=0.0) { const Real zl=z/pert_ref_height;const Real damp=std::exp(-0.5 *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 *std::cos(dval *(x - xc));state_pert(i, j, k, RhoQ1_comp)=rhonew *qvnew - rhoold *qvold;} })
Real tfac
Definition: ERF_InitCustomPert_GATE.H:24
amrex::Real KE_0
Definition: ERF_InitCustomPert_GATE.H:7
auto problo_arr
Definition: ERF_InitCustomPert_GATE.H:19
Real pert_deltaQV
Definition: ERF_InitCustomPert_GATE.H:15
Real pert_periods_T
Definition: ERF_InitCustomPert_GATE.H:16
Real qvfac
Definition: ERF_InitCustomPert_GATE.H:25
Real qv_0_Pert_Mag
Definition: ERF_InitCustomPert_GATE.H:10
Real pert_deltaT
Definition: ERF_InitCustomPert_GATE.H:14
amrex::Real T_0
Definition: ERF_InitCustomPert_GATE.H:5
Real cval
Definition: ERF_InitCustomPert_GATE.H:22
bool custom_TKE
Definition: ERF_InitCustomPert_GATE.H:12
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ P
Definition: ERF_IndexDefines.H:204
@ rho
Definition: ERF_Kessler.H:24
@ qv
Definition: ERF_Kessler.H:30