From 470260697452e60f9b4108c39f75a477f0bd1def Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 1 Apr 2004 20:43:31 +0000 Subject: [PATCH] Add functions to extract subdomain ids for cells as well. git-svn-id: https://svn.dealii.org/trunk@8954 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/grid_tools.h | 49 +++++++++++++++++++++ deal.II/deal.II/source/grid/grid_tools.cc | 53 +++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/deal.II/deal.II/include/grid/grid_tools.h b/deal.II/deal.II/include/grid/grid_tools.h index 6209d3ac6b..52ee05383a 100644 --- a/deal.II/deal.II/include/grid/grid_tools.h +++ b/deal.II/deal.II/include/grid/grid_tools.h @@ -259,6 +259,48 @@ class GridTools void partition_triangulation (const unsigned int n_partitions, Triangulation &triangulation); + /** + * For each active cell, return in the + * output array to which subdomain (as + * given by the @p{cell->subdomain_id()} + * function) it belongs. The output array + * is supposed to have the right size + * already when calling this function. + * + * This function returns the association + * of each cell with one subdomain. If + * you are looking for the association of + * each @em DoF with a subdomain, use the + * DoFTools::get_subdomain_association + * function. + */ + template + static void + get_subdomain_association (const Triangulation &triangulation, + std::vector &subdomain); + + /** + * Count how many cells are uniquely + * associated with the given @p subdomain + * index. + * + * This function will generate an + * exception if there are no cells with + * the given @p subdomain index. + * + * This function returns the number of + * cells associated with one + * subdomain. If you are looking for the + * association of @em DoFs with this + * subdomain, use the + * DoFTools::count_dofs_with_subdomain_association + * function. + */ + template + static unsigned int + count_cells_with_subdomain_association (const Triangulation &triangulation, + const unsigned int subdomain); + /** * Exception */ @@ -266,6 +308,13 @@ class GridTools int, << "The number of partitions you gave is " << arg1 << ", but must be greater than zero."); + /** + * Exception + */ + DeclException1 (ExcNonExistentSubdomain, + int, + << "The subdomain id " << arg1 + << " has no cells associated with it."); /** * Exception */ diff --git a/deal.II/deal.II/source/grid/grid_tools.cc b/deal.II/deal.II/source/grid/grid_tools.cc index 59b6486c6b..c613b4dbbe 100644 --- a/deal.II/deal.II/source/grid/grid_tools.cc +++ b/deal.II/deal.II/source/grid/grid_tools.cc @@ -322,6 +322,46 @@ partition_triangulation (const unsigned int n_partitions, +template +void +GridTools:: +get_subdomain_association (const Triangulation &triangulation, + std::vector &subdomain) +{ + Assert (subdomain.size() == triangulation.n_active_cells(), + ExcDimensionMismatch (subdomain.size(), + triangulation.n_active_cells())); + unsigned int index = 0; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell!=triangulation.end(); ++cell, ++index) + subdomain[index] = cell->subdomain_id(); + + Assert (index == subdomain.size(), ExcInternalError()); +} + + + +template +unsigned int +GridTools:: +count_cells_with_subdomain_association (const Triangulation &triangulation, + const unsigned int subdomain) +{ + unsigned int count = 0; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell!=triangulation.end(); ++cell) + if (cell->subdomain_id() == subdomain) + ++count; + + Assert (count != 0, ExcNonExistentSubdomain(subdomain)); + + return count; +} + + + #if deal_II_dimension != 1 template double @@ -355,3 +395,16 @@ template void GridTools::partition_triangulation (const unsigned int, Triangulation &); + +template +void +GridTools:: +get_subdomain_association (const Triangulation &, + std::vector &); + +template +unsigned int +GridTools:: +count_cells_with_subdomain_association (const Triangulation &, + const unsigned int ); + -- 2.39.5