# 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 UFC 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 UFC function.

   The code is stored as a dictionary, mapping names of UFC 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 UFC format, generating as output one or more .h/.c files conforming to the UFC format.

Functions

`compile_ufl_objects`(ufl_objects, options[, ...]) | Generate UFC code for a given UFL objects.

ffcx.compiler.analyze_ufl_objects(ufl_objects: list[Form | _ElementBase | Mesh | tuple[Expr, ndarray[tuple[Any, ...], dtype[floating]]]], scalar_type: type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None) → UFLData

  Analyze ufl object(s).

  Parameters:

    - ufl_objects – UFL objects

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

  Returns:

    form_datas: Form_data objects unique_elements: Unique elements across all forms and expressions element_numbers: Mapping to unique numbers for all elements unique_coordinate_elements: Unique coordinate elements across all forms and expressions expressions: List of all expressions after post-processing, with its evaluation points

    > and the original expression

  Return type:

    A data structure holding

ffcx.compiler.compile_ufl_objects(ufl_objects: list[Any], options: dict[str, int | float | type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None], object_names: dict[int, str] | None = None, prefix: str | None = None, visualise: bool = False) → tuple[str, str]

  Generate UFC code for a given UFL objects.

  Parameters:

    - ufl_objects – Objects to be compiled. Accepts elements, forms, integrals or coordinate mappings.

    - object_names – Map from object Python id to object name

    - prefix – Prefix

    - options – Options

    - visualise – Toggle visualisation

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

  Compute intermediate representation.

ffcx.compiler.format_code(code: CodeBlocks) → tuple[str, str]

  Format given code in UFC format. Returns two strings with header and source file contents.

ffcx.compiler.generate_code(ir: DataIR, options: dict[str, int | float | type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None]) → CodeBlocks

  Generate code blocks from intermediate representation.

ffcx.compiler.time() → floating-point number

  Return the current time in seconds since the Epoch. Fractions of a second may be present if the system clock provides them.