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 FluidStates | ||
10 | * \brief Adapter class for fluid states with different indices | ||
11 | */ | ||
12 | #ifndef DUMUX_MATERIAL_FLUID_STATE_ADAPTER_HH | ||
13 | #define DUMUX_MATERIAL_FLUID_STATE_ADAPTER_HH | ||
14 | |||
15 | #include <dune/common/exceptions.hh> | ||
16 | |||
17 | namespace Dumux { | ||
18 | |||
19 | /*! | ||
20 | * \ingroup FluidStates | ||
21 | * \tparam FluidState the fluid state that is adapted to another fluid state's index set | ||
22 | * \tparam AdapterPolicy | ||
23 | * \brief Adapter class for fluid states with different indices | ||
24 | * \note This is useful when writing a fluid system that has another fluid system as an ingredient | ||
25 | * To forward to the other fluid system (which variables to be sorted according to its own indices) | ||
26 | * create the fluid state adapter of the fluid state to forward and pass the adapter to this fluid state. | ||
27 | * You need to provide an adapter policy which maps the phase and component indices from the embedded fluid | ||
28 | * system's indices to the actual fluid system's indices. | ||
29 | */ | ||
30 | template<class FluidState, class AdapterPolicy> | ||
31 | class FluidStateAdapter | ||
32 | { | ||
33 | using FluidSystem = typename AdapterPolicy::FluidSystem; | ||
34 | public: | ||
35 | //! export scalar type | ||
36 | using Scalar = typename FluidState::Scalar; | ||
37 | |||
38 | //! export number of phases and components of the embedded fluid system | ||
39 | static constexpr int numPhases = FluidSystem::numPhases; | ||
40 | static constexpr int numComponents = FluidSystem::numComponents; | ||
41 | |||
42 | /*! | ||
43 | * \ingroup FluidStates | ||
44 | * \brief Adapter class for fluid states with different indices | ||
45 | * \param fluidState the fluid state to be wrapped | ||
46 | */ | ||
47 | 17173984 | FluidStateAdapter(const FluidState& fluidState) | |
48 | 17173984 | : fluidState_(fluidState) | |
49 | {} | ||
50 | |||
51 | /*! | ||
52 | * \name Member functions forwarding to the fluid state mapping the indices | ||
53 | */ | ||
54 | // \{ | ||
55 | int wettingPhase() const | ||
56 | { DUNE_THROW(Dune::InvalidStateException, "wetting phase index cannot be mapped"); } | ||
57 | |||
58 | 16 | Scalar moleFraction(int phaseIdx, int compIdx) const | |
59 | { | ||
60 | 16 | Scalar sumMoleFrac = 0.0; | |
61 |
16/28✓ Branch 0 taken 289013480 times.
✓ Branch 1 taken 144506740 times.
✓ Branch 2 taken 6794008 times.
✓ Branch 3 taken 3397004 times.
✓ Branch 4 taken 325347896 times.
✓ Branch 5 taken 162673948 times.
✓ Branch 6 taken 137910216 times.
✓ Branch 7 taken 68955108 times.
✓ Branch 8 taken 37285360 times.
✓ Branch 9 taken 18642680 times.
✓ Branch 10 taken 37384688 times.
✓ Branch 11 taken 18692344 times.
✓ Branch 12 taken 34836908 times.
✓ Branch 13 taken 17418454 times.
✓ Branch 14 taken 34737580 times.
✓ Branch 15 taken 17368790 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
1354965228 | for (int cIdx = 0; cIdx < numComponents; ++cIdx) |
62 |
16/28✓ Branch 0 taken 144506740 times.
✓ Branch 1 taken 144506740 times.
✓ Branch 2 taken 3397004 times.
✓ Branch 3 taken 3397004 times.
✓ Branch 4 taken 162673948 times.
✓ Branch 5 taken 162673948 times.
✓ Branch 6 taken 68955108 times.
✓ Branch 7 taken 68955108 times.
✓ Branch 8 taken 18642680 times.
✓ Branch 9 taken 18642680 times.
✓ Branch 10 taken 18692344 times.
✓ Branch 11 taken 18692344 times.
✓ Branch 12 taken 17418454 times.
✓ Branch 13 taken 17418454 times.
✓ Branch 14 taken 17368790 times.
✓ Branch 15 taken 17368790 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
1806620288 | sumMoleFrac += fluidState_.moleFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(cIdx)); |
63 | |||
64 |
12/12✓ Branch 0 taken 72240950 times.
✓ Branch 1 taken 72240958 times.
✓ Branch 2 taken 1692592 times.
✓ Branch 3 taken 1692592 times.
✓ Branch 4 taken 81244152 times.
✓ Branch 5 taken 81244152 times.
✓ Branch 6 taken 34502386 times.
✓ Branch 7 taken 34502386 times.
✓ Branch 8 taken 49664 times.
✓ Branch 9 taken 49664 times.
✓ Branch 10 taken 24832 times.
✓ Branch 11 taken 24832 times.
|
740722548 | return fluidState_.moleFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(compIdx))/sumMoleFrac; |
65 | } | ||
66 | |||
67 | 72960115 | Scalar massFraction(int phaseIdx, int compIdx) const | |
68 | { | ||
69 | 72960115 | Scalar sumMassFrac = 0.0; | |
70 |
2/4✓ Branch 0 taken 192644078 times.
✓ Branch 1 taken 72960091 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
265604241 | for (int cIdx = 0; cIdx < numComponents; ++cIdx) |
71 |
4/4✓ Branch 0 taken 49598143 times.
✓ Branch 1 taken 49598143 times.
✓ Branch 2 taken 42551648 times.
✓ Branch 3 taken 42551648 times.
|
327345589 | sumMassFrac += fluidState_.massFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(cIdx)); |
72 | |||
73 |
4/4✓ Branch 0 taken 28297463 times.
✓ Branch 1 taken 21300680 times.
✓ Branch 2 taken 21275824 times.
✓ Branch 3 taken 21275824 times.
|
101257626 | return fluidState_.massFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(compIdx))/sumMassFrac; |
74 | } | ||
75 | |||
76 | ✗ | Scalar averageMolarMass(int phaseIdx) const | |
77 | { | ||
78 | ✗ | Scalar sumXi = 0.0; | |
79 | ✗ | Scalar sumXiMi = 0.0; | |
80 | ✗ | for (int cIdx = 0; cIdx < numComponents; ++cIdx) | |
81 | { | ||
82 | ✗ | const auto xi = fluidState_.moleFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(cIdx)); | |
83 | ✗ | sumXi += xi; | |
84 | ✗ | sumXiMi += xi*FluidSystem::molarMass(cIdx); | |
85 | } | ||
86 | |||
87 | ✗ | return sumXiMi/sumXi; | |
88 | } | ||
89 | |||
90 | ✗ | Scalar pressure(int phaseIdx) const | |
91 |
29/32✓ Branch 0 taken 38235262 times.
✓ Branch 1 taken 66127597 times.
✓ Branch 2 taken 38235262 times.
✓ Branch 3 taken 66127597 times.
✓ Branch 4 taken 34223547 times.
✓ Branch 5 taken 35143314 times.
✓ Branch 6 taken 34223547 times.
✓ Branch 7 taken 38236584 times.
✓ Branch 8 taken 32551696 times.
✓ Branch 9 taken 38253113 times.
✓ Branch 10 taken 37840542 times.
✓ Branch 11 taken 36861292 times.
✓ Branch 12 taken 27355150 times.
✓ Branch 13 taken 44423815 times.
✓ Branch 14 taken 27355150 times.
✓ Branch 15 taken 44423813 times.
✓ Branch 16 taken 13037631 times.
✓ Branch 17 taken 23710963 times.
✓ Branch 18 taken 13037631 times.
✓ Branch 19 taken 23710965 times.
✓ Branch 20 taken 5211205 times.
✓ Branch 21 taken 29828451 times.
✓ Branch 22 taken 5211205 times.
✓ Branch 23 taken 29975089 times.
✓ Branch 24 taken 4763815 times.
✓ Branch 25 taken 17368790 times.
✓ Branch 26 taken 4763815 times.
✓ Branch 27 taken 17222150 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 3093270 times.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
|
948347719 | { return fluidState_.pressure(AdapterPolicy::phaseIdx(phaseIdx)); } |
92 | |||
93 | 162587616 | Scalar partialPressure(int phaseIdx, int compIdx) const | |
94 | { | ||
95 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 162587610 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 162587610 times.
|
162587616 | assert(FluidSystem::isGas(phaseIdx)); |
96 | 325175220 | return pressure(phaseIdx)*moleFraction(phaseIdx, compIdx); | |
97 | } | ||
98 | |||
99 | ✗ | Scalar temperature(int phaseIdx) const | |
100 |
29/32✓ Branch 0 taken 38235262 times.
✓ Branch 1 taken 66127597 times.
✓ Branch 2 taken 38235262 times.
✓ Branch 3 taken 66127597 times.
✓ Branch 4 taken 34223547 times.
✓ Branch 5 taken 35143314 times.
✓ Branch 6 taken 34223547 times.
✓ Branch 7 taken 38236584 times.
✓ Branch 8 taken 32551696 times.
✓ Branch 9 taken 38253113 times.
✓ Branch 10 taken 37840542 times.
✓ Branch 11 taken 36861292 times.
✓ Branch 12 taken 27355150 times.
✓ Branch 13 taken 44423815 times.
✓ Branch 14 taken 27355150 times.
✓ Branch 15 taken 44423813 times.
✓ Branch 16 taken 13037631 times.
✓ Branch 17 taken 23710963 times.
✓ Branch 18 taken 13037631 times.
✓ Branch 19 taken 23710965 times.
✓ Branch 20 taken 5211205 times.
✓ Branch 21 taken 29828451 times.
✓ Branch 22 taken 5211205 times.
✓ Branch 23 taken 29975089 times.
✓ Branch 24 taken 4763815 times.
✓ Branch 25 taken 17368790 times.
✓ Branch 26 taken 4763815 times.
✓ Branch 27 taken 17222150 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 3093270 times.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
|
958318908 | { return fluidState_.temperature(AdapterPolicy::phaseIdx(phaseIdx)); } |
101 | |||
102 | Scalar temperature() const | ||
103 | { return fluidState_.temperature(0); } | ||
104 | // \} | ||
105 | |||
106 | private: | ||
107 | const FluidState& fluidState_; | ||
108 | }; | ||
109 | |||
110 | } // end namespace Dumux | ||
111 | |||
112 | #endif | ||
113 |