Skip to content

Commit

Permalink
Recover export for non-Grid grid types (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
termi-official authored Dec 2, 2024
1 parent 2d294fb commit 12d7259
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Export/VTK.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/test_abstractgrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 12d7259

Please sign in to comment.