Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: add priority to fd coefficients for mixed derivatives #2331

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions devito/finite_differences/differentiable.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sympy.core.decorators import call_highest_priority
from sympy.core.evalf import evalf_table

from devito.finite_differences.tools import make_shift_x0
from devito.finite_differences.tools import make_shift_x0, coeff_priority
from devito.logger import warning
from devito.tools import (as_tuple, filter_ordered, flatten, frozendict,
infer_dtype, is_integer, split)
Expand Down Expand Up @@ -130,11 +130,8 @@ def coefficients(self):
coefficients = {f.coefficients for f in self._functions}
# If there is multiple ones, we have to revert to the highest priority
# i.e we have to remove symbolic
if len(coefficients) == 2:
return (coefficients - {'symbolic'}).pop()
else:
assert len(coefficients) == 1
return coefficients.pop()
key = lambda x: coeff_priority[x]
return sorted(coefficients, key=key, reverse=True)[0]

@cached_property
def _coeff_symbol(self, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions devito/finite_differences/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def numeric_weights(function, deriv_order, indices, x0):

fd_weights_registry = {'taylor': numeric_weights, 'standard': numeric_weights,
'symbolic': symbolic_weights}
coeff_priority = {'taylor': 1, 'standard': 1, 'symbolic': 0}


def generate_indices(expr, dim, order, side=None, matvec=None, x0=None):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_symbolic_coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,10 @@ def test_compound_nested_subs(self):

# `str` simply because some objects are of type EvalDerivative
assert str(eq.evaluate.rhs) == str(term0 + term1 + term2)

def test_priority(self):
grid = Grid(shape=(11,))
m = Function(name='m', grid=grid, space_order=2, coefficients='symbolic')
p = Function(name='p', grid=grid, space_order=2)

assert (p*m).coefficients == 'taylor'
Loading