dolfin.function.expression

Functions

numba_eval(*args[, numba_jit_options, …])

Decorator to create Numba JIT-compiled evaluate function.

Classes

Expression(f[, shape])

Initialise Expression

dolfin.function.expression.numba_eval(*args, numba_jit_options: dict = {'cache': False, 'nopython': True}, numba_cfunc_options: dict = {'cache': False, 'nopython': True})[source]

Decorator to create Numba JIT-compiled evaluate function.

A decorator that takes an evaluation function f and returns the C address of the Numba JIT-ed method. The call signature of f should be:

f: Callable(None, (numpy.array, numpy.array, numpy.array))

Python function accepting parameters: values, x, cell_index, t.

For more information on numba_jit_options and numba_cfunc_options read the Numba documentation.

Parameters
  • numba_jit_options (dict, optional) – Options passed to numba.jit. nopython must be True.

  • numba_cfunc_options (dict, optional) – Options passed to numba.cfunc. nopython must be True.

Example

>>> @function.expression.numba_eval
>>> def expr(values, x, cell_idx):
>>>    values[:, 0] = x[:, 0] + x[:, 1] + x[:, 2]
>>>    values[:, 1] = x[:, 0] - x[:, 1] - x[:, 2]
>>>    values[:, 2] = x[:, 0] + x[:, 1] + x[:, 2]
>>> mesh = UnitCubeMesh(MPI.comm_world, 3, 3, 3)
>>> W = VectorFunctionSpace(mesh, ('CG', 1))
>>> e = Expression(expr, shape=(3,))
>>> u = Function(W)
>>> u.interpolate(e)