From c15cd74361e0b068544611417ee05b414f164f05 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 19 Apr 2021 15:16:14 -0600 Subject: [PATCH] Provide a move constructor for Functions::InterpolatedUniformGridData. --- include/deal.II/base/function_lib.h | 14 ++++++++++++++ source/base/function_lib.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/deal.II/base/function_lib.h b/include/deal.II/base/function_lib.h index f181ea44f3..a48ec6dcbb 100644 --- a/include/deal.II/base/function_lib.h +++ b/include/deal.II/base/function_lib.h @@ -1555,6 +1555,20 @@ namespace Functions const std::array & n_subintervals, 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. + */ + InterpolatedUniformGridData( + std::array, dim> &&interval_endpoints, + std::array && n_subintervals, + 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 1a7b8f7674..1ef60b8eed 100644 --- a/source/base/function_lib.cc +++ b/source/base/function_lib.cc @@ -2683,6 +2683,32 @@ namespace Functions } + + template + InterpolatedUniformGridData::InterpolatedUniformGridData( + std::array, dim> &&interval_endpoints, + std::array && n_subintervals, + Table && data_values) + : interval_endpoints(std::move(interval_endpoints)) + , n_subintervals(std::move(n_subintervals)) + , data_values(std::move(data_values)) + { + for (unsigned int d = 0; d < dim; ++d) + { + Assert(this->n_subintervals[d] >= 1, + ExcMessage("There needs to be at least one subinterval in each " + "coordinate direction.")); + Assert(this->interval_endpoints[d].first < + this->interval_endpoints[d].second, + ExcMessage("The interval in each coordinate direction needs " + "to have positive size")); + Assert(this->data_values.size()[d] == this->n_subintervals[d] + 1, + ExcMessage("The data table does not have the correct size.")); + } + } + + + template double InterpolatedUniformGridData::value(const Point & p, -- 2.39.5