All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
FluidStateSaturationModules.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_SATURATION_MODULES_HPP
29 #define OPM_FLUID_STATE_SATURATION_MODULES_HPP
30 
31 #include <opm/common/ErrorMacros.hpp>
32 #include <opm/common/Exceptions.hpp>
33 
35 #include <opm/common/Valgrind.hpp>
36 
37 #include <algorithm>
38 
39 namespace Opm {
40 
45 template <class Scalar,
46  unsigned numPhases,
47  class Implementation>
49 {
50 public:
52  { Valgrind::SetUndefined(saturation_); }
53 
57  const Scalar& saturation(unsigned phaseIdx) const
58  { return saturation_[phaseIdx]; }
59 
63  bool phaseIsPresent(unsigned phaseIdx) const
64  { return saturation_[phaseIdx] > 0.0; }
65 
69  void setSaturation(unsigned phaseIdx, const Scalar& value)
70  { saturation_[phaseIdx] = value; }
71 
76  template <class FluidState>
77  void assign(const FluidState& fs)
78  {
79  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
80  saturation_[phaseIdx] = Opm::decay<Scalar>(fs.saturation(phaseIdx));
81  }
82  }
83 
92  void checkDefined() const
93  {
94  Valgrind::CheckDefined(saturation_);
95  }
96 
97 protected:
98  Scalar saturation_[numPhases];
99 };
100 
105 template <class Scalar>
107 {
108 public:
110  { }
111 
115  const Scalar& saturation(unsigned /* phaseIdx */) const
116  { OPM_THROW(std::runtime_error, "Saturation is not provided by this fluid state"); }
117 
121  bool phaseIsPresent(unsigned /* phaseIdx */) const
122  { OPM_THROW(std::runtime_error, "phaseIsPresent() is not provided by this fluid state"); }
123 
128  template <class FluidState>
129  void assign(const FluidState& /* fs */)
130  { }
131 
140  void checkDefined() const
141  { }
142 };
143 
144 } // namespace Opm
145 
146 #endif
bool phaseIsPresent(unsigned phaseIdx) const
Returns true iff a fluid phase shall be assumed to be present.
Definition: FluidStateSaturationModules.hpp:63
const Scalar & saturation(unsigned) const
The saturation of a fluid phase [-].
Definition: FluidStateSaturationModules.hpp:115
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
bool phaseIsPresent(unsigned) const
Returns true iff a fluid phase shall be assumed to be present.
Definition: FluidStateSaturationModules.hpp:121
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateSaturationModules.hpp:140
void assign(const FluidState &)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateSaturationModules.hpp:129
void setSaturation(unsigned phaseIdx, const Scalar &value)
Set the saturation of a phase [-].
Definition: FluidStateSaturationModules.hpp:69
Module for the modular fluid state which does not the saturations but throws std::logic_error instead...
Definition: FluidStateSaturationModules.hpp:106
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateSaturationModules.hpp:77
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateSaturationModules.hpp:92
Module for the modular fluid state which stores the saturations explicitly.
Definition: FluidStateSaturationModules.hpp:48
const Scalar & saturation(unsigned phaseIdx) const
The saturation of a fluid phase [-].
Definition: FluidStateSaturationModules.hpp:57