]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement GridTools::get_vertex_connectivity_of_cells
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 10 Apr 2015 09:15:21 +0000 (11:15 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Sat, 11 Apr 2015 06:22:14 +0000 (08:22 +0200)
include/deal.II/grid/grid_tools.h
source/grid/grid_tools.cc
source/grid/grid_tools.inst.in
tests/grid/vertex_connectivity.cc [new file with mode: 0644]
tests/grid/vertex_connectivity.output [new file with mode: 0644]

index 7483bb56f6e1c82bbd378a688cfd3d26a4ce334b..c51e06208af8ee32698bb9524d7f03849474e4ee 100644 (file)
@@ -585,6 +585,19 @@ namespace GridTools
   get_face_connectivity_of_cells (const Triangulation<dim, spacedim> &triangulation,
                                   SparsityPattern                    &connectivity) DEAL_II_DEPRECATED;
 
+  /**
+   * Produce a sparsity pattern in which nonzero entries indicate that two
+   * cells are connected via a common vertex. The diagonal entries of the
+   * sparsity pattern are also set.
+   *
+   * The rows and columns refer to the cells as they are traversed in their
+   * natural order using cell iterators.
+   */
+  template <int dim, int spacedim>
+  void
+  get_vertex_connectivity_of_cells (const Triangulation<dim, spacedim> &triangulation,
+                                    DynamicSparsityPattern             &connectivity);
+
   /**
    * Use the METIS partitioner to generate a partitioning of the active cells
    * making up the entire domain. After calling this function, the subdomain
index adf7da1a7dd565d2c1f0d3060db03a966da74e3b..6e0f5b7357f491e99d3c0b09ff96e276e9222768 100644 (file)
@@ -1577,6 +1577,34 @@ next_cell:
 
 
 
+  template <int dim, int spacedim>
+  void
+  get_vertex_connectivity_of_cells (const Triangulation<dim,spacedim> &triangulation,
+                                    DynamicSparsityPattern            &cell_connectivity)
+  {
+    std::vector<std::vector<unsigned int> > vertex_to_cell(triangulation.n_vertices());
+    unsigned int index = 0;
+    for (typename Triangulation<dim,spacedim>::active_cell_iterator cell=
+           triangulation.begin_active(); cell != triangulation.end(); ++cell, ++index)
+      {
+        for (unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
+          vertex_to_cell[cell->vertex_index(v)].push_back(index);
+      }
+
+    cell_connectivity.reinit (triangulation.n_active_cells(),
+                              triangulation.n_active_cells());
+    index = 0;
+    for (typename Triangulation<dim,spacedim>::active_cell_iterator cell=
+           triangulation.begin_active(); cell != triangulation.end(); ++cell, ++index)
+      {
+        for (unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
+          for (unsigned int n=0; n<vertex_to_cell[cell->vertex_index(v)].size(); ++n)
+            cell_connectivity.add(index, vertex_to_cell[cell->vertex_index(v)][n]);
+      }
+  }
+
+
+
   template <int dim, int spacedim>
   void
   partition_triangulation (const unsigned int           n_partitions,
index 63f0288e80ef864a5389ccd6d5402b31ac319d7d..8acb27b95c1b26e9f381d61c17eadbf9cc50a1ee 100644 (file)
@@ -168,6 +168,10 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension :  SPACE_DIMENSIONS
       (const Triangulation<deal_II_dimension, deal_II_space_dimension> &triangulation,
        SparsityPattern          &cell_connectivity);
 
+    template
+      void get_vertex_connectivity_of_cells
+      (const Triangulation<deal_II_dimension, deal_II_space_dimension> &triangulation,
+       DynamicSparsityPattern            &cell_connectivity);
 
     template
       void partition_triangulation (const unsigned int,
diff --git a/tests/grid/vertex_connectivity.cc b/tests/grid/vertex_connectivity.cc
new file mode 100644 (file)
index 0000000..a5af290
--- /dev/null
@@ -0,0 +1,59 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2015 - 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check GridTools::get_vertex_connectivity_of_cells for two different meshes
+
+#include "../tests.h"
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
+
+
+template <int dim>
+void test()
+{
+  // First check connectivity of plain mesh
+  Triangulation<dim> tria;
+  GridGenerator::subdivided_hyper_cube(tria, 3);
+  DynamicSparsityPattern dsp;
+  GridTools::get_vertex_connectivity_of_cells(tria, dsp);
+  dsp.print(deallog.get_file_stream());
+
+  // Refine a few cells and check again
+  tria.begin_active()->set_refine_flag();
+  tria.last()->set_refine_flag();
+  tria.execute_coarsening_and_refinement();
+  GridTools::get_vertex_connectivity_of_cells(tria, dsp);
+  dsp.print(deallog.get_file_stream());
+}
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  test<1>();
+  test<2>();
+  test<3>();
+
+  return 0;
+}
diff --git a/tests/grid/vertex_connectivity.output b/tests/grid/vertex_connectivity.output
new file mode 100644 (file)
index 0000000..fa5af3a
--- /dev/null
@@ -0,0 +1,101 @@
+
+[0,0,1]
+[1,0,1,2]
+[2,1,2]
+[0,0,2,3]
+[1,1,2]
+[2,0,1,2]
+[3,0,3,4]
+[4,3,4]
+[0,0,1,3,4]
+[1,0,1,2,3,4,5]
+[2,1,2,4,5]
+[3,0,1,3,4,6,7]
+[4,0,1,2,3,4,5,6,7,8]
+[5,1,2,4,5,7,8]
+[6,3,4,6,7]
+[7,3,4,5,6,7,8]
+[8,4,5,7,8]
+[0,0,1,2,3,4,8,10]
+[1,0,1,3,4]
+[2,0,2,3,5,6,9,10]
+[3,0,1,2,3,4,5,6,10,11]
+[4,0,1,3,4,6,11,12]
+[5,2,3,5,6]
+[6,2,3,4,5,6,11,13]
+[7,7,8,9,10]
+[8,0,7,8,9,10]
+[9,2,7,8,9,10]
+[10,0,2,3,7,8,9,10]
+[11,3,4,6,11,12,13,14]
+[12,4,11,12,13,14]
+[13,6,11,12,13,14]
+[14,11,12,13,14]
+[0,0,1,3,4,9,10,12,13]
+[1,0,1,2,3,4,5,9,10,11,12,13,14]
+[2,1,2,4,5,10,11,13,14]
+[3,0,1,3,4,6,7,9,10,12,13,15,16]
+[4,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
+[5,1,2,4,5,7,8,10,11,13,14,16,17]
+[6,3,4,6,7,12,13,15,16]
+[7,3,4,5,6,7,8,12,13,14,15,16,17]
+[8,4,5,7,8,13,14,16,17]
+[9,0,1,3,4,9,10,12,13,18,19,21,22]
+[10,0,1,2,3,4,5,9,10,11,12,13,14,18,19,20,21,22,23]
+[11,1,2,4,5,10,11,13,14,19,20,22,23]
+[12,0,1,3,4,6,7,9,10,12,13,15,16,18,19,21,22,24,25]
+[13,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]
+[14,1,2,4,5,7,8,10,11,13,14,16,17,19,20,22,23,25,26]
+[15,3,4,6,7,12,13,15,16,21,22,24,25]
+[16,3,4,5,6,7,8,12,13,14,15,16,17,21,22,23,24,25,26]
+[17,4,5,7,8,13,14,16,17,22,23,25,26]
+[18,9,10,12,13,18,19,21,22]
+[19,9,10,11,12,13,14,18,19,20,21,22,23]
+[20,10,11,13,14,19,20,22,23]
+[21,9,10,12,13,15,16,18,19,21,22,24,25]
+[22,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]
+[23,10,11,13,14,16,17,19,20,22,23,25,26]
+[24,12,13,15,16,21,22,24,25]
+[25,12,13,14,15,16,17,21,22,23,24,25,26]
+[26,13,14,16,17,22,23,25,26]
+[0,0,1,2,3,4,8,9,10,11,12,13,26,28,30,32]
+[1,0,1,3,4,9,10,12,13]
+[2,0,2,3,5,6,8,9,11,12,14,15,27,28,31,32]
+[3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,28,32]
+[4,0,1,3,4,6,7,9,10,12,13,15,16]
+[5,2,3,5,6,11,12,14,15]
+[6,2,3,4,5,6,7,11,12,13,14,15,16]
+[7,3,4,6,7,12,13,15,16]
+[8,0,2,3,8,9,11,12,17,18,20,21,29,30,31,32]
+[9,0,1,2,3,4,8,9,10,11,12,13,17,18,19,20,21,22,30,32]
+[10,0,1,3,4,9,10,12,13,18,19,21,22]
+[11,0,2,3,5,6,8,9,11,12,14,15,17,18,20,21,23,24,31,32]
+[12,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,32,33]
+[13,0,1,3,4,6,7,9,10,12,13,15,16,18,19,21,22,24,33,34]
+[14,2,3,5,6,11,12,14,15,20,21,23,24]
+[15,2,3,4,5,6,7,11,12,13,14,15,16,20,21,22,23,24,33,35]
+[16,3,4,6,7,12,13,15,16,21,22,24,33,34,35,36]
+[17,8,9,11,12,17,18,20,21]
+[18,8,9,10,11,12,13,17,18,19,20,21,22]
+[19,9,10,12,13,18,19,21,22]
+[20,8,9,11,12,14,15,17,18,20,21,23,24]
+[21,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,33,37]
+[22,9,10,12,13,15,16,18,19,21,22,24,33,34,37,38]
+[23,11,12,14,15,20,21,23,24]
+[24,11,12,13,14,15,16,20,21,22,23,24,33,35,37,39]
+[25,25,26,27,28,29,30,31,32]
+[26,0,25,26,27,28,29,30,31,32]
+[27,2,25,26,27,28,29,30,31,32]
+[28,0,2,3,25,26,27,28,29,30,31,32]
+[29,8,25,26,27,28,29,30,31,32]
+[30,0,8,9,25,26,27,28,29,30,31,32]
+[31,2,8,11,25,26,27,28,29,30,31,32]
+[32,0,2,3,8,9,11,12,25,26,27,28,29,30,31,32]
+[33,12,13,15,16,21,22,24,33,34,35,36,37,38,39,40]
+[34,13,16,22,33,34,35,36,37,38,39,40]
+[35,15,16,24,33,34,35,36,37,38,39,40]
+[36,16,33,34,35,36,37,38,39,40]
+[37,21,22,24,33,34,35,36,37,38,39,40]
+[38,22,33,34,35,36,37,38,39,40]
+[39,24,33,34,35,36,37,38,39,40]
+[40,33,34,35,36,37,38,39,40]

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.