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