soupy.solver module

soupy.solver.nonlinearVariationalSolver

class soupy.solver.nonlinearVariationalSolver.NonlinearVariationalSolver(parameters=None)[source]

Bases: object

Solver for the nonlinear variational problem

\[\text{Find } u \in U \qquad r(u,v) = 0 \quad \forall v \in V\]

The user must provide the variational forms for the residual form, an initial guess, boundary conditions, and optionally, variational forms for the Jacobian and backtracking cost functional.

This wraps the dolfin.NonlinearVariationalProblem and dolfin.NonlinearVariationalSolver classes using a different function signature

Constructor:

Parameters:

parameters (dict) – Solver parameters for the dolfin.NonlinearVariationalSolver class

Class will update the default dolfin.NonlinearVariationalSolver parameters with the data in parameters if it is provided. Otherwise, default parameters will be used

solve(residual_form, u, bcs, J_form, form_compiler_parameters=None)[source]

Solve the nonlinear variational system

\[\text{Find } u \in U \qquad r(u,v) = 0 \quad \forall v \in V\]

given using the dolfin.NonlinearVariationalSolver with a supplied initial guess

Parameters:
  • residual_form – Variational form for the residual

  • u (dolfin.Function) – Initial guess for the solution and function used in residual_form

  • bcs (list) – List of boundary conditions

  • J_form – Variational form for the Jacobian of the residual

  • energy_form – Optional variational form for the energy functional. If supplied, uses this as the backtracking cost

  • form_compiler_parameters – Optional form compiler_parameters

soupy.solver.newtonBacktrackSolver

class soupy.solver.newtonBacktrackSolver.NewtonBacktrackSolver[source]

Bases: object

Backtracking Newton solver for the nonlinear variational system

\[\text{Find } u \in U \qquad r(u,v) = 0 \quad \forall v \in V\]

The user must provide the variational forms for the residual form, an initial guess, boundary conditions, and optionally, variational forms for the Jacobian and backtracking cost functional.

Initializes the NewtonBacktrackSolver with the following parameters.

  • rel_tolerance –> we converge when \(\|r\|_2/\|r_0\|_2 \leq\) rel_tolerance

  • abs_tolerance –> we converge when \(\|r\|_2 \leq\) abs_tolerance

  • maxximum_iterations –> maximum number of iterations

  • c_armijo –> Armijo constant for sufficient reduction

  • max_backtracking_iter –> Maximum number of backtracking iterations

  • print_level –> Print info on screen

solve(residual_form, u, bcs=None, J_form=None, energy_form=None, solver=None)[source]

Solve the nonlinear variational system

\[\text{Find } u \in U \qquad r(u,v) = 0 \quad \forall v \in V\]

given using a backtracking Newton method with supplied initial guess

Parameters:
  • residual_form – Variational form for the residual

  • u (dolfin.Function) – Initial guess for the solution and funciton used in residual_form

  • bcs (list) – List of boundary conditions

  • J_form – Variational form for the Jacobian of the residual

  • energy_form – Optional variational form for the energy functional. If supplied, uses this as the backtracking cost

  • solver – Optional linear solver with method solve(A, x, b) Will initialize a solver if solver is None.

termination_reasons = ['Maximum number of Iteration reached', 'Norm of the gradient less than tolerance', 'Maximum number of backtracking reached', 'Norm of (g, da) less than tolerance']
soupy.solver.newtonBacktrackSolver.apply_BC(bcs, u)[source]

Applies a single or a list of dolfin.DirichletBC to the vector u

soupy.solver.newtonBacktrackSolver.homogenize_BC(bcs)[source]

Converts a single or a list of dolfin.DirichletBC to their homogenized (zeroed) forms

soupy.solver.PETScLUSolver

class soupy.solver.PETScLUSolver.PETScLUSolver(mpi_comm=mpi4py.MPI.COMM_WORLD, method='mumps')[source]

Bases: object

LU solver for linear systems \(Ax = b\) and \(A^Tx = b\). It is a wrapper for dolfin.PETScLUSolver providing custom implementations for methods solve_transpose and set_operator if they are unavailable in the dolfin version being used.

Constructor:

Parameters:
  • mpi_comm (MPI.Comm) – MPI Communicator for the linear system

  • method (str) – LU method

set_operator(A)[source]

Set the linear operator

Parameters:

A (dolfin.Matrix or dolfin.PETScMatrix) – Matrix for the solves

solve(x, b)[source]

Solve the linear system \(Ax = b\) and stores result to x

Parameters:
  • x (dolfin.Vector or dolfin.PETScVector) – Solution vector

  • b (dolfin.Vector or dolfin.PETScVector) – Right hand side vector

solve_transpose(x, b)[source]

Solve the linear system \(A^T x = b\) and stores result to x

Parameters:
  • x (dolfin.Vector or dolfin.PETScVector) – Solution vector

  • b (dolfin.Vector or dolfin.PETScVector) – Right hand side vector