JuliaVTK / WriteVTK.jl

Julia package for writing VTK XML files
Other
151 stars 32 forks source link

write rectilinear grid with celldata #112

Closed fab6 closed 1 year ago

fab6 commented 1 year ago

Hi,

at the moment I am writing pointData to a vtr file using something similar like this:

vtkfile = vtk_grid(fileName, x, y , z,  ascii = true)
vtkfile[string(fieldName)] = fieldPointDataValues
vtk_save(vtkfile)

where x, y, z are now the actual poinst. This works fine and the resulting vtr can be openend.

Now, I am directly reading cell data, that means xc, yc, zc are the actual cell centers and I would like to write out the data as cellData. At the moment I am trying:

vtkfile = vtk_grid(fileName, xc, yc , zc,  ascii = true)
vtk_cell_data(vtkfile, fieldCellDataValues, string(fieldName))
vtk_save(vtkfile)

The file gets written with the corresponding CellData item, but I am not able to load the file in paraview or visit. Do you have a hint, what I am doing wrong and how I can correct this? Thank you in advance! Fab

fab6 commented 1 year ago

ok, I think, I see it now, the dimension is different for writing; vtk_grid needs the point positions x,y,z but the data is the cell centered with a size decreased by one, e.g. something like:

fileName = "vtrtest"
vtk = vtk_grid(fileName, x, y , z)
fieldCellDataValues = rand((xcells[1] - 1) * (ycells[1] - 1)* (zcells[1] - 1))
vtk[string("testdata"), VTKCellData()] = fieldCellDataValues
vtk_save(vtk)