All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
FluidStateViscosityModules.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_VISCOSITY_MODULES_HPP
29 #define OPM_FLUID_STATE_VISCOSITY_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 {
44 template <class Scalar,
45  unsigned numPhases,
46  class Implementation>
48 {
49 public:
51  { Valgrind::SetUndefined(viscosity_); }
52 
56  const Scalar& viscosity(unsigned phaseIdx) const
57  { return viscosity_[phaseIdx]; }
58 
62  void setViscosity(unsigned phaseIdx, Scalar value)
63  { viscosity_[phaseIdx] = value; }
64 
69  template <class FluidState>
70  void assign(const FluidState& fs)
71  {
72  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
73  viscosity_[phaseIdx] = Opm::decay<Scalar>(fs.viscosity(phaseIdx));
74  }
75  }
76 
85  void checkDefined() const
86  {
87  Valgrind::CheckDefined(viscosity_);
88  }
89 
90 protected:
91  Scalar viscosity_[numPhases];
92 };
93 
98 template <class Scalar,
99  unsigned numPhases,
100  class Implementation>
102 {
103 public:
105  { }
106 
110  const Scalar& viscosity(unsigned /* phaseIdx */) const
111  { OPM_THROW(std::logic_error, "Viscosity is not provided by this fluid state"); }
112 
117  template <class FluidState>
118  void assign(const FluidState& /* fs */)
119  { }
120 
129  void checkDefined() const
130  { }
131 };
132 
133 } // namespace Opm
134 
135 #endif
Module for the modular fluid state which does not the viscosities but throws std::logic_error instead...
Definition: FluidStateViscosityModules.hpp:101
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: FluidStateViscosityModules.hpp:85
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateViscosityModules.hpp:70
void assign(const FluidState &)
Retrieve all parameters from an arbitrary fluid state.
Definition: FluidStateViscosityModules.hpp:118
const Scalar & viscosity(unsigned phaseIdx) const
The viscosity of a fluid phase [-].
Definition: FluidStateViscosityModules.hpp:56
const Scalar & viscosity(unsigned) const
The viscosity of a fluid phase [-].
Definition: FluidStateViscosityModules.hpp:110
void checkDefined() const
Make sure that all attributes are defined.
Definition: FluidStateViscosityModules.hpp:129
void setViscosity(unsigned phaseIdx, Scalar value)
Set the dynamic viscosity of a phase [Pa s].
Definition: FluidStateViscosityModules.hpp:62
Module for the modular fluid state which stores the viscosities explicitly.
Definition: FluidStateViscosityModules.hpp:47