Function

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 ArrayFunc 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 ArrayFunc objects have directly recognizable numpy equivalents, such as Sin or Inverse. By not evaluating directly but merely stacking operations, coplex operations can be defined prior to entering a quadrature loop, allowing for a higher lever 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, evalf)[source]

Base class

recurse_index(data, operations, cbuild)[source]

compile

compile()[source]
graphviz(title='graphviz')[source]

create function graph

stackstr(values=None)[source]

print stack

asciitree()[source]

string representation

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

evaluation error

class nutils.function.Tuple(items)[source]

combine

static vartuple(*f)[source]

evaluate

class nutils.function.PointShape[source]

shape of integration points

static pointshape(points)[source]

evaluate

class nutils.function.Cascade(ndims, side=0)[source]

point cascade: list of (elem,points) tuples

static cascade(elem, points, ndims, side)[source]

evaluate

class nutils.function.ArrayFunc(evalf, args, shape, dtype=<type 'float'>)[source]

array function

vector(ndims)[source]

vectorize

dot(weights, axis=0)[source]

array contraction

find(elem, C)[source]

iteratively find x for f(x) = target, starting at x=start

normalized()[source]

normalize last axis

normal(ndims=-1)[source]
curvature(ndims=-1)[source]
swapaxes(n1, n2)[source]

swap axes

transpose(trans=None)[source]
grad(coords, ndims=0)[source]

gradient

laplace(coords, ndims=0)[source]

laplacian

add_T(axes=(-2, -1))[source]

add transposed

symgrad(coords, ndims=0)[source]

gradient

div(coords, ndims=0)[source]

gradient

dotnorm(coords, ndims=0)[source]

normal component

ngrad(coords, ndims=0)[source]

normal gradient

nsymgrad(coords, ndims=0)[source]

normal gradient

T[source]

transpose

class nutils.function.ElemArea(weights)[source]

element area

static elemarea(weights)[source]

evaluate

class nutils.function.ElemInt(func, weights)[source]

elementwise integration

static elemint(w, f, ndim)[source]

evaluate

class nutils.function.Align(func, axes, ndim)[source]

align axes

static align(arr, trans, ndim)[source]
class nutils.function.Get(func, axis, item)[source]

get

class nutils.function.Product(func, axis)[source]

product

class nutils.function.IWeights[source]

integration weights

static iweights(elem, weights)[source]

evaluate

class nutils.function.OrientationHack(side=0)[source]

orientation hack for 1d elements; VERY dirty

static orientation(elem, side)[source]

evaluate

class nutils.function.Transform(fromcascade, tocascade, side=0)[source]

transform

static transform(fromcascade, tocascade, side)[source]
class nutils.function.Function(cascade, stdmap, igrad, axis)[source]

function

static function(cascade, stdmap, igrad)[source]

evaluate

class nutils.function.Choose(level, choices)[source]

piecewise function

static choose(level, *choices)[source]
class nutils.function.Choose2D(coords, contour, fin, fout)[source]

piecewise function

static choose2d(xy, contour, fin, fout)[source]

evaluate

class nutils.function.Inverse(func)[source]

inverse

class nutils.function.DofMap(cascade, dofmap, axis)[source]

dof axis

static evalmap(cascade, dofmap)[source]

evaluate

class nutils.function.Concatenate(funcs, axis=0)[source]

concatenate

static concatenate(iax, *arrays)[source]

evaluate

class nutils.function.Interpolate(x, xp, fp, left=None, right=None)[source]

interpolate uniformly spaced data; stepwise for now

class nutils.function.Cross(func1, func2, axis)[source]

cross product

class nutils.function.Determinant(func)[source]

normal

class nutils.function.DofIndex(array, iax, index)[source]

element-based indexing

static dofindex(arr, *item)[source]

evaluate

class nutils.function.Multiply(func1, func2)[source]

multiply

cdef()[source]

generate C code

class nutils.function.Negative(func)[source]

negate

class nutils.function.Add(func1, func2)[source]

add

cdef()[source]

generate C code

class nutils.function.BlockAdd(func1, func2)[source]

block addition (used for DG)

class nutils.function.Dot(func1, func2, naxes)[source]

dot

cdef()[source]

generate C code

class nutils.function.Sum(func, axis)[source]

sum

class nutils.function.Debug(func)[source]

debug

static debug(arr)[source]
class nutils.function.TakeDiag(func)[source]

extract diagonal

class nutils.function.Take(func, indices, axis)[source]

generalization of numpy.take(), to accept lists, slices, arrays

class nutils.function.Power(func, power)[source]

power

class nutils.function.ElemFunc(domainelem, side=0)[source]

trivial func

static elemfunc(cascade, domainelem)[source]

evaluate

find(elem, C)[source]

find coordinates

class nutils.function.Pointwise(args, evalf, deriv)[source]

pointwise transformation

class nutils.function.Sign(func)[source]

sign

class nutils.function.Eig(func, symmetric=False, sort=False)[source]

Eig

class nutils.function.Zeros(shape)[source]

zero

static zeros(points, shape)[source]

prepend point axes

class nutils.function.Inflate(func, dofmap, length, axis)[source]

inflate

static inflate(array, indices, length, axis)[source]
class nutils.function.Diagonalize(func)[source]

diagonal matrix

class nutils.function.Repeat(func, length, axis)[source]

repeat singleton axis

class nutils.function.Const(func)[source]

pointwise transformation

static const(points, arr)[source]

prepend point axes

nutils.function.asarray(arg)[source]

convert to ArrayFunc or numpy.ndarray

nutils.function.insert(arg, n)[source]

insert axis

nutils.function.stack(args, axis=0)[source]

stack functions along new axis

nutils.function.chain(funcs)[source]
nutils.function.merge(funcs)[source]

Combines unchained funcs into one function object.

nutils.function.vectorize(args)[source]
nutils.function.expand(arg, shape)[source]
nutils.function.repeat(arg, length, axis)[source]
nutils.function.get(arg, iax, item)[source]

get item

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

bring axis forward

nutils.function.elemint(arg, weights)[source]

elementwise integration

nutils.function.grad(arg, coords, ndims=0)[source]

local derivative

nutils.function.symgrad(arg, coords, ndims=0)[source]

symmetric gradient

nutils.function.div(arg, coords, ndims=0)[source]

gradient

nutils.function.sum(arg, axes=-1)[source]

sum over multiply axes

nutils.function.dot(arg1, arg2, axes)[source]

dot product

nutils.function.determinant(arg, axes=(-2, -1))[source]
nutils.function.inverse(arg, axes=(-2, -1))[source]
nutils.function.takediag(arg, ax1=-2, ax2=-1)[source]
nutils.function.localgradient(arg, ndims)[source]

local derivative

nutils.function.dotnorm(arg, coords, ndims=0)[source]

normal component

nutils.function.kronecker(arg, axis, length, pos)[source]
nutils.function.diagonalize(arg)[source]
nutils.function.concatenate(args, axis=0)[source]
nutils.function.transpose(arg, trans=None)[source]
nutils.function.product(arg, axis)[source]
nutils.function.choose(level, choices)[source]
nutils.function.cross(arg1, arg2, axis)[source]

cross product

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

outer product

nutils.function.pointwise(args, evalf, deriv)[source]

general pointwise operation

nutils.function.multiply(arg1, arg2)[source]
nutils.function.add(arg1, arg2)[source]
nutils.function.negative(arg)[source]

make negative

nutils.function.power(arg, n)[source]
nutils.function.sign(arg)[source]
nutils.function.eig( arg, axes [ symmetric ] )[source]

Compute the eigenvalues and vectors of a matrix. The eigenvalues and vectors are positioned on the last axes.

  • tuple axes The axis on which the eigenvalues and vectors are calculated
  • bool symmetric Is the matrix symmetric
  • int sort Sort the eigenvalues and vectors (-1=descending, 0=unsorted, 1=ascending)
nutils.function.swapaxes(arg, axes=(-2, -1))[source]

swap axes

nutils.function.opposite(arg)[source]

evaluate jump over interface

nutils.function.function(fmap, nmap, ndofs, ndims)[source]

create function on ndims-element

nutils.function.take(arg, index, axis)[source]

take index

nutils.function.inflate(arg, dofmap, length, axis)[source]
nutils.function.pointdata(topo, ischeme, func=None, shape=None, value=None)[source]

point data

nutils.function.fdapprox(func, w, dofs, delta=1e-05)[source]

Finite difference approximation of the variation of func in directions w around dofs. Input arguments: * func, the functional to differentiate * dofs, DOF vector of linearization point * w, the function space or a tuple of chained spaces * delta, finite difference step scaling of ||dofs||_inf

nutils.function.iwscale(coords, ndims)[source]

integration weights scale

nutils.function.supp(funcsp, indices)[source]

find support of selection of basis functions

class nutils.function.CBuilder(cachedir='/tmp/nutils')[source]

cbuilder