corealg Package¶
map_dag Module¶
Basic algorithms for applying functions to subexpressions.
- 
ufl.corealg.map_dag.map_expr_dag(function, expression, compress=True)¶
- Apply a function to each subexpression node in expression dag. - If compress is True (default), the output object from the function is cached in a dict and reused such that the resulting expression dag does not contain duplicate objects. - Returns the result of the final function call. 
multifunction Module¶
Base class for multifunctions with UFL Expr type dispatch.
- 
class ufl.corealg.multifunction.MultiFunction¶
- Bases: - object- Base class for collections of nonrecursive expression node handlers. - Subclass this (remember to call the __init__ method of this class), and implement handler functions for each Expr type, using the lower case handler name of the type (exprtype._ufl_handler_name_). - This class is optimized for efficient type based dispatch in the __call__ operator via typecode based lookup of the handler function bound to the algorithm object. Of course function call overhead of Python still applies. - 
expr(o, *args)¶
- Trigger error for types with missing handlers. 
 - 
reuse_if_untouched(o, *ops)¶
- Reuse object if operands are the same objects. - Use in your own subclass by setting e.g. expr = MultiFunction.reuse_if_untouched- as a default rule. 
 - 
undefined(o, *args)¶
- Trigger error for types with missing handlers. 
 
- 
- 
ufl.corealg.multifunction.get_num_args(function)¶
traversal Module¶
Various expression traversal utilities.
The algorithms here are non-recursive, which is faster than recursion by a factor 10 or so because of the function call overhead.
- 
ufl.corealg.traversal.cutoff_post_traversal(expr, cutofftypes)¶
- Yields o for each node o in expr, child before parent, but skipping subtrees of the cutofftypes. 
- 
ufl.corealg.traversal.post_traversal(expr)¶
- Yields o for each node o in expr, child before parent. 
- 
ufl.corealg.traversal.pre_traversal(expr)¶
- Yields o for each tree node o in expr, parent before child. 
- 
ufl.corealg.traversal.traverse_terminals(expr)¶
- Iterate over all terminal objects in expression, including duplicates. 
- 
ufl.corealg.traversal.traverse_unique_terminals(expr)¶
- Iterate over all terminal objects in expression, not including duplicates. 
- 
ufl.corealg.traversal.unique_post_traversal(expr, visited=None)¶
- Yields o for each node o in expr, child before parent. - Never visits a node twice. 
- 
ufl.corealg.traversal.unique_pre_traversal(expr, visited=None)¶
- Yields o for each tree node o in expr, parent before child. - This version only visits each node once!