From: Wolfgang Bangerth Date: Mon, 10 Jul 2017 14:06:40 +0000 (-0600) Subject: Reduce code duplication. X-Git-Tag: v9.0.0-rc1~1434^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e01e2b8371e7afb54368997dfcd6c40382826f08;p=dealii.git Reduce code duplication. 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. --- diff --git a/include/deal.II/dofs/dof_handler.h b/include/deal.II/dofs/dof_handler.h index ef739291bc..93edb0cb44 100644 --- a/include/deal.II/dofs/dof_handler.h +++ b/include/deal.II/dofs/dof_handler.h @@ -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::type. * - * The type of boundary_ids equals typename FunctionMap::type . + * There is, however, another overload of this function that takes + * a @p set argument (see below). */ template types::global_dof_index n_boundary_dofs (const std::map*> &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 &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 &) const; - - /* ----------------------- Inline functions ---------------------------------- */ diff --git a/include/deal.II/hp/dof_handler.h b/include/deal.II/hp/dof_handler.h index fed576c31c..81c0e3f40f 100644 --- a/include/deal.II/hp/dof_handler.h +++ b/include/deal.II/hp/dof_handler.h @@ -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::type. * - * The type of @p boundary_ids equals typename FunctionMap::type. + * There is, however, another overload of this function that takes + * a @p set argument (see below). */ template types::global_dof_index n_boundary_dofs (const std::map*> &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 &boundary_ids) const; diff --git a/source/dofs/dof_handler.cc b/source/dofs/dof_handler.cc index 7c3ea27e25..f4555e4eb1 100644 --- a/source/dofs/dof_handler.cc +++ b/source/dofs/dof_handler.cc @@ -887,87 +887,6 @@ DoFHandler::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 -types::global_dof_index DoFHandler<1>::n_boundary_dofs (const std::map*> &boundary_ids) const -{ - // check that only boundary - // indicators 0 and 1 are allowed - // in 1d - for (typename std::map*>::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 &boundary_ids) const -{ - // check that only boundary - // indicators 0 and 1 are allowed - // in 1d - for (std::set::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 -types::global_dof_index DoFHandler<1,2>::n_boundary_dofs (const std::map*> &boundary_ids) const -{ - // check that only boundary - // indicators 0 and 1 are allowed - // in 1d - for (typename std::map*>::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 &boundary_ids) const -{ - // check that only boundary - // indicators 0 and 1 are allowed - // in 1d - for (std::set::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::n_boundary_dofs () const { diff --git a/source/hp/dof_handler.cc b/source/hp/dof_handler.cc index abe9c915bd..32fce2a0be 100644 --- a/source/hp/dof_handler.cc +++ b/source/hp/dof_handler.cc @@ -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 - types::global_dof_index DoFHandler<1>::n_boundary_dofs (const std::map*> &boundary_ids) const - { - Assert (finite_elements != nullptr, ExcNoFESelected()); - - // check that only boundary - // indicators 0 and 1 are allowed - // in 1d - for (typename std::map*>::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 &boundary_ids) const - { - Assert (finite_elements != nullptr, ExcNoFESelected()); - - // check that only boundary indicators 0 and 1 are allowed in 1d - for (std::set::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 - types::global_dof_index DoFHandler<1,2>::n_boundary_dofs (const std::map*> &) const - { - Assert(false,ExcNotImplemented()); - return 0; - } - - template <> - types::global_dof_index DoFHandler<1,2>::n_boundary_dofs (const std::set &) 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 - types::global_dof_index DoFHandler<1,3>::n_boundary_dofs (const std::map*> &) const - { - Assert(false,ExcNotImplemented()); - return 0; - } - - template <> - types::global_dof_index DoFHandler<1,3>::n_boundary_dofs (const std::set &) const - { - Assert(false,ExcNotImplemented()); - return 0; - } - - template types::global_dof_index DoFHandler::n_boundary_dofs () const { @@ -1420,7 +1272,7 @@ namespace hp cell->active_fe_index()); for (unsigned int i=0; iactive_fe_index()); for (unsigned int i=0; i