3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
adapter.hh
Go to the documentation of this file.
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_MATERIAL_FLUID_STATE_ADAPTER_HH
25#define DUMUX_MATERIAL_FLUID_STATE_ADAPTER_HH
26
27#include <dune/common/exceptions.hh>
28
29namespace Dumux {
30
42template<class FluidState, class AdapterPolicy>
44{
45 using FluidSystem = typename AdapterPolicy::FluidSystem;
46public:
48 using Scalar = typename FluidState::Scalar;
49
51 static constexpr int numPhases = FluidSystem::numPhases;
52 static constexpr int numComponents = FluidSystem::numComponents;
53
59 FluidStateAdapter(const FluidState& fluidState)
60 : fluidState_(fluidState)
61 {}
62
66 // \{
67 int wettingPhase() const
68 { DUNE_THROW(Dune::InvalidStateException, "wetting phase index cannot be mapped"); }
69
70 Scalar moleFraction(int phaseIdx, int compIdx) const
71 {
72 Scalar sumMoleFrac = 0.0;
73 for (int cIdx = 0; cIdx < numComponents; ++cIdx)
74 sumMoleFrac += fluidState_.moleFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(cIdx));
75
76 return fluidState_.moleFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(compIdx))/sumMoleFrac;
77 }
78
79 Scalar massFraction(int phaseIdx, int compIdx) const
80 {
81 Scalar sumMassFrac = 0.0;
82 for (int cIdx = 0; cIdx < numComponents; ++cIdx)
83 sumMassFrac += fluidState_.massFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(cIdx));
84
85 return fluidState_.massFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(compIdx))/sumMassFrac;
86 }
87
88 Scalar averageMolarMass(int phaseIdx) const
89 {
90 Scalar sumXi = 0.0;
91 Scalar sumXiMi = 0.0;
92 for (int cIdx = 0; cIdx < numComponents; ++cIdx)
93 {
94 const auto xi = fluidState_.moleFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(cIdx));
95 sumXi += xi;
96 sumXiMi += xi*FluidSystem::molarMass(cIdx);
97 }
98
99 return sumXiMi/sumXi;
100 }
101
102 Scalar pressure(int phaseIdx) const
103 { return fluidState_.pressure(AdapterPolicy::phaseIdx(phaseIdx)); }
104
105 Scalar partialPressure(int phaseIdx, int compIdx) const
106 {
107 assert(FluidSystem::isGas(phaseIdx));
108 return pressure(phaseIdx)*moleFraction(phaseIdx, compIdx);
109 }
110
111 Scalar temperature(int phaseIdx) const
112 { return fluidState_.temperature(AdapterPolicy::phaseIdx(phaseIdx)); }
113
115 { return fluidState_.temperature(0); }
116 // \}
117
118private:
119 const FluidState& fluidState_;
120};
121
122} // end namespace Dumux
123
124#endif
FluidStateAdapter(const FluidState &fluidState)
Adapter class for fluid states with different indices.
Definition: adapter.hh:59
Definition: adapt.hh:29
Adapter class for fluid states with different indices.
Definition: adapter.hh:44
Scalar averageMolarMass(int phaseIdx) const
Definition: adapter.hh:88
static constexpr int numPhases
export number of phases and components of the embedded fluid system
Definition: adapter.hh:51
static constexpr int numComponents
Definition: adapter.hh:52
Scalar temperature(int phaseIdx) const
Definition: adapter.hh:111
Scalar massFraction(int phaseIdx, int compIdx) const
Definition: adapter.hh:79
typename FluidState::Scalar Scalar
export scalar type
Definition: adapter.hh:48
Scalar pressure(int phaseIdx) const
Definition: adapter.hh:102
Scalar moleFraction(int phaseIdx, int compIdx) const
Definition: adapter.hh:70
Scalar temperature() const
Definition: adapter.hh:114
int wettingPhase() const
Definition: adapter.hh:67
Scalar partialPressure(int phaseIdx, int compIdx) const
Definition: adapter.hh:105