https://mooseframework.inl.gov
ActionComponent.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 // MOOSE includes
11 #include "ActionComponent.h"
12 #include "ActionFactory.h"
13 
16 {
18  params.addClassDescription("Base class for components that are defined using actions.");
19  params.addParam<bool>("verbose", false, "Whether the component setup should be verbose");
20 
21  // These parameters should not appear. Let's suppress them for now
22  params.suppressParameter<std::vector<std::string>>("active");
23  params.suppressParameter<std::vector<std::string>>("inactive");
24 
25  return params;
26 }
27 
29  : Action(params),
31  _dimension(libMesh::invalid_uint),
32  _verbose(getParam<bool>("verbose"))
33 {
34 }
35 
36 void
38 {
39  // This is inspired by the PhysicsBase definition of act(). We register components to the
40  // task they use, and the base class calls the appropriate virtual member functions
41  mooseDoOnce(checkRequiredTasks());
42 
43  // These tasks are conceptually what we imagine a mostly-geometrical component should do
44  if (_current_task == "add_mesh_generator")
46  else if (_current_task == "add_positions")
48  else if (_current_task == "add_user_object")
50  else if (_current_task == "setup_component")
52  // If we define the Physics in a Physics block. See PhysicsComponentBase
53  else if (_current_task == "init_component_physics")
54  addPhysics();
55  // These tasks are there to match what the current combined Physics + Component do
56  // These combined components will likely still exist in the future, when it makes more
57  // sense to include the physics than to split it off into its own block
58  else if (_current_task == "add_variable")
60  // Useful for declaring materials on a component, which helps keep the input of local material
61  // properties on the component
62  else if (_current_task == "add_material")
63  addMaterials();
64  else if (_current_task == "check_integrity")
66  else
67  // For a new task that isn't registered to ActionComponent in the framework
69 }
70 
71 void
73 {
74  const auto registered_tasks = _action_factory.getTasksByAction(type());
75 
76  // Check for missing tasks
77  for (const auto & required_task : _required_tasks)
78  if (!registered_tasks.count(required_task))
80  "Task '" + required_task +
81  "' has been declared as required by a Component parent class of derived class '" +
82  type() +
83  "' but this task is not registered to the derived class. Registered tasks for "
84  "this Component are: " +
85  Moose::stringify(registered_tasks));
86 }
virtual void checkIntegrity()
Used for various checks notably:
std::set< std::string > _required_tasks
Manually keeps track of the tasks required by each component as tasks cannot be inherited.
const unsigned int invalid_uint
std::set< std::string > getTasksByAction(const std::string &action) const
virtual void addSolverVariables()
Used to add variables on a component.
virtual void actOnAdditionalTasks()
Use this if registering a new task to the derived ActionComponent.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Base class for components that are defined using an action.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
static InputParameters validParams()
Base class for actions.
Definition: Action.h:33
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
void checkRequiredTasks() const
Checks that tasks marked required by parent classes are indeed registered to derived classes...
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn&#39;t required or valid in the derived class...
virtual void act() override final
Method to add objects to the simulation or perform other setup tasks.
Utility class to help check parameters.
static InputParameters validParams()
Definition: Action.C:24
virtual void setupComponent()
virtual void addMeshGenerators()
virtual void addMaterials()
Used to add materials or functor materials on a component.
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:51
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition: Action.h:162
ActionFactory & _action_factory
Builds Actions.
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
ActionComponent(const InputParameters &params)
virtual void addPositionsObject()
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
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 addPhysics()
Used to add one or more Physics to be active on the component.
virtual void addUserObjects()