https://mooseframework.inl.gov
ADShaftConnectedPump1PhaseUserObject.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 
11 #include "VolumeJunction1Phase.h"
12 #include "MooseVariableScalar.h"
13 #include "THMIndicesVACE.h"
14 #include "Function.h"
15 #include "metaphysicl/parallel_numberarray.h"
16 #include "metaphysicl/parallel_dualnumber.h"
17 #include "metaphysicl/parallel_semidynamicsparsenumberarray.h"
18 #include "libmesh/parallel_algebra.h"
19 
21 
24 {
27 
28  params.addParam<BoundaryName>("inlet", "Pump inlet");
29  params.addParam<BoundaryName>("outlet", "Pump outlet");
30  params.addRequiredParam<Point>("di_out", "Direction of connected outlet");
31  params.addRequiredParam<Real>("gravity_magnitude", "Gravity constant, [m/s^2]");
32  params.addRequiredParam<Real>("omega_rated", "Rated pump speed [rad/s]");
33  params.addRequiredParam<Real>("volumetric_rated", "Rated pump volumetric flow rate [m^3/s]");
34  params.addRequiredParam<Real>("head_rated", "Rated pump head [m]");
35  params.addRequiredParam<Real>("torque_rated", "Rated pump torque [N-m]");
36  params.addRequiredParam<Real>("density_rated", "Rated pump fluid density [kg/m^3]");
37  params.addRequiredParam<Real>("speed_cr_fr", "Pump speed threshold for friction [-]");
38  params.addRequiredParam<Real>("tau_fr_const", "Pump friction constant [N-m]");
39  params.addRequiredParam<std::vector<Real>>("tau_fr_coeff", "Friction coefficients [N-m]");
40  params.addRequiredParam<Real>("speed_cr_I", "Pump speed threshold for inertia [-]");
41  params.addRequiredParam<Real>("inertia_const", "Pump inertia constant [kg-m^2]");
42  params.addRequiredParam<std::vector<Real>>("inertia_coeff", "Pump inertia coefficients [kg-m^2]");
43  params.addRequiredParam<FunctionName>("head", "Function to compute data for pump head [-]");
44  params.addRequiredParam<FunctionName>("torque_hydraulic",
45  "Function to compute data for pump torque [-]");
46  params.addRequiredParam<std::string>("pump_name", "Name of the instance of this pump component");
47  params.addParam<Real>(
48  "transition_width",
49  1e-3,
50  "Transition width for sign of the frictional torque at 0 speed over rated speed ratio.");
51  params.addRequiredCoupledVar("omega", "Shaft rotational speed [rad/s]");
52 
53  params.addClassDescription(
54  "Computes and caches flux and residual vectors for a 1-phase pump. Also computes pump torque "
55  "and head which is passed to the connected shaft");
56 
57  return params;
58 }
59 
61  const InputParameters & params)
64 
65  _di_out(getParam<Point>("di_out")),
66  _g(getParam<Real>("gravity_magnitude")),
67  _omega_rated(getParam<Real>("omega_rated")),
68  _volumetric_rated(getParam<Real>("volumetric_rated")),
69  _head_rated(getParam<Real>("head_rated")),
70  _torque_rated(getParam<Real>("torque_rated")),
71  _density_rated(getParam<Real>("density_rated")),
72  _speed_cr_fr(getParam<Real>("speed_cr_fr")),
73  _tau_fr_const(getParam<Real>("tau_fr_const")),
74  _tau_fr_coeff(getParam<std::vector<Real>>("tau_fr_coeff")),
75  _speed_cr_I(getParam<Real>("speed_cr_I")),
76  _inertia_const(getParam<Real>("inertia_const")),
77  _inertia_coeff(getParam<std::vector<Real>>("inertia_coeff")),
78  _head(getFunction("head")),
79  _torque_hydraulic(getFunction("torque_hydraulic")),
80  _pump_name(getParam<std::string>("pump_name")),
81  _omega(adCoupledScalarValue("omega")),
82  _transition_width(getParam<Real>("transition_width")),
83  _transition_friction(0, _transition_width)
84 {
85 }
86 
87 void
89 {
91 
94 }
95 
96 void
98 {
101 
102  _hydraulic_torque = 0;
103  _friction_torque = 0;
104  _pump_head = 0;
105 }
106 
107 void
109 {
113 
114  const unsigned int c = getBoundaryIDIndex();
115 
117 }
118 
119 void
121 {
123 
124  // inlet c=0 established in component
125  if (c == 0)
126  {
128 
129  ADReal Q_in = (_rhouA[0] / _rhoA[0]) * _A[0];
130 
131  ADReal nu = Q_in / _volumetric_rated;
132 
133  // Head and torque
134  ADReal x_p = std::atan2(alpha, nu);
135  const auto wt = _torque_hydraulic.value(x_p, ADPoint());
136  const auto wh = _head.value(x_p, ADPoint());
137 
138  const ADReal y = alpha * alpha + nu * nu;
139 
140  const auto zt = wt * _torque_rated;
141 
142  // Real homologous_torque = -(alpha * alpha + nu * nu) * wt * _torque_rated;
143  const ADReal homologous_torque = -y * zt;
144  _hydraulic_torque = homologous_torque * ((_rhoA[0] / _A[0]) / _density_rated);
145 
146  const auto zh = wh * _head_rated;
147 
148  // _pump_head = (alpha * alpha + nu * nu) * wh * _head_rated;
149  _pump_head = y * zh;
150 
151  // MoI
152  if (alpha < _speed_cr_I)
153  {
155  }
156  else
157  {
158  _moment_of_inertia += _inertia_coeff[0] + _inertia_coeff[1] * std::abs(alpha) +
159  _inertia_coeff[2] * alpha * alpha +
160  _inertia_coeff[3] * std::abs(alpha * alpha * alpha);
161  }
162 
163  // friction torque
164  ADReal sign;
166  sign = -1;
167  else if (alpha < _transition_friction.leftEnd())
168  sign = 1;
169  else
171 
172  if (alpha < _speed_cr_fr)
173  {
175  }
176  else
177  {
178  _friction_torque = sign * (_tau_fr_coeff[0] + _tau_fr_coeff[1] * std::abs(alpha) +
179  _tau_fr_coeff[2] * alpha * alpha +
180  _tau_fr_coeff[3] * std::abs(alpha * alpha * alpha));
181  }
182 
183  // compute momentum and energy source terms
184  // a negative torque value results in a positive S_energy
185  const ADReal S_energy = -_hydraulic_torque * _omega[0];
186 
187  // a positive head value results in a positive S_momentum
188  const ADRealVectorValue S_momentum = (_rhoA[0] / _A[0]) * _g * _pump_head * _A_ref * _di_out;
189 
191 
195 
197  }
198 }
199 
200 ADReal
202 {
203  return _hydraulic_torque;
204 }
205 
206 ADReal
208 {
209  return _friction_torque;
210 }
211 
212 ADReal
214 {
215  return _pump_head;
216 }
217 
218 void
220 {
223 
227 
230  comm().sum(_pump_head);
231 }
232 
233 void
235 {
238 
239  const auto & scpuo = static_cast<const ADShaftConnectedPump1PhaseUserObject &>(uo);
240  _hydraulic_torque += scpuo._hydraulic_torque;
241  _friction_torque += scpuo._friction_torque;
242  _pump_head += scpuo._pump_head;
243 }
const ADVariableValue & _rhoA
rho*A of the connected flow channels
const Function & _torque_hydraulic
Function to compute data for pump torque.
std::vector< std::vector< dof_id_type > > _flow_channel_dofs
Degrees of freedom for flow channel variables, for each connection.
virtual void computeFluxesAndResiduals(const unsigned int &c) override
Computes and stores the fluxes, the scalar residuals, and their Jacobians.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
unsigned int getBoundaryIDIndex()
Gets the index of the currently executing boundary within the vector of boundary IDs given to this Si...
const Real & _speed_cr_fr
Pump speed threshold for friction.
const Parallel::Communicator & comm() const
virtual void computeFluxesAndResiduals(const unsigned int &c) override
Computes and stores the fluxes, the scalar residuals, and their Jacobians.
const ADWeightedTransition _transition_friction
Transition for the sign of the frictional torque when speed is 0.
unsigned int _n_flux_eq
Number of flow channel flux components.
const std::vector< double > y
Computes and caches flux and residual vectors for a 1-phase pump.
const unsigned int _n_connections
Number of connected flow channels.
const ADReal & leftEnd() const
Returns the coordinate of the left end of the transition.
DualNumber< Real, DNDerivativeType, true > ADReal
void addRequiredParam(const std::string &name, const std::string &doc_string)
const Real & _volumetric_rated
Rated pump volumetric flow rate.
std::vector< ADReal > _residual
Cached scalar residual vector.
virtual void setOmegaDofs(const MooseVariableScalar *omega_var)
const std::vector< Real > & _tau_fr_coeff
Pump friction coefficients.
virtual void threadJoin(const UserObject &uo) override
const ADReal & rightEnd() const
Returns the coordinate of the right end of the transition.
const Real & _tau_fr_const
Pump friction constant.
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
virtual ADReal value(const ADReal &x, const ADReal &f1, const ADReal &f2) const override
Computes the transition value.
virtual void setupJunctionData(std::vector< dof_id_type > &scalar_dofs)
Stores data associated with a junction component.
const Real & _inertia_const
Pump inertia constant.
Computes and caches flux and residual vectors for a 1-phase volume junction.
registerMooseObject("ThermalHydraulicsApp", ADShaftConnectedPump1PhaseUserObject)
ADReal getFrictionTorque() const
Friction torque computed in the 1-phase shaft-connected pump.
ADReal getPumpHead() const
Pump head computed in the 1-phase shaft-connected pump.
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.
const std::vector< Real > & _inertia_coeff
Pump inertia coefficients.
static const std::string alpha
Definition: NS.h:134
ADReal getHydraulicTorque() const
Hydraulic torque computed in the 1-phase shaft-connected pump.
virtual void threadJoin(const UserObject &uo) override
void addClassDescription(const std::string &doc_string)
virtual void setupConnections(unsigned int n_connections, unsigned int n_flow_eq)
virtual Real value(Real t, const Point &p) const
const ADVariableValue & _rhouA
rho*u*A of the connected flow channels
ADShaftConnectedPump1PhaseUserObject(const InputParameters &params)
const Real & _speed_cr_I
Pump speed threshold for inertia.
const Function & _head
Function to compute data for pump head.