GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/material/components/constant.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 74 77 96.1%
Functions: 46 48 95.8%
Branches: 94 180 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-FileCopyrightText: 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 Setting constant fluid properties via the input file.
11 */
12 #ifndef DUMUX_COMPONENTS_CONSTANT_HH
13 #define DUMUX_COMPONENTS_CONSTANT_HH
14
15 #include <dune/common/exceptions.hh>
16 #include <dumux/common/parameters.hh>
17
18 #include <dumux/material/idealgas.hh>
19
20 #include <dumux/material/components/base.hh>
21 #include <dumux/material/components/liquid.hh>
22 #include <dumux/material/components/gas.hh>
23 #include <dumux/material/components/solid.hh>
24
25 namespace Dumux::Components {
26
27 /*!
28 * \ingroup Components
29 * \brief A component which returns run time specified values
30 * for all fluid properties.
31 *
32 * \tparam id The id used to read from the input file / parametertree
33 * \tparam Scalar The type used for scalar values
34 *
35 * \note For the constant component with id=1 you would specify the parameters in the input file as follows
36 * \code{.ini}
37 * [1.Component]
38 * MolarMass = 0.018 # kg/mol
39 * \endcode
40 * \note If you only have one component you can also omit the "1.".
41 */
42 template<int id, class Scalar>
43 class Constant
44 : public Components::Base<Scalar, Constant<id, Scalar> >
45 , public Components::Liquid<Scalar, Constant<id, Scalar> >
46 , public Components::Gas<Scalar, Constant<id, Scalar> >
47 , public Components::Solid<Scalar, Constant<id, Scalar> >
48 {
49 using IdealGas = Dumux::IdealGas<Scalar>;
50
51 public:
52 /*!
53 * \brief Returns true if the gas phase is assumed to be compressible
54 */
55 static constexpr bool gasIsCompressible()
56 { return false; }
57
58 /*!
59 * \brief Returns true if the gas phase viscosity is constant
60 */
61 static constexpr bool gasViscosityIsConstant()
62 { return true; }
63
64 /*!
65 * \brief Returns true if the gas phase is assumed to be ideal
66 */
67 static constexpr bool gasIsIdeal()
68 { return true; }
69
70 /*!
71 * \brief Returns true if the liquid phase is assumed to be compressible
72 */
73 static constexpr bool liquidIsCompressible()
74 { return false; }
75
76 /*!
77 * \brief Returns true if the liquid phase viscosity is constant
78 */
79 static constexpr bool liquidViscosityIsConstant()
80 { return true; }
81
82 /*!
83 * \brief A human readable name for the component.
84 */
85 29 static const std::string& name()
86 {
87
4/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 14 times.
✓ Branch 3 taken 11 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
29 static const std::string name = getParamFromGroup<std::string>(std::to_string(id), "Component.Name", "component");
88 29 return name;
89 }
90
91 /*!
92 * \brief The mass in \f$\mathrm{[kg]}\f$ of one mole of the component.
93 */
94 78656795 static Scalar molarMass()
95 {
96
5/6
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 78477530 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 31 times.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
78656795 static const Scalar molarMass = getParamFromGroup<Scalar>(std::to_string(id), "Component.MolarMass");
97 78656795 return molarMass;
98 }
99
100 /*!
101 * \brief Returns the temperature \f$\mathrm{[K]}\f$ at the components's triple point.
102 */
103 179220 static Scalar tripleTemperature()
104 {
105
5/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 179216 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
179220 static const Scalar tripleTemperature = getParamFromGroup<Scalar>(std::to_string(id), "Component.TripleTemperature");
106 179220 return tripleTemperature;
107 }
108
109 /*!
110 * \brief Returns the pressure \f$\mathrm{[Pa]}\f$ at the component's triple point.
111 */
112 179220 static Scalar triplePressure()
113 {
114
5/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 179214 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
179220 static const Scalar triplePressure = getParamFromGroup<Scalar>(std::to_string(id), "Component.TriplePressure");
115 179220 return triplePressure;
116 }
117
118 /*!
119 * \brief The vaporization enthalpy in \f$\mathrm{[J/kg]}\f$ needed to vaporize one kilogram of the liquid component to the gaseous state
120 */
121 1314641 static Scalar vaporizationEnthalpy()
122 {
123
4/6
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 752974 times.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
1314641 static const Scalar vaporizationEnthalpy = getParamFromGroup<Scalar>(std::to_string(id), "Component.EnthalpyOfVaporization");
124 1314641 return vaporizationEnthalpy;
125 }
126
127
128 /*!
129 * \brief Sets the liquid density in \f$\mathrm{[kg/m^3]}\f$.
130 *
131 * \param temperature phase temperature in \f$\mathrm{[K]}\f$
132 * \param pressure phase pressure in \f$\mathrm{[Pa]}\f$
133 */
134 61245774 static Scalar liquidDensity(Scalar temperature, Scalar pressure)
135 {
136
5/6
✓ Branch 0 taken 657 times.
✓ Branch 1 taken 61245117 times.
✓ Branch 3 taken 193 times.
✓ Branch 4 taken 464 times.
✓ Branch 7 taken 193 times.
✗ Branch 8 not taken.
61245774 static const Scalar density = getParamFromGroup<Scalar>(std::to_string(id), "Component.LiquidDensity");
137 61245774 return density;
138 }
139
140 /*!
141 * \brief The molar density in \f$\mathrm{[mol/m^3]}\f$ at a given pressure and temperature.
142 *
143 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
144 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
145 *
146 */
147 static Scalar liquidMolarDensity(Scalar temperature, Scalar pressure)
148 { return liquidDensity(temperature, pressure)/molarMass(); }
149
150 /*!
151 * \brief Sets the liquid dynamic viscosity in \f$\mathrm{[Pa*s]}\f$.
152 *
153 * \note We look for Component.LiquidKinematicViscosity or Component.LiquidDynamicViscosity.
154 * If both parameters are specified, it is considered a configuration error because it can
155 * be ambiguous if defaults are specified for several constant components in the plain
156 * "Component" group (without ID-prefix).
157 *
158 * \param temperature phase temperature in \f$\mathrm{[K]}\f$
159 * \param pressure phase pressure in \f$\mathrm{[Pa]}\f$
160 */
161 53826345 static Scalar liquidViscosity(Scalar temperature, Scalar pressure)
162 {
163
4/4
✓ Branch 0 taken 597 times.
✓ Branch 1 taken 53825748 times.
✓ Branch 3 taken 193 times.
✓ Branch 4 taken 404 times.
53826924 static const Scalar dynamicViscosity = [&]
164 {
165
3/4
✓ Branch 3 taken 193 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 174 times.
✓ Branch 8 taken 19 times.
386 if (hasParamInGroup(std::to_string(id), "Component.LiquidKinematicViscosity"))
166 {
167
2/4
✓ Branch 3 taken 174 times.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 174 times.
348 if (hasParamInGroup(std::to_string(id), "Component.LiquidDynamicViscosity"))
168 DUNE_THROW(Dune::InvalidStateException, "Found both Component.LiquidKinematicViscosity and Component.LiquidDynamicViscosity."
169 << " Please only specify either the kinematic or the dynamic viscosity for all constant components to avoid ambiguities.");
170
171
2/4
✓ Branch 2 taken 174 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 174 times.
✗ Branch 6 not taken.
174 return getParamFromGroup<Scalar>(std::to_string(id), "Component.LiquidKinematicViscosity") * liquidDensity(temperature, pressure);
172 }
173 else
174
1/2
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
19 return getParamFromGroup<Scalar>(std::to_string(id), "Component.LiquidDynamicViscosity");
175
1/2
✓ Branch 1 taken 193 times.
✗ Branch 2 not taken.
193 }();
176
177 53826345 return dynamicViscosity;
178 }
179
180 /*!
181 * \brief Thermal conductivity of the component \f$\mathrm{[W/(m*K)]}\f$ as a liquid.
182 * \param temperature temperature of phase in \f$\mathrm{[K]}\f$
183 * \param pressure pressure of phase in \f$\mathrm{[Pa]}\f$
184 */
185 7259106 static Scalar liquidThermalConductivity(Scalar temperature, Scalar pressure)
186 {
187
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 7259101 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
7259106 static const Scalar thermalConductivity = getParamFromGroup<Scalar>(std::to_string(id), "Component.LiquidThermalConductivity");
188 7259106 return thermalConductivity;
189 }
190
191 /*!
192 * \brief Specific internal energy of the component \f$\mathrm{[J/kg]}\f$ as a liquid.
193 * \param temperature temperature of phase in \f$\mathrm{[K]}\f$
194 * \param pressure pressure of phase in \f$\mathrm{[Pa]}\f$
195 */
196 7240021 static Scalar liquidInternalEnergy(Scalar temperature, Scalar pressure)
197 {
198 // u = c * dT for incompressible fluids
199 7240021 const Scalar heatCapacity = liquidHeatCapacity(temperature, pressure);
200
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 7240016 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
7240021 static const Scalar tRef = getParamFromGroup<Scalar>(std::to_string(id), "Component.ReferenceTemperature", 293.15);
201 7240021 return heatCapacity * (temperature - tRef);
202 }
203
204 /*!
205 * \brief Specific enthalpy of the component \f$\mathrm{[J/kg]}\f$ as a liquid.
206 *
207 * \param temperature temperature of phase in \f$\mathrm{[K]}\f$
208 * \param pressure pressure of phase in \f$\mathrm{[Pa]}\f$
209 */
210 7240021 static Scalar liquidEnthalpy(Scalar temperature, Scalar pressure)
211 {
212 7240021 const Scalar u = liquidInternalEnergy(temperature, pressure);
213 7240021 const Scalar rho = liquidDensity(temperature, pressure);
214 7240021 return u + pressure / rho;
215 }
216
217 /*!
218 * \brief Specific isobaric heat capacity of the component \f$\mathrm{[J/(kg*K)]}\f$ as a liquid.
219 *
220 * \param temperature temperature of phase in \f$\mathrm{[K]}\f$
221 * \param pressure pressure of phase in \f$\mathrm{[Pa]}\f$
222 */
223 7240122 static Scalar liquidHeatCapacity(Scalar temperature, Scalar pressure)
224 {
225
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 7240117 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
7240122 static const Scalar heatCapacity = getParamFromGroup<Scalar>(std::to_string(id), "Component.LiquidHeatCapacity");
226 7240122 return heatCapacity;
227 }
228
229 /*!
230 * \brief Sets the gas density in \f$\mathrm{[kg/m^3]}\f$.
231 *
232 * \param temperature phase temperature in \f$\mathrm{[K]}\f$
233 * \param pressure phase pressure in \f$\mathrm{[Pa]}\f$
234 */
235 716986 static Scalar gasDensity(Scalar temperature, Scalar pressure)
236 {
237
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 716981 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
716986 static const Scalar density = getParamFromGroup<Scalar>(std::to_string(id), "Component.GasDensity");
238 716986 return density;
239 }
240
241 /*!
242 * \brief The molar density in \f$\mathrm{[mol/m^3]}\f$ at a given pressure and temperature.
243 *
244 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
245 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
246 *
247 */
248 static Scalar gasMolarDensity(Scalar temperature, Scalar pressure)
249 { return gasDensity(temperature, pressure)/molarMass(); }
250
251
252 /*!
253 * \brief Sets the gas dynamic viscosity in \f$\mathrm{[Pa*s]}\f$.
254 *
255 * \note We look for Component.GasKinematicViscosity or Component.GasDynamicViscosity.
256 * If both parameters are specified, it is considered a configuration error because it can
257 * be ambiguous if defaults are specified for several constant components in the plain
258 * "Component" group (without ID-prefix).
259 *
260 * \param temperature phase temperature in \f$\mathrm{[K]}\f$
261 * \param pressure phase pressure in \f$\mathrm{[Pa]}\f$
262 */
263 358541 static Scalar gasViscosity(Scalar temperature, Scalar pressure)
264 {
265
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 358536 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
358551 static const Scalar dynamicViscosity = [&]
266 {
267
2/4
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
10 if (hasParamInGroup(std::to_string(id), "Component.GasKinematicViscosity"))
268 {
269
2/4
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
10 if (hasParamInGroup(std::to_string(id), "Component.GasDynamicViscosity"))
270 DUNE_THROW(Dune::InvalidStateException, "Found both Component.GasKinematicViscosity and Component.GasDynamicViscosity."
271 << " Please only specify either the kinematic or the dynamic viscosity for all constant components to avoid ambiguities.");
272
273
2/4
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
5 return getParamFromGroup<Scalar>(std::to_string(id), "Component.GasKinematicViscosity") * gasDensity(temperature, pressure);
274 }
275 else
276 return getParamFromGroup<Scalar>(std::to_string(id), "Component.GasDynamicViscosity");
277
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 }();
278
279 358541 return dynamicViscosity;
280 }
281
282 /*!
283 * \brief Thermal conductivity of the component \f$\mathrm{[W/(m*K)]}\f$ as a gas.
284 * \param temperature temperature of phase in \f$\mathrm{[K]}\f$
285 * \param pressure pressure of phase in \f$\mathrm{[Pa]}\f$
286 */
287 382541 static Scalar gasThermalConductivity(Scalar temperature, Scalar pressure)
288 {
289
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 382536 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
382541 static const Scalar thermalConductivity = getParamFromGroup<Scalar>(std::to_string(id), "Component.GasThermalConductivity");
290 382541 return thermalConductivity;
291 }
292
293 /*!
294 * \brief Specific internal energy of the component \f$\mathrm{[J/kg]}\f$ as a gas.
295 *
296 * Definition of enthalpy: \f$h= u + pv = u + p / \rho\f$.
297 *
298 * Rearranging for internal energy yields: \f$u = h - pv\f$.
299 *
300 * Exploiting the Ideal Gas assumption (\f$pv = R_{\textnormal{specific}} T\f$)gives: \f$u = h - R / M T \f$.
301 *
302 * The universal gas constant can only be used in the case of molar formulations.
303 * \param temperature temperature of phase in \f$\mathrm{[K]}\f$
304 * \param pressure pressure of phase in \f$\mathrm{[Pa]}\f$
305 */
306 static Scalar gasInternalEnergy(Scalar temperature, Scalar pressure)
307 {
308 // 1/molarMass: conversion from [J/(mol K)] to [J/(kg K)]
309 // R*T/molarMass: pressure *spec. volume for an ideal gas
310 return gasEnthalpy(temperature, pressure) - 1/molarMass()* IdealGas::R*temperature;
311
312 }
313
314 /*!
315 * \brief Specific enthalpy of the component \f$\mathrm{[J/kg]}\f$ as a gas.
316 *
317 * \param temperature temperature of phase in \f$\mathrm{[K]}\f$
318 * \param pressure pressure of phase in \f$\mathrm{[Pa]}\f$
319 */
320 956201 static Scalar gasEnthalpy(Scalar temperature, Scalar pressure)
321 {
322
4/6
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 573754 times.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
956201 static const Scalar tRef = getParamFromGroup<Scalar>(std::to_string(id), "Component.ReferenceTemperature", 293.15);
323 956201 return gasHeatCapacity(temperature, pressure)*(temperature - tRef) + vaporizationEnthalpy();
324 }
325
326 /*!
327 * \brief Specific isobaric heat capacity of the component \f$\mathrm{[J/(kg*K)]}\f$ as a gas.
328 *
329 * \param temperature temperature of phase in \f$\mathrm{[K]}\f$
330 * \param pressure pressure of phase in \f$\mathrm{[Pa]}\f$
331 */
332 956302 static Scalar gasHeatCapacity(Scalar temperature, Scalar pressure)
333 {
334
4/6
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 573855 times.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
956302 static const Scalar heatCapacity = getParamFromGroup<Scalar>(std::to_string(id), "Component.GasHeatCapacity");
335 956302 return heatCapacity;
336 }
337
338 /*!
339 * \brief The vapor pressure in \f$\mathrm{[Pa]}\f$ of a the component
340 * at a given temperature.
341 *
342 *\param T temperature of component in \f$\mathrm{[K]}\f$
343 *
344 * We use the Clausius-Clapeyron Equation to estimate the vapor pressure. Vapor pressure depends on the enthalpy of vaporization. We use the triple point pressure and temperature as a reference point.
345 */
346 179220 static Scalar vaporPressure(Scalar T)
347 {
348 179220 const Scalar p2 = triplePressure();
349 179220 const Scalar T2 = tripleTemperature();
350 179220 const Scalar exponent = -(vaporizationEnthalpy()*molarMass())/IdealGas::R*(1/T - 1/T2);
351
352 using std::exp;
353 179220 const Scalar vaporPressure = p2*exp(exponent);
354 179220 return vaporPressure;
355 }
356
357 /*!
358 * \brief The density in \f$\mathrm{[kg/m^3]}\f$ of the component at a given pressure in
359 * \f$\mathrm{[Pa]}\f$ and temperature in \f$\mathrm{[K]}\f$.
360 *
361 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
362 */
363 95489503 static Scalar solidDensity(Scalar temperature)
364 {
365
5/6
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 95489400 times.
✓ Branch 3 taken 89 times.
✓ Branch 4 taken 14 times.
✓ Branch 7 taken 89 times.
✗ Branch 8 not taken.
95489503 static const Scalar density = getParamFromGroup<Scalar>(std::to_string(id), "Component.SolidDensity");
366 95489503 return density;
367 }
368
369 /*!
370 * \brief Thermal conductivity of the component \f$\mathrm{[W/(m*K)]}\f$ as a solid.
371 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
372 */
373 95260463 static Scalar solidThermalConductivity(Scalar temperature)
374 {
375
5/6
✓ Branch 0 taken 99 times.
✓ Branch 1 taken 95260364 times.
✓ Branch 3 taken 84 times.
✓ Branch 4 taken 15 times.
✓ Branch 7 taken 84 times.
✗ Branch 8 not taken.
95260463 static const Scalar solidThermalConductivity = getParamFromGroup<Scalar>(std::to_string(id), "Component.SolidThermalConductivity");
376 95260463 return solidThermalConductivity;
377 }
378
379 /*!
380 * \brief Specific isobaric heat capacity of the component \f$\mathrm{[J/(kg*K)]}\f$ as a solid.
381 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
382 */
383 91963806 static Scalar solidHeatCapacity(Scalar temperature)
384 {
385
5/6
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 91963701 times.
✓ Branch 3 taken 82 times.
✓ Branch 4 taken 23 times.
✓ Branch 7 taken 82 times.
✗ Branch 8 not taken.
91963806 static const Scalar solidHeatCapacity = getParamFromGroup<Scalar>(std::to_string(id), "Component.SolidHeatCapacity");
386 91963806 return solidHeatCapacity;
387 }
388 };
389
390 } // end namespace Dumux::Components
391
392 #endif
393