]> https://gitweb.dealii.org/ - dealii.git/commitdiff
MatrixFree: Allow for non-matching number types in constraint handling
authorMatthias Maier <tamiko@43-1.org>
Mon, 28 May 2018 00:44:37 +0000 (19:44 -0500)
committerMatthias Maier <tamiko@43-1.org>
Wed, 6 Jun 2018 15:19:38 +0000 (10:19 -0500)
In order to facilitate an AffineConstraints<float> in the matrix free
framework:

 - templatify internal ConstraintValues::insert_entries to convert from
   compatible number2 types to Number types (aka exclusively 'double').

include/deal.II/matrix_free/dof_info.templates.h
source/matrix_free/matrix_free.inst.in

index 93d9de3a23bcfeebb6d57685bab771c619d79191..2acb55d565174a906cb923ef25dd8d9b67522851 100644 (file)
@@ -61,9 +61,11 @@ namespace internal
        * new_indices, and returns the storage position the double array for
        * access later on.
        */
+      template <typename number2>
       unsigned short
       insert_entries(
-        const std::vector<std::pair<types::global_dof_index, double>> &entries);
+        const std::vector<std::pair<types::global_dof_index, number2>>
+          &entries);
 
       std::vector<std::pair<types::global_dof_index, double>>
                                            constraint_entries;
@@ -83,15 +85,18 @@ namespace internal
     {}
 
     template <typename Number>
+    template <typename number2>
     unsigned short
     ConstraintValues<Number>::insert_entries(
-      const std::vector<std::pair<types::global_dof_index, double>> &entries)
+      const std::vector<std::pair<types::global_dof_index, number2>> &entries)
     {
       next_constraint.first.resize(entries.size());
       if (entries.size() > 0)
         {
           constraint_indices.resize(entries.size());
-          constraint_entries = entries;
+          // Use assign so that values for nonmatching Number / number2 are
+          // converted:
+          constraint_entries.assign(entries.begin(), entries.end());
           std::sort(constraint_entries.begin(),
                     constraint_entries.end(),
                     ConstraintComparator());
@@ -208,8 +213,8 @@ namespace internal
             {
               types::global_dof_index current_dof =
                 local_indices[lexicographic_inv[i]];
-              const std::vector<std::pair<types::global_dof_index, double>>
-                *entries_ptr = constraints.get_constraint_entries(current_dof);
+              const auto *entries_ptr =
+                constraints.get_constraint_entries(current_dof);
 
               // dof is constrained
               if (entries_ptr != nullptr)
@@ -226,8 +231,7 @@ namespace internal
                   // check whether this dof is identity constrained to another
                   // dof. then we can simply insert that dof and there is no
                   // need to actually resolve the constraint entries
-                  const std::vector<std::pair<types::global_dof_index, double>>
-                    &                           entries   = *entries_ptr;
+                  const auto &                  entries   = *entries_ptr;
                   const types::global_dof_index n_entries = entries.size();
                   if (n_entries == 1 &&
                       std::abs(entries[0].second - 1.) <
index 694b7904dfdca36346ad1fe44b73113a51d772be..b7cdcee9761b5325e52fc3e404a79d20175171db 100644 (file)
@@ -34,7 +34,8 @@ for (deal_II_dimension : DIMENSIONS)
     template void MatrixFree<deal_II_dimension, float>::
       print_memory_consumption<ConditionalOStream>(ConditionalOStream &) const;
 
-    template void MatrixFree<deal_II_dimension, double>::internal_reinit<double>(
+    template void
+    MatrixFree<deal_II_dimension, double>::internal_reinit<double>(
       const Mapping<deal_II_dimension> &,
       const std::vector<const DoFHandler<deal_II_dimension> *> &,
       const std::vector<const AffineConstraints<double> *> &,
@@ -42,7 +43,8 @@ for (deal_II_dimension : DIMENSIONS)
       const std::vector<hp::QCollection<1>> &,
       const AdditionalData &);
 
-    template void MatrixFree<deal_II_dimension, double>::internal_reinit<double>(
+    template void
+    MatrixFree<deal_II_dimension, double>::internal_reinit<double>(
       const Mapping<deal_II_dimension> &,
       const std::vector<const hp::DoFHandler<deal_II_dimension> *> &,
       const std::vector<const AffineConstraints<double> *> &,
@@ -66,6 +68,22 @@ for (deal_II_dimension : DIMENSIONS)
       const std::vector<hp::QCollection<1>> &,
       const AdditionalData &);
 
+    template void MatrixFree<deal_II_dimension, float>::internal_reinit<float>(
+      const Mapping<deal_II_dimension> &,
+      const std::vector<const DoFHandler<deal_II_dimension> *> &,
+      const std::vector<const AffineConstraints<float> *> &,
+      const std::vector<IndexSet> &,
+      const std::vector<hp::QCollection<1>> &,
+      const AdditionalData &);
+
+    template void MatrixFree<deal_II_dimension, float>::internal_reinit<float>(
+      const Mapping<deal_II_dimension> &,
+      const std::vector<const hp::DoFHandler<deal_II_dimension> *> &,
+      const std::vector<const AffineConstraints<float> *> &,
+      const std::vector<IndexSet> &,
+      const std::vector<hp::QCollection<1>> &,
+      const AdditionalData &);
+
 #ifndef DEAL_II_MSVC
     template void
     internal::MatrixFreeFunctions::ShapeInfo<double>::reinit<deal_II_dimension>(

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.