Skip to content

Commit 22ea4c5

Browse files
committed
runic in iterator-api branch
1 parent e0acfce commit 22ea4c5

8 files changed

Lines changed: 234 additions & 201 deletions

File tree

docs/make.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ using Documenter, GridVisualizeTools, ColorTypes
22

33
function mkdocs()
44
DocMeta.setdocmeta!(GridVisualizeTools, :DocTestSetup, :(using GridVisualizeTools, ColorTypes, Colors); recursive = true)
5-
makedocs(; sitename = "GridVisualizeTools.jl",
6-
modules = [GridVisualizeTools],
7-
clean = false,
8-
doctest = true,
9-
authors = "J. Fuhrmann",
10-
repo = "https://github.com/j-fu/GridVisualizeTools.jl",
11-
pages = [
12-
"Home" => "index.md",
13-
])
14-
if !isinteractive()
5+
makedocs(;
6+
sitename = "GridVisualizeTools.jl",
7+
modules = [GridVisualizeTools],
8+
clean = false,
9+
doctest = true,
10+
authors = "J. Fuhrmann",
11+
repo = "https://github.com/j-fu/GridVisualizeTools.jl",
12+
pages = [
13+
"Home" => "index.md",
14+
]
15+
)
16+
return if !isinteractive()
1517
deploydocs(; repo = "github.com/j-fu/GridVisualizeTools.jl.git", devbranch = "main")
1618
end
1719
end

src/colors.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ RGB{Float64}(0.85,0.6,0.6)
1515
1616
"""
1717
function region_cmap(n)
18-
ColorSchemes.distinguishable_colors(max(5, n),
19-
[Colors.RGB(0.85, 0.6, 0.6), Colors.RGB(0.6, 0.85, 0.6), Colors.RGB(0.6, 0.6, 0.85)];
20-
lchoices = range(70; stop = 80, length = 5),
21-
cchoices = range(25; stop = 65, length = 15),
22-
hchoices = range(20; stop = 360, length = 15))
18+
return ColorSchemes.distinguishable_colors(
19+
max(5, n),
20+
[Colors.RGB(0.85, 0.6, 0.6), Colors.RGB(0.6, 0.85, 0.6), Colors.RGB(0.6, 0.6, 0.85)];
21+
lchoices = range(70; stop = 80, length = 5),
22+
cchoices = range(25; stop = 65, length = 15),
23+
hchoices = range(20; stop = 360, length = 15)
24+
)
2325
end
2426

2527
"""
@@ -38,11 +40,13 @@ RGB{Float64}(1.0,0.0,0.0)
3840
3941
"""
4042
function bregion_cmap(n)
41-
ColorSchemes.distinguishable_colors(max(5, n),
42-
[Colors.RGB(1.0, 0.0, 0.0), Colors.RGB(0.0, 1.0, 0.0), Colors.RGB(0.0, 0.0, 1.0)];
43-
lchoices = range(50; stop = 75, length = 10),
44-
cchoices = range(75; stop = 100, length = 10),
45-
hchoices = range(20; stop = 360, length = 30))
43+
return ColorSchemes.distinguishable_colors(
44+
max(5, n),
45+
[Colors.RGB(1.0, 0.0, 0.0), Colors.RGB(0.0, 1.0, 0.0), Colors.RGB(0.0, 0.0, 1.0)];
46+
lchoices = range(50; stop = 75, length = 10),
47+
cchoices = range(75; stop = 100, length = 10),
48+
hchoices = range(20; stop = 360, length = 30)
49+
)
4650
end
4751

4852
"""
@@ -56,7 +60,7 @@ RGB{Float64}(1.0,0.0,0.0)
5660
"""
5761
function Colors.RGB(c::String)
5862
c64 = Colors.color_names[c]
59-
Colors.RGB(c64[1] / 255, c64[2] / 255, c64[3] / 255)
63+
return Colors.RGB(c64[1] / 255, c64[2] / 255, c64[3] / 255)
6064
end
6165

6266
"""

src/extraction.jl

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ Extract visible tetrahedra - those intersecting with the planes
77
Return corresponding points and facets for each region for drawing as mesh (Makie,MeshCat)
88
or trisurf (pyplot)
99
"""
10-
function extract_visible_cells3D(coord, cellnodes, cellregions, nregions, xyzcut;
11-
primepoints = zeros(0, 0), Tp = SVector{3, Float32}, Tf = SVector{3, Int32})
10+
function extract_visible_cells3D(
11+
coord, cellnodes, cellregions, nregions, xyzcut;
12+
primepoints = zeros(0, 0), Tp = SVector{3, Float32}, Tf = SVector{3, Int32}
13+
)
1214
all_lt = ones(Bool, 3)
1315
all_gt = ones(Bool, 3)
1416

1517
function take(coord, simplex, xyzcut, all_lt, all_gt)
16-
for idim = 1:3
18+
for idim in 1:3
1719
all_lt[idim] = true
1820
all_gt[idim] = true
19-
for inode = 1:4
21+
for inode in 1:4
2022
c = coord[idim, simplex[inode]] - xyzcut[idim]
2123
all_lt[idim] = all_lt[idim] && (c < 0.0)
2224
all_gt[idim] = all_gt[idim] && (c > 0.0)
@@ -25,22 +27,22 @@ function extract_visible_cells3D(coord, cellnodes, cellregions, nregions, xyzcut
2527
tke = false
2628
tke = tke || (!all_lt[1]) && (!all_gt[1]) && (!all_gt[2]) && (!all_gt[3])
2729
tke = tke || (!all_lt[2]) && (!all_gt[2]) && (!all_gt[1]) && (!all_gt[3])
28-
tke = tke || (!all_lt[3]) && (!all_gt[3]) && (!all_gt[1]) && (!all_gt[2])
30+
return tke = tke || (!all_lt[3]) && (!all_gt[3]) && (!all_gt[1]) && (!all_gt[2])
2931
end
3032

31-
faces = [Vector{Tf}(undef, 0) for iregion = 1:nregions]
32-
points = [Vector{Tp}(undef, 0) for iregion = 1:nregions]
33+
faces = [Vector{Tf}(undef, 0) for iregion in 1:nregions]
34+
points = [Vector{Tp}(undef, 0) for iregion in 1:nregions]
3335

34-
for iregion = 1:nregions
35-
for iprime = 1:size(primepoints, 2)
36+
for iregion in 1:nregions
37+
for iprime in 1:size(primepoints, 2)
3638
@views push!(points[iregion], Tp(primepoints[:, iprime]))
3739
end
3840
end
3941
tet = zeros(Int32, 4)
4042

41-
for itet = 1:size(cellnodes, 2)
43+
for itet in 1:size(cellnodes, 2)
4244
iregion = cellregions[itet]
43-
for i = 1:4
45+
for i in 1:4
4446
tet[i] = cellnodes[i, itet]
4547
end
4648
if take(coord, tet, xyzcut, all_lt, all_gt)
@@ -57,7 +59,7 @@ function extract_visible_cells3D(coord, cellnodes, cellregions, nregions, xyzcut
5759
end
5860
end
5961
end
60-
points, faces
62+
return points, faces
6163
end
6264

6365
"""
@@ -69,15 +71,17 @@ Extract visible boundary faces - those not cut off by the planes
6971
Return corresponding points and facets for each region for drawing as mesh (Makie,MeshCat)
7072
or trisurf (pyplot)
7173
"""
72-
function extract_visible_bfaces3D(coord, bfacenodes, bfaceregions, nbregions, xyzcut;
73-
primepoints = zeros(0, 0), Tp = SVector{3, Float32}, Tf = SVector{3, Int32})
74+
function extract_visible_bfaces3D(
75+
coord, bfacenodes, bfaceregions, nbregions, xyzcut;
76+
primepoints = zeros(0, 0), Tp = SVector{3, Float32}, Tf = SVector{3, Int32}
77+
)
7478
nbfaces = size(bfacenodes, 2)
7579
cutcoord = zeros(3)
7680

7781
function take(coord, simplex, xyzcut)
78-
for idim = 1:3
82+
for idim in 1:3
7983
all_gt = true
80-
for inode = 1:3
84+
for inode in 1:3
8185
c = coord[idim, simplex[inode]] - xyzcut[idim]
8286
all_gt = all_gt && c > 0
8387
end
@@ -91,18 +95,18 @@ function extract_visible_bfaces3D(coord, bfacenodes, bfaceregions, nbregions, xy
9195
Tc = SVector{3, eltype(coord)}
9296
xcoord = reinterpret(Tc, reshape(coord, (length(coord),)))
9397

94-
faces = [Vector{Tf}(undef, 0) for iregion = 1:nbregions]
95-
points = [Vector{Tp}(undef, 0) for iregion = 1:nbregions]
96-
for iregion = 1:nbregions
97-
for iprime = 1:size(primepoints, 2)
98+
faces = [Vector{Tf}(undef, 0) for iregion in 1:nbregions]
99+
points = [Vector{Tp}(undef, 0) for iregion in 1:nbregions]
100+
for iregion in 1:nbregions
101+
for iprime in 1:size(primepoints, 2)
98102
@views push!(points[iregion], Tp(primepoints[:, iprime]))
99103
end
100104
end
101105

102106
# remove some type instability here
103107
function collct(points, faces)
104108
trinodes = [1, 2, 3]
105-
for i = 1:nbfaces
109+
for i in 1:nbfaces
106110
iregion = bfaceregions[i]
107111
trinodes[1] = bfacenodes[1, i]
108112
trinodes[2] = bfacenodes[2, i]
@@ -115,7 +119,8 @@ function extract_visible_bfaces3D(coord, bfacenodes, bfaceregions, nbregions, xy
115119
@views push!(faces[iregion], (npts + 1, npts + 2, npts + 3))
116120
end
117121
end
122+
return
118123
end
119124
collct(points, faces)
120-
points, faces
125+
return points, faces
121126
end

src/linearsimplex.jl

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
1-
struct LinearSimplex{D,N,Tv}
2-
points::SVector{N,Point{D,Tv}}
3-
values::SVector{N,Tv}
1+
struct LinearSimplex{D, N, Tv}
2+
points::SVector{N, Point{D, Tv}}
3+
values::SVector{N, Tv}
44
end
55

6-
values(s::LinearSimplex)=s.values
7-
points(s::LinearSimplex)=s.points
6+
values(s::LinearSimplex) = s.values
7+
points(s::LinearSimplex) = s.points
88

99

10-
function LinearSimplex(::Type{Val{D}},points::Union{Vector,Tuple}, values::Union{Vector,Tuple}) where {D}
11-
spoints=SVector{D+1,Point{D,Float32}}(points...)
12-
svalues=SVector{D+1,Float32}(values...)
13-
LinearSimplex(spoints,svalues)
10+
function LinearSimplex(::Type{Val{D}}, points::Union{Vector, Tuple}, values::Union{Vector, Tuple}) where {D}
11+
spoints = SVector{D + 1, Point{D, Float32}}(points...)
12+
svalues = SVector{D + 1, Float32}(values...)
13+
return LinearSimplex(spoints, svalues)
1414
end
1515

16-
function LinearSimplex(::Type{Val{1}},points::AbstractMatrix, values::AbstractVector)
17-
@views spoints=SVector{2,Point{1,Float32}}(points[:,1],points[:,2])
18-
svalues=SVector{2,Float32}(values[1],values[2])
19-
LinearSimplex(spoints,svalues)
16+
function LinearSimplex(::Type{Val{1}}, points::AbstractMatrix, values::AbstractVector)
17+
@views spoints = SVector{2, Point{1, Float32}}(points[:, 1], points[:, 2])
18+
svalues = SVector{2, Float32}(values[1], values[2])
19+
return LinearSimplex(spoints, svalues)
2020
end
2121

22-
function LinearSimplex(::Type{Val{2}},points::AbstractMatrix, values::AbstractVector)
23-
@views spoints=SVector{3,Point{2,Float32}}(points[:,1],points[:,2],points[:,3])
24-
svalues=SVector{3,Float32}(values[1],values[2],values[3])
25-
LinearSimplex(spoints,svalues)
22+
function LinearSimplex(::Type{Val{2}}, points::AbstractMatrix, values::AbstractVector)
23+
@views spoints = SVector{3, Point{2, Float32}}(points[:, 1], points[:, 2], points[:, 3])
24+
svalues = SVector{3, Float32}(values[1], values[2], values[3])
25+
return LinearSimplex(spoints, svalues)
2626
end
2727

28-
function LinearSimplex(::Type{Val{3}},points::AbstractMatrix, values::AbstractVector)
29-
@views spoints=SVector{4,Point{3,Float32}}(points[:,1],points[:,2],points[:,3],points[:,4])
30-
svalues=SVector{4,Float32}(values[1],values[2],values[3],values[4])
31-
LinearSimplex(spoints,svalues)
28+
function LinearSimplex(::Type{Val{3}}, points::AbstractMatrix, values::AbstractVector)
29+
@views spoints = SVector{4, Point{3, Float32}}(points[:, 1], points[:, 2], points[:, 3], points[:, 4])
30+
svalues = SVector{4, Float32}(values[1], values[2], values[3], values[4])
31+
return LinearSimplex(spoints, svalues)
3232
end
3333

3434

35-
function LinearSimplex(::Type{Val{1}},points::AbstractMatrix, values::AbstractVector,coordscale)
36-
@views spoints=SVector{2,Point{1,Float32}}(points[:,1]*coordscale,points[:,2]*coordscale)
37-
svalues=SVector{2,Float32}(values[1],values[2])
38-
LinearSimplex(spoints,svalues)
35+
function LinearSimplex(::Type{Val{1}}, points::AbstractMatrix, values::AbstractVector, coordscale)
36+
@views spoints = SVector{2, Point{1, Float32}}(points[:, 1] * coordscale, points[:, 2] * coordscale)
37+
svalues = SVector{2, Float32}(values[1], values[2])
38+
return LinearSimplex(spoints, svalues)
3939
end
4040

41-
function LinearSimplex(::Type{Val{2}},points::AbstractMatrix, values::AbstractVector,coordscale)
42-
@views spoints=SVector{3,Point{2,Float32}}(points[:,1]*coordscale,points[:,2]*coordscale,points[:,3]*coordscale)
43-
svalues=SVector{3,Float32}(values[1],values[2],values[3])
44-
LinearSimplex(spoints,svalues)
41+
function LinearSimplex(::Type{Val{2}}, points::AbstractMatrix, values::AbstractVector, coordscale)
42+
@views spoints = SVector{3, Point{2, Float32}}(points[:, 1] * coordscale, points[:, 2] * coordscale, points[:, 3] * coordscale)
43+
svalues = SVector{3, Float32}(values[1], values[2], values[3])
44+
return LinearSimplex(spoints, svalues)
4545
end
4646

47-
function LinearSimplex(::Type{Val{3}},points::AbstractMatrix, values::AbstractVector,coordscale)
48-
@views spoints=SVector{4,Point{3,Float32}}(points[:,1]*coordscale,points[:,2]*coordscale,points[:,3]*coordscale,points[:,4]*coordscale)
49-
svalues=SVector{4,Float32}(values[1],values[2],values[3],values[4])
50-
LinearSimplex(spoints,svalues)
47+
function LinearSimplex(::Type{Val{3}}, points::AbstractMatrix, values::AbstractVector, coordscale)
48+
@views spoints = SVector{4, Point{3, Float32}}(points[:, 1] * coordscale, points[:, 2] * coordscale, points[:, 3] * coordscale, points[:, 4] * coordscale)
49+
svalues = SVector{4, Float32}(values[1], values[2], values[3], values[4])
50+
return LinearSimplex(spoints, svalues)
5151
end
5252

53-
LinearEdge(points,values)=LinearSimplex(Val{1},points,values)
54-
LinearTriangle(points,values)=LinearSimplex(Val{2},points,values)
55-
LinearTetrahedron(points,values)=LinearSimplex(Val{3},points,values)
53+
LinearEdge(points, values) = LinearSimplex(Val{1}, points, values)
54+
LinearTriangle(points, values) = LinearSimplex(Val{2}, points, values)
55+
LinearTetrahedron(points, values) = LinearSimplex(Val{3}, points, values)
5656

5757

5858
"""
@@ -81,15 +81,15 @@ Useful for:
8181
very few (<10) allocations. So any allocations beyond this from a
8282
call to `testloop` hint at possibilities to improve an iterator implementation.
8383
"""
84-
function testloop(iterators::AbstractVector{T}) where T<:LinearSimplexIterator
85-
threads=map(iterators) do iterator
86-
begin
87-
local x=0.0
84+
function testloop(iterators::AbstractVector{T}) where {T <: LinearSimplexIterator}
85+
threads = map(iterators) do iterator
86+
begin
87+
local x = 0.0
8888
for vt in iterator
89-
x+=sum(vt.values)
89+
x += sum(vt.values)
9090
end
91-
x
92-
end
91+
x
92+
end
9393
end
94-
sum(fetch.(threads))
94+
return sum(fetch.(threads))
9595
end

0 commit comments

Comments
 (0)