Jump to content
Sign in to follow this  
rsoltany

I need a VTK format for my mesh

Recommended Posts

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. 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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
}

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...