WriteVTK.jl
WriteVTK.jl copied to clipboard
Multiple times in one .vtu file?
I am not sure if this is possible with VTK, but it would be great to have one file that stores an unstructured mesh and data on the mesh at multiple times. For example, it would be great to do something like:
vtkfile = vtk_grid("my_vtk_file", x, y, z, cells)
times = linspace(0, 1, 10)
for (i, t) = enumerate(times)
vtk_point_data(vtkfile, pdata, "my_point_data", t)
end
where point data is being stored for several (10, in this example) times within one .vtu file. I am currently wasting a lot of space (and CPU time) storing the same grid in several hundred large files where each file contains the grid and the data for one time. The PVD example addresses the issue of having data at multiple times, but doesn't deal with the redundancy of storing the grid in each file.
I am not sure if VTK supports storing data for multiple times in one file like this. If it is supported by VTK, having support in WriteVTK.jl would be amazing. Thanks for your work on WriteVTK -- I love it!
Hi! Sorry for the late reply. Unfortunately, as far as I know, it's not possible to do such thing with VTK files. One possible workaround would be to save grid data to a separate file, which is written only once, and then "include" the file in each generated VTK file. I'm not really sure if that would work though. I tested using some XML syntax that should allow including other XML files, but that didn't work. I still need to make a few more tests.
Two ideas that also would allow for writing the grid only once, similar as @jipolanco's idea about including the grid information, but these might be easier to implement?
Idea 1: Add a copy method to be able to copy a vtkfile:
pvd = paraview_collection("output_pvd")
vtk = vtk_grid("vtkgrid", points, cells)
for i in 1:n_timesteps
u = solve() # solve the problem for given timestep
# copy the "base" file containing the grid might be faster than writing again
vtkfile = copy(vtk)
# although we have to rename the vtkfile, so maybe a copy like this instead
vtkfile = copy(vtk, "timestep$(i)")
vtk_point_data(vtkfile, u, "u") # write solution u to the file
collection_add_timestep(pvd, vtkfile, i)
end
Idea 2: Implement a way to reset the file, removing everything except the grid information from the buffer. This would (if it is possible to do) probably be faster then option 1, since it would only delete data.
pvd = paraview_collection("output_pvd")
vtk = vtk_grid("vtkgrid", points, cells)
for i in 1:n_timesteps
u = solve() # solve the problem for given timestep
# reset! the file to the "base" file
reset!(vtk)
# rename variant
reset!(vtk, "timestep$(i)")
vtk_point_data(vtkfile, u, "u") # write solution u to the file
collection_add_timestep(pvd, vtkfile, i)
end
of course none of these options saves any memory in the end, since the grid information is stored in each .vtu
file anyway. Could perhaps speed up the writing process however.