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  using std::abs;
121 
122  // inlet c=0 established in component
123  if (c == 0)
124  {
126 
127  const ADReal Q_in = (_rhouA[0] / _rhoA[0]) * _A[0];
128 
129  _flow_coeff = Q_in / (_omega[0] * _D_wheel * _D_wheel * _D_wheel);
130 
131  const auto head_coeff = _head_coefficient.value(_flow_coeff, ADPoint());
132 
133  const ADReal gH = head_coeff * _D_wheel * _D_wheel * _omega[0] * _omega[0];
134 
135  const auto power_coeff = _power_coefficient.value(_flow_coeff, ADPoint());
136 
137  // friction torque
139  Real sign;
140  if (_omega[0] >= 0)
141  sign = -1;
142  else
143  sign = 1;
144  if (alpha < _speed_cr_fr)
145  {
147  }
148  else
149  {
151  sign * (_tau_fr_coeff[0] + _tau_fr_coeff[1] * abs(alpha) +
153  }
154 
156  power_coeff * (rhoV / _volume) * _omega[0] * _omega[0] * Utility::pow<5>(_D_wheel);
157 
159 
160  if (alpha < _speed_cr_I)
161  {
163  }
164  else
165  {
167  _inertia_coeff[2] * alpha * alpha +
168  _inertia_coeff[3] * abs(alpha * alpha * alpha);
169  }
170 
171  // compute momentum and energy source terms
172  // a positive torque value results in a negative S_energy
173  _power = _torque * _omega[0];
174  const ADReal S_energy = -_power;
175 
176  _delta_p = (rhoV / _volume) * gH;
177 
178  const ADRealVectorValue S_momentum = -_delta_p * _A_ref * _di_out;
179 
181 
185  }
186 }
187 
188 ADReal
190 {
191  return _driving_torque;
192 }
193 
194 ADReal
196 {
197  return _friction_torque;
198 }
199 
200 ADReal
202 {
203  return _flow_coeff;
204 }
205 
206 ADReal
208 {
209  return _delta_p;
210 }
211 
212 ADReal
214 {
215  return _power;
216 }
217 
218 void
220 {
223 
227 
230  comm().sum(_flow_coeff);
231  comm().sum(_delta_p);
232  comm().sum(_power);
233 }
234 
235 void
237 {
240 
241  const auto & scpuo = static_cast<const ADShaftConnectedTurbine1PhaseUserObject &>(uo);
242  _driving_torque += scpuo._driving_torque;
243  _friction_torque += scpuo._friction_torque;
244  _flow_coeff += scpuo._flow_coeff;
245  _delta_p += scpuo._delta_p;
246  _power += scpuo._power;
247 }
const ADVariableValue & _rhoA
rho*A of the connected flow channels
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
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