# 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, residual=None, objective=None, jacobian=None, 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 reppresenting the non-linear problem

    - residual – callback to the residual for the non-linear solver, this fuction is used only if the argument a is None.

    - objective – callback to the objective for the non-linear solver, this fuction is used only if the argument a is None, if False the PETSSc default is norm 2.

    - jacobian – callback to the Jacobian for the non-linear solver, this fuction is used only if the argument a is None.

  fes
  second_order = False
  snes
  vectorMapping
  setup(x0)

    This is method is used to setup the PETSc SNES object

    Parameters:

      x0 – NGSolve grid function reppresenting the initial guess

  solve(x0)

    This is method solves the non-linear problem

    Parameters:

      x0 – NGSolve grid function reppresenting the initial guess

  petscResidual(snes, x, f)

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

    Parameters:

      - snes – PETSc SNES object reppresenting the non-linear solver

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

      - f – residual function as PETSc Vec

  abstract residual()

    Callback to the residual of the non-linear problem

    Parameters:

      x – current guess of the solution as a PETSc Vec

    Returns:

      the residual as an NGSolve grid function

  petscObjective(snes, x)

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

    Parameters:

      - snes – PETSc SNES object reppresenting the non-linear solver

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

      - energy – energy as a PETSc Scalar

  abstract objective()

    Callback to the objective of the non-linear problem

    Parameters:

      x – current guess of the solution as a PETSc Vec

    Returns:

      the energy

  petscJacobian(snes, x, J, P)

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

    Parameters:

      - snes – PETSc SNES object reppresenting 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

  abstract jacobian()

    Callback to the Jacobian of the non-linear problem

    Parameters:

      x – current guess of the solution as a PETSc Vec

    Returns:

      the Jacobian as an NGSolve matrix