diff --git a/devito/deprecations.py b/devito/deprecations.py index 17f61b0cf0..f13c145de5 100644 --- a/devito/deprecations.py +++ b/devito/deprecations.py @@ -11,5 +11,12 @@ def coeff_warn(self): DeprecationWarning, stacklevel=2) return + @cached_property + def symbolic_warn(self): + warn("coefficients='symbolic' is deprecated, coefficients should" + "be passed directly to the derivative object `u.dx(weights=...)", + DeprecationWarning, stacklevel=2) + return + deprecations = DevitoDeprecation() diff --git a/devito/types/dense.py b/devito/types/dense.py index d96cc9b838..e65e34ce4f 100644 --- a/devito/types/dense.py +++ b/devito/types/dense.py @@ -12,6 +12,7 @@ from devito.data import (DOMAIN, OWNED, HALO, NOPAD, FULL, LEFT, CENTER, RIGHT, Data, default_allocator) from devito.data.allocators import DataReference +from devito.deprecations import deprecations from devito.exceptions import InvalidArgument from devito.logger import debug, warning from devito.mpi import MPI @@ -73,10 +74,7 @@ def __init_finalize__(self, *args, function=None, **kwargs): super().__init_finalize__(*args, **kwargs) # Symbolic (finite difference) coefficients - self._coefficients = kwargs.get('coefficients', self._default_fd) - if self._coefficients not in fd_weights_registry: - raise ValueError("coefficients must be one of %s" - " not %s" % (str(fd_weights_registry), self._coefficients)) + self._coefficients = self.__coefficients_setup__(**kwargs) # Data-related properties self._data = None @@ -169,6 +167,19 @@ def __dtype_setup__(cls, **kwargs): else: return np.float32 + def __coefficients_setup__(self, **kwargs): + """ + Setup finite-differences coefficients mode + """ + coeffs = kwargs.get('coefficients', self._default_fd) + if coeffs not in fd_weights_registry: + if coeffs == 'symbolic': + deprecations.symbolic_warn + else: + raise ValueError("coefficients must be one of %s" + " not %s" % (str(fd_weights_registry), coeffs)) + return coeffs + def __staggered_setup__(self, **kwargs): """ Setup staggering-related metadata. This method assigns: diff --git a/tests/test_symbolic_coefficients.py b/tests/test_symbolic_coefficients.py index 91a322eff4..0c520549f6 100644 --- a/tests/test_symbolic_coefficients.py +++ b/tests/test_symbolic_coefficients.py @@ -25,7 +25,7 @@ class TestSC: def test_coefficients(self, expr, sorder, dorder, dim, weights, expected): """Test that custom coefficients return the expected result""" grid = Grid(shape=(10, 10)) - u = Function(name='u', grid=grid, space_order=sorder) + u = Function(name='u', grid=grid, space_order=sorder, coefficients='symbolic') x, y = grid.dimensions h_x, h_y = grid.spacing_symbols # noqa