File: XdmfExampleWrite.py

package info (click to toggle)
xdmf 3.0%2Bgit20160803-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 35,388 kB
  • ctags: 36,627
  • sloc: ansic: 265,382; cpp: 162,889; python: 10,976; f90: 1,378; yacc: 687; fortran: 464; xml: 200; java: 187; lex: 125; makefile: 82; sh: 28
file content (196 lines) | stat: -rw-r--r-- 9,663 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
from Xdmf import *

if __name__ == "__main__":
        primaryDomain = XdmfDomain.New()
        domaininfo = XdmfInformation.New("Domain", "This is the primary data structure in Xdmf")
        domaininfoinfo = XdmfInformation.New("Information", "Information can have information")
        domaininfo.insert(domaininfoinfo)
        primaryDomain.insert(domaininfo)

        gridHolder = XdmfGridCollection.New()
        gridHolder.setType(XdmfGridCollectionType.Spatial())
        holderInfo = XdmfInformation.New("Grid Collection 1", "This is the main grid collection")
        gridHolder.insert(holderInfo)
        gridHolder.setName("GridCollection Example")


        ungrid = XdmfUnstructuredGrid.New()
        ungrid.setName("Unstructured Grid Example")
        untime = XdmfTime.New(5.0)
        untimeinfo = XdmfInformation.New("Time", "This is the time for the Unstructured Grid")
        untime.insert(untimeinfo)
        ungrid.setTime(untime)
        unglobalID = XdmfAttribute.New()
        unglobalID.setType(XdmfAttributeType.GlobalId())
        unglobalID.setCenter(XdmfAttributeCenter.Node())
        unglobalID.setName("Global Node Equivalencies")
        task1globalnodes = [1, 4, 5, 7, 3, 6]
        unglobalID.insertAsInt32(0, task1globalnodes)
        unglobalIDinfo = XdmfInformation.New("Global Nodes", "This is the global nodes that accociate with the local nodes")
        ungrid.insert(unglobalID)
        unset = XdmfSet.New()
        unsetinfo = XdmfInformation.New("Data Set", "This is a set of arbitrary data")
        unset.insert(unsetinfo)
        unset.setName("Unstructured Grid's Set")
        unset.setType(XdmfSetType.Node())
        unsetattribute = XdmfAttribute.New()
        unsetattribute.setType(XdmfAttributeType.Scalar())
        unsetattribute.setCenter(XdmfAttributeCenter.Node())
        unsetattribute.setName("The Set's attribute")
        unsetattribdata = [1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1]
        unsetattribute.insertAsFloat64(0, unsetattribdata)
        unset.insert(unsetattribute)
        unsetdata = [5.1, 4.2, 3.3, 2.4, 1.5]
        unset.insertAsFloat64(0, unsetdata)
        ungrid.insert(unset)
        ungeometry = XdmfGeometry.New()
        ungeometry.setType(XdmfGeometryType.XYZ())
        ungeometry.setName("Unstructured Geometry")
        ungeopoints = [0.1, 0.1, 1.1, 1.1, 0.1, 1.1, 3.1, 0.1, 2.1, 0.1, 1.1, 1.1, 1.1,
                1.1, 1.1, 3.1, 2.1, 2.1, 0.1, 0.1, -1.1, 1.1, 0.1, -1.1, 3.1,
                0.1, -2.1, 0.1, 1.1, -1.1, 1.1, 1.1, -1.1, 3.1, 2.1, -2.1]
        ungeometry.insertAsFloat64(0, ungeopoints)
        ungeometryinfo = XdmfInformation.New("Geometry", "This is the geometry associated with the unstructured grid")
        ungeometry.insert(ungeometryinfo)
        ungrid.setGeometry(ungeometry)
        untopology = XdmfTopology.New()
        untopology.setType(XdmfTopologyType.Hexahedron())
        untopology.setName("Unstructured Topology")
        untopovalues = [0, 1, 7, 6, 3, 4, 10, 9, 1, 2, 8, 7, 4, 5, 11, 10]
        untopology.insertAsInt32(0, untopovalues)
        untopologyinfo = XdmfInformation.New("Topology", "This is the topology associated with the unstructured grid")
        ungrid.setTopology(untopology)


        curvdimensions = XdmfArray.New()
        curvdimensions.pushBackAsInt32(12)
        curvdimensions.pushBackAsInt32(12)
        curvdimensions.pushBackAsInt32(12)
        curvgrid = XdmfCurvilinearGrid.New(curvdimensions)
        curvgrid.setName("Curvilinear Grid Example")
        curvgridinfo = XdmfInformation.New("Curvilinear Grid", "This is an example curvilinear grid")
        curvgrid.insert(curvgridinfo)
        curvtime = XdmfTime.New(5.0)
        curvtimeinfo = XdmfInformation.New("Time", "The Time of the Curvilinear Grid")
        curvtime.insert(curvtimeinfo)
        curvgrid.setTime(curvtime)
        curvglobalID = XdmfAttribute.New()
        curvglobalID.setType(XdmfAttributeType.GlobalId())
        curvglobalID.setCenter(XdmfAttributeCenter.Node())
        curvglobalID.setName("Global Node Equivalencies")
        task2globalnodes = [7, 3, 8, 2, 5, 1]
        curvglobalID.insertAsInt32(0, task1globalnodes)
        curvglobalIDinfo = XdmfInformation.New("Global Node Equivalencies", "These are the global nodes that accociate with the local nodes")
        curvglobalID.insert(curvglobalIDinfo)
        curvgrid.insert(curvglobalID)
        curvgeometry = XdmfGeometry.New()
        curvgeometry.setType(XdmfGeometryType.XYZ())
        curvgeometry.setName("Curvilinear Geometry")
        curvgeopoints = [1.1, 1.1, 2.1, 2.1, 1.1, 2.1, 4.1, 1.1, 3.1, 1.1, 2.1, 2.1, 2.1,
                2.1, 2.1, 4.1, 3.1, 3.1, 1.1, 1.1, 0.1, 2.1, 1.1, 0.1, 4.1,
                1.1, -1.1, 1.1, 2.1, 0.1, 1.1, 2.1, -0.1, 4.1, 3.1, -1.1]
        curvgeometry.insertAsFloat64(0, curvgeopoints)
        curvgeometryinfo = XdmfInformation.New("Geometry", "The geometry of the curvilinear grid")
        curvgeometry.insert(curvgeometryinfo)
        curvgrid.setGeometry(curvgeometry)


        rectXcoordinates = [1.1, 1.1, 2.1, 2.1, 1.1, 2.1, 4.1, 1.1, 3.1, 1.1, 2.1, 2.1]
        rectYcoordinates = [2.1, 2.1, 2.1, 4.1, 3.1, 3.1, 1.1, 1.1, 0.1, 2.1, 1.1, 0.1]
        rectZcoordinates = [4.1, 1.1, -1.1, 1.1, 2.1, 0.1, 1.1, 2.1, -0.1, 4.1, 3.1, -1.1]
        rectXarray = XdmfArray.New()
        rectXarray.insertAsFloat64(0, rectXcoordinates)
        rectYarray = XdmfArray.New()
        rectYarray.insertAsFloat64(0, rectYcoordinates)
        rectZarray = XdmfArray.New()
        rectZarray.insertAsFloat64(0, rectZcoordinates)
        coordinatecontainer = ArrayVector()
        coordinatecontainer.push_back(rectXarray)
        coordinatecontainer.push_back(rectYarray)
        coordinatecontainer.push_back(rectZarray)
        rectgrid = XdmfRectilinearGrid.New(coordinatecontainer)
        rectgrid.setName("Rectilinear Grid Example")
        rectgridinfo = XdmfInformation.New("Rectilinear Grid", "This is an example of a rectilinear grid")
        rectglobalID = XdmfAttribute.New()
        rectglobalID.setType(XdmfAttributeType.GlobalId())
        rectglobalID.setCenter(XdmfAttributeCenter.Node())
        rectglobalID.setName("Global Node Equivalencies")
        task3globalnodes = [2, 7, 9, 0, 8, 6]
        rectglobalID.insertAsInt32(0, task3globalnodes)
        rectglobalIDinfo = XdmfInformation.New("Global Node Equivalencies", "These are the global nodes that associate with the local nodes")
        rectglobalID.insert(rectglobalIDinfo)
        recttime = XdmfTime.New(5.0)
        recttimeinfo = XdmfInformation.New("Time", "The time of the rectiliniear grid")
        recttime.insert(recttimeinfo)
        rectgrid.setTime(recttime)
        rectgrid.insert(rectglobalID)

        regbrick = XdmfArray.New()
        regbrickvals = [10, 10, 10]
        regbrick.insertAsFloat64(0, regbrickvals)
        regdimensions = XdmfArray.New()
        regdimensionvals = [5, 5, 5]
        regdimensions.insertAsInt32(0, regdimensionvals)
        regorigin = XdmfArray.New()
        regoriginvals = [0, 0, 0]
        regorigin.insertAsFloat64(0, regoriginvals)
        reggrid = XdmfRegularGrid.New(regbrick, regdimensions, regorigin)
        reggrid.setName("Regular Grid Example")
        reggridinfo = XdmfInformation.New("Regular Grid", "This is an example of a regular grid")
        regtime = XdmfTime.New(5.0)
        regtimeinfo = XdmfInformation.New("Time", "This is the time for the regular grid")
        reggrid.setTime(regtime)
        regglobalID = XdmfAttribute.New()
        regglobalID.setType(XdmfAttributeType.GlobalId())
        regglobalID.setCenter(XdmfAttributeCenter.Node())
        regglobalID.setName("Global Node Equivalencies")
        task4globalnodes = [3, 6, 1, 4, 2, 5, 9]
        regglobalID.insertAsInt32(0, task4globalnodes)
        regglobalIDinfo = XdmfInformation.New("Global Node Equivalencies", "These are the global nodes that associate with the local nodes")
        reggrid.insert(regglobalID)

        nodeholder = AttributeVector()
        nodeholder.push_back(unglobalID)
        nodeholder.push_back(curvglobalID)
        nodeholder.push_back(rectglobalID)
        nodeholder.push_back(regglobalID)
        mapcollection = XdmfMap.New(nodeholder)

        ungrid.insert(mapcollection[0])
        curvgrid.insert(mapcollection[1])
        rectgrid.insert(mapcollection[2])
        reggrid.insert(mapcollection[3])

        '''
        the version of XdmfMap.New used here returns a number of maps equal to the number of attributes it was provided with.
        '''
        for insertedmap in mapcollection:
                gridHolder.insert(insertedmap)

        gridHolder.insert(ungrid)
        gridHolder.insert(curvgrid)
        gridHolder.insert(rectgrid)
        gridHolder.insert(reggrid)

        secondaryHolder = XdmfGridCollection.New()
        secondaryHolder.setName("Secondary grid collection")
        gridHolder.insert(secondaryHolder)
        '''
        grid collections can be placed inside other grid collections
        '''

        primaryDomain.insert(gridHolder)
        '''
        grids can be inserted into the domain in the same way as the grid collection
        '''
        primaryDomain.insert(ungrid)
        primaryDomain.insert(curvgrid)
        primaryDomain.insert(rectgrid)
        primaryDomain.insert(reggrid)

        exampleHeavyWriter = XdmfHDF5Writer.New("testoutput.h5")
        exampleWriter = XdmfWriter.New("testoutput.xmf", exampleHeavyWriter)

        primaryDomain.accept(exampleHeavyWriter)
        exampleHeavyWriter.setMode(XdmfHeavyDataWriter.Overwrite)
        primaryDomain.accept(exampleWriter)