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 7244898 : Action::validParams() 25 : { 26 7244898 : InputParameters params = Moose::Builder::validParams(); 27 : 28 7244898 : params.addPrivateParam<std::string>("_moose_docs_type", 29 : "action"); // the type of syntax for documentation system 30 7244898 : params.addPrivateParam<std::string>("_action_name"); // the name passed to ActionFactory::create 31 7244898 : params.addPrivateParam<std::string>("task"); 32 7244898 : params.addPrivateParam<std::string>("registered_identifier"); 33 7244898 : params.addPrivateParam<std::string>("action_type"); 34 7244898 : params.addPrivateParam<ActionWarehouse *>("awh", nullptr); 35 : 36 7244898 : params.addParam<std::vector<std::string>>( 37 : "control_tags", 38 : "Adds user-defined labels for accessing object parameters via control logic."); 39 7244898 : params.addParamNamesToGroup("control_tags", "Advanced"); 40 7244898 : params.registerBase("Action"); 41 7244898 : return params; 42 0 : } 43 : 44 3008917 : Action::Action(const InputParameters & parameters) 45 : : ParallelParamObject( 46 3008917 : parameters.get<std::string>("action_type"), 47 3008917 : parameters.get<std::string>("_action_name"), 48 6017834 : *parameters.getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor"), 49 : parameters), 50 : MeshMetaDataInterface( 51 6017834 : *parameters.getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor")), 52 : PerfGraphInterface( 53 : parameters.getCheckedPointerParam<MooseApp *>("_moose_app", "In Action constructor") 54 : ->perfGraph(), 55 6017834 : "Action" + 56 3008917 : (parameters.get<std::string>("action_type") != "" 57 6017834 : ? std::string("::") + parameters.get<std::string>("action_type") 58 6017834 : : "") + 59 3008917 : (parameters.get<std::string>("_action_name") != "" 60 6017834 : ? std::string("::") + parameters.get<std::string>("_action_name") 61 3008917 : : "") + 62 7406194 : (parameters.isParamValid("task") && parameters.get<std::string>("task") != "" 63 7406194 : ? std::string("::") + parameters.get<std::string>("task") 64 : : "")), 65 6017834 : _registered_identifier(isParamValid("registered_identifier") 66 3008917 : ? getParam<std::string>("registered_identifier") 67 : : ""), 68 3008917 : _specific_task_name(_pars.isParamValid("task") ? getParam<std::string>("task") : ""), 69 3008917 : _awh(*getCheckedPointerParam<ActionWarehouse *>("awh")), 70 3008917 : _current_task(_awh.getCurrentTaskName()), 71 3008917 : _mesh(_awh.mesh()), 72 3008917 : _displaced_mesh(_awh.displacedMesh()), 73 3008917 : _problem(_awh.problemBase()), 74 27080253 : _act_timer(registerTimedSection("act", 4)) 75 : { 76 3008917 : if (_app.getActionFactory().currentlyConstructing() != ¶meters) 77 0 : mooseError("This object was not constructed using the ActionFactory, which is not supported."); 78 3008917 : } 79 : 80 : void 81 4408889 : Action::timedAct() 82 : { 83 4408889 : TIME_SECTION(_act_timer); 84 4408889 : act(); 85 4406026 : } 86 : 87 : bool 88 547580 : 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 1095160 : auto new_name = moose_object_pars.get<std::string>("_moose_base") + '_' + name() + '_' + rm_name + 100 1642740 : "_" + Moose::stringify(rm_type) + " " + std::to_string(unique_object_id); 101 : 102 547580 : auto rm_params = _factory.getValidParams(rm_name); 103 547580 : rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type; 104 : 105 547580 : 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 547580 : if (rm_input_parameter_func) 109 315305 : rm_input_parameter_func(moose_object_pars, rm_params); 110 : 111 547580 : rm_params.set<MooseMesh *>("mesh") = _mesh.get(); 112 : 113 547580 : if (!rm_params.areAllRequiredParamsValid()) 114 0 : mooseError("Missing required parameters for RelationshipManager " + rm_name + " for object " + 115 0 : name()); 116 : 117 547580 : auto rm_obj = _factory.create<RelationshipManager>(rm_name, new_name, rm_params); 118 : 119 547576 : 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 547576 : if (!added) 123 446850 : _factory.releaseSharedObjects(*rm_obj); 124 : else // we added it 125 100726 : unique_object_id++; 126 : 127 547576 : return added; 128 547576 : } 129 : 130 : void 131 5820297 : Action::addRelationshipManagers(Moose::RelationshipManagerType) 132 : { 133 5820297 : } 134 : 135 : bool 136 2700002 : Action::addRelationshipManagers(Moose::RelationshipManagerType input_rm_type, 137 : const InputParameters & moose_object_pars) 138 : { 139 2700002 : const auto & buildable_types = moose_object_pars.getBuildableRelationshipManagerTypes(); 140 : 141 2700002 : bool added = false; 142 : 143 3247578 : for (const auto & buildable_type : buildable_types) 144 : { 145 547580 : auto & rm_name = std::get<0>(buildable_type); 146 547580 : auto & rm_type = std::get<1>(buildable_type); 147 547580 : auto rm_input_parameter_func = std::get<2>(buildable_type); 148 : 149 547576 : added = addRelationshipManager( 150 547580 : input_rm_type, moose_object_pars, rm_name, rm_type, rm_input_parameter_func) || 151 : added; 152 547576 : } 153 : 154 2699998 : return added; 155 : } 156 : 157 : void 158 14831 : Action::associateWithParameter(const std::string & param_name, InputParameters & params) const 159 : { 160 14831 : associateWithParameter(parameters(), param_name, params); 161 14831 : } 162 : 163 : void 164 250289 : Action::associateWithParameter(const InputParameters & from_params, 165 : const std::string & param_name, 166 : InputParameters & params) const 167 : { 168 250289 : const auto to_hit_node = params.getHitNode(); 169 250289 : if (!to_hit_node || to_hit_node->isRoot()) 170 : { 171 250289 : if (const auto hit_node = from_params.getHitNode(param_name)) 172 116496 : params.setHitNode(*hit_node, {}); 173 133793 : else if (const auto hit_node = from_params.getHitNode()) 174 122624 : params.setHitNode(*hit_node, {}); 175 : } 176 250289 : }