ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InitCustomPert_CloudChamber.H
Go to the documentation of this file.
1 // Cloud Chamber custom thermodynamic initializer.
2 //
3 // ERF has already initialized the hydrostatic/base state when this snippet is
4 // called. `state` is therefore the current conserved state and state_pert is
5 // an additive correction. In anelastic mode density is fixed by that base
6 // state, so only RhoTheta and (for active moisture) RhoQ1/RhoQ2 are corrected
7 // here. Other conserved moisture lanes remain zero from ERF's earlier cold-start
8 // state initialization; native schemes own any later reservoirs or particles.
9 // The analytic perturbation is evaluated at cell centers and uses no RNG;
10 // consequently it is independent of MPI decomposition, tiling, and restart
11 // layout. theta is potential temperature, qv is vapor mixing ratio, and qc
12 // is cloud-water mixing ratio; none of these prescribed values claim
13 // physical panel temperature, wet-wall evaporation, or a wall-transfer law.
15  m_cloud_chamber_config.active,
16  "Cloud Chamber: initializer reached without a parsed configuration");
18  sc.compressibility_type[lev] == CompressibilityType::Anelastic,
19  "Cloud Chamber: every level must use erf.compressibility_type = Anelastic "
20  "(PseudoIncompressible is not supported)");
22  sc.terrain_type == TerrainType::None &&
23  sc.buildings_type == BuildingsType::None &&
24  sc.mesh_type == MeshType::ConstantDz,
25  "Cloud Chamber: terrain, buildings, and non-Cartesian mesh modes are unsupported");
28  "Cloud Chamber: unsupported moisture model in custom initializer");
30  m_cloud_chamber_config.has_moisture ==
31  (sc.moisture_type != MoistureType::None),
32  "Cloud Chamber: moisture-model selection and chamber configuration disagree");
33 
34 const GpuArray<Real, AMREX_SPACEDIM> prob_lo = {
35  geomdata.ProbLo(0), geomdata.ProbLo(1), geomdata.ProbLo(2)};
36 const GpuArray<Real, AMREX_SPACEDIM> dx = {
37  geomdata.CellSize(0), geomdata.CellSize(1), geomdata.CellSize(2)};
38 const auto config = m_cloud_chamber_config;
39 const Real rdOcp = sc.rdOcp;
40 
41 ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
42 {
43  const Real x = prob_lo[0] + (Real(i) + Real(0.5)) * dx[0];
44  const Real y = prob_lo[1] + (Real(j) + Real(0.5)) * dx[1];
45  const Real z = prob_lo[2] + (Real(k) + Real(0.5)) * dx[2];
46  const Real rho = state(i,j,k,Rho_comp);
47  const Real temperature = erf_cloud_chamber::linear_profile(
48  config.initial_temperature_bottom, config.initial_temperature_top,
49  z, config.prob_lo[2], config.prob_hi[2] - config.prob_lo[2]) +
51  x, y, z, config.prob_lo,
52  GpuArray<Real, AMREX_SPACEDIM>{
53  config.prob_hi[0] - config.prob_lo[0],
54  config.prob_hi[1] - config.prob_lo[1],
55  config.prob_hi[2] - config.prob_lo[2]},
56  config.temperature_perturbation_amplitude);
57  const Real target_theta = config.physical_initialization ?
58  temperature * std::pow(p_0 / p_hse(i,j,k), rdOcp) :
60  state_pert(i,j,k,RhoTheta_comp) =
61  rho * target_theta - state(i,j,k,RhoTheta_comp);
62 
63  if (config.has_moisture) {
64  const Real target_qv = config.physical_initialization ?
66  temperature, p_hse(i,j,k), config.initial_relative_humidity) :
68  state_pert(i,j,k,RhoQ1_comp) =
69  rho * target_qv - state(i,j,k,RhoQ1_comp);
70  // The selected native scheme owns cloud-water evolution. Starting from
71  // zero makes that source explicit instead of carrying stale state.
72  state_pert(i,j,k,RhoQ2_comp) = -state(i,j,k,RhoQ2_comp);
73  }
74 });
constexpr amrex::Real p_0
Definition: ERF_Constants.H:69
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:79
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:78
const GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_InitCustomPert_CloudChamber.H:36
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { const Real x=prob_lo[0]+(Real(i)+Real(0.5)) *dx[0];const Real y=prob_lo[1]+(Real(j)+Real(0.5)) *dx[1];const Real z=prob_lo[2]+(Real(k)+Real(0.5)) *dx[2];const Real rho=state(i, j, k, Rho_comp);const Real temperature=erf_cloud_chamber::linear_profile(config.initial_temperature_bottom, config.initial_temperature_top, z, config.prob_lo[2], config.prob_hi[2] - config.prob_lo[2])+erf_cloud_chamber::deterministic_perturbation(x, y, z, config.prob_lo, GpuArray< Real, AMREX_SPACEDIM >{ config.prob_hi[0] - config.prob_lo[0], config.prob_hi[1] - config.prob_lo[1], config.prob_hi[2] - config.prob_lo[2]}, config.temperature_perturbation_amplitude);const Real target_theta=config.physical_initialization ? temperature *std::pow(p_0/p_hse(i, j, k), rdOcp) :erf_cloud_chamber::theta_at(config, x, y, z);state_pert(i, j, k, RhoTheta_comp)=rho *target_theta - state(i, j, k, RhoTheta_comp);if(config.has_moisture) { const Real target_qv=config.physical_initialization ? erf_cloud_chamber::vapor_mixing_ratio_from_relative_humidity(temperature, p_hse(i, j, k), config.initial_relative_humidity) :erf_cloud_chamber::qv_at(config, z);state_pert(i, j, k, RhoQ1_comp)=rho *target_qv - state(i, j, k, RhoQ1_comp);state_pert(i, j, k, RhoQ2_comp)=-state(i, j, k, RhoQ2_comp);} })
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_cloud_chamber_config.active, "Cloud Chamber: initializer reached without a parsed configuration")
const Real rdOcp
Definition: ERF_InitCustomPert_CloudChamber.H:39
const auto config
Definition: ERF_InitCustomPert_CloudChamber.H:38
const GpuArray< Real, AMREX_SPACEDIM > prob_lo
Definition: ERF_InitCustomPert_CloudChamber.H:34
@ None
Definition: ERF_LSM_Types.H:6
@ rho
Definition: ERF_Kessler.H:25
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE amrex::Real theta_at(const Initialization &config, amrex::Real x, amrex::Real y, amrex::Real z) noexcept
Compute the potential temperature at a given location.
Definition: ERF_CloudChamber.H:306
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE amrex::Real deterministic_perturbation(amrex::Real x, amrex::Real y, amrex::Real z, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &lo, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &length, amrex::Real amplitude) noexcept
Compute a deterministic 3D sine perturbation.
Definition: ERF_CloudChamber.H:208
bool supports_moisture_model(const MoistureType moisture_type) noexcept
Return whether a moisture type is supported by the Cloud Chamber.
Definition: ERF_CloudChamber.H:153
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE amrex::Real vapor_mixing_ratio_from_relative_humidity(amrex::Real temperature_K, amrex::Real pressure_Pa, amrex::Real relative_humidity) noexcept
Convert relative humidity to water vapor mixing ratio.
Definition: ERF_CloudChamber.H:351
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE amrex::Real qv_at(const Initialization &config, amrex::Real z) noexcept
Compute the water vapor mixing ratio at a given height.
Definition: ERF_CloudChamber.H:334
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE amrex::Real linear_profile(amrex::Real bottom, amrex::Real top, amrex::Real coordinate, amrex::Real lower, amrex::Real length) noexcept
Compute a linear profile between two values.
Definition: ERF_CloudChamber.H:188