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 : #include "Action.h" 11 : #include "ActionWarehouse.h" 12 : #include "MooseApp.h" 13 : #include "MooseTypes.h" 14 : #include "MooseUtils.h" // remove when getBaseName is removed 15 : #include "Builder.h" 16 : #include "MooseMesh.h" 17 : #include "FEProblemBase.h" 18 : #include "DisplacedProblem.h" 19 : #include "RelationshipManager.h" 20 : #include "InputParameterWarehouse.h" 21 : #include "ActionFactory.h" 22 : 23 : const std::string Action::unique_action_name_param = "_unique_action_name"; 24 : 25 : InputParameters 26 9816191 : Action::validParams() 27 : { 28 9816191 : InputParameters params = ParallelParamObject::validParams(); 29 9816191 : params += Moose::Builder::validParams(); 30 : 31 9816191 : params.addPrivateParam<std::string>(unique_action_name_param); 32 39264764 : params.addPrivateParam<std::string>("_moose_docs_type", 33 : "action"); // the type of syntax for documentation system 34 19632382 : params.addPrivateParam<std::string>("task"); 35 9816191 : params.addPrivateParam<std::string>("registered_identifier"); 36 29448573 : params.addPrivateParam<ActionWarehouse *>("awh", nullptr); 37 : 38 39264764 : params.addParam<std::vector<std::string>>( 39 : "control_tags", 40 : "Adds user-defined labels for accessing object parameters via control logic."); 41 39264764 : params.addParamNamesToGroup("control_tags", "Advanced"); 42 9816191 : params.registerBase("Action"); 43 9816191 : return params; 44 0 : } 45 : 46 3303907 : Action::Action(const InputParameters & parameters) 47 : : ParallelParamObject(parameters), 48 : MeshMetaDataInterface(_app), 49 : PerfGraphInterface( 50 3303907 : _app.perfGraph(), 51 6607814 : "Action" + 52 9911721 : (parameters.getObjectType() != "" ? std::string("::") + parameters.getObjectType() 53 6607814 : : "") + 54 9911721 : (parameters.getObjectName() != "" ? std::string("::") + parameters.getObjectName() 55 6607814 : : "") + 56 8086150 : (parameters.isParamValid("task") && parameters.get<std::string>("task") != "" 57 13671475 : ? std::string("::") + parameters.get<std::string>("task") 58 : : "")), 59 : SolutionInvalidInterface(this, parameters), 60 13215628 : _registered_identifier(isParamValid("registered_identifier") 61 3303907 : ? getParam<std::string>("registered_identifier") 62 : : ""), 63 13215628 : _specific_task_name(_pars.isParamValid("task") ? getParam<std::string>("task") : ""), 64 13215628 : _awh(*getCheckedPointerParam<ActionWarehouse *>("awh")), 65 3303907 : _current_task(_awh.getCurrentTaskName()), 66 3303907 : _mesh(_awh.mesh()), 67 3303907 : _displaced_mesh(_awh.displacedMesh()), 68 3303907 : _problem(_awh.problemBase()), 69 19823442 : _act_timer(registerTimedSection("act", 4)) 70 : { 71 3303907 : if (_app.getActionFactory().currentlyConstructing() != ¶meters) 72 0 : mooseError("This object was not constructed using the ActionFactory, which is not supported."); 73 3303907 : } 74 : 75 : void 76 4847962 : Action::timedAct() 77 : { 78 4847962 : TIME_SECTION(_act_timer); 79 4847962 : act(); 80 4845680 : } 81 : 82 : bool 83 576506 : Action::addRelationshipManager( 84 : Moose::RelationshipManagerType /*input_rm_type*/, 85 : const InputParameters & moose_object_pars, 86 : std::string rm_name, 87 : Moose::RelationshipManagerType rm_type, 88 : Moose::RelationshipManagerInputParameterCallback rm_input_parameter_func, 89 : Moose::RMSystemType) 90 : { 91 : // These need unique names 92 : static unsigned int unique_object_id = 0; 93 : 94 1153012 : auto new_name = moose_object_pars.getBase() + '_' + name() + '_' + rm_name + "_" + 95 1729518 : Moose::stringify(rm_type) + " " + std::to_string(unique_object_id); 96 : 97 576506 : auto rm_params = _factory.getValidParams(rm_name); 98 1153012 : rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type; 99 : 100 1153012 : rm_params.set<std::string>("for_whom") = name(); 101 : 102 : // If there is a callback for setting the RM parameters let's use it 103 576506 : if (rm_input_parameter_func) 104 333646 : rm_input_parameter_func(moose_object_pars, rm_params); 105 : 106 1153012 : rm_params.set<MooseMesh *>("mesh") = _mesh.get(); 107 : 108 576506 : if (!rm_params.areAllRequiredParamsValid()) 109 0 : mooseError("Missing required parameters for RelationshipManager " + rm_name + " for object " + 110 0 : name()); 111 : 112 576506 : auto rm_obj = _factory.create<RelationshipManager>(rm_name, new_name, rm_params); 113 : 114 576503 : const bool added = _app.addRelationshipManager(rm_obj); 115 : 116 : // Delete the resources created on behalf of the RM if it ends up not being added to the App. 117 576503 : if (!added) 118 469682 : _factory.releaseSharedObjects(*rm_obj); 119 : else // we added it 120 106821 : unique_object_id++; 121 : 122 576503 : return added; 123 576503 : } 124 : 125 : void 126 6490984 : Action::addRelationshipManagers(Moose::RelationshipManagerType) 127 : { 128 6490984 : } 129 : 130 : bool 131 2885065 : Action::addRelationshipManagers(Moose::RelationshipManagerType input_rm_type, 132 : const InputParameters & moose_object_pars) 133 : { 134 2885065 : const auto & buildable_types = moose_object_pars.getBuildableRelationshipManagerTypes(); 135 : 136 2885065 : bool added = false; 137 : 138 3461568 : for (const auto & buildable_type : buildable_types) 139 : { 140 576506 : auto & rm_name = std::get<0>(buildable_type); 141 576506 : auto & rm_type = std::get<1>(buildable_type); 142 576506 : auto rm_input_parameter_func = std::get<2>(buildable_type); 143 : 144 576503 : added = addRelationshipManager( 145 576506 : input_rm_type, moose_object_pars, rm_name, rm_type, rm_input_parameter_func) || 146 : added; 147 576503 : } 148 : 149 2885062 : return added; 150 : } 151 : 152 : void 153 16660 : Action::associateWithParameter(const std::string & param_name, InputParameters & params) const 154 : { 155 16660 : associateWithParameter(parameters(), param_name, params); 156 16660 : } 157 : 158 : void 159 267621 : Action::associateWithParameter(const InputParameters & from_params, 160 : const std::string & param_name, 161 : InputParameters & params) const 162 : { 163 267621 : const auto to_hit_node = params.getHitNode(); 164 267621 : if (!to_hit_node || to_hit_node->isRoot()) 165 : { 166 267621 : if (const auto hit_node = from_params.getHitNode(param_name)) 167 125080 : params.setHitNode(*hit_node, {}); 168 142541 : else if (const auto hit_node = from_params.getHitNode()) 169 130660 : params.setHitNode(*hit_node, {}); 170 : } 171 267621 : }