[MOAB-dev] r2919 - in MOAB/trunk/tools/iMesh/python: . doc itaps perf test tools
jvporter at wisc.edu
jvporter at wisc.edu
Fri May 29 18:31:47 CDT 2009
Author: jvporter
Date: 2009-05-29 18:31:46 -0500 (Fri, 29 May 2009)
New Revision: 2919
Modified:
MOAB/trunk/tools/iMesh/python/common.h
MOAB/trunk/tools/iMesh/python/doc/ibase.rst
MOAB/trunk/tools/iMesh/python/doc/imesh.rst
MOAB/trunk/tools/iMesh/python/errors.h
MOAB/trunk/tools/iMesh/python/iBase.c
MOAB/trunk/tools/iMesh/python/iMesh.c
MOAB/trunk/tools/iMesh/python/iMesh_Python.h
MOAB/trunk/tools/iMesh/python/iMesh_entSet.c
MOAB/trunk/tools/iMesh/python/itaps/__init__.py
MOAB/trunk/tools/iMesh/python/perf/perf.py
MOAB/trunk/tools/iMesh/python/setup.py
MOAB/trunk/tools/iMesh/python/test/adj.py
MOAB/trunk/tools/iMesh/python/test/basic.py
MOAB/trunk/tools/iMesh/python/test/entset.py
MOAB/trunk/tools/iMesh/python/test/iter.py
MOAB/trunk/tools/iMesh/python/test/tags.py
MOAB/trunk/tools/iMesh/python/tools/volume.py
Log:
* Minor refactoring
* More consistent naming scheme for Python class names
* Friendlier adjacency lists (still need to update docs!)
Modified: MOAB/trunk/tools/iMesh/python/common.h
===================================================================
--- MOAB/trunk/tools/iMesh/python/common.h 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/common.h 2009-05-29 23:31:46 UTC (rev 2919)
@@ -36,10 +36,11 @@
SIMPLE_TYPE(name ## _Object,name ## _Type, \
namestr,docstr)
-#define ADD_ENUM(type,name,value) \
+#define ADD_ENUM(typename,name,value) \
do { \
PyObject *o = Py_BuildValue("i",(value)); \
- PyDict_SetItemString((type)->tp_dict,(name),o); \
+ PyDict_SetItemString((&typename ## _Type)-> \
+ tp_dict,(name),o); \
Py_DECREF(o); \
} while(0)
Modified: MOAB/trunk/tools/iMesh/python/doc/ibase.rst
===================================================================
--- MOAB/trunk/tools/iMesh/python/doc/ibase.rst 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/doc/ibase.rst 2009-05-29 23:31:46 UTC (rev 2919)
@@ -4,7 +4,7 @@
.. module:: itaps.iBase
-.. class:: itaps.iBase.type
+.. class:: itaps.iBase.Type
An enumeration of entity types corresponding to ``iBase_EntityType``.
@@ -29,7 +29,7 @@
Allows the user to request information about all the types
-.. class:: itaps.iBase.adjCost
+.. class:: itaps.iBase.AdjCost
An enumeration of entity types corresponding to ``iBase_AdjacencyCost``.
@@ -62,7 +62,7 @@
Only some adjacency info, exhaustive
-.. class:: itaps.iBase.storageOrder
+.. class:: itaps.iBase.StorageOrder
An enumeration of entity types corresponding to ``iBase_StorageOrder``.
@@ -76,7 +76,7 @@
...]``.
-.. class:: itaps.iBase.creationStatus
+.. class:: itaps.iBase.CreationStatus
An enumeration of entity types corresponding to ``iBase_CreationStatus``.
Modified: MOAB/trunk/tools/iMesh/python/doc/imesh.rst
===================================================================
--- MOAB/trunk/tools/iMesh/python/doc/imesh.rst 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/doc/imesh.rst 2009-05-29 23:31:46 UTC (rev 2919)
@@ -2,11 +2,11 @@
iMesh Interface
=================
-.. module:: itaps
+.. module:: itaps.iMesh
-.. class:: itaps.iMesh([options])
+.. class:: itaps.iMesh.Mesh([options])
- Return a new ``iMesh`` object with any implementation-specific options
+ Return a new ``Mesh`` object with any implementation-specific options
defined in ``options``.
:param options: Implementation-specific options string
@@ -229,7 +229,7 @@
:return: Array of tags associated with ``entities``
-.. class:: itaps.iMesh.topology
+.. class:: itaps.iMesh.Topology
An enumeration of mesh element topologies corresponding to
``iMesh_EntityTopology``.
@@ -285,13 +285,13 @@
Allows the user to request information about all the topology types
-.. class:: itaps.iMesh.iterator(set, type, topology[, size=1])
+.. 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.
+ ``iBase.Type.all`` or ``iMesh.Topology.all``, respectively.
:param set: Entity set to iterate over
:param type: Type of entities being requested
@@ -303,7 +303,7 @@
Resets the iterator to the beginning.
-.. class:: itaps.iMesh.entitySet
+.. class:: itaps.iMesh.EntitySet
.. attribute:: isList
@@ -342,7 +342,7 @@
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.
+ ``iBase.Type.all`` or ``iMesh.Topology.all``, respectively.
:param entSet: Entity set being queried
:param type: Type of entities being requested
@@ -480,12 +480,12 @@
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)
+ 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 ``itaps.iMesh.Iterator`` instance
.. method:: difference(entSet)
@@ -512,7 +512,7 @@
:return: Resulting entity set
-.. class:: itaps.iMesh.tag
+.. class:: itaps.iMesh.Tag
.. attribute:: name
@@ -541,7 +541,7 @@
:param data: Data to set
:param type: Character representing the tag's type (as above)
- .. method:: getData(entities, [, type])
+ .. method:: getData(entities[, type])
Get value(s) for the tag on an entity, entity set, or array of entities.
If ``type`` is not specified, this function will retrieve the tag type
@@ -552,7 +552,7 @@
:param type: Character representing the tag's type (as above)
:return: The retrieved data
- .. method:: rmvTag(entities)
+ .. method:: remove(entities)
Remove the tag value from an entity, entity set, or array of entities.
Modified: MOAB/trunk/tools/iMesh/python/errors.h
===================================================================
--- MOAB/trunk/tools/iMesh/python/errors.h 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/errors.h 2009-05-29 23:31:46 UTC (rev 2919)
@@ -7,3 +7,4 @@
#define ERR_ARR_SIZE "unexpected array size"
#define ERR_ARR_DIMS "1- or 2-dimensional array expected"
#define ERR_TYPE_CODE "invalid type code"
+#define ERR_ADJ_LIST "unable to create adjacency list"
Modified: MOAB/trunk/tools/iMesh/python/iBase.c
===================================================================
--- MOAB/trunk/tools/iMesh/python/iBase.c 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/iBase.c 2009-05-29 23:31:46 UTC (rev 2919)
@@ -35,10 +35,10 @@
}
static int NPY_IBASETAG;
-ENUM_TYPE(type, "iBase.type", "");
-ENUM_TYPE(adjCost, "iBase.adjCost", "");
-ENUM_TYPE(storageOrder, "iBase.storageOrder", "");
-ENUM_TYPE(creationStatus, "iBase.creationStatus", "");
+ENUM_TYPE(Type, "iBase.Type", "");
+ENUM_TYPE(AdjCost, "iBase.AdjCost", "");
+ENUM_TYPE(StorageOrder, "iBase.StorageOrder", "");
+ENUM_TYPE(CreationStatus, "iBase.CreationStatus", "");
static PyMethodDef module_methods[] = {
{0}
@@ -252,38 +252,38 @@
PyModule_AddObject(m, "_C_API", api_obj);
/***** initialize type enum *****/
- REGISTER_SIMPLE(m,type);
+ REGISTER_SIMPLE(m,Type);
- ADD_ENUM(&type_Type,"vertex", iBase_VERTEX);
- ADD_ENUM(&type_Type,"edge", iBase_EDGE);
- ADD_ENUM(&type_Type,"face", iBase_FACE);
- ADD_ENUM(&type_Type,"region", iBase_REGION);
- ADD_ENUM(&type_Type,"all", iBase_ALL_TYPES);
+ ADD_ENUM(Type,"vertex", iBase_VERTEX);
+ ADD_ENUM(Type,"edge", iBase_EDGE);
+ ADD_ENUM(Type,"face", iBase_FACE);
+ ADD_ENUM(Type,"region", iBase_REGION);
+ ADD_ENUM(Type,"all", iBase_ALL_TYPES);
/***** initialize adjacency cost enum *****/
- REGISTER_SIMPLE(m,adjCost);
+ REGISTER_SIMPLE(m,AdjCost);
- ADD_ENUM(&adjCost_Type,"unavailable", iBase_UNAVAILABLE);
- ADD_ENUM(&adjCost_Type,"all_order_1", iBase_ALL_ORDER_1);
- ADD_ENUM(&adjCost_Type,"all_order_logn", iBase_ALL_ORDER_LOGN);
- ADD_ENUM(&adjCost_Type,"all_order_n", iBase_ALL_ORDER_N);
- ADD_ENUM(&adjCost_Type,"some_order_1", iBase_SOME_ORDER_1);
- ADD_ENUM(&adjCost_Type,"some_order_logn", iBase_SOME_ORDER_LOGN);
- ADD_ENUM(&adjCost_Type,"some_order_n", iBase_SOME_ORDER_N);
+ ADD_ENUM(AdjCost,"unavailable", iBase_UNAVAILABLE);
+ ADD_ENUM(AdjCost,"all_order_1", iBase_ALL_ORDER_1);
+ ADD_ENUM(AdjCost,"all_order_logn", iBase_ALL_ORDER_LOGN);
+ ADD_ENUM(AdjCost,"all_order_n", iBase_ALL_ORDER_N);
+ ADD_ENUM(AdjCost,"some_order_1", iBase_SOME_ORDER_1);
+ ADD_ENUM(AdjCost,"some_order_logn", iBase_SOME_ORDER_LOGN);
+ ADD_ENUM(AdjCost,"some_order_n", iBase_SOME_ORDER_N);
/***** initialize storage order enum *****/
- REGISTER_SIMPLE(m,storageOrder);
+ REGISTER_SIMPLE(m,StorageOrder);
- ADD_ENUM(&storageOrder_Type,"blocked", iBase_BLOCKED);
- ADD_ENUM(&storageOrder_Type,"interleaved",iBase_INTERLEAVED);
+ ADD_ENUM(StorageOrder,"blocked", iBase_BLOCKED);
+ ADD_ENUM(StorageOrder,"interleaved", iBase_INTERLEAVED);
/***** initialize creation status enum *****/
- REGISTER_SIMPLE(m,creationStatus);
+ REGISTER_SIMPLE(m,CreationStatus);
- ADD_ENUM(&creationStatus_Type,"new", iBase_NEW);
- ADD_ENUM(&creationStatus_Type,"exists", iBase_ALREADY_EXISTED);
- ADD_ENUM(&creationStatus_Type,"duplicated", iBase_CREATED_DUPLICATE);
- ADD_ENUM(&creationStatus_Type,"failed", iBase_CREATION_FAILED);
+ ADD_ENUM(CreationStatus,"new", iBase_NEW);
+ ADD_ENUM(CreationStatus,"exists", iBase_ALREADY_EXISTED);
+ ADD_ENUM(CreationStatus,"duplicated", iBase_CREATED_DUPLICATE);
+ ADD_ENUM(CreationStatus,"failed", iBase_CREATION_FAILED);
/***** initialize iBaseEntity handle *****/
iBaseEntity_Type.tp_repr = (reprfunc)iBaseEntObj_repr;
Modified: MOAB/trunk/tools/iMesh/python/iMesh.c
===================================================================
--- MOAB/trunk/tools/iMesh/python/iMesh.c 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/iMesh.c 2009-05-29 23:31:46 UTC (rev 2919)
@@ -2,7 +2,6 @@
#include "iMesh_Python.h"
#include "iBase_Python.h"
-
int checkError(iMesh_Instance mesh,int err)
{
if(err)
@@ -26,6 +25,45 @@
return ret;
}
+/* TODO: these are never freed! */
+static PyObject *g_helper_module;
+static PyObject *g_adj_list;
+static PyObject *g_ind_adj_list;
+
+/* NOTE: steals references to adj and offsets */
+PyObject *
+AdjacencyList_New(PyObject *adj,PyObject *offsets)
+{
+ PyObject *res;
+
+ if( (res = PyObject_CallFunction(g_adj_list,"OO",adj,offsets)) == NULL)
+ PyErr_SetString(PyExc_RuntimeError,ERR_ADJ_LIST);
+
+ Py_DECREF(adj);
+ Py_DECREF(offsets);
+
+ return res;
+}
+
+/* NOTE: steals references to adj and offsets */
+PyObject *
+IndexedAdjacencyList_New(PyObject *ents, PyObject *adj,PyObject *indices,
+ PyObject *offsets)
+{
+ PyObject *res;
+
+ if( (res = PyObject_CallFunction(g_ind_adj_list,"OOOO",ents,adj,indices,
+ offsets)) == NULL)
+ PyErr_SetString(PyExc_RuntimeError,ERR_ADJ_LIST);
+
+ Py_DECREF(ents);
+ Py_DECREF(adj);
+ Py_DECREF(indices);
+ Py_DECREF(offsets);
+
+ return res;
+}
+
static int
iMeshObj_init(iMeshObject *self,PyObject *args,PyObject *kwds)
{
@@ -370,10 +408,16 @@
if(checkError(self->mesh,err))
return NULL;
- /* TODO: this is clunky */
+ npy_intp adj_dims[] = {adj_size};
+ npy_intp off_dims[] = {offsets_size};
+
+ return AdjacencyList_New(
+ PyArray_NewFromMalloc(1,adj_dims,NPY_IBASEENT,adj),
+ PyArray_NewFromMalloc(1,off_dims,NPY_INT,offsets) );
+
PyObject *pair = PyTuple_New(2);
npy_intp dims[1];
-
+
dims[0] = adj_size;
PyTuple_SET_ITEM(pair, 0,
PyArray_NewFromMalloc(1,dims,NPY_IBASEENT,adj));
@@ -435,10 +479,16 @@
if(checkError(self->mesh,err))
return NULL;
- /* TODO: this is clunky */
+ npy_intp adj_dims[] = {adj_size};
+ npy_intp off_dims[] = {offsets_size};
+
+ return AdjacencyList_New(
+ PyArray_NewFromMalloc(1,adj_dims,NPY_IBASEENT,adj),
+ PyArray_NewFromMalloc(1,off_dims,NPY_INT,offsets) );
+
PyObject *pair = PyTuple_New(2);
npy_intp dims[1];
-
+
dims[0] = adj_size;
PyTuple_SET_ITEM(pair, 0,
PyArray_NewFromMalloc(1,dims,NPY_IBASEENT,adj));
@@ -954,7 +1004,7 @@
static PyTypeObject iMeshType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
- "itaps.iMesh", /* tp_name */
+ "itaps.iMesh.Mesh", /* tp_name */
sizeof(iMeshObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)iMeshObj_dealloc, /* tp_dealloc */
@@ -1031,7 +1081,7 @@
static PyArray_ArrFuncs iMeshTagArr_Funcs;
int NPY_IMESHTAG;
-ENUM_TYPE(topology,"iMesh.topology","");
+ENUM_TYPE(Topology,"iMesh.Topology","");
static void
@@ -1098,45 +1148,55 @@
import_array();
import_iBase();
+ /***** import helper module *****/
+ if( (g_helper_module = PyImport_ImportModule("itaps.helpers")) == NULL)
+ return;
+ if( (g_adj_list = PyObject_GetAttrString(g_helper_module,"AdjacencyList") )
+ == NULL)
+ return;
+ if( (g_ind_adj_list = PyObject_GetAttrString(g_helper_module,
+ "IndexedAdjacencyList")) == NULL)
+ return;
+
iMeshType.tp_new = PyType_GenericNew;
if(PyType_Ready(&iMeshType) < 0)
return;
Py_INCREF(&iMeshType);
- PyModule_AddObject(m,"iMesh",(PyObject *)&iMeshType);
+ PyModule_AddObject(m,"Mesh",(PyObject *)&iMeshType);
/***** initialize topology enum *****/
- REGISTER_SIMPLE_SUB(iMeshType,topology);
+ REGISTER_SIMPLE(m,Topology);
- ADD_ENUM(&topology_Type,"point", iMesh_POINT);
- ADD_ENUM(&topology_Type,"line_segment", iMesh_LINE_SEGMENT);
- ADD_ENUM(&topology_Type,"polygon", iMesh_POLYGON);
- ADD_ENUM(&topology_Type,"triangle", iMesh_TRIANGLE);
- ADD_ENUM(&topology_Type,"quadrilateral", iMesh_QUADRILATERAL);
- ADD_ENUM(&topology_Type,"polyhedron", iMesh_POLYHEDRON);
- ADD_ENUM(&topology_Type,"tetrahedron", iMesh_TETRAHEDRON);
- ADD_ENUM(&topology_Type,"hexahedron", iMesh_HEXAHEDRON);
- ADD_ENUM(&topology_Type,"prism", iMesh_PRISM);
- ADD_ENUM(&topology_Type,"pyramid", iMesh_PYRAMID);
- ADD_ENUM(&topology_Type,"septahedron", iMesh_SEPTAHEDRON);
- ADD_ENUM(&topology_Type,"all", iMesh_ALL_TOPOLOGIES);
+ ADD_ENUM(Topology,"point", iMesh_POINT);
+ ADD_ENUM(Topology,"line_segment", iMesh_LINE_SEGMENT);
+ ADD_ENUM(Topology,"polygon", iMesh_POLYGON);
+ ADD_ENUM(Topology,"triangle", iMesh_TRIANGLE);
+ ADD_ENUM(Topology,"quadrilateral", iMesh_QUADRILATERAL);
+ ADD_ENUM(Topology,"polyhedron", iMesh_POLYHEDRON);
+ ADD_ENUM(Topology,"tetrahedron", iMesh_TETRAHEDRON);
+ ADD_ENUM(Topology,"hexahedron", iMesh_HEXAHEDRON);
+ ADD_ENUM(Topology,"prism", iMesh_PRISM);
+ ADD_ENUM(Topology,"pyramid", iMesh_PYRAMID);
+ ADD_ENUM(Topology,"septahedron", iMesh_SEPTAHEDRON);
+ ADD_ENUM(Topology,"all", iMesh_ALL_TOPOLOGIES);
+ /***** initialize iterator type *****/
iMeshIter_Type.tp_new = PyType_GenericNew;
if(PyType_Ready(&iMeshIter_Type) < 0)
return;
- PyDict_SetItemString(iMeshType.tp_dict,"iterator",
- (PyObject *)&iMeshIter_Type);
+ PyModule_AddObject(m,"Iterator",(PyObject *)&iMeshIter_Type);
+ /***** initialize entity set type *****/
iMeshEntitySet_Type.tp_base = &iBaseEntitySet_Type;
if(PyType_Ready(&iMeshEntitySet_Type) < 0)
return;
- PyDict_SetItemString(iMeshType.tp_dict,"entitySet",
- (PyObject *)&iMeshEntitySet_Type);
+ PyModule_AddObject(m,"EntitySet",(PyObject *)&iMeshEntitySet_Type);
+ /***** initialize tag type *****/
iMeshTag_Type.tp_base = &iBaseTag_Type;
if(PyType_Ready(&iMeshTag_Type) < 0)
return;
- PyDict_SetItemString(iMeshType.tp_dict,"tag",
- (PyObject *)&iMeshTag_Type);
+ PyModule_AddObject(m,"Tag",(PyObject *)&iMeshTag_Type);
/***** initialize iMeshEntitySet array *****/
Modified: MOAB/trunk/tools/iMesh/python/iMesh_Python.h
===================================================================
--- MOAB/trunk/tools/iMesh/python/iMesh_Python.h 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/iMesh_Python.h 2009-05-29 23:31:46 UTC (rev 2919)
@@ -40,6 +40,12 @@
enum iBase_TagValueType char_to_type(char c);
char type_to_char(enum iBase_TagValueType t);
+PyObject *
+AdjacencyList_New(PyObject *adj,PyObject *offsets);
+PyObject *
+IndexedAdjacencyList_New(PyObject *ents, PyObject *adj,PyObject *indices,
+ PyObject *offsets);
+
typedef struct
{
PyObject_HEAD
Modified: MOAB/trunk/tools/iMesh/python/iMesh_entSet.c
===================================================================
--- MOAB/trunk/tools/iMesh/python/iMesh_entSet.c 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/iMesh_entSet.c 2009-05-29 23:31:46 UTC (rev 2919)
@@ -118,27 +118,16 @@
if(checkError(self->mesh->mesh,err))
return NULL;
- /* TODO: this is clunky */
- PyObject *tup = PyTuple_New(4);
- npy_intp dims[1];
+ npy_intp ent_dims[] = {ent_size};
+ npy_intp adj_dims[] = {adj_size};
+ npy_intp ind_dims[] = {ind_size};
+ npy_intp off_dims[] = {off_size};
- dims[0] = ent_size;
- PyTuple_SET_ITEM(tup, 0,
- PyArray_NewFromMalloc(1,dims,NPY_IBASEENT,entities));
-
- dims[0] = adj_size;
- PyTuple_SET_ITEM(tup, 1,
- PyArray_NewFromMalloc(1,dims,NPY_IBASEENT,adj_ents));
-
- dims[0] = ind_size;
- PyTuple_SET_ITEM(tup, 2,
- PyArray_NewFromMalloc(1,dims,NPY_INT,indices));
-
- dims[0] = off_size;
- PyTuple_SET_ITEM(tup, 3,
- PyArray_NewFromMalloc(1,dims,NPY_INT,offsets));
-
- return tup;
+ return IndexedAdjacencyList_New(
+ PyArray_NewFromMalloc(1,ent_dims,NPY_IBASEENT,entities),
+ PyArray_NewFromMalloc(1,adj_dims,NPY_IBASEENT,adj_ents),
+ PyArray_NewFromMalloc(1,ind_dims,NPY_INT,indices),
+ PyArray_NewFromMalloc(1,off_dims,NPY_INT,offsets) );
}
static PyObject *
Modified: MOAB/trunk/tools/iMesh/python/itaps/__init__.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/itaps/__init__.py 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/itaps/__init__.py 2009-05-29 23:31:46 UTC (rev 2919)
@@ -1,2 +1 @@
-import iBase
-from iMesh import *
+__all__ = ['iBase', 'iMesh', 'helpers']
Modified: MOAB/trunk/tools/iMesh/python/perf/perf.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/perf/perf.py 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/perf/perf.py 2009-05-29 23:31:46 UTC (rev 2919)
@@ -63,50 +63,49 @@
##### 1 #####
timer.reset()
for x in range(count):
- m = iMesh()
+ m = iMesh.Mesh()
m.load(file)
m = None
py_stats[file].append( timer.delta()/count )
list_stats[file].append(0)
##### Intermission #####
- mesh = iMesh()
+ mesh = iMesh.Mesh()
root = mesh.rootSet
mesh.load(file)
##### 2 #####
timer.reset()
for x in range(count):
- root.getAdjEntIndices(iBase.type.all, iMesh.topology.all,
- iBase.type.all)
+ root.getAdjEntIndices(iBase.Type.all, iMesh.Topology.all,
+ iBase.Type.all)
py_stats[file].append( timer.delta()/count )
list_stats[file].append(0)
##### Intermission #####
- arr = root.getAdjEntIndices(iBase.type.all, iMesh.topology.all,
- iBase.type.all)
- list = map(lambda x: x.tolist(), arr)
+ arr = root.getEntities(iBase.Type.all, iMesh.Topology.all)
+ list = arr.tolist()
##### 3 #####
timer.reset()
for x in range(count):
- mesh.getEntAdj(arr[0], iBase.type.all)
+ mesh.getEntAdj(arr, iBase.Type.all)
py_stats[file].append( timer.delta()/count )
timer.reset()
for x in range(count):
- mesh.getEntAdj(list[0], iBase.type.all)
+ mesh.getEntAdj(list, iBase.Type.all)
list_stats[file].append( timer.delta()/count )
##### 4 #####
timer.reset()
for x in range(count):
- mesh.getEnt2ndAdj(arr[0], iBase.type.edge, iBase.type.vertex)
+ mesh.getEnt2ndAdj(arr, iBase.Type.edge, iBase.Type.vertex)
py_stats[file].append( timer.delta()/count )
timer.reset()
for x in range(count):
- mesh.getEnt2ndAdj(list[0], iBase.type.edge, iBase.type.vertex)
+ mesh.getEnt2ndAdj(list, iBase.Type.edge, iBase.Type.vertex)
list_stats[file].append( timer.delta()/count )
mesh = None
Modified: MOAB/trunk/tools/iMesh/python/setup.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/setup.py 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/setup.py 2009-05-29 23:31:46 UTC (rev 2919)
@@ -21,5 +21,6 @@
author = 'Jim Porter',
author_email = 'jvporter at wisc.edu',
packages = ['itaps'],
- ext_modules = [iBase, iMesh]
+ ext_modules = [iBase, iMesh],
+ py_modules = ['itaps.helpers']
)
Modified: MOAB/trunk/tools/iMesh/python/test/adj.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/adj.py 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/test/adj.py 2009-05-29 23:31:46 UTC (rev 2919)
@@ -1,14 +1,14 @@
from itaps import *
import unittest
-topo = iMesh.topology # shorthand
+topo = iMesh.Topology # shorthand
class TestAdj(unittest.TestCase):
def setUp(self):
- self.mesh = iMesh()
+ self.mesh = iMesh.Mesh()
self.verts = [[0,0,0], [0,0,1], [0,1,0], [0,1,1]]
self.ents = self.mesh.createVtx(self.verts,
- iBase.storageOrder.interleaved)
+ iBase.StorageOrder.interleaved)
self.lines = [
self.mesh.createEnt(topo.line_segment, self.ents[0:2] )[0],
@@ -23,76 +23,69 @@
self.root = None
self.lines = None
- @staticmethod
- def jaggify(arr,offsets):
- prev = offsets[0]
- jag = []
- for i in offsets[1:]:
- jag.append(arr[prev:i].tolist())
- prev = i
- return jag
-
def testSquare(self):
quad = self.mesh.createEnt(topo.quadrilateral, self.lines)[0]
root = self.mesh.rootSet
- self.assertEqual(root.getNumOfType(iBase.type.vertex), 4)
- self.assertEqual(root.getNumOfType(iBase.type.edge), 4)
- self.assertEqual(root.getNumOfType(iBase.type.face), 1)
+ self.assertEqual(root.getNumOfType(iBase.Type.vertex), 4)
+ self.assertEqual(root.getNumOfType(iBase.Type.edge), 4)
+ self.assertEqual(root.getNumOfType(iBase.Type.face), 1)
self.assertEqual(root.getNumOfTopo(topo.point), 4)
self.assertEqual(root.getNumOfTopo(topo.line_segment), 4)
self.assertEqual(root.getNumOfTopo(topo.quadrilateral), 1)
self.mesh.deleteEnt(quad)
- self.assertEqual(root.getNumOfType(iBase.type.face), 0)
+ self.assertEqual(root.getNumOfType(iBase.Type.face), 0)
self.assertEqual(root.getNumOfTopo(topo.quadrilateral), 0)
self.mesh.deleteEnt(self.lines)
- self.assertEqual(root.getNumOfType(iBase.type.edge), 0)
+ self.assertEqual(root.getNumOfType(iBase.Type.edge), 0)
self.assertEqual(root.getNumOfTopo(topo.line_segment), 0)
self.mesh.deleteEnt(self.ents)
- self.assertEqual(root.getNumOfType(iBase.type.vertex), 0)
+ self.assertEqual(root.getNumOfType(iBase.Type.vertex), 0)
self.assertEqual(root.getNumOfTopo(topo.point), 0)
def testAdj(self):
- adj = self.mesh.getEntAdj(self.ents[1], iBase.type.all)
+ adj = self.mesh.getEntAdj(self.ents[1], iBase.Type.all)
self.assertEqual(adj.tolist(), self.lines[0:2])
- adj = self.mesh.getEntAdj(self.ents, iBase.type.all)
- self.assertEqual(TestAdj.jaggify(adj[0],adj[1]),
- [ self.lines[::3],
- self.lines[0:2],
- self.lines[1:3],
- self.lines[2:4] ])
+ adj = self.mesh.getEntAdj(self.ents, iBase.Type.all)
+ 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])
+
def test2ndAdj(self):
quad = self.mesh.createEnt(topo.quadrilateral, self.lines)[0]
- adj = self.mesh.getEnt2ndAdj(self.ents[1], iBase.type.edge,
- iBase.type.vertex)
+ adj = self.mesh.getEnt2ndAdj(self.ents[1], iBase.Type.edge,
+ iBase.Type.vertex)
self.assertEqual(adj.tolist(), self.ents[0:3:2].tolist())
- adj = self.mesh.getEnt2ndAdj(self.ents, iBase.type.edge,
- iBase.type.vertex)
- self.assertEqual(TestAdj.jaggify(adj[0],adj[1]),
- [ self.ents[1::2].tolist(),
- self.ents[0::2].tolist(),
- self.ents[1::2].tolist(),
- self.ents[0::2].tolist() ])
+ adj = self.mesh.getEnt2ndAdj(self.ents, iBase.Type.edge,
+ iBase.Type.vertex)
+ 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())
+
def testAdjIndices(self):
set = self.mesh.createEntSet(True)
set.add(self.ents)
- adj = set.getAdjEntIndices(iBase.type.all, topo.all,
- iBase.type.all)
+ adj = set.getAdjEntIndices(iBase.Type.all, topo.all,
+ iBase.Type.all)
- self.assertEqual(adj[0].tolist(), self.ents.tolist())
- self.assertEqual(adj[1].tolist(), self.lines)
- self.assertEqual(TestAdj.jaggify(adj[2],adj[3]),
- [ [0,3], [0,1], [1,2], [2,3] ])
+ self.assertEqual(adj.entities.tolist(), self.ents.tolist())
+ self.assertEqual(adj.adj.tolist(), self.lines)
+ self.assert_( (adj.index(0) == [0,3]).all() )
+ self.assert_( (adj.index(1) == [0,1]).all() )
+ self.assert_( (adj.index(2) == [1,2]).all() )
+ self.assert_( (adj.index(3) == [2,3]).all() )
suite = unittest.TestLoader().loadTestsFromTestCase(TestAdj)
unittest.TextTestRunner(verbosity=2).run(suite)
Modified: MOAB/trunk/tools/iMesh/python/test/basic.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/basic.py 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/test/basic.py 2009-05-29 23:31:46 UTC (rev 2919)
@@ -4,7 +4,7 @@
class TestBasic(unittest.TestCase):
def testMinimal(self):
- mesh = iMesh("hello there")
+ mesh = iMesh.Mesh("hello there")
mesh.geometricDimension = 2
self.assertEqual(mesh.geometricDimension, 2)
@@ -12,63 +12,63 @@
mesh.dfltStorage
self.assert_(mesh.areEHValid(True))
- self.assertEqual(root.getNumOfType(iBase.type.all), 0)
- self.assertEqual(root.getNumOfTopo(iMesh.topology.all), 0)
+ self.assertEqual(root.getNumOfType(iBase.Type.all), 0)
+ self.assertEqual(root.getNumOfTopo(iMesh.Topology.all), 0)
self.assertEqual(mesh.adjTable.shape, (4,4))
def testVertex(self):
- mesh = iMesh()
+ mesh = iMesh.Mesh()
ent = mesh.createVtx([1,2,3])
root = mesh.rootSet
- self.assertEqual(root.getNumOfType(iBase.type.vertex), 1)
- self.assertEqual(root.getNumOfTopo(iMesh.topology.point), 1)
+ self.assertEqual(root.getNumOfType(iBase.Type.vertex), 1)
+ self.assertEqual(root.getNumOfTopo(iMesh.Topology.point), 1)
self.assert_( (mesh.getVtxCoords(ent) == [1,2,3]).all() )
- self.assert_( (mesh.getVtxCoords([ent], iBase.storageOrder.interleaved)
+ self.assert_( (mesh.getVtxCoords([ent], iBase.StorageOrder.interleaved)
== [[1,2,3]]).all() )
- self.assertEqual(mesh.getEntType(ent), iBase.type.vertex)
- self.assertEqual(mesh.getEntTopo(ent), iMesh.topology.point)
+ self.assertEqual(mesh.getEntType(ent), iBase.Type.vertex)
+ self.assertEqual(mesh.getEntTopo(ent), iMesh.Topology.point)
mesh.setVtxCoords(ent,[4,5,6])
self.assert_( (mesh.getVtxCoords(ent) == [4,5,6]).all() )
def testVertices(self):
- mesh = iMesh()
+ mesh = iMesh.Mesh()
verts = [[1,2,3], [4,5,6], [7,8,9], [10,11,12]]
- ents = mesh.createVtx(verts, iBase.storageOrder.interleaved)
+ ents = mesh.createVtx(verts, iBase.StorageOrder.interleaved)
root = mesh.rootSet
- self.assertEqual(root.getNumOfType(iBase.type.vertex), 4)
- self.assertEqual(root.getNumOfTopo(iMesh.topology.point), 4)
+ self.assertEqual(root.getNumOfType(iBase.Type.vertex), 4)
+ self.assertEqual(root.getNumOfTopo(iMesh.Topology.point), 4)
- coords = mesh.getVtxCoords(ents, iBase.storageOrder.interleaved)
+ coords = mesh.getVtxCoords(ents, iBase.StorageOrder.interleaved)
self.assert_( (coords == verts).all())
- self.assertEqual(mesh.getEntType(ents[0]), iBase.type.vertex)
- self.assert_( (mesh.getEntType(ents) == 4*[iBase.type.vertex]).all() )
+ self.assertEqual(mesh.getEntType(ents[0]), iBase.Type.vertex)
+ self.assert_( (mesh.getEntType(ents) == 4*[iBase.Type.vertex]).all() )
- self.assertEqual(mesh.getEntTopo(ents[0]), iMesh.topology.point)
+ self.assertEqual(mesh.getEntTopo(ents[0]), iMesh.Topology.point)
self.assert_( (mesh.getEntTopo(ents) ==
- 4*[iMesh.topology.point]).all() )
+ 4*[iMesh.Topology.point]).all() )
verts = [[12,11,10], [9,8,7], [6,5,4], [3,2,1]]
- mesh.setVtxCoords(ents, verts, iBase.storageOrder.interleaved)
+ mesh.setVtxCoords(ents, verts, iBase.StorageOrder.interleaved)
- coords = mesh.getVtxCoords(ents, iBase.storageOrder.interleaved)
+ coords = mesh.getVtxCoords(ents, iBase.StorageOrder.interleaved)
self.assert_( (coords == verts).all())
def testCreateEntArr(self):
- mesh = iMesh()
+ mesh = iMesh.Mesh()
verts = [[0,0,0], [0,0,1], [0,1,0], [0,1,1]]
- ents = mesh.createVtx(verts, iBase.storageOrder.interleaved)
+ ents = mesh.createVtx(verts, iBase.StorageOrder.interleaved)
root = mesh.rootSet
- topo = iMesh.topology
+ topo = iMesh.Topology
lines = mesh.createEntArr(topo.line_segment,ents)[0]
- self.assertEqual(root.getNumOfType(iBase.type.vertex), 4)
- self.assertEqual(root.getNumOfType(iBase.type.edge), 2)
+ self.assertEqual(root.getNumOfType(iBase.Type.vertex), 4)
+ self.assertEqual(root.getNumOfType(iBase.Type.edge), 2)
self.assertEqual(root.getNumOfTopo(topo.point), 4)
self.assertEqual(root.getNumOfTopo(topo.line_segment), 2)
@@ -76,41 +76,41 @@
def testSave(self):
file = tempfile.NamedTemporaryFile()
- mesh = iMesh()
+ mesh = iMesh.Mesh()
verts = [1,2,3]
mesh.createVtx(verts)
mesh.save(file.name)
- mesh = iMesh()
+ mesh = iMesh.Mesh()
root = mesh.rootSet
mesh.load(file.name)
- ents = root.getEntities(iBase.type.all, iMesh.topology.all)
+ ents = root.getEntities(iBase.Type.all, iMesh.Topology.all)
- self.assertEqual(root.getNumOfType(iBase.type.vertex), 1)
- self.assertEqual(root.getNumOfTopo(iMesh.topology.point), 1)
+ self.assertEqual(root.getNumOfType(iBase.Type.vertex), 1)
+ self.assertEqual(root.getNumOfTopo(iMesh.Topology.point), 1)
- coords = mesh.getVtxCoords(ents, iBase.storageOrder.interleaved)
+ coords = mesh.getVtxCoords(ents, iBase.StorageOrder.interleaved)
self.assert_( (coords == [1,2,3]).all() )
def testAltSave(self):
file = tempfile.NamedTemporaryFile()
- mesh = iMesh()
+ mesh = iMesh.Mesh()
verts = [1,2,3]
mesh.createVtx(verts)
mesh.rootSet.save(file.name)
- mesh = iMesh()
+ mesh = iMesh.Mesh()
root = mesh.rootSet
root.load(file.name)
- ents = root.getEntities(iBase.type.all, iMesh.topology.all)
+ ents = root.getEntities(iBase.Type.all, iMesh.Topology.all)
- self.assertEqual(root.getNumOfType(iBase.type.vertex), 1)
- self.assertEqual(root.getNumOfTopo(iMesh.topology.point), 1)
+ self.assertEqual(root.getNumOfType(iBase.Type.vertex), 1)
+ self.assertEqual(root.getNumOfTopo(iMesh.Topology.point), 1)
- coords = mesh.getVtxCoords(ents, iBase.storageOrder.interleaved)
+ coords = mesh.getVtxCoords(ents, iBase.StorageOrder.interleaved)
self.assert_( (coords == [1,2,3]).all() )
Modified: MOAB/trunk/tools/iMesh/python/test/entset.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/entset.py 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/test/entset.py 2009-05-29 23:31:46 UTC (rev 2919)
@@ -3,7 +3,7 @@
class TestEntSet(unittest.TestCase):
def setUp(self):
- self.mesh = iMesh()
+ self.mesh = iMesh.Mesh()
self.set = self.mesh.createEntSet(True)
def tearDown(self):
@@ -33,7 +33,7 @@
def testEntArr(self):
ents = self.mesh.createVtx([[1,2,3], [4,5,6], [7,8,9]],
- iBase.storageOrder.interleaved)
+ iBase.StorageOrder.interleaved)
self.assertFalse(self.set.contains(ents).any())
@@ -74,7 +74,7 @@
def testSubtract(self):
set2 = self.mesh.createEntSet(True)
ents = self.mesh.createVtx([[1,2,3], [4,5,6]],
- iBase.storageOrder.interleaved)
+ iBase.StorageOrder.interleaved)
self.set.add(ents)
set2.add(ents[0])
@@ -89,7 +89,7 @@
def testIntersect(self):
set2 = self.mesh.createEntSet(True)
ents = self.mesh.createVtx([[1,2,3], [4,5,6], [7,8,9]],
- iBase.storageOrder.interleaved)
+ iBase.StorageOrder.interleaved)
self.set.add(ents[0:2])
set2.add(ents[1:3])
@@ -106,7 +106,7 @@
def testUnite(self):
set2 = self.mesh.createEntSet(True)
ents = self.mesh.createVtx([[1,2,3], [4,5,6]],
- iBase.storageOrder.interleaved)
+ iBase.StorageOrder.interleaved)
self.set.add(ents[0])
set2.add(ents[1])
Modified: MOAB/trunk/tools/iMesh/python/test/iter.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/iter.py 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/test/iter.py 2009-05-29 23:31:46 UTC (rev 2919)
@@ -3,7 +3,7 @@
class TestIter(unittest.TestCase):
def setUp(self):
- self.mesh = iMesh()
+ self.mesh = iMesh.Mesh()
self.empty = self.mesh.createEntSet(True)
self.ent = self.mesh.createVtx([1,2,3])
@@ -11,30 +11,30 @@
self.set.add(self.ent)
def testEmpty(self):
- for i in self.empty.iterate(iBase.type.all, iMesh.topology.all):
+ for i in self.empty.iterate(iBase.Type.all, iMesh.Topology.all):
self.fail('empty iterator has >0 elements')
def testArrEmpty(self):
- for i in self.empty.iterate(iBase.type.all, iMesh.topology.all, 16):
+ for i in self.empty.iterate(iBase.Type.all, iMesh.Topology.all, 16):
self.fail('empty iterator has >0 elements')
def testSingle(self):
count = 0
- for i in self.set.iterate(iBase.type.all, iMesh.topology.all):
+ for i in self.set.iterate(iBase.Type.all, iMesh.Topology.all):
count += 1
self.assertEqual(i, self.ent)
self.assertEqual(count, 1)
def testArr(self):
count = 0
- for i in self.set.iterate(iBase.type.all, iMesh.topology.all, 16):
+ for i in self.set.iterate(iBase.Type.all, iMesh.Topology.all, 16):
count += 1
self.assertEqual(i[0], self.ent)
self.assertEqual(count,1)
def testAlternate(self):
count = 0
- iter = iMesh.iterator(self.set, iBase.type.all, iMesh.topology.all)
+ iter = iMesh.Iterator(self.set, iBase.Type.all, iMesh.Topology.all)
for i in iter:
count += 1
self.assertEqual(i, self.ent)
Modified: MOAB/trunk/tools/iMesh/python/test/tags.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/tags.py 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/test/tags.py 2009-05-29 23:31:46 UTC (rev 2919)
@@ -4,7 +4,7 @@
class TestTags(unittest.TestCase):
def setUp(self):
- self.mesh = iMesh()
+ self.mesh = iMesh.Mesh()
self.itag = self.mesh.createTag('int', 1, 'i')
self.dtag = self.mesh.createTag('double', 1, 'd')
@@ -12,7 +12,7 @@
self.btag = self.mesh.createTag('bytes', 3, 'b')
self.ents = self.mesh.createVtx([[1,2,3], [4,5,6], [7,8,9]],
- iBase.storageOrder.interleaved)
+ iBase.StorageOrder.interleaved)
self.ent = self.ents[0]
self.set = self.mesh.createEntSet(True)
Modified: MOAB/trunk/tools/iMesh/python/tools/volume.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/tools/volume.py 2009-05-28 23:14:04 UTC (rev 2918)
+++ MOAB/trunk/tools/iMesh/python/tools/volume.py 2009-05-29 23:31:46 UTC (rev 2919)
@@ -27,19 +27,19 @@
subvolume(coords[1], coords[2], coords[5], coords[6], coords[7])
def calc_volume(filename):
- mesh = iMesh()
+ mesh = iMesh.Mesh()
mesh.load(filename)
- volume = ndarray(mesh.rootSet.getNumOfType(iBase.type.region), float_)
+ volume = ndarray(mesh.rootSet.getNumOfType(iBase.Type.region), float_)
x=0
- for i in mesh.rootSet.iterate(iBase.type.region, iMesh.topology.all):
+ for i in mesh.rootSet.iterate(iBase.Type.region, iMesh.Topology.all):
topo = mesh.getEntTopo(i)
- curr = mesh.getVtxCoords( mesh.getEntAdj(i, iBase.type.vertex),
- iBase.storageOrder.interleaved )
+ curr = mesh.getVtxCoords( mesh.getEntAdj(i, iBase.Type.vertex),
+ iBase.StorageOrder.interleaved )
- if topo == iMesh.topology.tetrahedron:
+ if topo == iMesh.Topology.tetrahedron:
volume[x] = tet_volume(curr)
- elif topo == iMesh.topology.hexahedron:
+ elif topo == iMesh.Topology.hexahedron:
volume[x] = hex_volume(curr)
else:
assert(False)
More information about the moab-dev
mailing list