Commit 914df20
feat(geospatial): add 3D spatial indexing and vectorize z-coordinate search
Add comprehensive 3D support to GeospatialIndex with automatic detection
and two-pronged approach for handling grids with varying layer geometry.
**3D Spatial Indexing (grid_varies_by_layer=True):**
- Uses (x,y,z) KD-tree for grids where geometry varies by layer
- Implements 3D bounding box containment tests
- Indexes all nnodes with full 3D coordinates
- Performance: up to 414x speedup for 15000 cells with 10000 points
**2D with Z-Search (grid_varies_by_layer=False):**
- Uses (x,y) KD-tree with vectorized z-coordinate layer search
- Suitable for VertexGrid and UnstructuredGrid with consistent 2D geometry
- Performance: up to 348x speedup for 5000 cells with 10000 points
**Key Changes:**
- Add is_3d flag auto-detected from grid.grid_varies_by_layer
- Implement _build_3d_index() for 3D KD-tree construction
- Implement _precompute_3d_bounds() for 3D bounding box tests
- Implement _point_in_cell_3d() for 3D containment
- Vectorize _find_layer_for_z() using numpy masks (no loops)
- Update query_points() to accept z parameter and route to 2D/3D logic
- Simplify UnstructuredGrid.intersect() and VertexGrid.intersect()
- Fix list vs array handling with np.atleast_1d()
**Performance Benchmarks:**
Structured grids: 0.10x-0.58x (slower, should use searchsorted)
Vertex grids: 1.2x-348x speedup (best for 1000+ cells)
Unstructured 2D: 1.1x-352x speedup (best for 1000+ cells)
Unstructured 3D: 1.1x-414x speedup (best for 2000+ cells)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent b89708a commit 914df20
File tree
3 files changed
+274
-102
lines changed- flopy
- discretization
- utils
3 files changed
+274
-102
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
775 | 775 | | |
776 | 776 | | |
777 | 777 | | |
778 | | - | |
779 | | - | |
780 | | - | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
781 | 782 | | |
782 | | - | |
783 | | - | |
784 | | - | |
| 783 | + | |
785 | 784 | | |
786 | 785 | | |
787 | | - | |
| 786 | + | |
788 | 787 | | |
789 | 788 | | |
790 | 789 | | |
791 | 790 | | |
792 | | - | |
793 | | - | |
794 | | - | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
806 | | - | |
807 | | - | |
808 | | - | |
809 | | - | |
810 | | - | |
811 | | - | |
812 | | - | |
813 | | - | |
814 | | - | |
815 | | - | |
816 | | - | |
817 | | - | |
818 | | - | |
819 | | - | |
820 | | - | |
821 | | - | |
822 | | - | |
823 | | - | |
824 | | - | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
825 | 800 | | |
826 | 801 | | |
827 | 802 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
408 | | - | |
409 | | - | |
410 | | - | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
411 | 419 | | |
412 | 420 | | |
413 | | - | |
414 | 421 | | |
415 | 422 | | |
416 | 423 | | |
417 | 424 | | |
418 | 425 | | |
419 | 426 | | |
420 | 427 | | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
445 | 438 | | |
446 | 439 | | |
447 | 440 | | |
| |||
0 commit comments