From 7c1bda6df1bdd351ef73eb19ea0556b0a2a3b75b Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Wed, 19 Dec 2018 14:07:16 +0100 Subject: [PATCH] rename XYTabulated2DFunction to IntervalTabulated2DFunction ... because every 2D function depends on two variables which are usually called X and Y. The name of that class is still clunky, suggestions are appreciated. (also, UniformXTabulated2DFunction is a bad name. I also take suggestions for that.) --- ...on.hpp => IntervalTabulated2DFunction.hpp} | 38 +++++++++---------- tests/test_2dtables.cpp | 29 +++++++------- 2 files changed, 31 insertions(+), 36 deletions(-) rename opm/material/common/{XYTabulated2DFunction.hpp => IntervalTabulated2DFunction.hpp} (90%) diff --git a/opm/material/common/XYTabulated2DFunction.hpp b/opm/material/common/IntervalTabulated2DFunction.hpp similarity index 90% rename from opm/material/common/XYTabulated2DFunction.hpp rename to opm/material/common/IntervalTabulated2DFunction.hpp index 1546c2bcf..ba4fdee8f 100644 --- a/opm/material/common/XYTabulated2DFunction.hpp +++ b/opm/material/common/IntervalTabulated2DFunction.hpp @@ -23,10 +23,10 @@ /*! * \file * - * \copydoc Opm::XYTabulated2DFunction.hpp + * \copydoc Opm::IntervalTabulated2DFunction */ -#ifndef OPM_XY_TABULATED_2D_FUNCTION_HPP -#define OPM_XY_TABULATED_2D_FUNCTION_HPP +#ifndef OPM_INTERVAL_TABULATED_2D_FUNCTION_HPP +#define OPM_INTERVAL_TABULATED_2D_FUNCTION_HPP #include #include @@ -45,27 +45,26 @@ namespace Opm { * \brief Implements a function that depends on two variables. * * The function is sampled in regular intervals in both directions, i.e., the - * interpolation cells are rectangles. The table can be specified to be extrapolated in - * either direction. + * interpolation cells are rectangles. The table can be extrapolated in either direction. */ template -class XYTabulated2DFunction +class IntervalTabulated2DFunction { public: - XYTabulated2DFunction() + IntervalTabulated2DFunction() { } template - XYTabulated2DFunction(const std::vector& xPos, - const std::vector& yPos, - const DataContainer& data, - const bool xExtrapolate = false, - const bool yExtrapolate = false) - : xPos_(xPos) - , yPos_(yPos) - , samples_(data) - , xExtrapolate_(xExtrapolate) - , yExtrapolate_(yExtrapolate) + IntervalTabulated2DFunction(const std::vector& xPos, + const std::vector& yPos, + const DataContainer& data, + const bool xExtrapolate = false, + const bool yExtrapolate = false) + : xPos_(xPos) + , yPos_(yPos) + , samples_(data) + , xExtrapolate_(xExtrapolate) + , yExtrapolate_(yExtrapolate) { #ifndef NDEBUG // in debug mode, ensure that the x and y positions arrays are strictly @@ -166,7 +165,7 @@ public: * a \c Opm::NumericalIssue exception is thrown. */ template - void eval(const Evaluation& x, const Evaluation& y, Evaluation& result) const + Evaluation eval(const Evaluation& x, const Evaluation& y) const { if ((!xExtrapolate_ && !appliesX(x)) || (!yExtrapolate_ && !appliesY(y))) { std::ostringstream oss; @@ -190,8 +189,7 @@ public: Valgrind::CheckDefined(s2); // ... and combine them using the x position - result = s1 * (1.0 - alpha) + s2 * alpha; - Valgrind::CheckDefined(result); + return s1*(1.0 - alpha) + s2*alpha; } private: diff --git a/tests/test_2dtables.cpp b/tests/test_2dtables.cpp index d3ab7fe7a..8999f6d71 100644 --- a/tests/test_2dtables.cpp +++ b/tests/test_2dtables.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include @@ -134,8 +134,8 @@ struct Test template - std::shared_ptr > - createXYTabulated2DFunction(Fn& f) + std::shared_ptr > + createIntervalTabulated2DFunction(Fn& f) { const Scalar xMin = -2.0; const Scalar xMax = 3.0; @@ -145,22 +145,20 @@ struct Test const Scalar yMax = 1/3.0; const unsigned n = 40; - std::vector x_samples(m); - std::vector y_samples(n); + std::vector xSamples(m); + std::vector ySamples(n); std::vector> data(m, std::vector(n)); for (unsigned i = 0; i < m; ++i) { - x_samples[i] = xMin + Scalar(i)/(m - 1) * (xMax - xMin); + xSamples[i] = xMin + Scalar(i)/(m - 1) * (xMax - xMin); for (unsigned j = 0; j < n; ++j) { - y_samples[j] = yMin + Scalar(j)/(n -1) * (yMax - yMin); - data[i][j] = f(x_samples[i], y_samples[j]); + ySamples[j] = yMin + Scalar(j)/(n -1) * (yMax - yMin); + data[i][j] = f(xSamples[i], ySamples[j]); } } - auto tab = std::make_shared>(x_samples, y_samples, data, true, true); - - return tab; + return std::make_shared>(xSamples, ySamples, data, true, true); } template @@ -212,8 +210,7 @@ struct Test for (unsigned j = 0; j < numY; ++j) { Scalar y = yMin + Scalar(j)/numY*(yMax - yMin); - Scalar result; - table->eval(x, y, result); + Scalar result = table->eval(x, y); if (std::abs(result - f(x, y)) > tolerance) { std::cerr << __FILE__ << ":" << __LINE__ << ": table->eval("<