FFC: The FEniCS Form Compiler¶
FFC is a compiler for finite element variational forms. From a
high-level description of the form, it generates efficient low-level
C++ code that can be used to assemble the corresponding discrete
operator (tensor). In particular, a bilinear form may be assembled
into a matrix and a linear form may be assembled into a vector. FFC
may be used either from the command line (by invoking the ffc
command) or as a Python module (import ffc
).
FFC is part of the FEniCS Project.
For more information, visit http://www.fenicsproject.org
Documentation¶
Installation¶
FFC is normally installed as part of an installation of FEniCS. If you are using FFC as part of the FEniCS software suite, it is recommended that you follow the installation instructions for FEniCS.
To install FFC itself, read on below for a list of requirements and installation instructions.
Requirements and dependencies¶
FFC requires Python version 3.5 or later and depends on the following Python packages:
- NumPy
- six
FFC also depends on the following FEniCS Python packages:
- FIAT
- UFL
- dijitso
These packages will be automatically installed as part of the installation of FFC, if not already present on your system.
TSFC requirements¶
To use experimental tsfc
representation, additional
dependencies are needed:
and in turn their additional dependencies:
Note
TSFC requirements are not installed in FEniCS Docker images by default yet but they can be easilly installed on demand:
docker pull quay.io/fenicsproject/stable
docker run -ti --rm quay.io/fenicsproject/stable
pip3 install --prefix=${FENICS_PREFIX} --no-cache-dir \
git+https://github.com/blechta/tsfc.git@2018.1.0 \
git+https://github.com/blechta/COFFEE.git@2018.1.0 \
git+https://github.com/blechta/FInAT.git@2018.1.0 \
singledispatch networkx pulp && \
sudo rm -rf /tmp/* /var/tmp/*
The first two commands (or their modification, or
fenicsproject
helper script) are to be run on a host,
while the last command, to be run in the container, actually
installs all the TSFC requirements. For further reading,
see FEniCS Docker reference.
[1] | (1, 2, 3) These are forks of the original packages tested to be compatible with FFC and updated frequently from upstream. |
[2] | (1, 2, 3) Pip-installable. |
Installation instructions¶
To install FFC, download the source code from the FFC Bitbucket repository, and run the following command:
pip3 install .
To install to a specific location, add the --prefix
flag
to the installation command:
pip3 install --prefix=<some directory> .
User manual¶
Note
This page is work in progress.
ffc package¶
Subpackages¶
ffc.errorcontrol package¶
Submodules¶
ffc.errorcontrol.errorcontrol module¶
This module provides compilation of forms required for goal-oriented error control
-
ffc.errorcontrol.errorcontrol.
compile_with_error_control
(forms, object_names, reserved_objects, prefix, parameters)[source]¶ Compile forms and additionally generate and compile forms required for performing goal-oriented error control
For linear problems, the input forms should be a bilinear form (a) and a linear form (L) specifying the variational problem and additionally a linear form (M) specifying the goal functional.
For nonlinear problems, the input should be linear form (F) and a functional (M) specifying the goal functional.
Arguments
- forms (tuple)
- Three (linear case) or two (nonlinear case) forms specifying the primal problem and the goal
- object_names (dict)
- Map from object ids to object names
- reserved_names (dict)
- Map from reserved object names to object ids
- prefix (string)
- Basename of header file
- parameters (dict)
- Parameters for form compilation
ffc.errorcontrol.errorcontrolgenerators module¶
This module provides an abstract ErrorControlGenerator class for generating forms required for goal-oriented error control and a realization of this: UFLErrorControlGenerator for handling pure UFL forms.
-
class
ffc.errorcontrol.errorcontrolgenerators.
ErrorControlGenerator
(module, F, M, u)[source]¶ Bases:
object
-
cell_residual
()[source]¶ Generate and return (bilinear, linear) forms defining linear variational problem for the strong cell residual
-
dual_forms
()[source]¶ Generate and return (bilinear, linear) forms defining linear dual variational problem
-
facet_residual
()[source]¶ Generate and return (bilinear, linear) forms defining linear variational problem for the strong facet residual(s)
-
-
class
ffc.errorcontrol.errorcontrolgenerators.
UFLErrorControlGenerator
(F, M, u)[source]¶ Bases:
ffc.errorcontrol.errorcontrolgenerators.ErrorControlGenerator
This class provides a realization of ErrorControlGenerator for use with pure UFL forms
Module contents¶
This module contains functionality for working with automated goal-oriented error control. In particular it offers the following function:
compile_with_error_control - Compile forms and generate error control forms
ffc.quadrature package¶
Submodules¶
ffc.quadrature.codesnippets module¶
Code snippets for code generation.
ffc.quadrature.cpp module¶
This module defines rules and algorithms for generating C++ code.
-
ffc.quadrature.cpp.
count_ops
(code)[source]¶ Count the number of operations in code (multiply-add pairs).
-
ffc.quadrature.cpp.
indent
(block, num_spaces)[source]¶ Indent each row of the given string block with n spaces.
-
ffc.quadrature.cpp.
remove_unused
(code, used_set=set())[source]¶ Remove unused variables from a given C++ code. This is useful when generating code that will be compiled with gcc and parameters -Wall -Werror, in which case gcc returns an error when seeing a variable declaration for a variable that is never used.
Optionally, a set may be specified to indicate a set of variables names that are known to be used a priori.
ffc.quadrature.deprecation module¶
-
exception
ffc.quadrature.deprecation.
QuadratureRepresentationDeprecationWarning
[source]¶ Bases:
DeprecationWarning
Warning about deprecation of quadrature representation
ffc.quadrature.expr module¶
This file implements a base class to represent an expression.
-
class
ffc.quadrature.expr.
Expr
[source]¶ Bases:
object
-
get_var_occurrences
()[source]¶ Determine the number of times all variables occurs in the expression. Returns a dictionary of variables and the number of times they occur. Works for FloatValue and Symbol.
-
ops
()[source]¶ Return number of operations to compute the expression. This is always zero for a FloatValue.
-
reduce_ops
()[source]¶ Reduce number of operations to evaluate the expression. There is nothing to be done for FloatValue and Symbol.
-
reduce_var
(var)[source]¶ Reduce the expression by another variable by using division. This works for FloatValue, Symbol and Product.
-
reduce_vartype
(var_type)[source]¶ Reduce expression with given var_type. It returns a tuple (found, remain), where ‘found’ is an expression that only has variables of type == var_type. If no variables are found, found=(). The ‘remain’ part contains the leftover after division by ‘found’ such that: self = found*remain. Works for FloatValue and Symbol.
-
t
¶
-
val
¶
-
ffc.quadrature.floatvalue module¶
This file implements a class to represent a float.
-
class
ffc.quadrature.floatvalue.
FloatValue
(value)[source]¶ Bases:
ffc.quadrature.expr.Expr
ffc.quadrature.fraction module¶
This file implements a class to represent a fraction.
-
class
ffc.quadrature.fraction.
Fraction
(numerator, denominator)[source]¶ Bases:
ffc.quadrature.expr.Expr
-
denom
¶
-
get_var_occurrences
()[source]¶ Determine the number of minimum number of times all variables occurs in the expression simply by calling the function on the numerator.
-
num
¶
-
reduce_ops
()[source]¶ Reduce number of operations to evaluate the expression. There is nothing to be done for FloatValue and Symbol.
-
reduce_vartype
(var_type)[source]¶ Reduce expression with given var_type. It returns a tuple (found, remain), where ‘found’ is an expression that only has variables of type == var_type. If no variables are found, found=(). The ‘remain’ part contains the leftover after division by ‘found’ such that: self = found*remain.
-
ffc.quadrature.optimisedquadraturetransformer module¶
QuadratureTransformer (optimised) for quadrature code generation to translate UFL expressions.
-
class
ffc.quadrature.optimisedquadraturetransformer.
QuadratureTransformerOpt
(*args)[source]¶ Bases:
ffc.quadrature.quadraturetransformerbase.QuadratureTransformerBase
Transform UFL representation to quadrature code.
-
create_argument
(ufl_argument, derivatives, component, local_comp, local_offset, ffc_element, transformation, multiindices, tdim, gdim, avg)[source]¶ Create code for basis functions, and update relevant tables of used basis.
-
ffc.quadrature.parameters module¶
Quadrature representation class for UFL
ffc.quadrature.product module¶
This file implements a class to represent a product.
-
class
ffc.quadrature.product.
Product
(variables)[source]¶ Bases:
ffc.quadrature.expr.Expr
-
get_var_occurrences
()[source]¶ Determine the number of times all variables occurs in the expression. Returns a dictionary of variables and the number of times they occur.
-
reduce_vartype
(var_type)[source]¶ Reduce expression with given var_type. It returns a tuple (found, remain), where ‘found’ is an expression that only has variables of type == var_type. If no variables are found, found=(). The ‘remain’ part contains the leftover after division by ‘found’ such that: self = found*remain.
-
vrs
¶
-
ffc.quadrature.quadraturegenerator module¶
Code generator for quadrature representation.
ffc.quadrature.quadratureoptimization module¶
ffc.quadrature.quadraturerepresentation module¶
Quadrature representation class for UFL
ffc.quadrature.quadraturetransformer module¶
QuadratureTransformer for quadrature code generation to translate UFL expressions.
-
class
ffc.quadrature.quadraturetransformer.
QuadratureTransformer
(*args)[source]¶ Bases:
ffc.quadrature.quadraturetransformerbase.QuadratureTransformerBase
Transform UFL representation to quadrature code.
-
create_argument
(ufl_argument, derivatives, component, local_comp, local_offset, ffc_element, transformation, multiindices, tdim, gdim, avg)[source]¶ Create code for basis functions, and update relevant tables of used basis.
-
ffc.quadrature.quadraturetransformerbase module¶
QuadratureTransformerBase, a common class for quadrature transformers to translate UFL expressions.
-
class
ffc.quadrature.quadraturetransformerbase.
FFCMultiIndex
(dims)[source]¶ Bases:
object
A MultiIndex represents a list of indices and holds the following data:
rank - rank of multiindex dims - a list of dimensions indices - a list of all possible multiindex values
ffc.quadrature.quadratureutils module¶
Utility functions for quadrature representation.
-
ffc.quadrature.quadratureutils.
contains_zeros
(tables)[source]¶ Checks if any tables contains only zeros.
-
ffc.quadrature.quadratureutils.
create_psi_tables
(tables, eliminate_zeros, entity_type)[source]¶ Create names and maps for tables and non-zero entries if appropriate.
-
ffc.quadrature.quadratureutils.
flatten_psi_tables
(tables, entity_type)[source]¶ Create a ‘flat’ dictionary of tables with unique names and a name map that maps number of quadrature points and element name to a unique element number.
- Input tables on the format for scalar and non-scalar elements respectively:
- tables[num_points][element][entity][derivs][ip][dof] tables[num_points][element][entity][derivs][ip][component][dof]
- Planning to change this into:
- tables[num_points][element][avg][entity][derivs][ip][dof] tables[num_points][element][avg][entity][derivs][ip][component][dof]
- Returns:
- element_map - { num_quad_points: {ufl_element: element_number} }. flat_tables - { unique_table_name: values[ip,dof] }.
-
ffc.quadrature.quadratureutils.
get_ones
(tables)[source]¶ Return names of tables for which all values are 1.0.
-
ffc.quadrature.quadratureutils.
unique_psi_tables
(tables, eliminate_zeros)[source]¶ Returns a name map and a dictionary of unique tables. The function checks if values in the tables are equal, if this is the case it creates a name mapping. It also create additional information (depending on which parameters are set) such as if the table contains all ones, or only zeros, and a list on non-zero columns. unique_tables - {name:values,}. name_map - {original_name:[new_name, non-zero-columns (list), is zero (bool), is ones (bool)],}.
-
ffc.quadrature.quadratureutils.
unique_tables
(tables)[source]¶ Removes tables with redundant values and returns a name_map and a inverse_name_map. E.g.,
tables = {a:[0,1,2], b:[0,2,3], c:[0,1,2], d:[0,1,2]} results in: tables = {a:[0,1,2], b:[0,2,3]} name_map = {a:[c,d]} inverse_name_map = {a:a, b:b, c:a, d:a}.
ffc.quadrature.reduce_operations module¶
Some simple functions for manipulating expressions symbolically
-
ffc.quadrature.reduce_operations.
expand_operations
(expression, format)[source]¶ This function expands an expression and returns the value. E.g., ((x + y)) –> x + y 2*(x + y) –> 2*x + 2*y (x + y)*(x + y) –> x*x + y*y + 2*x*y z*(x*(y + 3) + 2) + 1 –> 1 + 2*z + x*y*z + x*z*3 z*((y + 3)*x + 2) + 1 –> 1 + 2*z + x*y*z + x*z*3
-
ffc.quadrature.reduce_operations.
get_constants
(expression, const_terms, format, constants=[])[source]¶ This function returns a new expression where all geometry terms have been substituted with geometry declarations, these declarations are added to the const_terms dictionary.
-
ffc.quadrature.reduce_operations.
get_geo_terms
(expression, geo_terms, offset, format)[source]¶ This function returns a new expression where all geometry terms have been substituted with geometry declarations, these declarations are added to the geo_terms dictionary.
-
ffc.quadrature.reduce_operations.
get_indices
(variable, format, from_get_indices=False)[source]¶ This function returns the indices of a given variable. E.g., P[0][j], returns [‘j’] P[ip][k], returns [‘ip’,’k’] P[ip][nzc0[j] + 3], returns [‘ip’,’j’] w[0][j + 2] , returns [j]
-
ffc.quadrature.reduce_operations.
get_simple_variables
(expression, format)[source]¶ - This function takes as argument an expression (preferably expanded):
- expression = “x*x + y*x + x*y*z”
returns a list of products and a dictionary:
prods = [“x*x”, “y*x”, “x*y*z”] variables = {variable: [num_occurences, [pos_in_prods]]} variables = {“x”:[3, [0,1,2]], “y”:[2, [1,2]], “z”:[1, [2]]}
-
ffc.quadrature.reduce_operations.
get_variables
(expression, variables, format, constants=[])[source]¶ This function returns a new expression where all geometry terms have been substituted with geometry declarations, these declarations are added to the const_terms dictionary.
-
ffc.quadrature.reduce_operations.
group_vars
(expr, format)[source]¶ Group variables in an expression, such that: “x + y + z + 2*y + 6*z” = “x + 3*y + 7*z” “x*x + x*x + 2*x + 3*x + 5” = “2.0*x*x + 5.0*x + 5” “x*y + y*x + 2*x*y + 3*x + 0*x + 5” = “5.0*x*y + 3.0*x + 5” “(y + z)*x + 5*(y + z)*x” = “6.0*(y + z)*x” “1/(x*x) + 2*1/(x*x) + std::sqrt(x) + 6*std::sqrt(x)” = “3*1/(x*x) + 7*std::sqrt(x)”
-
ffc.quadrature.reduce_operations.
is_constant
(variable, format, constants=[], from_is_constant=False)[source]¶ Determine if a variable is constant or not. The function accepts an optional list of variables (loop indices) that will be regarded as constants for the given variable. If none are supplied it is assumed that all array accesses will result in a non-constant variable.
v = 2.0, is constant v = Jinv_00*det, is constant v = w[0][1], is constant v = 2*w[0][1], is constant v = W0[ip], is constant if constants = [‘ip’] else not v = P_t0[ip][j], is constant if constants = [‘j’,’ip’] else not
-
ffc.quadrature.reduce_operations.
operation_count
(expression, format)[source]¶ This function returns the number of double operations in an expression. We do split () but not [] as we only have unsigned integer operations in [].
-
ffc.quadrature.reduce_operations.
reduce_operations
(expression, format)[source]¶ This function reduces the number of opertions needed to compute a given expression. It looks for the variable that appears the most and groups terms containing this variable inside parenthesis. The function is called recursively until no further reductions are possible.
“x + y + x” = 2*x + y “x*x + 2.0*x*y + y*y” = y*y + (2.0*y + x)*x, not (x + y)*(x + y) as it should be!! z*x*y + z*x*3 + 2*z + 1” = z*(x*(y + 3) + 2) + 1
-
ffc.quadrature.reduce_operations.
reduction_possible
(variables)[source]¶ Find the variable that occurs in the most products, if more variables occur the same number of times and in the same products add them to list.
-
ffc.quadrature.reduce_operations.
split_expression
(expression, format, operator, allow_split=False)[source]¶ Split the expression at the given operator, return list. Do not split () or [] unless told to split (). This is to enable easy count of double operations which can be in (), but in [] we only have integer operations.
ffc.quadrature.sumobj module¶
This file implements a class to represent a sum.
-
class
ffc.quadrature.sumobj.
Sum
(variables)[source]¶ Bases:
ffc.quadrature.expr.Expr
-
get_var_occurrences
()[source]¶ Determine the number of minimum number of times all variables occurs in the expression. Returns a dictionary of variables and the number of times they occur. x*x + x returns {x:1}, x + y returns {}.
-
reduce_vartype
(var_type)[source]¶ Reduce expression with given var_type. It returns a list of tuples [(found, remain)], where ‘found’ is an expression that only has variables of type == var_type. If no variables are found, found=(). The ‘remain’ part contains the leftover after division by ‘found’ such that: self = Sum([f*r for f,r in self.reduce_vartype(Type)]).
-
vrs
¶
-
ffc.quadrature.symbol module¶
This file implements a class to represent a symbol.
-
class
ffc.quadrature.symbol.
Symbol
(variable, symbol_type, base_expr=None, base_op=0)[source]¶ Bases:
ffc.quadrature.expr.Expr
-
base_expr
¶
-
base_op
¶
-
cond
¶
-
exp
¶
-
get_var_occurrences
()[source]¶ Determine the number of times all variables occurs in the expression. Returns a dictionary of variables and the number of times they occur.
-
v
¶
-
ffc.quadrature.symbolics module¶
This file contains functions to optimise the code generated for quadrature representation.
-
ffc.quadrature.symbolics.
generate_aux_constants
(constant_decl, name, var_type, print_ops=False)[source]¶ A helper tool to generate code for constant declarations.
-
ffc.quadrature.symbolics.
optimise_code
(expr, ip_consts, geo_consts, trans_set)[source]¶ Optimise a given expression with respect to, basis functions, integration points variables and geometric constants. The function will update the dictionaries ip_const and geo_consts with new declarations and update the trans_set (used transformations).
ffc.quadrature.tabulate_basis module¶
Quadrature representation class.
Module contents¶
ffc.tsfc package¶
Submodules¶
ffc.tsfc.tsfcgenerator module¶
ffc.tsfc.tsfcoptimization module¶
ffc.tsfc.tsfcrepresentation module¶
Module contents¶
ffc.uflacs package¶
Subpackages¶
Algorithms for the representation phase of the form compilation.
Compressed row storage ‘matrix’ (actually just a non-rectangular 2d array).
-
class
ffc.uflacs.analysis.crsarray.
CRSArray
(row_capacity, element_capacity, dtype)[source]¶ Bases:
object
An array of variable length dense arrays.
Stored efficiently with simple compressed row storage. This CRS array variant doesn’t have a sparsity pattern, as each row is simply a dense vector.
Values are stored in one flat array ‘data[]’, and ‘row_offsets[i]’ contains the index to the first element on row i for 0<=i<=num_rows. There is no column index.
-
classmethod
from_rows
(rows, num_rows, num_elements, dtype)[source]¶ Construct a CRSArray from a list of row element lists.
-
num_elements
¶
-
classmethod
Tools for analysing dependencies within expression graphs.
-
ffc.uflacs.analysis.dependencies.
compute_dependencies
(e2i, V, ignore_terminal_modifiers=True)[source]¶
-
ffc.uflacs.analysis.dependencies.
mark_active
(dependencies, targets)[source]¶ Return an array marking the recursive dependencies of targets.
Input: - dependencies - CRSArray of ints, a mapping from a symbol to the symbols of its dependencies. - targets - Sequence of symbols to mark the dependencies of.
Output: - active - Truth value for each symbol. - num_used - Number of true values in active array.
-
ffc.uflacs.analysis.dependencies.
mark_image
(inverse_dependencies, sources)[source]¶ Return an array marking the set of symbols dependent on the sources.
Input: - dependencies - CRSArray of ints, a mapping from a symbol to the symbols of its dependencies. - sources - Sequence of symbols to mark the dependants of.
Output: - image - Truth value for each symbol. - num_used - Number of true values in active array.
Tools for computing various shapes of ufl expressions.
The total shape is the regular shape tuple plus the index shape tuple. The index shape tuple is the tuple of index dimensions of the free indices of the expression, sorted by the count of the free indices.
The total shape of a tensor valued expression A
and
A[*indices(len(A.ufl_shape))]
is therefore the same.
Algorithms for factorizing argument dependent monomials.
-
ffc.uflacs.analysis.factorization.
add_to_fv
(expr, FV, e2fi)[source]¶ Add expression expr to factor vector FV and expr->FVindex mapping e2fi.
-
ffc.uflacs.analysis.factorization.
build_argument_dependencies
(dependencies, arg_indices)[source]¶ Preliminary algorithm: build list of argument vertex indices each vertex (indirectly) depends on.
-
ffc.uflacs.analysis.factorization.
build_argument_indices
(V)[source]¶ Build ordered list of indices to modified arguments.
-
ffc.uflacs.analysis.factorization.
compute_argument_factorization
(SV, SV_deps, SV_targets, rank)[source]¶ Factorizes a scalar expression graph w.r.t. scalar Argument components.
The result is a triplet (AV, FV, IM):
The scalar argument component subgraph:
AV[ai] = v
with the property
SV[arg_indices] == AV[:]
An expression graph vertex list with all non-argument factors:
FV[fi] = f
with the property that none of the expressions depend on Arguments.
A dict representation of the final integrand of rank r:
IM = { (ai1_1, …, ai1_r): fi1, (ai2_1, …, ai2_r): fi2, }
This mapping represents the factorization of SV[-1] w.r.t. Arguments s.t.:
SV[-1] := sum(FV[fik] * product(AV[ai] for ai in aik) for aik, fik in IM.items())
where := means equivalence in the mathematical sense, of course in a different technical representation.
-
ffc.uflacs.analysis.factorization.
handle_conditional
(v, si, deps, SV_factors, FV, sv2fv, e2fi)[source]¶
-
ffc.uflacs.analysis.factorization.
handle_division
(v, si, deps, SV_factors, FV, sv2fv, e2fi)[source]¶
Linearized data structure for the computational graph.
Rebuilding UFL expressions from linearized representation of computational graph.
-
class
ffc.uflacs.analysis.graph_rebuild.
ReconstructScalarSubexpressions
[source]¶ Bases:
ufl.corealg.multifunction.MultiFunction
-
abs
(o, ops)¶
-
atan_2
(o, ops)¶
-
bessel_function
(o, ops)¶
-
component_tensor
(o, *args, **kwargs)¶
-
expr_list
(o, *args, **kwargs)¶
-
expr_mapping
(o, *args, **kwargs)¶
-
label
(o, *args, **kwargs)¶
-
list_tensor
(o, *args, **kwargs)¶
-
math_function
(o, ops)¶
-
max_value
(o, ops)¶
-
min_value
(o, ops)¶
-
multi_index
(o, *args, **kwargs)¶
-
power
(o, ops)¶
-
transposed
(o, *args, **kwargs)¶
-
utility_type
(o, *args, **kwargs)¶
-
variable
(o, *args, **kwargs)¶
-
-
ffc.uflacs.analysis.graph_rebuild.
rebuild_expression_from_graph
(G)[source]¶ This is currently only used by tests.
-
ffc.uflacs.analysis.graph_rebuild.
rebuild_with_scalar_subexpressions
(G, targets=None)[source]¶ Build a new expression2index mapping where each subexpression is scalar valued.
Input: - G.e2i - G.V - G.V_symbols - G.total_unique_symbols
Output: - NV - Array with reverse mapping from index to expression - nvs - Tuple of ne2i indices corresponding to the last vertex of G.V
Old output now no longer returned but possible to restore if needed: - ne2i - Mapping from scalar subexpressions to a contiguous unique index - W - Array with reconstructed scalar subexpressions for each original symbol
Algorithms for working with computational graphs.
-
ffc.uflacs.analysis.graph_ssa.
allocate_registers
(active, partitions, targets, scores, max_registers, score_threshold)[source]¶ FIXME: Cover with tests.
TODO: Allow reuse of registers, reducing memory usage.
TODO: Probably want to sort within partitions.
-
ffc.uflacs.analysis.graph_ssa.
compute_cache_scores
(V, active, dependencies, inverse_dependencies, partitions, cache_score_policy=<function default_cache_score_policy>)[source]¶ FIXME: Cover with tests.
TODO: Experiment with heuristics later when we have functional code generation.
-
ffc.uflacs.analysis.graph_ssa.
default_cache_score_policy
(vtype, ndeps, ninvdeps, partition)[source]¶
-
ffc.uflacs.analysis.graph_ssa.
default_partition_seed
(expr, rank)[source]¶ Partition 0: Piecewise constant on each cell (including Real and DG0 coefficients) Partition 1: Depends on x Partition 2: Depends on x and coefficients Partitions [3,3+rank): depend on argument with count partition-3
-
ffc.uflacs.analysis.graph_ssa.
mark_partitions
(V, active, dependencies, rank, partition_seed=<function default_partition_seed>, partition_combiner=<built-in function max>)[source]¶ FIXME: Cover this with tests.
Input: - V - Array of expressions. - active - Boolish array. - dependencies - CRSArray with V dependencies. - partition_seed - Policy for determining the partition of a terminalish. - partition_combiner - Policy for determinging the partition of an operator.
Output: - partitions - Array of partition int ids.
Assigning symbols to computational graph nodes.
-
ffc.uflacs.analysis.graph_symbols.
build_graph_symbols
(V, e2i, DEBUG)[source]¶ Tabulate scalar value numbering of all nodes in a a list based representation of an expression graph.
Returns: V_shapes - CRSArray of the total shapes of nodes in V. V_symbols - CRSArray of symbols (value numbers) of each component of each node in V. total_unique_symbols - The number of symbol values assigned to unique scalar components of the nodes in V.
-
ffc.uflacs.analysis.graph_symbols.
build_node_shapes
(V)[source]¶ Build total shapes for each node in list representation of expression graph.
V is an array of ufl expressions, possibly nonscalar and with free indices.
Returning a CRSArray where row i is the total shape of V[i].
-
ffc.uflacs.analysis.graph_symbols.
build_node_sizes
(V_shapes)[source]¶ Compute all the products of a sequence of shapes.
-
ffc.uflacs.analysis.graph_symbols.
build_node_symbols
(V, e2i, V_shapes, V_sizes)[source]¶ Tabulate scalar value numbering of all nodes in a a list based representation of an expression graph.
Returns: V_symbols - CRSArray of symbols (value numbers) of each component of each node in V. total_unique_symbols - The number of symbol values assigned to unique scalar components of the nodes in V.
Algorithms for working with graphs.
Algorithms for working with multiindices.
Definitions of ‘modified terminals’, a core concept in uflacs.
-
class
ffc.uflacs.analysis.modified_terminals.
ModifiedTerminal
(expr, terminal, reference_value, base_shape, base_symmetry, component, flat_component, global_derivatives, local_derivatives, averaged, restriction)[source]¶ Bases:
object
A modified terminal expression is an object of a Terminal subtype, wrapped in terminal modifier types.
The variables of this class are:
expr - The original UFL expression terminal - the underlying Terminal object
global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘
component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
Possibly other component model: - global_component - reference_component - flat_component
-
ffc.uflacs.analysis.modified_terminals.
analyse_modified_terminal
(expr)[source]¶ Analyse a so-called ‘modified terminal’ expression.
Return its properties in more compact form as a ModifiedTerminal object.
A modified terminal expression is an object of a Terminal subtype, wrapped in terminal modifier types.
The wrapper types can include 0-* Grad or ReferenceGrad objects, and 0-1 ReferenceValue, 0-1 Restricted, 0-1 Indexed, and 0-1 FacetAvg or CellAvg objects.
Algorithms for value numbering within computational graphs.
-
class
ffc.uflacs.analysis.valuenumbering.
ValueNumberer
(e2i, V_sizes, V_symbols)[source]¶ Bases:
ufl.corealg.multifunction.MultiFunction
An algorithm to map the scalar components of an expression node to unique value numbers, with fallthrough for types that can be mapped to the value numbers of their operands.
-
cell_avg
(v, i)¶ Modifiers: terminal - the underlying Terminal object global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘ component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
-
facet_avg
(v, i)¶ Modifiers: terminal - the underlying Terminal object global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘ component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
-
grad
(v, i)¶ Modifiers: terminal - the underlying Terminal object global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘ component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
-
reference_grad
(v, i)¶ Modifiers: terminal - the underlying Terminal object global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘ component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
-
reference_value
(v, i)¶ Modifiers: terminal - the underlying Terminal object global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘ component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
-
restricted
(v, i)¶ Modifiers: terminal - the underlying Terminal object global_derivatives - tuple of ints, each meaning derivative in that global direction local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame averaged - None, ‘facet’ or ‘cell’ restriction - None, ‘+’ or ‘-‘ component - tuple of ints, the global component of the Terminal flat_component - single int, flattened local component of the Terminal, considering symmetry
-
Algorithms for the analysis phase of the form compilation.
FFC/UFC specific variable access.
-
class
ffc.uflacs.backends.ffc.access.
FFCBackendAccess
(ir, language, symbols, parameters)[source]¶ Bases:
ufl.corealg.multifunction.MultiFunction
FFC specific cpp formatter class.
-
cell_normal
(e, mt, tabledata, num_points)¶
-
facet_jacobian
(e, mt, tabledata, num_points)¶
-
facet_jacobian_determinant
(e, mt, tabledata, num_points)¶
-
facet_jacobian_inverse
(e, mt, tabledata, num_points)¶
-
facet_normal
(e, mt, tabledata, num_points)¶
-
jacobian_determinant
(e, mt, tabledata, num_points)¶
-
jacobian_inverse
(e, mt, tabledata, num_points)¶
-
Collection of FFC specific pieces for the code generation phase.
FFC/UFC specific symbol naming.
-
ffc.uflacs.backends.ffc.common.
num_coordinate_component_dofs
(coordinate_element)[source]¶ Get the number of dofs for a coordinate component for this degree.
This is a local hack that works for Lagrange 1-3, better would be to get this passed by ffc from fiat through the ir. The table data is to messy to figure out a clean design for that quickly.
FFC/UFC specific variable definitions.
-
class
ffc.uflacs.backends.ffc.definitions.
FFCBackendDefinitions
(ir, language, symbols, parameters)[source]¶ Bases:
ufl.corealg.multifunction.MultiFunction
FFC specific code definitions.
-
argument
(t, mt, tabledata, num_points, access)[source]¶ Arguments are accessed through element tables.
-
cell_coordinate
(e, mt, tabledata, num_points, access)[source]¶ Return definition code for the reference spatial coordinates.
If reference coordinates are given:
No definition needed.
If physical coordinates are given and domain is affine:
X = K*(x-x0)
This is inserted symbolically.
If physical coordinates are given and domain is non- affine:
Not currently supported.
-
cell_edge_vectors
(e, mt, tabledata, num_points, access)¶ These quantities refer to coordinate_dofs
-
cell_facet_jacobian
(e, mt, tabledata, num_points, access)¶ These quantities refer to constant tables defined in ufc_geometry.h.
-
cell_normal
(e, mt, tabledata, num_points, access)¶ These quantities are expected to be replaced in symbolic preprocessing.
-
cell_vertices
(e, mt, tabledata, num_points, access)¶ These quantities refer to coordinate_dofs
-
constant_value
(e, mt, tabledata, num_points, access)[source]¶ Constants simply use literals in the target language.
-
facet_edge_vectors
(e, mt, tabledata, num_points, access)¶ These quantities refer to coordinate_dofs
-
facet_jacobian
(e, mt, tabledata, num_points, access)¶ These quantities are expected to be replaced in symbolic preprocessing.
-
facet_jacobian_determinant
(e, mt, tabledata, num_points, access)¶ These quantities are expected to be replaced in symbolic preprocessing.
-
facet_jacobian_inverse
(e, mt, tabledata, num_points, access)¶ These quantities are expected to be replaced in symbolic preprocessing.
-
facet_normal
(e, mt, tabledata, num_points, access)¶ These quantities are expected to be replaced in symbolic preprocessing.
-
facet_orientation
(e, mt, tabledata, num_points, access)¶ These quantities refer to constant tables defined in ufc_geometry.h.
-
jacobian
(e, mt, tabledata, num_points, access)[source]¶ Return definition code for the Jacobian of x(X).
J = sum_k xdof_k grad_X xphi_k(X)
-
jacobian_determinant
(e, mt, tabledata, num_points, access)¶ These quantities are expected to be replaced in symbolic preprocessing.
-
jacobian_inverse
(e, mt, tabledata, num_points, access)¶ These quantities are expected to be replaced in symbolic preprocessing.
-
reference_cell_edge_vectors
(e, mt, tabledata, num_points, access)¶ These quantities refer to constant tables defined in ufc_geometry.h.
-
reference_cell_volume
(e, mt, tabledata, num_points, access)¶ These quantities refer to constant tables defined in ufc_geometry.h.
-
reference_facet_edge_vectors
(e, mt, tabledata, num_points, access)¶ These quantities refer to constant tables defined in ufc_geometry.h.
-
reference_facet_volume
(e, mt, tabledata, num_points, access)¶ These quantities refer to constant tables defined in ufc_geometry.h.
-
reference_normal
(e, mt, tabledata, num_points, access)¶ These quantities refer to constant tables defined in ufc_geometry.h.
-
spatial_coordinate
(e, mt, tabledata, num_points, access)[source]¶ Return definition code for the physical spatial coordinates.
- If physical coordinates are given:
- No definition needed.
- If reference coordinates are given:
- x = sum_k xdof_k xphi_k(X)
- If reference facet coordinates are given:
- x = sum_k xdof_k xphi_k(Xf)
-
FFC/UFC specific symbol naming.
-
class
ffc.uflacs.backends.ffc.symbols.
FFCBackendSymbols
(language, coefficient_numbering)[source]¶ Bases:
object
FFC specific symbol definitions. Provides non-ufl symbols.
-
cell_orientation_argument
(restriction)[source]¶ Cell orientation argument in ufc. Not same as cell orientation in generated code.
-
cell_orientation_internal
(restriction)[source]¶ Internal value for cell orientation in generated code.
-
coefficient_dof_sum_index
()[source]¶ Index for loops over coefficient dofs, assumed to never be used in two nested loops.
-
coefficient_value
(mt)[source]¶ Symbol for variable holding value or derivative component of coefficient.
-
custom_quadrature_weights
()[source]¶ Quadrature weights including cell measure scaling, argument to custom integrals.
-
custom_weights_table
()[source]¶ Table for chunk of custom quadrature weights (including cell measure scaling).
-
points_table
(num_points)[source]¶ Table of quadrature points (points on the reference integration entity).
-
The FFC specific backend to the UFLACS form compiler algorithms.
-
ffc.uflacs.backends.ufc.coordinate_mapping.
generate_assign_inverse
(L, K, J, detJ, gdim, tdim)[source]¶
-
ffc.uflacs.backends.ufc.coordinate_mapping.
generate_compute_ATA
(L, ATA, A, m, n, index_prefix='')[source]¶ Generate code to declare and compute ATA[i,j] = sum_k A[k,i]*A[k,j] with given A shaped (m,n).
-
class
ffc.uflacs.backends.ufc.coordinate_mapping.
ufc_coordinate_mapping
[source]¶ Bases:
ffc.uflacs.backends.ufc.generator.ufc_generator
Each function maps to a keyword in the template. See documentation of ufc_generator.
-
class
ffc.uflacs.backends.ufc.dofmap.
ufc_dofmap
[source]¶ Bases:
ffc.uflacs.backends.ufc.generator.ufc_generator
Each function maps to a keyword in the template. See documentation of ufc_generator.
Work in progress translation of FFC evaluatebasis code to uflacs CNodes format.
Work in progress translation of FFC evaluatebasis code to uflacs CNodes format.
-
ffc.uflacs.backends.ufc.evaluatebasis.
generate_compute_basisvalues
(L, dofs_data, element_cellname, tdim, X, ip)[source]¶
-
ffc.uflacs.backends.ufc.evaluatebasis.
generate_evaluate_reference_basis
(L, data, parameters)[source]¶ Generate code to evaluate element basisfunctions at an arbitrary point on the reference element.
The value(s) of the basisfunction is/are computed as in FIAT as the dot product of the coefficients (computed at compile time) and basisvalues which are dependent on the coordinate and thus have to be computed at run time.
The function should work for all elements supported by FIAT, but it remains untested for tensor valued elements.
This code is adapted from code in FFC which computed the basis from physical coordinates, and also to use UFLACS utilities.
The FFC code has a comment “From FIAT_NEW.polynomial_set.tabulate()”.
Work in progress translation of FFC evaluatebasisderivatives code to uflacs CNodes format.
-
ffc.uflacs.backends.ufc.evaluatebasisderivatives.
generate_evaluate_basis_derivatives
(L, data)[source]¶ Evaluate the derivatives of an element basisfunction at a point. The values are computed as in FIAT as the matrix product of the coefficients (computed at compile time), basisvalues which are dependent on the coordinate and thus have to be computed at run time and combinations (depending on the order of derivative) of dmats tables which hold the derivatives of the expansion coefficients.
-
ffc.uflacs.backends.ufc.evaluatedof.
generate_evaluate_dof
(L, ir)[source]¶ Generate code for evaluate_dof.
-
ffc.uflacs.backends.ufc.finite_element.
compute_values
(L, data, dof_data)[source]¶ This function computes the value of the basisfunction as the dot product of the coefficients and basisvalues.
-
ffc.uflacs.backends.ufc.finite_element.
generate_element_mapping
(mapping, i, num_reference_components, tdim, gdim, J, detJ, K)[source]¶
-
class
ffc.uflacs.backends.ufc.finite_element.
ufc_finite_element
[source]¶ Bases:
ffc.uflacs.backends.ufc.generator.ufc_generator
Each function maps to a keyword in the template. See documentation of ufc_generator.
-
ffc.uflacs.backends.ufc.form.
add_ufc_form_integral_methods
(cls)[source]¶ This function generates methods on the class it decorates, for each integral name template and for each integral type.
This allows implementing e.g. create_###_integrals once in the decorated class as ‘_create_foo_integrals’, and this function will expand that implementation into ‘create_cell_integrals’, ‘create_exterior_facet_integrals’, etc.
Name templates are taken from ‘integral_name_templates’ and ‘ufc_integral_types’.
-
class
ffc.uflacs.backends.ufc.form.
ufc_form
[source]¶ Bases:
ffc.uflacs.backends.ufc.generator.ufc_generator
Each function maps to a keyword in the template. See documentation of ufc_generator.
- The exceptions are functions on the form
- def _*_foo_*(self, L, ir, parameters, integral_type, declname)
which add_ufc_form_integral_methods will duplicate for foo = each integral type.
-
create_cell_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_cell_integral().
-
create_custom_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_custom_integral().
-
create_cutcell_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_cutcell_integral().
-
create_default_cell_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_default_cell_integral().
-
create_default_custom_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_default_custom_integral().
-
create_default_cutcell_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_default_cutcell_integral().
-
create_default_exterior_facet_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_default_exterior_facet_integral().
-
create_default_interface_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_default_interface_integral().
-
create_default_interior_facet_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_default_interior_facet_integral().
-
create_default_overlap_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_default_overlap_integral().
-
create_default_vertex_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_default_vertex_integral().
-
create_exterior_facet_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_exterior_facet_integral().
-
create_interface_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_interface_integral().
-
create_interior_facet_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_interior_facet_integral().
-
create_overlap_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_overlap_integral().
-
create_vertex_integral
(L, ir, parameters)¶ Return implementation of ufc::form::create_vertex_integral().
-
has_cell_integrals
(L, ir, parameters)¶ Return implementation of ufc::form::has_cell_integrals().
-
has_custom_integrals
(L, ir, parameters)¶ Return implementation of ufc::form::has_custom_integrals().
-
has_cutcell_integrals
(L, ir, parameters)¶ Return implementation of ufc::form::has_cutcell_integrals().
-
has_exterior_facet_integrals
(L, ir, parameters)¶ Return implementation of ufc::form::has_exterior_facet_integrals().
-
has_interface_integrals
(L, ir, parameters)¶ Return implementation of ufc::form::has_interface_integrals().
-
has_interior_facet_integrals
(L, ir, parameters)¶ Return implementation of ufc::form::has_interior_facet_integrals().
-
has_overlap_integrals
(L, ir, parameters)¶ Return implementation of ufc::form::has_overlap_integrals().
-
has_vertex_integrals
(L, ir, parameters)¶ Return implementation of ufc::form::has_vertex_integrals().
-
max_cell_subdomain_id
(L, ir, parameters)¶ Return implementation of ufc::form::max_cell_subdomain_id().
-
max_custom_subdomain_id
(L, ir, parameters)¶ Return implementation of ufc::form::max_custom_subdomain_id().
-
max_cutcell_subdomain_id
(L, ir, parameters)¶ Return implementation of ufc::form::max_cutcell_subdomain_id().
-
max_exterior_facet_subdomain_id
(L, ir, parameters)¶ Return implementation of ufc::form::max_exterior_facet_subdomain_id().
-
max_interface_subdomain_id
(L, ir, parameters)¶ Return implementation of ufc::form::max_interface_subdomain_id().
-
max_interior_facet_subdomain_id
(L, ir, parameters)¶ Return implementation of ufc::form::max_interior_facet_subdomain_id().
-
max_overlap_subdomain_id
(L, ir, parameters)¶ Return implementation of ufc::form::max_overlap_subdomain_id().
-
max_vertex_subdomain_id
(L, ir, parameters)¶ Return implementation of ufc::form::max_vertex_subdomain_id().
-
class
ffc.uflacs.backends.ufc.generator.
ufc_generator
(basename)[source]¶ Bases:
object
Common functionality for code generators producing ufc classes.
The generate function is the driver for generating code for a class. It automatically extracts each template keyword %(foo)s and calls self.foo(…) to define the code snippet for that keyword.
The standard arguments to every self.foo(…) function are: - L (the language module reference) - ir (the full ir dict) - parameters (the parameters dict, can be omitted) If the second argument is not named “ir”, it must be a valid key in ir, and the value of ir[keyname] is passed instead of the full ir dict. Invalid keynames result in attempts at informative errors, meaning errors will often be caught early when making changes.
-
constructor_arguments
(L, ir)[source]¶ Return empty string. Override in classes that need constructor.
-
generate
(L, ir, parameters=None, snippets=None, jit=False)[source]¶ Return composition of templates with generated snippets.
-
-
class
ffc.uflacs.backends.ufc.integrals.
ufc_integral
(integral_type)[source]¶ Bases:
ffc.uflacs.backends.ufc.generator.ufc_generator
Each function maps to a keyword in the template. See documentation of ufc_generator.
-
ffc.uflacs.backends.ufc.utils.
generate_return_literal_switch
(L, i, values, default, literal_type, typename=None)[source]¶
Backend for generating UFC code.
Collection of backends to UFLACS form compiler algorithms.
In the end we want to specify a clean and mature API here.
We may or may not want to move e.g. the FFC backend to FFC instead of having it here.
-
class
ffc.uflacs.language.cnodes.
Add
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '+'¶
-
precedence
= 5¶
-
-
class
ffc.uflacs.language.cnodes.
AddressOf
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.PrefixUnaryOp
-
op
= '&'¶
-
precedence
= 3¶
-
-
class
ffc.uflacs.language.cnodes.
And
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '&&'¶
-
precedence
= 11¶
-
-
class
ffc.uflacs.language.cnodes.
ArrayAccess
(array, indices)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprOperator
-
array
¶
-
indices
¶
-
precedence
= 2¶
-
-
class
ffc.uflacs.language.cnodes.
ArrayDecl
(typename, symbol, sizes=None, values=None, alignas=None, padlen=0)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
A declaration or definition of an array.
Note that just setting values=0 is sufficient to initialize the entire array to zero.
Otherwise use nested lists of lists to represent multidimensional array values to initialize to.
-
alignas
¶
-
is_scoped
= False¶
-
padlen
¶
-
sizes
¶
-
symbol
¶
-
typename
¶
-
values
¶
-
-
class
ffc.uflacs.language.cnodes.
Assign
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '='¶
-
-
class
ffc.uflacs.language.cnodes.
AssignAdd
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '+='¶
-
-
class
ffc.uflacs.language.cnodes.
AssignAnd
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '&&='¶
-
-
class
ffc.uflacs.language.cnodes.
AssignBitAnd
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '&='¶
-
-
class
ffc.uflacs.language.cnodes.
AssignBitOr
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '|='¶
-
-
class
ffc.uflacs.language.cnodes.
AssignBitXor
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '^='¶
-
-
class
ffc.uflacs.language.cnodes.
AssignDiv
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '/='¶
-
-
class
ffc.uflacs.language.cnodes.
AssignLShift
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '<<='¶
-
-
class
ffc.uflacs.language.cnodes.
AssignMod
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '%='¶
-
-
class
ffc.uflacs.language.cnodes.
AssignMul
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '*='¶
-
-
class
ffc.uflacs.language.cnodes.
AssignOp
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
Base class for assignment operators.
-
precedence
= 13¶
-
sideeffect
= True¶
-
-
class
ffc.uflacs.language.cnodes.
AssignOr
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '||='¶
-
-
class
ffc.uflacs.language.cnodes.
AssignRShift
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '>>='¶
-
-
class
ffc.uflacs.language.cnodes.
AssignSub
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.AssignOp
-
op
= '-='¶
-
-
class
ffc.uflacs.language.cnodes.
BinOp
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprOperator
-
lhs
¶
-
rhs
¶
-
-
class
ffc.uflacs.language.cnodes.
BitAnd
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '&'¶
-
precedence
= 8¶
-
-
class
ffc.uflacs.language.cnodes.
BitNot
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.PrefixUnaryOp
-
op
= '~'¶
-
precedence
= 3¶
-
-
class
ffc.uflacs.language.cnodes.
BitOr
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '|'¶
-
precedence
= 10¶
-
-
class
ffc.uflacs.language.cnodes.
BitXor
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '^'¶
-
precedence
= 9¶
-
-
class
ffc.uflacs.language.cnodes.
Break
[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
is_scoped
= True¶
-
-
class
ffc.uflacs.language.cnodes.
CExpr
[source]¶ Bases:
ffc.uflacs.language.cnodes.CNode
Base class for all C expressions.
All subtypes should define a ‘precedence’ class attribute.
-
class
ffc.uflacs.language.cnodes.
CExprLiteral
[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprTerminal
A float or int literal value.
-
precedence
= 0¶
-
-
class
ffc.uflacs.language.cnodes.
CExprOperator
[source]¶ Bases:
ffc.uflacs.language.cnodes.CExpr
Base class for all C expression operator.
-
sideeffect
= False¶
-
-
class
ffc.uflacs.language.cnodes.
CExprTerminal
[source]¶ Bases:
ffc.uflacs.language.cnodes.CExpr
Base class for all C expression terminals.
-
sideeffect
= False¶
-
-
class
ffc.uflacs.language.cnodes.
CNode
[source]¶ Bases:
object
Base class for all C AST nodes.
-
debug
= False¶
-
-
class
ffc.uflacs.language.cnodes.
CStatement
[source]¶ Bases:
ffc.uflacs.language.cnodes.CNode
Base class for all C statements.
Subtypes do _not_ define a ‘precedence’ class attribute.
-
is_scoped
= False¶
-
-
class
ffc.uflacs.language.cnodes.
Call
(function, arguments=None)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprOperator
-
arguments
¶
-
function
¶
-
precedence
= 2¶
-
sideeffect
= True¶
-
-
class
ffc.uflacs.language.cnodes.
Case
(value)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
is_scoped
= False¶
-
value
¶
-
-
class
ffc.uflacs.language.cnodes.
Comment
(comment)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
Line comment(s) used for annotating the generated code with human readable remarks.
-
comment
¶
-
is_scoped
= True¶
-
-
class
ffc.uflacs.language.cnodes.
Conditional
(condition, true, false)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprOperator
-
condition
¶
-
false
¶
-
precedence
= 13¶
-
true
¶
-
-
class
ffc.uflacs.language.cnodes.
Continue
[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
is_scoped
= True¶
-
-
class
ffc.uflacs.language.cnodes.
Default
[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
is_scoped
= False¶
-
-
class
ffc.uflacs.language.cnodes.
Dereference
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.PrefixUnaryOp
-
op
= '*'¶
-
precedence
= 3¶
-
-
class
ffc.uflacs.language.cnodes.
Div
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '/'¶
-
precedence
= 4¶
-
-
class
ffc.uflacs.language.cnodes.
Do
(condition, body)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
body
¶
-
condition
¶
-
is_scoped
= True¶
-
-
class
ffc.uflacs.language.cnodes.
EQ
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '=='¶
-
precedence
= 7¶
-
-
class
ffc.uflacs.language.cnodes.
Else
(body)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
body
¶
-
is_scoped
= True¶
-
-
class
ffc.uflacs.language.cnodes.
ElseIf
(condition, body)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
body
¶
-
condition
¶
-
is_scoped
= True¶
-
-
class
ffc.uflacs.language.cnodes.
FlattenedArray
(array, dummy=None, dims=None, strides=None, offset=None)[source]¶ Bases:
object
Syntax carrying object only, will get translated on __getitem__ to ArrayAccess.
-
array
¶
-
dims
¶
-
offset
¶
-
strides
¶
-
-
class
ffc.uflacs.language.cnodes.
For
(init, check, update, body, pragma=None)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
body
¶
-
check
¶
-
init
¶
-
is_scoped
= True¶
-
pragma
¶
-
update
¶
-
-
class
ffc.uflacs.language.cnodes.
ForRange
(index, begin, end, body, index_type='int', vectorize=None)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
Slightly higher-level for loop assuming incrementing an index over a range.
-
begin
¶
-
body
¶
-
end
¶
-
index
¶
-
index_type
¶
-
is_scoped
= True¶
-
pragma
¶
-
-
class
ffc.uflacs.language.cnodes.
GE
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '>='¶
-
precedence
= 6¶
-
-
class
ffc.uflacs.language.cnodes.
GT
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '>'¶
-
precedence
= 6¶
-
-
class
ffc.uflacs.language.cnodes.
If
(condition, body)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
body
¶
-
condition
¶
-
is_scoped
= True¶
-
-
class
ffc.uflacs.language.cnodes.
LE
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '<='¶
-
precedence
= 6¶
-
-
class
ffc.uflacs.language.cnodes.
LT
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '<'¶
-
precedence
= 6¶
-
-
class
ffc.uflacs.language.cnodes.
LiteralBool
(value)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprLiteral
A boolean literal value.
-
precedence
= 0¶
-
value
¶
-
-
class
ffc.uflacs.language.cnodes.
LiteralFloat
(value)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprLiteral
A floating point literal value.
-
precedence
= 0¶
-
value
¶
-
-
class
ffc.uflacs.language.cnodes.
LiteralInt
(value)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprLiteral
An integer literal value.
-
precedence
= 0¶
-
value
¶
-
-
class
ffc.uflacs.language.cnodes.
LiteralString
(value)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprLiteral
A boolean literal value.
-
precedence
= 0¶
-
value
¶
-
-
class
ffc.uflacs.language.cnodes.
Mod
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '%'¶
-
precedence
= 4¶
-
-
class
ffc.uflacs.language.cnodes.
Mul
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '*'¶
-
precedence
= 4¶
-
-
class
ffc.uflacs.language.cnodes.
NE
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '!='¶
-
precedence
= 7¶
-
-
class
ffc.uflacs.language.cnodes.
Namespace
(name, body)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
body
¶
-
is_scoped
= True¶
-
name
¶
-
-
class
ffc.uflacs.language.cnodes.
NaryOp
(args)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprOperator
Base class for special n-ary operators.
-
args
¶
-
-
class
ffc.uflacs.language.cnodes.
Neg
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.PrefixUnaryOp
-
op
= '-'¶
-
precedence
= 3¶
-
-
class
ffc.uflacs.language.cnodes.
New
(typename)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExpr
-
typename
¶
-
-
class
ffc.uflacs.language.cnodes.
Not
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.PrefixUnaryOp
-
op
= '!'¶
-
precedence
= 3¶
-
-
class
ffc.uflacs.language.cnodes.
Null
[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprLiteral
A null pointer literal.
-
precedence
= 0¶
-
-
class
ffc.uflacs.language.cnodes.
Or
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '||'¶
-
precedence
= 12¶
-
-
class
ffc.uflacs.language.cnodes.
Pos
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.PrefixUnaryOp
-
op
= '+'¶
-
precedence
= 3¶
-
-
class
ffc.uflacs.language.cnodes.
PostDecrement
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.PostfixUnaryOp
-
op
= '--'¶
-
precedence
= 2¶
-
sideeffect
= True¶
-
-
class
ffc.uflacs.language.cnodes.
PostIncrement
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.PostfixUnaryOp
-
op
= '++'¶
-
precedence
= 2¶
-
sideeffect
= True¶
-
-
class
ffc.uflacs.language.cnodes.
PostfixUnaryOp
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.UnaryOp
Base class for postfix unary operators.
-
class
ffc.uflacs.language.cnodes.
Pragma
(comment)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
Pragma comments used for compiler-specific annotations.
-
comment
¶
-
is_scoped
= True¶
-
-
class
ffc.uflacs.language.cnodes.
PreDecrement
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.PrefixUnaryOp
-
op
= '--'¶
-
precedence
= 3¶
-
sideeffect
= True¶
-
-
class
ffc.uflacs.language.cnodes.
PreIncrement
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.PrefixUnaryOp
-
op
= '++'¶
-
precedence
= 3¶
-
sideeffect
= True¶
-
-
class
ffc.uflacs.language.cnodes.
PrefixUnaryOp
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.UnaryOp
Base class for prefix unary operators.
-
class
ffc.uflacs.language.cnodes.
Product
(args)[source]¶ Bases:
ffc.uflacs.language.cnodes.NaryOp
Product of any number of operands.
-
op
= '*'¶
-
precedence
= 4¶
-
-
class
ffc.uflacs.language.cnodes.
Return
(value=None)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
is_scoped
= True¶
-
value
¶
-
-
class
ffc.uflacs.language.cnodes.
Scope
(body)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
body
¶
-
is_scoped
= True¶
-
-
class
ffc.uflacs.language.cnodes.
SizeOf
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.PrefixUnaryOp
-
op
= 'sizeof'¶
-
precedence
= 3¶
-
-
class
ffc.uflacs.language.cnodes.
Statement
(expr)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
Make an expression into a statement.
-
expr
¶
-
is_scoped
= False¶
-
-
class
ffc.uflacs.language.cnodes.
StatementList
(statements)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
A simple sequence of statements. No new scopes are introduced.
-
is_scoped
¶ bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
-
statements
¶
-
-
class
ffc.uflacs.language.cnodes.
Sub
(lhs, rhs)[source]¶ Bases:
ffc.uflacs.language.cnodes.BinOp
-
op
= '-'¶
-
precedence
= 5¶
-
-
class
ffc.uflacs.language.cnodes.
Sum
(args)[source]¶ Bases:
ffc.uflacs.language.cnodes.NaryOp
Sum of any number of operands.
-
op
= '+'¶
-
precedence
= 5¶
-
-
class
ffc.uflacs.language.cnodes.
Switch
(arg, cases, default=None, autobreak=True, autoscope=True)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
arg
¶
-
autobreak
¶
-
autoscope
¶
-
cases
¶
-
default
¶
-
is_scoped
= True¶
-
-
class
ffc.uflacs.language.cnodes.
Symbol
(name)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprTerminal
A named symbol.
-
name
¶
-
precedence
= 0¶
-
-
class
ffc.uflacs.language.cnodes.
Throw
(exception, message)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
exception
¶
-
is_scoped
= True¶
-
message
¶
-
-
class
ffc.uflacs.language.cnodes.
UnaryOp
(arg)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprOperator
Base class for unary operators.
-
arg
¶
-
-
class
ffc.uflacs.language.cnodes.
Using
(name)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
is_scoped
= True¶
-
name
¶
-
-
class
ffc.uflacs.language.cnodes.
VariableDecl
(typename, symbol, value=None)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
Declare a variable, optionally define initial value.
-
is_scoped
= False¶
-
symbol
¶
-
typename
¶
-
value
¶
-
-
class
ffc.uflacs.language.cnodes.
VerbatimExpr
(codestring)[source]¶ Bases:
ffc.uflacs.language.cnodes.CExprTerminal
A verbatim copy of an expression source string.
Handled as having the lowest precedence which will introduce parentheses around it most of the time.
-
codestring
¶
-
precedence
= 15¶
-
-
class
ffc.uflacs.language.cnodes.
VerbatimStatement
(codestring)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
Wraps a source code string to be pasted verbatim into the source code.
-
codestring
¶
-
is_scoped
= False¶
-
-
class
ffc.uflacs.language.cnodes.
While
(condition, body)[source]¶ Bases:
ffc.uflacs.language.cnodes.CStatement
-
body
¶
-
condition
¶
-
is_scoped
= True¶
-
-
ffc.uflacs.language.cnodes.
accumulate_loop
(dst, src, ranges)[source]¶ Generate a nested loop over a list of ranges, adding src to dst in the innermost loop.
Ranges is a list on the format [(index, begin, end),…].
-
ffc.uflacs.language.cnodes.
as_cexpr
(node)[source]¶ Typechecks and wraps an object as a valid CExpr.
Accepts CExpr nodes, treats int and float as literals, and treats a string as a symbol.
-
ffc.uflacs.language.cnodes.
as_cstatement
(node)[source]¶ Perform type checking on node and wrap in a suitable statement type if necessary.
-
ffc.uflacs.language.cnodes.
assign_loop
(dst, src, ranges)[source]¶ Generate a nested loop over a list of ranges, assigning src to dst in the innermost loop.
Ranges is a list on the format [(index, begin, end),…].
-
ffc.uflacs.language.cnodes.
build_1d_initializer_list
(values, formatter, padlen=0, precision=None)[source]¶ Return a list containing a single line formatted like “{ 0.0, 1.0, 2.0 }”
-
ffc.uflacs.language.cnodes.
build_initializer_lists
(values, sizes, level, formatter, padlen=0, precision=None)[source]¶ Return a list of lines with initializer lists for a multidimensional array.
Example output:
{ { 0.0, 0.1 }, { 1.0, 1.1 } }
-
ffc.uflacs.language.cnodes.
commented_code_list
(code, comments)[source]¶ Convenience wrapper for adding comment to code list if the list is not empty.
-
ffc.uflacs.language.cnodes.
flattened_indices
(indices, shape)[source]¶ Given a tuple of indices and a shape tuple, return CNode expression for flattened indexing into multidimensional array.
Indices and shape entries can be int values, str symbol names, or CNode expressions.
-
ffc.uflacs.language.cnodes.
float_product
(factors)[source]¶ Build product of float factors, simplifying ones and zeros and returning 1.0 if empty sequence.
-
ffc.uflacs.language.cnodes.
leftover
(size, padlen)[source]¶ Return minimum integer to add to size to make it divisible by padlen.
Tools for indentation-aware code string stitching.
When formatting an AST into a string, it’s better to collect lists of snippets and then join them than adding the pieces continually, which gives O(n^2) behaviour w.r.t. AST size n.
-
class
ffc.uflacs.language.format_lines.
Indented
(body)[source]¶ Bases:
object
Class to mark a collection of snippets for indentation.
This way nested indentations can be handled by adding the prefix spaces only once to each line instead of splitting and indenting substrings repeatedly.
-
body
¶
-
-
ffc.uflacs.language.format_lines.
format_indented_lines
(snippets, level=0)[source]¶ Format recursive sequences of indented lines as one string.
-
ffc.uflacs.language.format_lines.
iter_indented_lines
(snippets, level=0)[source]¶ Iterate over indented string lines from a snippets data structure.
The snippets object can be built recursively using the following types:
- str: Split and yield as one line at a time indented to the appropriate level.
- Indented: Yield the lines within this object indented by one level.
- tuple,list: Yield lines from recursive application of this function to list items.
-
class
ffc.uflacs.language.precedence.
PRECEDENCE
[source]¶ Bases:
object
An enum-like class for C operator precedence levels.
-
ADD
= 5¶
-
ADDRESSOF
= 3¶
-
AND
= 11¶
-
ASSIGN
= 13¶
-
BIT_AND
= 8¶
-
BIT_NOT
= 3¶
-
BIT_OR
= 10¶
-
BIT_XOR
= 9¶
-
CALL
= 2¶
-
CONDITIONAL
= 13¶
-
DEREFERENCE
= 3¶
-
DIV
= 4¶
-
EQ
= 7¶
-
GE
= 6¶
-
GT
= 6¶
-
HIGHEST
= 0¶
-
LE
= 6¶
-
LITERAL
= 0¶
-
LOWEST
= 15¶
-
LT
= 6¶
-
MOD
= 4¶
-
MUL
= 4¶
-
NE
= 7¶
-
NEG
= 3¶
-
NOT
= 3¶
-
OR
= 12¶
-
POS
= 3¶
-
POST_DEC
= 2¶
-
POST_INC
= 2¶
-
PRE_DEC
= 3¶
-
PRE_INC
= 3¶
-
SIZEOF
= 3¶
-
SUB
= 5¶
-
SUBSCRIPT
= 2¶
-
SYMBOL
= 0¶
-
Tools for C/C++ expression formatting.
-
class
ffc.uflacs.language.ufl_to_cnodes.
UFL2CNodesMixin
(language)[source]¶ Bases:
object
Rules collection mixin for a UFL to CNodes translator class.
-
class
ffc.uflacs.language.ufl_to_cnodes.
UFL2CNodesTranslatorC
(language)[source]¶ Bases:
ufl.corealg.multifunction.MultiFunction
,ffc.uflacs.language.ufl_to_cnodes.UFL2CNodesMixin
,ffc.uflacs.language.ufl_to_cnodes.RulesForC
UFL to CNodes translator class.
-
class
ffc.uflacs.language.ufl_to_cnodes.
UFL2CNodesTranslatorCpp
(language)[source]¶ Bases:
ufl.corealg.multifunction.MultiFunction
,ffc.uflacs.language.ufl_to_cnodes.UFL2CNodesMixin
,ffc.uflacs.language.ufl_to_cnodes.RulesForCpp
UFL to CNodes translator class.
Submodules¶
ffc.uflacs.build_uflacs_ir module¶
Main algorithm for building the uflacs intermediate representation.
-
ffc.uflacs.build_uflacs_ir.
analyse_dependencies
(V, V_deps, V_targets, modified_terminal_indices, modified_terminals, mt_unique_table_reference)[source]¶
-
ffc.uflacs.build_uflacs_ir.
build_scalar_graph
(expressions)[source]¶ Build list representation of expression graph covering the given expressions.
TODO: Renaming, refactoring and cleanup of the graph building algorithms used in here
-
ffc.uflacs.build_uflacs_ir.
build_uflacs_ir
(cell, integral_type, entitytype, integrands, tensor_shape, coefficient_numbering, quadrature_rules, parameters)[source]¶
-
class
ffc.uflacs.build_uflacs_ir.
common_block_data_t
(block_mode, ttypes, factor_index, factor_is_piecewise, unames, restrictions, transposed)¶ Bases:
tuple
-
block_mode
¶ Alias for field number 0
-
factor_index
¶ Alias for field number 2
-
factor_is_piecewise
¶ Alias for field number 3
-
restrictions
¶ Alias for field number 5
-
transposed
¶ Alias for field number 6
-
ttypes
¶ Alias for field number 1
-
unames
¶ Alias for field number 4
-
-
class
ffc.uflacs.build_uflacs_ir.
full_block_data_t
(block_mode, ttypes, factor_index, factor_is_piecewise, unames, restrictions, transposed, ma_data)¶ Bases:
tuple
-
block_mode
¶ Alias for field number 0
-
factor_index
¶ Alias for field number 2
-
factor_is_piecewise
¶ Alias for field number 3
-
ma_data
¶ Alias for field number 7
-
restrictions
¶ Alias for field number 5
-
transposed
¶ Alias for field number 6
-
ttypes
¶ Alias for field number 1
-
unames
¶ Alias for field number 4
-
-
ffc.uflacs.build_uflacs_ir.
integrate_block
(weights, unames, ttypes, unique_tables, unique_table_num_dofs)[source]¶
-
ffc.uflacs.build_uflacs_ir.
integrate_block_interior_facets
(weights, unames, ttypes, unique_tables, unique_table_num_dofs)[source]¶
-
class
ffc.uflacs.build_uflacs_ir.
ma_data_t
(ma_index, tabledata)¶ Bases:
tuple
-
ma_index
¶ Alias for field number 0
-
tabledata
¶ Alias for field number 1
-
-
ffc.uflacs.build_uflacs_ir.
multiply_block
(point_index, unames, ttypes, unique_tables, unique_table_num_dofs)[source]¶
-
ffc.uflacs.build_uflacs_ir.
multiply_block_interior_facets
(point_index, unames, ttypes, unique_tables, unique_table_num_dofs)[source]¶
-
ffc.uflacs.build_uflacs_ir.
parse_uflacs_optimization_parameters
(parameters, integral_type)[source]¶ Following model from quadrature representation, extracting uflacs specific parameters from the global parameters dict.
-
class
ffc.uflacs.build_uflacs_ir.
partial_block_data_t
(block_mode, ttypes, factor_index, factor_is_piecewise, unames, restrictions, transposed, ma_data, piecewise_ma_index)¶ Bases:
tuple
-
block_mode
¶ Alias for field number 0
-
factor_index
¶ Alias for field number 2
-
factor_is_piecewise
¶ Alias for field number 3
-
ma_data
¶ Alias for field number 7
-
piecewise_ma_index
¶ Alias for field number 8
-
restrictions
¶ Alias for field number 5
-
transposed
¶ Alias for field number 6
-
ttypes
¶ Alias for field number 1
-
unames
¶ Alias for field number 4
-
-
class
ffc.uflacs.build_uflacs_ir.
preintegrated_block_data_t
(block_mode, ttypes, factor_index, factor_is_piecewise, unames, restrictions, transposed, is_uniform, name)¶ Bases:
tuple
-
block_mode
¶ Alias for field number 0
-
factor_index
¶ Alias for field number 2
-
factor_is_piecewise
¶ Alias for field number 3
-
is_uniform
¶ Alias for field number 7
-
name
¶ Alias for field number 8
-
restrictions
¶ Alias for field number 5
-
transposed
¶ Alias for field number 6
-
ttypes
¶ Alias for field number 1
-
unames
¶ Alias for field number 4
-
-
class
ffc.uflacs.build_uflacs_ir.
premultiplied_block_data_t
(block_mode, ttypes, factor_index, factor_is_piecewise, unames, restrictions, transposed, is_uniform, name)¶ Bases:
tuple
-
block_mode
¶ Alias for field number 0
-
factor_index
¶ Alias for field number 2
-
factor_is_piecewise
¶ Alias for field number 3
-
is_uniform
¶ Alias for field number 7
-
name
¶ Alias for field number 8
-
restrictions
¶ Alias for field number 5
-
transposed
¶ Alias for field number 6
-
ttypes
¶ Alias for field number 1
-
unames
¶ Alias for field number 4
-
ffc.uflacs.elementtables module¶
Tools for precomputed tables of terminal values.
-
ffc.uflacs.elementtables.
build_element_tables
(num_points, quadrature_rules, cell, integral_type, entitytype, modified_terminals, rtol=1e-05, atol=1e-08)[source]¶ Build the element tables needed for a list of modified terminals.
- Input:
- entitytype - str modified_terminals - ordered sequence of unique modified terminals FIXME: Document
- Output:
- tables - dict(name: table) mt_table_names - dict(ModifiedTerminal: name)
-
ffc.uflacs.elementtables.
build_optimized_tables
(num_points, quadrature_rules, cell, integral_type, entitytype, modified_terminals, existing_tables, compress_zeros, rtol=1e-05, atol=1e-08)[source]¶
-
ffc.uflacs.elementtables.
build_unique_tables
(tables, rtol=1e-05, atol=1e-08)[source]¶ Given a list or dict of tables, return a list of unique tables and a dict of unique table indices for each input table key.
-
ffc.uflacs.elementtables.
clamp_table_small_numbers
(table, rtol=1e-05, atol=1e-08, numbers=(-1.0, -0.5, 0.0, 0.5, 1.0))[source]¶ Clamp almost 0,1,-1 values to integers. Returns new table.
-
ffc.uflacs.elementtables.
generate_psi_table_name
(num_points, element_counter, averaged, entitytype, derivative_counts, flat_component)[source]¶ Generate a name for the psi table of the form: FE#_C#_D###[_AC|_AF|][_F|V][_Q#], where ‘#’ will be an integer value.
- FE - is a simple counter to distinguish the various bases, it will be
- assigned in an arbitrary fashion.
- C - is the component number if any (this does not yet take into account
- tensor valued functions)
- D - is the number of derivatives in each spatial direction if any.
- If the element is defined in 3D, then D012 means d^3(*)/dydz^2.
AC - marks that the element values are averaged over the cell
AF - marks that the element values are averaged over the facet
F - marks that the first array dimension enumerates facets on the cell
V - marks that the first array dimension enumerates vertices on the cell
Q - number of quadrature points, to distinguish between tables in a mixed quadrature degree setting
-
ffc.uflacs.elementtables.
get_ffc_table_values
(points, cell, integral_type, ufl_element, avg, entitytype, derivative_counts, flat_component)[source]¶ Extract values from ffc element table.
Returns a 3D numpy array with axes (entity number, quadrature point number, dof number)
-
ffc.uflacs.elementtables.
optimize_element_tables
(tables, table_origins, compress_zeros, rtol=1e-05, atol=1e-08)[source]¶ Optimize tables and make unique set.
Steps taken:
- clamp values that are very close to -1, 0, +1 to those values
- remove dofs from beginning and end of tables where values are all zero
- for each modified terminal, provide the dof range that a given table corresponds to
- Terminology:
name - str, name used in input arguments here table - numpy array of float values stripped_table - numpy array of float values with zeroes
removed from each end of dofrange- Input:
- tables - { name: table } table_origins - FIXME
- Output:
- unique_tables - { unique_name: stripped_table } unique_table_origins - FIXME
-
ffc.uflacs.elementtables.
strip_table_zeros
(table, compress_zeros, rtol=1e-05, atol=1e-08)[source]¶ Strip zero columns from table. Returns column range (begin, end) and the new compact table.
-
ffc.uflacs.elementtables.
table_origin_t
¶ alias of
ffc.uflacs.elementtables.table_origin
-
ffc.uflacs.elementtables.
unique_table_reference_t
¶ alias of
ffc.uflacs.elementtables.unique_table_reference
ffc.uflacs.integralgenerator module¶
Controlling algorithm for building the tabulate_tensor source structure from factorized representation.
-
class
ffc.uflacs.integralgenerator.
IntegralGenerator
(ir, backend, precision)[source]¶ Bases:
object
-
generate
()[source]¶ Generate entire tabulate_tensor body.
Assumes that the code returned from here will be wrapped in a context that matches a suitable version of the UFC tabulate_tensor signatures.
-
generate_block_parts
(num_points, blockmap, blockdata)[source]¶ Generate and return code parts for a given block.
Returns parts occuring before, inside, and after the quadrature loop identified by num_points.
Should be called with num_points=None for quadloop-independent blocks.
-
generate_element_tables
()[source]¶ Generate static tables with precomputed element basis function values in quadrature points.
-
generate_runtime_quadrature_loop
()[source]¶ Generate quadrature loop for custom integrals, with physical points given runtime.
-
get_var
(num_points, v)[source]¶ “Lookup ufl expression v in variable scope dicts.
Scope is determined by num_points which identifies the quadrature loop scope or None if outside quadrature loops.
If v is not found in quadrature loop scope, the piecewise scope (None) is checked.
Returns the CNodes expression to access the value in the code.
-
ffc.uflacs.params module¶
Collection of exposed parameters available to tune form compiler algorithms.
ffc.uflacs.tools module¶
-
ffc.uflacs.tools.
accumulate_integrals
(itg_data, quadrature_rule_sizes)[source]¶ Group and accumulate integrals according to the number of quadrature points in their rules.
ffc.uflacs.uflacsgenerator module¶
Controlling algorithm for building the tabulate_tensor source structure from factorized representation.
ffc.uflacs.uflacsoptimization module¶
ffc.uflacs.uflacsrepresentation module¶
Module contents¶
This is UFLACS, the UFL Analyser and Compiler System.
Submodules¶
ffc.analysis module¶
Compiler stage 1: Analysis¶
This module implements the analysis/preprocessing of variational forms, including automatic selection of elements, degrees and form representation type.
-
ffc.analysis.
analyze_forms
(forms, parameters)[source]¶ Analyze form(s), returning
form_datas - a tuple of form_data objects unique_elements - a tuple of unique elements across all forms element_numbers - a mapping to unique numbers for all elements
-
ffc.analysis.
analyze_ufl_objects
(ufl_objects, kind, parameters)[source]¶ Analyze ufl object(s), either forms, elements, or coordinate mappings, returning:
form_datas - a tuple of form_data objects unique_elements - a tuple of unique elements across all forms element_numbers - a mapping to unique numbers for all elements
ffc.classname module¶
This module defines some basics for generating C++ code.
ffc.codegeneration module¶
ffc.compiler module¶
This is the compiler, acting as the main interface for compilation of forms and breaking the compilation into several sequential stages. The output of each stage is the input of the next stage.
Compiler stage 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 completely handled by UFL.
Compiler stage 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.
Compiler stage 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.
Compiler stage 3: Optimization¶
Input: Intermediate Representation (IR) Output: Optimized Intermediate Representation (OIR)
This stage examines the IR and performs optimizations.
Optimization is currently disabled as a separate stage but is implemented as part of the code generation for quadrature representation.
Compiler stage 4: Code generation¶
Input: Optimized Intermediate Representation (OIR) Output: C++ code
This stage examines the OIR 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.
Compiler stage 5: 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/.cpp files conforming to the UFC format.
The main interface is defined by the following two functions:
compile_form compile_element
The compiler stages are implemented by the following functions:
analyze_forms or analyze_elements (stage 1) compute_ir (stage 2) optimize_ir (stage 3) generate_code (stage 4) format_code (stage 5)
ffc.fiatinterface module¶
-
class
ffc.fiatinterface.
SpaceOfReals
[source]¶ Bases:
object
Constant over the entire domain, rather than just cellwise.
-
ffc.fiatinterface.
create_quadrature
(shape, degree, scheme='default')[source]¶ Generate quadrature rule (points, weights) for given shape that will integrate an polynomial of order ‘degree’ exactly.
-
ffc.fiatinterface.
map_facet_points
(points, facet, cellname)[source]¶ Map points from the e (UFC) reference simplex of dimension d - 1 to a given facet on the (UFC) reference simplex of dimension d. This may be used to transform points tabulated for example on the 2D reference triangle to points on a given facet of the reference tetrahedron.
ffc.formatting module¶
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 ufc_utils.
ffc.git_commit_hash module¶
ffc.jitcompiler module¶
This module provides a just-in-time (JIT) form compiler. It uses dijitso to wrap the generated code into a Python module.
-
exception
ffc.jitcompiler.
FFCJitError
[source]¶ Bases:
ffc.jitcompiler.FFCError
-
ffc.jitcompiler.
compute_jit_prefix
(ufl_object, parameters, kind=None)[source]¶ Compute the prefix (module name) for jit modules.
-
ffc.jitcompiler.
jit
(ufl_object, parameters=None, indirect=False)[source]¶ Just-in-time compile the given form or element
Parameters:
ufl_object : The UFL object to be compiled parameters : A set of parameters
ffc.log module¶
This module provides functions used by the FFC implementation to output messages. These may be redirected by the user of FFC.
This module reuses the corresponding log.py module from UFL which is a wrapper for the standard Python logging module.
-
ffc.log.
add_indent
(*message)¶
-
ffc.log.
add_logfile
(*message)¶
-
ffc.log.
begin
(*message)¶
-
ffc.log.
debug
(*message)¶
-
ffc.log.
deprecate
(*message)¶
-
ffc.log.
end
(*message)¶
-
ffc.log.
error
(*message)¶
-
ffc.log.
ffc_assert
(condition, *message)[source]¶ Assert that condition is true and otherwise issue an error with given message.
-
ffc.log.
get_handler
(*message)¶
-
ffc.log.
get_logger
(*message)¶
-
ffc.log.
info
(*message)¶
-
ffc.log.
info_blue
(*message)¶
-
ffc.log.
info_green
(*message)¶
-
ffc.log.
info_red
(*message)¶
-
ffc.log.
log
(*message)¶
-
ffc.log.
pop_level
(*message)¶
-
ffc.log.
push_level
(*message)¶
-
ffc.log.
set_handler
(*message)¶
-
ffc.log.
set_indent
(*message)¶
-
ffc.log.
set_level
(*message)¶
-
ffc.log.
set_prefix
(*message)¶
-
ffc.log.
warning
(*message)¶
-
ffc.log.
warning_blue
(*message)¶
-
ffc.log.
warning_green
(*message)¶
-
ffc.log.
warning_red
(*message)¶
ffc.main module¶
This script is the command-line interface to FFC.
It parses command-line arguments and generates code from input UFL form files.
ffc.optimization module¶
ffc.parameters module¶
-
ffc.parameters.
compute_jit_parameters_signature
(parameters)[source]¶ Return parameters signature (some parameters must be ignored).
-
ffc.parameters.
default_parameters
()[source]¶ Return (a copy of) the default parameter values for FFC.
-
ffc.parameters.
split_parameters
(parameters)[source]¶ Split a parameters dict into groups based on what parameters are used for.
ffc.plot module¶
This module provides functionality for plotting finite elements.
ffc.representation module¶
Compiler stage 2: Code representation¶
This 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”.
-
ffc.representation.
compute_ir
(analysis, prefix, parameters, jit=False)[source]¶ Compute intermediate representation.
-
ffc.representation.
make_all_element_classnames
(prefix, elements, coordinate_elements, element_numbers, parameters, jit)[source]¶
ffc.representationutils module¶
This module contains utility functions for some code shared between quadrature and tensor representation.
-
ffc.representationutils.
create_quadrature_points_and_weights
(integral_type, cell, degree, rule)[source]¶ Create quadrature rule and return points and weights.
-
ffc.representationutils.
initialize_integral_code
(ir, prefix, parameters)[source]¶ Representation independent default initialization of code dict for integral from intermediate representation.
-
ffc.representationutils.
initialize_integral_ir
(representation, itg_data, form_data, form_id)[source]¶ Initialize a representation dict with common information that is expected independently of which representation is chosen.
-
ffc.representationutils.
integral_type_to_entity_dim
(integral_type, tdim)[source]¶ Given integral_type and domain tdim, return the tdim of the integration entity.
-
ffc.representationutils.
map_integral_points
(points, integral_type, cell, entity)[source]¶ Map points from reference entity to its parent reference cell.
-
ffc.representationutils.
transform_component
(component, offset, ufl_element)[source]¶ This function accounts for the fact that if the geometrical and topological dimension does not match, then for native vector elements, in particular the Piola-mapped ones, the physical value dimensions and the reference value dimensions are not the same. This has certain consequences for mixed elements, aka ‘fun with offsets’.
ffc.utils module¶
-
ffc.utils.
compute_permutations
(k, n, skip=[])[source]¶ Compute all permutations of k elements from (0, n) in rising order. Any elements that are contained in the list skip are not included.
-
ffc.utils.
insert_nested_dict
(root, keys, value)[source]¶ Set root[keys[0]][…][keys[-1]] = value, creating subdicts on the way if missing.
ffc.wrappers module¶
Module contents¶
FEniCS Form Compiler (FFC)¶
FFC compiles finite element variational forms into C++ code.
The interface consists of the following functions:
compile_form - Compilation of forms compile_element - Compilation of finite elements jit - Just-In-Time compilation of forms and elements default_parameters - Default parameter values for FFC ufc_signature - Signature of UFC interface (SHA-1 hash of ufc.h)
Release notes¶
Changes in the next release¶
Summary of changes¶
Note
Developers should use this page to track and list changes during development. At the time of release, this page should be published (and renamed) to list the most important changes in the new release.
Detailed changes¶
Note
At the time of release, make a verbatim copy of the ChangeLog here (and remove this note).
Changes in version 2019.1.0¶
Summary of changes¶
- Support
NodalEnrichedElement
Detailed changes¶
- Support
NodalEnrichedElement
seedemo/NodalMini.ufl
.
Changes in version 2018.1.0¶
FFC 2018.1.0 was released on 2018-06-14.
Summary of changes¶
- Remove python2 support.
Changes in version 2017.2.0¶
FFC 2017.2.0 was released on 2017-12-05.
Summary of changes¶
- Some fixes for ufc::eval for esoteric element combinations
- Reimplement code generation for all ufc classes with new class ufc::coordinate_mapping which can map between coordinates, compute jacobians, etc. for a coordinate mapping parameterized by a specific finite element.
- New functions in ufc::finite_element: - evaluate_reference_basis - evaluate_reference_basis_derivatives - transform_reference_basis_derivatives - tabulate_reference_dof_coordinates
- New functions in ufc::dofmap: - num_global_support_dofs - num_element_support_dofs
- Improved docstrings for parts of ufc.h
- FFC now accepts Q and DQ finite element families defined on quadrilaterals and hexahedrons
- Some fixes for ufc_geometry.h for quadrilateral and hexahedron cells
Changes in version 2017.1.0¶
FFC 2017.1.0.post2 was released on 2017-09-12.
Summary of changes¶
- Change PyPI package name to fenics-ffc.
Changes in version 2017.1.0¶
FFC 2017.1.0 was released on 2017-05-09.
Summary of changes¶
- Add experimental
tsfc
representation; for installation see TSFC requirements
Detailed changes¶
- Let ffc -O parameter take an optional integer level like -O2, -O0
- Implement blockwise optimizations in uflacs code generation
- Expose uflacs optimization parameters through parameter system
Changes in version 2016.2.0¶
FFC 2016.2.0 was released on 2016-11-30.
Summary of changes¶
- Generalize ufc interface to non-affine parameterized coordinates
- Add
ufc::coordinate_mapping
class - Make ufc interface depend on C++11 features requiring gcc version >= 4.8
- Change the mapping
pullback as metric
todouble covariant piola
(this preserves tangential-tangential trace). - Added Hellan-Herrmann-Johnson element as supported element
- Add mapping
double contravariant piola
(this preserves normal-normal trace). - Include comment with effective representation and integral metadata
to generated
tabulate_tensor
code
Detailed changes¶
- Jit compiler now compiles elements separately from forms to avoid duplicate work
- Add parameter max_signature_length to optionally shorten signatures in the jit cache
- Move uflacs module into ffc.uflacs
- Remove installation of pkg-config and CMake files (UFC path and compiler flags are available from ffc module)
- Add dependency on dijitso and remove dependency on instant
- Add experimental Bitbucket pipelines
- Tidy the repo after UFC and UFLACS merge, and general spring cleanup. This includes removal of instructions how to merge two repos, commit hash c8389032268041fe94682790cb773663bdf27286.
Changes in version 2016.1.0¶
FFC 2016.1.0 was released on 2016-06-23.
- Add function get_ufc_include to get path to ufc.h
- Merge UFLACS into FFC
- Generalize ufc interface to non-affine parameterized coordinates
- Add ufc::coordinate_mapping class
- Make ufc interface depend on C++11 features requiring gcc version >= 4.8
- Add function ufc_signature() to the form compiler interface
- Add function git_commit_hash()
Changes in version 1.6.0¶
FFC 1.6.0 was released on 2015-07-28.
- Rename and modify a number of UFC interface functions. See docstrings in ufc.h for details.
- Bump required SWIG version to 3.0.3
- Disable dual basis (
tabulate_coordinates
andevaluate_dofs
) for enriched elements until correct implementation is brought up
[FIXME: These links don’t belong here, should go under API reference somehow.]