1+ function assign_coordinates_at_point_in_plane! (
2+ ixcoord,
3+ ixvalues,
4+ coordinates,
5+ function_values,
6+ node_index,
7+ intersection_count
8+ )
9+
10+ @views ixcoord[:, intersection_count] .= coordinates[:, node_index]
11+ ixvalues[intersection_count] = function_values[node_index]
12+
13+ return nothing
14+
15+ end
16+
17+ function assign_coordinates_at_intersection! (
18+ ixcoord,
19+ ixvalues,
20+ coordinates,
21+ function_values,
22+ planeq_values_start,
23+ planeq_values_end,
24+ node_index_start,
25+ node_index_end,
26+ intersection_count
27+ )
28+
29+ t = planeq_values_start / (planeq_values_start - planeq_values_end)
30+ @views @. ixcoord[:, intersection_count] = coordinates[:, node_index_start] + t * (coordinates[:, node_index_end] - coordinates[:, node_index_start])
31+ ixvalues[intersection_count] = function_values[node_index_start] + t * (function_values[node_index_end] - function_values[node_index_start])
32+
33+ return nothing
34+ end
35+
36+
137"""
238 $(SIGNATURES)
339 Calculate intersections between tetrahedron with given piecewise linear
1046 and the plane.
1147
1248 Input:
13- - pointlist : 3xN array of grid point coordinates
14- - node_indices: 4 element array of node indices (pointing into pointlist and function_values)
49+ - coordinates : 3xN array of grid point coordinates
50+ - node_indices: 4 element array of node indices (pointing into coordinates and function_values)
1551 - planeq_values: 4 element array of plane equation evaluated at the node coordinates
1652 - function_values: N element array of function values
1753
2056 - ixvalues: 4 element array of function values at plane - tetdedge intersections
2157
2258 Returns:
23- - nxs ,ixcoord,ixvalues
59+ - amount_intersections ,ixcoord,ixvalues
2460
2561 This method can be used both for the evaluation of plane sections and for
2662 the evaluation of function isosurfaces.
2763"""
28- function tet_x_plane ! (
64+ function calculate_plane_tetrahedron_intersection ! (
2965 ixcoord,
3066 ixvalues,
31- pointlist ,
67+ coordinates ,
3268 node_indices,
3369 planeq_values,
3470 function_values;
@@ -42,34 +78,32 @@ function tet_x_plane!(
4278 )
4379 return 0
4480 end
45- # Interpolate coordinates and function_values according to
46- # evaluation of the plane equation
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 )
50- @inbounds @simd for n1 in 1 : 3
51- N1 = node_indices[n1]
52- @inbounds @fastmath @simd for n2 in (n1 + 1 ): 4
53- N2 = node_indices[n2]
5481
55- if planeq_values[n1] * planeq_values[n2] < tol && ! visited_list[n1] && ! visited_list[n2]
82+ amount_intersections = 0
5683
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
61- t = planeq_values[n1] / (planeq_values[n1] - planeq_values[n2])
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])
84+ @inbounds for n1 in 1 : 4
85+ N1 = node_indices[n1]
86+ if abs (planeq_values[n1]) < tol
87+ amount_intersections += 1
88+ assign_coordinates_at_point_in_plane! (ixcoord, ixvalues, coordinates, function_values, N1, amount_intersections)
89+ else
90+ for n2 in (n1 + 1 ): 4
91+ N2 = node_indices[n2]
92+ if (abs (planeq_values[n2]) < tol) # We do not allow the 2nd node to be in the plane
93+ continue
94+ end
95+ if planeq_values[n1] * planeq_values[n2] < tol^ 2
96+ amount_intersections += 1
97+ assign_coordinates_at_intersection! (ixcoord, ixvalues, coordinates, function_values, planeq_values[n1], planeq_values[n2], N1, N2, amount_intersections)
98+ end
6699 end
67100 end
68101 end
69- if intersection_count > 4
70- @warn " computed $intersection_count intersection points of a tetrahedron and a plane. Expected at most 4."
102+
103+ if amount_intersections > 4
104+ @warn " computed $(amount_intersections) intersection points of a tetrahedron and a plane. Expected at most 4."
71105 end
72- return intersection_count
106+ return amount_intersections
73107end
74108
75109"""
@@ -231,7 +265,7 @@ function marching_tetrahedra(
231265 planeq[2 ] = all_planeq[node_indices[2 ]]
232266 planeq[3 ] = all_planeq[node_indices[3 ]]
233267 planeq[4 ] = all_planeq[node_indices[4 ]]
234- nxs = tet_x_plane ! (
268+ nxs = calculate_plane_tetrahedron_intersection ! (
235269 ixcoord,
236270 ixvalues,
237271 coord,
0 commit comments