I need a VTK format for my mesh
Hi,I am going to work with Fenics to run my problems. Actually, we should have vtk format for my meshes to run Fenics. There is 2 formats for vtk, one is vtp where it is for surface mesh and another format is vtu for volume mesh. I need a code for exporting my mesh to this formats. And for every surface I need a vtp outcome. For example, if I have 10 surfaces, and one volume, I need a code to give me 11 files, 10 files for each surfaces, and 1 file for my volume. Does it make sense? I could pay for this code who want to write it.
Answers
-
I can make template for that.
Please describe your vtp and vtu formats
If it is not so long, it's free for you!
0 -
what should I describe for you? I need a vtk files which I can easily open them in Paraview.
0 -
Could you give me an example of vtk file?
I think it is a text file that has node coordinates, element definition, isn't it?
0 -
I will attach some vtk file that you can easily open it in text file and paraview. . the vtu is volume and the vtp is one of my surfaces.
0 -
Is this you mentioning?
http://www.earthmodels.org/software/vtk-and-paraview/vtk-file-formats
0 -
yes thats it.
0 -
OK. let's have a look
I think the template will be simple.
just I am trying to understand its format, where is node coodinate, node id, element nodes,...etc
0 -
-
yes thats it
0 -
-
-
no there are tetrahedral. and I myself cannot find out the what rangemin is. I am asking my professor to answer me.
0 -
-
-
this is the surface and the volume mesh that i can see in paraview
0 -
that surface is one of my surfaces.
0 -
I see,
so the surface is formed by triangle elements? and each of them has 6 node (3 vertices and 3 mid-points)?
it is tria6 element type in Hypermesh, isn't it?
0 -
Yes it is triangle, and No, my mesh does not have middle point
0 -
-
I think we need to couple template with some tcl codes
because the format is not suitable to be output by pure template...
0 -
-
oh no, that was my problem too
0 -
I found it,
the offset field will define type of poly, if it is shifted by 3 => it is triangle element
But I am stuck with connectivity field, it doesn't refer to global node ids but indices
and searching how can we generate the indices
0 -
Hi,
I wrote it. Below proc will help to export vtp, a template is not neccessary.
example running it from command window of hypermesh:
p_Export2DToVtpFile MyModel.vtp all; #export all 2d elems
p_Export2DToVtpFile MyModel.vtp displayed; #export only displayed 2d elems
proc p_Export2DToVtpFile {FilePath {displayed_or_all displayed}} { *createmark elems 1 $displayed_or_all *createmark elems 2 'by config' tria3 quad4 tria6 quad8 *markintersection elems 1 elems 2 set ElemList [hm_getmark elems 1] set ElemNodeList [join [hm_getvalue elems mark=1 dataname=nodes]] set ElemNodeCount [join [hm_getvalue elems mark=1 dataname=nodecount]] set CompList [hm_getvalue elems mark=1 dataname=collector.id] eval *createmark nodes 1 $ElemNodeList set NodeList [hm_getmark nodes 1] set CoordList [join [hm_getvalue nodes mark=1 dataname=coordinates]] set _NodeList [lsort -integer $NodeList] set MinNodeId [lindex $_NodeList 0] set MaxNodeId [lindex $_NodeList end] set _ElemList [lsort -integer $ElemList] set MinElemId [lindex $_ElemList 0] set MaxElemId [lindex $_ElemList end] set NodeCount [llength $NodeList] set ElemCount [llength $ElemList] set Buffer {<VTKFile type='PolyData' version='1.0' byte_order='LittleEndian' header_type='UInt64'>} append Buffer \n { <PolyData>} append Buffer \n { <Piece NumberOfPoints='NodeCount' NumberOfPolys='ElemCount'>} append Buffer \n { <PointData Scalars='GlobalNodeID'>} append Buffer \n { <DataArray type='Int32' Name='GlobalNodeID' format='ascii' RangeMin='MinNodeId' RangeMax='MaxNodeId'>} set Buffer [string map [list NodeCount $NodeCount ElemCount $ElemCount MinNodeId $MinNodeId MaxNodeId $MaxNodeId] $Buffer] append Buffer \n $NodeList append Buffer \n { </DataArray>} append Buffer \n { </PointData>} append Buffer \n { <CellData Scalars='ModelFaceID'>} append Buffer \n { <DataArray type='Int32' Name='GlobalElementID' format='ascii' } append Buffer 'RangeMin=\'$MinElemId\' RangeMax=\'$MaxElemId\'>' append Buffer \n $ElemList append Buffer \n { </DataArray>} set _CompList [lsort -integer $CompList] set MinCompId [lindex $_CompList 0] set MaxCompId [lindex $_CompList end] append Buffer \n { <DataArray type='Int32' Name='ModelFaceID' format='ascii' } append Buffer 'RangeMin=\'$MinCompId\' RangeMax=\'$MaxCompId\'>' append Buffer \n $CompList append Buffer \n { </DataArray>} append Buffer \n { </CellData>} append Buffer \n { <Points>} set _CoordList [lsort -real $CoordList] set MinCoord [lindex $_CoordList 0] set MaxCoord [lindex $_CoordList end] append Buffer \n { <DataArray type='Float32' Name='Points' NumberOfComponents='3' format='ascii' } append Buffer 'RangeMin=\'$MinCoord\' RangeMax=\'$MaxCoord\'>' append Buffer \n $CoordList append Buffer \n { </DataArray>} append Buffer \n { </Points>} append Buffer \n { <Polys>} append Buffer \n { <DataArray type='Int64' Name='connectivity' format='ascii' } append Buffer 'RangeMin=\'$MinNodeId\' RangeMax=\'$MaxNodeId\'>' #append Buffer \n $ElemNodeList; #oh, it doesn't refer to global node ids but indices set i -1 foreach NodeId $NodeList { set Index($NodeId) [incr i] } set Indices {} foreach NodeId $ElemNodeList { lappend Indices $Index($NodeId) } append Buffer \n $Indices append Buffer \n { </DataArray>} set Offsets {} set InitOffset 0 foreach NodeCount $ElemNodeCount { lappend Offsets [incr InitOffset $NodeCount] } set MinOffset [lindex $Offsets 0] set MaxOffset [lindex $Offsets end] append Buffer \n { <DataArray type='Int64' Name='offsets' format='ascii' } append Buffer 'RangeMin=\'$MinOffset\' RangeMax=\'$MaxOffset\'>' append Buffer \n $Offsets append Buffer \n { </DataArray>} append Buffer \n { </Polys>} append Buffer \n { </Piece>} append Buffer \n { </PolyData>} append Buffer \n {</VTKFile>} *clearmark nodes 1 *clearmark elems 1 *clearmark elems 2 set fpt [open $FilePath w] #fconfigure $fpt -encoding utf-8 puts $fpt $Buffer close $fpt set FilePath }
0 -
Thank you so much, it helped me alot, but what about the volume mesh which has vtu format?
0 -
Do it your self, base on my script
0 -
thank you so muchh.
0 -
Hello @, first of all thank you very much for your work, I know this is very late but I really need to export a surface mesh to VTK and I can't seem to get your script to work, I have copied the script you pasted, pasted it onto a notepad and saved it with a .tcl extension.
I have opened it with HyperMath and have separated all the lines, I am uploading the result here (I have uploaded it with a .txt extension so that it will allow me to upload it).
I have then tried to run the command you posted on the command view of Hypermesh (making sure I was in the correct folder) while my mesh was open, but I get the error "hm_getvalue: Mark is empty."
Am I missing any steps? Is the file I uploaded correctly modified? Is the extension .tcl ok or does it need to have a different extension?. Thank you very much for your help.
0 -