Skip to content

2D Tolerance Search and N-Dimension Uniform Grid#11

Closed
matthew-mccall wants to merge 17 commits intojacobmerson:developfrom
matthew-mccall:2d-tolerance-search
Closed

2D Tolerance Search and N-Dimension Uniform Grid#11
matthew-mccall wants to merge 17 commits intojacobmerson:developfrom
matthew-mccall:2d-tolerance-search

Conversation

@matthew-mccall
Copy link

This pull request introduces significant generalization and refactoring of the point localization and search infrastructure, preparing the codebase for both 2D and 3D mesh support. The changes include replacing hardcoded 2D structures with dimension-agnostic templates, introducing new search classes and functors for 3D, and improving the robustness and clarity of the point search logic.

Generalization and Refactoring for Dimension-Agnostic Support:

  • Introduced template functions and classes such as simplex_bbox, within_bbox, bbox_verts_within_simplex, and simplex_intersects_bbox to generalize bounding box and intersection logic for arbitrary dimensions, replacing 2D-specific implementations. [1] [2] [3] [4]
  • Added GridTriIntersectionFunctor3D and corresponding construct_intersection_map_3d to support 3D mesh intersection, alongside renaming and refactoring the 2D functor and intersection map construction for clarity.

Search Infrastructure Modernization:

  • Refactored GridPointSearch to GridPointSearch2D and replaced std::optional with std::unique_ptr for the search_ member in OmegaHField, making the design ready for alternative search strategies and consistent with modern C++ practices. [1] [2] [3]

Point Search Logic and API Improvements:

  • Enhanced the point search operator to robustly distinguish between vertex, edge, and face hits, using a new tolerance structure (PointSearchTolerances) and improving the logic for nearest element detection and classification. [1] [2] [3]
  • Updated result structures and usages to reflect the new naming and dimensionality (e.g., element_id instead of tri_id, GridPointSearch2D::Result), and improved error checking and reporting. [1] [2] [3]

These changes collectively make the codebase more extensible, robust, and ready for future 3D mesh support.

Updated `GridPointSearch` to use a templated design (`GridPointSearch<dim>`) and introduced `GridPointSearch2D` as a specific case for 2D point localization. This change ensures clearer extensibility for other dimensions and improves code maintainability by centralizing shared logic in a new base class (`PointLocalizationSearch`). Adjusted test cases, headers, and related implementations accordingly.
Replaced `std::optional` with `std::unique_ptr` for `search_` to better handle polymorphism and align with future extensions. Updated type aliasing and constructors accordingly to enhance code clarity and maintainability.
Introduced support for 3D point localization and grid intersection with a new `GridTriIntersectionFunctor3D`. Refactored 2D implementations for consistency, generalizing methods to handle dimensions dynamically. Added templates and utilities to support both 2D and 3D use cases effectively.
Replaced the local implementation of barycentric_from_global with Omega_h's standard implementation. Removed the custom function from both source and header files, and updated all calls to use Omega_h::barycentric_from_global<2, 2>. This change enhances code maintainability and aligns functionality with the Omega_h library.
Introduce bbox_verts_within_simplex to check if an AABBox's vertices are within a simplex using barycentric coordinates. Also, add a virtual destructor to the PointLocalizationSearch class for proper cleanup in derived classes.
Renamed `construct_intersection_map` to `construct_intersection_map_2d` and added `construct_intersection_map_3d` for 3D support. Introduced `GridPointSearch3D` class, extending point localization for 3D grids with associated functionality and data structures. Updated tests to reflect these changes.
Introduce a new REGION dimensionality to represent 3D regions in point search operations. Adjust loops and result assignment logic to incorporate this new dimension for improved handling of 3D cases.
Simplified indentation and adjusted line breaks in edge and vertex search loops for improved readability. Added constructor overloads to `GridPointSearch2D` for handling tolerances via a new `PointSearchTolerances` abstraction. Updated `PointLocalizationSearch` class with support for tolerances.
Previous algorithm checked edges then vertices. Now we check vertices, then edges.
Converted `PointSearchTolerances` to use `const` references for safer and more efficient handling. Added default tolerances initialization in 2D and 3D grid search constructors. Renamed `tri_id` to `element_id` in `Result` for improved clarity and consistency across dimensionalities.
…ces handling

Revised result assignment logic to incorporate detailed checks for vertex, edge, and face proximity, using new tolerances-based conditions. Updated tests to reflect changes in dimensionality and result handling for improved accuracy verification.
Removed unused `edge_found` variable for cleaner logic in result assignment. Updated test cases to add new points and verify dimensionality, element IDs, and coordinates for various scenarios, enhancing accuracy and coverage.
@jacobmerson jacobmerson requested a review from Copilot November 6, 2025 18:50
@jacobmerson
Copy link
Owner

/runtests

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the point search functionality to support both 2D and 3D meshes by introducing a templated base class hierarchy. The main changes include:

  • Introduces a PointLocalizationSearch base class templated on dimension
  • Renames GridPointSearch to GridPointSearch2D and adds GridPointSearch3D implementation
  • Updates the 2D point search algorithm to check for vertices and edges before faces
  • Adds tolerance-based matching for vertices and edges
  • Removes the UniformGrid default template parameter in favor of explicit specialization

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/pcms/uniform_grid.h Removes default template parameter and adds explicit 2D/3D type aliases
src/pcms/point_search.h Introduces base class hierarchy and separate 2D/3D implementations
src/pcms/point_search.cpp Implements 3D point search and refactors 2D algorithm with tolerance-based matching
test/test_point_search.cpp Updates tests to use new class names and test new behavior
src/pcms/interpolator/adj_search.hpp Updates references from GridPointSearch to GridPointSearch2D
src/pcms/adapter/omega_h/omega_h_field.h Changes from std::optional to std::unique_ptr for polymorphic storage
Comments suppressed due to low confidence (1)

src/pcms/point_search.cpp:656

  • In the 3D constructor GridPointSearch3D, querying Omega_h::FACE to Omega_h::EDGE and Omega_h::FACE to Omega_h::VERT adjacencies is incorrect. For 3D tetrahedral meshes, the top-level elements are Omega_h::REGION (tetrahedra), not Omega_h::FACE. These should be mesh.ask_down(Omega_h::REGION, Omega_h::EDGE) and mesh.ask_down(Omega_h::REGION, Omega_h::VERT).
  tris2edges_adj_ = mesh.ask_down(Omega_h::FACE, Omega_h::EDGE);
  tris2verts_adj_ = mesh.ask_down(Omega_h::FACE, Omega_h::VERT);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jacobmerson
Copy link
Owner

@matthew-mccall I started reviewing this, but I realized it's on my fork. Can you close this pull request and re-open it on SCOREC/pcms.

Thanks!

matthew-mccall and others added 3 commits November 10, 2025 00:16
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants