https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ADIncompressibleMomentumSPBase.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
12#include "ScalarCoupleable.h"
14#include "PhysicalConstants.h"
15
18{
21 "Base class for assembling the path-integrated incompressible momentum equation.");
22 params.addCoupledVar("temperatures",
23 {},
24 "Fluid temperature in each segment of this component. Takes a "
25 "list of scalar variable names");
26 params.addParam<bool>(
27 "is_implicit",
28 true,
29 "Whether an explicit (previous value calculation) or implicit (current value) is used");
30 params.addRequiredParam<MooseFunctorName>("reference_pressure", "system reference pressure [Pa]");
31 params.addRequiredParam<std::vector<UserObjectName>>(
32 "fp",
33 "Fluid properties user object(s). Supply either one (applied to all segments) "
34 "or one per segment.");
35 params.addParam<UserObjectName>("reference_fp",
36 "Fluid properties of the liquid phase for draining problems.");
37 params.addParam<std::vector<MooseFunctorName>>(
38 "areas",
39 std::vector<MooseFunctorName>({}),
40 "Component flow areas per segment. Takes a vector of functors.");
41 params.addParam<std::vector<MooseFunctorName>>(
42 "perimeters",
43 std::vector<MooseFunctorName>({}),
44 "Component flow perimeters per segment. Takes a vector of functors.");
45 params.addParam<std::vector<MooseFunctorName>>(
46 "lengths",
47 std::vector<MooseFunctorName>({}),
48 "Component flow lengths per segment. Takes a vector of functors.");
49 params.addParam<std::vector<MooseFunctorName>>(
50 "height_changes",
51 std::vector<MooseFunctorName>({}),
52 "Height change from inlet to outlet of each segment. Takes a vector of functors.");
53 params.addParam<std::vector<MooseFunctorName>>(
54 "forms_losses",
55 std::vector<MooseFunctorName>({}),
56 "Forms loss coefficients per segment. Takes a vector of functors.");
57 params.addParam<std::vector<MooseFunctorName>>(
58 "pump_pressures",
59 std::vector<MooseFunctorName>({}),
60 "Pump pressure gains per segment [Pa]. Takes a vector of functors.");
61 params.addParam<std::vector<MooseFunctorName>>(
62 "roughnesses",
63 std::vector<MooseFunctorName>({}),
64 "Component wall roughnesses per segment [m]. Takes a vector of functors.");
65 params.addParam<MooseFunctorName>(
66 "g", PhysicalConstants::acceleration_of_gravity, "Gravitational acceleration [m/s^2]");
67
68 return params;
69}
70
72 : Base(parameters),
73 _n_temps(ScalarCoupleable::coupledScalarComponents("temperatures")),
74 _T(_n_temps),
75 _is_implicit(this->template getParam<bool>("is_implicit")),
76 _Pref(this->template getFunctor<ADReal>("reference_pressure")),
77 _n_fp(this->template getParam<std::vector<UserObjectName>>("fp").size()),
78 _n_segments(this->template getParam<std::vector<MooseFunctorName>>("areas").size()),
79 _fp(_n_segments), // size it here, or after _n_segments if declared later in the header
80 _fp_ref(isParamValid("reference_fp") ? &getUserObjectByName<SinglePhaseFluidProperties>(
81 getParam<UserObjectName>("reference_fp"))
82 : nullptr),
83 _areas(this->template getParam<std::vector<MooseFunctorName>>("areas").size()),
84 _perimeters(this->template getParam<std::vector<MooseFunctorName>>("perimeters").size()),
85 _lengths(this->template getParam<std::vector<MooseFunctorName>>("lengths").size()),
86 _dZs(this->template getParam<std::vector<MooseFunctorName>>("height_changes").size()),
87 _forms_losses(this->template getParam<std::vector<MooseFunctorName>>("forms_losses").size()),
88 _dPps(this->template getParam<std::vector<MooseFunctorName>>("pump_pressures").size()),
89 _roughnesses(this->template getParam<std::vector<MooseFunctorName>>("roughnesses").size()),
90 _gravity(this->template getFunctor<ADReal>("g"))
91{
92 const auto & area_names = MooseBase::getParam<std::vector<MooseFunctorName>>("areas");
93 const auto & perimeter_names = MooseBase::getParam<std::vector<MooseFunctorName>>("perimeters");
94 const auto & length_names = MooseBase::getParam<std::vector<MooseFunctorName>>("lengths");
95 const auto & dZ_names = MooseBase::getParam<std::vector<MooseFunctorName>>("height_changes");
96 const auto & forms_loss_names =
97 MooseBase::getParam<std::vector<MooseFunctorName>>("forms_losses");
98 const auto & dPp_names = MooseBase::getParam<std::vector<MooseFunctorName>>("pump_pressures");
99 const auto & roughness_names = MooseBase::getParam<std::vector<MooseFunctorName>>("roughnesses");
100 if (_n_segments != area_names.size() || _n_segments != perimeter_names.size() ||
101 _n_segments != length_names.size() || _n_segments != dZ_names.size() ||
102 _n_segments != forms_loss_names.size() || _n_segments != dPp_names.size() ||
103 _n_segments != roughness_names.size() || _n_segments != _n_temps)
104 {
106 "Must provide consistent number of segments for each parameter! Including temperatures!");
107 }
108 for (const auto j : make_range(_n_segments))
109 {
110 _T[j] = &(ScalarCoupleable::adCoupledScalarValue("temperatures", j));
111 _areas[j] = &(this->template getFunctor<ADReal>(area_names[j]));
112 _perimeters[j] = &(this->template getFunctor<ADReal>(perimeter_names[j]));
113 _lengths[j] = &(this->template getFunctor<ADReal>(length_names[j]));
114 _dZs[j] = &(this->template getFunctor<ADReal>(dZ_names[j]));
115 _forms_losses[j] = &(this->template getFunctor<ADReal>(forms_loss_names[j]));
116 _dPps[j] = &(this->template getFunctor<ADReal>(dPp_names[j]));
117 _roughnesses[j] = &(this->template getFunctor<ADReal>(roughness_names[j]));
118 }
119 const auto & fp_names = MooseBase::getParam<std::vector<UserObjectName>>("fp");
120 if (_n_fp != 1 && _n_fp != _n_segments)
122 "fp", "Provide either one fluid properties object or one per segment (", _n_segments, ").");
123
124 for (const auto j : make_range(_n_segments))
125 {
126 const auto & name = (_n_fp == 1) ? fp_names[0] : fp_names[j];
127 _fp[j] = &getUserObjectByName<SinglePhaseFluidProperties>(name);
128 }
129}
130
131ADReal
133{
134 ADReal momentum_residual = 0;
135 const Moose::PointArg arg = {Point(1, 2, 3)};
136 const int i = 0;
137 const auto state = _is_implicit ? Moose::currentState() : Moose::oldState();
138 const auto P = _Pref(arg, state);
139
140 // Inertia scale: Sum_j (rho_j / rho_ref,j) L_j / A_j. Reduces to Sum_j L_j / A_j when
141 // every segment holds the reference liquid. Gas-filled segments carry ~no inertia.
142 ADReal L_over_A_sum = 0;
143 for (const auto j : make_range(_n_segments))
144 {
145 const auto Tj = (*(_T[j]))[i];
146 const auto rho_j = _fp[j]->rho_from_p_T(P, Tj);
147 const auto rho_ref = _fp_ref ? _fp_ref->rho_from_p_T(P, Tj) : rho_j;
148 L_over_A_sum +=
149 max(rho_j / rho_ref, 1e-6) * (*(_lengths[j]))(arg, state) / (*(_areas[j]))(arg, state);
150 }
151 const auto inv_L_over_A_sum = 1.0 / L_over_A_sum;
152
153 for (const auto j : make_range(_n_segments))
154 {
155 const auto Tj = (*(_T[j]))[i];
156 const auto A = (*(_areas[j]))(arg, state);
157 const auto Dh = 4.0 * A / (*(_perimeters[j]))(arg, state);
158 // Segment properties (blended liquid/gas) and liquid reference density
159 const auto mu = _fp[j]->mu_from_p_T(P, Tj);
160 const auto rho_j = _fp[j]->rho_from_p_T(P, Tj);
161 const auto rho_ref = _fp_ref ? _fp_ref->rho_from_p_T(P, Tj) : rho_j;
162 // Velocity is continuous along the path (volumetric continuity); the mass flux
163 // actually present in this segment is rho_j * v.
164 const auto v = massFlowRate() / (rho_ref * A);
165 const auto Gj = rho_j * v;
166 const auto fd = computeFrictionFactor(mu, Gj, Dh, j);
167 // Friction and form losses: f L/Dh * rho_j v|v| / 2 (-> 0 as rho_j -> 0)
168 momentum_residual += fd * (*(_lengths[j]))(arg, state) / Dh * Gj * abs(Gj) / 2.0 / rho_j;
169 momentum_residual += (*(_forms_losses[j]))(arg, state) * Gj * abs(Gj) / 2.0 / rho_j;
170 // Gravity: hydrostatic head of whatever is in the segment
171 momentum_residual += rho_j * _gravity(arg, state) * (*(_dZs[j]))(arg, state);
172 // Pump
173 momentum_residual -= (*(_dPps[j]))(arg, state);
174 }
175 momentum_residual += pressureDrop();
176 return momentum_residual * inv_L_over_A_sum;
177}
178
179Real
181{
182 mooseError("Internal error, calling computeQpJacobian in AD class.");
183 return 0.0;
184}
185
186ADReal
188 const ADReal & G,
189 const ADReal & Dh,
190 const unsigned int j)
191{
192 const Moose::PointArg arg = {Point(1, 2, 3)};
193 const auto state = _is_implicit ? Moose::currentState() : Moose::oldState();
194 const auto Re = max(abs(G) * Dh / mu, 1.0e-03);
195 if (Re < 2300.0) // laminar
196 return 64.0 / Re;
197 else if (Re > 4000.0) // turbulent using Swamee-Jain approx. of Colebrook-White eq.
198 return 0.25 /
199 pow((log10((*(_roughnesses[j]))(arg, state) / (Dh * 3.7) + 5.74 / pow(Re, 0.9))), 2);
200 else // transition, conservative interpolation between the two
201 {
202 const auto f_lam_2300 = 64.0 / 2300.0;
203 const auto f_turb_4000 =
204 0.25 /
205 pow(log10((*(_roughnesses[j]))(arg, state) / (Dh * 3.7) + 5.74 / pow(4000.0, 0.9)), 2);
206 return f_lam_2300 + (f_turb_4000 - f_lam_2300) * (Re - 2300.0) / 1700.0;
207 }
208}
DualNumber< Real, DNDerivativeType, true > ADReal
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
const double mu
const double Re
const double v
const size_t _n_segments
Number of geometrically/thermally unique segments.
const unsigned int _n_fp
Number of fluid property user objects supplied.
const bool _is_implicit
Property state integration flag.
std::vector< const Moose::Functor< ADReal > * > _dZs
Height change inlet to outlet of each segment.
ADIncompressibleMomentumSPBase(const InputParameters &parameters)
virtual ADReal pressureDrop() const =0
const size_t _n_temps
Number of coupled temperature variables.
virtual ADReal computeFrictionFactor(const ADReal &mu, const ADReal &G, const ADReal &Dh, const unsigned int j)
std::vector< const Moose::Functor< ADReal > * > _perimeters
Wetted perimeter of each segment.
const Moose::Functor< ADReal > & _Pref
System reference pressure.
std::vector< const Moose::Functor< ADReal > * > _roughnesses
Wall roughness of each segment.
std::vector< const Moose::Functor< ADReal > * > _areas
Flow area of each segment.
const Moose::Functor< ADReal > & _gravity
Gravitational acceleration in the vertical downward direction.
std::vector< const Moose::Functor< ADReal > * > _forms_losses
Forms loss coefficients of each segment.
const SinglePhaseFluidProperties * _fp_ref
Pure liquid fluid properties reference (for draining problems, not for multiphase flow)
std::vector< const SinglePhaseFluidProperties * > _fp
Fluid properties per segment (non-owning pointers)
std::vector< const ADVariableValue * > _T
Coupled temperature variables.
std::vector< const Moose::Functor< ADReal > * > _dPps
Pump pressure gains of each segment.
virtual ADReal massFlowRate() const =0
std::vector< const Moose::Functor< ADReal > * > _lengths
Length of each segment.
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addCoupledVar(const std::string &name, const std::string &doc_string)
const std::string & name() const
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
const ADVariableValue & adCoupledScalarValue(const std::string &var_name, unsigned int comp=0) const
Common class for single phase fluid properties.
StateArg oldState()
StateArg currentState()
const auto acceleration_of_gravity