dolfinx_adjoint.fem.petsc module
- dolfinx_adjoint.fem.petsc.AdjointProblemSolver(A: Mat, b: Vec, x: Function, bcs=None)
Linear solver using PETSc as a linear algebra backend for the adjoint equations.
- Parameters:
A (PETSc.Mat) – The matrix of the adjoint equation.
b (PETSc.Vec) – The right-hand side of the adjoint equation.
x (fem.Function) – The solution of the adjoint equation.
bcs (list) – The boundary conditions of the adjoint equation.
- Returns:
The solution of the adjoint equation.
- Return type:
(fem.Function)
- class dolfinx_adjoint.fem.petsc.LinearProblem(*args, **kwargs)
Bases:
LinearProblemOVERLOADS:
dolfinx.fem.petsc.LinearProblem. Linear problem class for solving the linear problemThe overloaded class modifies the initialization of the LinearProblem to keep track of the dependencies in the computational graph and the adjoint equations. The original functionality is kept.
- solve(*args, **kwargs)
OVERLOADS:
dolfinx.fem.petsc.LinearProblem.solve()Solve linear problem into function u. Returns the number of iterations and if the solver converged.- Parameters:
args – Arguments to
dolfinx.fem.petsc.LinearProblem.solve()kwargs – Keyword arguments to
dolfinx.fem.petsc.LinearProblem.solve()graph (graph, optional) – An additional keyword argument to specifier whether the assemble operation should be added to the graph. If not present, the original functionality of dolfinx is used without any additional functionalities.
- Returns:
The solution function u after solving the linear problem.
- Return type:
fem.Function
- class dolfinx_adjoint.fem.petsc.LinearProblemNode(object: Any, a: Form, L: Form, **kwargs)
Bases:
AbstractNodeNode for the initialization of
dolfinx.fem.petsc.LinearProblem.
- class dolfinx_adjoint.fem.petsc.NewtonSolverNonlinearProblem(*args, **kwargs)
Bases:
NewtonSolverNonlinearProblemOVERLOADS:
dolfinx.fem.petsc.NewtonSolverNonlinearProblem. Nonlinear problem class for solving the non-linear problemThe overloaded class modifies the initialization of the NewtonSolverNonlinearProblem to keep track of the dependencies in the computational graph and the adjoint equations. The original functionality is kept.
- class dolfinx_adjoint.fem.petsc.NewtonSolverNonlinearProblemNode(object: Any, F: Form, u: Function, **kwargs)
Bases:
AbstractNodeNode for the initialization of
dolfinx.fem.petsc.NewtonSolverNonlinearProblem.
- class dolfinx_adjoint.fem.petsc.NonlinearProblem(*args, **kwargs)
Bases:
NonlinearProblemOVERLOADS:
dolfinx.fem.petsc.NonlinearProblem. Nonlinear problem class for solving the non-linear problemThe overloaded class modifies the initialization of the NonlinearProblem to keep track of the dependencies in the computational graph and the adjoint equations. The original functionality is kept.
- solve(*args, **kwargs)
OVERLOADS:
dolfinx.fem.petsc.NonlinearProblem.solve()Solve non-linear problem into function u. Returns the number of iterations and if the solver converged.- Parameters:
args – Arguments to
dolfinx.fem.petsc.NonlinearProblem.solve()kwargs – Keyword arguments to
dolfinx.fem.petsc.NonlinearProblem.solve()graph (graph, optional) – An additional keyword argument to specifier whether the assemble operation should be added to the graph. If not present, the original functionality of dolfinx is used without any additional functionalities.
- Returns:
The solution function u after solving the nonlinear problem.
- Return type:
fem.Function
- class dolfinx_adjoint.fem.petsc.NonlinearProblemNode(object: Any, F: Form, u: Function, **kwargs)
Bases:
AbstractNodeNode for the initialization of
dolfinx.fem.petsc.NonlinearProblem.
- class dolfinx_adjoint.fem.petsc.NonlinearProblem_Boundary_Edge(predecessor: Node, successor: Node, ctx=None, input_value=None)
Bases:
EdgeEdge providing the adjoint equation for the derivative of the solution to the nonlinear problem with respect to the boundary condition.
- calculate_adjoint()
The method provides the adjoint equation for the derivative of the solution to the nonlinear problem with respect to the boundary condition.
- By taking the derivative of F(u) = 0 with respect to a boundary condition g, we obtain a representation of du/dg:
dF/dg = ∂F/∂u * du/dg + ∂F/∂g = 0 => du/dg = -(∂F/∂u)^-1 * ∂F/∂g
- By using the accumulated input gradient x the adjoint equation is calculated as:
(∂F/∂u)ᵀ λ = -xᵀ
- The accumulated gradient is defined by:
λᵀ * ∂F/∂g
- Returns:
The accumulated gradient up to this point in the computational graph.
- Return type:
(PETSc.Vec)
- class dolfinx_adjoint.fem.petsc.NonlinearProblem_Coefficient_Edge(predecessor: Node, successor: Node, ctx=None, input_value=None)
Bases:
EdgeEdge providing the adjoint equation for the derivative of the solution to the nonlinear problem with respect to the coefficient.
- calculate_adjoint()
The method provides the adjoint equation for the derivative of the solution to the nonlinear problem with respect to the coefficient.
- By taking the derivative of F(u) = 0 with respect to a coefficient f, we obtain a representation of du/df:
dF/df = ∂F/∂u * du/df + ∂F/∂f = 0 => du/df = -(∂F/∂u)^-1 * ∂F/∂f
- By using the accumulated input gradient x the adjoint equation is calculated as:
(∂F/∂u)ᵀ λ = -xᵀ
- The accumulated gradient is defined by:
λᵀ * ∂F/∂f
- Returns:
The accumulated gradient up to this point in the computational graph.
- Return type:
(PETSc.Vec)
- class dolfinx_adjoint.fem.petsc.NonlinearProblem_Constant_Edge(predecessor: Node, successor: Node, ctx=None, input_value=None)
Bases:
EdgeEdge providing the adjoint equation for the derivative of the solution to the nonlinear problem with respect to the constant.
- calculate_adjoint()
The method provides the adjoint equation for the derivative of the solution to the nonlinear problem with respect to the constant.
- By taking the derivative of F(u) = 0 with respect to a constant c, we obtain a representation of du/dc:
dF/dc = ∂F/∂u * du/dc + ∂F/∂c = 0 => du/dc = -(∂F/∂u)^-1 * ∂F/∂c
- By using the accumulated input gradient x the adjoint equation is calculated as:
(∂F/∂u)ᵀ λ = -xᵀ
- The accumulated gradient is defined by:
λᵀ * ∂F/∂c
- Returns:
The accumulated gradient up to this point in the computational graph.
- Return type:
(PETSc.Vec)