My Project
Loading...
Searching...
No Matches
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#include <stdexcept>
36
37namespace Opm {
38
43template <class Scalar,
44 unsigned numPhases,
45 unsigned numComponents,
46 class Implementation>
48{
49public:
51 {
52 Valgrind::SetUndefined(fugacityCoefficient_);
53 }
54
58 const Scalar& fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
59 { return fugacityCoefficient_[phaseIdx][compIdx]; }
60
64 Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
65 { return asImp_().pressure(phaseIdx)*fugacityCoefficient_[phaseIdx][compIdx]*asImp_().moleFraction(phaseIdx, compIdx); }
66
70 void setFugacityCoefficient(unsigned phaseIdx, unsigned compIdx, const Scalar& value)
71 { fugacityCoefficient_[phaseIdx][compIdx] = value; }
72
77 template <class FluidState>
78 void assign(const FluidState& fs)
79 {
80 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
81 for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
82 fugacityCoefficient_[phaseIdx][compIdx] = fs.fugacityCoefficient(phaseIdx, compIdx);
83 }
84 }
85 }
86
95 void checkDefined() const
96 {
97 Valgrind::CheckDefined(fugacityCoefficient_);
98 }
99
100protected:
101 const Implementation& asImp_() const
102 { return *static_cast<const Implementation*>(this); }
103
104 Scalar fugacityCoefficient_[numPhases][numComponents];
105};
106
111template <class Scalar,
112 unsigned numPhases,
113 unsigned numComponents,
114 class Implementation>
116{
117 static_assert(numPhases == numComponents,
118 "The number of phases must be the same as the number of (pseudo-) components if you assume immiscibility");
119
120public:
122 { Valgrind::SetUndefined(fugacityCoefficient_); }
123
127 Scalar fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
128 { return (phaseIdx == compIdx)?fugacityCoefficient_[phaseIdx]:std::numeric_limits<Scalar>::infinity(); }
129
133 Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
134 { return asImp_().pressure(phaseIdx)*fugacityCoefficient(phaseIdx, compIdx)*asImp_().moleFraction(phaseIdx, compIdx); }
135
139 void setFugacityCoefficient(unsigned phaseIdx, const Scalar& value)
140 { fugacityCoefficient_[phaseIdx] = value; }
141
146 template <class FluidState>
147 void assign(const FluidState& fs)
148 {
149 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
150 fugacityCoefficient_[phaseIdx] = fs.fugacityCoefficient(phaseIdx, /*compIdx=*/phaseIdx);
151 }
152 }
153
162 void checkDefined() const
163 {
164 Valgrind::CheckDefined(fugacityCoefficient_);
165 }
166
167protected:
168 const Implementation& asImp_() const
169 { return *static_cast<const Implementation*>(this); }
170
171 Scalar fugacityCoefficient_[numPhases];
172};
173
178template <class Scalar>
180{
181public:
183 { }
184
188 const Scalar& fugacityCoefficient(unsigned /* phaseIdx */, unsigned /* compIdx */) const
189 { throw std::logic_error("Fugacity coefficients are not provided by this fluid state"); }
190
194 const Scalar& fugacity(unsigned /* phaseIdx */, unsigned /* compIdx */) const
195 { throw std::logic_error("Fugacities coefficients are not provided by this fluid state"); }
196
205 void checkDefined() const
206 { }
207};
208
209
210} // namespace Opm
211
212#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:48
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition FluidStateFugacityModules.hpp:78
void checkDefined() const
Make sure that all attributes are defined.
Definition FluidStateFugacityModules.hpp:95
void setFugacityCoefficient(unsigned phaseIdx, unsigned compIdx, const Scalar &value)
Set the fugacity of a component in a phase [].
Definition FluidStateFugacityModules.hpp:70
Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
The fugacity of a component in a phase [Pa].
Definition FluidStateFugacityModules.hpp:64
const Scalar & fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
The fugacity coefficient of a component in a phase [].
Definition FluidStateFugacityModules.hpp:58
Module for the modular fluid state which stores the phase fugacity coefficients explicitly assuming i...
Definition FluidStateFugacityModules.hpp:116
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition FluidStateFugacityModules.hpp:147
Scalar fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
The fugacity coefficient of a component in a phase [].
Definition FluidStateFugacityModules.hpp:127
void setFugacityCoefficient(unsigned phaseIdx, const Scalar &value)
Set the fugacity of a component in a phase [].
Definition FluidStateFugacityModules.hpp:139
void checkDefined() const
Make sure that all attributes are defined.
Definition FluidStateFugacityModules.hpp:162
Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
The fugacity of a component in a phase [Pa].
Definition FluidStateFugacityModules.hpp:133
Module for the modular fluid state which does not store the fugacities but throws std::logic_error in...
Definition FluidStateFugacityModules.hpp:180
const Scalar & fugacity(unsigned, unsigned) const
The fugacity of a component in a phase [Pa].
Definition FluidStateFugacityModules.hpp:194
const Scalar & fugacityCoefficient(unsigned, unsigned) const
The fugacity coefficient of a component in a phase [].
Definition FluidStateFugacityModules.hpp:188
void checkDefined() const
Make sure that all attributes are defined.
Definition FluidStateFugacityModules.hpp:205
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30