opm-common
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 <array>
34 #include <limits>
35 #include <stdexcept>
36 
37 namespace Opm {
38 
43 template <class ValueType,
44  unsigned numPhases,
45  unsigned numComponents,
46  class Implementation>
48 {
49 public:
51  {
52  Valgrind::SetUndefined(fugacityCoefficient_);
53  }
54 
58  const ValueType& fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
59  { return fugacityCoefficient_[phaseIdx][compIdx]; }
60 
64  ValueType 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 ValueType& 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 
100 protected:
101  const Implementation& asImp_() const
102  { return *static_cast<const Implementation*>(this); }
103 
104  std::array<std::array<ValueType, numComponents>, numPhases> fugacityCoefficient_{};
105 };
106 
111 template <class ValueT,
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 
120 public:
122  { Valgrind::SetUndefined(fugacityCoefficient_); }
123 
127  ValueT fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
128  { return (phaseIdx == compIdx)?fugacityCoefficient_[phaseIdx]:std::numeric_limits<ValueT>::infinity(); }
129 
133  ValueT 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 ValueT& 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 
167 protected:
168  const Implementation& asImp_() const
169  { return *static_cast<const Implementation*>(this); }
170 
171  std::array<ValueT, numPhases> fugacityCoefficient_{};
172 };
173 
178 template <class ValueT>
180 {
181 public:
183  { }
184 
188  const ValueT& fugacityCoefficient(unsigned /* phaseIdx */, unsigned /* compIdx */) const
189  { throw std::logic_error("Fugacity coefficients are not provided by this fluid state"); }
190 
194  const ValueT& 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
Module for the modular fluid state which stores the phase fugacity coefficients explicitly assuming i...
Definition: FluidStateFugacityModules.hpp:115
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateFugacityModules.hpp:78
void setFugacityCoefficient(unsigned phaseIdx, const ValueT &value)
Set the fugacity of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:139
const ValueType & fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
The fugacity coefficient of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:58
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateFugacityModules.hpp:147
ValueT fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
The fugacity coefficient of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:127
void setFugacityCoefficient(unsigned phaseIdx, unsigned compIdx, const ValueType &value)
Set the fugacity of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:70
Module for the modular fluid state which stores the phase fugacity coefficients explicitly.
Definition: FluidStateFugacityModules.hpp:47
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateFugacityModules.hpp:162
ValueT fugacity(unsigned phaseIdx, unsigned compIdx) const
The fugacity of a component in a phase [Pa].
Definition: FluidStateFugacityModules.hpp:133
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateFugacityModules.hpp:95
ValueType fugacity(unsigned phaseIdx, unsigned compIdx) const
The fugacity of a component in a phase [Pa].
Definition: FluidStateFugacityModules.hpp:64
const ValueT & fugacityCoefficient(unsigned, unsigned) const
The fugacity coefficient of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:188
const ValueT & fugacity(unsigned, unsigned) const
The fugacity of a component in a phase [Pa].
Definition: FluidStateFugacityModules.hpp:194
Module for the modular fluid state which does not store the fugacities but throws std::logic_error in...
Definition: FluidStateFugacityModules.hpp:179
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateFugacityModules.hpp:205
Some templates to wrap the valgrind client request macros.