From 466463675111668db9c069994d8730c987f3ee2b Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sun, 19 May 2024 23:58:49 +0200 Subject: [PATCH] fixes --- src/Grid/grid_generators.jl | 129 +++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 59 deletions(-) diff --git a/src/Grid/grid_generators.jl b/src/Grid/grid_generators.jl index 6a4d400308..f79e0c2b5c 100644 --- a/src/Grid/grid_generators.jl +++ b/src/Grid/grid_generators.jl @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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