ngsPETSc.snes

This module contains all the functions related to the PETSc SNES

Classes

NonLinearSolver

This class creates a PETSc Non-Linear Solver (SNES) from a callback to

Module Contents

class ngsPETSc.snes.NonLinearSolver(fes, a=None, use_objective=False, use_jacobian=True, solverParameters={}, optionsPrefix='')

This class creates a PETSc Non-Linear Solver (SNES) from a callback to a NGSolve residual vector

Parameters:
  • fes – the finite element space over which the non-linear problem is defined

  • a – the variational form representing the non-linear problem

  • objective – If True, adds a objective function callback to SNES If False the PETSc default is norm 2.

  • jacobian – If True, adds a Jacobian callback to SNES

fes
snes
a = None
use_jacobian = False
jacobianMatType
vectorMapping
workgf
solve(x0=None, f=None)

This method solves the non-linear problem

Parameters:
  • x0 – optional NGSolve grid function representing the initial guess

  • x0 – optional NGSolve grid function representing the affine part of the rhs

petscResidual(_snes, x, f)

This method is used to wrap the callback for the residual in a PETSc compatible way

Parameters:
  • snes – PETSc SNES object representing the non-linear solver

  • x – current guess of the solution as a PETSc Vec

  • f – residual function as PETSc Vec

petscObjective(_snes, x)

This method is used to wrap the callback for the objective in a PETSc compatible way

Parameters:
  • snes – PETSc SNES object representing the non-linear solver

  • x – current guess of the solution as a PETSc Vec

petscJacobian(_snes, x, J, P)

This method is used to wrap the callback for the Jacobian in a PETSc compatible way

Parameters:
  • snes – PETSc SNES object representing the non-linear solver

  • x – current guess of the solution as a PETSc Vec

  • J – Jacobian computed at x as a PETSc Mat

  • P – preconditioner for the Jacobian computed at x as a PETSc Mat

objective(x)

Default callback for the objective of the non-linear problem

Parameters:

x – current iterate as an NGSolve grid function

Returns:

the energy

residual(x, f)

Default callback for the residual of the non-linear problem

Parameters:
  • x – current iterate as an NGSolve grid function

  • f – residual as as an NGSolve grid function

jacobian(x)

Default callback for the Jacobian of the non-linear problem

Parameters:

x – current iterate as an NGSolve grid function

Returns:

the Jacobian as an NGSolve matrix