@@ -44,23 +44,32 @@ function tet_x_plane!(
4444 end
4545 # Interpolate coordinates and function_values according to
4646 # evaluation of the plane equation
47- nxs = 0
47+ intersection_count = 0
48+ # List to check whether a node has already been visited, when checking for possible intersections
49+ visited_list = @MArray zeros (Bool, 4 )
4850 @inbounds @simd for n1 in 1 : 3
4951 N1 = node_indices[n1]
5052 @inbounds @fastmath @simd for n2 in (n1 + 1 ): 4
5153 N2 = node_indices[n2]
52- if planeq_values[n1] != planeq_values[n2] &&
53- planeq_values[n1] * planeq_values[n2] < tol
54- nxs += 1
54+
55+ if planeq_values[n1] * planeq_values[n2] < tol && ! visited_list[n1] && ! visited_list[n2]
56+
57+ abs (planeq_values[n1]) < tol && (visited_list[n1] = true )
58+ abs (planeq_values[n2]) < tol && (visited_list[n2] = true )
59+
60+ intersection_count += 1
5561 t = planeq_values[n1] / (planeq_values[n1] - planeq_values[n2])
56- ixcoord[1 , nxs ] = pointlist[1 , N1] + t * (pointlist[1 , N2] - pointlist[1 , N1])
57- ixcoord[2 , nxs ] = pointlist[2 , N1] + t * (pointlist[2 , N2] - pointlist[2 , N1])
58- ixcoord[3 , nxs ] = pointlist[3 , N1] + t * (pointlist[3 , N2] - pointlist[3 , N1])
59- ixvalues[nxs ] = function_values[N1] + t * (function_values[N2] - function_values[N1])
62+ ixcoord[1 , intersection_count ] = pointlist[1 , N1] + t * (pointlist[1 , N2] - pointlist[1 , N1])
63+ ixcoord[2 , intersection_count ] = pointlist[2 , N1] + t * (pointlist[2 , N2] - pointlist[2 , N1])
64+ ixcoord[3 , intersection_count ] = pointlist[3 , N1] + t * (pointlist[3 , N2] - pointlist[3 , N1])
65+ ixvalues[intersection_count ] = function_values[N1] + t * (function_values[N2] - function_values[N1])
6066 end
6167 end
6268 end
63- return nxs
69+ if ! (intersection_count in [3 , 4 ])
70+ @warn " computed $intersection_count intersection points of a tetrahedron and a plane. Expected value is 3 or 4."
71+ end
72+ return intersection_count
6473end
6574
6675"""
@@ -190,7 +199,7 @@ function marching_tetrahedra(
190199
191200 function pushtris (ns, ixcoord, ixvalues)
192201 # number of intersection points can be 3 or 4
193- return if ns >= 3
202+ if ns >= 3
194203 last_i = length (all_ixvalues)
195204 for is in 1 : ns
196205 @views push! (all_ixcoord, ixcoord[:, is])
@@ -201,6 +210,7 @@ function marching_tetrahedra(
201210 push! (all_ixfaces, (last_i + 3 , last_i + 2 , last_i + 4 ))
202211 end
203212 end
213+ return nothing
204214 end
205215
206216 for igrid in 1 : length (allcoords)
0 commit comments