GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/material/components/simpleco2.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 34 38 89.5%
Functions: 1 4 25.0%
Branches: 24 46 52.2%

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