Skip to content

Commit

Permalink
api: fix zeroth order only and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mloubout committed May 3, 2024
1 parent 59e5483 commit 535e53d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion devito/finite_differences/derivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _process_kwargs(cls, expr, *dims, **kwargs):
orders = kwargs.get('deriv_order', dims[0][1])
if dims[0][1] != orders:
raise ValueError("Two different values of `deriv_order`")
new_dims = tuple([dims[0][0]]*dims[0][1])
new_dims = tuple([dims[0][0]]*max(1, dims[0][1]))
else:
# Single Dimension
orders = kwargs.get('deriv_order', 1)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,20 @@ def test_zero_spec(self):
assert expr0.subs(drv0, drv1) == expr1
assert expr1.subs(drv1, drv0) == expr0

def test_zero_fd_interp(self):
"""
Test that zero-order derivatives are generating interpolation coefficients
"""
grid = Grid((11,))
x, = grid.dimensions
f = Function(name="f", grid=grid, space_order=4)

assert Derivative(f, x, deriv_order=0).evaluate == f
expected = (-f.subs(x, x - x.spacing) / 16 + f.subs(x, x) * 9 / 16 +
f.subs(x, x + x.spacing) * 9 / 16 - f.subs(x, x + 2*x.spacing) / 16)
finterp = Derivative(f, (x, 0), x0={x: x+x.spacing/2}).evaluate
assert simplify(finterp - expected) == 0


class TestTwoStageEvaluation(object):

Expand Down

0 comments on commit 535e53d

Please sign in to comment.