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, element_dimensions, ...)

Intermediate representation of an expression.

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

Intermediate representation of a form.

IntegralIR(integral_type, subdomain_id, ...)

Intermediate representation of an integral.

QuadratureIR(cell_shape, points, weights)

Intermediate representation of a quadrature rule.

class ffcx.ir.representation.CustomElementIR(cell_type: CellType, value_shape: tuple[int, ...], wcoeffs: ndarray[Any, dtype[float64]], x: list[list[ndarray[Any, dtype[float64]]]], M: list[list[ndarray[Any, dtype[float64]]]], map_type: MapType, sobolev_space: SobolevSpace, interpolation_nderivs: int, discontinuous: bool, embedded_subdegree: int, embedded_superdegree: int, polyset_type: 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, num_sub_elements: int, block_size: int, sub_elements: list[str], element_type: str, entity_dofs: list[list[list[int]]], lagrange_variant: LagrangeVariant, dpc_variant: DPCVariant, basix_family: ElementFamily, basix_cell: 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, 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 16

basix_family: ElementFamily

Alias for field number 15

block_size: int

Alias for field number 9

cell_shape: str

Alias for field number 3

custom_element: CustomElementIR

Alias for field number 18

custom_quadrature: QuadratureIR

Alias for field number 19

degree: int

Alias for field number 7

discontinuous: bool

Alias for field number 17

dpc_variant: DPCVariant

Alias for field number 14

element_type: str

Alias for field number 11

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

Alias for field number 12

id: int

Alias for field number 0

lagrange_variant: LagrangeVariant

Alias for field number 13

name: str

Alias for field number 1

num_sub_elements: int

Alias for field number 8

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 10

topological_dimension: int

Alias for field number 4

class ffcx.ir.representation.ExpressionIR(name: str, element_dimensions: dict[_ElementBase, int], options: dict, unique_tables: dict[str, ndarray[Any, dtype[float64]]], unique_table_types: dict[str, str], integrand: dict[QuadratureRule, dict], coefficient_numbering: dict[Coefficient, int], coefficient_offsets: dict[Coefficient, int], integral_type: str, entitytype: str, tensor_shape: list[int], expression_shape: list[int], original_constant_offsets: dict[Constant, int], points: ndarray[Any, dtype[float64]], coefficient_names: list[str], constant_names: list[str], needs_facet_permutations: bool, function_spaces: dict[str, tuple[str, str, str, int, CellType, 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, element_dimensions, 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 14

coefficient_numbering: dict[Coefficient, int]

Alias for field number 6

coefficient_offsets: dict[Coefficient, int]

Alias for field number 7

constant_names: list[str]

Alias for field number 15

element_dimensions: dict[_ElementBase, int]

Alias for field number 1

entitytype: str

Alias for field number 9

expression_shape: list[int]

Alias for field number 11

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

Alias for field number 17

integral_type: str

Alias for field number 8

integrand: dict[QuadratureRule, dict]

Alias for field number 5

name: str

Alias for field number 0

name_from_uflfile: str

Alias for field number 18

needs_facet_permutations: bool

Alias for field number 16

options: dict

Alias for field number 2

original_coefficient_positions: list[int]

Alias for field number 19

original_constant_offsets: dict[Constant, int]

Alias for field number 12

points: ndarray[Any, dtype[float64]]

Alias for field number 13

tensor_shape: list[int]

Alias for field number 10

unique_table_types: dict[str, str]

Alias for field number 4

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

Alias for field number 3

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, CellType, 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, subdomain_id: str | tuple[int, ...] | int, rank: int, geometric_dimension: int, topological_dimension: int, entitytype: str, num_facets: int, num_vertices: int, enabled_coefficients: list[bool], element_dimensions: dict[_ElementBase, int], element_ids: dict[_ElementBase, int], tensor_shape: list[int], coefficient_numbering: dict[Coefficient, int], coefficient_offsets: dict[Coefficient, int], original_constant_offsets: dict[Constant, int], options: dict, cell_shape: str, unique_tables: dict[str, ndarray[Any, dtype[float64]]], unique_table_types: dict[str, str], integrand: dict[QuadratureRule, dict], name: str, needs_facet_permutations: bool, coordinate_element: str, sum_factorization: bool)[source]

Bases: NamedTuple

Intermediate representation of an integral.

Create new instance of IntegralIR(integral_type, subdomain_id, rank, geometric_dimension, topological_dimension, entitytype, num_facets, num_vertices, enabled_coefficients, element_dimensions, element_ids, tensor_shape, coefficient_numbering, coefficient_offsets, original_constant_offsets, options, cell_shape, unique_tables, unique_table_types, integrand, name, needs_facet_permutations, coordinate_element, sum_factorization)

cell_shape: str

Alias for field number 16

coefficient_numbering: dict[Coefficient, int]

Alias for field number 12

coefficient_offsets: dict[Coefficient, int]

Alias for field number 13

coordinate_element: str

Alias for field number 22

element_dimensions: dict[_ElementBase, int]

Alias for field number 9

element_ids: dict[_ElementBase, int]

Alias for field number 10

enabled_coefficients: list[bool]

Alias for field number 8

entitytype: str

Alias for field number 5

geometric_dimension: int

Alias for field number 3

integral_type: str

Alias for field number 0

integrand: dict[QuadratureRule, dict]

Alias for field number 19

name: str

Alias for field number 20

needs_facet_permutations: bool

Alias for field number 21

num_facets: int

Alias for field number 6

num_vertices: int

Alias for field number 7

options: dict

Alias for field number 15

original_constant_offsets: dict[Constant, int]

Alias for field number 14

rank: int

Alias for field number 2

subdomain_id: str | tuple[int, ...] | int

Alias for field number 1

sum_factorization: bool

Alias for field number 23

tensor_shape: list[int]

Alias for field number 11

topological_dimension: int

Alias for field number 4

unique_table_types: dict[str, str]

Alias for field number 18

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

Alias for field number 17

class ffcx.ir.representation.QuadratureIR(cell_shape: str, points: ndarray[Any, dtype[float64]], weights: ndarray[Any, dtype[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[FormData, ...], unique_elements: list[_ElementBase], element_numbers: dict[_ElementBase, int], unique_coordinate_elements: list[_ElementBase], expressions: list[tuple[Expr, ndarray[Any, dtype[float64]], 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, prefix, options, visualise)[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.