@@ -2269,6 +2269,9 @@ def __init__(self, coordinates):
2269
2269
# submesh
2270
2270
self .submesh_parent = None
2271
2271
2272
+ self ._spatial_index = None
2273
+ self ._saved_coordinate_dat_version = coordinates .dat .dat_version
2274
+
2272
2275
def _ufl_signature_data_ (self , * args , ** kwargs ):
2273
2276
return (type (self ), self .extruded , self .variable_layers ,
2274
2277
super ()._ufl_signature_data_ (* args , ** kwargs ))
@@ -2448,12 +2451,9 @@ def clear_spatial_index(self):
2448
2451
2449
2452
Use this if you move the mesh (for example by reassigning to
2450
2453
the coordinate field)."""
2451
- try :
2452
- del self .spatial_index
2453
- except AttributeError :
2454
- pass
2454
+ self ._spatial_index = None
2455
2455
2456
- @utils . cached_property
2456
+ @property
2457
2457
def spatial_index (self ):
2458
2458
"""Spatial index to quickly find which cell contains a given point.
2459
2459
@@ -2466,10 +2466,15 @@ def spatial_index(self):
2466
2466
can be found.
2467
2467
2468
2468
"""
2469
-
2470
2469
from firedrake import function , functionspace
2471
2470
from firedrake .parloops import par_loop , READ , MIN , MAX
2472
2471
2472
+ if (
2473
+ self ._spatial_index
2474
+ and self .coordinates .dat .dat_version == self ._saved_coordinate_dat_version
2475
+ ):
2476
+ return self ._spatial_index
2477
+
2473
2478
gdim = self .geometric_dimension ()
2474
2479
if gdim <= 1 :
2475
2480
info_red ("libspatialindex does not support 1-dimension, falling back on brute force." )
@@ -2531,7 +2536,9 @@ def spatial_index(self):
2531
2536
coords_max = coords_mid + (tolerance + 0.5 )* d
2532
2537
2533
2538
# Build spatial index
2534
- return spatialindex .from_regions (coords_min , coords_max )
2539
+ self ._spatial_index = spatialindex .from_regions (coords_min , coords_max )
2540
+ self ._saved_coordinate_dat_version = self .coordinates .dat .dat_version
2541
+ return self ._spatial_index
2535
2542
2536
2543
@PETSc .Log .EventDecorator ()
2537
2544
def locate_cell (self , x , tolerance = None , cell_ignore = None ):
0 commit comments