dolfinx_adjoint.fem.forms module
- class dolfinx_adjoint.fem.forms.FormNode(object: Any, ufl_form: Form)
Bases:
AbstractNodeNode for the operation
dolfinx.fem.form().In order to compile the form from the ufl form in the forward pass, the ufl form needs to be saved in the node.
- object
The object that is being compiled.
- Type:
Any
- ufl_form
The ufl form that is being compiled.
- Type:
ufl.form.Form
- class dolfinx_adjoint.fem.forms.Form_Coefficient_Edge(predecessor: Node, successor: Node, ctx=None, input_value=None)
Bases:
EdgeEdge providing the adjoint equation for the derivative of the form with respect to a coefficient.
- calculate_adjoint()
The method provides the adjoint equation for the derivative of the form with respect to a coefficient.
Since the symbolic equations are available in the ufl form, the derivative can be calculated using the symbolic differentiation provided by UFL.
- Returns:
The accumulated gradient up to this point in the computational graph.
- Return type:
(PETSc.Vec)
- class dolfinx_adjoint.fem.forms.Form_Constant_Edge(predecessor: Node, successor: Node, ctx=None, input_value=None)
Bases:
EdgeEdge providing the adjoint equation for the derivative of the form with respect to a constant.
- calculate_adjoint()
The method provides the adjoint equation for the derivative of the form with respect to a constant.
Since the symbolic equations are available in the ufl form, the derivative can be calculated using the symbolic differentiation provided by UFL. However, the constant needs to be replaced by a function in order to use the UFL functionality.
- Returns:
The accumulated gradient up to this point in the computational graph.
- Return type:
(PETSc.Vec)
- dolfinx_adjoint.fem.forms.form(*args, **kwargs)
OVERLOADS:
dolfinx.fem.form(). Create a Form or an array of Forms.The overloaded function adds the functionality to keep track of the dependencies in the computational graph and the adjoint equations. The original functionality is kept.
- Parameters:
args – Arguments to
dolfinx.fem.assemble_scalar().kwargs – Keyword arguments to
dolfinx.fem.assemble_scalar().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:
Compiled finite element Form.
Note
When a form is compiled from a UFL form, the dependencies in the symbolic equation is lost. The resulting compiled form does not support symbolic differentiation. The graph and the custom edges are used to keep track of the dependencies and the adjoint equations.