]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add functions to extract subdomain ids for cells as well.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 1 Apr 2004 20:43:31 +0000 (20:43 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 1 Apr 2004 20:43:31 +0000 (20:43 +0000)
git-svn-id: https://svn.dealii.org/trunk@8954 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/grid/grid_tools.h
deal.II/deal.II/source/grid/grid_tools.cc

index 6209d3ac6b8330235aacb56058a0da5fcc645848..52ee05383acfeb80b6fdbc215237c59607708b2f 100644 (file)
@@ -259,6 +259,48 @@ class GridTools
     void partition_triangulation (const unsigned int  n_partitions,
                                   Triangulation<dim> &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
+                                     * <tt>DoFTools::get_subdomain_association</tt>
+                                     * function.
+                                      */
+    template <int dim>
+    static void
+    get_subdomain_association (const Triangulation<dim>  &triangulation,
+                               std::vector<unsigned int> &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
+                                     * <tt>DoFTools::count_dofs_with_subdomain_association</tt>
+                                     * function.
+                                      */
+    template <int dim>
+    static unsigned int
+    count_cells_with_subdomain_association (const Triangulation<dim> &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
                                      */
index 59b6486c6bff0842a098a4f2f116d87f93abac3b..c613b4dbbeeca3a58ac4526fadf9ed8576ae0ff9 100644 (file)
@@ -322,6 +322,46 @@ partition_triangulation (const unsigned int  n_partitions,
 
 
 
+template <int dim>
+void
+GridTools::
+get_subdomain_association (const Triangulation<dim>  &triangulation,
+                           std::vector<unsigned int> &subdomain)
+{
+  Assert (subdomain.size() == triangulation.n_active_cells(),
+          ExcDimensionMismatch (subdomain.size(),
+                                triangulation.n_active_cells()));
+  unsigned int index = 0;
+  for (typename Triangulation<dim>::active_cell_iterator
+         cell = triangulation.begin_active();
+       cell!=triangulation.end(); ++cell, ++index)
+    subdomain[index] = cell->subdomain_id();
+
+  Assert (index == subdomain.size(), ExcInternalError());
+}
+
+
+
+template <int dim>
+unsigned int
+GridTools::
+count_cells_with_subdomain_association (const Triangulation<dim> &triangulation,
+                                        const unsigned int        subdomain)
+{
+  unsigned int count = 0;
+  for (typename Triangulation<dim>::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<deal_II_dimension> &);
+
+template
+void
+GridTools::
+get_subdomain_association (const Triangulation<deal_II_dimension>  &,
+                           std::vector<unsigned int> &);
+
+template
+unsigned int
+GridTools::
+count_cells_with_subdomain_association (const Triangulation<deal_II_dimension> &,
+                                        const unsigned int        );
+

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.