cashocs.nonlinear_solvers.newton_solver#

Newton solver for nonlinear PDEs.

Functions

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

Solves a nonlinear problem with Newton's method.

cashocs.nonlinear_solvers.newton_solver.newton_solve(nonlinear_form, u, bcs, derivative=None, shift=None, rtol=1e-10, atol=1e-10, max_iter=50, convergence_type='combined', norm_type='l2', damped=True, inexact=True, verbose=True, ksp_options=None, A_tensor=None, b_tensor=None, is_linear=False, preconditioner_form=None, linear_solver=None)[source]#

Solves a nonlinear problem with Newton's method.

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.

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

  • rtol (float) – Relative tolerance of the solver if convergence_type is either 'combined' or 'rel' (default is rtol = 1e-10).

  • atol (float) – Absolute tolerance of the solver if convergence_type is either 'combined' or 'abs' (default is atol = 1e-10).

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

  • convergence_type (Literal['combined', 'rel', 'abs']) – Determines the type of stopping criterion that is used.

  • norm_type (Literal['l2', 'linf']) – Determines which norm is used in the stopping criterion.

  • damped (bool) – If True, then a damping strategy is used. If False, the classical Newton-Raphson iteration (without damping) is used (default is True).

  • inexact (bool) – If True, an inexact Newton's method is used. Default is True.

  • verbose (bool) – If True, prints status of the iteration to the console (default is True).

  • ksp_options (Optional[_typing.KspOption]) – The list of options for the linear solver.

  • 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.

  • is_linear (bool) – A boolean flag, which indicates whether the problem is actually linear.

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

  • linear_solver (Optional[_utils.linalg.LinearSolver]) – The linear solver (KSP) which is used to solve the linear systems arising from the discretized PDE.

Returns:

The solution of the nonlinear variational problem, if converged. This overwrites the input function u.

Return type:

fenics.Function

Examples

Consider the problem

\[\begin{split}\begin{alignedat}{2} - \Delta u + u^3 &= 1 \quad &&\text{ in } \Omega=(0,1)^2 \\ u &= 0 \quad &&\text{ on } \Gamma. \end{alignedat}\end{split}\]

This is solved with the code

from fenics import *
import cashocs

mesh, _, boundaries, dx, _, _ = cashocs.regular_mesh(25)
V = FunctionSpace(mesh, 'CG', 1)

u = Function(function_space)
v = TestFunction(function_space)
F = inner(grad(u), grad(v))*dx + pow(u,3)*v*dx - Constant(1)*v*dx
bcs = cashocs.create_dirichlet_bcs(V, Constant(0.0), boundaries, [1,2,3,4])
cashocs.newton_solve(F, u, bcs)