Read Xdmf: Difference between revisions
From XdmfWeb
Jump to navigationJump to search
(New page: == Reading XDMF Data == Image:TwoHex.jpg The following Xdmf XML file is a simple example of a Uniform Grid that contains two Hexahedron that share a face. There are values centered a...) |
Dave.demarle (talk | contribs) mNo edit summary |
||
Line 62: | Line 62: | ||
The XML is stored in the file "MyGrid.xmf". The following Python program demonstrated parsing the XML and | The XML is stored in the file "MyGrid.xmf". The following Python program demonstrated parsing the XML and | ||
retrieving the data values. | retrieving the data values. | ||
<pre style="color: red">Note this code snippet is from version 2 or 1 and needs updating for xdmf3.</pre> | |||
from Xdmf import * | from Xdmf import * |
Revision as of 14:12, 19 August 2014
Reading XDMF Data
The following Xdmf XML file is a simple example of a Uniform Grid that contains two Hexahedron that share a face. There are values centered at the nodes and at the cell centers. The values for geometry, connectivity, and scalars are all stored directly in the XML file.
<?xml version="1.0" ?> <!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []> <Xdmf> <Domain> <Grid Name="TestGrid"> <Topology Type="Hexahedron" NumberOfElements="2" > <DataItem Format="XML" DataType="Float" Dimensions="2 8"> 0 1 7 6 3 4 10 9 1 2 8 7 4 5 11 10 </DataItem> </Topology> <Geometry Type="XYZ"> <DataItem Format="XML" DataType="Float" Precision="8" Dimensions="4 3 3"> 0.0 0.0 1.0 1.0 0.0 1.0 3.0 0.0 2.0 0.0 1.0 1.0 1.0 1.0 1.0 3.0 2.0 2.0 0.0 0.0 -1.0 1.0 0.0 -1.0 3.0 0.0 -2.0 0.0 1.0 -1.0 1.0 1.0 -1.0 3.0 2.0 -2.0 </DataItem> </Geometry> <Attribute Name="NodeValues" Center="Node"> <DataItem Format="XML" DataType="Float" Precision="8" Dimensions="4 3" > 100 200 300 300 400 500 300 400 500 500 600 700 </DataItem> </Attribute> <Attribute Name="CellValues" Center="Cell"> <DataItem Format="XML" DataType="Float" Precision="8" Dimensions="2" > 100 200 </DataItem> </Attribute> </Grid> </Domain> </Xdmf>
The XML is stored in the file "MyGrid.xmf". The following Python program demonstrated parsing the XML and retrieving the data values.
Note this code snippet is from version 2 or 1 and needs updating for xdmf3.
from Xdmf import * dom = XdmfDOM() dom.Parse('MyGrid.xmf') # We now have a tree. Find the one and only Grid element ge = dom.FindElementByPath('/Xdmf/Domain/Grid') grid = XdmfGrid() grid.SetDOM(dom) grid.SetElement(ge) # Read Light Data grid.UpdateInformation() # Read Heavy Data which includes Topology and Geometry grid.Update() top = grid.GetTopology() conn = top.GetConnectivity() print 'Values = ', conn.GetValues() geo = grid.GetGeometry() points = geo.GetPoints() print 'Geo Type = ', geo.GetGeometryTypeAsString(), ' # Points = ', geo.GetNumberOfPoints() print 'Points = ', points.GetValues() # for each Attribute, print Light Data and Values for i in range(grid.GetNumberOfAttributes()) : attr = grid.GetAttribute(i) print 'Attribute ', i, ' Name = ', attr.Get('Name') # Attribute HeavyData is not Updated by default # there could potentially be many causing huge IO attr.Update() vals = attr.GetValues() print 'Values ', vals.GetValues()