Module diff

class findiff.diff.BinaryOperator(left, right)

Base class for all binary operators (like addition) that allow to combine or chain differential operators

class findiff.diff.Coef(value)

Encapsulates a constant (number) or variable (N-dimensional coordinate array) value to multiply with a linear operator

Parameters:

value – a number or an numpy.ndarray with meshed coordinates

Example:

The following example defines the differential operator

\[2x\frac{\partial^3}{\partial x^2\partial z}\]
>>> X, Y, Z, U = numpy.meshgrid(x, y, z, u, indexing="ij")
>>> diff_op = Coef(2*X) * FinDiff((0, dx, 2), (2, dz, 1))
class findiff.diff.Diff(axis, order, **kwargs)

Representation of a single partial derivative based on finite differences.

This class is usually not used directly by the user, but is wrapped in a FinDiff object.

Parameters:
  • axis – the numpy axis along which to apply the derivative

  • order – the order of the derivative

  • kwargs

    optional keyword arguments

    Allowed keywords:

    acc: even integer

    The desired accuracy order.

apply(u, *args, **kwargs)

Applies the partial derivative to a numpy array.

diff(y, h, acc)

The core function to take a partial derivative on a uniform grid.

Central coefficients will be used whenever possible. Backward or forward coefficients will be used if not enough points are available on either side, i.e. forward coefficients for the low index boundary and backward coefficients for the high index boundary.

diff_non_uni(y, coords, **kwargs)

The core function to take a partial derivative on a non-uniform grid

matrix(shape, h=None, acc=None, coords=None, sparse_type=<class 'scipy.sparse._csr.csr_matrix'>)

Matrix representation of the partial derivative.

Parameters:
  • shape – Tuple with the shape of the grid (number of grid points in each dimension)

  • h – The grid spacing for the axis of the partial derivative (only used for uniform grids)

  • coords – The coordinate values of the grid on the axis of the partial derivative (only used for non-uniform grids)

  • acc – The accuracy order of the derivative (even int)

  • sparse_type – The scipy sparse matrix type used for the matrix representation.

:returns matrix representation (scipy sparse matrix)

class findiff.diff.Id

The identity operator. When applied to an array, returns the same array (not a copy)

matrix(shape)

Matrix representation of the identity operator, i.e. identity matrix of given shape.

Parameters:

shape (tuple of ints) – Shape of the arrays to which Id shall be applied

Returns:

Sparse identity matrix.

Return type:

scipy.sparse.csr_matrix

class findiff.diff.LinearMap(value)
class findiff.diff.Minus(left, right)

A class to subtract two differential operators from each other

class findiff.diff.Mul(left, right)

A class to multiply (chain) two differential operators

matrix(shape, *args, **kwargs)

Matrix representation of given operator product on an equidistant grid of given shape.

Parameters:

shape – tuple with the shape of the grid

Returns:

scipy sparse matrix representing the operator product

class findiff.diff.Operator

Base class for all operator classes

class findiff.diff.Plus(left, right)

A class to add two differential operators