]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make sure we always generate consistently oriented meshes. 15686/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Sat, 8 Jul 2023 22:50:44 +0000 (16:50 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sun, 9 Jul 2023 01:22:49 +0000 (19:22 -0600)
examples/step-14/step-14.cc
examples/step-19/step-19.cc
examples/step-49/doc/results.dox

index c717830becab0f7b062ec0c833e81d8879ef13b0..5df33680d3da4ed586557f26b7fa6ac8aca03e3d 100644 (file)
@@ -33,6 +33,7 @@
 #include <deal.II/lac/affine_constraints.h>
 #include <deal.II/grid/tria.h>
 #include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
 #include <deal.II/grid/grid_out.h>
 #include <deal.II/grid/grid_refinement.h>
 #include <deal.II/dofs/dof_handler.h>
@@ -1293,10 +1294,23 @@ namespace Step14
         }
 
       // Finally pass all this information to the library to generate a
-      // triangulation. The last parameter may be used to pass information
-      // about non-zero boundary indicators at certain faces of the
-      // triangulation to the library, but we don't want that here, so we give
-      // an empty object:
+      // triangulation. The right call for this is
+      // Triangulation::create_triangulation(), but that function wants
+      // its input in a format in which cells are consistently oriented
+      // in some way. It turns out that the mesh we describe with the
+      // `vertices` and `cells` objects above already is consistently
+      // oriented, but if you modify the code in some way it may not
+      // be any more, and so it is good practice to call a function
+      // that ensures it is -- GridTools::consistently_order_cells()
+      // does this.
+      //
+      // The last parameter of the call to Triangulation::create_triangulation()
+      // below describes what we want to do about boundary and manifold
+      // indicators on boundary faces. Here, we don't want to do anything
+      // specific (in particular, we are fine with labeling all boundaries
+      // with boundary indicator zero, and so we call the function with
+      // an empty object as the last argument:
+      GridTools::consistently_order_cells(cells);
       coarse_grid.create_triangulation(vertices, cells, SubCellData());
 
       // And since we want that the evaluation point (3/4,3/4) in this example
index 8e6f034e425f74093c9aa938f28d1d7edd585457..3a5e062e13dee616480999fa442ecaafff4b75f0 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <deal.II/grid/tria.h>
 #include <deal.II/grid/grid_refinement.h>
+#include <deal.II/grid/grid_tools.h>
 
 #include <deal.II/fe/mapping_q.h>
 #include <deal.II/matrix_free/fe_point_evaluation.h>
@@ -291,7 +292,10 @@ namespace Step19
     //
     // This information is then handed to the
     // Triangulation::create_triangulation() function, and the mesh is twice
-    // globally refined.
+    // globally refined. As discussed in the corresponding place in step-14,
+    // the inputs to Triangulation::create_triangulation() need to be
+    // consistently oriented, which a function in namespace GridTools
+    // does for us.
     std::vector<CellData<dim>> cells((nx - 1) * (ny - 1), CellData<dim>());
     for (unsigned int i = 0; i < cells.size(); ++i)
       {
@@ -299,6 +303,7 @@ namespace Step19
         cells[i].material_id = 0;
       }
 
+    GridTools::consistently_order_cells(cells);
     triangulation.create_triangulation(
       vertices,
       cells,
index e14b2c5dae9a2a88b3c2146a743040a9c97453f0..2bf45946598675c335703f1a1342306992ac6164 100644 (file)
@@ -80,7 +80,7 @@ the techniques previously described:
 
 @code
 // Given a list of points and how vertices connect to cells, create a
-// mesh. This is in the same way as we do in step 14.
+// mesh. This is in the same way as we do in step-14.
 void create_2d_grid(
   const std::vector<Point<2>> &vertices,
   const std::vector<
@@ -95,6 +95,7 @@ void create_2d_grid(
         cells[i].vertices[j] = vertex_indices[i][j];
     }
 
+  GridTools::consistently_order_cells(cells);
   coarse_grid.create_triangulation(vertices, cells, SubCellData());
 }
 

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.