From 1415f774d4c19187fc036f9f6f1843cc4e4950bb Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 24 Mar 2004 20:15:44 +0000 Subject: [PATCH] DoFTools::count_dofs_with_subdomain_association. git-svn-id: https://svn.dealii.org/trunk@8864 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/dofs/dof_tools.h | 25 ++++++++++++-- deal.II/deal.II/source/dofs/dof_tools.cc | 44 +++++++++++++++++++++++- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/deal.II/deal.II/include/dofs/dof_tools.h b/deal.II/deal.II/include/dofs/dof_tools.h index 9f0f8a75f8..0fe5070afa 100644 --- a/deal.II/deal.II/include/dofs/dof_tools.h +++ b/deal.II/deal.II/include/dofs/dof_tools.h @@ -805,8 +805,29 @@ class DoFTools static void get_subdomain_association (const DoFHandler &dof_handler, std::vector &subdomain); - - /** + + /** + * Count how many degrees of freedom are + * uniquely associated with the given + * @arg subdomain index. + * + * Note that there may be rare cases + * where cells with the given @arg + * subdomain index exist, but none of its + * degrees of freedom are actually + * associated with it. In that case, the + * returned value will be zero. + * + * This function will generate an + * exception if there are no cells with + * the given @arg subdomain index. + */ + template + static unsigned int + count_dofs_with_subdomain_association (const DoFHandler &dof_handler, + const unsigned int subdomain); + + /** * Count how many degrees of * freedom out of the total * number belong to each diff --git a/deal.II/deal.II/source/dofs/dof_tools.cc b/deal.II/deal.II/source/dofs/dof_tools.cc index f3f04aa07e..f5ffb0e50a 100644 --- a/deal.II/deal.II/source/dofs/dof_tools.cc +++ b/deal.II/deal.II/source/dofs/dof_tools.cc @@ -1715,6 +1715,41 @@ get_subdomain_association (const DoFHandler &dof_handler, +template +unsigned int +DoFTools:: +count_dofs_with_subdomain_association (const DoFHandler &dof_handler, + const unsigned int subdomain) +{ + // in debug mode, make sure that there are + // some cells at least with this subdomain + // id +#ifdef DEBUG + { + bool found = false; + for (typename Triangulation::active_cell_iterator + cell=dof_handler.get_tria().begin_active(); + cell!=dof_handler.get_tria().end(); ++cell) + if (cell->subdomain_id() == subdomain) + { + found = true; + break; + } + Assert (found == true, + ExcMessage ("There are no cells for the given subdomain!")); + } +#endif + + std::vector subdomain_association (dof_handler.n_dofs()); + get_subdomain_association (dof_handler, subdomain_association); + + return std::count (subdomain_association.begin(), + subdomain_association.end(), + subdomain); +} + + + template void DoFTools:: @@ -3038,7 +3073,14 @@ DoFTools::get_subdomain_association (const DoFHandler &dof_handler, std::vector &subdomain_association); - + +template +unsigned int +DoFTools:: +count_dofs_with_subdomain_association (const DoFHandler &, + const unsigned int); + + template void DoFTools::count_dofs_per_component -- 2.39.5