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  SolutionInvalidInterface(this, parameters),
60  _registered_identifier(isParamValid("registered_identifier")
61  ? getParam<std::string>("registered_identifier")
62  : ""),
63  _specific_task_name(_pars.isParamValid("task") ? getParam<std::string>("task") : ""),
64  _awh(*getCheckedPointerParam<ActionWarehouse *>("awh")),
65  _current_task(_awh.getCurrentTaskName()),
66  _mesh(_awh.mesh()),
67  _displaced_mesh(_awh.displacedMesh()),
68  _problem(_awh.problemBase()),
69  _act_timer(registerTimedSection("act", 4))
70 {
72  mooseError("This object was not constructed using the ActionFactory, which is not supported.");
73 }
74 
75 void
77 {
78  TIME_SECTION(_act_timer);
79  act();
80 }
81 
82 bool
84  Moose::RelationshipManagerType /*input_rm_type*/,
85  const InputParameters & moose_object_pars,
86  std::string rm_name,
90 {
91  // These need unique names
92  static unsigned int unique_object_id = 0;
93 
94  auto new_name = moose_object_pars.getBase() + '_' + name() + '_' + rm_name + "_" +
95  Moose::stringify(rm_type) + " " + std::to_string(unique_object_id);
96 
97  auto rm_params = _factory.getValidParams(rm_name);
98  rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type;
99 
100  rm_params.set<std::string>("for_whom") = name();
101 
102  // If there is a callback for setting the RM parameters let's use it
103  if (rm_input_parameter_func)
104  rm_input_parameter_func(moose_object_pars, rm_params);
105 
106  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
107 
108  if (!rm_params.areAllRequiredParamsValid())
109  mooseError("Missing required parameters for RelationshipManager " + rm_name + " for object " +
110  name());
111 
112  auto rm_obj = _factory.create<RelationshipManager>(rm_name, new_name, rm_params);
113 
114  const bool added = _app.addRelationshipManager(rm_obj);
115 
116  // Delete the resources created on behalf of the RM if it ends up not being added to the App.
117  if (!added)
119  else // we added it
120  unique_object_id++;
121 
122  return added;
123 }
124 
125 void
127 {
128 }
129 
130 bool
132  const InputParameters & moose_object_pars)
133 {
134  const auto & buildable_types = moose_object_pars.getBuildableRelationshipManagerTypes();
135 
136  bool added = false;
137 
138  for (const auto & buildable_type : buildable_types)
139  {
140  auto & rm_name = std::get<0>(buildable_type);
141  auto & rm_type = std::get<1>(buildable_type);
142  auto rm_input_parameter_func = std::get<2>(buildable_type);
143 
144  added = addRelationshipManager(
145  input_rm_type, moose_object_pars, rm_name, rm_type, rm_input_parameter_func) ||
146  added;
147  }
148 
149  return added;
150 }
151 
152 void
153 Action::associateWithParameter(const std::string & param_name, InputParameters & params) const
154 {
155  associateWithParameter(parameters(), param_name, params);
156 }
157 
158 void
160  const std::string & param_name,
161  InputParameters & params) const
162 {
163  const auto to_hit_node = params.getHitNode();
164  if (!to_hit_node || to_hit_node->isRoot())
165  {
166  if (const auto hit_node = from_params.getHitNode(param_name))
167  params.setHitNode(*hit_node, {});
168  else if (const auto hit_node = from_params.getHitNode())
169  params.setHitNode(*hit_node, {});
170  }
171 }
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:131
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:1135
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:121
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:41
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:83
ActionFactory & getActionFactory()
Retrieve a writable reference to the ActionFactory associated with this App.
Definition: MooseApp.h:406
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...
An interface that allows the marking of invalid solutions during a solve.
static InputParameters validParams()
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition: MooseApp.C:3097
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:92
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:357
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:174
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:181
void timedAct()
The method called externally that causes the action to act()
Definition: Action.C:76
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:153
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:271
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:131
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...