[cig-commits] r6441 - in short/3D/PyLith/trunk: . examples/twotri3
libsrc/meshio modulesrc/meshio modulesrc/topology
unittests/libtests/meshio unittests/pytests/materials/data
unittests/pytests/meshio unittests/pytests/meshio/data
brad at geodynamics.org
brad at geodynamics.org
Tue Mar 27 14:13:26 PDT 2007
Author: brad
Date: 2007-03-27 14:13:25 -0700 (Tue, 27 Mar 2007)
New Revision: 6441
Added:
short/3D/PyLith/trunk/unittests/pytests/meshio/data/
short/3D/PyLith/trunk/unittests/pytests/meshio/data/Makefile.am
short/3D/PyLith/trunk/unittests/pytests/meshio/data/mesh2Din3D.txt
Removed:
short/3D/PyLith/trunk/unittests/pytests/meshio/testmeshio.pyxe.src
Modified:
short/3D/PyLith/trunk/TODO
short/3D/PyLith/trunk/configure.ac
short/3D/PyLith/trunk/examples/twotri3/twotri3.mesh
short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src
short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc
short/3D/PyLith/trunk/unittests/pytests/materials/data/twoelems.mesh
short/3D/PyLith/trunk/unittests/pytests/meshio/Makefile.am
short/3D/PyLith/trunk/unittests/pytests/meshio/TestMeshIOAscii.py
short/3D/PyLith/trunk/unittests/pytests/meshio/testdriver.py
Log:
Added indices for vertices and cells to MeshIOAscii files. Makes it easier for user to match cells, vertices, etc.
Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/TODO 2007-03-27 21:13:25 UTC (rev 6441)
@@ -21,22 +21,11 @@
a. Python object
b. unit tests at Python level
-3. Implement unit tests for MeshIO at Python level.
- a. read()/write()
- b. checkFile()
-
- STATUS:
-
- Replace write/read with read/write and check to make sure files
- are the same. A little more of pain to setup but doesn't require
- any messy module stuff.
-
======================================================================
SECONDARY PRIORITIES
======================================================================
0. Adjust MeshIOAscii format
- a. Add indices for coordinates, simplices, material ids (easier to see)
b. Add group of vertices
1. Implement MeshIOHDF5 & HDF5
@@ -127,3 +116,11 @@
Note: I think this would give us incredible flexibility in selecting
the appropriate discretization for a problem. For example, I think
it would allow us to use spectral elements.
+
+
+======================================================================
+QUESTIONS FOR LEIF
+======================================================================
+
+How do we trap C++ exceptions in Pyrex?
+
Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/configure.ac 2007-03-27 21:13:25 UTC (rev 6441)
@@ -167,6 +167,7 @@
unittests/pytests/materials/Makefile
unittests/pytests/materials/data/Makefile
unittests/pytests/meshio/Makefile
+ unittests/pytests/meshio/data/Makefile
doc/Makefile])
AC_OUTPUT
Modified: short/3D/PyLith/trunk/examples/twotri3/twotri3.mesh
===================================================================
--- short/3D/PyLith/trunk/examples/twotri3/twotri3.mesh 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/examples/twotri3/twotri3.mesh 2007-03-27 21:13:25 UTC (rev 6441)
@@ -4,21 +4,22 @@
dimension = 2
count = 4
coordinates = {
- -1.0 0.0
- 0.0 1.0
- 0.0 -1.0
- 1.0 0.0
+ 0 -1.0 0.0
+ 1 0.0 1.0
+ 2 0.0 -1.0
+ 3 1.0 0.0
}
}
cells = {
num-corners = 3
count = 2
simplices = {
- 0 2 1
- 1 2 3
+ 0 0 2 1
+ 1 1 2 3
}
material-ids = {
- 1 1
+ 0 1
+ 1 1
}
}
}
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2007-03-27 21:13:25 UTC (rev 6441)
@@ -79,6 +79,7 @@
const int meshDim)
{ // _buildMesh
assert(0 != _mesh);
+
*_mesh = new Mesh(PETSC_COMM_WORLD, meshDim);
ALE::Obj<Mesh>& mesh = *_mesh;
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc 2007-03-27 21:13:25 UTC (rev 6441)
@@ -181,8 +181,12 @@
filein.ignore(maxIgnore, '{');
delete[] coordinates; coordinates = new double[size];
assert(0 != coordinates);
- for (int i=0; i < size; ++i)
- filein >> coordinates[i];
+ int label;
+ for (int iVertex=0, i=0; iVertex < numVertices; ++iVertex) {
+ filein >> label;
+ for (int iDim=0; iDim < numDims; ++iDim)
+ filein >> coordinates[i++];
+ } // for
filein.ignore(maxIgnore, '}');
} else {
std::ostringstream msg;
@@ -222,6 +226,7 @@
<< std::setprecision(6);
for(int iVertex=0, i=0; iVertex < numVertices; ++iVertex) {
fileout << " ";
+ fileout << std::setw(8) << iVertex;
for(int iDim=0; iDim < spaceDim; ++iDim)
fileout << std::setw(18) << coordinates[i++];
fileout << "\n";
@@ -269,8 +274,12 @@
filein.ignore(maxIgnore, '{');
delete[] cells; cells = new int[size];
assert(0 != cells);
- for (int i=0; i < size; ++i)
- filein >> cells[i];
+ int label;
+ for (int iCell=0, i=0; iCell < numCells; ++iCell) {
+ filein >> label;
+ for (int iCorner=0; iCorner < numCorners; ++iCorner)
+ filein >> cells[i++];
+ } // for
if (!useIndexZero()) {
// if files begins with index 1, then decrement to index 0
// for compatibility with Sieve
@@ -289,8 +298,11 @@
filein.ignore(maxIgnore, '{');
delete[] materialIds; materialIds = new int[size];
assert(0 != materialIds);
- for (int i=0; i < size; ++i)
- filein >> materialIds[i];
+ int label = 0;
+ for (int iCell=0; iCell < numCells; ++iCell) {
+ filein >> label;
+ filein >> materialIds[iCell];
+ } // for
filein.ignore(maxIgnore, '}');
} else {
std::ostringstream msg;
@@ -338,10 +350,9 @@
<< " simplices = {\n";
for(int iCell=0, i=0; iCell < numCells; ++iCell) {
- fileout << " ";
+ fileout << " " << std::setw(8) << iCell;
for (int iCorner=0; iCorner < numCorners; ++iCorner)
- fileout << std::setw(8)
- << cells[i++];
+ fileout << std::setw(8) << cells[i++];
fileout << "\n";
} // for
fileout
@@ -355,8 +366,10 @@
(0 == materialIds && 0 == numCells) );
fileout
<< " material-ids = {\n";
- for(int iCell=0, i=0; iCell < numCells; ++iCell)
- fileout << " " << materialIds[iCell] << "\n";
+ for(int iCell=0, i=0; iCell < numCells; ++iCell) {
+ fileout << " " << std::setw(8) << iCell;
+ fileout << std::setw(4) << materialIds[iCell] << "\n";
+ } // for
fileout
<< " }\n";
delete[] materialIds; materialIds = 0;
Modified: short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src 2007-03-27 21:13:25 UTC (rev 6441)
@@ -69,8 +69,9 @@
"Caught unknown C++ exception.");
} // try/catch
#}embed
-
- #cdef topology.Mesh mesh
+ if mesh.name != "pylith_topology_Mesh":
+ raise TypeError, \
+ "Argument must be extension module type 'Mesh'."
MeshIO_read(self.thisptr, ptrFromHandle(mesh))
return
@@ -92,6 +93,9 @@
"Caught unknown C++ exception.");
} // try/catch
#}embed
+ if not mesh.name == "pylith_topology_Mesh":
+ raise TypeError, \
+ "Argument must be extension module type 'Mesh'."
MeshIO_write(self.thisptr, ptrFromHandle(mesh))
return
Modified: short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src 2007-03-27 21:13:25 UTC (rev 6441)
@@ -15,6 +15,7 @@
#include <stdexcept>
#include <Python.h>
+#include <assert.h>
#}header
# ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIOAscii.cc 2007-03-27 21:13:25 UTC (rev 6441)
@@ -120,6 +120,7 @@
MeshIOAscii iohandler;
iohandler.filename(filename);
iohandler.write(meshOut);
+ delete meshOut; meshOut = 0;
// Read mesh
ALE::Obj<Mesh> meshIn;
@@ -127,8 +128,6 @@
// Make sure meshIn matches data
checkVals(meshIn, data);
-
- delete meshOut; meshOut = 0;
} // _testWriteRead
// End of file
Modified: short/3D/PyLith/trunk/unittests/pytests/materials/data/twoelems.mesh
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/data/twoelems.mesh 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/data/twoelems.mesh 2007-03-27 21:13:25 UTC (rev 6441)
@@ -4,20 +4,21 @@
dimension = 1
count = 3
coordinates = {
- -1.0
- 0.0
- 1.0
+ 0 -1.0
+ 1 0.0
+ 2 1.0
}
}
cells = {
num-corners = 2
count = 2
simplices = {
- 0 1
- 1 2
+ 0 0 1
+ 1 1 2
}
material-ids = {
- 54 54
+ 0 54
+ 1 54
}
}
}
Modified: short/3D/PyLith/trunk/unittests/pytests/meshio/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/Makefile.am 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/Makefile.am 2007-03-27 21:13:25 UTC (rev 6441)
@@ -13,6 +13,8 @@
subpackage = meshio
include $(top_srcdir)/subpackage.am
+SUBDIRS = data
+
TESTS = testdriver.py
check_SCRIPTS = testdriver.py
@@ -22,37 +24,4 @@
TestMeshIOAscii.py
-# module
-subpkgpyexec_LTLIBRARIES = testmeshiomodule.la
-
-testmeshiomodule_la_LDFLAGS = -module
-
-testmeshiomodule_la_SOURCES = testmeshio.pyxe
-
-nodist_testmeshiomodule_la_SOURCES = \
- testmeshio.c testmeshio_embed.cpp testmeshio_embed.h \
- $(top_srcdir)/unittests/libtests/meshio/TestMeshIOAscii.cc
-
-testmeshiomodule_la_LIBADD = \
- $(PETSC_LIB)
-
-INCLUDES += \
- -I$(PYTHON_INCDIR) \
- $(PETSC_INCLUDE) \
- -I$(top_srcdir)/unittests/libtests/meshio
-
-testmeshio.pyx testmeshio_embed.cpp testmeshio_embed.h: testmeshio.pyxe
- pyrexembed testmeshio.pyxe
-testmeshio.pyxe: $(srcdir)/testmeshio.pyxe.src
- cp $(srcdir)/testmeshio.pyxe.src $@
-testmeshio_embed.cpp: testmeshio_embed.h
-testmeshio_embed.h: testmeshio.pyx
-
-.pyx.c:
- pyrexc $<
-
-CLEANFILES = \
- testmeshio.pyxe testmeshio.pyx testmeshio.c *_embed.* \
- $(am__installdirs)/testmeshiomodule.*
-
# End of file
Modified: short/3D/PyLith/trunk/unittests/pytests/meshio/TestMeshIOAscii.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/TestMeshIOAscii.py 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/TestMeshIOAscii.py 2007-03-27 21:13:25 UTC (rev 6441)
@@ -43,21 +43,29 @@
return
- def test_writeread(self):
+ def test_readwrite(self):
"""
Test write() and read().
"""
- filename = "mesh.txt"
-
- import pylith.meshio.testmeshio as testmodule
- mesh = testmodule.createMesh()
-
+ filenameIn = "data/mesh2Din3D.txt"
+ filenameOut = "data/mesh2Din3D_test.txt"
+
iohandler = MeshIOAscii()
- iohandler.filename = filename
+ iohandler.filename = filenameIn
+ mesh = iohandler.read()
+ iohandler.filename = filenameOut
iohandler.write(mesh)
- iohandler.read(mesh)
- testmodule.checkVals(mesh)
+ fileE = open(filenameIn, "r")
+ linesE = fileE.readlines()
+ fileE.close()
+ fileT = open(filenameOut, "r")
+ linesT = fileT.readlines()
+ fileT.close()
+
+ self.assertEqual(len(linesE), len(linesT))
+ for (lineE, lineT) in zip(linesE, linesT):
+ self.assertEqual(lineE, lineT)
return
Added: short/3D/PyLith/trunk/unittests/pytests/meshio/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/data/Makefile.am 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/data/Makefile.am 2007-03-27 21:13:25 UTC (rev 6441)
@@ -0,0 +1,31 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+noinst_DATA = \
+ mesh2Din3D.txt
+
+noinst_TMP = \
+ mesh2Din3D_test.txt
+
+# 'export' the input files by performing a mock install
+export_datadir = $(top_builddir)/unittests/pytests/meshio/data
+export-data: $(noinst_DATA)
+ for f in $(noinst_DATA); do $(install_sh_DATA) $(srcdir)/$$f $(export_datadir); done
+
+BUILT_SOURCES = export-data
+
+CLEANFILES = \
+ $(export_datadir)/$(noinst_DATA) \
+ $(export_datadir)/$(noinst_TMP)
+
+
+# End of file
Added: short/3D/PyLith/trunk/unittests/pytests/meshio/data/mesh2Din3D.txt
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/data/mesh2Din3D.txt 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/data/mesh2Din3D.txt 2007-03-27 21:13:25 UTC (rev 6441)
@@ -0,0 +1,33 @@
+mesh = {
+ dimension = 2
+ use-index-zero = true
+ vertices = {
+ dimension = 2
+ count = 9
+ coordinates = {
+ 0 -1.000000e+00 3.000000e+00
+ 1 2.000000e-01 1.000000e+00
+ 2 3.300000e+00 5.000000e-01
+ 3 -1.200000e+00 9.000000e-01
+ 4 3.000000e-01 9.000000e-01
+ 5 1.000000e+00 4.000000e-01
+ 6 3.000000e+00 2.900000e+00
+ 7 -1.000000e-01 6.000000e+00
+ 8 1.200000e+00 -2.000000e-01
+ }
+ }
+ cells = {
+ count = 3
+ num-corners = 4
+ simplices = {
+ 0 0 2 3 1
+ 1 4 3 6 5
+ 2 3 7 8 6
+ }
+ material-ids = {
+ 0 0
+ 1 1
+ 2 0
+ }
+ }
+}
Modified: short/3D/PyLith/trunk/unittests/pytests/meshio/testdriver.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/testdriver.py 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/testdriver.py 2007-03-27 21:13:25 UTC (rev 6441)
@@ -37,7 +37,11 @@
"""
Run the application.
"""
+ from pylith.utils.PetscManager import PetscManager
+ manager = PetscManager()
+ manager.initialize()
unittest.TextTestRunner(verbosity=2).run(self._suite())
+ manager.finalize()
return
Deleted: short/3D/PyLith/trunk/unittests/pytests/meshio/testmeshio.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/testmeshio.pyxe.src 2007-03-27 20:54:47 UTC (rev 6440)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/testmeshio.pyxe.src 2007-03-27 21:13:25 UTC (rev 6441)
@@ -1,105 +0,0 @@
-# -*- Pyrex -*-
-#
-# ======================================================================
-#
-# Brad T. Aagaard
-# U.S. Geological Survey
-#
-# {LicenseText}
-#
-# ======================================================================
-#
-
-#header{
-#include "pylith/meshio/MeshIO.hh"
-#include "TestMeshIO.hh"
-#include "data/MeshData.hh"
-#include "data/MeshData2Din3D.hh"
-#}header
-
-# ----------------------------------------------------------------------
-cdef extern from "Python.h":
- object PyCObject_FromVoidPtr(void*, void (*destruct)(void*))
- void* PyCObject_AsVoidPtr(object)
-
-cdef void* ptrFromHandle(obj):
- return PyCObject_AsVoidPtr(obj.handle)
-
-cdef extern from "stdlib.h":
- ctypedef unsigned long size_t
- void* malloc(size_t size)
- void free(void* mem)
-
-
-#embed{ void ALEMesh_destructor(void* pObj)
- ALE::Obj<ALE::Mesh>* pMesh = (ALE::Obj<ALE::Mesh>*) pObj;
- delete pMesh;
-#}embed
-
-# ----------------------------------------------------------------------
-cdef class TestMeshIO:
-
- cdef void* thisptr # Pointer to C++ object
- cdef readonly object handle # PyCObject holding pointer to C++ object
- cdef readonly object name # Identifier for object base type
-
- def __init__(self):
- """
- Constructor.
- """
- # create shim for constructor
- #embed{ void* TestMeshIO_constructor()
- return (void*)(new pylith::meshio::TestMeshIO);
- #}embed
-
- self.thisptr = TestMeshIO_constructor()
- self.handle = self._createHandle()
- self.name = "pylith_meshio_TestMeshIO"
- return
-
-
- def createMesh(self):
- """
- Create mesh from data.
- """
- # create shim for method 'createMesh'
- #embed{ void TestMeshIO_createMesh(void* pObj, void** meshObj)
- pylith::meshio::MeshData2Din3D data;
- ALE::Obj<ALE::Mesh>* mesh =
- ((pylith::meshio::TestMeshIO*) pObj)->createMesh(data);
- *meshObj = (void*) mesh;
- #}embed
-
- cdef void* meshObj
- meshObj = NULL
- TestMeshIO_createMesh(self.thisptr, &meshObj)
- return PyCObject_FromVoidPtr(meshObj, ALEMesh_destructor)
-
-
- def checkVals(self, mesh):
- """
- Check mesh to make sure it matches original mesh.
- """
- # create shim for method 'checkVals'
- #embed{ void TestMeshIO_checkVals(void* pObj, void* meshObj)
- ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshObj;
- pylith::meshio::MeshData2Din3D data;
- ((pylith::meshio::TestMeshIO*) pObj)->checkVals(*mesh, data);
- #}embed
- TestMeshIO_checkVals(self.thisptr, PyCObject_AsVoidPtr(mesh))
- return
-
-
- def _createHandle(self):
- """
- Wrap pointer to C++ object in PyCObject.
- """
- # create shim for destructor
- #embed{ void TestMeshIO_destructor(void* pObj)
- pylith::meshio::TestMeshIO* tester = (pylith::meshio::TestMeshIO*) pObj;
- delete tester;
- #}embed
- return PyCObject_FromVoidPtr(self.thisptr, TestMeshIO_destructor)
-
-
-# End of file
More information about the cig-commits
mailing list