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.