https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NumericsTest.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 "gtest/gtest.h"
11#include "Numerics.h"
12#include "THMTestUtils.h"
13
14TEST(NumericsTest, test_absoluteFuzzyEqualVectors_True)
15{
16 const RealVectorValue a(1.0, 2.0, 3.0);
17 const RealVectorValue b(1.0 + 1.0e-15, 2.0, 3.0);
18 EXPECT_TRUE(THM::absoluteFuzzyEqualVectors(a, b));
19}
20
21TEST(NumericsTest, test_absoluteFuzzyEqualVectors_False)
22{
23 const RealVectorValue a(1.0, 2.0, 3.0);
24 const RealVectorValue b(1.1, 2.0, 3.0);
25 EXPECT_FALSE(THM::absoluteFuzzyEqualVectors(a, b));
26}
27
28TEST(NumericsTest, test_areParallelVectors_True)
29{
30 const RealVectorValue a(1.0, 2.0, 3.0);
31 const RealVectorValue b(-2.0, -4.0, -6.0);
32 EXPECT_TRUE(THM::areParallelVectors(a, b));
33}
34
35TEST(NumericsTest, test_areParallelVectors_False)
36{
37 const RealVectorValue a(1.0, 2.0, 3.0);
38 const RealVectorValue b(2.0, 3.0, 1.0);
39 EXPECT_FALSE(THM::areParallelVectors(a, b));
40}
41
42TEST(NumericsTest, test_haveSameDirection_True)
43{
44 const RealVectorValue a(1.0, 2.0, 3.0);
45 const RealVectorValue b(2.0, 4.0, 6.0);
46 EXPECT_TRUE(THM::haveSameDirection(a, b));
47}
48
49TEST(NumericsTest, test_haveSameDirection_False)
50{
51 const RealVectorValue a(1.0, 2.0, 3.0);
52 const RealVectorValue b(-1.0, 2.0, 3.0);
53 EXPECT_FALSE(THM::haveSameDirection(a, b));
54}
55
56TEST(NumericsTest, Reynolds)
57{
58 ABS_TEST(THM::Reynolds(0.1, 999., 0.5, 2.0e-2, 0.9), 1.11, 1e-13);
59 ABS_TEST(THM::Reynolds(0.1, 999., -0.5, 2.0e-2, 0.9), 1.11, 1e-13);
60}
61
62TEST(NumericsTest, Prandtl) { ABS_TEST(THM::Prandtl(10., 0.1, 2.), 0.5, 1e-13); }
63
64TEST(NumericsTest, Peclet)
65{
66 ABS_TEST(THM::Peclet(0.1, 999., 999., 0.5, 2.0e-2, 0.9), 1108.89, 1e-13);
67}
68
69TEST(NumericsTest, Grashof)
70{
71 ABS_TEST(THM::Grashof(0.1, 1., 2.0e-2, 999., 0.05, 9.81), 3.1329247392e3, 1e-13);
72}
73
74TEST(NumericsTest, Laplace) { ABS_TEST(THM::Laplace(0.001, 1., 9.81), 0.010096375546923, 1e-13); }
75
76TEST(NumericsTest, viscosityNumber)
77{
78 ABS_TEST(THM::viscosityNumber(0.05, 0.02, 999., 2., 9.81), 0.062602188259, 1e-13);
79}
80
81TEST(NumericsTest, wallHeatTransferCoefficient)
82{
83 ABS_TEST(THM::wallHeatTransferCoefficient(2., 6., 3.), 4, 1e-13);
84}
85
86TEST(NumericsTest, Dean) { ABS_TEST(THM::Dean(1., 4.), 2, 1e-15); }
87
88TEST(NumericsTest, vel)
89{
90 const Real arhoA = 1;
91 const Real arhouA = 2;
92
93 Real vel, dvel_darhoA, dvel_darhouA;
94 THM::vel_from_arhoA_arhouA(arhoA, arhouA, vel, dvel_darhoA, dvel_darhouA);
95 ABS_TEST(vel, 2., 1e-15);
96 ABS_TEST(dvel_darhoA, -2, 1e-15);
97 ABS_TEST(dvel_darhouA, 1., 1e-15);
98
99 ABS_TEST(THM::dvel_darhoA(arhoA, arhouA), -2., 1e-15);
100 ABS_TEST(THM::dvel_darhouA(arhoA), 1., 1e-15);
101}
102
103TEST(NumericsTest, rho)
104{
105 const Real arhoA = 2;
106 const Real alpha = 0.1;
107 const Real A = 1;
108
109 Real rho, drho_darhoA, drho_dalpha;
110 THM::rho_from_arhoA_alpha_A(arhoA, alpha, A, rho, drho_darhoA, drho_dalpha);
111 ABS_TEST(rho, 20., 1e-15);
112 ABS_TEST(drho_darhoA, 10., 1e-15);
113 ABS_TEST(drho_dalpha, -200., 1e-13);
114}
115
116TEST(NumericsTest, specific_volume)
117{
118 const Real arhoA = 2;
119 const Real A = 1;
120
121 Real v, dv_drhoA;
122 THM::v_from_rhoA_A(arhoA, A, v, dv_drhoA);
123 ABS_TEST(v, 0.5, 1e-15);
124 ABS_TEST(dv_drhoA, -0.25, 1e-15);
125
126 const Real alpha = 0.1;
127 Real dv_darhoA, dv_dalpha;
128 THM::v_from_arhoA_alpha_A(arhoA, alpha, A, v, dv_darhoA, dv_dalpha);
129 ABS_TEST(v, 0.05, 1e-15);
130 ABS_TEST(dv_darhoA, -0.025, 1e-15);
131 ABS_TEST(dv_dalpha, 0.5, 1e-13);
132
133 const Real rho = 20;
134 Real dv_drho;
135 THM::v_from_rho(rho, v, dv_drho);
136 ABS_TEST(v, 0.05, 1e-15);
137 ABS_TEST(dv_darhoA, -0.025, 1e-15);
138
139 ABS_TEST(THM::dv_dalpha_liquid(A, arhoA, true), 0.5, 1e-15);
140 ABS_TEST(THM::dv_dalpha_liquid(A, arhoA, false), -0.5, 1e-15);
141
142 ABS_TEST(THM::dv_darhoA(A, arhoA), -0.25, 1e-15);
143}
144
145TEST(NumericsTest, internal_energy)
146{
147 const Real arhoA = 2;
148 const Real arhouA = 4;
149 const Real arhoEA = 8;
150
151 Real e, de_darhoA, de_darhouA, de_darhoEA;
152 THM::e_from_arhoA_arhouA_arhoEA(arhoA, arhouA, arhoEA, e, de_darhoA, de_darhouA, de_darhoEA);
153 ABS_TEST(e, 2., 1e-15);
154 ABS_TEST(de_darhoA, 0., 1e-15);
155 ABS_TEST(de_darhouA, -1., 1e-15);
156 ABS_TEST(de_darhoEA, 0.5, 1e-15);
157
158 const Real E = 10;
159 const Real vel = 2;
160 Real de_dE, de_dvel;
161 THM::e_from_E_vel(E, vel, e, de_dE, de_dvel);
162 ABS_TEST(e, 8., 1e-15);
163 ABS_TEST(de_dE, 1., 1e-15);
164 ABS_TEST(de_dvel, -2., 1e-15);
165
166 ABS_TEST(THM::de_darhoA(arhoA, arhouA, arhoEA), 0., 1e-15);
167 ABS_TEST(THM::de_darhouA(arhoA, arhouA), -1., 1e-15);
168 ABS_TEST(THM::de_darhoEA(arhoA), 0.5, 1e-15);
169}
170
171TEST(NumericsTest, total_energy)
172{
173 const Real arhoA = 2.;
174 const Real arhoEA = 8.;
175
176 Real E, dE_darhoA, dE_darhoEA;
177 THM::E_from_arhoA_arhoEA(arhoA, arhoEA, E, dE_darhoA, dE_darhoEA);
178 ABS_TEST(E, 4., 1e-15);
179 ABS_TEST(dE_darhoA, -2., 1e-15);
180 ABS_TEST(dE_darhoEA, 0.5, 1e-15);
181
182 const Real e = 4.;
183 const Real vel = 2.;
184
185 Real dE_de, dE_dvel;
186 THM::E_from_e_vel(e, vel, E, dE_de, dE_dvel);
187
188 ABS_TEST(E, 6., 1e-15);
189 ABS_TEST(dE_de, 1., 1e-15);
190 ABS_TEST(dE_dvel, 2., 1e-15);
191}
192
193TEST(NumericsTest, specific_enthalpy)
194{
195 const Real e = 6;
196 const Real p = 4;
197 const Real rho = 2;
198
199 Real h, dh_de, dh_dp, dh_drho;
200 THM::h_from_e_p_rho(e, p, rho, h, dh_de, dh_dp, dh_drho);
201 ABS_TEST(h, 8., 1e-15);
202 ABS_TEST(dh_de, 1., 1e-15);
203 ABS_TEST(dh_dp, 0.5, 1e-15);
204 ABS_TEST(dh_drho, -1., 1e-15);
205}
206
207TEST(NumericsTest, xlets)
208{
209 EXPECT_FALSE(THM::isInlet(2, 1));
210 EXPECT_TRUE(THM::isInlet(2, -1));
211 EXPECT_TRUE(THM::isInlet(-2, 1));
212 EXPECT_FALSE(THM::isInlet(-2, -1));
213
214 EXPECT_TRUE(THM::isOutlet(2, 1));
215 EXPECT_FALSE(THM::isOutlet(2, -1));
216 EXPECT_FALSE(THM::isOutlet(-2, 1));
217 EXPECT_TRUE(THM::isOutlet(-2, -1));
218}
const Real p
const double rho
const double v
TEST(NumericsTest, test_absoluteFuzzyEqualVectors_True)
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
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
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
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
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