function¶
- class nutils.function.Lowerable¶
Bases:
object
Protocol for lowering to
nutils.evaluable.Array
.- lower(self, points_shape, transform_chains, coordinates)¶
Lower this object to a
nutils.evaluable.Array
.- Parameters:
points_shape (
tuple
of scalar, integernutils.evaluable.Array
) – The shape of the leading points axes that are to be added to the lowerednutils.evaluable.Array
.transform_chains (mapping of
str
tonutils.transform.EvaluableTransformChain
pairs) –coordinates (mapping of
str
tonutils.evaluable.Array
objects) – The coordinates at which the function will be evaluated.
- __weakref__¶
list of weak references to the object (if defined)
- class nutils.function.Array(shape, dtype, spaces, arguments)¶
Bases:
NDArrayOperatorsMixin
Base class for array valued functions.
- Parameters:
- arguments¶
The mapping of argument names to their shapes and dtypes for all arguments of this array function.
- Type:
mapping of
str
- classmethod cast(_Array__value, dtype=None, ndim=None)¶
Cast a value to an
Array
.- Parameters:
value (
Array
, or anumpy.ndarray
or similar) – The value to cast.
- __len__(self)¶
Length of the first axis.
- __iter__(self)¶
Iterator over the first axis.
- normalized(self, _Array__axis=-1)¶
See
normalized()
.
- curvature(self, ndims=-1)¶
See
curvature()
.
- swapaxes(self, _Array__axis1, _Array__axis2)¶
See
swapaxes()
.
- transpose(self, _Array__axes)¶
See
transpose()
.
- nsymgrad(self, _Array__geom, ndims=0)¶
See
nsymgrad()
.
- eval(self, **arguments)¶
Evaluate this function.
- derivative(self, _Array__var)¶
See
derivative()
.
- replace(self, _Array__arguments)¶
Return a copy with arguments applied.
- contains(self, _Array__name)¶
Test if target occurs in this function.
- conjugate(self)¶
See
conjugate()
.
- conj(self)¶
See
conjugate()
.
- class nutils.function.Custom(args, shape, dtype, npointwise=0)¶
Bases:
Array
Combined
nutils.function
andnutils.evaluable
array base class.Ordinary
Array
subclasses should define theArray.lower
method, which returns the correspondingnutils.evaluable.Array
with the proper amount of points axes. In many cases theArray
subclass is trivial and the correspondingnutils.evaluable.Array
contains all the specifics. For those situations theCustom
base class exists. Rather than defining theArray.lower
method, this base class allows you to define aCustom.evalf()
and optionally aCustom.partial_derivative()
, which are used to instantiate a genericnutils.evaluable.Array
automatically during lowering.By default the
Array
arguments passed to the constructor are unmodified. Broadcasting and singleton expansion, if required, should be applied before passing the arguments to the constructor ofCustom
. It is possible to declarenpointwise
leading axes as being pointwise. In that caseCustom
applies singleton expansion to the leading pointwise axes and the shape of the result passed toCustom
should not include the pointwise axes.For internal reasons, both
evalf
andpartial_derivative
must be decorated asclassmethod
orstaticmethod
, meaning that they will not receive a reference toself
when called. Instead, all relevant data should be passed toevalf
via the constructor argumentargs
. The constructor will automatically distinguish between Array and non-Array arguments, and pass the latter on toevalf
unchanged. Thepartial_derivative
will not be called for those arguments.The lowered array does not have a Nutils hash by default. If this is desired, the methods
evalf()
andpartial_derivative()
can be decorated withnutils.types.hashable_function()
in addition toclassmethod
orstaticmethod
.- Parameters:
args (iterable of
Array
objects or immutable and hashable objects) – The arguments of this array function.shape (
tuple
ofint
orArray
) – The shape of the array function without leading pointwise axes.dtype (
bool
,int
,float
orcomplex
) – The dtype of the array elements.npointwise (
int
) – The number of leading pointwise axis.
Example
The following class implements
multiply()
usingCustom
without broadcasting and forfloat
arrays only.>>> class Multiply(Custom): ... ... def __init__(self, left: IntoArray, right: IntoArray) -> None: ... # Broadcast the arrays. `broadcast_arrays` automatically casts the ... # arguments to `Array`. ... left, right = broadcast_arrays(left, right) ... # Dtype coercion is beyond the scope of this example. ... if left.dtype != float or right.dtype != float: ... raise ValueError('left and right arguments should have dtype float') ... # We treat all axes as pointwise, hence parameter `shape`, the shape ... # of the remainder, is empty and `npointwise` is the dimension of the ... # arrays. ... super().__init__(args=(left, right), shape=(), dtype=float, npointwise=left.ndim) ... ... @staticmethod ... def evalf(left: numpy.ndarray, right: numpy.ndarray) -> numpy.ndarray: ... # Because all axes are pointwise, the evaluated `left` and `right` ... # arrays are 1d. ... return left * right ... ... @staticmethod ... def partial_derivative(iarg: int, left: Array, right: Array) -> IntoArray: ... # The arguments passed to this function are of type `Array` and the ... # pointwise axes are omitted, hence `left` and `right` are 0d. ... if iarg == 0: ... return right ... elif iarg == 1: ... return left ... else: ... raise NotImplementedError ... >>> Multiply([1., 2.], [3., 4.]).eval() array([ 3., 8.]) >>> a = Argument('a', (2,)) >>> Multiply(a, [3., 4.]).derivative(a).eval(a=numpy.array([1., 2.])).export('dense') array([[ 3., 0.], [ 0., 4.]])
The following class wraps
numpy.roll()
, applied to the last axis of the array argument, with constant shift.>>> class Roll(Custom): ... ... def __init__(self, array: IntoArray, shift: int) -> None: ... array = asarray(array) ... # We are being nit-picky here and cast `exponent` to an `int` without ... # truncation. ... shift = shift.__index__() ... # We treat all but the last axis of `array` as pointwise. ... super().__init__(args=(array, shift), shape=array.shape[-1:], dtype=array.dtype, npointwise=array.ndim-1) ... ... @staticmethod ... def evalf(array: numpy.ndarray, shift: int) -> numpy.ndarray: ... # `array` is evaluated to a `numpy.ndarray` because we passed `array` ... # as an `Array` to the constructor. `shift`, however, is untouched ... # because it is not an `Array`. The `array` has two axes: a points ... # axis and the axis to be rolled. ... return numpy.roll(array, shift, 1) ... ... @staticmethod ... def partial_derivative(iarg, array: Array, shift: int) -> IntoArray: ... if iarg == 0: ... return Roll(eye(array.shape[0]), shift).T ... else: ... # We don't implement the derivative to `shift`, because this is ... # a constant `int`. ... raise NotImplementedError ... >>> Roll([1, 2, 3], 1).eval() array([3, 1, 2]) >>> b = Argument('b', (3,)) >>> Roll(b, 1).derivative(b).eval().export('dense') array([[ 0., 0., 1.], [ 1., 0., 0.], [ 0., 1., 0.]])
- classmethod evalf(*args)¶
Evaluate this function for the given evaluated arguments.
This function is called with arguments that correspond to the arguments that are passed to the constructor of
Custom
: every instance ofArray
is evaluated to anumpy.ndarray
with one leading axis compared to theArray
and all other instances are passed as is. The return value of this method should also include a leading axis with the same length as the other array arguments have, or length one if there are no array arguments. If constructor argumentnpointwise
is nonzero, the pointwise axes of theArray
arguments are raveled and included in the single leading axis of the evaluated array arguments as well.If possible this method should not use
self
, e.g. by decorating this method withstaticmethod()
. The result of this function must only depend on the arguments and must not mutate the arguments.This method is equivalent to
nutils.evaluable.Array.evalf
up to the treatment of the leading axis.- Parameters:
*args – The evaluated arguments corresponding to the
args
parameter of theCustom
constructor.- Returns:
The result of this function with one leading points axis.
- Return type:
- classmethod partial_derivative(iarg, *args)¶
Return the partial derivative of this function to
Custom
constructor argument numberiarg
.This method is only called for those arguments that are instances of
Array
with dtypefloat
and have the derivative target as a dependency. It is therefor allowed to omit an implementation for some or all arguments if the above conditions are not met.Axes that are declared pointwise via the
npointwise
constructor argument are omitted.
- class nutils.function.Argument(name, shape, *, dtype=<class 'float'>)¶
Bases:
Array
Array valued function argument.
- Parameters:
- nutils.function.implements(np_function)¶
Register an
__array_function__
or__array_ufunc__
implementation for Array objects.
- nutils.function.asarray(__arg)¶
Cast a value to an
Array
.- Parameters:
value (
Array
, or anumpy.ndarray
or similar) – The value to cast.- Return type:
- nutils.function.zeros(shape, dtype=<class 'float'>)¶
Create a new
Array
of given shape and dtype, filled with zeros.
- nutils.function.ones(shape, dtype=<class 'float'>)¶
Create a new
Array
of given shape and dtype, filled with ones.
- nutils.function.eye(__n, dtype=<class 'float'>)¶
Create a 2-D
Array
with ones on the diagonal and zeros elsewhere.
- nutils.function.levicivita(__n, dtype=<class 'float'>)¶
Create an n-D Levi-Civita symbol.
- nutils.function.add(__left, __right)¶
Return the sum of the arguments, elementwise.
- nutils.function.subtract(__left, __right)¶
Return the difference of the arguments, elementwise.
- nutils.function.positive(__arg)¶
Return the argument unchanged.
- nutils.function.negative(__arg)¶
Return the negation of the argument, elementwise.
- nutils.function.multiply(__left, __right)¶
Return the product of the arguments, elementwise.
- nutils.function.divide(__dividend, __divisor)¶
Return the true-division of the arguments, elementwise.
- nutils.function.floor_divide(__dividend, __divisor)¶
Return the floor-division of the arguments, elementwise.
- nutils.function.reciprocal(__arg)¶
Return the reciprocal of the argument, elementwise.
- nutils.function.power(__base, __exponent)¶
Return the exponentiation of the arguments, elementwise.
- nutils.function.sqrt(__arg)¶
Return the square root of the argument, elementwise.
- nutils.function.abs(__arg)¶
Return the absolute value of the argument, elementwise.
- nutils.function.matmul(__arg1, __arg2)¶
Return the matrix product of two arrays.
- Parameters:
- Return type:
See also
numpy.matmul
the equivalent Numpy function.
- nutils.function.sign(__arg)¶
Return the sign of the argument, elementwise.
- nutils.function.mod(__dividend, __divisor)¶
Return the remainder of the floored division, elementwise.
- nutils.function.divmod(__dividend, __divisor)¶
Return the floor-division and remainder, elementwise.
- nutils.function.cos(__arg)¶
Return the trigonometric cosine of the argument, elementwise.
- nutils.function.sin(__arg)¶
Return the trigonometric sine of the argument, elementwise.
- nutils.function.tan(__arg)¶
Return the trigonometric tangent of the argument, elementwise.
- nutils.function.arccos(__arg)¶
Return the trigonometric inverse cosine of the argument, elementwise.
- nutils.function.arcsin(__arg)¶
Return the trigonometric inverse sine of the argument, elementwise.
- nutils.function.arctan(__arg)¶
Return the trigonometric inverse tangent of the argument, elementwise.
- nutils.function.arctan2(__dividend, __divisor)¶
Return the trigonometric inverse tangent of the
dividend / divisor
, elementwise.
- nutils.function.cosh(__arg)¶
Return the hyperbolic cosine of the argument, elementwise.
- nutils.function.sinh(__arg)¶
Return the hyperbolic sine of the argument, elementwise.
- nutils.function.tanh(__arg)¶
Return the hyperbolic tangent of the argument, elementwise.
- nutils.function.arctanh(__arg)¶
Return the hyperbolic inverse tangent of the argument, elementwise.
- nutils.function.exp(__arg)¶
Return the exponential of the argument, elementwise.
- nutils.function.log(__arg)¶
Return the natural logarithm of the argument, elementwise.
- nutils.function.ln(__arg)¶
Return the natural logarithm of the argument, elementwise.
- nutils.function.log2(__arg)¶
Return the base 2 logarithm of the argument, elementwise.
- nutils.function.log10(__arg)¶
Return the base 10 logarithm of the argument, elementwise.
- nutils.function.greater(__left, __right)¶
Return if the first argument is greater than the second, elementwise.
- nutils.function.equal(__left, __right)¶
Return if the first argument equals the second, elementwise.
- nutils.function.less(__left, __right)¶
Return if the first argument is less than the second, elementwise.
- nutils.function.min(__a, __b)¶
Return the minimum of the arguments, elementwise.
- nutils.function.max(__a, __b)¶
Return the maximum of the arguments, elementwise.
- nutils.function.opposite(__arg)¶
Evaluate this function at the opposite side.
When evaluating a function
arg
at an interface, the function will be evaluated at one side of the interface.opposite()
selects the opposite side.Example
We create a one dimensional topology with two elements and a discontinuous function
f
that is 1 on the first element and 2 on the second:>>> from nutils import mesh, function >>> topo, geom = mesh.rectilinear([2]) >>> f = topo.basis('discont', 0).dot([1, 2])
Evaluating this function at the interface gives (for this particular topology) the value at the side of the first element:
>>> topo.interfaces.sample('bezier', 1).eval(f) array([ 1.])
Using
opposite()
we obtain the value at the side of second element:>>> topo.interfaces.sample('bezier', 1).eval(function.opposite(f)) array([ 2.])
It is allowed to nest opposites:
>>> topo.interfaces.sample('bezier', 1).eval(function.opposite(function.opposite(f))) array([ 1.])
- nutils.function.mean(__arg)¶
Return the mean of the argument at an interface.
Example
We create a one dimensional topology with two elements and a discontinuous function
f
that is 1 on the first element and 2 on the second:>>> from nutils import mesh, function >>> topo, geom = mesh.rectilinear([2]) >>> f = topo.basis('discont', 0).dot([1, 2])
Evaluating the mean of this function at the interface gives:
>>> topo.interfaces.sample('bezier', 1).eval(function.mean(f)) array([ 1.5])
- nutils.function.jump(__arg)¶
Return the jump of the argument at an interface.
The sign of the jump depends on the orientation of the interfaces in a
Topology
. Usually the jump is used as part of an inner product with thenormal()
of the geometry is used, which is independent of the orientation of the interfaces.Example
We create a one dimensional topology with two elements and a discontinuous function
f
that is 1 on the first element and 2 on the second:>>> from nutils import mesh, function >>> topo, geom = mesh.rectilinear([2]) >>> f = topo.basis('discont', 0).dot([1, 2])
Evaluating the jump of this function at the interface gives (for this particular topology):
>>> topo.interfaces.sample('bezier', 1).eval(function.jump(f)) array([ 1.])
- nutils.function.sum(__arg, axis=None)¶
Return the sum of array elements over the given axes.
- nutils.function.product(__arg, axis)¶
Return the product of array elements over the given axes.
- nutils.function.conjugate(__arg)¶
Return the complex conjugate, elementwise.
- nutils.function.conj(__arg)¶
Return the complex conjugate, elementwise.
- nutils.function.real(__arg)¶
Return the real part of the complex argument.
- nutils.function.imag(__arg)¶
Return the imaginary part of the complex argument.
- nutils.function.dot(__a, __b, axes=None)¶
Return the inner product of the arguments over the given axes, elementwise over the remanining axes.
- Parameters:
axis (
int
, a sequence ofint
, orNone
) – The axis or axes along which the inner product is performed. If the second argument has one dimension and axes isNone
, the default, the inner product of the second argument with the first axis of the first argument is computed. Otherwiseaxes=None
is not allowed.
- Return type:
- nutils.function.vdot(__a, __b, axes=None)¶
Return the dot product of two vectors.
If the arguments are not 1D, the arguments are flattened. The dot product is then defined as
sum(conjugate(a) * b)
- nutils.function.trace(__arg, axis1=-2, axis2=-1)¶
Return the trace, the sum of the diagonal, of an array over the two given axes, elementwise over the remanining axes.
- nutils.function.norm2(__arg, axis=-1)¶
Return the 2-norm of the argument over the given axis, elementwise over the remanining axes.
- nutils.function.normalized(__arg, axis=-1)¶
Return the argument normalized over the given axis, elementwise over the remanining axes.
- Parameters:
- Return type:
See also
norm2()
The 2-norm.
- nutils.function.matmat(__arg0, *args)¶
helper function, contracts last axis of arg0 with first axis of arg1, etc
- nutils.function.inverse(__arg, __axes=(-2, -1))¶
Return the inverse of the argument along the given axes, elementwise over the remaining axes.
- nutils.function.determinant(__arg, __axes=(-2, -1))¶
Return the determinant of the argument along the given axes, elementwise over the remaining axes.
- nutils.function.eig(__arg, __axes=(-2, -1), symmetric=False)¶
Return the eigenvalues and right eigenvectors of the argument along the given axes, elementwise over the remaining axes.
- Parameters:
- Returns:
- nutils.function.takediag(__arg, __axis=-2, __rmaxis=-1)¶
Return the diagonal of the argument along the given axes.
- Parameters:
- Return type:
See also
diagonalize()
The complement operation.
- nutils.function.diagonalize(__arg, __axis=-1, __newaxis=-1)¶
Return argument with
newaxis
such thataxis
and newaxis` is diagonal.- Parameters:
- Return type:
See also
takediag()
The complement operation.
- nutils.function.cross(__arg1, __arg2, axis=-1)¶
Return the cross product of the arguments over the given axis, elementwise over the remaining axes.
- Parameters:
- Return type:
See also
takediag()
The inverse operation.
- nutils.function.outer(arg1, arg2=None, axis=0)¶
outer product
- nutils.function.transpose(__array, __axes=None)¶
Permute the axes of an array.
- Parameters:
- Returns:
The transposed array. Axis
i
of the resulting array corresponds to axisaxes[i]
of the argument.- Return type:
- nutils.function.insertaxis(__array, axis, length)¶
Insert an axis with given length.
- nutils.function.expand_dims(__array, axis)¶
Insert a singleton axis.
- nutils.function.repeat(__array, __n, axis)¶
Repeat the given axis of an array n times.
- nutils.function.swapaxes(__array, __axis1, __axis2)¶
Swap two axes of an array.
- nutils.function.ravel(__array, axis)¶
Ravel two consecutive axes of an array.
- Parameters:
- Return type:
See also
unravel()
The reverse operation.
- nutils.function.unravel(__array, axis, shape)¶
Unravel an axis to the given shape.
- Parameters:
- Returns:
The resulting array with unraveled axes
axis
andaxis+1
.- Return type:
See also
ravel()
The reverse operation.
- nutils.function.take(__array, __indices, axis)¶
Take elements from an array along an axis.
- Parameters:
indices (
Array
with dtypeint
orbool
or something that can becast()
into one) – The indices of elements to take. The array of indices may have any dimension, including zero. However, if the array is boolean, the array must 1-D.axis (
int
) – The axis to take elements from or, ifindices
has more than one dimension, the first axis of a range ofindices.ndim
axes to take elements from.
- Returns:
The array with the taken elements. The original
axis
is replaced byindices.ndim
axes.- Return type:
- nutils.function.get(__array, __axis, __index)¶
Get one element from an array along an axis.
- Parameters:
- Return type:
See also
take()
Take elements from an array along an axis.
kronecker()
The complement operation.
- nutils.function.scatter(__array, length, indices)¶
Distribute the last dimensions of an array over a new axis.
- Parameters:
- Return type:
Notes
Scatter strictly reorganizes array entries, it cannot assign multiple entries to the same position. In other words, the provided indices must be unique.
See also
take()
The complement operation.
- nutils.function.kronecker(__array, axis, length, pos)¶
Position an element in an axis of given length.
- Parameters:
- Return type:
See also
get()
The complement operation.
- nutils.function.concatenate(__arrays, axis=0)¶
Join arrays along an existing axis.
- Parameters:
- Return type:
See also
stack()
Join arrays along an new axis.
- nutils.function.stack(__arrays, axis=0)¶
Join arrays along a new axis.
- Parameters:
- Return type:
See also
stack()
Join arrays along an new axis.
- nutils.function.broadcast_arrays(*arrays)¶
Broadcast the given arrays.
- nutils.function.typecast_arrays(*arrays, min_dtype=<class 'bool'>)¶
Cast the given arrays to the same dtype.
- nutils.function.broadcast_shapes(*shapes)¶
Broadcast the given shapes into a single shape.
- nutils.function.broadcast_to(array, shape)¶
Broadcast an array to a new shape.
- nutils.function.derivative(__arg, __var)¶
Differentiate arg to var.
- nutils.function.grad(__arg, __geom, ndims=0)¶
Return the gradient of the argument to the given geometry.
- nutils.function.curl(__arg, __geom)¶
Return the curl of the argument w.r.t. the given geometry.
- nutils.function.normal(__geom, refgeom=None)¶
Return the normal of the geometry.
- Parameters:
refgeom (
Array
, optional`) – The reference geometry. IfNone
, the reference geometry is the tip coordinate system of the spaces on whichgeom
is defined. The dimension of the reference geometry must be exactly one smaller than the dimension of the geometry.
- Return type:
- nutils.function.dotnorm(__arg, __geom, axis=-1)¶
Return the inner product of an array with the normal of the given geometry.
- nutils.function.tangent(__geom, __vec)¶
Return the tangent.
- nutils.function.jacobian(__geom, __ndims=None)¶
Return the absolute value of the determinant of the Jacobian matrix of the given geometry.
- nutils.function.J(__geom, __ndims=None)¶
Return the absolute value of the determinant of the Jacobian matrix of the given geometry.
Alias of
jacobian()
.
- nutils.function.surfgrad(__arg, geom)¶
Return the surface gradient of the argument to the given geometry.
- nutils.function.curvature(__geom, ndims=-1)¶
Return the curvature of the given geometry.
- nutils.function.div(__arg, __geom, ndims=0)¶
Return the divergence of
arg
w.r.t. the given geometry.
- nutils.function.laplace(__arg, __geom, ndims=0)¶
Return the Laplacian of
arg
w.r.t. the given geometry.
- nutils.function.symgrad(__arg, __geom, ndims=0)¶
Return the symmetric gradient of
arg
w.r.t. the given geometry.
- nutils.function.ngrad(__arg, __geom, ndims=0)¶
Return the inner product of the gradient of
arg
with the normal of the given geometry.
- nutils.function.nsymgrad(__arg, __geom, ndims=0)¶
Return the inner product of the symmetric gradient of
arg
with the normal of the given geometry.
- nutils.function.eval(funcs, **arguments)¶
Evaluate one or several Array objects.
- nutils.function.rootcoords(space, __dim)¶
Return the root coordinates.
- nutils.function.Elemwise(__data, __index, dtype)¶
elemwise
- nutils.function.piecewise(level, intervals, *funcs)¶
- nutils.function.partition(f, *levels)¶
Create a partition of unity for a scalar function f.
When
n
levels are specified,n+1
indicator functions are formed that evaluate to one if and only if the following condition holds:indicator 0: f < levels[0] indicator 1: levels[0] < f < levels[1] ... indicator n-1: levels[n-2] < f < levels[n-1] indicator n: f > levels[n-1]
At the interval boundaries the indicators evaluate to one half, in the remainder of the domain they evaluate to zero such that the whole forms a partition of unity. The partitions can be used to create a piecewise continuous function by means of multiplication and addition.
The following example creates a topology consiting of three elements, and a function
f
that is zero in the first element, parabolic in the second, and zero again in the third element.>>> from nutils import mesh >>> domain, x = mesh.rectilinear([3]) >>> left, center, right = partition(x[0], 1, 2) >>> f = (1 - (2*x[0]-3)**2) * center
- nutils.function.heaviside(f)¶
Create a heaviside step-function based on a scalar function f.
\[ \begin{align}\begin{aligned}H(f) &= 0 && f < 0\\H(f) &= 0.5 && f = 0\\H(f) &= 1 && f > 0\end{aligned}\end{align} \]See also
partition()
generalized version of
heaviside()
sign()
like
heaviside()
but with different levels
- nutils.function.choose(__index, __choices)¶
Function equivalent of
numpy.choose()
.
- nutils.function.chain(_funcs)¶
- nutils.function.vectorize(args)¶
Combine scalar-valued bases into a vector-valued basis.
- Parameters:
args (iterable of 1-dimensional
nutils.function.Array
objects) –- Return type:
- nutils.function.add_T(__arg, axes=(-2, -1))¶
add transposed
- nutils.function.dotarg(__argname, *arrays, shape=(), dtype=<class 'float'>)¶
Return the inner product of the first axes of the given arrays with an argument with the given name.
An argument with shape
(arrays[0].shape[0], ..., arrays[-1].shape[0]) + shape
will be created. Repeatedly the inner product of the result, starting with the argument, with every array fromarrays
is taken, where all but the first axis are treated as an outer product.- Parameters:
- Returns:
The inner product with shape
shape + arrays[0].shape[1:] + ... + arrays[-1].shape[1:]
.- Return type:
- class nutils.function.Basis(ndofs, nelems, index, coords)¶
Bases:
Array
Abstract base class for bases.
A basis is a sequence of elementwise polynomial functions.
- Parameters:
Notes
Subclasses must implement
get_dofs()
andget_coefficients()
and if possible should redefineget_support()
.- get_support(self, dof)¶
Return the support of basis function
dof
.If
dof
is anint
, return the indices of elements that form the support ofdof
. Ifdof
is an array, return the union of supports of the selected dofs as a unique array. The returned array is always unique, i.e. strict monotonic increasing.- Parameters:
dof (
int
or array ofint
orbool
) – Index or indices of basis function or a mask.- Returns:
support – The elements (as indices) where function
dof
has support.- Return type:
sorted and unique
numpy.ndarray
- get_dofs(self, ielem)¶
Return an array of indices of basis functions with support on element
ielem
.If
ielem
is anint
, return the dofs on elementielem
matching the coefficients array as returned byget_coefficients()
. Ifielem
is an array, return the union of dofs on the selected elements as a unique array, i.e. a strict monotonic increasing array.
- get_ndofs(self, ielem)¶
Return the number of basis functions with support on element
ielem
.
- get_coefficients(self, ielem)¶
Return an array of coefficients for all basis functions with support on element
ielem
.- Parameters:
ielem (
int
) – Element number.- Returns:
coefficients – Array of coefficients with shape
(nlocaldofs,)+(degree,)*ndims
, where the first axis corresponds to the dofs returned byget_dofs()
.- Return type:
- class nutils.function.PlainBasis(coefficients, dofs, ndofs, index, coords)¶
Bases:
Basis
A general purpose implementation of a
Basis
.Use this class only if there exists no specific implementation of
Basis
for the basis at hand.- Parameters:
coefficients (
tuple
ofnumpy.ndarray
objects) – The coefficients of the basis functions per transform. The order should match thetransforms
argument.dofs (
tuple
ofnumpy.ndarray
objects) – The dofs corresponding to thecoefficients
argument.ndofs (
int
) – The number of basis functions.index (
Array
) – The element index.coords (
Array
) – The element local coordinates.
- class nutils.function.DiscontBasis(coefficients, index, coords)¶
Bases:
Basis
A discontinuous basis with monotonic increasing dofs.
- Parameters:
coefficients (
tuple
ofnumpy.ndarray
objects) – The coefficients of the basis functions per transform. The order should match thetransforms
argument.index (
Array
) – The element index.coords (
Array
) – The element local coordinates.
- class nutils.function.LegendreBasis(degree, nelems, index, coords)¶
Bases:
Basis
A discontinuous Legendre basis.
- class nutils.function.MaskedBasis(parent, indices)¶
Bases:
Basis
An order preserving subset of another
Basis
.
- class nutils.function.StructuredBasis(coeffs, start_dofs, stop_dofs, dofs_shape, transforms_shape, index, coords)¶
Bases:
Basis
A basis for class:nutils.transformseq.StructuredTransforms.
- Parameters:
coeffs (
tuple
oftuple
s of arrays) – Per dimension the coefficients of the basis functions per transform.start_dofs (
tuple
of arrays ofint
s) – Per dimension the dof of the first entry incoeffs
per transform.stop_dofs (
tuple
of arrays ofint
s) – Per dimension one plus the dof of the last entry incoeffs
per transform.transforms_shape (
tuple
ofint
s) – The tensor shape of the transforms.index (
Array
) – The element index.coords (
Array
) – The element local coordinates.