www.mooseframework.org
Static Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
Registry Class Reference

The registry is used as a global singleton to collect information on all available MooseObject and Action classes for use in a moose app/simulation. More...

#include <Registry.h>

Static Public Member Functions

template<typename T >
static char add (const RegistryEntry &info)
 Adds information on a MooseObject to the registry. More...
 
template<typename T >
static char addAction (const RegistryEntry &info)
 Adds information on an Action object to the registry. More...
 
static void registerObjectsTo (Factory &f, const std::set< std::string > &labels)
 This registers all MooseObjects known to the registry that have the given label(s) with the factory f. More...
 
static void registerActionsTo (ActionFactory &f, const std::set< std::string > &labels)
 This registers all Actions known to the registry that have the given label(s) with the factory f. More...
 
static void checkLabels (const std::set< std::string > &known_labels={})
 This runs error checking to make sure that all objects and actions in the registry have valid labels. More...
 
static char addKnownLabel (const std::string &label)
 addKnownLabel whitelists a label as valid for purposes of the checkLabels function. More...
 
static const std::map< std::string, std::vector< RegistryEntry > > & allObjects ()
 Returns a per-label keyed map of all MooseObjects in the registry. More...
 
static const std::map< std::string, std::vector< RegistryEntry > > & allActions ()
 Returns a per-label keyed map of all Actions in the registry. More...
 
static RegistryEntryobjData (const std::string &name)
 
static bool isADObj (const std::string &name)
 
static bool isRegisteredObj (const std::string &name)
 

Static Private Member Functions

static void addInner (const RegistryEntry &info)
 
static void addActionInner (const RegistryEntry &info)
 

Private Attributes

std::map< std::string, RegistryEntry_name_to_entry
 
std::map< std::string, std::vector< RegistryEntry > > _per_label_objects
 
std::map< std::string, std::vector< RegistryEntry > > _per_label_actions
 
std::set< std::string > _known_labels
 

Detailed Description

The registry is used as a global singleton to collect information on all available MooseObject and Action classes for use in a moose app/simulation.

It must be global because we want+need to be able to register objects in global scope during static initialization time before other parts of the moose app execution have started running. This allows us to distribute registration across all the files that define the actual classes being registered so we don't have to have any central location with a bajillion includes that makes (especially incremental) compiles slow. The registry collects the app, name, and other information for each objects and makes it available to the moose object and action factories and others for general use. All public functions in this class modify and return data from the global singleton.

Definition at line 196 of file Registry.h.

Member Function Documentation

◆ add()

template<typename T >
static char Registry::add ( const RegistryEntry info)
inlinestatic

Adds information on a MooseObject to the registry.

The _build_ptr, _build_action_ptr, and _params_ptr objects of the info object should all be nullptr - these are set automatically by the add function itself using the templated type T.

Definition at line 203 of file Registry.h.

204  {
205  RegistryEntry copy = info;
206  copy._build_ptr = &buildObj<T>;
207  copy._params_ptr = &validParams<T>;
208  addInner(copy);
209  return 0;
210  }
buildPtr _build_ptr
function pointer for building instances of the MooseObject (if the entry is for an object)...
Definition: Registry.h:156
paramsPtr _params_ptr
function pointer for building InputParameters objects for the object or action.
Definition: Registry.h:160
static void addInner(const RegistryEntry &info)
Definition: Registry.C:38
Holds details and meta-data info for a particular MooseObject or Action for use in the registry...
Definition: Registry.h:144

◆ addAction()

template<typename T >
static char Registry::addAction ( const RegistryEntry info)
inlinestatic

Adds information on an Action object to the registry.

The _build_ptr, _build_action_ptr, and _params_ptr objects of the info object should all be nullptr - these are set automatically by the addAction function itself using the templated type T.

Definition at line 216 of file Registry.h.

217  {
218  RegistryEntry copy = info;
219  copy._build_action_ptr = &buildAct<T>;
220  copy._params_ptr = &validParams<T>;
221  addActionInner(copy);
222  return 0;
223  }
buildActionPtr _build_action_ptr
function pointer for building instances of the Action (if the entry is for an action).
Definition: Registry.h:158
paramsPtr _params_ptr
function pointer for building InputParameters objects for the object or action.
Definition: Registry.h:160
static void addActionInner(const RegistryEntry &info)
Definition: Registry.C:45
Holds details and meta-data info for a particular MooseObject or Action for use in the registry...
Definition: Registry.h:144

◆ addActionInner()

void Registry::addActionInner ( const RegistryEntry info)
staticprivate

Definition at line 45 of file Registry.C.

Referenced by addAction().

46 {
47  auto & r = getRegistry();
48  r._per_label_actions[info._label].push_back(info);
49 }
static Registry & getRegistry()
Definition: Registry.C:18
std::string _label
label (usually app name - e.g. "YourAnimalApp") that the object or action is associated with...
Definition: Registry.h:147

◆ addInner()

void Registry::addInner ( const RegistryEntry info)
staticprivate

Definition at line 38 of file Registry.C.

Referenced by add().

39 {
40  auto & r = getRegistry();
41  r._per_label_objects[info._label].push_back(info);
42 }
static Registry & getRegistry()
Definition: Registry.C:18
std::string _label
label (usually app name - e.g. "YourAnimalApp") that the object or action is associated with...
Definition: Registry.h:147

◆ addKnownLabel()

char Registry::addKnownLabel ( const std::string &  label)
static

addKnownLabel whitelists a label as valid for purposes of the checkLabels function.

Definition at line 159 of file Registry.C.

Referenced by MooseApp::MooseApp().

160 {
161  auto & r = getRegistry();
162  r._known_labels.insert(label);
163  return 0;
164 }
static Registry & getRegistry()
Definition: Registry.C:18

◆ allActions()

const std::map< std::string, std::vector< RegistryEntry > > & Registry::allActions ( )
static

Returns a per-label keyed map of all Actions in the registry.

Definition at line 32 of file Registry.C.

Referenced by JsonSyntaxTree::JsonSyntaxTree(), and MooseApp::setupOptions().

33 {
35 }
std::map< std::string, std::vector< RegistryEntry > > _per_label_actions
Definition: Registry.h:257
static Registry & getRegistry()
Definition: Registry.C:18

◆ allObjects()

const std::map< std::string, std::vector< RegistryEntry > > & Registry::allObjects ( )
static

Returns a per-label keyed map of all MooseObjects in the registry.

Definition at line 27 of file Registry.C.

Referenced by JsonSyntaxTree::JsonSyntaxTree(), and MooseApp::setupOptions().

28 {
30 }
std::map< std::string, std::vector< RegistryEntry > > _per_label_objects
Definition: Registry.h:256
static Registry & getRegistry()
Definition: Registry.C:18

◆ checkLabels()

void Registry::checkLabels ( const std::set< std::string > &  known_labels = {})
static

This runs error checking to make sure that all objects and actions in the registry have valid labels.

Labels are considered valid if they have been added to the list of known labels via the addKnownLabel function or they have been used to register objects to a factory via registerObjectsTo or registerActionsTo.

Definition at line 136 of file Registry.C.

Referenced by MooseApp::checkRegistryLabels().

137 {
138  auto & r = getRegistry();
139  std::vector<RegistryEntry> orphs;
140 
141  for (auto & entry : r._per_label_objects)
142  if (known_labels.count(entry.first) == 0 && r._known_labels.count(entry.first) == 0)
143  orphs.insert(orphs.end(), entry.second.begin(), entry.second.end());
144  for (auto & entry : r._per_label_actions)
145  if (known_labels.count(entry.first) == 0 && r._known_labels.count(entry.first) == 0)
146  orphs.insert(orphs.end(), entry.second.begin(), entry.second.end());
147 
148  if (orphs.size() > 0)
149  {
150  std::stringstream lst;
151  for (auto & orph : orphs)
152  lst << "\n\t" << orph._classname << " (app='" << orph._label << "')";
153  mooseError("The following objects/actions have been registered to unknown applications/labels:",
154  lst.str());
155  }
156 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
static Registry & getRegistry()
Definition: Registry.C:18

◆ isADObj()

bool Registry::isADObj ( const std::string &  name)
static

Definition at line 110 of file Registry.C.

Referenced by AddBCAction::act(), AddMaterialAction::act(), AddKernelAction::act(), and AddDGKernelAction::act().

111 {
112  auto & r = getRegistry();
113 
114  auto it = r._name_to_entry.find(name);
115 
116  return (it != r._name_to_entry.end()) && it->second._is_ad;
117 }
static Registry & getRegistry()
Definition: Registry.C:18

◆ isRegisteredObj()

bool Registry::isRegisteredObj ( const std::string &  name)
static

Definition at line 100 of file Registry.C.

101 {
102  auto & r = getRegistry();
103 
104  auto it = r._name_to_entry.find(name);
105 
106  return it != r._name_to_entry.end();
107 }
static Registry & getRegistry()
Definition: Registry.C:18

◆ objData()

RegistryEntry & Registry::objData ( const std::string &  name)
static

Definition at line 87 of file Registry.C.

88 {
89  auto & r = getRegistry();
90 
91  auto it = r._name_to_entry.find(name);
92 
93  if (it != r._name_to_entry.end())
94  return it->second;
95  else
96  mooseError("Object ", name, " is not registered yet");
97 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
static Registry & getRegistry()
Definition: Registry.C:18

◆ registerActionsTo()

void Registry::registerActionsTo ( ActionFactory f,
const std::set< std::string > &  labels 
)
static

This registers all Actions known to the registry that have the given label(s) with the factory f.

Definition at line 120 of file Registry.C.

Referenced by Moose::registerActions().

121 {
122  auto & r = getRegistry();
123  for (const auto & label : labels)
124  {
125  r._known_labels.insert(label);
126  if (r._per_label_actions.count(label) == 0)
127  continue;
128 
129  for (const auto & obj : r._per_label_actions[label])
130  f.reg(
131  obj._classname, obj._name, obj._build_action_ptr, obj._params_ptr, obj._file, obj._line);
132  }
133 }
void reg(const std::string &name, const std::string &task, const std::string &file="", int line=-1)
Definition: ActionFactory.h:75
static Registry & getRegistry()
Definition: Registry.C:18

◆ registerObjectsTo()

void Registry::registerObjectsTo ( Factory f,
const std::set< std::string > &  labels 
)
static

This registers all MooseObjects known to the registry that have the given label(s) with the factory f.

Definition at line 52 of file Registry.C.

Referenced by Moose::registerObjects().

53 {
54  auto & r = getRegistry();
55  for (const auto & label : labels)
56  {
57  r._known_labels.insert(label);
58  if (r._per_label_objects.count(label) == 0)
59  continue;
60 
61  for (const auto & obj : r._per_label_objects[label])
62  {
63  std::string name = obj._name;
64  if (name.empty())
65  name = obj._alias;
66  if (name.empty())
67  name = obj._classname;
68 
69  r._name_to_entry[name] = obj;
70 
71  f.reg(obj._label,
72  name,
73  obj._build_ptr,
74  obj._params_ptr,
75  obj._deprecated_time,
76  obj._replaced_by,
77  obj._file,
78  obj._line);
79 
80  if (!obj._alias.empty())
81  f.associateNameToClass(name, obj._classname);
82  }
83  }
84 }
if(nl->nonlinearSolver() ->matvec &&nl->nonlinearSolver() ->residual_and_jacobian_object)
void associateNameToClass(const std::string &name, const std::string &class_name)
Associates an object name with a class name.
Definition: Factory.C:292
void reg(const std::string &obj_name, const std::string &file="", int line=-1)
Register a new object.
Definition: Factory.h:165
static Registry & getRegistry()
Definition: Registry.C:18

Member Data Documentation

◆ _known_labels

std::set<std::string> Registry::_known_labels
private

Definition at line 258 of file Registry.h.

◆ _name_to_entry

std::map<std::string, RegistryEntry> Registry::_name_to_entry
private

Definition at line 255 of file Registry.h.

◆ _per_label_actions

std::map<std::string, std::vector<RegistryEntry> > Registry::_per_label_actions
private

Definition at line 257 of file Registry.h.

Referenced by allActions().

◆ _per_label_objects

std::map<std::string, std::vector<RegistryEntry> > Registry::_per_label_objects
private

Definition at line 256 of file Registry.h.

Referenced by allObjects().


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