Skip to content

Commit 7b0d38e

Browse files
committed
compiler: Start SubDimMax
1 parent 7b9d763 commit 7b0d38e

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

devito/petsc/equations.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from devito.symbolics import retrieve_indexed, retrieve_dimensions
2+
from devito.petsc import EssentialBC
3+
from devito.types.dimension import CustomBoundSubDimension
4+
from devito import Min, Max
5+
6+
7+
def lower_exprs_petsc(expressions, **kwargs):
8+
mapper = {}
9+
10+
additional_exprs = []
11+
12+
# build mapper
13+
for e in expressions:
14+
if not isinstance(e, EssentialBC):
15+
continue
16+
indexeds = retrieve_indexed(e)
17+
dims = retrieve_dimensions([i for j in indexeds for i in j.indices], mode='unique')
18+
19+
dims = [d for d in dims if d.is_Sub and not d.local]
20+
21+
for d in dims:
22+
# replace the dim with a new one that has a different symbolic_min and symbolic_max
23+
24+
# obvs shouldn't be obtained from indexeds[0], but how should it be obtained?
25+
# USE e.lhs function -> the one that the BC is being applied to
26+
halo_size_left = indexeds[0].function._size_halo[d].left
27+
halo_size_right = indexeds[0].function._size_halo[d].right
28+
29+
grid = indexeds[0].function.grid
30+
31+
from devito.petsc.types.dimension import SubDimMax
32+
33+
# TODO: change name..
34+
35+
# global_rtkn = kwargs.get(d.rtkn.name, d.rtkn.value)
36+
# in theory this class shoulod just take in d directly
37+
subdim_max = SubDimMax(d.name + '_max', subdim=d, thickness=d.thickness)
38+
39+
# from IPython import embed; embed()
40+
41+
new_dim = CustomBoundSubDimension(
42+
name=d.name,
43+
parent=d.parent,
44+
thickness=d.thickness,
45+
local=d.local,
46+
custom_left=Max(d.ltkn, d.parent.symbolic_min - halo_size_left),
47+
custom_right=Min(subdim_max, d.parent.symbolic_max + halo_size_right)
48+
)
49+
mapper[d] = new_dim
50+
51+
# from IPython import embed; embed()
52+
53+
# build new expressions
54+
for e in expressions:
55+
if not isinstance(e, EssentialBC):
56+
continue
57+
58+
# build new expression
59+
new_e = e.subs(mapper)
60+
61+
additional_exprs.append(new_e)
62+
63+
return expressions + additional_exprs
64+
65+
66+

devito/petsc/types/dimension.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from devito.types.dimension import Thickness
2+
3+
4+
5+
class SubDimMax(Thickness):
6+
"""
7+
"""
8+
9+
def __init_finalize__(self, *args, **kwargs):
10+
self._subdim = kwargs.pop('subdim')
11+
self._dtype = self._subdim.dtype
12+
13+
super().__init_finalize__(*args, **kwargs)
14+
15+
@property
16+
def subdim(self):
17+
return self._subdim
18+
19+
def _arg_defaults(self, alias=None):
20+
key = alias or self
21+
# from IPython import embed; embed()
22+
return {key.name: self.data}
23+
24+
def _arg_values(self, grid=None, **kwargs):
25+
26+
# global rtkn
27+
grtkn = kwargs.get(self.name, self.value)
28+
29+
g_x_M = grid.distributor.decomposition[self.subdim.parent].glb_max
30+
31+
32+
return {self.name: g_x_M}

0 commit comments

Comments
 (0)