From 322c6fb0ffe9358ac2f29f339586afd9f49855da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Thu, 28 Mar 2019 16:14:38 +0100 Subject: [PATCH] Address review issues. --- .../common/UniformXTabulated2DFunction.hpp | 54 ++++++++++--------- .../fluidsystems/blackoilpvt/LiveOilPvt.hpp | 6 +-- .../fluidsystems/blackoilpvt/WetGasPvt.hpp | 6 +-- tests/test_2dtables.cpp | 4 +- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/opm/material/common/UniformXTabulated2DFunction.hpp b/opm/material/common/UniformXTabulated2DFunction.hpp index 48680a52a..943cfe447 100644 --- a/opm/material/common/UniformXTabulated2DFunction.hpp +++ b/opm/material/common/UniformXTabulated2DFunction.hpp @@ -44,16 +44,6 @@ namespace Opm { -/*! - * \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 at Y = 0. - */ -enum class InterpolationGuide { LeftExtreme, RightExtreme, Vertical }; /*! * \brief Implements a scalar function that depends on two variables and which is sampled @@ -70,7 +60,21 @@ class UniformXTabulated2DFunction public: - explicit UniformXTabulated2DFunction(const InterpolationGuide iGuide) + /*! + * \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. + */ + enum class InterpolationPolicy { LeftExtreme, RightExtreme, Vertical }; + + explicit UniformXTabulated2DFunction(const InterpolationPolicy iGuide) : interpGuide_(iGuide) { } @@ -298,13 +302,13 @@ public: const Evaluation& alpha = xToAlpha(x, i); // find upper and lower y value Evaluation shift = 0.0; - if (interpGuide_ == InterpolationGuide::Vertical) { + if (interpGuide_ == InterpolationPolicy::Vertical) { // Shift is zero, no need to reset it. } else { - if (interpGuide_ == InterpolationGuide::LeftExtreme) { + if (interpGuide_ == InterpolationPolicy::LeftExtreme) { shift = yPos_[i+1] - yPos_[i]; } else { - assert(interpGuide_ == InterpolationGuide::RightExtreme); + assert(interpGuide_ == InterpolationPolicy::RightExtreme); shift = yPos_[i+1] - yPos_[i]; auto yEnd = yPos_[i]*(1.0 - alpha) + yPos_[i+1]*alpha; if (yEnd > 0.) { @@ -314,13 +318,13 @@ public: } } } - auto ylower = y - alpha*shift; - auto yupper = y + (1-alpha)*shift; + auto yLower = y - alpha*shift; + auto yUpper = y + (1-alpha)*shift; - unsigned j1 = ySegmentIndex(ylower, i, extrapolate); - unsigned j2 = ySegmentIndex(yupper, i + 1, extrapolate); - const Evaluation& beta1 = yToBeta(ylower, i, j1); - const Evaluation& beta2 = yToBeta(yupper, i + 1, j2); + unsigned j1 = ySegmentIndex(yLower, i, extrapolate); + unsigned j2 = ySegmentIndex(yUpper, i + 1, extrapolate); + const Evaluation& beta1 = yToBeta(yLower, i, j1); + const Evaluation& beta2 = yToBeta(yUpper, i + 1, j2); // evaluate the two function values for the same y value ... const Evaluation& s1 = valueAt(i, j1)*(1.0 - beta1) + valueAt(i, j1 + 1)*beta1; @@ -345,8 +349,8 @@ public: { if (xPos_.empty() || xPos_.back() < nextX) { xPos_.push_back(nextX); - yPos_.resize(xPos_.size()); - samples_.resize(xPos_.size()); + yPos_.push_back(-1e100); + samples_.push_back({}); return xPos_.size() - 1; } else if (xPos_.front() > nextX) { @@ -371,7 +375,7 @@ public: 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_ == InterpolationGuide::RightExtreme) { + if (interpGuide_ == InterpolationPolicy::RightExtreme) { yPos_[i] = y; } return samples_[i].size() - 1; @@ -379,7 +383,7 @@ public: 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_ == InterpolationGuide::LeftExtreme) { + if (interpGuide_ == InterpolationPolicy::LeftExtreme) { yPos_[i] = y; } return 0; @@ -432,7 +436,7 @@ private: std::vector xPos_; // the position on the y-axis of the guide point std::vector yPos_; - InterpolationGuide interpGuide_; + InterpolationPolicy interpGuide_; }; diff --git a/opm/material/fluidsystems/blackoilpvt/LiveOilPvt.hpp b/opm/material/fluidsystems/blackoilpvt/LiveOilPvt.hpp index cfafec318..c3b6ce7c1 100644 --- a/opm/material/fluidsystems/blackoilpvt/LiveOilPvt.hpp +++ b/opm/material/fluidsystems/blackoilpvt/LiveOilPvt.hpp @@ -238,11 +238,11 @@ public: { oilReferenceDensity_.resize(numRegions); gasReferenceDensity_.resize(numRegions); - inverseOilBTable_.resize(numRegions, TabulatedTwoDFunction{InterpolationGuide::LeftExtreme}); - inverseOilBMuTable_.resize(numRegions, TabulatedTwoDFunction{InterpolationGuide::LeftExtreme}); + inverseOilBTable_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::LeftExtreme}); + inverseOilBMuTable_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::LeftExtreme}); inverseSaturatedOilBTable_.resize(numRegions); inverseSaturatedOilBMuTable_.resize(numRegions); - oilMuTable_.resize(numRegions, TabulatedTwoDFunction{InterpolationGuide::LeftExtreme}); + oilMuTable_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::LeftExtreme}); saturatedOilMuTable_.resize(numRegions); saturatedGasDissolutionFactorTable_.resize(numRegions); saturationPressure_.resize(numRegions); diff --git a/opm/material/fluidsystems/blackoilpvt/WetGasPvt.hpp b/opm/material/fluidsystems/blackoilpvt/WetGasPvt.hpp index d4669d811..b881c104c 100644 --- a/opm/material/fluidsystems/blackoilpvt/WetGasPvt.hpp +++ b/opm/material/fluidsystems/blackoilpvt/WetGasPvt.hpp @@ -234,11 +234,11 @@ public: { oilReferenceDensity_.resize(numRegions); gasReferenceDensity_.resize(numRegions); - inverseGasB_.resize(numRegions, TabulatedTwoDFunction{InterpolationGuide::RightExtreme}); - inverseGasBMu_.resize(numRegions, TabulatedTwoDFunction{InterpolationGuide::RightExtreme}); + inverseGasB_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::RightExtreme}); + inverseGasBMu_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::RightExtreme}); inverseSaturatedGasB_.resize(numRegions); inverseSaturatedGasBMu_.resize(numRegions); - gasMu_.resize(numRegions, TabulatedTwoDFunction{InterpolationGuide::RightExtreme}); + gasMu_.resize(numRegions, TabulatedTwoDFunction{TabulatedTwoDFunction::InterpolationPolicy::RightExtreme}); saturatedOilVaporizationFactorTable_.resize(numRegions); saturationPressure_.resize(numRegions); } diff --git a/tests/test_2dtables.cpp b/tests/test_2dtables.cpp index 94080e336..c5dfc6620 100644 --- a/tests/test_2dtables.cpp +++ b/tests/test_2dtables.cpp @@ -90,7 +90,7 @@ struct Test Scalar yMin = -1/2.0; Scalar yMax = 1/3.0; unsigned n = 40; - auto tab = std::make_shared>(Opm::InterpolationGuide::Vertical); + auto tab = std::make_shared>(Opm::UniformXTabulated2DFunction::InterpolationPolicy::Vertical); for (unsigned i = 0; i < m; ++i) { Scalar x = xMin + Scalar(i)/(m - 1) * (xMax - xMin); tab->appendXPos(x); @@ -115,7 +115,7 @@ struct Test Scalar yMin = - 4.0; Scalar yMax = 5.0; - auto tab = std::make_shared>(Opm::InterpolationGuide::Vertical); + auto tab = std::make_shared>(Opm::UniformXTabulated2DFunction::InterpolationPolicy::Vertical); for (unsigned i = 0; i < m; ++i) { Scalar x = xMin + Scalar(i)/(m - 1) * (xMax - xMin);