Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed May 19, 2024
1 parent 18c1231 commit 4664636
Showing 1 changed file with 70 additions and 59 deletions.
129 changes: 70 additions & 59 deletions src/Grid/grid_generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ function generate_grid(::Type{Line}, nel::NTuple{1,Int}, left::Vec{1,T}=Vec{1}((
boundary_matrix = boundaries_to_sparse(boundary)

# Cell face sets
facetsets = Dict("left" => Set{FacetIndex}([boundary[1]]),
"right" => Set{FacetIndex}([boundary[2]]))
facetsets = Dict("left" => OrderedSet{FacetIndex}([boundary[1]]),
"right" => OrderedSet{FacetIndex}([boundary[2]]))
foreach(s -> sort!(s, by = x -> x.idx), values(facetsets))
return Grid(cells, nodes, facetsets=facetsets, boundary_matrix=boundary_matrix)
end

Expand Down Expand Up @@ -78,8 +79,9 @@ function generate_grid(::Type{QuadraticLine}, nel::NTuple{1,Int}, left::Vec{1,T}
boundary_matrix = boundaries_to_sparse(boundary)

# Cell face sets
facetsets = Dict("left" => Set{FacetIndex}([boundary[1]]),
"right" => Set{FacetIndex}([boundary[2]]))
facetsets = Dict("left" => OrderedSet{FacetIndex}([boundary[1]]),
"right" => OrderedSet{FacetIndex}([boundary[2]]))
foreach(s -> sort!(s, by = x -> x.idx), values(facetsets))
return Grid(cells, nodes, facetsets=facetsets, boundary_matrix=boundary_matrix)
end

Expand Down Expand Up @@ -143,11 +145,12 @@ function generate_grid(C::Type{Quadrilateral}, nel::NTuple{2,Int}, LL::Vec{2,T},

# Cell face sets
offset = 0
facetsets = Dict{String, Set{FacetIndex}}()
facetsets["bottom"] = Set{FacetIndex}(boundary[(1:length(cell_array[:,1])) .+ offset]); offset += length(cell_array[:,1])
facetsets["right"] = Set{FacetIndex}(boundary[(1:length(cell_array[end,:])) .+ offset]); offset += length(cell_array[end,:])
facetsets["top"] = Set{FacetIndex}(boundary[(1:length(cell_array[:,end])) .+ offset]); offset += length(cell_array[:,end])
facetsets["left"] = Set{FacetIndex}(boundary[(1:length(cell_array[1,:])) .+ offset]); offset += length(cell_array[1,:])
facetsets = Dict{String, OrderedSet{FacetIndex}}()
facetsets["bottom"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[:,1])) .+ offset]); offset += length(cell_array[:,1])
facetsets["right"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[end,:])) .+ offset]); offset += length(cell_array[end,:])
facetsets["top"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[:,end])) .+ offset]); offset += length(cell_array[:,end])
facetsets["left"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[1,:])) .+ offset]); offset += length(cell_array[1,:])
foreach(s -> sort!(s, by = x -> x.idx), values(facetsets))

return Grid(cells, nodes, facetsets=facetsets, boundary_matrix=boundary_matrix)
end
Expand All @@ -174,19 +177,20 @@ function generate_grid(::Type{QuadraticQuadrilateral}, nel::NTuple{2,Int}, LL::V
# Cell faces
cell_array = reshape(collect(1:nel_tot),(nel_x, nel_y))
boundary = FacetIndex[[FacetIndex(cl, 1) for cl in cell_array[:,1]];
[FacetIndex(cl, 2) for cl in cell_array[end,:]];
[FacetIndex(cl, 3) for cl in cell_array[:,end]];
[FacetIndex(cl, 4) for cl in cell_array[1,:]]]
[FacetIndex(cl, 2) for cl in cell_array[end,:]];
[FacetIndex(cl, 3) for cl in cell_array[:,end]];
[FacetIndex(cl, 4) for cl in cell_array[1,:]]]

boundary_matrix = boundaries_to_sparse(boundary)

# Cell face sets
offset = 0
facetsets = Dict{String, Set{FacetIndex}}()
facetsets["bottom"] = Set{FacetIndex}(boundary[(1:length(cell_array[:,1])) .+ offset]); offset += length(cell_array[:,1])
facetsets["right"] = Set{FacetIndex}(boundary[(1:length(cell_array[end,:])) .+ offset]); offset += length(cell_array[end,:])
facetsets["top"] = Set{FacetIndex}(boundary[(1:length(cell_array[:,end])) .+ offset]); offset += length(cell_array[:,end])
facetsets["left"] = Set{FacetIndex}(boundary[(1:length(cell_array[1,:])) .+ offset]); offset += length(cell_array[1,:])
facetsets = Dict{String, OrderedSet{FacetIndex}}()
facetsets["bottom"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[:,1])) .+ offset]); offset += length(cell_array[:,1])
facetsets["right"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[end,:])) .+ offset]); offset += length(cell_array[end,:])
facetsets["top"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[:,end])) .+ offset]); offset += length(cell_array[:,end])
facetsets["left"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[1,:])) .+ offset]); offset += length(cell_array[1,:])
foreach(s -> sort!(s, by = x -> x.idx), values(facetsets))

return Grid(cells, nodes, facetsets=facetsets, boundary_matrix=boundary_matrix)
end
Expand Down Expand Up @@ -227,13 +231,14 @@ function generate_grid(::Type{Hexahedron}, nel::NTuple{3,Int}, left::Vec{3,T}=Ve

# Cell face sets
offset = 0
facetsets = Dict{String,Set{FacetIndex}}()
facetsets["bottom"] = Set{FacetIndex}(boundary[(1:length(cell_array[:,:,1][:])) .+ offset]); offset += length(cell_array[:,:,1][:])
facetsets["front"] = Set{FacetIndex}(boundary[(1:length(cell_array[:,1,:][:])) .+ offset]); offset += length(cell_array[:,1,:][:])
facetsets["right"] = Set{FacetIndex}(boundary[(1:length(cell_array[end,:,:][:])) .+ offset]); offset += length(cell_array[end,:,:][:])
facetsets["back"] = Set{FacetIndex}(boundary[(1:length(cell_array[:,end,:][:])) .+ offset]); offset += length(cell_array[:,end,:][:])
facetsets["left"] = Set{FacetIndex}(boundary[(1:length(cell_array[1,:,:][:])) .+ offset]); offset += length(cell_array[1,:,:][:])
facetsets["top"] = Set{FacetIndex}(boundary[(1:length(cell_array[:,:,end][:])) .+ offset]); offset += length(cell_array[:,:,end][:])
facetsets = Dict{String,OrderedSet{FacetIndex}}()
facetsets["bottom"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[:,:,1][:])) .+ offset]); offset += length(cell_array[:,:,1][:])
facetsets["front"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[:,1,:][:])) .+ offset]); offset += length(cell_array[:,1,:][:])
facetsets["right"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[end,:,:][:])) .+ offset]); offset += length(cell_array[end,:,:][:])
facetsets["back"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[:,end,:][:])) .+ offset]); offset += length(cell_array[:,end,:][:])
facetsets["left"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[1,:,:][:])) .+ offset]); offset += length(cell_array[1,:,:][:])
facetsets["top"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[:,:,end][:])) .+ offset]); offset += length(cell_array[:,:,end][:])
foreach(s -> sort!(s, by = x -> x.idx), values(facetsets))

return Grid(cells, nodes, facetsets=facetsets, boundary_matrix=boundary_matrix)
end
Expand Down Expand Up @@ -276,13 +281,14 @@ function generate_grid(::Type{Wedge}, nel::NTuple{3,Int}, left::Vec{3,T}=Vec{3}(
boundary_matrix = boundaries_to_sparse([le; ri; bo; to; fr; ba])

facetsets = Dict(
"left" => Set(le),
"right" => Set(ri),
"front" => Set(fr),
"back" => Set(ba),
"bottom" => Set(bo),
"top" => Set(to),
"left" => OrderedSet{FacetIndex}(le),
"right" => OrderedSet{FacetIndex}(ri),
"front" => OrderedSet{FacetIndex}(fr),
"back" => OrderedSet{FacetIndex}(ba),
"bottom" => OrderedSet{FacetIndex}(bo),
"top" => OrderedSet{FacetIndex}(to),
)
foreach(s -> sort!(s, by = x -> x.idx), values(facetsets))

return Grid(cells, nodes, facetsets=facetsets, boundary_matrix=boundary_matrix)
end
Expand Down Expand Up @@ -339,13 +345,14 @@ function generate_grid(::Type{Pyramid}, nel::NTuple{3,Int}, left::Vec{3,T}=Vec{3
boundary_matrix = boundaries_to_sparse([le; ri; bo; to; fr; ba])

facetsets = Dict(
"left" => Set(le),
"right" => Set(ri),
"front" => Set(fr),
"back" => Set(ba),
"bottom" => Set(bo),
"top" => Set(to),
"left" => OrderedSet{FacetIndex}(le),
"right" => OrderedSet{FacetIndex}(ri),
"front" => OrderedSet{FacetIndex}(fr),
"back" => OrderedSet{FacetIndex}(ba),
"bottom" => OrderedSet{FacetIndex}(bo),
"top" => OrderedSet{FacetIndex}(to),
)
foreach(s -> sort!(s, by = x -> x.idx), values(facetsets))

return Grid(cells, nodes, facetsets=facetsets, boundary_matrix=boundary_matrix)
end
Expand Down Expand Up @@ -397,13 +404,14 @@ function Ferrite.generate_grid(::Type{SerendipityQuadraticHexahedron}, nel::NTup

# Cell face sets
offset = 0
facetsets = Dict{String,Set{FacetIndex}}()
facetsets["bottom"] = Set{FacetIndex}(boundary[(1:length(cell_array[:,:,1][:])) .+ offset]); offset += length(cell_array[:,:,1][:])
facetsets["front"] = Set{FacetIndex}(boundary[(1:length(cell_array[:,1,:][:])) .+ offset]); offset += length(cell_array[:,1,:][:])
facetsets["right"] = Set{FacetIndex}(boundary[(1:length(cell_array[end,:,:][:])) .+ offset]); offset += length(cell_array[end,:,:][:])
facetsets["back"] = Set{FacetIndex}(boundary[(1:length(cell_array[:,end,:][:])) .+ offset]); offset += length(cell_array[:,end,:][:])
facetsets["left"] = Set{FacetIndex}(boundary[(1:length(cell_array[1,:,:][:])) .+ offset]); offset += length(cell_array[1,:,:][:])
facetsets["top"] = Set{FacetIndex}(boundary[(1:length(cell_array[:,:,end][:])) .+ offset]); offset += length(cell_array[:,:,end][:])
facetsets = Dict{String,OrderedSet{FacetIndex}}()
facetsets["bottom"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[:,:,1][:])) .+ offset]); offset += length(cell_array[:,:,1][:])
facetsets["front"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[:,1,:][:])) .+ offset]); offset += length(cell_array[:,1,:][:])
facetsets["right"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[end,:,:][:])) .+ offset]); offset += length(cell_array[end,:,:][:])
facetsets["back"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[:,end,:][:])) .+ offset]); offset += length(cell_array[:,end,:][:])
facetsets["left"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[1,:,:][:])) .+ offset]); offset += length(cell_array[1,:,:][:])
facetsets["top"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[:,:,end][:])) .+ offset]); offset += length(cell_array[:,:,end][:])
foreach(s -> sort!(s, by = x -> x.idx), values(facetsets))

return Grid(cells, nodes, facetsets=facetsets, boundary_matrix=boundary_matrix)
end
Expand Down Expand Up @@ -437,11 +445,12 @@ function generate_grid(::Type{Triangle}, nel::NTuple{2,Int}, LL::Vec{2,T}, LR::V

# Cell face sets
offset = 0
facetsets = Dict{String,Set{FacetIndex}}()
facetsets["bottom"] = Set{FacetIndex}(boundary[(1:length(cell_array[1,:,1])) .+ offset]); offset += length(cell_array[1,:,1])
facetsets["right"] = Set{FacetIndex}(boundary[(1:length(cell_array[2,end,:])) .+ offset]); offset += length(cell_array[2,end,:])
facetsets["top"] = Set{FacetIndex}(boundary[(1:length(cell_array[2,:,end])) .+ offset]); offset += length(cell_array[2,:,end])
facetsets["left"] = Set{FacetIndex}(boundary[(1:length(cell_array[1,1,:])) .+ offset]); offset += length(cell_array[1,1,:])
facetsets = Dict{String,OrderedSet{FacetIndex}}()
facetsets["bottom"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[1,:,1])) .+ offset]); offset += length(cell_array[1,:,1])
facetsets["right"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[2,end,:])) .+ offset]); offset += length(cell_array[2,end,:])
facetsets["top"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[2,:,end])) .+ offset]); offset += length(cell_array[2,:,end])
facetsets["left"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[1,1,:])) .+ offset]); offset += length(cell_array[1,1,:])
foreach(s -> sort!(s, by = x -> x.idx), values(facetsets))

return Grid(cells, nodes, facetsets=facetsets, boundary_matrix=boundary_matrix)
end
Expand Down Expand Up @@ -477,11 +486,12 @@ function generate_grid(::Type{QuadraticTriangle}, nel::NTuple{2,Int}, LL::Vec{2,

# Cell face sets
offset = 0
facetsets = Dict{String,Set{FacetIndex}}()
facetsets["bottom"] = Set{FacetIndex}(boundary[(1:length(cell_array[1,:,1])) .+ offset]); offset += length(cell_array[1,:,1])
facetsets["right"] = Set{FacetIndex}(boundary[(1:length(cell_array[2,end,:])) .+ offset]); offset += length(cell_array[2,end,:])
facetsets["top"] = Set{FacetIndex}(boundary[(1:length(cell_array[2,:,end])) .+ offset]); offset += length(cell_array[2,:,end])
facetsets["left"] = Set{FacetIndex}(boundary[(1:length(cell_array[1,1,:])) .+ offset]); offset += length(cell_array[1,1,:])
facetsets = Dict{String,OrderedSet{FacetIndex}}()
facetsets["bottom"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[1,:,1])) .+ offset]); offset += length(cell_array[1,:,1])
facetsets["right"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[2,end,:])) .+ offset]); offset += length(cell_array[2,end,:])
facetsets["top"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[2,:,end])) .+ offset]); offset += length(cell_array[2,:,end])
facetsets["left"] = OrderedSet{FacetIndex}(boundary[(1:length(cell_array[1,1,:])) .+ offset]); offset += length(cell_array[1,1,:])
foreach(s -> sort!(s, by = x -> x.idx), values(facetsets))

return Grid(cells, nodes, facetsets=facetsets, boundary_matrix=boundary_matrix)
end
Expand Down Expand Up @@ -555,13 +565,14 @@ function generate_grid(::Type{Tetrahedron}, cells_per_dim::NTuple{3,Int}, left::
boundary_matrix = boundaries_to_sparse([le; ri; bo; to; fr; ba])

facetsets = Dict(
"left" => Set(le),
"right" => Set(ri),
"front" => Set(fr),
"back" => Set(ba),
"bottom" => Set(bo),
"top" => Set(to),
"left" => OrderedSet{FacetIndex}(le),
"right" => OrderedSet{FacetIndex}(ri),
"front" => OrderedSet{FacetIndex}(fr),
"back" => OrderedSet{FacetIndex}(ba),
"bottom" => OrderedSet{FacetIndex}(bo),
"top" => OrderedSet{FacetIndex}(to),
)
foreach(s -> sort!(s, by = x -> x.idx), values(facetsets))

return Grid(cells, nodes, facetsets=facetsets, boundary_matrix=boundary_matrix)
end

0 comments on commit 4664636

Please sign in to comment.