CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (http://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   How to visualize polyhedron mesh in paraview (http://www.cfd-online.com/Forums/openfoam-pre-processing/130861-how-visualize-polyhedron-mesh-paraview.html)

gejiabin March 5, 2014 08:21

How to visualize polyhedron mesh in paraview
 
Recently,I use the "polyDualMesh" to produce polyhedron mesh,then I visualize it in paraview by "foamToVTK".But the "foamToVTK" decomposes the
Polyhedra into pramid type.paraFoam is not work on my computer and I have to use foamToVTK for post-processing

gejiabin March 7, 2014 04:59

python solution
 
I have one solution.Since I need only to observe polymesh,I convert the openfoam mesh format to paraview unstructed grid format .vtk using python.
It is tedious,is there any more simple way?

#!/usr/bin/vtkpython
datapath_read_points="constant/polyMesh/points"
datapath_read_faces="constant/polyMesh/faces"
datapath_write="VTK/1.vtk"

file_read_points=open(datapath_read_points,'r')
file_read_faces=open(datapath_read_faces,'r')
file_write=open(datapath_write,'w')
#----------------------------------------------------
#Header
file_write.write("# vtk DataFile Version 3.1\n" )
file_write.write("Visualization for polyMesh\n" )
file_write.write("ASCII\n" )
file_write.write("DATASET UNSTRUCTURED_GRID\n" )

#----------------------------------------------------

l_points=file_read_points.readlines()
numPoints=l_points[18]
numPoints=numPoints.replace("\n"," ")
file_write.write("POINTS " + numPoints + "float\n" )
for line in l_points[20:20+int(numPoints)]:
line=line.replace("(","")
line=line.replace(")","")
file_write.write(line)

#----------------------------------------------------
l_cells_=file_read_faces.readlines()
numCells=l_cells_[18]
numCells=numCells.replace("\n"," ")
#------------------------------------------
l_cells_=l_cells_[20:]

while l_cells_[-1]!=')\n':
l_cells_.pop()

l_cells=[]
for line in l_cells_:

if line=="(\n":
l_cells[-1]+="("
continue

if line==")\n":
l_cells[-1]+=")\n"
continue

if line=="\n":
l_cells.append("")
continue

if len( line.split('(') )>1:
l_cells.append(line)
continue

if len(l_cells)==0:
l_cells.append(line.replace("\n"," "))
continue

l_cells[-1]+=line.replace("\n"," ")

#------------------------------------------
numSize=0;
for line in l_cells:
if line=="":
continue
line=line.split('(');
numSize+=int(line[0])+1;

file_write.write("CELLS " + numCells + str(numSize) +"\n")
for line in l_cells:
if line=="":
continue
line=line.replace("("," ")
line=line.replace(")","")
file_write.write(line)

#----------------------------------------------------
file_write.write("CELL_TYPES "+numCells + "\n" )
file_write.write("7 "*int(numCells))

file_read_points.close()
file_read_faces.close()
file_write.close()
#----------------------------------------------------

akrasemann March 7, 2014 09:09

I'm not sure weather this helps, but I had difficulties displaying a polyhedral mesh created by enGrid. If your problem is displaying, the following might help:

wyldckat pointed out to me in this post http://www.cfd-online.com/Forums/engrid/128987-exporting-mesh-openfoam-chtmultiregion-case.html#post471822 that one has to tick the check box "Use VTKPolyhedron" to display the mesh properly.


All times are GMT -4. The time now is 12:41.