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.make_classname(prefix, basename, signature)[source]
ffc.quadrature.cpp.make_integral_classname(prefix, integral_type, form_id, subdomain_id)[source]
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.cpp.set_exception_handling(convert_exceptions_to_warnings)[source]

Set handling of exceptions.

ffc.quadrature.cpp.set_float_formatting(precision)[source]

Set floating point formatting based on precision.

ffc.quadrature.deprecation module

exception ffc.quadrature.deprecation.QuadratureRepresentationDeprecationWarning[source]

Bases: DeprecationWarning

Warning about deprecation of quadrature representation

ffc.quadrature.deprecation.issue_deprecation_warning()[source]

Issue warning about quadrature deprecation

ffc.quadrature.expr module

This file implements a base class to represent an expression.

class ffc.quadrature.expr.Expr[source]

Bases: object

expand()[source]

Expand the expression. (FloatValue and Symbol are expanded by construction).

get_unique_vars(var_type)[source]

Get unique variables (Symbols) as a set.

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
expand()[source]

Expand the fraction expression.

get_unique_vars(var_type)[source]

Get unique variables (Symbols) as a set.

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
ops()[source]

Return number of operations needed to evaluate fraction.

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 fraction by another variable through division of numerator.

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.

abs(o, *operands)[source]
binary_condition(o, *operands)[source]
cell_coordinate(o)[source]
cell_facet_jacobian(o)[source]
cell_facet_jacobian_determinant(o)[source]
cell_facet_jacobian_inverse(o)[source]
cell_facet_origin(o)[source]
cell_normal(o)[source]
cell_orientation(o)[source]
cell_origin(o)[source]
cell_volume(o)[source]
circumradius(o)[source]
conditional(o, *operands)[source]
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.

create_function(ufl_function, derivatives, component, local_comp, local_offset, ffc_element, is_quad_element, transformation, multiindices, tdim, gdim, avg)[source]

Create code for basis functions, and update relevant tables of used basis.

division(o, *operands)[source]
facet_area(o)[source]
facet_coordinate(o)[source]
facet_jacobian(o)[source]
facet_jacobian_determinant(o)[source]
facet_jacobian_inverse(o)[source]
facet_normal(o)[source]
facet_origin(o)[source]
jacobian(o)[source]
jacobian_determinant(o)[source]
jacobian_inverse(o)[source]
max_facet_edge_length(o)[source]
max_value(o, *operands)[source]
min_facet_edge_length(o)[source]
min_value(o, *operands)[source]
not_condition(o, *operands)[source]
power(o)[source]
product(o, *operands)[source]
quadrature_weight(o)[source]
sum(o, *operands)[source]
ffc.quadrature.optimisedquadraturetransformer.firstkey(d)[source]

ffc.quadrature.parameters module

Quadrature representation class for UFL

ffc.quadrature.parameters.default_optimize_parameters()[source]
ffc.quadrature.parameters.parse_optimise_parameters(parameters, itg_data)[source]

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

expand()[source]

Expand all members of the product.

get_unique_vars(var_type)[source]

Get unique variables (Symbols) as a set.

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.

get_vrs()[source]

Return all ‘real’ variables.

ops()[source]

Get the number of operations to compute product.

reduce_ops()[source]

Reduce the number of operations to evaluate the 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.

vrs

ffc.quadrature.quadraturegenerator module

Code generator for quadrature representation.

ffc.quadrature.quadraturegenerator.generate_integral_code(ir, prefix, parameters)[source]

Generate code for integral from intermediate representation.

ffc.quadrature.quadratureoptimization module

ffc.quadrature.quadratureoptimization.optimize_integral_ir(ir, parameters)[source]

Compute optimized intermediate representation of integral.

ffc.quadrature.quadraturerepresentation module

Quadrature representation class for UFL

ffc.quadrature.quadraturerepresentation.compute_integral_ir(itg_data, form_data, form_id, element_numbers, classnames, parameters)[source]

Compute intermediate represention of integral.

ffc.quadrature.quadraturerepresentation.sort_integrals(integrals, default_scheme, default_degree)[source]

Sort and accumulate integrals according to the number of quadrature points needed per axis.

All integrals should be over the same (sub)domain.

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.

abs(o, *operands)[source]
binary_condition(o, *operands)[source]
cell_coordinate(o)[source]
cell_facet_jacobian(o)[source]
cell_facet_jacobian_determinant(o)[source]
cell_facet_jacobian_inverse(o)[source]
cell_facet_origin(o)[source]
cell_normal(o)[source]
cell_orientation(o)[source]
cell_origin(o)[source]
cell_volume(o)[source]
circumradius(o)[source]
conditional(o, *operands)[source]
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.

create_function(ufl_function, derivatives, component, local_comp, local_offset, ffc_element, is_quad_element, transformation, multiindices, tdim, gdim, avg)[source]

Create code for basis functions, and update relevant tables of used basis.

division(o, *operands)[source]
facet_area(o)[source]
facet_coordinate(o)[source]
facet_jacobian(o)[source]
facet_jacobian_determinant(o)[source]
facet_jacobian_inverse(o)[source]
facet_normal(o)[source]
facet_origin(o)[source]
jacobian(o)[source]
jacobian_determinant(o)[source]
jacobian_inverse(o)[source]
max_facet_edge_length(o)[source]
max_value(o, *operands)[source]
min_facet_edge_length(o)[source]
min_value(o, *operands)[source]
not_condition(o, *operands)[source]
power(o)[source]
product(o, *operands)[source]
quadrature_weight(o)[source]
sum(o, *operands)[source]
ffc.quadrature.quadraturetransformer.firstkey(d)[source]

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
class ffc.quadrature.quadraturetransformerbase.QuadratureTransformerBase(psi_tables, quad_weights, gdim, tdim, entity_type, function_replace_map, optimise_parameters)[source]

Bases: ufl.algorithms.transformer.Transformer

Transform UFL representation to quadrature code.

abs(o, *operands)[source]
acos(o, *operands)[source]
argument(o)[source]
asin(o, *operands)[source]
atan(o, *operands)[source]
atan_2(o, *operands)[source]
atan_2_function(o)[source]
bessel_function(o)[source]
bessel_i(o, *operands)[source]
bessel_j(o, *operands)[source]
bessel_k(o, *operands)[source]
bessel_y(o, *operands)[source]
cell_avg(o)[source]
cell_coordinate(o)[source]
cell_facet_jacobian(o)[source]
cell_facet_jacobian_determinant(o)[source]
cell_facet_jacobian_inverse(o)[source]
cell_facet_origin(o)[source]
cell_normal(o)[source]
cell_orientation(o)[source]
cell_origin(o)[source]
cell_volume(o)[source]
circumradius(o)[source]
coefficient(o)[source]
component()[source]

Return current component tuple.

component_tensor(o)[source]
compound_tensor_operator(o)[source]
condition(o)[source]
constant_value(o)[source]
cos(o, *operands)[source]
cosh(o, *operands)[source]
derivative(o, *operands)[source]
derivatives()[source]

Return all derivatives tuple.

disp()[source]
division(o, *operands)[source]
erf(o, *operands)[source]
exp(o, *operands)[source]
expr(o)[source]

Trigger error.

facet_area(o)[source]
facet_avg(o)[source]
facet_coordinate(o)[source]
facet_jacobian(o)[source]
facet_jacobian_determinant(o)[source]
facet_jacobian_inverse(o)[source]
facet_normal(o)[source]
facet_origin(o)[source]
generate_terms(integrand, integral_type)[source]

Generate terms for code generation.

geometric_quantity(o)[source]
grad(o)[source]
identity(o)[source]
index_sum(o)[source]
indexed(o)[source]
jacobian(o)[source]
jacobian_determinant(o)[source]
jacobian_inverse(o)[source]
label(o)[source]
list_tensor(o)[source]
ln(o, *operands)[source]
math_function(o)[source]
max_facet_edge_length(o)[source]
min_facet_edge_length(o)[source]
multi_index(o)[source]
negative_restricted(o)[source]
positive_restricted(o)[source]
power(o)[source]
product(o, *operands)[source]
quadrature_weight(o)[source]
restricted(o)[source]
scalar_value(o)[source]

ScalarValue covers IntValue and FloatValue

sin(o, *operands)[source]
sinh(o, *operands)[source]
spatial_coordinate(o)[source]
sqrt(o, *operands)[source]
sum(o, *operands)[source]
tan(o, *operands)[source]
tanh(o, *operands)[source]
terminal(o)[source]

Always reuse Expr (ignore children)

update_cell()[source]
update_facets(facet0, facet1)[source]
update_points(points)[source]
update_vertex(vertex)[source]
variable(o)[source]
zero(o)[source]

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_permutations(expr)[source]
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

expand()[source]

Expand all members of the sum.

get_unique_vars(var_type)[source]

Get unique variables (Symbols) as a set.

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 {}.

ops()[source]

Return number of operations to compute value of sum.

reduce_ops()[source]

Reduce the number of operations needed to evaluate the sum.

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_unique_vars(var_type)[source]

Get unique variables (Symbols) as a set.

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.

ops()[source]

Returning the number of floating point operation for symbol.

v

ffc.quadrature.symbolics module

This file contains functions to optimise the code generated for quadrature representation.

ffc.quadrature.symbolics.create_float(val)[source]
ffc.quadrature.symbolics.create_fraction(num, denom)[source]
ffc.quadrature.symbolics.create_product(variables)[source]
ffc.quadrature.symbolics.create_sum(variables)[source]
ffc.quadrature.symbolics.create_symbol(variable, symbol_type, base_expr=None, base_op=0)[source]
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.

ffc.quadrature.tabulate_basis.tabulate_basis(sorted_integrals, form_data, itg_data)[source]

Tabulate the basisfunctions and derivatives.

Module contents