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 
5  int fix_random_seed = 0;
6  long random_seed = -1;
7  {
8  ParmParse pp_erf("erf");
9  pp_erf.query("deterministic_ic_pert", deterministic_ic_pert);
10  pp_erf.query("fix_random_seed", fix_random_seed);
11  pp_erf.query("random_seed", random_seed);
12  }
13  const std::uint64_t ic_pert_seed = fix_random_seed
14  ? std::uint64_t(1024)
15  : ((random_seed >= 0) ? static_cast<std::uint64_t>(random_seed) : std::uint64_t(0));
16  constexpr int x_velocity_hash_comp = 1;
17  constexpr int y_velocity_hash_comp = 2;
18  constexpr int z_velocity_hash_comp = 3;
19 
20  Real U_0 = zero; pp_prob.query("U_0", U_0);
21  Real V_0 = zero; pp_prob.query("V_0", V_0);
22  Real W_0 = zero; pp_prob.query("W_0", W_0);
23 
24  // random initial perturbations (legacy code)
25  Real U_0_Pert_Mag = zero; pp_prob.query("U_0_Pert_Mag", U_0_Pert_Mag);
26  Real V_0_Pert_Mag = zero; pp_prob.query("V_0_Pert_Mag", V_0_Pert_Mag);
27  Real W_0_Pert_Mag = zero; pp_prob.query("W_0_Pert_Mag", W_0_Pert_Mag);
28 
29  // divergence-free initial perturbations
30  Real pert_deltaU = zero; pp_prob.query("pert_deltaU", pert_deltaU);
31  Real pert_deltaV = zero; pp_prob.query("pert_deltaV", pert_deltaV);
32  Real pert_periods_U = amrex::Real(5.0); pp_prob.query("pert_periods_U", pert_periods_U);
33  Real pert_periods_V = amrex::Real(5.0); pp_prob.query("pert_periods_V", pert_periods_V);
34  Real pert_ref_height = amrex::Real(100.0); pp_prob.query("pert_ref_height", pert_ref_height);
35 
36  auto problo = geomdata.ProbLo();
37  auto probhi = geomdata.ProbHi();
38 
39  Real aval = pert_periods_U * two * PI / (probhi[1] - problo[1]);
40  Real bval = pert_periods_V * two * PI / (probhi[0] - problo[0]);
43 
44  if (pert_ref_height > 0) {
45  if ((pert_deltaU != zero) || (pert_deltaV != zero)) {
46  amrex::Print() << "Adding divergence-free perturbations "
47  << pert_deltaU << " " << pert_deltaV
48  << std::endl;
49  }
50  if (U_0_Pert_Mag != zero) {
51  amrex::Print() << "Adding random x-velocity perturbations" << std::endl;
52  }
53  if (V_0_Pert_Mag != zero) {
54  amrex::Print() << "Adding random y-velocity perturbations" << std::endl;
55  }
56  }
57 
58  // Set the x-velocity
59  ParallelForRNG(xbx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept {
60  const Real* prob_lo = geomdata.ProbLo();
61  const Real* dx = geomdata.CellSize();
62  const Real y = prob_lo[1] + (j + myhalf) * dx[1];
63  const Real z = (z_nd) ? fourth*( z_nd(i,j ,k) + z_nd(i,j ,k+1)
64  + z_nd(i,j+1,k) + z_nd(i,j+1,k+1) )
65  : prob_lo[2] + (k + myhalf) * dx[2];
66  const Real z_agl = z - erf_prob_heights::z_ground_xface(i,j,z_sfc_nd); // height above the ground
67 
68  // Set the x-velocity
69  x_vel_pert(i, j, k) = U_0;
70  if ((z_agl <= pert_ref_height) && (U_0_Pert_Mag != zero))
71  {
72  Real rand_double;
74  rand_double = erf_hash_rng::hash_uniform(
75  i, j, k, x_velocity_hash_comp, lev, ic_pert_seed);
76  } else {
77  rand_double = amrex::Random(engine); // Between zero and one
78  }
79  Real x_vel_prime = (rand_double*two - one)*U_0_Pert_Mag;
80  x_vel_pert(i, j, k) += x_vel_prime;
81  }
82  if (pert_deltaU != zero)
83  {
84  const amrex::Real yl = y - prob_lo[1];
85  const amrex::Real zl = z_agl / pert_ref_height;
86  const amrex::Real damp = std::exp(-myhalf * zl * zl);
87  x_vel_pert(i, j, k) += ufac * damp * z_agl * std::cos(aval * yl);
88  }
89  });
90 
91  // Set the y-velocity
92  ParallelForRNG(ybx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept
93  {
94  const Real* prob_lo = geomdata.ProbLo();
95  const Real* dx = geomdata.CellSize();
96  const Real x = prob_lo[0] + (i + myhalf) * dx[0];
97  const Real z = (z_nd) ? fourth*( z_nd(i ,j,k) + z_nd(i ,j,k+1)
98  + z_nd(i+1,j,k) + z_nd(i+1,j,k+1) )
99  : prob_lo[2] + (k + myhalf) * dx[2];
100  const Real z_agl = z - erf_prob_heights::z_ground_yface(i,j,z_sfc_nd); // height above the ground
101 
102  // Set the y-velocity
103  y_vel_pert(i, j, k) = V_0;
104  if ((z_agl <= pert_ref_height) && (V_0_Pert_Mag != zero))
105  {
106  Real rand_double;
107  if (deterministic_ic_pert) {
108  rand_double = erf_hash_rng::hash_uniform(
109  i, j, k, y_velocity_hash_comp, lev, ic_pert_seed);
110  } else {
111  rand_double = amrex::Random(engine); // Between zero and one
112  }
113  Real y_vel_prime = (rand_double*two - one)*V_0_Pert_Mag;
114  y_vel_pert(i, j, k) += y_vel_prime;
115  }
116  if (pert_deltaV != zero)
117  {
118  const amrex::Real xl = x - prob_lo[0];
119  const amrex::Real zl = z_agl / pert_ref_height;
120  const amrex::Real damp = std::exp(-myhalf * zl * zl);
121  y_vel_pert(i, j, k) += vfac * damp * z_agl * std::cos(bval * xl);
122  }
123  });
124 
125  // Set the z-velocity
126  ParallelForRNG(zbx, [=] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept
127  {
128  const int dom_lo_z = geomdata.Domain().smallEnd()[2];
129  const int dom_hi_z = geomdata.Domain().bigEnd()[2];
130 
131  // Set the z-velocity
132  if (k == dom_lo_z || k == dom_hi_z+1)
133  {
134  z_vel_pert(i, j, k) = zero;
135  }
136  else
137  {
138  z_vel_pert(i, j, k) = W_0;
139  if (W_0_Pert_Mag != zero)
140  {
141  Real rand_double;
142  if (deterministic_ic_pert) {
143  rand_double = erf_hash_rng::hash_uniform(
144  i, j, k, z_velocity_hash_comp, lev, ic_pert_seed);
145  } else {
146  rand_double = amrex::Random(engine); // Between zero and one
147  }
148  Real z_vel_prime = (rand_double*two - one)*W_0_Pert_Mag;
149  z_vel_pert(i, j, k) += z_vel_prime;
150  }
151  }
152  });
Real bval
Definition: ERF_InitCustomPertVels_ABL.H:40
Real aval
Definition: ERF_InitCustomPertVels_ABL.H:39
Real W_0_Pert_Mag
Definition: ERF_InitCustomPertVels_ABL.H:27
int deterministic_ic_pert
Definition: ERF_InitCustomPertVels_ABL.H:4
Real pert_ref_height
Definition: ERF_InitCustomPertVels_ABL.H:34
constexpr int y_velocity_hash_comp
Definition: ERF_InitCustomPertVels_ABL.H:17
auto probhi
Definition: ERF_InitCustomPertVels_ABL.H:37
constexpr int x_velocity_hash_comp
Definition: ERF_InitCustomPertVels_ABL.H:16
ParmParse pp_prob("prob")
Real U_0_Pert_Mag
Definition: ERF_InitCustomPertVels_ABL.H:25
Real pert_periods_V
Definition: ERF_InitCustomPertVels_ABL.H:33
Real vfac
Definition: ERF_InitCustomPertVels_ABL.H:42
long random_seed
Definition: ERF_InitCustomPertVels_ABL.H:6
Real pert_deltaV
Definition: ERF_InitCustomPertVels_ABL.H:31
Real U_0
Definition: ERF_InitCustomPertVels_ABL.H:20
const std::uint64_t ic_pert_seed
Definition: ERF_InitCustomPertVels_ABL.H:13
Real ufac
Definition: ERF_InitCustomPertVels_ABL.H:41
Real V_0
Definition: ERF_InitCustomPertVels_ABL.H:21
Real pert_deltaU
Definition: ERF_InitCustomPertVels_ABL.H:30
Real pert_periods_U
Definition: ERF_InitCustomPertVels_ABL.H:32
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+myhalf) *dx[1];const Real z=(z_nd) ? fourth *(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+myhalf) *dx[2];const Real z_agl=z - erf_prob_heights::z_ground_xface(i, j, z_sfc_nd);x_vel_pert(i, j, k)=U_0;if((z_agl<=pert_ref_height) &&(U_0_Pert_Mag !=zero)) { Real rand_double;if(deterministic_ic_pert) { rand_double=erf_hash_rng::hash_uniform(i, j, k, x_velocity_hash_comp, lev, ic_pert_seed);} else { rand_double=amrex::Random(engine);} Real x_vel_prime=(rand_double *two - one) *U_0_Pert_Mag;x_vel_pert(i, j, k)+=x_vel_prime;} if(pert_deltaU !=zero) { const amrex::Real yl=y - prob_lo[1];const amrex::Real zl=z_agl/pert_ref_height;const amrex::Real damp=std::exp(-myhalf *zl *zl);x_vel_pert(i, j, k)+=ufac *damp *z_agl *std::cos(aval *yl);} })
Real W_0
Definition: ERF_InitCustomPertVels_ABL.H:22
int fix_random_seed
Definition: ERF_InitCustomPertVels_ABL.H:5
constexpr int z_velocity_hash_comp
Definition: ERF_InitCustomPertVels_ABL.H:18
Real V_0_Pert_Mag
Definition: ERF_InitCustomPertVels_ABL.H:26
auto problo
Definition: ERF_InitCustomPertVels_ABL.H:36
const Real dx
Definition: ERF_InitCustomPert_ABL.H:44
const GpuArray< Real, AMREX_SPACEDIM > prob_lo
Definition: ERF_InitCustomPert_CloudChamber.H:33
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
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
@ xl
Definition: ERF_WSM6.H:345
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real hash_uniform(int i, int j, int k, int comp, int lev, std::uint64_t seed) noexcept
Definition: ERF_HashRNG.H:68
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real z_ground_xface(int i, int j, amrex::Array4< amrex::Real const > const &z_sfc_nd) noexcept
Height of the ground under x-face (i,j)
Definition: ERF_ProbHeights.H:58
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real z_ground_yface(int i, int j, amrex::Array4< amrex::Real const > const &z_sfc_nd) noexcept
Height of the ground under y-face (i,j)
Definition: ERF_ProbHeights.H:66