Scroll to navigation

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.
Bases: NamedTuple

UFL data.

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

Mapping to unique numbers for all elements

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


Unique coordinate elements across all forms and expressions

Unique elements across all forms and expressions



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.
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.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.
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.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.
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.
Return location of UFCx header files.

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.
Retrieve the language option from the options database.

Applies for internal languages the alias conversion.


Return (a copy of) the merged option values for FFCX.
priority_options -- take priority over all other option values (see notes)
merged option values

Note:

This function sets the log level from the merged option values prior to returning.

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:

{ "epsilon": 1e-7 }





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.

Bases: NamedTuple

Intermediate representation of a DOLFINx Expression.

Create new instance of ExpressionIR(expression, original_coefficient_positions, coefficient_names, constant_names, name_from_uflfile)

Alias for field number 2

Alias for field number 3

Alias for field number 0

Alias for field number 4



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)

Alias for field number 7

Alias for field number 11

Alias for field number 9

Alias for field number 10

Alias for field number 12

Alias for field number 0


Alias for field number 13

Alias for field number 1

Alias for field number 5

Alias for field number 4

Alias for field number 8


Alias for field number 3

Alias for field number 2

Alias for field number 15


Bases: NamedTuple

Intermediate representation of an integral.

Create new instance of IntegralIR(expression, rank, enabled_coefficients, part)

Alias for field number 2

Alias for field number 0

Alias for field number 3

Alias for field number 1


Bases: NamedTuple

Intermediate representation of a quadrature rule.

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

Alias for field number 0






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.
Bases: object

A quadrature rule.

Initialise.

Return unique deterministic identifier.

Note:

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





Given integral_type and domain tdim, return the tdim of the integration 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