ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SBMParticleMixing.H
Go to the documentation of this file.
1 #ifndef ERF_SBM_PARTICLE_MIXING_H_
2 #define ERF_SBM_PARTICLE_MIXING_H_
3 
5 #include "ERF_DataStruct.H"
7 
8 #include <AMReX_Geometry.H>
9 #include <AMReX_GpuQualifiers.H>
10 #include <AMReX_Math.H>
11 #include <AMReX_MultiFab.H>
12 #include <AMReX_REAL.H>
13 
14 #include <array>
15 #include <limits>
16 #include <string>
17 #include <vector>
18 
19 namespace erf_sbm {
20 
21 /**
22  * Turbulent gradient mixing of spectral particles. One coefficient acts on
23  * every member of every bin group, and particle molecular (Brownian)
24  * diffusion is zero under every policy.
25  *
26  * HostPassiveScalar consumes ERF's Scalar_h/Scalar_v eddy channels, which are
27  * already density weighted and Schmidt scaled. Under ERF's LES closures they
28  * equal the Q channels that diffuse moisture, but the PBL schemes other than
29  * SHOC fill Q_v and not Scalar_v, so this policy is for LES closures only and
30  * enabling it must reject a PBL scheme. ConstantReference multiplies
31  * kinematic reference diffusivities by the face-averaged dry-air density.
32  */
34 
36 {
38  // Kinematic horizontal and vertical diffusivities [m^2/s], ConstantReference only.
39  amrex::Real reference_kh{0};
40  amrex::Real reference_kv{0};
41 
42  /** Exact policy and coefficient-source line for a restart identity. */
43  [[nodiscard]] std::string identity () const;
44 };
45 
46 [[nodiscard]] const char* particle_mixing_name (ParticleMixingPolicy policy) noexcept;
47 
48 [[nodiscard]] bool parse_particle_mixing_policy (const std::string& name,
49  ParticleMixingPolicy& policy);
50 
51 [[nodiscard]] bool validate_particle_mixing_config (const ParticleMixingConfig& config,
52  std::string& reason);
53 
54 /** The policy named by erf.sbm_particle_mixing and its reference diffusivities. */
55 [[nodiscard]] bool make_particle_mixing_config (const std::string& name,
56  amrex::Real reference_kh,
57  amrex::Real reference_kv,
58  ParticleMixingConfig& config,
59  std::string& reason);
60 
61 /**
62  * The ERF configuration a policy is qualified with: no molecular, PBL or RANS
63  * diffusion; ERF turbulence only as the same Smagorinsky or Deardorff LES on
64  * every level, and only with HostPassiveScalar, which requires it; and a
65  * constant- or stretched-dz mesh. SBM's own AMR envelope (two levels, a
66  * constant-dz mesh) bounds the levels.
67  */
68 [[nodiscard]] bool validate_particle_mixing_host (const ParticleMixingConfig& config,
69  const std::vector<TurbChoice>& turbulence,
70  MolecDiffType molecular,
71  MeshType mesh,
72  std::string& reason);
73 
74 /**
75  * As above. With `terrain_qualification`, for qualification only, a policy
76  * other than None also accepts a terrain-fitted (VariableDz) mesh on one
77  * level; the stage still checks the geometry admission below.
78  */
79 [[nodiscard]] bool validate_particle_mixing_host (const ParticleMixingConfig& config,
80  const std::vector<TurbChoice>& turbulence,
81  MolecDiffType molecular,
82  MeshType mesh,
83  bool terrain_qualification,
84  std::string& reason);
85 
86 /**
87  * Mixing accepts periodic, wall, outflow and inflow faces. An inflow_outflow
88  * z face is rejected: ERF's own vertical scalar diffusion has no inward-only
89  * rule there to follow, and ERF accepts inflow_outflow on x and y faces only.
90  */
91 [[nodiscard]] bool validate_particle_mixing_boundaries (
92  const ParticleMixingConfig& config,
93  const SBMPhysicalBoundaryConfig& boundaries,
94  std::string& reason);
95 
96 /** Restart-schema lines of a mixing policy; empty for None. */
97 [[nodiscard]] std::string particle_mixing_schema (const ParticleMixingConfig& config);
98 
99 /**
100  * As above, followed with a line of the diffusive semantics of every face
101  * that is neither periodic nor a wall, when there is one.
102  */
103 [[nodiscard]] std::string particle_mixing_schema (const ParticleMixingConfig& config,
104  const SBMPhysicalBoundaryConfig& boundaries);
105 
106 /** The host coefficient semantics of a mixing policy other than None. */
107 [[nodiscard]] bool particle_mixing_coefficients (
108  const ParticleMixingConfig& config,
110  std::string& reason);
111 
112 /**
113  * The low-order operator mesh; terrain-fitted (VariableDz) meshes are rejected
114  * unless `terrain_qualification` is set, for qualification only.
115  */
116 [[nodiscard]] bool particle_mixing_mesh (MeshType mesh_type,
118  std::string& reason,
119  bool terrain_qualification = false);
120 
121 /**
122  * The terrain geometry terrain mixing is qualified on: in every valid cell,
123  * the drop sqrt(dx_drop^2 + dy_drop^2) of ComputeTerrainCellDrops, unclamped,
124  * at most `max_drop` cell thicknesses, and a finite, positive thickness.
125  * Fails with the worst cell and its drop otherwise. An engineering envelope,
126  * not a stability bound.
127  */
128 [[nodiscard]] bool admit_terrain_mixing_geometry (const amrex::MultiFab& z_nd,
129  const amrex::BoxArray& cells,
130  amrex::Real max_drop,
131  std::string& reason);
132 
133 /**
134  * The face transmissibility of a policy; None gives zero on every face.
135  * `density` must be the dry-air density (ERF's Rho_comp), which
136  * ConstantReference multiplies by.
137  */
138 [[nodiscard]] bool build_particle_mixing_transmissibility (
139  const ParticleMixingConfig& config,
140  const amrex::Geometry& geom,
142  const amrex::MultiFab& density,
143  int density_component,
144  const amrex::MultiFab* eddy_diffusivity,
146  std::string& diagnostic);
147 
148 /** As above, with the diffusive faces of `boundary` open. */
149 [[nodiscard]] bool build_particle_mixing_transmissibility (
150  const ParticleMixingConfig& config,
151  const amrex::Geometry& geom,
153  const amrex::MultiFab& density,
154  int density_component,
155  const amrex::MultiFab* eddy_diffusivity,
158  std::string& diagnostic);
159 
160 /**
161  * Terrain-fitted mixing only: the fraction theta in [0, 1] of one matched
162  * coordinate's nominal low-order diffusive rate `low` that a face carries,
163  * given that coordinate's native rate `high`: 1 for low = 0, 0 where high is
164  * zero or opposes low, |high| / |low| where it is smaller, and 1 otherwise,
165  * so theta low lies between zero and high. A nonfinite rate gives NaN, which
166  * the caller rejects. A face's group takes the least fraction of its
167  * coordinates.
168  */
169 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
170 matched_diffusion_fraction (const amrex::Real high, const amrex::Real low) noexcept
171 {
172  if (!amrex::Math::isfinite(high) || !amrex::Math::isfinite(low)) {
173  return std::numeric_limits<amrex::Real>::quiet_NaN();
174  }
175  if (low == amrex::Real(0.0)) { return amrex::Real(1.0); }
176  if (high == amrex::Real(0.0) || (high > amrex::Real(0.0)) != (low > amrex::Real(0.0))) {
177  return amrex::Real(0.0);
178  }
179  const amrex::Real h = amrex::Math::abs(high);
180  const amrex::Real l = amrex::Math::abs(low);
181  return h < l ? h / l : amrex::Real(1.0);
182 }
183 
184 /**
185  * As particle_mixing_schema with boundaries, for the mixing mesh: a
186  * terrain-fitted (VariableDz) mesh adds a line naming its operator and
187  * boundary policy; every other mesh leaves the schema unchanged.
188  */
189 [[nodiscard]] std::string particle_mixing_schema (const ParticleMixingConfig& config,
190  const SBMPhysicalBoundaryConfig& boundaries,
192 
193 /** The diffusive faces of a boundary configuration, with the dry-air carrier of each direction. */
195  const SBMPhysicalBoundaryConfig& boundaries,
196  const std::array<const amrex::MultiFab*, AMREX_SPACEDIM>& carrier);
197 
198 } // namespace erf_sbm
199 
200 #endif
MolecDiffType
Molecular diffusion model used for transport coefficients.
Definition: ERF_DiffStruct.H:17
const auto config
Definition: ERF_InitCustomPert_CloudChamber.H:38
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
DiffusionMesh
Definition: ERF_AuxiliaryDiffusion.H:32
MappedFaceField< MappedFaceTransmissibilityTag > MappedFaceTransmissibility
Definition: ERF_AuxiliaryDiffusion.H:24
Definition: ERF.H:128
const char * particle_mixing_name(const ParticleMixingPolicy policy) noexcept
Definition: ERF_SBMParticleMixing.cpp:17
std::string particle_mixing_schema(const ParticleMixingConfig &config)
Definition: ERF_SBMParticleMixing.cpp:210
bool make_particle_mixing_config(const std::string &name, const amrex::Real reference_kh, const amrex::Real reference_kv, ParticleMixingConfig &config, std::string &reason)
Definition: ERF_SBMParticleMixing.cpp:78
bool particle_mixing_mesh(const MeshType mesh_type, erf_auxiliary::DiffusionMesh &mesh, std::string &reason, const bool terrain_qualification)
Definition: ERF_SBMParticleMixing.cpp:278
bool validate_particle_mixing_config(const ParticleMixingConfig &config, std::string &reason)
Definition: ERF_SBMParticleMixing.cpp:57
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real matched_diffusion_fraction(const amrex::Real high, const amrex::Real low) noexcept
Definition: ERF_SBMParticleMixing.H:170
bool build_particle_mixing_transmissibility(const ParticleMixingConfig &config, const amrex::Geometry &geom, const erf_auxiliary::MappedDiffusionMetrics &metrics, const amrex::MultiFab &density, const int density_component, const amrex::MultiFab *eddy_diffusivity, erf_auxiliary::MappedFaceTransmissibility &transmissibility, std::string &diagnostic)
Definition: ERF_SBMParticleMixing.cpp:303
bool validate_particle_mixing_host(const ParticleMixingConfig &config, const std::vector< TurbChoice > &turbulence, const MolecDiffType molecular, const MeshType mesh, std::string &reason)
Definition: ERF_SBMParticleMixing.cpp:101
bool admit_terrain_mixing_geometry(const amrex::MultiFab &z_nd, const amrex::BoxArray &cells, const amrex::Real max_drop, std::string &reason)
Definition: ERF_SBMParticleMixing.cpp:368
bool validate_particle_mixing_boundaries(const ParticleMixingConfig &config, const SBMPhysicalBoundaryConfig &boundaries, std::string &reason)
Definition: ERF_SBMParticleMixing.cpp:180
bool parse_particle_mixing_policy(const std::string &name, ParticleMixingPolicy &policy)
Definition: ERF_SBMParticleMixing.cpp:28
bool particle_mixing_coefficients(const ParticleMixingConfig &config, erf_auxiliary::MappedDiffusionCoefficients &coefficients, std::string &reason)
Definition: ERF_SBMParticleMixing.cpp:247
erf_auxiliary::MappedDiffusionBoundary particle_mixing_boundary(const SBMPhysicalBoundaryConfig &boundaries, const std::array< const amrex::MultiFab *, AMREX_SPACEDIM > &carrier)
Definition: ERF_SBMParticleMixing.cpp:428
ParticleMixingPolicy
Definition: ERF_SBMParticleMixing.H:33
Definition: ERF_AuxiliaryDiffusion.H:102
Definition: ERF_AuxiliaryDiffusion.H:63
Definition: ERF_AuxiliaryDiffusion.H:42
Definition: ERF_SBMParticleMixing.H:36
amrex::Real reference_kv
Definition: ERF_SBMParticleMixing.H:40
ParticleMixingPolicy policy
Definition: ERF_SBMParticleMixing.H:37
std::string identity() const
Definition: ERF_SBMParticleMixing.cpp:42
amrex::Real reference_kh
Definition: ERF_SBMParticleMixing.H:39