-
Notifications
You must be signed in to change notification settings - Fork 104
Petsc solver updates #3226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Petsc solver updates #3226
Changes from all commits
4323aa5
210ce59
1ddf5b8
50764ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -165,6 +165,39 @@ PetscErrorCode PetscMonitor(TS ts, PetscInt UNUSED(step), PetscReal t, Vec X, vo | |||||
| PetscFunctionBegin; | ||||||
|
|
||||||
| auto* s = static_cast<PetscSolver*>(ctx); | ||||||
|
|
||||||
| if (s->diagnose) { | ||||||
| // Print diagnostic information. | ||||||
| // Using the same format at the SNES solver | ||||||
|
|
||||||
| SNESConvergedReason reason; | ||||||
| SNESGetConvergedReason(s->snes, &reason); | ||||||
|
|
||||||
| PetscReal timestep; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
| TSGetTimeStep(s->ts, ×tep); | ||||||
|
|
||||||
| // SNES failure counter is only reset when TSSolve is called | ||||||
| static PetscInt prev_snes_failures = 0; | ||||||
| PetscInt snes_failures; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'snes_failures' is not initialized [cppcoreguidelines-init-variables]
Suggested change
|
||||||
| TSGetSNESFailures(s->ts, &snes_failures); | ||||||
| snes_failures -= prev_snes_failures; | ||||||
| prev_snes_failures += snes_failures; | ||||||
|
|
||||||
| // Get number of iterations | ||||||
| int nl_its; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'nl_its' is not initialized [cppcoreguidelines-init-variables]
Suggested change
|
||||||
| SNESGetIterationNumber(s->snes, &nl_its); | ||||||
| int lin_its; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'lin_its' is not initialized [cppcoreguidelines-init-variables]
Suggested change
|
||||||
| SNESGetLinearSolveIterations(s->snes, &lin_its); | ||||||
|
|
||||||
| output.print("\r"); // Carriage return for printing to screen | ||||||
| output.write("Time: {}, timestep: {}, nl iter: {}, lin iter: {}, reason: {}", t, | ||||||
| timestep, nl_its, lin_its, static_cast<int>(reason)); | ||||||
| if (snes_failures > 0) { | ||||||
| output.write(", SNES failures: {}", snes_failures); | ||||||
| } | ||||||
| output.write("\n"); | ||||||
| } | ||||||
|
|
||||||
| if (t < s->next_output) { | ||||||
| // Not reached output time yet => return | ||||||
| PetscFunctionReturn(0); | ||||||
|
|
@@ -903,8 +936,19 @@ PetscErrorCode PetscSolver::rhs(BoutReal t, Vec udata, Vec dudata, bool linear) | |||||
| load_vars(const_cast<BoutReal*>(udata_array)); | ||||||
| VecRestoreArrayRead(udata, &udata_array); | ||||||
|
|
||||||
| // Call RHS function | ||||||
| run_rhs(t, linear); | ||||||
| try { | ||||||
| // Call RHS function | ||||||
| run_rhs(t, linear); | ||||||
| } catch (BoutException& e) { | ||||||
| // Simulation might fail, e.g. negative densities | ||||||
| // if timestep too large | ||||||
| output_warn.write("WARNING: BoutException thrown: {}\n", e.what()); | ||||||
|
|
||||||
| // Tell SNES that the input was out of domain | ||||||
| SNESSetFunctionDomainError(snes); | ||||||
| // Note: Returning non-zero error here leaves vectors in locked state | ||||||
| return 0; | ||||||
| } | ||||||
|
|
||||||
| // Save derivatives to PETSc | ||||||
| BoutReal* dudata_array; | ||||||
|
|
||||||
There was a problem hiding this comment.
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; ^