Skip to content

Commit 4738ab1

Browse files
committed
allowing more triangulation attempts and algorithm improvements
1 parent 9fee653 commit 4738ab1

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

‎openmc/model/surface_composite.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,9 +1029,9 @@ def _constrain_triangulation(self, points, depth=0):
10291029
-------
10301030
None
10311031
"""
1032-
# Only attempt the triangulation up to 3 times.
1033-
if depth > 2:
1034-
raise RuntimeError('Could not create a valid triangulation after 3'
1032+
# Only attempt the triangulation up to 5 times.
1033+
if depth > 4:
1034+
raise RuntimeError('Could not create a valid triangulation after 5'
10351035
' attempts')
10361036

10371037
tri = Delaunay(points, qhull_options='QJ')
@@ -1077,7 +1077,8 @@ def _group_simplices(self, neighbor_map, group=None):
10771077
return group
10781078
# If group is empty, grab the next simplex in the dictionary and recurse
10791079
if group is None:
1080-
sidx = next(iter(neighbor_map))
1080+
# Start with smallest neighbor lists
1081+
sidx = sorted(neighbor_map.items(), key=lambda item:len(item[1]))[0][0]
10811082
return self._group_simplices(neighbor_map, group=[sidx])
10821083
# Otherwise use the last simplex in the group
10831084
else:
@@ -1087,13 +1088,16 @@ def _group_simplices(self, neighbor_map, group=None):
10871088
# For each neighbor check if it is part of the same convex
10881089
# hull as the rest of the group. If yes, recurse. If no, continue on.
10891090
for n in neighbors:
1090-
if n in group or neighbor_map.get(n, None) is None:
1091+
if n in group or neighbor_map.get(n) is None:
10911092
continue
10921093
test_group = group + [n]
10931094
test_point_idx = np.unique(self._tri.simplices[test_group, :])
10941095
test_points = self.points[test_point_idx]
1095-
# If test_points are convex keep adding to this group
1096-
if len(test_points) == len(ConvexHull(test_points).vertices):
1096+
test_hull = ConvexHull(test_points, qhull_options='Qc')
1097+
pts_on_hull = len(test_hull.vertices) + len(test_hull.coplanar)
1098+
# If test_points are convex (including coplanar) keep adding to
1099+
# this group
1100+
if len(test_points) == pts_on_hull:
10971101
group = self._group_simplices(neighbor_map, group=test_group)
10981102
return group
10991103

0 commit comments

Comments
 (0)