[cig-commits] r13188 - in cs/cigma/trunk/tests/data: brick1 brick2
luis at geodynamics.org
luis at geodynamics.org
Wed Oct 29 15:12:15 PDT 2008
Author: luis
Date: 2008-10-29 15:12:14 -0700 (Wed, 29 Oct 2008)
New Revision: 13188
Added:
cs/cigma/trunk/tests/data/brick1/brick1.py
cs/cigma/trunk/tests/data/brick2/brick2.py
Log:
Export .exo meshes to other formats
Added: cs/cigma/trunk/tests/data/brick1/brick1.py
===================================================================
--- cs/cigma/trunk/tests/data/brick1/brick1.py (rev 0)
+++ cs/cigma/trunk/tests/data/brick1/brick1.py 2008-10-29 22:12:14 UTC (rev 13188)
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+
+from __future__ import with_statement
+
+import numpy
+from Scientific.IO.NetCDF import NetCDFFile
+import tables
+import pyvtk
+
+def main():
+
+ #
+ # Read data from exodusII file
+ #
+ fp = NetCDFFile('brick1.exo','r')
+
+ nno = fp.dimensions['num_nodes']
+ nsd = fp.dimensions['num_dim']
+
+ nel = fp.dimensions['num_elem']
+ ndofs = fp.dimensions['num_nod_per_el1']
+
+ coord = numpy.array(fp.variables['coord']).T
+ connect = numpy.array(fp.variables['connect1'])
+ connect -= 1
+
+ fp.close()
+
+ #
+ # Write mesh data to simple text files
+ #
+ with open('brick1_coords.dat', 'w') as f:
+ f.write('%d %d\n' % (nno,nsd))
+ for n in xrange(nno):
+ f.write('%g %g %g\n' % tuple(coord[n]))
+ print 'Wrote', f.name
+
+ with open('brick1_connect.dat', 'w') as f:
+ f.write('%d %d\n' % (nel,ndofs))
+ for e in xrange(nel):
+ for i in xrange(ndofs):
+ f.write(' %d' % connect[e,i])
+ f.write('\n')
+ print 'Wrote', f.name
+
+ #
+ # Write mesh data to HDF5
+ #
+ h5 = tables.openFile('brick1.h5', 'w')
+ h5.createArray('/', 'coordinates', coord)
+ h5.createArray('/', 'connectivity', connect)
+ print 'Wrote', h5.filename
+ h5.close()
+
+ #
+ # Write mesh data to vtk
+ #
+ from pyvtk import VtkData, UnstructuredGrid, PointData, Scalars
+ points = [tuple(pt) for pt in coord]
+ cells = [tuple(cell) for cell in connect]
+ scalars = Scalars(numpy.zeros(nno), name='zeros', lookup_table='default')
+ grid = UnstructuredGrid(points, hexahedron=cells)
+ vtk = VtkData(grid, PointData(scalars), 'Brick meshed with hex8 elements')
+ vtk.tofile('brick1.vtk')
+ print 'Wrote brick1.vtk'
+
+ return 0
+
+if __name__ == '__main__':
+ main()
Property changes on: cs/cigma/trunk/tests/data/brick1/brick1.py
___________________________________________________________________
Name: svn:executable
+ *
Added: cs/cigma/trunk/tests/data/brick2/brick2.py
===================================================================
--- cs/cigma/trunk/tests/data/brick2/brick2.py (rev 0)
+++ cs/cigma/trunk/tests/data/brick2/brick2.py 2008-10-29 22:12:14 UTC (rev 13188)
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+
+from __future__ import with_statement
+
+import numpy
+import tables
+from Scientific.IO.NetCDF import NetCDFFile
+
+def main():
+
+ #
+ # Read data from exodusII file
+ #
+ fp = NetCDFFile('brick2.exo','r')
+
+ nno = fp.dimensions['num_nodes']
+ nsd = fp.dimensions['num_dim']
+
+ nel = fp.dimensions['num_elem']
+ ndofs = fp.dimensions['num_nod_per_el1']
+
+ coord = numpy.array(fp.variables['coord']).T
+ connect = numpy.array(fp.variables['connect1'])
+ connect -= 1
+
+ fp.close()
+
+ #
+ # Write mesh data to simple text files
+ #
+ with open('brick2_coords.dat', 'w') as f:
+ f.write('%d %d\n' % (nno,nsd))
+ for n in xrange(nno):
+ f.write('%g %g %g\n' % tuple(coord[n]))
+ print 'Wrote', f.name
+
+ with open('brick2_connect.dat', 'w') as f:
+ f.write('%d %d\n' % (nel,ndofs))
+ for e in xrange(nel):
+ for i in xrange(ndofs):
+ f.write(' %d' % connect[e,i])
+ f.write('\n')
+ print 'Wrote', f.name
+
+ #
+ # Write mesh data to HDF5
+ #
+ h5 = tables.openFile('brick2.h5', 'w')
+ h5.createArray('/', 'coordinates', coord)
+ h5.createArray('/', 'connectivity', connect)
+ print 'Wrote', h5.filename
+ h5.close()
+
+ #
+ # Write mesh data to vtk
+ #
+ from pyvtk import VtkData, UnstructuredGrid, PointData, Scalars
+ points = [tuple(pt) for pt in coord]
+ cells = [tuple(cell) for cell in connect]
+ scalars = Scalars(numpy.zeros(nno), name='zeros', lookup_table='default')
+ grid = UnstructuredGrid(points, tetra=cells)
+ vtk = VtkData(grid, PointData(scalars), 'Brick meshed with tet4 elements')
+ vtk.tofile('brick2.vtk')
+ print 'Wrote brick2.vtk'
+
+ return 0
+
+if __name__ == '__main__':
+ main()
Property changes on: cs/cigma/trunk/tests/data/brick2/brick2.py
___________________________________________________________________
Name: svn:executable
+ *
More information about the CIG-COMMITS
mailing list