--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2013 - 2018 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// Test InterpolatedTensorProductGridData
+//
+// Like the _10 test, but using the move constructor that moves the
+// data from the initializing tables into the
+// InterpolatedTensorProductGridData object.
+
+#include <deal.II/base/function_lib.h>
+
+#include "../tests.h"
+
+// now interpolate the function x*y*z onto points. note that this function is
+// (bi/tri)linear and so we can later know what the correct value is that the
+// function should provide
+Table<1, double>
+fill(const std::array<std::vector<double>, 1> &coordinates)
+{
+ Table<1, double> data(coordinates[0].size());
+ for (unsigned int i = 0; i < coordinates[0].size(); ++i)
+ data[i] = coordinates[0][i];
+ return data;
+}
+
+Table<2, double>
+fill(const std::array<std::vector<double>, 2> &coordinates)
+{
+ Table<2, double> data(coordinates[0].size(), coordinates[1].size());
+ for (unsigned int i = 0; i < coordinates[0].size(); ++i)
+ for (unsigned int j = 0; j < coordinates[1].size(); ++j)
+ data[i][j] = coordinates[0][i] * coordinates[1][j];
+ return data;
+}
+
+Table<3, double>
+fill(const std::array<std::vector<double>, 3> &coordinates)
+{
+ Table<3, double> data(coordinates[0].size(),
+ coordinates[1].size(),
+ coordinates[2].size());
+ for (unsigned int i = 0; i < coordinates[0].size(); ++i)
+ for (unsigned int j = 0; j < coordinates[1].size(); ++j)
+ for (unsigned int k = 0; k < coordinates[2].size(); ++k)
+ data[i][j][k] =
+ coordinates[0][i] * coordinates[1][j] * coordinates[2][k];
+ return data;
+}
+
+
+template <int dim>
+void
+check()
+{
+ // have coordinate arrays that span an interval starting at d+1
+ // d+5 nonuniform intervals
+ std::array<std::vector<double>, dim> coordinates;
+ for (unsigned int d = 0; d < dim; ++d)
+ for (unsigned int i = 0; i < d + 5; ++i)
+ coordinates[d].push_back(d + 1 + 1. * i * i);
+
+ const std::array<std::vector<double>, dim> coordinates_backup = coordinates;
+
+ Table<dim, double> data = fill(coordinates);
+
+ Functions::InterpolatedTensorProductGridData<dim> f(std::move(coordinates),
+ std::move(data));
+
+ // Verify tha the data has really been moved
+ for (unsigned int d = 0; d < dim; ++d)
+ Assert(data.size()[d] == 0, ExcInternalError());
+ for (unsigned int d = 0; d < dim; ++d)
+ Assert(coordinates[d].size() == 0, ExcInternalError());
+
+ // now choose a number of randomly chosen points inside the box and
+ // verify that the function values and gradients returned are correct
+ for (unsigned int i = 0; i < 10; ++i)
+ {
+ Point<dim> p;
+ for (unsigned int d = 0; d < dim; ++d)
+ p[d] = coordinates_backup[d][0] +
+ (random_value<double>()) *
+ (coordinates_backup[d].back() - coordinates_backup[d][0]);
+
+ double exact_value = 1;
+ for (unsigned int d = 0; d < dim; ++d)
+ exact_value *= p[d];
+
+ AssertThrow(std::fabs(exact_value - f.value(p)) < 1e-12,
+ ExcInternalError());
+
+ Tensor<1, dim> exact_gradient;
+ for (unsigned int d = 0; d < dim; ++d)
+ {
+ exact_gradient[d] = 1.0;
+ for (unsigned int k = 0; k < dim; ++k)
+ exact_gradient[d] *= (k == d) ? 1.0 : p[k];
+ }
+
+ AssertThrow((exact_gradient - f.gradient(p)).norm() < 1e-12,
+ ExcInternalError());
+ }
+
+ // now also verify that it computes values outside the box correctly, as
+ // documented
+ double value_at_bottom_left = 1;
+ for (unsigned int d = 0; d < dim; ++d)
+ value_at_bottom_left *= coordinates_backup[d][0];
+
+ AssertThrow(std::fabs(f.value(Point<dim>()) - value_at_bottom_left) < 1e-12,
+ ExcInternalError());
+
+ Point<dim> top_right;
+ double value_at_top_right = 1;
+ for (unsigned int d = 0; d < dim; ++d)
+ {
+ top_right[d] = 1000;
+ value_at_top_right *= coordinates_backup[d].back();
+ }
+ AssertThrow(std::fabs(f.value(top_right) - value_at_top_right) < 1e-12,
+ ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int
+main()
+{
+ initlog();
+
+ check<1>();
+ check<2>();
+ check<3>();
+}