LCOV - code coverage report
Current view: top level - src/components - ShaftConnectedTurbine1Phase.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #32971 (54bef8) with base c6cf66 Lines: 129 130 99.2 %
Date: 2026-05-29 20:41:18 Functions: 6 6 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 "ShaftConnectedTurbine1Phase.h"
      11             : #include "FlowModelSinglePhase.h"
      12             : #include "Numerics.h"
      13             : #include "Shaft.h"
      14             : #include "MooseVariableScalar.h"
      15             : #include "Assembly.h"
      16             : #include "ScalarKernel.h"
      17             : 
      18             : registerMooseObject("ThermalHydraulicsApp", ShaftConnectedTurbine1Phase);
      19             : 
      20             : InputParameters
      21          44 : ShaftConnectedTurbine1Phase::validParams()
      22             : {
      23          44 :   InputParameters params = VolumeJunction1Phase::validParams();
      24          44 :   params += ShaftConnectable::validParams();
      25          44 :   params.makeParamRequired<Real>("A_ref");
      26          88 :   params.addRequiredParam<BoundaryName>("inlet", "Turbine inlet");
      27          88 :   params.addRequiredParam<BoundaryName>("outlet", "Turbine outlet");
      28          44 :   params.set<std::vector<BoundaryName>>("connections") = {};
      29          44 :   params.suppressParameter<std::vector<BoundaryName>>("connections");
      30          88 :   params.addRequiredParam<Real>("omega_rated", "Rated turbine speed [rad/s]");
      31          88 :   params.addRequiredParam<Real>("D_wheel",
      32             :                                 "Any physical dimension of the turbine as a measure of the "
      33             :                                 "turbine's size, usually the rotor diameter [m]");
      34          88 :   params.addRequiredParam<Real>("speed_cr_fr", "Turbine speed threshold for friction [-]");
      35          88 :   params.addRequiredParam<Real>("tau_fr_const", "Turbine friction constant [N-m]");
      36          88 :   params.addRequiredParam<std::vector<Real>>("tau_fr_coeff", "Turbine friction coefficients [N-m]");
      37          88 :   params.addRequiredParam<Real>("speed_cr_I", "Turbine speed threshold for inertia [-]");
      38          88 :   params.addRequiredParam<Real>("inertia_const", "Turbine inertia constant [kg-m^2]");
      39          88 :   params.addRequiredParam<std::vector<Real>>("inertia_coeff",
      40             :                                              "Turbine inertia coefficients [kg-m^2]");
      41          88 :   params.addRequiredParam<FunctionName>("head_coefficient",
      42             :                                         "Head coefficient vs flow coefficient function [-]");
      43          88 :   params.addRequiredParam<FunctionName>("power_coefficient",
      44             :                                         "Power coefficient vs flow coefficient function [-]");
      45             : 
      46          44 :   params.addClassDescription(
      47             :       "1-phase turbine that must be connected to a Shaft component. Turbine speed "
      48             :       "is controlled by the connected shaft; Driving torque and delta_p are "
      49             :       "computed by user input functions of inlet flow rate (flow coefficient aux variable) and "
      50             :       "shaft speed");
      51             : 
      52          44 :   return params;
      53           0 : }
      54             : 
      55          22 : ShaftConnectedTurbine1Phase::ShaftConnectedTurbine1Phase(const InputParameters & parameters)
      56             :   : VolumeJunction1Phase(parameters),
      57             :     ShaftConnectable(this),
      58          22 :     _inlet(getParam<BoundaryName>("inlet")),
      59          44 :     _outlet(getParam<BoundaryName>("outlet")),
      60          44 :     _omega_rated(getParam<Real>("omega_rated")),
      61          44 :     _D_wheel(getParam<Real>("D_wheel")),
      62          44 :     _speed_cr_fr(getParam<Real>("speed_cr_fr")),
      63          44 :     _tau_fr_const(getParam<Real>("tau_fr_const")),
      64          44 :     _tau_fr_coeff(getParam<std::vector<Real>>("tau_fr_coeff")),
      65          44 :     _speed_cr_I(getParam<Real>("speed_cr_I")),
      66          44 :     _inertia_const(getParam<Real>("inertia_const")),
      67          44 :     _inertia_coeff(getParam<std::vector<Real>>("inertia_coeff")),
      68          44 :     _head_coefficient(getParam<FunctionName>("head_coefficient")),
      69          44 :     _power_coefficient(getParam<FunctionName>("power_coefficient")),
      70          22 :     _delta_p_var_name(junctionVariableName("delta_p")),
      71          22 :     _power_var_name(junctionVariableName("power")),
      72          22 :     _driving_torque_var_name(junctionVariableName("driving_torque")),
      73          22 :     _friction_torque_var_name(junctionVariableName("friction_torque")),
      74          22 :     _flow_coeff_var_name(junctionVariableName("flow_coeff")),
      75          44 :     _moi_var_name(junctionVariableName("moment_of_inertia"))
      76             : {
      77             :   // this determines connection ordering
      78          22 :   addConnection(_inlet);
      79          22 :   addConnection(_outlet);
      80             : 
      81          22 :   checkSizeEqualsValue<Real>("tau_fr_coeff", 4);
      82          22 :   checkSizeEqualsValue<Real>("inertia_coeff", 4);
      83          22 : }
      84             : 
      85             : void
      86          20 : ShaftConnectedTurbine1Phase::check() const
      87             : {
      88          20 :   VolumeJunction1Phase::check();
      89          20 :   checkShaftConnection(this);
      90          20 : }
      91             : 
      92             : void
      93          20 : ShaftConnectedTurbine1Phase::buildVolumeJunctionUserObject()
      94             : {
      95          20 :   const Component & c = getComponentByName<Component>(_shaft_name);
      96          20 :   const Shaft & scc = dynamic_cast<const Shaft &>(c);
      97          20 :   const VariableName omega_var_name = scc.getOmegaVariableName();
      98             : 
      99          20 :   ExecFlagEnum execute_on(MooseUtils::getDefaultExecFlagEnum());
     100          80 :   execute_on = {EXEC_INITIAL, EXEC_LINEAR, EXEC_NONLINEAR};
     101             : 
     102             :   {
     103          20 :     const std::string class_name = "ADShaftConnectedTurbine1PhaseUserObject";
     104          20 :     InputParameters params = _factory.getValidParams(class_name);
     105          20 :     params.set<bool>("use_scalar_variables") = false;
     106          20 :     params.set<subdomain_id_type>("junction_subdomain_id") = _junction_subdomain_id;
     107          20 :     params.set<std::vector<BoundaryName>>("boundary") = _boundary_names;
     108          40 :     params.set<std::vector<Real>>("normals") = _normals;
     109          20 :     params.set<std::vector<processor_id_type>>("processor_ids") = getConnectedProcessorIDs();
     110          20 :     params.set<std::vector<UserObjectName>>("numerical_flux_names") = _numerical_flux_names;
     111          20 :     params.set<Real>("volume") = _volume;
     112          60 :     params.set<std::vector<VariableName>>("A") = {FlowModel::AREA};
     113          60 :     params.set<std::vector<VariableName>>("rhoA") = {FlowModelSinglePhase::RHOA};
     114          60 :     params.set<std::vector<VariableName>>("rhouA") = {FlowModelSinglePhase::RHOUA};
     115          60 :     params.set<std::vector<VariableName>>("rhoEA") = {FlowModelSinglePhase::RHOEA};
     116          60 :     params.set<std::vector<VariableName>>("rhoV") = {_rhoV_var_name};
     117          60 :     params.set<std::vector<VariableName>>("rhouV") = {_rhouV_var_name};
     118          60 :     params.set<std::vector<VariableName>>("rhovV") = {_rhovV_var_name};
     119          60 :     params.set<std::vector<VariableName>>("rhowV") = {_rhowV_var_name};
     120          60 :     params.set<std::vector<VariableName>>("rhoEV") = {_rhoEV_var_name};
     121             :     // the direction of the outlet channel
     122          20 :     params.set<Point>("di_out") = _directions[1].unit();
     123          20 :     params.set<Real>("omega_rated") = _omega_rated;
     124          20 :     params.set<Real>("D_wheel") = _D_wheel;
     125          20 :     params.set<Real>("speed_cr_fr") = _speed_cr_fr;
     126          20 :     params.set<Real>("tau_fr_const") = _tau_fr_const;
     127          20 :     params.set<std::vector<Real>>("tau_fr_coeff") = _tau_fr_coeff;
     128          20 :     params.set<Real>("speed_cr_I") = _speed_cr_I;
     129          20 :     params.set<Real>("inertia_const") = _inertia_const;
     130          20 :     params.set<std::vector<Real>>("inertia_coeff") = _inertia_coeff;
     131          20 :     params.set<FunctionName>("head_coefficient") = _head_coefficient;
     132          40 :     params.set<FunctionName>("power_coefficient") = _power_coefficient;
     133          60 :     params.set<std::vector<VariableName>>("omega") = {omega_var_name};
     134          40 :     params.set<Real>("A_ref") = getParam<Real>("A_ref");
     135          40 :     params.set<Real>("K") = getParam<Real>("K");
     136          20 :     params.set<UserObjectName>("fp") = _fp_name;
     137          20 :     params.set<std::string>("turbine_name") = cname();
     138          40 :     params.set<bool>("apply_velocity_scaling") = getParam<bool>("apply_velocity_scaling");
     139          20 :     params.set<ExecFlagEnum>("execute_on") = execute_on;
     140          20 :     getTHMProblem().addUserObject(class_name, getShaftConnectedUserObjectName(), params);
     141          20 :     connectObject(params, _junction_uo_name, "K");
     142          20 :   }
     143          40 : }
     144             : 
     145             : void
     146          20 : ShaftConnectedTurbine1Phase::addVariables()
     147             : {
     148          20 :   VolumeJunction1Phase::addVariables();
     149             : 
     150          20 :   addJunctionVariable(false, _delta_p_var_name);
     151          20 :   addJunctionVariable(false, _power_var_name);
     152          20 :   addJunctionVariable(false, _driving_torque_var_name);
     153          20 :   addJunctionVariable(false, _flow_coeff_var_name);
     154          20 :   addJunctionVariable(false, _friction_torque_var_name);
     155          20 :   addJunctionVariable(false, _moment_of_inertia_var_name);
     156             : 
     157          20 :   if (!_app.isRestarting())
     158             :   {
     159          20 :     addJunctionIC(_delta_p_var_name, 0);
     160          20 :     addJunctionIC(_power_var_name, 0);
     161          20 :     addJunctionIC(_driving_torque_var_name, 0);
     162          20 :     addJunctionIC(_flow_coeff_var_name, 0);
     163          20 :     addJunctionIC(_friction_torque_var_name, 0);
     164          20 :     addJunctionIC(_moment_of_inertia_var_name, _inertia_const);
     165             :   }
     166          20 : }
     167             : 
     168             : void
     169          20 : ShaftConnectedTurbine1Phase::addMooseObjects()
     170             : {
     171          20 :   VolumeJunction1Phase::addMooseObjects();
     172             : 
     173             :   const std::vector<std::pair<std::string, VariableName>> quantities_aux = {
     174          20 :       {"delta_p", _delta_p_var_name},
     175          20 :       {"flow_coefficient", _flow_coeff_var_name},
     176          20 :       {"driving_torque", _driving_torque_var_name},
     177          20 :       {"friction_torque", _friction_torque_var_name},
     178          20 :       {"moment_of_inertia", _moment_of_inertia_var_name},
     179         140 :       {"power", _power_var_name}};
     180         140 :   for (const auto & quantity_and_name : quantities_aux)
     181             :   {
     182         120 :     const std::string class_name = "ShaftConnectedTurbine1PhaseAux";
     183         120 :     InputParameters params = _factory.getValidParams(class_name);
     184         240 :     params.set<AuxVariableName>("variable") = quantity_and_name.second;
     185         120 :     params.set<MooseEnum>("quantity") = quantity_and_name.first;
     186         240 :     params.set<UserObjectName>("turbine_uo") = getShaftConnectedUserObjectName();
     187         240 :     const std::string obj_name = genName(name(), quantity_and_name.first + "_aux");
     188         120 :     params.set<std::vector<SubdomainName>>("block") = getSubdomainNames();
     189         120 :     getTHMProblem().addAuxKernel(class_name, obj_name, params);
     190         120 :   }
     191          40 : }

Generated by: LCOV version 1.14