2015-06-18 06:47:07 -05:00
|
|
|
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
// vi: set et ts=4 sw=4 sts=4:
|
2014-07-07 11:15:02 -05:00
|
|
|
/*
|
|
|
|
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 2 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/>.
|
2016-03-14 08:11:22 -05:00
|
|
|
|
|
|
|
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.
|
2014-07-07 11:15:02 -05:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
* \file
|
|
|
|
*
|
|
|
|
* \brief This is the unit test for the 2D tabulation classes.
|
|
|
|
*
|
|
|
|
* I.e., for the UniformTabulated2DFunction and UniformXTabulated2DFunction classes.
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
2015-04-27 09:34:36 -05:00
|
|
|
#include <opm/material/common/UniformXTabulated2DFunction.hpp>
|
|
|
|
#include <opm/material/common/UniformTabulated2DFunction.hpp>
|
2018-12-06 06:19:04 -06:00
|
|
|
#include <opm/material/common/XYTabulated2DFunction.hpp>
|
2014-07-07 11:15:02 -05:00
|
|
|
|
2016-04-17 04:28:06 -05:00
|
|
|
#include <dune/common/parallel/mpihelper.hh>
|
|
|
|
|
2014-07-07 11:15:02 -05:00
|
|
|
#include <memory>
|
|
|
|
#include <cmath>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
template <class ScalarT>
|
|
|
|
struct Test
|
|
|
|
{
|
|
|
|
typedef ScalarT Scalar;
|
2015-09-22 04:20:55 -05:00
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
static Scalar testFn1(Scalar x, Scalar /* y */)
|
2014-07-07 11:15:02 -05:00
|
|
|
{ return x; }
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
static Scalar testFn2(Scalar /* x */, Scalar y)
|
2014-07-07 11:15:02 -05:00
|
|
|
{ return y; }
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
static Scalar testFn3(Scalar x, Scalar y)
|
2014-07-07 11:15:02 -05:00
|
|
|
{ return x*y; }
|
|
|
|
|
|
|
|
template <class Fn>
|
|
|
|
std::shared_ptr<Opm::UniformTabulated2DFunction<Scalar> >
|
2017-01-18 10:04:59 -06:00
|
|
|
createUniformTabulatedFunction(Fn& f)
|
2014-07-07 11:15:02 -05:00
|
|
|
{
|
|
|
|
Scalar xMin = -2.0;
|
|
|
|
Scalar xMax = 3.0;
|
2015-09-22 04:20:55 -05:00
|
|
|
unsigned m = 50;
|
2014-07-07 11:15:02 -05:00
|
|
|
|
|
|
|
Scalar yMin = -1/2.0;
|
|
|
|
Scalar yMax = 1/3.0;
|
2015-09-22 04:20:55 -05:00
|
|
|
unsigned n = 40;
|
2014-07-07 11:15:02 -05:00
|
|
|
|
|
|
|
auto tab = std::make_shared<Opm::UniformTabulated2DFunction<Scalar>>(
|
|
|
|
xMin, xMax, m,
|
|
|
|
yMin, yMax, n);
|
2015-09-22 04:20:55 -05:00
|
|
|
for (unsigned i = 0; i < m; ++i) {
|
2014-07-07 11:15:02 -05:00
|
|
|
Scalar x = xMin + Scalar(i)/(m - 1) * (xMax - xMin);
|
2015-09-22 04:20:55 -05:00
|
|
|
for (unsigned j = 0; j < n; ++j) {
|
2014-07-07 11:15:02 -05:00
|
|
|
Scalar y = yMin + Scalar(j)/(n - 1) * (yMax - yMin);
|
|
|
|
tab->setSamplePoint(i, j, f(x, y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Fn>
|
|
|
|
std::shared_ptr<Opm::UniformXTabulated2DFunction<Scalar> >
|
2017-01-18 10:04:59 -06:00
|
|
|
createUniformXTabulatedFunction(Fn& f)
|
2014-07-07 11:15:02 -05:00
|
|
|
{
|
|
|
|
Scalar xMin = -2.0;
|
|
|
|
Scalar xMax = 3.0;
|
2015-09-22 04:20:55 -05:00
|
|
|
unsigned m = 50;
|
2014-07-07 11:15:02 -05:00
|
|
|
|
|
|
|
Scalar yMin = -1/2.0;
|
|
|
|
Scalar yMax = 1/3.0;
|
2015-09-22 04:20:55 -05:00
|
|
|
unsigned n = 40;
|
2014-07-07 11:15:02 -05:00
|
|
|
|
|
|
|
auto tab = std::make_shared<Opm::UniformXTabulated2DFunction<Scalar>>();
|
2015-09-22 04:20:55 -05:00
|
|
|
for (unsigned i = 0; i < m; ++i) {
|
2014-07-07 11:15:02 -05:00
|
|
|
Scalar x = xMin + Scalar(i)/(m - 1) * (xMax - xMin);
|
|
|
|
tab->appendXPos(x);
|
2015-09-22 04:20:55 -05:00
|
|
|
for (unsigned j = 0; j < n; ++j) {
|
2014-07-07 11:15:02 -05:00
|
|
|
Scalar y = yMin + Scalar(j)/(n -1) * (yMax - yMin);
|
|
|
|
tab->appendSamplePoint(i, y, f(x, y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Fn>
|
|
|
|
std::shared_ptr<Opm::UniformXTabulated2DFunction<Scalar> >
|
2017-01-18 10:04:59 -06:00
|
|
|
createUniformXTabulatedFunction2(Fn& f)
|
2014-07-07 11:15:02 -05:00
|
|
|
{
|
|
|
|
Scalar xMin = -2.0;
|
|
|
|
Scalar xMax = 3.0;
|
|
|
|
Scalar m = 50;
|
|
|
|
|
2015-10-29 07:54:37 -05:00
|
|
|
Scalar yMin = - 4.0;
|
|
|
|
Scalar yMax = 5.0;
|
2014-07-07 11:15:02 -05:00
|
|
|
|
|
|
|
auto tab = std::make_shared<Opm::UniformXTabulated2DFunction<Scalar>>();
|
2015-09-22 04:20:55 -05:00
|
|
|
for (unsigned i = 0; i < m; ++i) {
|
2014-07-07 11:15:02 -05:00
|
|
|
Scalar x = xMin + Scalar(i)/(m - 1) * (xMax - xMin);
|
|
|
|
tab->appendXPos(x);
|
|
|
|
|
|
|
|
Scalar n = i + 10;
|
|
|
|
|
2015-09-22 04:20:55 -05:00
|
|
|
for (unsigned j = 0; j < n; ++j) {
|
2014-07-07 11:15:02 -05:00
|
|
|
Scalar y = yMin + Scalar(j)/(n -1) * (yMax - yMin);
|
|
|
|
tab->appendSamplePoint(i, y, f(x, y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:19:04 -06:00
|
|
|
|
|
|
|
template <class Fn>
|
|
|
|
std::shared_ptr<Opm::XYTabulated2DFunction<Scalar> >
|
|
|
|
createXYTabulated2DFunction(Fn& f)
|
|
|
|
{
|
|
|
|
const Scalar xMin = -2.0;
|
|
|
|
const Scalar xMax = 3.0;
|
2018-12-11 03:44:25 -06:00
|
|
|
const unsigned m = 50;
|
2018-12-06 06:19:04 -06:00
|
|
|
|
|
|
|
const Scalar yMin = -1/2.0;
|
|
|
|
const Scalar yMax = 1/3.0;
|
|
|
|
const unsigned n = 40;
|
|
|
|
|
|
|
|
std::vector<Scalar> x_samples(m);
|
|
|
|
std::vector<Scalar> y_samples(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);
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto tab = std::make_shared<Opm::XYTabulated2DFunction<Scalar>>(x_samples, y_samples, data, true, true);
|
|
|
|
|
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
|
2014-07-07 11:15:02 -05:00
|
|
|
template <class Fn, class Table>
|
2017-01-18 10:04:59 -06:00
|
|
|
bool compareTableWithAnalyticFn(const Table& table,
|
2014-07-07 11:15:02 -05:00
|
|
|
Scalar xMin,
|
|
|
|
Scalar xMax,
|
2015-09-22 04:20:55 -05:00
|
|
|
unsigned numX,
|
2014-07-07 11:15:02 -05:00
|
|
|
|
|
|
|
Scalar yMin,
|
|
|
|
Scalar yMax,
|
2015-09-22 04:20:55 -05:00
|
|
|
unsigned numY,
|
2014-07-07 11:15:02 -05:00
|
|
|
|
2017-01-18 10:04:59 -06:00
|
|
|
Fn& f,
|
2014-07-07 11:15:02 -05:00
|
|
|
Scalar tolerance = 1e-8)
|
|
|
|
{
|
|
|
|
// make sure that the tabulated function evaluates to the same thing as the analytic
|
|
|
|
// one (modulo tolerance)
|
2015-09-22 04:20:55 -05:00
|
|
|
for (unsigned i = 1; i <= numX; ++i) {
|
2014-07-07 11:15:02 -05:00
|
|
|
Scalar x = xMin + Scalar(i)/numX*(xMax - xMin);
|
|
|
|
|
2015-09-22 04:20:55 -05:00
|
|
|
for (unsigned j = 0; j < numY; ++j) {
|
2014-07-07 11:15:02 -05:00
|
|
|
Scalar y = yMin + Scalar(j)/numY*(yMax - yMin);
|
|
|
|
if (std::abs(table->eval(x, y) - f(x, y)) > tolerance) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": table->eval("<<x<<","<<y<<") != f("<<x<<","<<y<<"): " << table->eval(x,y) << " != " << f(x,y) << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:19:04 -06:00
|
|
|
template <class Fn, class Table>
|
|
|
|
bool compareTableWithAnalyticFn2(const Table& table,
|
|
|
|
const Scalar xMin,
|
|
|
|
const Scalar xMax,
|
|
|
|
unsigned numX,
|
|
|
|
const Scalar yMin,
|
|
|
|
const Scalar yMax,
|
|
|
|
unsigned numY,
|
|
|
|
|
|
|
|
Fn& f,
|
|
|
|
Scalar tolerance = 1e-8)
|
|
|
|
{
|
|
|
|
// make sure that the tabulated function evaluates to the same thing as the analytic
|
|
|
|
// one (modulo tolerance)
|
|
|
|
for (unsigned i = 1; i <= numX; ++i) {
|
|
|
|
Scalar x = xMin + Scalar(i)/numX*(xMax - xMin);
|
|
|
|
|
|
|
|
for (unsigned j = 0; j < numY; ++j) {
|
|
|
|
Scalar y = yMin + Scalar(j)/numY*(yMax - yMin);
|
|
|
|
Scalar result;
|
|
|
|
table->eval(x, y, result);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-07 11:15:02 -05:00
|
|
|
template <class UniformTablePtr, class UniformXTablePtr, class Fn>
|
|
|
|
bool compareTables(const UniformTablePtr uTable,
|
|
|
|
const UniformXTablePtr uXTable,
|
2017-01-18 10:04:59 -06:00
|
|
|
Fn& f,
|
2014-07-07 11:15:02 -05:00
|
|
|
Scalar tolerance = 1e-8)
|
|
|
|
{
|
|
|
|
// make sure the uniform and the non-uniform tables exhibit the same dimensions
|
2016-01-14 18:28:07 -06:00
|
|
|
if (std::abs(uTable->xMin() - uXTable->xMin()) > tolerance) {
|
2014-07-07 11:15:02 -05:00
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->xMin() != uXTable->xMin(): " << uTable->xMin() << " != " << uXTable->xMin() << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-14 18:28:07 -06:00
|
|
|
if (std::abs(uTable->xMax() - uXTable->xMax()) > tolerance) {
|
2014-07-07 11:15:02 -05:00
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->xMax() != uXTable->xMax(): " << uTable->xMax() << " != " << uXTable->xMax() << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (uTable->numX() != uXTable->numX()) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->numX() != uXTable->numX(): " << uTable->numX() << " != " << uXTable->numX() << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-22 04:20:55 -05:00
|
|
|
for (unsigned i = 0; i < uTable->numX(); ++i) {
|
2016-01-14 18:28:07 -06:00
|
|
|
if (std::abs(uTable->yMin() - uXTable->yMin(i)) > tolerance) {
|
2014-07-07 11:15:02 -05:00
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->yMin() != uXTable->yMin("<<i<<"): " << uTable->yMin() << " != " << uXTable->yMin(i) << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
if (std::abs(uTable->yMax() - uXTable->yMax(i)) > tolerance) {
|
2014-07-07 11:15:02 -05:00
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->yMax() != uXTable->yMax("<<i<<"): " << uTable->yMax() << " != " << uXTable->yMax(i) << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uTable->numY() != uXTable->numY(i)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->numY() != uXTable->numY("<<i<<"): " << uTable->numY() << " != " << uXTable->numY(i) << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure that the x and y values are identical
|
2015-09-22 04:20:55 -05:00
|
|
|
for (unsigned i = 0; i < uTable->numX(); ++i) {
|
2016-01-14 18:28:07 -06:00
|
|
|
if (std::abs(uTable->iToX(i) - uXTable->iToX(i)) > tolerance) {
|
2014-07-07 11:15:02 -05:00
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->iToX("<<i<<") != uXTable->iToX("<<i<<"): " << uTable->iToX(i) << " != " << uXTable->iToX(i) << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-22 04:20:55 -05:00
|
|
|
for (unsigned j = 0; j < uTable->numY(); ++j) {
|
2016-01-14 18:28:07 -06:00
|
|
|
if (std::abs(uTable->jToY(j) - uXTable->jToY(i, j)) > tolerance) {
|
2014-07-07 11:15:02 -05:00
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->jToY("<<j<<") != uXTable->jToY("<<i<<","<<j<<"): " << uTable->jToY(i) << " != " << uXTable->jToY(i, j) << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check that the appicable range is correct. Note that due to rounding errors it is
|
|
|
|
// undefined whether the table applies to the boundary of the tabulated domain or not
|
|
|
|
Scalar xMin = uTable->xMin();
|
|
|
|
Scalar yMin = uTable->yMin();
|
|
|
|
Scalar xMax = uTable->xMax();
|
|
|
|
Scalar yMax = uTable->yMax();
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
Scalar x = xMin - tolerance;
|
|
|
|
Scalar y = yMin - tolerance;
|
2014-07-07 11:15:02 -05:00
|
|
|
if (uTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (uXTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uXTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
x = xMin - tolerance;
|
|
|
|
y = yMin + tolerance;
|
2014-07-07 11:15:02 -05:00
|
|
|
if (uTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (uXTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uXTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
x = xMin + tolerance;
|
|
|
|
y = yMin - tolerance;
|
2014-07-07 11:15:02 -05:00
|
|
|
if (uTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (uXTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uXTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
x = xMin + tolerance;
|
|
|
|
y = yMin + tolerance;
|
2014-07-07 11:15:02 -05:00
|
|
|
if (!uTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": !uTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!uXTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": !uXTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
x = xMax + tolerance;
|
|
|
|
y = yMax + tolerance;
|
2014-07-07 11:15:02 -05:00
|
|
|
if (uTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (uXTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uXTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
x = xMax - tolerance;
|
|
|
|
y = yMax + tolerance;
|
2014-07-07 11:15:02 -05:00
|
|
|
if (uTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (uXTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uXTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
x = xMax + tolerance;
|
|
|
|
y = yMax - tolerance;
|
2014-07-07 11:15:02 -05:00
|
|
|
if (uTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (uXTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": uXTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
x = xMax - tolerance;
|
|
|
|
y = yMax - tolerance;
|
2014-07-07 11:15:02 -05:00
|
|
|
if (!uTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": !uTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!uXTable->applies(x, y)) {
|
|
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ": !uXTable->applies("<<x<<","<<y<<")\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure that the function values at the sampling points are identical and that
|
|
|
|
// they correspond to the analytic function
|
2015-09-22 04:20:55 -05:00
|
|
|
unsigned m2 = uTable->numX()*5;
|
|
|
|
unsigned n2 = uTable->numY()*5;
|
2014-07-07 11:15:02 -05:00
|
|
|
if (!compareTableWithAnalyticFn(uTable,
|
|
|
|
xMin, xMax, m2,
|
|
|
|
yMin, yMax, n2,
|
|
|
|
f,
|
|
|
|
tolerance))
|
|
|
|
return false;
|
|
|
|
if (!compareTableWithAnalyticFn(uXTable,
|
|
|
|
xMin, xMax, m2,
|
|
|
|
yMin, yMax, n2,
|
|
|
|
f,
|
|
|
|
tolerance))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-01-14 18:28:07 -06:00
|
|
|
};
|
2014-07-07 11:15:02 -05:00
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
|
|
|
|
template <class TestType>
|
|
|
|
inline int testAll( const typename TestType::Scalar tolerance = 1e-6 )
|
2014-07-07 11:15:02 -05:00
|
|
|
{
|
2016-01-14 18:28:07 -06:00
|
|
|
TestType test;
|
|
|
|
auto uniformTab = test.createUniformTabulatedFunction(TestType::testFn1);
|
|
|
|
auto uniformXTab = test.createUniformXTabulatedFunction(TestType::testFn1);
|
|
|
|
if (!test.compareTables(uniformTab, uniformXTab, TestType::testFn1, tolerance))
|
2014-07-07 11:15:02 -05:00
|
|
|
return 1;
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
uniformTab = test.createUniformTabulatedFunction(TestType::testFn2);
|
|
|
|
uniformXTab = test.createUniformXTabulatedFunction(TestType::testFn2);
|
|
|
|
if (!test.compareTables(uniformTab, uniformXTab, TestType::testFn2, tolerance))
|
2014-07-07 11:15:02 -05:00
|
|
|
return 1;
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
uniformTab = test.createUniformTabulatedFunction(TestType::testFn3);
|
|
|
|
uniformXTab = test.createUniformXTabulatedFunction(TestType::testFn3);
|
|
|
|
if (!test.compareTables(uniformTab, uniformXTab, TestType::testFn3, /*tolerance=*/1e-2))
|
2014-07-07 11:15:02 -05:00
|
|
|
return 1;
|
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
uniformXTab = test.createUniformXTabulatedFunction2(TestType::testFn3);
|
|
|
|
if (!test.compareTableWithAnalyticFn(uniformXTab,
|
2015-10-29 07:54:37 -05:00
|
|
|
-2.0, 3.0, 100,
|
|
|
|
-4.0, 5.0, 100,
|
2016-01-14 18:28:07 -06:00
|
|
|
TestType::testFn3,
|
2014-07-07 11:15:02 -05:00
|
|
|
/*tolerance=*/1e-2))
|
|
|
|
return 1;
|
|
|
|
|
2018-12-06 06:19:04 -06:00
|
|
|
{
|
|
|
|
using ScalarType = typename TestType::Scalar;
|
|
|
|
|
|
|
|
auto xytab = test.createXYTabulated2DFunction(TestType::testFn1);
|
|
|
|
const ScalarType xMin = -4.0;
|
|
|
|
const ScalarType xMax = 8.0;
|
|
|
|
const unsigned m = 250;
|
|
|
|
|
|
|
|
const ScalarType yMin = -2. / 2.0;
|
|
|
|
const ScalarType yMax = 3. / 3.0;
|
|
|
|
const unsigned n = 170;
|
|
|
|
|
|
|
|
// extrapolation and interpolation involved, the tolerance needs to be bigger
|
|
|
|
const ScalarType temp_tolerance = 1000. * tolerance;
|
|
|
|
|
|
|
|
if (!test.compareTableWithAnalyticFn2(xytab, xMin, xMax, m, yMin, yMax, n, TestType::testFn1, temp_tolerance))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
xytab = test.createXYTabulated2DFunction(TestType::testFn2);
|
|
|
|
|
|
|
|
if (!test.compareTableWithAnalyticFn2(xytab, xMin, xMax, m, yMin, yMax, n, TestType::testFn2, temp_tolerance))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
xytab = test.createXYTabulated2DFunction(TestType::testFn3);
|
|
|
|
|
|
|
|
if (!test.compareTableWithAnalyticFn2(xytab, xMin, xMax, m, yMin, yMax, n, TestType::testFn3, temp_tolerance))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-07-07 11:15:02 -05:00
|
|
|
// CSV output for debugging
|
|
|
|
#if 0
|
|
|
|
int m = 100;
|
|
|
|
int n = 100;
|
|
|
|
Scalar xMin = -3.0;
|
|
|
|
Scalar xMax = 4.0;
|
|
|
|
|
|
|
|
Scalar yMin = -1;
|
|
|
|
Scalar yMax = 1;
|
|
|
|
for (int i = 0; i < m; ++i) {
|
|
|
|
Scalar x = xMin + Scalar(i)/m * (xMax - xMin);
|
|
|
|
|
|
|
|
for (int j = 0; j < n; ++j) {
|
|
|
|
Scalar y = yMin + Scalar(j)/n * (yMax - yMin);
|
|
|
|
|
|
|
|
std::cout << x << " "
|
|
|
|
<< y << " "
|
|
|
|
<< uniformXTab->eval(x,y,true) << "\n";
|
|
|
|
}
|
|
|
|
std::cout << "\n";
|
|
|
|
}
|
|
|
|
#endif
|
2016-01-14 18:28:07 -06:00
|
|
|
return 0;
|
|
|
|
}
|
2014-07-07 11:15:02 -05:00
|
|
|
|
2016-01-14 18:28:07 -06:00
|
|
|
|
2016-04-17 04:28:06 -05:00
|
|
|
int main(int argc, char **argv)
|
2016-01-14 18:28:07 -06:00
|
|
|
{
|
2016-04-17 04:28:06 -05:00
|
|
|
Dune::MPIHelper::instance(argc, argv);
|
|
|
|
|
|
|
|
if (testAll<Test<double> >(1e-12))
|
2016-01-14 18:28:07 -06:00
|
|
|
return 1;
|
2016-04-17 04:28:06 -05:00
|
|
|
if (testAll<Test<float> >(1e-6))
|
2016-01-14 18:28:07 -06:00
|
|
|
return 1;
|
2016-04-17 04:28:06 -05:00
|
|
|
|
2014-07-07 11:15:02 -05:00
|
|
|
return 0;
|
|
|
|
}
|