From: Peter Munch Date: Sun, 7 Feb 2021 10:27:52 +0000 (+0100) Subject: Remove MatrixType from MGTransferGlobalCoarsening X-Git-Tag: v9.3.0-rc1~470^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d9fc09dcd86d697298f468a148cf79f740e9e9e;p=dealii.git Remove MatrixType from MGTransferGlobalCoarsening --- 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