From: Wolfgang Bangerth Date: Wed, 6 Mar 2024 23:45:55 +0000 (-0700) Subject: Make a specialization the general template. X-Git-Tag: v9.6.0-rc1~503^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80eca88d82a372fe2daf715558e46a5b27dae237;p=dealii.git Make a specialization the general template. We can do that because the general template does not work anyway, and can not have been used anywhere. --- diff --git a/include/deal.II/multigrid/mg_transfer_global_coarsening.h b/include/deal.II/multigrid/mg_transfer_global_coarsening.h index dc84d2a4a5..f84b2ea795 100644 --- a/include/deal.II/multigrid/mg_transfer_global_coarsening.h +++ b/include/deal.II/multigrid/mg_transfer_global_coarsening.h @@ -207,66 +207,27 @@ namespace MGTransferGlobalCoarseningTools /** - * Abstract base class for transfer operators between two multigrid levels. + * An abstract base class for transfer operators between two multigrid levels. + * Specialization for LinearAlgebra::distributed::Vector. The implementation of + * restriction and prolongation between levels is delegated to derived classes, + * which implement prolongate_and_add_internal() and restrict_and_add_internal() + * accordingly. */ template class MGTwoLevelTransferBase : public Subscriptor { public: - /** - * Perform prolongation on a solution vector. - */ - virtual void - prolongate_and_add(VectorType &dst, const VectorType &src) const = 0; - - /** - * Perform restriction on a residual vector. - */ - virtual void - restrict_and_add(VectorType &dst, const VectorType &src) const = 0; - - /** - * Perform interpolation of a solution vector from the fine level to the - * coarse level. This function is different from restriction, where a - * weighted residual is transferred to a coarser level (transposition of - * prolongation matrix). In other words, restriction acts on right hand - * side vectors, whereas interpolation acts on solution vectors. - */ - virtual void - interpolate(VectorType &dst, const VectorType &src) const = 0; - - /** - * Enable inplace vector operations if external and internal vectors - * are compatible. - */ - virtual void - enable_inplace_operations_if_possible( - const std::shared_ptr - &partitioner_coarse, - const std::shared_ptr - &partitioner_fine) = 0; + static_assert( + std::is_same_v< + VectorType, + LinearAlgebra::distributed::Vector>, + "This class is currently only implemented for vectors of " + "type LinearAlgebra::distributed::Vector."); /** - * Return the memory consumption of the allocated memory in this class. + * The scalar type used by the vector-type template argument. */ - virtual std::size_t - memory_consumption() const = 0; -}; - - -/** - * Base class for transfer operators between two multigrid levels. - * Specialization for LinearAlgebra::distributed::Vector. The implementation of - * restriction and prolongation between levels is delegated to derived classes, - * which implement prolongate_and_add_internal() and restrict_and_add_internal() - * accordingly. - */ -template -class MGTwoLevelTransferBase> - : public Subscriptor -{ -public: - using VectorType = LinearAlgebra::distributed::Vector; + using Number = typename VectorType::value_type; /** * Default constructor. @@ -335,8 +296,7 @@ protected: * partitioners. */ void - update_ghost_values( - const LinearAlgebra::distributed::Vector &vec) const; + update_ghost_values(const VectorType &vec) const; /** * A wrapper around compress() optimized in case the @@ -344,8 +304,7 @@ protected: * partitioners. */ void - compress(LinearAlgebra::distributed::Vector &vec, - const VectorOperation::values op) const; + compress(VectorType &vec, const VectorOperation::values op) const; /** * A wrapper around zero_out_ghost_values() optimized in case the @@ -353,8 +312,7 @@ protected: * partitioners. */ void - zero_out_ghost_values( - const LinearAlgebra::distributed::Vector &vec) const; + zero_out_ghost_values(const VectorType &vec) const; /** * Enable inplace vector operations if external and internal vectors @@ -447,57 +405,24 @@ template class MGTwoLevelTransfer : public MGTwoLevelTransferBase { public: - /** - * @copydoc MGTwoLevelTransferBase::prolongate_and_add - */ - void - prolongate_and_add(VectorType &dst, const VectorType &src) const override; + static_assert( + std::is_same_v< + VectorType, + LinearAlgebra::distributed::Vector>, + "This class is currently only implemented for vectors of " + "type LinearAlgebra::distributed::Vector."); /** - * @copydoc MGTwoLevelTransferBase::restrict_and_add + * The scalar type used by the vector-type template argument. */ - void - restrict_and_add(VectorType &dst, const VectorType &src) const override; + using Number = typename VectorType::value_type; /** - * @copydoc MGTwoLevelTransferBase::interpolate - */ - void - interpolate(VectorType &dst, const VectorType &src) const override; - - /** - * Enable inplace vector operations if external and internal vectors - * are compatible. + * A data type representing a vectorized array of the same kind of objects + * stored in the `VectorType`. */ - void - enable_inplace_operations_if_possible( - const std::shared_ptr - &partitioner_coarse, - const std::shared_ptr &partitioner_fine) - override; - - /** - * Return the memory consumption of the allocated memory in this class. - */ - std::size_t - memory_consumption() const override; -}; - - - -/** - * Class for transfer between two multigrid levels for p- or global coarsening. - * Specialization for LinearAlgebra::distributed::Vector. - * - * The implementation of this class is explained in detail in @cite munch2022gc. - */ -template -class MGTwoLevelTransfer> - : public MGTwoLevelTransferBase> -{ using VectorizedArrayType = VectorizedArray; -public: /** * Set up global coarsening between the given DoFHandler objects ( * @p dof_handler_fine and @p dof_handler_coarse). The transfer @@ -573,9 +498,7 @@ public: * @copydoc MGTwoLevelTransferBase::interpolate */ void - interpolate( - LinearAlgebra::distributed::Vector &dst, - const LinearAlgebra::distributed::Vector &src) const override; + interpolate(VectorType &dst, const VectorType &src) const override; /** * Enable inplace vector operations if external and internal vectors @@ -596,14 +519,12 @@ public: protected: void - prolongate_and_add_internal( - LinearAlgebra::distributed::Vector &dst, - const LinearAlgebra::distributed::Vector &src) const override; + prolongate_and_add_internal(VectorType &dst, + const VectorType &src) const override; void - restrict_and_add_internal( - LinearAlgebra::distributed::Vector &dst, - const LinearAlgebra::distributed::Vector &src) const override; + restrict_and_add_internal(VectorType &dst, + const VectorType &src) const override; private: /** diff --git a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h index f2df2c85f3..3025bd18a9 100644 --- a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h +++ b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h @@ -2852,20 +2852,18 @@ namespace MGTransferGlobalCoarseningTools -template -MGTwoLevelTransferBase< - LinearAlgebra::distributed::Vector>::MGTwoLevelTransferBase() +template +MGTwoLevelTransferBase::MGTwoLevelTransferBase() : vec_fine_needs_ghost_update(true) {} -template +template void -MGTwoLevelTransferBase>:: - prolongate_and_add( - LinearAlgebra::distributed::Vector &dst, - const LinearAlgebra::distributed::Vector &src) const +MGTwoLevelTransferBase::prolongate_and_add( + VectorType &dst, + const VectorType &src) const { const bool use_dst_inplace = this->vec_fine.size() == 0; auto *const vec_fine_ptr = use_dst_inplace ? &dst : &this->vec_fine; @@ -2903,12 +2901,11 @@ MGTwoLevelTransferBase>:: -template +template void -MGTwoLevelTransfer>:: - prolongate_and_add_internal( - LinearAlgebra::distributed::Vector &dst, - const LinearAlgebra::distributed::Vector &src) const +MGTwoLevelTransfer::prolongate_and_add_internal( + VectorType &dst, + const VectorType &src) const { const unsigned int n_lanes = VectorizedArrayType::size(); @@ -3033,11 +3030,11 @@ MGTwoLevelTransfer>:: -template +template void -MGTwoLevelTransferBase>:: - restrict_and_add(LinearAlgebra::distributed::Vector &dst, - const LinearAlgebra::distributed::Vector &src) const +MGTwoLevelTransferBase::restrict_and_add( + VectorType &dst, + const VectorType &src) const { const bool use_src_inplace = this->vec_fine.size() == 0; const auto *const vec_fine_ptr = use_src_inplace ? &src : &this->vec_fine; @@ -3084,12 +3081,11 @@ MGTwoLevelTransferBase>:: -template +template void -MGTwoLevelTransfer>:: - restrict_and_add_internal( - LinearAlgebra::distributed::Vector &dst, - const LinearAlgebra::distributed::Vector &src) const +MGTwoLevelTransfer::restrict_and_add_internal( + VectorType &dst, + const VectorType &src) const { const unsigned int n_lanes = VectorizedArrayType::size(); @@ -3215,11 +3211,10 @@ MGTwoLevelTransfer>:: -template +template void -MGTwoLevelTransfer>:: - interpolate(LinearAlgebra::distributed::Vector &dst, - const LinearAlgebra::distributed::Vector &src) const +MGTwoLevelTransfer::interpolate(VectorType &dst, + const VectorType &src) const { const unsigned int n_lanes = VectorizedArrayType::size(); @@ -3397,10 +3392,12 @@ namespace internal } // namespace } // namespace internal -template + + +template template void -MGTwoLevelTransferBase>:: +MGTwoLevelTransferBase:: internal_enable_inplace_operations_if_possible( const std::shared_ptr &external_partitioner_coarse, @@ -3465,14 +3462,15 @@ MGTwoLevelTransferBase>:: } } -template + + +template void -MGTwoLevelTransfer>:: - enable_inplace_operations_if_possible( - const std::shared_ptr - &external_partitioner_coarse, - const std::shared_ptr - &external_partitioner_fine) +MGTwoLevelTransfer::enable_inplace_operations_if_possible( + const std::shared_ptr + &external_partitioner_coarse, + const std::shared_ptr + &external_partitioner_fine) { this->internal_enable_inplace_operations_if_possible( external_partitioner_coarse, @@ -3484,15 +3482,15 @@ MGTwoLevelTransfer>:: -template +template void -MGTwoLevelTransfer>:: - reinit_geometric_transfer(const DoFHandler &dof_handler_fine, - const DoFHandler &dof_handler_coarse, - const AffineConstraints &constraints_fine, - const AffineConstraints &constraints_coarse, - const unsigned int mg_level_fine, - const unsigned int mg_level_coarse) +MGTwoLevelTransfer::reinit_geometric_transfer( + const DoFHandler &dof_handler_fine, + const DoFHandler &dof_handler_coarse, + const AffineConstraints &constraints_fine, + const AffineConstraints &constraints_coarse, + const unsigned int mg_level_fine, + const unsigned int mg_level_coarse) { internal::MGTwoLevelTransferImplementation::reinit_geometric_transfer( dof_handler_fine, @@ -3506,16 +3504,15 @@ MGTwoLevelTransfer>:: -template +template void -MGTwoLevelTransfer>:: - reinit_polynomial_transfer( - const DoFHandler &dof_handler_fine, - const DoFHandler &dof_handler_coarse, - const AffineConstraints &constraints_fine, - const AffineConstraints &constraints_coarse, - const unsigned int mg_level_fine, - const unsigned int mg_level_coarse) +MGTwoLevelTransfer::reinit_polynomial_transfer( + const DoFHandler &dof_handler_fine, + const DoFHandler &dof_handler_coarse, + const AffineConstraints &constraints_fine, + const AffineConstraints &constraints_coarse, + const unsigned int mg_level_fine, + const unsigned int mg_level_coarse) { internal::MGTwoLevelTransferImplementation::reinit_polynomial_transfer( dof_handler_fine, @@ -3529,9 +3526,9 @@ MGTwoLevelTransfer>:: -template +template void -MGTwoLevelTransfer>::reinit( +MGTwoLevelTransfer::reinit( const DoFHandler &dof_handler_fine, const DoFHandler &dof_handler_coarse, const AffineConstraints &constraints_fine, @@ -3622,11 +3619,11 @@ MGTwoLevelTransfer>::reinit( -template +template bool -MGTwoLevelTransfer>:: - fast_polynomial_transfer_supported(const unsigned int fe_degree_fine, - const unsigned int fe_degree_coarse) +MGTwoLevelTransfer::fast_polynomial_transfer_supported( + const unsigned int fe_degree_fine, + const unsigned int fe_degree_coarse) { CellTransferFactory cell_transfer(fe_degree_fine, fe_degree_coarse); CellProlongatorTest cell_transfer_test; @@ -3636,10 +3633,9 @@ MGTwoLevelTransfer>:: -template +template std::size_t -MGTwoLevelTransfer>:: - memory_consumption() const +MGTwoLevelTransfer::memory_consumption() const { std::size_t size = 0; @@ -3664,11 +3660,10 @@ MGTwoLevelTransfer>:: -template +template void -MGTwoLevelTransferBase>:: - update_ghost_values( - const LinearAlgebra::distributed::Vector &vec) const +MGTwoLevelTransferBase::update_ghost_values( + const VectorType &vec) const { if ((vec.get_partitioner().get() == this->partitioner_coarse.get()) && (this->partitioner_coarse_embedded != nullptr)) @@ -3686,11 +3681,11 @@ MGTwoLevelTransferBase>:: -template +template void -MGTwoLevelTransferBase>::compress( - LinearAlgebra::distributed::Vector &vec, - const VectorOperation::values op) const +MGTwoLevelTransferBase::compress( + VectorType &vec, + const VectorOperation::values op) const { Assert(op == VectorOperation::add, ExcNotImplemented()); @@ -3710,11 +3705,10 @@ MGTwoLevelTransferBase>::compress( -template +template void -MGTwoLevelTransferBase>:: - zero_out_ghost_values( - const LinearAlgebra::distributed::Vector &vec) const +MGTwoLevelTransferBase::zero_out_ghost_values( + const VectorType &vec) const { if ((vec.get_partitioner().get() == this->partitioner_coarse.get()) && (this->partitioner_coarse_embedded != nullptr))