https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Numerics.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
10#include "Numerics.h"
11#include "MooseUtils.h"
12#include "ADReal.h"
13
14namespace THM
15{
16
17bool
18absoluteFuzzyEqualVectors(const RealVectorValue & a, const RealVectorValue & b, const Real & tol)
19{
20 return MooseUtils::absoluteFuzzyEqual(a(0), b(0), tol) &&
21 MooseUtils::absoluteFuzzyEqual(a(1), b(1), tol) &&
22 MooseUtils::absoluteFuzzyEqual(a(2), b(2), tol);
23}
24
25bool
26areParallelVectors(const RealVectorValue & a, const RealVectorValue & b, const Real & tol)
27{
28 const RealVectorValue c = a.cross(b);
29 return absoluteFuzzyEqualVectors(c, RealVectorValue(0, 0, 0), tol);
30}
31
32bool
33haveSameDirection(const RealVectorValue & a, const RealVectorValue & b, const Real & tol)
34{
35 return areParallelVectors(a, b, tol) && a * b > 0;
36}
37
38Real
39applyQuotientRule(const Real & num, const Real & den, const Real & dnum_dy, const Real & dden_dy)
40{
41 return (dnum_dy * den - num * dden_dy) / (den * den);
42}
43
44DenseVector<Real>
45applyQuotientRule(const Real & num,
46 const Real & den,
47 const DenseVector<Real> & dnum_dy,
48 const DenseVector<Real> & dden_dy)
49{
50 DenseVector<Real> d_dy = dnum_dy;
51 d_dy *= 1.0 / den;
52 d_dy.add(-num / std::pow(den, 2), dden_dy);
53
54 return d_dy;
55}
56
57void
58vel_from_arhoA_arhouA(Real arhoA, Real arhouA, Real & vel, Real & dvel_darhoA, Real & dvel_darhouA)
59{
60 vel = arhouA / arhoA;
61 dvel_darhoA = -arhouA / (arhoA * arhoA);
62 dvel_darhouA = 1.0 / arhoA;
63}
64
67{
68 return arhouA / arhoA;
69}
70
71Real
72dvel_darhoA(Real arhoA, Real arhouA)
73{
74 return -arhouA / (arhoA * arhoA);
75}
76
77Real
78dvel_darhouA(Real arhoA)
79{
80 return 1.0 / arhoA;
81}
82
83void
85 Real arhoA, Real alpha, Real A, Real & rho, Real & drho_darhoA, Real & drho_dalpha)
86{
87 rho = arhoA / (alpha * A);
88
89 drho_darhoA = 1.0 / (alpha * A);
90 drho_dalpha = -arhoA / (alpha * alpha * A);
91}
92
95{
96 return arhoA / (alpha * A);
97}
98
99void
100v_from_rhoA_A(Real rhoA, Real A, Real & v, Real & dv_drhoA)
101{
102 v = A / rhoA;
103 dv_drhoA = -A / (rhoA * rhoA);
104}
105
106ADReal
108{
109 return A / rhoA;
110}
111
112void
113v_from_arhoA_alpha_A(Real arhoA, Real alpha, Real A, Real & v, Real & dv_darhoA, Real & dv_dalpha)
114{
115 v = (alpha * A) / arhoA;
116 dv_darhoA = -(alpha * A) / (arhoA * arhoA);
117 dv_dalpha = A / arhoA;
118}
119
120ADReal
122{
123 return (alpha * A) / arhoA;
124}
125
126void
127v_from_rho(Real rho, Real & v, Real & dv_drho)
128{
129 v = 1.0 / rho;
130 dv_drho = -1.0 / (rho * rho);
131}
132
133Real
134dv_dalpha_liquid(Real area, Real arhoA, bool is_liquid)
135{
136 const Real sign = is_liquid ? 1.0 : -1.0;
137 return sign * (area / arhoA);
138}
139
140Real
141dv_darhoA(Real area, Real arhoA)
142{
143 return -area / arhoA / arhoA;
144}
145
146void
148 Real arhouA,
149 Real arhoEA,
150 Real & e,
151 Real & de_darhoA_val,
152 Real & de_darhouA_val,
153 Real & de_darhoEA_val)
154{
155 e = arhoEA / arhoA - 0.5 * arhouA * arhouA / (arhoA * arhoA);
156 de_darhoA_val = de_darhoA(arhoA, arhouA, arhoEA);
157 de_darhouA_val = de_darhouA(arhoA, arhouA);
158 de_darhoEA_val = de_darhoEA(arhoA);
159}
160
161ADReal
163{
164 return arhoEA / arhoA - 0.5 * arhouA * arhouA / (arhoA * arhoA);
165}
166
167void
168e_from_E_vel(Real E, Real vel, Real & e, Real & de_dE, Real & de_dvel)
169{
170 e = E - 0.5 * vel * vel;
171 de_dE = 1;
172 de_dvel = -vel;
173}
174ADReal
176{
177 return E - 0.5 * vel * vel;
178}
179
180Real
181de_darhoA(Real arhoA, Real arhouA, Real arhoEA)
182{
183 return (-arhoEA / arhoA / arhoA + arhouA * arhouA / arhoA / arhoA / arhoA);
184}
185
186Real
187de_darhouA(Real arhoA, Real arhouA)
188{
189 return (-arhouA / arhoA / arhoA);
190}
191
192Real
193de_darhoEA(Real arhoA)
194{
195 return (1 / arhoA);
196}
197
198void
199E_from_arhoA_arhoEA(Real arhoA, Real arhoEA, Real & E, Real & dE_darhoA, Real & dE_darhoEA)
200{
201 E = arhoEA / arhoA;
202 dE_darhoA = -arhoEA / (arhoA * arhoA);
203 dE_darhoEA = 1.0 / arhoA;
204}
205ADReal
207{
208 return arhoEA / arhoA;
209}
210
211void
212E_from_e_vel(Real e, Real vel, Real & E, Real & dE_de, Real & dE_dvel)
213{
214 E = e + 0.5 * vel * vel;
215 dE_de = 1.0;
216 dE_dvel = vel;
217}
218
219void
220h_from_e_p_rho(Real e, Real p, Real rho, Real & h, Real & dh_de, Real & dh_dp, Real & dh_drho)
221{
222 h = e + p / rho;
223 dh_de = 1.0;
224 dh_dp = 1.0 / rho;
225 dh_drho = -p / (rho * rho);
226}
227
228ADReal
230{
231 return e + p / rho;
232}
233
234bool
235isInlet(Real vel, Real normal)
236{
237 return (vel * normal) < 0;
238}
239
240bool
241isInlet(ADReal vel, Real normal)
242{
243 return (MetaPhysicL::raw_value(vel) * normal) < 0;
244}
245
246bool
247isOutlet(Real vel, Real normal)
248{
249 return (vel * normal) >= 0;
250}
251
252bool
253isOutlet(ADReal vel, Real normal)
254{
255 return (MetaPhysicL::raw_value(vel) * normal) >= 0;
256}
257
258} // namespace THM
DualNumber< Real, DNDerivativeType, true > ADReal
const double tol
const Real p
const double rho
const double v
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const
auto raw_value(const Eigen::Map< T > &in)
void v_from_rhoA_A(Real rhoA, Real A, Real &v, Real &dv_drhoA)
Computes specific volume and its derivatives from rho*A, and area.
Definition Numerics.C:100
Real dv_dalpha_liquid(Real area, Real arhoA, bool is_liquid)
Derivative of specific volume wrt alpha_liquid.
Definition Numerics.C:134
bool haveSameDirection(const RealVectorValue &a, const RealVectorValue &b, const Real &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Tests if two real-valued vectors are in the same direction.
bool isOutlet(Real vel, Real normal)
Determine if outlet boundary condition should be applied.
Definition Numerics.C:247
bool absoluteFuzzyEqualVectors(const RealVectorValue &a, const RealVectorValue &b, const Real &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Tests if two real-valued vectors are equal within some absolute tolerance.
void v_from_rho(Real rho, Real &v, Real &dv_drho)
Computes specific volume and its derivative with respect to density.
Definition Numerics.C:127
Real dv_darhoA(Real area, Real arhoA)
Derivative of specific volume wrt density equation solution variable.
Definition Numerics.C:141
void h_from_e_p_rho(Real e, Real p, Real rho, Real &h, Real &dh_de, Real &dh_dp, Real &dh_drho)
Computes specific enthalpy and its derivatives from specific internal energy, pressure,...
Definition Numerics.C:220
Real dvel_darhoA(Real arhoA, Real arhouA)
Derivative of velocity w.r.t.
Definition Numerics.C:72
bool isInlet(Real vel, Real normal)
Determine if inlet boundary condition should be applied.
Definition Numerics.C:235
Real de_darhouA(Real arhoA, Real arhouA)
Derivative of specific internal energy wrt momentum of the phase (rhouA or arhouA)
Definition Numerics.C:187
Real dvel_darhouA(Real arhoA)
Derivative of velocity w.r.t.
Definition Numerics.C:78
void v_from_arhoA_alpha_A(Real arhoA, Real alpha, Real A, Real &v, Real &dv_darhoA, Real &dv_dalpha)
Computes specific volume and its derivatives from alpha*rho*A, volume fraction, and area.
Definition Numerics.C:113
Real applyQuotientRule(const Real &num, const Real &den, const Real &dnum_dy, const Real &dden_dy)
Computes a derivative of a fraction using quotient rule for a derivative w.r.t.
Definition Numerics.C:39
void rho_from_arhoA_alpha_A(Real arhoA, Real alpha, Real A, Real &rho, Real &drho_darhoA, Real &drho_dalpha)
Computes density and its derivatives from alpha*rho*A, alpha, and area.
Definition Numerics.C:84
void E_from_arhoA_arhoEA(Real arhoA, Real arhoEA, Real &E, Real &dE_darhoA, Real &dE_darhoEA)
Computes specific total energy and its derivatives from alpha*rho*A and alpha*rho*E*A.
Definition Numerics.C:199
Real de_darhoEA(Real arhoA)
Derivative of specific internal energy wrt total energy of the phase (rhoEA or arhoEA)
Definition Numerics.C:193
void e_from_arhoA_arhouA_arhoEA(Real arhoA, Real arhouA, Real arhoEA, Real &e, Real &de_darhoA, Real &de_darhouA, Real &de_darhoEA)
Computes specific internal energy and its derivatives from alpha*rho*A, alpha*rho*u*A,...
Definition Numerics.C:147
void E_from_e_vel(Real e, Real vel, Real &E, Real &dE_de, Real &dE_dvel)
Computes specific total energy and its derivatives from specific internal energy and velocity.
Definition Numerics.C:212
void vel_from_arhoA_arhouA(Real arhoA, Real arhouA, Real &vel, Real &dvel_darhoA, Real &dvel_darhouA)
Computes velocity and its derivatives from alpha*rho*A and alpha*rho*u*A.
Definition Numerics.C:58
Real de_darhoA(Real arhoA, Real arhouA, Real arhoEA)
Derivative of specific internal energy wrt density of the phase (rhoA or arhoA)
Definition Numerics.C:181
bool areParallelVectors(const RealVectorValue &a, const RealVectorValue &b, const Real &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Tests if two real-valued vectors are parallel within some absolute tolerance.
void e_from_E_vel(Real E, Real vel, Real &e, Real &de_dE, Real &de_dvel)
Computes specific internal energy and its derivatives from specific total energy and velocity.
Definition Numerics.C:168