From fc84fe31596c199d089b0bc6574b406b50fc86dc Mon Sep 17 00:00:00 2001 From: Niklas Fehn Date: Mon, 2 Mar 2020 18:06:58 +0100 Subject: [PATCH] MGTransfer: don't repeat yourself --- include/deal.II/multigrid/mg_transfer.h | 16 ++++++ .../deal.II/multigrid/mg_transfer.templates.h | 57 ++++++++++--------- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/include/deal.II/multigrid/mg_transfer.h b/include/deal.II/multigrid/mg_transfer.h index fc2e630f22..89cef8c89c 100644 --- a/include/deal.II/multigrid/mg_transfer.h +++ b/include/deal.II/multigrid/mg_transfer.h @@ -417,6 +417,14 @@ protected: */ SmartPointer> mg_constrained_dofs; + +private: + /** + * This function is called to make sure that build() has been invoked. + */ + template + void + assert_built(const DoFHandler &dof_handler) const; }; @@ -634,6 +642,14 @@ protected: */ mutable MGLevelObject> solution_ghosted_level_vector; + +private: + /** + * This function is called to make sure that build() has been invoked. + */ + template + void + assert_built(const DoFHandler &dof_handler) const; }; diff --git a/include/deal.II/multigrid/mg_transfer.templates.h b/include/deal.II/multigrid/mg_transfer.templates.h index 0cf2bbf44d..0158b6310b 100644 --- a/include/deal.II/multigrid/mg_transfer.templates.h +++ b/include/deal.II/multigrid/mg_transfer.templates.h @@ -210,9 +210,7 @@ MGLevelGlobalTransfer::copy_to_mg( MGLevelObject & dst, const InVector & src) const { - Assert(copy_indices.size() == - dof_handler.get_triangulation().n_global_levels(), - ExcMessage("MGTransfer::build() has not been called!")); + assert_built(dof_handler); AssertIndexRange(dst.max_level(), dof_handler.get_triangulation().n_global_levels()); AssertIndexRange(dst.min_level(), dst.max_level() + 1); @@ -282,10 +280,7 @@ MGLevelGlobalTransfer::copy_from_mg( OutVector & dst, const MGLevelObject &src) const { - (void)dof_handler; - Assert(copy_indices.size() == - dof_handler.get_triangulation().n_global_levels(), - ExcMessage("MGTransfer::build() has not been called!")); + assert_built(dof_handler); AssertIndexRange(src.max_level(), dof_handler.get_triangulation().n_global_levels()); AssertIndexRange(src.min_level(), src.max_level() + 1); @@ -359,10 +354,7 @@ MGLevelGlobalTransfer::copy_from_mg_add( OutVector & dst, const MGLevelObject &src) const { - (void)dof_handler; - Assert(copy_indices.size() == - dof_handler.get_triangulation().n_global_levels(), - ExcMessage("MGTransfer::build() has not been called!")); + assert_built(dof_handler); // For non-DG: degrees of freedom in the refinement face may need special // attention, since they belong to the coarse level, but have fine level // basis functions @@ -399,6 +391,17 @@ MGLevelGlobalTransfer::set_component_to_block_map( component_to_block_map = map; } +template +template +void +MGLevelGlobalTransfer::assert_built( + const DoFHandler &dof_handler) const +{ + (void)dof_handler; + Assert(copy_indices.size() == + dof_handler.get_triangulation().n_global_levels(), + ExcMessage("MGTransfer::build() has not been called!")); +} /* --------- MGLevelGlobalTransfer ------- @@ -412,9 +415,7 @@ MGLevelGlobalTransfer>::copy_to_mg( MGLevelObject> &dst, const LinearAlgebra::distributed::Vector & src) const { - Assert(copy_indices.size() == - dof_handler.get_triangulation().n_global_levels(), - ExcMessage("MGTransfer::build() has not been called!")); + assert_built(dof_handler); copy_to_mg(dof_handler, dst, src, false); } @@ -428,9 +429,7 @@ MGLevelGlobalTransfer>::copy_to_mg( const LinearAlgebra::distributed::Vector & src, const bool solution_transfer) const { - Assert(copy_indices.size() == - dof_handler.get_triangulation().n_global_levels(), - ExcMessage("MGTransfer::build() has not been called!")); + assert_built(dof_handler); LinearAlgebra::distributed::Vector &this_ghosted_global_vector = solution_transfer ? solution_ghosted_global_vector : ghosted_global_vector; const std::vector> &this_copy_indices = @@ -439,8 +438,6 @@ MGLevelGlobalTransfer>::copy_to_mg( solution_transfer ? solution_copy_indices_level_mine : copy_indices_level_mine; - (void)dof_handler; - AssertIndexRange(dst.max_level(), dof_handler.get_triangulation().n_global_levels()); AssertIndexRange(dst.min_level(), dst.max_level() + 1); @@ -536,10 +533,7 @@ MGLevelGlobalTransfer>::copy_from_mg( LinearAlgebra::distributed::Vector & dst, const MGLevelObject> &src) const { - (void)dof_handler; - Assert(copy_indices.size() == - dof_handler.get_triangulation().n_global_levels(), - ExcMessage("MGTransfer::build() has not been called!")); + assert_built(dof_handler); AssertIndexRange(src.max_level(), dof_handler.get_triangulation().n_global_levels()); AssertIndexRange(src.min_level(), src.max_level() + 1); @@ -614,10 +608,7 @@ MGLevelGlobalTransfer>:: LinearAlgebra::distributed::Vector &dst, const MGLevelObject> &src) const { - (void)dof_handler; - Assert(copy_indices.size() == - dof_handler.get_triangulation().n_global_levels(), - ExcMessage("MGTransfer::build() has not been called!")); + assert_built(dof_handler); // For non-DG: degrees of freedom in the refinement face may need special // attention, since they belong to the coarse level, but have fine level // basis functions @@ -663,6 +654,18 @@ MGLevelGlobalTransfer>:: component_to_block_map = map; } +template +template +void +MGLevelGlobalTransfer>::assert_built( + const DoFHandler &dof_handler) const +{ + (void)dof_handler; + Assert(copy_indices.size() == + dof_handler.get_triangulation().n_global_levels(), + ExcMessage("MGTransfer::build() has not been called!")); +} + DEAL_II_NAMESPACE_CLOSE -- 2.39.5