JuliaVTK / WriteVTK.jl

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

convert from point data to cell data before writing #95

Closed fab6 closed 2 years ago

fab6 commented 2 years ago

Hi,

I would like to convert the available point data for a rectilineargrid to cell data for rectilineargrid. Is this possible? Maybe you have a hint how to do this!?

Thank you in advance! Fab

jipolanco commented 2 years ago

Hi, for rectilinear grids this should be easy. It's sufficient to pass an array that has dimensions (Nx - 1, Ny - 1, Nz - 1) instead of (Nx, Ny, Nz). Such an array may represent the average of the values of neighbouring vertices, or whatever you want the cell values to be.

This is also briefly described in the docs.

fredrikekre commented 2 years ago

Probably this is also a transformation that can be done in ParaView, although I have never tried it.

fab6 commented 2 years ago

Hi,

thank you for the quick help! Yes, paraview is able to do this (I did not think about this) and for the dimensions it would be straight forward. I was thinking that the averaging of the data could be not so straight forward... thanks again

jipolanco commented 2 years ago

Here's a simple generic function you could use to do the averaging:

function point_average(u)
    v = similar(u, size(u) .- 1)
    for I ∈ CartesianIndices(v)
        J = I + oneunit(I)
        v[I] = sum(i -> u[i], I:J) / length(I:J)
    end
    v
end

u = rand(6, 8, 10)
ucells = point_average(u)

You may want to look at this blog post for details.

fab6 commented 2 years ago

Thank you for your help! I did not see this.