The function module defines the Evaluable class and derived objects, commonly referred to as nutils functions. They represent mappings from a nutils.topology onto Python space. The notabe class of Array objects map onto the space of Numpy arrays of predefined dimension and shape. Most functions used in nutils applicatons are of this latter type, including the geometry and function bases for analysis.

Nutils functions are essentially postponed python functions, stored in a tree structure of input/output dependencies. Many Array objects have directly recognizable numpy equivalents, such as Sin or Inverse. By not evaluating directly but merely stacking operations, complex operations can be defined prior to entering a quadrature loop, allowing for a higher level style programming. It also allows for automatic differentiation and code optimization.

It is important to realize that nutils functions do not map for a physical xy-domain but from a topology, where a point is characterized by the combination of an element and its local coordinate. This is a natural fit for typical finite element operations such as quadrature. Evaluation from physical coordinates is possible only via inverting of the geometry function, which is a fundamentally expensive and currently unsupported operation.

class nutils.function.Evaluable(args: tuple)[source]

Base class


string representation


create function graph


print stack

exception nutils.function.EvaluationError(etype, evalue, evaluable, values)[source]

evaluation error

class nutils.function.Cache[source]
class nutils.function.Points(opposite=False)[source]
class nutils.function.Tuple(items: tuple)[source]


class nutils.function.TransformChain(args: tuple, todims)[source]
class nutils.function.SelectChain(n, todims=None)[source]
class nutils.function.PopHead(todims: int, trans=<nutils.function.SelectChain object>)[source]
class nutils.function.SelectBifurcation(trans, first: bool, todims=None)[source]
class nutils.function.Promote(ndims: int, trans)[source]
class nutils.function.TailOfTransform(trans, depth, todims: int)[source]
class nutils.function.Array(args: tuple, shape: tuple, dtype: nutils.function.<lambda>)[source]

array function

class nutils.function.Normal(lgrad: nutils.function.<lambda>)[source]


class nutils.function.ArrayFunc(args: tuple, shape: tuple)[source]

deprecated ArrayFunc alias

class nutils.function.Constant(value: nutils.numeric.const)[source]
class nutils.function.DofMap(dofs: tuple, index: nutils.function.<lambda>)[source]
class nutils.function.InsertAxis(func: nutils.function.<lambda>, axis: int, length: nutils.function.<lambda>)[source]
class nutils.function.Transpose(func: nutils.function.<lambda>, axes: tuple)[source]
class nutils.function.Get(func: nutils.function.<lambda>, axis: int, item: nutils.function.<lambda>)[source]
class nutils.function.Product(func: nutils.function.<lambda>)[source]
class nutils.function.ApplyTransforms(trans, points=<nutils.function.Points object>)[source]
class nutils.function.LinearFrom(trans, fromdims: int)[source]
class nutils.function.Inverse(func: nutils.function.<lambda>)[source]
class nutils.function.Concatenate(funcs: tuple, axis: int = 0)[source]
class nutils.function.Interpolate(x: nutils.function.<lambda>, xp: nutils.numeric.const, fp: nutils.numeric.const, left=None, right=None)[source]

interpolate uniformly spaced data; stepwise for now

class nutils.function.Cross(func1: nutils.function.<lambda>, func2: nutils.function.<lambda>, axis: int)[source]
class nutils.function.Determinant(func: nutils.function.<lambda>)[source]
class nutils.function.Multiply(funcs: nutils.util.frozenmultiset)[source]
class nutils.function.Add(funcs: nutils.util.frozenmultiset)[source]
class nutils.function.BlockAdd(funcs: nutils.util.frozenmultiset)[source]

block addition (used for DG)

class nutils.function.Dot(funcs: nutils.util.frozenmultiset, axes: tuple)[source]
class nutils.function.Sum(func: nutils.function.<lambda>, axis: int)[source]
class nutils.function.TakeDiag(func: nutils.function.<lambda>, axis: int, rmaxis: int)[source]
class nutils.function.Take(func: nutils.function.<lambda>, indices: nutils.function.<lambda>, axis: int)[source]
class nutils.function.Power(func: nutils.function.<lambda>, power: nutils.function.<lambda>)[source]
class nutils.function.Pointwise(*args)[source]
class nutils.function.Cos(*args)[source]
class nutils.function.Sin(*args)[source]
class nutils.function.Tan(*args)[source]
class nutils.function.ArcSin(*args)[source]
class nutils.function.ArcCos(*args)[source]
class nutils.function.ArcTan(*args)[source]
class nutils.function.Exp(*args)[source]
class nutils.function.Log(*args)[source]
class nutils.function.Mod(*args)[source]
class nutils.function.ArcTan2(*args)[source]
class nutils.function.Greater(*args)[source]
class nutils.function.Equal(*args)[source]
class nutils.function.Less(*args)[source]
class nutils.function.Minimum(*args)[source]
class nutils.function.Maximum(*args)[source]
class nutils.function.Int(*args)[source]
class nutils.function.Sign(func: nutils.function.<lambda>)[source]
class nutils.function.Sampled(data: nutils.util.frozendict, trans=<nutils.function.SelectChain object>)[source]


class nutils.function.Elemwise(data: tuple, index: nutils.function.<lambda>, dtype: nutils.function.<lambda>)[source]
class nutils.function.Eig(func: nutils.function.<lambda>, symmetric: bool = False)[source]
class nutils.function.ArrayFromTuple(arrays, index: int, shape: tuple, dtype: nutils.function.<lambda>)[source]
class nutils.function.Zeros(shape: tuple, dtype: nutils.function.<lambda>)[source]


class nutils.function.Inflate(func: nutils.function.<lambda>, dofmap: nutils.function.<lambda>, length: int, axis: int)[source]
class nutils.function.Diagonalize(func: nutils.function.<lambda>, axis=<class 'int'>, newaxis=<class 'int'>)[source]
class nutils.function.Guard(fun: nutils.function.<lambda>)[source]

bar all simplifications

class nutils.function.TrigNormal(angle: nutils.function.<lambda>)[source]

cos, sin

class nutils.function.TrigTangent(angle: nutils.function.<lambda>)[source]

-sin, cos

class nutils.function.Find(where: nutils.function.<lambda>)[source]

indices of boolean index vector

class nutils.function.DerivativeTargetBase(args: tuple, shape: tuple, dtype: nutils.function.<lambda>)[source]

base class for derivative targets

class nutils.function.Argument(name, shape: tuple, nderiv: int = 0)[source]

Array argument, to be substituted before evaluation.

The Argument is an Array with a known shape, but whose values are to be defined later, before evaluation, e.g. using replace_arguments().

It is possible to take the derivative of an Array to an Argument:

>>> from nutils import function
>>> a = function.Argument('x', [])
>>> b = function.Argument('y', [])
>>> f = a**3 + b**2
>>> function.derivative(f, a).simplified == (3.*a**2).simplified

Furthermore, derivatives to the local cooardinates are remembered and applied to the replacement when using replace_arguments():

>>> from nutils import mesh
>>> domain, x = mesh.rectilinear([2,2])
>>> basis = domain.basis('spline', degree=2)
>>> c = function.Argument('c', basis.shape)
>>> replace_arguments(c.grad(x), dict(c=basis)) == basis.grad(x)
  • name (str) – The Identifier of this argument.
  • shape (tuple of ints) – The shape of this argument.
  • nderiv (int, non-negative) – Number of times a derivative to the local coordinates is taken. Default: 0.
class nutils.function.LocalCoords(ndims: int)[source]

local coords derivative target

class nutils.function.Ravel(func: nutils.function.<lambda>, axis: int)[source]
class nutils.function.Unravel(func: nutils.function.<lambda>, axis: int, shape: tuple)[source]
class nutils.function.Mask(func: nutils.function.<lambda>, mask: nutils.numeric.const, axis: int)[source]
class nutils.function.FindTransform(transforms: tuple, trans)[source]
class nutils.function.Range(length: nutils.function.<lambda>, offset: nutils.function.<lambda> = Array<>)[source]
class nutils.function.Polyval(coeffs: nutils.function.<lambda>, points: nutils.function.<lambda>, ngrad: int = 0)[source]

Computes the \(k\)-dimensional array

\[\begin{split}j_0,\dots,j_{k-1} \mapsto \sum_{\substack{i_0,\dots,i_{n-1}\in\mathbb{N}\\i_0+\cdots+i_{n-1}\le d}} p_0^{i_0} \cdots p_{n-1}^{i_{n-1}} c_{j_0,\dots,j_{k-1},i_0,\dots,i_{n-1}},\end{split}\]

where \(p\) are the \(n\)-dimensional local coordinates and \(c\) is the argument coeffs and \(d\) is the degree of the polynomial, where \(d\) is the length of the last \(n\) axes of coeffs.


All coefficients with a (combined) degree larger than \(d\) should be zero. Failing to do so won’t raise an Exception, but might give incorrect results.

nutils.function.bringforward(arg, axis)[source]

bring axis forward

nutils.function.matmat(arg0, *args)[source]

helper function, contracts last axis of arg0 with first axis of arg1, etc

nutils.function.derivative(func, var, seen=None)[source]
nutils.function.localgradient(arg, ndims)[source]

local derivative

nutils.function.outer(arg1, arg2=None, axis=0)[source]

outer product

nutils.function.polyfunc(coeffs, dofs, ndofs, transforms, *, issorted=True)[source]

Create an inflated Polyval with coefficients coeffs and corresponding dofs dofs. The arguments coeffs, dofs and transforms are assumed to have matching order. In addition, if issorted is true, the transforms argument is assumed to be sorted.

nutils.function.replace_arguments(value, arguments)[source]

Replace Argument objects in value.

Replace Argument objects in value according to the arguments map, taking into account derivatives to the local coordinates.


The edited value.

Return type:


class nutils.function.Namespace(*, default_geometry_name='x')[source]

Namespace for Array objects supporting assignments with tensor expressions.

The Namespace object is used to store Array objects.

>>> from nutils import function
>>> ns = function.Namespace()
>>> ns.A = function.zeros([3, 3])
>>> ns.x = function.zeros([3])
>>> ns.c = 2

In addition to the assignment of Array objects, it is also possible to specify an array using a tensor expression string — see nutils.expression.parse() for the syntax. All attributes defined in this namespace are available as variables in the expression. If the array defined by the expression has one or more dimensions the indices of the axes should be appended to the attribute name. Examples:

>>> ns.cAx_i = 'c A_ij x_j'
>>> ns.xAx = 'x_i A_ij x_j'

It is also possible to simply evaluate an expression without storing its value in the namespace by passing the expression to the method eval_ suffixed with appropriate indices:

>>> ns.eval_('2 c')
>>> ns.eval_i('c A_ij x_j')
>>> ns.eval_ij('A_ij + A_ji')

For zero and one dimensional expressions the following shorthand can be used:

>>> '2 c' @ ns
>>> 'A_ij x_j' @ ns

When evaluating an expression through this namespace the following functions are available: opposite, sin, cos, tan, sinh, cosh, tanh, arcsin, arccos, arctan2, arctanh, exp, abs, ln, log, log2, log10, sqrt and sign.

Parameters:default_geometry_name (str) – The name of the default geometry. This argument is passed to nutils.expression.parse(). Default: 'x'.

types.MappingProxyType – A readonly map of argument names and shapes.


str – The name of the default geometry. See argument with the same name.


nutils.function.Array – The default geometry, shorthand for getattr(ns, ns.default_geometry_name).

copy_(*, default_geometry_name=None)[source]

Return a copy of this namespace.