Skip to content

Commit

Permalink
Fix grid coloring for edge case with one or zero cells (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijas authored Feb 21, 2023
1 parent 88c619c commit 2cd15f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Grid/coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function create_incidence_matrix(g::Grid, cellset=1:getncells(g))
end
end

incidence_matrix = sparse(I, J, V)
incidence_matrix = sparse(I, J, V, getncells(g), getncells(g))
return incidence_matrix
end

Expand Down Expand Up @@ -70,6 +70,13 @@ end

# See Appendix A in https://www.math.colostate.edu/%7Ebangerth/publications/2013-pattern.pdf
function workstream_coloring(incidence_matrix, cellset)

if length(cellset) == 0
return Vector{Int}[]
elseif length(cellset) == 1
return Vector{Int}[Int[first(cellset)]]
end

###################
# 1. Partitioning #
###################
Expand Down
8 changes: 6 additions & 2 deletions test/test_grid_dofhandler_vtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ end
function test_coloring(grid, cellset=1:getncells(grid))
for alg in (ColoringAlgorithm.Greedy, ColoringAlgorithm.WorkStream)
color_vectors = create_coloring(grid, cellset; alg=alg)
@test sum(length, color_vectors) == length(cellset)
@test union(Set.(color_vectors)...) == Set(cellset)
@test sum(length, color_vectors, init=0) == length(cellset)
@test union!(Set{Int}(), color_vectors...) == Set(cellset)
conn = Ferrite.create_incidence_matrix(grid, cellset)
for color in color_vectors, c1 in color, c2 in color
@test !conn[c1, c2]
Expand All @@ -450,6 +450,10 @@ end
test_coloring(generate_grid(Hexahedron, (5, 5, 5)), Set{Int}(1:3^3))
# unconnected subset
test_coloring(generate_grid(Triangle, (10, 10)), union(Set(1:10), Set(70:80)))

#Special case with one and zero elements in the sets
test_coloring(generate_grid(Quadrilateral, (2, 2)), [1])
test_coloring(generate_grid(Quadrilateral, (2, 2)), [])
end

@testset "DoF distribution" begin
Expand Down

0 comments on commit 2cd15f7

Please sign in to comment.