FluidStateFugacityModules.hpp
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 This file is part of the Open Porous Media project (OPM).
5
6 OPM 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 2 of the License, or
9 (at your option) any later version.
10
11 OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
28#ifndef OPM_FLUID_STATE_FUGACITY_MODULES_HPP
29#define OPM_FLUID_STATE_FUGACITY_MODULES_HPP
30
32
33#include <algorithm>
34#include <limits>
35
36namespace Opm {
37
42template <class Scalar,
43 unsigned numPhases,
44 unsigned numComponents,
45 class Implementation>
47{
48public:
50 {
52 }
53
57 const Scalar& fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
58 { return fugacityCoefficient_[phaseIdx][compIdx]; }
59
63 Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
64 { return asImp_().pressure(phaseIdx)*fugacityCoefficient_[phaseIdx][compIdx]*asImp_().moleFraction(phaseIdx, compIdx); }
65
69 void setFugacityCoefficient(unsigned phaseIdx, unsigned compIdx, const Scalar& value)
70 { fugacityCoefficient_[phaseIdx][compIdx] = value; }
71
76 template <class FluidState>
77 void assign(const FluidState& fs)
78 {
79 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
80 for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
81 fugacityCoefficient_[phaseIdx][compIdx] = fs.fugacityCoefficient(phaseIdx, compIdx);
82 }
83 }
84 }
85
94 void checkDefined() const
95 {
97 }
98
99protected:
100 const Implementation& asImp_() const
101 { return *static_cast<const Implementation*>(this); }
102
103 Scalar fugacityCoefficient_[numPhases][numComponents];
104};
105
110template <class Scalar,
111 unsigned numPhases,
112 unsigned numComponents,
113 class Implementation>
115{
116 static_assert(numPhases == numComponents,
117 "The number of phases must be the same as the number of (pseudo-) components if you assume immiscibility");
118
119public:
122
126 Scalar fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
127 { return (phaseIdx == compIdx)?fugacityCoefficient_[phaseIdx]:std::numeric_limits<Scalar>::infinity(); }
128
132 Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
133 { return asImp_().pressure(phaseIdx)*fugacityCoefficient(phaseIdx, compIdx)*asImp_().moleFraction(phaseIdx, compIdx); }
134
138 void setFugacityCoefficient(unsigned phaseIdx, const Scalar& value)
139 { fugacityCoefficient_[phaseIdx] = value; }
140
145 template <class FluidState>
146 void assign(const FluidState& fs)
147 {
148 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
149 fugacityCoefficient_[phaseIdx] = fs.fugacityCoefficient(phaseIdx, /*compIdx=*/phaseIdx);
150 }
151 }
152
161 void checkDefined() const
162 {
164 }
165
166protected:
167 const Implementation& asImp_() const
168 { return *static_cast<const Implementation*>(this); }
169
170 Scalar fugacityCoefficient_[numPhases];
171};
172
177template <class Scalar>
179{
180public:
182 { }
183
187 const Scalar& fugacityCoefficient(unsigned /* phaseIdx */, unsigned /* compIdx */) const
188 { throw std::logic_error("Fugacity coefficients are not provided by this fluid state"); }
189
193 const Scalar& fugacity(unsigned /* phaseIdx */, unsigned /* compIdx */) const
194 { throw std::logic_error("Fugacities coefficients are not provided by this fluid state"); }
195
204 void checkDefined() const
205 { }
206};
207
208
209} // namespace Opm
210
211#endif
Some templates to wrap the valgrind client request macros.
Module for the modular fluid state which stores the phase fugacity coefficients explicitly.
Definition: FluidStateFugacityModules.hpp:47
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateFugacityModules.hpp:77
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateFugacityModules.hpp:94
void setFugacityCoefficient(unsigned phaseIdx, unsigned compIdx, const Scalar &value)
Set the fugacity of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:69
Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
The fugacity of a component in a phase [Pa].
Definition: FluidStateFugacityModules.hpp:63
FluidStateExplicitFugacityModule()
Definition: FluidStateFugacityModules.hpp:49
Scalar fugacityCoefficient_[numPhases][numComponents]
Definition: FluidStateFugacityModules.hpp:103
const Implementation & asImp_() const
Definition: FluidStateFugacityModules.hpp:100
const Scalar & fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
The fugacity coefficient of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:57
Module for the modular fluid state which stores the phase fugacity coefficients explicitly assuming i...
Definition: FluidStateFugacityModules.hpp:115
Scalar fugacityCoefficient_[numPhases]
Definition: FluidStateFugacityModules.hpp:170
FluidStateImmiscibleFugacityModule()
Definition: FluidStateFugacityModules.hpp:120
const Implementation & asImp_() const
Definition: FluidStateFugacityModules.hpp:167
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateFugacityModules.hpp:146
Scalar fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
The fugacity coefficient of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:126
void setFugacityCoefficient(unsigned phaseIdx, const Scalar &value)
Set the fugacity of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:138
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateFugacityModules.hpp:161
Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
The fugacity of a component in a phase [Pa].
Definition: FluidStateFugacityModules.hpp:132
Module for the modular fluid state which does not store the fugacities but throws std::logic_error in...
Definition: FluidStateFugacityModules.hpp:179
FluidStateNullFugacityModule()
Definition: FluidStateFugacityModules.hpp:181
const Scalar & fugacity(unsigned, unsigned) const
The fugacity of a component in a phase [Pa].
Definition: FluidStateFugacityModules.hpp:193
const Scalar & fugacityCoefficient(unsigned, unsigned) const
The fugacity coefficient of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:187
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateFugacityModules.hpp:204
bool CheckDefined(const T &value)
Make valgrind complain if any of the memory occupied by an object is undefined.
Definition: Valgrind.hpp:74
void SetUndefined(const T &value)
Make the memory on which an object resides undefined in valgrind runs.
Definition: Valgrind.hpp:171
Definition: Air_Mesitylene.hpp:34