diff --git a/src/Export/VTK.jl b/src/Export/VTK.jl index 840817fd4b..9eb6e84e68 100644 --- a/src/Export/VTK.jl +++ b/src/Export/VTK.jl @@ -114,17 +114,19 @@ nodes_to_vtkorder(cell::QuadraticHexahedron) = [ cell.nodes[27], # interior ] -function create_vtk_griddata(grid::Grid{dim, C, T}) where {dim, C, T} +function create_vtk_griddata(grid::AbstractGrid{sdim}) where {sdim} cls = WriteVTK.MeshCell[] for cell in getcells(grid) celltype = cell_to_vtkcell(typeof(cell)) push!(cls, WriteVTK.MeshCell(celltype, nodes_to_vtkorder(cell))) end - coords = reshape(reinterpret(T, getnodes(grid)), (dim, getnnodes(grid))) + T = get_coordinate_eltype(grid) + nodes_flat = reinterpret(T, getnodes(grid)) + coords = reshape(nodes_flat, (sdim, getnnodes(grid))) return coords, cls end -function create_vtk_grid(filename::AbstractString, grid::Grid{dim, C, T}; kwargs...) where {dim, C, T} +function create_vtk_grid(filename::AbstractString, grid::AbstractGrid; kwargs...) coords, cls = create_vtk_griddata(grid) return WriteVTK.vtk_grid(filename, coords, cls; kwargs...) end diff --git a/test/test_abstractgrid.jl b/test/test_abstractgrid.jl index 16d3c8996c..e34536b95f 100644 --- a/test/test_abstractgrid.jl +++ b/test/test_abstractgrid.jl @@ -92,4 +92,19 @@ colors1 = Ferrite.create_coloring(subtype_grid, alg = ColoringAlgorithm.Greedy) colors2 = Ferrite.create_coloring(reference_grid, alg = ColoringAlgorithm.Greedy) @test all(colors1 .== colors2) + + @testset "IO interface" begin + # Generate files + gridfilename = "smallgrid" + refgridfilename = "refgrid" + VTKGridFile(gridfilename, subtype_grid) do vtk::VTKGridFile + end + VTKGridFile(refgridfilename, reference_grid) do vtk::VTKGridFile + end + # Check if the output is the same + @test bytes2hex(open(SHA.sha1, gridfilename * ".vtu")) == bytes2hex(open(SHA.sha1, refgridfilename * ".vtu")) + # Cleanup + rm(gridfilename * ".vtu") + rm(refgridfilename * ".vtu") + end end