Skip to content

Commit

Permalink
Add caching to Cell
Browse files Browse the repository at this point in the history
  • Loading branch information
FranzBangar committed Jun 4, 2024
1 parent f3db386 commit c7813dc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/classy_blocks/modify/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ def update(self, junction: Junction) -> None:
for cell in linked_junction.cells:
cell.invalidate()

def clear_cache(self):
for cell in self.cells:
cell._quality = None

def add_clamp(self, clamp: ClampBase) -> None:
for junction in self.junctions:
if junction.vertex == clamp.vertex:
Expand All @@ -83,4 +79,9 @@ def clamps(self) -> List[ClampBase]:
@property
def quality(self) -> float:
"""Returns summed qualities of all junctions"""
# It is only called when optimizing linked clamps
# or at the end of an iteration.
for cell in self.cells:
cell.invalidate()

return sum([cell.quality for cell in self.cells])
3 changes: 3 additions & 0 deletions src/classy_blocks/modify/junction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def quality(self) -> float:
"""Returns average quality of all cells at this junction;
this serves as an indicator of which junction to optimize,
not a measurement of overall mesh quality"""
for cell in self.cells:
cell.invalidate()

return sum([cell.quality for cell in self.cells]) / len(self.cells)

@property
Expand Down
2 changes: 0 additions & 2 deletions src/classy_blocks/modify/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ def fquality(clamp, junction, params):
# return np.max(np.abs(sensitivities.flatten()))

def optimize_iteration(self, method: MinimizationMethodType) -> None:
self.grid.clear_cache()

clamps = sorted(self.grid.clamps, key=lambda c: self._get_sensitivity(c), reverse=True)

for clamp in clamps:
Expand Down

0 comments on commit c7813dc

Please sign in to comment.