Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache split cells #128

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions FIAT/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ class AlfeldSplit(PowellSabinSplit):
"""Splits a simplicial complex by connecting cell vertices to their
barycenter.
"""
def __new__(cls, ref_el):
try:
return ref_el._split_cache[cls]
except KeyError:
self = super().__new__(cls)
return ref_el._split_cache.setdefault(cls, self)

def __init__(self, ref_el):
sd = ref_el.get_spatial_dimension()
super().__init__(ref_el, dimension=sd)
Expand All @@ -313,6 +320,13 @@ class WorseyFarinSplit(PowellSabinSplit):
"""Splits a simplicial complex by connecting cell and facet vertices to their
barycenter. This reduces to Powell-Sabin on the triangle, and Alfeld on the interval.
"""
def __new__(cls, ref_el):
try:
return ref_el._split_cache[cls]
except KeyError:
self = super().__new__(cls)
return ref_el._split_cache.setdefault(cls, self)

def __init__(self, ref_el):
sd = ref_el.get_spatial_dimension()
super().__init__(ref_el, dimension=sd-1)
Expand Down
3 changes: 3 additions & 0 deletions FIAT/reference_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ def __init__(self, shape, vertices, topology):
d01_entities = tuple(e for d, e in neighbors if d == dim1)
self.connectivity[(dim0, dim1)].append(d01_entities)

# Dictionary with derived cells
self._split_cache = {}

def _key(self):
"""Hashable object key data (excluding type)."""
# Default: only type matters
Expand Down
9 changes: 9 additions & 0 deletions test/FIAT/unit/test_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def cell(request):
return ufc_simplex(dim)


def test_split_cache(cell):
A = AlfeldSplit(cell)
B = AlfeldSplit(cell)
assert B is A
fe = Lagrange(cell, 1, variant="alfeld")
C = fe.ref_complex
assert C is A


@pytest.mark.parametrize("split", (AlfeldSplit, IsoSplit))
def test_split_entity_transform(split, cell):
split_cell = split(cell)
Expand Down
Loading