devito
devito copied to clipboard
Custom stencils not fully lowered if not made into EvalDerivative
Stencils specified as the weighted sum of terms need to be assembled into an EvalDerivative
to ensure that symbolic flop reduction is fully applied. An example of such a stencil is:
coeffs = [1, 2, 1]
inds = [-1. 0, 1]
expr = sum([coeff*f.subs({x: x+ind*h_x}) for coeff, ind in zip(coeffs/inds)])
stencil = expr/h_x**2
In this case, flop reduction will not be carried out fully, as the resulting stencil object is of type Mul
. The correct way to form such a stencil is:
coeffs = [1, 2, 1]
inds = [-1. 0, 1]
terms = [coeff*f.subs({x: x+ind*h_x})/h_x**2 for coeff, ind in zip(coeffs/inds)])
stencil = EvalDerivative(*terms, base=f)
In the case of nested derivatives, an EvalDerivative
needs to be used at each layer