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 : InputParameters 24 7777520 : Action::validParams() 25 : { 26 7777520 : InputParameters params = Moose::Builder::validParams(); 27 : 28 7777520 : params.addPrivateParam<std::string>("_moose_docs_type", 29 : "action"); // the type of syntax for documentation system 30 7777520 : params.addPrivateParam<std::string>("_action_name"); // the name passed to ActionFactory::create 31 7777520 : params.addPrivateParam<std::string>("task"); 32 7777520 : params.addPrivateParam<std::string>("registered_identifier"); 33 7777520 : params.addPrivateParam<std::string>("action_type"); 34 7777520 : params.addPrivateParam<ActionWarehouse *>("awh", nullptr); 35 : 36 7777520 : params.addParam<std::vector<std::string>>( 37 : "control_tags", 38 : "Adds user-defined labels for accessing object parameters via control logic."); 39 7777520 : params.addParamNamesToGroup("control_tags", "Advanced"); 40 7777520 : params.registerBase("Action"); 41 7777520 : return params; 42 0 : } 43 : 44 3249108 : Action::Action(const InputParameters & parameters) 45 : : ParallelParamObject( 46 3249108 : parameters.get<std::string>("action_type"), 47 3249108 : parameters.get<std::string>("_action_name"), 48 6498216 : *parameters.getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor"), 49 : parameters), 50 : MeshMetaDataInterface( 51 6498216 : *parameters.getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor")), 52 : PerfGraphInterface( 53 : parameters.getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor") 54 : ->perfGraph(), 55 6498216 : "Action" + 56 3249108 : (parameters.get<std::string>("action_type") != "" 57 6498216 : ? std::string("::") + parameters.get<std::string>("action_type") 58 6498216 : : "") + 59 3249108 : (parameters.get<std::string>("_action_name") != "" 60 6498216 : ? std::string("::") + parameters.get<std::string>("_action_name") 61 3249108 : : "") + 62 7996609 : (parameters.isParamValid("task") && parameters.get<std::string>("task") != "" 63 7996609 : ? std::string("::") + parameters.get<std::string>("task") 64 : : "")), 65 6498216 : _registered_identifier(isParamValid("registered_identifier") 66 3249108 : ? getParam<std::string>("registered_identifier") 67 : : ""), 68 3249108 : _specific_task_name(_pars.isParamValid("task") ? getParam<std::string>("task") : ""), 69 3249108 : _awh(*getCheckedPointerParam<ActionWarehouse *>("awh")), 70 3249108 : _current_task(_awh.getCurrentTaskName()), 71 3249108 : _mesh(_awh.mesh()), 72 3249108 : _displaced_mesh(_awh.displacedMesh()), 73 3249108 : _problem(_awh.problemBase()), 74 29241972 : _act_timer(registerTimedSection("act", 4)) 75 : { 76 3249108 : if (_app.getActionFactory().currentlyConstructing() != ¶meters) 77 0 : mooseError("This object was not constructed using the ActionFactory, which is not supported."); 78 3249108 : } 79 : 80 : void 81 4824708 : Action::timedAct() 82 : { 83 4824708 : TIME_SECTION(_act_timer); 84 4824708 : act(); 85 4821837 : } 86 : 87 : bool 88 589586 : Action::addRelationshipManager( 89 : Moose::RelationshipManagerType /*input_rm_type*/, 90 : const InputParameters & moose_object_pars, 91 : std::string rm_name, 92 : Moose::RelationshipManagerType rm_type, 93 : Moose::RelationshipManagerInputParameterCallback rm_input_parameter_func, 94 : Moose::RMSystemType) 95 : { 96 : // These need unique names 97 : static unsigned int unique_object_id = 0; 98 : 99 1179172 : auto new_name = moose_object_pars.get<std::string>("_moose_base") + '_' + name() + '_' + rm_name + 100 1768758 : "_" + Moose::stringify(rm_type) + " " + std::to_string(unique_object_id); 101 : 102 589586 : auto rm_params = _factory.getValidParams(rm_name); 103 589586 : rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type; 104 : 105 589586 : rm_params.set<std::string>("for_whom") = name(); 106 : 107 : // If there is a callback for setting the RM parameters let's use it 108 589586 : if (rm_input_parameter_func) 109 338369 : rm_input_parameter_func(moose_object_pars, rm_params); 110 : 111 589586 : rm_params.set<MooseMesh *>("mesh") = _mesh.get(); 112 : 113 589586 : if (!rm_params.areAllRequiredParamsValid()) 114 0 : mooseError("Missing required parameters for RelationshipManager " + rm_name + " for object " + 115 0 : name()); 116 : 117 589586 : auto rm_obj = _factory.create<RelationshipManager>(rm_name, new_name, rm_params); 118 : 119 589582 : const bool added = _app.addRelationshipManager(rm_obj); 120 : 121 : // Delete the resources created on behalf of the RM if it ends up not being added to the App. 122 589582 : if (!added) 123 481000 : _factory.releaseSharedObjects(*rm_obj); 124 : else // we added it 125 108582 : unique_object_id++; 126 : 127 589582 : return added; 128 589582 : } 129 : 130 : void 131 6294760 : Action::addRelationshipManagers(Moose::RelationshipManagerType) 132 : { 133 6294760 : } 134 : 135 : bool 136 2917852 : Action::addRelationshipManagers(Moose::RelationshipManagerType input_rm_type, 137 : const InputParameters & moose_object_pars) 138 : { 139 2917852 : const auto & buildable_types = moose_object_pars.getBuildableRelationshipManagerTypes(); 140 : 141 2917852 : bool added = false; 142 : 143 3507434 : for (const auto & buildable_type : buildable_types) 144 : { 145 589586 : auto & rm_name = std::get<0>(buildable_type); 146 589586 : auto & rm_type = std::get<1>(buildable_type); 147 589586 : auto rm_input_parameter_func = std::get<2>(buildable_type); 148 : 149 589582 : added = addRelationshipManager( 150 589586 : input_rm_type, moose_object_pars, rm_name, rm_type, rm_input_parameter_func) || 151 : added; 152 589582 : } 153 : 154 2917848 : return added; 155 : } 156 : 157 : void 158 16141 : Action::associateWithParameter(const std::string & param_name, InputParameters & params) const 159 : { 160 16141 : associateWithParameter(parameters(), param_name, params); 161 16141 : } 162 : 163 : void 164 269992 : Action::associateWithParameter(const InputParameters & from_params, 165 : const std::string & param_name, 166 : InputParameters & params) const 167 : { 168 269992 : const auto to_hit_node = params.getHitNode(); 169 269992 : if (!to_hit_node || to_hit_node->isRoot()) 170 : { 171 269992 : if (const auto hit_node = from_params.getHitNode(param_name)) 172 125624 : params.setHitNode(*hit_node, {}); 173 144368 : else if (const auto hit_node = from_params.getHitNode()) 174 132246 : params.setHitNode(*hit_node, {}); 175 : } 176 269992 : }