- trixie 1:0.9.0-2
- testing 1:0.10.1.post0-1
- unstable 1:0.10.1.post0-1
- experimental 1:0.11.0-1exp1
| FENICSFORMCOMPILERX(1) | FFCx | FENICSFORMCOMPILERX(1) |
NAME¶
fenicsformcompilerx - FFCx Documentation
The is a new version of the FEniCS Form Compiler. It is developed at <https://github.com/FEniCS/ffcx>.
| ffcx <#module-ffcx> | FEniCS Form Compiler (FFCx). |
| ffcx.__main__ <#module-ffcx.__main__> | Run FFCx on a UFL file. |
| ffcx.analysis <#module-ffcx.analysis> | Compiler stage 1: Analysis. |
| ffcx.compiler <#module-ffcx.compiler> | Main interface for compilation of forms. |
| ffcx.element_interface <#module-ffcx.element_interface> | Finite element interface. |
| ffcx.formatting <#module-ffcx.formatting> | Compiler stage 5: Code formatting. |
| ffcx.main <#module-ffcx.main> | Command-line interface to FFCx. |
| ffcx.naming <#module-ffcx.naming> | Naming. |
| ffcx.codegeneration <#module-ffcx.codegeneration> | FFCx code generation. |
| ffcx.options <#module-ffcx.options> | Options. |
| ffcx.ir.representation <#module-ffcx.ir.representation> | Compiler stage 2: Code representation. |
| ffcx.ir.representationutils <#module-ffcx.ir.representationutils> | Utility functions for some code shared between representations. |
FFCX¶
FEniCS Form Compiler (FFCx).
FFCx compiles finite element variational forms into C code.
FFCX.__MAIN__¶
Run FFCx on a UFL file.
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). |
Classes
| UFLData(form_data, unique_elements, ...) | UFL data. |
- 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]])
- Bases: NamedTuple
UFL data.
Create new instance of UFLData(form_data, unique_elements, element_numbers, unique_coordinate_elements, expressions)
- 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
- 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[tuple[Any, ...], dtype[floating]]]], scalar_type: DTypeLike) -> UFLData <#ffcx.analysis.UFLData>
- Analyze ufl object(s).
- ufl_objects -- UFL objects
- scalar_type -- Scalar type that should be used for the analysis
- Returns
- A named tuple UFLData.
FFCX.COMPILER¶
Main interface for compilation of forms.
Breaks the compilation into several sequential stages. The output of each stage is the input of the next stage.
Compiler stages¶
- 0.
- Language, parsing
- Input: Python code or .ufl file
- Output: UFL form
This stage consists of parsing and expressing a form in the UFL form language. This stage is handled by UFL.
- 1.
- Analysis
- Input: UFL form
- Output: Preprocessed UFL form and FormData (metadata)
This stage preprocesses the UFL form and extracts form metadata. It may also perform simplifications on the form.
- 2.
- Code representation
- Input: Preprocessed UFL form and FormData (metadata)
- Output: Intermediate Representation (IR)
This stage examines the input and generates all data needed for code generation. This includes generation of finite element basis functions, extraction of data for mapping of degrees of freedom and possible precomputation of integrals. Most of the complexity of compilation is handled in this stage.
The IR is stored as a dictionary, mapping names of UFCx functions to data needed for generation of the corresponding code.
- 3.
- Code generation
- Input: Intermediate Representation (IR)
- Output: C code
This stage examines the IR and generates the actual C code for the body of each UFCx function.
The code is stored as a dictionary, mapping names of UFCx functions to strings containing the C code of the body of each function.
- 4.
- Code formatting
- Input: C code
- Output: C code files
This stage examines the generated C++ code and formats it according to the UFCx format, generating as output one or more .h/.c files conforming to the UFCx format.
Functions
| compile_ufl_objects(ufl_objects, options[, ...]) | Generate UFCx code for a given UFL objects. |
- ffcx.compiler.compile_ufl_objects(ufl_objects: list[Any], options: dict[str, int | float | DTypeLike], object_names: dict[int, str] | None = None, namespace: str | None = None, visualise: bool = False) -> tuple[list[str], tuple[str, ...]]
- Generate UFCx code for a given UFL objects.
- ufl_objects -- Objects to be compiled. Accepts elements, forms, integrals or coordinate mappings.
- object_names -- Map from object Python id to object name
- namespace -- Convenience namespace/prefix for generated code.
- options -- Options
- visualise --
Toggle visualisation
Returns: tuple containing list of code file strings and tuple of associated file suffixes.
FFCX.ELEMENT_INTERFACE¶
Finite element interface.
Functions
| basix_index(indices) | Get the Basix index of a derivative. |
| create_quadrature(cellname, degree, rule, ...) | Create a quadrature rule. |
| map_edge_points(points, edge, cellname) | Map points from a reference edge to a physical edge. |
| map_facet_points(points, facet, cellname) | Map points from a reference facet to a physical facet. |
| reference_cell_vertices(cellname) | Get the vertices of a reference cell. |
- ffcx.element_interface.basix_index(indices: tuple[int]) -> int
- Get the Basix index of a derivative.
- ffcx.element_interface.map_edge_points(points: ndarray[tuple[Any, ...], dtype[float64]], edge: int, cellname: str) -> ndarray[tuple[Any, ...], dtype[float64]]
- Map points from a reference edge to a physical edge.
- ffcx.element_interface.map_facet_points(points: ndarray[tuple[Any, ...], dtype[float64]], facet: int, cellname: str) -> ndarray[tuple[Any, ...], dtype[float64]]
- Map points from a reference facet to a physical facet.
- ffcx.element_interface.reference_cell_vertices(cellname: str) -> ndarray[tuple[Any, ...], dtype[float64]]
- Get the vertices of a reference cell.
FFCX.FORMATTING¶
Compiler stage 5: Code formatting.
This module implements the formatting of UFCx code from a given dictionary of generated C++ code for the body of each UFCx function.
It relies on templates for UFCx code available as part of the module ufcx_utils.
Functions
| format_code(code_blocks) | Format given code in UFCx format. |
| write_code(code, prefix, suffixes, output_dir) | Write code to files. |
- ffcx.formatting.format_code(code_blocks: CodeBlocks) -> list[str]
- Format given code in UFCx format.
Returns two strings with header and source file contents.
FFCX.MAIN¶
Command-line interface to FFCx.
Parse command-line arguments and generate code from input UFL form files.
Functions
| main([args]) | Run ffcx on a UFL file. |
- ffcx.main.main(args: Sequence[str] | None = None) -> int
- Run ffcx on a UFL file.
FFCX.NAMING¶
Naming.
Functions
| compute_signature(ufl_objects, tag) | Compute the signature hash. |
| expression_name(expression, prefix) | Get expression name. |
| form_name(original_form, form_id, prefix) | Get form name. |
| integral_name(original_form, integral_type, ...) | Get integral name. |
- ffcx.naming.compute_signature(ufl_objects: list[Form] | list[tuple[Expr, ndarray[tuple[Any, ...], dtype[floating]]]], tag: str) -> str
- Compute the signature hash.
Based on the UFL type of the objects and an additional optional 'tag'.
FFCX.CODEGENERATION¶
FFCx code generation.
Functions
| get_include_path() | Return location of UFCx header files. |
| get_signature() | Return SHA-1 hash of the contents of ufcx.h. |
- ffcx.codegeneration.get_include_path()
- Return location of UFCx header files.
- ffcx.codegeneration.get_signature()
- Return SHA-1 hash of the contents of ufcx.h.
In this implementation, the value is computed on import.
FFCX.OPTIONS¶
Options.
Functions
| get_language(options) | Retrieve the language option from the options database. |
| get_options([priority_options]) | Return (a copy of) the merged option values for FFCX. |
- ffcx.options.get_language(options: dict[str, int | float | DTypeLike]) -> str
- Retrieve the language option from the options database.
Applies for internal languages the alias conversion.
- ffcx.options.get_options(priority_options: dict[str, DTypeLike | int | float] | None = None) -> dict[str, int | float | DTypeLike]
- Return (a copy of) the merged option values for FFCX.
- Parameters
- priority_options -- take priority over all other option values (see notes)
- Returns
- merged option values
Note:
The ffcx_options.json files are cached on the first call. Subsequent calls to this function use this cache.
Priority ordering of options from highest to lowest is:
- priority_options (API and command line options)
- $PWD/ffcx_options.json (local options)
- $XDG_CONFIG_HOME/ffcx/ffcx_options.json (user options)
- FFCX_DEFAULT_OPTIONS in ffcx.options
XDG_CONFIG_HOME is ~/.config/ if the environment variable is not set.
Example ffcx_options.json file:
FFCX.IR.REPRESENTATION¶
Compiler stage 2: Code representation.
Module computes intermediate representations of forms. 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
| basix_cell_from_string(string) | Convert a string to a Basix CellType. |
| compute_ir(analysis, object_names, prefix, ...) | Compute intermediate representation. |
Classes
| DataIR(integrals, forms, expressions) | Intermediate representation of data. |
| ExpressionIR(expression, ...) | Intermediate representation of a DOLFINx Expression. |
| FormIR(id, name, signature, rank, ...) | Intermediate representation of a form. |
| IntegralIR(expression, rank, ...) | Intermediate representation of an integral. |
| QuadratureIR(cell_shape, points, weights) | Intermediate representation of a quadrature rule. |
- class ffcx.ir.representation.DataIR(integrals: list[IntegralIR <#ffcx.ir.representation.IntegralIR>], forms: list[FormIR <#ffcx.ir.representation.FormIR>], expressions: list[ExpressionIR <#ffcx.ir.representation.ExpressionIR>])
- Bases: NamedTuple
Intermediate representation of data.
Create new instance of DataIR(integrals, forms, expressions)
- expressions: list[ExpressionIR <#ffcx.ir.representation.ExpressionIR>]
- Alias for field number 2
- forms: list[FormIR <#ffcx.ir.representation.FormIR>]
- Alias for field number 1
- integrals: list[IntegralIR <#ffcx.ir.representation.IntegralIR>]
- Alias for field number 0
- class ffcx.ir.representation.ExpressionIR(expression: CommonExpressionIR, original_coefficient_positions: list[int], coefficient_names: list[str], constant_names: list[str], name_from_uflfile: str)
- Bases: NamedTuple
Intermediate representation of a DOLFINx Expression.
Create new instance of ExpressionIR(expression, original_coefficient_positions, coefficient_names, constant_names, name_from_uflfile)
- coefficient_names: list[str]
- Alias for field number 2
- constant_names: list[str]
- Alias for field number 3
- expression: CommonExpressionIR
- Alias for field number 0
- name_from_uflfile: str
- Alias for field number 4
- original_coefficient_positions: list[int]
- Alias for field number 1
- class ffcx.ir.representation.FormIR(id: int, name: str, signature: str, rank: int, num_coefficients: int, name_from_uflfile: str, original_coefficient_positions: list[int], coefficient_names: list[str], num_constants: int, constant_ranks: list[int], constant_shapes: list[list[int]], constant_names: list[str], finite_element_hashes: list[int], integral_names: dict[str, list[str]], integral_domains: dict[str, list[basix.CellType]], subdomain_ids: dict[str, list[int]])
- Bases: NamedTuple
Intermediate representation of a form.
Create new instance of FormIR(id, name, signature, rank, num_coefficients, name_from_uflfile, original_coefficient_positions, coefficient_names, num_constants, constant_ranks, constant_shapes, constant_names, finite_element_hashes, integral_names, integral_domains, subdomain_ids)
- coefficient_names: list[str]
- Alias for field number 7
- constant_names: list[str]
- Alias for field number 11
- constant_ranks: list[int]
- Alias for field number 9
- constant_shapes: list[list[int]]
- Alias for field number 10
- finite_element_hashes: list[int]
- Alias for field number 12
- id: int
- Alias for field number 0
- integral_domains: dict[str, list[CellType]]
- Alias for field number 14
- 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 5
- num_coefficients: int
- Alias for field number 4
- num_constants: int
- Alias for field number 8
- original_coefficient_positions: list[int]
- Alias for field number 6
- rank: int
- Alias for field number 3
- signature: str
- Alias for field number 2
- subdomain_ids: dict[str, list[int]]
- Alias for field number 15
- class ffcx.ir.representation.IntegralIR(expression: CommonExpressionIR, rank: int, enabled_coefficients: list[bool], part: TensorPart)
- Bases: NamedTuple
Intermediate representation of an integral.
Create new instance of IntegralIR(expression, rank, enabled_coefficients, part)
- enabled_coefficients: list[bool]
- Alias for field number 2
- expression: CommonExpressionIR
- Alias for field number 0
- part: TensorPart
- Alias for field number 3
- rank: int
- Alias for field number 1
- class ffcx.ir.representation.QuadratureIR(cell_shape: str, points: npt.NDArray[np.float64], weights: npt.NDArray[np.float64])
- 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[tuple[Any, ...], dtype[float64]]
- Alias for field number 1
- weights: ndarray[tuple[Any, ...], dtype[float64]]
- Alias for field number 2
- ffcx.ir.representation.basix_cell_from_string(string: str) -> CellType
- Convert a string to a Basix CellType.
FFCX.IR.REPRESENTATIONUTILS¶
Utility functions for some code shared between representations.
Functions
| create_quadrature_points_and_weights(...[, ...]) | Create quadrature rule and return points and weights. |
| integral_type_to_entity_dim(integral_type, tdim) | Given integral_type and domain tdim, return the tdim of the integration entity. |
| map_integral_points(points, integral_type, ...) | Map points from reference entity to its parent reference cell. |
Classes
| QuadratureRule(points, weights[, tensor_factors]) | A quadrature rule. |
- class ffcx.ir.representationutils.QuadratureRule(points, weights, tensor_factors=None)
- Bases: object
A quadrature rule.
Initialise.
- id()
- Return unique deterministic identifier.
Note:
- ffcx.ir.representationutils.create_quadrature_points_and_weights(integral_type, cell, degree, rule, elements, use_tensor_product=False)
- Create quadrature rule and return points and weights.
- ffcx.ir.representationutils.integral_type_to_entity_dim(integral_type, tdim)
- Given integral_type and domain tdim, return the tdim of the integration entity.
- ffcx.ir.representationutils.map_integral_points(points, integral_type, cell, entity)
- Map points from reference entity to its parent reference cell.
- Index <>
- Module Index <>
- Search Page <>
Author¶
FEniCS Project
Copyright¶
2026, FEniCS Project
| June 16, 2026 | 0.11.0 |