GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/material/fluidsystems/1padapter.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 44 54 81.5%
Functions: 66 107 61.7%
Branches: 146 287 50.9%

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
28/60
✓ Branch 0 taken 110087250 times.
✓ Branch 1 taken 110087250 times.
✓ Branch 2 taken 55043625 times.
✓ Branch 3 taken 55043625 times.
✓ Branch 4 taken 72199302 times.
✓ Branch 5 taken 72199302 times.
✓ Branch 6 taken 36112067 times.
✓ Branch 7 taken 36112067 times.
✓ Branch 8 taken 77228264 times.
✓ Branch 9 taken 77228264 times.
✓ Branch 10 taken 38614132 times.
✓ Branch 11 taken 38614132 times.
✓ Branch 12 taken 127977510 times.
✓ Branch 13 taken 127977510 times.
✓ Branch 14 taken 63988755 times.
✓ Branch 15 taken 63988755 times.
✓ Branch 16 taken 48343679 times.
✓ Branch 17 taken 48343679 times.
✓ Branch 18 taken 31096690 times.
✓ Branch 19 taken 31096690 times.
✓ Branch 20 taken 4842643 times.
✓ Branch 21 taken 4842643 times.
✓ Branch 22 taken 4792979 times.
✓ Branch 23 taken 4792979 times.
✓ Branch 24 taken 17418454 times.
✓ Branch 25 taken 17418454 times.
✓ Branch 26 taken 17393622 times.
✓ Branch 27 taken 17393622 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ 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 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
1410277944 if (compIdx == 0)
54 return phase;
55
21/50
✗ Branch 0 not taken.
✓ Branch 1 taken 1408170 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62216345 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 19904806 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 34502372 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 35953558 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 1164775 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 17222159 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 5339569 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 1028938 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 15 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 6954611 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 39051 times.
✓ Branch 24 taken 12 times.
✓ Branch 25 taken 20 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 5248 times.
✓ Branch 28 taken 1 times.
✓ Branch 29 taken 2 times.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ 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 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
185739660 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 471801511 { 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 67 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
79 { 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.
1637 { 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
14/54
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 75 times.
✓ Branch 2 taken 267172 times.
✓ Branch 3 taken 77 times.
✓ Branch 4 taken 76 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 35042 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 12 times.
✓ Branch 9 taken 11 times.
✓ Branch 10 taken 14 times.
✓ Branch 11 taken 12 times.
✓ Branch 12 taken 11 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 5 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
337019 { 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
33/45
✓ Branch 0 taken 24630636 times.
✓ Branch 1 taken 24470188 times.
✓ Branch 2 taken 43536970 times.
✓ Branch 3 taken 106225886 times.
✓ Branch 4 taken 59153996 times.
✓ Branch 5 taken 18268862 times.
✓ Branch 6 taken 124144537 times.
✓ Branch 7 taken 85407659 times.
✓ Branch 8 taken 28988828 times.
✓ Branch 9 taken 154852888 times.
✓ Branch 10 taken 45126555 times.
✓ Branch 11 taken 27963832 times.
✓ Branch 12 taken 102443971 times.
✓ Branch 13 taken 27624850 times.
✓ Branch 14 taken 20172562 times.
✓ Branch 15 taken 76242283 times.
✓ Branch 16 taken 2647950 times.
✓ Branch 17 taken 104840 times.
✓ Branch 18 taken 34597355 times.
✓ Branch 19 taken 36145188 times.
✓ Branch 20 taken 11110670 times.
✓ Branch 21 taken 9527687 times.
✓ Branch 22 taken 6178777 times.
✓ Branch 23 taken 6158220 times.
✓ Branch 24 taken 34471200 times.
✓ Branch 25 taken 34481500 times.
✓ Branch 26 taken 30800 times.
✓ Branch 27 taken 415450 times.
✓ Branch 28 taken 415450 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 1389120 times.
✓ Branch 31 taken 1389120 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 8400 times.
✓ Branch 34 taken 8400 times.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
1562414648 { 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 73724813 static Scalar density(const FluidState &fluidState, int phaseIdx = 0)
176 {
177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73724809 times.
73724813 assert(phaseIdx == 0);
178
2/4
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
76632947 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 73154613 static Scalar molarDensity(const FluidState &fluidState, int phaseIdx = 0)
185 {
186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73154609 times.
73154613 assert(phaseIdx == 0);
187 73154613 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 36197936 static Scalar enthalpy(const FluidState &fluidState, int phaseIdx = 0)
194 {
195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36197932 times.
36197936 assert(phaseIdx == 0);
196 36197936 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 50283612 static Scalar componentEnthalpy(const FluidState &fluidState,
208 int phaseIdx,
209 int compIdx)
210 {
211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50283612 times.
50283612 assert(phaseIdx == 0);
212
2/4
✓ Branch 0 taken 29053868 times.
✓ Branch 1 taken 29114544 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
87222280 return MultiPhaseFluidSystem::componentEnthalpy(adaptFluidState(fluidState), phase,
213 50283612 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 70659027 static Scalar viscosity(const FluidState &fluidState, int phaseIdx = 0)
220 {
221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70659023 times.
70659027 assert(phaseIdx == 0);
222
2/4
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
70659041 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 70668907 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 70668892 times.
70668907 assert(phaseIdx == 0);
258
4/4
✓ Branch 0 taken 70668885 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 70668884 times.
141337816 return MultiPhaseFluidSystem::binaryDiffusionCoefficient(adaptFluidState(fluidState), phase,
259 AdapterPolicy::compIdx(compIIdx),
260 70668893 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 115753591 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 18760617 return MultiPhaseFluidSystem::heatCapacity(adaptFluidState(fluidState), phase);
281 }
282 };
283
284 } // namespace FluidSystems
285 } // namespace
286
287 #endif
288