https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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.
 
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.
 
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.
 
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.
 
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
 
std::set< std::string > _tasks
 The registered tasks.
 
std::vector< const InputParameters * > _currently_constructing
 The object's parameters that are currently being constructed (if any).
 

Detailed Description

Specialized factory for generic Action System objects.

Definition at line 48 of file ActionFactory.h.

Member Typedef Documentation

◆ const_iterator

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

Definition at line 82 of file ActionFactory.h.

◆ iterator

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

Typedef for registered Action iterator.

Definition at line 81 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

◆ ~ActionFactory()

ActionFactory::~ActionFactory ( )
virtual

Definition at line 19 of file ActionFactory.C.

19{}

Member Function Documentation

◆ app()

MooseApp & ActionFactory::app ( )
inline

Definition at line 55 of file ActionFactory.h.

55{ return _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}

◆ buildAction()

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

Definition at line 112 of file ActionFactory.h.

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

◆ 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.

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)
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}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
std::vector< const InputParameters * > _currently_constructing
The object's parameters that are currently being constructed (if any).
static const std::string unique_action_name_param
The name of the parameter that contains the unique action name.
Definition Action.h:41
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.
void setHitNode(const std::string &param, const hit::Node &node, const SetParamHitNodeKey)
Sets the hit node associated with the parameter param to node.
const Parser & parser() const
Definition MooseApp.C:1879
const hit::Node * getCurrentActionHitNode() const
Definition MooseApp.C:3062
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
Definition MooseApp.C:2867
static const std::string name_param
The name of the parameter that contains the object name.
Definition MooseBase.h:55
static const std::string type_param
The name of the parameter that contains the object type.
Definition MooseBase.h:53
static const std::string app_param
The name of the parameter that contains the MooseApp.
Definition MooseBase.h:59
hit::Node & getRoot()
Definition Parser.C:525
std::string shortName(const std::string &name)
Definition MooseUtils.C:623

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

◆ 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.

174{
175 return _currently_constructing.size() ? _currently_constructing.back() : nullptr;
176}

Referenced by Action::Action().

◆ end() [1/2]

ActionFactory::iterator ActionFactory::end ( )

Definition at line 138 of file ActionFactory.C.

139{
140 return _name_to_build_info.end();
141}

◆ 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}

◆ 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.

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

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

◆ 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.

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

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

◆ getTaskName()

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

Definition at line 114 of file ActionFactory.C.

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}

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

◆ getTasksByAction()

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

Definition at line 157 of file ActionFactory.C.

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}

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

◆ 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.

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::multimap< std::string, BuildInfo >::iterator iterator
Typedef for registered Action iterator.
Storage for action instances.
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...
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
Definition MooseApp.h:217

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

◆ isRegisteredTask()

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

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

Definition at line 100 of file ActionFactory.h.

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

Referenced by ActionWarehouse::hasTask().

◆ reg()

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

Definition at line 22 of file ActionFactory.C.

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::set< std::pair< std::string, std::string > > _current_objs
set<objectname, task> used to track if an object previously added is being added again
void addInfo(const std::string &key0, const std::string &file, int line)
Associate a key with file/line info.
std::string name(const ElemQuality q)

Referenced by Registry::registerActionsTo().

Member Data Documentation

◆ _app

MooseApp& ActionFactory::_app
private

Definition at line 117 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 125 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 133 of file ActionFactory.h.

Referenced by currentlyConstructing().

◆ _name_to_build_info

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

Definition at line 119 of file ActionFactory.h.

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

◆ _name_to_line

FileLineInfoMap ActionFactory::_name_to_line
private

Definition at line 121 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 122 of file ActionFactory.h.

Referenced by getActionsByTask(), and reg().

◆ _tasks

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

The registered tasks.

Definition at line 128 of file ActionFactory.h.

Referenced by isRegisteredTask(), and reg().


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