]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce ReferenceCell::compute_orientation and ::permute_according_orientation 11424/head
authorPeter Munch <peterrmuench@gmail.com>
Sun, 27 Dec 2020 07:47:28 +0000 (08:47 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Sun, 27 Dec 2020 07:47:28 +0000 (08:47 +0100)
include/deal.II/grid/connectivity.h
include/deal.II/grid/reference_cell.h
source/base/qprojector.cc

index 47b5912f63d18743e9b9f8e027ae99865eff9ee6..3e422c9a94485779b1cc6850fc21759ebe808613 100644 (file)
@@ -986,107 +986,6 @@ namespace internal
 
 
 
-    /**
-     * Determine the orientation of an entity of @p type described by its
-     * vertices @p var_1 relative to an entity described by @p var_0.
-     */
-    template <typename T, std::size_t N>
-    inline unsigned char
-    compute_orientation(const ReferenceCell::Type entity_type,
-                        const std::array<T, N> &  vertices_0,
-                        const std::array<T, N> &  vertices_1)
-    {
-      if (entity_type == ReferenceCell::Type::Line)
-        {
-          const std::array<T, 2> i{{vertices_0[0], vertices_0[1]}};
-          const std::array<T, 3> j{{vertices_1[0], vertices_1[1]}};
-
-          // line_orientation=true
-          if (i == std::array<T, 2>{{j[0], j[1]}})
-            return 1;
-
-          // line_orientation=false
-          if (i == std::array<T, 2>{{j[1], j[0]}})
-            return 0;
-        }
-      else if (entity_type == ReferenceCell::Type::Tri)
-        {
-          const std::array<T, 3> i{
-            {vertices_0[0], vertices_0[1], vertices_0[2]}};
-          const std::array<T, 3> j{
-            {vertices_1[0], vertices_1[1], vertices_1[2]}};
-
-          // face_orientation=true, face_rotation=false, face_flip=false
-          if (i == std::array<T, 3>{{j[0], j[1], j[2]}})
-            return 1;
-
-          // face_orientation=true, face_rotation=true, face_flip=false
-          if (i == std::array<T, 3>{{j[1], j[0], j[2]}})
-            return 3;
-
-          // face_orientation=true, face_rotation=false, face_flip=true
-          if (i == std::array<T, 3>{{j[2], j[0], j[1]}})
-            return 5;
-
-          // face_orientation=false, face_rotation=false, face_flip=false
-          if (i == std::array<T, 3>{{j[0], j[2], j[1]}})
-            return 0;
-
-          // face_orientation=false, face_rotation=true, face_flip=false
-          if (i == std::array<T, 3>{{j[1], j[2], j[0]}})
-            return 2;
-
-          // face_orientation=false, face_rotation=false, face_flip=true
-          if (i == std::array<T, 3>{{j[2], j[1], j[0]}})
-            return 4;
-        }
-      else if (entity_type == ReferenceCell::Type::Quad)
-        {
-          const std::array<T, 4> i{
-            {vertices_0[0], vertices_0[1], vertices_0[2], vertices_0[3]}};
-          const std::array<T, 4> j{
-            {vertices_1[0], vertices_1[1], vertices_1[2], vertices_1[3]}};
-
-          // face_orientation=true, face_rotation=false, face_flip=false
-          if (i == std::array<T, 4>{{j[0], j[1], j[2], j[3]}})
-            return 1;
-
-          // face_orientation=true, face_rotation=true, face_flip=false
-          if (i == std::array<T, 4>{{j[1], j[3], j[0], j[2]}})
-            return 3;
-
-          // face_orientation=true, face_rotation=false, face_flip=true
-          if (i == std::array<T, 4>{{j[3], j[2], j[1], j[0]}})
-            return 5;
-
-          // face_orientation=true, face_rotation=true, face_flip=true
-          if (i == std::array<T, 4>{{j[2], j[0], j[3], j[1]}})
-            return 7;
-
-          // face_orientation=false, face_rotation=false, face_flip=false
-          if (i == std::array<T, 4>{{j[0], j[2], j[1], j[3]}})
-            return 0;
-
-          // face_orientation=false, face_rotation=true, face_flip=false
-          if (i == std::array<T, 4>{{j[2], j[3], j[0], j[1]}})
-            return 2;
-
-          // face_orientation=false, face_rotation=false, face_flip=true
-          if (i == std::array<T, 4>{{j[3], j[1], j[2], j[0]}})
-            return 4;
-
-          // face_orientation=false, face_rotation=true, face_flip=true
-          if (i == std::array<T, 4>{{j[1], j[0], j[3], j[2]}})
-            return 6;
-        }
-
-      AssertThrow(false, dealii::StandardExceptions::ExcNotImplemented());
-
-      return -1;
-    }
-
-
-
     /**
      * Build entities of dimension d (with 0<d<dim). Entities are described by
      * a set of vertices.
@@ -1263,11 +1162,11 @@ namespace internal
             }
           else
             {
-              col_d[offset_i] = counter;
-              orientations[offset_i] =
-                compute_orientation(ad_entity_types[offset_i],
-                                    ref_indices,
-                                    ad_entity_vertices[offset_i]);
+              col_d[offset_i]        = counter;
+              orientations[offset_i] = ReferenceCell::compute_orientation(
+                ad_entity_types[offset_i],
+                ref_indices,
+                ad_entity_vertices[offset_i]);
             }
         }
       ptr_0.push_back(col_0.size());
index 28a314d2b4700d04775374dfdfb22707bb39559d..cf564890448cfeac77afa44ce8dbcbce9addf335 100644 (file)
@@ -183,6 +183,199 @@ namespace ReferenceCell
     return Point<dim>(+0.0, +0.0, +0.0);
   }
 
+  /**
+   * Determine the orientation of an entity of @p type described by its
+   * vertices @p var_1 relative to an entity described by @p var_0.
+   */
+  template <typename T, std::size_t N>
+  inline unsigned char
+  compute_orientation(const ReferenceCell::Type entity_type,
+                      const std::array<T, N> &  vertices_0,
+                      const std::array<T, N> &  vertices_1)
+  {
+    if (entity_type == ReferenceCell::Type::Line)
+      {
+        const std::array<T, 2> i{{vertices_0[0], vertices_0[1]}};
+        const std::array<T, 2> j{{vertices_1[0], vertices_1[1]}};
+
+        // line_orientation=true
+        if (i == std::array<T, 2>{{j[0], j[1]}})
+          return 1;
+
+        // line_orientation=false
+        if (i == std::array<T, 2>{{j[1], j[0]}})
+          return 0;
+      }
+    else if (entity_type == ReferenceCell::Type::Tri)
+      {
+        const std::array<T, 3> i{{vertices_0[0], vertices_0[1], vertices_0[2]}};
+        const std::array<T, 3> j{{vertices_1[0], vertices_1[1], vertices_1[2]}};
+
+        // face_orientation=true, face_rotation=false, face_flip=false
+        if (i == std::array<T, 3>{{j[0], j[1], j[2]}})
+          return 1;
+
+        // face_orientation=true, face_rotation=true, face_flip=false
+        if (i == std::array<T, 3>{{j[1], j[0], j[2]}})
+          return 3;
+
+        // face_orientation=true, face_rotation=false, face_flip=true
+        if (i == std::array<T, 3>{{j[2], j[0], j[1]}})
+          return 5;
+
+        // face_orientation=false, face_rotation=false, face_flip=false
+        if (i == std::array<T, 3>{{j[0], j[2], j[1]}})
+          return 0;
+
+        // face_orientation=false, face_rotation=true, face_flip=false
+        if (i == std::array<T, 3>{{j[1], j[2], j[0]}})
+          return 2;
+
+        // face_orientation=false, face_rotation=false, face_flip=true
+        if (i == std::array<T, 3>{{j[2], j[1], j[0]}})
+          return 4;
+      }
+    else if (entity_type == ReferenceCell::Type::Quad)
+      {
+        const std::array<T, 4> i{
+          {vertices_0[0], vertices_0[1], vertices_0[2], vertices_0[3]}};
+        const std::array<T, 4> j{
+          {vertices_1[0], vertices_1[1], vertices_1[2], vertices_1[3]}};
+
+        // face_orientation=true, face_rotation=false, face_flip=false
+        if (i == std::array<T, 4>{{j[0], j[1], j[2], j[3]}})
+          return 1;
+
+        // face_orientation=true, face_rotation=true, face_flip=false
+        if (i == std::array<T, 4>{{j[1], j[3], j[0], j[2]}})
+          return 3;
+
+        // face_orientation=true, face_rotation=false, face_flip=true
+        if (i == std::array<T, 4>{{j[3], j[2], j[1], j[0]}})
+          return 5;
+
+        // face_orientation=true, face_rotation=true, face_flip=true
+        if (i == std::array<T, 4>{{j[2], j[0], j[3], j[1]}})
+          return 7;
+
+        // face_orientation=false, face_rotation=false, face_flip=false
+        if (i == std::array<T, 4>{{j[0], j[2], j[1], j[3]}})
+          return 0;
+
+        // face_orientation=false, face_rotation=true, face_flip=false
+        if (i == std::array<T, 4>{{j[2], j[3], j[0], j[1]}})
+          return 2;
+
+        // face_orientation=false, face_rotation=false, face_flip=true
+        if (i == std::array<T, 4>{{j[3], j[1], j[2], j[0]}})
+          return 4;
+
+        // face_orientation=false, face_rotation=true, face_flip=true
+        if (i == std::array<T, 4>{{j[1], j[0], j[3], j[2]}})
+          return 6;
+      }
+
+    AssertThrow(false, dealii::StandardExceptions::ExcNotImplemented());
+
+    return -1;
+  }
+
+  /**
+   * Inverse function of compute_orientation().
+   */
+  template <typename T, std::size_t N>
+  inline std::array<T, N>
+  permute_according_orientation(const ReferenceCell::Type entity_type,
+                                const std::array<T, N> &  vertices,
+                                const unsigned int        orientation)
+  {
+    std::array<T, 4> temp;
+
+    if (entity_type == ReferenceCell::Type::Line)
+      {
+        switch (orientation)
+          {
+            case 1:
+              temp = {{vertices[0], vertices[1]}};
+              break;
+            case 0:
+              temp = {{vertices[1], vertices[0]}};
+              break;
+            default:
+              Assert(false, ExcNotImplemented());
+          }
+      }
+    else if (entity_type == ReferenceCell::Type::Tri)
+      {
+        switch (orientation)
+          {
+            case 1:
+              temp = {{vertices[0], vertices[1], vertices[2]}};
+              break;
+            case 3:
+              temp = {{vertices[1], vertices[0], vertices[2]}};
+              break;
+            case 5:
+              temp = {{vertices[2], vertices[0], vertices[1]}};
+              break;
+            case 0:
+              temp = {{vertices[0], vertices[2], vertices[1]}};
+              break;
+            case 2:
+              temp = {{vertices[1], vertices[2], vertices[0]}};
+              break;
+            case 4:
+              temp = {{vertices[2], vertices[1], vertices[0]}};
+              break;
+            default:
+              Assert(false, ExcNotImplemented());
+          }
+      }
+    else if (entity_type == ReferenceCell::Type::Quad)
+      {
+        switch (orientation)
+          {
+            case 1:
+              temp = {{vertices[0], vertices[1], vertices[2], vertices[3]}};
+              break;
+            case 3:
+              temp = {{vertices[1], vertices[3], vertices[0], vertices[2]}};
+              break;
+            case 5:
+              temp = {{vertices[3], vertices[2], vertices[1], vertices[0]}};
+              break;
+            case 7:
+              temp = {{vertices[2], vertices[0], vertices[3], vertices[1]}};
+              break;
+            case 0:
+              temp = {{vertices[0], vertices[2], vertices[1], vertices[3]}};
+              break;
+            case 2:
+              temp = {{vertices[2], vertices[3], vertices[0], vertices[1]}};
+              break;
+            case 4:
+              temp = {{vertices[3], vertices[1], vertices[2], vertices[0]}};
+              break;
+            case 6:
+              temp = {{vertices[1], vertices[0], vertices[3], vertices[2]}};
+              break;
+            default:
+              Assert(false, ExcNotImplemented());
+          }
+      }
+    else
+      {
+        AssertThrow(false, ExcNotImplemented());
+      }
+
+    std::array<T, N> temp_;
+    std::copy_n(temp.begin(), N, temp_.begin());
+
+    return temp_;
+  }
+
+
+
   namespace internal
   {
     /**
index b0cd657d780b6a9d0512ce5b68a5068eb9eb0f8c..62604c078a5f1538e58bbb107f60b8160a6546b9 100644 (file)
@@ -645,52 +645,26 @@ QProjector<3>::project_to_all_faces(
 {
   const auto support_points_tri =
     [](const auto &face, const auto &orientation) -> std::vector<Point<3>> {
-    // determine support point of the current line with the correct
-    // orientation
-    switch (orientation)
-      {
-        case 1:
-          return {{face.first[0], face.first[1], face.first[2]}};
-        case 3:
-          return {{face.first[1], face.first[0], face.first[2]}};
-        case 5:
-          return {{face.first[2], face.first[0], face.first[1]}};
-        case 0:
-          return {{face.first[0], face.first[2], face.first[1]}};
-        case 2:
-          return {{face.first[1], face.first[2], face.first[0]}};
-        case 4:
-          return {{face.first[2], face.first[1], face.first[0]}};
-        default:
-          Assert(false, ExcNotImplemented());
-          return {{}};
-      }
+    std::array<Point<3>, 3> vertices;
+    std::copy_n(face.first.begin(), face.first.size(), vertices.begin());
+    const auto temp =
+      ReferenceCell::permute_according_orientation(ReferenceCell::Type::Tri,
+                                                   vertices,
+                                                   orientation);
+    return std::vector<Point<3>>(temp.begin(),
+                                 temp.begin() + face.first.size());
   };
 
   const auto support_points_quad =
     [](const auto &face, const auto &orientation) -> std::vector<Point<3>> {
-    switch (orientation)
-      {
-        case 1:
-          return {{face.first[0], face.first[1], face.first[2], face.first[3]}};
-        case 3:
-          return {{face.first[1], face.first[3], face.first[0], face.first[2]}};
-        case 5:
-          return {{face.first[3], face.first[2], face.first[1], face.first[0]}};
-        case 7:
-          return {{face.first[2], face.first[0], face.first[3], face.first[1]}};
-        case 0:
-          return {{face.first[0], face.first[2], face.first[1], face.first[3]}};
-        case 2:
-          return {{face.first[2], face.first[3], face.first[0], face.first[1]}};
-        case 4:
-          return {{face.first[3], face.first[1], face.first[2], face.first[0]}};
-        case 6:
-          return {{face.first[1], face.first[0], face.first[3], face.first[2]}};
-        default:
-          Assert(false, ExcNotImplemented());
-          return {{}};
-      }
+    std::array<Point<3>, 4> vertices;
+    std::copy_n(face.first.begin(), face.first.size(), vertices.begin());
+    const auto temp =
+      ReferenceCell::permute_according_orientation(ReferenceCell::Type::Quad,
+                                                   vertices,
+                                                   orientation);
+    return std::vector<Point<3>>(temp.begin(),
+                                 temp.begin() + face.first.size());
   };
 
   const auto process = [&](const auto faces) {

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.