Skip to content

Commit 42535d0

Browse files
committed
bit of clean up
1 parent 7e83811 commit 42535d0

3 files changed

Lines changed: 19 additions & 39 deletions

File tree

devito/petsc/equations.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ def lower_exprs_petsc(expressions, **kwargs):
1818

1919
def constrain_essential_bcs(expressions, **kwargs):
2020
"""
21-
Expand ConstrainBC expressions to include halo regions by creating new
22-
CustomDimensions for all relevant subdimensions and space dimensions,
23-
then applying the mapper to all ConstrainBCs.
21+
NOTE:
2422
"""
25-
2623
sregistry = kwargs['sregistry']
2724
new_exprs = []
2825

@@ -40,7 +37,7 @@ def constrain_essential_bcs(expressions, **kwargs):
4037
space_dims = [d for d in all_dims if isinstance(d, SpaceDimension)]
4138

4239
mapper = {}
43-
40+
# from IPython import embed; embed()
4441
for d in subdims:
4542
halo = halo_size[d]
4643

@@ -52,7 +49,7 @@ def constrain_essential_bcs(expressions, **kwargs):
5249
)
5350

5451
mapper[d] = CustomDimension(
55-
name=sregistry.make_name(prefix=f"{d.name}_new"),
52+
name=d.name,
5653
symbolic_min=Max(subdim_min, d.parent.symbolic_min - halo.left),
5754
symbolic_max=Min(subdim_max, d.parent.symbolic_max + halo.right),
5855
)
@@ -73,6 +70,7 @@ def constrain_essential_bcs(expressions, **kwargs):
7370
)
7471

7572
# Apply mapper to all expressions
73+
# from IPython import embed; embed()
7674
for e in expressions:
7775
if not isinstance(e, ConstrainBC):
7876
new_exprs.append(e)
@@ -83,7 +81,9 @@ def constrain_essential_bcs(expressions, **kwargs):
8381
new_exprs.append(e)
8482
continue
8583

86-
new_e = uxreplace(e, mapper)
84+
# new_e = uxreplace(e, mapper)
85+
new_e = e.subs(mapper)
86+
8787

8888
if e.implicit_dims:
8989
new_e = new_e._rebuild(

examples/petsc/Poisson/ed_bueler_2d.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def exact(x, y):
103103
bcs += [EssentialBC(u, bc, subdomain=sub4)]
104104

105105

106-
107106
exprs = [eqn] + bcs
108107
petsc = petscsolve(
109108
exprs, target=u,
@@ -112,8 +111,6 @@ def exact(x, y):
112111
constrain_bcs=True
113112
)
114113

115-
116-
117114
rank = grid.distributor.myrank
118115
# from IPython import embed; embed()
119116

tests/test_petsc.py

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,25 +2213,24 @@ def test_petsc_pi(self):
22132213
class TestPetscSection:
22142214
"""
22152215
These tests validate the use of `PetscSection` (from PETSc) to constrain essential
2216-
boundary nodes by removing them from the linear solver, rather than leaving them in
2216+
boundary nodes by removing them from the linear solver, rather than keeping them in
22172217
the system as trivial equations.
22182218
22192219
Users specify essential boundary conditions via the `EssentialBC` equation, with a specifed `SubDomain`.
22202220
When `constrain_bcs=True` is passed to `petscsolve`, the Devito compiler generates code that
2221-
removes these degrees of freedom from the linear system. A requirement for this in PETSc is
2222-
that each MPI rank identifies ALL constrained nodes that lie within its local data region, including
2221+
removes these degrees of freedom from the linear system. A PETSc requirement is
2222+
that each MPI rank identifies ALL constrained nodes within its local data region, including
22232223
non-owned (halo) nodes.
22242224
22252225
To achieve this, the compiler creates new `EssentialBC`-like equations with modified (sub)dimensions
2226-
(to extend the loop bounds) that are utilised in two callback functions to constrain the nodes.
2227-
No non-owned (haloed) data is indexed into - the loops are purely used to specify the constrained "local" indices
2228-
on each rank.
2226+
(to extend the loop bounds), which are used in two callback functions to constrain the nodes.
2227+
No non-owned (halo) data is indexed into - the loops are only used to specify the constrained "local"
2228+
indices on each rank.
22292229
22302230
Tests in this class use the following notation:
22312231
- `x` : a grid point
22322232
- `[]` : the `SubDomain` specified by the `EssentialBC` (the region being constrained)
22332233
- `|` : an MPI rank boundary
2234-
22352234
"""
22362235
# first test that the loop generated is correct symbolically..
22372236

@@ -2272,10 +2271,7 @@ def _get_loop_bounds(self, shape, so, subdomain):
22722271
@pytest.mark.parallel(mode=[1, 2, 4])
22732272
def test_1_constrain_indices_1d(self, mode):
22742273
# halo size 2
2275-
# 12 grid points in 1D with a subdomain spanning the region contained inside the brackets [], x represents a grid point, | represents the decomposition
2276-
# {rank: (min, max)} represents the loop bounds to constrain indices (locally) corresponding to the subdomain on this particular rank
2277-
# IMPROVE WORDING
2278-
# In petsc, when constraining indices, you constrain local (haloed) indices - INCLUDING NON OWNED INDICES
2274+
# 12 grid points
22792275

22802276
# 1 rank:
22812277
# 0
@@ -2295,8 +2291,7 @@ def test_1_constrain_indices_1d(self, mode):
22952291
# 0 1 2 3
22962292
# [x x x|x x x|x] x x|x x x
22972293

2298-
# Expected: {0: (0, 4), 1: (-2, 3), 2: (-2, 0), 3: (null loop - locally doesn't cover any of the subdomain)}
2299-
# rank 3 comes out as (-2,-3) -> null loop
2294+
# Expected: {0: (0, 4), 1: (-2, 3), 2: (-2, 0), 3: (-2, -3)}
23002295

23012296
class Middle(SubDomain):
23022297
name = 'submiddle'
@@ -2519,10 +2514,7 @@ def test_4_constrain_indices_1d(self, mode):
25192514

25202515
# subdomain on the right side of the grid not left
25212516
# halo size 2
2522-
# 24 grid points in 1D with a subdomain spanning the region contained inside the brackets [], x represents a grid point, | represents the decomposition
2523-
# {rank: (min, max)} represents the loop bounds to constrain indices (locally) corresponding to the subdomain on this particular rank
2524-
# IMPROVE WORDING
2525-
# In petsc, when constraining indices, you constrain local (haloed) indices - INCLUDING NON OWNED INDICES
2517+
# 24 grid points in 1D
25262518

25272519
# 1 rank:
25282520
# 0
@@ -2623,10 +2615,7 @@ def test_5_constrain_indices_1d(self, mode):
26232615
# subdomain on the right side of the grid not left
26242616
# halo size 4
26252617
# same as test 4 but halo size 4 (so don't test 8 ranks)
2626-
# 24 grid points in 1D with a subdomain spanning the region contained inside the brackets [], x represents a grid point, | represents the decomposition
2627-
# {rank: (min, max)} represents the loop bounds to constrain indices (locally) corresponding to the subdomain on this particular rank
2628-
# IMPROVE WORDING
2629-
# In petsc, when constraining indices, you constrain local (haloed) indices - INCLUDING NON OWNED INDICES
2618+
# 24 grid points in 1D
26302619

26312620
# 1 rank:
26322621
# 0
@@ -2709,10 +2698,7 @@ def test_6_constrain_indices_1d(self, mode):
27092698

27102699
# subdomain in the MIDDLE
27112700
# halo size 2
2712-
# 24 grid points in 1D with a subdomain spanning the region contained inside the brackets [], x represents a grid point, | represents the decomposition
2713-
# {rank: (min, max)} represents the loop bounds to constrain indices (locally) corresponding to the subdomain on this particular rank
2714-
# IMPROVE WORDING
2715-
# In petsc, when constraining indices, you constrain local (haloed) indices - INCLUDING NON OWNED INDICES
2701+
# 24 grid points in 1D
27162702

27172703
# 1 rank:
27182704
# 0
@@ -2811,10 +2797,7 @@ def test_7_constrain_indices_1d(self, mode):
28112797

28122798
# subdomain in the MIDDLE
28132799
# halo size 4
2814-
# 24 grid points in 1D with a subdomain spanning the region contained inside the brackets [], x represents a grid point, | represents the decomposition
2815-
# {rank: (min, max)} represents the loop bounds to constrain indices (locally) corresponding to the subdomain on this particular rank
2816-
# IMPROVE WORDING
2817-
# In petsc, when constraining indices, you constrain local (haloed) indices - INCLUDING NON OWNED INDICES
2800+
# 24 grid points in 1D
28182801

28192802
# 1 rank:
28202803
# 0

0 commit comments

Comments
 (0)