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  Copyright (C) 2011-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
26 #ifndef OPM_FLUID_STATE_FUGACITY_MODULES_HPP
27 #define OPM_FLUID_STATE_FUGACITY_MODULES_HPP
28 
30 
31 #include <opm/common/ErrorMacros.hpp>
32 #include <opm/common/Exceptions.hpp>
33 
34 #include <algorithm>
35 #include <limits>
36 
37 namespace Opm {
38 
43 template <class Scalar,
44  int numPhases,
45  int numComponents,
46  class Implementation>
48 {
49 public:
51  {
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  {
98  }
99 
100 protected:
101  const Implementation &asImp_() const
102  { return *static_cast<const Implementation*>(this); }
103 
104  Scalar fugacityCoefficient_[numPhases][numComponents];
105 };
106 
111 template <class Scalar,
112  int numPhases,
113  int numComponents,
114  class Implementation>
116 {
117  static_assert((int) numPhases == (int) 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  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 
167 protected:
168  const Implementation &asImp_() const
169  { return *static_cast<const Implementation*>(this); }
170 
171  Scalar fugacityCoefficient_[numPhases];
172 };
173 
178 template <class Scalar>
180 {
181 public:
183  { }
184 
188  const Scalar& fugacityCoefficient(int /* phaseIdx */, int /* compIdx */) const
189  { OPM_THROW(std::logic_error, "Fugacity coefficients are not provided by this fluid state"); }
190 
194  const Scalar& fugacity(int /* phaseIdx */, int /* compIdx */) const
195  { OPM_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
void SetUndefined(const T &value OPM_UNUSED)
Make the memory on which an object resides undefined in valgrind runs.
Definition: Valgrind.hpp:138
const Implementation & asImp_() const
Definition: FluidStateFugacityModules.hpp:101
bool CheckDefined(const T &value OPM_UNUSED)
Make valgrind complain if any of the memory occupied by an object is undefined.
Definition: Valgrind.hpp:74
Definition: Air_Mesitylene.hpp:31
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 checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateFugacityModules.hpp:205
FluidStateNullFugacityModule()
Definition: FluidStateFugacityModules.hpp:182
Module for the modular fluid state which does not store the fugacities but throws std::logic_error in...
Definition: FluidStateFugacityModules.hpp:179
const Scalar & fugacityCoefficient(int, int) const
The fugacity coefficient of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:188
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateFugacityModules.hpp:78
void setFugacityCoefficient(unsigned phaseIdx, unsigned compIdx, const Scalar &value)
Set the fugacity of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:70
FluidStateExplicitFugacityModule()
Definition: FluidStateFugacityModules.hpp:50
const Scalar & fugacity(int, int) const
The fugacity of a component in a phase [Pa].
Definition: FluidStateFugacityModules.hpp:194
Scalar fugacity(unsigned phaseIdx, unsigned compIdx) const
The fugacity of a component in a phase [Pa].
Definition: FluidStateFugacityModules.hpp:64
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateFugacityModules.hpp:95
Module for the modular fluid state which stores the phase fugacity coefficients explicitly assuming i...
Definition: FluidStateFugacityModules.hpp:115
const Scalar & fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
The fugacity coefficient of a component in a phase [].
Definition: FluidStateFugacityModules.hpp:58
Scalar fugacityCoefficient_[numPhases][numComponents]
Definition: FluidStateFugacityModules.hpp:104