www.mooseframework.org
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
 
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 16 of file ActionFactory.C.

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

◆ ~ActionFactory()

ActionFactory::~ActionFactory ( )
virtual

Definition at line 18 of file ActionFactory.C.

18 {}

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 124 of file ActionFactory.C.

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

◆ begin() [2/2]

ActionFactory::const_iterator ActionFactory::begin ( ) const

Definition at line 130 of file ActionFactory.C.

131 {
132  return _name_to_build_info.begin();
133 }
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 113 of file ActionFactory.h.

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

◆ create()

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

Definition at line 39 of file ActionFactory.C.

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

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

Referenced by Action::Action().

172 {
173  return _currently_constructing.size() ? _currently_constructing.back() : nullptr;
174 }
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 136 of file ActionFactory.C.

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

◆ end() [2/2]

ActionFactory::const_iterator ActionFactory::end ( ) const

Definition at line 142 of file ActionFactory.C.

143 {
144  return _name_to_build_info.end();
145 }
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

Definition at line 149 of file ActionFactory.C.

Referenced by ActionWarehouse::buildBuildableActions().

150 {
151  return _task_to_action_map.equal_range(task);
152 }
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 177 of file ActionFactory.C.

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

178 {
179  return _name_to_line.getInfo(name, task);
180 }
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 112 of file ActionFactory.C.

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

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

◆ getTasksByAction()

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

Definition at line 155 of file ActionFactory.C.

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

156 {
157  std::set<std::string> tasks;
158 
159  std::pair<std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator,
160  std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator>
161  iters = _name_to_build_info.equal_range(action);
162  for (std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator it = iters.first;
163  it != iters.second;
164  ++it)
165  tasks.insert(it->second._task);
166 
167  return tasks;
168 }
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 92 of file ActionFactory.C.

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

93 {
100 
101  if (iter == _name_to_build_info.end())
102  mooseError(std::string("A '") + name + "' is not a registered Action\n\n");
103 
104  InputParameters params = iter->second._obj_pointer->buildParameters();
105  params.addPrivateParam("_moose_app", &_app);
107 
108  return params;
109 }
std::string name(const ElemQuality q)
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:299
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:195
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 101 of file ActionFactory.h.

Referenced by ActionWarehouse::hasTask().

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

◆ reg()

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

Definition at line 21 of file ActionFactory.C.

Referenced by Registry::registerActionsTo().

22 {
23  const std::string & name = obj->_classname;
24  const std::string & task = obj->_name;
25 
26  auto key = std::make_pair(name, task);
27  if (_current_objs.count(key) > 0)
28  return;
29  _current_objs.insert(key);
30 
31  BuildInfo build_info{obj, task};
32  _name_to_build_info.insert(std::make_pair(name, build_info));
33  _task_to_action_map.insert(std::make_pair(task, name));
34  _tasks.insert(task);
35  _name_to_line.addInfo(name, task, obj->_file, obj->_line);
36 }
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 118 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 126 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 134 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 120 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 122 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 123 of file ActionFactory.h.

Referenced by getActionsByTask(), and reg().

◆ _tasks

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

The registered tasks.

Definition at line 129 of file ActionFactory.h.

Referenced by isRegisteredTask(), and reg().


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