From 85bb201a30f714d65e9ac4bec1229c75b7b4e22b Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 20 Jul 2016 11:07:17 +0200 Subject: [PATCH] Use std::set for boundary_indicators and rename set_zero_boundary_dofs --- doc/news/changes.h | 7 +- .../deal.II/multigrid/mg_constrained_dofs.h | 32 ++++++--- include/deal.II/multigrid/mg_tools.h | 14 +++- source/multigrid/mg_tools.cc | 67 +++++-------------- source/multigrid/mg_tools.inst.in | 8 +-- tests/multigrid/constrained_dofs_03.cc | 8 ++- 6 files changed, 62 insertions(+), 74 deletions(-) diff --git a/doc/news/changes.h b/doc/news/changes.h index df133e88fc..bc3106010e 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -360,9 +360,10 @@ inconvenience this causes.

Specific improvements

    -
  1. Improved: Replace by a std::vector for initializing - the constrained boundary DoFs, since the function values - where not used. Allow for non-primitive FiniteElements. +
  2. Improved: Allow for initializing the constrained + boundary DoFs in MGConstrainedDoFs using a std::set + instead of a FunctionMap whose function values were not used. + Allow for non-primitive FiniteElements.
    (Daniel Arndt, 2016/07/20)
  3. diff --git a/include/deal.II/multigrid/mg_constrained_dofs.h b/include/deal.II/multigrid/mg_constrained_dofs.h index a2706716a1..68103f605a 100644 --- a/include/deal.II/multigrid/mg_constrained_dofs.h +++ b/include/deal.II/multigrid/mg_constrained_dofs.h @@ -61,6 +61,8 @@ public: * This function internally calls the initialize() function above and the * constrains degrees on the external boundary of the domain by calling * MGTools::make_boundary_list() with the given second and third argument. + * + * @deprecated Use initialize() followed by set_zero_boundary_dofs() instead */ template void initialize(const DoFHandler &dof, @@ -68,16 +70,19 @@ public: const ComponentMask &component_mask = ComponentMask()) DEAL_II_DEPRECATED; /** - * Fill the internal data structures with information about interface and boundary dofs. + * Fill the internal data structures with information + * about Dirichlet boundary dofs. * - * This function internally calls the initialize() function above and the - * constrains degrees on the external boundary of the domain by calling - * MGTools::make_boundary_list() with the given second and third argument. + * The initialize() function has to be called before + * to set hanging node constraints. + * + * This function can be called multiple times to allow considering + * different sets of boundary_ids for different components. */ template - void set_zero_boundary_dofs(const DoFHandler &dof, - const std::vector &boundary_indicators, - const ComponentMask &component_mask = ComponentMask()); + void make_zero_boundary_constraints(const DoFHandler &dof, + const std::set &boundary_ids, + const ComponentMask &component_mask = ComponentMask()); /** * Reset the data structures. @@ -140,9 +145,11 @@ void MGConstrainedDoFs::initialize(const DoFHandler &dof) { boundary_indices.clear(); + refinement_edge_indices.clear(); const unsigned int nlevels = dof.get_triangulation().n_global_levels(); + //At this point refinement_edge_indices is empty. refinement_edge_indices.resize(nlevels); for (unsigned int l=0; l &dof, // allocate an IndexSet for each global level. Contents will be // overwritten inside make_boundary_list. const unsigned int n_levels = dof.get_triangulation().n_global_levels(); + //At this point boundary_indices is empty. boundary_indices.resize(n_levels); MGTools::make_boundary_list (dof, @@ -175,17 +183,19 @@ MGConstrainedDoFs::initialize(const DoFHandler &dof, template inline void -MGConstrainedDoFs::set_zero_boundary_dofs(const DoFHandler &dof, - const std::vector &boundary_indicators, - const ComponentMask &component_mask) +MGConstrainedDoFs::make_zero_boundary_constraints(const DoFHandler &dof, + const std::set &boundary_ids, + const ComponentMask &component_mask) { // allocate an IndexSet for each global level. Contents will be // overwritten inside make_boundary_list. const unsigned int n_levels = dof.get_triangulation().n_global_levels(); + Assert(boundary_indices.size() == 0 || boundary_indices.size() == n_levels, + ExcInternalError()); boundary_indices.resize(n_levels); MGTools::make_boundary_list (dof, - boundary_indicators, + boundary_ids, boundary_indices, component_mask); } diff --git a/include/deal.II/multigrid/mg_tools.h b/include/deal.II/multigrid/mg_tools.h index 816ef7500c..dfc7b8b67d 100644 --- a/include/deal.II/multigrid/mg_tools.h +++ b/include/deal.II/multigrid/mg_tools.h @@ -178,6 +178,9 @@ namespace MGTools * indices of degrees of freedom for each level that are at the part of the * boundary identified by the function_map argument. Its length has to match * the number of levels in the dof handler object. + * + * Previous content in @p boundary_indices is not overwritten, + * but added to. */ template void @@ -189,6 +192,9 @@ namespace MGTools /** * The same function as above, but return an IndexSet rather than a * std::set on each level. + * + * Previous content in @p boundary_indices is not overwritten, + * but added to. */ template void @@ -199,12 +205,16 @@ namespace MGTools /** * The same function as above, but return an IndexSet rather than a - * std::set on each level. + * std::set on each level and use a std::set of + * boundary_ids as input. + * + * Previous content in @p boundary_indices is not overwritten, + * but added to. */ template void make_boundary_list (const DoFHandler &mg_dof, - const std::vector &boundary_indicators, + const std::set &boundary_ids, std::vector &boundary_indices, const ComponentMask &component_mask = ComponentMask()); diff --git a/source/multigrid/mg_tools.cc b/source/multigrid/mg_tools.cc index a65f2cb6e3..387d5903d1 100644 --- a/source/multigrid/mg_tools.cc +++ b/source/multigrid/mg_tools.cc @@ -1179,20 +1179,6 @@ namespace MGTools } - - template <> - void - make_boundary_list( - const DoFHandler<1,2> &, - const FunctionMap<1>::type &, - std::vector > &, - const ComponentMask &) - { - Assert(false, ExcNotImplemented()); - } - - - template void make_boundary_list( @@ -1205,20 +1191,17 @@ namespace MGTools ExcDimensionMismatch (boundary_indices.size(), dof.get_triangulation().n_global_levels())); - std::vector boundary_indicators; + std::set boundary_ids; typename std::map* >::const_iterator it = function_map.begin(); for (; it!=function_map.end(); ++it) - boundary_indicators.push_back(it->first); + boundary_ids.insert(it->first); std::vector boundary_indexset; - make_boundary_list(dof, boundary_indicators, boundary_indexset, component_mask); + make_boundary_list(dof, boundary_ids, boundary_indexset, component_mask); for (unsigned int i=0; i boundary_indicators; + std::set boundary_ids; typename std::map* >::const_iterator it = function_map.begin(); for (; it!=function_map.end(); ++it) - boundary_indicators.push_back(it->first); + boundary_ids.insert(it->first); - make_boundary_list (dof, boundary_indicators, boundary_indices, component_mask); + make_boundary_list (dof, boundary_ids, boundary_indices, component_mask); } @@ -1246,20 +1229,7 @@ namespace MGTools void make_boundary_list( const DoFHandler<1,1> &, - const std::vector &, - std::vector &, - const ComponentMask &) - { - Assert(false, ExcNotImplemented()); - } - - - - template <> - void - make_boundary_list( - const DoFHandler<1,2> &, - const std::vector &, + const std::set &, std::vector &, const ComponentMask &) { @@ -1270,14 +1240,14 @@ namespace MGTools template void make_boundary_list(const DoFHandler &dof, - const std::vector &boundary_indicators, + const std::set &boundary_ids, std::vector &boundary_indices, const ComponentMask &component_mask) { boundary_indices.resize(dof.get_triangulation().n_global_levels()); - // if for whatever reason we were passed an empty vector, return immediately - if (boundary_indicators.size() == 0) + // if for whatever reason we were passed an empty set, return immediately + if (boundary_ids.size() == 0) return; for (unsigned int i=0; i::invalid_dof_index); - // First, deal with the simpler case when we have to identif all boundary dofs + // First, deal with the simpler case when we have to identify all boundary dofs if (component_mask.n_selected_components(n_components) == n_components) { typename DoFHandler::cell_iterator @@ -1316,7 +1286,7 @@ namespace MGTools face = cell->face(face_no); const types::boundary_id bi = face->boundary_id(); // Face is listed in boundary map - if (std::find(boundary_indicators.begin(), boundary_indicators.end(), bi) != boundary_indicators.end()) + if (boundary_ids.find(bi) != boundary_ids.end()) { face->get_mg_dof_indices(level, local_dofs); boundary_indices[level].add_indices(local_dofs.begin(), local_dofs.end()); @@ -1346,8 +1316,7 @@ namespace MGTools typename DoFHandler::face_iterator face = cell->face(face_no); const types::boundary_id boundary_component = face->boundary_id(); - if (std::find(boundary_indicators.begin(), boundary_indicators.end(), boundary_component) - != boundary_indicators.end()) + if (boundary_ids.find(boundary_component) != boundary_ids.end()) // we want to constrain this boundary { @@ -1378,9 +1347,6 @@ namespace MGTools face->get_mg_dof_indices (level, local_dofs); if (fe_is_system) { - // enter those dofs into the list that match the component - // signature. avoid the usual complication that we can't - // just use *_system_to_component_index for non-primitive FEs for (unsigned int i=0; i &dof, - const std::vector &boundary_indicators, - std::vector &boundary_indices, - const ComponentMask &component_mask); + const DoFHandler &, + const std::set &, + std::vector &, + const ComponentMask &); template diff --git a/tests/multigrid/constrained_dofs_03.cc b/tests/multigrid/constrained_dofs_03.cc index 6f55029b96..4ce74154d8 100644 --- a/tests/multigrid/constrained_dofs_03.cc +++ b/tests/multigrid/constrained_dofs_03.cc @@ -55,10 +55,12 @@ void check_fe(FiniteElement &fe, ComponentMask &component_mask) dofh.distribute_dofs(fe); dofh.distribute_mg_dofs(fe); - MGConstrainedDoFs mg_constrained_dofs; - std::vector boundary_indicators(1,0); + MGConstrainedDoFs mg_constrained_dofs; + std::set boundary_indicators; + + boundary_indicators.insert(0); mg_constrained_dofs.initialize(dofh); - mg_constrained_dofs.set_zero_boundary_dofs(dofh, boundary_indicators, component_mask); + mg_constrained_dofs.make_zero_boundary_constraints(dofh, boundary_indicators, component_mask); const unsigned int n_levels = tr.n_global_levels(); for (unsigned int level = 0; level < n_levels; ++level) -- 2.39.5