LCOV - code coverage report
Current view: top level - src/actions - Action.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31653 (2d163b) with base 0cc44f Lines: 77 81 95.1 %
Date: 2025-11-04 20:38:02 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     8150191 : Action::validParams()
      27             : {
      28     8150191 :   InputParameters params = ParallelParamObject::validParams();
      29     8150191 :   params += Moose::Builder::validParams();
      30             : 
      31     8150191 :   params.addPrivateParam<std::string>(unique_action_name_param);
      32    32600764 :   params.addPrivateParam<std::string>("_moose_docs_type",
      33             :                                       "action"); // the type of syntax for documentation system
      34    16300382 :   params.addPrivateParam<std::string>("task");
      35     8150191 :   params.addPrivateParam<std::string>("registered_identifier");
      36    24450573 :   params.addPrivateParam<ActionWarehouse *>("awh", nullptr);
      37             : 
      38    32600764 :   params.addParam<std::vector<std::string>>(
      39             :       "control_tags",
      40             :       "Adds user-defined labels for accessing object parameters via control logic.");
      41    32600764 :   params.addParamNamesToGroup("control_tags", "Advanced");
      42     8150191 :   params.registerBase("Action");
      43     8150191 :   return params;
      44           0 : }
      45             : 
      46     3456425 : Action::Action(const InputParameters & parameters)
      47             :   : ParallelParamObject(parameters),
      48             :     MeshMetaDataInterface(_app),
      49             :     PerfGraphInterface(
      50     3456425 :         _app.perfGraph(),
      51     6912850 :         "Action" +
      52    10369275 :             (parameters.getObjectType() != "" ? std::string("::") + parameters.getObjectType()
      53     6912850 :                                               : "") +
      54    10369275 :             (parameters.getObjectName() != "" ? std::string("::") + parameters.getObjectName()
      55     6912850 :                                               : "") +
      56     8465400 :             (parameters.isParamValid("task") && parameters.get<std::string>("task") != ""
      57    14301356 :                  ? std::string("::") + parameters.get<std::string>("task")
      58             :                  : "")),
      59             :     SolutionInvalidInterface(this, parameters),
      60    13825700 :     _registered_identifier(isParamValid("registered_identifier")
      61     3456425 :                                ? getParam<std::string>("registered_identifier")
      62             :                                : ""),
      63    13825700 :     _specific_task_name(_pars.isParamValid("task") ? getParam<std::string>("task") : ""),
      64    13825700 :     _awh(*getCheckedPointerParam<ActionWarehouse *>("awh")),
      65     3456425 :     _current_task(_awh.getCurrentTaskName()),
      66     3456425 :     _mesh(_awh.mesh()),
      67     3456425 :     _displaced_mesh(_awh.displacedMesh()),
      68     3456425 :     _problem(_awh.problemBase()),
      69    20738550 :     _act_timer(registerTimedSection("act", 4))
      70             : {
      71     3456425 :   if (_app.getActionFactory().currentlyConstructing() != &parameters)
      72           0 :     mooseError("This object was not constructed using the ActionFactory, which is not supported.");
      73     3456425 : }
      74             : 
      75             : void
      76     5077299 : Action::timedAct()
      77             : {
      78     5077299 :   TIME_SECTION(_act_timer);
      79     5077299 :   act();
      80     5074386 : }
      81             : 
      82             : bool
      83      608100 : 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     1216200 :   auto new_name = moose_object_pars.getBase() + '_' + name() + '_' + rm_name + "_" +
      95     1824300 :                   Moose::stringify(rm_type) + " " + std::to_string(unique_object_id);
      96             : 
      97      608100 :   auto rm_params = _factory.getValidParams(rm_name);
      98     1216200 :   rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type;
      99             : 
     100     1216200 :   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      608100 :   if (rm_input_parameter_func)
     104      349546 :     rm_input_parameter_func(moose_object_pars, rm_params);
     105             : 
     106     1216200 :   rm_params.set<MooseMesh *>("mesh") = _mesh.get();
     107             : 
     108      608100 :   if (!rm_params.areAllRequiredParamsValid())
     109           0 :     mooseError("Missing required parameters for RelationshipManager " + rm_name + " for object " +
     110           0 :                name());
     111             : 
     112      608100 :   auto rm_obj = _factory.create<RelationshipManager>(rm_name, new_name, rm_params);
     113             : 
     114      608096 :   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      608096 :   if (!added)
     118      495600 :     _factory.releaseSharedObjects(*rm_obj);
     119             :   else // we added it
     120      112496 :     unique_object_id++;
     121             : 
     122      608096 :   return added;
     123      608096 : }
     124             : 
     125             : void
     126     6774441 : Action::addRelationshipManagers(Moose::RelationshipManagerType)
     127             : {
     128     6774441 : }
     129             : 
     130             : bool
     131     3026011 : Action::addRelationshipManagers(Moose::RelationshipManagerType input_rm_type,
     132             :                                 const InputParameters & moose_object_pars)
     133             : {
     134     3026011 :   const auto & buildable_types = moose_object_pars.getBuildableRelationshipManagerTypes();
     135             : 
     136     3026011 :   bool added = false;
     137             : 
     138     3634107 :   for (const auto & buildable_type : buildable_types)
     139             :   {
     140      608100 :     auto & rm_name = std::get<0>(buildable_type);
     141      608100 :     auto & rm_type = std::get<1>(buildable_type);
     142      608100 :     auto rm_input_parameter_func = std::get<2>(buildable_type);
     143             : 
     144      608096 :     added = addRelationshipManager(
     145      608100 :                 input_rm_type, moose_object_pars, rm_name, rm_type, rm_input_parameter_func) ||
     146             :             added;
     147      608096 :   }
     148             : 
     149     3026007 :   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      279329 : Action::associateWithParameter(const InputParameters & from_params,
     160             :                                const std::string & param_name,
     161             :                                InputParameters & params) const
     162             : {
     163      279329 :   const auto to_hit_node = params.getHitNode();
     164      279329 :   if (!to_hit_node || to_hit_node->isRoot())
     165             :   {
     166      279329 :     if (const auto hit_node = from_params.getHitNode(param_name))
     167      130283 :       params.setHitNode(*hit_node, {});
     168      149046 :     else if (const auto hit_node = from_params.getHitNode())
     169      136810 :       params.setHitNode(*hit_node, {});
     170             :   }
     171      279329 : }

Generated by: LCOV version 1.14