cashocs.nonlinear_solvers.snes.SNESSolver#

class cashocs.nonlinear_solvers.snes.SNESSolver(
nonlinear_form: ufl.Form,
u: fenics.Function,
bcs: fenics.DirichletBC | list[fenics.DirichletBC],
derivative: ufl.Form | None = None,
petsc_options: _typing.KspOption | None = None,
shift: ufl.Form | None = None,
rtol: float | None = None,
atol: float | None = None,
max_iter: int | None = None,
A_tensor: fenics.PETScMatrix | None = None,
b_tensor: fenics.PETScVector | None = None,
preconditioner_form: ufl.Form | None = None,
)[source]#

Bases: object

Interface for using PETSc’s SNES solver.

Initialize the SNES solver.

Parameters:
  • nonlinear_form (ufl.Form) – The variational form of the nonlinear problem to be solved by Newton’s method.

  • u (fenics.Function) – The sought solution / initial guess. It is not assumed that the initial guess satisfies the Dirichlet boundary conditions, they are applied automatically. The method overwrites / updates this Function.

  • bcs (fenics.DirichletBC | list[fenics.DirichletBC]) – A list of DirichletBCs for the nonlinear variational problem.

  • derivative (ufl.Form | None) – The Jacobian of nonlinear_form, used for the Newton method. Default is None, and in this case the Jacobian is computed automatically with AD.

  • petsc_options (_typing.KspOption | None) – The options for PETSc SNES object.

  • shift (ufl.Form | None) – A shift term, if the right-hand side of the nonlinear problem is not zero, but shift.

  • rtol (float | None) – Relative tolerance of the solver. Overrides the specification in the petsc_options.

  • atol (float | None) – Absolute tolerance of the solver. Overrides the specification in the petsc_options.

  • max_iter (int | None) – Maximum number of iterations carried out by the method. Overrides the specification in the petsc_options.

  • A_tensor (fenics.PETScMatrix | None) – A fenics.PETScMatrix for storing the left-hand side of the linear sub-problem.

  • b_tensor (fenics.PETScVector | None) – A fenics.PETScVector for storing the right-hand side of the linear sub-problem.

  • preconditioner_form (ufl.Form | None) – A UFL form which defines the preconditioner matrix.

Methods Summary

assemble_function(snes, x, f)

Interface for PETSc SNESSetFunction.

assemble_jacobian(snes, x, J, P)

Interface for PETSc SNESSetJacobian.

monitor(snes, its, norm)

The monitoring function for the SNES solver.

solve()

Solves the nonlinear problem with PETSc's SNES.

Methods Documentation

assemble_function(
snes: petsc4py.PETSc.SNES,
x: petsc4py.PETSc.Vec,
f: petsc4py.PETSc.Vec,
) None[source]#

Interface for PETSc SNESSetFunction.

Parameters:
  • snes (petsc4py.PETSc.SNES) – The SNES solver

  • x (petsc4py.PETSc.Vec) – The current iterate

  • f (petsc4py.PETSc.Vec) – The vector in which the function evaluation is stored.

Return type:

None

assemble_jacobian(
snes: petsc4py.PETSc.SNES,
x: petsc4py.PETSc.Vec,
J: petsc4py.PETSc.Mat,
P: petsc4py.PETSc.Mat,
) None[source]#

Interface for PETSc SNESSetJacobian.

Parameters:
  • snes (petsc4py.PETSc.SNES) – The SNES solver.

  • x (petsc4py.PETSc.Vec) – The current iterate.

  • J (petsc4py.PETSc.Mat) – The matrix storing the Jacobian.

  • P (petsc4py.PETSc.Mat) – The matrix storing the preconditioner for the Jacobian.

Return type:

None

monitor(
snes: petsc4py.PETSc.SNES,
its: int,
norm: float,
) None[source]#

The monitoring function for the SNES solver.

Parameters:
  • snes (petsc4py.PETSc.SNES) – The SNES solver.

  • its (int) – The current iteration.

  • norm (float) – The current residual norm.

Return type:

None

solve() fenics.Function[source]#

Solves the nonlinear problem with PETSc’s SNES.

Return type:

fenics.Function