1 #ifndef ERF_CLOUD_CHAMBER_H_
2 #define ERF_CLOUD_CHAMBER_H_
4 #include <AMReX_Array.H>
5 #include <AMReX_Geometry.H>
6 #include <AMReX_ParmParse.H>
7 #include <AMReX_REAL.H>
51 amrex::Real
qv_top = amrex::Real(0.0);
52 amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>
prob_lo = {};
53 amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>
prob_hi = {};
74 for (
const auto& wall : walls) {
75 if ((wall.heat_is_conductive() && wall.heat.model == ScalarModel::BulkAero) ||
76 (wall.vapor_is_wet() && wall.vapor.model == ScalarModel::BulkAero)) {
86 if (wall.has_wall_rate_channel()) {
return true; }
93 std::optional<erf_wall_thermodynamics::Boundary>
m_boundary;
94 std::array<SidewallTemperatureBands, 4>
m_bands;
122 switch (contract.
mode) {
126 return "Cloud Chamber: physical moist initialization requires prob.initial_relative_humidity";
129 return "Cloud Chamber: prob.initial_relative_humidity requires an active moisture model";
132 return "Cloud Chamber: physical_temperature_rh cannot be combined with legacy theta/qv profile keys";
137 return "Cloud Chamber: legacy_theta_qv cannot be combined with physical temperature/RH profile keys";
155 switch (moisture_type) {
157 case MoistureType::SatAdj:
158 case MoistureType::MoistNoCondensation:
159 case MoistureType::Kessler_NoRain:
160 case MoistureType::Kessler:
161 case MoistureType::SAM_NoPrecip_NoIce:
162 case MoistureType::SAM_NoIce:
163 case MoistureType::SAM:
164 case MoistureType::WSM6:
165 case MoistureType::WDM6:
166 case MoistureType::Morrison_NoIce:
167 case MoistureType::Morrison:
168 case MoistureType::SuperDroplets:
170 case MoistureType::SBM:
186 AMREX_GPU_HOST_DEVICE
189 amrex::Real coordinate, amrex::Real lower,
190 amrex::Real
length) noexcept
192 return bottom + (top - bottom) * (coordinate - lower) /
length;
206 AMREX_GPU_HOST_DEVICE
209 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& lo,
210 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>&
length,
211 amrex::Real amplitude) noexcept
213 constexpr amrex::Real
pi = amrex::Real(3.1415926535897932384626433832795);
214 const amrex::Real sx = std::sin(amrex::Real(2.0) *
pi * (
x -
lo[0]) /
length[0]);
215 const amrex::Real sy = std::sin(amrex::Real(2.0) *
pi * (
y -
lo[1]) /
length[1]);
216 const amrex::Real sz = std::sin(
pi * (
z -
lo[2]) /
length[2]);
217 return amplitude * sx * sy * sz;
229 AMREX_GPU_HOST_DEVICE
232 amrex::Real
dx, amrex::Real
dy,
233 int nx,
int ny) noexcept
235 if (
nx <= 1 ||
ny <= 1) {
return amrex::Real(0.0); }
236 if (
lx ==
ly &&
dx ==
dy) {
return amrex::Real(1.0); }
237 constexpr amrex::Real
pi = amrex::Real(3.1415926535897932384626433832795);
238 const amrex::Real kx_d = std::sin(
pi *
dx /
lx) /
dx;
239 const amrex::Real ky_d = std::sin(
pi *
dy /
ly) /
dy;
240 return ky_d == amrex::Real(0.0) ? amrex::Real(0.0) : kx_d / ky_d;
247 AMREX_GPU_HOST_DEVICE
250 amrex::Real x, amrex::Real y, amrex::Real z,
251 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& lo,
252 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>&
length,
253 amrex::Real
U_0,
int nx,
int ny) noexcept
255 if (
nx <= 1 ||
ny <= 1) {
return amrex::Real(0.0); }
256 constexpr amrex::Real
pi = amrex::Real(3.1415926535897932384626433832795);
257 const amrex::Real sx = std::sin(
pi * (
x -
lo[0]) /
length[0]);
258 const amrex::Real sz = std::sin(
pi * (
z -
lo[2]) /
length[2]);
259 return U_0 * sx * sx *
260 std::sin(amrex::Real(2.0) *
pi * (
y -
lo[1]) /
length[1]) * sz * sz;
267 AMREX_GPU_HOST_DEVICE
270 amrex::Real x, amrex::Real y, amrex::Real z,
271 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& lo,
272 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>&
length,
275 if (
nx <= 1 ||
ny <= 1) {
return amrex::Real(0.0); }
276 constexpr amrex::Real
pi = amrex::Real(3.1415926535897932384626433832795);
277 const amrex::Real sy = std::sin(
pi * (
y -
lo[1]) /
length[1]);
278 const amrex::Real sz = std::sin(
pi * (
z -
lo[2]) /
length[2]);
280 std::sin(amrex::Real(2.0) *
pi * (
x -
lo[0]) /
length[0]) *
288 AMREX_GPU_HOST_DEVICE
292 return amrex::Real(0.0);
304 AMREX_GPU_HOST_DEVICE
307 amrex::Real z) noexcept
309 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>
length = {
313 const amrex::Real bottom =
config.physical_initialization ?
314 config.initial_temperature_bottom :
config.theta_bottom;
315 const amrex::Real top =
config.physical_initialization ?
317 const amrex::Real amplitude =
config.physical_initialization ?
318 config.temperature_perturbation_amplitude :
config.theta_perturbation_amplitude;
332 AMREX_GPU_HOST_DEVICE
349 AMREX_GPU_HOST_DEVICE
352 amrex::Real pressure_Pa,
353 amrex::Real relative_humidity) noexcept
357 const amrex::Real es_Pa =
erf_esatw(temperature_K) * amrex::Real(100.0);
358 const amrex::Real ev_Pa = relative_humidity * es_Pa;
359 return RdoRv * ev_Pa / (pressure_Pa - ev_Pa);
362 inline bool finite (amrex::Real value) noexcept
364 return std::isfinite(
static_cast<double>(value));
370 amrex::Error(
"Cloud Chamber: " + key +
" must be finite");
389 return finite(rh) && rh >= amrex::Real(0.0) && rh <= amrex::Real(1.0);
396 if (!
pp.contains(
"wetness")) {
return {}; }
398 return "Cloud Chamber: " + face +
".wetness is only valid on physical walls with moisture = wet";
401 pp.get(
"wetness", rh);
403 return "Cloud Chamber: " + face +
".wetness must be a finite relative humidity fraction in [0,1]";
428 amrex::Real
z0_m = amrex::Real(0.0);
429 amrex::Real
z0_h = amrex::Real(0.0);
430 amrex::Real
z0_q = amrex::Real(0.0);
434 const std::string& face)
437 auto selector = [&](
const char* key, std::string& value) {
438 if (!
pp.query(key, value)) {
return false; }
439 value = amrex::toLower(value);
442 std::string aggregate;
445 amrex::Error(
"Cloud Chamber: " + face +
".wall_transfer_model only accepts "
446 "resolved_molecular; select other models with the per-channel keys");
452 auto coefficient = [&](
const char* key, amrex::Real& value) {
453 if (!
pp.query(key, value)) {
return false; }
468 return model ==
"bulk_aero" || model ==
"bulk_aero_plus_molecular";
473 const std::string& face)
481 contract.
heat_model ==
"neutral_roughness_log";
484 const bool any_neutral =
485 momentum_neutral || heat_neutral || vapor_neutral;
487 const bool any_channel_key =
499 return "Cloud Chamber: " + face +
500 " cannot combine wall_transfer_model with per-channel wall model keys";
505 !momentum_bulk && !momentum_neutral) {
506 return "Cloud Chamber: " + face +
507 ".momentum_transfer_model must be resolved_noslip, bulk_aero, bulk_aero_plus_molecular, "
508 "neutral_roughness_log, or law_of_wall_momentum";
516 contract.
heat_model !=
"resolved_molecular" && !heat_bulk && !heat_neutral) {
517 return "Cloud Chamber: " + face +
518 ".heat_transfer_model must be resolved_molecular, bulk_aero, bulk_aero_plus_molecular, or neutral_roughness_log";
521 contract.
vapor_model !=
"resolved_molecular" && !vapor_bulk && !vapor_neutral) {
522 return "Cloud Chamber: " + face +
523 ".vapor_transfer_model must be resolved_molecular, bulk_aero, bulk_aero_plus_molecular, or neutral_roughness_log";
526 const bool bulk_active = heat_bulk || vapor_bulk || momentum_bulk;
528 contract.
heat_model ==
"bulk_aero_plus_molecular" ||
530 return "Cloud Chamber: " + face +
" bulk_aero_plus_molecular requires coefficient_source = fixed";
534 if (most_provider && !(face ==
"zlo" || face ==
"zhi")) {
535 return "Cloud Chamber: " + face +
536 " supports coefficient_source = most only on zlo or zhi";
538 if ((any_neutral || (bulk_active && most_provider)) &&
540 return "Cloud Chamber: " + face +
541 " requires z0_m for the active neutral/MOST wall-transfer channels";
543 if ((heat_neutral || (heat_bulk && most_provider)) &&
545 return "Cloud Chamber: " + face +
546 " requires z0_h for neutral roughness-log heat or MOST heat";
548 if ((vapor_neutral || (vapor_bulk && most_provider)) &&
550 return "Cloud Chamber: " + face +
551 " requires z0_q for neutral roughness-log vapor or MOST vapor";
554 !(any_neutral || (bulk_active && most_provider))) {
555 return "Cloud Chamber: " + face +
556 ".z0_m requires a neutral_roughness_log or MOST channel";
559 !(heat_neutral || (heat_bulk && most_provider))) {
560 return "Cloud Chamber: " + face +
561 ".z0_h requires neutral_roughness_log heat or MOST heat";
564 !(vapor_neutral || (vapor_bulk && most_provider))) {
565 return "Cloud Chamber: " + face +
566 ".z0_q requires neutral_roughness_log vapor or MOST vapor";
574 return "Cloud Chamber: " + face +
575 " active roughness lengths z0_m, z0_h, and z0_q must be finite and positive";
582 return "Cloud Chamber: " + face +
583 " active bulk_aero channels require coefficient_source = fixed or most";
586 return "Cloud Chamber: " + face +
587 ".coefficient_source requires a bulk_aero or bulk_aero_plus_molecular channel";
590 if (momentum_bulk && !most_provider &&
592 return "Cloud Chamber: " + face +
593 " requires C_D when momentum_transfer_model = " + contract.
momentum_model +
594 " with coefficient_source = fixed";
597 return "Cloud Chamber: " + face +
598 ".C_D is not valid with coefficient_source = most";
601 return "Cloud Chamber: " + face +
602 " requires C_H when heat_transfer_model = " + contract.
heat_model +
603 " with coefficient_source = fixed";
606 return "Cloud Chamber: " + face +
607 ".C_H is not valid with coefficient_source = most";
610 return "Cloud Chamber: " + face +
611 " requires C_E when vapor_transfer_model = " + contract.
vapor_model +
612 " with coefficient_source = fixed";
615 return "Cloud Chamber: " + face +
616 ".C_E is not valid with coefficient_source = most";
619 return "Cloud Chamber: " + face +
620 ".C_D requires momentum_transfer_model = bulk_aero or bulk_aero_plus_molecular";
623 return "Cloud Chamber: " + face +
624 ".C_H requires heat_transfer_model = bulk_aero or bulk_aero_plus_molecular";
627 return "Cloud Chamber: " + face +
628 ".C_E requires vapor_transfer_model = bulk_aero or bulk_aero_plus_molecular";
639 return "Cloud Chamber: " + face +
640 " bulk coefficients C_D, C_H, and C_E must be finite and nonnegative";
653 const bool edges =
pp.contains(
"temperature_height_edges"), values =
pp.contains(
"temperature_values");
654 if (edges || values) {
655 const auto prefix =
"Cloud Chamber: " + face +
": ";
656 if (!physical || !sidewall_bands) {
return prefix +
"temperature bands require a physical x or y sidewall"; }
657 if (!(edges && values)) {
return prefix +
"temperature_height_edges and temperature_values must be supplied together"; }
658 if (
pp.contains(
"temperature")) {
return prefix +
"temperature and temperature bands are mutually exclusive"; }
661 if (
pp.contains(
"heat") ||
pp.contains(
"thermal")) {
662 return "Cloud Chamber: " + face +
".heat and its .thermal alias require physical_temperature_rh";
667 std::string heat =
"conductive";
668 const bool explicit_heat =
pp.query(
"heat", heat);
669 heat = amrex::toLower(heat);
670 if (heat !=
"conductive" && heat !=
"adiabatic") {
671 return "Cloud Chamber: " + face +
".heat must be conductive or adiabatic";
674 if (
pp.query(
"thermal", alias)) {
675 alias = amrex::toLower(alias);
676 if (alias ==
"fixed_temperature") { alias =
"conductive"; }
677 else if (alias !=
"adiabatic") {
678 return "Cloud Chamber: " + face +
".thermal must be fixed_temperature or adiabatic";
680 if (explicit_heat && heat != alias) {
681 return "Cloud Chamber: conflicting " + face +
".heat and " + face +
".thermal";
686 const bool conductive = heat ==
"conductive";
688 thermal.
mode = conductive ? ThermalMode::FixedPhysicalTemperature : ThermalMode::Adiabatic;
690 amrex::Vector<amrex::Real>
z, temperatures;
691 pp.getarr(
"temperature_height_edges",
z);
692 pp.getarr(
"temperature_values", temperatures);
693 const auto error = sidewall_bands->
define(std::move(
z), temperatures, geom);
694 if (!error.empty()) {
return "Cloud Chamber: " + face +
": " + error; }
700 return "Cloud Chamber: " + face +
".temperature must be finite and positive Kelvin";
703 return "Cloud Chamber: missing required physical " + face +
704 ".temperature (needed for conductive heat or wet-wall saturation)";
712 const std::string& face)
715 return "Cloud Chamber: " + face +
716 " coupled heat/vapor MOST requires z0_h == z0_q because the "
717 "prescribed-temperature bulk-Richardson closure uses one scalar "
718 "similarity resistance; z0_h=" +
719 std::to_string(
static_cast<double>(wall.
heat.
z0)) +
721 std::to_string(
static_cast<double>(wall.
vapor.
z0));
728 amrex::ParmParse pp_geom(
"geometry");
730 pp_geom.getarr(
"is_periodic",
periodic);
731 if (
periodic.size() != AMREX_SPACEDIM) {
732 amrex::Error(
"Cloud Chamber: geometry.is_periodic must provide three values");
734 for (
int d = 0; d < AMREX_SPACEDIM; ++d) {
736 amrex::Error(
"Cloud Chamber: geometry.is_periodic must be 0 0 0");
743 amrex::ParmParse pp_erf(
"erf");
745 if (pp_erf.query(
"terrain_type", value) &&
746 amrex::toLower(value) !=
"none") {
747 amrex::Error(
"Cloud Chamber: erf.terrain_type must be None; terrain and embedded boundaries are out of scope");
750 if (pp_erf.query(
"buildings_type", value) &&
751 amrex::toLower(value) !=
"none") {
752 amrex::Error(
"Cloud Chamber: erf.buildings_type must be None; immersed buildings are out of scope");
755 if (pp_erf.query(
"mesh_type", value) &&
756 amrex::toLower(value) !=
"constantdz") {
757 amrex::Error(
"Cloud Chamber: erf.mesh_type must be ConstantDz");
761 amrex::Error(
"Cloud Chamber: the vertical grid must be uniform (no erf.grid_stretching_ratio, "
762 "erf.initial_dz or erf.terrain_z_levels)");
767 const std::string& face)
769 if (
pp.contains(
"physical_temperature") ||
pp.contains(
"relative_humidity") ||
770 pp.contains(
"rh") ||
pp.contains(
"roughness") ||
771 pp.contains(
"roughness_length") ||
pp.contains(
"z0") ||
772 pp.contains(
"most") ||
pp.contains(
"MOST")) {
773 amrex::Error(
"Cloud Chamber: " + face +
774 " must use temperature and moisture for physical walls; "
775 "roughness aliases and legacy aliases are unsupported");
782 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>&
dx)
784 for (
int n = 0; n < 2 * AMREX_SPACEDIM; ++n) {
785 const auto& wall = walls[n];
786 const int dir = n / 2;
787 const amrex::Real z_ref = amrex::Real(0.5) *
dx[dir];
789 const auto check = [&](
bool active,
const char* key,
790 amrex::Real
z0) -> std::string {
791 if (!active) {
return {}; }
793 !(
z0 > amrex::Real(0.0)) || !(z_ref >
z0)) {
794 return "Cloud Chamber: " + face +
" " + key +
795 " requires 0 < " + key +
" < z_ref; " + key +
"=" +
796 std::to_string(
static_cast<double>(
z0)) +
798 std::to_string(
static_cast<double>(z_ref));
805 const bool heat_rough = wall.heat_uses_most() ||
806 (wall.heat_is_conductive() && wall.heat.model == ScalarModel::NeutralRoughnessLog);
807 const bool vapor_rough = wall.vapor.model == ScalarModel::NeutralRoughnessLog ||
808 (wall.vapor.model == ScalarModel::BulkAero &&
809 wall.vapor.provider == CoefficientProvider::MOST);
810 const auto momentum_error = check(
811 wall.momentum.model == MomentumModel::NeutralRoughnessLog ||
812 wall.momentum_uses_most() || heat_rough || vapor_rough,
813 "z0_m", wall.momentum.z0_m);
814 if (!momentum_error.empty()) {
return momentum_error; }
815 const auto heat_error = check(
817 "z0_h", wall.heat.z0);
818 if (!heat_error.empty()) {
return heat_error; }
819 const auto vapor_error = check(
821 "z0_q", wall.vapor.z0);
822 if (!vapor_error.empty()) {
return vapor_error; }
830 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>&
dx)
833 if (!error.empty()) { amrex::Error(error); }
837 const amrex::Real*
probhi,
838 const MoistureType selected_moisture_model)
842 for (
int d = 0; d < AMREX_SPACEDIM; ++d) {
848 amrex::Error(
"Cloud Chamber: geometry.prob_hi must exceed geometry.prob_lo in every direction");
852 amrex::ParmParse pp_erf(
"erf");
853 CompressibilityType compressibility_type = CompressibilityType::FullyCompressible;
855 if (pp_erf.query(
"anelastic", anelastic)) {
856 if (anelastic == 1) { compressibility_type = CompressibilityType::Anelastic; }
858 pp_erf.query_enum_case_insensitive(
"compressibility_type", compressibility_type);
862 if (compressibility_type != CompressibilityType::Anelastic) {
863 amrex::Error(
"Cloud Chamber: erf.compressibility_type = Anelastic is required "
864 "(FullyCompressible and PseudoIncompressible are not supported)");
866 bool use_gravity =
false;
867 if (!pp_erf.query(
"use_gravity", use_gravity) || !use_gravity) {
868 amrex::Error(
"Cloud Chamber: erf.use_gravity = true is required");
871 amrex::ParmParse pp_amr(
"amr");
873 pp_amr.query(
"max_level", max_level);
874 if (max_level != 0) {
875 amrex::Error(
"Cloud Chamber: amr.max_level must be 0");
880 amrex::ParmParse
pp_prob(
"prob");
884 const amrex::Real pressure_tolerance = amrex::Real(1.0e-6) *
p_0;
885 if (std::abs(
p_inf -
p_0) > pressure_tolerance) {
886 amrex::Error(
"Cloud Chamber: prob.p_inf must match ERF's p_0 = 100000 Pa within 1e-6 relative tolerance");
891 amrex::Error(
"Cloud Chamber: selected moisture model is unsupported; use an Eulerian model from the supported moisture allowlist");
894 if (!
config.has_moisture && pp_erf.contains(
"moisture_model")) {
895 amrex::Error(
"Cloud Chamber: omit erf.moisture_model for dry mode instead of explicitly selecting None");
897 if (!
config.has_moisture &&
899 amrex::Error(
"Cloud Chamber: qv_bottom/qv_top require an active moisture model");
902 std::string init_mode;
903 pp_prob.get(
"thermodynamic_initialization", init_mode);
904 init_mode = amrex::toLower(init_mode);
905 if (init_mode ==
"physical_temperature_rh") {
906 config.physical_initialization =
true;
909 if (amrex::toLower(
init_type) !=
"constantdensity") {
910 amrex::Error(
"Cloud Chamber: physical initialization requires the existing HSE-backed erf.init_type = ConstantDensity path");
912 bool vert_implicit =
false;
913 pp_erf.query(
"vert_implicit", vert_implicit);
915 amrex::Error(
"Cloud Chamber: physical wall transfer requires erf.vert_implicit = false");
917 pp_prob.get(
"initial_temperature_bottom",
config.initial_temperature_bottom);
918 pp_prob.get(
"initial_temperature_top",
config.initial_temperature_top);
919 const bool has_initial_relative_humidity =
pp_prob.contains(
"initial_relative_humidity");
920 auto physical_contract_error = [&](
bool has_legacy_profile_keys) {
924 has_initial_relative_humidity,
925 has_legacy_profile_keys,
929 std::string contract_error = physical_contract_error(
false);
930 if (!contract_error.empty()) {
931 amrex::Error(contract_error);
933 if (
config.has_moisture) {
934 pp_prob.get(
"initial_relative_humidity",
config.initial_relative_humidity);
936 pp_prob.query(
"temperature_perturbation_amplitude",
937 config.temperature_perturbation_amplitude);
938 const bool has_legacy_profile_keys =
pp_prob.contains(
"theta_bottom") ||
939 pp_prob.contains(
"theta_top") ||
940 pp_prob.contains(
"theta_perturbation_amplitude") ||
941 pp_prob.contains(
"qv_bottom") ||
943 contract_error = physical_contract_error(has_legacy_profile_keys);
944 if (!contract_error.empty()) {
945 amrex::Error(contract_error);
950 config.temperature_perturbation_amplitude);
951 if (
config.initial_temperature_bottom <= amrex::Real(0.0) ||
952 config.initial_temperature_top <= amrex::Real(0.0)) {
953 amrex::Error(
"Cloud Chamber: physical initial temperatures must be positive");
955 if (
config.has_moisture) {
957 if (
config.initial_relative_humidity < amrex::Real(0.0) ||
958 config.initial_relative_humidity > amrex::Real(1.0)) {
959 amrex::Error(
"Cloud Chamber: initial_relative_humidity must lie in [0,1]");
962 }
else if (init_mode ==
"legacy_theta_qv") {
963 config.physical_initialization =
false;
969 pp_prob.contains(
"initial_temperature_bottom") ||
970 pp_prob.contains(
"initial_temperature_top") ||
971 pp_prob.contains(
"initial_relative_humidity") ||
972 pp_prob.contains(
"temperature_perturbation_amplitude")};
974 if (!contract_error.empty()) {
975 amrex::Error(contract_error);
979 pp_prob.query(
"theta_perturbation_amplitude",
980 config.theta_perturbation_amplitude);
982 amrex::Error(
"Cloud Chamber: prob.thermodynamic_initialization must be physical_temperature_rh or legacy_theta_qv");
984 std::string perturbation_mode =
"deterministic_sine";
985 pp_prob.query(
"perturbation_mode", perturbation_mode);
986 if (amrex::toLower(perturbation_mode) !=
"deterministic_sine") {
987 amrex::Error(
"Cloud Chamber: prob.perturbation_mode must be deterministic_sine");
989 if (!
config.physical_initialization) {
993 config.theta_perturbation_amplitude);
994 if (
config.theta_bottom <= amrex::Real(0.0) ||
995 config.theta_top <= amrex::Real(0.0)) {
996 amrex::Error(
"Cloud Chamber: theta profile values must be positive");
1000 if (
config.has_moisture) {
1001 if (!
config.physical_initialization) {
1006 if (
config.qv_bottom < amrex::Real(0.0) ||
1007 config.qv_top < amrex::Real(0.0)) {
1008 amrex::Error(
"Cloud Chamber: qv profile values must be nonnegative");
1013 for (
int d = 0; d < AMREX_SPACEDIM; ++d) {
1016 amrex::Error(
"Cloud Chamber: every rectangular dimension must be finite and positive");
1027 const DiffChoice& dc, amrex::Real dx_inv,
const std::string& face)
1030 const auto positive = [](amrex::Real
x) {
return finite(
x) &&
x > 0; };
1031 const auto error = [&](
const char* channel,
const char* key) {
1032 return "Cloud Chamber: " + face +
"." + channel +
"_transfer_model = "
1033 "bulk_aero_plus_molecular requires finite positive " + key;
1035 const auto inv_distance = amrex::Real(2) * dx_inv;
1037 if (!positive(dc.
dynamic_viscosity)) {
return error(
"momentum",
"dynamic_viscosity"); }
1038 if (!positive(dc.
rho0_trans)) {
return error(
"momentum",
"rho0_trans"); }
1040 if (!positive(speed)) {
1041 return error(
"momentum",
"(dynamic_viscosity/rho0_trans) / half-cell distance");
1044 }
else if (wall.
momentum.
model == MomentumModel::ResolvedNoSlip &&
1052 const auto scalar = [&](
ScalarTransfer& transfer,
const std::string& model,
bool active,
1053 amrex::Real
alpha,
const char* channel,
const char* key) -> std::string {
1054 if (model ==
"bulk_aero_plus_molecular") {
1055 if (!positive(
alpha)) {
return error(channel, key); }
1057 const auto speed =
alpha * inv_distance;
1058 if (!positive(speed)) {
return error(channel,
"molecular transfer speed"); }
1061 }
else if (active && transfer.
model == ScalarModel::ResolvedMolecular) {
1069 if (!heat_error.empty()) {
return heat_error; }
1079 geom.ProbLo(), geom.ProbHi(), selected_moisture_model);
1081 amrex::Error(
"Cloud Chamber: physical wall transfer requires erf.molec_diff_type = ConstantAlpha");
1086 const auto dx_inv = geom.InvCellSizeArray();
1089 for (
int n = 0; n < 2 * AMREX_SPACEDIM; ++n) {
1090 const std::string face =
face_name(faces[n]);
1091 amrex::ParmParse pp_face(face.c_str());
1094 if (!pp_face.query(
"type", type) ||
1095 amrex::toLower(type) !=
"noslipwall") {
1096 amrex::Error(
"Cloud Chamber: " + face +
".type must be NoSlipWall");
1098 auto& wall = walls[n];
1100 const std::string transfer_error =
1102 if (!transfer_error.empty()) {
1103 amrex::Error(transfer_error);
1105 const bool any_channel_key =
1106 transfer_contract.momentum_model_specified ||
1107 transfer_contract.heat_model_specified ||
1108 transfer_contract.vapor_model_specified ||
1109 transfer_contract.coefficient_source_specified ||
1110 transfer_contract.momentum_coefficient_specified ||
1111 transfer_contract.heat_coefficient_specified ||
1112 transfer_contract.vapor_coefficient_specified ||
1113 transfer_contract.z0_m_specified ||
1114 transfer_contract.z0_h_specified ||
1115 transfer_contract.z0_q_specified;
1116 if (!
config.physical_initialization && any_channel_key) {
1117 amrex::Error(
"Cloud Chamber: per-channel wall transfer keys require physical temperature initialization");
1119 if (
config.physical_initialization) {
1120 if (pp_face.contains(
"theta") || pp_face.contains(
"qv") ||
1121 pp_face.contains(
"theta_grad") || pp_face.contains(
"qv_grad")) {
1122 amrex::Error(
"Cloud Chamber: physical walls cannot combine temperature/moisture with legacy theta/qv wall keys");
1124 std::string moisture;
1125 pp_face.get(
"moisture", moisture);
1126 moisture = amrex::toLower(moisture);
1127 if (moisture ==
"dry") {
1129 }
else if (moisture ==
"wet") {
1131 if (!
config.has_moisture) {
1132 amrex::Error(
"Cloud Chamber: wet walls require an active moisture model");
1135 amrex::Error(
"Cloud Chamber: " + face +
".moisture must be dry or wet");
1137 if (transfer_contract.momentum_model ==
"law_of_wall_momentum") {
1138 transfer_contract.momentum_model =
"neutral_roughness_log";
1140 wall.momentum.model =
1141 transfer_contract.momentum_model ==
"neutral_roughness_log" ?
1149 (transfer_contract.heat_model ==
"neutral_roughness_log" ?
1155 (transfer_contract.vapor_model ==
"neutral_roughness_log" ?
1158 wall.momentum.z0_m = transfer_contract.z0_m;
1159 wall.momentum.C_D = transfer_contract.momentum_coefficient;
1160 wall.heat.z0 = transfer_contract.z0_h;
1161 wall.vapor.z0 = transfer_contract.z0_q;
1163 wall.momentum.provider = transfer_contract.coefficient_source ==
"most" ?
1168 wall.heat.provider = transfer_contract.coefficient_source ==
"most" ?
1171 wall.heat.coefficient = transfer_contract.heat_coefficient;
1174 wall.vapor.provider = transfer_contract.coefficient_source ==
"most" ?
1177 wall.vapor.coefficient = transfer_contract.vapor_coefficient;
1180 if (!pp_face.query(
"theta", wall.thermal.temperature_K)) {
1181 amrex::Error(
"Cloud Chamber: missing required " + face +
".theta");
1184 wall.moisture =
config.has_moisture ?
1187 if (
config.has_moisture && !pp_face.contains(
"qv")) {
1188 amrex::Error(
"Cloud Chamber: legacy cloudy walls require " + face +
".qv");
1192 geom, n < 4 ? &
config.m_bands[n] :
nullptr);
1193 if (!heat_error.empty()) { amrex::Error(heat_error); }
1195 if (!coupled_error.empty()) { amrex::Error(coupled_error); }
1196 if (
config.physical_initialization) {
1199 wall, transfer_contract, dc, dx_inv[n/2], face);
1200 if (!speed_error.empty()) { amrex::Error(speed_error); }
1202 for (
int d = 0; d < AMREX_SPACEDIM; ++d) {
1203 if (pp_face.contains(
"velocity")) {
1204 amrex::Error(
"Cloud Chamber: wall velocity metadata is not active; use NoSlipWall with zero velocity");
1206 wall.wall_velocity[d] = amrex::Real(0.0);
1209 if (!wetness_error.empty()) { amrex::Error(wetness_error); }
1212 config.m_boundary = walls;
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
constexpr amrex::Real p_0
Definition: ERF_Constants.H:69
constexpr amrex::Real RdoRv
Definition: ERF_Constants.H:60
auto probhi
Definition: ERF_InitCustomPertVels_ABL.H:37
auto problo
Definition: ERF_InitCustomPertVels_ABL.H:36
const Real lx
Definition: ERF_InitCustomPertVels_CloudChamber.H:10
const int nx
Definition: ERF_InitCustomPertVels_CloudChamber.H:14
const int ny
Definition: ERF_InitCustomPertVels_CloudChamber.H:15
const Real v_scale
Definition: ERF_InitCustomPertVels_CloudChamber.H:16
const Real ly
Definition: ERF_InitCustomPertVels_CloudChamber.H:11
InitType init_type
Definition: ERF_InitCustomPertVels_EkmanSpiral.H:8
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
const Real dy
Definition: ERF_InitCustomPert_ABL.H:101
ParmParse pp_prob("prob")
const Real length
Definition: ERF_InitCustomPert_AnelasticWallDiffusion.H:16
const auto config
Definition: ERF_InitCustomPert_CloudChamber.H:38
amrex::Real p_inf
Definition: ERF_InitCustomPert_DataAssimilation_ISV.H:5
Real U_0
Definition: ERF_InitCustomPert_TurbulentInflow.H:18
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw(amrex::Real t, bool use_empirical=false)
Definition: ERF_MicrophysicsUtils.H:160
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE WallGradCoeffs WallGradientCoeffsUniform() noexcept
Definition: ERF_WallGradientCoeffs.H:46
Definition: ERF_CloudChamberTemperatureBands.H:18
std::string define(amrex::Vector< amrex::Real > edges, const amrex::Vector< amrex::Real > &values, const amrex::Geometry &geom)
Definition: ERF_CloudChamberTemperatureBands.H:20
@ None
Definition: ERF_LSM_Types.H:6
@ alpha
Definition: ERF_SLM.H:153
Definition: ERF_CloudChamber.H:25
void require_zero_periodicity()
Definition: ERF_CloudChamber.H:726
WallFace
Definition: ERF_CloudChamber.H:34
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE amrex::Real initial_u_velocity_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 U_0, int nx, int ny) noexcept
Evaluate the x-face component of the Cloud Chamber initial velocity.
Definition: ERF_CloudChamber.H:249
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
std::string parse_wall_heat(amrex::ParmParse &pp, const std::string &face, bool physical, erf_wall_thermodynamics::FaceWall &wall, const amrex::Geometry &geom, SidewallTemperatureBands *sidewall_bands)
Definition: ERF_CloudChamber.H:648
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
std::string wall_transfer_contract_error(const WallTransferContract &contract, const std::string &face)
Definition: ERF_CloudChamber.H:472
std::string wall_roughness_geometry_error(const erf_wall_thermodynamics::Boundary &walls, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dx)
Definition: ERF_CloudChamber.H:780
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE amrex::Real staggered_velocity_v_scale(amrex::Real lx, amrex::Real ly, amrex::Real dx, amrex::Real dy, int nx, int ny) noexcept
Discrete derivative ratio for the staggered initial velocity field.
Definition: ERF_CloudChamber.H:231
bool valid_wall_wetness(amrex::Real rh) noexcept
Definition: ERF_CloudChamber.H:387
std::string wall_coupled_most_roughness_error(const erf_wall_thermodynamics::FaceWall &wall, const std::string &face)
Definition: ERF_CloudChamber.H:711
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
WallTransferContract read_wall_transfer_contract(const amrex::ParmParse &pp, const std::string &face)
Definition: ERF_CloudChamber.H:433
std::string face_name(WallFace face)
Definition: ERF_CloudChamber.H:374
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
void require_finite(const std::string &key, amrex::Real value)
Definition: ERF_CloudChamber.H:367
std::string parse_wall_wetness(amrex::ParmParse &pp, const std::string &face, erf_wall_thermodynamics::FaceWall &wall)
Definition: ERF_CloudChamber.H:393
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
void validate_wall_roughness_geometry(const erf_wall_thermodynamics::Boundary &walls, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dx)
Definition: ERF_CloudChamber.H:828
Config parse_config(const amrex::Geometry &geom, MoistureType selected_moisture_model, const DiffChoice &dc)
Definition: ERF_CloudChamber.H:1074
InitializationMode
Definition: ERF_CloudChamber.H:97
void reject_unsupported_face_keys(amrex::ParmParse &pp, const std::string &face)
Definition: ERF_CloudChamber.H:766
void require_no_unsupported_geometry()
Definition: ERF_CloudChamber.H:741
bool is_bulk_model(const std::string &model)
Definition: ERF_CloudChamber.H:466
std::string initialization_contract_error(const InitializationContract &contract)
Validate the initialization contract and return an error message if violated.
Definition: ERF_CloudChamber.H:120
bool finite(amrex::Real value) noexcept
Definition: ERF_CloudChamber.H:362
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
Initialization parse_initialization(const amrex::Real *problo, const amrex::Real *probhi, const MoistureType selected_moisture_model)
Definition: ERF_CloudChamber.H:836
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE amrex::Real initial_w_velocity_perturbation() noexcept
The Cloud Chamber initial vertical velocity perturbation.
Definition: ERF_CloudChamber.H:290
std::string set_wall_transport_speeds(erf_wall_thermodynamics::FaceWall &wall, const WallTransferContract &contract, const DiffChoice &dc, amrex::Real dx_inv, const std::string &face)
Definition: ERF_CloudChamber.H:1025
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE amrex::Real initial_v_velocity_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 U_0, amrex::Real v_scale, int nx, int ny) noexcept
Evaluate the y-face component of the Cloud Chamber initial velocity.
Definition: ERF_CloudChamber.H:269
Definition: ERF_WallThermodynamics.H:10
amrex::GpuArray< TemperatureBandView, 4 > SidewallBandViews
Definition: ERF_WallThermodynamics.H:63
ScalarModel
Definition: ERF_WallThermodynamics.H:32
amrex::GpuArray< FaceWall, 2 *AMREX_SPACEDIM > Boundary
Definition: ERF_WallThermodynamics.H:133
real(c_double), parameter, private pi
Definition: ERF_module_mp_morr_two_moment.F90:100
Definition: ERF_DiffStruct.H:25
MolecDiffType molec_diff_type
Selected molecular transport model.
Definition: ERF_DiffStruct.H:97
amrex::Real alpha_C
Kinematic scalar diffusivity [m2/s].
Definition: ERF_DiffStruct.H:101
amrex::Real dynamic_viscosity
Dynamic viscosity for momentum diffusion [kg/(m-s)].
Definition: ERF_DiffStruct.H:109
amrex::Real rho0_trans
Reference density used to compute dynamic diffusion coefficients [kg/m3].
Definition: ERF_DiffStruct.H:104
amrex::Real alpha_T
Kinematic temperature diffusivity [m2/s].
Definition: ERF_DiffStruct.H:100
static MeshType mesh_type
Vertical mesh representation.
Definition: ERF_DataStruct.H:3004
Definition: ERF_CloudChamber.H:56
std::array< SidewallTemperatureBands, 4 > m_bands
Definition: ERF_CloudChamber.H:94
bool has_wall_rate_channel() const
Definition: ERF_CloudChamber.H:83
const erf_wall_thermodynamics::Boundary & transport_boundary() const &&=delete
erf_wall_thermodynamics::SidewallBandViews temperature_band_views() const &noexcept
Definition: ERF_CloudChamber.H:65
std::optional< erf_wall_thermodynamics::Boundary > m_boundary
Definition: ERF_CloudChamber.H:93
static bool has_bulk_scalar_wall(const erf_wall_thermodynamics::Boundary &walls) noexcept
Definition: ERF_CloudChamber.H:71
friend Config parse_config(const amrex::Geometry &, MoistureType, const DiffChoice &)
Definition: ERF_CloudChamber.H:1074
const erf_wall_thermodynamics::Boundary & transport_boundary() const &
Definition: ERF_CloudChamber.H:59
erf_wall_thermodynamics::SidewallBandViews temperature_band_views() const &&=delete
Contract used to validate initialization parameter consistency.
Definition: ERF_CloudChamber.H:105
InitializationMode mode
Definition: ERF_CloudChamber.H:106
bool has_initial_relative_humidity
Definition: ERF_CloudChamber.H:109
bool has_physical_profile_keys
Definition: ERF_CloudChamber.H:111
bool has_moisture
Definition: ERF_CloudChamber.H:108
bool has_legacy_profile_keys
Definition: ERF_CloudChamber.H:110
Profile data used by the device initializer; no wall transport is exposed here.
Definition: ERF_CloudChamber.H:39
amrex::Real temperature_perturbation_amplitude
Definition: ERF_CloudChamber.H:46
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > prob_hi
Definition: ERF_CloudChamber.H:53
bool has_moisture
Definition: ERF_CloudChamber.H:41
bool physical_initialization
Definition: ERF_CloudChamber.H:42
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > prob_lo
Definition: ERF_CloudChamber.H:52
amrex::Real initial_temperature_top
Definition: ERF_CloudChamber.H:44
bool active
Definition: ERF_CloudChamber.H:40
amrex::Real theta_perturbation_amplitude
Definition: ERF_CloudChamber.H:49
amrex::Real qv_bottom
Definition: ERF_CloudChamber.H:50
amrex::Real qv_top
Definition: ERF_CloudChamber.H:51
amrex::Real initial_relative_humidity
Definition: ERF_CloudChamber.H:45
amrex::Real theta_top
Definition: ERF_CloudChamber.H:48
amrex::Real theta_bottom
Definition: ERF_CloudChamber.H:47
amrex::Real initial_temperature_bottom
Definition: ERF_CloudChamber.H:43
Definition: ERF_CloudChamber.H:409
amrex::Real z0_m
Definition: ERF_CloudChamber.H:428
std::string heat_model
Definition: ERF_CloudChamber.H:422
bool momentum_model_specified
Definition: ERF_CloudChamber.H:411
amrex::Real z0_q
Definition: ERF_CloudChamber.H:430
bool z0_h_specified
Definition: ERF_CloudChamber.H:419
bool coefficient_source_specified
Definition: ERF_CloudChamber.H:414
std::string coefficient_source
Definition: ERF_CloudChamber.H:424
std::string vapor_model
Definition: ERF_CloudChamber.H:423
bool z0_q_specified
Definition: ERF_CloudChamber.H:420
std::string momentum_model
Definition: ERF_CloudChamber.H:421
amrex::Real z0_h
Definition: ERF_CloudChamber.H:429
bool legacy_aggregate_specified
Definition: ERF_CloudChamber.H:410
bool vapor_model_specified
Definition: ERF_CloudChamber.H:413
amrex::Real momentum_coefficient
Definition: ERF_CloudChamber.H:425
bool heat_coefficient_specified
Definition: ERF_CloudChamber.H:416
amrex::Real heat_coefficient
Definition: ERF_CloudChamber.H:426
bool heat_model_specified
Definition: ERF_CloudChamber.H:412
bool momentum_coefficient_specified
Definition: ERF_CloudChamber.H:415
bool z0_m_specified
Definition: ERF_CloudChamber.H:418
amrex::Real vapor_coefficient
Definition: ERF_CloudChamber.H:427
bool vapor_coefficient_specified
Definition: ERF_CloudChamber.H:417
Definition: ERF_WallThermodynamics.H:86
constexpr AMREX_GPU_HOST_DEVICE bool heat_is_conductive() const noexcept
Definition: ERF_WallThermodynamics.H:96
ScalarTransfer vapor
Definition: ERF_WallThermodynamics.H:92
ScalarTransfer heat
Definition: ERF_WallThermodynamics.H:91
constexpr AMREX_GPU_HOST_DEVICE bool heat_uses_most() const noexcept
Definition: ERF_WallThermodynamics.H:108
constexpr AMREX_GPU_HOST_DEVICE bool vapor_is_wet() const noexcept
Definition: ERF_WallThermodynamics.H:99
MoistureMode moisture
Definition: ERF_WallThermodynamics.H:88
MomentumTransfer momentum
Definition: ERF_WallThermodynamics.H:90
amrex::Real wetness
Definition: ERF_WallThermodynamics.H:89
constexpr AMREX_GPU_HOST_DEVICE bool vapor_uses_most() const noexcept
Definition: ERF_WallThermodynamics.H:114
ThermalBoundary thermal
Definition: ERF_WallThermodynamics.H:87
amrex::Real resolved_row_rate
Definition: ERF_WallThermodynamics.H:72
MomentumModel model
Definition: ERF_WallThermodynamics.H:67
amrex::Real molecular_speed
Definition: ERF_WallThermodynamics.H:71
Definition: ERF_WallThermodynamics.H:75
amrex::Real z0
Definition: ERF_WallThermodynamics.H:79
amrex::Real resolved_speed
Definition: ERF_WallThermodynamics.H:83
amrex::Real molecular_speed
Definition: ERF_WallThermodynamics.H:81
ScalarModel model
Definition: ERF_WallThermodynamics.H:76
Definition: ERF_WallThermodynamics.H:44
amrex::Real temperature_K
Definition: ERF_WallThermodynamics.H:46
ThermalMode mode
Definition: ERF_WallThermodynamics.H:45