Skip to content

Commit 4c886eb

Browse files
Merge pull request #2934 from devitocodes/warn-if-shrunk-bounds
dsl: Warn if shrinking SpaceDimension bounds
2 parents e7890ce + 21bf445 commit 4c886eb

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

devito/operator/operator.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
)
4444
from devito.types import Buffer, Evaluable, device_layer, disk_layer, host_layer
4545
from devito.types.dimension import Thickness
46+
from devito.warnings import warn
4647

4748
__all__ = ['Operator']
4849

@@ -688,8 +689,15 @@ def _prepare_arguments(self, autotune=None, estimate_memory=False, **kwargs):
688689
p._arg_check(args, self._dspace[p], am=self._access_modes.get(p),
689690
**kwargs)
690691
for d in self.dimensions:
692+
try:
693+
if d.is_Space and any(self._dspace[d].offsets):
694+
warn(f"Shrinking bounds (`{d.min_name}`, `{d.max_name}`); "
695+
f"some `{d}` points will not be computed. Likely "
696+
"insufficient space_order for the derivatives.")
697+
except AttributeError:
698+
pass
691699
if d.is_Derived:
692-
d._arg_check(args, self._dspace[p])
700+
d._arg_check(args)
693701

694702
# Turn arguments into a format suitable for the generated code
695703
# E.g., instead of NumPy arrays for Functions, the generated code expects

tests/test_operator.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from devito.types import (
3939
Array, Barrier, ConditionalDimension, CustomDimension, Indirection, Scalar, Symbol
4040
)
41+
from devito.warnings import DevitoWarning
4142

4243

4344
def dimify(dimensions):
@@ -1343,6 +1344,22 @@ def test_apply_args_consitency(self, vfact):
13431344
if isinstance(v, int):
13441345
assert args1[k] == v
13451346

1347+
def test_warn_if_shrunk_spacedim_bounds(self):
1348+
grid = Grid(shape=(20, 20))
1349+
1350+
f = Function(name='f', grid=grid, space_order=0)
1351+
u = TimeFunction(name='u', grid=grid, space_order=8)
1352+
1353+
eq = Eq(u.forward, u + (u*f).laplace)
1354+
1355+
op = Operator(eq)
1356+
1357+
u.data[:] = 2.
1358+
f.data[:] = 3.
1359+
1360+
with pytest.warns(DevitoWarning, match="Shrinking bounds*"):
1361+
op.apply(time_M=3)
1362+
13461363

13471364
@skipif('device')
13481365
class TestDeclarator:

0 commit comments

Comments
 (0)