www.mooseframework.org
Action.h
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 #pragma once
11 
12 #include "InputParameters.h"
13 #include "ConsoleStreamInterface.h"
14 #include "Registry.h"
15 #include "PerfGraphInterface.h"
16 
17 #include <string>
18 #include <ostream>
19 
20 class Action;
21 class ActionWarehouse;
22 class ActionFactory;
23 class MooseMesh;
24 class FEProblemBase;
25 class Executioner;
26 class MooseApp;
27 class Factory;
28 
29 template <>
31 
36 {
37 public:
39 
40  virtual ~Action() {}
41 
45  void timedAct();
46 
47 protected:
59  const InputParameters & moose_object_pars);
60 
61 public:
72 
76  const std::string & name() const { return _name; }
77 
79 
82  std::string getBaseName() const;
83  std::string getShortName() const;
85 
86  const std::string & type() const { return _action_type; }
87 
89  const InputParameters & parameters() const { return _pars; }
90 
91  const std::string & specificTaskName() const { return _specific_task_name; }
92 
93  const std::set<std::string> & getAllTasks() const { return _all_tasks; }
94 
96 
101  template <typename T>
102  const T & getParam(const std::string & name) const;
104 
109  template <typename T>
110  T getCheckedPointerParam(const std::string & name, const std::string & error_string = "") const
111  {
112  return parameters().getCheckedPointerParam<T>(name, error_string);
113  }
114 
115  inline bool isParamValid(const std::string & name) const { return _pars.isParamValid(name); }
116 
117  void appendTask(const std::string & task) { _all_tasks.insert(task); }
118 
125  template <typename... Args>
126  [[noreturn]] void paramError(const std::string & param, Args... args) {
127  auto prefix = param + ": ";
128  if (!_pars.inputLocation(param).empty())
129  prefix = _pars.inputLocation(param) + ": (" + _pars.paramFullpath(param) + "):\n";
130  mooseError(prefix, args...);
131  }
132 
139  template <typename... Args>
140  void paramWarning(const std::string & param, Args... args)
141  {
142  auto prefix = param + ": ";
143  if (!_pars.inputLocation(param).empty())
144  prefix = _pars.inputLocation(param) + ": (" + _pars.paramFullpath(param) + "):\n";
145  mooseWarning(prefix, args...);
146  }
147 
155  template <typename... Args>
156  void paramInfo(const std::string & param, Args... args)
157  {
158  auto prefix = param + ": ";
159  if (!_pars.inputLocation(param).empty())
160  prefix = _pars.inputLocation(param) + ": (" + _pars.paramFullpath(param) + "):\n";
161  mooseInfo(prefix, args...);
162  }
163 
164 protected:
168  virtual void act() = 0;
169 
172 
173  // The registered syntax for this block if any
175 
177  std::string _name;
178 
179  // The type name of this Action instance
180  std::string _action_type;
181 
184 
187 
190 
197  std::string _specific_task_name;
198 
204  std::set<std::string> _all_tasks;
205 
208 
210  const std::string & _current_task;
211 
212  std::shared_ptr<MooseMesh> & _mesh;
213  std::shared_ptr<MooseMesh> & _displaced_mesh;
214 
216  std::shared_ptr<FEProblemBase> & _problem;
217 
220 };
221 
222 template <typename T>
223 const T &
224 Action::getParam(const std::string & name) const
225 {
226  return InputParameters::getParamHelper(name, _pars, static_cast<T *>(0));
227 }
228 
bool isParamValid(const std::string &name) const
Definition: Action.h:115
static const T & getParamHelper(const std::string &name, const InputParameters &pars, const T *the_type)
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:716
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition: Action.h:207
ActionFactory & _action_factory
Builds Actions.
Definition: Action.h:189
const std::string & name() const
The name of the action.
Definition: Action.h:76
Generic factory class for build all sorts of objects.
Definition: Factory.h:153
std::string getShortName() const
DEPRECATED METHODS.
Definition: Action.C:193
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller...
Definition: Action.h:110
Action(InputParameters parameters)
Definition: Action.C:50
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:219
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: Action.h:224
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller...
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
void paramWarning(const std::string &param, Args... args)
Emits a warning prefixed with the file and line number of the given param (from the input file) along...
Definition: Action.h:140
InputParameters & parameters()
Definition: Action.h:88
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Base class for actions.
Definition: Action.h:35
unsigned int PerfID
Definition: MooseTypes.h:163
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
std::string _specific_task_name
This member will only be populated if this Action instance is only designed to handle one task...
Definition: Action.h:197
std::string _action_type
Definition: Action.h:180
void mooseInfo(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
Definition: MooseError.h:252
std::string _registered_identifier
Definition: Action.h:174
InputParameters _pars
Input parameters for the action.
Definition: Action.h:171
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::set< std::string > _all_tasks
A list of all the tasks that this Action will satisfy.
Definition: Action.h:204
std::shared_ptr< MooseMesh > & _displaced_mesh
Definition: Action.h:213
const std::string & inputLocation(const std::string &param) const
Get/set a string representing the location in the input text the parameter originated from (i...
Specialized factory for generic Action System objects.
Definition: ActionFactory.h:64
An inteface for the _console for outputting to the Console object.
const std::set< std::string > & getAllTasks() const
Definition: Action.h:93
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
void paramInfo(const std::string &param, Args... args)
Emits an informational message prefixed with the file and line number of the given param (from the in...
Definition: Action.h:156
const std::string & _current_task
The current action (even though we have seperate instances for each action)
Definition: Action.h:210
Executioners are objects that do the actual work of solving your problem.
Definition: Executioner.h:32
Interface for objects that needs transient capabilities.
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:212
void paramError(const std::string &param, Args... args)
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: Action.h:126
PerfID _act_timer
Timers.
Definition: Action.h:219
void timedAct()
The method called externally that causes the action to act()
Definition: Action.C:86
const std::string & type() const
Definition: Action.h:86
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:216
virtual void act()=0
Method to add objects to the simulation or perform other setup tasks.
virtual ~Action()
Definition: Action.h:40
const std::string & specificTaskName() const
Definition: Action.h:91
MooseApp & _app
The MOOSE application this is associated with.
Definition: Action.h:183
void appendTask(const std::string &task)
Definition: Action.h:117
const InputParameters & parameters() const
Definition: Action.h:89
InputParameters validParams< Action >()
Definition: Action.C:22
const std::string & paramFullpath(const std::string &param) const
Get/set a string representing the full HIT parameter path from the input file (e.g.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.