GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/material/fluidsystems/1padapter.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 44 54 81.5%
Functions: 69 107 64.5%
Branches: 208 287 72.5%

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::OnePAdapter
11 */
12 #ifndef DUMUX_FLUIDSYTEMS_ONEP_ADAPTER_HH
13 #define DUMUX_FLUIDSYTEMS_ONEP_ADAPTER_HH
14
15 #include <cassert>
16
17 #include <dune/common/exceptions.hh>
18
19 #include <dumux/material/fluidsystems/base.hh>
20 #include <dumux/material/fluidstates/adapter.hh>
21
22 namespace Dumux {
23 namespace FluidSystems {
24
25 /*!
26 * \ingroup FluidSystems
27 * \brief An adapter for multi-phase fluid systems to be used with (compositional) one-phase models
28 * \tparam MPFluidSystem the multi-phase fluid system to be adapted
29 * \tparam phase the index of the phase we choose from the multi-phase fluid system
30 */
31 template <class MPFluidSystem, int phase = 0>
32 class OnePAdapter
33 : public Base<typename MPFluidSystem::Scalar, OnePAdapter<MPFluidSystem, phase>>
34 {
35 using ThisType = OnePAdapter<MPFluidSystem, phase>;
36
37 static_assert(phase < MPFluidSystem::numPhases, "Phase does not exist in multi-phase fluidsystem!");
38
39 struct AdapterPolicy
40 {
41 using FluidSystem = MPFluidSystem;
42
43 // the phase index is always zero, other phases than the chosen phase should never be called
44 static int phaseIdx(int mpFluidPhaseIdx)
45 { return 0; }
46
47 // the main component is currently excepted to have the same index as it's phase
48 // (see Fluidsystems::Base::getMainComponent for more information)
49 // so we swap the main component with the first component
50 // this mapping works in both ways since we are only swapping components
51 static constexpr int compIdx(int compIdx)
52 {
53
48/60
✓ Branch 0 taken 111727200 times.
✓ Branch 1 taken 111727200 times.
✓ Branch 2 taken 55863600 times.
✓ Branch 3 taken 55863600 times.
✓ Branch 4 taken 75475304 times.
✓ Branch 5 taken 75475304 times.
✓ Branch 6 taken 37750068 times.
✓ Branch 7 taken 37750068 times.
✓ Branch 8 taken 77236064 times.
✓ Branch 9 taken 77236064 times.
✓ Branch 10 taken 38618032 times.
✓ Branch 11 taken 38618032 times.
✓ Branch 12 taken 131254489 times.
✓ Branch 13 taken 131254489 times.
✓ Branch 14 taken 65627732 times.
✓ Branch 15 taken 65627732 times.
✓ Branch 16 taken 49985581 times.
✓ Branch 17 taken 49985581 times.
✓ Branch 18 taken 31917641 times.
✓ Branch 19 taken 31917641 times.
✓ Branch 20 taken 4842643 times.
✓ Branch 21 taken 4842643 times.
✓ Branch 22 taken 4792979 times.
✓ Branch 23 taken 4792979 times.
✓ Branch 24 taken 18245254 times.
✓ Branch 25 taken 18245254 times.
✓ Branch 26 taken 18216522 times.
✓ Branch 27 taken 18216522 times.
✓ Branch 28 taken 3900 times.
✓ Branch 29 taken 3900 times.
✓ Branch 30 taken 1950 times.
✓ Branch 31 taken 1950 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 7800 times.
✓ Branch 41 taken 7800 times.
✓ Branch 42 taken 3900 times.
✓ Branch 43 taken 3900 times.
✓ Branch 44 taken 3900 times.
✓ Branch 45 taken 3900 times.
✓ Branch 46 taken 1950 times.
✓ Branch 47 taken 1950 times.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✓ Branch 52 taken 850 times.
✓ Branch 53 taken 850 times.
✓ Branch 54 taken 850 times.
✓ Branch 55 taken 850 times.
✓ Branch 56 taken 850 times.
✓ Branch 57 taken 850 times.
✓ Branch 58 taken 850 times.
✓ Branch 59 taken 850 times.
1443159818 if (compIdx == 0)
54 return phase;
55
31/50
✗ Branch 0 not taken.
✓ Branch 1 taken 1409145 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63325570 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 20723806 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 35325272 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 37593509 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 1164775 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 18041159 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 5341519 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 1028938 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 1966 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 6956564 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 40876 times.
✓ Branch 24 taken 12 times.
✓ Branch 25 taken 46 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 5273 times.
✓ Branch 28 taken 1 times.
✓ Branch 29 taken 27 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 25 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 25 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 25 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 25 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 25 times.
✗ Branch 40 not taken.
✓ Branch 41 taken 25 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 25 times.
✗ Branch 44 not taken.
✓ Branch 45 taken 12 times.
✗ Branch 46 not taken.
✓ Branch 47 taken 25 times.
✗ Branch 48 not taken.
✓ Branch 49 taken 36 times.
190958714 else if (compIdx == phase)
56 return 0;
57 else
58 return compIdx;
59 }
60 };
61
62 template<class FluidState>
63 static auto adaptFluidState(const FluidState& fluidState)
64 481086313 { return FluidStateAdapter<FluidState, AdapterPolicy>(fluidState); }
65
66 public:
67 using Scalar = typename MPFluidSystem::Scalar;
68 using ParameterCache = NullParameterCache;
69
70 //! export the wrapped MultiPhaseFluidSystem type
71 using MultiPhaseFluidSystem = MPFluidSystem;
72 //! the index of the phase we choose from the multi-phase fluid system
73 static constexpr int multiphaseFluidsystemPhaseIdx = phase;
74
75 //! number of phases in the fluid system
76 static constexpr int numPhases = 1;
77 //! for compositional models, the number of components has to be the same as in the multi-phase fluid system as the composition needs to be defined,
78 //! while for non-compositional models, the number of components must equal the number of phases (1 in this case)
79 static constexpr int numComponents = MultiPhaseFluidSystem::isMiscible() ? MultiPhaseFluidSystem::numComponents : numPhases;
80 //! number of components has to be the same as in the multi-phase fluid system as the composition needs to be defined
81 static constexpr int phase0Idx = 0; //!< index of the only phase
82
83 //! convert a component index of the multi-phase component index to the actual component index
84 static constexpr int compIdx(int multiPhaseFluidSystemCompIdx)
85
18/24
✓ Branch 1 taken 21920 times.
✓ Branch 2 taken 21920 times.
✓ Branch 3 taken 31408 times.
✓ Branch 4 taken 12432 times.
✓ Branch 5 taken 21920 times.
✓ Branch 6 taken 21920 times.
✓ Branch 7 taken 24496 times.
✓ Branch 8 taken 144 times.
✓ Branch 9 taken 49220 times.
✓ Branch 10 taken 49220 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 73800 times.
✓ Branch 13 taken 48356 times.
✓ Branch 14 taken 48356 times.
✓ Branch 15 taken 48356 times.
✓ Branch 16 taken 48356 times.
✓ Branch 17 taken 48356 times.
✓ Branch 18 taken 48356 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 96712 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
737168 { return AdapterPolicy::compIdx(multiPhaseFluidSystemCompIdx); }
86
87 /*!
88 * \brief Initialize the fluid system's static parameters generically
89 */
90 template<class ...Args>
91 static void init(Args&&... args)
92
4/6
✓ Branch 1 taken 69 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
81 { MultiPhaseFluidSystem::init(std::forward<Args>(args)...); }
93
94 /****************************************
95 * Fluid phase related static parameters
96 ****************************************/
97 /*!
98 * \brief Return the human readable name of a fluid phase
99 *
100 * \param phaseIdx The index of the fluid phase to consider
101 */
102 static std::string phaseName(int phaseIdx = 0)
103
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1772 { return MultiPhaseFluidSystem::phaseName(phase); }
104
105 /*!
106 * \brief A human readable name for the component.
107 *
108 * \param compIdx The index of the component to consider
109 */
110 static std::string componentName(int compIdx)
111
36/54
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 77 times.
✓ Branch 2 taken 267172 times.
✓ Branch 3 taken 78 times.
✓ Branch 4 taken 78 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 35042 times.
✓ Branch 7 taken 25 times.
✓ Branch 8 taken 12 times.
✓ Branch 9 taken 11 times.
✓ Branch 10 taken 16 times.
✓ Branch 11 taken 12 times.
✓ Branch 12 taken 11 times.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 5 times.
✓ 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 33 taken 12 times.
✓ Branch 34 taken 12 times.
✓ Branch 36 taken 36 times.
✓ Branch 37 taken 12 times.
✓ 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.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 1 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 1 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
337173 { return MultiPhaseFluidSystem::componentName(AdapterPolicy::compIdx(compIdx)); }
112
113 /*!
114 * \brief A human readable name for the component.
115 */
116 static std::string name()
117 { return MultiPhaseFluidSystem::phaseName(phase); }
118
119 /*!
120 * \brief There is only one phase, so no mass transfer between phases can occur
121 */
122 static constexpr bool isMiscible()
123 { return false; }
124
125 /*!
126 * \brief Returns whether the fluid is gaseous
127 */
128 static constexpr bool isGas(int phaseIdx = 0)
129 { return MultiPhaseFluidSystem::isGas(phase); }
130
131 /*!
132 * \brief Returns true if and only if a fluid phase is assumed to
133 * be an ideal mixture.
134 *
135 * We define an ideal mixture as a fluid phase where the fugacity
136 * coefficients of all components times the pressure of the phase
137 * are independent on the fluid composition. This assumption is true
138 * if only a single component is involved. If you are unsure what
139 * this function should return, it is safe to return false. The
140 * only damage done will be (slightly) increased computation times
141 * in some cases.
142 *
143 * \param phaseIdx The index of the fluid phase to consider
144 */
145 static constexpr bool isIdealMixture(int phaseIdx = 0)
146
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
5 { return MultiPhaseFluidSystem::isIdealMixture(phase); }
147
148 /*!
149 * \brief Returns true if the fluid is assumed to be compressible
150 */
151 static constexpr bool isCompressible(int phaseIdx = 0)
152 { return MultiPhaseFluidSystem::isCompressible(phase); }
153
154 /*!
155 * \brief Returns true if the fluid viscosity is constant
156 */
157 static constexpr bool viscosityIsConstant(int phaseIdx = 0)
158 { return MultiPhaseFluidSystem::viscosityIsConstant(phase); }
159
160 /*!
161 * \brief Returns true if the fluid is assumed to be an ideal gas
162 */
163 static constexpr bool isIdealGas(int phaseIdx = 0)
164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 { return MultiPhaseFluidSystem::isIdealGas(phase); }
165
166 /*!
167 * \brief The mass in \f$\mathrm{[kg]}\f$ of one mole of the component.
168 */
169 654032 static Scalar molarMass(int compIdx)
170
43/45
✓ Branch 0 taken 24632586 times.
✓ Branch 1 taken 24472138 times.
✓ Branch 2 taken 43536970 times.
✓ Branch 3 taken 107335111 times.
✓ Branch 4 taken 60263221 times.
✓ Branch 5 taken 18268862 times.
✓ Branch 6 taken 125254737 times.
✓ Branch 7 taken 86517859 times.
✓ Branch 8 taken 28988828 times.
✓ Branch 9 taken 156492838 times.
✓ Branch 10 taken 46766505 times.
✓ Branch 11 taken 27963832 times.
✓ Branch 12 taken 103266871 times.
✓ Branch 13 taken 28447750 times.
✓ Branch 14 taken 20172562 times.
✓ Branch 15 taken 76242308 times.
✓ Branch 16 taken 2647976 times.
✓ Branch 17 taken 104840 times.
✓ Branch 18 taken 34597381 times.
✓ Branch 19 taken 36145213 times.
✓ Branch 20 taken 11110670 times.
✓ Branch 21 taken 9527713 times.
✓ Branch 22 taken 6178803 times.
✓ Branch 23 taken 6158220 times.
✓ Branch 24 taken 36109225 times.
✓ Branch 25 taken 36119525 times.
✓ Branch 26 taken 30800 times.
✓ Branch 27 taken 417275 times.
✓ Branch 28 taken 417275 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 1389145 times.
✓ Branch 31 taken 1389145 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 8425 times.
✓ Branch 34 taken 8425 times.
✓ Branch 36 taken 25 times.
✓ Branch 37 taken 25 times.
✓ Branch 39 taken 25 times.
✓ Branch 40 taken 25 times.
✓ Branch 42 taken 25 times.
✓ Branch 43 taken 25 times.
✓ Branch 45 taken 25 times.
✓ Branch 46 taken 25 times.
✓ Branch 48 taken 25 times.
✓ Branch 49 taken 25 times.
1581383728 { return MultiPhaseFluidSystem::molarMass(AdapterPolicy::compIdx(compIdx)); }
171
172 using Base<Scalar, ThisType>::density;
173 //! \copydoc Base<Scalar,ThisType>::density(const FluidState&,int)
174 template <class FluidState>
175 74551613 static Scalar density(const FluidState &fluidState, int phaseIdx = 0)
176 {
177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 74547709 times.
74551613 assert(phaseIdx == 0);
178
2/4
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
77459748 return MultiPhaseFluidSystem::density(adaptFluidState(fluidState), phase);
179 }
180
181 using Base<Scalar, ThisType>::molarDensity;
182 //! \copydoc Base<Scalar,ThisType>::molarDensity(const FluidState&,int)
183 template <class FluidState>
184 73975563 static Scalar molarDensity(const FluidState &fluidState, int phaseIdx = 0)
185 {
186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73975559 times.
73975563 assert(phaseIdx == 0);
187 73975563 return MultiPhaseFluidSystem::molarDensity(adaptFluidState(fluidState), phase);
188 }
189
190 using Base<Scalar, ThisType>::enthalpy;
191 //! \copydoc Base<Scalar,ThisType>::enthalpy(const FluidState&,int)
192 template <class FluidState>
193 37020836 static Scalar enthalpy(const FluidState &fluidState, int phaseIdx = 0)
194 {
195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37018882 times.
37020836 assert(phaseIdx == 0);
196 37020836 return MultiPhaseFluidSystem::enthalpy(adaptFluidState(fluidState), phase);
197 }
198
199 /*!
200 * \brief Returns the specific enthalpy \f$\mathrm{[J/kg]}\f$ of a component in a specific phase
201 * \param fluidState An arbitrary fluid state
202 * \param phaseIdx The index of the fluid phase to consider
203 * \param compIdx The index of the component to consider
204 *
205 */
206 template <class FluidState>
207 52500112 static Scalar componentEnthalpy(const FluidState &fluidState,
208 int phaseIdx,
209 int compIdx)
210 {
211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52500112 times.
52500112 assert(phaseIdx == 0);
212
2/4
✓ Branch 0 taken 30162118 times.
✓ Branch 1 taken 30222794 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
90547030 return MultiPhaseFluidSystem::componentEnthalpy(adaptFluidState(fluidState), phase,
213 52500112 AdapterPolicy::compIdx(compIdx));
214 }
215
216 using Base<Scalar, ThisType>::viscosity;
217 //! \copydoc Base<Scalar,ThisType>::viscosity(const FluidState&,int)
218 template <class FluidState>
219 71485827 static Scalar viscosity(const FluidState &fluidState, int phaseIdx = 0)
220 {
221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71481923 times.
71485827 assert(phaseIdx == 0);
222
2/4
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
71485842 return MultiPhaseFluidSystem::viscosity(adaptFluidState(fluidState), phase);
223 }
224
225 using Base<Scalar, ThisType>::fugacityCoefficient;
226 //! \copydoc Base<Scalar,ThisType>::fugacityCoefficient(const FluidState&,int,int)
227 template <class FluidState>
228 10 static Scalar fugacityCoefficient(const FluidState &fluidState,
229 int phaseIdx,
230 int compIdx)
231 {
232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
10 assert(phaseIdx == 0);
233
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
16 return MultiPhaseFluidSystem::fugacityCoefficient(adaptFluidState(fluidState), phase,
234 10 AdapterPolicy::compIdx(compIdx));
235 }
236
237 using Base<Scalar, ThisType>::diffusionCoefficient;
238 //! \copydoc Base<Scalar,ThisType>::diffusionCoefficient(const FluidState&,int,int)
239 template <class FluidState>
240 14 static Scalar diffusionCoefficient(const FluidState &fluidState,
241 int phaseIdx,
242 int compIdx)
243 {
244
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
14 assert(phaseIdx == 0);
245
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
14 return MultiPhaseFluidSystem::diffusionCoefficient(adaptFluidState(fluidState), phase,
246 AdapterPolicy::compIdx(compIdx));
247 }
248
249 using Base<Scalar, ThisType>::binaryDiffusionCoefficient;
250 //! \copydoc Base<Scalar,ThisType>::binaryDiffusionCoefficient(const FluidState&,int,int,int)
251 template <class FluidState>
252 71489857 static Scalar binaryDiffusionCoefficient(const FluidState &fluidState,
253 int phaseIdx,
254 int compIIdx,
255 int compJIdx)
256 {
257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71489842 times.
71489857 assert(phaseIdx == 0);
258
4/4
✓ Branch 0 taken 71489835 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 71489834 times.
142979716 return MultiPhaseFluidSystem::binaryDiffusionCoefficient(adaptFluidState(fluidState), phase,
259 AdapterPolicy::compIdx(compIIdx),
260 71489843 AdapterPolicy::compIdx(compJIdx));
261 }
262
263 using Base<Scalar, ThisType>::thermalConductivity;
264 //! \copydoc Base<Scalar,ThisType>::thermalConductivity(const FluidState&,int)
265 template <class FluidState>
266 14355920 static Scalar thermalConductivity(const FluidState &fluidState,
267 int phaseIdx = 0)
268 {
269
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14355916 times.
14355920 assert(phaseIdx == 0);
270 120021491 return MultiPhaseFluidSystem::thermalConductivity(adaptFluidState(fluidState), phase);
271 }
272
273 using Base<Scalar, ThisType>::heatCapacity;
274 //! \copydoc Base<Scalar,ThisType>::heatCapacity(const FluidState&,int)
275 template <class FluidState>
276 1391827 static Scalar heatCapacity(const FluidState &fluidState,
277 int phaseIdx = 0)
278 {
279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1391823 times.
1391827 assert(phaseIdx == 0);
280 19581317 return MultiPhaseFluidSystem::heatCapacity(adaptFluidState(fluidState), phase);
281 }
282 };
283
284 } // namespace FluidSystems
285 } // namespace
286
287 #endif
288