从Paraview中的像元和点创建网格 [英] Create mesh from cells and points in Paraview

查看:793
本文介绍了从Paraview中的像元和点创建网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CSV文件,其中包含我想在Paraview中可视化的应力数据和几何形状,这些数据是从ANSYS Mechanical中导出的.每个节点都有一堆与之相关的应力数据.我在Paraview中设法将点导入为点云,但我也想重新创建ANSYS网格.我认为Paraview中的可编程源"可能是一种替代方法,并且通过谷歌搜索,我可能会弄清楚如何将数据读取到numpy数组中,但是基本的问题是,如何在Paraview中的可编程源中从点创建网格和细胞/面部? 我的CSV文件如下所示:

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
...

更新
此处是一个示例csv文件(包括连接性列)的链接,该网格在Ansys中的外观如何,网格在Paraview和经过稍微修改的脚本中的外观.

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.

推荐答案

以下python脚本从csv文件创建一个polydata对象并将其写入文件,该文件可以在paraview中读取:

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()

或者您可以在csv文件上使用可编程过滤器(请参见此处).这样我不确定如何将节点和面数据馈送到单独的对象中.

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.

这篇关于从Paraview中的像元和点创建网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆