Scroll to navigation

FENICSFORMCOMPILERX(1) FEniCS Form Compiler X FENICSFORMCOMPILERX(1)

NAME

fenicsformcompilerx - FEniCS Form Compiler X Documentation

The is an experimental version of the FEniCS Form Compiler. It is developed at https://github.com/FEniCS/ffcx.

ffcx FEniCS Form Compiler (FFCx).
ffcx.__main__ Run ffcx on a UFL file.
ffcx.analysis Compiler stage 1: Analysis.
ffcx.compiler Main interface for compilation of forms.
ffcx.element_interface Finite element interface.
ffcx.formatting Compiler stage 5: Code formatting.
ffcx.main Command-line interface to FFCx.
ffcx.naming Naming.
ffcx.codegeneration FFCx code generation.
ffcx.options Options.
ffcx.ir.representation Compiler stage 2: Code representation.
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.

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.__MAIN__

Run ffcx on a UFL file.

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, options) Analyze ufl object(s).

Classes

UFLData(form_data, unique_elements, ...) UFL data.

Analyze ufl object(s).
  • ufl_objects – UFL objects
  • options – FFCx options. These options take priority over all other set options.

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


A data structure holding


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[, ...]) Generate UFC code for a given UFL objects.
Analyze ufl object(s).
  • ufl_objects – UFL objects
  • options – FFCx options. These options take priority over all other set options.

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


A data structure holding


Generate UFC code for a given UFL objects.
  • ufl_objects – Objects to be compiled. Accepts elements, forms, integrals or coordinate mappings. object_names: Object names
  • object_names – TODO.
  • prefix – Prefix
  • options – Options
  • visualise – Toggle visualisation




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

Generate code blocks from intermediate representation.

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

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_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 UFC code from a given dictionary of generated C++ code for the body of each UFC function.

It relies on templates for UFC code available as part of the module ufcx_utils.

Functions

format_code(code, options) Format given code in UFC format.
write_code(code_h, code_c, prefix, output_dir) Write code to files.
Format given code in UFC 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.
alias of int

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 }





Run ffcx on a UFL file.

FFCX.NAMING

Naming.

Functions

compute_signature(ufl_objects, tag) Compute the signature hash.
dofmap_name(ufl_element, prefix) Get DOF map name.
expression_name(expression, prefix) Get expression name.
finite_element_name(ufl_element, prefix) Get finite element 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_options([priority_options]) Return (a copy of) the merged option values for FFCX.
Bases: object

Special type indicating an unconstrained type.

  • Any is compatible with every type.
  • Any assumed to have all methods.
  • All values assumed to be instances of Any.

Note that all the above statements are true from the point of view of static type checkers. At runtime, Any should not be used with instance checks.


Bases: PurePath

PurePath subclass that can make system calls.

Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa.

Construct a PurePath from one or several strings and or existing PurePath objects. The strings and path objects are combined so as to yield a canonicalized path, which is incorporated into the new PurePath object.

Return an absolute version of this path by prepending the current working directory. No normalization or symlink resolution is performed.

Use resolve() to get the canonical path to a file.


Change the permissions of the path, like os.chmod().

Return a new path pointing to the current working directory (as returned by os.getcwd()).

Whether this path exists.

Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)

Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.

Return the group name of the file gid.

Make this path a hard link pointing to the same file as target.

Note the order of arguments (self, target) is the reverse of os.link’s.


Return a new path pointing to the user’s home directory (as returned by os.path.expanduser(‘~’)).

Whether this path is a block device.

Whether this path is a character device.

Whether this path is a directory.

Whether this path is a FIFO.

Whether this path is a regular file (also True for symlinks pointing to regular files).

Check if this path is a POSIX mount point

Whether this path is a socket.

Whether this path is a symbolic link.

Iterate over the files in this directory. Does not yield any result for the special paths ‘.’ and ‘..’.

Like chmod(), except if the path points to a symlink, the symlink’s permissions are changed, rather than its target’s.

Make the target path a hard link pointing to this path.

Note this function does not make this path a hard link to target, despite the implication of the function and argument names. The order of arguments (target, link) is the reverse of Path.symlink_to, but matches that of os.link.

Deprecated since Python 3.10 and scheduled for removal in Python 3.12. Use hardlink_to() instead.


Like stat(), except if the path points to a symlink, the symlink’s status information is returned, rather than its target’s.

Create a new directory at this given path.

Open the file pointed by this path and return a file object, as the built-in open() function does.

Return the login name of the file owner.

Open the file in bytes mode, read it, and close the file.

Open the file in text mode, read it, and close the file.

Return the path to which the symbolic link points.

Rename this path to the target path.

The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.

Returns the new Path instance pointing to the target path.


Rename this path to the target path, overwriting if that path exists.

The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.

Returns the new Path instance pointing to the target path.


Make the path absolute, resolving all symlinks on the way and also normalizing it.

Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.

Remove this directory. The directory must be empty.

Return whether other_path is the same or not as this file (as returned by os.path.samefile()).

Return the result of the stat() system call on this path, like os.stat() does.

Make this path a symlink pointing to the target path. Note the order of arguments (link, target) is the reverse of os.symlink.

Create this file with the given access mode, if it doesn’t exist.

Remove this file or link. If the path is a directory, use rmdir() instead.

Open the file in bytes mode, write to it, and close the file.

Open the file in text mode, write to it, and close the file.


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


Alias for field number 0

Alias for field number 8

Alias for field number 9

Alias for field number 10

Alias for field number 7

Alias for field number 5

Alias for field number 11

Alias for field number 6

Alias for field number 1

Alias for field number 2



Bases: NamedTuple

Intermediate representation of data.

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

Alias for field number 1

Alias for field number 0

Alias for field number 4

Alias for field number 3

Alias for field number 2


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)

Alias for field number 10


Alias for field number 5

Alias for field number 0

Alias for field number 1

Alias for field number 4

Alias for field number 7

Alias for field number 3

Alias for field number 8

Alias for field number 2

Alias for field number 9


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)

Alias for field number 16

Alias for field number 15

Alias for field number 9

Alias for field number 3

Alias for field number 18

Alias for field number 19

Alias for field number 7

Alias for field number 17

Alias for field number 14

Alias for field number 11

Alias for field number 12

Alias for field number 0

Alias for field number 13

Alias for field number 1

Alias for field number 8

Alias for field number 6

Alias for field number 2

Alias for field number 5

Alias for field number 10

Alias for field number 4


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)

Alias for field number 14



Alias for field number 15


Alias for field number 9

Alias for field number 11


Alias for field number 8

Alias for field number 5

Alias for field number 0

Alias for field number 18

Alias for field number 16

Alias for field number 2

Alias for field number 19


Alias for field number 13

Alias for field number 10

Alias for field number 4



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)

Alias for field number 9

Alias for field number 10

Alias for field number 12

Alias for field number 11


Alias for field number 0

Alias for field number 13

Alias for field number 1

Alias for field number 6

Alias for field number 4

Alias for field number 5

Alias for field number 8

Alias for field number 3

Alias for field number 2

Alias for field number 14


Bases: object

An integral over a single domain.

Initialise.

Return the domain type of this integral.

Return the integrand expression, which is an Expr instance.

Return the compiler metadata this integral has been annotated with.

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})


Return the domain data of this integral.

Return the subdomain id of this integral.

Return the integration domain of this integral.


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)

Alias for field number 16



Alias for field number 22


Alias for field number 10

Alias for field number 8

Alias for field number 5

Alias for field number 3

Alias for field number 0

Alias for field number 19

Alias for field number 20

Alias for field number 21

Alias for field number 6

Alias for field number 7

Alias for field number 15


Alias for field number 2


Alias for field number 23

Alias for field number 11

Alias for field number 4

Alias for field number 18



Bases: NamedTuple

Intermediate representation of a quadrature rule.

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

Alias for field number 0

Alias for field number 1

Alias for field number 2


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.









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

2024, FEniCS Project

April 11, 2024 0.8.0.dev0