Skip to content

SNES solver interface for standard, block and nest systems #3648

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

Open
wants to merge 87 commits into
base: main
Choose a base branch
from

Conversation

jorgensd
Copy link
Member

@jorgensd jorgensd commented Feb 24, 2025

A "functional" approach to the snes problem interface.
This reduced the code to:

  • One factory function: create_snes_solver, that returns the the user a SNESObject and a vector to solve into x
  • A SNESSolver, that handles destruction of PETSc objects. It also store convenient wrappers to transfer data from your dolfinx.fem.Function|list[dolfinx.fem.Function (u) to the PETSc vector used for solving (x)

The tests now show examples of:

  1. How to use SNESSolver, the highest level interface
  2. How to use create_snes_solver, the mid-level interface
  3. How to use the functions supplied in dolfinx.nls.petsc and dolfinx.fem.petsc to interact with your own snes solver instance.

@jhale
Copy link
Member

jhale commented Mar 6, 2025

My impression is that we should first tackle the comment made by @garth-wells https://github.com/FEniCS/dolfinx/pull/3648/files#r1973997836 in a separate PR.

This can then be refactored to use #3659 which should remove many of the if statements regarding assigning functions to vectors and vice-versa. We can then think about if there are any smart ways to deal with Mat and Vec types in the SNES solver setup.

jorgensd and others added 2 commits May 19, 2025 09:45
* Unify assemble_residual

* Ruff format

* Fix imports

* Add back comma

* Move assignment of block data out of assembler

* Ignore type-hints
@jhale
Copy link
Member

jhale commented May 20, 2025

I propose I code some further adjustments:

  • API change: SNESSolver immediately becomes NonlinearProblem, i.e. a high level class that wraps SNES, as LinearProblem is a high level class that wraps KSP.
  • API change: Current NonlinearProblem becomes NewtonSolverNonlinearProblem and is marked as deprecated.
  • API change: Python NewtonSolver is marked as deprecated.
  • compute_jacobian has name changed and documentation string added.
  • Consider further factoring into private functions in assemble_residual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants