From: Martin Kronbichler Date: Fri, 10 Apr 2015 09:15:21 +0000 (+0200) Subject: Implement GridTools::get_vertex_connectivity_of_cells X-Git-Tag: v8.3.0-rc1~299^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82c1c61a6cd901d2487e6f4df6bd6aa9cf500e36;p=dealii.git Implement GridTools::get_vertex_connectivity_of_cells --- diff --git a/include/deal.II/grid/grid_tools.h b/include/deal.II/grid/grid_tools.h index 7483bb56f6..c51e06208a 100644 --- a/include/deal.II/grid/grid_tools.h +++ b/include/deal.II/grid/grid_tools.h @@ -585,6 +585,19 @@ namespace GridTools get_face_connectivity_of_cells (const Triangulation &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 + void + get_vertex_connectivity_of_cells (const Triangulation &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 diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index adf7da1a7d..6e0f5b7357 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -1577,6 +1577,34 @@ next_cell: + template + void + get_vertex_connectivity_of_cells (const Triangulation &triangulation, + DynamicSparsityPattern &cell_connectivity) + { + std::vector > vertex_to_cell(triangulation.n_vertices()); + unsigned int index = 0; + for (typename Triangulation::active_cell_iterator cell= + triangulation.begin_active(); cell != triangulation.end(); ++cell, ++index) + { + for (unsigned int v=0; v::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::active_cell_iterator cell= + triangulation.begin_active(); cell != triangulation.end(); ++cell, ++index) + { + for (unsigned int v=0; v::vertices_per_cell; ++v) + for (unsigned int n=0; nvertex_index(v)].size(); ++n) + cell_connectivity.add(index, vertex_to_cell[cell->vertex_index(v)][n]); + } + } + + + template void partition_triangulation (const unsigned int n_partitions, diff --git a/source/grid/grid_tools.inst.in b/source/grid/grid_tools.inst.in index 63f0288e80..8acb27b95c 100644 --- a/source/grid/grid_tools.inst.in +++ b/source/grid/grid_tools.inst.in @@ -168,6 +168,10 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS (const Triangulation &triangulation, SparsityPattern &cell_connectivity); + template + void get_vertex_connectivity_of_cells + (const Triangulation &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 index 0000000000..a5af290fbe --- /dev/null +++ b/tests/grid/vertex_connectivity.cc @@ -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 +#include +#include +#include +#include + + +template +void test() +{ + // First check connectivity of plain mesh + Triangulation 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 index 0000000000..fa5af3a3ea --- /dev/null +++ b/tests/grid/vertex_connectivity.output @@ -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]