https://mooseframework.inl.gov
Classes | Public Types | Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
ActionFactory Class Reference

Specialized factory for generic Action System objects. More...

#include <ActionFactory.h>

Classes

struct  BuildInfo
 

Public Types

typedef std::multimap< std::string, BuildInfo >::iterator iterator
 Typedef for registered Action iterator. More...
 
typedef std::multimap< std::string, BuildInfo >::const_iterator const_iterator
 

Public Member Functions

 ActionFactory (MooseApp &app)
 
virtual ~ActionFactory ()
 
MooseAppapp ()
 
void reg (std::shared_ptr< RegistryEntryBase > obj)
 
FileLineInfo getLineInfo (const std::string &name, const std::string &task) const
 Gets file and line information where an action was registered. More...
 
std::string getTaskName (const std::string &action)
 
std::shared_ptr< Actioncreate (const std::string &action, const std::string &action_name, InputParameters &parameters)
 
InputParameters getValidParams (const std::string &name)
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
std::pair< std::multimap< std::string, std::string >::const_iterator, std::multimap< std::string, std::string >::const_iteratorgetActionsByTask (const std::string &task) const
 Returns begin and end iterators in a multimap from tasks to actions names. More...
 
std::set< std::string > getTasksByAction (const std::string &action) const
 
bool isRegisteredTask (const std::string &task) const
 Whether or not a task with the name task is registered. More...
 
const InputParameterscurrentlyConstructing () const
 

Static Private Member Functions

template<class T >
static std::shared_ptr< ActionbuildAction (const InputParameters &parameters)
 

Private Attributes

MooseApp_app
 
std::multimap< std::string, BuildInfo_name_to_build_info
 
FileLineInfoMap _name_to_line
 
std::multimap< std::string, std::string > _task_to_action_map
 
std::set< std::pair< std::string, std::string > > _current_objs
 set<objectname, task> used to track if an object previously added is being added again More...
 
std::set< std::string > _tasks
 The registered tasks. More...
 
std::vector< const InputParameters * > _currently_constructing
 The object's parameters that are currently being constructed (if any). More...
 

Detailed Description

Specialized factory for generic Action System objects.

Definition at line 50 of file ActionFactory.h.

Member Typedef Documentation

◆ const_iterator

typedef std::multimap<std::string, BuildInfo>::const_iterator ActionFactory::const_iterator

Definition at line 84 of file ActionFactory.h.

◆ iterator

typedef std::multimap<std::string, BuildInfo>::iterator ActionFactory::iterator

Typedef for registered Action iterator.

Definition at line 83 of file ActionFactory.h.

Constructor & Destructor Documentation

◆ ActionFactory()

ActionFactory::ActionFactory ( MooseApp app)

Definition at line 17 of file ActionFactory.C.

17 : _app(app) {}
MooseApp & _app
MooseApp & app()
Definition: ActionFactory.h:57

◆ ~ActionFactory()

ActionFactory::~ActionFactory ( )
virtual

Definition at line 19 of file ActionFactory.C.

19 {}

Member Function Documentation

◆ app()

MooseApp& ActionFactory::app ( )
inline

Definition at line 57 of file ActionFactory.h.

57 { return _app; }
MooseApp & _app

◆ begin() [1/2]

ActionFactory::iterator ActionFactory::begin ( )

Definition at line 126 of file ActionFactory.C.

127 {
128  return _name_to_build_info.begin();
129 }
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ begin() [2/2]

ActionFactory::const_iterator ActionFactory::begin ( ) const

Definition at line 132 of file ActionFactory.C.

133 {
134  return _name_to_build_info.begin();
135 }
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ buildAction()

template<class T >
static std::shared_ptr<Action> ActionFactory::buildAction ( const InputParameters parameters)
inlinestaticprivate

Definition at line 114 of file ActionFactory.h.

115  {
116  return std::make_shared<T>(parameters);
117  }

◆ create()

std::shared_ptr< Action > ActionFactory::create ( const std::string &  action,
const std::string &  action_name,
InputParameters parameters 
)

Definition at line 40 of file ActionFactory.C.

Referenced by AddActionComponentAction::act(), CreateMeshSetupActionsForComponents::act(), ActionWarehouse::buildBuildableActions(), CommonOutputAction::create(), AddVariableAction::createInitialConditionAction(), MooseApp::createMinimalApp(), DumpObjectsProblem::DumpObjectsProblem(), CreateExecutionerAction::setupAutoPreconditioning(), ReadExecutorParamsAction::setupAutoPreconditioning(), and Moose::Builder::walkRaw().

43 {
44  std::string action_name = MooseUtils::shortName(full_action_name);
45  incoming_parser_params.addPrivateParam(MooseBase::app_param, &_app);
46  incoming_parser_params.set<std::string>(MooseBase::type_param) = action;
47 
48  std::pair<ActionFactory::iterator, ActionFactory::iterator> iters;
49 
50  const std::string unique_action_name =
51  action + incoming_parser_params.get<std::string>("task") + full_action_name;
52 
53  // Create the actual parameters object that the object will reference
55  unique_action_name, incoming_parser_params, 0, {});
56 
57  if (!action_params.getHitNode())
58  {
59  // If we currently are in an action, that means that we're creating an
60  // action from within an action. Associate the action creating this one
61  // with the new action's parameters so that errors can be associated with it
62  if (const auto hit_node = _app.getCurrentActionHitNode())
63  action_params.setHitNode(*hit_node, {});
64  // Don't have one, so just use the root
65  else
66  action_params.setHitNode(_app.parser().getRoot(), {});
67  }
68 
69  action_params.set<std::string>(Action::unique_action_name_param) = unique_action_name;
70  action_params.set<std::string>(MooseBase::name_param) = action_name;
71 
72  // Check and finalize the parameters
73  action_params.finalize(action_name);
74 
75  iters = _name_to_build_info.equal_range(action);
76  BuildInfo * build_info = &(iters.first->second);
77  if (!build_info)
78  mooseError(
79  std::string("Unable to find buildable Action from supplied InputParameters Object for ") +
80  action_name);
81 
82  // Create the object
83  _currently_constructing.push_back(&action_params);
84  std::shared_ptr<Action> action_obj = build_info->_obj_pointer->buildAction(action_params);
85  _currently_constructing.pop_back();
86 
87  if (action_params.get<std::string>("task") == "")
88  action_obj->appendTask(build_info->_task);
89 
90  return action_obj;
91 }
static const std::string name_param
The name of the parameter that contains the object name.
Definition: MooseBase.h:55
static const std::string app_param
The name of the parameter that contains the MooseApp.
Definition: MooseBase.h:59
static const std::string type_param
The name of the parameter that contains the object type.
Definition: MooseBase.h:53
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
Definition: MooseApp.C:2900
InputParameters & addInputParameters(const std::string &name, const InputParameters &parameters, THREAD_ID tid, const AddRemoveParamsKey)
Method for adding a new InputParameters object.
hit::Node & getRoot()
Definition: Parser.C:449
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static const std::string unique_action_name_param
The name of the parameter that contains the unique action name.
Definition: Action.h:37
const hit::Node * getCurrentActionHitNode() const
Definition: MooseApp.C:3095
std::string shortName(const std::string &name)
Function for stripping name after the file / in parser block.
Definition: MooseUtils.C:608
MooseApp & _app
const Parser & parser() const
Definition: MooseApp.C:1987
std::vector< const InputParameters * > _currently_constructing
The object&#39;s parameters that are currently being constructed (if any).
std::multimap< std::string, BuildInfo > _name_to_build_info
void setHitNode(const std::string &param, const hit::Node &node, const SetParamHitNodeKey)
Sets the hit node associated with the parameter param to node.

◆ currentlyConstructing()

const InputParameters * ActionFactory::currentlyConstructing ( ) const
Returns
The InputParameters for the object that is currently being constructed, if any.

Can be used to ensure that all Actions are created using the ActionFactory

Definition at line 173 of file ActionFactory.C.

Referenced by Action::Action().

174 {
175  return _currently_constructing.size() ? _currently_constructing.back() : nullptr;
176 }
std::vector< const InputParameters * > _currently_constructing
The object&#39;s parameters that are currently being constructed (if any).

◆ end() [1/2]

ActionFactory::iterator ActionFactory::end ( )

Definition at line 138 of file ActionFactory.C.

139 {
140  return _name_to_build_info.end();
141 }
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ end() [2/2]

ActionFactory::const_iterator ActionFactory::end ( ) const

Definition at line 144 of file ActionFactory.C.

145 {
146  return _name_to_build_info.end();
147 }
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ getActionsByTask()

std::pair< std::multimap< std::string, std::string >::const_iterator, std::multimap< std::string, std::string >::const_iterator > ActionFactory::getActionsByTask ( const std::string &  task) const

Returns begin and end iterators in a multimap from tasks to actions names.

Definition at line 151 of file ActionFactory.C.

Referenced by ActionWarehouse::buildBuildableActions(), and Moose::Builder::buildJsonSyntaxTree().

152 {
153  return _task_to_action_map.equal_range(task);
154 }
std::multimap< std::string, std::string > _task_to_action_map

◆ getLineInfo()

FileLineInfo ActionFactory::getLineInfo ( const std::string &  name,
const std::string &  task 
) const

Gets file and line information where an action was registered.

Parameters
nameAction name
tasktask name
Returns
A FileLineInfo associated with the name/task pair

Definition at line 179 of file ActionFactory.C.

Referenced by Moose::Builder::buildJsonSyntaxTree().

180 {
181  return _name_to_line.getInfo(name, task);
182 }
FileLineInfo getInfo(const std::string &key0) const
Get file/line info for a key.
Definition: FileLineInfo.C:76
FileLineInfoMap _name_to_line

◆ getTaskName()

std::string ActionFactory::getTaskName ( const std::string &  action)

Definition at line 114 of file ActionFactory.C.

Referenced by Moose::Builder::buildFullTree(), and Moose::Builder::buildJsonSyntaxTree().

115 {
116  // We are returning only the first found instance here
117  std::multimap<std::string, BuildInfo>::iterator iter = _name_to_build_info.find(action);
118 
119  if (iter != _name_to_build_info.end())
120  return iter->second._task;
121  else
122  return "";
123 }
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ getTasksByAction()

std::set< std::string > ActionFactory::getTasksByAction ( const std::string &  action) const

Definition at line 157 of file ActionFactory.C.

Referenced by ActionWarehouse::addActionBlock(), Moose::Builder::buildJsonSyntaxTree(), ActionComponent::checkRequiredTasks(), PhysicsBase::checkRequiredTasks(), and MooseServer::getActionParameters().

158 {
159  std::set<std::string> tasks;
160 
161  std::pair<std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator,
162  std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator>
163  iters = _name_to_build_info.equal_range(action);
164  for (std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator it = iters.first;
165  it != iters.second;
166  ++it)
167  tasks.insert(it->second._task);
168 
169  return tasks;
170 }
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ getValidParams()

InputParameters ActionFactory::getValidParams ( const std::string &  name)

If an Action is registered more than once, it'll appear in the _name_to_build_info data structure multiple times. The actual parameters function remains the same however so we can safely use the first instance

Definition at line 94 of file ActionFactory.C.

Referenced by CreateMeshSetupActionsForComponents::act(), ActionWarehouse::buildBuildableActions(), Moose::Builder::buildFullTree(), Moose::Builder::buildJsonSyntaxTree(), AddVariableAction::createInitialConditionAction(), MooseApp::createMinimalApp(), DumpObjectsProblem::DumpObjectsProblem(), MooseServer::getActionParameters(), Moose::Builder::listValidParams(), ReadExecutorParamsAction::setupAutoPreconditioning(), CreateExecutionerAction::setupAutoPreconditioning(), and Moose::Builder::walkRaw().

95 {
102 
103  if (iter == _name_to_build_info.end())
104  mooseError(std::string("A '") + name + "' is not a registered Action\n\n");
105 
106  InputParameters params = iter->second._obj_pointer->buildParameters();
109 
110  return params;
111 }
std::string name(const ElemQuality q)
static const std::string app_param
The name of the parameter that contains the MooseApp.
Definition: MooseBase.h:59
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
Storage for action instances.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::multimap< std::string, BuildInfo >::iterator iterator
Typedef for registered Action iterator.
Definition: ActionFactory.h:83
MooseApp & _app
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
Definition: MooseApp.h:204
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ isRegisteredTask()

bool ActionFactory::isRegisteredTask ( const std::string &  task) const
inline

Whether or not a task with the name task is registered.

Definition at line 102 of file ActionFactory.h.

Referenced by ActionWarehouse::hasTask().

102 { return _tasks.count(task); }
std::set< std::string > _tasks
The registered tasks.

◆ reg()

void ActionFactory::reg ( std::shared_ptr< RegistryEntryBase obj)

Definition at line 22 of file ActionFactory.C.

Referenced by Registry::registerActionsTo().

23 {
24  const std::string & name = obj->_classname;
25  const std::string & task = obj->_name;
26 
27  auto key = std::make_pair(name, task);
28  if (_current_objs.count(key) > 0)
29  return;
30  _current_objs.insert(key);
31 
32  BuildInfo build_info{obj, task};
33  _name_to_build_info.insert(std::make_pair(name, build_info));
34  _task_to_action_map.insert(std::make_pair(task, name));
35  _tasks.insert(task);
36  _name_to_line.addInfo(name, task, obj->_file, obj->_line);
37 }
std::string name(const ElemQuality q)
std::set< std::string > _tasks
The registered tasks.
void addInfo(const std::string &key0, const std::string &file, int line)
Associate a key with file/line info.
Definition: FileLineInfo.C:35
FileLineInfoMap _name_to_line
std::set< std::pair< std::string, std::string > > _current_objs
set<objectname, task> used to track if an object previously added is being added again ...
std::multimap< std::string, BuildInfo > _name_to_build_info
std::multimap< std::string, std::string > _task_to_action_map

Member Data Documentation

◆ _app

MooseApp& ActionFactory::_app
private

Definition at line 119 of file ActionFactory.h.

Referenced by app(), create(), and getValidParams().

◆ _current_objs

std::set<std::pair<std::string, std::string> > ActionFactory::_current_objs
private

set<objectname, task> used to track if an object previously added is being added again

Definition at line 127 of file ActionFactory.h.

Referenced by reg().

◆ _currently_constructing

std::vector<const InputParameters *> ActionFactory::_currently_constructing
private

The object's parameters that are currently being constructed (if any).

This is a vector because we create within create, thus the last entry is the one that is being constructed at the moment

Definition at line 135 of file ActionFactory.h.

Referenced by create(), and currentlyConstructing().

◆ _name_to_build_info

std::multimap<std::string, BuildInfo> ActionFactory::_name_to_build_info
private

Definition at line 121 of file ActionFactory.h.

Referenced by begin(), create(), end(), getTaskName(), getTasksByAction(), getValidParams(), and reg().

◆ _name_to_line

FileLineInfoMap ActionFactory::_name_to_line
private

Definition at line 123 of file ActionFactory.h.

Referenced by getLineInfo(), and reg().

◆ _task_to_action_map

std::multimap<std::string, std::string> ActionFactory::_task_to_action_map
private

Definition at line 124 of file ActionFactory.h.

Referenced by getActionsByTask(), and reg().

◆ _tasks

std::set<std::string> ActionFactory::_tasks
private

The registered tasks.

Definition at line 130 of file ActionFactory.h.

Referenced by isRegisteredTask(), and reg().


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