Loading...
Searching...
No Matches
TwoPhaseLETCurves.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 3 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_TWO_PHASE_LET_CURVES_HPP
#define OPM_TWO_PHASE_LET_CURVES_HPP
#include "TwoPhaseLETCurvesParams.hpp"
#include <opm/common/Exceptions.hpp>
#include <opm/material/common/MathToolbox.hpp>
namespace Opm {
template <class TraitsT, class ParamsT = TwoPhaseLETCurvesParams<TraitsT> >
class TwoPhaseLETCurves : public TraitsT
{
public:
using Traits = TraitsT;
using Params = ParamsT;
using Scalar = typename Traits::Scalar;
static_assert(Traits::numPhases == 2,
"The number of fluid phases must be two if you want to use "
"this material law!");
static constexpr Scalar eps = 1.0e-10; //tolerance
static constexpr int numPhases = Traits::numPhases;
static constexpr bool implementsTwoPhaseApi = true;
static constexpr bool implementsTwoPhaseSatApi = true;
static constexpr bool isSaturationDependent = true;
static constexpr bool isPressureDependent = false;
static constexpr bool isTemperatureDependent = false;
static constexpr bool isCompositionDependent = false;
template <class Container, class FluidState>
static void capillaryPressures(Container& /* values */, const Params& /* params */, const FluidState& /* fs */)
{
throw std::logic_error("The capillaryPressures(fs) method is not yet implemented");
}
template <class Container, class FluidState>
static void saturations(Container& /* pc */, const Params& /* params */, const FluidState& /* fs */)
{
throw std::logic_error("The saturations(fs) method is not yet implemented");
}
template <class Container, class FluidState>
static void relativePermeabilities(Container& /* pc */, const Params& /* params */, const FluidState& /* fs */)
{
throw std::logic_error("The relativePermeabilities(fs) method is not yet implemented");
}
template <class FluidState, class Evaluation = typename FluidState::Scalar>
static Evaluation pcnw(const Params& /* params */, const FluidState& /* fs */)
{
throw std::logic_error("TwoPhaseLETCurves::pcnw"
" not implemented!");
}
template <class Evaluation>
static Evaluation twoPhaseSatPcnw(const Params& params, const Evaluation& Sw)
{
Evaluation Ss = (Sw-params.Sminpc())/params.dSpc();
if (Ss < 0.0) {
Ss -= (Opm::decay<Scalar>(Ss));
} else if (Ss > 1.0) {
Ss -= (Opm::decay<Scalar>(Ss-1.0));
}
const Evaluation powS = Opm::pow(Ss,params.Tpc());
const Evaluation pow1mS = Opm::pow(1.0-Ss,params.Lpc());
const Evaluation F = pow1mS/(pow1mS+powS*params.Epc());
Evaluation tmp = params.Pct()+(params.Pcir()-params.Pct())*F;
return tmp;
}
template <class Evaluation>
static Evaluation twoPhaseSatPcnwInv(const Params& /* params */, const Evaluation&)
{
throw std::logic_error("TwoPhaseLETCurves::twoPhaseSatPcnwInv"
" not implemented!");
}
template <class FluidState, class Evaluation = typename FluidState::Scalar>
static Evaluation Sw(const Params& /* params */, const FluidState& /* fs */)
{
throw std::logic_error("The Sw(fs) method is not yet implemented");
}
template <class Evaluation>
static Evaluation twoPhaseSatSw(const Params& /* params */, const Evaluation& /* pc */)
{
throw std::logic_error("The twoPhaseSatSw(fs) method is not yet implemented");
}
template <class FluidState, class Evaluation = typename FluidState::Scalar>
static Evaluation Sn(const Params& /* params */, const FluidState& /* fs */)
{
throw std::logic_error("The Sn(fs) method is not yet implemented");
}
template <class Evaluation>
static Evaluation twoPhaseSatSn(const Params& /* params */, const Evaluation& /* pc */)
{
throw std::logic_error("The twoPhaseSatSn(fs) method is not yet implemented");
}
template <class FluidState, class Evaluation = typename FluidState::Scalar>
static Evaluation krw(const Params& /* params */, const FluidState& /* fs */)
{
throw std::logic_error("TwoPhaseLETCurves::krw"
" not implemented!");
}
template <class Evaluation>
static Evaluation twoPhaseSatKrw(const Params& params, const Evaluation& Sw)
{
return twoPhaseSatKrLET(Params::wIdx, params, Sw);
}
template <class Evaluation>
static Evaluation twoPhaseSatKrLET(const unsigned phaseIdx, const Params& params, const Evaluation& S)
{
Evaluation Ss = (S-params.Smin(phaseIdx))/params.dS(phaseIdx);
if (Ss < 0.0) {
Ss -= (Opm::decay<Scalar>(Ss));
} else if (Ss > 1.0) {
Ss -= (Opm::decay<Scalar>(Ss-1.0));
}
const Evaluation powS = Opm::pow(Ss,params.L(phaseIdx));
const Evaluation pow1mS = Opm::pow(1.0-Ss,params.T(phaseIdx));
const Evaluation tmp = params.Krt(phaseIdx)*powS/(powS+pow1mS*params.E(phaseIdx));
return tmp;
}
template <class Evaluation>
static Evaluation twoPhaseSatKrwInv(const Params& /* params */, const Evaluation& /* krw */)
{
throw std::logic_error("TwoPhaseLETCurves::twoPhaseSatKrwInv"
" not implemented!");
}
template <class FluidState, class Evaluation = typename FluidState::Scalar>
static Evaluation krn(const Params& /* params */, const FluidState& /* fs */)
{
throw std::logic_error("TwoPhaseLETCurves::krn"
" not implemented!");
}
template <class Evaluation>
static Evaluation twoPhaseSatKrn(const Params& params, const Evaluation& Sw)
{
const Evaluation sn = 1.0 - Sw;
return twoPhaseSatKrLET(Params::nwIdx, params, sn);
}
template <class Evaluation>
static Evaluation twoPhaseSatKrnInv(const Params& params, const Evaluation& krn)
{
// since inverting the formula for krn is hard to do analytically, we use the
// Newton-Raphson method
Evaluation sw = 0.5;
//Scalar eps = 1e-10;
for (int i = 0; i < 20; ++i) {
Evaluation f = krn - twoPhaseSatKrn(params, sw);
if (Opm::abs(f) < 1e-10) {
return sw;
}
Evaluation fStar = krn - twoPhaseSatKrn(params, sw + eps);
Evaluation fPrime = (fStar - f)/eps;
Evaluation delta = f/fPrime;
sw -= delta;
if (sw < 0) {
sw = 0.0;
}
if (sw > 1.0) {
sw = 1.0;
}
if (Opm::abs(delta) < 1e-10)
return sw;
}
// Fallback to simple bisection
Evaluation SL = 0.0;
Evaluation fL = krn - twoPhaseSatKrn(params, SL);
if (Opm::abs(fL) < eps)
return SL;
Evaluation SR = 1.0;
Evaluation fR = krn - twoPhaseSatKrn(params, SR);
if (Opm::abs(fR) < eps)
return SR;
if (fL*fR < 0.0) {
for (int i = 0; i < 50; ++i) {
sw = 0.5*(SL+SR);
if (abs(SR-SL) < eps) {
return sw;
}
Evaluation fw = krn - twoPhaseSatKrn(params, sw);
if (Opm::abs(fw) < eps) {
return sw;
}
if (fw * fR > 0) {
SR = sw;
fR = fw;
} else if (fw * fL > 0) {
SL = sw;
fL = fw;
}
}
}
throw NumericalProblem("Couldn't invert the TwoPhaseLETCurves non-wetting phase"
" relperm within 20 newton iterations and 50 bisection iterations");
}
};
} // namespace Opm
#endif // OPM_TWO_PHASE_LET_CURVES_HPP
Exceptions.hpp
Provides the OPM specific exception classes.
MathToolbox.hpp
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
TwoPhaseLETCurvesParams.hpp
Opm::TwoPhaseLETCurves
Implementation of the LET curve saturation functions.
Definition TwoPhaseLETCurves.hpp:50
Opm::TwoPhaseLETCurves::krn
static Evaluation krn(const Params &, const FluidState &)
The relative permeability for the non-wetting phase of the medium as implied by the LET parameterizat...
Definition TwoPhaseLETCurves.hpp:237
Opm::TwoPhaseLETCurves::pcnw
static Evaluation pcnw(const Params &, const FluidState &)
The capillary pressure-saturation curve.
Definition TwoPhaseLETCurves.hpp:130
Opm::TwoPhaseLETCurves< Traits >::implementsTwoPhaseSatApi
static constexpr bool implementsTwoPhaseSatApi
Definition TwoPhaseLETCurves.hpp:71
Opm::TwoPhaseLETCurves::krw
static Evaluation krw(const Params &, const FluidState &)
The relative permeability for the wetting phase of the medium implied by the LET parameterization.
Definition TwoPhaseLETCurves.hpp:193
Opm::TwoPhaseLETCurves< Traits >::isSaturationDependent
static constexpr bool isSaturationDependent
Definition TwoPhaseLETCurves.hpp:75
Opm::TwoPhaseLETCurves< Traits >::numPhases
static constexpr int numPhases
Definition TwoPhaseLETCurves.hpp:63
Opm::TwoPhaseLETCurves< Traits >::isCompositionDependent
static constexpr bool isCompositionDependent
Definition TwoPhaseLETCurves.hpp:87
Opm::TwoPhaseLETCurves< Traits >::isTemperatureDependent
static constexpr bool isTemperatureDependent
Definition TwoPhaseLETCurves.hpp:83
Opm::TwoPhaseLETCurves::saturations
static void saturations(Container &, const Params &, const FluidState &)
Calculate the saturations of the phases starting from their pressure differences.
Definition TwoPhaseLETCurves.hpp:103
Opm::TwoPhaseLETCurves< Traits >::isPressureDependent
static constexpr bool isPressureDependent
Definition TwoPhaseLETCurves.hpp:79
Opm::TwoPhaseLETCurves::capillaryPressures
static void capillaryPressures(Container &, const Params &, const FluidState &)
The capillary pressure-saturation curves.
Definition TwoPhaseLETCurves.hpp:93
Opm::TwoPhaseLETCurves< Traits >::implementsTwoPhaseApi
static constexpr bool implementsTwoPhaseApi
Definition TwoPhaseLETCurves.hpp:67
Opm::TwoPhaseLETCurves::relativePermeabilities
static void relativePermeabilities(Container &, const Params &, const FluidState &)
The relative permeability-saturation curves.
Definition TwoPhaseLETCurves.hpp:119
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30