Need Help Generating VTK Files for Vector Visualization in ParaView
Hi everyone,
I'm having trouble generating VTK files for my vectors to visualize them in ParaView with Tough3. I haven't been able to create a proper VTK file, and I'm wondering if anyone has a Python script or code snippet that could help me with this.
If you have any suggestions or examples, I would greatly appreciate it!
Thank you!
3 replies
-
Hi
You can do it with the development version of toughio, to install it, run in a console or iPython kernel:
pip install https://github.com/keurfonluu/toughio/archive/devel.zip
Then, assuming you have connection outputs in OUTPUT_CONNE.csv and a MESH file:
import toughio mesh = toughio.read_input("MESH") output_conne = toughio.read_output("OUTPUT_CONNE.csv", time_steps=-1) # e.g., last time step output = output_conne.to_element(mesh)
The snippet above reads the MESH file, then output file, and finally approximates the flows at the element centers from the flow data at the interfaces.
To generate a VTK with only the approximate flow outputs, we can use PyVista:
import numpy as np import pyvista as pv points = np.array([v["center"] for v in mesh["elements"].values()]) grid = pv.PolyData(points) for k, v in output.data.items(): grid[k] = v grid.save("OUTPUT_CONNE.vtk")
This code snippet uses the centers of the elements to generate a cloud of points, and then associates the approximated data points to the vertices.
Note that this requires a version of toughio that is still in development and which will be released whenever it's ready.