ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_Plotfile2DCloudOptics.H
Go to the documentation of this file.
1 /**
2  * \file ERF_Plotfile2DCloudOptics.H
3  */
4 #ifndef ERF_PLOTFILE2DCLOUDOPTICS_H_
5 #define ERF_PLOTFILE2DCLOUDOPTICS_H_
6 
7 #include <string>
8 
9 #include <AMReX_Geometry.H>
10 #include <AMReX_Math.H>
11 #include <AMReX_MultiFab.H>
12 #include "ERF_DataStruct.H"
13 #include "ERF_NumericalConstants.H"
14 
15 namespace plotfile2d {
16 
17 // Illustrative mass extinction [m^2/kg], in qc, qi, qr, qs, qg order.
18 // These fixed bulk proxies are not scheme-calibrated optical properties.
20 {
21  amrex::GpuArray<amrex::Real, 5> kext{{amrex::Real(150.), amrex::Real(65.4),
22  amrex::Real(3.), amrex::Real(30.),
23  amrex::Real(7.5)}};
24  // Two-stream-inspired default for conservative scattering (g = 0.85).
25  // User-tunable; not calibrated to the active microphysics or radiation scheme.
26  amrex::Real reflectance_scale = amrex::Real(7.7);
27 };
28 
29 //! Value written where the optical diagnostics are missing or invalid
30 constexpr amrex::Real cloud_optics_missing = amrex::Real(-999.);
31 
32 std::string
34 // Reads and validates erf.plot2d.cloud_optics.*, aborting on an invalid value.
36 // Prints the resolved settings as one "Plot2D cloud optics:" line.
38 bool cloud_optics_available (const MoistureComponentIndices& indices) noexcept;
39 
40 // Reference-illumination hydrometeor-only proxy, not a radiative-transfer solution.
41 // The two branches avoid overflow in tau + scale for large finite values.
42 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real
43 cloud_reflectance (amrex::Real tau, amrex::Real scale) noexcept
44 {
45  if (!amrex::Math::isfinite(tau) || tau < zero ||
46  !amrex::Math::isfinite(scale) || scale <= zero) {
47  return cloud_optics_missing;
48  }
49  if (tau == zero) {
50  return zero;
51  }
52  const amrex::Real value = tau > scale ? one / (one + scale / tau)
53  : (tau / scale) / (one + tau / scale);
54  return amrex::min(amrex::Real(one), amrex::max(amrex::Real(zero), value));
55 }
56 
57 // dst is the collapsed slab of cons with the same box ordering and mapping.
58 // Explicit destination components may be -1 for unrequested outputs. Computes
59 // one tau slab, sums z-stacked boxes, then transforms the completed level sum.
60 // This is the sum over this level's covered cells, even for an incomplete
61 // bottom-reaching column; no coarse-level mass is added. The writer retains
62 // its existing missing-value policy for columns with no ground source.
63 // Nonfinite present mass (even with kext=0), bad metrics, or overflow -> -999.
64 void fill_cloud_optics (amrex::MultiFab& dst,
65  int tau_component,
66  int albedo_component,
67  const amrex::MultiFab& cons,
68  const MoistureComponentIndices& indices,
69  const CloudOpticsParameters& parameters,
70  const amrex::Geometry& geom,
71  const amrex::MultiFab& detJ);
72 
73 } // namespace plotfile2d
74 #endif
Dimensionless numeric literals and pure mathematical constants.
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
@ cons
Definition: ERF_IndexDefines.H:231
Definition: ERF.H:125
CloudOpticsParameters parse_cloud_optics_parameters()
Definition: ERF_Plotfile2DCloudOptics.cpp:45
std::string cloud_optics_parameter_error(const CloudOpticsParameters &parameters)
Definition: ERF_Plotfile2DCloudOptics.cpp:28
bool cloud_optics_available(const MoistureComponentIndices &indices) noexcept
Definition: ERF_Plotfile2DCloudOptics.cpp:76
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real cloud_reflectance(amrex::Real tau, amrex::Real scale) noexcept
Definition: ERF_Plotfile2DCloudOptics.H:43
void fill_cloud_optics(MultiFab &dst, int tau_component, int albedo_component, const MultiFab &cons, const MoistureComponentIndices &indices, const CloudOpticsParameters &parameters, const Geometry &geom, const MultiFab &detJ)
Definition: ERF_Plotfile2DCloudOptics.cpp:87
constexpr amrex::Real cloud_optics_missing
Value written where the optical diagnostics are missing or invalid.
Definition: ERF_Plotfile2DCloudOptics.H:30
void print_cloud_optics_parameters(const CloudOpticsParameters &parameters)
Definition: ERF_Plotfile2DCloudOptics.cpp:64
The moisture data carried by the active microphysics scheme.
Definition: ERF_DataStruct.H:279
Definition: ERF_Plotfile2DCloudOptics.H:20
amrex::GpuArray< amrex::Real, 5 > kext
Definition: ERF_Plotfile2DCloudOptics.H:21
amrex::Real reflectance_scale
Definition: ERF_Plotfile2DCloudOptics.H:26