From 5d9fc09dcd86d697298f468a148cf79f740e9e9e Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Sun, 7 Feb 2021 11:27:52 +0100 Subject: [PATCH] Remove MatrixType from MGTransferGlobalCoarsening --- .../multigrid/mg_transfer_global_coarsening.h | 72 +++++++++---------- .../multigrid_a_01.cc | 5 +- .../multigrid_p_01.cc | 5 +- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/include/deal.II/multigrid/mg_transfer_global_coarsening.h b/include/deal.II/multigrid/mg_transfer_global_coarsening.h index dc88c7e8fa..c69d210fb8 100644 --- a/include/deal.II/multigrid/mg_transfer_global_coarsening.h +++ b/include/deal.II/multigrid/mg_transfer_global_coarsening.h @@ -247,32 +247,26 @@ private: * one of these element, as well as, systems with different elements or other * elements are currently not implemented. */ -template +template class MGTransferGlobalCoarsening : public dealii::MGTransferBase { public: - static_assert(std::is_same::value, - "Types do not match."); - - /** - * Dimension. - */ - static const int dim = MatrixType::dim; - /** * Value type. */ - using Number = typename MatrixType::value_type; + using Number = typename VectorType::value_type; /** - * Constructor taking an operator for each level (minimum requirement is - * that the operator provides the function initialize_dof_vector()) and - * transfer operators (with the coarsest level kept empty in @p transfer). + * Constructor taking a collection of transfer operators (with the coarsest + * level kept + * empty in @p transfer) and an optional function that initializes the + * internal level vectors within the function call copy_to_mg() if used in the + * context of PreconditionMG. */ MGTransferGlobalCoarsening( - const MGLevelObject & matrices, - const MGLevelObject> &transfer); + const MGLevelObject> &transfer, + const std::function + &initialize_dof_vector = {}); /** * Perform prolongation. @@ -315,8 +309,16 @@ public: const MGLevelObject &src) const; private: - const MGLevelObject & matrices; + /** + * Collection of the two-level transfer operators. + */ const MGLevelObject> &transfer; + + /** + * Function to initialize internal level vectors. + */ + const std::function + initialize_dof_vector; }; @@ -368,22 +370,20 @@ MGTwoLevelTransfer>:: -template -MGTransferGlobalCoarsening::MGTransferGlobalCoarsening( - const MGLevelObject & matrices, - const MGLevelObject> &transfer) - : matrices(matrices) - , transfer(transfer) -{ - AssertDimension(matrices.max_level() - matrices.min_level(), - transfer.max_level() - transfer.min_level()); -} +template +MGTransferGlobalCoarsening::MGTransferGlobalCoarsening( + const MGLevelObject> &transfer, + const std::function + &initialize_dof_vector) + : transfer(transfer) + , initialize_dof_vector(initialize_dof_vector) +{} -template +template void -MGTransferGlobalCoarsening::prolongate( +MGTransferGlobalCoarsening::prolongate( const unsigned int to_level, VectorType & dst, const VectorType & src) const @@ -393,9 +393,9 @@ MGTransferGlobalCoarsening::prolongate( -template +template void -MGTransferGlobalCoarsening::restrict_and_add( +MGTransferGlobalCoarsening::restrict_and_add( const unsigned int from_level, VectorType & dst, const VectorType & src) const @@ -405,10 +405,10 @@ MGTransferGlobalCoarsening::restrict_and_add( -template +template template void -MGTransferGlobalCoarsening::copy_to_mg( +MGTransferGlobalCoarsening::copy_to_mg( const DoFHandler &dof_handler, MGLevelObject & dst, const InVector & src) const @@ -416,17 +416,17 @@ MGTransferGlobalCoarsening::copy_to_mg( (void)dof_handler; for (unsigned int level = dst.min_level(); level <= dst.max_level(); ++level) - matrices[level].initialize_dof_vector(dst[level]); + initialize_dof_vector(level, dst[level]); dst[dst.max_level()].copy_locally_owned_data_from(src); } -template +template template void -MGTransferGlobalCoarsening::copy_from_mg( +MGTransferGlobalCoarsening::copy_from_mg( const DoFHandler &dof_handler, OutVector & dst, const MGLevelObject &src) const diff --git a/tests/multigrid-global-coarsening/multigrid_a_01.cc b/tests/multigrid-global-coarsening/multigrid_a_01.cc index 83470e4650..1e2053b142 100644 --- a/tests/multigrid-global-coarsening/multigrid_a_01.cc +++ b/tests/multigrid-global-coarsening/multigrid_a_01.cc @@ -100,8 +100,9 @@ test(const unsigned int n_refinements, constraints[l + 1], constraints[l]); - MGTransferGlobalCoarsening, VectorType> transfer( - operators, transfers); + MGTransferGlobalCoarsening transfer( + transfers, + [&](const auto l, auto &vec) { operators[l].initialize_dof_vector(vec); }); GMGParameters mg_data; // TODO diff --git a/tests/multigrid-global-coarsening/multigrid_p_01.cc b/tests/multigrid-global-coarsening/multigrid_p_01.cc index 623d35b62d..863be260ed 100644 --- a/tests/multigrid-global-coarsening/multigrid_p_01.cc +++ b/tests/multigrid-global-coarsening/multigrid_p_01.cc @@ -101,8 +101,9 @@ test(const unsigned int n_refinements, constraints[l + 1], constraints[l]); - MGTransferGlobalCoarsening, VectorType> transfer( - operators, transfers); + MGTransferGlobalCoarsening transfer( + transfers, + [&](const auto l, auto &vec) { operators[l].initialize_dof_vector(vec); }); GMGParameters mg_data; // TODO -- 2.39.5