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.)
This commit is contained in:
parent
7a4c6546b4
commit
7c1bda6df1
@ -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 <opm/material/common/Valgrind.hpp>
|
||||
#include <opm/material/common/Exceptions.hpp>
|
||||
@ -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 Scalar>
|
||||
class XYTabulated2DFunction
|
||||
class IntervalTabulated2DFunction
|
||||
{
|
||||
public:
|
||||
XYTabulated2DFunction()
|
||||
IntervalTabulated2DFunction()
|
||||
{ }
|
||||
|
||||
template <class DataContainer>
|
||||
XYTabulated2DFunction(const std::vector<Scalar>& xPos,
|
||||
const std::vector<Scalar>& 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<Scalar>& xPos,
|
||||
const std::vector<Scalar>& 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 <typename Evaluation>
|
||||
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:
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include <opm/material/common/UniformXTabulated2DFunction.hpp>
|
||||
#include <opm/material/common/UniformTabulated2DFunction.hpp>
|
||||
#include <opm/material/common/XYTabulated2DFunction.hpp>
|
||||
#include <opm/material/common/IntervalTabulated2DFunction.hpp>
|
||||
|
||||
#include <dune/common/parallel/mpihelper.hh>
|
||||
|
||||
@ -134,8 +134,8 @@ struct Test
|
||||
|
||||
|
||||
template <class Fn>
|
||||
std::shared_ptr<Opm::XYTabulated2DFunction<Scalar> >
|
||||
createXYTabulated2DFunction(Fn& f)
|
||||
std::shared_ptr<Opm::IntervalTabulated2DFunction<Scalar> >
|
||||
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<Scalar> x_samples(m);
|
||||
std::vector<Scalar> y_samples(n);
|
||||
std::vector<Scalar> xSamples(m);
|
||||
std::vector<Scalar> ySamples(n);
|
||||
std::vector<std::vector<Scalar>> data(m, std::vector<Scalar>(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<Opm::XYTabulated2DFunction<Scalar>>(x_samples, y_samples, data, true, true);
|
||||
|
||||
return tab;
|
||||
return std::make_shared<Opm::IntervalTabulated2DFunction<Scalar>>(xSamples, ySamples, data, true, true);
|
||||
}
|
||||
|
||||
template <class Fn, class Table>
|
||||
@ -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("<<x<<","<<y<<") != f("<<x<<","<<y<<"): " << result << " != " << f(x,y) << "\n";
|
||||
return false;
|
||||
@ -423,7 +420,7 @@ inline int testAll(const typename TestType::Scalar tolerance = 1e-6)
|
||||
{
|
||||
using ScalarType = typename TestType::Scalar;
|
||||
|
||||
auto xytab = test.createXYTabulated2DFunction(TestType::testFn1);
|
||||
auto xytab = test.createIntervalTabulated2DFunction(TestType::testFn1);
|
||||
const ScalarType xMin = -4.0;
|
||||
const ScalarType xMax = 8.0;
|
||||
const unsigned m = 250;
|
||||
@ -438,12 +435,12 @@ inline int testAll(const typename TestType::Scalar tolerance = 1e-6)
|
||||
if (!test.compareTableWithAnalyticFn2(xytab, xMin, xMax, m, yMin, yMax, n, TestType::testFn1, tmpTolerance))
|
||||
return 1;
|
||||
|
||||
xytab = test.createXYTabulated2DFunction(TestType::testFn2);
|
||||
xytab = test.createIntervalTabulated2DFunction(TestType::testFn2);
|
||||
|
||||
if (!test.compareTableWithAnalyticFn2(xytab, xMin, xMax, m, yMin, yMax, n, TestType::testFn2, tmpTolerance))
|
||||
return 1;
|
||||
|
||||
xytab = test.createXYTabulated2DFunction(TestType::testFn3);
|
||||
xytab = test.createIntervalTabulated2DFunction(TestType::testFn3);
|
||||
|
||||
if (!test.compareTableWithAnalyticFn2(xytab, xMin, xMax, m, yMin, yMax, n, TestType::testFn3, tmpTolerance))
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user