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