Skip to content

Commit 21f1921

Browse files
authored
Merge pull request #2731 from devitocodes/patch-border
dsl: Fix SubDomainSet auxiliary dimension name to avoid clashes
2 parents 9d78954 + e66f6f0 commit 21f1921

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

devito/types/grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ def __subdomain_finalize_core__(self, grid):
873873
# SubDomainSet ID to make them unique so they can be used to key a dictionary
874874
# of replacements without risking overwriting.
875875
i_dim = Dimension(f'n_{str(id(self))}')
876-
d_dim = DefaultDimension(name='d', default_value=2*grid.dim)
876+
d_dim = DefaultDimension(name='sds_dim', default_value=2*grid.dim)
877877
sd_func = Function(name=self.name, grid=self._grid,
878878
shape=(self._n_domains, 2*grid.dim),
879879
dimensions=(i_dim, d_dim), dtype=np.int32)

tests/test_subdomains.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from conftest import opts_tiling, assert_structure
88
from devito import (ConditionalDimension, Constant, Grid, Function, TimeFunction,
9-
Eq, solve, Operator, SubDomain, SubDomainSet, Lt, SparseTimeFunction,
10-
VectorFunction, TensorFunction, Border)
9+
Eq, solve, Operator, SubDomain, SubDomainSet, Lt, SparseFunction,
10+
SparseTimeFunction, VectorFunction, TensorFunction, Border)
1111
from devito.ir import FindNodes, FindSymbols, Expression, Iteration, SymbolRegistry
1212
from devito.tools import timed_region
1313

@@ -724,6 +724,23 @@ class Dummy(SubDomainSet):
724724
assert y.is_Parallel
725725
assert z.is_Parallel
726726

727+
def test_subdomainset_w_sparse(self):
728+
grid = Grid(shape=(11, 11))
729+
f = Function(name='f', grid=grid)
730+
s = SparseFunction(name='s', grid=grid, npoint=1)
731+
732+
border = SubDomainSet(N=1, bounds=(2, 2, 2, 2), grid=grid)
733+
op = Operator([Eq(f, 0, subdomain=border)] + s.inject(f, expr=1))
734+
735+
# There was an issue where a clash between auxiliary dimension
736+
# names used for SparseFunction and SubDomainSet resulted in
737+
# cryptic errors when applying the operator
738+
op()
739+
740+
check = np.zeros((11, 11))
741+
check[0, 0] = 1
742+
assert np.all(np.isclose(f.data, check))
743+
727744

728745
class TestBorder:
729746
# Note: This class is partially covered by doctests

0 commit comments

Comments
 (0)