-
Notifications
You must be signed in to change notification settings - Fork 16
Mesh intersection routines #209
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: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 pull request adds conservative field projection capabilities via mesh intersection to the PCMS interpolator library. The implementation enables Galerkin-based projection of scalar fields between non-conforming 2D triangular meshes using supermesh techniques.
Key changes include:
- Implementation of mesh intersection algorithms with adjacency-based breadth-first search
- Load vector and mass matrix integrators for conservative field transfer
- PETSc-based linear system solver for projection
- New optional dependencies: MeshFields and PETSc
- Enhanced RBF kernel documentation and new kernel types (multiquadric, inverse multiquadric, thin plate spline, cubic)
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| test/test_load_vector.cpp | Test suite for load vector computation and mesh intersection |
| test/CMakeLists.txt | Build configuration for new mesh intersection tests with conditional dependencies |
| src/pcms/interpolator/mesh_intersection/*.hpp | Core mesh intersection, conservative projection, and integration routines |
| src/pcms/interpolator/mls_interpolation.hpp | Expanded RBF kernel documentation and new kernel definitions |
| src/pcms/interpolator/mls_interpolation.cpp | Implementation of new RBF kernels (multiquadric, inverse multiquadric, thin plate spline, cubic) |
| src/pcms/interpolator/mls_interpolation_impl.hpp | Code formatting updates and scratch size fix |
| src/pcms/interpolator/pcms_interpolator_view_utils.hpp | Documentation for square root helper function |
| src/pcms/interpolator/adj_search.hpp | Fix for handling points outside mesh boundaries |
| CMakeLists.txt | Build system support for optional MeshFields and PETSc dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 0.0, 1.0 // v3 | ||
| }); | ||
|
|
||
| // Target Mesh with two traingles |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'traingles' to 'triangles'.
| Omega_h::build_from_elems_and_coords(&target_mesh, OMEGA_H_SIMPLEX, 2, | ||
| ev2v_source, coords); | ||
|
|
||
| // Source Mesh with two traingles |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'traingles' to 'triangles'.
| // Source Mesh with two traingles | |
| // Source Mesh with two triangles |
| points_h(0, 0) = 0.0; | ||
| points_h(0, 1) = 0.0; | ||
| points_h(1, 0) = 1.0; | ||
| points_h(0, 1) = 0.0; |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Index mismatch: line 59 sets points_h(0, 1) but should set points_h(1, 1) to define the second point's y-coordinate. This overwrites the first point's y-coordinate and leaves the second point's y-coordinate uninitialized.
| points_h(0, 1) = 0.0; | |
| points_h(1, 1) = 0.0; |
| "source elements") | ||
| { | ||
| // the source elements are triangle1 (0,0), (1,0) & (1,1) and triangle2 | ||
| // (0,0), (1,1) & (0,1) the target elements are traingle1 (0,0), (1,0) & |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'traingle1' to 'triangle1'.
| // (0,0), (1,1) & (0,1) the target elements are traingle1 (0,0), (1,0) & | |
| // (0,0), (1,1) & (0,1) the target elements are triangle1 (0,0), (1,0) & |
| endif() | ||
|
|
||
| if (PCMS_ENABLE_MESHFIELDS) | ||
| list(APPEND PCMS_UNIT_TEST_SOURCES test_load_vector.cpp) |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation: use spaces instead of tabs for consistency with the surrounding code style. Lines 358, 364, 368-369 use tabs while the rest of the file uses spaces.
| */ | ||
|
|
||
| #ifndef PCMS_INTERPOLATOR_GALERKIN_PROJECTION_SOLVER_HPP | ||
| #ifndef PCMS_INTERPOLATOR_GALERKIN_PROJECTION_SOLVER_HPP |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate header guard declaration. The second #ifndef on line 19 should be #define PCMS_INTERPOLATOR_GALERKIN_PROJECTION_SOLVER_HPP.
| #ifndef PCMS_INTERPOLATOR_GALERKIN_PROJECTION_SOLVER_HPP | |
| #define PCMS_INTERPOLATOR_GALERKIN_PROJECTION_SOLVER_HPP |
| #include <petscvec_kokkos.hpp> | ||
| #include <sstream> //ostringstream | ||
|
|
||
| #include <pcms/interpolator/mesh_interscetion/load_vector_integrator.hpp> |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling in include path: 'mesh_interscetion' should be 'mesh_intersection'.
| #include <pcms/interpolator/mesh_interscetion/load_vector_integrator.hpp> | |
| #include <pcms/interpolator/mesh_intersection/load_vector_integrator.hpp> |
| // calculates the interpolated values | ||
| Kokkos::parallel_for( | ||
| "MLS coefficients", tp.set_scratch_size(1, Kokkos::PerTeam(scratch_size)), | ||
| "MLS coefficients", tp.set_scratch_size(1, Kokkos::PerTeam(shared_size)), |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed from scratch_size to shared_size without verification that shared_size is the correct value. Line 474 asserts scratch_size > shared_size, so using shared_size may lead to insufficient scratch memory allocation. This should use scratch_size or the assertion logic should be updated.
| "MLS coefficients", tp.set_scratch_size(1, Kokkos::PerTeam(shared_size)), | |
| "MLS coefficients", tp.set_scratch_size(1, Kokkos::PerTeam(scratch_size)), |
| find_library(PETSC_LIBRARY petsc HINTS ${PETSC_LIB_DIR}) | ||
|
|
||
| if (NOT PETSC_LIBRARY) | ||
| message(FATAL_ERROR "Couldnot find libpetsc in ${PETSC_LIB_DIR}") |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spacing: 'Couldnot' should be 'Could not'.
| message(FATAL_ERROR "Couldnot find libpetsc in ${PETSC_LIB_DIR}") | |
| message(FATAL_ERROR "Could not find libpetsc in ${PETSC_LIB_DIR}") |
| phi = 0.0; | ||
| } else { | ||
| phi = | ||
| a * a * ratio * ratio * Kokkos::log(a * ratio); // a shouldnot be zero |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spacing in comment: 'shouldnot' should be 'should not'.
| a * a * ratio * ratio * Kokkos::log(a * ratio); // a shouldnot be zero | |
| a * a * ratio * ratio * Kokkos::log(a * ratio); // a should not be zero |
|
@abhiyanpaudel can you share the petsc configuration you are using so we can add that to CI? |
./configure \
PETSC_ARCH=linux-gnu-gpu-kokkos \
--with-kokkos-dir="$BUILD_DIR/${DEVICE_ARCH}/kokkos/install/" \
--with-kokkos-kernels-dir="$BUILD_DIR/${DEVICE_ARCH}/kokkoskernels/install/" \
--with-cuda=1 \
--with-openblas-dir="${OPENBLAS_RHEL9_ROOT}" |
| * meshes. | ||
| * | ||
| * @created by Abhiyan Paudel | ||
| * @date August 2025 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would take out @created and @date from the header. That info is captured in the git history.
Sichao25
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me. Added a few minor questions and suggestions for consideration. A test for the main behavior (e.g., Galerkin projection) would be helpful.
| #include <pcms/interpolator/mesh_interscetion/load_vector_integrator.hpp> | ||
| #include <MeshField.hpp> | ||
|
|
||
| #include <petscmat.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong, but from the CMakeLists it looks like the mesh_intersection source and headers will always be compiled, but the petsc library can be disabled. I'm wondering do these headers still exist if we disable the petsc library?
|
|
||
| auto elmMassMatrix = buildMassMatrix(mesh, coordFe); | ||
|
|
||
| auto host_elmMassMatrix = Kokkos::create_mirror_view(elmMassMatrix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this view now or in the future?
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | ||
|
|
||
| KSP ksp; | ||
| ierr = KSPCreate(PETSC_COMM_SELF, &ksp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why we need PETSC_COMM_SELF here. Based on the documentation, PETSC_COMM_WORLD and MPI_COMM_WORLD are identical by default unless you want a subset of MPI_COMM_WORLD.
| target_link_libraries(pcms_mesh_intersection PUBLIC ${PCMS_PETSC_LIBRARIES}) | ||
| endif() | ||
|
|
||
| target_compile_definitions(pcms_mesh_intersection PUBLIC R3D_USE_CUDA) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any behavior that depends specifically on the CUDA-only backend in Omega_h? If so, it may be removed in the future.
|
@abhiyanpaudel #217 should be merged soon. This brings in petsc to the CI pipeline. |
This pull request adds routines for performing Galerkin projection using mesh intersections. The implementation supports linear, 2D triangular elements and enables conservative field transfer between non-matching meshes.