GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/material/components/simpleco2.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 37 50 74.0%
Functions: 1 4 25.0%
Branches: 22 42 52.4%

Line Branch Exec Source
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 //
4 // SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 /*!
8 * \file
9 * \ingroup Components
10 * \brief A much simpler (and thus potentially less buggy) version of
11 * pure CO2.
12 */
13 #ifndef DUMUX_SIMPLE_CO2_HH
14 #define DUMUX_SIMPLE_CO2_HH
15
16 #include <dune/common/stdstreams.hh>
17
18 #include <dumux/common/parameters.hh>
19 #include <dumux/material/idealgas.hh>
20
21 #include <cmath>
22
23 #include <dumux/material/components/base.hh>
24 #include <dumux/material/components/gas.hh>
25
26 namespace Dumux::Components {
27
28 /*!
29 * \ingroup Components
30 * \brief A simple version of pure CO2
31 *
32 * \tparam Scalar The type used for scalar values
33 */
34 template <class Scalar>
35 class SimpleCO2
36 : public Components::Base<Scalar, SimpleCO2<Scalar> >
37 , public Components::Gas<Scalar, SimpleCO2<Scalar> >
38 {
39 using IdealGas = Dumux::IdealGas<Scalar>;
40
41 public:
42 /*!
43 * \brief A human readable name for the CO2.
44 */
45 static std::string name()
46
20/40
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
10 { return "SimpleCO2"; }
47
48 /*!
49 * \brief The mass in \f$\mathrm{[kg/mol]}\f$ of one mole of CO2.
50 */
51 static constexpr Scalar molarMass()
52 { return 44.0e-3; /* [kg/mol] */ }
53
54 /*!
55 * \brief Returns the critical temperature \f$\mathrm{[K]}\f$ of CO2
56 */
57 static Scalar criticalTemperature()
58 { return 273.15 + 30.95; /* [K] */ }
59
60 /*!
61 * \brief Returns the critical pressure \f$\mathrm{[Pa]}\f$ of CO2
62 */
63 static Scalar criticalPressure()
64 { return 73.8e5; /* [Pa] */ }
65
66 /*!
67 * \brief Returns the temperature \f$\mathrm{[K]}\f$ at CO2's triple point.
68 */
69 static Scalar tripleTemperature()
70 { return 273.15 - 56.35; /* [K] */ }
71
72 /*!
73 * \brief Returns the pressure \f$\mathrm{[Pa]}\f$ at CO2's triple point.
74 */
75 static Scalar triplePressure()
76 { return 5.11e5; /* [N/m^2] */ }
77
78
79 /*!
80 * \brief Specific enthalpy of CO2 \f$\mathrm{[J/kg]}\f$.
81 * source: Shomate Equation for a temperature range of 298. to 1200K.
82 * with components published by NIST \cite NIST
83 * https://webbook.nist.gov/cgi/cbook.cgi?ID=C124389&Mask=1&Type=JANAFG&Table=on
84 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
85 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
86 */
87 static const Scalar gasEnthalpy(Scalar temperature,
88 Scalar pressure)
89 {
90 const Scalar t = temperature/1000;
91 constexpr double a = 24.99735;
92 constexpr double b = 55.18696;
93 constexpr double c = -33.69137;
94 constexpr double d = 7.948387;
95 constexpr double e = -0.136638;
96 constexpr double f = -403.6075;
97 constexpr double h = -393.5224;
98 return (a*t + b*t*t/2 + c*t*t*t/3 + d*t*t*t*t/4 - e/t +f -h)*1000/molarMass(); //conversion from kJ/mol to J/kg
99 }
100
101 /*!
102 * \brief Specific internal energy of CO2 \f$\mathrm{[J/kg]}\f$.
103 *
104 * Definition of enthalpy: \f$h= u + pv = u + p / \rho\f$.
105 * Rearranging for internal energy yields: \f$u = h - pv\f$.
106 * Exploiting the Ideal Gas assumption (\f$pv = R_{\textnormal{specific}} T\f$)gives: \f$u = h - R / M T \f$.
107 *
108 * The universal gas constant can only be used in the case of molar formulations.
109 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
110 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
111 */
112 static const Scalar gasInternalEnergy(Scalar temperature,
113 Scalar pressure)
114 {
115 // 1/molarMass: conversion from [J/(mol K)] to [J/(kg K)]
116 // R*T/molarMass: pressure *spec. volume for an ideal gas
117 return gasEnthalpy(temperature, pressure)
118 - 1.0/molarMass()*IdealGas::R*temperature;
119 }
120
121 /*!
122 * \brief Returns true if the gas phase is assumed to be compressible
123 */
124 static constexpr bool gasIsCompressible()
125 { return true; }
126
127 /*!
128 * \brief Returns true if the gas phase viscostiy is constant
129 */
130 static constexpr bool gasViscosityIsConstant()
131 { return false; }
132
133 /*!
134 * \brief The density \f$\mathrm{[kg/m^3]}\f$ of CO2 at a given pressure and temperature.
135 *
136 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
137 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
138 */
139 static Scalar gasDensity(Scalar temperature, Scalar pressure)
140 5191746 { return IdealGas::density(molarMass(), temperature, pressure); }
141
142 /*!
143 * \brief The molar density of CO2 in \f$\mathrm{[mol/m^3]}\f$ at a given pressure and temperature.
144 *
145 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
146 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
147 *
148 */
149 static Scalar gasMolarDensity(Scalar temperature, Scalar pressure)
150 5191544 { return IdealGas::molarDensity(temperature, pressure); }
151
152 /*!
153 * \brief Returns true if the gas phase is assumed to be ideal
154 */
155 static constexpr bool gasIsIdeal()
156 { return true; }
157
158 /*!
159 * \brief The pressure of CO2 in \f$\mathrm{[Pa]}\f$ at a given density and temperature.
160 *
161 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
162 * \param density density of component in \f$\mathrm{[kg/m^3]}\f$
163 */
164 static Scalar gasPressure(Scalar temperature, Scalar density)
165 { return IdealGas::pressure(temperature, density/molarMass()); }
166
167 /*!
168 * \brief The dynamic viscosity \f$\mathrm{[Pa*s]}\f$ of CO2.
169 * Equations given in: - Vesovic et al., 1990
170 * - Fenhour et al., 1998
171 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
172 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
173 * TODO: this does not look like a really "simple" parameterization. Can this be simplified further?
174 */
175 5191645 static Scalar gasViscosity(Scalar temperature, Scalar pressure)
176 {
177 5191645 constexpr double a0 = 0.235156;
178 5191645 constexpr double a1 = -0.491266;
179 5191645 constexpr double a2 = 5.211155E-2;
180 5191645 constexpr double a3 = 5.347906E-2;
181 5191645 constexpr double a4 = -1.537102E-2;
182
183 5191645 constexpr double d11 = 0.4071119E-2;
184 5191645 constexpr double d21 = 0.7198037E-4;
185 5191645 constexpr double d64 = 0.2411697E-16;
186 5191645 constexpr double d81 = 0.2971072E-22;
187 5191645 constexpr double d82 = -0.1627888E-22;
188
189 5191645 constexpr double ESP = 251.196;
190
191
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5191641 times.
5191645 if(temperature < 275.0) // regularisation
192 {
193 4 temperature = 275.0;
194 4 Dune::dgrave << "Temperature below 275K in viscosity function:"
195 4 << "Regularizing temperature to 275K. " << std::endl;
196 }
197
198
199 5191645 const double TStar = temperature/ESP;
200
201 /* mu0: viscosity in zero-density limit */
202 using std::exp;
203 using std::log;
204 using std::sqrt;
205 5191645 const double logTStar = log(TStar);
206 10383290 const double SigmaStar = exp(a0 + a1*logTStar
207 5191645 + a2*logTStar*logTStar
208 5191645 + a3*logTStar*logTStar*logTStar
209 5191645 + a4*logTStar*logTStar*logTStar*logTStar );
210 5191645 const double mu0 = 1.00697*sqrt(temperature) / SigmaStar;
211
212 /* dmu : excess viscosity at elevated density */
213 5191645 const double rho = gasDensity(temperature, pressure); /* CO2 mass density [kg/m^3] */
214
215 using Dune::power;
216 5191645 const double dmu = d11*rho + d21*rho*rho + d64*power(rho, 6)/(TStar*TStar*TStar)
217 10383290 + d81*power(rho, 8) + d82*power(rho, 8)/TStar;
218
219 5191645 return (mu0 + dmu)/1.0E6; /* conversion to [Pa s] */
220 }
221
222
223 /*!
224 * \brief Thermal conductivity \f$\mathrm{[[W/(m*K)]}\f$ of CO2.
225 *
226 * Thermal conductivity of CO2 at T=20°C, see:
227 * http://www.engineeringtoolbox.com/carbon-dioxide-d_1000.html
228 *
229 * \param temperature absolute temperature in \f$\mathrm{[K]}\f$
230 * \param pressure of the phase in \f$\mathrm{[Pa]}\f$
231 */
232 static Scalar gasThermalConductivity(Scalar temperature, Scalar pressure)
233 {
234 return 0.087;
235 }
236
237 /*!
238 * \brief Specific isobaric heat capacity of CO2 \f$\mathrm{[J/(kg*K)]}\f$.
239 * source: Shomate Equation for a temperature range of 298. to 1200K.
240 * with components published by NIST \cite NIST
241 * https://webbook.nist.gov/cgi/cbook.cgi?ID=C124389&Mask=1&Type=JANAFG&Table=on
242 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
243 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
244 */
245 static Scalar gasHeatCapacity(Scalar temperature, Scalar pressure)
246 {
247 101 const Scalar t = temperature/1000;
248 101 constexpr double a = 24.99735;
249 101 constexpr double b = 55.18696;
250 101 constexpr double c = -33.69137;
251 101 constexpr double d = 7.948387;
252 101 constexpr double e = -0.136638;
253 101 return (a + b*t + c*t*t + d*t*t*t + e/(t*t))/molarMass();
254 }
255
256 };
257
258 } // end namespace Dumux::Components
259
260 #endif
261