Substitutions

Substitutions(self, *args)

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

Examples

>>> 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(1, 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.dx, 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)

Notes

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.

Attributes

Name Description
coefficients The Coefficient objects passed.
Back to top