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  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_DENSITY_MODULES_HPP
27 #define OPM_FLUID_STATE_DENSITY_MODULES_HPP
28 
29 #include <opm/common/ErrorMacros.hpp>
30 #include <opm/common/Exceptions.hpp>
31 
34 
35 #include <algorithm>
36 
37 namespace Opm {
38 
43 template <class Scalar,
44  int numPhases,
45  class Implementation>
47 {
48 public:
51 
55  const Scalar& density(unsigned phaseIdx) const
56  { return density_[phaseIdx]; }
57 
61  Scalar molarDensity(unsigned phaseIdx) const
62  { return density_[phaseIdx]/asImp_().averageMolarMass(phaseIdx); }
63 
67  Scalar molarVolume(unsigned phaseIdx) const
68  { return 1/molarDensity(phaseIdx); }
69 
73  void setDensity(unsigned phaseIdx, const Scalar& value)
74  { density_[phaseIdx] = value; }
75 
80  template <class FluidState>
81  void assign(const FluidState& fs)
82  {
83  typedef typename FluidState::Scalar FsScalar;
84  typedef Opm::MathToolbox<FsScalar> FsToolbox;
85  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
86  density_[phaseIdx] = FsToolbox::template toLhs<Scalar>(fs.density(phaseIdx));
87  }
88  }
89 
98  void checkDefined() const
99  {
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  int numPhases,
116  class Implementation>
118 {
119 public:
121  { }
122 
126  const Scalar& density(int /* phaseIdx */) const
127  { OPM_THROW(std::logic_error, "Density is not provided by this fluid state"); }
128 
132  Scalar molarDensity(int /* phaseIdx */) const
133  { OPM_THROW(std::logic_error, "Molar density is not provided by this fluid state"); }
134 
138  Scalar molarVolume(int /* 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 SetUndefined(const T &value OPM_UNUSED)
Make the memory on which an object resides undefined in valgrind runs.
Definition: Valgrind.hpp:138
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
const Scalar & density(int) const
The density of a fluid phase [kg/m^3].
Definition: FluidStateDensityModules.hpp:126
Definition: MathToolbox.hpp:39
Definition: Air_Mesitylene.hpp:31
void assign(const FluidState &)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateDensityModules.hpp:146
Some templates to wrap the valgrind client request macros.
Module for the modular fluid state which does not the densities but throws std::logic_error instead...
Definition: FluidStateDensityModules.hpp:117
void setDensity(unsigned phaseIdx, const Scalar &value)
Set the density of a phase [kg/m^3].
Definition: FluidStateDensityModules.hpp:73
Scalar molarVolume(unsigned phaseIdx) const
The molar volume of a fluid phase [m^3/mol].
Definition: FluidStateDensityModules.hpp:67
Scalar density_[numPhases]
Definition: FluidStateDensityModules.hpp:107
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateDensityModules.hpp:98
FluidStateNullDensityModule()
Definition: FluidStateDensityModules.hpp:120
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateDensityModules.hpp:157
Scalar molarVolume(int) const
The molar volume of a fluid phase [m^3/mol].
Definition: FluidStateDensityModules.hpp:138
const Implementation & asImp_() const
Definition: FluidStateDensityModules.hpp:104
FluidStateExplicitDensityModule()
Definition: FluidStateDensityModules.hpp:49
Scalar molarDensity(int) const
The molar density of a fluid phase [mol/m^3].
Definition: FluidStateDensityModules.hpp:132
const Scalar & density(unsigned phaseIdx) const
The density of a fluid phase [kg/m^3].
Definition: FluidStateDensityModules.hpp:55
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateDensityModules.hpp:81
Scalar molarDensity(unsigned phaseIdx) const
The molar density of a fluid phase [mol/m^3].
Definition: FluidStateDensityModules.hpp:61
Module for the modular fluid state which stores the densities explicitly.
Definition: FluidStateDensityModules.hpp:46
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...