Skip to content

Conversation

@abhiyanpaudel
Copy link
Collaborator

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.

@jacobmerson jacobmerson requested review from Sichao25, Copilot and jacobmerson and removed request for Copilot October 31, 2025 19:42
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 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
Copy link

Copilot AI Oct 31, 2025

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'.

Copilot uses AI. Check for mistakes.
Omega_h::build_from_elems_and_coords(&target_mesh, OMEGA_H_SIMPLEX, 2,
ev2v_source, coords);

// Source Mesh with two traingles
Copy link

Copilot AI Oct 31, 2025

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'.

Suggested change
// Source Mesh with two traingles
// Source Mesh with two triangles

Copilot uses AI. Check for mistakes.
points_h(0, 0) = 0.0;
points_h(0, 1) = 0.0;
points_h(1, 0) = 1.0;
points_h(0, 1) = 0.0;
Copy link

Copilot AI Oct 31, 2025

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.

Suggested change
points_h(0, 1) = 0.0;
points_h(1, 1) = 0.0;

Copilot uses AI. Check for mistakes.
"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) &
Copy link

Copilot AI Oct 31, 2025

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'.

Suggested change
// (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) &

Copilot uses AI. Check for mistakes.
endif()

if (PCMS_ENABLE_MESHFIELDS)
list(APPEND PCMS_UNIT_TEST_SOURCES test_load_vector.cpp)
Copy link

Copilot AI Oct 31, 2025

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.

Copilot uses AI. Check for mistakes.
*/

#ifndef PCMS_INTERPOLATOR_GALERKIN_PROJECTION_SOLVER_HPP
#ifndef PCMS_INTERPOLATOR_GALERKIN_PROJECTION_SOLVER_HPP
Copy link

Copilot AI Oct 31, 2025

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.

Suggested change
#ifndef PCMS_INTERPOLATOR_GALERKIN_PROJECTION_SOLVER_HPP
#define PCMS_INTERPOLATOR_GALERKIN_PROJECTION_SOLVER_HPP

Copilot uses AI. Check for mistakes.
#include <petscvec_kokkos.hpp>
#include <sstream> //ostringstream

#include <pcms/interpolator/mesh_interscetion/load_vector_integrator.hpp>
Copy link

Copilot AI Oct 31, 2025

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'.

Suggested change
#include <pcms/interpolator/mesh_interscetion/load_vector_integrator.hpp>
#include <pcms/interpolator/mesh_intersection/load_vector_integrator.hpp>

Copilot uses AI. Check for mistakes.
// 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)),
Copy link

Copilot AI Oct 31, 2025

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.

Suggested change
"MLS coefficients", tp.set_scratch_size(1, Kokkos::PerTeam(shared_size)),
"MLS coefficients", tp.set_scratch_size(1, Kokkos::PerTeam(scratch_size)),

Copilot uses AI. Check for mistakes.
find_library(PETSC_LIBRARY petsc HINTS ${PETSC_LIB_DIR})

if (NOT PETSC_LIBRARY)
message(FATAL_ERROR "Couldnot find libpetsc in ${PETSC_LIB_DIR}")
Copy link

Copilot AI Oct 31, 2025

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'.

Suggested change
message(FATAL_ERROR "Couldnot find libpetsc in ${PETSC_LIB_DIR}")
message(FATAL_ERROR "Could not find libpetsc in ${PETSC_LIB_DIR}")

Copilot uses AI. Check for mistakes.
phi = 0.0;
} else {
phi =
a * a * ratio * ratio * Kokkos::log(a * ratio); // a shouldnot be zero
Copy link

Copilot AI Oct 31, 2025

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'.

Suggested change
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

Copilot uses AI. Check for mistakes.
@jacobmerson
Copy link
Collaborator

@abhiyanpaudel can you share the petsc configuration you are using so we can add that to CI?

@abhiyanpaudel
Copy link
Collaborator Author

./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
Copy link
Collaborator

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.

Copy link
Contributor

@Sichao25 Sichao25 left a 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>
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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)
Copy link
Contributor

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.

@jacobmerson
Copy link
Collaborator

@abhiyanpaudel #217 should be merged soon. This brings in petsc to the CI pipeline.

@jacobmerson jacobmerson mentioned this pull request Dec 9, 2025
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.

5 participants