Skip to content

Commit 79c0ab7

Browse files
committed
make grid coloring not depend on iteration order of dicts and sets
1 parent 236eb50 commit 79c0ab7

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
[#1235])
3333
- Relax vector input type from `Vector` to `AbstractVector` in `evaluate_at_points!`.
3434
([#1183])
35+
- The result of grid coloring is now not dependent on iteration order of dictionaries and sets. This may change the coloring obtained from `create_coloring`
36+
compared to previous Ferrite versions.
3537

3638
### Documentation updates
3739
- Extended assembly docs with information on how to support direct assembly into new matrix

src/Ferrite.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using LinearAlgebra:
1212
using NearestNeighbors:
1313
NearestNeighbors, KDTree, knn
1414
using OrderedCollections:
15-
OrderedSet
15+
OrderedDict, OrderedSet
1616
using SparseArrays:
1717
SparseArrays, SparseMatrixCSC, nonzeros, nzrange, rowvals,
1818
AbstractSparseMatrix, AbstractSparseMatrixCSC, sparsevec

src/Grid/coloring.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Incidence matrix for element connections in the grid
22
function create_incidence_matrix(g::AbstractGrid, cellset = 1:getncells(g))
3-
cell_containing_node = Dict{Int, Set{Int}}()
3+
cell_containing_node = OrderedDict{Int, Set{Int}}()
44
for cellid in cellset
55
cell = getcells(g, cellid)
66
for v in get_node_ids(cell)
@@ -78,21 +78,21 @@ function workstream_coloring(incidence_matrix, cellset)
7878
###################
7979
# 1. Partitioning #
8080
###################
81-
zones = Set{Int}[]
81+
zones = OrderedSet{Int}[]
8282
n_visited = 0
8383
Z = 1
84-
Z0 = Set{Int}() # Dummy zone
85-
remaining_cells = Set{Int}(cellset)
84+
Z0 = OrderedSet{Int}() # Dummy zone
85+
remaining_cells = OrderedSet{Int}(cellset)
8686
while n_visited < length(cellset)
8787
setdiff!(remaining_cells, zones...)
8888
## Zone 1: Just the first element
8989
@assert length(remaining_cells) > 0
90-
push!(zones, Set{Int}(first(remaining_cells)))
90+
push!(zones, OrderedSet{Int}((first(remaining_cells),)))
9191
Z += 1
9292
n_visited += 1
9393
## Zone N: All elements with connection to elements in Zone N-1
9494
while true
95-
s = Set{Int}()
95+
s = OrderedSet{Int}()
9696
# Loop over all elements in previous zone and add their neighbouring elements
9797
# unless they are in any of the previous 2 zones.
9898
empty_zone = true

test/test_vtk_export.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
@test Ferrite.write_cell_colors(vtk, grid, colors) === vtk
2222
end
2323
@test v isa VTKGridFile
24-
@test bytes2hex(open(SHA.sha1, fname * ".vtu")) == "b804d0b064121b672d8e35bcff8446eda361cac3"
24+
@test bytes2hex(open(SHA.sha1, fname * ".vtu")) == "960aa8323da524f642376bba6ff7d8f7c349b218"
2525
end
2626
end
2727
@testset "constraints" begin

0 commit comments

Comments
 (0)