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 9931724 : Action::validParams() 27 : { 28 9931724 : InputParameters params = ParallelParamObject::validParams(); 29 9931724 : params += Moose::Builder::validParams(); 30 : 31 9931724 : params.addPrivateParam<std::string>(unique_action_name_param); 32 39726896 : params.addPrivateParam<std::string>("_moose_docs_type", 33 : "action"); // the type of syntax for documentation system 34 19863448 : params.addPrivateParam<std::string>("task"); 35 9931724 : params.addPrivateParam<std::string>("registered_identifier"); 36 29795172 : params.addPrivateParam<ActionWarehouse *>("awh", nullptr); 37 : 38 39726896 : params.addParam<std::vector<std::string>>( 39 : "control_tags", 40 : "Adds user-defined labels for accessing object parameters via control logic."); 41 39726896 : params.addParamNamesToGroup("control_tags", "Advanced"); 42 9931724 : params.registerBase("Action"); 43 9931724 : return params; 44 0 : } 45 : 46 3345249 : Action::Action(const InputParameters & parameters) 47 : : ParallelParamObject(parameters), 48 : MeshMetaDataInterface(_app), 49 : PerfGraphInterface( 50 3345249 : _app.perfGraph(), 51 6690498 : "Action" + 52 10035747 : (parameters.getObjectType() != "" ? std::string("::") + parameters.getObjectType() 53 6690498 : : "") + 54 10035747 : (parameters.getObjectName() != "" ? std::string("::") + parameters.getObjectName() 55 6690498 : : "") + 56 8188258 : (parameters.isParamValid("task") && parameters.get<std::string>("task") != "" 57 13842220 : ? std::string("::") + parameters.get<std::string>("task") 58 : : "")), 59 : SolutionInvalidInterface(this, parameters), 60 13380996 : _registered_identifier(isParamValid("registered_identifier") 61 3345249 : ? getParam<std::string>("registered_identifier") 62 : : ""), 63 13380996 : _specific_task_name(_pars.isParamValid("task") ? getParam<std::string>("task") : ""), 64 13380996 : _awh(*getCheckedPointerParam<ActionWarehouse *>("awh")), 65 3345249 : _current_task(_awh.getCurrentTaskName()), 66 3345249 : _mesh(_awh.mesh()), 67 3345249 : _displaced_mesh(_awh.displacedMesh()), 68 3345249 : _problem(_awh.problemBase()), 69 20071494 : _act_timer(registerTimedSection("act", 4)) 70 : { 71 3345249 : if (_app.getActionFactory().currentlyConstructing() != ¶meters) 72 0 : mooseError("This object was not constructed using the ActionFactory, which is not supported."); 73 3345249 : } 74 : 75 : void 76 4910526 : Action::timedAct() 77 : { 78 4910526 : TIME_SECTION(_act_timer); 79 4910526 : act(); 80 4908237 : } 81 : 82 : bool 83 581483 : 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 1162966 : auto new_name = moose_object_pars.getBase() + '_' + name() + '_' + rm_name + "_" + 95 1744449 : Moose::stringify(rm_type) + " " + std::to_string(unique_object_id); 96 : 97 581483 : auto rm_params = _factory.getValidParams(rm_name); 98 1162966 : rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type; 99 : 100 1162966 : 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 581483 : if (rm_input_parameter_func) 104 337902 : rm_input_parameter_func(moose_object_pars, rm_params); 105 : 106 1162966 : rm_params.set<MooseMesh *>("mesh") = _mesh.get(); 107 : 108 581483 : if (!rm_params.areAllRequiredParamsValid()) 109 0 : mooseError("Missing required parameters for RelationshipManager " + rm_name + " for object " + 110 0 : name()); 111 : 112 581483 : auto rm_obj = _factory.create<RelationshipManager>(rm_name, new_name, rm_params); 113 : 114 581480 : 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 581480 : if (!added) 118 473797 : _factory.releaseSharedObjects(*rm_obj); 119 : else // we added it 120 107683 : unique_object_id++; 121 : 122 581480 : return added; 123 581480 : } 124 : 125 : void 126 6572754 : Action::addRelationshipManagers(Moose::RelationshipManagerType) 127 : { 128 6572754 : } 129 : 130 : bool 131 2925422 : Action::addRelationshipManagers(Moose::RelationshipManagerType input_rm_type, 132 : const InputParameters & moose_object_pars) 133 : { 134 2925422 : const auto & buildable_types = moose_object_pars.getBuildableRelationshipManagerTypes(); 135 : 136 2925422 : bool added = false; 137 : 138 3506902 : for (const auto & buildable_type : buildable_types) 139 : { 140 581483 : auto & rm_name = std::get<0>(buildable_type); 141 581483 : auto & rm_type = std::get<1>(buildable_type); 142 581483 : auto rm_input_parameter_func = std::get<2>(buildable_type); 143 : 144 581480 : added = addRelationshipManager( 145 581483 : input_rm_type, moose_object_pars, rm_name, rm_type, rm_input_parameter_func) || 146 : added; 147 581480 : } 148 : 149 2925419 : return added; 150 : } 151 : 152 : void 153 16780 : Action::associateWithParameter(const std::string & param_name, InputParameters & params) const 154 : { 155 16780 : associateWithParameter(parameters(), param_name, params); 156 16780 : } 157 : 158 : void 159 270433 : Action::associateWithParameter(const InputParameters & from_params, 160 : const std::string & param_name, 161 : InputParameters & params) const 162 : { 163 270433 : const auto to_hit_node = params.getHitNode(); 164 270433 : if (!to_hit_node || to_hit_node->isRoot()) 165 : { 166 270433 : if (const auto hit_node = from_params.getHitNode(param_name)) 167 126164 : params.setHitNode(*hit_node, {}); 168 144269 : else if (const auto hit_node = from_params.getHitNode()) 169 132236 : params.setHitNode(*hit_node, {}); 170 : } 171 270433 : }