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