Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
change for mixed mesh implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ksagiyam committed Apr 2, 2024
1 parent a2c0d27 commit 304a38e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
16 changes: 11 additions & 5 deletions pyop2/types/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ def __init__(self, maps):
if self._initialized:
return
self._maps = maps
if not all(m is None or m.iterset == self.iterset for m in self._maps):
raise ex.MapTypeError("All maps in a MixedMap need to share the same iterset")
# TODO: Think about different communicators on maps (c.f. MixedSet)
# TODO: What if all maps are None?
comms = tuple(m.comm for m in self._maps if m is not None)
Expand Down Expand Up @@ -344,7 +342,11 @@ def split(self):
@utils.cached_property
def iterset(self):
""":class:`MixedSet` mapped from."""
return functools.reduce(lambda a, b: a or b, map(lambda s: s if s is None else s.iterset, self._maps))
s, = set(m.iterset for m in self._maps)
if len(s) == 1:
return functools.reduce(lambda a, b: a or b, map(lambda s: s if s is None else s.iterset, self._maps))
else:
raise RuntimeError("Found multiple itersets.")

@utils.cached_property
def toset(self):
Expand All @@ -356,7 +358,11 @@ def toset(self):
def arity(self):
"""Arity of the mapping: total number of toset elements mapped to per
iterset element."""
return sum(m.arity for m in self._maps)
s, = set(m.iterset for m in self._maps)
if len(s) == 1:
return sum(m.arity for m in self._maps)
else:
raise RuntimeError("Found multiple itersets.")

@utils.cached_property
def arities(self):
Expand Down Expand Up @@ -402,7 +408,7 @@ def offset(self):
@utils.cached_property
def offset_quotient(self):
"""Offsets quotient."""
raise NotImplementedError("offset_quotient not implemented for MixedMap")
return tuple(0 if m is None else m.offset_quotient for m in self._maps)

def __iter__(self):
r"""Yield all :class:`Map`\s when iterated over."""
Expand Down
4 changes: 4 additions & 0 deletions pyop2/types/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def __init__(self, size, name=None, halo=None, comm=None):
# A cache of objects built on top of this set
self._cache = {}

def indices(self):
"""Returns iterator."""
return range(self.total_size)

@utils.cached_property
def core_size(self):
"""Core set size. Owned elements not touching halo elements."""
Expand Down
5 changes: 0 additions & 5 deletions test/unit/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,11 +1446,6 @@ def test_mixed_map_split(self, maps):
assert mmap.split[i] == m
assert mmap.split[:-1] == tuple(mmap)[:-1]

def test_mixed_map_nonunique_itset(self, m_iterset_toset, m_set_toset):
"Map toset should be Set."
with pytest.raises(exceptions.MapTypeError):
op2.MixedMap((m_iterset_toset, m_set_toset))

def test_mixed_map_iterset(self, mmap):
"MixedMap iterset should return the common iterset of all Maps."
for m in mmap:
Expand Down

0 comments on commit 304a38e

Please sign in to comment.