ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
erf_sbm::SBMBoundaryLedger Struct Reference

#include <ERF_SBMPhysicalBoundary.H>

Collaboration diagram for erf_sbm::SBMBoundaryLedger:

Public Member Functions

void reset (int components)
 
double total_outward (int component) const
 
double total_gross (int component) const
 
std::string serialize () const
 

Static Public Member Functions

static bool parse (const std::string &text, int components, SBMBoundaryLedger &ledger, std::string &reason)
 

Public Attributes

int ncomp {0}
 
std::vector< double > outward
 
std::vector< double > gross
 
std::uint64_t face_stage_terms {0}
 

Detailed Description

Cumulative composite outward transfer through each physical face: coarse faces under a finer level are excluded, so the sum closes the leaf-domain inventory. Gross is the sum of absolute face transfers, a roundoff scale.

Member Function Documentation

◆ parse()

bool erf_sbm::SBMBoundaryLedger::parse ( const std::string &  text,
int  components,
SBMBoundaryLedger &  ledger,
std::string &  reason 
)
static
238 {
239  reason.clear();
240  std::istringstream input(text);
241  input.imbue(std::locale::classic());
242  std::string header;
243  std::string ncomp_line;
244  std::string terms_line;
245  if (!std::getline(input, header) || header != "ERF-SBM-BOUNDARY-LEDGER-v1" ||
246  !std::getline(input, ncomp_line) ||
247  ncomp_line != "ncomp=" + std::to_string(components) ||
248  !std::getline(input, terms_line) ||
249  terms_line.rfind("face_stage_terms=", 0) != 0) {
250  reason = "the boundary ledger header does not match the active layout";
251  return false;
252  }
253  SBMBoundaryLedger parsed;
254  parsed.reset(components);
255  std::istringstream terms(terms_line.substr(std::string("face_stage_terms=").size()));
256  terms.imbue(std::locale::classic());
257  if (!(terms >> parsed.face_stage_terms)) {
258  reason = "the boundary ledger operation count is unreadable";
259  return false;
260  }
261  for (int face = 0; face < physical_face_count; ++face) {
262  for (int component = 0; component < components; ++component) {
263  std::string name;
264  int index = -1;
265  double out_value = 0.0;
266  double gross_value = 0.0;
267  if (!(input >> name >> index >> out_value >> gross_value) ||
268  name != face_name(face) || index != component ||
269  !std::isfinite(out_value) || !std::isfinite(gross_value) ||
270  gross_value < 0.0) {
271  reason = "the boundary ledger entry for " + std::string(face_name(face)) +
272  " component " + std::to_string(component) + " is invalid";
273  return false;
274  }
275  const auto slot = static_cast<std::size_t>(face * components + component);
276  parsed.outward[slot] = out_value;
277  parsed.gross[slot] = gross_value;
278  }
279  }
280  std::string trailing;
281  if (input >> trailing) {
282  reason = "the boundary ledger has trailing data";
283  return false;
284  }
285  ledger = std::move(parsed);
286  return true;
287 }
std::string input
Definition: ERF_InputPreflight.cpp:29
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
const char * face_name(const int face) noexcept
Definition: ERF_SBMPhysicalBoundary.cpp:70
constexpr int physical_face_count
Definition: ERF_SBMPhysicalBoundary.H:19

Referenced by ERF::ReadCheckpointFile().

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

◆ reset()

void erf_sbm::SBMBoundaryLedger::reset ( int  components)
189 {
190  ncomp = components;
191  outward.assign(static_cast<std::size_t>(physical_face_count * components), 0.0);
192  gross.assign(static_cast<std::size_t>(physical_face_count * components), 0.0);
193  face_stage_terms = 0;
194 }
std::vector< double > gross
Definition: ERF_SBMPhysicalBoundary.H:66
int ncomp
Definition: ERF_SBMPhysicalBoundary.H:64
std::vector< double > outward
Definition: ERF_SBMPhysicalBoundary.H:65
std::uint64_t face_stage_terms
Definition: ERF_SBMPhysicalBoundary.H:67

Referenced by parse(), and erf_sbm::SBMTransport::SBMTransport().

Here is the caller graph for this function:

◆ serialize()

std::string erf_sbm::SBMBoundaryLedger::serialize ( ) const
218 {
219  std::ostringstream text;
220  text.imbue(std::locale::classic());
221  text << "ERF-SBM-BOUNDARY-LEDGER-v1\n"
222  << "ncomp=" << ncomp << '\n'
223  << "face_stage_terms=" << face_stage_terms << '\n';
224  for (int face = 0; face < physical_face_count; ++face) {
225  for (int component = 0; component < ncomp; ++component) {
226  const auto index = static_cast<std::size_t>(face * ncomp + component);
227  text << face_name(face) << ' ' << component << ' '
228  << canonical_decimal(outward[index]) << ' '
229  << canonical_decimal(gross[index]) << '\n';
230  }
231  }
232  return text.str();
233 }
std::string canonical_decimal(const T value)
Definition: ERF_SBMCanonicalIdentity.H:19
Here is the call graph for this function:

◆ total_gross()

double erf_sbm::SBMBoundaryLedger::total_gross ( int  component) const
208 {
209  double total = 0.0;
210  for (int face = 0; face < physical_face_count; ++face) {
211  total += gross[static_cast<std::size_t>(face * ncomp + component)];
212  }
213  return total;
214 }
@ total
Definition: ERF_NOAHMP_Fields.H:137

◆ total_outward()

double erf_sbm::SBMBoundaryLedger::total_outward ( int  component) const
198 {
199  double total = 0.0;
200  for (int face = 0; face < physical_face_count; ++face) {
201  total += outward[static_cast<std::size_t>(face * ncomp + component)];
202  }
203  return total;
204 }

Member Data Documentation

◆ face_stage_terms

std::uint64_t erf_sbm::SBMBoundaryLedger::face_stage_terms {0}

◆ gross

std::vector<double> erf_sbm::SBMBoundaryLedger::gross

◆ ncomp

int erf_sbm::SBMBoundaryLedger::ncomp {0}

◆ outward

std::vector<double> erf_sbm::SBMBoundaryLedger::outward

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