https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
23const std::string Action::unique_action_name_param = "_unique_action_name";
24
27{
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
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
75void
77{
78 TIME_SECTION(_act_timer);
79
80 const auto parallel_verify = [libmesh_dbg_var(this)](const bool libmesh_dbg_var(before))
81 {
82#ifndef NDEBUG
83 const std::string value = this->typeAndName() + "_" + _current_task;
84 if (!comm().verify(value.size()) || !comm().verify(value))
85 mooseError("Parallel inconsistency found ",
86 before ? "before" : "after",
87 " executing task ",
89#endif
90 };
91
92 parallel_verify(true);
93
94 act();
95
96 parallel_verify(false);
97}
98
99bool
101 Moose::RelationshipManagerType /*input_rm_type*/,
102 const InputParameters & moose_object_pars,
103 std::string rm_name,
107{
108 // These need unique names
109 static unsigned int unique_object_id = 0;
110
111 auto new_name = moose_object_pars.getBase() + '_' + name() + '_' + rm_name + "_" +
112 Moose::stringify(rm_type) + " " + std::to_string(unique_object_id);
113
114 auto rm_params = _factory.getValidParams(rm_name);
115 rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type;
116
117 rm_params.set<std::string>("for_whom") = name();
118
119 // If there is a callback for setting the RM parameters let's use it
120 if (rm_input_parameter_func)
121 rm_input_parameter_func(moose_object_pars, rm_params);
122
123 rm_params.set<MooseMesh *>("mesh") = _mesh.get();
124
125 if (!rm_params.areAllRequiredParamsValid())
126 mooseError("Missing required parameters for RelationshipManager " + rm_name + " for object " +
127 name());
128
129 auto rm_obj = _factory.create<RelationshipManager>(rm_name, new_name, rm_params);
130
131 const bool added = _app.addRelationshipManager(rm_obj);
132
133 // Delete the resources created on behalf of the RM if it ends up not being added to the App.
134 if (!added)
136 else // we added it
137 unique_object_id++;
138
139 return added;
140}
141
142void
146
147bool
149 const InputParameters & moose_object_pars)
150{
151 const auto & buildable_types = moose_object_pars.getBuildableRelationshipManagerTypes();
152
153 bool added = false;
154
155 for (const auto & buildable_type : buildable_types)
156 {
157 auto & rm_name = std::get<0>(buildable_type);
158 auto & rm_type = std::get<1>(buildable_type);
159 auto rm_input_parameter_func = std::get<2>(buildable_type);
160
162 input_rm_type, moose_object_pars, rm_name, rm_type, rm_input_parameter_func) ||
163 added;
164 }
165
166 return added;
167}
168
169void
170Action::associateWithParameter(const std::string & param_name, InputParameters & params) const
171{
172 associateWithParameter(parameters(), param_name, params);
173}
174
175void
177 const std::string & param_name,
178 InputParameters & params) const
179{
180 const auto to_hit_node = params.getHitNode();
181 if (!to_hit_node || to_hit_node->isRoot())
182 {
183 if (const auto hit_node = from_params.getHitNode(param_name))
184 params.setHitNode(*hit_node, {});
185 else if (const auto hit_node = from_params.getHitNode())
186 params.setHitNode(*hit_node, {});
187 }
188}
const InputParameters * currentlyConstructing() const
Storage for action instances.
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:100
void associateWithParameter(const std::string &param_name, InputParameters &params) const
Associates the object's parameters params with the input location from this Action's parameter with t...
Definition Action.C:170
static const std::string unique_action_name_param
The name of the parameter that contains the unique action name.
Definition Action.h:41
std::shared_ptr< MooseMesh > & _mesh
Definition Action.h:174
Action(const InputParameters &parameters)
Definition Action.C:46
static InputParameters validParams()
Definition Action.C:26
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
void timedAct()
The method called externally that causes the action to act()
Definition Action.C:76
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:148
virtual void act()=0
Method to add objects to the simulation or perform other setup tasks.
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition Action.h:172
PerfID _act_timer
Timers.
Definition Action.h:181
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:142
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
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:156
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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...
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.
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 setHitNode(const std::string &param, const hit::Node &node, const SetParamHitNodeKey)
Sets the hit node associated with the parameter param to node.
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
const hit::Node * getHitNode(const std::string &param) const
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
const std::string & getBase() const
The Interface used to retrieve mesh meta data (attributes) set by the MeshGenerator system.
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition MooseApp.C:2991
ActionFactory & getActionFactory()
Retrieve a writable reference to the ActionFactory associated with this App.
Definition MooseApp.h:412
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
std::string typeAndName() const
Get the class's combined type and name; useful in error handling.
Definition MooseBase.C:57
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
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
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
static InputParameters validParams()
Parameters that are processed directly by the Parser and are valid anywhere in the input.
Definition Builder.C:121
Base class shared by both Action and MooseObject.
static InputParameters validParams()
Factory & _factory
The Factory associated with the MooseApp.
Interface for objects interacting with the PerfGraph.
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
An interface that allows the marking of invalid solutions during a solve.
const Parallel::Communicator & comm() const
MeshBase & mesh
std::function< void(const InputParameters &, InputParameters &)> RelationshipManagerInputParameterCallback
The type for the callback to set RelationshipManager parameters.
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:64
RelationshipManagerType
Main types of Relationship Managers.