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

Functions

bool register_dust_model (const std::string &name, DustModelCreator creator)
 Add a model to the registry; aborts on an empty name or a name registered twice. More...
 
std::vector< std::string > dust_model_names ()
 Names erf.dust.model accepts, sorted; empty when no model is compiled in. More...
 
std::unique_ptr< DustModel > make_dust_model (const std::string &name)
 The model registered as name, or nullptr when no model has that name. More...
 
std::unique_ptr< DustModel > make_dust_model_from_inputs ()
 The model the inputs select, or nullptr when erf.dust.enable is not true. More...
 

Function Documentation

◆ dust_model_names()

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

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

47 {
48  std::vector<std::string> names;
49  for (const auto& kv : dust_model_registry()) { names.push_back(kv.first); }
50  return names; // std::map keeps them sorted
51 }

Referenced by make_dust_model_from_inputs().

Here is the caller graph for this function:

◆ make_dust_model()

std::unique_ptr<DustModel> make_dust_model ( const std::string &  name)

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

55 {
56  const auto& registry = dust_model_registry();
57  const auto it = registry.find(name);
58  if (it == registry.end()) { return nullptr; }
59  return it->second();
60 }
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139

Referenced by make_dust_model_from_inputs().

Here is the caller graph for this function:

◆ make_dust_model_from_inputs()

std::unique_ptr<DustModel> make_dust_model_from_inputs ( )

The model the inputs select, or nullptr when erf.dust.enable is not true.

erf.dust.model names the model; with one model compiled in it may be left out. Aborts when dust is enabled and no model, or no model of that name, is compiled in, listing the names this executable accepts, and when the model fills more dust scalars than the build has (NSCALARS_DUST).

64 {
65  amrex::ParmParse pp("erf.dust");
66  bool enable = false;
67  pp.query("enable", enable);
68  if (!enable) { return nullptr; }
69 
70  std::string name;
71  if (!pp.query("model", name)) {
72  const std::vector<std::string> names = dust_model_names();
73  if (names.size() != 1) {
74  amrex::Abort("erf.dust.enable = true needs erf.dust.model to name one of the dust models compiled in ("
75  + known_dust_models() + ")");
76  }
77  name = names.front();
78  }
79 
80  std::unique_ptr<DustModel> model = make_dust_model(name);
81  if (!model) {
82  amrex::Abort("erf.dust.model = \"" + name + "\" is not one of the dust models compiled in ("
83  + known_dust_models() + ")");
84  }
85  if (model->num_scalars() < 1 || model->num_scalars() > NSCALARS_DUST) {
86  amrex::Abort("dust model \"" + name + "\" fills " + std::to_string(model->num_scalars())
87  + " dust scalar(s), but this build has " + std::to_string(NSCALARS_DUST)
88  + "; rebuild with ERF_NUM_DUST_SCALARS (CMake) or NUM_DUST_SCALARS (GNU make) = "
89  + std::to_string(model->num_scalars()));
90  }
91  return model;
92 }
std::vector< std::string > dust_model_names()
Names erf.dust.model accepts, sorted; empty when no model is compiled in.
Definition: ERF_DustModelRegistry.cpp:46
std::unique_ptr< DustModel > make_dust_model(const std::string &name)
The model registered as name, or nullptr when no model has that name.
Definition: ERF_DustModelRegistry.cpp:54
#define NSCALARS_DUST
Definition: ERF_IndexDefines.H:30
ParmParse pp("prob")
Here is the call graph for this function:

◆ register_dust_model()

bool register_dust_model ( const std::string &  name,
DustModelCreator  creator 
)

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

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

32 {
33  auto& registry = dust_model_registry();
34  if (name.empty()) {
35  amrex::Abort("ERF_REGISTER_DUST_MODEL: a dust model registered an empty name");
36  }
37  if (registry.count(name) > 0) {
38  amrex::Abort("ERF_REGISTER_DUST_MODEL: two dust models registered the name \"" + name
39  + "\"; each model directory in the build must use its own name");
40  }
41  registry.emplace(name, std::move(creator));
42  return true;
43 }