Skip to content

Commit 624eeef

Browse files
authored
Merge pull request #101 from WIAS-PDELib/fix/commongrids_ringsector
Fix dangling nodes in ringsector
2 parents 34f85ad + 18f55b9 commit 624eeef

14 files changed

Lines changed: 134 additions & 8 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Changelog
2+
## [1.14.1] - 2025-11-14
3+
- fix dangling nodes in full ringsector
4+
- add `isconsistent` checks to CI tests
5+
- somewhat extend `isconsistent` checks
6+
27
## [1.14.0] - 2025-07-01
38

49
- add `trim!`/`trim` function to remove precomputed grid components for lightweight storage

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ExtendableGrids"
22
uuid = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
33
authors = ["Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de>", "Christian Merdon <christian.merdon@wias-berlin.de>", "Johannes Taraz <johannes.taraz@gmail.com>", "Patrick Jaap <patrick.jaap@wias-berlin.de>"]
4-
version = "1.14.0"
4+
version = "1.14.1"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

examples/examples1d.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ end
4949
using Test
5050

5151
function runtests()
52+
@test isconsistent(interval_from_vector())
53+
@test isconsistent(interval_localref())
54+
@test isconsistent(interval_multiregion())
55+
@test isconsistent(interval_subgrid())
56+
5257
@test numbers_match(interval_from_vector(), 21, 20, 2)
5358
@test numbers_match(interval_localref(), 27, 26, 2)
5459
@test numbers_match(interval_multiregion(), 21, 20, 3)

examples/examples2d.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,22 @@ end
9898
# Unit tests
9999
using Test
100100
function runtests()
101+
102+
@test isconsistent(rectangle())
103+
@test isconsistent(rectangle_localref())
104+
@test isconsistent(rectangle_multiregion())
105+
@test isconsistent(rectangle_subgrid())
106+
@test isconsistent(rect2d_bregion_function())
107+
101108
@test numbers_match(rectangle(), 441, 800, 80)
102109
@test numbers_match(rectangle_localref(), 729, 1352, 104)
103110
@test numbers_match(rectangle_multiregion(), 441, 800, 100)
104111
@test numbers_match(rectangle_subgrid(), 360, 600, 120)
105112
@test numbers_match(rect2d_bregion_function(), 79, 112, 44)
106113

107114
g, sg, sf = sorted_subgrid()
115+
@test isconsistent(g)
116+
@test isconsistent(sg)
108117
@test numbers_match(g, 187, 306, 66)
109118
@test numbers_match(sg, 17, 16, 0)
110119
@test issorted(view(sg[Coordinates], 1, :))

examples/examples3d.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ end
4444
using Test
4545

4646
function runtests()
47+
@test isconsistent(quadrilateral())
48+
@test isconsistent(cross3d())
49+
50+
4751
@test numbers_match(quadrilateral(), 330, 1200, 440)
4852
@test mask_bedges()
4953
@test numbers_match(cross3d(), 189, 480, 344)

src/adjacency.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ function Base.append!(adj::VariableTargetAdjacency, column)
130130
return push!(adj.colstart, length(adj.colentries) + 1)
131131
end
132132

133+
"""
134+
$(TYPEDSIGNATURES)
135+
136+
Maximum for VariableTargetAdjacency
137+
"""
138+
Base.maximum(adj::VariableTargetAdjacency) = Base.maximum(adj.colentries)
139+
140+
"""
141+
$(TYPEDSIGNATURES)
142+
143+
Minimum for VariableTargetAdjacency
144+
"""
145+
Base.minimum(adj::VariableTargetAdjacency) = Base.minimum(adj.colentries)
146+
133147
"""
134148
$(TYPEDEF)
135149

src/commongrids.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ end
174174

175175

176176
"""
177-
ringsector(rad,ang; eltype=Triangle2D)
177+
ringsector(rad,ang)
178178
179179
Sector of ring or full ring (if `ang[begin]-ang[end]≈2π`)
180180
"""
181-
function ringsector(rad, ang; eltype = Triangle2D)
182-
Tv = Float32
181+
function ringsector(rad, ang)
182+
Tv = promote_type(eltype(rad), eltype(ang))
183183
Ti = Int32
184184

185185
coord = ElasticArray{Tv, 2}(undef, 2, 0)
@@ -201,7 +201,9 @@ function ringsector(rad, ang; eltype = Triangle2D)
201201
x = cos(ϕ)
202202
y = sin(ϕ)
203203
for irad in 1:nrad
204-
append!(coord, (rad[irad] * x, rad[irad] * y))
204+
if iarc < narc || !fullcircle
205+
append!(coord, (rad[irad] * x, rad[irad] * y))
206+
end
205207
icoord = size(coord, 2)
206208
if irad < nrad
207209
if iarc < narc

src/extendablegrid.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,30 @@ or, if `warnoly==true`, return false.
459459
"""
460460
function isconsistent(grid; warnonly = false)
461461
consistent = true
462+
nnodes = num_nodes(grid)
463+
464+
if maximum(grid[CellNodes]) != nnodes
465+
@warn "maximum(grid[CellNodes])!=nnodes"
466+
consistent = false
467+
end
468+
469+
if minimum(grid[CellNodes]) != 1
470+
@warn "minimum(grid[CellNodes])!=1"
471+
consistent = false
472+
end
473+
474+
if length(grid[BFaceNodes]) > 0
475+
if maximum(grid[BFaceNodes]) > nnodes
476+
@warn "maximum(grid[BFaceNodes])>nnodes"
477+
consistent = false
478+
end
479+
480+
if minimum(grid[BFaceNodes]) < 1
481+
@warn "minimum(grid[BFaceNodes])<1"
482+
consistent = false
483+
end
484+
end
485+
462486
dnodes = dangling_nodes(grid)
463487
if !isnothing(dnodes)
464488
@warn "Found dangling nodes: $(dnodes)"

test/gmsh.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,41 +51,51 @@ end
5151
ExtendableGrids.simplexgrid_to_gmsh(grid1; filename = joinpath(path, "testfile.msh"))
5252

5353
grid2 = ExtendableGrids.simplexgrid_from_gmsh(joinpath(path, "testfile.msh"); Tc = Float32, Ti = Int64)
54+
@test isconsistent(grid2)
5455

5556
@test seemingly_equal(grid2, grid1; sort = true, confidence = :low)
5657
@test seemingly_equal(grid2, grid1; sort = true, confidence = :full)
5758

5859
grid1 = ExtendableGrids.simplexgrid_from_gmsh(joinpath(path, "sto_2d.msh"); Tc = Float64, Ti = Int64)
60+
@test isconsistent(grid1)
5961

6062
ExtendableGrids.simplexgrid_to_gmsh(grid1; filename = joinpath(path, "testfile.msh"))
6163
grid2 = ExtendableGrids.simplexgrid_from_gmsh(joinpath(path, "testfile.msh"); Tc = Float64, Ti = Int64)
64+
@test isconsistent(grid2)
6265

6366
@test seemingly_equal(grid1, grid2; sort = true, confidence = :low)
6467
@test seemingly_equal(grid1, grid2; sort = true, confidence = :full)
6568

6669
grid1 = ExtendableGrids.simplexgrid_from_gmsh(joinpath(path, "sto_3d.msh"); Tc = Float32, Ti = Int64)
70+
@test isconsistent(grid1)
6771

6872
ExtendableGrids.simplexgrid_to_gmsh(grid1; filename = joinpath(path, "testfile.msh"))
6973
grid2 = ExtendableGrids.simplexgrid_from_gmsh(joinpath(path, "testfile.msh"); Tc = Float64, Ti = Int32)
74+
@test isconsistent(grid2)
7075

7176
@test seemingly_equal(grid1, grid2; sort = true, confidence = :low)
7277
@test seemingly_equal(grid1, grid2; sort = true, confidence = :full)
7378

7479
grid1 = ExtendableGrids.simplexgrid_from_gmsh(joinpath(path, "sto_2d.msh"))
80+
@test isconsistent(grid1)
7581

7682
grid2 = ExtendableGrids.simplexgrid_from_gmsh(joinpath(path, "sto_3d.msh"); Tc = Float32, Ti = Int32)
83+
@test isconsistent(grid2)
7784

7885
@test !seemingly_equal(grid1, grid2; sort = true, confidence = :low)
7986
@test !seemingly_equal(grid1, grid2; sort = true, confidence = :full)
8087

8188
grid1 = ExtendableGrids.simplexgrid_from_gmsh(joinpath(path, "testmesh.gmsh"); incomplete = true)
8289
ExtendableGrids.seal!(grid1; encode = false)
90+
@test isconsistent(grid1)
8391

8492
ExtendableGrids.simplexgrid_to_gmsh(grid1; filename = joinpath(path, "completed_testfile.msh"))
8593
grid2 = ExtendableGrids.simplexgrid_from_gmsh(joinpath(path, "completed_testfile.msh"))
94+
@test isconsistent(grid2)
8695

8796
grid3 = ExtendableGrids.simplexgrid_from_gmsh(joinpath(path, "testmesh.gmsh"); incomplete = true)
8897
ExtendableGrids.seal!(grid3; encode = true)
98+
@test isconsistent(grid3)
8999

90100
@test seemingly_equal(grid1, grid2; sort = true, confidence = :low)
91101
@test seemingly_equal(grid1, grid2; sort = true, confidence = :full)
@@ -98,7 +108,9 @@ end
98108
grid2 = simplexgrid(x, x)
99109
grid3 = simplexgrid(x, x)
100110
ExtendableGrids.seal!(grid2)
111+
@test isconsistent(grid2)
101112
ExtendableGrids.seal!(grid3; encode = false)
113+
@test isconsistent(grid3)
102114

103115
@test seemingly_equal(grid2, grid1; sort = true, confidence = :low)
104116
@test seemingly_equal(grid2, grid1; sort = true, confidence = :full)
@@ -109,9 +121,11 @@ end
109121
@testset "Read/write mixed gmsh 2d" begin
110122
path = joinpath(pkgdir(ExtendableGrids), "test")
111123
grid1 = ExtendableGrids.mixedgrid_from_gmsh(joinpath(path, "mixedgrid_2d.msh"); Tc = Float64, Ti = Int64)
124+
@test_broken isconsistent(grid1)
112125

113126
ExtendableGrids.mixedgrid_to_gmsh(grid1; filename = joinpath(path, "testfile.msh"))
114127
grid2 = ExtendableGrids.mixedgrid_from_gmsh(joinpath(path, "testfile.msh"); Tc = Float32, Ti = UInt64)
128+
@test_broken isconsistent(grid2)
115129

116130
@test seemingly_equal(grid1, grid2; sort = true, confidence = :low)
117131
@test seemingly_equal(grid1, grid2; sort = true, confidence = :full)
@@ -121,6 +135,9 @@ end
121135
path = joinpath(pkgdir(ExtendableGrids), "test")
122136
grid = simplexgrid(joinpath(path, "disk1hole.geo"))
123137
@test num_cells(grid) > 0
138+
@test_broken isconsistent(grid)
139+
124140
grid = simplexgrid(joinpath(path, "cube6.geo"))
125141
@test num_cells(grid) > 0
142+
@test isconsistent(grid)
126143
end

test/partitioning.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Metis
1717

1818

1919
for grid in (grid1, grid2, grid3)
20+
@test isconsistent(grid)
2021
@test num_pcolors(grid) == 1
2122
@test num_partitions(grid) == 1
2223
@test pcolors(grid) == 1:1
@@ -28,6 +29,7 @@ import Metis
2829

2930
for npart in [10, 15, 20]
3031
grid4 = partition(grid1, PlainMetisPartitioning(npart = npart); nodes = true, keep_nodepermutation = true)
32+
@test isconsistent(grid4)
3133
@test num_pcolors(grid4) > 1
3234
@test num_partitions(grid4) == npart
3335
@test pcolors(grid4) |> length > 0
@@ -39,6 +41,7 @@ import Metis
3941

4042
for npart in [3, 4, 5, 6]
4143
grid4 = partition(grid1, RecursiveMetisPartitioning(npart = npart); nodes = true, keep_nodepermutation = true)
44+
@test isconsistent(grid4)
4245
@test num_pcolors(grid4) > 1
4346
@test num_partitions(grid4) > npart
4447
@test pcolors(grid4) |> length > 0

0 commit comments

Comments
 (0)