Skip to content

Commit

Permalink
Merge pull request #332 from andlaus/fix_max_oil_sat
Browse files Browse the repository at this point in the history
black oil PVT: make the maximum oil saturation a evaluation
  • Loading branch information
totto82 authored May 7, 2019
2 parents 94cbc7e + 8aba85d commit b2bfa87
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 43 deletions.
44 changes: 20 additions & 24 deletions opm/material/common/UniformXTabulated2DFunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
#include <cassert>

namespace Opm {




/*!
* \brief Implements a scalar function that depends on two variables and which is sampled
* uniformly in the X direction, but non-uniformly on the Y axis-
Expand All @@ -63,19 +59,21 @@ class UniformXTabulated2DFunction
/*!
* \brief Indicates how interpolation will be performed.
*
* Normal interpolation is done by interpolating vertically
* between lines of sample points, whereas LeftExtreme or
* RightExtreme implies guided interpolation, where
* interpolation is done parallel to a guide line. With
* LeftExtreme the lowest Y values will be used for the guide,
* and the guide line slope extends unchanged to infinity. With
* RightExtreme, the highest Y values are used, and the slope
* decreases linearly down to 0 (normal interpolation) for y <= 0.
* Normal interpolation is done by interpolating vertically between lines of sample
* points, whereas LeftExtreme or RightExtreme implies guided interpolation, where
* interpolation is done parallel to a guide line. With LeftExtreme the lowest Y
* values will be used for the guide, and the guide line slope extends unchanged to
* infinity. With RightExtreme, the highest Y values are used, and the slope
* decreases linearly down to 0 (normal interpolation) for y <= 0.
*/
enum class InterpolationPolicy { LeftExtreme, RightExtreme, Vertical };

explicit UniformXTabulated2DFunction(const InterpolationPolicy iGuide)
: interpGuide_(iGuide)
enum InterpolationPolicy {
LeftExtreme,
RightExtreme,
Vertical
};

explicit UniformXTabulated2DFunction(const InterpolationPolicy interpolationGuide = Vertical)
: interpolationGuide_(interpolationGuide)
{ }

/*!
Expand Down Expand Up @@ -306,16 +304,16 @@ class UniformXTabulated2DFunction
// value as one would get by interpolating along the boundary curve
// itself.
Evaluation shift = 0.0;
if (interpGuide_ == InterpolationPolicy::Vertical) {
if (interpolationGuide_ == InterpolationPolicy::Vertical) {
// Shift is zero, no need to reset it.
} else {
// find upper and lower y value
if (interpGuide_ == InterpolationPolicy::LeftExtreme) {
if (interpolationGuide_ == InterpolationPolicy::LeftExtreme) {
// The domain is above the boundary curve, up to y = infinity.
// The shift is therefore the same for all values of y.
shift = yPos_[i+1] - yPos_[i];
} else {
assert(interpGuide_ == InterpolationPolicy::RightExtreme);
assert(interpolationGuide_ == InterpolationPolicy::RightExtreme);
// The domain is below the boundary curve, down to y = 0.
// The shift is therefore no longer the the same for all
// values of y, since at y = 0 the shift must be zero.
Expand Down Expand Up @@ -387,15 +385,15 @@ class UniformXTabulated2DFunction
Scalar x = iToX(i);
if (samples_[i].empty() || std::get<1>(samples_[i].back()) < y) {
samples_[i].push_back(SamplePoint(x, y, value));
if (interpGuide_ == InterpolationPolicy::RightExtreme) {
if (interpolationGuide_ == InterpolationPolicy::RightExtreme) {
yPos_[i] = y;
}
return samples_[i].size() - 1;
}
else if (std::get<1>(samples_[i].front()) > y) {
// slow, but we still don't care...
samples_[i].insert(samples_[i].begin(), SamplePoint(x, y, value));
if (interpGuide_ == InterpolationPolicy::LeftExtreme) {
if (interpolationGuide_ == InterpolationPolicy::LeftExtreme) {
yPos_[i] = y;
}
return 0;
Expand Down Expand Up @@ -448,9 +446,7 @@ class UniformXTabulated2DFunction
std::vector<Scalar> xPos_;
// the position on the y-axis of the guide point
std::vector<Scalar> yPos_;
InterpolationPolicy interpGuide_;


InterpolationPolicy interpolationGuide_;
};
} // namespace Opm

Expand Down
8 changes: 4 additions & 4 deletions opm/material/fluidsystems/BlackOilFluidSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
void setRegionIndex(unsigned val)
{ regionIdx_ = val; }

const Scalar maxOilSat() const
const Evaluation& maxOilSat() const
{ return maxOilSat_; }

void setMaxOilSat(Scalar val)
void setMaxOilSat(const Evaluation& val)
{ maxOilSat_ = val; }

private:
Scalar maxOilSat_;
Evaluation maxOilSat_;
unsigned regionIdx_;
};

Expand Down Expand Up @@ -1000,7 +1000,7 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
static LhsEval saturatedDissolutionFactor(const FluidState& fluidState,
unsigned phaseIdx,
unsigned regionIdx,
Scalar maxOilSaturation)
const LhsEval& maxOilSaturation)
{
assert(0 <= phaseIdx && phaseIdx <= numPhases);
assert(0 <= regionIdx && regionIdx <= numRegions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class ConstantCompressibilityOilPvt
const Evaluation& /*temperature*/,
const Evaluation& /*pressure*/,
const Evaluation& /*oilSaturation*/,
Scalar /*maxOilSaturation*/) const
const Evaluation& /*maxOilSaturation*/) const
{ return 0.0; /* this is dead oil! */ }

/*!
Expand Down
2 changes: 1 addition & 1 deletion opm/material/fluidsystems/blackoilpvt/DeadOilPvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class DeadOilPvt
const Evaluation& /*temperature*/,
const Evaluation& /*pressure*/,
const Evaluation& /*oilSaturation*/,
Scalar /*maxOilSaturation*/) const
const Evaluation& /*maxOilSaturation*/) const
{ return 0.0; /* this is dead oil! */ }

/*!
Expand Down
2 changes: 1 addition & 1 deletion opm/material/fluidsystems/blackoilpvt/DryGasPvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class DryGasPvt
const Evaluation& /*temperature*/,
const Evaluation& /*pressure*/,
const Evaluation& /*oilSaturation*/,
Scalar /*maxOilSaturation*/) const
const Evaluation& /*maxOilSaturation*/) const
{ return 0.0; /* this is dry gas! */ }

/*!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class GasPvtMultiplexer
const Evaluation& temperature,
const Evaluation& pressure,
const Evaluation& oilSaturation,
Scalar maxOilSaturation) const
const Evaluation& maxOilSaturation) const
{ OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedOilVaporizationFactor(regionIdx, temperature, pressure, oilSaturation, maxOilSaturation)); return 0; }

/*!
Expand Down
2 changes: 1 addition & 1 deletion opm/material/fluidsystems/blackoilpvt/GasPvtThermal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class GasPvtThermal
const Evaluation& temperature,
const Evaluation& pressure,
const Evaluation& oilSaturation,
Scalar maxOilSaturation) const
const Evaluation& maxOilSaturation) const
{ return isothermalPvt_->saturatedOilVaporizationFactor(regionIdx, temperature, pressure, oilSaturation, maxOilSaturation); }

/*!
Expand Down
6 changes: 3 additions & 3 deletions opm/material/fluidsystems/blackoilpvt/LiveOilPvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#define OPM_LIVE_OIL_PVT_HPP

#include <opm/material/Constants.hpp>

#include <opm/material/common/OpmFinal.hpp>
#include <opm/material/common/MathToolbox.hpp>
#include <opm/material/common/UniformXTabulated2DFunction.hpp>
#include <opm/material/common/Tabulated1DFunction.hpp>

Expand Down Expand Up @@ -500,14 +500,14 @@ class LiveOilPvt
const Evaluation& /*temperature*/,
const Evaluation& pressure,
const Evaluation& oilSaturation,
Scalar maxOilSaturation) const
Evaluation maxOilSaturation) const
{
Evaluation tmp =
saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);

// apply the vaporization parameters for the gas phase (cf. the Eclipse VAPPARS
// keyword)
maxOilSaturation = std::min(maxOilSaturation, Scalar(1.0));
maxOilSaturation = Opm::min(maxOilSaturation, Scalar(1.0));
if (vapPar2_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
static const Scalar eps = 0.001;
const Evaluation& So = Opm::max(oilSaturation, eps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class OilPvtMultiplexer
const Evaluation& temperature,
const Evaluation& pressure,
const Evaluation& oilSaturation,
Scalar maxOilSaturation) const
const Evaluation& maxOilSaturation) const
{ OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedGasDissolutionFactor(regionIdx, temperature, pressure, oilSaturation, maxOilSaturation)); return 0; }

/*!
Expand Down
2 changes: 1 addition & 1 deletion opm/material/fluidsystems/blackoilpvt/OilPvtThermal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class OilPvtThermal
const Evaluation& temperature,
const Evaluation& pressure,
const Evaluation& oilSaturation,
Scalar maxOilSaturation) const
const Evaluation& maxOilSaturation) const
{ return isothermalPvt_->saturatedGasDissolutionFactor(regionIdx, temperature, pressure, oilSaturation, maxOilSaturation); }

/*!
Expand Down
5 changes: 3 additions & 2 deletions opm/material/fluidsystems/blackoilpvt/WetGasPvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define OPM_WET_GAS_PVT_HPP

#include <opm/material/Constants.hpp>
#include <opm/material/common/MathToolbox.hpp>
#include <opm/material/common/OpmFinal.hpp>
#include <opm/material/common/UniformXTabulated2DFunction.hpp>
#include <opm/material/common/Tabulated1DFunction.hpp>
Expand Down Expand Up @@ -520,14 +521,14 @@ class WetGasPvt
const Evaluation& /*temperature*/,
const Evaluation& pressure,
const Evaluation& oilSaturation,
Scalar maxOilSaturation) const
Evaluation maxOilSaturation) const
{
Evaluation tmp =
saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);

// apply the vaporization parameters for the gas phase (cf. the Eclipse VAPPARS
// keyword)
maxOilSaturation = std::min(maxOilSaturation, Scalar(1.0));
maxOilSaturation = Opm::min(maxOilSaturation, Scalar(1.0));
if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
static const Scalar eps = 0.001;
const Evaluation& So = Opm::max(oilSaturation, eps);
Expand Down
4 changes: 1 addition & 3 deletions tests/test_eclblackoilpvt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,14 @@ static const char* deckString1 =
template <class Evaluation, class OilPvt, class GasPvt, class WaterPvt>
void ensurePvtApi(const OilPvt& oilPvt, const GasPvt& gasPvt, const WaterPvt& waterPvt)
{
typedef typename Opm::MathToolbox<Evaluation> Toolbox;

// we don't want to run this, we just want to make sure that it compiles
while (0) {
Evaluation temperature = 273.15 + 20.0;
Evaluation pressure = 1e5;
Evaluation Rs = 0.0;
Evaluation Rv = 0.0;
Evaluation So = 0.5;
typename Toolbox::Scalar maxSo = 1.0;
Evaluation maxSo = 1.0;
Evaluation tmp;

/////
Expand Down

0 comments on commit b2bfa87

Please sign in to comment.