Skip to content

Commit a1b1bcb

Browse files
committed
misc: Docs
1 parent 7f72d77 commit a1b1bcb

5 files changed

Lines changed: 34 additions & 66 deletions

File tree

devito/petsc/equations.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def lower_exprs_petsc(expressions, **kwargs):
1919

2020
def constrain_essential_bcs(expressions, **kwargs):
2121
"""
22+
Expand loop bounds for `ConstrainBC` expressions so that each MPI rank
23+
iterates over all locally visible constrained points, including those in
24+
the halo. PETSc requires each rank to report all constrained nodes in its
25+
local data region. The loops are not used for data access — only to
26+
identify which local indices are constrained.
2227
"""
2328
constrain_expressions = [e for e in expressions if isinstance(e, ConstrainBC)]
2429
if not constrain_expressions:

devito/petsc/iet/builder.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,6 @@ def _setup(self):
252252

253253
dmda_calls = self._create_dmda_calls(dmda)
254254

255-
mainctx = sobjs['userctx']
256-
257-
call_struct_callback = petsc_call(
258-
self.callback_builder.user_struct_efunc.name, [Byref(mainctx)]
259-
)
260-
261255
# TODO: maybe don't need to explictly set this
262256
mat_set_dm = petsc_call('MatSetDM', [sobjs['Jac'], dmda])
263257

@@ -331,7 +325,6 @@ def _setup(self):
331325
matvec_operation,
332326
formfunc_operation,
333327
snes_set_options,
334-
call_struct_callback,
335328
mat_set_dm,
336329
create_field_decomp,
337330
matop_create_submats_op,
@@ -420,7 +413,6 @@ class ConstrainedBCBuilder(ConstrainedBCMixin, BuilderBase):
420413
pass
421414

422415

423-
# TODO: Implement this class properly
424416
class CoupledConstrainedBCBuilder(ConstrainedBCMixin, CoupledBuilder):
425417
pass
426418

devito/petsc/iet/callbacks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ def _make_constrain_bc(self):
697697

698698
def _create_count_bc_body(self, body, pairs):
699699
"""
700-
Generic CountBCs body. `pairs` is a list of (numBCPtr, counter) tuples,
700+
Build the `CountBCs` body. `pairs` is a list of (numBCPtr, counter) tuples,
701701
one per field. All fields are handled in a single callback body.
702702
"""
703703
objs = self.objs
@@ -737,7 +737,7 @@ def _create_count_bc_body(self, body, pairs):
737737

738738
def _create_set_point_bc_body(self, body, constrain_bc_dict):
739739
"""
740-
Generic SetPointBCs body, handles single- and multi-field.
740+
Build the `SetPointBCs` body.
741741
"""
742742
targets = list(constrain_bc_dict.keys())
743743
nfields = len(targets)

devito/petsc/iet/passes.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,12 @@ def lower_petsc(iet, **kwargs):
7070
)
7171
grid = unique_grids.pop()
7272

73-
# Protect PETSc solve targets from being dropped by `_drop_if_unwritten`.
7473
# `lower_petsc` runs before `mpiize`, replacing `PetscMetaData` (an
7574
# `Expression` subclass whose `.write` reveals the target function) with
7675
# `Call` nodes to run the PETSc solver. Once that happens,
7776
# `_drop_if_unwritten` can no longer see the target as written and
7877
# incorrectly discards its `HaloSpot`. So we compose `dist-drop-unwritten`
79-
# with a guard that always returns False for PETSc targets.
78+
# with a guard that always returns False for `petsc_targets`.
8079
options = kwargs['options']
8180
petsc_targets = {n.write for n in data if n.write is not None}
8281
if petsc_targets:
@@ -164,9 +163,7 @@ def lower_petsc_symbols(iet, **kwargs):
164163
def linear_indices(iet, **kwargs):
165164
"""
166165
Convert multidimensional grid accesses in the callback `SetPointBCs` to flat
167-
linear indices. DMDASetPointBC expects BC points as 1D offsets (e.g. i*ny + j),
168-
so each u[x, y] access is linearised to its stride expression and written into
169-
bcPointsArr.
166+
linear indices. DMDASetPointBC expects BC points as 1D offsets (e.g. i*ny + j).
170167
"""
171168
if not iet.name.startswith("SetPointBCs"):
172169
return iet, {}

devito/petsc/types/dimension.py

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,73 @@
11
from devito.types.dimension import Thickness
22

33

4-
class SubDimMax(Thickness):
5-
"""
6-
Local index of a SubDimension's right global boundary, which may not correspond
7-
to a locally owned point. Not used for indexing into data.
8-
"""
4+
class _SubDimBound(Thickness):
95
def __init_finalize__(self, *args, **kwargs):
106
self._subdim = kwargs.pop('subdim')
117
self._dtype = self._subdim.dtype
12-
138
super().__init_finalize__(*args, **kwargs)
149

1510
@property
1611
def subdim(self):
1712
return self._subdim
1813

14+
15+
class _SpaceDimBound(Thickness):
16+
def __init_finalize__(self, *args, **kwargs):
17+
self._space_dim = kwargs.pop('space_dim')
18+
self._dtype = self._space_dim.dtype
19+
super().__init_finalize__(*args, **kwargs)
20+
21+
@property
22+
def space_dim(self):
23+
return self._space_dim
24+
25+
26+
class SubDimMax(_SubDimBound):
27+
"""
28+
Local index of a SubDimension's right global boundary, which may not correspond
29+
to a locally owned point. Not used for indexing into data.
30+
"""
1931
def _arg_values(self, grid=None, **kwargs):
2032
dist = grid.distributor
21-
# global rtkn
2233
grtkn = kwargs.get(self.subdim.rtkn.name, self.subdim.rtkn.value)
23-
# decomposition info
2434
decomp = dist.decomposition[self.subdim.parent]
25-
glb_max = decomp.glb_max
26-
val = decomp.index_glb_to_loc_unsafe(glb_max - grtkn)
35+
val = decomp.index_glb_to_loc_unsafe(decomp.glb_max - grtkn)
2736
return {self.name: int(val)}
2837

2938

30-
class SubDimMin(Thickness):
39+
class SubDimMin(_SubDimBound):
3140
"""
3241
Local index of a SubDimension's left global boundary, which may not correspond
3342
to a locally owned point. Not used for indexing into data.
3443
"""
35-
def __init_finalize__(self, *args, **kwargs):
36-
self._subdim = kwargs.pop('subdim')
37-
self._dtype = self._subdim.dtype
38-
39-
super().__init_finalize__(*args, **kwargs)
40-
41-
@property
42-
def subdim(self):
43-
return self._subdim
44-
4544
def _arg_values(self, grid=None, **kwargs):
4645
dist = grid.distributor
47-
# global ltkn
4846
gltkn = kwargs.get(self.subdim.ltkn.name, self.subdim.ltkn.value)
49-
# decomposition info
5047
decomp = dist.decomposition[self.subdim.parent]
51-
glb_min = decomp.glb_min
52-
val = decomp.index_glb_to_loc_unsafe(glb_min + gltkn)
48+
val = decomp.index_glb_to_loc_unsafe(decomp.glb_min + gltkn)
5349
return {self.name: int(val)}
5450

5551

56-
class SpaceDimMax(Thickness):
52+
class SpaceDimMax(_SpaceDimBound):
5753
"""
5854
Local index of a SpaceDimension's right global boundary, which may not correspond
5955
to a locally owned point. Not used for indexing into data.
6056
"""
61-
def __init_finalize__(self, *args, **kwargs):
62-
self._space_dim = kwargs.pop('space_dim')
63-
self._dtype = self._space_dim.dtype
64-
65-
super().__init_finalize__(*args, **kwargs)
66-
67-
@property
68-
def space_dim(self):
69-
return self._space_dim
70-
7157
def _arg_values(self, grid=None, **kwargs):
7258
dist = grid.distributor
7359
decomp = dist.decomposition[self.space_dim]
74-
glb_max = decomp.glb_max
75-
val = decomp.index_glb_to_loc_unsafe(glb_max)
60+
val = decomp.index_glb_to_loc_unsafe(decomp.glb_max)
7661
return {self.name: int(val)}
7762

7863

79-
class SpaceDimMin(Thickness):
64+
class SpaceDimMin(_SpaceDimBound):
8065
"""
8166
Local index of a SpaceDimension's left global boundary, which may not correspond
8267
to a locally owned point. Not used for indexing into data.
8368
"""
84-
def __init_finalize__(self, *args, **kwargs):
85-
self._space_dim = kwargs.pop('space_dim')
86-
self._dtype = self._space_dim.dtype
87-
88-
super().__init_finalize__(*args, **kwargs)
89-
90-
@property
91-
def space_dim(self):
92-
return self._space_dim
93-
9469
def _arg_values(self, grid=None, **kwargs):
9570
dist = grid.distributor
9671
decomp = dist.decomposition[self.space_dim]
97-
glb_min = decomp.glb_min
98-
val = decomp.index_glb_to_loc_unsafe(glb_min)
72+
val = decomp.index_glb_to_loc_unsafe(decomp.glb_min)
9973
return {self.name: int(val)}

0 commit comments

Comments
 (0)