GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/material/fluidsystems/1pgas.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 25 44 56.8%
Functions: 8 27 29.6%
Branches: 16 40 40.0%

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 FluidSystems
10 * \brief @copybrief Dumux::FluidSystems::OnePGas
11 */
12 #ifndef DUMUX_GAS_PHASE_HH
13 #define DUMUX_GAS_PHASE_HH
14
15 #include <cassert>
16 #include <limits>
17
18 #include <dune/common/exceptions.hh>
19
20 #include <dumux/material/fluidsystems/base.hh>
21 #include <dumux/material/components/componenttraits.hh>
22 #include <dumux/io/name.hh>
23
24 namespace Dumux {
25 namespace FluidSystems {
26
27 /*!
28 * \ingroup FluidSystems
29 * \brief A gaseous phase consisting of a single component
30 */
31 template <class Scalar, class ComponentT>
32 class OnePGas
33 : public Base<Scalar, OnePGas<Scalar, ComponentT> >
34 {
35 using ThisType = OnePGas<Scalar, ComponentT>;
36
37 static_assert(ComponentTraits<ComponentT>::hasGasState, "The component does not implement a gas state!");
38
39 public:
40 using Component = ComponentT;
41 using ParameterCache = NullParameterCache;
42
43 static constexpr int numPhases = 1; //!< Number of phases in the fluid system
44 static constexpr int numComponents = 1; //!< Number of components in the fluid system
45
46 static constexpr int phase0Idx = 0; //!< index of the only phase
47 static constexpr int comp0Idx = 0; //!< index of the only component
48
49 /*!
50 * \brief Initialize the fluid system's static parameters generically
51 */
52 static void init()
53 { }
54
55 /****************************************
56 * Fluid phase related static parameters
57 ****************************************/
58 /*!
59 * \brief Return the human readable name of a fluid phase
60 *
61 * \param phaseIdx The index of the fluid phase to consider
62 */
63 static std::string phaseName(int phaseIdx = 0)
64 638 { return IOName::gaseousPhase(); }
65
66 /*!
67 * \brief A human readable name for the component.
68 *
69 * \param compIdx The index of the component to consider
70 */
71 static std::string componentName(int compIdx = 0)
72
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 { return Component::name(); }
73
74 /*!
75 * \brief A human readable name for the component.
76 */
77 static std::string name()
78 4 { return Component::name(); }
79
80 /*!
81 * \brief There is only one phase, so not mass transfer between phases can occur
82 */
83 static constexpr bool isMiscible()
84 { return false; }
85
86 /*!
87 * \brief Returns whether the fluid is gaseous
88 */
89 static constexpr bool isGas(int phaseIdx = 0)
90 { return true; }
91
92 /*!
93 * \brief Returns true if and only if a fluid phase is assumed to
94 * be an ideal mixture.
95 *
96 * We define an ideal mixture as a fluid phase where the fugacity
97 * coefficients of all components times the pressure of the phase
98 * are independent on the fluid composition. This assumption is true
99 * if only a single component is involved. If you are unsure what
100 * this function should return, it is safe to return false. The
101 * only damage done will be (slightly) increased computation times
102 * in some cases.
103 *
104 * \param phaseIdx The index of the fluid phase to consider
105 */
106 static constexpr bool isIdealMixture(int phaseIdx = 0)
107 { return true; }
108
109 /*!
110 * \brief Returns true if the fluid is assumed to be compressible
111 */
112 static constexpr bool isCompressible(int phaseIdx = 0)
113 { return Component::gasIsCompressible(); }
114
115 /*!
116 * \brief Returns true if the fluid is assumed to be an ideal gas
117 */
118 static constexpr bool isIdealGas(int phaseIdx = 0)
119 { return Component::gasIsIdeal(); }
120
121 /*!
122 * \brief Returns true if and only if a fluid phase is assumed to
123 * have a constant viscosity.
124 *
125 * \param phaseIdx The index of the fluid phase to consider
126 */
127 static constexpr bool viscosityIsConstant(int phaseIdx)
128 { return Component::gasViscosityIsConstant(); }
129
130 /*!
131 * \brief The mass in \f$\mathrm{[kg]}\f$ of one mole of the component.
132 */
133 static Scalar molarMass(int compIdx = 0)
134 { return Component::molarMass(); }
135
136 /*!
137 * \brief Returns the critical temperature in \f$\mathrm{[K]}\f$ of the component
138 */
139 static Scalar criticalTemperature(int compIdx = 0)
140 { return Component::criticalTemperature(); }
141
142 /*!
143 * \brief Returns the critical pressure in \f$\mathrm{[Pa]}\f$ of the component
144 */
145 static Scalar criticalPressure(int compIdx = 0)
146 { return Component::criticalPressure(); }
147
148 /*!
149 * \brief Returns the temperature in \f$\mathrm{[K]}\f$ at the component's triple point.
150 */
151 static Scalar tripleTemperature(int compIdx = 0)
152 { return Component::tripleTemperature(); }
153
154 /*!
155 * \brief Returns the pressure in \f$\mathrm{[Pa]}\f$ at the component's triple point.
156 */
157 static Scalar triplePressure(int compIdx = 0)
158 { return Component::triplePressure(); }
159
160 /*!
161 * \brief The vapor pressure in \f$\mathrm{[Pa]}\f$ of the component at a given
162 * temperature.
163 * \param T temperature \f$\mathrm{[K]}\f$
164 */
165 static Scalar vaporPressure(Scalar T)
166 { return Component::vaporPressure(T); }
167
168 /*!
169 * \brief The density \f$\mathrm{[kg/m^3]}\f$ of the component at a given pressure and temperature.
170 * \param temperature The given temperature \f$\mathrm{[K]}\f$
171 * \param pressure The given pressure \f$\mathrm{[Pa]}\f$
172 */
173 static Scalar density(Scalar temperature, Scalar pressure)
174 19975576 { return Component::gasDensity(temperature, pressure); }
175
176 using Base<Scalar, ThisType>::density;
177 //! \copydoc Base<Scalar,ThisType>::density(const FluidState&,int)
178 template <class FluidState>
179 1 static Scalar density(const FluidState &fluidState,
180 const int phaseIdx)
181 {
182 return density(fluidState.temperature(phaseIdx),
183 31 fluidState.pressure(phaseIdx));
184 }
185
186 /*!
187 * \brief The molar density \f$\rho_{mol,\alpha}\f$
188 * of a fluid phase \f$\alpha\f$ in \f$\mathrm{[mol/m^3]}\f$
189 *
190 * The molar density is defined by the
191 * mass density \f$\rho_\alpha\f$ and the component molar mass \f$M_\alpha\f$:
192 *
193 * \f[\rho_{mol,\alpha} = \frac{\rho_\alpha}{M_\alpha} \;.\f]
194 * \param temperature The temperature at which to evaluate the molar density
195 * \param pressure The pressure at which to evaluate the molar density
196 */
197 static Scalar molarDensity(Scalar temperature, Scalar pressure)
198 8 { return Component::gasMolarDensity(temperature, pressure); }
199
200 using Base<Scalar, ThisType>::molarDensity;
201 //! \copydoc Base<Scalar,ThisType>::molarDensity(const FluidState&,int)
202 template <class FluidState>
203 1 static Scalar molarDensity(const FluidState &fluidState,
204 const int phaseIdx)
205 {
206 return molarDensity(fluidState.temperature(phaseIdx),
207 1 fluidState.pressure(phaseIdx));
208 }
209
210 /*!
211 * \brief The pressure \f$\mathrm{[Pa]}\f$ of the component at a given density and temperature.
212 * \param temperature The given temperature \f$\mathrm{[K]}\f$
213 * \param density The given density \f$\mathrm{[kg/m^3]}\f$
214 */
215 static Scalar pressure(Scalar temperature, Scalar density)
216 { return Component::gasPressure(temperature, density); }
217
218 /*!
219 * \brief Specific enthalpy \f$\mathrm{[J/kg]}\f$ of the pure component as a gas.
220 * \param temperature The given temperature \f$\mathrm{[K]}\f$
221 * \param pressure The given pressure \f$\mathrm{[Pa]}\f$
222 */
223 static const Scalar enthalpy(Scalar temperature, Scalar pressure)
224 8 { return Component::gasEnthalpy(temperature, pressure); }
225
226 using Base<Scalar, ThisType>::enthalpy;
227 //! \copydoc Base<Scalar,ThisType>::enthalpy(const FluidState&,int)
228 template <class FluidState>
229 1 static Scalar enthalpy(const FluidState &fluidState,
230 const int phaseIdx)
231 {
232 return enthalpy(fluidState.temperature(phaseIdx),
233 1 fluidState.pressure(phaseIdx));
234 }
235
236 /*!
237 * \brief Specific internal energy \f$\mathrm{[J/kg]}\f$ of the pure component as a gas.
238 * \param temperature The given temperature \f$\mathrm{[K]}\f$
239 * \param pressure The given pressure \f$\mathrm{[Pa]}\f$
240 */
241 static const Scalar internalEnergy(Scalar temperature, Scalar pressure)
242 { return Component::gasInternalEnergy(temperature, pressure); }
243
244 /*!
245 * \brief The dynamic viscosity \f$\mathrm{[Pa s]}\f$ of the pure component at a given pressure and temperature.
246 * \param temperature The given temperature \f$\mathrm{[K]}\f$
247 * \param pressure The given pressure \f$\mathrm{[Pa]}\f$
248 */
249 static Scalar viscosity(Scalar temperature, Scalar pressure)
250 5004857 { return Component::gasViscosity(temperature, pressure); }
251
252 using Base<Scalar, ThisType>::viscosity;
253 //! \copydoc Base<Scalar,ThisType>::viscosity(const FluidState&,int)
254 template <class FluidState>
255 1 static Scalar viscosity(const FluidState &fluidState,
256 const int phaseIdx)
257 {
258 return viscosity(fluidState.temperature(phaseIdx),
259
1/2
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
16 fluidState.pressure(phaseIdx));
260 }
261
262 using Base<Scalar, ThisType>::fugacityCoefficient;
263 //! \copydoc Base<Scalar,ThisType>::fugacityCoefficient(const FluidState&,int,int)
264 template <class FluidState>
265 static Scalar fugacityCoefficient(const FluidState &fluidState,
266 int phaseIdx,
267 int compIdx)
268 {
269 assert(0 <= phaseIdx && phaseIdx < numPhases);
270 assert(0 <= compIdx && compIdx < numComponents);
271
272 if (phaseIdx == compIdx)
273 // We could calculate the real fugacity coefficient of
274 // the component in the fluid. Probably that's not worth
275 // the effort, since the fugacity coefficient of the other
276 // component is infinite anyway...
277 return 1.0;
278 return std::numeric_limits<Scalar>::infinity();
279 }
280
281 using Base<Scalar, ThisType>::diffusionCoefficient;
282 //! \copydoc Base<Scalar,ThisType>::diffusionCoefficient(const FluidState&,int,int)
283 template <class FluidState>
284 1 static Scalar diffusionCoefficient(const FluidState &fluidState,
285 int phaseIdx,
286 int compIdx)
287 {
288
7/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
11 DUNE_THROW(Dune::InvalidStateException, "Not applicable: Diffusion coefficients");
289 }
290
291 using Base<Scalar, ThisType>::binaryDiffusionCoefficient;
292 //! \copydoc Base<Scalar,ThisType>::binaryDiffusionCoefficient(const FluidState&,int,int,int)
293 template <class FluidState>
294 1 static Scalar binaryDiffusionCoefficient(const FluidState &fluidState,
295 int phaseIdx,
296 int compIIdx,
297 int compJIdx)
298
299 {
300
7/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
11 DUNE_THROW(Dune::InvalidStateException, "Not applicable: Binary diffusion coefficients");
301 }
302
303 /*!
304 * \brief Thermal conductivity of the fluid \f$\mathrm{[W/(m K)]}\f$.
305 * \param temperature The given temperature \f$\mathrm{[K]}\f$
306 * \param pressure The given pressure \f$\mathrm{[Pa]}\f$
307 */
308 static Scalar thermalConductivity(Scalar temperature, Scalar pressure)
309 68786564 { return Component::gasThermalConductivity(temperature, pressure); }
310
311 using Base<Scalar, ThisType>::thermalConductivity;
312 //! \copydoc Base<Scalar,ThisType>::thermalConductivity(const FluidState&,int)
313 template <class FluidState>
314 1 static Scalar thermalConductivity(const FluidState &fluidState,
315 const int phaseIdx)
316 {
317 return thermalConductivity(fluidState.temperature(phaseIdx),
318 68623261 fluidState.pressure(phaseIdx));
319 }
320
321 /*!
322 * \brief Specific isobaric heat capacity of the fluid \f$\mathrm{[J/(kg K)]}\f$.
323 * \param temperature The given temperature \f$\mathrm{[K]}\f$
324 * \param pressure The given pressure \f$\mathrm{[Pa]}\f$
325 */
326 static Scalar heatCapacity(Scalar temperature, Scalar pressure)
327 24863940 { return Component::gasHeatCapacity(temperature, pressure); }
328
329 using Base<Scalar, ThisType>::heatCapacity;
330 //! \copydoc Base<Scalar,ThisType>::heatCapacity(const FluidState&,int)
331 template <class FluidState>
332 1 static Scalar heatCapacity(const FluidState &fluidState,
333 const int phaseIdx)
334 {
335 return heatCapacity(fluidState.temperature(phaseIdx),
336 24863933 fluidState.pressure(phaseIdx));
337 }
338 };
339
340 } // namespace FluidSystems
341 } // namespace
342
343 #endif
344