version 3.8
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_MATERIAL_FLUID_STATE_ADAPTER_HH
13#define DUMUX_MATERIAL_FLUID_STATE_ADAPTER_HH
14
15#include <dune/common/exceptions.hh>
16
17namespace Dumux {
18
30template<class FluidState, class AdapterPolicy>
32{
33 using FluidSystem = typename AdapterPolicy::FluidSystem;
34public:
36 using Scalar = typename FluidState::Scalar;
37
39 static constexpr int numPhases = FluidSystem::numPhases;
40 static constexpr int numComponents = FluidSystem::numComponents;
41
47 FluidStateAdapter(const FluidState& fluidState)
48 : fluidState_(fluidState)
49 {}
50
54 // \{
55 int wettingPhase() const
56 { DUNE_THROW(Dune::InvalidStateException, "wetting phase index cannot be mapped"); }
57
58 Scalar moleFraction(int phaseIdx, int compIdx) const
59 {
60 Scalar sumMoleFrac = 0.0;
61 for (int cIdx = 0; cIdx < numComponents; ++cIdx)
62 sumMoleFrac += fluidState_.moleFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(cIdx));
63
64 return fluidState_.moleFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(compIdx))/sumMoleFrac;
65 }
66
67 Scalar massFraction(int phaseIdx, int compIdx) const
68 {
69 Scalar sumMassFrac = 0.0;
70 for (int cIdx = 0; cIdx < numComponents; ++cIdx)
71 sumMassFrac += fluidState_.massFraction(AdapterPolicy::phaseIdx(phaseIdx), AdapterPolicy::compIdx(cIdx));
72
73 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 { return fluidState_.pressure(AdapterPolicy::phaseIdx(phaseIdx)); }
92
93 Scalar partialPressure(int phaseIdx, int compIdx) const
94 {
95 assert(FluidSystem::isGas(phaseIdx));
96 return pressure(phaseIdx)*moleFraction(phaseIdx, compIdx);
97 }
98
99 Scalar temperature(int phaseIdx) const
100 { return fluidState_.temperature(AdapterPolicy::phaseIdx(phaseIdx)); }
101
103 { return fluidState_.temperature(0); }
104 // \}
105
106private:
107 const FluidState& fluidState_;
108};
109
110} // end namespace Dumux
111
112#endif
Adapter class for fluid states with different indices.
Definition: adapter.hh:32
Scalar averageMolarMass(int phaseIdx) const
Definition: adapter.hh:76
static constexpr int numPhases
export number of phases and components of the embedded fluid system
Definition: adapter.hh:39
static constexpr int numComponents
Definition: adapter.hh:40
Scalar temperature(int phaseIdx) const
Definition: adapter.hh:99
Scalar massFraction(int phaseIdx, int compIdx) const
Definition: adapter.hh:67
typename FluidState::Scalar Scalar
export scalar type
Definition: adapter.hh:36
Scalar pressure(int phaseIdx) const
Definition: adapter.hh:90
Scalar moleFraction(int phaseIdx, int compIdx) const
Definition: adapter.hh:58
Scalar temperature() const
Definition: adapter.hh:102
int wettingPhase() const
Definition: adapter.hh:55
Scalar partialPressure(int phaseIdx, int compIdx) const
Definition: adapter.hh:93
FluidStateAdapter(const FluidState &fluidState)
Adapter class for fluid states with different indices.
Definition: adapter.hh:47
Definition: adapt.hh:17