Skip to content

Conversation

@bendudson
Copy link
Contributor

Improvements to the petsc time integration solver interface:

  1. Catch exceptions in run_rhs, telling SNES that the solution is out of domain. This should cause PETSc to reject the timestep. Previously some processors would stop and others would hang.

  2. Add output diagnostic compatible with snes. If solver:diagnose=true then BOUT++ will now output a line that has the same format at the lines printed by the snes BOUT++ solver. This should enable the log parser to work.

If run_rhs throws an exception then it should be caught, and SNES
notified that an error occurred.
If solver:diagnose is set then a line will be printed for
each internal (TS) step. The format is the same as the `snes`
solver, so the same post-processing scripts can be used.
@bendudson bendudson requested a review from mikekryjak December 5, 2025 20:24
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

// Print diagnostic information.
// Using the same format at the SNES solver

SNESConvergedReason reason;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'reason' is not initialized [cppcoreguidelines-init-variables]

    SNESConvergedReason reason;
                        ^

SNESConvergedReason reason;
SNESGetConvergedReason(s->snes, &reason);

PetscReal timestep;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'timestep' is not initialized [cppcoreguidelines-init-variables]

src/solver/impls/petsc/petsc.cxx:48:

- #include <petsc.h>
+ #include <math.h>
+ #include <petsc.h>
Suggested change
PetscReal timestep;
PetscReal timestep = NAN;


// SNES failure counter is only reset when TSSolve is called
static PetscInt prev_snes_failures = 0;
PetscInt snes_failures;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'snes_failures' is not initialized [cppcoreguidelines-init-variables]

Suggested change
PetscInt snes_failures;
PetscInt snes_failures = 0;

prev_snes_failures += snes_failures;

// Get number of iterations
int nl_its;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'nl_its' is not initialized [cppcoreguidelines-init-variables]

Suggested change
int nl_its;
int nl_its = 0;

// Get number of iterations
int nl_its;
SNESGetIterationNumber(s->snes, &nl_its);
int lin_its;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'lin_its' is not initialized [cppcoreguidelines-init-variables]

Suggested change
int lin_its;
int lin_its = 0;

Calls to run_rhs may throw an exception if given out of domain
values. Catch and return error code if this happens.
@bendudson bendudson merged commit 1523a7e into next Dec 19, 2025
25 of 27 checks passed
@bendudson bendudson deleted the petsc-solver-updates branch December 19, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants