FluidStateTemperatureModules.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_TEMPERATURE_MODULES_HPP
29 #define OPM_FLUID_STATE_TEMPERATURE_MODULES_HPP
30 
31 #include <opm/common/Valgrind.hpp>
32 
34 #include <opm/common/ErrorMacros.hpp>
35 #include <opm/common/Exceptions.hpp>
36 
37 #include <algorithm>
38 #include <cassert>
39 
40 namespace Opm {
41 
46 template <class Scalar,
47  unsigned numPhases,
48  class Implementation>
50 {
51 public:
53  { Valgrind::SetUndefined(temperature_); }
54 
58  const Scalar& temperature(unsigned phaseIdx) const
59  { return temperature_[phaseIdx]; }
60 
64  void setTemperature(unsigned phaseIdx, const Scalar& value)
65  { temperature_[phaseIdx] = value; }
66 
71  template <class FluidState>
72  void assign(const FluidState& fs)
73  {
74  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
75  temperature_[phaseIdx] = fs.temperature(phaseIdx);
76  }
77  }
78 
87  void checkDefined() const
88  {
89  Valgrind::CheckDefined(temperature_);
90  }
91 
92 protected:
93  Scalar temperature_[numPhases];
94 };
95 
100 template <class Scalar,
101  unsigned numPhases,
102  class Implementation>
104 {
105 public:
107  { Valgrind::SetUndefined(temperature_); }
108 
112  const Scalar& temperature(unsigned /*phaseIdx*/) const
113  { return temperature_; }
114 
118  void setTemperature(const Scalar& value)
119  { temperature_ = value; }
120 
125  template <class FluidState>
126  void assign(const FluidState& fs)
127  {
128  temperature_ = Opm::decay<Scalar>(fs.temperature(/*phaseIdx=*/0));
129 
130 #ifndef NDEBUG
131  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
132  assert(std::abs(Opm::scalarValue(fs.temperature(phaseIdx))
133  - Opm::scalarValue(temperature_)) < 1e-30);
134  }
135 #endif
136  }
137 
146  void checkDefined() const
147  {
148  Valgrind::CheckDefined(temperature_);
149  }
150 
151 protected:
152  Scalar temperature_;
153 };
154 
159 template <class Scalar>
161 {
162 public:
164  { }
165 
169  const Scalar& temperature(unsigned /* phaseIdx */) const
170  { OPM_THROW(std::runtime_error, "Temperature is not provided by this fluid state"); }
171 
176  template <class FluidState>
177  void assign(const FluidState& /* fs */)
178  { }
179 
188  void checkDefined() const
189  { }
190 };
191 
192 } // namespace Opm
193 
194 #endif
Module for the modular fluid state which stores the temperatures explicitly and assumes thermal equil...
Definition: FluidStateTemperatureModules.hpp:103
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateTemperatureModules.hpp:126
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateTemperatureModules.hpp:87
Module for the modular fluid state which does not the temperatures but throws std::logic_error instea...
Definition: FluidStateTemperatureModules.hpp:160
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateTemperatureModules.hpp:146
void setTemperature(const Scalar &value)
Set the temperature of a phase [-].
Definition: FluidStateTemperatureModules.hpp:118
Module for the modular fluid state which stores the temperatures explicitly.
Definition: FluidStateTemperatureModules.hpp:49
Definition: Air_Mesitylene.hpp:33
const Scalar & temperature(unsigned phaseIdx) const
The temperature of a fluid phase [-].
Definition: FluidStateTemperatureModules.hpp:58
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateTemperatureModules.hpp:188
const Scalar & temperature(unsigned) const
The temperature of a fluid phase [-].
Definition: FluidStateTemperatureModules.hpp:112
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateTemperatureModules.hpp:72
const Scalar & temperature(unsigned) const
The temperature of a fluid phase [-].
Definition: FluidStateTemperatureModules.hpp:169
void assign(const FluidState &)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateTemperatureModules.hpp:177
void setTemperature(unsigned phaseIdx, const Scalar &value)
Set the temperature of a phase [-].
Definition: FluidStateTemperatureModules.hpp:64