Skip to content
Snippets Groups Projects
Commit 74468b78 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

Merge branch 'minor_bug' into 'master'

[SNES] Use SNESGetConvergedReasonString

See merge request ogs/ogs!4903
parents 10a0c3b5 e606de3e
No related branches found
No related tags found
No related merge requests found
......@@ -14,30 +14,9 @@
#include <petscmat.h>
#include <petscvec.h>
#include <spdlog/fmt/bundled/core.h>
#include <string>
#include "BaseLib/RunTime.h"
template <>
struct fmt::formatter<SNESConvergedReason>
{
constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
template <typename FormatContext>
auto format(SNESConvergedReason const reason, FormatContext& ctx)
{
if (reason < 0)
{
return fmt::format_to(ctx.out(), "DIVERGED: {}",
SNESConvergedReasons[reason]);
}
return fmt::format_to(ctx.out(), "CONVERGED: {}",
SNESConvergedReasons[reason]);
}
};
namespace
{
struct PetscContext
......@@ -51,6 +30,21 @@ struct PetscContext
int const process_id;
};
void printConvergenceReason(SNES const& snes_solver,
SNESConvergedReason const& reason)
{
const char* strreason;
SNESGetConvergedReasonString(snes_solver, &strreason);
if (reason < 0)
{
INFO("PETScSNES diverged reason: {:s}.", strreason);
}
else
{
INFO("PETScSNES converged reason: {:s}.", strreason);
}
}
PetscErrorCode updateResidual(SNES /*snes*/, Vec x, Vec petsc_r,
void* petsc_context)
{
......@@ -229,9 +223,9 @@ NonlinearSolverStatus PETScNonlinearSolver::solve(
DBUG("PETScNonlinearSolver: call SNESSolve");
SNESSolve(_snes_solver, nullptr, x_snes.getRawVector());
SNESConvergedReason reason = SNES_CONVERGED_ITERATING;
SNESConvergedReason reason;
SNESGetConvergedReason(_snes_solver, &reason);
INFO("PETSsSNES convergence reason {}.", reason);
printConvergenceReason(_snes_solver, reason);
PetscInt iterations;
SNESGetIterationNumber(_snes_solver, &iterations);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment