https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 _connected_components(std::make_shared<std::set<ActionComponent *>>())
34{
35 _connected_components->insert(this);
36}
37
38void
40{
41 // This is inspired by the PhysicsBase definition of act(). We register components to the
42 // task they use, and the base class calls the appropriate virtual member functions
43 mooseDoOnce(checkRequiredTasks());
44
45 // These tasks are conceptually what we imagine a mostly-geometrical component should do
46 if (_current_task == "add_mesh_generator")
48 else if (_current_task == "add_positions")
50 else if (_current_task == "add_user_object")
52 else if (_current_task == "setup_component")
54 // If we define the Physics in a Physics block. See PhysicsComponentBase
55 else if (_current_task == "init_component_physics")
56 addPhysics();
57 // These tasks are there to match what the current combined Physics + Component do
58 // These combined components will likely still exist in the future, when it makes more
59 // sense to include the physics than to split it off into its own block
60 else if (_current_task == "add_variable")
62 // Useful for declaring materials on a component, which helps keep the input of local material
63 // properties on the component
64 else if (_current_task == "add_material")
66 else if (_current_task == "check_integrity")
68 else
69 // For a new task that isn't registered to ActionComponent in the framework
71}
72
73void
75{
76 const auto registered_tasks = _action_factory.getTasksByAction(type());
77
78 // Check for missing tasks
79 for (const auto & required_task : _required_tasks)
80 if (!registered_tasks.count(required_task))
82 "Task '" + required_task +
83 "' has been declared as required by a Component parent class of derived class '" +
84 type() +
85 "' but this task is not registered to the derived class. Registered tasks for "
86 "this Component are: " +
87 Moose::stringify(registered_tasks));
88}
89
90void
92{
93 // Already in the same group
95 return;
96
97 // Hold a reference to the other group before we re-point its members
98 auto other_group = component._connected_components;
99 _connected_components->insert(other_group->begin(), other_group->end());
100
101 // Every former member of the other group now shares this group's set
102 for (auto * member : *other_group)
103 member->_connected_components = _connected_components;
104}
Base class for components that are defined using an action.
virtual void actOnAdditionalTasks()
Use this if registering a new task to the derived ActionComponent.
virtual void addPhysics()
Used to add one or more Physics to be active on the component.
virtual void addMaterials()
Used to add materials or functor materials on a component.
void checkRequiredTasks() const
Checks that tasks marked required by parent classes are indeed registered to derived classes.
virtual void act() override final
Method to add objects to the simulation or perform other setup tasks.
void addConnectedComponent(ActionComponent &component)
Merge another component's group into this component's group.
virtual void addUserObjects()
std::set< std::string > _required_tasks
Manually keeps track of the tasks required by each component as tasks cannot be inherited.
virtual void addPositionsObject()
std::shared_ptr< std::set< ActionComponent * > > _connected_components
Group of components that share a common mesh after junctioning.
virtual void checkIntegrity()
Used for various checks notably:
virtual void setupComponent()
static InputParameters validParams()
virtual void addMeshGenerators()
ActionComponent(const InputParameters &params)
virtual void addSolverVariables()
Used to add variables on a component.
std::set< std::string > getTasksByAction(const std::string &action) const
Base class for actions.
Definition Action.h:38
static InputParameters validParams()
Definition Action.C:26
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition Action.h:172
Utility class to help check parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn't required or valid in the derived class...
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 addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
ActionFactory & _action_factory
Builds Actions.
void mooseWarning(Args &&... args) const
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:64
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...