11 #include "libmesh/utility.h"
20 params.addRequiredRangeCheckedParam<Real>(
23 "Parameter 'a' in the van der Waals expression (P + n^2 a/V^2)(V - nb) = nRT. "
24 "Example for methane 0.2303 Pa m^6 mol^-2");
25 params.addRequiredRangeCheckedParam<Real>(
28 "Parameter 'b' in the van der Waals expression (P + n^2 a/V^2)(V - nb) = nRT. "
29 "Example for methane 4.31E-5 m^3/mol");
30 params.addRequiredRangeCheckedParam<Real>(
31 "temperature",
"temperature > 0",
"Temperature in Kelvin");
32 params.addRequiredRangeCheckedParam<Real>(
35 "Molar mass of the gas. Example for methane 16.04246E-3 kg/mol");
36 params.addRangeCheckedParam<Real>(
"infinity_ratio",
39 "For P<0 the density is not physically defined, "
40 "but numerically it is advantageous to define "
41 "it: density(P=-infinity) = "
42 "-infinity_ratio*molar_mass, and density tends "
43 "exponentially towards this value as P -> "
44 "-infinity. (Units are mol/m^3).");
45 params.addClassDescription(
"Density of van der Waals gas.");
51 _a(getParam<Real>(
"a")),
52 _b(getParam<Real>(
"b")),
53 _rt(getParam<Real>(
"temperature") * 8.314472),
54 _molar_mass(getParam<Real>(
"molar_mass")),
55 _infinity_ratio(getParam<Real>(
"infinity_ratio")),
72 Real sq = std::sqrt(4.0 * Utility::pow<3>(-1.0 + 3.0 * y + 3.0 *
_rhs) +
73 Utility::pow<2>(-2.0 - 18.0 * y + 9.0 *
_rhs));
74 Real cr = std::cbrt(-2.0 + 9.0 *
_rhs - 18.0 * y + sq);
76 x += std::cbrt(2.0) * (-1.0 + 3.0 *
_rhs + 3.0 * y) / (3.0 * cr);
77 x -= cr / (3.0 * std::cbrt(2.0));
97 Real sq = std::sqrt(4.0 * Utility::pow<3>(-1.0 + 3.0 * y + 3.0 *
_rhs) +
98 Utility::pow<2>(-2.0 - 18.0 * y + 9.0 *
_rhs));
99 Real dsq = 0.5 / sq * (4.0 * 3.0 * Utility::pow<2>(-1.0 + 3.0 * y + 3.0 *
_rhs) * 3.0 * dy +
100 2.0 * (-2.0 - 18.0 * y + 9.0 *
_rhs) * (-18.0 * dy));
101 Real cr = std::cbrt(-2.0 + 9.0 *
_rhs - 18.0 * y + sq);
103 1.0 / 3.0 *
std::pow(-2.0 + 9.0 *
_rhs - 18.0 * y + sq, -2.0 / 3.0) * (-18.0 * dy + dsq);
104 Real dx = std::cbrt(2.0) *
105 ((3.0 * dy) / (3.0 * cr) + (-1.0 + 3.0 *
_rhs + 3.0 * y) / 3.0 * (-dcr / (cr * cr)));
106 dx -= dcr / (3.0 * std::cbrt(2.0));
120 Real sq = std::sqrt(4.0 * Utility::pow<3>(-1.0 + 3.0 * y + 3.0 *
_rhs) +
121 Utility::pow<2>(-2.0 - 18.0 * y + 9.0 *
_rhs));
122 Real dsq = 0.5 / sq * (4.0 * 3.0 * Utility::pow<2>(-1.0 + 3.0 * y + 3.0 *
_rhs) * 3.0 * dy +
123 2.0 * (-2.0 - 18.0 * y + 9.0 *
_rhs) * (-18.0 * dy));
124 Real d2sq = -dsq * dsq / sq;
125 d2sq += 0.5 / sq * (4.0 * 3.0 * 2.0 * (-1.0 + 3.0 * y + 3.0 *
_rhs) * 3.0 * dy * 3.0 * dy +
126 2.0 * (-18.0 * dy) * (-18.0 * dy));
127 Real cr = std::cbrt(-2.0 + 9.0 *
_rhs - 18.0 * y + sq);
129 1.0 / 3.0 *
std::pow(-2.0 + 9.0 *
_rhs - 18.0 * y + sq, -2.0 / 3.0) * (-18.0 * dy + dsq);
130 Real d2cr = 1.0 / 3.0 * (-2.0 / 3.0) *
std::pow(-2 + 9 *
_rhs - 18 * y + sq, -5. / 3.) *
131 Utility::pow<2>(-18 * dy + dsq);
132 d2cr += 1.0 / 3.0 *
std::pow(-2 + 9 *
_rhs - 18 * y + sq, -2. / 3.) * d2sq;
135 Real d2x = std::cbrt(2.0) *
136 (-(3.0 * dy) * dcr / (3.0 * cr * cr) + 3.0 * dy / 3.0 * (-dcr / (cr * cr)) +
137 (-1.0 + 3.0 *
_rhs + 3.0 * y) / 3.0 *
138 (-d2cr / (cr * cr) + 2.0 * dcr * dcr / Utility::pow<3>(cr)));
139 d2x -= d2cr / (3.0 * std::cbrt(2.0));