From c562fd12cc35ce7018d26cf42b6cd316c1b48978 Mon Sep 17 00:00:00 2001 From: Mathias Anselmann Date: Thu, 6 Jun 2019 17:14:54 +0200 Subject: [PATCH] united extract_dofs() for DoFHandler and hp::DoFHandler, drawback: auto deduction not working anymore in some other places --- include/deal.II/dofs/dof_tools.h | 34 ++------ source/dofs/dof_tools.cc | 79 +++---------------- source/dofs/dof_tools.inst.in | 16 +++- source/dofs/dof_tools_constraints.cc | 3 +- tests/dofs/dof_tools_12.cc | 8 +- tests/dofs/dof_tools_12a.cc | 8 +- tests/dofs/dof_tools_13a.cc | 10 +-- tests/dofs/extract_dofs_by_component_01.cc | 3 +- tests/dofs/extract_dofs_by_component_01_hp.cc | 3 +- tests/dofs/extract_dofs_by_component_01x.cc | 3 +- tests/dofs/extract_dofs_by_component_01y.cc | 3 +- tests/dofs/extract_dofs_by_component_02.cc | 3 +- tests/dofs/extract_dofs_by_component_02_hp.cc | 3 +- 13 files changed, 60 insertions(+), 116 deletions(-) diff --git a/include/deal.II/dofs/dof_tools.h b/include/deal.II/dofs/dof_tools.h index d25d74f20e..bc8a88c4d7 100644 --- a/include/deal.II/dofs/dof_tools.h +++ b/include/deal.II/dofs/dof_tools.h @@ -1351,20 +1351,11 @@ namespace DoFTools * first have to be mapped to the global degrees of freedom, to correspond * with them. */ - template - void - extract_dofs(const DoFHandler &dof_handler, - const ComponentMask & component_mask, - std::vector & selected_dofs); - - /** - * The same function as above, but for a hp::DoFHandler. - */ - template + template void - extract_dofs(const hp::DoFHandler &dof_handler, - const ComponentMask & component_mask, - std::vector & selected_dofs); + extract_dofs(const DoFHandlerType &dof_handler, + const ComponentMask & component_mask, + std::vector & selected_dofs); /** * This function is the equivalent to the DoFTools::extract_dofs() functions @@ -1390,20 +1381,11 @@ namespace DoFTools * sequential computations of course equals DoFHandler::n_dofs(). The * previous contents of this array are overwritten. */ - template - void - extract_dofs(const DoFHandler &dof_handler, - const BlockMask & block_mask, - std::vector & selected_dofs); - - /** - * The same function as above, but for a hp::DoFHandler. - */ - template + template void - extract_dofs(const hp::DoFHandler &dof_handler, - const BlockMask & block_mask, - std::vector & selected_dofs); + extract_dofs(const DoFHandlerType &dof_handler, + const BlockMask & block_mask, + std::vector & selected_dofs); /** * Do the same thing as the corresponding extract_dofs() function for one diff --git a/source/dofs/dof_tools.cc b/source/dofs/dof_tools.cc index c7665b4a25..9607414e56 100644 --- a/source/dofs/dof_tools.cc +++ b/source/dofs/dof_tools.cc @@ -397,59 +397,11 @@ namespace DoFTools - template - void - extract_dofs(const DoFHandler &dof, - const ComponentMask & component_mask, - std::vector & selected_dofs) - { - const FiniteElement &fe = dof.get_fe(); - (void)fe; - - Assert(component_mask.represents_n_components(fe.n_components()), - ExcMessage( - "The given component mask is not sized correctly to represent the " - "components of the given finite element.")); - Assert(selected_dofs.size() == dof.n_locally_owned_dofs(), - ExcDimensionMismatch(selected_dofs.size(), - dof.n_locally_owned_dofs())); - - // two special cases: no component is selected, and all components are - // selected; both rather stupid, but easy to catch - if (component_mask.n_selected_components(n_components(dof)) == 0) - { - std::fill_n(selected_dofs.begin(), dof.n_locally_owned_dofs(), false); - return; - } - else if (component_mask.n_selected_components(n_components(dof)) == - n_components(dof)) - { - std::fill_n(selected_dofs.begin(), dof.n_locally_owned_dofs(), true); - return; - } - - - // preset all values by false - std::fill_n(selected_dofs.begin(), dof.n_locally_owned_dofs(), false); - - // get the component association of each DoF and then select the ones - // that match the given set of blocks - std::vector dofs_by_component(dof.n_locally_owned_dofs()); - internal::get_component_association(dof, component_mask, dofs_by_component); - - for (types::global_dof_index i = 0; i < dof.n_locally_owned_dofs(); ++i) - if (component_mask[dofs_by_component[i]] == true) - selected_dofs[i] = true; - } - - - // TODO: Unify the following two functions with the non-hp case - - template + template void - extract_dofs(const hp::DoFHandler &dof, - const ComponentMask & component_mask, - std::vector & selected_dofs) + extract_dofs(const DoFHandlerType &dof, + const ComponentMask & component_mask, + std::vector & selected_dofs) { Assert(component_mask.represents_n_components( dof.get_fe_collection().n_components()), @@ -492,26 +444,15 @@ namespace DoFTools - template - void - extract_dofs(const DoFHandler &dof, - const BlockMask & block_mask, - std::vector & selected_dofs) - { - // simply forward to the function that works based on a component mask - extract_dofs(dof, dof.get_fe().component_mask(block_mask), selected_dofs); - } - - - - template + template void - extract_dofs(const hp::DoFHandler &dof, - const BlockMask & block_mask, - std::vector & selected_dofs) + extract_dofs(const DoFHandlerType &dof, + const BlockMask & block_mask, + std::vector & selected_dofs) { // simply forward to the function that works based on a component mask - extract_dofs(dof, dof.get_fe().component_mask(block_mask), selected_dofs); + extract_dofs( + dof, dof.get_fe_collection().component_mask(block_mask), selected_dofs); } diff --git a/source/dofs/dof_tools.inst.in b/source/dofs/dof_tools.inst.in index 5866a24787..39bb4fcbbd 100644 --- a/source/dofs/dof_tools.inst.in +++ b/source/dofs/dof_tools.inst.in @@ -689,25 +689,33 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : DIMENSIONS) &patch); template void - extract_dofs( + extract_dofs>( const DoFHandler &, const ComponentMask &, std::vector &); template void - extract_dofs( + extract_dofs>( const DoFHandler &, const BlockMask &, std::vector &); template void - extract_dofs( + extract_dofs>( const hp::DoFHandler &, const ComponentMask &, std::vector &); template void - extract_dofs( + extract_dofs>( const hp::DoFHandler &, const BlockMask &, std::vector &); diff --git a/source/dofs/dof_tools_constraints.cc b/source/dofs/dof_tools_constraints.cc index ee6727dc52..c97405c778 100644 --- a/source/dofs/dof_tools_constraints.cc +++ b/source/dofs/dof_tools_constraints.cc @@ -3133,7 +3133,8 @@ namespace DoFTools { std::vector mask(coarse_grid.get_fe(0).n_components(), false); mask[coarse_component] = true; - extract_dofs(coarse_grid, ComponentMask(mask), coarse_dof_is_parameter); + extract_dofs>( + coarse_grid, ComponentMask(mask), coarse_dof_is_parameter); } // now we know that the weights in each row constitute a constraint. enter diff --git a/tests/dofs/dof_tools_12.cc b/tests/dofs/dof_tools_12.cc index d6f3c4e6dc..fa922baac2 100644 --- a/tests/dofs/dof_tools_12.cc +++ b/tests/dofs/dof_tools_12.cc @@ -31,11 +31,15 @@ check_this(const DoFHandler &dof_handler) // only select first component mask[0] = true; - DoFTools::extract_dofs(dof_handler, ComponentMask(mask), selected_dofs); + DoFTools::extract_dofs>(dof_handler, + ComponentMask(mask), + selected_dofs); output_bool_vector(selected_dofs); // also select last component mask.back() = true; - DoFTools::extract_dofs(dof_handler, ComponentMask(mask), selected_dofs); + DoFTools::extract_dofs>(dof_handler, + ComponentMask(mask), + selected_dofs); output_bool_vector(selected_dofs); } diff --git a/tests/dofs/dof_tools_12a.cc b/tests/dofs/dof_tools_12a.cc index 39be28d6a9..bb25d2ae63 100644 --- a/tests/dofs/dof_tools_12a.cc +++ b/tests/dofs/dof_tools_12a.cc @@ -63,12 +63,16 @@ check_this(const DoFHandlerType &dof_handler) // only select first component mask[0] = true; - DoFTools::extract_dofs(dof_handler, ComponentMask(mask), selected_dofs); + DoFTools::extract_dofs(dof_handler, + ComponentMask(mask), + selected_dofs); output_bool_vector(selected_dofs); // also select last component mask.back() = true; - DoFTools::extract_dofs(dof_handler, ComponentMask(mask), selected_dofs); + DoFTools::extract_dofs(dof_handler, + ComponentMask(mask), + selected_dofs); output_bool_vector(selected_dofs); } diff --git a/tests/dofs/dof_tools_13a.cc b/tests/dofs/dof_tools_13a.cc index e16739853b..3d797bf78f 100644 --- a/tests/dofs/dof_tools_13a.cc +++ b/tests/dofs/dof_tools_13a.cc @@ -56,9 +56,8 @@ check_this(const DoFHandler &dof_handler) std::vector component_mask(dof_handler.get_fe().n_components(), false); component_mask[0] = true; - DoFTools::extract_dofs(dof_handler, - ComponentMask(component_mask), - component_dofs); + DoFTools::extract_dofs>( + dof_handler, ComponentMask(component_mask), component_dofs); for (unsigned int i = 0; i < dof_data.size(); ++i) if (component_dofs[i] == true) @@ -91,9 +90,8 @@ check_this(const DoFHandler &dof_handler) std::vector component_mask(dof_handler.get_fe().n_components(), false); component_mask.back() = true; - DoFTools::extract_dofs(dof_handler, - ComponentMask(component_mask), - component_dofs); + DoFTools::extract_dofs>( + dof_handler, ComponentMask(component_mask), component_dofs); for (unsigned int i = 0; i < dof_data.size(); ++i) if (component_dofs[i] == true) dof_data(i) = i + 1; diff --git a/tests/dofs/extract_dofs_by_component_01.cc b/tests/dofs/extract_dofs_by_component_01.cc index d0f8587d2e..ee1b4cce7c 100644 --- a/tests/dofs/extract_dofs_by_component_01.cc +++ b/tests/dofs/extract_dofs_by_component_01.cc @@ -70,7 +70,8 @@ check() component_mask[c] = (int_mask & (1 << c)); std::vector dofs(dof.n_dofs()); - DoFTools::extract_dofs(dof, ComponentMask(component_mask), dofs); + DoFTools::extract_dofs>( + dof, ComponentMask(component_mask), dofs); for (unsigned int d = 0; d < dof.n_dofs(); ++d) deallog << dofs[d]; diff --git a/tests/dofs/extract_dofs_by_component_01_hp.cc b/tests/dofs/extract_dofs_by_component_01_hp.cc index 92de6e0698..9ddd85cafc 100644 --- a/tests/dofs/extract_dofs_by_component_01_hp.cc +++ b/tests/dofs/extract_dofs_by_component_01_hp.cc @@ -71,7 +71,8 @@ check() component_mask[c] = (int_mask & (1 << c)); std::vector dofs(dof.n_dofs()); - DoFTools::extract_dofs(dof, ComponentMask(component_mask), dofs); + DoFTools::extract_dofs>( + dof, ComponentMask(component_mask), dofs); for (unsigned int d = 0; d < dof.n_dofs(); ++d) deallog << dofs[d]; diff --git a/tests/dofs/extract_dofs_by_component_01x.cc b/tests/dofs/extract_dofs_by_component_01x.cc index e5f5726f1f..0c52237192 100644 --- a/tests/dofs/extract_dofs_by_component_01x.cc +++ b/tests/dofs/extract_dofs_by_component_01x.cc @@ -63,7 +63,8 @@ check() component_mask[0] = true; std::vector dofs(dof.n_dofs()); - DoFTools::extract_dofs(dof, ComponentMask(component_mask), dofs); + DoFTools::extract_dofs>( + dof, ComponentMask(component_mask), dofs); for (unsigned int d = 0; d < dof.n_dofs(); ++d) deallog << dofs[d]; diff --git a/tests/dofs/extract_dofs_by_component_01y.cc b/tests/dofs/extract_dofs_by_component_01y.cc index 3b0a516a7f..9f537c577f 100644 --- a/tests/dofs/extract_dofs_by_component_01y.cc +++ b/tests/dofs/extract_dofs_by_component_01y.cc @@ -67,7 +67,8 @@ check() component_mask[comp] = true; std::vector dofs(dof.n_dofs()); - DoFTools::extract_dofs(dof, ComponentMask(component_mask), dofs); + DoFTools::extract_dofs>( + dof, ComponentMask(component_mask), dofs); for (unsigned int d = 0; d < dof.n_dofs(); ++d) deallog << dofs[d]; diff --git a/tests/dofs/extract_dofs_by_component_02.cc b/tests/dofs/extract_dofs_by_component_02.cc index 9b72031d37..4bbae11248 100644 --- a/tests/dofs/extract_dofs_by_component_02.cc +++ b/tests/dofs/extract_dofs_by_component_02.cc @@ -70,7 +70,8 @@ check() component_mask[c] = (int_mask & (1 << c)); std::vector dofs(dof.n_dofs()); - DoFTools::extract_dofs(dof, BlockMask(component_mask), dofs); + DoFTools::extract_dofs>( + dof, BlockMask(component_mask), dofs); for (unsigned int d = 0; d < dof.n_dofs(); ++d) deallog << dofs[d]; diff --git a/tests/dofs/extract_dofs_by_component_02_hp.cc b/tests/dofs/extract_dofs_by_component_02_hp.cc index 20e88da1a3..6762eeb656 100644 --- a/tests/dofs/extract_dofs_by_component_02_hp.cc +++ b/tests/dofs/extract_dofs_by_component_02_hp.cc @@ -71,7 +71,8 @@ check() component_mask[c] = (int_mask & (1 << c)); std::vector dofs(dof.n_dofs()); - DoFTools::extract_dofs(dof, BlockMask(component_mask), dofs); + DoFTools::extract_dofs>( + dof, BlockMask(component_mask), dofs); for (unsigned int d = 0; d < dof.n_dofs(); ++d) deallog << dofs[d]; -- 2.39.5