ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitCustomPertVels_Bomex.H
Go to the documentation of this file.
1 
2  ParmParse pp_prob("prob");
3 
4  Real U_0 = 0.0; pp_prob.query("U_0", U_0);
5  Real V_0 = 0.0; pp_prob.query("V_0", V_0);
6  Real W_0 = 0.0; pp_prob.query("W_0", W_0);
7 
8  // random initial perturbations (legacy code)
9  Real U_0_Pert_Mag = 0.0; pp_prob.query("U_0_Pert_Mag", U_0_Pert_Mag);
10  Real V_0_Pert_Mag = 0.0; pp_prob.query("V_0_Pert_Mag", V_0_Pert_Mag);
11  Real W_0_Pert_Mag = 0.0; pp_prob.query("W_0_Pert_Mag", W_0_Pert_Mag);
12  Real qv_0_Pert_Mag = 0.0; pp_prob.query("qv_0_Pert_Mag", qv_0_Pert_Mag);
13 
14  // divergence-free initial perturbations
15  Real pert_deltaU = 0.0; pp_prob.query("pert_deltaU", pert_deltaU);
16  Real pert_deltaV = 0.0; pp_prob.query("pert_deltaV", pert_deltaV);
17  Real pert_periods_U = 5.0; pp_prob.query("pert_periods_U", pert_periods_U);
18  Real pert_periods_V = 5.0; pp_prob.query("pert_periods_V", pert_periods_V);
19  Real pert_ref_height = 100.0; pp_prob.query("pert_ref_height", pert_ref_height);
20 
21  auto problo = geomdata.ProbLo();
22  auto probhi = geomdata.ProbHi();
23 
24  Real aval = pert_periods_U * 2.0 * PI / (probhi[1] - problo[1]);
25  Real bval = pert_periods_V * 2.0 * PI / (probhi[0] - problo[0]);
26  Real ufac = pert_deltaU * std::exp(0.5) / pert_ref_height;
27  Real vfac = pert_deltaV * std::exp(0.5) / pert_ref_height;
28 
29  // Set the x-velocity
30  ParallelForRNG(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const RandomEngine& engine) noexcept
31  {
32  const Real* prob_lo = geomdata.ProbLo();
33  const Real* dx = geomdata.CellSize();
34  const Real y = prob_lo[1] + (j + 0.5) * dx[1];
35  const Real z = prob_lo[2] + (k + 0.5) * dx[2];
36 
37  // Set the x-velocity
38  x_vel_pert(i, j, k) = U_0;
39  if ((z <= pert_ref_height) && (U_0_Pert_Mag != 0.0))
40  {
41  Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
42  Real x_vel_prime = (rand_double*2.0 - 1.0)*U_0_Pert_Mag;
43  x_vel_pert(i, j, k) += x_vel_prime;
44  }
45  if (pert_deltaU != 0.0)
46  {
47  const amrex::Real yl = y - prob_lo[1];
48  const amrex::Real zl = z / pert_ref_height;
49  const amrex::Real damp = std::exp(-0.5 * zl * zl);
50  x_vel_pert(i, j, k) += ufac * damp * z * std::cos(aval * yl);
51  }
52  });
53 
54  // Set the y-velocity
55  ParallelForRNG(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const RandomEngine& engine) noexcept
56  {
57  const Real* prob_lo = geomdata.ProbLo();
58  const Real* dx = geomdata.CellSize();
59  const Real x = prob_lo[0] + (i + 0.5) * dx[0];
60  const Real z = prob_lo[2] + (k + 0.5) * dx[2];
61 
62  // Set the y-velocity
63  y_vel_pert(i, j, k) = V_0;
64  if ((z <= pert_ref_height) && (V_0_Pert_Mag != 0.0))
65  {
66  Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
67  Real y_vel_prime = (rand_double*2.0 - 1.0)*V_0_Pert_Mag;
68  y_vel_pert(i, j, k) += y_vel_prime;
69  }
70  if (pert_deltaV != 0.0)
71  {
72  const amrex::Real xl = x - prob_lo[0];
73  const amrex::Real zl = z / pert_ref_height;
74  const amrex::Real damp = std::exp(-0.5 * zl * zl);
75  y_vel_pert(i, j, k) += vfac * damp * z * std::cos(bval * xl);
76  }
77  });
78 
79  // Set the z-velocity
80  ParallelForRNG(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const RandomEngine& engine) noexcept
81  {
82  const int dom_lo_z = geomdata.Domain().smallEnd()[2];
83  const int dom_hi_z = geomdata.Domain().bigEnd()[2];
84 // Set the z-velocity
85  if (k == dom_lo_z || k == dom_hi_z+1)
86  {
87  z_vel_pert(i, j, k) = 0.0;
88  }
89  else if (W_0_Pert_Mag != 0.0)
90  {
91  Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0
92  Real z_vel_prime = (rand_double*2.0 - 1.0)*W_0_Pert_Mag;
93  z_vel_pert(i, j, k) = W_0 + z_vel_prime;
94  }
95  });
constexpr amrex::Real PI
Definition: ERF_Constants.H:6
Real bval
Definition: ERF_InitCustomPertVels_Bomex.H:25
Real aval
Definition: ERF_InitCustomPertVels_Bomex.H:24
Real W_0_Pert_Mag
Definition: ERF_InitCustomPertVels_Bomex.H:11
Real pert_ref_height
Definition: ERF_InitCustomPertVels_Bomex.H:19
ParallelForRNG(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const RandomEngine &engine) noexcept { const Real *prob_lo=geomdata.ProbLo();const Real *dx=geomdata.CellSize();const Real y=prob_lo[1]+(j+0.5) *dx[1];const Real z=prob_lo[2]+(k+0.5) *dx[2];x_vel_pert(i, j, k)=U_0;if((z<=pert_ref_height) &&(U_0_Pert_Mag !=0.0)) { Real rand_double=amrex::Random(engine);Real x_vel_prime=(rand_double *2.0 - 1.0) *U_0_Pert_Mag;x_vel_pert(i, j, k)+=x_vel_prime;} if(pert_deltaU !=0.0) { const amrex::Real yl=y - prob_lo[1];const amrex::Real zl=z/pert_ref_height;const amrex::Real damp=std::exp(-0.5 *zl *zl);x_vel_pert(i, j, k)+=ufac *damp *z *std::cos(aval *yl);} })
auto probhi
Definition: ERF_InitCustomPertVels_Bomex.H:22
ParmParse pp_prob("prob")
Real U_0_Pert_Mag
Definition: ERF_InitCustomPertVels_Bomex.H:9
Real pert_periods_V
Definition: ERF_InitCustomPertVels_Bomex.H:18
Real vfac
Definition: ERF_InitCustomPertVels_Bomex.H:27
Real pert_deltaV
Definition: ERF_InitCustomPertVels_Bomex.H:16
Real U_0
Definition: ERF_InitCustomPertVels_Bomex.H:4
Real ufac
Definition: ERF_InitCustomPertVels_Bomex.H:26
Real V_0
Definition: ERF_InitCustomPertVels_Bomex.H:5
Real pert_deltaU
Definition: ERF_InitCustomPertVels_Bomex.H:15
Real pert_periods_U
Definition: ERF_InitCustomPertVels_Bomex.H:17
Real W_0
Definition: ERF_InitCustomPertVels_Bomex.H:6
Real V_0_Pert_Mag
Definition: ERF_InitCustomPertVels_Bomex.H:10
auto problo
Definition: ERF_InitCustomPertVels_Bomex.H:21
Real qv_0_Pert_Mag
Definition: ERF_InitCustomPertVels_Bomex.H:12
const Real dx
Definition: ERF_InitCustomPert_ABL.H:23
const amrex::Real * prob_lo
Definition: ERF_InitCustomPert_IsentropicVortex.H:16
const Box zbx
Definition: ERF_SetupDiff.H:9
const Box xbx
Definition: ERF_SetupDiff.H:7
const Box ybx
Definition: ERF_SetupDiff.H:8
amrex::Real Real
Definition: ERF_ShocInterface.H:19