ngsPETSc.snes
=============

.. py:module:: ngsPETSc.snes

.. autoapi-nested-parse::

   This module contains all the functions related to the PETSc SNES



Classes
-------

.. autoapisummary::

   ngsPETSc.snes.NonLinearSolver


Module Contents
---------------

.. py:class:: 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

   :arg fes: the finite element space over which the non-linear problem
             is defined

   :arg a: the variational form representing the non-linear problem

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

   :arg jacobian: If True, adds a Jacobian callback to SNES


   .. py:attribute:: fes


   .. py:attribute:: snes


   .. py:attribute:: a
      :value: None



   .. py:attribute:: use_jacobian
      :value: False



   .. py:attribute:: jacobianMatType


   .. py:attribute:: vectorMapping


   .. py:attribute:: workgf


   .. py:method:: solve(x0=None, f=None)

      This method solves the non-linear problem

      :arg x0: optional NGSolve grid function representing the initial guess
      :arg x0: optional NGSolve grid function representing the affine part of the rhs



   .. py:method:: petscResidual(_snes, x, f)

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

      :arg snes: PETSc SNES object representing the non-linear solver

      :arg x: current guess of the solution as a PETSc Vec

      :arg f: residual function as PETSc Vec



   .. py:method:: petscObjective(_snes, x)

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

      :arg snes: PETSc SNES object representing the non-linear solver

      :arg x: current guess of the solution as a PETSc Vec



   .. py:method:: petscJacobian(_snes, x, J, P)

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

      :arg snes: PETSc SNES object representing the non-linear solver

      :arg x: current guess of the solution as a PETSc Vec

      :arg J: Jacobian computed at x as a PETSc Mat

      :arg P: preconditioner for the Jacobian computed at x
              as a PETSc Mat



   .. py:method:: objective(x)

      Default callback for the objective of the non-linear problem

      :arg x: current iterate as an NGSolve grid function

      :return: the energy



   .. py:method:: residual(x, f)

      Default callback for the residual of the non-linear problem

      :arg x: current iterate as an NGSolve grid function

      :arg f: residual as as an NGSolve grid function




   .. py:method:: jacobian(x)

      Default callback for the Jacobian of the non-linear problem

      :arg x: current iterate as an NGSolve grid function

      :return: the Jacobian as an NGSolve matrix



