[cig-commits] r13988 - in cs/cigma/trunk/examples: . utils utils/triangle

luis at geodynamics.org luis at geodynamics.org
Wed Jan 28 09:05:21 PST 2009


Author: luis
Date: 2009-01-28 09:05:21 -0800 (Wed, 28 Jan 2009)
New Revision: 13988

Added:
   cs/cigma/trunk/examples/utils/
   cs/cigma/trunk/examples/utils/triangle/
   cs/cigma/trunk/examples/utils/triangle/README
   cs/cigma/trunk/examples/utils/triangle/square.py
   cs/cigma/trunk/examples/utils/triangle/square.sh
Log:
Use Triangle mesh generator for discretizing a square domain with both linear and quadratic triangular elements.

Added: cs/cigma/trunk/examples/utils/triangle/README
===================================================================
--- cs/cigma/trunk/examples/utils/triangle/README	                        (rev 0)
+++ cs/cigma/trunk/examples/utils/triangle/README	2009-01-28 17:05:21 UTC (rev 13988)
@@ -0,0 +1,4 @@
+
+Triangle: A Two-Dimensional Quality Mesh Generator and Delaunay Triangulator
+http://www.cs.cmu.edu/~quake/triangle.html
+

Added: cs/cigma/trunk/examples/utils/triangle/square.py
===================================================================
--- cs/cigma/trunk/examples/utils/triangle/square.py	                        (rev 0)
+++ cs/cigma/trunk/examples/utils/triangle/square.py	2009-01-28 17:05:21 UTC (rev 13988)
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+
+from __future__ import with_statement
+
+import numpy
+import tables
+
+def read_coords(filename):
+    coords = None
+    with open(filename, 'r') as fp:
+        # read header
+        line = fp.readline()
+        cols = line.split()
+        nno, ndim, natt, nbdr = map(int, cols)
+        coords = numpy.zeros((nno, ndim), dtype=float)
+        # read nodes
+        for n in xrange(nno):
+            line = fp.readline()
+            cols = line.split()
+            i = int(cols[0]) - 1
+            for j in xrange(ndim):
+                coords[i,j] = float(cols[1+j])
+    return coords
+
+def read_connect(filename):
+    connect = None
+    with open(filename, 'r') as fp:
+        # read header
+        line = fp.readline()
+        cols = line.split()
+        nel, ndofs, natt = map(int, cols)
+        connect = numpy.zeros((nel, ndofs), dtype=int)
+        # read elements
+        for e in xrange(nel):
+            line = fp.readline()
+            cols = line.split()
+            i = int(cols[0]) - 1
+            for j in xrange(ndofs):
+                connect[i,j] = int(cols[1+j])
+        connect -= 1
+    return connect
+
+def main():
+
+    h5 = tables.openFile('square.h5', 'w')
+
+    levels = range(1,7);
+    celltypes = {'square1': 'tri3', 'square2': 'tri6'}
+
+    for prefix in ('square1', 'square2'):
+        root = h5.createGroup('/', celltypes[prefix])
+        for r in levels:
+            coords = read_coords('%s.%d.node' % (prefix, r))
+            connect = read_connect('%s.%d.ele' % (prefix, r))
+            group = h5.createGroup(root, 'mesh%d' % r)
+            h5.createArray(group, 'coordinates', coords)
+            h5.createArray(group, 'connectivity', connect)
+            group._v_attrs.CellType = celltypes[prefix]
+
+    print 'Wrote', h5.filename
+    h5.close()
+
+    return 0
+
+if __name__ == '__main__':
+    import sys
+    ret = main()
+    sys.exit(ret)
+


Property changes on: cs/cigma/trunk/examples/utils/triangle/square.py
___________________________________________________________________
Name: svn:executable
   + *

Added: cs/cigma/trunk/examples/utils/triangle/square.sh
===================================================================
--- cs/cigma/trunk/examples/utils/triangle/square.sh	                        (rev 0)
+++ cs/cigma/trunk/examples/utils/triangle/square.sh	2009-01-28 17:05:21 UTC (rev 13988)
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# refine square1
+o="-evn"
+./triangle $o -p square1
+./triangle $o -a0.30 square1.1
+./triangle $o -a0.20 square1.2
+./triangle $o -a0.10 square1.3
+./triangle $o -a0.05 square1.4
+./triangle $o -a0.02 square1.5
+
+# refine square2
+o="-evn -o2"
+./triangle $o -p square2
+./triangle $o -a0.30 square2.1
+./triangle $o -a0.20 square2.2
+./triangle $o -a0.10 square2.3
+./triangle $o -a0.05 square2.4
+./triangle $o -a0.02 square2.5
+


Property changes on: cs/cigma/trunk/examples/utils/triangle/square.sh
___________________________________________________________________
Name: svn:executable
   + *



More information about the CIG-COMMITS mailing list