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