SaturationOverlayFluidState.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 */
27 #ifndef OPM_SATURATION_OVERLAY_FLUID_STATE_HPP
28 #define OPM_SATURATION_OVERLAY_FLUID_STATE_HPP
29 
30 #include <opm/common/Valgrind.hpp>
31 
32 #include <array>
33 #include <utility>
34 
35 namespace Opm {
36 
42 template <class FluidState>
44 {
45 public:
46  typedef typename FluidState::Scalar Scalar;
47 
48  enum { numPhases = FluidState::numPhases };
49  enum { numComponents = FluidState::numComponents };
50 
58  SaturationOverlayFluidState(const FluidState& fs)
59  : fs_(&fs)
60  {
61  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
62  saturation_[phaseIdx] = fs.saturation(phaseIdx);
63  }
64 
65  // copy constructor
67  : fs_(fs.fs_)
68  , saturation_(fs.saturation_)
69  {}
70 
71  // assignment operator
73  {
74  fs_ = fs.fs_;
75  saturation_ = fs.saturation_;
76  return *this;
77  }
78 
79  /*****************************************************
80  * Generic access to fluid properties (No assumptions
81  * on thermodynamic equilibrium required)
82  *****************************************************/
86  auto saturation(unsigned phaseIdx) const
87  -> decltype(std::declval<FluidState>().saturation(phaseIdx))
88  { return saturation_[phaseIdx]; }
89 
93  bool phaseIsPresent(unsigned phaseIdx) const
94  { return saturation_[phaseIdx] > 0.0; }
95 
99  auto moleFraction(unsigned phaseIdx, unsigned compIdx) const
100  -> decltype(std::declval<FluidState>().moleFraction(phaseIdx, compIdx))
101  { return fs_->moleFraction(phaseIdx, compIdx); }
102 
106  auto massFraction(unsigned phaseIdx, unsigned compIdx) const
107  -> decltype(std::declval<FluidState>().massFraction(phaseIdx, compIdx))
108  { return fs_->massFraction(phaseIdx, compIdx); }
109 
118  auto averageMolarMass(unsigned phaseIdx) const
119  -> decltype(std::declval<FluidState>().averageMolarMass(phaseIdx))
120  { return fs_->averageMolarMass(phaseIdx); }
121 
131  auto molarity(unsigned phaseIdx, unsigned compIdx) const
132  -> decltype(std::declval<FluidState>().molarity(phaseIdx, compIdx))
133  { return fs_->molarity(phaseIdx, compIdx); }
134 
138  auto fugacity(unsigned phaseIdx, unsigned compIdx) const
139  -> decltype(std::declval<FluidState>().fugacity(phaseIdx, compIdx))
140  { return fs_->fugacity(phaseIdx, compIdx); }
141 
145  auto fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const
146  -> decltype(std::declval<FluidState>().fugacityCoefficient(phaseIdx, compIdx))
147  { return fs_->fugacityCoefficient(phaseIdx, compIdx); }
148 
152  auto molarVolume(unsigned phaseIdx) const
153  -> decltype(std::declval<FluidState>().molarVolume(phaseIdx))
154  { return fs_->molarVolume(phaseIdx); }
155 
159  auto density(unsigned phaseIdx) const
160  -> decltype(std::declval<FluidState>().density(phaseIdx))
161  { return fs_->density(phaseIdx); }
162 
166  auto molarDensity(unsigned phaseIdx) const
167  -> decltype(std::declval<FluidState>().molarDensity(phaseIdx))
168  { return fs_->molarDensity(phaseIdx); }
169 
173  auto temperature(unsigned phaseIdx) const
174  -> decltype(std::declval<FluidState>().temperature(phaseIdx))
175  { return fs_->temperature(phaseIdx); }
176 
180  auto pressure(unsigned phaseIdx) const
181  -> decltype(std::declval<FluidState>().pressure(phaseIdx))
182  { return fs_->pressure(phaseIdx); }
183 
187  auto enthalpy(unsigned phaseIdx) const
188  -> decltype(std::declval<FluidState>().enthalpy(phaseIdx))
189  { return fs_->enthalpy(phaseIdx); }
190 
194  auto internalEnergy(unsigned phaseIdx) const
195  -> decltype(std::declval<FluidState>().internalEnergy(phaseIdx))
196  { return fs_->internalEnergy(phaseIdx); }
197 
201  auto viscosity(unsigned phaseIdx) const
202  -> decltype(std::declval<FluidState>().viscosity(phaseIdx))
203  { return fs_->viscosity(phaseIdx); }
204 
205 
206  /*****************************************************
207  * Setter methods. Note that these are not part of the
208  * generic FluidState interface but specific for each
209  * implementation...
210  *****************************************************/
214  void setSaturation(unsigned phaseIdx, const Scalar& value)
215  { saturation_[phaseIdx] = value; }
216 
225  void checkDefined() const
226  {
227  Valgrind::CheckDefined(saturation_);
228  }
229 
230 protected:
231  const FluidState* fs_;
232  std::array<Scalar, numPhases> saturation_;
233 };
234 
235 } // namespace Opm
236 
237 #endif
auto molarDensity(unsigned phaseIdx) const -> decltype(std::declval< FluidState >().molarDensity(phaseIdx))
The molar density of a fluid phase [mol/m^3].
Definition: SaturationOverlayFluidState.hpp:166
auto massFraction(unsigned phaseIdx, unsigned compIdx) const -> decltype(std::declval< FluidState >().massFraction(phaseIdx, compIdx))
The mass fraction of a component in a phase [].
Definition: SaturationOverlayFluidState.hpp:106
bool phaseIsPresent(unsigned phaseIdx) const
Returns true iff a fluid phase shall be assumed to be present.
Definition: SaturationOverlayFluidState.hpp:93
auto fugacity(unsigned phaseIdx, unsigned compIdx) const -> decltype(std::declval< FluidState >().fugacity(phaseIdx, compIdx))
The fugacity of a component in a phase [Pa].
Definition: SaturationOverlayFluidState.hpp:138
auto molarVolume(unsigned phaseIdx) const -> decltype(std::declval< FluidState >().molarVolume(phaseIdx))
The molar volume of a fluid phase [m^3/mol].
Definition: SaturationOverlayFluidState.hpp:152
auto pressure(unsigned phaseIdx) const -> decltype(std::declval< FluidState >().pressure(phaseIdx))
The pressure of a fluid phase [Pa].
Definition: SaturationOverlayFluidState.hpp:180
This is a fluid state which allows to set the fluid saturations and takes all other quantities from a...
Definition: SaturationOverlayFluidState.hpp:43
auto saturation(unsigned phaseIdx) const -> decltype(std::declval< FluidState >().saturation(phaseIdx))
Returns the saturation of a phase [].
Definition: SaturationOverlayFluidState.hpp:86
auto molarity(unsigned phaseIdx, unsigned compIdx) const -> decltype(std::declval< FluidState >().molarity(phaseIdx, compIdx))
The molar concentration of a component in a phase [mol/m^3].
Definition: SaturationOverlayFluidState.hpp:131
SaturationOverlayFluidState(const FluidState &fs)
Constructor.
Definition: SaturationOverlayFluidState.hpp:58
Definition: Air_Mesitylene.hpp:33
auto moleFraction(unsigned phaseIdx, unsigned compIdx) const -> decltype(std::declval< FluidState >().moleFraction(phaseIdx, compIdx))
The mole fraction of a component in a phase [].
Definition: SaturationOverlayFluidState.hpp:99
auto enthalpy(unsigned phaseIdx) const -> decltype(std::declval< FluidState >().enthalpy(phaseIdx))
The specific enthalpy of a fluid phase [J/kg].
Definition: SaturationOverlayFluidState.hpp:187
auto density(unsigned phaseIdx) const -> decltype(std::declval< FluidState >().density(phaseIdx))
The mass density of a fluid phase [kg/m^3].
Definition: SaturationOverlayFluidState.hpp:159
auto internalEnergy(unsigned phaseIdx) const -> decltype(std::declval< FluidState >().internalEnergy(phaseIdx))
The specific internal energy of a fluid phase [J/kg].
Definition: SaturationOverlayFluidState.hpp:194
void setSaturation(unsigned phaseIdx, const Scalar &value)
Set the saturation [-] of a fluid phase.
Definition: SaturationOverlayFluidState.hpp:214
auto viscosity(unsigned phaseIdx) const -> decltype(std::declval< FluidState >().viscosity(phaseIdx))
The dynamic viscosity of a fluid phase [Pa s].
Definition: SaturationOverlayFluidState.hpp:201
auto averageMolarMass(unsigned phaseIdx) const -> decltype(std::declval< FluidState >().averageMolarMass(phaseIdx))
The average molar mass of a fluid phase [kg/mol].
Definition: SaturationOverlayFluidState.hpp:118
void checkDefined() const
Make sure that all attributes are defined.
Definition: SaturationOverlayFluidState.hpp:225
auto temperature(unsigned phaseIdx) const -> decltype(std::declval< FluidState >().temperature(phaseIdx))
The temperature of a fluid phase [K].
Definition: SaturationOverlayFluidState.hpp:173
auto fugacityCoefficient(unsigned phaseIdx, unsigned compIdx) const -> decltype(std::declval< FluidState >().fugacityCoefficient(phaseIdx, compIdx))
The fugacity coefficient of a component in a phase [-].
Definition: SaturationOverlayFluidState.hpp:145