ffcx.ir.representation

Compiler stage 2: Code representation.

Module computes intermediate representations of forms, elements and dofmaps. For each UFC function, we extract the data needed for code generation at a later stage.

The representation should conform strictly to the naming and order of functions in UFC. Thus, for code generation of the function “foo”, one should only need to use the data stored in the intermediate representation under the key “foo”.

Functions

compute_ir(analysis, object_names, prefix, ...)

Compute intermediate representation.

Classes

CustomElementIR(cell_type, value_shape, ...)

Intermediate representation of a custom element.

DataIR(elements, dofmaps, integrals, forms, ...)

Intermediate representation of data.

DofMapIR(id, name, signature, ...)

Intermediate representation of a DOF map.

ElementIR(id, name, signature, cell_shape, ...)

Intermediate representation of an element.

ExpressionIR(name, options, unique_tables, ...)

Intermediate representation of an expression.

FormIR(id, name, signature, rank, ...)

Intermediate representation of a form.

IntegralIR(integral_type, rank, entitytype, ...)

Intermediate representation of an integral.

QuadratureIR(cell_shape, points, weights)

Intermediate representation of a quadrature rule.

class ffcx.ir.representation.CustomElementIR(cell_type: basix.CellType, value_shape: tuple[int, ...], wcoeffs: npt.NDArray[np.float64], x: list[list[npt.NDArray[np.float64]]], M: list[list[npt.NDArray[np.float64]]], map_type: basix.MapType, sobolev_space: basix.SobolevSpace, interpolation_nderivs: int, discontinuous: bool, embedded_subdegree: int, embedded_superdegree: int, polyset_type: basix.PolysetType)[source]

Bases: NamedTuple

Intermediate representation of a custom element.

Create new instance of CustomElementIR(cell_type, value_shape, wcoeffs, x, M, map_type, sobolev_space, interpolation_nderivs, discontinuous, embedded_subdegree, embedded_superdegree, polyset_type)

M: list[list[ndarray[Any, dtype[float64]]]]

Alias for field number 4

cell_type: CellType

Alias for field number 0

discontinuous: bool

Alias for field number 8

embedded_subdegree: int

Alias for field number 9

embedded_superdegree: int

Alias for field number 10

interpolation_nderivs: int

Alias for field number 7

map_type: MapType

Alias for field number 5

polyset_type: PolysetType

Alias for field number 11

sobolev_space: SobolevSpace

Alias for field number 6

value_shape: tuple[int, ...]

Alias for field number 1

wcoeffs: ndarray[Any, dtype[float64]]

Alias for field number 2

x: list[list[ndarray[Any, dtype[float64]]]]

Alias for field number 3

class ffcx.ir.representation.DataIR(elements: list[ElementIR], dofmaps: list[DofMapIR], integrals: list[IntegralIR], forms: list[FormIR], expressions: list[ExpressionIR])[source]

Bases: NamedTuple

Intermediate representation of data.

Create new instance of DataIR(elements, dofmaps, integrals, forms, expressions)

dofmaps: list[DofMapIR]

Alias for field number 1

elements: list[ElementIR]

Alias for field number 0

expressions: list[ExpressionIR]

Alias for field number 4

forms: list[FormIR]

Alias for field number 3

integrals: list[IntegralIR]

Alias for field number 2

class ffcx.ir.representation.DofMapIR(id: int, name: str, signature: str, num_global_support_dofs: int, num_element_support_dofs: int, entity_dofs: list[list[list[int]]], entity_closure_dofs: list[list[list[int]]], num_entity_closure_dofs: list[list[int]], num_sub_dofmaps: int, sub_dofmaps: list[str], block_size: int)[source]

Bases: NamedTuple

Intermediate representation of a DOF map.

Create new instance of DofMapIR(id, name, signature, num_global_support_dofs, num_element_support_dofs, entity_dofs, entity_closure_dofs, num_entity_closure_dofs, num_sub_dofmaps, sub_dofmaps, block_size)

block_size: int

Alias for field number 10

entity_closure_dofs: list[list[list[int]]]

Alias for field number 6

entity_dofs: list[list[list[int]]]

Alias for field number 5

id: int

Alias for field number 0

name: str

Alias for field number 1

num_element_support_dofs: int

Alias for field number 4

num_entity_closure_dofs: list[list[int]]

Alias for field number 7

num_global_support_dofs: int

Alias for field number 3

num_sub_dofmaps: int

Alias for field number 8

signature: str

Alias for field number 2

sub_dofmaps: list[str]

Alias for field number 9

class ffcx.ir.representation.ElementIR(id: int, name: str, signature: str, cell_shape: str, topological_dimension: int, space_dimension: int, reference_value_shape: tuple[int, ...], degree: int, symmetric: bool, num_sub_elements: int, block_size: int, sub_elements: list[str], element_type: str, entity_dofs: list[list[list[int]]], lagrange_variant: basix.LagrangeVariant, dpc_variant: basix.DPCVariant, basix_family: basix.ElementFamily, basix_cell: basix.CellType, discontinuous: bool, custom_element: CustomElementIR, custom_quadrature: QuadratureIR)[source]

Bases: NamedTuple

Intermediate representation of an element.

Create new instance of ElementIR(id, name, signature, cell_shape, topological_dimension, space_dimension, reference_value_shape, degree, symmetric, num_sub_elements, block_size, sub_elements, element_type, entity_dofs, lagrange_variant, dpc_variant, basix_family, basix_cell, discontinuous, custom_element, custom_quadrature)

basix_cell: CellType

Alias for field number 17

basix_family: ElementFamily

Alias for field number 16

block_size: int

Alias for field number 10

cell_shape: str

Alias for field number 3

custom_element: CustomElementIR

Alias for field number 19

custom_quadrature: QuadratureIR

Alias for field number 20

degree: int

Alias for field number 7

discontinuous: bool

Alias for field number 18

dpc_variant: DPCVariant

Alias for field number 15

element_type: str

Alias for field number 12

entity_dofs: list[list[list[int]]]

Alias for field number 13

id: int

Alias for field number 0

lagrange_variant: LagrangeVariant

Alias for field number 14

name: str

Alias for field number 1

num_sub_elements: int

Alias for field number 9

reference_value_shape: tuple[int, ...]

Alias for field number 6

signature: str

Alias for field number 2

space_dimension: int

Alias for field number 5

sub_elements: list[str]

Alias for field number 11

symmetric: bool

Alias for field number 8

topological_dimension: int

Alias for field number 4

class ffcx.ir.representation.ExpressionIR(name: str, options: dict, unique_tables: dict[str, npt.NDArray[np.float64]], unique_table_types: dict[str, str], integrand: dict[QuadratureRule, dict], coefficient_numbering: dict[ufl.Coefficient, int], coefficient_offsets: dict[ufl.Coefficient, int], integral_type: str, entitytype: str, tensor_shape: list[int], expression_shape: list[int], original_constant_offsets: dict[ufl.Constant, int], points: npt.NDArray[np.float64], coefficient_names: list[str], constant_names: list[str], needs_facet_permutations: bool, function_spaces: dict[str, tuple[str, str, str, int, basix.CellType, basix.LagrangeVariant, tuple[int]]], name_from_uflfile: str, original_coefficient_positions: list[int])[source]

Bases: NamedTuple

Intermediate representation of an expression.

Create new instance of ExpressionIR(name, options, unique_tables, unique_table_types, integrand, coefficient_numbering, coefficient_offsets, integral_type, entitytype, tensor_shape, expression_shape, original_constant_offsets, points, coefficient_names, constant_names, needs_facet_permutations, function_spaces, name_from_uflfile, original_coefficient_positions)

coefficient_names: list[str]

Alias for field number 13

coefficient_numbering: dict[Coefficient, int]

Alias for field number 5

coefficient_offsets: dict[Coefficient, int]

Alias for field number 6

constant_names: list[str]

Alias for field number 14

entitytype: str

Alias for field number 8

expression_shape: list[int]

Alias for field number 10

function_spaces: dict[str, tuple[str, str, str, int, CellType, LagrangeVariant, tuple[int]]]

Alias for field number 16

integral_type: str

Alias for field number 7

integrand: dict[QuadratureRule, dict]

Alias for field number 4

name: str

Alias for field number 0

name_from_uflfile: str

Alias for field number 17

needs_facet_permutations: bool

Alias for field number 15

options: dict

Alias for field number 1

original_coefficient_positions: list[int]

Alias for field number 18

original_constant_offsets: dict[Constant, int]

Alias for field number 11

points: ndarray[Any, dtype[float64]]

Alias for field number 12

tensor_shape: list[int]

Alias for field number 9

unique_table_types: dict[str, str]

Alias for field number 3

unique_tables: dict[str, ndarray[Any, dtype[float64]]]

Alias for field number 2

class ffcx.ir.representation.FormIR(id: int, name: str, signature: str, rank: int, num_coefficients: int, num_constants: int, name_from_uflfile: str, function_spaces: dict[str, tuple[str, str, str, int, basix.CellType, basix.LagrangeVariant, tuple[int]]], original_coefficient_position: list[int], coefficient_names: list[str], constant_names: list[str], finite_elements: list[str], dofmaps: list[str], integral_names: dict[str, list[str]], subdomain_ids: dict[str, list[int]])[source]

Bases: NamedTuple

Intermediate representation of a form.

Create new instance of FormIR(id, name, signature, rank, num_coefficients, num_constants, name_from_uflfile, function_spaces, original_coefficient_position, coefficient_names, constant_names, finite_elements, dofmaps, integral_names, subdomain_ids)

coefficient_names: list[str]

Alias for field number 9

constant_names: list[str]

Alias for field number 10

dofmaps: list[str]

Alias for field number 12

finite_elements: list[str]

Alias for field number 11

function_spaces: dict[str, tuple[str, str, str, int, CellType, LagrangeVariant, tuple[int]]]

Alias for field number 7

id: int

Alias for field number 0

integral_names: dict[str, list[str]]

Alias for field number 13

name: str

Alias for field number 1

name_from_uflfile: str

Alias for field number 6

num_coefficients: int

Alias for field number 4

num_constants: int

Alias for field number 5

original_coefficient_position: list[int]

Alias for field number 8

rank: int

Alias for field number 3

signature: str

Alias for field number 2

subdomain_ids: dict[str, list[int]]

Alias for field number 14

class ffcx.ir.representation.Integral(integrand, integral_type, domain, subdomain_id, metadata, subdomain_data)[source]

Bases: object

An integral over a single domain.

Initialise.

integral_type()[source]

Return the domain type of this integral.

integrand()[source]

Return the integrand expression, which is an Expr instance.

metadata()[source]

Return the compiler metadata this integral has been annotated with.

reconstruct(integrand=None, integral_type=None, domain=None, subdomain_id=None, metadata=None, subdomain_data=None)[source]

Construct a new Integral object with some properties replaced with new values.

Example

<a = Integral instance> b = a.reconstruct(expand_compounds(a.integrand())) c = a.reconstruct(metadata={‘quadrature_degree’:2})

subdomain_data()[source]

Return the domain data of this integral.

subdomain_id()[source]

Return the subdomain id of this integral.

ufl_domain()[source]

Return the integration domain of this integral.

class ffcx.ir.representation.IntegralIR(integral_type: str, rank: int, entitytype: str, enabled_coefficients: list[bool], tensor_shape: list[int], coefficient_numbering: dict[ufl.Coefficient, int], coefficient_offsets: dict[ufl.Coefficient, int], original_constant_offsets: dict[ufl.Constant, int], unique_tables: dict[str, npt.NDArray[np.float64]], unique_table_types: dict[str, str], integrand: dict[QuadratureRule, dict], name: str, needs_facet_permutations: bool, coordinate_element: str)[source]

Bases: NamedTuple

Intermediate representation of an integral.

Create new instance of IntegralIR(integral_type, rank, entitytype, enabled_coefficients, tensor_shape, coefficient_numbering, coefficient_offsets, original_constant_offsets, unique_tables, unique_table_types, integrand, name, needs_facet_permutations, coordinate_element)

coefficient_numbering: dict[Coefficient, int]

Alias for field number 5

coefficient_offsets: dict[Coefficient, int]

Alias for field number 6

coordinate_element: str

Alias for field number 13

enabled_coefficients: list[bool]

Alias for field number 3

entitytype: str

Alias for field number 2

integral_type: str

Alias for field number 0

integrand: dict[QuadratureRule, dict]

Alias for field number 10

name: str

Alias for field number 11

needs_facet_permutations: bool

Alias for field number 12

original_constant_offsets: dict[Constant, int]

Alias for field number 7

rank: int

Alias for field number 1

tensor_shape: list[int]

Alias for field number 4

unique_table_types: dict[str, str]

Alias for field number 9

unique_tables: dict[str, ndarray[Any, dtype[float64]]]

Alias for field number 8

class ffcx.ir.representation.QuadratureIR(cell_shape: str, points: npt.NDArray[np.float64], weights: npt.NDArray[np.float64])[source]

Bases: NamedTuple

Intermediate representation of a quadrature rule.

Create new instance of QuadratureIR(cell_shape, points, weights)

cell_shape: str

Alias for field number 0

points: ndarray[Any, dtype[float64]]

Alias for field number 1

weights: ndarray[Any, dtype[float64]]

Alias for field number 2

class ffcx.ir.representation.QuadratureRule(points, weights, tensor_factors=None)[source]

Bases: object

A quadrature rule.

Initialise.

id()[source]

Return unique deterministic identifier.

Note

This identifier is used to provide unique names to tables and symbols in generated code.

class ffcx.ir.representation.UFLData(form_data: tuple[ufl.algorithms.formdata.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.float64], ufl.core.expr.Expr]])[source]

Bases: NamedTuple

UFL data.

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

element_numbers: dict[_ElementBase, int]

Alias for field number 2

expressions: list[tuple[Expr, ndarray[Any, dtype[float64]], Expr]]

Alias for field number 4

form_data: tuple[FormData, ...]

Alias for field number 0

unique_coordinate_elements: list[_ElementBase]

Alias for field number 3

unique_elements: list[_ElementBase]

Alias for field number 1

ffcx.ir.representation.compute_integral_ir(cell, integral_type, entitytype, integrands, argument_shape, p, visualise)[source]

Compute intermediate representation for an integral.

ffcx.ir.representation.compute_ir(analysis: UFLData, object_names: dict[int, str], prefix: str, options: dict[str, dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any] | int | float], visualise: bool) DataIR[source]

Compute intermediate representation.

ffcx.ir.representation.create_quadrature_points_and_weights(integral_type, cell, degree, rule, elements, use_tensor_product=False)[source]

Create quadrature rule and return points and weights.

ffcx.ir.representation.sorted_expr_sum(seq)[source]

Sorted expr sum.