Warning

You are reading a version of the website built against the unstable main branch. This content is liable to change without notice and may be inappropriate for your use case. You can find the documentation for the current stable release here.

firedrake.external_operators package

Submodules

firedrake.external_operators.abstract_external_operators module

class firedrake.external_operators.abstract_external_operators.AbstractExternalOperator(*operands, function_space, derivatives=None, argument_slots=(), operator_data=None)[source]

Bases: ExternalOperator

assemble(assembly_opts=None)[source]

External operator assembly

Parameters:

assembly_opts (dict) – Dictionary containing assembly options of the finite element assembly, which may be of interest for the assembly methods of the external operator subclass. These options are passed on to the assembly methods of the external operator subclass.

Returns:

The result of assembling the external operator.

Return type:

firedrake.function.Function or firedrake.cofunction.Cofunction or firedrake.matrix.MatrixBase

Notes

More information can be found at www.firedrakeproject.org/external_operators.html#assembly.

assemble_method(args)[source]

Decorator helper function to specify the type of external operator type associated with each assembly methods.

The \(assemble_method\) decorator is used to specify the type of external operator associated with the assembly methods of the external operator subclass. Each assembly method must be decorated with \(assemble_method\). The role of this decorator is to record the assembly methods of the subclass. The type of external operator is fully specified via the derivative multi-index and a tuple representing the argument slots of the external operator.

Parameters:
  • derivs (tuple) – Derivative multi-index of the external operator associated with the assembly method decorated.

  • args (tuple) – Tuple representing the argument slots of the external operator, i.e. \(self.argument_slots()\), in which integers stand for the numbers of the arguments of type Argument or Coargument, and \(None\) stands for arguments of type Function or Cofunction.

Notes

More information can be found at www.firedrakeproject.org/external_operators.html#build-your-own-external-operator.

assembly_method()[source]

Return the assembly method of this external operator, or None if there is none.

Returns:

The method registered with assemble_method() for the derivatives and the argument slots of this operator.

Return type:

Callable or None

function_space()[source]
ufl_operands
class firedrake.external_operators.abstract_external_operators.AssemblyRegisterMetaClass(name, bases, attrs)[source]

Bases: UFLType

Metaclass registering assembly methods specified by external operator subclasses.

This metaclass is used to register assembly methods specified by subclasses of AbstractExternalOperator. For any new external operator subclass, AssemblyRegisterMetaClass will collect all assembly methods specified by the subclass and construct a registry to map from assembly identifiers, specified via the \(assemble_method\) decorator to the corresponding assembly methods, and attach that registry to the subclass.

Notes

This metaclass subclasses \(UFLType\) to avoid metaclass conflict for AbstractExternalOperator.

firedrake.external_operators.abstract_external_operators.assemble_method(derivs, args)

Decorator helper function to specify the type of external operator type associated with each assembly methods.

The \(assemble_method\) decorator is used to specify the type of external operator associated with the assembly methods of the external operator subclass. Each assembly method must be decorated with \(assemble_method\). The role of this decorator is to record the assembly methods of the subclass. The type of external operator is fully specified via the derivative multi-index and a tuple representing the argument slots of the external operator.

Parameters:
  • derivs (tuple) – Derivative multi-index of the external operator associated with the assembly method decorated.

  • args (tuple) – Tuple representing the argument slots of the external operator, i.e. \(self.argument_slots()\), in which integers stand for the numbers of the arguments of type Argument or Coargument, and \(None\) stands for arguments of type Function or Cofunction.

Notes

More information can be found at www.firedrakeproject.org/external_operators.html#build-your-own-external-operator.

firedrake.external_operators.ml_operator module

class firedrake.external_operators.ml_operator.MLOperator(*operands, function_space, derivatives=None, argument_slots=(), operator_data)[source]

Bases: AbstractExternalOperator

assemble_jacobian(*args, **kwargs)[source]

Assemble the Jacobian using the AD engine of the ML framework.

assemble_jacobian_action(*args, **kwargs)[source]

Assemble the Jacobian action using the AD engine of the ML framework.

assemble_jacobian_adjoint(*args, **kwargs)[source]

Assemble the Jacobian Hermitian transpose using the AD engine of the ML framework.

assemble_jacobian_adjoint_action(*args, **kwargs)[source]

Assemble the action of the Jacobian adjoint using the AD engine of the ML framework.

assemble_model(*args, **kwargs)[source]

Assemble the operator via a forward pass through the ML model.

property inputs_format
property model
ufl_operands

firedrake.external_operators.point_expr_operator module

class firedrake.external_operators.point_expr_operator.PointexprOperator(*operands, function_space, derivatives=None, argument_slots=(), operator_data)[source]

Bases: AbstractExternalOperator

assemble_Jacobian(*args, assembly_opts, **kwargs)[source]
assemble_Jacobian_action(*args, **kwargs)[source]
assemble_Jacobian_adjoint(*args, assembly_opts, **kwargs)[source]
assemble_Jacobian_adjoint_action(*args, **kwargs)[source]
assemble_operator(*args, **kwargs)[source]
property expr
ufl_operands
firedrake.external_operators.point_expr_operator.point_expr(point_expr, function_space)[source]

Helper function for instantiating the PointexprOperator class.

This function facilitates having a two-stage instantiation which dissociates between class arguments that are fixed, such as the function space and the input function, and the operands of the operator, which may change, e.g. when the operator is used in a time-loop.

Example

# Stage 1: Partially initialise the operator.
N = point_expr(lambda x, y: x - y, function_space=V)
# Stage 2: Define the operands and use the operator in a UFL expression.
F = (inner(grad(u), grad(v)) + inner(N(u, f), v)) * dx
Parameters:
Returns:

The partially initialised PointexprOperator class.

Return type:

collections.abc.Callable

Module contents