ufl.utils package¶
Submodules¶
ufl.utils.counted module¶
Utilites for types with a global unique counter attached to each object.
ufl.utils.derivativetuples module¶
This module contains a collection of utilities for representing partial derivatives as integer tuples.
- ufl.utils.derivativetuples.compute_derivative_tuples(n, gdim)[source]¶
Compute the list of all derivative tuples for derivatives of given total order n and given geometric dimension gdim. This function returns two lists. The first is a list of tuples, where each tuple of length n specifies the coordinate directions of the n derivatives. The second is a corresponding list of tuples, where each tuple of length gdim specifies the number of derivatives in each direction. Both lists have length gdim^n and are ordered as expected by the UFC function tabulate_basis_derivatives.
Example: If n = 2 and gdim = 3, then the nice tuples are
(0, 0) <–> (2, 0, 0) <–> d^2/dxdx (0, 1) <–> (1, 1, 0) <–> d^2/dxdy (0, 2) <–> (1, 0, 1) <–> d^2/dxdz (1, 0) <–> (1, 1, 0) <–> d^2/dydx (1, 1) <–> (0, 2, 0) <–> d^2/dydy (1, 2) <–> (0, 1, 1) <–> d^2/dydz (2, 0) <–> (1, 0, 1) <–> d^2/dzdx (2, 1) <–> (0, 1, 1) <–> d^2/dzdy (2, 2) <–> (0, 0, 2) <–> d^2/dzdz
- ufl.utils.derivativetuples.derivative_counts_to_listing(derivative_counts)[source]¶
Convert a derivative count tuple to a derivative listing tuple.
The derivative d^3 / dy^2 dz is represented in counting form as (0, 2, 1) meaning (dx^0, dy^2, dz^1) and in listing form as (1, 1, 2) meaning (dy, dy, dz).
- ufl.utils.derivativetuples.derivative_listing_to_counts(derivatives, gdim)[source]¶
Convert a derivative listing tuple to a derivative count tuple.
The derivative d^3 / dy^2 dz is represented in counting form as (0, 2, 1) meaning (dx^0, dy^2, dz^1) and in listing form as (1, 1, 2) meaning (dy, dy, dz).
ufl.utils.dicts module¶
Various dict manipulation utilities.
- ufl.utils.dicts.dict_sum(items)[source]¶
Construct a dict, in between dict(items) and sum(items), by accumulating items for each key.
ufl.utils.formatting module¶
Various string formatting utilities.
- ufl.utils.formatting.camel2underscore(name)[source]¶
Convert a CamelCaps string to underscore_syntax.
ufl.utils.indexflattening module¶
This module contains a collection of utilities for mapping between multiindices and a flattened index space.
- ufl.utils.indexflattening.flatten_multiindex(ii, strides)[source]¶
Return the flat index corresponding to the given multiindex.
ufl.utils.sequences module¶
Various sequence manipulation utilities.
- ufl.utils.sequences.and_tuples(seqa, seqb)[source]¶
Return ‘and’ of all pairs in two sequences of same length.
- ufl.utils.sequences.iter_tree(tree)[source]¶
Iterate over all nodes in a tree represented by lists of lists of leaves.
- ufl.utils.sequences.max_degree(degrees)[source]¶
Maximum degree for mixture of scalar and tuple degrees.
ufl.utils.sorting module¶
Utilites for sorting.
- ufl.utils.sorting.canonicalize_metadata(metadata)[source]¶
Assuming metadata to be a dict with string keys and builtin python types as values.
Transform dict to a tuple of (key, value) item tuples ordered by key, with dict, list and tuple values converted the same way recursively. Lists and tuples are converted to tuples. Other values are converted using str(). This is such that the end result can be hashed and sorted using regular <, because python 3 doesn’t allow e.g. (3 < “auto”) which occurs regularly in metadata.
- ufl.utils.sorting.sorted_by_key(mapping)[source]¶
Sort dict items by key, allowing different key types.
- ufl.utils.sorting.topological_sorting(nodes, edges)[source]¶
Return a topologically sorted list of the nodes
Implemented algorithm from Wikipedia :P
<http://en.wikipedia.org/wiki/Topological_sorting>
No error for cyclic edges…
ufl.utils.stacks module¶
Various utility data structures.
ufl.utils.ufltypedicts module¶
Various utility data structures.