www.mooseframework.org
Action.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "MooseMesh.h"
16 #include "FEProblemBase.h"
17 #include "DisplacedProblem.h"
18 #include "RelationshipManager.h"
19 
20 template <>
23 {
25 
30  params.addParam<std::vector<std::string>>(
31  "active",
32  std::vector<std::string>({"__all__"}),
33  "If specified only the blocks named will be visited and made active");
34  params.addParam<std::vector<std::string>>(
35  "inactive",
36  std::vector<std::string>(),
37  "If specified blocks matching these identifiers will be skipped.");
38 
39  params.addPrivateParam<std::string>("_moose_docs_type",
40  "action"); // the type of syntax for documentation system
41  params.addPrivateParam<std::string>("_action_name"); // the name passed to ActionFactory::create
42  params.addPrivateParam<std::string>("task");
43  params.addPrivateParam<std::string>("registered_identifier");
44  params.addPrivateParam<std::string>("action_type");
45  params.addPrivateParam<ActionWarehouse *>("awh", NULL);
46 
47  return params;
48 }
49 
52  *parameters.getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor")),
54  parameters.getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor")
55  ->perfGraph(),
56  "Action" +
57  (parameters.get<std::string>("action_type") != ""
58  ? std::string("::") + parameters.get<std::string>("action_type")
59  : "") +
60  (parameters.get<std::string>("_action_name") != ""
61  ? std::string("::") + parameters.get<std::string>("_action_name")
62  : "") +
63  (parameters.isParamValid("task") && parameters.get<std::string>("task") != ""
64  ? std::string("::") + parameters.get<std::string>("task")
65  : "")),
66  _pars(parameters),
67  _registered_identifier(isParamValid("registered_identifier")
68  ? getParam<std::string>("registered_identifier")
69  : ""),
70  _name(getParam<std::string>("_action_name")),
71  _action_type(getParam<std::string>("action_type")),
72  _app(*getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor")),
73  _factory(_app.getFactory()),
74  _action_factory(_app.getActionFactory()),
75  _specific_task_name(_pars.isParamValid("task") ? getParam<std::string>("task") : ""),
76  _awh(*getCheckedPointerParam<ActionWarehouse *>("awh")),
77  _current_task(_awh.getCurrentTaskName()),
78  _mesh(_awh.mesh()),
79  _displaced_mesh(_awh.displacedMesh()),
80  _problem(_awh.problemBase()),
81  _act_timer(registerTimedSection("act", 4))
82 {
83 }
84 
85 void
87 {
88  TIME_SECTION(_act_timer);
89  act();
90 }
91 
93 
94 void
96  const InputParameters & moose_object_pars)
97 {
98  const auto & buildable_types = moose_object_pars.getBuildableRelationshipManagerTypes();
99 
100  // These need unique names
101  static unsigned int unique_object_id = 0;
102 
103  for (const auto & buildable_type : buildable_types)
104  {
105  unique_object_id++;
106 
107  auto & rm_name = std::get<0>(buildable_type);
108  auto & rm_type = std::get<1>(buildable_type);
109  auto rm_input_parameter_func = std::get<2>(buildable_type);
110 
111  auto new_name = moose_object_pars.get<std::string>("_moose_base") + '_' + name() + '_' +
112  rm_name + "_" + Moose::stringify(rm_type) + " " +
113  std::to_string(unique_object_id);
114 
115  auto rm_params = _factory.getValidParams(rm_name);
116  rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type;
117  rm_params.set<std::string>("for_whom") = name();
118 
119  // Figure out if we shouldn't be adding this one yet
120  if (((rm_type & input_rm_type) != input_rm_type) // Does this RM not have the type passed in?
121 
122  || // Or are we adding Geometric but this one needs to be delayed
123 
124  (((input_rm_type & Moose::RelationshipManagerType::GEOMETRIC) ==
128  !rm_params.template get<bool>("attach_geometric_early"))
129 
130  || // Or is this an Algebraic and Geometric one that we already added earlier?
131 
132  (((input_rm_type & Moose::RelationshipManagerType::ALGEBRAIC) ==
136  rm_params.template get<bool>("attach_geometric_early")))
137  continue;
138 
139  // If there is a callback for setting the RM parameters let's use it
140  if (rm_input_parameter_func)
141  rm_input_parameter_func(moose_object_pars, rm_params);
142 
143  // If we're doing geometric but we can't build it early - then let's not build it yet
144  // (It will get built when we do algebraic)
145  if ((input_rm_type & Moose::RelationshipManagerType::GEOMETRIC) ==
147  !rm_params.get<bool>("attach_geometric_early"))
148  {
149  // We also need to tell the mesh not to delete remote elements yet
150  // Note this will get reset in AddRelationshipManager::act() when attaching Algebraic
151  _mesh->getMesh().allow_remote_element_removal(false);
152 
153  if (_problem->getDisplacedProblem())
154  _problem->getDisplacedProblem()->mesh().getMesh().allow_remote_element_removal(false);
155 
156  // Keep looking for more RMs
157  continue;
158  }
159  // Ok the above block may have told the mesh not to allow remote element removal during the
160  // initial MeshBase::prepare_for_use, which is called after attaching geometric ghosting
161  // functors. If we did tell the mesh not to allow remote element removal **and** we're using a
162  // DistributedMesh, then we need to tell the mesh to allow remote element removal and ensure
163  // that the mesh will delete its remote elements after the EquationSystems init
164  else if (input_rm_type == Moose::RelationshipManagerType::ALGEBRAIC &&
165  (rm_params.get<Moose::RelationshipManagerType>("rm_type") &
168  !rm_params.get<bool>("attach_geometric_early") && _mesh->isDistributedMesh())
169  {
170  _mesh->needsRemoteElemDeletion(true);
171  if (_displaced_mesh)
172  _displaced_mesh->needsRemoteElemDeletion(true);
173  }
174 
175  rm_params.set<MooseMesh *>("mesh") = _mesh.get();
176 
177  if (rm_params.areAllRequiredParamsValid())
178  {
179  auto rm_obj = _factory.create<RelationshipManager>(rm_name, new_name, rm_params);
180 
181  // Delete the resources created on behalf of the RM if it ends up not being added to the App.
182  if (!_app.addRelationshipManager(rm_obj))
184  }
185  else
186  mooseError("Missing required parameters for RelationshipManager " + rm_name + " for object " +
187  name());
188  }
189 }
190 
192 std::string
194 {
195  mooseDeprecated("getShortName() is deprecated.");
197 }
198 
199 std::string
201 {
202  mooseDeprecated("getBaseName() is deprecated.");
203  return MooseUtils::baseName(_name);
204 }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:87
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:716
const std::string & name() const
The name of the action.
Definition: Action.h:76
std::string getShortName() const
DEPRECATED METHODS.
Definition: Action.C:193
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...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: Factory.C:67
Action(InputParameters parameters)
Definition: Action.C:50
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Base class for MOOSE-based applications.
Definition: MooseApp.h:59
Storage for action instances.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Factory & _factory
The Factory associated with the MooseApp.
Definition: Action.h:186
InputParameters emptyInputParameters()
std::string shortName(const std::string &name)
Function for stripping name after the file / in parser block.
Definition: MooseUtils.C:363
std::string getBaseName() const
Deprecated name methods, use name()
Definition: Action.C:200
std::string _name
The name of the action.
Definition: Action.h:177
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
Definition: MooseApp.C:1692
void 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:95
std::shared_ptr< MooseMesh > & _displaced_mesh
Definition: Action.h:213
An inteface for the _console for outputting to the Console object.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:236
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:60
Interface for objects that needs transient capabilities.
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:166
std::string baseName(const std::string &name)
Function for string the information before the final / in a parser block.
Definition: MooseUtils.C:369
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:212
InputParameters validParams< Action >()
Definition: Action.C:22
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
PerfID _act_timer
Timers.
Definition: Action.h:219
void timedAct()
The method called externally that causes the action to act()
Definition: Action.C:86
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:216
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option 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.
MooseApp & _app
The MOOSE application this is associated with.
Definition: Action.h:183