Open EdCaunt opened 3 years ago
some more discussion here: https://devitocodes.slack.com/archives/C3W8GF3H9/p1634720363011200?thread_ts=1634717124.009900&cid=C3W8GF3H9
This was also found to affect substitutions at forward and backward time steps (although this may have been fixed since?). However, a new MFE is:
import numpy as np
from devito import *
grid = Grid(shape=(10, 10))
f = TimeFunction(name='f', grid=grid, space_order=2, coefficients='symbolic')
x, y = grid.dimensions
subs = Substitutions(
Coefficient(1, f, x, np.array([2, 2, 2]) / x.spacing),
Coefficient(1, f, y, np.array([2, 2, 2]) / y.spacing)
)
print(grad(f)._evaluate().subs(subs.rules))
# --> Vector((2/h_x)*f(t, x, y) + (2/h_x)*f(t, x - h_x, y) + (2/h_x)*f(t, x + h_x, y), (2/h_y)*f(t, x, y) + (2/h_y)*f(t, x, y - h_y) + (2/h_y)*f(t, x, y + h_y))
print(grad(f, shift=0.5)._evaluate().subs(subs.rules))
# --> Vector(f(t, x, y)*W(x, 1, f(t, x, y), x + 0.5*h_x) + f(t, x + h_x, y)*W(x + h_x, 1, f(t, x, y), x + 0.5*h_x), f(t, x, y)*W(y, 1, f(t, x, y), y + 0.5*h_y) + f(t, x, y + h_y)*W(y + h_y, 1, f(t, x, y), y + 0.5*h_y))
coefficents=symbolic
is deprecated so should reopen if still an issue with the new api
Setting
coefficents=symbolic
on a function withstaggered
and not specifying stencil coefficients results in derivatives defaulting to incorrect values. It appears that specifying coefficients does not change them from this incorrect default.A short example:
One would expect all of these operators to have the same ccode (ignoring differences in variable names). However, this is not the case. The latter two do not have the same stencil operation.
Eq(vf, f.dxc).evaluate
returnsEq(v_f(x + h_x/2), -f(x)/h_x + f(x + h_x)/h_x)
whilstEq(vg, g.dx).evaluate
andEq(vh, h.dx, coefficients=coeffs)
both returnEq(v_g(x + h_x/2), g(x + h_x)/(2*h_x))