Write Xdmf

From XdmfWeb
Revision as of 13:30, 23 January 2009 by Jerry (talk | contribs)
Jump to navigationJump to search

Writing Xdmf

Xdmf can be generated in many different manners. Using the low level HDF5 library and print statements is certainly one of them. Utilizing the XDMF API, however, provides some convenient advantages. Suppose we wanted to generate an XDMF dataset of a co-rectilinear mesh with scalar values at each node

from Xdmf import *

d = XdmfDOM() 

root = XdmfRoot()
root.SetVersion(2.2) # Change the Version number because we can
# Information
i = XdmfInformation() # Arbitrary Name=Value Facility
root.Insert(i) # XML DOM is used as the keeper of the structure
              # Insert() creates an XML node and inserts it under
              # the parent
# Domain
dm = XdmfDomain()
# Grid
g = XdmfGrid()
g.SetName("Structured Grid")
# Topology
t = g.GetTopology()
t.GetShapeDesc().SetShapeFromString('10 20 30')
# Geometry
geo = g.GetGeometry()
geo.SetOrigin(1, 2, 3)
geo.SetDxDyDz(0.1, 0.2, 0.3)
# Attribute
attr = XdmfAttribute()
p = attr.GetValues()
p.SetShapeFromString("10 20 30")
p.Generate(0.0, 1.0, 0, p.GetNumberOfElements() - 1)
# Update XML and Write Values to DataItems
root.Build() # DataItems > 100 values are heavy
print d.Serialize() # prints to stdout 

d.Write('SMesh.xmf') # write to file

Would result in the Light Data XML to be written to the file Smesh.xmf and the Heavy data to be written to Xdmf.h5.

<?xml version="1.0" ?>
<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>
<Xdmf xmlns:xi="http://www.w3.org/2003/XInclude" Version="2.2">
 <Information Name="SampleLocation" Value="4"/>
   <Grid Name="Structured Grid" GridType="Uniform">
     <Topology TopologyType="3DCORECTMesh" NumberOfElements="10 20 30 "/>
     <Geometry GeometryType="ORIGIN_DXDYDZ">
       <DataItem Dimensions="3 " NumberType="Float" Precision="4" Format="XML">
          1 2 3
       <DataItem Dimensions="3 " NumberType="Float" Precision="4" Format="XML">
        0.1 0.2 0.3
     <Attribute Name="Pressure" AttributeType="Scalar" Center="Cell">
       <DataItem Dimensions="6000 " NumberType="Float" Precision="4" Format="HDF">Xdmf.h5:/Data</DataItem>