Skip to content

WIP: Save Jacobian to file - #3464

Open
bendudson wants to merge 1 commit into
nextfrom
save-petsc-jacobian
Open

WIP: Save Jacobian to file#3464
bendudson wants to merge 1 commit into
nextfrom
save-petsc-jacobian

Conversation

@bendudson

Copy link
Copy Markdown
Contributor

Work in progress on utilities for saving the solver Jacobian.

  • PetscPreconditioner saves Jacobian using PETSc binary or ASCII format.
  • Solver saves metadata: A Jacobian global index offset field to the dmp files, and a JSON file with the variable information.
  • SNES solver outputs Jacobian if save_jacobian = true. An option jacobian_export_kind select whether the Jacobian is calculated using the nonlinear system being solved (that depends on timestep and scaling), the scaled RHS function (that depends on variable scaling), or the raw rhs function is saved.

- PetscPreconditioner saves Jacobian using PETSc binary or ASCII
  format.
- Solver saves metadata: A Jacobian global index offset field to
  the dmp files, and a JSON file with the variable information.
- SNES solver outputs Jacobian if `save_jacobian = true`.  An option
  `jacobian_export_kind` select whether the Jacobian is calculated using
  the nonlinear system being solved (that depends on timestep and
  scaling), the scaled RHS function (that depends on variable scaling),
  or the raw `rhs` function is saved.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

.withDefault("jacobian")),
jacobian_export_format((*options)["jacobian_export_format"]
.doc("Format for saved Jacobian matrices: binary, ascii")
.withDefault(PetscMatrixExportFormat::binary)) {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "PetscMatrixExportFormat" is directly included [misc-include-cleaner]

src/solver/impls/snes/snes.cxx:1:

+ #include "bout/petsc_preconditioner.hxx"


PetscErrorCode ComputeJacobianDefaultMaybeExport(SNES snes, Vec x1, Mat Jac, Mat Jac_new,
void* ctx) {
PetscErrorCode err = SNESComputeJacobianDefault(snes, x1, Jac, Jac_new, ctx);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: variable 'err' of type 'PetscErrorCode' (aka 'int') can be declared 'const' [misc-const-correctness]

Suggested change
PetscErrorCode err = SNESComputeJacobianDefault(snes, x1, Jac, Jac_new, ctx);
ctx) {const

Comment thread src/solver/solver.cxx

Field3D Solver::jacobianIndexBase(int localStart) { return globalIndex(localStart); }

std::vector<Solver::JacobianVariableMetadata> Solver::getJacobianMetadata2D() const {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "std::vector" is directly included [misc-include-cleaner]

src/solver/solver.cxx:59:

+ #include <vector>

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.

1 participant