From 535e53dd76992d3747e83a8f5eb12d30a29ecc0e Mon Sep 17 00:00:00 2001 From: mloubout Date: Fri, 3 May 2024 10:23:34 -0400 Subject: [PATCH] api: fix zeroth order only and add test --- devito/finite_differences/derivative.py | 2 +- tests/test_derivatives.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/devito/finite_differences/derivative.py b/devito/finite_differences/derivative.py index 74f7c7cfe94..371cff71643 100644 --- a/devito/finite_differences/derivative.py +++ b/devito/finite_differences/derivative.py @@ -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) diff --git a/tests/test_derivatives.py b/tests/test_derivatives.py index 1ce0b953f8f..f8d4bd8ac69 100644 --- a/tests/test_derivatives.py +++ b/tests/test_derivatives.py @@ -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):