All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 
31 #include <opm/common/Valgrind.hpp>
32 
33 #include <opm/common/ErrorMacros.hpp>
34 #include <opm/common/Exceptions.hpp>
35 
36 #include <algorithm>
37 #include <limits>
38 
39 namespace Opm {
40 
45 template <class Scalar,
46  unsigned numPhases,
47  unsigned numComponents,
48  class Implementation>
50 {
51 public:
53  {
54  Valgrind::SetUndefined(fugacityCoefficient_);
55  }
56 
60  const Scalar& fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
61  { return fugacityCoefficient_[phaseIdx][compIdx]; }
62 
66  Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
67  { return asImp_().pressure(phaseIdx)*fugacityCoefficient_[phaseIdx][compIdx]*asImp_().moleFraction(phaseIdx, compIdx); }
68 
72  void setFugacityCoefficient(unsigned phaseIdx, unsigned compIdx, const Scalar& value)
73  { fugacityCoefficient_[phaseIdx][compIdx] = value; }
74 
79  template <class FluidState>
80  void assign(const FluidState& fs)
81  {
82  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
83  for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
84  fugacityCoefficient_[phaseIdx][compIdx] = fs.fugacityCoefficient(phaseIdx, compIdx);
85  }
86  }
87  }
88 
97  void checkDefined() const
98  {
99  Valgrind::CheckDefined(fugacityCoefficient_);
100  }
101 
102 protected:
103  const Implementation& asImp_() const
104  { return *static_cast<const Implementation*>(this); }
105 
106  Scalar fugacityCoefficient_[numPhases][numComponents];
107 };
108 
113 template <class Scalar,
114  unsigned numPhases,
115  unsigned numComponents,
116  class Implementation>
118 {
119  static_assert(numPhases == numComponents,
120  "The number of phases must be the same as the number of (pseudo-) components if you assume immiscibility");
121 
122 public:
124  { Valgrind::SetUndefined(fugacityCoefficient_); }
125 
129  Scalar fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
130  { return (phaseIdx == compIdx)?fugacityCoefficient_[phaseIdx]:std::numeric_limits<Scalar>::infinity(); }
131 
135  Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
136  { return asImp_().pressure(phaseIdx)*fugacityCoefficient(phaseIdx, compIdx)*asImp_().moleFraction(phaseIdx, compIdx); }
137 
141  void setFugacityCoefficient(unsigned phaseIdx, const Scalar& value)
142  { fugacityCoefficient_[phaseIdx] = value; }
143 
148  template <class FluidState>
149  void assign(const FluidState& fs)
150  {
151  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
152  fugacityCoefficient_[phaseIdx] = fs.fugacityCoefficient(phaseIdx, /*compIdx=*/phaseIdx);
153  }
154  }
155 
164  void checkDefined() const
165  {
166  Valgrind::CheckDefined(fugacityCoefficient_);
167  }
168 
169 protected:
170  const Implementation& asImp_() const
171  { return *static_cast<const Implementation*>(this); }
172 
173  Scalar fugacityCoefficient_[numPhases];
174 };
175 
180 template <class Scalar>
182 {
183 public:
185  { }
186 
190  const Scalar& fugacityCoefficient(unsigned /* phaseIdx */, unsigned /* compIdx */) const
191  { OPM_THROW(std::logic_error, "Fugacity coefficients are not provided by this fluid state"); }
192 
196  const Scalar& fugacity(unsigned /* phaseIdx */, unsigned /* compIdx */) const
197  { OPM_THROW(std::logic_error, "Fugacities coefficients are not provided by this fluid state"); }
198 
207  void checkDefined() const
208  { }
209 };
210 
211 
212 } // namespace Opm
213 
214 #endif
Module for the modular fluid state which stores the phase fugacity coefficients explicitly assuming i...
Definition: FluidStateFugacityModules.hpp:117
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateFugacityModules.hpp:80
Scalar fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
The fugacity coefficient of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:129
void setFugacityCoefficient(unsigned phaseIdx, const Scalar &value)
Set the fugacity of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:141
const Scalar & fugacityCoefficient(unsigned, unsigned) const
The fugacity coefficient of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:190
const Scalar & fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
The fugacity coefficient of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:60
const Scalar & fugacity(unsigned, unsigned) const
The fugacity of a component in a phase [Pa].
Definition: FluidStateFugacityModules.hpp:196
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateFugacityModules.hpp:97
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateFugacityModules.hpp:164
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateFugacityModules.hpp:207
Module for the modular fluid state which stores the phase fugacity coefficients explicitly.
Definition: FluidStateFugacityModules.hpp:49
Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
The fugacity of a component in a phase [Pa].
Definition: FluidStateFugacityModules.hpp:135
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateFugacityModules.hpp:149
void setFugacityCoefficient(unsigned phaseIdx, unsigned compIdx, const Scalar &value)
Set the fugacity of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:72
Module for the modular fluid state which does not store the fugacities but throws std::logic_error in...
Definition: FluidStateFugacityModules.hpp:181
Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
The fugacity of a component in a phase [Pa].
Definition: FluidStateFugacityModules.hpp:66