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

Make showgrid work for all cells #570

Merged
merged 3 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
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
53 changes: 21 additions & 32 deletions src/Grid/grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,25 @@ nnodes(c::C) where {C<:AbstractCell} = nnodes(typeof(c))
nnodes(::Type{<:AbstractCell{dim,N,M}}) where {dim,N,M} = N

# Typealias for commonly used cells
const Line = Cell{1,2,2}
const Line2D = Cell{2,2,1}
const Line3D = Cell{3,2,0}
const QuadraticLine = Cell{1,3,2}

const Triangle = Cell{2,3,3}
const QuadraticTriangle = Cell{2,6,3}

const Quadrilateral = Cell{2,4,4}
const Quadrilateral3D = Cell{3,4,1}
const QuadraticQuadrilateral = Cell{2,9,4}

const Tetrahedron = Cell{3,4,4}
const QuadraticTetrahedron = Cell{3,10,4}

const Hexahedron = Cell{3,8,6}
const implemented_celltypes = (
(const Line = Cell{1,2,2}),
(const Line2D = Cell{2,2,1}),
(const Line3D = Cell{3,2,0}),
(const QuadraticLine = Cell{1,3,2}),

(const Triangle = Cell{2,3,3}),
(const QuadraticTriangle = Cell{2,6,3}),

(const Quadrilateral = Cell{2,4,4}),
(const Quadrilateral3D = Cell{3,4,1}),
(const QuadraticQuadrilateral = Cell{2,9,4}),

(const Tetrahedron = Cell{3,4,4}),
(const QuadraticTetrahedron = Cell{3,10,4}),

(const Hexahedron = Cell{3,8,6}),
(Cell{2,20,6})
)

"""
A `CellIndex` wraps an Int and corresponds to a cell with that number in the mesh
Expand Down Expand Up @@ -708,25 +711,11 @@ end

function Base.show(io::IO, ::MIME"text/plain", grid::Grid)
print(io, "$(typeof(grid)) with $(getncells(grid)) ")
typestrs = sort!(collect(Set(celltypes[typeof(x)] for x in grid.cells)))
str = join(io, typestrs, '/')
typestrs = sort!(collect(Set(repr(typeof(x)) for x in grid.cells)))
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be really slow, try showing something like generate_grid(Triangle, (1000, 1000)) in the REPL.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, missed that performance regression. Fixed in #559.

join(io, typestrs, '/')
print(io, " cells and $(getnnodes(grid)) nodes")
end

const celltypes = Dict{DataType, String}(Cell{1,2,2} => "Line",
Cell{2,2,2} => "2D-Line",
Cell{3,2,0} => "3D-Line",
Cell{1,3,2} => "QuadraticLine",
Cell{2,3,3} => "Triangle",
Cell{2,6,3} => "QuadraticTriangle",
Cell{2,4,4} => "Quadrilateral",
Cell{3,4,1} => "3D-Quadrilateral",
Cell{2,9,4} => "QuadraticQuadrilateral",
Cell{3,4,4} => "Tetrahedron",
Cell{3,10,4} => "QuadraticTetrahedron",
Cell{3,8,6} => "Hexahedron",
Cell{3,20,6} => "Cell{3,20,6}")

# Functions to uniquely identify vertices, edges and faces, used when distributing
# dofs over a mesh. For this we can ignore the nodes on edged, faces and inside cells,
# we only need to use the nodes that are vertices.
Expand Down
2 changes: 1 addition & 1 deletion test/test_apply_analytical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
end

@testset "DofHandler" begin
for (CT,name) in Ferrite.celltypes
for CT in Ferrite.implemented_celltypes
for ip_order_u in 1:2
for ip_order_p in 1:2
dh = testdh(CT, ip_order_u, ip_order_p)
Expand Down
4 changes: 2 additions & 2 deletions test/test_grid_dofhandler_vtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ end
addfaceset!(grid, "right-faceset", getfaceset(grid, "right"))
addnodeset!(grid, "middle-nodes", x -> norm(x) < radius)

gridfilename = "grid-$(Ferrite.celltypes[celltype])"
gridfilename = "grid-$(repr(celltype))"
vtk_grid(gridfilename, grid) do vtk
vtk_cellset(vtk, grid, "cell-1")
vtk_cellset(vtk, grid, "middle-cells")
Expand Down Expand Up @@ -73,7 +73,7 @@ end
u = rand(rng, ndofs(dofhandler))
apply!(u, ch)

dofhandlerfilename = "dofhandler-$(Ferrite.celltypes[celltype])"
dofhandlerfilename = "dofhandler-$(repr(celltype))"
vtk_grid(dofhandlerfilename, dofhandler) do vtk
vtk_point_data(vtk, ch)
vtk_point_data(vtk, dofhandler, u)
Expand Down