[MOAB-dev] r2920 - MOAB/trunk/tools/iMesh/python/itaps

jvporter at wisc.edu jvporter at wisc.edu
Mon Jun 1 11:48:30 CDT 2009


Author: jvporter
Date: 2009-06-01 11:48:29 -0500 (Mon, 01 Jun 2009)
New Revision: 2920

Added:
   MOAB/trunk/tools/iMesh/python/itaps/helpers.py
Log:
Forgot to commit helper file


Added: MOAB/trunk/tools/iMesh/python/itaps/helpers.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/itaps/helpers.py	                        (rev 0)
+++ MOAB/trunk/tools/iMesh/python/itaps/helpers.py	2009-06-01 16:48:29 UTC (rev 2920)
@@ -0,0 +1,37 @@
+class AdjacencyList:
+    def __init__(self, adj, offsets):
+        self.adj = adj
+        self.offsets = offsets
+
+    def __getitem__(self, key):
+        if isinstance(key, tuple):
+            if self.length(key[0]) <= key[1]:
+                raise IndexError
+            return self.adj[ self.offsets[key[0]] + key[1] ]
+        else:
+            return self.adj[ self.offsets[key]:self.offsets[key+1] ]
+
+    def length(self, i):
+        return self.offsets[i+1] - self.offsets[i]
+
+
+class IndexedAdjacencyList:
+    def __init__(self, entities, adj, indices, offsets):
+        self.entities = entities
+        self.adj = adj
+        self.indices = indices
+        self.offsets = offsets
+
+    def __getitem__(self, key):
+        return self.adj[ self.index(key) ]
+
+    def index(self, key):
+        if isinstance(key, tuple):
+            if self.length(key[0]) <= key[1]:
+                raise IndexError
+            return self.indices[ self.offsets[key[0]] + key[1] ]
+        else:
+            return self.indices[ self.offsets[key]:self.offsets[key+1] ]
+
+    def length(self, i):
+        return self.offsets[i+1] - self.offsets[i]



More information about the moab-dev mailing list