LCOV - code coverage report
Current view: top level - src/components - Shaft.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #32971 (54bef8) with base c6cf66 Lines: 54 68 79.4 %
Date: 2026-05-29 20:41:18 Functions: 7 7 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 "Shaft.h"
      11             : #include "ShaftConnectable.h"
      12             : #include "Component1DConnection.h"
      13             : 
      14             : registerMooseObject("ThermalHydraulicsApp", Shaft);
      15             : 
      16             : InputParameters
      17         264 : Shaft::validParams()
      18             : {
      19         264 :   InputParameters params = Component::validParams();
      20         528 :   params.addParam<Real>("scaling_factor_omega", 1.0, "Scaling factor for omega [-]");
      21         528 :   params.addParam<Real>("initial_speed", "Initial shaft speed");
      22         528 :   params.addParam<bool>("ad", true, "Use AD version or not");
      23         528 :   params.addRequiredParam<std::vector<std::string>>("connected_components",
      24             :                                                     "Names of the connected components");
      25         264 :   params.addClassDescription("Component that connects torque of turbomachinery components");
      26         264 :   return params;
      27           0 : }
      28             : 
      29         132 : Shaft::Shaft(const InputParameters & parameters)
      30             :   : Component(parameters),
      31         132 :     _scaling_factor_omega(getParam<Real>("scaling_factor_omega")),
      32         264 :     _omega_var_name(genName(name(), "omega")),
      33         396 :     _connected_components(getParam<std::vector<std::string>>("connected_components"))
      34             : {
      35         357 :   for (auto & comp_name : _connected_components)
      36         225 :     addDependency(comp_name);
      37         132 : }
      38             : 
      39             : void
      40         132 : Shaft::init()
      41             : {
      42             :   Component::init();
      43             : 
      44         357 :   for (const auto & comp_name : _connected_components)
      45             :   {
      46             :     if (hasComponentByName<Component>(comp_name))
      47             :     {
      48             :       const Component & c = getComponentByName<Component>(comp_name);
      49         225 :       const ShaftConnectable & scc = dynamic_cast<const ShaftConnectable &>(c);
      50         225 :       scc.setShaftName(name());
      51             :     }
      52             :   }
      53         132 : }
      54             : 
      55             : void
      56         126 : Shaft::check() const
      57             : {
      58         126 :   if (_connected_components.size() == 0)
      59          10 :     logError("No components are connected to the shaft.");
      60             : 
      61         246 :   bool ics_set = getTHMProblem().hasInitialConditionsFromFile() || isParamValid("initial_speed");
      62         126 :   if (!ics_set && !_app.isRestarting())
      63           4 :     logError("The `initial_speed` parameter is missing.");
      64         126 : }
      65             : 
      66             : void
      67         120 : Shaft::addVariables()
      68             : {
      69         120 :   getTHMProblem().addSimVariable(
      70         120 :       true, _omega_var_name, libMesh::FEType(FIRST, SCALAR), _scaling_factor_omega);
      71             : 
      72         240 :   if (isParamValid("initial_speed"))
      73         324 :     getTHMProblem().addConstantScalarIC(_omega_var_name, getParam<Real>("initial_speed"));
      74         120 : }
      75             : 
      76             : void
      77         120 : Shaft::addMooseObjects()
      78             : {
      79             :   std::vector<UserObjectName> uo_names;
      80             : 
      81         343 :   for (const auto & comp_name : _connected_components)
      82             :   {
      83             :     const Component & c = getComponentByName<Component>(comp_name);
      84         223 :     const ShaftConnectable & scc = dynamic_cast<const ShaftConnectable &>(c);
      85         446 :     uo_names.push_back(scc.getShaftConnectedUserObjectName());
      86             :   }
      87             : 
      88         240 :   if (getParam<bool>("ad"))
      89             :   {
      90             :     {
      91         120 :       std::string class_name = "ADShaftTimeDerivativeScalarKernel";
      92         120 :       InputParameters params = _factory.getValidParams(class_name);
      93         240 :       params.set<NonlinearVariableName>("variable") = _omega_var_name;
      94         120 :       params.set<std::vector<UserObjectName>>("uo_names") = {uo_names};
      95         240 :       getTHMProblem().addScalarKernel(class_name, genName(name(), "td"), params);
      96         120 :     }
      97             : 
      98         343 :     for (std::size_t i = 0; i < uo_names.size(); i++)
      99             :     {
     100         223 :       std::string class_name = "ADShaftComponentTorqueScalarKernel";
     101         223 :       InputParameters params = _factory.getValidParams(class_name);
     102         446 :       params.set<NonlinearVariableName>("variable") = _omega_var_name;
     103         223 :       params.set<UserObjectName>("shaft_connected_component_uo") = uo_names[i];
     104         223 :       getTHMProblem().addScalarKernel(class_name, genName(name(), i, "shaft_speed"), params);
     105         223 :     }
     106             :   }
     107             :   else
     108             :   {
     109             :     {
     110           0 :       std::string class_name = "ShaftTimeDerivativeScalarKernel";
     111           0 :       InputParameters params = _factory.getValidParams(class_name);
     112           0 :       params.set<NonlinearVariableName>("variable") = _omega_var_name;
     113           0 :       params.set<std::vector<UserObjectName>>("uo_names") = {uo_names};
     114           0 :       getTHMProblem().addScalarKernel(class_name, genName(name(), "td"), params);
     115           0 :     }
     116             : 
     117           0 :     for (std::size_t i = 0; i < uo_names.size(); i++)
     118             :     {
     119           0 :       std::string class_name = "ShaftComponentTorqueScalarKernel";
     120           0 :       InputParameters params = _factory.getValidParams(class_name);
     121           0 :       params.set<NonlinearVariableName>("variable") = _omega_var_name;
     122           0 :       params.set<UserObjectName>("shaft_connected_component_uo") = uo_names[i];
     123           0 :       getTHMProblem().addScalarKernel(class_name, genName(name(), i, "shaft_speed"), params);
     124           0 :     }
     125             :   }
     126         120 : }
     127             : 
     128             : VariableName
     129         223 : Shaft::getOmegaVariableName() const
     130             : {
     131         223 :   return _omega_var_name;
     132             : }

Generated by: LCOV version 1.14