openmc-dev / openmc

OpenMC Monte Carlo Code
https://docs.openmc.org
Other
699 stars 444 forks source link

Polygon fix to better handle colinear points #2935

Closed eepeterson closed 3 weeks ago

eepeterson commented 1 month ago

Description

This PR fixes issues with coplanar points in the openmc.model.Polygon class. As far as I am aware, QHull cannot be forced to generate specific edges (or follow constraints that would enforce that). As a result, my workaround has been to split edges of the desired polygon in half if the first triangulation does not produce an edge on that segment of the polygon. This produces colinear points that are not included in the scipy.spatial.ConvexHull object when testing for the convexity of a particular grouping of triangles inside the polygon. However, they do show up in the coplanar attribute and therefore we can say that if the number of test points is equal to the number of vertices in the convex hull plus the coplanar points then the grouping of triangles is still convex. This combined with increasing the number of attempts at triangulation I believe will provide a more robust Polygon functionality. I also altered the algorithm for grouping simplices by starting with ones with the smallest neighbor lists since that has anecdotally resulted in smaller numbers of convex regions comprising a polygon. Although I'm sure it's not universal, it's likely better than grabbing a simplex at random.

Fixes #2931 pinging @MicahGale since he raised the issue

Checklist

MicahGale commented 4 weeks ago

Should the examples from #2931, and from slack be added as test cases?