ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
erf_sbm::SpectralGrid Class Reference

#include <ERF_SpectralGrid.H>

Collaboration diagram for erf_sbm::SpectralGrid:

Public Member Functions

 SpectralGrid (SpectralGridSpec spec)
 
CoordinateKind coordinate_kind () const noexcept
 
const std::string & coordinate_units () const noexcept
 
const std::vector< amrex::Real > & edges () const noexcept
 
const std::vector< amrex::Real > & pivots () const noexcept
 
int nbins () const noexcept
 
amrex::Real pivot (const int bin) const
 
std::string identity () const
 

Static Public Member Functions

static GridValidation validate (const SpectralGridSpec &spec)
 
static bool two_moment_realizable (amrex::Real C, amrex::Real M, amrex::Real lower, amrex::Real upper) noexcept
 
static EndpointTransform two_moment_to_endpoints (amrex::Real C, amrex::Real M, amrex::Real lower, amrex::Real upper)
 
static std::pair< amrex::Real, amrex::Real > endpoints_to_two_moment (amrex::Real L, amrex::Real H, amrex::Real lower, amrex::Real upper)
 

Private Attributes

SpectralGridSpec m_spec
 

Detailed Description

Runtime-sized, immutable-after-construction spectral grid.

Constructor & Destructor Documentation

◆ SpectralGrid()

erf_sbm::SpectralGrid::SpectralGrid ( SpectralGridSpec  spec)
explicit
42  : m_spec(std::move(spec))
43 {
44  const auto result = validate(m_spec);
45  if (!result.valid) throw std::invalid_argument("invalid spectral grid: " + result.message);
46 }
SpectralGridSpec m_spec
Definition: ERF_SpectralGrid.H:137
static GridValidation validate(const SpectralGridSpec &spec)
Definition: ERF_SpectralGrid.cpp:13
Here is the call graph for this function:

Member Function Documentation

◆ coordinate_kind()

CoordinateKind erf_sbm::SpectralGrid::coordinate_kind ( ) const
inlinenoexcept
116 { return m_spec.coordinate_kind; }
CoordinateKind coordinate_kind
Definition: ERF_SpectralGrid.H:22

◆ coordinate_units()

const std::string& erf_sbm::SpectralGrid::coordinate_units ( ) const
inlinenoexcept
117 { return m_spec.coordinate_units; }
std::string coordinate_units
Definition: ERF_SpectralGrid.H:23

◆ edges()

const std::vector<amrex::Real>& erf_sbm::SpectralGrid::edges ( ) const
inlinenoexcept
118 { return m_spec.edges; }
std::vector< amrex::Real > edges
Definition: ERF_SpectralGrid.H:24

◆ endpoints_to_two_moment()

std::pair< amrex::Real, amrex::Real > erf_sbm::SpectralGrid::endpoints_to_two_moment ( amrex::Real  L,
amrex::Real  H,
amrex::Real  lower,
amrex::Real  upper 
)
static
80 {
81  amrex::Real C = amrex::Real(0.0);
82  amrex::Real M = amrex::Real(0.0);
83  if (!try_endpoints_to_two_moment(L, H, lower, upper, C, M)) {
84  throw std::invalid_argument("invalid two-moment endpoint state");
85  }
86  return {C, M};
87 }
Real H
Definition: ERF_InitCustomPert_MovingTerrain.H:7
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool try_endpoints_to_two_moment(const amrex::Real L, const amrex::Real H, const amrex::Real lower, const amrex::Real upper, amrex::Real &C, amrex::Real &M) noexcept
Definition: ERF_SpectralGrid.H:89
Here is the call graph for this function:

◆ identity()

std::string erf_sbm::SpectralGrid::identity ( ) const
49 {
50  std::ostringstream out;
51  out << "spectral-grid-v4|kind=" << static_cast<int>(m_spec.coordinate_kind)
52  << "|coordinate_units=" << m_spec.coordinate_units << "|edges=";
53  for (const auto x : m_spec.edges) out << canonical_real(x) << ',';
54  out << "|pivots=";
55  for (const auto x : m_spec.pivots) out << canonical_real(x) << ',';
56  return out.str();
57 }
for(int i=0;i< m_num_species;i++)
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:48
std::string canonical_real(const amrex::Real value, const bool allow_unbounded_nan=false)
Definition: ERF_SBMCanonicalIdentity.H:18
std::vector< amrex::Real > pivots
Definition: ERF_SpectralGrid.H:25
Here is the call graph for this function:

◆ nbins()

int erf_sbm::SpectralGrid::nbins ( ) const
inlinenoexcept
120 { return static_cast<int>(m_spec.edges.size()) - 1; }

◆ pivot()

amrex::Real erf_sbm::SpectralGrid::pivot ( const int  bin) const
inline
122 { return m_spec.pivots.at(static_cast<std::size_t>(bin)); }

Referenced by validate().

Here is the caller graph for this function:

◆ pivots()

const std::vector<amrex::Real>& erf_sbm::SpectralGrid::pivots ( ) const
inlinenoexcept
119 { return m_spec.pivots; }

◆ two_moment_realizable()

bool erf_sbm::SpectralGrid::two_moment_realizable ( amrex::Real  C,
amrex::Real  M,
amrex::Real  lower,
amrex::Real  upper 
)
staticnoexcept
61 {
62  EndpointTransform result;
63  return try_two_moment_to_endpoints(C, M, lower, upper, result);
64 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool try_two_moment_to_endpoints(const amrex::Real C, const amrex::Real M, const amrex::Real lower, const amrex::Real upper, EndpointTransform &result) noexcept
Definition: ERF_SpectralGrid.H:48
Here is the call graph for this function:

◆ two_moment_to_endpoints()

EndpointTransform erf_sbm::SpectralGrid::two_moment_to_endpoints ( amrex::Real  C,
amrex::Real  M,
amrex::Real  lower,
amrex::Real  upper 
)
static
69 {
70  EndpointTransform result;
71  if (!try_two_moment_to_endpoints(C, M, lower, upper, result)) {
72  throw std::invalid_argument("invalid or materially non-realizable two-moment state");
73  }
74  return result;
75 }
Here is the call graph for this function:

◆ validate()

GridValidation erf_sbm::SpectralGrid::validate ( const SpectralGridSpec &  spec)
static
14 {
15  if (spec.edges.size() < 2) return {false, "spectral grid needs at least one bin"};
16  if (spec.coordinate_units.empty()) return {false, "spectral coordinate units are required"};
17  for (std::size_t i = 0; i < spec.edges.size(); ++i) {
18  const auto edge = spec.edges[i];
19  if (!std::isfinite(edge) || edge < amrex::Real(0.0)) return {false, "edges must be finite and nonnegative"};
20  if (i > 0) {
21  const auto lower = spec.edges[i-1];
22  if (!(lower < edge)) return {false, "edges must be strictly increasing"};
23  const auto width = edge - lower;
24  const auto scale = std::max(std::abs(lower), std::abs(edge));
25  // This is a relative conditioning rule. There is deliberately
26  // no absolute floor: [0, small] remains a valid scientific bin.
27  if (scale > amrex::Real(0.0) &&
28  width < amrex::Real(1000.0) * std::numeric_limits<amrex::Real>::epsilon() * scale) {
29  return {false, "spectral bin edge separation is below the relative conditioning threshold"};
30  }
31  }
32  }
33  if (spec.pivots.size() != spec.edges.size() - 1) return {false, "one positive pivot is required per bin"};
34  for (std::size_t i = 0; i < spec.pivots.size(); ++i) {
35  const auto pivot = spec.pivots[i];
36  if (!std::isfinite(pivot) || pivot <= amrex::Real(0.0)) return {false, "pivots must be finite and positive"};
37  if (!(spec.edges[i] <= pivot && pivot <= spec.edges[i+1])) return {false, "pivot must lie inside its bin"};
38  }
39  return {true, {}};
40 }
amrex::Real pivot(const int bin) const
Definition: ERF_SpectralGrid.H:122
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12

Referenced by SpectralGrid(), and erf_sbm::SBMLayout::validate().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_spec

SpectralGridSpec erf_sbm::SpectralGrid::m_spec
private

The documentation for this class was generated from the following files: