[MOAB-dev] r2921 - in MOAB/trunk/tools/iMesh/python: doc itaps test

jvporter at wisc.edu jvporter at wisc.edu
Mon Jun 1 13:57:10 CDT 2009


Author: jvporter
Date: 2009-06-01 13:57:09 -0500 (Mon, 01 Jun 2009)
New Revision: 2921

Modified:
   MOAB/trunk/tools/iMesh/python/doc/ibase.rst
   MOAB/trunk/tools/iMesh/python/doc/imesh.rst
   MOAB/trunk/tools/iMesh/python/doc/index.rst
   MOAB/trunk/tools/iMesh/python/itaps/helpers.py
   MOAB/trunk/tools/iMesh/python/test/adj.py
Log:
* Minor changes to helpers
* More tests for helpers
* Add helpers documentation
* Fix indexing in documentation


Modified: MOAB/trunk/tools/iMesh/python/doc/ibase.rst
===================================================================
--- MOAB/trunk/tools/iMesh/python/doc/ibase.rst	2009-06-01 16:48:29 UTC (rev 2920)
+++ MOAB/trunk/tools/iMesh/python/doc/ibase.rst	2009-06-01 18:57:09 UTC (rev 2921)
@@ -4,8 +4,11 @@
 
 .. module:: itaps.iBase
 
-.. class:: itaps.iBase.Type
+Type
+====
 
+.. class:: Type
+
    An enumeration of entity types corresponding to ``iBase_EntityType``.
 
    .. data:: vertex
@@ -29,8 +32,11 @@
       Allows the user to request information about all the types
 
 
-.. class:: itaps.iBase.AdjCost
+AdjCost
+=======
 
+.. class:: AdjCost
+
    An enumeration of entity types corresponding to ``iBase_AdjacencyCost``.
 
    .. data:: unavailable
@@ -62,8 +68,11 @@
       Only some adjacency info, exhaustive
 
 
-.. class:: itaps.iBase.StorageOrder
+StorageOrder
+============
 
+.. class:: StorageOrder
+
    An enumeration of entity types corresponding to ``iBase_StorageOrder``.
 
    .. data:: interleaved
@@ -76,8 +85,11 @@
       ...]``.
 
 
-.. class:: itaps.iBase.CreationStatus
+CreationStatus
+==============
 
+.. class:: CreationStatus
+
    An enumeration of entity types corresponding to ``iBase_CreationStatus``.
 
    .. data:: new

Modified: MOAB/trunk/tools/iMesh/python/doc/imesh.rst
===================================================================
--- MOAB/trunk/tools/iMesh/python/doc/imesh.rst	2009-06-01 16:48:29 UTC (rev 2920)
+++ MOAB/trunk/tools/iMesh/python/doc/imesh.rst	2009-06-01 18:57:09 UTC (rev 2921)
@@ -4,8 +4,11 @@
 
 .. module:: itaps.iMesh
 
-.. class:: itaps.iMesh.Mesh([options])
+Mesh
+====
 
+.. class:: Mesh([options])
+
    Return a new ``Mesh`` object with any implementation-specific options
    defined in ``options``.
 
@@ -93,46 +96,39 @@
 
       Get entities of the specified type adjacent to elements of ``entities``.
       If ``entities`` is a single entity handle, returns an array of adjacent
-      entities.
+      entities. If ``entities`` is an array of entities, return an
+      :class:`~itaps.helpers.AdjacencyList` instance.
 
-      If ``entities`` is an array of entities, returns a tuple type, with the
-      first element being an array of offsets into the second element such that
-      ``ret[0][ ret[1][i]:ret[1][i+1] ]`` is a list of entities adjacent to
-      ``entities[i]``.
-
       :param entities: Entity or array of entities being queried
       :param typeReq: Type of adjacent entities being requested
       :return: If ``entities`` is a single element, an array of adjacent
-               entities. Otherwise, a tuple containing an array of offsets and
-               an array of adjacent entities.
+               entities. Otherwise, an :class:`~itaps.helpers.AdjacencyList`
+               instance.
 
    .. method:: getEnt2ndAdj(entities, bridgeType, typeReq)
 
       Get "2nd order" adjacencies to an array of entities, that is, from each 
       entity, through other entities of a specified "bridge" dimension, to
       other entities of another specified "to" dimension. If ``entities`` is a
-      single entity handle, returns an array of adjacent entities.
+      single entity handle, returns an array of adjacent entities. If 
+      ``entities`` is an array of entities, return an
+      :class:`~itaps.helpers.AdjacencyList` instance.
 
-      If ``entities`` is an array of entities, returns a tuple type, with the
-      first element being an array of offsets into the second element such that
-      ``ret[0][ ret[1][i]:ret[1][i+1] ]`` is a list of entities adjacent to
-      ``entities[i]``.
-
       :param entities: Entity or array of entities being queried
       :param brideType: Type of bridge entity for 2nd order adjacencies
       :param typeReq: Type of adjacent entities being requested
       :return: If ``entities`` is a single element, an array of adjacent
-               entities. Otherwise, a tuple containing an array of offsets and
-               an array of adjacent entities.
+               entities. Otherwise, an :class:`~itaps.helpers.AdjacencyList`
+               instance.
 
    .. method:: createEntSet(isList)
 
-      Create an entity set, either ordered (``isList == True``) or unordered 
-      (``isList == False``). Unordered entity sets can contain a given entity
-      or set only once.
+      Create an :class:`EntitySet`, either ordered (``isList == True``) or
+      unordered (``isList == False``). Unordered entity sets can contain a
+      given entity or set only once.
 
       :param isList: True if the list should be ordered, false otherwise
-      :return: The newly-created entity set
+      :return: The newly-created :class:`EntitySet`
 
    .. method:: destroyEntSet(entSet)
 
@@ -185,9 +181,9 @@
 
    .. method:: createTag(name, size, type)
 
-      Create a tag with specified ``name``, ``size``, and ``type``. The tag
-      size is the number of values of type ``type`` that can be held. ``type``
-      is one of the following:
+      Create a :class:`Tag` with specified ``name``, ``size``, and ``type``.
+      The tag's ``size`` is the number of values of type ``type`` that can be
+      held. ``type`` is one of the following:
 
       +-------+---------------+
       | ``i`` | Integer       |
@@ -202,15 +198,16 @@
       :param name: Tag name
       :param size: Size of tag in number of values
       :param type: Character representing the tag's type
-      :return: The created tag
+      :return: The created :class:`Tag`
 
    .. method:: destroyTag(tag, forced)
 
-      Destroy a tag. If ``forced`` is true and entities still have values set
-      for this tag, the tag is deleted anyway and those values disappear.
-      Otherwise the tag is not deleted if entities still have values set for it.
+      Destroy a :class:`Tag`. If ``forced`` is true and entities still have
+      values set for this tag, the tag is deleted anyway and those values
+      disappear. Otherwise the tag is not deleted if entities still have values
+      set for it.
 
-      :param tag: Tag to delete
+      :param tag: :class:`Tag` to delete
       :param forced: True if the tag should be deleted even if there are values
                      set for it
 
@@ -219,92 +216,21 @@
       Get the handle of an existing tag with the specified ``name``.
 
       :param name: The name of the tag to find
-      :return: The tag with the specified name
+      :return: The :class:`Tag` with the specified name
 
    .. method:: getAllTags(entities)
 
       Get all the tags associated with a specified entity or entity set.
 
       :param entities: Entity or entity set being queried
-      :return: Array of tags associated with ``entities``
+      :return: Array of :class:`Tag`s associated with ``entities``
 
 
-.. class:: itaps.iMesh.Topology
+EntitySet
+=========
 
-   An enumeration of mesh element topologies corresponding to
-   ``iMesh_EntityTopology``.
+.. class:: EntitySet
 
-   .. data:: point
-
-      A general zero-dimensional entity
-
-   .. data:: line_segment
-
-      A general one-dimensional entity
-
-   .. data:: polygon
-
-      A general two-dimensional element
-
-   .. data:: triangle
-
-      A three-sided, two-dimensional element
-
-   .. data:: quadrilateral
-
-      A four-sided, two-dimensional element
-
-   .. data:: polyhedron
-
-      A general three-dimensional element
-
-   .. data:: tetrahedron
-
-      A four-sided, three-dimensional element whose faces are triangles
-
-   .. data:: hexahedron
-
-      A six-sided, three-dimensional element whose faces are quadrilaterals
-
-   .. data:: prism
-
-      A five-sided, three-dimensional element which has three quadrilateral
-      faces and two triangular faces
-
-   .. data:: pyramid
-
-      A five-sided, three-dimensional element which has one quadrilateral face
-      and four triangular faces
-
-   .. data:: septahedron
-
-      A hexahedral entity with one collapsed edge
-
-   .. data:: all
-
-      Allows the user to request information about all the topology types
-
-
-.. class:: itaps.iMesh.Iterator(set, type, topology[, count=1])
-
-   Return a new iterator on the entity set ``set`` to iterate over entities of
-   the specified ``type`` and ``topology``. If ``size`` is greater than 1, each
-   step of the iteration will return an array of ``size`` entities. All
-   entities of a given type or topology are requested by specifying 
-   ``iBase.Type.all`` or  ``iMesh.Topology.all``, respectively.
-
-   :param set: Entity set to iterate over
-   :param type: Type of entities being requested
-   :param topo: Topology of entities being requested
-   :param count: Number of entities to return on each step of iteration
-
-   .. method:: reset()
-
-      Resets the iterator to the beginning.
-
-
-.. class:: itaps.iMesh.EntitySet
-
    .. attribute:: isList
 
       Return whether this entity set is ordered.
@@ -342,7 +268,8 @@
 
       Get entities of a specific type and/or topology in this entity set. All 
       entities of a given type or topology are requested by specifying
-      ``iBase.Type.all`` or ``iMesh.Topology.all``, respectively.
+      :attr:`itaps.iBase.Type.all` or :attr:`itaps.iMesh.Topology.all`,
+      respectively.
 
       :param entSet: Entity set being queried
       :param type: Type of entities being requested
@@ -352,8 +279,8 @@
 
    .. method:: getAdjEntIndices(type, topo, adjType)
 
-      Given an entity set and optionally a type or topology, return a tuple
-      containing the following:
+      Given an entity set and optionally a type or topology, return an
+      :class:`~itaps.helpers.IndexedAdjacencyList` containing the following:
 
       * The entities in the set of the specified ``type`` and/or ``topology``
       * The entities adjacent to those entities with the specified type
@@ -363,15 +290,10 @@
       * An array of offsets into the index buffer for each entity in the first
         list
 
-      That is, given an entity located in ``ret[0][i]``, the list of entities to
-      which it is adjacent is::
-
-        ret[1][  ret[2][ ret[3][i]:ret[3][i+1] ]  ]
-
       :param type: Type of entities being requested
       :param topo: Topology of entities being requested
       :param adjType: Type of adjacent entities being requested
-      :return: 4-tuple containing the adjacency information
+      :return: An :class:`~itaps.helpers.IndexedAdjacencyList` instance
 
    .. method:: getNumEntSets(numHops)
 
@@ -476,16 +398,16 @@
 
    .. method:: iterate(type, topo[, count=1])
 
-      Initialize an iterator over the specified entity type and topology for
-      this entity set. If ``count`` is greater than 1, each step of the
-      iteration returns an array of ``count`` entities. Equivalent to::
+      Initialize an :class:`Iterator` over the specified entity type and
+      topology for this entity set. If ``count`` is greater than 1, each step
+      of the iteration returns an array of ``count`` entities. Equivalent to::
 
         itaps.iMesh.Iterator(self, type, topo, count)
 
       :param type: Type of entities being requested
       :param topo: Topology of entities being requested
       :param count: Number of entities to return on each step of iteration
-      :return: An ``itaps.iMesh.Iterator`` instance
+      :return: An :class:`Iterator` instance
 
    .. method:: difference(entSet)
 
@@ -512,8 +434,33 @@
       :return: Resulting entity set
 
 
-.. class:: itaps.iMesh.Tag
+Iterator
+========
 
+.. class:: Iterator(set, type, topology[, count=1])
+
+   Return a new iterator on the entity set ``set`` to iterate over entities of
+   the specified ``type`` and ``topology``. If ``size`` is greater than 1, each
+   step of the iteration will return an array of ``size`` entities. All
+   entities of a given type or topology are requested by specifying 
+   :attr:`itaps.iBase.Type.all` or :attr:`itaps.iMesh.Topology.all`,
+   respectively.
+
+   :param set: Entity set to iterate over
+   :param type: Type of entities being requested
+   :param topo: Topology of entities being requested
+   :param count: Number of entities to return on each step of iteration
+
+   .. method:: reset()
+
+      Resets the iterator to the beginning.
+
+
+Tag
+===
+
+.. class:: Tag
+
    .. attribute:: name
 
       Get the name for this tag.
@@ -558,3 +505,61 @@
 
       :param entities: Entity, entity set, or array of entities from which tag
                        is being removed
+
+Topology
+========
+
+.. class:: Topology
+
+   An enumeration of mesh element topologies corresponding to
+   ``iMesh_EntityTopology``.
+
+   .. data:: point
+
+      A general zero-dimensional entity
+
+   .. data:: line_segment
+
+      A general one-dimensional entity
+
+   .. data:: polygon
+
+      A general two-dimensional element
+
+   .. data:: triangle
+
+      A three-sided, two-dimensional element
+
+   .. data:: quadrilateral
+
+      A four-sided, two-dimensional element
+
+   .. data:: polyhedron
+
+      A general three-dimensional element
+
+   .. data:: tetrahedron
+
+      A four-sided, three-dimensional element whose faces are triangles
+
+   .. data:: hexahedron
+
+      A six-sided, three-dimensional element whose faces are quadrilaterals
+
+   .. data:: prism
+
+      A five-sided, three-dimensional element which has three quadrilateral
+      faces and two triangular faces
+
+   .. data:: pyramid
+
+      A five-sided, three-dimensional element which has one quadrilateral face
+      and four triangular faces
+
+   .. data:: septahedron
+
+      A hexahedral entity with one collapsed edge
+
+   .. data:: all
+
+      Allows the user to request information about all the topology types
\ No newline at end of file

Modified: MOAB/trunk/tools/iMesh/python/doc/index.rst
===================================================================
--- MOAB/trunk/tools/iMesh/python/doc/index.rst	2009-06-01 16:48:29 UTC (rev 2920)
+++ MOAB/trunk/tools/iMesh/python/doc/index.rst	2009-06-01 18:57:09 UTC (rev 2921)
@@ -10,4 +10,5 @@
 
    build
    ibase
-   imesh
\ No newline at end of file
+   imesh
+   helpers
\ No newline at end of file

Modified: MOAB/trunk/tools/iMesh/python/itaps/helpers.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/itaps/helpers.py	2009-06-01 16:48:29 UTC (rev 2920)
+++ MOAB/trunk/tools/iMesh/python/itaps/helpers.py	2009-06-01 18:57:09 UTC (rev 2921)
@@ -11,10 +11,16 @@
         else:
             return self.adj[ self.offsets[key]:self.offsets[key+1] ]
 
-    def length(self, i):
-        return self.offsets[i+1] - self.offsets[i]
+    def length(self, i = None):
+        if i == None:
+            return len(self.offsets)-1
+        else:
+            return self.offsets[i+1] - self.offsets[i]
 
+    def __len__(self):
+        return self.length()
 
+
 class IndexedAdjacencyList:
     def __init__(self, entities, adj, indices, offsets):
         self.entities = entities
@@ -33,5 +39,11 @@
         else:
             return self.indices[ self.offsets[key]:self.offsets[key+1] ]
 
-    def length(self, i):
-        return self.offsets[i+1] - self.offsets[i]
+    def length(self, i = None):
+        if i == None:
+            return len(self.offsets)-1
+        else:
+            return self.offsets[i+1] - self.offsets[i]
+
+    def __len__(self):
+        return self.length()

Modified: MOAB/trunk/tools/iMesh/python/test/adj.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/adj.py	2009-06-01 16:48:29 UTC (rev 2920)
+++ MOAB/trunk/tools/iMesh/python/test/adj.py	2009-06-01 18:57:09 UTC (rev 2921)
@@ -53,11 +53,19 @@
 
         adj = self.mesh.getEntAdj(self.ents, iBase.Type.all)
 
+        for i in range( len(adj) ):
+            self.assertEqual(adj.length(i), 2)
+
         self.assertEqual(adj[0].tolist(), self.lines[::3])
         self.assertEqual(adj[1].tolist(), self.lines[0:2])
         self.assertEqual(adj[2].tolist(), self.lines[1:3])
         self.assertEqual(adj[3].tolist(), self.lines[2:4])
 
+        self.assertEqual(adj[0,0], self.lines[0])
+        self.assertEqual(adj[2,1], self.lines[2])
+
+        self.assertRaises(IndexError, adj.__getitem__, (0,2))
+
     def test2ndAdj(self):
         quad = self.mesh.createEnt(topo.quadrilateral, self.lines)[0]
 
@@ -68,11 +76,19 @@
         adj = self.mesh.getEnt2ndAdj(self.ents, iBase.Type.edge,
                                      iBase.Type.vertex)
 
+        for i in range( len(adj) ):
+            self.assertEqual(adj.length(i), 2)
+
         self.assertEqual(adj[0].tolist(), self.ents[1::2].tolist())
         self.assertEqual(adj[1].tolist(), self.ents[0::2].tolist())
         self.assertEqual(adj[2].tolist(), self.ents[1::2].tolist())
         self.assertEqual(adj[3].tolist(), self.ents[0::2].tolist())
 
+        self.assertEqual(adj[0,0], self.ents[1])
+        self.assertEqual(adj[2,1], self.ents[3])
+
+        self.assertRaises(IndexError, adj.__getitem__, (0,2))
+
     def testAdjIndices(self):
         set = self.mesh.createEntSet(True)
         set.add(self.ents)



More information about the moab-dev mailing list