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

Generated by: LCOV version 1.14