From a6cdf078087dac69263c52e7e3daa36c02c226e6 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Fri, 28 Mar 2025 15:43:20 -0500 Subject: [PATCH] SolverMPGMRES: allow to switch strategies with an AdditionalData flag --- include/deal.II/lac/solver_gmres.h | 65 ++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/include/deal.II/lac/solver_gmres.h b/include/deal.II/lac/solver_gmres.h index b3102db8a5..47c880334c 100644 --- a/include/deal.II/lac/solver_gmres.h +++ b/include/deal.II/lac/solver_gmres.h @@ -700,12 +700,14 @@ public: /** * Constructor. By default, set the maximum basis size to 30. */ - explicit AdditionalData(const unsigned int max_basis_size = 30, + explicit AdditionalData(const unsigned int max_basis_size = 30, + const bool use_truncated_mpgmres_strategy = true, const LinearAlgebra::OrthogonalizationStrategy orthogonalization_strategy = LinearAlgebra::OrthogonalizationStrategy:: delayed_classical_gram_schmidt) : max_basis_size(max_basis_size) + , use_truncated_mpgmres_strategy(use_truncated_mpgmres_strategy) , orthogonalization_strategy(orthogonalization_strategy) {} @@ -714,6 +716,17 @@ public: */ unsigned int max_basis_size; + /** + * If set to true (the default) a "truncated" search space is + * constructed consisting of the span of independent Krylov space + * associated with each preconditioner. If set to false, the full + * MPGMRES strategy for constructing the search space is used. This + * space consists of all possible combinations of iterative + * preconditioner applications; see the documentation of SolverMPGMRES + * for details. + */ + bool use_truncated_mpgmres_strategy; + /** * Strategy to orthogonalize vectors. */ @@ -750,7 +763,7 @@ protected: /** * Indexing strategy to construct the search space. * - * This enum class is internally used in the impelmentation of the + * This enum class is internally used in the implementation of the * MPGMRES algorithm to switch between the strategies. */ enum class IndexingStrategy @@ -820,7 +833,34 @@ DEAL_II_CXX20_REQUIRES(concepts::is_vector_space_vector) class SolverFGMRES : public SolverMPGMRES { public: - using AdditionalData = typename SolverMPGMRES::AdditionalData; + /** + * Standardized data struct to pipe additional data to the solver. + */ + struct AdditionalData + { + /** + * Constructor. By default, set the maximum basis size to 30. + */ + explicit AdditionalData( // + const unsigned int max_basis_size = 30, + const LinearAlgebra::OrthogonalizationStrategy + orthogonalization_strategy = LinearAlgebra::OrthogonalizationStrategy:: + delayed_classical_gram_schmidt) + : max_basis_size(max_basis_size) + , orthogonalization_strategy(orthogonalization_strategy) + {} + + /** + * Maximum basis size. + */ + unsigned int max_basis_size; + + /** + * Strategy to orthogonalize vectors. + */ + LinearAlgebra::OrthogonalizationStrategy orthogonalization_strategy; + }; + /** * Constructor. @@ -2102,7 +2142,10 @@ SolverMPGMRES::SolverMPGMRES(SolverControl &cn, : SolverBase(cn, mem) , additional_data(data) { - indexing_strategy = IndexingStrategy::truncated_mpgmres; + if (data.use_truncated_mpgmres_strategy) + indexing_strategy = IndexingStrategy::truncated_mpgmres; + else + indexing_strategy = IndexingStrategy::full_mpgmres; } @@ -2114,7 +2157,10 @@ SolverMPGMRES::SolverMPGMRES(SolverControl &cn, : SolverBase(cn) , additional_data(data) { - indexing_strategy = IndexingStrategy::truncated_mpgmres; + if (data.use_truncated_mpgmres_strategy) + indexing_strategy = IndexingStrategy::truncated_mpgmres; + else + indexing_strategy = IndexingStrategy::full_mpgmres; } @@ -2296,7 +2342,10 @@ DEAL_II_CXX20_REQUIRES(concepts::is_vector_space_vector) SolverFGMRES::SolverFGMRES(SolverControl &cn, VectorMemory &mem, const AdditionalData &data) - : SolverMPGMRES(cn, mem, data) + : SolverMPGMRES(cn, + mem, + {data.max_basis_size, + data.orthogonalization_strategy}) { this->indexing_strategy = SolverMPGMRES::IndexingStrategy::fgmres; } @@ -2307,7 +2356,9 @@ template DEAL_II_CXX20_REQUIRES(concepts::is_vector_space_vector) SolverFGMRES::SolverFGMRES(SolverControl &cn, const AdditionalData &data) - : SolverMPGMRES(cn, data) + : SolverMPGMRES(cn, + {data.max_basis_size, + data.orthogonalization_strategy}) { this->indexing_strategy = SolverMPGMRES::IndexingStrategy::fgmres; } -- 2.39.5