ufl.formatting package

Submodules

ufl.formatting.graph module

Algorithms for working with linearized computational graphs.

class ufl.formatting.graph.Graph(expression)

Bases: object

Graph class which computes connectivity on demand.

E()
Ein()
Eout()
V()
Vin()
Vout()
class ufl.formatting.graph.HeapItem(incoming, outgoing, i)

Bases: object

class ufl.formatting.graph.StringDependencyDefiner(argument_deps=None, coefficient_deps=None)

Bases: ufl.corealg.multifunction.MultiFunction

Given an expr, returns a frozenset of its dependencies.

Possible dependency values are:
“c” - depends on runtime information like the cell, local<->global coordinate mappings, facet normals, or coefficients “x” - depends on local coordinates “v%d” % i - depends on argument i, for i in [0,rank)
argument(x)
coefficient(x)
expr(o)

Trigger error for types with missing handlers.

facet_normal(o)
geometric_quantity(x)
spatial_derivative(o)
ufl.formatting.graph.build_graph(expr)

Build a linearized graph from an UFL Expr.

Returns G = (V, E), with V being a list of graph nodes (Expr objects) in post traversal ordering and E being a list of edges. Each edge is represented as a (i, j) tuple where i and j are vertex indices into V.

ufl.formatting.graph.depth_first_ordering(G)
ufl.formatting.graph.extract_incoming_edges(G)

Build lists of incoming edges to each vertex in a linearized graph.

ufl.formatting.graph.extract_incoming_vertex_connections(G)

Build lists of vertices in incoming and outgoing edges to and from each vertex in a linearized graph.

Returns lists Vin and Vout.

ufl.formatting.graph.extract_outgoing_edges(G)

Build list of outgoing edges from each vertex in a linearized graph.

ufl.formatting.graph.extract_outgoing_vertex_connections(G)

Build lists of vertices in incoming and outgoing edges to and from each vertex in a linearized graph.

Returns lists Vin and Vout.

ufl.formatting.graph.len_items(sequence)
ufl.formatting.graph.lists(n)
ufl.formatting.graph.partition(G, criteria=<function string_set_criteria>)
ufl.formatting.graph.string_set_criteria(v, keys)

ufl.formatting.latextools module

This module defines basic utilities for stitching together LaTeX documents.

ufl.formatting.latextools.align(lines)
ufl.formatting.latextools.document(title, sections)
ufl.formatting.latextools.itemize(items)
ufl.formatting.latextools.section(s)
ufl.formatting.latextools.subsection(s)
ufl.formatting.latextools.subsubsection(s)
ufl.formatting.latextools.testdocument()
ufl.formatting.latextools.verbatim(string)

ufl.formatting.printing module

A collection of utility algorithms for printing of UFL objects, mostly intended for debugging purposes.

ufl.formatting.printing.form_info(form)
ufl.formatting.printing.integral_info(integral)
ufl.formatting.printing.tree_format(expression, indentation=0, parentheses=True)

ufl.formatting.ufl2dot module

A collection of utility algorithms for printing of UFL objects in the DOT graph visualization language, mostly intended for debugging purposers.

class ufl.formatting.ufl2dot.CompactLabeller(function_mapping=None)

Bases: ufl.formatting.ufl2dot.ReprLabeller

cell_avg(e)
component_tensor(e)
conj(e)
curl(e)
determinant(e)
dev(e)
diff(e)
div(e)
division(e)
dot(e)
facet_avg(e)
form_argument(e)
geometric_quantity(e)
grad(e)
identity(e)
imag(e)
index_sum(e)
indexed(e)
inner(e)
math_function(e)
multi_index(e)
nabla_div(e)
nabla_grad(e)
negative_restricted(e)
outer(e)
positive_restricted(e)
power(e)
product(e)
real(e)
scalar_value(e)
skew(e)
sum(e)
trace(e)
transposed(e)
zero(e)
class ufl.formatting.ufl2dot.FancyLabeller(function_mapping=None)

Bases: ufl.formatting.ufl2dot.CompactLabeller

class ufl.formatting.ufl2dot.ReprLabeller

Bases: ufl.corealg.multifunction.MultiFunction

operator(e)
terminal(e)
ufl.formatting.ufl2dot.build_entities(e, nodes, edges, nodeoffset, prefix='', labeller=None)
ufl.formatting.ufl2dot.format_entities(nodes, edges)
ufl.formatting.ufl2dot.ufl2dot(expression, formname='a', nodeoffset=0, begin=True, end=True, labeling='repr', object_names=None)

ufl.formatting.ufl2latex module

This module defines expression transformation utilities, either converting UFL expressions to new UFL expressions or converting UFL expressions to other representations.

class ufl.formatting.ufl2latex.Expression2LatexHandler(argument_names=None, coefficient_names=None)

Bases: ufl.corealg.multifunction.MultiFunction

abs(o, a)
acos(o, f)
and_condition(o, a, b)
argument(o)
asin(o, f)
atan(o, f)
atan2(o, f1, f2)
bessel_K(o, nu, f)
bessel_i(o, nu, f)
bessel_j(o, nu, f)
bessel_y(o, nu, f)
cell_avg(o, f)
coefficient(o)
coefficient_derivative(o, f, w, v)
cofactor(o, A)
component_tensor(o, *ops)
conditional(o, c, t, f)
conj(o, a)
constant(o)
cos(o, f)
cosh(o, f)
cross(o, a, b)
curl(o, f)
determinant(o, A)
deviatoric(o, A)
div(o, f)
division(o, a, b)
dot(o, a, b)
eq(o, a, b)
erf(o, f)
exp(o, f)
expr(o)

Trigger error for types with missing handlers.

facet_normal(o)
ge(o, a, b)
grad(o, f)
gt(o, a, b)
identity(o)
imag(o, a)
index_sum(o, f, i)
indexed(o, a, b)
inner(o, a, b)
inverse(o, A)
le(o, a, b)
list_tensor(o)
ln(o, f)
lt(o, a, b)
max_value(o, a, b)
min_value(o, a, b)
multi_index(o)
nabla_div(o, f)
nabla_grad(o, f)
ne(o, a, b)
negative_restricted(o, f)
not_condition(o, a)
or_condition(o, a, b)
outer(o, a, b)
permutation_symbol(o)
positive_restricted(o, f)
power(o, a, b)
product(o, *ops)
real(o, a)
scalar_value(o)
sin(o, f)
sinh(o, f)
skew(o, A)
sqrt(o, f)
sum(o, *ops)
sym(o, A)
tan(o, f)
tanh(o, f)
trace(o, A)
transposed(o, a)
variable(o)
variable_derivative(o, f, v)
zero(o)
ufl.formatting.ufl2latex.bfname(i, p)
ufl.formatting.ufl2latex.build_precedence_map()
ufl.formatting.ufl2latex.cfname(i)
ufl.formatting.ufl2latex.code2latex(G, partitions, formdata)

TODO: Document me

ufl.formatting.ufl2latex.dependency_sorting(deplist, rank)
ufl.formatting.ufl2latex.deps2latex(deps)
ufl.formatting.ufl2latex.element2latex(element)
ufl.formatting.ufl2latex.expression2latex(expression, argument_names=None, coefficient_names=None)
ufl.formatting.ufl2latex.form2code2latex(formdata)
ufl.formatting.ufl2latex.form2latex(form, formdata)
ufl.formatting.ufl2latex.format_index(ii)
ufl.formatting.ufl2latex.format_multi_index(ii, formatstring='%s')
ufl.formatting.ufl2latex.formdata2latex(formdata)
ufl.formatting.ufl2latex.forms2latexdocument(forms, uflfilename, compile=False)

Render forms from a .ufl file as a LaTeX document.

ufl.formatting.ufl2latex.integrand2code(integrand, formdata)
ufl.formatting.ufl2latex.par(s, condition=True)
ufl.formatting.ufl2latex.ufl2latex(expression)

Generate LaTeX code for a UFL expression or form (wrapper for form2latex and expression2latex).

ufl.formatting.ufl2unicode module

class ufl.formatting.ufl2unicode.Expression2UnicodeHandler(argument_names=None, coefficient_names=None, colorama_bold=False)

Bases: ufl.corealg.multifunction.MultiFunction

abs(o, a)
and_condition(o, a, b)
argument(o)
atan2(o, f1, f2)
bessel_K(o, nu, f)
bessel_i(o, nu, f)
bessel_j(o, nu, f)
bessel_y(o, nu, f)
cell_avg(o, f)
coefficient(o)
coefficient_derivative(o, f, w, v, cd)
cofactor(o, A)
component_tensor(o, A, ii)
conditional(o, c, t, f)
conj(o, a)
cross(o, a, b)
curl(o, f)
determinant(o, A)
deviatoric(o, A)
div(o, f)
division(o, a, b)
dot(o, a, b)
eq(o, a, b)
exp(o, f)
expr(o)

Trigger error for types with missing handlers.

expr_list(o, *ops)
expr_mapping(o, *ops)
facet_avg(o, f)
facet_normal(o)
ge(o, a, b)
grad(o, f)
gt(o, a, b)
identity(o)
imag(o, a)
index_sum(o, f, i)
indexed(o, A, ii)
inner(o, a, b)
inverse(o, A)
label(o)
le(o, a, b)
list_tensor(o, *ops)
lt(o, a, b)
math_function(o, f)
max_value(o, a, b)
min_value(o, a, b)
multi_index(o)
nabla_div(o, f)
nabla_grad(o, f)
ne(o, a, b)
negative_restricted(o, f)
not_condition(o, a)
or_condition(o, a, b)
outer(o, a, b)
permutation_symbol(o)
positive_restricted(o, f)
power(o, a, b)
product(o, a, b)
real(o, a)
scalar_value(o)
skew(o, A)
spatial_coordinate(o)
sqrt(o, f)
sum(o, a, b)
sym(o, A)
trace(o, A)
transposed(o, a)
variable(o, f, l)
variable_derivative(o, f, v)
zero(o)
class ufl.formatting.ufl2unicode.PrecedenceRules

Bases: ufl.corealg.multifunction.MultiFunction

An enum-like class for C operator precedence levels.

add(o)
and_condition(o)
bessel_function(o)
call(o)
cell_avg(o)
cofactor(o)
component_tensor(o)
conditional(o)
cross(o)
derivative(o)
deviatoric(o)
division(o)
dot(o)
eq(o)
facet_avg(o)
ge(o)
gt(o)
highest(o)
index_sum(o)
indexed(o)
inner(o)
le(o)
list_tensor(o)
lowest(o)
lt(o)
math_function(o)
mathop(o)
max_value(o)
min_value(o)
ne(o)
not_condition(o)
operator(o)
or_condition(o)
outer(o)
power(o)
product(o)
restricted(o)
skew(o)
sym(o)
terminal(o)
trace(o)
class ufl.formatting.ufl2unicode.UC

Bases: object

An enum-like class for unicode characters.

Gamma = 'Γ'
Omega = 'Ω'
bold_math_A = '𝐀'
bold_math_a = '𝐚'
circled_times = '⊗'
combining_overline = '̅'
combining_right_arrow_above = '⃗'
cross_product = '⨯'
division_slash = '∕'
dot = '⋅'
element_of = '∈'
epsilon = 'ε'
for_all = '∀'
gamma = 'γ'
ge = '≥'
gt = '>'
integral = '∫'
integral_contour = '∮'
integral_double = '∬'
integral_surface = '∯'
integral_triple = '∭'
integral_volume = '∰'
le = '≤'
left_angled_bracket = '⟨'
left_double_angled_bracket = '⟪'
left_white_square_bracket = '⟦'
logical_and = '∧'
logical_not = '¬'
logical_or = '∨'
lt = '<'
nabla = '∇'
nary_product = '∏'
ne = '≠'
not_element_of = '∉'
omega = 'ω'
partial = '∂'
right_angled_bracket = '⟩'
right_double_angled_bracket = '⟫'
right_white_squared_bracket = '⟧'
sqrt = '√'
subscript_digits = ['₀', '₁', '₂', '₃', '₄', '₅', '₆', '₇', '₈', '₉']
subscript_equals = '₌'
subscript_left_paren = '₍'
subscript_minus = '₋'
subscript_plus = '₊'
subscript_right_paren = '₎'
sum = '∑'
superscript_digits = ['⁰', '¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹']
superscript_equals = '⁼'
superscript_left_paren = '⁽'
superscript_minus = '⁻'
superscript_plus = '⁺'
superscript_right_paren = '⁾'
thin_space = '\u2009'
transpose = 'ᵀ'
ufl.formatting.ufl2unicode.binop(expr, a, b, op, sep=' ')
ufl.formatting.ufl2unicode.bolden_letter(c)
ufl.formatting.ufl2unicode.bolden_string(s)
ufl.formatting.ufl2unicode.expression2unicode(expression, argument_names=None, coefficient_names=None)
ufl.formatting.ufl2unicode.form2unicode(form, formdata)
ufl.formatting.ufl2unicode.format_index(ii)
ufl.formatting.ufl2unicode.get_integral_symbol(integral_type, domain, subdomain_id)
ufl.formatting.ufl2unicode.is_int(s)
ufl.formatting.ufl2unicode.mathop(expr, arg, opname)
ufl.formatting.ufl2unicode.measure_font(dx)
ufl.formatting.ufl2unicode.opfont(opname)
ufl.formatting.ufl2unicode.overline_string(f)
ufl.formatting.ufl2unicode.par(s)
ufl.formatting.ufl2unicode.prec(expr)
ufl.formatting.ufl2unicode.precedence(expr)
ufl.formatting.ufl2unicode.subscript_digit(digit)
ufl.formatting.ufl2unicode.subscript_number(number)
ufl.formatting.ufl2unicode.superscript_digit(digit)
ufl.formatting.ufl2unicode.superscript_number(number)
ufl.formatting.ufl2unicode.ufl2unicode(expression)

Generate Unicode string for a UFL expression or form.

Module contents