]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Provide a move constructor for Functions::InterpolatedUniformGridData.
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 19 Apr 2021 21:16:14 +0000 (15:16 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 26 Apr 2021 01:05:21 +0000 (19:05 -0600)
include/deal.II/base/function_lib.h
source/base/function_lib.cc

index f181ea44f3dc68a35a8345e69caf5e26b345184b..a48ec6dcbbd748bca314afe469c584b54ccde2cd 100644 (file)
@@ -1555,6 +1555,20 @@ namespace Functions
       const std::array<unsigned int, dim> &             n_subintervals,
       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.
+     */
+    InterpolatedUniformGridData(
+      std::array<std::pair<double, double>, dim> &&interval_endpoints,
+      std::array<unsigned int, dim> &&             n_subintervals,
+      Table<dim, double> &&                        data_values);
+
     /**
      * Compute the value of the function set by bilinear interpolation of the
      * given data set.
index 1a7b8f7674d23d4e07c607023ab152c6b46175c8..1ef60b8eeda148ae8a20a2ffbb5b90e535d86d65 100644 (file)
@@ -2683,6 +2683,32 @@ namespace Functions
   }
 
 
+
+  template <int dim>
+  InterpolatedUniformGridData<dim>::InterpolatedUniformGridData(
+    std::array<std::pair<double, double>, dim> &&interval_endpoints,
+    std::array<unsigned int, dim> &&             n_subintervals,
+    Table<dim, double> &&                        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 <int dim>
   double
   InterpolatedUniformGridData<dim>::value(const Point<dim> & p,

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.