https://mooseframework.inl.gov
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 
23 const std::string Action::unique_action_name_param = "_unique_action_name";
24 
27 {
29  params += Moose::Builder::validParams();
30 
31  params.addPrivateParam<std::string>(unique_action_name_param);
32  params.addPrivateParam<std::string>("_moose_docs_type",
33  "action"); // the type of syntax for documentation system
34  params.addPrivateParam<std::string>("task");
35  params.addPrivateParam<std::string>("registered_identifier");
36  params.addPrivateParam<ActionWarehouse *>("awh", nullptr);
37 
38  params.addParam<std::vector<std::string>>(
39  "control_tags",
40  "Adds user-defined labels for accessing object parameters via control logic.");
41  params.addParamNamesToGroup("control_tags", "Advanced");
42  params.registerBase("Action");
43  return params;
44 }
45 
46 Action::Action(const InputParameters & parameters)
47  : ParallelParamObject(parameters),
50  _app.perfGraph(),
51  "Action" +
52  (parameters.getObjectType() != "" ? std::string("::") + parameters.getObjectType()
53  : "") +
54  (parameters.getObjectName() != "" ? std::string("::") + parameters.getObjectName()
55  : "") +
56  (parameters.isParamValid("task") && parameters.get<std::string>("task") != ""
57  ? std::string("::") + parameters.get<std::string>("task")
58  : "")),
59  _registered_identifier(isParamValid("registered_identifier")
60  ? getParam<std::string>("registered_identifier")
61  : ""),
62  _specific_task_name(_pars.isParamValid("task") ? getParam<std::string>("task") : ""),
63  _awh(*getCheckedPointerParam<ActionWarehouse *>("awh")),
64  _current_task(_awh.getCurrentTaskName()),
65  _mesh(_awh.mesh()),
66  _displaced_mesh(_awh.displacedMesh()),
67  _problem(_awh.problemBase()),
68  _act_timer(registerTimedSection("act", 4))
69 {
71  mooseError("This object was not constructed using the ActionFactory, which is not supported.");
72 }
73 
74 void
76 {
77  TIME_SECTION(_act_timer);
78  act();
79 }
80 
81 bool
83  Moose::RelationshipManagerType /*input_rm_type*/,
84  const InputParameters & moose_object_pars,
85  std::string rm_name,
89 {
90  // These need unique names
91  static unsigned int unique_object_id = 0;
92 
93  auto new_name = moose_object_pars.getBase() + '_' + name() + '_' + rm_name + "_" +
94  Moose::stringify(rm_type) + " " + std::to_string(unique_object_id);
95 
96  auto rm_params = _factory.getValidParams(rm_name);
97  rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type;
98 
99  rm_params.set<std::string>("for_whom") = name();
100 
101  // If there is a callback for setting the RM parameters let's use it
102  if (rm_input_parameter_func)
103  rm_input_parameter_func(moose_object_pars, rm_params);
104 
105  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
106 
107  if (!rm_params.areAllRequiredParamsValid())
108  mooseError("Missing required parameters for RelationshipManager " + rm_name + " for object " +
109  name());
110 
111  auto rm_obj = _factory.create<RelationshipManager>(rm_name, new_name, rm_params);
112 
113  const bool added = _app.addRelationshipManager(rm_obj);
114 
115  // Delete the resources created on behalf of the RM if it ends up not being added to the App.
116  if (!added)
118  else // we added it
119  unique_object_id++;
120 
121  return added;
122 }
123 
124 void
126 {
127 }
128 
129 bool
131  const InputParameters & moose_object_pars)
132 {
133  const auto & buildable_types = moose_object_pars.getBuildableRelationshipManagerTypes();
134 
135  bool added = false;
136 
137  for (const auto & buildable_type : buildable_types)
138  {
139  auto & rm_name = std::get<0>(buildable_type);
140  auto & rm_type = std::get<1>(buildable_type);
141  auto rm_input_parameter_func = std::get<2>(buildable_type);
142 
143  added = addRelationshipManager(
144  input_rm_type, moose_object_pars, rm_name, rm_type, rm_input_parameter_func) ||
145  added;
146  }
147 
148  return added;
149 }
150 
151 void
152 Action::associateWithParameter(const std::string & param_name, InputParameters & params) const
153 {
154  associateWithParameter(parameters(), param_name, params);
155 }
156 
157 void
159  const std::string & param_name,
160  InputParameters & params) const
161 {
162  const auto to_hit_node = params.getHitNode();
163  if (!to_hit_node || to_hit_node->isRoot())
164  {
165  if (const auto hit_node = from_params.getHitNode(param_name))
166  params.setHitNode(*hit_node, {});
167  else if (const auto hit_node = from_params.getHitNode())
168  params.setHitNode(*hit_node, {});
169  }
170 }
const hit::Node * getHitNode(const std::string &param) const
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:964
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...
Factory & _factory
The Factory associated with the MooseApp.
Action(const InputParameters &parameters)
Definition: Action.C:46
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:127
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:1155
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
Storage for action instances.
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
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:82
ActionFactory & getActionFactory()
Retrieve a writable reference to the ActionFactory associated with this App.
Definition: MooseApp.h:399
const std::string & getBase() const
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
static InputParameters validParams()
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition: MooseApp.C:3024
static InputParameters validParams()
Definition: Action.C:26
std::function< void(const InputParameters &, InputParameters &)> RelationshipManagerInputParameterCallback
The type for the callback to set RelationshipManager parameters.
Definition: MooseTypes.h:990
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:353
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:167
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
const InputParameters * currentlyConstructing() const
RMSystemType
Definition: MooseTypes.h:972
PerfID _act_timer
Timers.
Definition: Action.h:174
void timedAct()
The method called externally that causes the action to act()
Definition: Action.C:75
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:152
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
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:130
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...