JuliaVTK / WriteVTK.jl

Julia package for writing VTK XML files
Other
155 stars 33 forks source link

Specify point or cell data #85

Closed RibeiroAndre closed 3 years ago

RibeiroAndre commented 3 years ago

Hi, I have this block:

outfile = vtk_grid(file, points, cells, compress=3) do vtk
        vtk["Velocity"] = velocity;
        vtk["Pressure"] = pressure;

And this works fine. However, I just stumbled upon a case where my numbers of points and cells are the same. So the writer assumes I'm saving point data (though I'm actually writing cell data). Is there a way to specify that I'm writing point/cell data? Thanks!

RibeiroAndre commented 3 years ago

Oh, and I do have a case where one variable is point data and the other is cell data, so if there's a way to specify it per variable, that'd be perfect!

fredrikekre commented 3 years ago

From the README:

For convenience, the input data is automatically associated either to grid points or data cells, or interpreted as field data, according to the input data dimensions. If more control is desired, one can explicitly pass a VTKPointData, a VTKCellData or a VTKFieldData instance as a second index:

vtkfile["Velocity", VTKPointData()] = vel
vtkfile["Pressure", VTKCellData()] = p
vtkfile["Time", VTKFieldData()] = 42.0

Does that help?

RibeiroAndre commented 3 years ago

Ah, I didn't realize I could use that syntax inside the do block. It works, thanks a lot!