Plotting the mesh cell centroids with scalars value.

Hello Everyone.

I have a csv file which I exported from a commercial CFD software.
It contains x,y,z values of cell centroids and corresponding values of the scalar(velocitymagnitude, tempreature etc) at thoes points. I want to plot these points as a scalar scenes (not a point cloud)

I’ll happy if anyone can show a direction on how to go about and which algorithm to use. I am using VTK with python


What do you mean by “plot these points as a scalar scenes”?

If you only have point positions and scalar values at those positions then what you have is a point cloud and you can use various point cloud visualization methods to display it.

If you can also load the full volumetric mesh (all the cell points and their connectivity) into VTK, then you can visualize your data set as a solid object.

Hi Andras,
Thank you for your reply!
I have a csv file like below

CentroidX, CentroidY, CentroidZ, VelocityMagnitude, Cell Type, vtkOriginalIndices, vtkIsSelected, vtkCompositeIndexArray
5 0 0 1 4.54706 0.105832 0.0136055 0
till 190000 rows.

how can I view velocity magnitude scalar? it should not a point cloud, it should be a surface (like scalar scene in commercial CFD packages). I think I will have to interpolate between the points to get the surface (which I am not sure about).

I will really happy if you can direct me on how it can be done?
Just let me know if you want more clarification.

I am unable to upload pictures and data since I am new user.

One option is to find a mesh file format that your FEM software can export to and VTK can read. If there is no such common format then you may use additional software that can convert between different mesh file formats.

Can you share a link to a google drive or dropbox folder with the CSV file, pictures, etc? If so, I can try to rebuild the mesh for you and make an example with PyVista.

Yeah… CSV files are difficult to deal with because the geometries/connectivity between the cells usually aren’t preserved. Your best option is likely to use any format other than a simple table of the data/mesh - I’d bet that the CFD software you are using has some methods for exporting to other formats (any other non-proprietary format would be better than a CSV table)

Hi Bane,
Thanks for the reply.
Here is the csv file.

Hi @shadab_anwar, sorry for the delayed response.

It appears the CSV file you shared is a tabular representation of a VTK dataset… I’d highly recommend that you take a closer look at other formats that your CFD software can export to as the original geometries of your mesh cannot be recovered, only approximated. Also, this is a pretty complicated mesh and triangulating its cell centers is going to mess it up.

With that said… using some open-source Python libraries like PyVista (based on VTK) and pandas, we can triangulate the point-cloud. DO NOTE that the holes in the original mesh are file

import pyvista as pv
import pandas as pd

# Use Pandas to load the CSV file
df = pd.read_csv('exportNonvert.csv')

# Make a PolyData object of the point cloud
spatial_ref = ['CentroidX', 'CentroidY', 'CentroidZ']
names = [n for n in list(df.keys()) if n not in spatial_ref]

# Make the point cloud PolyData
points = pv.PolyData(df[spatial_ref].values)

# Add the scalar arrays to the mesh
for name in names:
    points[name] = df[name].values

# Run a Delaunay 2D filter using the best fitting plane
surface = points.delaunay_2d()

# And plot it
surface.plot(scalars='CentroidMagnitude', cpos='xy', )

HI Bane,

Thanks for the reply,

I did a similar kind of thing using paraview, but this sounds promising. I’ll definitely explore more about pyvista.

And regarding other mesh formats, I am constrained to use csv format since I’ll be doing some post processing on these points and add another column of a property with a scalar value and later visualize it.

Thanks for showing me the direction. Appreciated.