Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Action.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "Action.h"
11 #include "ActionWarehouse.h"
12 #include "MooseApp.h"
13 #include "MooseTypes.h"
14 #include "MooseUtils.h" // remove when getBaseName is removed
15 #include "Builder.h"
16 #include "MooseMesh.h"
17 #include "FEProblemBase.h"
18 #include "DisplacedProblem.h"
19 #include "RelationshipManager.h"
21 #include "ActionFactory.h"
22 
25 {
27 
28  params.addPrivateParam<std::string>("_moose_docs_type",
29  "action"); // the type of syntax for documentation system
30  params.addPrivateParam<std::string>("_action_name"); // the name passed to ActionFactory::create
31  params.addPrivateParam<std::string>("task");
32  params.addPrivateParam<std::string>("registered_identifier");
33  params.addPrivateParam<std::string>("action_type");
34  params.addPrivateParam<ActionWarehouse *>("awh", nullptr);
35 
36  params.addParam<std::vector<std::string>>(
37  "control_tags",
38  "Adds user-defined labels for accessing object parameters via control logic.");
39  params.addParamNamesToGroup("control_tags", "Advanced");
40  params.registerBase("Action");
41  return params;
42 }
43 
44 Action::Action(const InputParameters & parameters)
46  parameters.get<std::string>("action_type"),
47  parameters.get<std::string>("_action_name"),
48  *parameters.getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor"),
49  parameters),
51  *parameters.getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor")),
53  parameters.getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor")
54  ->perfGraph(),
55  "Action" +
56  (parameters.get<std::string>("action_type") != ""
57  ? std::string("::") + parameters.get<std::string>("action_type")
58  : "") +
59  (parameters.get<std::string>("_action_name") != ""
60  ? std::string("::") + parameters.get<std::string>("_action_name")
61  : "") +
62  (parameters.isParamValid("task") && parameters.get<std::string>("task") != ""
63  ? std::string("::") + parameters.get<std::string>("task")
64  : "")),
65  _registered_identifier(isParamValid("registered_identifier")
66  ? getParam<std::string>("registered_identifier")
67  : ""),
68  _specific_task_name(_pars.isParamValid("task") ? getParam<std::string>("task") : ""),
69  _awh(*getCheckedPointerParam<ActionWarehouse *>("awh")),
70  _current_task(_awh.getCurrentTaskName()),
71  _mesh(_awh.mesh()),
72  _displaced_mesh(_awh.displacedMesh()),
73  _problem(_awh.problemBase()),
74  _act_timer(registerTimedSection("act", 4))
75 {
77  mooseError("This object was not constructed using the ActionFactory, which is not supported.");
78 }
79 
80 void
82 {
83  TIME_SECTION(_act_timer);
84  act();
85 }
86 
87 bool
89  Moose::RelationshipManagerType /*input_rm_type*/,
90  const InputParameters & moose_object_pars,
91  std::string rm_name,
95 {
96  // These need unique names
97  static unsigned int unique_object_id = 0;
98 
99  auto new_name = moose_object_pars.get<std::string>("_moose_base") + '_' + name() + '_' + rm_name +
100  "_" + Moose::stringify(rm_type) + " " + std::to_string(unique_object_id);
101 
102  auto rm_params = _factory.getValidParams(rm_name);
103  rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type;
104 
105  rm_params.set<std::string>("for_whom") = name();
106 
107  // If there is a callback for setting the RM parameters let's use it
108  if (rm_input_parameter_func)
109  rm_input_parameter_func(moose_object_pars, rm_params);
110 
111  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
112 
113  if (!rm_params.areAllRequiredParamsValid())
114  mooseError("Missing required parameters for RelationshipManager " + rm_name + " for object " +
115  name());
116 
117  auto rm_obj = _factory.create<RelationshipManager>(rm_name, new_name, rm_params);
118 
119  const bool added = _app.addRelationshipManager(rm_obj);
120 
121  // Delete the resources created on behalf of the RM if it ends up not being added to the App.
122  if (!added)
124  else // we added it
125  unique_object_id++;
126 
127  return added;
128 }
129 
130 void
132 {
133 }
134 
135 bool
137  const InputParameters & moose_object_pars)
138 {
139  const auto & buildable_types = moose_object_pars.getBuildableRelationshipManagerTypes();
140 
141  bool added = false;
142 
143  for (const auto & buildable_type : buildable_types)
144  {
145  auto & rm_name = std::get<0>(buildable_type);
146  auto & rm_type = std::get<1>(buildable_type);
147  auto rm_input_parameter_func = std::get<2>(buildable_type);
148 
149  added = addRelationshipManager(
150  input_rm_type, moose_object_pars, rm_name, rm_type, rm_input_parameter_func) ||
151  added;
152  }
153 
154  return added;
155 }
156 
157 void
158 Action::associateWithParameter(const std::string & param_name, InputParameters & params) const
159 {
160  associateWithParameter(parameters(), param_name, params);
161 }
162 
163 void
165  const std::string & param_name,
166  InputParameters & params) const
167 {
168  const auto to_hit_node = params.getHitNode();
169  if (!to_hit_node || to_hit_node->isRoot())
170  {
171  if (const auto hit_node = from_params.getHitNode(param_name))
172  params.setHitNode(*hit_node, {});
173  else if (const auto hit_node = from_params.getHitNode())
174  params.setHitNode(*hit_node, {});
175  }
176 }
const hit::Node * getHitNode(const std::string &param) const
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:963
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...
const std::vector< std::tuple< std::string, Moose::RelationshipManagerType, Moose::RelationshipManagerInputParameterCallback > > & getBuildableRelationshipManagerTypes() const
Returns the list of buildable (or required) RelationshipManager object types for this object...
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
Action(const InputParameters &parameters)
Definition: Action.C:44
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1122
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
Definition: Factory.C:111
MeshBase & mesh
static InputParameters validParams()
Parameters that are processed directly by the Parser and are valid anywhere in the input...
Definition: Builder.C:141
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition: Factory.C:68
Base class for MOOSE-based applications.
Definition: MooseApp.h:85
Storage for action instances.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool addRelationshipManager(Moose::RelationshipManagerType input_rm_type, const InputParameters &moose_object_pars, std::string rm_name, Moose::RelationshipManagerType rm_type, Moose::RelationshipManagerInputParameterCallback rm_input_parameter_func, Moose::RMSystemType sys_type=Moose::RMSystemType::NONE)
Method for adding a single relationship manager.
Definition: Action.C:88
ActionFactory & getActionFactory()
Retrieve a writable reference to the ActionFactory associated with this App.
Definition: MooseApp.h:439
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
Factory & _factory
The Factory associated with the MooseApp.
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition: MooseApp.C:2925
static InputParameters validParams()
Definition: Action.C:24
std::function< void(const InputParameters &, InputParameters &)> RelationshipManagerInputParameterCallback
The type for the callback to set RelationshipManager parameters.
Definition: MooseTypes.h:989
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
Interface for objects interacting with the PerfGraph.
void releaseSharedObjects(const MooseObject &moose_object, THREAD_ID tid=0)
Releases any shared resources created as a side effect of creating an object through the Factory::cre...
Definition: Factory.C:127
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:164
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
const InputParameters * currentlyConstructing() const
RMSystemType
Definition: MooseTypes.h:971
PerfID _act_timer
Timers.
Definition: Action.h:171
void timedAct()
The method called externally that causes the action to act()
Definition: Action.C:81
void associateWithParameter(const std::string &param_name, InputParameters &params) const
Associates the object&#39;s parameters params with the input location from this Action&#39;s parameter with t...
Definition: Action.C:158
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
bool addRelationshipManagers(Moose::RelationshipManagerType when_type, const InputParameters &moose_object_pars)
Method to add a relationship manager for the objects being added to the system.
Definition: Action.C:136
const InputParameters & parameters() const
Get the parameters of the object.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
virtual void act()=0
Method to add objects to the simulation or perform other setup tasks.
The Interface used to retrieve mesh meta data (attributes) set by the MeshGenerator system...
void setHitNode(const std::string &param, const hit::Node &node, const SetParamHitNodeKey)
Sets the hit node associated with the parameter param to node.
Base class shared by both Action and MooseObject.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...