Line data Source code
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 : #pragma once 11 : 12 : #include "ParallelParamObject.h" 13 : #include "InputParameters.h" 14 : #include "MeshMetaDataInterface.h" 15 : #include "Registry.h" 16 : #include "PerfGraphInterface.h" 17 : #include "MooseObjectParameterName.h" 18 : 19 : #include <string> 20 : #include <ostream> 21 : 22 : class ActionWarehouse; 23 : class ActionFactory; 24 : class MooseMesh; 25 : class FEProblemBase; 26 : class Executioner; 27 : class MooseApp; 28 : class Factory; 29 : 30 : /** 31 : * Base class for actions. 32 : */ 33 : class Action : public ParallelParamObject, public MeshMetaDataInterface, public PerfGraphInterface 34 : { 35 : public: 36 : /// The name of the parameter that contains the unique action name 37 : static const std::string unique_action_name_param; 38 : 39 : static InputParameters validParams(); 40 : 41 : Action(const InputParameters & parameters); 42 : 43 3068553 : virtual ~Action() = default; 44 : 45 : /** 46 : * The method called externally that causes the action to act() 47 : */ 48 : void timedAct(); 49 : 50 : private: 51 : /** 52 : * Method for adding a single relationship manager 53 : * @param input_rm_type What relationship manager type we are currently adding 54 : * @param moose_object_pars The parameters of the MooseObject that requested the RM 55 : * @param rm_name The class type of the RM, e.g. ElementSideNeighborLayers 56 : * @param rm_type The RelationshipManagerType, e.g. geometric, algebraic, coupling 57 : * @param rm_input_parameter_func The RM callback function, typically a lambda defined in the 58 : * requesting MooseObject's validParams function 59 : * @param sys_type A RMSystemType that can be used to limit the systems and consequent dof_maps 60 : * that the RM can be attached to 61 : * @return Whether a relationship manager was added 62 : */ 63 : bool 64 : addRelationshipManager(Moose::RelationshipManagerType input_rm_type, 65 : const InputParameters & moose_object_pars, 66 : std::string rm_name, 67 : Moose::RelationshipManagerType rm_type, 68 : Moose::RelationshipManagerInputParameterCallback rm_input_parameter_func, 69 : Moose::RMSystemType sys_type = Moose::RMSystemType::NONE); 70 : 71 : protected: 72 : /** 73 : * Method to add a relationship manager for the objects being added to the system. Relationship 74 : * managers have to be added relatively early. In many cases before the Action::act() method 75 : * is called. 76 : * @param when_type The parameter indicating the normal time for adding either Geometric or 77 : * Algebraic RelationshipManagers. It may not always be possible to add your 78 : * RelationshipManager as early as you'd like. In these cases, your DistributedMesh may 79 : * consume more memory during the problem setup. 80 : * @param moose_object_pars The MooseObject to inspect for RelationshipManagers to add 81 : * @return Whether a relationship manager was added 82 : */ 83 : bool addRelationshipManagers(Moose::RelationshipManagerType when_type, 84 : const InputParameters & moose_object_pars); 85 : 86 : public: 87 : /** 88 : * Method to add a relationship manager for the objects being added to the system. Relationship 89 : * managers have to be added relatively early. In many cases before the Action::act() method 90 : * is called. 91 : * @param when_type The parameter indicating the normal time for adding either Geometric or 92 : * Algebraic RelationshipManagers. It may not always be possible to add your 93 : * RelationshipManager as early as you'd like. In these cases, your DistributedMesh may 94 : * consume more memory during the problem setup. 95 : */ 96 : virtual void addRelationshipManagers(Moose::RelationshipManagerType when_type); 97 : 98 : /** 99 : * The unique name for accessing input parameters of this action in the InputParameterWarehouse 100 : */ 101 1451587 : MooseObjectName uniqueActionName() const { return uniqueName(); } 102 : 103 3780137 : const std::string & specificTaskName() const { return _specific_task_name; } 104 : 105 2812763 : const std::set<std::string> & getAllTasks() const { return _all_tasks; } 106 : 107 8040554 : void appendTask(const std::string & task) { _all_tasks.insert(task); } 108 : 109 : protected: 110 : /** 111 : * Method to add objects to the simulation or perform other setup tasks. 112 : */ 113 : virtual void act() = 0; 114 : 115 : /** 116 : * Associates the object's parameters \p params with the input location from this 117 : * Action's parameter with the name \p param_name, if one exists. 118 : * 119 : * For example, you have a parameter in this action of type bool with name "add_mesh". 120 : * You then add an action within this action that creates a mesh if this param is 121 : * true. If you call associateWithParameter("add_mesh", action_params) where 122 : * action_params are the parameters for the action, we then associate that action 123 : * with the "add_mesh" parameter. Therefore, the resulting created mesh will also 124 : * be associated with the "add_mesh" param and any errors that are non-parameter errors 125 : * (i.e., mooseError/mooseWarning) will have the line context of the "add_mesh" 126 : * parameter in this action. The same goes for any errors that are produce within 127 : * the created action. 128 : */ 129 : void associateWithParameter(const std::string & param_name, InputParameters & params) const; 130 : 131 : /** 132 : * The same as associateWithParameter() without \p from_params, but instead 133 : * allows you to associate this with another object's parameters instead of the 134 : * parameters from this action. 135 : * 136 : * An example here is when you want to associate the creation of an action with 137 : * an argument from the application. 138 : */ 139 : void associateWithParameter(const InputParameters & from_params, 140 : const std::string & param_name, 141 : InputParameters & params) const; 142 : 143 : // The registered syntax for this block if any 144 : std::string _registered_identifier; 145 : 146 : /** 147 : * This member will only be populated if this Action instance is only designed to 148 : * handle one task. This happens when an Action is registered with several pieces 149 : * of syntax in which case separate instances are built to handle the different 150 : * incoming parameter values. 151 : */ 152 : std::string _specific_task_name; 153 : 154 : /** 155 : * A list of all the tasks that this Action will satisfy. 156 : * Note: That this is _not_ populated at construction time. However, all tasks will be 157 : * added prior to act(). 158 : */ 159 : std::set<std::string> _all_tasks; 160 : 161 : /// Reference to ActionWarehouse where we store object build by actions 162 : ActionWarehouse & _awh; 163 : 164 : /// The current action (even though we have separate instances for each action) 165 : const std::string & _current_task; 166 : 167 : std::shared_ptr<MooseMesh> & _mesh; 168 : std::shared_ptr<MooseMesh> & _displaced_mesh; 169 : 170 : /// Convenience reference to a problem this action works on 171 : std::shared_ptr<FEProblemBase> & _problem; 172 : 173 : /// Timers 174 : PerfID _act_timer; 175 : 176 : // Base classes have the same name for that attribute, pick one 177 : using MooseBase::_app; 178 : };