www.mooseframework.org
RichardsDensityVDW.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "RichardsDensityVDW.h"
11 #include "libmesh/utility.h"
12 
14 
15 template <>
16 InputParameters
18 {
19  InputParameters params = validParams<RichardsDensity>();
20  params.addRequiredRangeCheckedParam<Real>(
21  "a",
22  "a > 0",
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>(
26  "b",
27  "b > 0",
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>(
33  "molar_mass",
34  "molar_mass > 0",
35  "Molar mass of the gas. Example for methane 16.04246E-3 kg/mol");
36  params.addRangeCheckedParam<Real>("infinity_ratio",
37  10,
38  "infinity_ratio > 0",
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.");
46  return params;
47 }
48 
49 RichardsDensityVDW::RichardsDensityVDW(const InputParameters & parameters)
50  : RichardsDensity(parameters),
51  _a(getParam<Real>("a")),
52  _b(getParam<Real>("b")),
53  _rt(getParam<Real>("temperature") * 8.314472), // multiply by gas constant
54  _molar_mass(getParam<Real>("molar_mass")),
55  _infinity_ratio(getParam<Real>("infinity_ratio")),
56  _rhs(_rt * _b / _a),
57  _b2oa(_b * _b / _a)
58 {
59  _vdw0 = densityVDW(0);
61 }
62 
63 Real
65 {
66  // transform (P + a/V^2)(V-b) = RT to
67  // (y + x^2)(1/x - 1) = rhs
68  // with: y = b^2*P/a, x = b/V, rhs = RT*b/a
69  // Then solve for x, using mathematica
70  // Then density = molar_mass/V = molar_mass*x/b
71  Real y = _b2oa * p;
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);
75  Real x = 1.0 / 3.0;
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));
78  return _molar_mass * x / _b;
79 }
80 
81 Real
83 {
84  if (p >= 0)
85  return densityVDW(p) - _vdw0;
86  else
87  return _infinity_ratio * _molar_mass * (std::exp(_slope0 * p) - 1.0);
88 }
89 
90 Real
92 {
93  if (p >= 0)
94  {
95  Real y = _b2oa * p;
96  Real dy = _b2oa;
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);
102  Real dcr =
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));
107  return _molar_mass * dx / _b;
108  }
109  else
110  return _infinity_ratio * _molar_mass * _slope0 * std::exp(_slope0 * p);
111 }
112 
113 Real
115 {
116  if (p >= 0)
117  {
118  Real y = _b2oa * p;
119  Real dy = _b2oa;
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);
128  Real dcr =
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;
133  // Real dx = std::pow(2, 1.0/3.0)*( (3*dy)/3/cr + (-1 + 3*_rhs + 3*y)/3*(-dcr/cr/cr));
134  // dx -= dcr/3/std::pow(2, 1.0/3.0);
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));
140  return _molar_mass * d2x / _b;
141  }
142  else
143  return _infinity_ratio * _molar_mass * Utility::pow<2>(_slope0) * std::exp(_slope0 * p);
144 }
RichardsDensityVDW::d2density
Real d2density(Real p) const
second derivative of fluid density wrt porepressure
Definition: RichardsDensityVDW.C:114
registerMooseObject
registerMooseObject("RichardsApp", RichardsDensityVDW)
pow
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
Definition: ExpressionBuilder.h:673
RichardsDensityVDW::density
Real density(Real p) const
fluid density as a function of porepressure
Definition: RichardsDensityVDW.C:82
validParams< RichardsDensityVDW >
InputParameters validParams< RichardsDensityVDW >()
Definition: RichardsDensityVDW.C:17
RichardsDensityVDW::RichardsDensityVDW
RichardsDensityVDW(const InputParameters &parameters)
Definition: RichardsDensityVDW.C:49
RichardsDensityVDW::_b
Real _b
van der Waals b
Definition: RichardsDensityVDW.h:64
RichardsDensityVDW::_infinity_ratio
Real _infinity_ratio
density at P=-infinity is _infinity_ratio*_molar_mass
Definition: RichardsDensityVDW.h:73
RichardsDensityVDW::_rhs
Real _rhs
R*T*b/a.
Definition: RichardsDensityVDW.h:76
RichardsDensityVDW::densityVDW
Real densityVDW(Real p) const
Density according to the van der Waals expression This is modified to yield density(p) as noted above...
Definition: RichardsDensityVDW.C:64
RichardsDensityVDW::_b2oa
Real _b2oa
b^2/a
Definition: RichardsDensityVDW.h:79
RichardsDensityVDW::_molar_mass
Real _molar_mass
molar mass of gas
Definition: RichardsDensityVDW.h:70
RichardsDensityVDW.h
validParams< RichardsDensity >
InputParameters validParams< RichardsDensity >()
Definition: RichardsDensity.C:16
RichardsDensityVDW::ddensity
Real ddensity(Real p) const
derivative of fluid density wrt porepressure
Definition: RichardsDensityVDW.C:91
RichardsDensity
Base class for fluid density as a function of porepressure The functions density, ddensity and d2dens...
Definition: RichardsDensity.h:24
RichardsDensityVDW::_vdw0
Real _vdw0
density at P=0 according to the van der Waals expression
Definition: RichardsDensityVDW.h:82
RichardsDensityVDW::_slope0
Real _slope0
(1/_molar_mass)*d(density)/dP at P=0
Definition: RichardsDensityVDW.h:85
RichardsDensityVDW
Density of a gas according to the van der Waals expression (P + n^2 a/V^2)(V - nb) = nRT How density ...
Definition: RichardsDensityVDW.h:36