Skip to content

Commit 1e9a70c

Browse files
committed
Fixed issue of missing shapes in sliceplots of given grids and planes
Fixed error in tet_x_plane function in marching.jl which incorrectly assessed intersections between tetrahedron edges and plane
1 parent 344056b commit 1e9a70c

5 files changed

Lines changed: 44 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## Future Release
6+
7+
### Fixed
8+
9+
- Reworked `tet_x_plane!()` to improve tetrahedron-plane-crosssection
10+
511
## [3.0.0] - 2025-03-03
612

713
### Changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ version = "3.0.0"
77
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
88
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
99
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
10+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1011
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
1112

1213
[compat]
1314
ColorSchemes = "3"
1415
Colors = "0.12, 0.13"
1516
DocStringExtensions = "0.8, 0.9"
17+
StaticArrays = "1.9.13"
1618
StaticArraysCore = "1.4"
1719
julia = "1.6"

src/GridVisualizeTools.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ColorSchemes
1010

1111
using DocStringExtensions: SIGNATURES, TYPEDEF, TYPEDSIGNATURES
1212
using StaticArraysCore: SVector
13+
using StaticArrays: @MArray
1314

1415
include("colors.jl")
1516
export region_cmap, bregion_cmap, rgbtuple, rgbcolor

src/marching.jl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
6473
end
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)

test/runtests.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ using Test, Documenter, GridVisualizeTools, ColorTypes, Colors
33
DocMeta.setdocmeta!(GridVisualizeTools, :DocTestSetup, :(using GridVisualizeTools, ColorTypes, Colors); recursive = true)
44
doctest(GridVisualizeTools)
55

6+
7+
@testset "tet_x_plane" begin
8+
#Testing amount of intersected edges of (x,y,z)-tetrahedron (0,0,0),(1,0,0),(1,1,0),(1,1,1) with plane x+y-1=0
9+
@test GridVisualizeTools.tet_x_plane!(
10+
[0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0],
11+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
12+
[0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0; 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0; 0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0],
13+
Int32[1, 2, 4, 8],
14+
[-1.0, 0.0, 1.0, 1.0],
15+
[0, 0, 0, 0, 0, 0, 0, 1],
16+
tol = 1.0e-12
17+
) == 3
18+
end
19+
20+
621
if isdefined(Docs, :undocumented_names) # >=1.11
722
@testset "UndocumentedNames" begin
823
@test isempty(Docs.undocumented_names(GridVisualizeTools))

0 commit comments

Comments
 (0)