Loading...
Searching...
No Matches
SimpleHuDuanH2O.hpp
Go to the documentation of this file.
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#ifndef OPM_SIMPLE_HU_DUAN_H2O_HPP
#define OPM_SIMPLE_HU_DUAN_H2O_HPP
#include "Component.hpp"
#include "iapws/Common.hpp"
#include <opm/common/Exceptions.hpp>
#include <opm/common/TimingMacros.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/material/IdealGas.hpp>
#include <opm/material/common/MathToolbox.hpp>
#include <cassert>
#include <cmath>
#include <string_view>
namespace Opm {
template <class Scalar>
class SimpleHuDuanH2O : public Component<Scalar, SimpleHuDuanH2O<Scalar>>
{
using IdealGas = ::Opm::IdealGas<Scalar>;
using Common = IAPWS::Common<Scalar>;
static constexpr Scalar R = Constants<Scalar>::R / 18e-3; // specific gas constant of water
public:
// OPM_HOST_DEVICE static Scalar R_()
// { return Scalar(R); }
OPM_HOST_DEVICE static std::string_view name()
{ return "H2O"; }
OPM_HOST_DEVICE static bool gasIsCompressible()
{ return true; }
OPM_HOST_DEVICE static bool liquidIsCompressible()
{ return false; }
OPM_HOST_DEVICE static bool gasIsIdeal()
{ return true; }
OPM_HOST_DEVICE static Scalar molarMass()
{ return 18e-3; }
OPM_HOST_DEVICE static Scalar criticalTemperature()
{ return 647.096; /* [K] */ }
OPM_HOST_DEVICE static Scalar criticalPressure()
{ return 22.064e6; /* [N/m^2] */ }
OPM_HOST_DEVICE static Scalar tripleTemperature()
{ return 273.16; /* [K] */ }
OPM_HOST_DEVICE static Scalar triplePressure()
{ return 611.657; /* [N/m^2] */ }
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation vaporPressure(const Evaluation& T)
{
OPM_TIMEFUNCTION_LOCAL(Subsystem::PvtProps);
if (T > criticalTemperature())
return criticalPressure();
if (T < tripleTemperature())
return 0; // water is solid: We don't take sublimation into account
static constexpr Scalar n[10] = {
0.11670521452767e4, -0.72421316703206e6, -0.17073846940092e2,
0.12020824702470e5, -0.32325550322333e7, 0.14915108613530e2,
-0.48232657361591e4, 0.40511340542057e6, -0.23855557567849,
0.65017534844798e3
};
Evaluation sigma = T + n[8]/(T - n[9]);
Evaluation A = (sigma + n[0])*sigma + n[1];
Evaluation B = (n[2]*sigma + n[3])*sigma + n[4];
Evaluation C = (n[5]*sigma + n[6])*sigma + n[7];
Evaluation tmp = 2.0*C/(sqrt(B*B - 4.0*A*C) - B);
tmp *= tmp;
tmp *= tmp;
return 1e6*tmp;
}
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation gasEnthalpy(const Evaluation& temperature,
const Evaluation& /*pressure*/)
{ return 1.976e3*temperature + 40.65e3/molarMass(); }
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation gasHeatCapacity(const Evaluation&,
const Evaluation&)
{ return 1.976e3; }
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation liquidEnthalpy(const Evaluation& temperature,
const Evaluation& /*pressure*/)
{ return (temperature - 288.71) * (4.18060737e+03 + 8.64644981e-02 * (temperature - 288.71)); }
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation liquidHeatCapacity(const Evaluation&,
const Evaluation&)
{ return 4.184e3; }
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation gasInternalEnergy(const Evaluation& temperature,
const Evaluation& pressure)
{
return
gasEnthalpy(temperature, pressure) -
1/molarMass()* // conversion from [J/(mol K)] to [J/(kg K)]
IdealGas::R*temperature; // = pressure *spec. volume for an ideal gas
}
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation
liquidInternalEnergy(const Evaluation& temperature,
const Evaluation& pressure,
bool extrapolate)
{
return
liquidEnthalpy(temperature, pressure) -
pressure/liquidDensity(temperature, pressure, extrapolate);
}
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation liquidThermalConductivity(const Evaluation& /*temperature*/,
const Evaluation& /*pressure*/)
{
return 0.578078; // conductivity of liquid water [W / (m K ) ] IAPWS evaluated at p=.1 MPa, T=8°C
}
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation gasThermalConductivity(const Evaluation& /*temperature*/,
const Evaluation& /*pressure*/)
{
return 0.028224; // conductivity of steam [W / (m K ) ] IAPWS evaluated at p=.1 MPa, T=8°C
}
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation gasDensity(const Evaluation& temperature, const Evaluation& pressure)
{
// Assume an ideal gas
return molarMass()*IdealGas::molarDensity(temperature, pressure);
}
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation gasPressure(const Evaluation& temperature, const Evaluation& density)
{
// Assume an ideal gas
return IdealGas::pressure(temperature, density/molarMass());
}
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation liquidDensity(const Evaluation& temperature, const Evaluation& pressure,
bool extrapolate)
{
return liquidDensity_(temperature, pressure, extrapolate);
}
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation liquidPressure(const Evaluation& /*temperature*/, const Evaluation& /*density*/)
{
#if OPM_IS_INSIDE_DEVICE_FUNCTION
assert(false && "The liquid pressure is undefined for incompressible fluids");
#else
throw std::logic_error("The liquid pressure is undefined for incompressible fluids");
#endif
}
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation gasViscosity(const Evaluation& /*temperature*/,
const Evaluation& /*pressure*/)
{
return 1e-05;
}
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation liquidViscosity(const Evaluation& temperature, const Evaluation& pressure,
bool extrapolate)
{
if (temperature > 570) {
// This preprocessing statement loses this warning message
// But printing it possibly thousands of times inside a gpu function also seems problematic
#if !OPM_IS_INSIDE_DEVICE_FUNCTION
const std::string msg =
"Viscosity of water based on Hu et al is too "
"different from IAPWS for T above 570K and (T = " +
std::to_string(getValue(temperature)) + ")";
if (extrapolate)
{
OpmLog::warning(msg);
}
else
throw NumericalProblem(msg);
#else
// no warning on the GPU when using extrapolate is somewhat bad,
// but how does one tame warning output when encountered by thousands of threads?
if (!extrapolate) {
assert(false && "Viscosity of water based on Hu et al is too different from IAPWS for T above 570K");
}
#endif
}
const Evaluation rho = liquidDensity(temperature, pressure, extrapolate);
return Common::viscosity(temperature, rho);
}
private:
template <class Evaluation>
OPM_HOST_DEVICE static Evaluation liquidDensity_(const Evaluation& T, const Evaluation& pressure, bool extrapolate) {
// Hu, Duan, Zhu and Chou: PVTx properties of the CO2-H2O and CO2-H2O-NaCl
// systems below 647 K: Assessment of experimental data and
// thermodynamics models, Chemical Geology, 2007.
OPM_TIMEBLOCK_LOCAL(liquidDensity_, Subsystem::PvtProps);
if (T > 647 || pressure > 100e6) {
#if !OPM_IS_INSIDE_DEVICE_FUNCTION
const std::string msg =
"Density of water is only implemented for temperatures "
"below 647K and pressures below 100MPa. (T = " +
std::to_string(getValue(T)) + ", p=" +
std::to_string(getValue(pressure)) + ")";
if (extrapolate)
{
OpmLog::warning(msg);
}
else
throw NumericalProblem(msg);
#else
// no warning on the GPU when using extrapolate is somewhat bad,
// but how does one tame warning output when encountered by thousands of threads?
if (!extrapolate) {
assert(false && "Density of water is only implemented for temperatures below 647K and pressures below 100MPa");
}
#endif
}
Evaluation p = pressure / 1e6; // to MPa
Scalar Mw = molarMass() * 1e3; //kg/kmol
static constexpr Scalar k0[5] = { 3.27225e-07, -4.20950e-04, 2.32594e-01, -4.16920e+01, 5.71292e+03 };
static constexpr Scalar k1[5] = { -2.32306e-10, 2.91138e-07, -1.49662e-04, 3.59860e-02, -3.55071 };
static constexpr Scalar k2[3] = { 2.57241e-14, -1.24336e-11, 5.42707e-07 };
static constexpr Scalar k3[3] = { -4.42028e-18, 2.10007e-15, -8.11491e-11 };
Evaluation k0_eval = 1e-3 * (((k0[0]*T + k0[1])*T + k0[2])*T + k0[3] + k0[4]/T);
Evaluation k1_eval = 1e-2 * (((k1[0]*T + k1[1])*T + k1[2])*T + k1[3] + k1[4]/T);
Evaluation k2_eval = 1e-1 * ((k2[0]*T + k2[1])*T*T + k2[2]);
Evaluation k3_eval = (k3[0]*T + k3[1])*T*T + k3[2];
// molar volum (m³/kmol):
Evaluation vw = ((k3_eval*p + k2_eval)*p + k1_eval)*p + k0_eval;
// density kg/m3
return Mw / vw;
}
};
} // namespace Opm
#endif
Common.hpp
Implements relations which are common for all regions of the IAPWS '97 formulation.
Component.hpp
Abstract base class of a pure chemical species.
Exceptions.hpp
Provides the OPM specific exception classes.
IdealGas.hpp
Relations valid for an ideal gas.
MathToolbox.hpp
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
Opm::Component
Abstract base class of a pure chemical species.
Definition Component.hpp:44
Opm::Constants::R
static constexpr Scalar R
The ideal gas constant [J/(mol K)].
Definition Constants.hpp:45
Opm::IAPWS::Common
Implements relations which are common for all regions of the IAPWS '97 formulation.
Definition Common.hpp:56
Opm::IAPWS::Common::viscosity
static OPM_HOST_DEVICE Evaluation viscosity(const Evaluation &temperature, const Evaluation &rho)
The dynamic viscosity of pure water.
Definition Common.hpp:103
Opm::IdealGas
Relations valid for an ideal gas.
Definition IdealGas.hpp:39
Opm::IdealGas::pressure
static OPM_HOST_DEVICE Evaluation pressure(const Evaluation &temperature, const Evaluation &rhoMolar)
The pressure of the gas in , depending on the molar density and temperature.
Definition IdealGas.hpp:59
Opm::IdealGas::molarDensity
static OPM_HOST_DEVICE Evaluation molarDensity(const Evaluation &temperature, const Evaluation &pressure)
The molar density of the gas , depending on pressure and temperature.
Definition IdealGas.hpp:68
Opm::IdealGas::R
static constexpr Scalar R
The ideal gas constant .
Definition IdealGas.hpp:42
Opm::NumericalProblem
Definition Exceptions.hpp:40
Opm::SimpleHuDuanH2O
A simple version of pure water with density from Hu et al.
Definition SimpleHuDuanH2O.hpp:66
Opm::SimpleHuDuanH2O::liquidDensity
static OPM_HOST_DEVICE Evaluation liquidDensity(const Evaluation &temperature, const Evaluation &pressure, bool extrapolate)
The density of pure water at a given pressure and temperature .
Definition SimpleHuDuanH2O.hpp:316
Opm::SimpleHuDuanH2O::liquidViscosity
static OPM_HOST_DEVICE Evaluation liquidViscosity(const Evaluation &temperature, const Evaluation &pressure, bool extrapolate)
The dynamic viscosity of pure water.
Definition SimpleHuDuanH2O.hpp:361
Opm::SimpleHuDuanH2O::gasDensity
static OPM_HOST_DEVICE Evaluation gasDensity(const Evaluation &temperature, const Evaluation &pressure)
The density of steam at a given pressure and temperature.
Definition SimpleHuDuanH2O.hpp:288
Opm::SimpleHuDuanH2O::gasHeatCapacity
static OPM_HOST_DEVICE Evaluation gasHeatCapacity(const Evaluation &, const Evaluation &)
Specific isobaric heat capacity of the component [J/kg] as a gas.
Definition SimpleHuDuanH2O.hpp:188
Opm::SimpleHuDuanH2O::criticalTemperature
static OPM_HOST_DEVICE Scalar criticalTemperature()
Returns the critical temperature of water.
Definition SimpleHuDuanH2O.hpp:109
Opm::SimpleHuDuanH2O::liquidPressure
static OPM_HOST_DEVICE Evaluation liquidPressure(const Evaluation &, const Evaluation &)
The pressure of water in at a given density and temperature.
Definition SimpleHuDuanH2O.hpp:329
Opm::SimpleHuDuanH2O::gasThermalConductivity
static OPM_HOST_DEVICE Evaluation gasThermalConductivity(const Evaluation &, const Evaluation &)
Specific heat conductivity of steam .
Definition SimpleHuDuanH2O.hpp:275
Opm::SimpleHuDuanH2O::liquidThermalConductivity
static OPM_HOST_DEVICE Evaluation liquidThermalConductivity(const Evaluation &, const Evaluation &)
Specific heat conductivity of liquid water .
Definition SimpleHuDuanH2O.hpp:262
Opm::SimpleHuDuanH2O::gasInternalEnergy
static OPM_HOST_DEVICE Evaluation gasInternalEnergy(const Evaluation &temperature, const Evaluation &pressure)
Specific internal energy of steam .
Definition SimpleHuDuanH2O.hpp:228
Opm::SimpleHuDuanH2O::liquidHeatCapacity
static OPM_HOST_DEVICE Evaluation liquidHeatCapacity(const Evaluation &, const Evaluation &)
Specific isobaric heat capacity of the component [J/kg] as a liquid.
Definition SimpleHuDuanH2O.hpp:210
Opm::SimpleHuDuanH2O::tripleTemperature
static OPM_HOST_DEVICE Scalar tripleTemperature()
Returns the temperature at water's triple point.
Definition SimpleHuDuanH2O.hpp:121
Opm::SimpleHuDuanH2O::liquidIsCompressible
static OPM_HOST_DEVICE bool liquidIsCompressible()
Returns true iff the liquid phase is assumed to be compressible.
Definition SimpleHuDuanH2O.hpp:91
Opm::SimpleHuDuanH2O::gasViscosity
static OPM_HOST_DEVICE Evaluation gasViscosity(const Evaluation &, const Evaluation &)
The dynamic viscosity of steam.
Definition SimpleHuDuanH2O.hpp:346
Opm::SimpleHuDuanH2O::molarMass
static OPM_HOST_DEVICE Scalar molarMass()
The molar mass in of water.
Definition SimpleHuDuanH2O.hpp:103
Opm::SimpleHuDuanH2O::triplePressure
static OPM_HOST_DEVICE Scalar triplePressure()
Returns the pressure at water's triple point.
Definition SimpleHuDuanH2O.hpp:127
Opm::SimpleHuDuanH2O::gasEnthalpy
static OPM_HOST_DEVICE Evaluation gasEnthalpy(const Evaluation &temperature, const Evaluation &)
Specific enthalpy of water steam .
Definition SimpleHuDuanH2O.hpp:179
Opm::SimpleHuDuanH2O::gasIsCompressible
static OPM_HOST_DEVICE bool gasIsCompressible()
Returns true iff the gas phase is assumed to be compressible.
Definition SimpleHuDuanH2O.hpp:85
Opm::SimpleHuDuanH2O::vaporPressure
static OPM_HOST_DEVICE Evaluation vaporPressure(const Evaluation &T)
The vapor pressure in of pure water at a given temperature.
Definition SimpleHuDuanH2O.hpp:143
Opm::SimpleHuDuanH2O::liquidInternalEnergy
static OPM_HOST_DEVICE Evaluation liquidInternalEnergy(const Evaluation &temperature, const Evaluation &pressure, bool extrapolate)
Specific internal energy of liquid water .
Definition SimpleHuDuanH2O.hpp:246
Opm::SimpleHuDuanH2O::name
static OPM_HOST_DEVICE std::string_view name()
A human readable name for the water.
Definition SimpleHuDuanH2O.hpp:79
Opm::SimpleHuDuanH2O::criticalPressure
static OPM_HOST_DEVICE Scalar criticalPressure()
Returns the critical pressure of water.
Definition SimpleHuDuanH2O.hpp:115
Opm::SimpleHuDuanH2O::gasIsIdeal
static OPM_HOST_DEVICE bool gasIsIdeal()
Returns true iff the gas phase is assumed to be ideal.
Definition SimpleHuDuanH2O.hpp:97
Opm::SimpleHuDuanH2O::gasPressure
static OPM_HOST_DEVICE Evaluation gasPressure(const Evaluation &temperature, const Evaluation &density)
The pressure of steam in at a given density and temperature.
Definition SimpleHuDuanH2O.hpp:301
Opm::SimpleHuDuanH2O::liquidEnthalpy
static OPM_HOST_DEVICE Evaluation liquidEnthalpy(const Evaluation &temperature, const Evaluation &)
Specific enthalpy of liquid water .
Definition SimpleHuDuanH2O.hpp:202
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30