https://mooseframework.inl.gov
ADShaftConnectedTurbine1PhaseUserObject.C
Go to the documentation of this file.
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 
13 #include "VolumeJunction1Phase.h"
14 #include "MooseVariableScalar.h"
15 #include "THMIndicesVACE.h"
16 #include "Function.h"
17 #include "Numerics.h"
18 #include "metaphysicl/parallel_numberarray.h"
19 #include "metaphysicl/parallel_dualnumber.h"
20 #include "metaphysicl/parallel_semidynamicsparsenumberarray.h"
21 #include "libmesh/parallel_algebra.h"
22 #include "libmesh/utility.h"
23 
25 
28 {
31 
32  params.addParam<BoundaryName>("inlet", "Turbine inlet");
33  params.addParam<BoundaryName>("outlet", "Turbine outlet");
34  params.addRequiredParam<Point>("di_out", "Direction of connected outlet");
35  params.addRequiredParam<Real>("omega_rated", "Rated turbine speed [rad/s]");
36  params.addRequiredParam<Real>("D_wheel", "Diameter of turbine wheel [m]");
37  params.addRequiredParam<Real>("speed_cr_fr", "Turbine speed threshold for friction [-]");
38  params.addRequiredParam<Real>("tau_fr_const", "Turbine friction constant [N-m]");
39  params.addRequiredParam<std::vector<Real>>("tau_fr_coeff", "Friction coefficients [N-m]");
40  params.addRequiredParam<Real>("speed_cr_I", "Turbine speed threshold for inertia [-]");
41  params.addRequiredParam<Real>("inertia_const", "Turbine inertia constant [kg-m^2]");
42  params.addRequiredParam<std::vector<Real>>("inertia_coeff",
43  "Turbine inertia coefficients [kg-m^2]");
44  params.addRequiredParam<FunctionName>("head_coefficient",
45  "Function to compute data for turbine head [-]");
46  params.addRequiredParam<FunctionName>("power_coefficient",
47  "Function to compute data for turbine power [-]");
48  params.addRequiredParam<std::string>("turbine_name",
49  "Name of the instance of this turbine component");
50  params.addRequiredCoupledVar("omega", "Shaft rotational speed [rad/s]");
51 
52  params.addClassDescription("Computes and caches flux and residual vectors for a 1-phase "
53  "turbine. Also computes turbine torque "
54  "and delta_p which is passed to the connected shaft");
55 
56  return params;
57 }
58 
60  const InputParameters & params)
63 
64  _di_out(getParam<Point>("di_out")),
65  _omega_rated(getParam<Real>("omega_rated")),
66  _D_wheel(getParam<Real>("D_wheel")),
67  _speed_cr_fr(getParam<Real>("speed_cr_fr")),
68  _tau_fr_const(getParam<Real>("tau_fr_const")),
69  _tau_fr_coeff(getParam<std::vector<Real>>("tau_fr_coeff")),
70  _speed_cr_I(getParam<Real>("speed_cr_I")),
71  _inertia_const(getParam<Real>("inertia_const")),
72  _inertia_coeff(getParam<std::vector<Real>>("inertia_coeff")),
73  _head_coefficient(getFunction("head_coefficient")),
74  _power_coefficient(getFunction("power_coefficient")),
75  _turbine_name(getParam<std::string>("turbine_name")),
76 
77  _omega(adCoupledScalarValue("omega"))
78 {
79 }
80 
81 void
83 {
85 
88 }
89 
90 void
92 {
95 
96  _driving_torque = 0;
97  _friction_torque = 0;
98  _flow_coeff = 0;
99  _delta_p = 0;
100  _power = 0;
101 }
102 
103 void
105 {
109 
110  const unsigned int c = getBoundaryIDIndex();
111 
113 }
114 
115 void
117 {
119 
120  // inlet c=0 established in component
121  if (c == 0)
122  {
124 
125  const ADReal Q_in = (_rhouA[0] / _rhoA[0]) * _A[0];
126 
127  _flow_coeff = Q_in / (_omega[0] * _D_wheel * _D_wheel * _D_wheel);
128 
129  const auto head_coeff = _head_coefficient.value(_flow_coeff, ADPoint());
130 
131  const ADReal gH = head_coeff * _D_wheel * _D_wheel * _omega[0] * _omega[0];
132 
133  const auto power_coeff = _power_coefficient.value(_flow_coeff, ADPoint());
134 
135  // friction torque
137  Real sign;
138  if (_omega[0] >= 0)
139  sign = -1;
140  else
141  sign = 1;
142  if (alpha < _speed_cr_fr)
143  {
145  }
146  else
147  {
148  _friction_torque = sign * (_tau_fr_coeff[0] + _tau_fr_coeff[1] * std::abs(alpha) +
149  _tau_fr_coeff[2] * alpha * alpha +
150  _tau_fr_coeff[3] * std::abs(alpha * alpha * alpha));
151  }
152 
154  power_coeff * (rhoV / _volume) * _omega[0] * _omega[0] * Utility::pow<5>(_D_wheel);
155 
157 
158  if (alpha < _speed_cr_I)
159  {
161  }
162  else
163  {
164  _moment_of_inertia += _inertia_coeff[0] + _inertia_coeff[1] * std::abs(alpha) +
165  _inertia_coeff[2] * alpha * alpha +
166  _inertia_coeff[3] * std::abs(alpha * alpha * alpha);
167  }
168 
169  // compute momentum and energy source terms
170  // a positive torque value results in a negative S_energy
171  _power = _torque * _omega[0];
172  const ADReal S_energy = -_power;
173 
174  _delta_p = (rhoV / _volume) * gH;
175 
176  const ADRealVectorValue S_momentum = -_delta_p * _A_ref * _di_out;
177 
179 
183  }
184 }
185 
186 ADReal
188 {
189  return _driving_torque;
190 }
191 
192 ADReal
194 {
195  return _friction_torque;
196 }
197 
198 ADReal
200 {
201  return _flow_coeff;
202 }
203 
204 ADReal
206 {
207  return _delta_p;
208 }
209 
210 ADReal
212 {
213  return _power;
214 }
215 
216 void
218 {
221 
225 
228  comm().sum(_flow_coeff);
229  comm().sum(_delta_p);
230  comm().sum(_power);
231 }
232 
233 void
235 {
238 
239  const auto & scpuo = static_cast<const ADShaftConnectedTurbine1PhaseUserObject &>(uo);
240  _driving_torque += scpuo._driving_torque;
241  _friction_torque += scpuo._friction_torque;
242  _flow_coeff += scpuo._flow_coeff;
243  _delta_p += scpuo._delta_p;
244  _power += scpuo._power;
245 }
const ADVariableValue & _rhoA
rho*A of the connected flow channels
std::vector< std::vector< dof_id_type > > _flow_channel_dofs
Degrees of freedom for flow channel variables, for each connection.
const Real & _speed_cr_I
Turbine speed threshold for inertia.
const std::vector< Real > & _tau_fr_coeff
Turbine friction coefficients.
ADReal _flow_coeff
Turbine flow coefficient - independent variable in user supplied head and power functions.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
ADReal getTurbinePower() const
Turbine power computed in the 1-phase shaft-connected turbine.
unsigned int getBoundaryIDIndex()
Gets the index of the currently executing boundary within the vector of boundary IDs given to this Si...
const ADVariableValue & _omega
Connected shaft speed.
const Parallel::Communicator & comm() const
virtual void computeFluxesAndResiduals(const unsigned int &c) override
Computes and stores the fluxes, the scalar residuals, and their Jacobians.
unsigned int _n_flux_eq
Number of flow channel flux components.
registerMooseObject("ThermalHydraulicsApp", ADShaftConnectedTurbine1PhaseUserObject)
const unsigned int _n_connections
Number of connected flow channels.
DualNumber< Real, DNDerivativeType, true > ADReal
virtual void threadJoin(const UserObject &uo) override
void addRequiredParam(const std::string &name, const std::string &doc_string)
std::vector< ADReal > _residual
Cached scalar residual vector.
const Real & _volume
Volume of the junction.
virtual void setOmegaDofs(const MooseVariableScalar *omega_var)
const Real & _speed_cr_fr
Turbine speed threshold for friction.
virtual void threadJoin(const UserObject &uo) override
const std::vector< Real > & _inertia_coeff
Turbine inertia coefficients.
ADReal getFlowCoefficient() const
Flow coefficient computed in the 1-phase shaft-connected turbine.
virtual void storeConnectionData()
Stores data (connection index, face shape functions, DoFs associated with flow channel variables) rel...
T sign(T x)
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
ADReal getTurbineDeltaP() const
Turbine head computed in the 1-phase shaft-connected turbine.
virtual void setupJunctionData(std::vector< dof_id_type > &scalar_dofs)
Stores data associated with a junction component.
virtual void computeFluxesAndResiduals(const unsigned int &c) override
Computes and stores the fluxes, the scalar residuals, and their Jacobians.
Computes and caches flux and residual vectors for a 1-phase volume junction.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
std::vector< dof_id_type > _scalar_dofs
Degrees of freedom for scalar variables.
Interface class for user objects that are connected to a shaft.
const ADVariableValue & _A
Cross-sectional area of connected flow channels.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void setConnectionData(const std::vector< std::vector< dof_id_type >> &flow_channel_dofs)
Stores data computed by a volume-junction-like object associated with the conection.
static const std::string alpha
Definition: NS.h:134
void addClassDescription(const std::string &doc_string)
ADReal getFrictionTorque() const
Friction torque computed in the 1-phase shaft-connected turbine.
virtual void setupConnections(unsigned int n_connections, unsigned int n_flow_eq)
Computes and caches flux and residual vectors for a 1-phase turbine.
ADReal getDrivingTorque() const
Driving torque computed in the 1-phase shaft-connected turbine.
virtual Real value(Real t, const Point &p) const
const Function & _power_coefficient
Function to compute data for turbine power.
const Function & _head_coefficient
Function to compute data for turbine head.
const ADVariableValue & _rhouA
rho*u*A of the connected flow channels