trixi-framework / Trixi2Vtk.jl

Convert output files generated with Trixi.jl to VTK.
https://trixi-framework.github.io/Trixi.jl/stable/
MIT License
11 stars 8 forks source link

Export velocity field as vector such that one can use the Paraview streamtracer function #77

Open DanielDoehring opened 11 months ago

DanielDoehring commented 11 months ago

Currently, the velocity field is exported as three scalars. If you want to use Paraview to compute e.g. the streamlines a vector-valued velocity field is required.

Exporting the velocities (and maybe also the magnetic field) as a vector-field would be a nice feature/change.

DanielDoehring commented 11 months ago

The goal would be putting the funcitonality provided by this code


pd = PlotData2D(sol)

using Printf

mkpath("out")  # Create output directory automatically

Velocities_String = "out/Velocities.vtk"
Velocities = open(Velocities_String, "w")

write(Velocities, "# vtk DataFile Version 3.0\n")
write(Velocities, "vtk output\n")
write(Velocities, "ASCII\n")
write(Velocities, "DATASET STRUCTURED_GRID\n")

Nx = length(pd.x)
Ny = length(pd.y)
NumPoints = Int(Nx * Ny)
NumPointsString = string(Int(Nx * Ny))

write(Velocities, "DIMENSIONS ", string(Nx), " ", string(Ny), " 1\n")
write(Velocities, "POINTS ", NumPointsString, " float\n")
for i in 1:Nx
  for j in 1:Ny
    write(Velocities, "$(pd.x[i]) $(pd.y[j]) 0\n")
  end
end

write(Velocities, "\n")
write(Velocities, "POINT_DATA ", NumPointsString, "\n")

write(Velocities, "\n")
write(Velocities, "VECTORS U float\n")
v1 = pd.data[2]
v2 = pd.data[3]
for i in 1:Nx
  for j in 1:Ny
    # Need to transpose back (note interchanged `j, i`), see l. 528 of src/visualization/utilities.jl
    write(Velocities, string(v1[j,i]), " ", string(v2[j,i]), " 0\n")
  end
end

close(Velocities)

in Trixi.jl/Trixi2Vtk.jl.