Skip to content

Commit

Permalink
tests: Removed unecessary complexity from MPI + SubDomains test
Browse files Browse the repository at this point in the history
  • Loading branch information
EdCaunt committed Oct 26, 2023
1 parent 50b1afa commit df05fb3
Showing 1 changed file with 22 additions and 38 deletions.
60 changes: 22 additions & 38 deletions tests/test_subdomains.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,29 @@ def define(self, dimensions):

assert u0.data.all() == u1.data.all() == u2.data.all() == u3.data.all()

sd_specs = [None, ('middle', 1, 7), ('middle', 2, 3), ('middle', 7, 1),
('right', 3), ('right', 7), ('left', 3), ('left', 7)]
sd_specs = [('middle', 1, 7), ('middle', 2, 3), ('middle', 7, 1),
('middle', 5, 5), ('right', 3), ('right', 7), ('left', 3),
('left', 7)]

@pytest.mark.parametrize('x_spec', sd_specs)
@pytest.mark.parametrize('y_spec', sd_specs)
@pytest.mark.parallel(mode=[2, 4, 6])
def test_subdomains_mpi(self, x_spec, y_spec):
@pytest.mark.parametrize('spec', sd_specs)
@pytest.mark.parallel(mode=[2, 3])
def test_subdomains_mpi(self, spec):

class sd0(SubDomain):
name = 'd0'

def __init__(self, x_spec, y_spec):
def __init__(self, spec):
super().__init__()
self.x_spec = x_spec
self.y_spec = y_spec
self.spec = spec

def define(self, dimensions):
x, y = dimensions
return {x: self.x_spec if self.x_spec is not None else x,
y: self.y_spec if self.y_spec is not None else y}
s_d0 = sd0(x_spec, y_spec)
x = dimensions[0]
return {x: self.spec}
s_d0 = sd0(spec)

grid = Grid(shape=(11, 11), extent=(10., 10.), subdomains=(s_d0,))
grid = Grid(shape=(11,), extent=(10.,), subdomains=(s_d0,))
x = grid.dimensions[0]
xd0 = grid.subdomains['d0'].dimensions[0]
f = Function(name='f', grid=grid)

Operator(Eq(f, f+1, subdomain=grid.subdomains['d0']))()
Expand All @@ -194,30 +194,14 @@ def define(self, dimensions):
# to the operator output.
check = np.zeros(grid.shape)

m_map = {dim.root.symbolic_min: 0
for dim in grid.subdomains['d0'].dimensions}
M_map = {dim.root.symbolic_max: shape-1 for dim, shape
in zip(grid.subdomains['d0'].dimensions, grid.shape)}
mM_map = {**m_map, **M_map}
start = tuple(dim.symbolic_min.subs(mM_map)
for dim in grid.subdomains['d0'].dimensions)
stop = tuple(dim.symbolic_max.subs(mM_map)
for dim in grid.subdomains['d0'].dimensions)

slices = []
for dim, sta, sto in zip(grid.subdomains['d0'].dimensions, start, stop):
if dim.is_Sub:
t_map = {k: v for k, v in dim._thickness_map.items()
if v is not None}
slices.append(slice(int(sta.subs(t_map)),
int(sto.subs(t_map)+1)))
else:
slices.append(slice(int(sta), int(sto+1)))
slices = tuple(slices)

check[slices] = 1

assert np.all(check == f.data.__gather)
mM_map = {x.symbolic_min: 0, x.symbolic_max: grid.shape[0]-1}
t_map = {k: v for k, v in xd0._thickness_map.items() if v is not None}
start = int(xd0.symbolic_min.subs({**mM_map, **t_map}))
stop = int(xd0.symbolic_max.subs({**mM_map, **t_map})+1)

check[slice(start, stop)] = 1

assert np.all(check[grid.distributor.glb_slices[x]] == f.data)


class TestMultiSubDomain(object):
Expand Down

0 comments on commit df05fb3

Please sign in to comment.