Skip to content

Commit

Permalink
dsl: Patch issue #1578 (Check legality of symbolic derivatives)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leitevmd committed Feb 24, 2021
1 parent dcd9637 commit 3709560
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions devito/finite_differences/derivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ def evaluate(self):
# Evaluate finite-difference.
# Note: evaluate and _eval_fd splitted for potential future different
# types of discretizations.
do = self.deriv_order
if isinstance(do, int):
do = (do,)
for i, d in enumerate(self.dims):
expr_order = self.expr.time_order if d.is_Time else self.expr.space_order
if do[i] > expr_order:
raise ValueError("Expression order must be equal or greater than "
"Derivative order")
return self._eval_fd(self.expr)

@property
Expand Down
13 changes: 13 additions & 0 deletions tests/test_derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,16 @@ def test_shifted_grad(self, shift, ndim):
x0 = (None if shift is None else d + shift[i] * d.spacing if
type(shift) is tuple else d + shift * d.spacing)
assert gi == getattr(f, 'd%s' % d.name)(x0=x0).evaluate

def test_lower_order_derivatives(self):
grid = Grid(tuple([11]*2))
u = TimeFunction(name="u", grid=grid, space_order=2, time_order=2)
m = TimeFunction(name="m", grid=grid, space_order=1, time_order=1)
try:
Operator(Eq(u.forward, u.biharmonic(1/m)))
Operator(Eq(u.forward, (u * m).dx2))
Operator(Eq(u.forward, (u * m).dt2))
except ValueError:
assert True
else:
assert False

0 comments on commit 3709560

Please sign in to comment.