From 14c11b1e8034a04d37547d8d0c016a9c95aedf51 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 19 Apr 2021 12:58:32 -0600 Subject: [PATCH] Provide a move constructor for InterpolatedTensorProductGridData. --- include/deal.II/base/function_lib.h | 13 +++++++++++++ source/base/function_lib.cc | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/deal.II/base/function_lib.h b/include/deal.II/base/function_lib.h index 8164606ada..f181ea44f3 100644 --- a/include/deal.II/base/function_lib.h +++ b/include/deal.II/base/function_lib.h @@ -1425,6 +1425,19 @@ namespace Functions const std::array, dim> &coordinate_values, const Table & data_values); + /** + * Like the previous constructor, but take the arguments as rvalue + * references and *move*, instead of *copy* the data. This is often useful + * in cases where the data stored in these tables is large and the + * information used to initialize the current object is no longer needed + * separately. In other words, there is no need to keep the original object + * from which this object could copy its information, but it might as well + * take over ("move") the data. + */ + InterpolatedTensorProductGridData( + std::array, dim> &&coordinate_values, + Table && data_values); + /** * Compute the value of the function set by bilinear interpolation of the * given data set. diff --git a/source/base/function_lib.cc b/source/base/function_lib.cc index 3517aa053d..1a7b8f7674 100644 --- a/source/base/function_lib.cc +++ b/source/base/function_lib.cc @@ -2484,6 +2484,8 @@ namespace Functions } } // namespace + + template InterpolatedTensorProductGridData::InterpolatedTensorProductGridData( const std::array, dim> &coordinate_values, @@ -2511,6 +2513,33 @@ namespace Functions + template + InterpolatedTensorProductGridData::InterpolatedTensorProductGridData( + std::array, dim> &&coordinate_values, + Table && data_values) + : coordinate_values(std::move(coordinate_values)) + , data_values(std::move(data_values)) + { + for (unsigned int d = 0; d < dim; ++d) + { + Assert( + this->coordinate_values[d].size() >= 2, + ExcMessage( + "Coordinate arrays must have at least two coordinate values!")); + for (unsigned int i = 0; i < this->coordinate_values[d].size() - 1; ++i) + Assert( + this->coordinate_values[d][i] < this->coordinate_values[d][i + 1], + ExcMessage( + "Coordinate arrays must be sorted in strictly ascending order.")); + + Assert(this->data_values.size()[d] == this->coordinate_values[d].size(), + ExcMessage( + "Data and coordinate tables do not have the same size.")); + } + } + + + template TableIndices InterpolatedTensorProductGridData::table_index_of_point( -- 2.39.5