]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix copying hp::FEValues objects.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 28 Apr 2020 18:17:57 +0000 (12:17 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 30 Apr 2020 14:33:28 +0000 (08:33 -0600)
include/deal.II/hp/fe_values.h
source/hp/fe_values.cc

index 10ffea670633de12ab973537e02e5a4352b868ec..4841d7ad86578ef2ada0ba88170d2f870d282e41 100644 (file)
@@ -87,6 +87,18 @@ namespace hp
       const QCollection<q_dim> &                              q_collection,
       const UpdateFlags                                       update_flags);
 
+    /**
+     * Copy constructor.
+     */
+    FEValuesBase(const FEValuesBase<dim, q_dim, FEValuesType> &other);
+
+    /**
+     * Copy operator. While objects of this type can be copy-constructed,
+     * they cannot be copied and consequently this operator is disabled.
+     */
+    FEValuesBase &
+    operator=(const FEValuesBase &) = delete;
+
     /**
      * For timing purposes it may be useful to create all required FE*Values
      * objects in advance, rather than computing them on request via lazy
@@ -196,7 +208,7 @@ namespace hp
      * Initially, all entries have zero pointers, and we will allocate them
      * lazily as needed in select_fe_values() or precalculate_fe_values().
      */
-    Table<3, std::shared_ptr<FEValuesType>> fe_values_table;
+    Table<3, std::unique_ptr<FEValuesType>> fe_values_table;
 
     /**
      * Set of indices pointing at the fe_values object selected last time
index ff1c635a00d75bc85987931741ebc6b460d059f1..04291740bbe7c42fc5c40abd857628277e04e72d 100644 (file)
@@ -13,6 +13,7 @@
 //
 // ---------------------------------------------------------------------
 
+#include <deal.II/base/std_cxx14/memory.h>
 #include <deal.II/base/thread_management.h>
 
 #include <deal.II/fe/mapping_q1.h>
@@ -64,6 +65,38 @@ namespace hp
 
 
 
+  template <int dim, int q_dim, class FEValuesType>
+  FEValuesBase<dim, q_dim, FEValuesType>::FEValuesBase(
+    const FEValuesBase<dim, q_dim, FEValuesType> &other)
+    : fe_collection(other.fe_collection)
+    , mapping_collection(other.mapping_collection)
+    , q_collection(other.q_collection)
+    , fe_values_table(fe_collection->size(),
+                      mapping_collection->size(),
+                      q_collection.size())
+    , present_fe_values_index(other.present_fe_values_index)
+    , update_flags(other.update_flags)
+  {
+    // We've already resized the `fe_values_table` correctly above, but right
+    // now it just contains nullptrs. Create copies of the objects that
+    // `other.fe_values_table` stores
+    for (unsigned int fe_index = 0; fe_index < fe_collection->size();
+         ++fe_index)
+      for (unsigned int m_index = 0; m_index < mapping_collection->size();
+           ++m_index)
+        for (unsigned int q_index = 0; q_index < q_collection.size(); ++q_index)
+          if (other.fe_values_table[fe_index][m_index][q_index].get() !=
+              nullptr)
+            fe_values_table[fe_index][m_index][q_index] =
+              std_cxx14::make_unique<FEValuesType>(
+                (*mapping_collection)[m_index],
+                (*fe_collection)[fe_index],
+                q_collection[q_index],
+                update_flags);
+  }
+
+
+
   template <int dim, int q_dim, class FEValuesType>
   FEValuesType &
   FEValuesBase<dim, q_dim, FEValuesType>::select_fe_values(
@@ -86,10 +119,11 @@ namespace hp
     // of indices
     if (fe_values_table(present_fe_values_index).get() == nullptr)
       fe_values_table(present_fe_values_index) =
-        std::make_shared<FEValuesType>((*mapping_collection)[mapping_index],
-                                       (*fe_collection)[fe_index],
-                                       q_collection[q_index],
-                                       update_flags);
+        std_cxx14::make_unique<FEValuesType>(
+          (*mapping_collection)[mapping_index],
+          (*fe_collection)[fe_index],
+          q_collection[q_index],
+          update_flags);
 
     // now there definitely is one!
     return *fe_values_table(present_fe_values_index);
@@ -121,7 +155,7 @@ namespace hp
         task_group +=
           Threads::new_task([&, fe_index, mapping_index, q_index]() {
             fe_values_table(TableIndices<3>(fe_index, mapping_index, q_index)) =
-              std::make_shared<FEValuesType>(
+              std_cxx14::make_unique<FEValuesType>(
                 (*mapping_collection)[mapping_index],
                 (*fe_collection)[fe_index],
                 q_collection[q_index],

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.