ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_StructureModelRegistry.cpp File Reference
#include <ERF_StructureModelRegistry.H>
#include <AMReX.H>
#include <AMReX_ParmParse.H>
#include <algorithm>
#include <cstddef>
#include <map>
Include dependency graph for ERF_StructureModelRegistry.cpp:

Functions

bool register_structure_model (const std::string &name, StructureModelCreator creator)
 Add a model to the registry; aborts on an empty name or a name registered twice. More...
 
std::vector< std::string > structure_model_names ()
 Names erf.structures.model accepts, sorted; empty when no model is compiled in. More...
 
std::unique_ptr< StructureModel > make_structure_model (const std::string &name, int max_level)
 The model registered as name, or nullptr when no model has that name. More...
 
std::unique_ptr< StructureModel > make_structure_model_from_inputs (int max_level)
 The model erf.structures.model selects, or nullptr when the key is not set. More...
 
void check_structure_plot_names (const StructureModel &model, const std::vector< std::string > &taken)
 Stop the run when the model's plot_var_names() cannot all be plotted. More...
 

Function Documentation

◆ check_structure_plot_names()

void check_structure_plot_names ( const StructureModel &  model,
const std::vector< std::string > &  taken 
)

Stop the run when the model's plot_var_names() cannot all be plotted.

Aborts, naming the model and the name, on an empty name, a name the model lists twice, or a name in taken (the names ERF and the other models already provide). ERF's plotfile assembly would otherwise drop the name from the list and still fill it, and fail with a less helpful message.

74 {
75  const std::vector<std::string> names = model.plot_var_names();
76  for (std::size_t i = 0; i < names.size(); ++i) {
77  const std::string& n = names[i];
78  const std::string who = std::string("structure model \"") + model.name() + "\"";
79  if (n.empty()) {
80  amrex::Abort(who + " lists an empty plot variable name");
81  }
82  if (std::find(names.begin(), names.begin() + static_cast<std::ptrdiff_t>(i), n) != names.begin() + static_cast<std::ptrdiff_t>(i)) {
83  amrex::Abort(who + " lists the plot variable \"" + n + "\" twice");
84  }
85  if (std::find(taken.begin(), taken.end(), n) != taken.end()) {
86  amrex::Abort(who + " lists the plot variable \"" + n
87  + "\", which ERF or another model already provides; give the model's names its own prefix");
88  }
89  }
90 }
virtual std::vector< std::string > plot_var_names() const
Fields the ERF plotfile can carry, by name.
Definition: ERF_StructureModel.H:304
virtual const char * name() const =0
Name of the model, as erf.structures.model selects it.

Referenced by ERF::appendPlot3DVariables().

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

◆ make_structure_model()

std::unique_ptr<StructureModel> make_structure_model ( const std::string &  name,
int  max_level 
)

The model registered as name, or nullptr when no model has that name.

46 {
47  const auto& registry = structure_model_registry();
48  const auto it = registry.find(name);
49  if (it == registry.end()) { return nullptr; }
50  return it->second(max_level);
51 }
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139

Referenced by make_structure_model_from_inputs().

Here is the caller graph for this function:

◆ make_structure_model_from_inputs()

std::unique_ptr<StructureModel> make_structure_model_from_inputs ( int  max_level)

The model erf.structures.model selects, or nullptr when the key is not set.

Aborts when the key names no registered model, listing the names this executable accepts.

55 {
56  amrex::ParmParse pp("erf.structures");
57  std::string name;
58  if (!pp.query("model", name)) { return nullptr; }
59 
60  std::unique_ptr<StructureModel> model = make_structure_model(name, max_level);
61  if (!model) {
62  std::string known;
63  for (const auto& n : structure_model_names()) { known += (known.empty() ? "" : ", ") + ("\"" + n + "\""); }
64  amrex::Abort("erf.structures.model = \"" + name + "\" is not one of the structure models compiled in ("
65  + (known.empty() ? std::string("none; add a model directory with ERF_STRUCTURE_MODEL_DIRS"
66  " in CMake or STRUCTURE_HOME in GNU make")
67  : known) + ")");
68  }
69  return model;
70 }
ParmParse pp("prob")
std::unique_ptr< StructureModel > make_structure_model(const std::string &name, int max_level)
The model registered as name, or nullptr when no model has that name.
Definition: ERF_StructureModelRegistry.cpp:45
std::vector< std::string > structure_model_names()
Names erf.structures.model accepts, sorted; empty when no model is compiled in.
Definition: ERF_StructureModelRegistry.cpp:37

Referenced by ERF::ERF_shared().

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

◆ register_structure_model()

bool register_structure_model ( const std::string &  name,
StructureModelCreator  creator 
)

Add a model to the registry; aborts on an empty name or a name registered twice.

Called by ERF_REGISTER_STRUCTURE_MODEL; returns true so the macro can hold the result in a static variable.

23 {
24  auto& registry = structure_model_registry();
25  if (name.empty()) {
26  amrex::Abort("ERF_REGISTER_STRUCTURE_MODEL: a structure model registered an empty name");
27  }
28  if (registry.count(name) > 0) {
29  amrex::Abort("ERF_REGISTER_STRUCTURE_MODEL: two structure models registered the name \"" + name
30  + "\"; each model directory in the build must use its own name");
31  }
32  registry.emplace(name, std::move(creator));
33  return true;
34 }

◆ structure_model_names()

std::vector<std::string> structure_model_names ( )

Names erf.structures.model accepts, sorted; empty when no model is compiled in.

38 {
39  std::vector<std::string> names;
40  for (const auto& kv : structure_model_registry()) { names.push_back(kv.first); }
41  return names; // std::map keeps them sorted
42 }

Referenced by make_structure_model_from_inputs().

Here is the caller graph for this function: