FDOperator fails with backward difference operators
Something is assumed about symmetrical number of points to both directions in stencil.
This probably does not affect any existing code, since non-central difference operators are not in use.
from gpaw.fd_operators import FDOperator
from gpaw.grid_descriptor import GridDescriptor
import numpy as np
def apply(op, array):
result = np.zeros_like(array)
op.apply(array, result)
return result
gd = GridDescriptor([4,4,4])
# Define backward difference operators
doesntwork = FDOperator( [-1.0, 1.0], [ [-1, 0, 0],[0, 0, 0]], gd)
# Add a dummy forward point with zero weight
works = FDOperator( [-1.0, 1.0, 0.0], [ [-1, 0, 0],[0, 0, 0],[1,0,0] ], gd)
f = gd.zeros()
f[-1,-1,-1] = 1
Rworks = apply(works, f)
Rdoesntwork = apply(doesntwork, f)
print("works", Rworks)
print("doesn't", Rdoesntwork)
r = Rdoesntwork-Rworks
print("diff",r)
assert np.linalg.norm(r) < 1e-10
Edited by Mikael Kuisma