]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Restructure includes of FloatingPointComparator 14312/head
authorMartin Kronbichler <martin.kronbichler@uni-a.de>
Mon, 26 Sep 2022 10:04:27 +0000 (12:04 +0200)
committerMartin Kronbichler <martin.kronbichler@uni-a.de>
Mon, 26 Sep 2022 10:04:27 +0000 (12:04 +0200)
include/deal.II/matrix_free/constraint_info.h
include/deal.II/matrix_free/dof_info.h
include/deal.II/matrix_free/dof_info.templates.h
include/deal.II/matrix_free/mapping_info.templates.h
include/deal.II/matrix_free/matrix_free.templates.h
source/matrix_free/dof_info.cc

index 91c735c36f7cbae6391930bc8e1b15ead8fb5f58..b11e18aeb4057f3582c08c16da95b975cd6c57e2 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <deal.II/base/config.h>
 
+#include <deal.II/base/floating_point_comparator.h>
+
 #include <deal.II/matrix_free/dof_info.h>
 #include <deal.II/matrix_free/evaluation_template_factory.h>
 #include <deal.II/matrix_free/hanging_nodes_internal.h>
@@ -33,6 +35,41 @@ namespace internal
 {
   namespace MatrixFreeFunctions
   {
+    /**
+     * A struct that takes entries describing a constraint and puts them into
+     * a sorted list where duplicates are filtered out
+     */
+    template <typename Number>
+    struct ConstraintValues
+    {
+      ConstraintValues();
+
+      /**
+       * This function inserts some constrained entries to the collection of
+       * all values. It stores the (reordered) numbering of the dofs
+       * (according to the ordering that matches with the function) in
+       * 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, number2>>
+          &entries);
+
+      std::vector<std::pair<types::global_dof_index, double>>
+                                           constraint_entries;
+      std::vector<types::global_dof_index> constraint_indices;
+
+      std::pair<std::vector<Number>, types::global_dof_index> next_constraint;
+      std::map<std::vector<Number>,
+               types::global_dof_index,
+               FloatingPointComparator<Number>>
+        constraints;
+    };
+
+
+
     /**
      * A helper class to apply constraints in matrix-free loops in
      * user code. It combines constraint related functionalties from
@@ -131,6 +168,73 @@ namespace internal
 
 
 
+    // ------------------------- inline functions --------------------------
+
+    template <typename Number>
+    ConstraintValues<Number>::ConstraintValues()
+      : constraints(FloatingPointComparator<Number>(
+          1. * std::numeric_limits<double>::epsilon() * 1024.))
+    {}
+
+
+
+    template <typename Number>
+    template <typename number2>
+    unsigned short
+    ConstraintValues<Number>::insert_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());
+          // 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(),
+                    [](const std::pair<types::global_dof_index, double> &p1,
+                       const std::pair<types::global_dof_index, double> &p2) {
+                      return p1.second < p2.second;
+                    });
+          for (types::global_dof_index j = 0; j < constraint_entries.size();
+               j++)
+            {
+              // copy the indices of the constraint entries after sorting.
+              constraint_indices[j] = constraint_entries[j].first;
+
+              // one_constraint takes the weights of the constraint
+              next_constraint.first[j] = constraint_entries[j].second;
+            }
+        }
+
+      // check whether or not constraint is already in pool. the initial
+      // implementation computed a hash value based on the truncated array (to
+      // given accuracy around 1e-13) in order to easily detect different
+      // arrays and then made a fine-grained check when the hash values were
+      // equal. this was quite lengthy and now we use a std::map with a
+      // user-defined comparator to compare floating point arrays to a
+      // tolerance 1e-13.
+      types::global_dof_index insert_position = numbers::invalid_dof_index;
+      const auto position = constraints.find(next_constraint.first);
+      if (position != constraints.end())
+        insert_position = position->second;
+      else
+        {
+          next_constraint.second = constraints.size();
+          constraints.insert(next_constraint);
+          insert_position = next_constraint.second;
+        }
+
+      // we want to store the result as a short variable, so we have to make
+      // sure that the result does not exceed the limits when casting.
+      Assert(insert_position < (1 << (8 * sizeof(unsigned short))),
+             ExcInternalError());
+      return static_cast<unsigned short>(insert_position);
+    }
+
+
+
     template <int dim, typename Number>
     inline void
     ConstraintInfo<dim, Number>::reinit(
index f60288cff093af614f179ebd0741496738e1a651..1e45a1bac8095f683c7171b210dc16bab0d58c31 100644 (file)
@@ -21,7 +21,6 @@
 #include <deal.II/base/config.h>
 
 #include <deal.II/base/exceptions.h>
-#include <deal.II/base/floating_point_comparator.h>
 #include <deal.II/base/vectorization.h>
 
 #include <deal.II/matrix_free/face_info.h>
@@ -46,6 +45,9 @@ namespace internal
     class HangingNodes;
 
     struct TaskInfo;
+
+    template <typename Number>
+    struct ConstraintValues;
   } // namespace MatrixFreeFunctions
 } // namespace internal
 
@@ -80,39 +82,6 @@ namespace internal
      */
     using compressed_constraint_kind = std::uint8_t;
 
-    /**
-     * A struct that takes entries describing a constraint and puts them into
-     * a sorted list where duplicates are filtered out
-     */
-    template <typename Number>
-    struct ConstraintValues
-    {
-      ConstraintValues();
-
-      /**
-       * This function inserts some constrained entries to the collection of
-       * all values. It stores the (reordered) numbering of the dofs
-       * (according to the ordering that matches with the function) in
-       * 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, number2>>
-          &entries);
-
-      std::vector<std::pair<types::global_dof_index, double>>
-                                           constraint_entries;
-      std::vector<types::global_dof_index> constraint_indices;
-
-      std::pair<std::vector<Number>, types::global_dof_index> next_constraint;
-      std::map<std::vector<Number>,
-               types::global_dof_index,
-               FloatingPointComparator<VectorizedArray<Number>>>
-        constraints;
-    };
-
     /**
      * The class that stores the indices of the degrees of freedom for all the
      * cells. Essentially, this is a smart number cache in the style of a
index 7acb48b8b9e61dd591da89e1e06269875a3356d7..d3f84e0cdbfc948b5fdd69362a124c0d58e85772 100644 (file)
@@ -27,6 +27,7 @@
 #include <deal.II/lac/dynamic_sparsity_pattern.h>
 #include <deal.II/lac/sparsity_pattern.h>
 
+#include <deal.II/matrix_free/constraint_info.h>
 #include <deal.II/matrix_free/dof_info.h>
 #include <deal.II/matrix_free/hanging_nodes_internal.h>
 #include <deal.II/matrix_free/task_info.h>
@@ -39,73 +40,6 @@ namespace internal
 {
   namespace MatrixFreeFunctions
   {
-    template <typename Number>
-    ConstraintValues<Number>::ConstraintValues()
-      : constraints(FloatingPointComparator<VectorizedArray<Number>>(
-          1. * std::numeric_limits<double>::epsilon() * 1024.))
-    {}
-
-
-
-    template <typename Number>
-    template <typename number2>
-    unsigned short
-    ConstraintValues<Number>::insert_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());
-          // 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(),
-                    [](const std::pair<types::global_dof_index, double> &p1,
-                       const std::pair<types::global_dof_index, double> &p2) {
-                      return p1.second < p2.second;
-                    });
-          for (types::global_dof_index j = 0; j < constraint_entries.size();
-               j++)
-            {
-              // copy the indices of the constraint entries after sorting.
-              constraint_indices[j] = constraint_entries[j].first;
-
-              // one_constraint takes the weights of the constraint
-              next_constraint.first[j] = constraint_entries[j].second;
-            }
-        }
-
-      // check whether or not constraint is already in pool. the initial
-      // implementation computed a hash value based on the truncated array (to
-      // given accuracy around 1e-13) in order to easily detect different
-      // arrays and then made a fine-grained check when the hash values were
-      // equal. this was quite lengthy and now we use a std::map with a
-      // user-defined comparator to compare floating point arrays to a
-      // tolerance 1e-13.
-      types::global_dof_index insert_position = numbers::invalid_dof_index;
-      const auto position = constraints.find(next_constraint.first);
-      if (position != constraints.end())
-        insert_position = position->second;
-      else
-        {
-          next_constraint.second = constraints.size();
-          constraints.insert(next_constraint);
-          insert_position = next_constraint.second;
-        }
-
-      // we want to store the result as a short variable, so we have to make
-      // sure that the result does not exceed the limits when casting.
-      Assert(insert_position < (1 << (8 * sizeof(unsigned short))),
-             ExcInternalError());
-      return static_cast<unsigned short>(insert_position);
-    }
-
-
-
-    // ----------------- actual DoFInfo functions -----------------------------
-
     template <typename number>
     void
     DoFInfo::read_dof_indices(
index bb584128e9855cd5f467c9d3a885403ec479fc5b..62ffd3e98f32f8c173287ee5c9c0e3f812544ea6 100644 (file)
@@ -1081,8 +1081,8 @@ namespace internal
         // evaluation
         std::map<std::array<Tensor<2, dim>, dim + 1>,
                  unsigned int,
-                 FloatingPointComparator<VectorizedArray<double>>>
-          compressed_jacobians(FloatingPointComparator<VectorizedArray<double>>(
+                 FloatingPointComparator<double>>
+          compressed_jacobians(FloatingPointComparator<double>(
             1e4 * jacobian_size * std::numeric_limits<double>::epsilon() *
             1024.));
 
index 1b43fc4d036bdbe59d06a44a393573660044e90b..f5c1baf106cb522cb2b05bcdf46d55c9328f2a1e 100644 (file)
@@ -40,6 +40,7 @@
 
 #include <deal.II/lac/dynamic_sparsity_pattern.h>
 
+#include <deal.II/matrix_free/constraint_info.h>
 #include <deal.II/matrix_free/face_info.h>
 #include <deal.II/matrix_free/face_setup_internal.h>
 #include <deal.II/matrix_free/hanging_nodes_internal.h>
index 6fe7abaebd15ae21fb458ba4fbf44789f33dbcb8..7ba077ef9e980387d3e16f57b9d63749e222c816 100644 (file)
@@ -1543,16 +1543,6 @@ namespace internal
 {
   namespace MatrixFreeFunctions
   {
-    template struct ConstraintValues<double>;
-
-    template unsigned short
-    ConstraintValues<double>::insert_entries(
-      const std::vector<std::pair<types::global_dof_index, float>> &);
-    template unsigned short
-    ConstraintValues<double>::insert_entries(
-      const std::vector<std::pair<types::global_dof_index, double>> &);
-
-
     template void
     DoFInfo::read_dof_indices<double>(
       const std::vector<types::global_dof_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.