-
Notifications
You must be signed in to change notification settings - Fork 190
Cache mesh bounding boxes correctly #5180
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
base: main
Are you sure you want to change the base?
Changes from all commits
5f081d8
74841c6
78e732c
12e44ad
29ccc99
6aad438
bd63300
534b1fd
b0d466c
54fab47
aa43b3b
0f9e94f
4b3f3a3
7441d2d
d3bc21c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ | |
| import firedrake.extrusion_utils as eutils | ||
| import firedrake.cython.rtree as rtree | ||
| import firedrake.utils as utils | ||
| from firedrake.utils import as_cstr, IntType, RealType | ||
| from firedrake.utils import as_cstr, IntType, RealType, cached_property_until | ||
| from firedrake.logging import logger | ||
| from firedrake.parameters import parameters | ||
| from firedrake.petsc import PETSc, DEFAULT_PARTITIONER | ||
|
|
@@ -2380,10 +2380,6 @@ def __init__(self, coordinates): | |
| # submesh | ||
| self.submesh_parent = None | ||
|
|
||
| self._bounding_box_coords = None | ||
| self._rtree = None | ||
| self._saved_coordinate_dat_version = coordinates.dat.dat_version | ||
|
|
||
| # Cache mesh object on the coordinateless coordinates function | ||
| coordinates._as_mesh_geometry = weakref.ref(self) | ||
|
|
||
|
|
@@ -2477,9 +2473,11 @@ def clear_rtree(self): | |
|
|
||
| Use this if you move the mesh (for example by reassigning to | ||
| the coordinate field).""" | ||
| self._rtree = None | ||
| # `cached_property_until` stores the cached rtree in self._rtree_cache | ||
| # setting it to None will force the rtree to be rebuilt on next access. | ||
| self._rtree_cache = None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this for?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without context this line makes no sense. I would prefer to hide it as much as possible. Why not: def clear_rtree(self):
# comment about why this does the right thing
self._rtree_cache = NoneWe should definitely look to deprecate |
||
|
|
||
| @cached_property | ||
| @cached_property_until(lambda self: self.coordinates.dat.dat_version) | ||
| @PETSc.Log.EventDecorator() | ||
| def bounding_box_coords(self) -> Tuple[np.ndarray, np.ndarray]: | ||
| """Calculates bounding boxes for the mesh rtree. | ||
|
|
@@ -2558,10 +2556,9 @@ def bounding_box_coords(self) -> Tuple[np.ndarray, np.ndarray]: | |
| column_list = V.cell_node_list.reshape(-1) | ||
| coords_min = mesh._order_data_by_cell_index(column_list, coords_min.dat.data_ro_with_halos) | ||
| coords_max = mesh._order_data_by_cell_index(column_list, coords_max.dat.data_ro_with_halos) | ||
|
|
||
| return coords_min, coords_max | ||
|
|
||
| @property | ||
| @cached_property_until(lambda self: (self.coordinates.dat.dat_version, self.tolerance)) | ||
| @PETSc.Log.EventDecorator() | ||
| def rtree(self): | ||
| """Builds an rtree from bounding box coordinates, expanding | ||
|
|
@@ -2579,12 +2576,6 @@ def rtree(self): | |
| can be found. | ||
|
|
||
| """ | ||
| if self.coordinates.dat.dat_version != self._saved_coordinate_dat_version: | ||
| if "bounding_box_coords" in self.__dict__: | ||
| del self.bounding_box_coords | ||
| else: | ||
| if self._rtree: | ||
| return self._rtree | ||
| # Change min and max to refer to an n-hypercube, where n is the | ||
| # geometric dimension of the mesh, centred on the midpoint of the | ||
| # bounding box. Its side length is the L1 diameter of the bounding box. | ||
|
|
@@ -2609,7 +2600,6 @@ def rtree(self): | |
|
|
||
| with PETSc.Log.Event("rtree_build"): | ||
| self._rtree = rtree.build_from_aabb(coords_min, coords_max) | ||
| self._saved_coordinate_dat_version = self.coordinates.dat.dat_version | ||
| return self._rtree | ||
|
|
||
| @PETSc.Log.EventDecorator() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.