@@ -312,22 +312,23 @@ function marching_triangles(
312
312
func = funcs[igrid]
313
313
coord = coords[igrid]
314
314
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 )
317
317
318
318
# the objective_func is used to determine the intersection (line equation or iso levels)
319
319
# 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)
321
321
(i1, i2, i3) = (1 , 2 , 3 )
322
322
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
324
325
325
326
# sort f[i1] ≤ f[i2] ≤ f[i3]
326
327
f[1 ] <= f[2 ] ? (i1, i2) = (1 , 2 ) : (i1, i2) = (2 , 1 )
327
328
f[i2] <= f[3 ] ? i3 = 3 : (i2, i3) = (3 , i2)
328
329
f[i1] > f[i2] ? (i1, i2) = (i2, i1) : nothing
329
330
330
- (n1, n2, n3) = (nodes [i1], nodes [i2], nodes [i3])
331
+ (n1, n2, n3) = (tri_nodes [i1], tri_nodes [i2], tri_nodes [i3])
331
332
332
333
dx31 = coord[1 , n3] - coord[1 , n1]
333
334
dx21 = coord[1 , n2] - coord[1 , n1]
@@ -371,14 +372,18 @@ function marching_triangles(
371
372
end
372
373
373
374
for itri in 1 : size (cellnodes[igrid], 2 )
375
+
376
+ # nodes of the current triangle
377
+ tri_nodes = @views cellnodes[igrid][:, itri]
378
+
374
379
for level in levels
375
380
# objective func is iso-level equation
376
381
@views @fastmath map! (
377
382
inode -> (func[inode] - level),
378
383
objective_values,
379
- 1 : size (coord, 2 )
384
+ tri_nodes
380
385
)
381
- @views isect (cellnodes[igrid][:, itri] , objective_values, func)
386
+ @views isect (tri_nodes , objective_values, func)
382
387
end
383
388
384
389
for line in lines
0 commit comments