@@ -312,22 +312,23 @@ function marching_triangles(
312312 func = funcs[igrid]
313313 coord = coords[igrid]
314314
315- # pre-allcate memory
316- objective_values = Vector {Tv} (undef, size (coord, 2 ) )
315+ # pre-allcate memory for triangle values (3 nodes per triangle)
316+ objective_values = Vector {Tv} (undef, 3 )
317317
318318 # the objective_func is used to determine the intersection (line equation or iso levels)
319319 # the value_func is used to interpolate values at the intersections
320- function isect (nodes , objective_func, value_func)
320+ function isect (tri_nodes , objective_func, value_func)
321321 (i1, i2, i3) = (1 , 2 , 3 )
322322
323- f = (objective_func[nodes[1 ]], objective_func[nodes[2 ]], objective_func[nodes[3 ]])
323+ # 3 values of the objective function
324+ f = objective_func
324325
325326 # sort f[i1] ≤ f[i2] ≤ f[i3]
326327 f[1 ] <= f[2 ] ? (i1, i2) = (1 , 2 ) : (i1, i2) = (2 , 1 )
327328 f[i2] <= f[3 ] ? i3 = 3 : (i2, i3) = (3 , i2)
328329 f[i1] > f[i2] ? (i1, i2) = (i2, i1) : nothing
329330
330- (n1, n2, n3) = (nodes [i1], nodes [i2], nodes [i3])
331+ (n1, n2, n3) = (tri_nodes [i1], tri_nodes [i2], tri_nodes [i3])
331332
332333 dx31 = coord[1 , n3] - coord[1 , n1]
333334 dx21 = coord[1 , n2] - coord[1 , n1]
@@ -371,14 +372,18 @@ function marching_triangles(
371372 end
372373
373374 for itri in 1 : size (cellnodes[igrid], 2 )
375+
376+ # nodes of the current triangle
377+ tri_nodes = @views cellnodes[igrid][:, itri]
378+
374379 for level in levels
375380 # objective func is iso-level equation
376381 @views @fastmath map! (
377382 inode -> (func[inode] - level),
378383 objective_values,
379- 1 : size (coord, 2 )
384+ tri_nodes
380385 )
381- @views isect (cellnodes[igrid][:, itri] , objective_values, func)
386+ @views isect (tri_nodes , objective_values, func)
382387 end
383388
384389 for line in lines
@@ -388,9 +393,9 @@ function marching_triangles(
388393 @views @fastmath map! (
389394 inode -> (line_equation (line, coord[:, inode])),
390395 objective_values,
391- 1 : size (coord, 2 )
396+ tri_nodes
392397 )
393- @views isect (cellnodes[igrid][:, itri] , objective_values, func)
398+ @views isect (tri_nodes , objective_values, func)
394399 end
395400
396401 end
0 commit comments