All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
FluidStateDensityModules.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_DENSITY_MODULES_HPP
29 #define OPM_FLUID_STATE_DENSITY_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(density_); }
53 
57  const Scalar& density(unsigned phaseIdx) const
58  { return density_[phaseIdx]; }
59 
63  Scalar molarDensity(unsigned phaseIdx) const
64  { return density_[phaseIdx]/asImp_().averageMolarMass(phaseIdx); }
65 
69  Scalar molarVolume(unsigned phaseIdx) const
70  { return 1/molarDensity(phaseIdx); }
71 
75  void setDensity(unsigned phaseIdx, const Scalar& value)
76  { density_[phaseIdx] = value; }
77 
82  template <class FluidState>
83  void assign(const FluidState& fs)
84  {
85  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
86  density_[phaseIdx] = Opm::decay<Scalar>(fs.density(phaseIdx));
87  }
88  }
89 
98  void checkDefined() const
99  {
100  Valgrind::CheckDefined(density_);
101  }
102 
103 protected:
104  const Implementation& asImp_() const
105  { return *static_cast<const Implementation*>(this); }
106 
107  Scalar density_[numPhases];
108 };
109 
114 template <class Scalar,
115  unsigned numPhases,
116  class Implementation>
118 {
119 public:
121  { }
122 
126  const Scalar& density(unsigned /* phaseIdx */) const
127  { OPM_THROW(std::logic_error, "Density is not provided by this fluid state"); }
128 
132  const Scalar& molarDensity(unsigned /* phaseIdx */) const
133  { OPM_THROW(std::logic_error, "Molar density is not provided by this fluid state"); }
134 
138  const Scalar& molarVolume(unsigned /* phaseIdx */) const
139  { OPM_THROW(std::logic_error, "Molar volume is not provided by this fluid state"); }
140 
145  template <class FluidState>
146  void assign(const FluidState& /* fs */)
147  { }
148 
157  void checkDefined() const
158  { }
159 };
160 
161 } // namespace Opm
162 
163 #endif
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateDensityModules.hpp:83
const Scalar & molarVolume(unsigned) const
The molar volume of a fluid phase [m^3/mol].
Definition: FluidStateDensityModules.hpp:138
Scalar molarVolume(unsigned phaseIdx) const
The molar volume of a fluid phase [m^3/mol].
Definition: FluidStateDensityModules.hpp:69
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
const Scalar & density(unsigned) const
The density of a fluid phase [kg/m^3].
Definition: FluidStateDensityModules.hpp:126
Scalar molarDensity(unsigned phaseIdx) const
The molar density of a fluid phase [mol/m^3].
Definition: FluidStateDensityModules.hpp:63
const Scalar & molarDensity(unsigned) const
The molar density of a fluid phase [mol/m^3].
Definition: FluidStateDensityModules.hpp:132
Module for the modular fluid state which stores the densities explicitly.
Definition: FluidStateDensityModules.hpp:48
void setDensity(unsigned phaseIdx, const Scalar &value)
Set the density of a phase [kg/m^3].
Definition: FluidStateDensityModules.hpp:75
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateDensityModules.hpp:98
const Scalar & density(unsigned phaseIdx) const
The density of a fluid phase [kg/m^3].
Definition: FluidStateDensityModules.hpp:57
void assign(const FluidState &)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateDensityModules.hpp:146
Module for the modular fluid state which does not the densities but throws std::logic_error instead...
Definition: FluidStateDensityModules.hpp:117
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateDensityModules.hpp:157