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

Multiple times in one .vtu file? #24

Open
omalled opened this issue Oct 24, 2016 · 5 comments
Open

Multiple times in one .vtu file? #24

omalled opened this issue Oct 24, 2016 · 5 comments

Comments

@omalled
Copy link

omalled commented Oct 24, 2016

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!

@jipolanco
Copy link
Member

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.

@fredrikekre
Copy link
Contributor

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.

@lucasbanting
Copy link

We can now do this with VTK-HDF5 for ImageData and Unstructured grids.

Not sure how to best describe the interface to specify a vtk-hdf file in this library, but if anyone has ideas I can attempt to add it.

@jipolanco
Copy link
Member

@lucasbanting It would be very interesting to add a VTK-HDF5 interface. However, from looking at some examples it's not very clear to me how one would include multiple times in a single VTK-HDF5 file. Do you have any examples? Does it involve creating separate HDF5 groups for each timestep or something like that?

As for a possible interface, I'd propose to extend the current interface so that vtk_grid accepts an optional filetype argument, which would take a singleton type instance such as VTKXML() or VTKHDF5(). One would use it as follows:

saved_files = vtk_grid(VTKHDF5(), filename, points..., [cells]; kws...) do vtk
    # add datasets here...
end

In any case, I'd rather not include HDF5.jl as a hard dependency to WriteVTK.jl, but instead to optionally support VTK-HDF5 output using Requires.jl or the new package extensions in Julia 1.9.

@lucasbanting
Copy link

I was just going off of: https://www.kitware.com/vtk-hdf-reader/ , and saw where it said it is intended to replace XDMF.
I'll try to come up with a working example to see what's possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants