]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Provide a move constructor for InterpolatedTensorProductGridData.
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 19 Apr 2021 18:58:32 +0000 (12:58 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 19 Apr 2021 18:58:32 +0000 (12:58 -0600)
include/deal.II/base/function_lib.h
source/base/function_lib.cc

index 8164606ada8f5a614bba3ca5deadc1a35cd53cb9..f181ea44f3dc68a35a8345e69caf5e26b345184b 100644 (file)
@@ -1425,6 +1425,19 @@ namespace Functions
       const std::array<std::vector<double>, dim> &coordinate_values,
       const Table<dim, double> &                  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<std::vector<double>, dim> &&coordinate_values,
+      Table<dim, double> &&                  data_values);
+
     /**
      * Compute the value of the function set by bilinear interpolation of the
      * given data set.
index 3517aa053d247e2584d299c66186bcfc04d5e848..1a7b8f7674d23d4e07c607023ab152c6b46175c8 100644 (file)
@@ -2484,6 +2484,8 @@ namespace Functions
     }
   } // namespace
 
+
+
   template <int dim>
   InterpolatedTensorProductGridData<dim>::InterpolatedTensorProductGridData(
     const std::array<std::vector<double>, dim> &coordinate_values,
@@ -2511,6 +2513,33 @@ namespace Functions
 
 
 
+  template <int dim>
+  InterpolatedTensorProductGridData<dim>::InterpolatedTensorProductGridData(
+    std::array<std::vector<double>, dim> &&coordinate_values,
+    Table<dim, double> &&                  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 <int dim>
   TableIndices<dim>
   InterpolatedTensorProductGridData<dim>::table_index_of_point(

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.