From ee7a28798805e26a8f7513d16f5ccef9dad06f01 Mon Sep 17 00:00:00 2001 From: Andrea Iob Date: Wed, 29 May 2024 17:53:56 +0200 Subject: [PATCH] LS: properly set up KSP debug options for the split system --- src/LA/system_solvers_split.cpp | 27 +++++++++++++++++++++++++++ src/LA/system_solvers_split.hpp | 2 ++ 2 files changed, 29 insertions(+) diff --git a/src/LA/system_solvers_split.cpp b/src/LA/system_solvers_split.cpp index d6a607e83f..b3d0253789 100644 --- a/src/LA/system_solvers_split.cpp +++ b/src/LA/system_solvers_split.cpp @@ -1572,6 +1572,33 @@ void SplitSystemSolver::setupSplitKrylovs() } } +/*! + * Perform actions before Krylov subspace method setup. + */ +void SplitSystemSolver::preKrylovSetupActions() +{ + // Execute base actions + SystemSolver::preKrylovSetupActions(); + + // Set KSP debug options + if (m_debug) { + int nSplits = getSplitCount(); + for (int split = 0; split < nSplits; ++split) { + std::string prefix = "fieldsplit_" + std::to_string(split) + "_"; + +#if (PETSC_VERSION_MAJOR >= 3 && PETSC_VERSION_MINOR >= 7) + PetscOptionsSetValue(PETSC_NULLPTR, ("-" + prefix + "ksp_monitor_true_residual").c_str(), ""); + PetscOptionsSetValue(PETSC_NULLPTR, ("-" + prefix + "ksp_converged_reason").c_str(), ""); + PetscOptionsSetValue(PETSC_NULLPTR, ("-" + prefix + "ksp_monitor_singular_value").c_str(), ""); +#else + PetscOptionsSetValue(("-" + prefix + "ksp_monitor_true_residual").c_str(), ""); + PetscOptionsSetValue(("-" + prefix + "ksp_converged_reason").c_str(), ""); + PetscOptionsSetValue(("-" + prefix + "ksp_monitor_singular_value").c_str(), ""); +#endif + } + } +} + /*! * Generate the split permutation. * diff --git a/src/LA/system_solvers_split.hpp b/src/LA/system_solvers_split.hpp index a4fdf922b5..600bf129d6 100644 --- a/src/LA/system_solvers_split.hpp +++ b/src/LA/system_solvers_split.hpp @@ -142,6 +142,8 @@ class SplitSystemSolver : public SystemSolver { using SystemSolver::setupKrylov; virtual void setupSplitKrylovs(); + void preKrylovSetupActions() override; + void postKSPSolveActions() override; void initializeKSPOptions() override;