]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use TriaObjectsOrientations in connectivity.h. 14662/head
authorDavid Wells <drwells@email.unc.edu>
Tue, 10 Jan 2023 17:25:23 +0000 (12:25 -0500)
committerDavid Wells <drwells@email.unc.edu>
Tue, 10 Jan 2023 17:25:23 +0000 (12:25 -0500)
include/deal.II/grid/connectivity.h
source/grid/tria.cc

index dbbdbe201f17b7d5869c5a8eea7a5f7d961f377c..3be9d0ebc25819775b85052acb993cda031e4c61 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <deal.II/grid/reference_cell.h>
 #include <deal.II/grid/tria_description.h>
+#include <deal.II/grid/tria_objects_orientations.h>
 
 
 DEAL_II_NAMESPACE_OPEN
@@ -827,7 +828,7 @@ namespace internal
         , cell_types(cell_types)
       {}
 
-      inline std::vector<unsigned char> &
+      inline TriaObjectsOrientations &
       entity_orientations(const unsigned int structdim)
       {
         if (structdim == 1)
@@ -838,7 +839,7 @@ namespace internal
         return quad_orientation;
       }
 
-      inline const std::vector<unsigned char> &
+      inline const TriaObjectsOrientations &
       entity_orientations(const unsigned int structdim) const
       {
         if (structdim == 1)
@@ -919,12 +920,12 @@ namespace internal
 
       CRS<T> line_vertices;
 
-      std::vector<unsigned char> line_orientation;
+      TriaObjectsOrientations line_orientation;
 
       CRS<T> quad_vertices;
       CRS<T> quad_lines;
 
-      std::vector<unsigned char> quad_orientation;
+      TriaObjectsOrientations quad_orientation;
 
       CRS<T> cell_entities;
       CRS<T> neighbors;
@@ -1003,7 +1004,7 @@ namespace internal
       const CRS<unsigned int> &                         crs,
       CRS<unsigned int> &                               crs_d,        // result
       CRS<unsigned int> &                               crs_0,        // result
-      std::vector<unsigned char> &                      orientations, // result
+      TriaObjectsOrientations &                         orientations, // result
       const FU &                                        second_key_function)
     {
       const bool compatibility_mode = true;
@@ -1094,7 +1095,7 @@ namespace internal
         }
 
       col_d.resize(keys.size());
-      orientations.resize(keys.size());
+      orientations.reinit(keys.size());
 
       // step 2: sort according to key so that entities with same key can be
       // merged
@@ -1147,7 +1148,7 @@ namespace internal
 
           if (ref_key != std::get<0>(keys[i]))
             {
-              // new key
+              // new key: default orientation is correct
               counter++;
               ref_key     = std::get<0>(keys[i]);
               ref_indices = ad_entity_vertices[offset_i];
@@ -1156,18 +1157,17 @@ namespace internal
               for (const auto j : ad_entity_vertices[offset_i])
                 if (j != 0)
                   col_0.push_back(j - offset);
-
-              // take its orientation as default
-              col_d[offset_i]        = counter;
-              orientations[offset_i] = 1;
             }
           else
             {
-              col_d[offset_i] = counter;
-              orientations[offset_i] =
+              // previously seen key: set orientation relative to the first
+              // occurrence
+              orientations.set_raw_orientation(
+                offset_i,
                 ad_entity_types[offset_i].compute_orientation(
-                  ad_entity_vertices[offset_i], ref_indices);
+                  ad_entity_vertices[offset_i], ref_indices));
             }
+          col_d[offset_i] = counter;
         }
       ptr_0.push_back(col_0.size());
     }
@@ -1186,7 +1186,7 @@ namespace internal
                  const CRS<unsigned int> &                 crs,
                  CRS<unsigned int> &                       crs_d,
                  CRS<unsigned int> &                       crs_0,
-                 std::vector<unsigned char> &              orientations,
+                 TriaObjectsOrientations &                 orientations,
                  const FU &                                second_key_function)
     {
       std::size_t key_length = 0;
@@ -1249,14 +1249,13 @@ namespace internal
       const CRS<unsigned int> &                         con_lv,
       const CRS<unsigned int> &                         con_cq,
       const CRS<unsigned int> &                         con_qv,
-      const std::vector<unsigned char> &                ori_cq,
+      const TriaObjectsOrientations &                   ori_cq,
       CRS<unsigned int> &                               con_ql,   // result
-      std::vector<unsigned char> &                      ori_ql,   // result
+      TriaObjectsOrientations &                         ori_ql,   // result
       std::vector<dealii::ReferenceCell> &              quad_t_id // result
     )
     {
       // reset output
-      ori_ql     = {};
       con_ql.ptr = {};
       con_ql.col = {};
 
@@ -1289,7 +1288,7 @@ namespace internal
 
       // allocate memory
       con_ql.col.resize(con_ql.ptr.back());
-      ori_ql.resize(con_ql.ptr.back());
+      ori_ql.reinit(con_ql.ptr.back());
 
       // loop over cells
       for (unsigned int c = 0; c < con_cq.ptr.size() - 1; ++c)
@@ -1306,7 +1305,7 @@ namespace internal
               const unsigned int f = con_cq.col[f_];
 
               // only faces with default orientation have to do something
-              if (ori_cq[f_] != 1)
+              if (ori_cq.get_raw_orientation(f_) != 1u)
                 continue;
 
               // determine entity type of face
@@ -1338,7 +1337,7 @@ namespace internal
                       }
 
                   // ... comparison gives orientation
-                  ori_ql[con_ql.ptr[f] + l] = (same ? 1 : 0);
+                  ori_ql.set_raw_orientation(con_ql.ptr[f] + l, same ? 1u : 0u);
                 }
             }
         }
@@ -1370,7 +1369,7 @@ namespace internal
 
       if (dim == 2 || dim == 3) // build lines
         {
-          std::vector<unsigned char> dummy;
+          TriaObjectsOrientations dummy;
 
           build_entity(1,
                        cell_t,
index 7fa1766667398f06a7ecf712c1dc2f9fcf76f99b..e61a77c8f65c604be5cfee3a84f5b5ff19af7d71 100644 (file)
@@ -2347,7 +2347,8 @@ namespace internal
 
                     // set line orientations
                     const unsigned char raw_orientation =
-                      connectivity.entity_orientations(1)[k];
+                      connectivity.entity_orientations(1).get_raw_orientation(
+                        k);
                     // it doesn't make sense to set any flags except
                     // orientation for a line
                     Assert(raw_orientation == 0u || raw_orientation == 1u,
@@ -2370,12 +2371,19 @@ namespace internal
 
           // in 2D optional: since in in pure QUAD meshes same line
           // orientations can be guaranteed
-          const bool orientation_needed =
-            dim == 3 ||
-            (dim == 2 &&
-             std::any_of(connectivity.entity_orientations(1).begin(),
-                         connectivity.entity_orientations(1).end(),
-                         [](const auto &i) { return i == 0; }));
+          bool orientation_needed = false;
+          if (dim == 3)
+            orientation_needed = true;
+          else if (dim == 2)
+            {
+              const auto &orientations = connectivity.entity_orientations(1);
+              for (unsigned int i = 0; i < orientations.n_objects(); ++i)
+                if (orientations.get_raw_orientation(i) != 1u)
+                  {
+                    orientation_needed = true;
+                    break;
+                  }
+            }
 
           // allocate memory
           reserve_space_(cells_0, n_cell);
@@ -2412,7 +2420,8 @@ namespace internal
                     {
                       level.face_orientations.set_raw_orientation(
                         cell * GeometryInfo<dim>::faces_per_cell + j,
-                        connectivity.entity_orientations(dim - 1)[i]);
+                        connectivity.entity_orientations(dim - 1)
+                          .get_raw_orientation(i));
                     }
                 }
             }

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.