I have a CSV file with stress data and geometry that I have exported from ANSYS Mechanical that I would like to visualize in Paraview. Each node has a bunch of stress data related to it. I managed import the points as a point cloud in Paraview but I want to recreate the ANSYS mesh as well. I thought that "programable source" in Paraview could be an alternative way and with some googleing I could probably figure out how to read the data in to numpy arrays but the fundamental question is, how can I create mesh in programable source in Paraview from points and cells/faces?
My CSV file looks something like this:
Node, X, Y, Z, Stress_data
1, 1.0, 1.0, 1.0, 123
2, 2.0, 2.0, 2.0, 234
3, 3.0, 3.0, 3.0, 345
...
Faces
1, 2, 3
3, 4, 5
...
Update
Here is a link to an example csv file (connectivity column included), how the mesh looks in Ansys, how the mesh looks in Paraview and an slightly modified script.
The following python script creates a polydata object from your csv-file and writes it to a file, that can be read in paraview:
import vtk
f = open('Example-2.csv')
pd = vtk.vtkPolyData()
points = vtk.vtkPoints()
cells = vtk.vtkCellArray()
connectivity = vtk.vtkIntArray()
connectivity.SetName('Connectivity')
stress = vtk.vtkFloatArray()
stress.SetName('Stress')
line = f.readline()
for line in iter(lambda: f.readline(), ""):
if 'Faces' in line:
break
v = line.split(',')
points.InsertNextPoint(float(v[1]),
float(v[2]),
float(v[3]))
stress.InsertNextTuple1(float(v[5]))
connectivity.InsertNextTuple1(float(v[4]))
for line in iter(lambda: f.readline(), ""):
v = line.split(',')
cell = vtk.vtkTriangle()
Ids = cell.GetPointIds()
for kId in range(len(v)):
Ids.SetId(kId,int(v[kId]))
cells.InsertNextCell(cell)
f.close()
pd.SetPoints(points)
pd.SetPolys(cells)
pd.GetPointData().AddArray(stress)
pd.GetPointData().AddArray(connectivity)
writer = vtk.vtkXMLPolyDataWriter()
writer.SetFileName('Example-2.vtp')
writer.SetInputData(pd)
writer.Write()
Or you could use a programmable filter on your csv-file (see here). This way I'm not sure how to feed node and face data into separate objects.