LCOV - code coverage report
Current view: top level - src/actions - Action.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 1f9d31 Lines: 77 81 95.1 %
Date: 2025-09-02 20:01:20 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14