ufl Package¶
ufl
Package¶
The Unified Form Language is an embedded domain specific language for definition of variational forms intended for finite element discretization. More precisely, it defines a fixed interface for choosing finite element spaces and defining expressions for weak forms in a notation close to mathematical notation.
This Python module contains the language as well as algorithms to work with it.
To import the language, type:
from ufl import *
To import the underlying classes an UFL expression tree is built from, type:
from ufl.classes import *
Various algorithms for working with UFL expression trees can be found in:
from ufl.algorithms import *
The classes and algorithms are considered implementation details and should not be used in form definitions.
For more details on the language, see
and
The development version can be found in the repository at
A very brief overview of the language contents follows:
Domains:
Domain, Region
Cells:
Cell, interval, triangle, tetrahedron, quadrilateral, hexahedron, cell1D, cell2D, cell3D,
Elements:
FiniteElement, MixedElement, VectorElement, TensorElement EnrichedElement, RestrictedElement, TensorProductElement
Arguments:
Argument, TestFunction, TrialFunction
Coefficients:
Coefficient, Constant, VectorConstant, TensorConstant
Splitting form arguments in mixed spaces:
split
Literal constants:
Identity, PermutationSymbol
Geometric quantities:
SpatialCoordinate, FacetNormal, CellVolume, Circumradius, CellSurfaceArea, FacetArea, MinFacetEdgeLength, MaxFacetEdgeLength, FacetDiameter, LocalCoordinate, GeometryJacobi, GeometryJacobiDeterminant, InverseGeometryJacobi
Indices:
Index, indices, i, j, k, l, p, q, r, s
Scalar to tensor expression conversion:
as_tensor, as_vector, as_matrix
Unit vectors and matrices:
unit_vector, unit_vectors, unit_matrix, unit_matrices
Tensor algebra operators:
outer, inner, dot, cross, perp, det, inv, cofac, transpose, tr, diag, diag_vector, dev, skew, sym
Elementwise tensor operators:
elem_mult, elem_div, elem_pow, elem_op
Differential operators:
variable, diff, grad, div, nabla_grad, nabla_div, Dx, Dn, curl, rot
Nonlinear functions:
Max, Min, abs, sign, sqrt, exp, ln, erf, cos, sin, tan, acos, asin, atan, atan_2, cosh, sinh, tanh, bessel_J, bessel_Y, bessel_I, bessel_K
- Discontinuous Galerkin operators:
jump, avg, v(‘+’), v(‘-‘), cell_avg, facet_avg
Conditional operators:
eq, ne, le, ge, lt, gt, <, >, <=, >=, And, Or, Not, conditional
Integral measures:
dx, ds, dS, dP, dE, dc
Form transformations:
rhs, lhs, system, functional, replace, adjoint, action, energy_norm, sensitivity_rhs, derivative
algebra
Module¶
Basic algebra operations.
-
class
ufl.algebra.
Abs
(a)¶ Bases:
ufl.operatorbase.AlgebraOperator
-
evaluate
(x, mapping, component, index_values)¶
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.algebra.
Division
(a, b)¶ Bases:
ufl.operatorbase.AlgebraOperator
-
evaluate
(x, mapping, component, index_values)¶
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.algebra.
Power
(a, b)¶ Bases:
ufl.operatorbase.AlgebraOperator
-
evaluate
(x, mapping, component, index_values)¶
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
argument
Module¶
This module defines the class Argument and a number of related classes (functions), including TestFunction and TrialFunction.
-
class
ufl.argument.
Argument
(element, count=None)¶ Bases:
ufl.terminal.FormArgument
UFL value: Representation of an argument to a form.
-
cell
()¶
-
domain
()¶
-
element
()¶
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
reconstruct
(element=None, count=None)¶
-
shape
()¶
-
-
ufl.argument.
Arguments
(element)¶ UFL value: Create an Argument in a mixed space, and return a tuple with the function components corresponding to the subelements.
-
ufl.argument.
TestFunction
(element)¶ UFL value: Create a test function argument to a form.
-
ufl.argument.
TestFunctions
(element)¶ UFL value: Create a TestFunction in a mixed space, and return a tuple with the function components corresponding to the subelements.
-
ufl.argument.
TrialFunction
(element)¶ UFL value: Create a trial function argument to a form.
-
ufl.argument.
TrialFunctions
(element)¶ UFL value: Create a TrialFunction in a mixed space, and return a tuple with the function components corresponding to the subelements.
assertions
Module¶
This module provides assertion functions used by the UFL implementation.
-
ufl.assertions.
expecting_expr
(v)¶
-
ufl.assertions.
expecting_instance
(v, c)¶
-
ufl.assertions.
expecting_python_scalar
(v)¶
-
ufl.assertions.
expecting_terminal
(v)¶
-
ufl.assertions.
expecting_true_ufl_scalar
(v)¶
-
ufl.assertions.
ufl_assert
(condition, *message)¶ Assert that condition is true and otherwise issue an error with given message.
classes
Module¶
This file is useful for external code like tests and form compilers, since it enables the syntax “from ufl.classes import FooBar” for getting implementation details not exposed through the default ufl namespace. It also contains functionality used by algorithms for dealing with groups of classes, and for mapping types to different handler functions.
coefficient
Module¶
This module defines the Coefficient class and a number of related classes, including Constant.
-
class
ufl.coefficient.
Coefficient
(element, count=None)¶ Bases:
ufl.terminal.FormArgument
UFL form argument type: Representation of a form coefficient.
-
cell
()¶
-
domain
()¶
-
element
()¶
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
reconstruct
(element=None, count=None)¶
-
shape
()¶
-
-
ufl.coefficient.
Coefficients
(element)¶ UFL value: Create a Coefficient in a mixed space, and return a tuple with the function components corresponding to the subelements.
-
class
ufl.coefficient.
Constant
(domain, count=None)¶ Bases:
ufl.coefficient.ConstantBase
UFL value: Represents a globally constant scalar valued coefficient.
-
class
ufl.coefficient.
ConstantBase
(element, count)¶ Bases:
ufl.coefficient.Coefficient
-
class
ufl.coefficient.
TensorConstant
(domain, shape=None, symmetry=None, count=None)¶ Bases:
ufl.coefficient.ConstantBase
UFL value: Represents a globally constant tensor valued coefficient.
-
class
ufl.coefficient.
VectorConstant
(domain, dim=None, count=None)¶ Bases:
ufl.coefficient.ConstantBase
UFL value: Represents a globally constant vector valued coefficient.
common
Module¶
This module contains a collection of common utilities.
-
class
ufl.common.
ExampleCounted
(count=None)¶ Bases:
object
An example class for classes of objects identified by a global counter.
The old inheritance pattern is deprecated. Mimic this class instead.
-
count
()¶
-
-
class
ufl.common.
StackDict
(*args, **kwargs)¶ Bases:
dict
A dict that can be changed incrementally with ‘d.push(k,v)’ and have changes rolled back with ‘k,v = d.pop()’.
-
pop
()¶
-
push
(k, v)¶
-
-
ufl.common.
and_tuples
(seqa, seqb)¶ Return ‘and’ of all pairs in two sequences of same length.
-
ufl.common.
camel2underscore
(name)¶ Convert a CamelCaps string to underscore_syntax.
-
ufl.common.
component_to_index
(component, shape)¶
-
ufl.common.
counted_init
(self, count=None, countedclass=None)¶
-
ufl.common.
dict_sum
(items)¶ Construct a dict, in between dict(items) and sum(items), by accumulating items for each key.
-
ufl.common.
dstr
(d, colsize=80)¶ Pretty-print dictionary of key-value pairs.
-
ufl.common.
estr
(elements)¶ Format list of elements for printing.
-
ufl.common.
fast_post_traversal
(expr)¶ Yields o for each tree node o in expr, child before parent.
-
ufl.common.
fast_post_traversal2
(expr, visited=None)¶ Yields o for each tree node o in expr, child before parent.
-
ufl.common.
fast_pre_traversal
(expr)¶ Yields o for each tree node o in expr, parent before child.
-
ufl.common.
fast_pre_traversal2
(expr, visited=None)¶ Yields o for each tree node o in expr, parent before child.
This version only visits each node once!
-
ufl.common.
get_status_output
(cmd, input=None, cwd=None, env=None)¶
-
ufl.common.
index_to_component
(index, shape)¶
-
ufl.common.
istr
(o)¶ Format object as string, inserting ? for None.
-
ufl.common.
iter_tree
(tree)¶ Iterate over all nodes in a tree represented by lists of lists of leaves.
-
ufl.common.
lstr
(l)¶ Pretty-print list or tuple, invoking str() on items instead of repr() like str() does.
-
ufl.common.
mergedicts
(dicts)¶
-
ufl.common.
openpdf
(pdffilename)¶ Open PDF file in external pdf viewer.
-
ufl.common.
or_tuples
(seqa, seqb)¶ Return ‘or’ of all pairs in two sequences of same length.
-
ufl.common.
pdflatex
(latexfilename, pdffilename, flags)¶ Execute pdflatex to compile a latex file into pdf.
-
ufl.common.
product
(sequence)¶ Return the product of all elements in a sequence.
-
ufl.common.
recursive_chain
(lists)¶
-
ufl.common.
slice_dict
(dictionary, keys, default=None)¶
-
ufl.common.
some_key
(a_dict)¶ Return an arbitrary key from a dictionary.
-
ufl.common.
sorted_by_count
(seq)¶
-
ufl.common.
sorted_items
(mapping)¶
-
ufl.common.
split_dict
(d, criteria)¶ Split a dict d into two dicts based on a criteria on the keys.
-
ufl.common.
sstr
(s)¶ Pretty-print set.
-
ufl.common.
strides
(shape)¶
-
ufl.common.
subdict
(superdict, keys)¶
-
ufl.common.
tstr
(t, colsize=80)¶ Pretty-print list of tuples of key-value pairs.
-
ufl.common.
unique_post_traversal
(expr, visited=None)¶ Yields o for each node o in expr, child before parent.
Never visits a node twice.
-
ufl.common.
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!
-
ufl.common.
unzip
(seq)¶ Inverse operation of zip: unzip(zip(a, b)) == (a, b)
-
ufl.common.
write_file
(filename, text)¶
-
ufl.common.
xor
(a, b)¶
conditional
Module¶
This module defines classes for conditional expressions.
-
class
ufl.conditional.
AndCondition
(left, right)¶ Bases:
ufl.conditional.BinaryCondition
-
evaluate
(x, mapping, component, index_values)¶
-
-
class
ufl.conditional.
BinaryCondition
(name, left, right)¶ Bases:
ufl.conditional.Condition
-
operands
()¶
-
-
class
ufl.conditional.
Condition
¶ Bases:
ufl.operatorbase.Operator
-
free_indices
()¶
-
index_dimensions
()¶
-
shape
()¶
-
-
class
ufl.conditional.
Conditional
(condition, true_value, false_value)¶ Bases:
ufl.operatorbase.Operator
-
evaluate
(x, mapping, component, index_values)¶
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.conditional.
EQ
(left, right)¶ Bases:
ufl.conditional.BinaryCondition
-
evaluate
(x, mapping, component, index_values)¶
-
-
class
ufl.conditional.
GE
(left, right)¶ Bases:
ufl.conditional.BinaryCondition
-
evaluate
(x, mapping, component, index_values)¶
-
-
class
ufl.conditional.
GT
(left, right)¶ Bases:
ufl.conditional.BinaryCondition
-
evaluate
(x, mapping, component, index_values)¶
-
-
class
ufl.conditional.
LE
(left, right)¶ Bases:
ufl.conditional.BinaryCondition
-
evaluate
(x, mapping, component, index_values)¶
-
-
class
ufl.conditional.
LT
(left, right)¶ Bases:
ufl.conditional.BinaryCondition
-
evaluate
(x, mapping, component, index_values)¶
-
-
class
ufl.conditional.
NE
(left, right)¶ Bases:
ufl.conditional.BinaryCondition
-
evaluate
(x, mapping, component, index_values)¶
-
-
class
ufl.conditional.
NotCondition
(condition)¶ Bases:
ufl.conditional.Condition
-
evaluate
(x, mapping, component, index_values)¶
-
operands
()¶
-
-
class
ufl.conditional.
OrCondition
(left, right)¶ Bases:
ufl.conditional.BinaryCondition
-
evaluate
(x, mapping, component, index_values)¶
-
constantvalue
Module¶
This module defines classes representing constant values.
-
class
ufl.constantvalue.
ConstantValue
¶ Bases:
ufl.terminal.Terminal
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
-
class
ufl.constantvalue.
FloatValue
(value, shape=(), free_indices=(), index_dimensions=None)¶ Bases:
ufl.constantvalue.ScalarValue
UFL literal type: Representation of a constant scalar floating point value.
-
class
ufl.constantvalue.
Identity
(dim)¶ Bases:
ufl.constantvalue.ConstantValue
UFL literal type: Representation of an identity matrix.
-
evaluate
(x, mapping, component, index_values)¶
-
shape
()¶
-
-
class
ufl.constantvalue.
IndexAnnotated
(shape=(), free_indices=(), index_dimensions=None)¶ Bases:
ufl.constantvalue.ConstantValue
Class to annotate expressions that don’t depend on indices with a set of free indices, used internally to keep index properties intact during automatic differentiation.
-
class
ufl.constantvalue.
IntValue
(value, shape=(), free_indices=(), index_dimensions=None)¶ Bases:
ufl.constantvalue.ScalarValue
UFL literal type: Representation of a constant scalar integer value.
-
class
ufl.constantvalue.
PermutationSymbol
(dim)¶ Bases:
ufl.constantvalue.ConstantValue
UFL literal type: Representation of a permutation symbol.
This is also known as the Levi-Civita symbol, antisymmetric symbol, or alternating symbol.
-
evaluate
(x, mapping, component, index_values)¶
-
shape
()¶
-
-
class
ufl.constantvalue.
ScalarValue
(value, shape=(), free_indices=(), index_dimensions=None)¶ Bases:
ufl.constantvalue.IndexAnnotated
A constant scalar value.
-
evaluate
(x, mapping, component, index_values)¶
-
free_indices
()¶
-
index_dimensions
()¶
-
reconstruct
(free_indices=None)¶ Reconstruct with new free indices.
-
shape
()¶
-
value
()¶
-
-
class
ufl.constantvalue.
Zero
(shape=(), free_indices=(), index_dimensions=None)¶ Bases:
ufl.constantvalue.IndexAnnotated
UFL literal type: Representation of a zero valued expression.
-
evaluate
(x, mapping, component, index_values)¶
-
free_indices
()¶
-
index_dimensions
()¶
-
reconstruct
(free_indices=None)¶
-
shape
()¶
-
-
ufl.constantvalue.
as_ufl
(expression)¶ Converts expression to an Expr if possible.
-
ufl.constantvalue.
format_float
(x)¶ Format float value based on global UFL precision.
-
ufl.constantvalue.
is_python_scalar
(expression)¶ Return True iff expression is of a Python scalar type.
-
ufl.constantvalue.
is_true_ufl_scalar
(expression)¶ Return True iff expression is scalar-valued, with no free indices.
-
ufl.constantvalue.
is_ufl_scalar
(expression)¶ Return True iff expression is scalar-valued, but possibly containing free indices.
-
ufl.constantvalue.
zero
(*shape)¶ UFL literal constant: Return a zero tensor with the given shape.
differentiation
Module¶
Differential operators.
-
class
ufl.differentiation.
CoefficientDerivative
(integrand, coefficients, arguments, coefficient_derivatives)¶ Bases:
ufl.differentiation.Derivative
Derivative of the integrand of a form w.r.t. the degrees of freedom in a discrete Coefficient.
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.differentiation.
CompoundDerivative
¶ Bases:
ufl.differentiation.Derivative
Base class for all compound derivative types.
-
class
ufl.differentiation.
Curl
(f)¶ Bases:
ufl.differentiation.CompoundDerivative
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.differentiation.
Derivative
¶ Bases:
ufl.operatorbase.Operator
Base class for all derivative types.
-
class
ufl.differentiation.
Div
(f)¶ Bases:
ufl.differentiation.CompoundDerivative
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.differentiation.
Grad
(f)¶ Bases:
ufl.differentiation.CompoundDerivative
-
evaluate
(x, mapping, component, index_values, derivatives=())¶ Get child from mapping and return the component asked for.
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
reconstruct
(op)¶ Return a new object of the same type with new operands.
-
shape
()¶
-
-
class
ufl.differentiation.
NablaDiv
(f)¶ Bases:
ufl.differentiation.CompoundDerivative
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.differentiation.
NablaGrad
(f)¶ Bases:
ufl.differentiation.CompoundDerivative
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
reconstruct
(op)¶ Return a new object of the same type with new operands.
-
shape
()¶
-
-
class
ufl.differentiation.
VariableDerivative
(f, v)¶ Bases:
ufl.differentiation.Derivative
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
ufl.differentiation.
split_indices
(expression, idx)¶
domains
Module¶
Types for specification of domains and subdomain relations.
-
class
ufl.domains.
Domain
(cell, name=None, gdim=None, tdim=None)¶ Bases:
ufl.domains.DomainDescription
-
subdomain_ids
()¶
-
top_domain
()¶
-
-
class
ufl.domains.
DomainDescription
(cell, name, gdim, tdim)¶ Bases:
object
-
cell
()¶
-
geometric_dimension
()¶
-
name
()¶
-
top_domain
()¶
-
topological_dimension
()¶
-
-
class
ufl.domains.
Region
(parent, subdomain_ids, name)¶ Bases:
ufl.domains.DomainDescription
-
subdomain_ids
()¶
-
top_domain
()¶
-
-
ufl.domains.
as_domain
(domain)¶
-
ufl.domains.
extract_domains
(integrand)¶
-
ufl.domains.
extract_top_domains
(integrand)¶
equation
Module¶
The Equation class, used to express equations like a == L.
-
class
ufl.equation.
Equation
(lhs, rhs)¶ This class is used to represent equations expressed by the “==” operator. Examples include a == L and F == 0 where a, L and F are Form objects.
Create equation lhs == rhs
expr
Module¶
This module defines the Expr class, the superclass for all expression tree node types in UFL.
NB! A note about other operators not implemented here:
More operators (special functions) on Exprs are defined in exproperators.py, as well as the transpose “A.T” and spatial derivative “a.dx(i)”. This is to avoid circular dependencies between Expr and its subclasses.
-
class
ufl.expr.
Expr
¶ Bases:
object
Base class for all UFL objects.
-
T
¶ Transposed a rank two tensor expression. For more general transpose operations of higher order tensor expressions, use indexing and Tensor.
-
cell
()¶ Return the cell this expression is defined on.
-
domain
()¶ Return the domain this expression is defined on.
-
dx
(*ii)¶ Return the partial derivative with respect to spatial variable number i.
-
evaluate
(x, mapping, component, index_values, derivatives=())¶ Evaluate expression at given coordinate with given values for terminals.
-
free_indices
()¶ Return a tuple with the free indices (unassigned) of the expression.
-
geometric_dimension
()¶ Return the geometric dimension this expression lives in.
-
index_dimensions
()¶ Return a dict with the free or repeated indices in the expression as keys and the dimensions of those indices as values.
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
operands
()¶ Return a sequence with all subtree nodes in expression tree.
-
rank
()¶ Return the tensor rank of the expression.
-
reconstruct
(*operands)¶ Return a new object of the same type with new operands.
-
shape
()¶ Return the tensor shape of the expression.
-
signature_data
()¶ Return data that uniquely identifies this object.
-
x__del__
()¶
-
-
ufl.expr.
print_expr_statistics
()¶
exprequals
Module¶
-
ufl.exprequals.
expr_equals
(self, other)¶ Checks whether the two expressions are represented the exact same way. This does not check if the expressions are mathematically equal or equivalent! Used by sets and dicts.
-
ufl.exprequals.
print_collisions
()¶
exproperators
Module¶
This module attaches special functions to Expr. This way we avoid circular dependencies between e.g. Sum and its superclass Expr.
-
ufl.exproperators.
analyse_key
(ii, rank)¶ Takes something the user might input as an index tuple inside [], which could include complete slices (:) and ellipsis (...), and returns tuples of actual UFL index objects.
The return value is a tuple (indices, axis_indices), each being a tuple of IndexBase instances.
The return value ‘indices’ corresponds to all input objects of these types: - Index - FixedIndex - int => Wrapped in FixedIndex
The return value ‘axis_indices’ corresponds to all input objects of these types: - Complete slice (:) => Replaced by a single new index - Ellipsis (...) => Replaced by multiple new indices
form
Module¶
The Form class.
-
class
ufl.form.
Form
(integrals)¶ Bases:
object
Description of a weak form consisting of a sum of integrals over subdomains.
-
cell
()¶
-
compute_form_data
(object_names=None, common_cell=None, element_mapping=None)¶ Compute and return form metadata
-
deprecated_signature
(function_replace_map=None)¶
-
form_data
()¶ Return form metadata (None if form has not been preprocessed)
-
integral_groups
()¶ Return a dict, which is a mapping from domain types to integrals.
In particular, the keys are domain_type strings, and the values are lists of Integral instances. The Integrals in each list share the same domain type (the key), but have potentially different domain ids and metadata.
-
integrals
(domain_type=None)¶
-
is_preprocessed
()¶ Return true if this form is the result of a preprocessing of another form.
-
x_repr_latex_
()¶
-
x_repr_png_
()¶
-
-
ufl.form.
integral_dict_to_sequence
(integrals)¶ Map a dictionary of lists of Integrals keyed by domain type into a sequence of Integral objects .
-
ufl.form.
integral_sequence_to_dict
(integrals)¶ Map a sequence of Integral objects to a dictionary of lists of Integrals keyed by domain type.
-
ufl.form.
join_dintegrals
(aintegrals, bintegrals)¶
formoperators
Module¶
Various high level ways to transform a complete Form into a new Form.
-
ufl.formoperators.
action
(form, coefficient=None)¶ UFL form operator: Given a bilinear form, return a linear form with an additional coefficient, representing the action of the form on the coefficient. This can be used for matrix-free methods.
-
ufl.formoperators.
adjoint
(form, reordered_arguments=None)¶ UFL form operator: Given a combined bilinear form, compute the adjoint form by changing the ordering (count) of the test and trial functions.
By default, new Argument objects will be created with opposite ordering. However, if the adjoint form is to be added to other forms later, their arguments must match. In that case, the user must provide a tuple reordered_arguments=(u2,v2).
-
ufl.formoperators.
derivative
(form, coefficient, argument=None, coefficient_derivatives=None)¶ UFL form operator: Given any form, compute the linearization of the form with respect to the given Coefficient. The resulting form has one additional Argument in the same finite element space as the coefficient. A tuple of Coefficients may be provided in place of a single Coefficient, in which case the new Argument argument is based on a MixedElement created from this tuple.
-
ufl.formoperators.
energy_norm
(form, coefficient=None)¶ UFL form operator: Given a bilinear form, return a linear form with an additional coefficient, representing the action of the form on the coefficient. This can be used for matrix-free methods.
-
ufl.formoperators.
functional
(form)¶ UFL form operator: Extract the functional part of form.
-
ufl.formoperators.
lhs
(form)¶ UFL form operator: Given a combined bilinear and linear form, extract the left hand side (bilinear form part).
Example:
a = u*v*dx + f*v*dx a = lhs(a) -> u*v*dx
-
ufl.formoperators.
rhs
(form)¶ UFL form operator: Given a combined bilinear and linear form, extract the right hand side (negated linear form part).
Example:
a = u*v*dx + f*v*dx L = rhs(a) -> -f*v*dx
-
ufl.formoperators.
sensitivity_rhs
(a, u, L, v)¶ UFL form operator: Compute the right hand side for a sensitivity calculation system.
The derivation behind this computation is as follows. Assume a, L to be bilinear and linear forms corresponding to the assembled linear system
Ax = b.Where x is the vector of the discrete function corresponding to u. Let v be some scalar variable this equation depends on. Then we can write
0 = d/dv[Ax-b] = dA/dv x + A dx/dv - db/dv, A dx/dv = db/dv - dA/dv x,and solve this system for dx/dv, using the same bilinear form a and matrix A from the original system. Assume the forms are written
v = variable(v_expression) L = IL(v)*dx a = Ia(v)*dxwhere IL and Ia are integrand expressions. Define a Coefficient u representing the solution to the equations. Then we can compute db/dv and dA/dv from the forms
da = diff(a, v) dL = diff(L, v)and the action of da on u by
dau = action(da, u)In total, we can build the right hand side of the system to compute du/dv with the single line
dL = diff(L, v) - action(diff(a, v), u)or, using this function
dL = sensitivity_rhs(a, u, L, v)
-
ufl.formoperators.
set_list_item
(li, i, v)¶
-
ufl.formoperators.
system
(form)¶ UFL form operator: Split a form into the left hand side and right hand side, see lhs and rhs.
-
ufl.formoperators.
zero_lists
(shape)¶
geometry
Module¶
Types for quantities computed from cell geometry.
-
class
ufl.geometry.
Cell
(cellname, geometric_dimension=None)¶ Bases:
object
Representation of a finite element cell.
Initialize basic cell description.
-
J
¶ UFL geometry value: The Jacobi of the local to global coordinate mapping.
-
Jinv
¶ UFL geometry value: The inverse of the Jacobi of the local to global coordinate mapping.
-
cellname
()¶ Return the cellname of the cell.
-
circumradius
¶ UFL geometry value: The circumradius of the cell.
-
d
¶ The dimension of the cell.
Only valid if the geometric and topological dimensions are the same.
-
detJ
¶ UFL geometry value: The determinant of the Jacobi of the local to global coordinate mapping.
-
domain
()¶
-
facet_area
¶ UFL geometry value: The area of a facet of the cell.
-
facet_cellname
()¶ Return the cellname of the facet of this cell.
-
facet_diameter
¶ UFL geometry value: The diameter of a facet of the cell.
-
geometric_dimension
()¶ Return the dimension of the space this cell is embedded in.
-
is_undefined
()¶ Return whether this cell is undefined, in which case no dimensions are available.
-
max_facet_edge_length
¶ UFL geometry value: The maximum edge length of a facet of the cell.
-
min_facet_edge_length
¶ UFL geometry value: The minimum edge length of a facet of the cell.
-
n
¶ UFL geometry value: The facet normal on the cell boundary.
-
surface_area
¶ UFL geometry value: The total surface area of the cell.
-
topological_dimension
()¶ Return the dimension of the topology of this cell.
-
volume
¶ UFL geometry value: The volume of the cell.
-
x
¶ UFL geometry value: The global spatial coordinates.
-
xi
¶ UFL geometry value: The local spatial coordinates.
-
-
class
ufl.geometry.
CellSurfaceArea
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
Representation of the total surface area of a cell.
-
shape
()¶
-
-
class
ufl.geometry.
CellVolume
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
Representation of a cell volume.
-
shape
()¶
-
-
class
ufl.geometry.
Circumradius
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
Representation of the circumradius of a cell.
-
shape
()¶
-
-
class
ufl.geometry.
FacetArea
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
Representation of the area of a cell facet.
-
shape
()¶
-
-
class
ufl.geometry.
FacetDiameter
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
(EXPERIMENTAL) Representation of the diameter of a facet.
This is not yet defined.
-
shape
()¶
-
-
class
ufl.geometry.
FacetNormal
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
Representation of a facet normal.
-
shape
()¶
-
-
class
ufl.geometry.
GeometricQuantity
(cell)¶ Bases:
ufl.terminal.Terminal
-
cell
()¶
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
-
class
ufl.geometry.
GeometryJacobi
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
(EXPERIMENTAL) Representation of the Jacobi of the mapping from local to global coordinates.
-
evaluate
(x, mapping, component, index_values)¶
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
shape
()¶
-
-
class
ufl.geometry.
GeometryJacobiDeterminant
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
(EXPERIMENTAL) Representation of the determinant of the Jacobi of the mapping from local to global coordinates.
-
evaluate
(x, mapping, component, index_values)¶
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
shape
()¶
-
-
class
ufl.geometry.
InverseGeometryJacobi
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
(EXPERIMENTAL) Representation of the (pseudo-)inverse of the Jacobi of the mapping from local to global coordinates.
-
evaluate
(x, mapping, component, index_values)¶
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
shape
()¶
-
-
class
ufl.geometry.
LocalCoordinate
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
(EXPERIMENTAL) Representation of a local coordinate on the reference cell.
-
evaluate
(x, mapping, component, index_values)¶
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
shape
()¶
-
-
class
ufl.geometry.
MaxFacetEdgeLength
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
Representation of the maximum edge length of a facet.
-
shape
()¶
-
-
class
ufl.geometry.
MinFacetEdgeLength
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
Representation of the minimum edge length of a facet.
-
shape
()¶
-
-
class
ufl.geometry.
ProductCell
(*cells)¶ Bases:
ufl.geometry.Cell
Representation of a cell formed by Cartesian products of other cells.
Create a ProductCell from a given list of cells.
-
sub_cells
()¶ Return list of cell factors.
-
-
class
ufl.geometry.
SpatialCoordinate
(cell)¶ Bases:
ufl.geometry.GeometricQuantity
Representation of a spatial coordinate.
-
evaluate
(x, mapping, component, index_values)¶
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
shape
()¶
-
-
ufl.geometry.
as_cell
(cell)¶ Convert any valid object to a Cell (in particular, cellname string), or return cell if it is already a Cell.
indexed
Module¶
This module defines the Indexed class.
indexing
Module¶
This module defines the single index types and some internal index utilities.
-
class
ufl.indexing.
FixedIndex
(value)¶ Bases:
ufl.indexing.IndexBase
UFL value: An index with a specific value assigned.
-
class
ufl.indexing.
Index
(count=None)¶ Bases:
ufl.indexing.IndexBase
UFL value: An index with no value assigned.
Used to represent free indices in Einstein indexing notation.
-
count
()¶
-
-
class
ufl.indexing.
MultiIndex
(ii, idims)¶ Bases:
ufl.terminal.UtilityType
Represents a sequence of indices, either fixed or free.
-
evaluate
(x, mapping, component, index_values)¶
-
free_indices
()¶
-
index_dimensions
()¶
-
-
ufl.indexing.
as_index
(i)¶
-
ufl.indexing.
as_multi_index
(ii, shape=None)¶
-
ufl.indexing.
indices
(n)¶ UFL value: Return a tuple of n new Index objects.
indexsum
Module¶
This module defines the IndexSum class.
-
class
ufl.indexsum.
IndexSum
(summand, index)¶ Bases:
ufl.operatorbase.AlgebraOperator
-
dimension
()¶
-
evaluate
(x, mapping, component, index_values)¶
-
free_indices
()¶
-
index
()¶
-
index_dimensions
()¶
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
operands
()¶
-
shape
()¶
-
indexutils
Module¶
Some utilities for working with index tuples.
-
ufl.indexutils.
complete_shape
(shape, default_dim)¶ Complete shape tuple by replacing non-integers with a default dimension.
-
ufl.indexutils.
repeated_indices
(indices)¶ Return tuple of indices occuring more than once in input.
Return a tuple of indices occuring in both index tuples ai and bi.
-
ufl.indexutils.
single_indices
(indices)¶ Return a tuple of all indices occuring exactly once in input.
-
ufl.indexutils.
unique_indices
(indices)¶ Return a tuple of all indices from input, with no single index occuring more than once in output.
integral
Module¶
The Integral class.
-
class
ufl.integral.
Integral
(integrand, domain_type, domain_description, compiler_data, domain_data)¶ Bases:
object
An integral over a single domain.
-
compiler_data
()¶ Return the compiler metadata this integral has been annotated with.
-
domain_data
()¶ Return the assembler metadata this integral has been annotated with.
-
domain_description
()¶ Return the domain description of this integral.
NB! Can be one of many types, this is work in progress!
-
domain_id
()¶ Return the domain id of this integral.
-
domain_type
()¶ Return the domain type of this integral.
-
integrand
()¶ Return the integrand expression, which is an Expr instance.
-
measure
()¶ Return the measure associated with this integral.
-
reconstruct
(integrand=None, domain_type=None, domain_description=None, compiler_data=None, domain_data=None)¶ Construct a new Integral object with some properties replaced with new values.
- Example:
- <a = Integral instance> b = a.reconstruct(expand_compounds(a.integrand())) c = a.reconstruct(compiler_data={‘quadrature_degree’:2})
-
-
ufl.integral.
Integral2
(integrand, domain_type, domain_desc, compiler_data, domain_data)¶
-
class
ufl.integral.
Measure
(domain_type, domain_id=None, metadata=None, domain_data=None)¶ Bases:
object
A measure for integration.
-
CELL
= 'cell'¶
-
DOMAIN_ID_CONSTANTS
= ('undefined', 'unique', 'everywhere', 'otherwise')¶
-
DOMAIN_ID_DEFAULT
= 'everywhere'¶
-
DOMAIN_ID_EVERYWHERE
= 'everywhere'¶
-
DOMAIN_ID_OTHERWISE
= 'otherwise'¶
-
DOMAIN_ID_UNDEFINED
= 'undefined'¶
-
DOMAIN_ID_UNIQUE
= 'unique'¶
-
EXTERIOR_FACET
= 'exterior_facet'¶
-
INTERIOR_FACET
= 'interior_facet'¶
-
MACRO_CELL
= 'macro_cell'¶
-
POINT
= 'point'¶
-
SURFACE
= 'surface'¶
-
domain_data
()¶ Return the integral domain_data. This data is not interpreted by UFL. Its intension is to give a context in which the domain id is interpreted.
-
domain_description
()¶ Return the domain description of this measure.
NB! Can be one of many types, this is work in progress!
-
domain_id
()¶ Return the domain id of this measure (integer).
-
domain_type
()¶ Return the domain type, one of “cell”, “exterior_facet”, “interior_facet”, etc.
-
metadata
()¶ Return the integral metadata. This data is not interpreted by UFL. It is passed to the form compiler which can ignore it or use it to compile each integral of a form in a different way.
-
reconstruct
(domain_id=None, metadata=None, domain_data=None)¶ Construct a new Measure object with some properties replaced with new values.
- Example:
- <dm = Measure instance> b = dm.reconstruct(domain_id=2) c = dm.reconstruct(metadata={ “quadrature_degree”: 3 })
- Used by the call operator, so this is equivalent:
- b = dm(2) c = dm(0, { “quadrature_degree”: 3 })
-
-
class
ufl.integral.
MeasureSum
(*measures)¶ Bases:
object
Notational intermediate object to translate the notation ‘f*(ds(1)+ds(3))’ into ‘f*ds(1) + f*ds(3)’. Note that MeasureSum objects will never actually be part of forms.
-
class
ufl.integral.
ProductMeasure
(*measures)¶ Bases:
ufl.integral.Measure
Representation of a product measure.
Create ProductMeasure from given list of measures.
-
sub_measures
()¶ Return submeasures.
-
-
ufl.integral.
as_domain_type
(domain_type)¶
-
ufl.integral.
is_globally_constant
(expr)¶ Check if an expression is globally constant, which includes spatially independent constant coefficients that are not known before assembly time.
-
ufl.integral.
is_scalar_constant_expression
(expr)¶ Check if an expression is a globally constant scalar expression.
-
ufl.integral.
register_domain_type
(domain_type, measure_name)¶
log
Module¶
This module provides functions used by the UFL implementation to output messages. These may be redirected by the user of UFL.
-
class
ufl.log.
Logger
(name, exception_type=<type 'exceptions.Exception'>)¶ Create logger instance.
-
add_indent
(increment=1)¶ Add to indentation level.
-
add_logfile
(filename=None, mode='a', level=10)¶
-
begin
(*message)¶ Begin task: write message and increase indentation level.
-
debug
(*message)¶ Write debug message.
-
deprecate
(*message)¶ Write deprecation message.
-
end
()¶ End task: write a newline and decrease indentation level.
-
error
(*message)¶ Write error message and raise an exception.
-
get_handler
()¶ Get handler for logging.
-
get_logfile_handler
(filename)¶
-
get_logger
()¶ Return message logger.
-
info
(*message)¶ Write info message.
-
info_blue
(*message)¶ Write info message in blue.
-
info_green
(*message)¶ Write info message in green.
-
info_red
(*message)¶ Write info message in red.
-
log
(level, *message)¶ Write a log message on given log level
-
pop_level
()¶ Pop log level from the level stack, reverting to before the last push_level.
-
push_level
(level)¶ Push a log level on the level stack.
-
set_handler
(handler)¶ Replace handler for logging. To add additional handlers instead of replacing the existing, use log.get_logger().addHandler(myhandler). See the logging module for more details.
-
set_indent
(level)¶ Set indentation level.
-
set_level
(level)¶ Set log level.
-
set_prefix
(prefix)¶ Set prefix for log messages.
-
warning
(*message)¶ Write warning message.
-
warning_blue
(*message)¶ Write warning message in blue.
-
warning_green
(*message)¶ Write warning message in green.
-
warning_red
(*message)¶ Write warning message in red.
-
mathfunctions
Module¶
This module provides basic mathematical functions.
-
class
ufl.mathfunctions.
Acos
(argument)¶
-
class
ufl.mathfunctions.
Asin
(argument)¶
-
class
ufl.mathfunctions.
Atan
(argument)¶
-
class
ufl.mathfunctions.
Atan2
(arg1, arg2)¶ Bases:
ufl.operatorbase.Operator
-
evaluate
(x, mapping, component, index_values)¶
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.mathfunctions.
BesselFunction
(name, classname, nu, argument)¶ Bases:
ufl.operatorbase.Operator
Base class for all bessel functions
-
evaluate
(x, mapping, component, index_values)¶
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.mathfunctions.
BesselI
(nu, argument)¶
-
class
ufl.mathfunctions.
BesselJ
(nu, argument)¶
-
class
ufl.mathfunctions.
BesselK
(nu, argument)¶
-
class
ufl.mathfunctions.
BesselY
(nu, argument)¶
-
class
ufl.mathfunctions.
Cos
(argument)¶
-
class
ufl.mathfunctions.
Cosh
(argument)¶
-
class
ufl.mathfunctions.
Erf
(argument)¶ Bases:
ufl.mathfunctions.MathFunction
-
evaluate
(x, mapping, component, index_values)¶
-
-
class
ufl.mathfunctions.
Exp
(argument)¶
-
class
ufl.mathfunctions.
Ln
(argument)¶ Bases:
ufl.mathfunctions.MathFunction
-
evaluate
(x, mapping, component, index_values)¶
-
-
class
ufl.mathfunctions.
MathFunction
(name, argument)¶ Bases:
ufl.operatorbase.Operator
Base class for all math functions
-
evaluate
(x, mapping, component, index_values)¶
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.mathfunctions.
Sin
(argument)¶
-
class
ufl.mathfunctions.
Sinh
(argument)¶
-
class
ufl.mathfunctions.
Sqrt
(argument)¶
-
class
ufl.mathfunctions.
Tan
(argument)¶
-
class
ufl.mathfunctions.
Tanh
(argument)¶
objects
Module¶
Utility objects for pretty syntax in user code.
operatorbase
Module¶
Base class for all operators, i.e. non-terminal expr types.
-
class
ufl.operatorbase.
AlgebraOperator
¶ Bases:
ufl.operatorbase.Operator
-
class
ufl.operatorbase.
Operator
¶ Bases:
ufl.expr.Expr
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
reconstruct
(*operands)¶ Return a new object of the same type with new operands.
-
signature_data
()¶
-
-
class
ufl.operatorbase.
Tuple
(*items)¶ Bases:
ufl.operatorbase.WrapperType
For internal use, never to be created by users.
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.operatorbase.
WrapperType
¶ Bases:
ufl.operatorbase.Operator
-
ufl.operatorbase.
compute_hash
(expr)¶
-
ufl.operatorbase.
compute_hash1
(expr)¶
-
ufl.operatorbase.
compute_hash2
(expr)¶
-
ufl.operatorbase.
compute_hash3
(expr)¶
-
ufl.operatorbase.
compute_hash4
(expr)¶
-
ufl.operatorbase.
compute_hash5
(expr)¶
-
ufl.operatorbase.
compute_hash_with_stats
(expr)¶
-
ufl.operatorbase.
get_some_terminals
(expr)¶
-
ufl.operatorbase.
traverse_terminals2
(expr)¶
-
ufl.operatorbase.
typetuple
(e)¶
operators
Module¶
This module extends the form language with free function operators, which are either already available as member functions on UFL objects or defined as compound operators involving basic operations on the UFL objects.
-
ufl.operators.
And
(left, right)¶ UFL operator: A boolean expresion (left and right) for use with conditional.
-
ufl.operators.
Dn
(f)¶ UFL operator: Take the directional derivative of f in the facet normal direction, Dn(f) := dot(grad(f), n).
-
ufl.operators.
Dt
(f)¶ UFL operator: <Not implemented yet!> The partial derivative of f with respect to time.
-
ufl.operators.
Dx
(f, *i)¶ UFL operator: Take the partial derivative of f with respect to spatial variable number i. Equivalent to f.dx(*i).
-
ufl.operators.
Max
(x, y)¶ UFL operator: Take the maximum of x and y.
-
ufl.operators.
Min
(x, y)¶ UFL operator: Take the minimum of x and y.
-
ufl.operators.
Not
(condition)¶ UFL operator: A boolean expresion (not condition) for use with conditional.
-
ufl.operators.
Or
(left, right)¶ UFL operator: A boolean expresion (left or right) for use with conditional.
-
ufl.operators.
acos
(f)¶ UFL operator: Take the inverse cosinus of f.
-
ufl.operators.
asin
(f)¶ UFL operator: Take the inverse sinus of f.
-
ufl.operators.
atan
(f)¶ UFL operator: Take the inverse tangent of f.
-
ufl.operators.
atan_2
(f1, f2)¶ UFL operator: Take the inverse tangent of f.
-
ufl.operators.
avg
(v)¶ UFL operator: Take the average of v across a facet.
-
ufl.operators.
bessel_I
(nu, f)¶ UFL operator: regular modified cylindrical Bessel function.
-
ufl.operators.
bessel_J
(nu, f)¶ UFL operator: cylindrical Bessel function of the first kind.
-
ufl.operators.
bessel_K
(nu, f)¶ UFL operator: irregular modified cylindrical Bessel function.
-
ufl.operators.
bessel_Y
(nu, f)¶ UFL operator: cylindrical Bessel function of the second kind.
-
ufl.operators.
cell_avg
(f)¶ UFL operator: Take the average of v over a cell.
-
ufl.operators.
cofac
(A)¶ UFL operator: Take the cofactor of A.
-
ufl.operators.
conditional
(condition, true_value, false_value)¶ UFL operator: A conditional expression, taking the value of true_value when condition evaluates to true and false_value otherwise.
-
ufl.operators.
contraction
(a, a_axes, b, b_axes)¶ UFL operator: Take the contraction of a and b over given axes.
-
ufl.operators.
cos
(f)¶ UFL operator: Take the cosinus of f.
-
ufl.operators.
cosh
(f)¶ UFL operator: Take the cosinus hyperbolicus of f.
-
ufl.operators.
cross
(a, b)¶ UFL operator: Take the cross product of a and b.
-
ufl.operators.
curl
(f)¶ UFL operator: Take the curl of f.
-
ufl.operators.
det
(A)¶ UFL operator: Take the determinant of A.
-
ufl.operators.
dev
(A)¶ UFL operator: Take the deviatoric part of A.
-
ufl.operators.
diag
(A)¶ UFL operator: Take the diagonal part of rank 2 tensor A _or_ make a diagonal rank 2 tensor from a rank 1 tensor.
Always returns a rank 2 tensor. See also diag_vector.
-
ufl.operators.
diag_vector
(A)¶ UFL operator: Take the diagonal part of rank 2 tensor A and return as a vector.
See also diag.
-
ufl.operators.
diff
(f, v)¶ UFL operator: Take the derivative of f with respect to the variable v.
If f is a form, diff is applied to each integrand.
-
ufl.operators.
div
(f)¶ UFL operator: Take the divergence of f.
This operator follows the div convention where
div(v) = v[i].dx(i)
div(T)[:] = T[:,i].dx(i)
for vector expressions v, and arbitrary rank tensor expressions T.
-
ufl.operators.
dot
(a, b)¶ UFL operator: Take the dot product of a and b.
-
ufl.operators.
elem_div
(A, B)¶ UFL operator: Take the elementwise division of the tensors A and B with the same shape.
-
ufl.operators.
elem_mult
(A, B)¶ UFL operator: Take the elementwise multiplication of the tensors A and B with the same shape.
-
ufl.operators.
elem_op
(op, *args)¶ UFL operator: Take the elementwise application of operator op on scalar values from one or more tensor arguments.
-
ufl.operators.
elem_op_items
(op_ind, indices, *args)¶
-
ufl.operators.
elem_pow
(A, B)¶ UFL operator: Take the elementwise power of the tensors A and B with the same shape.
-
ufl.operators.
eq
(left, right)¶ UFL operator: A boolean expresion (left == right) for use with conditional.
-
ufl.operators.
erf
(f)¶ UFL operator: Take the error function of f.
-
ufl.operators.
exp
(f)¶ UFL operator: Take the exponential of f.
-
ufl.operators.
exterior_derivative
(f)¶ UFL operator: Take the exterior derivative of f.
The exterior derivative uses the element family to determine whether id, grad, curl or div should be used.
Note that this uses the ‘grad’ and ‘div’ operators, as opposed to ‘nabla_grad’ and ‘nabla_div’.
-
ufl.operators.
facet_avg
(f)¶ UFL operator: Take the average of v over a facet.
-
ufl.operators.
ge
(left, right)¶ UFL operator: A boolean expresion (left >= right) for use with conditional.
-
ufl.operators.
grad
(f)¶ UFL operator: Take the gradient of f.
This operator follows the grad convention where
grad(s)[i] = s.dx(j)
grad(v)[i,j] = v[i].dx(j)
grad(T)[:,i] = T[:].dx(i)
for scalar expressions s, vector expressions v, and arbitrary rank tensor expressions T.
-
ufl.operators.
gt
(left, right)¶ UFL operator: A boolean expresion (left > right) for use with conditional.
-
ufl.operators.
inner
(a, b)¶ UFL operator: Take the inner product of a and b.
-
ufl.operators.
inv
(A)¶ UFL operator: Take the inverse of A.
-
ufl.operators.
jump
(v, n=None)¶ UFL operator: Take the jump of v across a facet.
-
ufl.operators.
le
(left, right)¶ UFL operator: A boolean expresion (left <= right) for use with conditional.
-
ufl.operators.
ln
(f)¶ UFL operator: Take the natural logarithm of f.
-
ufl.operators.
lt
(left, right)¶ UFL operator: A boolean expresion (left < right) for use with conditional.
-
ufl.operators.
nabla_div
(f)¶ UFL operator: Take the divergence of f.
This operator follows the div convention where
nabla_div(v) = v[i].dx(i)
nabla_div(T)[:] = T[i,:].dx(i)
for vector expressions v, and arbitrary rank tensor expressions T.
-
ufl.operators.
nabla_grad
(f)¶ UFL operator: Take the gradient of f.
This operator follows the grad convention where
nabla_grad(s)[i] = s.dx(j)
nabla_grad(v)[i,j] = v[j].dx(i)
nabla_grad(T)[i,:] = T[:].dx(i)
for scalar expressions s, vector expressions v, and arbitrary rank tensor expressions T.
-
ufl.operators.
ne
(left, right)¶ UFL operator: A boolean expresion (left != right) for use with conditional.
-
ufl.operators.
outer
(*operands)¶ UFL operator: Take the outer product of two or more operands.
-
ufl.operators.
perp
(v)¶ UFL operator: Take the perp of v, i.e. (-v1, +v0).
-
ufl.operators.
rank
(f)¶ UFL operator: The rank of f.
-
ufl.operators.
rot
(f)¶ UFL operator: Take the curl of f.
-
ufl.operators.
shape
(f)¶ UFL operator: The shape of f.
-
ufl.operators.
sign
(x)¶ UFL operator: Take the sign (+1 or -1) of x.
-
ufl.operators.
sin
(f)¶ UFL operator: Take the sinus of f.
-
ufl.operators.
sinh
(f)¶ UFL operator: Take the sinus hyperbolicus of f.
-
ufl.operators.
skew
(A)¶ UFL operator: Take the skew symmetric part of A.
-
ufl.operators.
sqrt
(f)¶ UFL operator: Take the square root of f.
-
ufl.operators.
sym
(A)¶ UFL operator: Take the symmetric part of A.
-
ufl.operators.
tan
(f)¶ UFL operator: Take the tangent of f.
-
ufl.operators.
tanh
(f)¶ UFL operator: Take the tangent hyperbolicus of f.
-
ufl.operators.
tr
(A)¶ UFL operator: Take the trace of A.
-
ufl.operators.
transpose
(A)¶ UFL operator: Take the transposed of tensor A.
-
ufl.operators.
variable
(e)¶ UFL operator: Define a variable representing the given expression, see also diff().
permutation
Module¶
This module provides utility functions for computing permutations and generating index lists.
-
ufl.permutation.
build_component_numbering
(shape, symmetry)¶ Build a numbering of components within the given value shape, taking into consideration a symmetry mapping which leaves the mapping noncontiguous. Returns a dict { component -> numbering } and an ordered list of components [ numbering -> component ]. The dict contains all components while the list only contains the ones not mapped by the symmetry mapping.
-
ufl.permutation.
compute_indices
(shape)¶ Compute all index combinations for given shape
-
ufl.permutation.
compute_indices2
(shape)¶ Compute all index combinations for given shape
-
ufl.permutation.
compute_order_tuples
(k, n)¶ Compute all tuples of n integers such that the sum is k
-
ufl.permutation.
compute_permutation_pairs
(j, k)¶ Compute all permutations of j + k elements from (0, j + k) in rising order within (0, j) and (j, j + k) respectively.
-
ufl.permutation.
compute_permutations
(k, n, skip=None)¶ Compute all permutations of k elements from (0, n) in rising order. Any elements that are contained in the list skip are not included.
-
ufl.permutation.
compute_sign
(permutation)¶ Compute sign by sorting.
precedence
Module¶
Precedence handling.
-
ufl.precedence.
assign_precedences
(precedence_list)¶ Given a precedence list, assign ints to class._precedence.
-
ufl.precedence.
build_precedence_list
()¶
-
ufl.precedence.
build_precedence_mapping
(precedence_list)¶ Given a precedence list, build a dict with class->int mappings. Utility function used by some external code.
-
ufl.precedence.
parstr
(child, parent, pre='(', post=')', format=<type 'str'>)¶
restriction
Module¶
Restriction operations.
-
class
ufl.restriction.
CellAvg
(f)¶ Bases:
ufl.operatorbase.Operator
-
evaluate
(x, mapping, component, index_values)¶ Performs an approximate symbolic evaluation, since we dont have a cell.
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.restriction.
FacetAvg
(f)¶ Bases:
ufl.operatorbase.Operator
-
evaluate
(x, mapping, component, index_values)¶ Performs an approximate symbolic evaluation, since we dont have a cell.
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.restriction.
NegativeRestricted
(f)¶ Bases:
ufl.restriction.Restricted
-
class
ufl.restriction.
PositiveRestricted
(f)¶ Bases:
ufl.restriction.Restricted
sorting
Module¶
This module contains a sorting rule for expr objects that is more robust w.r.t. argument numbering than using repr.
-
ufl.sorting.
cmp_expr
(a, b)¶ Sorting rule for Expr objects.
-
ufl.sorting.
expr_key
(expr)¶
-
ufl.sorting.
sorted_expr
(seq)¶
-
ufl.sorting.
sorted_expr_sum
(seq)¶
-
ufl.sorting.
topological_sorting
(nodes, edges)¶ 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...
split_functions
Module¶
Algorithm for splitting a Coefficient or Argument into subfunctions.
-
ufl.split_functions.
split
(v)¶ UFL operator: If v is a Coefficient or Argument in a mixed space, returns a tuple with the function components corresponding to the subelements.
tensoralgebra
Module¶
Compound tensor algebra operations.
-
class
ufl.tensoralgebra.
Cofactor
(A)¶ Bases:
ufl.tensoralgebra.CompoundTensorOperator
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.tensoralgebra.
CompoundTensorOperator
¶
-
class
ufl.tensoralgebra.
Cross
(a, b)¶ Bases:
ufl.tensoralgebra.CompoundTensorOperator
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.tensoralgebra.
Determinant
(A)¶ Bases:
ufl.tensoralgebra.CompoundTensorOperator
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.tensoralgebra.
Deviatoric
(A)¶ Bases:
ufl.tensoralgebra.CompoundTensorOperator
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.tensoralgebra.
Dot
(a, b)¶ Bases:
ufl.tensoralgebra.CompoundTensorOperator
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.tensoralgebra.
Inner
(a, b)¶ Bases:
ufl.tensoralgebra.CompoundTensorOperator
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.tensoralgebra.
Inverse
(A)¶ Bases:
ufl.tensoralgebra.CompoundTensorOperator
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.tensoralgebra.
Outer
(a, b)¶ Bases:
ufl.tensoralgebra.CompoundTensorOperator
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.tensoralgebra.
Skew
(A)¶ Bases:
ufl.tensoralgebra.CompoundTensorOperator
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.tensoralgebra.
Sym
(A)¶ Bases:
ufl.tensoralgebra.CompoundTensorOperator
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.tensoralgebra.
Trace
(A)¶ Bases:
ufl.tensoralgebra.CompoundTensorOperator
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
class
ufl.tensoralgebra.
Transposed
(A)¶ Bases:
ufl.tensoralgebra.CompoundTensorOperator
-
free_indices
()¶
-
index_dimensions
()¶
-
operands
()¶
-
shape
()¶
-
-
ufl.tensoralgebra.
merge_indices
(a, b)¶
tensors
Module¶
Classes used to group scalar expressions into expressions with rank > 0.
-
class
ufl.tensors.
ComponentTensor
(expression, indices)¶ Bases:
ufl.operatorbase.WrapperType
UFL operator type: Maps the free indices of a scalar valued expression to tensor axes.
-
evaluate
(x, mapping, component, index_values)¶
-
free_indices
()¶
-
index_dimensions
()¶
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
operands
()¶
-
reconstruct
(expressions, indices)¶
-
shape
()¶
-
-
class
ufl.tensors.
ListTensor
(*expressions)¶ Bases:
ufl.operatorbase.WrapperType
UFL operator type: Wraps a list of expressions into a tensor valued expression of one higher rank.
-
evaluate
(x, mapping, component, index_values, derivatives=())¶
-
free_indices
()¶
-
index_dimensions
()¶
-
is_cellwise_constant
()¶ Return whether this expression is spatially constant over each cell.
-
operands
()¶
-
shape
()¶
-
-
ufl.tensors.
as_matrix
(expressions, indices=None)¶ UFL operator: As as_tensor(), but limited to rank 2 tensors.
-
ufl.tensors.
as_scalar
(expression)¶ Given a scalar or tensor valued expression A, returns either of the tuples:
(a,b) = (A, ()) (a,b) = (A[indices], indices)
such that a is always a scalar valued expression.
-
ufl.tensors.
as_tensor
(expressions, indices=None)¶ UFL operator: Make a tensor valued expression.
This works in two different ways, by using indices or lists.
1) Returns A such that A[indices] = expressions. If indices are provided, expressions must be a scalar valued expression with all the provided indices among its free indices. This operator will then map each of these indices to a tensor axis, thereby making a tensor valued expression from a scalar valued expression with free indices.
2) Returns A such that A[k,...] = expressions[k]. If no indices are provided, expressions must be a list or tuple of expressions. The expressions can also consist of recursively nested lists to build higher rank tensors.
-
ufl.tensors.
as_vector
(expressions, index=None)¶ UFL operator: As as_tensor(), but limited to rank 1 tensors.
-
ufl.tensors.
dyad
(d, *iota)¶ TODO: Develop this concept, can e.g. write A[i,j]*dyad(j,i) for the transpose.
-
ufl.tensors.
from_numpy_to_lists
(expressions)¶
-
ufl.tensors.
numpy2nestedlists
(arr)¶
-
ufl.tensors.
relabel
(A, indexmap)¶ UFL operator: Relabel free indices of A with new indices, using the given mapping.
-
ufl.tensors.
unit_indexed_tensor
(shape, component)¶
-
ufl.tensors.
unit_list
(i, n)¶
-
ufl.tensors.
unit_list2
(i, j, n)¶
-
ufl.tensors.
unit_matrices
(d)¶ UFL value: A tuple of constant unit matrices in all directions with dimension d.
-
ufl.tensors.
unit_matrix
(i, j, d)¶ UFL value: A constant unit matrix in direction i,j with dimension d.
-
ufl.tensors.
unit_vector
(i, d)¶ UFL value: A constant unit vector in direction i with dimension d.
-
ufl.tensors.
unit_vectors
(d)¶ UFL value: A tuple of constant unit vectors in all directions with dimension d.
-
ufl.tensors.
unwrap_list_tensor
(lt)¶
terminal
Module¶
This module defines the Terminal class, the superclass for all types that are terminal nodes in the expression trees.
-
class
ufl.terminal.
Data
(data)¶ Bases:
ufl.terminal.UtilityType
For internal use, never to be created by users.
-
class
ufl.terminal.
FormArgument
(count=None, countedclass=None)¶ Bases:
ufl.terminal.Terminal
-
count
()¶
-
-
class
ufl.terminal.
Terminal
¶ Bases:
ufl.expr.Expr
A terminal node in the UFL expression tree.
-
evaluate
(x, mapping, component, index_values, derivatives=())¶ Get self from mapping and return the component asked for.
-
free_indices
()¶ A Terminal object never has free indices.
-
index_dimensions
()¶ A Terminal object never has free indices.
-
operands
()¶ A Terminal object never has operands.
-
reconstruct
(*operands)¶ Return self.
-
signature_data
()¶
-
testobjects
Module¶
Some premade objects useful for quick testing.
variable
Module¶
Defines the Variable and Label classes, used to label expressions as variables for differentiation.
-
class
ufl.variable.
Label
(count=None)¶ Bases:
ufl.terminal.UtilityType
-
count
()¶
-
-
class
ufl.variable.
Variable
(expression, label=None)¶ Bases:
ufl.operatorbase.WrapperType
A Variable is a representative for another expression.
It will be used by the end-user mainly for defining a quantity to differentiate w.r.t. using diff. Example:
e = <...> e = variable(e) f = exp(e**2) df = diff(f, e)
-
cell
()¶
-
domain
()¶
-
evaluate
(x, mapping, component, index_values)¶
-
expression
()¶
-
free_indices
()¶
-
index_dimensions
()¶
-
is_cellwise_constant
()¶
-
label
()¶
-
operands
()¶
-
shape
()¶
-
Subpackages¶
- algorithms Package
algorithms
Packagead
Moduleanalysis
Moduleargument_dependencies
Modulechecks
Moduledeprecated
Moduledomain_analysis
Moduleelementtransformations
Moduleestimate_degrees
Moduleexpand_compounds
Moduleexpand_indices
Moduleformdata
Moduleformfiles
Moduleformtransformations
Moduleforward_ad
Modulegraph
Modulelatextools
Modulemultifunction
Modulepdiffs
Modulepredicates
Modulepreprocess
Moduleprinting
Modulepropagate_restrictions
Modulerenumbering
Modulereplace
Modulesignature
Moduletransformations
Moduletransformer
Moduletraversal
Moduletuplenotation
Moduleufl2dot
Moduleufl2latex
Module
- finiteelement Package