SCOREC / pumi-pic

support libraries for unstructured mesh particle in cell simulations on GPUs and CPUs
BSD 3-Clause "New" or "Revised" License
36 stars 15 forks source link

Unit test for find_exit_face function #128

Open Fuad-HH opened 1 month ago

Fuad-HH commented 1 month ago

We discovered that the find_exit_face function in pumipic_adjacency.tpp should not work when the useBcc flag is true. A test case is added here to demonstrate the failed scenario.

Briefly, the function here decides which edge the ray crosses by the index of the minimum of the barycentric coordinates of the ray's destination; this is incorrect. The following picture demonstrates this. Although it has the same destination and the origin is in the same triangle, they will intersect different edges.

image

I have added the failing test case to fix it in the future.

Note: It uses a mesh called square2d4elem.msh and it's added to the pumipic_data repository. It's in this pull request

jacobmerson commented 1 month ago

@cwsmith @Angelyr The same problem also exists in the 3D implementation of find_exit_face. We are working on an equivalent test case. We do have a working version that uses barycentric coords in 2D. We worked out the math, but not implemented in 3D.

cwsmith commented 1 month ago

@Fuad-HH Thanks for the PR.

I haven't looked at the code yet, but could you explain the difference between the arrow and the line segment in the figure?

Fuad-HH commented 1 month ago

@Fuad-HH Thanks for the PR.

I haven't looked at the code yet, but could you explain the difference between the arrow and the line segment in the figure?

To test if the function provides the correct intersected face, I have simulated these two rays in the picture that share the same destination point. The function gives the correct exit face for the left ray and the wrong exit face for the right. We discovered this by looking at the algorithm used to find the exit face here. It uses the destination's barycentric coordinate to find the exit/intersected face. In this test case, these two rays share the same destination but they intersect two different edges. But as expected, the find_exit_face method returns the same exit face for both of them which is incorrect.

More specifics are provided in the header section of the test case.