https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Numerics.h
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#pragma once
11
12#include "libmesh/libmesh_common.h"
13#include "libmesh/vector_value.h"
14#include "libmesh/dense_vector.h"
15
16#include "ADReal.h"
17#include "NavierStokesMethods.h"
18#include "HeatTransferUtils.h"
19
20namespace THM
21{
22
23// Default value for magnitude of acceleration due to gravity
24static const Real gravity_const = 9.81;
25
26// Default value for gravitational acceleration vector
27static VectorValue<Real> default_gravity_vector = VectorValue<Real>(0.0, 0.0, -gravity_const);
28
29// Stefan-Boltzman constant, in [W/m^2-K]
30static const Real Stefan_Boltzman_const = 5.670e-8;
31
37template <typename T>
38int
39sgn(T val)
40{
41 return (T(0) < val) - (val < T(0));
42}
43
51bool absoluteFuzzyEqualVectors(const RealVectorValue & a,
52 const RealVectorValue & b,
54
62bool areParallelVectors(const RealVectorValue & a,
63 const RealVectorValue & b,
65
73bool haveSameDirection(const RealVectorValue & a,
74 const RealVectorValue & b,
76
86Real
87applyQuotientRule(const Real & num, const Real & den, const Real & dnum_dy, const Real & dden_dy);
88
98DenseVector<Real> applyQuotientRule(const Real & num,
99 const Real & den,
100 const DenseVector<Real> & dnum_dy,
101 const DenseVector<Real> & dden_dy);
102
114template <typename T1, typename T2, typename T3, typename T4, typename T5>
115auto
116Reynolds(const T1 & volume_fraction, const T2 & rho, const T3 & vel, const T4 & D_h, const T5 & mu)
117{
118 return volume_fraction * HeatTransferUtils::reynolds(rho, vel, D_h, mu);
119}
120
129template <typename T1, typename T2, typename T3>
130auto
131Prandtl(const T1 & cp, const T2 & mu, const T3 & k)
132{
133 return HeatTransferUtils::prandtl(cp, mu, k);
134}
135
149template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
150auto
151Peclet(const T1 & volume_fraction,
152 const T2 & cp,
153 const T3 & rho,
154 const T4 & vel,
155 const T5 & D_h,
156 const T6 & k)
157{
158 const auto diffusivity = HeatTransferUtils::thermalDiffusivity(k, rho, cp);
159 return volume_fraction * HeatTransferUtils::peclet(vel, D_h, diffusivity);
160}
161
174template <typename T1, typename T2, typename T3, typename T4, typename T5>
175auto
176Grashof(const T1 & beta,
177 const T2 & dT,
178 const T3 & D_h,
179 const T4 & rho_liquid,
180 const T5 & mu_liquid,
181 const Real & gravity_magnitude)
182{
183 using std::pow;
184 return gravity_magnitude * beta * dT * pow(D_h, 3) * (rho_liquid * rho_liquid) /
185 (mu_liquid * mu_liquid);
186}
187
197template <typename T1, typename T2>
198auto
199Laplace(const T1 & surf_tension, const T2 & delta_rho, const Real & gravity_magnitude)
200{
201 using std::sqrt;
202 return sqrt(surf_tension / (gravity_magnitude * delta_rho));
203}
204
216template <typename T1, typename T2, typename T3, typename T4>
217auto
218viscosityNumber(const T1 & viscosity,
219 const T2 & surf_tension,
220 const T3 & rho_k,
221 const T4 & delta_rho,
222 const Real & gravity_magnitude)
223{
224 using std::sqrt;
225 return viscosity /
226 sqrt(rho_k * surf_tension * sqrt(surf_tension / gravity_magnitude / delta_rho));
227}
228
230
238template <typename T1, typename T2>
239auto
240Dean(const T1 & Re, const T2 & doD)
241{
242 using std::sqrt;
243 return Re * sqrt(doD);
244}
245
255void
256vel_from_arhoA_arhouA(Real arhoA, Real arhouA, Real & vel, Real & dvel_darhoA, Real & dvel_darhouA);
257
266
274Real dvel_darhoA(Real arhoA, Real arhouA);
275
282Real dvel_darhouA(Real arhoA);
283
295 Real arhoA, Real alpha, Real A, Real & rho, Real & drho_darhoA, Real & drho_dalpha);
296
306
314void v_from_rhoA_A(Real rhoA, Real A, Real & v, Real & dv_drhoA);
315
324
334void
335v_from_arhoA_alpha_A(Real arhoA, Real alpha, Real A, Real & v, Real & dv_darhoA, Real & dv_dalpha);
336
346
354void v_from_rho(Real rho, Real & v, Real & dv_drho);
355
364Real dv_dalpha_liquid(Real area, Real arhoA, bool is_liquid);
365
372Real dv_darhoA(Real area, Real arhoA);
373
386void e_from_arhoA_arhouA_arhoEA(Real arhoA,
387 Real arhouA,
388 Real arhoEA,
389 Real & e,
390 Real & de_darhoA,
391 Real & de_darhouA,
392 Real & de_darhoEA);
393
395
405void e_from_E_vel(Real E, Real vel, Real & e, Real & de_dE, Real & de_dvel);
406
415
423Real de_darhoA(Real arhoA, Real arhouA, Real arhoEA);
424
431Real de_darhouA(Real arhoA, Real arhouA);
432
438Real de_darhoEA(Real arhoA);
439
449void E_from_arhoA_arhoEA(Real arhoA, Real arhoEA, Real & E, Real & dE_darhoA, Real & dE_darhoEA);
450
459
469void E_from_e_vel(Real e, Real vel, Real & E, Real & dE_de, Real & dE_dvel);
470
483void h_from_e_p_rho(Real e, Real p, Real rho, Real & h, Real & dh_de, Real & dh_dp, Real & dh_drho);
484
486
494bool isInlet(Real vel, Real normal);
495bool isInlet(ADReal vel, Real normal);
496
504bool isOutlet(Real vel, Real normal);
505bool isOutlet(ADReal vel, Real normal);
506}
DualNumber< Real, DNDerivativeType, true > ADReal
const double tol
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
const double mu
const Real p
const double Re
const double rho
const double T
const double v
auto peclet(const T1 &vel, const T2 &L, const T3 &diffusivity)
Compute Peclet number.
auto reynolds(const T1 &rho, const T2 &vel, const T3 &L, const T4 &mu)
Compute Reynolds number.
auto prandtl(const T1 &cp, const T2 &mu, const T3 &k)
Compute Prandtl number.
auto thermalDiffusivity(const T1 &k, const T2 &rho, const T3 &cp)
Compute thermal diffusivity.
auto wallHeatTransferCoefficient(const T1 &Nu, const T2 &k, const T3 &D_h)
Compute wall heat transfer coefficient.
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
int sgn(T val)
The sign function.
Definition Numerics.h:39
Real dv_dalpha_liquid(Real area, Real arhoA, bool is_liquid)
Derivative of specific volume wrt alpha_liquid.
Definition Numerics.C:134
auto viscosityNumber(const T1 &viscosity, const T2 &surf_tension, const T3 &rho_k, const T4 &delta_rho, const Real &gravity_magnitude)
Compute viscosity number (or coefficient)
Definition Numerics.h:218
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.
Definition Numerics.C:33
bool isOutlet(Real vel, Real normal)
Determine if outlet boundary condition should be applied.
Definition Numerics.C:247
auto Prandtl(const T1 &cp, const T2 &mu, const T3 &k)
Compute Prandtl number.
Definition Numerics.h:131
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.
Definition Numerics.C:18
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
static const Real Stefan_Boltzman_const
Definition Numerics.h:30
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
auto Laplace(const T1 &surf_tension, const T2 &delta_rho, const Real &gravity_magnitude)
Compute Laplace number (or coefficient)
Definition Numerics.h:199
auto Reynolds(const T1 &volume_fraction, const T2 &rho, const T3 &vel, const T4 &D_h, const T5 &mu)
Compute Reynolds number.
Definition Numerics.h:116
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
auto Grashof(const T1 &beta, const T2 &dT, const T3 &D_h, const T4 &rho_liquid, const T5 &mu_liquid, const Real &gravity_magnitude)
Compute Grashof number.
Definition Numerics.h:176
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.
Definition Numerics.C:26
auto Peclet(const T1 &volume_fraction, const T2 &cp, const T3 &rho, const T4 &vel, const T5 &D_h, const T6 &k)
Compute Peclet number.
Definition Numerics.h:151
auto Dean(const T1 &Re, const T2 &doD)
Compute Dean number.
Definition Numerics.h:240
static VectorValue< Real > default_gravity_vector
Definition Numerics.h:27
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
static const Real gravity_const
Definition Numerics.h:24
static constexpr Real TOLERANCE