solvers#

class CustomNewtonProblem(quadrature_map, F, J, u, bcs, max_it=50, rtol=1e-08, atol=1e-08)[source]#

Bases: object

Custom implementation of the Newton method for QuadratureMap objects.

Parameters:
  • quadrature_map (dolfinx_materials.quadrature_map.QuadratureMap) – The abstract QuadratureMap object

  • F (Form) – Nonlinear residual form

  • J (Form) – Associated Jacobian form

  • u (fem.Function) – Unknown function representing the solution

  • bcs (list) – list of fem.dirichletbc

  • max_it (int, optional) – Maximum number of iterations, by default 50

  • rtol (float, optional) – Relative tolerance, by default 1e-8

  • atol (float, optional) – Absolute tolerance, by default 1e-8

solve(solver, print_steps=True, print_solution=True)[source]#

Solve method.

Parameters:
  • solver (KSP object) – PETSc KSP solver for the linear system

  • print_steps (bool, optional) – Print iteration info, by default True

  • print_solution (bool, optional) – Print convergence info, by default True

Returns:

  • converged (bool) – Convergence status

  • it (int) – Number of iterations to convergence

class NonlinearMaterialProblem(qmap, F, J, u, bcs)[source]#

Bases: NonlinearProblem

This class handles the definition of a nonlinear problem containing an abstract QuadratureMap object compatible with a dolfinx NewtonSolver.

Parameters:
  • qmap (dolfinx_materials.quadrature_map.QuadratureMap) – The abstract QuadratureMap object

  • F (Form) – Nonlinear residual form

  • J (Form) – Associated Jacobian form

  • u (fem.Function) – Unknown function representing the solution

  • bcs (list) – list of fem.dirichletbc

form(x)[source]#

This function is called before the residual or Jacobian is computed. This is usually used to update ghost values.

Parameters:

x – The vector containing the latest solution

solve(solver, print_solution=True)[source]#

Solve the problem

Parameters:
  • solver – Nonlinear solver object

  • print_solution (bool, optional) – Print convergence info, by default True

Returns:

  • converged (bool) – Convergence status

  • it (int) – Number of iterations to convergence

class SNESNonlinearMaterialProblem(qmap, F, J, u, bcs)[source]#

Bases: NonlinearMaterialProblem

This class handles the definition of a nonlinear problem containing an abstract QuadratureMap object compatible with a PETSc SNESSolver.

Parameters:
  • qmap (dolfinx_materials.quadrature_map.QuadratureMap) – The abstract QuadratureMap object

  • F (Form) – Nonlinear residual form

  • J (Form) – Associated Jacobian form

  • u (fem.Function) – Unknown function representing the solution

  • bcs (list) – list of fem.dirichletbc

F(snes, x, F)[source]#

Assemble residual vector.

J(snes, x, J, P)[source]#

Assemble Jacobian matrix.

solve(solver, print_solution=True)[source]#

Solve the problem

Parameters:
  • solver – Nonlinear solver object

  • print_solution (bool, optional) – Print convergence info, by default True

Returns:

  • converged (bool) – Convergence status

  • it (int) – Number of iterations to convergence