ffcx.analysis#

Compiler stage 1: Analysis.

This module implements the analysis/preprocessing of variational forms, including automatic selection of elements, degrees and form representation type.

Functions

analyze_ufl_objects(ufl_objects, scalar_type)

Analyze ufl object(s).

check_interpolation(interpolation, argument)

Check that an interpolation holding an argument can be turned into a table.

check_proxy_targets(o)

Check that each interpolation of an expression lands in a supported space.

integral_sub_kernel_targets(itg_data)

Collect what needs a sub-kernel called in an integral.

interpolated_argument(interpolation)

Get the argument that an analysed interpolation maps directly, if it maps one.

interpolated_expression(interpolation)

Get the expression that an interpolation or proxy coefficient evaluates.

interpolation_arguments(interpolation)

Get the arguments that an interpolated expression is linear in, by number.

interpolation_has_runtime_table(interpolation)

Whether an interpolation's element table has to be built for each cell.

interpolation_target_space(interpolation)

Get the function space that an interpolation lands in.

required_coefficients(expression)

Get the coefficients that evaluating an expression reads, sorted by count.

required_constants(expression)

Get the constants that evaluating an expression reads, sorted by count.

sub_kernel_coefficients(target)

Get the coefficients that the sub-kernel of a proxy coefficient or an interpolation reads.

sub_kernel_constants(target)

Get the constants that the sub-kernel of a proxy coefficient or an interpolation reads.

sub_kernel_targets(expressions)

Collect what needs a sub-kernel called in the kernel of some expressions.

Classes

IntermediateCoefficientReplacer([processing])

Replace interpolations of an expression by proxy coefficients.

ProxyCoefficient(*args, **kw)

A coefficient that stands for an interpolation of an expression.

UFLData(form_data, unique_elements, ...)

UFL data.

class ffcx.analysis.IntermediateCoefficientReplacer(processing: _Processing | None = None)[source]#

Bases: DAGTraverser

Replace interpolations of an expression by proxy coefficients.

An interpolation holding an argument is left in place: it is a modified terminal, see ffcx.ir.analysis.modified_terminals. If it interpolates the argument itself, its operand is rewritten into the argument’s reference value, which interpolated_argument recognises from then on. Interpolations nested in the expression of a replaced one are left too, and replaced when that expression is compiled into a kernel of its own.

Initialise.

Parameters:

processing – How the expressions to replace in have been processed, to classify their interpolations by, or None if they have already been classified.

process(o: Expr) → Expr[source]#
process(o: Interpolate) → Expr
process(o: Expr) → Expr

Replace the interpolations of an expression.

Parameters:

o – The expression.

class ffcx.analysis.ProxyCoefficient(*args, **kw)[source]#

Bases: Coefficient

A coefficient that stands for an interpolation of an expression.

Its degrees of freedom are built in the kernel, by evaluating the expression at the interpolation points of the target element, see ffcx.codegeneration.interpolation.

Initialise.

Parameters:
  • V – The space interpolated into.

  • operator – The interpolation, of an expression already mapped onto the reference cell of the target element.

property operand: Expr#

The expression interpolated, on the reference cell of the target element.

property operator: Interpolate#

The interpolation that this proxy coefficient stands for.

class ffcx.analysis.UFLData(form_data: tuple[FormData, ...], unique_elements: list[basix.ufl._ElementBase], element_numbers: dict[basix.ufl._ElementBase, int], unique_coordinate_elements: list[basix.ufl._ElementBase], expressions: list[tuple[ufl.core.expr.Expr, npt.NDArray[np.floating], ufl.core.expr.Expr]], sub_kernels: dict[ProxyCoefficient | ufl.Interpolate, int])[source]#

Bases: NamedTuple

UFL data.

Create new instance of UFLData(form_data, unique_elements, element_numbers, unique_coordinate_elements, expressions, sub_kernels)

element_numbers: dict[basix.ufl._ElementBase, int]#

Mapping to unique numbers for all elements

expressions: list[tuple[ufl.core.expr.Expr, npt.NDArray[np.floating], ufl.core.expr.Expr]]#

List of all expressions after post-processing, with evaluation points and original expression

form_data: tuple[FormData, ...]#

FormData objects

sub_kernels: dict[ProxyCoefficient | ufl.Interpolate, int]#

The sub-kernel of each proxy coefficient, and of each interpolation whose table is built for each cell, as an index into expressions

unique_coordinate_elements: list[basix.ufl._ElementBase]#

Unique coordinate elements across all forms and expressions

unique_elements: list[basix.ufl._ElementBase]#

Unique elements across all forms and expressions

ffcx.analysis.analyze_ufl_objects(ufl_objects: list[Form | _ElementBase | Mesh | tuple[Expr, NDArray[floating]]], scalar_type: DTypeLike, do_cancel_jacobian_products: bool = True) → UFLData[source]#

Analyze ufl object(s).

Parameters:
  • ufl_objects – UFL objects

  • scalar_type – Scalar type that should be used for the analysis

  • do_cancel_jacobian_products – Whether to cancel jacobian products.

Returns:

A named tuple UFLData.

ffcx.analysis.check_interpolation(interpolation: Interpolate, argument: Argument | None) → None[source]#

Check that an interpolation holding an argument can be turned into a table.

Parameters:
  • interpolation – A ufl.Interpolate.

  • argument – The argument it maps directly, or None if it interpolates an expression merely linear in its arguments.

ffcx.analysis.check_proxy_targets(o: Form | Expr) → None[source]#

Check that each interpolation of an expression lands in a supported space.

Such an interpolation becomes a ProxyCoefficient, whose dofs are built by ffcx.codegeneration.interpolation. This is checked before UFL maps the interpolations onto their reference cells. An interpolation holding an argument is checked by check_interpolation once it is classified.

Parameters:

o – A form or an expression, as given.

ffcx.analysis.integral_sub_kernel_targets(itg_data: IntegralData) → list[ProxyCoefficient | Interpolate][source]#

Collect what needs a sub-kernel called in an integral.

See sub_kernel_targets. The proxy coefficients come first, ordered by count, which is also the order they are numbered in within the kernel.

Parameters:

itg_data – The integral data of a form analysed by _analyze_form, whose integrands hold the proxy coefficients.

ffcx.analysis.interpolated_argument(interpolation: Interpolate) → Argument | None[source]#

Get the argument that an analysed interpolation maps directly, if it maps one.

The analysis rewrites the operand of each interpolation of an argument itself into the argument’s reference value, see _classify_interpolation, so after it this is an exact comparison.

Parameters:

interpolation – A ufl.Interpolate, from an analysed form or expression.

Returns:

The argument, or None if the operand is not its reference value.

ffcx.analysis.interpolated_expression(interpolation: ProxyCoefficient | Interpolate) → Expr[source]#

Get the expression that an interpolation or proxy coefficient evaluates.

Parameters:

interpolation – A ProxyCoefficient or a ufl.Interpolate.

ffcx.analysis.interpolation_arguments(interpolation: ProxyCoefficient | Interpolate) → tuple[Argument, ...][source]#

Get the arguments that an interpolated expression is linear in, by number.

Parameters:

interpolation – A ProxyCoefficient or a ufl.Interpolate.

ffcx.analysis.interpolation_has_runtime_table(interpolation: Interpolate) → bool[source]#

Whether an interpolation’s element table has to be built for each cell.

Interpolating an argument itself is a fixed map between the reference elements, so the table is known at compile time. Interpolating an expression that is merely linear in the argument, as differentiating a non-linear interpolated expression produces, brings in coefficients, so the table depends on the cell.

Parameters:

interpolation – A ufl.Interpolate, from an analysed form or expression.

ffcx.analysis.interpolation_target_space(interpolation: ProxyCoefficient | Interpolate) → FunctionSpace[source]#

Get the function space that an interpolation lands in.

Parameters:

interpolation – A ProxyCoefficient or a ufl.Interpolate.

ffcx.analysis.required_coefficients(expression: Expr) → list[Coefficient][source]#

Get the coefficients that evaluating an expression reads, sorted by count.

A proxy coefficient is built from the coefficients of the expression it interpolates, so it stands for those rather than for itself.

Parameters:

expression – An expression.

ffcx.analysis.required_constants(expression: Expr) → list[Constant][source]#

Get the constants that evaluating an expression reads, sorted by count.

Parameters:

expression – An expression.

ffcx.analysis.sub_kernel_coefficients(target: ProxyCoefficient | Interpolate) → list[Coefficient][source]#

Get the coefficients that the sub-kernel of a proxy coefficient or an interpolation reads.

They are passed to the kernel in this order. They are taken from the expression as given rather than as compiled, which may have lost some, so that two proxies that differ only in their coefficients share one kernel.

Parameters:

target – A ProxyCoefficient, or a ufl.Interpolate whose table is built for each cell.

ffcx.analysis.sub_kernel_constants(target: ProxyCoefficient | Interpolate) → list[Constant][source]#

Get the constants that the sub-kernel of a proxy coefficient or an interpolation reads.

They are passed to the kernel in this order, see sub_kernel_coefficients.

Parameters:

target – See sub_kernel_coefficients.

ffcx.analysis.sub_kernel_targets(expressions: Iterable[Expr]) → list[ProxyCoefficient | Interpolate][source]#

Collect what needs a sub-kernel called in the kernel of some expressions.

A proxy coefficient always needs one: its degrees of freedom are built per cell by evaluating the interpolated expression. An interpolation that survived into the expressions, which is one holding an argument, needs one too, unless its expression is the argument itself and the table is known at compile time. Whatever is nested in the expression of such an interpolation is evaluated by its kernel, so it needs none here.

Parameters:

expressions – Processed expressions, such as the integrands of a form.

Returns:

The proxy coefficients, ordered by count, followed by the interpolations whose table is built for each cell, in the order they are met.