]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Reduce code duplication.
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 10 Jul 2017 14:06:40 +0000 (08:06 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 10 Jul 2017 14:06:40 +0000 (08:06 -0600)
The (hp::)DoFHandler::n_boundary_dofs() functions were specialized for
the 1d case back in the day when faces in 1d were not usable the same
way faces in 2d/3d were accessible via iterators. Because C++ doesn't
allow partial specialization of member functions, the code was also
replicated three times for the <1,1>, <1,2>, and <1,3> cases.

Fix this: We can now always use the generic approach since the necessary
iterators were added several years ago. This also fixes a bug: in <1,2>
and <1,3>, we allow triangulations to have more than 2 end points,
which the existing code was not equipped to deal with.

include/deal.II/dofs/dof_handler.h
include/deal.II/hp/dof_handler.h
source/dofs/dof_handler.cc
source/hp/dof_handler.cc

index ef739291bc691de2c7592c3f3c4fda28142d864b..93edb0cb443f20c0fdd5669d081ba71ddc9d6efd 100644 (file)
@@ -731,18 +731,21 @@ public:
    * Return the number of degrees of freedom located on those parts of the
    * boundary which have a boundary indicator listed in the given set. The
    * reason that a @p map rather than a @p set is used is the same as
-   * described in the section on the @p make_boundary_sparsity_pattern
-   * function.
+   * described in the documentation of that variant of
+   * DoFTools::make_boundary_sparsity_pattern() that takes a map.
+   * To this end, the type of the @p boundary_ids argument is the same
+   * as typename FunctionMap<spacedim,number>::type.
    *
-   * The type of boundary_ids equals typename FunctionMap<spacedim,number>::type .
+   * There is, however, another overload of this function that takes
+   * a @p set argument (see below).
    */
   template <typename number>
   types::global_dof_index
   n_boundary_dofs (const std::map<types::boundary_id, const Function<spacedim,number>*> &boundary_ids) const;
 
   /**
-   * Same function, but with different data type of the argument, which is
-   * here simply a list of the boundary indicators under consideration.
+   * Return the number of degrees of freedom located on those parts of the
+   * boundary which have a boundary indicator listed in the given set. The
    */
   types::global_dof_index
   n_boundary_dofs (const std::set<types::boundary_id> &boundary_ids) const;
@@ -1109,14 +1112,8 @@ private:
 
 
 
-/* -------------- declaration of explicit specializations ------------- */
-
 #ifndef DOXYGEN
 
-template <> types::global_dof_index DoFHandler<1>::n_boundary_dofs () const;
-template <> types::global_dof_index DoFHandler<1>::n_boundary_dofs (const std::set<types::boundary_id> &) const;
-
-
 /* ----------------------- Inline functions ---------------------------------- */
 
 
index fed576c31c8da8f036c9064e4db1a6bd7ef3ec88..81c0e3f40ff337d28146b0fb0041b6222da53404 100644 (file)
@@ -561,18 +561,21 @@ namespace hp
      * Return the number of degrees of freedom located on those parts of the
      * boundary which have a boundary indicator listed in the given set. The
      * reason that a @p map rather than a @p set is used is the same as
-     * described in the section on the @p make_boundary_sparsity_pattern
-     * function.
+     * described in the documentation of that variant of
+     * DoFTools::make_boundary_sparsity_pattern() that takes a map.
+     * To this end, the type of the @p boundary_ids argument is the same
+     * as typename FunctionMap<spacedim,number>::type.
      *
-     * The type of @p boundary_ids equals typename FunctionMap<spacedim,number>::type.
+     * There is, however, another overload of this function that takes
+     * a @p set argument (see below).
      */
     template <typename number>
     types::global_dof_index
     n_boundary_dofs (const std::map<types::boundary_id, const Function<spacedim,number>*> &boundary_ids) const;
 
     /**
-     * Same function, but with different data type of the argument, which is
-     * here simply a list of the boundary indicators under consideration.
+     * Return the number of degrees of freedom located on those parts of the
+     * boundary which have a boundary indicator listed in the given set. The
      */
     types::global_dof_index
     n_boundary_dofs (const std::set<types::boundary_id> &boundary_ids) const;
index 7c3ea27e25be936225c5da2158642b9337361f81..f4555e4eb13fc45b14cacb4b6dfb4bea9613e176 100644 (file)
@@ -887,87 +887,6 @@ DoFHandler<dim, spacedim>::mg_cell_iterators_on_level (const unsigned int level)
 
 
 
-template <>
-types::global_dof_index DoFHandler<1>::n_boundary_dofs () const
-{
-  return 2*get_fe().dofs_per_vertex;
-}
-
-
-
-template <>
-template <typename number>
-types::global_dof_index DoFHandler<1>::n_boundary_dofs (const std::map<types::boundary_id, const Function<1,number>*> &boundary_ids) const
-{
-  // check that only boundary
-  // indicators 0 and 1 are allowed
-  // in 1d
-  for (typename std::map<types::boundary_id, const Function<1,number>*>::const_iterator i=boundary_ids.begin();
-       i!=boundary_ids.end(); ++i)
-    Assert ((i->first == 0) || (i->first == 1),
-            ExcInvalidBoundaryIndicator());
-
-  return boundary_ids.size()*get_fe().dofs_per_vertex;
-}
-
-
-
-template <>
-types::global_dof_index DoFHandler<1>::n_boundary_dofs (const std::set<types::boundary_id> &boundary_ids) const
-{
-  // check that only boundary
-  // indicators 0 and 1 are allowed
-  // in 1d
-  for (std::set<types::boundary_id>::const_iterator i=boundary_ids.begin();
-       i!=boundary_ids.end(); ++i)
-    Assert ((*i == 0) || (*i == 1),
-            ExcInvalidBoundaryIndicator());
-
-  return boundary_ids.size()*get_fe().dofs_per_vertex;
-}
-
-
-template <>
-types::global_dof_index DoFHandler<1,2>::n_boundary_dofs () const
-{
-  return 2*get_fe().dofs_per_vertex;
-}
-
-
-
-template <>
-template <typename number>
-types::global_dof_index DoFHandler<1,2>::n_boundary_dofs (const std::map<types::boundary_id, const Function<2,number>*> &boundary_ids) const
-{
-  // check that only boundary
-  // indicators 0 and 1 are allowed
-  // in 1d
-  for (typename std::map<types::boundary_id, const Function<2,number>*>::const_iterator i=boundary_ids.begin();
-       i!=boundary_ids.end(); ++i)
-    Assert ((i->first == 0) || (i->first == 1),
-            ExcInvalidBoundaryIndicator());
-
-  return boundary_ids.size()*get_fe().dofs_per_vertex;
-}
-
-
-
-template <>
-types::global_dof_index DoFHandler<1,2>::n_boundary_dofs (const std::set<types::boundary_id> &boundary_ids) const
-{
-  // check that only boundary
-  // indicators 0 and 1 are allowed
-  // in 1d
-  for (std::set<types::boundary_id>::const_iterator i=boundary_ids.begin();
-       i!=boundary_ids.end(); ++i)
-    Assert ((*i == 0) || (*i == 1),
-            ExcInvalidBoundaryIndicator());
-
-  return boundary_ids.size()*get_fe().dofs_per_vertex;
-}
-
-
-
 template <int dim, int spacedim>
 types::global_dof_index DoFHandler<dim,spacedim>::n_boundary_dofs () const
 {
index abe9c915bd68bc9172848d9e89b5d1f6247072c7..32fce2a0befa076b26916131b8c7a4617b01c34a 100644 (file)
@@ -1245,154 +1245,6 @@ namespace hp
 //------------------------------------------------------------------
 
 
-  template <>
-  types::global_dof_index DoFHandler<1>::n_boundary_dofs () const
-  {
-    Assert (finite_elements != nullptr, ExcNoFESelected());
-
-    DoFHandler<1,1>::cell_iterator cell;
-    types::global_dof_index n = 0;
-
-    // search left-most cell
-    cell = this->begin_active();
-    while (!cell->at_boundary(0))
-      cell = cell->neighbor(0);
-    n += cell->get_fe().dofs_per_vertex;
-
-    // same with right-most cell
-    cell = this->begin_active();
-    while (!cell->at_boundary(1))
-      cell = cell->neighbor(1);
-    n += cell->get_fe().dofs_per_vertex;
-
-    return n;
-  }
-
-
-
-  template <>
-  template <typename number>
-  types::global_dof_index DoFHandler<1>::n_boundary_dofs (const std::map<types::boundary_id, const Function<1,number>*> &boundary_ids) const
-  {
-    Assert (finite_elements != nullptr, ExcNoFESelected());
-
-    // check that only boundary
-    // indicators 0 and 1 are allowed
-    // in 1d
-    for (typename std::map<types::boundary_id, const Function<1,number>*>::const_iterator i=boundary_ids.begin();
-         i!=boundary_ids.end(); ++i)
-      Assert ((i->first == 0) || (i->first == 1),
-              ExcInvalidBoundaryIndicator());
-
-    DoFHandler<1,1>::active_cell_iterator cell;
-    types::global_dof_index n = 0;
-
-    // search left-most cell
-    if (boundary_ids.find (0) != boundary_ids.end())
-      {
-        cell = this->begin_active();
-        while (!cell->at_boundary(0))
-          cell = cell->neighbor(0);
-        n += cell->get_fe().dofs_per_vertex;
-      }
-
-    // same with right-most cell
-    if (boundary_ids.find (1) != boundary_ids.end())
-      {
-        cell = this->begin_active();
-        while (!cell->at_boundary(1))
-          cell = cell->neighbor(1);
-        n += cell->get_fe().dofs_per_vertex;
-      }
-
-    return n;
-  }
-
-
-
-  template <>
-  types::global_dof_index DoFHandler<1>::n_boundary_dofs (const std::set<types::boundary_id> &boundary_ids) const
-  {
-    Assert (finite_elements != nullptr, ExcNoFESelected());
-
-    // check that only boundary indicators 0 and 1 are allowed in 1d
-    for (std::set<types::boundary_id>::const_iterator i=boundary_ids.begin();
-         i!=boundary_ids.end(); ++i)
-      Assert ((*i == 0) || (*i == 1),
-              ExcInvalidBoundaryIndicator());
-
-    DoFHandler<1,1>::active_cell_iterator cell;
-    types::global_dof_index n = 0;
-
-    // search left-most cell
-    if (boundary_ids.find (0) != boundary_ids.end())
-      {
-        cell = this->begin_active();
-        while (!cell->at_boundary(0))
-          cell = cell->neighbor(0);
-        n += cell->get_fe().dofs_per_vertex;
-      }
-
-    // same with right-most cell
-    if (boundary_ids.find (1) != boundary_ids.end())
-      {
-        cell = this->begin_active();
-        while (!cell->at_boundary(1))
-          cell = cell->neighbor(1);
-        n += cell->get_fe().dofs_per_vertex;
-      }
-
-    return n;
-  }
-
-
-  template <>
-  types::global_dof_index DoFHandler<1,2>::n_boundary_dofs () const
-  {
-    Assert(false,ExcNotImplemented());
-    return 0;
-  }
-
-  template <>
-  template <typename number>
-  types::global_dof_index DoFHandler<1,2>::n_boundary_dofs (const std::map<types::boundary_id, const Function<2,number>*> &) const
-  {
-    Assert(false,ExcNotImplemented());
-    return 0;
-  }
-
-  template <>
-  types::global_dof_index DoFHandler<1,2>::n_boundary_dofs (const std::set<types::boundary_id> &) const
-  {
-    Assert(false,ExcNotImplemented());
-    return 0;
-  }
-
-
-
-  template <>
-  types::global_dof_index DoFHandler<1,3>::n_boundary_dofs () const
-  {
-    Assert(false,ExcNotImplemented());
-    return 0;
-  }
-
-  template <>
-  template <typename number>
-  types::global_dof_index DoFHandler<1,3>::n_boundary_dofs (const std::map<types::boundary_id, const Function<3,number>*> &) const
-  {
-    Assert(false,ExcNotImplemented());
-    return 0;
-  }
-
-  template <>
-  types::global_dof_index DoFHandler<1,3>::n_boundary_dofs (const std::set<types::boundary_id> &) const
-  {
-    Assert(false,ExcNotImplemented());
-    return 0;
-  }
-
-
   template <int dim, int spacedim>
   types::global_dof_index DoFHandler<dim,spacedim>::n_boundary_dofs () const
   {
@@ -1420,7 +1272,7 @@ namespace hp
                                             cell->active_fe_index());
             for (unsigned int i=0; i<dofs_per_face; ++i)
               boundary_dofs.insert(dofs_on_face[i]);
-          };
+          }
     return boundary_dofs.size();
   }
 
@@ -1455,7 +1307,7 @@ namespace hp
                                             cell->active_fe_index());
             for (unsigned int i=0; i<dofs_per_face; ++i)
               boundary_dofs.insert(dofs_on_face[i]);
-          };
+          }
     return boundary_dofs.size();
   }
 

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.