cashocs.nonlinear_solvers.snes#

Interface for the PETSc SNES solver for nonlinear equations.

Functions

snes_solve(nonlinear_form, u, bcs[, ...])

Solve a nonlinear PDE problem with PETSc SNES.

Classes

SNESSolver(nonlinear_form, u, bcs[, ...])

Interface for using PETSc's SNES solver.

class cashocs.nonlinear_solvers.snes.SNESSolver(nonlinear_form, u, bcs, derivative=None, petsc_options=None, shift=None, rtol=None, atol=None, max_iter=None, A_tensor=None, b_tensor=None, preconditioner_form=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 (Union[fenics.DirichletBC, List[fenics.DirichletBC]]) – A list of DirichletBCs for the nonlinear variational problem.

  • derivative (Optional[ufl.Form]) – 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 (Optional[_typing.KspOption]) – The options for PETSc SNES object.

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

  • rtol (Optional[float]) – Relative tolerance of the solver. Overrides the specification in the petsc_options.

  • atol (Optional[float]) – Absolute tolerance of the solver. Overrides the specification in the petsc_options.

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

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

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

  • preconditioner_form (Optional[ufl.Form]) – A UFL form which defines the preconditioner matrix.

assemble_function(snes, x, f)[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, x, J, P)[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

solve()[source]#

Solves the nonlinear problem with PETSc’s SNES.

Return type:

fenics.Function

cashocs.nonlinear_solvers.snes.snes_solve(nonlinear_form, u, bcs, derivative=None, petsc_options=None, shift=None, rtol=None, atol=None, max_iter=None, A_tensor=None, b_tensor=None, preconditioner_form=None)[source]#

Solve a nonlinear PDE problem with PETSc SNES.

An overview over possible PETSc command line options for the SNES can be found at https://petsc.org/release/manualpages/SNES/.

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 (Union[fenics.DirichletBC, List[fenics.DirichletBC]]) – A list of DirichletBCs for the nonlinear variational problem.

  • derivative (Optional[ufl.Form]) – 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 (Optional[_typing.KspOption]) – The options for PETSc SNES object.

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

  • rtol (Optional[float]) – Relative tolerance of the solver (default is rtol = 1e-10).

  • atol (Optional[float]) – Absolute tolerance of the solver (default is atol = 1e-10).

  • max_iter (Optional[int]) – Maximum number of iterations carried out by the method (default is max_iter = 50).

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

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

  • preconditioner_form (Optional[ufl.Form]) – A UFL form which defines the preconditioner matrix.

Returns:

The solution in form of a FEniCS Function.

Return type:

fenics.Function