]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make CellData look like our usual style.
authorWolfgang Bangerth <bangerth@colostate.edu>
Sun, 9 Jan 2022 17:35:47 +0000 (10:35 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sun, 9 Jan 2022 18:57:27 +0000 (11:57 -0700)
include/deal.II/fe/fe_tools_extrapolate.templates.h

index 18617b8facd2dc9a4cc5af9c61748b5ba7a6a641..d6b7fb68d7f8d7116d5860110d91170696c626da 100644 (file)
@@ -99,92 +99,54 @@ namespace FETools
       };
 
 
-      // A structure holding all data
-      // of cells needed from other processes
-      // for the extrapolate algorithm.
+      /**
+       * A structure holding all data of cells needed from other processes
+       * for the extrapolate algorithm.
+       */
       struct CellData
       {
+        /**
+         * Default constructor.
+         */
         CellData();
 
+        /**
+         * Constructor setting the `dof_values` member to the right size.
+         */
         CellData(const unsigned int dofs_per_cell);
 
-        Vector<value_type> dof_values;
-
-        unsigned int tree_index;
-
-        typename dealii::internal::p4est::types<dim>::quadrant quadrant;
-
-        int receiver;
-
+        /**
+         * Comparison operator.
+         */
         bool
-        operator<(const CellData &rhs) const
-        {
-          if (dealii::internal::p4est::functions<dim>::quadrant_compare(
-                &quadrant, &rhs.quadrant) < 0)
-            return true;
-
-          return false;
-        }
-
-        unsigned int
-        bytes_for_buffer() const
-        {
-          return (sizeof(unsigned int) +                   // dofs_per_cell
-                  dof_values.size() * sizeof(value_type) + // dof_values
-                  sizeof(unsigned int) +                   // tree_index
-                  sizeof(typename dealii::internal::p4est::types<
-                         dim>::quadrant)); // quadrant
-        }
+        operator<(const CellData &rhs) const;
 
+        /**
+         * Pack the data of this object into a char[] buffer.
+         */
         void
-        pack_data(std::vector<char> &buffer) const
-        {
-          buffer.resize(bytes_for_buffer());
-
-          char *ptr = buffer.data();
-
-          unsigned int n_dofs = dof_values.size();
-          std::memcpy(ptr, &n_dofs, sizeof(unsigned int));
-          ptr += sizeof(unsigned int);
-
-          std::memcpy(ptr, dof_values.begin(), n_dofs * sizeof(value_type));
-          ptr += n_dofs * sizeof(value_type);
-
-          std::memcpy(ptr, &tree_index, sizeof(unsigned int));
-          ptr += sizeof(unsigned int);
-
-          std::memcpy(
-            ptr,
-            &quadrant,
-            sizeof(typename dealii::internal::p4est::types<dim>::quadrant));
-          ptr += sizeof(typename dealii::internal::p4est::types<dim>::quadrant);
-
-          Assert(ptr == buffer.data() + buffer.size(), ExcInternalError());
-        }
+        pack_data(std::vector<char> &buffer) const;
 
+        /**
+         * Unpack the data of the given buffer into the members of this object.
+         */
         void
-        unpack_data(const std::vector<char> &buffer)
-        {
-          const char * ptr = buffer.data();
-          unsigned int n_dofs;
-          memcpy(&n_dofs, ptr, sizeof(unsigned int));
-          ptr += sizeof(unsigned int);
+        unpack_data(const std::vector<char> &buffer);
 
-          dof_values.reinit(n_dofs);
-          std::memcpy(dof_values.begin(), ptr, n_dofs * sizeof(value_type));
-          ptr += n_dofs * sizeof(value_type);
 
-          std::memcpy(&tree_index, ptr, sizeof(unsigned int));
-          ptr += sizeof(unsigned int);
+        /**
+         * The values of degrees of freedom associated with the current cell.
+         */
+        Vector<value_type> dof_values;
 
-          std::memcpy(
-            &quadrant,
-            ptr,
-            sizeof(typename dealii::internal::p4est::types<dim>::quadrant));
-          ptr += sizeof(typename dealii::internal::p4est::types<dim>::quadrant);
+        /**
+         * The tree within the forest (i.e., the coarse cell) and which of its
+         * descendents we are currently working on.
+         */
+        unsigned int                                           tree_index;
+        typename dealii::internal::p4est::types<dim>::quadrant quadrant;
 
-          Assert(ptr == buffer.data() + buffer.size(), ExcInternalError());
-        }
+        int receiver;
       };
 
       // Problem: The function extrapolates a polynomial
@@ -400,6 +362,8 @@ namespace FETools
       unsigned int round;
     };
 
+
+
     template <class OutVector>
     class ExtrapolateImplementation<1, 1, OutVector>
     {
@@ -472,10 +436,90 @@ namespace FETools
     template <int dim, int spacedim, class OutVector>
     ExtrapolateImplementation<dim, spacedim, OutVector>::CellData::CellData(
       const unsigned int dofs_per_cell)
-      : tree_index(0)
+      : dof_values(dofs_per_cell)
+      , tree_index(0)
       , receiver(0)
+    {}
+
+
+
+    template <int dim, int spacedim, class OutVector>
+    bool
+    ExtrapolateImplementation<dim, spacedim, OutVector>::CellData::operator<(
+      const CellData &rhs) const
+    {
+      if (dealii::internal::p4est::functions<dim>::quadrant_compare(
+            &quadrant, &rhs.quadrant) < 0)
+        return true;
+
+      return false;
+    }
+
+
+
+    template <int dim, int spacedim, class OutVector>
+    void
+    ExtrapolateImplementation<dim, spacedim, OutVector>::CellData::pack_data(
+      std::vector<char> &buffer) const
+    {
+      // Compute how much memory we need to pack the data of this
+      // structure into a char[] buffer.
+      const unsigned int bytes_for_buffer =
+        (sizeof(unsigned int) +                   // dofs_per_cell
+         dof_values.size() * sizeof(value_type) + // dof_values
+         sizeof(unsigned int) +                   // tree_index
+         sizeof(
+           typename dealii::internal::p4est::types<dim>::quadrant)); // quadrant
+
+      buffer.resize(bytes_for_buffer);
+
+      char *ptr = buffer.data();
+
+      unsigned int n_dofs = dof_values.size();
+      std::memcpy(ptr, &n_dofs, sizeof(unsigned int));
+      ptr += sizeof(unsigned int);
+
+      std::memcpy(ptr, dof_values.begin(), n_dofs * sizeof(value_type));
+      ptr += n_dofs * sizeof(value_type);
+
+      std::memcpy(ptr, &tree_index, sizeof(unsigned int));
+      ptr += sizeof(unsigned int);
+
+      std::memcpy(ptr,
+                  &quadrant,
+                  sizeof(
+                    typename dealii::internal::p4est::types<dim>::quadrant));
+      ptr += sizeof(typename dealii::internal::p4est::types<dim>::quadrant);
+
+      Assert(ptr == buffer.data() + buffer.size(), ExcInternalError());
+    }
+
+
+
+    template <int dim, int spacedim, class OutVector>
+    void
+    ExtrapolateImplementation<dim, spacedim, OutVector>::CellData::unpack_data(
+      const std::vector<char> &buffer)
     {
-      dof_values.reinit(dofs_per_cell);
+      const char * ptr = buffer.data();
+      unsigned int n_dofs;
+      memcpy(&n_dofs, ptr, sizeof(unsigned int));
+      ptr += sizeof(unsigned int);
+
+      dof_values.reinit(n_dofs);
+      std::memcpy(dof_values.begin(), ptr, n_dofs * sizeof(value_type));
+      ptr += n_dofs * sizeof(value_type);
+
+      std::memcpy(&tree_index, ptr, sizeof(unsigned int));
+      ptr += sizeof(unsigned int);
+
+      std::memcpy(&quadrant,
+                  ptr,
+                  sizeof(
+                    typename dealii::internal::p4est::types<dim>::quadrant));
+      ptr += sizeof(typename dealii::internal::p4est::types<dim>::quadrant);
+
+      Assert(ptr == buffer.data() + buffer.size(), ExcInternalError());
     }
 
 

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.