[cig-commits] r6803 - in short/3D/PyLith/trunk: libsrc/meshio
modulesrc/faults modulesrc/feassemble modulesrc/materials
modulesrc/meshio modulesrc/solver modulesrc/topology
modulesrc/utils pylith pylith/meshio
unittests/libtests/meshio unittests/libtests/meshio/data
unittests/pytests/meshio unittests/pytests/meshio/data
brad at geodynamics.org
brad at geodynamics.org
Tue May 8 16:33:53 PDT 2007
Author: brad
Date: 2007-05-08 16:33:52 -0700 (Tue, 08 May 2007)
New Revision: 6803
Added:
short/3D/PyLith/trunk/pylith/meshio/MeshIOCubit.py
short/3D/PyLith/trunk/unittests/pytests/meshio/TestMeshIOCubit.py
short/3D/PyLith/trunk/unittests/pytests/meshio/TestMeshIOLagrit.py
short/3D/PyLith/trunk/unittests/pytests/meshio/data/cube2.txt
short/3D/PyLith/trunk/unittests/pytests/meshio/data/cube2_ascii.gmv
short/3D/PyLith/trunk/unittests/pytests/meshio/data/cube2_ascii.pset
short/3D/PyLith/trunk/unittests/pytests/meshio/data/twohex8.exo
short/3D/PyLith/trunk/unittests/pytests/meshio/data/twohex8.txt
Modified:
short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc
short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.cc
short/3D/PyLith/trunk/libsrc/meshio/PsetFileBinary.cc
short/3D/PyLith/trunk/modulesrc/faults/Makefile.am
short/3D/PyLith/trunk/modulesrc/feassemble/Makefile.am
short/3D/PyLith/trunk/modulesrc/materials/Makefile.am
short/3D/PyLith/trunk/modulesrc/meshio/Makefile.am
short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src
short/3D/PyLith/trunk/modulesrc/solver/Makefile.am
short/3D/PyLith/trunk/modulesrc/topology/Makefile.am
short/3D/PyLith/trunk/modulesrc/utils/Makefile.am
short/3D/PyLith/trunk/pylith/Makefile.am
short/3D/PyLith/trunk/pylith/meshio/MeshIOLagrit.py
short/3D/PyLith/trunk/pylith/meshio/__init__.py
short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIO.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/data/cube2_binary.pset
short/3D/PyLith/trunk/unittests/libtests/meshio/test_meshio.cc
short/3D/PyLith/trunk/unittests/pytests/meshio/Makefile.am
short/3D/PyLith/trunk/unittests/pytests/meshio/data/Makefile.am
short/3D/PyLith/trunk/unittests/pytests/meshio/testdriver.py
Log:
Added Python unit tests for importing meshes from LaGriT and Cubit. Fixed a few deficiencies in C++ tests. Fixed bugs in corresponding C++ code.
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc 2007-05-08 23:33:52 UTC (rev 6803)
@@ -17,6 +17,7 @@
#include "GMVFileAscii.hh" // USES GMVFileAscii
#include "GMVFileBinary.hh" // USES GMVFileBinary
#include "PsetFileAscii.hh" // USES PsetFileAscii
+#include "PsetFileBinary.hh" // USES PsetFileBinary
#include "pylith/utils/array.hh" // USES double_array, int_array
@@ -64,20 +65,18 @@
cells, numCells, numCorners, meshDim);
_setMaterials(materialIds);
-#if 0
std::vector<PsetFile::Pset> groups;
if (PsetFile::isAscii(_filenamePset.c_str())) {
PsetFileAscii filein(_filenamePset.c_str());
filein.read(&groups);
} else {
- PsetFileBinary filein(_filenamePset.c_str());
+ PsetFileBinary filein(_filenamePset.c_str(), _flipEndian);
filein.read(&groups);
} // if/else
GroupPtType type = VERTEX;
const int numGroups = groups.size();
for (int iGroup=0; iGroup < numGroups; ++iGroup)
_setGroup(groups[iGroup].name, type, groups[iGroup].points);
-#endif
} // _read
// ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.cc 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/libsrc/meshio/PsetFileAscii.cc 2007-05-08 23:33:52 UTC (rev 6803)
@@ -143,6 +143,8 @@
for (int i=0; i < size; ++i)
fin >> group->points[i];
+ group->points -= 1; // use zero base
+
info << "Done." << journal::endl;
} // _readPset
@@ -161,7 +163,7 @@
const int numCols = 10;
for (int i=0, iCol=0; i < size; ++i) {
- fout << std::setw(8) << group.points[i];
+ fout << std::setw(8) << 1+group.points[i];
if (++iCol == numCols) {
fout << std::endl;
iCol = 0;
Modified: short/3D/PyLith/trunk/libsrc/meshio/PsetFileBinary.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/PsetFileBinary.cc 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/libsrc/meshio/PsetFileBinary.cc 2007-05-08 23:33:52 UTC (rev 6803)
@@ -66,11 +66,12 @@
// Read number of psets
int numGroups = 0;
- fin.read((char*) numGroups, sizeof(int));
+ fin.read((char*) &numGroups, sizeof(int));
if (_flipEndian)
BinaryIO::swapByteOrder((char*) &numGroups, 1, sizeof(int));
assert(numGroups >= 0);
groups->resize(numGroups);
+ std::string extra = BinaryIO::readString(fin, 8);
// Read groups
info << "Reading " << numGroups << " point sets from file." << journal::endl;
@@ -114,6 +115,8 @@
void
pylith::meshio::PsetFileBinary::_readHeader(std::ifstream& fin)
{ // _readHeader
+ std::string extra = BinaryIO::readString(fin, 4); // Read superfluous 4 bytes
+
std::string header = BinaryIO::readString(fin, strlen(_HEADER));
std::string headerE = _HEADER;
headerE = headerE.substr(0, headerE.find_first_of(" "));
@@ -151,18 +154,21 @@
int size = 0;
fin.read((char*) &size, sizeof(int));
+ std::string extra = BinaryIO::readString(fin, 8);
if (_flipEndian)
BinaryIO::swapByteOrder((char*) &size, 1, sizeof(size));
assert(size >= 0);
-
info << "Reading point set '" << group->name << "' with " << size
<< " points." << journal::endl;
group->points.resize(size);
fin.read((char*) &group->points[0], size*sizeof(int));
+ extra = BinaryIO::readString(fin, 8);
if (_flipEndian)
BinaryIO::swapByteOrder((char*) &group->points[0], size, sizeof(int));
+ group->points -= 1; // use zero base
+
info << "Done." << journal::endl;
} // _readPset
@@ -189,6 +195,7 @@
fout.write((char*) &sizeIO, sizeof(int));
int_array pointsIO(group.points);
+ pointsIO += 1; // switch from zero base to one base
if (_flipEndian)
BinaryIO::swapByteOrder((char*) &pointsIO[0], size, sizeof(int));
fout.write((char*) &pointsIO[0], size*sizeof(int));
Modified: short/3D/PyLith/trunk/modulesrc/faults/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/faults/Makefile.am 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/modulesrc/faults/Makefile.am 2007-05-08 23:33:52 UTC (rev 6803)
@@ -26,6 +26,10 @@
$(top_builddir)/libsrc/libpylith.la \
$(PETSC_LIB)
+if ENABLE_CUBIT
+ faultsmodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
+endif
+
INCLUDES += -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
faults.pyx faults_embed.cpp faults_embed.h: faults.pyxe
Modified: short/3D/PyLith/trunk/modulesrc/feassemble/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/feassemble/Makefile.am 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/modulesrc/feassemble/Makefile.am 2007-05-08 23:33:52 UTC (rev 6803)
@@ -26,6 +26,10 @@
$(top_builddir)/libsrc/libpylith.la \
$(PETSC_LIB)
+if ENABLE_CUBIT
+ feassemblemodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
+endif
+
INCLUDES += -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
feassemble.pyx feassemble_embed.cpp feassemble_embed.h: feassemble.pyxe
Modified: short/3D/PyLith/trunk/modulesrc/materials/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/materials/Makefile.am 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/modulesrc/materials/Makefile.am 2007-05-08 23:33:52 UTC (rev 6803)
@@ -26,6 +26,10 @@
$(top_builddir)/libsrc/libpylith.la \
$(PETSC_LIB)
+if ENABLE_CUBIT
+ materialsmodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
+endif
+
INCLUDES += -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
materials.pyx materials_embed.cpp materials_embed.h: materials.pyxe
Modified: short/3D/PyLith/trunk/modulesrc/meshio/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/meshio/Makefile.am 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/modulesrc/meshio/Makefile.am 2007-05-08 23:33:52 UTC (rev 6803)
@@ -26,6 +26,10 @@
$(top_builddir)/libsrc/libpylith.la \
$(PETSC_LIB)
+if ENABLE_CUBIT
+ meshiomodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
+endif
+
INCLUDES += -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
PYREX_INCLUDES = -I$(top_srcdir)/modulesrc/topology
Modified: short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src 2007-05-08 23:33:52 UTC (rev 6803)
@@ -13,6 +13,7 @@
#header{
#include "pylith/meshio/MeshIO.hh"
#include "pylith/meshio/MeshIOAscii.hh"
+#include "pylith/meshio/MeshIOCubit.hh"
#include "pylith/meshio/MeshIOLagrit.hh"
#include <stdexcept>
@@ -288,6 +289,72 @@
# ----------------------------------------------------------------------
+cdef class MeshIOCubit(MeshIO):
+
+ def __init__(self):
+ """Constructor."""
+ # create shim for constructor
+ #embed{ void* MeshIOCubit_constructor()
+ void* result = 0;
+ try {
+ result = (void*)(new pylith::meshio::MeshIOCubit);
+ assert(0 != result);
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ return result;
+ #}embed
+
+ MeshIO.__init__(self)
+ self.thisptr = MeshIOCubit_constructor()
+ self.handle = self._createHandle()
+ return
+
+
+ property filename:
+ def __set__(self, name):
+ """Set filename."""
+ # create shim for method 'filename'
+ #embed{ void MeshIOCubit_filename_set(void* objVptr, char* name)
+ try {
+ assert(0 != objVptr);
+ ((pylith::meshio::MeshIOCubit*) objVptr)->filename(name);
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ #}embed
+ MeshIOCubit_filename_set(self.thisptr, name)
+
+ def __get__(self):
+ """Get filename."""
+ # create shim for method 'filename'
+ #embed{ char* MeshIOCubit_filename_get(void* objVptr)
+ char* result = 0;
+ try {
+ assert(0 != objVptr);
+ result = (char*) ((pylith::meshio::MeshIOCubit*) objVptr)->filename();
+ assert(0 != result);
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ return result;
+ #}embed
+ return MeshIOCubit_filename_get(self.thisptr)
+
+
+# ----------------------------------------------------------------------
cdef class MeshIOLagrit(MeshIO):
def __init__(self):
Modified: short/3D/PyLith/trunk/modulesrc/solver/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/solver/Makefile.am 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/modulesrc/solver/Makefile.am 2007-05-08 23:33:52 UTC (rev 6803)
@@ -26,6 +26,10 @@
$(top_builddir)/libsrc/libpylith.la \
$(PETSC_LIB)
+if ENABLE_CUBIT
+ solvermodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
+endif
+
INCLUDES += -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
solver.pyx solver_embed.cpp solver_embed.h: solver.pyxe
Modified: short/3D/PyLith/trunk/modulesrc/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/Makefile.am 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/modulesrc/topology/Makefile.am 2007-05-08 23:33:52 UTC (rev 6803)
@@ -26,6 +26,10 @@
$(top_builddir)/libsrc/libpylith.la \
$(PETSC_LIB)
+if ENABLE_CUBIT
+ topologymodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
+endif
+
INCLUDES += -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
topology.pyx topology_embed.cpp topology_embed.h: topology.pyxe
Modified: short/3D/PyLith/trunk/modulesrc/utils/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/utils/Makefile.am 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/modulesrc/utils/Makefile.am 2007-05-08 23:33:52 UTC (rev 6803)
@@ -26,6 +26,10 @@
$(top_builddir)/libsrc/libpylith.la \
$(PETSC_LIB)
+if ENABLE_CUBIT
+ petscmodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
+endif
+
INCLUDES += -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
petsc.pyx petsc_embed.cpp petsc_embed.h: petsc.pyxe
Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/pylith/Makefile.am 2007-05-08 23:33:52 UTC (rev 6803)
@@ -48,6 +48,7 @@
materials/MaterialsBin.py \
meshio/MeshIO.py \
meshio/MeshIOAscii.py \
+ meshio/MeshIOCubit.py \
meshio/MeshIOLagrit.py \
meshio/__init__.py \
problems/__init__.py \
Added: short/3D/PyLith/trunk/pylith/meshio/MeshIOCubit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/MeshIOCubit.py 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/pylith/meshio/MeshIOCubit.py 2007-05-08 23:33:52 UTC (rev 6803)
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pyre/meshio/MeshIOCubit.py
+##
+## @brief Python object for reading/writing finite-element mesh from
+## Cubit.
+##
+## Factory: mesh_io
+
+from MeshIO import MeshIO
+
+# MeshIOCubit class
+class MeshIOCubit(MeshIO):
+ """
+ Python object for reading/writing finite-element mesh from Cubit.
+
+ Factory: mesh_io
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(MeshIO.Inventory):
+ """
+ Python object for managing MeshIOCubit facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing MeshIOCubit facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b filename Name of Cubit Exodus file.
+ ##
+ ## \b Facilities
+ ## @li coordsys Coordinate system associated with mesh.
+
+ import pyre.inventory
+
+ filename = pyre.inventory.str("filename", default="mesh.exo")
+ filename.meta['tip'] = "Name of Cubit Exodus file."
+
+ from spatialdata.geocoords.CSCart import CSCart
+ coordsys = pyre.inventory.facility("coordsys", family="coordsys",
+ factory=CSCart)
+ coordsys.meta['tip'] = "Coordinate system associated with mesh."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="meshiocubit"):
+ """
+ Constructor.
+ """
+ MeshIO.__init__(self, name)
+ import pylith.meshio.meshio as bindings
+ self.cppHandle = bindings.MeshIOCubit()
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ MeshIO._configure(self)
+ self.filename = self.inventory.filename
+ self.coordsys = self.inventory.coordsys
+ return
+
+
+ def _sync(self):
+ """
+ Force synchronization between Python and C++.
+ """
+ MeshIO._sync(self)
+ self.cppHandle.filename = self.filename
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def mesh_io():
+ """
+ Factory associated with MeshIOCubit.
+ """
+ return MeshIOCubit()
+
+
+# End of file
Modified: short/3D/PyLith/trunk/pylith/meshio/MeshIOLagrit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/MeshIOLagrit.py 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/pylith/meshio/MeshIOLagrit.py 2007-05-08 23:33:52 UTC (rev 6803)
@@ -65,7 +65,7 @@
# PUBLIC METHODS /////////////////////////////////////////////////////
- def __init__(self, name="meshiogmv"):
+ def __init__(self, name="meshiolagrit"):
"""
Constructor.
"""
Modified: short/3D/PyLith/trunk/pylith/meshio/__init__.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/__init__.py 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/pylith/meshio/__init__.py 2007-05-08 23:33:52 UTC (rev 6803)
@@ -16,6 +16,7 @@
__all__ = ['MeshIO',
'MeshIOAscii',
+ 'MeshIOCubit',
'MeshIOLagrit']
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIO.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIO.cc 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestMeshIO.cc 2007-05-08 23:33:52 UTC (rev 6803)
@@ -175,6 +175,10 @@
// Check groups
const ALE::Obj<std::set<std::string> >& groupNames =
mesh->getIntSections();
+ if (data.numGroups > 0) {
+ CPPUNIT_ASSERT(!groupNames.isNull());
+ CPPUNIT_ASSERT_EQUAL(data.numGroups, int(groupNames->size()));
+ } // if
int iGroup = 0;
int index = 0;
for (std::set<std::string>::const_iterator name=groupNames->begin();
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/data/cube2_binary.pset
===================================================================
(Binary files differ)
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/test_meshio.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/test_meshio.cc 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/test_meshio.cc 2007-05-08 23:33:52 UTC (rev 6803)
@@ -32,6 +32,9 @@
main(int argc,
char* argv[])
{ // main
+ //journal::info_t info("meshiocubit");
+ //info.activate();
+
CppUnit::TestResultCollector result;
try {
@@ -42,9 +45,6 @@
// Initialize Python
Py_Initialize();
- journal::info_t info("meshiocubit");
- //info.activate();
-
// Create event manager and test controller
CppUnit::TestResult controller;
Modified: short/3D/PyLith/trunk/unittests/pytests/meshio/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/Makefile.am 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/Makefile.am 2007-05-08 23:33:52 UTC (rev 6803)
@@ -20,7 +20,9 @@
check_SCRIPTS = testdriver.py
noinst_PYTHON = \
- TestMeshIOAscii.py
+ TestMeshIOAscii.py \
+ TestMeshIOCubit.py \
+ TestMeshIOLagrit.py
# End of file
Added: short/3D/PyLith/trunk/unittests/pytests/meshio/TestMeshIOCubit.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/TestMeshIOCubit.py 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/TestMeshIOCubit.py 2007-05-08 23:33:52 UTC (rev 6803)
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/meshio/TestMeshIOCubit.py
+
+## @brief Unit testing of Python MeshIOCubit object.
+
+import unittest
+
+from pylith.meshio.MeshIOCubit import MeshIOCubit
+from pylith.meshio.MeshIOAscii import MeshIOAscii
+
+# ----------------------------------------------------------------------
+class TestMeshIOCubit(unittest.TestCase):
+ """
+ Unit testing of Python MeshIOCubit object.
+ """
+
+ def test_constructor(self):
+ """
+ Test constructor.
+ """
+ iohandler = MeshIOCubit()
+ self.assertNotEqual(None, iohandler.cppHandle)
+ return
+
+
+ def test_filename(self):
+ """
+ Test filename().
+ """
+ iohandler = MeshIOCubit()
+ value = "hi.txt"
+ iohandler.filename = value
+ self.assertEqual(value, iohandler.filename)
+ return
+
+
+ def test_readwrite(self):
+ """
+ Test read().
+ """
+ from spatialdata.geocoords.CSCart import CSCart
+
+ # For now, we only test reading the file.
+ iohandler = MeshIOCubit()
+
+ filenameIn = "data/twohex8.exo"
+ filenameOut = "data/twohex8_test.txt"
+ filenameE = "data/twohex8.txt"
+
+ iohandler.filename = filenameIn
+ iohandler.coordsys = CSCart()
+ mesh = iohandler.read(debug=False, interpolate=False)
+ self.assertEqual(3, mesh.dimension())
+
+ testhandler = MeshIOAscii()
+ testhandler.filename = filenameOut
+ testhandler.coordsys = CSCart()
+ testhandler.write(mesh)
+
+ fileE = open(filenameE, "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
+
+
+# End of file
Added: short/3D/PyLith/trunk/unittests/pytests/meshio/TestMeshIOLagrit.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/TestMeshIOLagrit.py 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/TestMeshIOLagrit.py 2007-05-08 23:33:52 UTC (rev 6803)
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/meshio/TestMeshIOLagrit.py
+
+## @brief Unit testing of Python MeshIOLagrit object.
+
+import unittest
+
+from pylith.meshio.MeshIOLagrit import MeshIOLagrit
+from pylith.meshio.MeshIOAscii import MeshIOAscii
+
+# ----------------------------------------------------------------------
+class TestMeshIOLagrit(unittest.TestCase):
+ """
+ Unit testing of Python MeshIOLagrit object.
+ """
+
+ def test_constructor(self):
+ """
+ Test constructor.
+ """
+ iohandler = MeshIOLagrit()
+ self.assertNotEqual(None, iohandler.cppHandle)
+ return
+
+
+ def test_filename(self):
+ """
+ Test filename().
+ """
+ iohandler = MeshIOLagrit()
+ valueGmv = "hi.txt"
+ valuePset = "hi2.txt"
+ iohandler.filenameGmv = valueGmv
+ iohandler.filenamePset = valuePset
+ self.assertEqual(valueGmv, iohandler.filenameGmv)
+ self.assertEqual(valuePset, iohandler.filenamePset)
+ return
+
+
+ def test_readwrite(self):
+ """
+ Test read().
+ """
+ from spatialdata.geocoords.CSCart import CSCart
+
+ # For now, we only test reading the file. We would like to write
+ # the file and compare against the original.
+ iohandler = MeshIOLagrit()
+
+ filenameGmvIn = "data/cube2_ascii.gmv"
+ filenamePsetIn = "data/cube2_ascii.pset"
+ filenameOut = "data/cube2_test.txt"
+ filenameE = "data/cube2.txt"
+
+ iohandler.filenameGmv = filenameGmvIn
+ iohandler.filenamePset = filenamePsetIn
+ iohandler.coordsys = CSCart()
+ mesh = iohandler.read(debug=False, interpolate=False)
+ self.assertEqual(3, mesh.dimension())
+
+ testhandler = MeshIOAscii()
+ testhandler.filename = filenameOut
+ testhandler.coordsys = CSCart()
+ testhandler.write(mesh)
+
+ fileE = open(filenameE, "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
+
+
+# End of file
Modified: short/3D/PyLith/trunk/unittests/pytests/meshio/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/data/Makefile.am 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/data/Makefile.am 2007-05-08 23:33:52 UTC (rev 6803)
@@ -11,10 +11,17 @@
#
noinst_DATA = \
- mesh2Din3D.txt
+ mesh2Din3D.txt \
+ cube2_ascii.gmv \
+ cube2_ascii.pset \
+ cube2.txt \
+ twohex8.exo \
+ twohex8.txt
noinst_TMP = \
- mesh2Din3D_test.txt
+ cube2_test.txt \
+ mesh2Din3D_test.txt \
+ twohex8_test.txt
# 'export' the input files by performing a mock install
export_datadir = $(top_builddir)/unittests/pytests/meshio/data
Added: short/3D/PyLith/trunk/unittests/pytests/meshio/data/cube2.txt
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/data/cube2.txt 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/data/cube2.txt 2007-05-08 23:33:52 UTC (rev 6803)
@@ -0,0 +1,139 @@
+mesh = {
+ dimension = 3
+ use-index-zero = true
+ vertices = {
+ dimension = 3
+ count = 12
+ coordinates = {
+ 0 0.000000e+00 -5.000000e-01 -5.000000e-01
+ 1 0.000000e+00 -5.000000e-01 5.000000e-01
+ 2 1.000000e+00 -5.000000e-01 -5.000000e-01
+ 3 1.000000e+00 -5.000000e-01 5.000000e-01
+ 4 0.000000e+00 5.000000e-01 -5.000000e-01
+ 5 0.000000e+00 5.000000e-01 5.000000e-01
+ 6 1.000000e+00 5.000000e-01 -5.000000e-01
+ 7 1.000000e+00 5.000000e-01 5.000000e-01
+ 8 -1.000000e+00 -5.000000e-01 -5.000000e-01
+ 9 -1.000000e+00 -5.000000e-01 5.000000e-01
+ 10 -1.000000e+00 5.000000e-01 -5.000000e-01
+ 11 -1.000000e+00 5.000000e-01 5.000000e-01
+ }
+ }
+ cells = {
+ count = 12
+ num-corners = 4
+ simplices = {
+ 0 9 5 8 10
+ 1 8 9 1 5
+ 2 1 3 2 4
+ 3 8 5 4 10
+ 4 8 1 4 5
+ 5 5 3 6 7
+ 6 4 3 2 6
+ 7 5 3 4 6
+ 8 1 3 4 5
+ 9 9 5 10 11
+ 10 8 1 0 4
+ 11 0 1 2 4
+ }
+ material-ids = {
+ 0 2
+ 1 2
+ 2 1
+ 3 2
+ 4 2
+ 5 1
+ 6 1
+ 7 1
+ 8 1
+ 9 2
+ 10 2
+ 11 1
+ }
+ }
+ group = {
+ name = fault
+ type = vertices
+ count = 4
+ indices = {
+ 0
+ 1
+ 4
+ 5
+ }
+ }
+ group = {
+ name = xm
+ type = vertices
+ count = 4
+ indices = {
+ 8
+ 9
+ 10
+ 11
+ }
+ }
+ group = {
+ name = xp
+ type = vertices
+ count = 4
+ indices = {
+ 2
+ 3
+ 6
+ 7
+ }
+ }
+ group = {
+ name = ym
+ type = vertices
+ count = 6
+ indices = {
+ 0
+ 1
+ 2
+ 3
+ 8
+ 9
+ }
+ }
+ group = {
+ name = yp
+ type = vertices
+ count = 6
+ indices = {
+ 4
+ 5
+ 6
+ 7
+ 10
+ 11
+ }
+ }
+ group = {
+ name = zm
+ type = vertices
+ count = 6
+ indices = {
+ 0
+ 2
+ 4
+ 6
+ 8
+ 10
+ }
+ }
+ group = {
+ name = zp
+ type = vertices
+ count = 6
+ indices = {
+ 1
+ 3
+ 5
+ 7
+ 9
+ 11
+ }
+ }
+}
Added: short/3D/PyLith/trunk/unittests/pytests/meshio/data/cube2_ascii.gmv
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/data/cube2_ascii.gmv 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/data/cube2_ascii.gmv 2007-05-08 23:33:52 UTC (rev 6803)
@@ -0,0 +1,52 @@
+gmvinput ascii
+codename LaGriT
+simdate 05/08/07
+nodes 12
+ 0.00000E+000 0.00000E+000 1.00000E+000 1.00000E+000 0.00000E+000 0.00000E+000 1.00000E+000 1.00000E+000 -1.00000E+000 -1.00000E+000
+ -1.00000E+000 -1.00000E+000
+ -5.00000E-001 -5.00000E-001 -5.00000E-001 -5.00000E-001 5.00000E-001 5.00000E-001 5.00000E-001 5.00000E-001 -5.00000E-001 -5.00000E-001
+ 5.00000E-001 5.00000E-001
+ -5.00000E-001 5.00000E-001 -5.00000E-001 5.00000E-001 -5.00000E-001 5.00000E-001 -5.00000E-001 5.00000E-001 -5.00000E-001 5.00000E-001
+ -5.00000E-001 5.00000E-001
+cells 12
+tet 4 10 9 6 11
+tet 4 9 2 10 6
+tet 4 2 3 4 5
+tet 4 9 5 6 11
+tet 4 9 5 2 6
+tet 4 6 7 4 8
+tet 4 5 3 4 7
+tet 4 6 5 4 7
+tet 4 2 5 4 6
+tet 4 10 11 6 12
+tet 4 9 1 2 5
+tet 4 1 3 2 5
+variable
+imt1 1
+ 2.00000E+000 2.00000E+000 1.00000E+000 1.00000E+000 2.00000E+000 1.00000E+000 1.00000E+000 1.00000E+000 2.00000E+000 2.00000E+000
+ 2.00000E+000 2.00000E+000
+itp1 1
+ 1.20000E+001 1.20000E+001 1.00000E+001 1.00000E+001 1.20000E+001 1.20000E+001 1.00000E+001 1.00000E+001 1.00000E+001 1.00000E+001
+ 1.00000E+001 1.00000E+001
+icr1 1
+ 1.10000E+001 1.20000E+001 1.30000E+001 1.40000E+001 1.70000E+001 1.80000E+001 1.90000E+001 2.00000E+001 1.50000E+001 1.60000E+001
+ 2.10000E+001 2.20000E+001
+isn1 1
+ 0.00000E+000 0.00000E+000 0.00000E+000 0.00000E+000 0.00000E+000 0.00000E+000 0.00000E+000 0.00000E+000 0.00000E+000 0.00000E+000
+ 0.00000E+000 0.00000E+000
+endvars
+flags
+imt1 3 1
+material
+material
+ERROR
+ 2 2 1 1 2 1 1 1 2 2 2 2
+endflag
+material 3 0
+material
+material
+ERROR
+ 2 2 1 2 2 1 1 1 1 2 2 1
+cycleno 0
+probtime 0.00000E+000
+endgmv
Added: short/3D/PyLith/trunk/unittests/pytests/meshio/data/cube2_ascii.pset
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/data/cube2_ascii.pset 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/data/cube2_ascii.pset 2007-05-08 23:33:52 UTC (rev 6803)
@@ -0,0 +1,16 @@
+pset ascii
+ 7
+fault 1 4
+ 1 2 5 6
+xm 2 4
+ 9 10 11 12
+xp 3 4
+ 3 4 7 8
+ym 4 6
+ 1 2 3 4 9 10
+yp 5 6
+ 5 6 7 8 11 12
+zm 6 6
+ 1 3 5 7 9 11
+zp 7 6
+ 2 4 6 8 10 12
Added: short/3D/PyLith/trunk/unittests/pytests/meshio/data/twohex8.exo
===================================================================
(Binary files differ)
Property changes on: short/3D/PyLith/trunk/unittests/pytests/meshio/data/twohex8.exo
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: short/3D/PyLith/trunk/unittests/pytests/meshio/data/twohex8.txt
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/data/twohex8.txt 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/data/twohex8.txt 2007-05-08 23:33:52 UTC (rev 6803)
@@ -0,0 +1,58 @@
+mesh = {
+ dimension = 3
+ use-index-zero = true
+ vertices = {
+ dimension = 3
+ count = 12
+ coordinates = {
+ 0 -2.000000e+00 -1.000000e+00 1.000000e+00
+ 1 -2.000000e+00 -1.000000e+00 -1.000000e+00
+ 2 -2.000000e+00 1.000000e+00 -1.000000e+00
+ 3 -2.000000e+00 1.000000e+00 1.000000e+00
+ 4 0.000000e+00 -1.000000e+00 1.000000e+00
+ 5 0.000000e+00 -1.000000e+00 -1.000000e+00
+ 6 0.000000e+00 1.000000e+00 -1.000000e+00
+ 7 0.000000e+00 1.000000e+00 1.000000e+00
+ 8 2.000000e+00 -1.000000e+00 1.000000e+00
+ 9 2.000000e+00 -1.000000e+00 -1.000000e+00
+ 10 2.000000e+00 1.000000e+00 -1.000000e+00
+ 11 2.000000e+00 1.000000e+00 1.000000e+00
+ }
+ }
+ cells = {
+ count = 2
+ num-corners = 8
+ simplices = {
+ 0 0 1 2 3 4 5 6 7
+ 1 4 5 6 7 8 9 10 11
+ }
+ material-ids = {
+ 0 7
+ 1 8
+ }
+ }
+ group = {
+ name = 2
+ type = vertices
+ count = 4
+ indices = {
+ 8
+ 9
+ 10
+ 11
+ }
+ }
+ group = {
+ name = 4
+ type = vertices
+ count = 6
+ indices = {
+ 0
+ 3
+ 4
+ 7
+ 8
+ 11
+ }
+ }
+}
Modified: short/3D/PyLith/trunk/unittests/pytests/meshio/testdriver.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/testdriver.py 2007-05-08 21:28:45 UTC (rev 6802)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/testdriver.py 2007-05-08 23:33:52 UTC (rev 6803)
@@ -57,6 +57,12 @@
from TestMeshIOAscii import TestMeshIOAscii
suite.addTest(unittest.makeSuite(TestMeshIOAscii))
+ from TestMeshIOCubit import TestMeshIOCubit
+ suite.addTest(unittest.makeSuite(TestMeshIOCubit))
+
+ from TestMeshIOLagrit import TestMeshIOLagrit
+ suite.addTest(unittest.makeSuite(TestMeshIOLagrit))
+
return suite
More information about the cig-commits
mailing list