Substitutions(self, *args)

Devito class to convert Coefficient objects into replacent rules to be applied when constructing a Devito Eq.


>>> from devito import Grid, TimeFunction, Coefficient
>>> grid = Grid(shape=(4, 4))
>>> u = TimeFunction(name='u', grid=grid, space_order=2, coefficients='symbolic')
>>> x, y = grid.dimensions

Now define some partial d/dx FD coefficients of the Function u:

>>> u_x_coeffs = Coefficient(2, u, x, np.array([-0.6, 0.1, 0.6]))

And now create our Substitutions object to pass to equation:

>>> from devito import Substitutions
>>> subs = Substitutions(u_x_coeffs)

Now create a Devito equation and pass to it ‘subs’

>>> from devito import Eq
>>> eq = Eq(u.dt+u.dx2, coefficients=subs)

When evaluated, the derivatives will use the custom coefficients. We can check that by

>>> eq.evaluate
Eq(-u(t, x, y)/dt + u(t + dt, x, y)/dt + 0.1*u(t, x, y) - 0.6*u(t, x - h_x, y) + 0.6*u(t, x + h_x, y), 0)


If a Function is declared with ‘symbolic’ coefficients and no replacement rules for any derivative appearing in a Devito equation, the coefficients will revert to those of the ‘default’ Taylor expansion.


Name Description
coefficients The Coefficient objects passed.
Back to top