00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #ifndef OPM_FLUID_STATE_DENSITY_MODULES_HPP
00029 #define OPM_FLUID_STATE_DENSITY_MODULES_HPP
00030
00031 #include <opm/common/ErrorMacros.hpp>
00032 #include <opm/common/Exceptions.hpp>
00033
00034 #include <opm/material/common/MathToolbox.hpp>
00035 #include <opm/common/Valgrind.hpp>
00036
00037 #include <algorithm>
00038
00039 namespace Opm {
00040
00045 template <class Scalar,
00046 unsigned numPhases,
00047 class Implementation>
00048 class FluidStateExplicitDensityModule
00049 {
00050 public:
00051 FluidStateExplicitDensityModule()
00052 { Valgrind::SetUndefined(density_); }
00053
00057 const Scalar& density(unsigned phaseIdx) const
00058 { return density_[phaseIdx]; }
00059
00063 Scalar molarDensity(unsigned phaseIdx) const
00064 { return density_[phaseIdx]/asImp_().averageMolarMass(phaseIdx); }
00065
00069 Scalar molarVolume(unsigned phaseIdx) const
00070 { return 1/molarDensity(phaseIdx); }
00071
00075 void setDensity(unsigned phaseIdx, const Scalar& value)
00076 { density_[phaseIdx] = value; }
00077
00082 template <class FluidState>
00083 void assign(const FluidState& fs)
00084 {
00085 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
00086 density_[phaseIdx] = Opm::decay<Scalar>(fs.density(phaseIdx));
00087 }
00088 }
00089
00098 void checkDefined() const
00099 {
00100 Valgrind::CheckDefined(density_);
00101 }
00102
00103 protected:
00104 const Implementation& asImp_() const
00105 { return *static_cast<const Implementation*>(this); }
00106
00107 Scalar density_[numPhases];
00108 };
00109
00114 template <class Scalar,
00115 unsigned numPhases,
00116 class Implementation>
00117 class FluidStateNullDensityModule
00118 {
00119 public:
00120 FluidStateNullDensityModule()
00121 { }
00122
00126 const Scalar& density(unsigned ) const
00127 { OPM_THROW(std::logic_error, "Density is not provided by this fluid state"); }
00128
00132 const Scalar& molarDensity(unsigned ) const
00133 { OPM_THROW(std::logic_error, "Molar density is not provided by this fluid state"); }
00134
00138 const Scalar& molarVolume(unsigned ) const
00139 { OPM_THROW(std::logic_error, "Molar volume is not provided by this fluid state"); }
00140
00145 template <class FluidState>
00146 void assign(const FluidState& )
00147 { }
00148
00157 void checkDefined() const
00158 { }
00159 };
00160
00161 }
00162
00163 #endif