Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster ExclusiveTopology construction #927

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions src/Grid/topology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,18 @@ function _num_shared_vertices(cell_a::C1, cell_b::C2) where {C1, C2}
end

function _exclusive_topology_ctor(cells::Vector{C}, vertex_cell_table::Array{Set{Int}}, vertex_table, face_table, edge_table, cell_neighbor_table) where C <: AbstractCell
cell_neighbor_ids = Set{Int}()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an advantage to making this ordered so the order in the cell_neighbor_table[cell_id] will not be "random"? Maybe it doesn't matter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this does not matter, because we do not enforce any ordering and locality properties on our grids in general.

for (cell_id, cell) in enumerate(cells)
# Gather all cells which are connected via vertices
cell_neighbor_ids = Set{Int}()
empty!(cell_neighbor_ids)
for vertex ∈ vertices(cell)
for vertex_cell_id ∈ vertex_cell_table[vertex]
if vertex_cell_id != cell_id
push!(cell_neighbor_ids, vertex_cell_id)
end
end
end
cell_neighbor_table[cell_id] = EntityNeighborhood(CellIndex.(collect(cell_neighbor_ids)))
cell_neighbor_table[cell_id] = EntityNeighborhood([CellIndex(cell_id) for cell_id in cell_neighbor_ids])

# Any of the neighbors is now sorted in the respective categories
for cell_neighbor_id ∈ cell_neighbor_ids
Expand Down Expand Up @@ -187,24 +188,10 @@ function ExclusiveTopology(cells::Vector{C}) where C <: AbstractCell
end

# Setup matrices
vertex_table = Matrix{EntityNeighborhood{VertexIndex}}(undef, length(cells), max_vertices)
for j = 1:size(vertex_table,2)
for i = 1:size(vertex_table,1)
vertex_table[i,j] = EntityNeighborhood{VertexIndex}(VertexIndex[])
end
end
face_table = Matrix{EntityNeighborhood{FaceIndex}}(undef, length(cells), max_faces)
for j = 1:size(face_table,2)
for i = 1:size(face_table,1)
face_table[i,j] = EntityNeighborhood{FaceIndex}(FaceIndex[])
end
end
edge_table = Matrix{EntityNeighborhood{EdgeIndex}}(undef, length(cells), max_edges)
for j = 1:size(edge_table,2)
for i = 1:size(edge_table,1)
edge_table[i,j] = EntityNeighborhood{EdgeIndex}(EdgeIndex[])
end
end
vertex_table = [EntityNeighborhood{VertexIndex}(VertexIndex[]) for _ in 1:length(cells), _ in 1:max_vertices]
edge_table = [EntityNeighborhood{EdgeIndex }(EdgeIndex[] ) for _ in 1:length(cells), _ in 1:max_edges]
face_table = [EntityNeighborhood{FaceIndex }(FaceIndex[] ) for _ in 1:length(cells), _ in 1:max_faces]

cell_neighbor_table = Vector{EntityNeighborhood{CellIndex}}(undef, length(cells))

_exclusive_topology_ctor(cells, vertex_cell_table, vertex_table, face_table, edge_table, cell_neighbor_table)
Expand Down
Loading