[cig-commits] r6327 - in short/3D/PyLith/trunk: . modulesrc/meshio
pylith/materials pylith/meshio unittests/pytests/materials
unittests/pytests/materials/data
brad at geodynamics.org
brad at geodynamics.org
Tue Mar 20 22:45:31 PDT 2007
Author: brad
Date: 2007-03-20 22:45:30 -0700 (Tue, 20 Mar 2007)
New Revision: 6327
Added:
short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticIsotropic3D.py
short/3D/PyLith/trunk/unittests/pytests/materials/TestMaterial.py
short/3D/PyLith/trunk/unittests/pytests/materials/data/
short/3D/PyLith/trunk/unittests/pytests/materials/data/Makefile.am
short/3D/PyLith/trunk/unittests/pytests/materials/data/matinitialize.spatialdb
short/3D/PyLith/trunk/unittests/pytests/materials/data/twoelems.mesh
short/3D/PyLith/trunk/unittests/pytests/materials/testmaterials.py
Modified:
short/3D/PyLith/trunk/configure.ac
short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src
short/3D/PyLith/trunk/pylith/materials/ElasticIsotropic3D.py
short/3D/PyLith/trunk/pylith/materials/Material.py
short/3D/PyLith/trunk/pylith/meshio/MeshIO.py
short/3D/PyLith/trunk/pylith/meshio/MeshIOAscii.py
short/3D/PyLith/trunk/unittests/pytests/materials/Makefile.am
Log:
Worked on Python tests for materials. PETSc initialization doesn't seem to work in unit test.
Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/configure.ac 2007-03-21 05:45:30 UTC (rev 6327)
@@ -165,6 +165,7 @@
unittests/pytests/Makefile
unittests/pytests/feassemble/Makefile
unittests/pytests/materials/Makefile
+ unittests/pytests/materials/data/Makefile
unittests/pytests/meshio/Makefile
doc/Makefile])
Modified: short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src 2007-03-21 05:45:30 UTC (rev 6327)
@@ -15,6 +15,7 @@
#include "pylith/meshio/MeshIOAscii.hh"
#include <stdexcept>
+#include <assert.h>
#include <Python.h>
#}header
@@ -32,8 +33,6 @@
void* malloc(size_t size)
void free(void* mem)
-#cimport topology # USES topology.Mesh
-
# ----------------------------------------------------------------------
cdef class MeshIO:
@@ -58,6 +57,8 @@
# create shim for method 'read'
#embed{ void MeshIO_read(void* pObj, void* pMeshObj)
try {
+ assert(0 != pObj);
+ assert(0 != pMeshObj);
ALE::Obj<ALE::Mesh>* pMesh = (ALE::Obj<ALE::Mesh>*) pMeshObj;
((pylith::meshio::MeshIO*) pObj)->read(pMesh);
} catch (const std::exception& err) {
@@ -71,7 +72,7 @@
#cdef topology.Mesh mesh
MeshIO_read(self.thisptr, ptrFromHandle(mesh))
- return mesh
+ return
def write(self, mesh):
Modified: short/3D/PyLith/trunk/pylith/materials/ElasticIsotropic3D.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/ElasticIsotropic3D.py 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/pylith/materials/ElasticIsotropic3D.py 2007-03-21 05:45:30 UTC (rev 6327)
@@ -36,8 +36,8 @@
Constructor.
"""
Material.__init__(self, name)
- # :TODO: Need to create module for materials
- # self.cppHandle = bindings.ElasticIsotropic3D()
+ import pylith.materials.materials as bindings
+ self.cppHandle = bindings.ElasticIsotropic3D()
return
Modified: short/3D/PyLith/trunk/pylith/materials/Material.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/Material.py 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/pylith/materials/Material.py 2007-03-21 05:45:30 UTC (rev 6327)
@@ -61,8 +61,8 @@
id = pyre.inventory.int("id", default=0)
id.meta['tip'] = "Material identifier (from mesh generator)."
- matname = pyre.inventory.str("name", default="")
- matname.meta['tip'] = "Name of material."
+ label = pyre.inventory.str("label", default="")
+ label.meta['tip'] = "Name of material."
from spatialdata.spatialdb.SpatialDB import SpatialDB
db = pyre.inventory.facility("db", factory=SpatialDB,
@@ -85,15 +85,17 @@
return
- def initialize(self):
+ def initialize(self, mesh):
"""
Initialize material property manager.
"""
- self._info.log("Initializing material '%s'." % self.matname)
+ self._info.log("Initializing material '%s'." % self.label)
self.db.initialize()
- #self.cppHandle.id = self.id
- #self.cppHandle.matname = self.matname
- #self.cppHandle.db = self.db
+ self.cppHandle.id = self.id
+ self.cppHandle.label = self.label
+ self.cppHandle.db = self.db
+ self.cppHandle.initialize(mesh.cppHandle. mesh.coordsys.cppHandle,
+ self.quadrature.cppHandle)
return
@@ -105,7 +107,7 @@
"""
Component._configure(self)
self.id = self.inventory.id
- self.matname = self.inventory.matname
+ self.label = self.inventory.label
self.db = self.inventory.db
self.quadrature = self.inventory.quadrature
return
Modified: short/3D/PyLith/trunk/pylith/meshio/MeshIO.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/MeshIO.py 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/pylith/meshio/MeshIO.py 2007-03-21 05:45:30 UTC (rev 6327)
@@ -70,7 +70,7 @@
self._sync()
from pylith.topology.Mesh import Mesh
mesh = Mesh()
- mesh.cppHandle = self.cppHandle.read(mesh.cppHandle)
+ self.cppHandle.read(mesh.cppHandle)
return mesh
Modified: short/3D/PyLith/trunk/pylith/meshio/MeshIOAscii.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/MeshIOAscii.py 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/pylith/meshio/MeshIOAscii.py 2007-03-21 05:45:30 UTC (rev 6327)
@@ -70,7 +70,6 @@
"""
MeshIO._configure(self)
self.filename = self.inventory.filename
- self.cppHandle.filename = self.filename
return
Modified: short/3D/PyLith/trunk/unittests/pytests/materials/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/Makefile.am 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/Makefile.am 2007-03-21 05:45:30 UTC (rev 6327)
@@ -13,43 +13,16 @@
subpackage = materials
include $(top_srcdir)/subpackage.am
-TESTS = testfeassemble.py
+SUBDIRS = data
-check_SCRIPTS = testfeassemble.py
+TESTS = testmaterials.py
+check_SCRIPTS = testmaterials.py
+
noinst_PYTHON = \
- TestFIATSimplex.py \
- TestQuadrature.py \
- TestIntegrator.py
+ TestHomogeneous.py \
+ TestMaterial.py \
+ TestElasticIsotropic3D.py
-# module
-subpkgpyexec_LTLIBRARIES = testfeassemblemodule.la
-
-testfeassemblemodule_la_LDFLAGS = -module
-
-testfeassemblemodule_la_SOURCES = testfeassemble.pyxe
-
-nodist_testfeassemblemodule_la_SOURCES = \
- testfeassemble.c testfeassemble_embed.cpp testfeassemble_embed.h
-
-testfeassemblemodule_la_LIBADD = \
- $(PETSC_LIB)
-
-INCLUDES += -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
-
-testfeassemble.pyx testfeassemble_embed.cpp testfeassemble_embed.h: testfeassemble.pyxe
- pyrexembed testfeassemble.pyxe
-testfeassemble.pyxe: $(srcdir)/testfeassemble.pyxe.src
- cp $(srcdir)/testfeassemble.pyxe.src $@
-testfeassemble_embed.cpp: testfeassemble_embed.h
-testfeassemble_embed.h: testfeassemble.pyx
-
-.pyx.c:
- pyrexc $<
-
-CLEANFILES = \
- testfeassemble.pyxe testfeassemble.pyx testfeassemble.c *_embed.* \
- $(am__installdirs)/testfeassemblemodule.*
-
# End of file
Added: short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticIsotropic3D.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticIsotropic3D.py 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticIsotropic3D.py 2007-03-21 05:45:30 UTC (rev 6327)
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/materials/TestElasticIsotropic3D.py
+
+## @brief Unit testing of ElasticIsotropic3D object.
+
+import unittest
+
+# ----------------------------------------------------------------------
+class TestElasticIsotropic3D(unittest.TestCase):
+ """
+ Unit testing of ElasticIsotropic3D object.
+ """
+
+ def test_constructor(self):
+ """
+ Test constructor.
+ """
+ from pylith.materials.ElasticIsotropic3D import ElasticIsotropic3D
+ material = ElasticIsotropic3D()
+
+ self.assertNotEqual(None, material.cppHandle)
+ return
+
+
+# End of file
Added: short/3D/PyLith/trunk/unittests/pytests/materials/TestMaterial.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/TestMaterial.py 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/TestMaterial.py 2007-03-21 05:45:30 UTC (rev 6327)
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/materials/TestMaterial.py
+
+## @brief Unit testing of Material object.
+
+import unittest
+
+# ----------------------------------------------------------------------
+class TestMaterial(unittest.TestCase):
+ """
+ Unit testing of Material object.
+ """
+
+ def test_initialize(self):
+ """
+ Test initialize().
+
+ WARNING: This is not a rigorous test of initialize() because we
+ don't verify the results.
+ """
+ from pylith.utils.PetscManager import PetscManager
+ petsc = PetscManager()
+ petsc.initialize()
+
+ from pylith.materials.ElasticIsotropic3D import ElasticIsotropic3D
+ material = ElasticIsotropic3D()
+
+ from spatialdata.spatialdb.SimpleDB import SimpleDB
+ from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
+ iohandler = SimpleIOAscii()
+ iohandler.filename = "data/matinitialize.spatialdb"
+ db = SimpleDB()
+ db.iohandler = iohandler
+ material.db = db
+ material.label = "my material"
+ material.id = 54
+
+ from pylith.meshio.MeshIOAscii import MeshIOAscii
+ importer = MeshIOAscii()
+ importer.filename = "data/twoelems.mesh"
+ mesh = importer.read()
+
+ material.initialize(mesh)
+
+ # We should really add something here to check to make sure things
+ # actually initialized correctly
+
+ petsc.finalize()
+ return
+
+
+# End of file
Added: short/3D/PyLith/trunk/unittests/pytests/materials/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/data/Makefile.am 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/data/Makefile.am 2007-03-21 05:45:30 UTC (rev 6327)
@@ -0,0 +1,31 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+noinst_DATA = \
+ matinitialize.spatialdb \
+ twoelems.mesh
+
+noinst_TMP =
+
+# 'export' the input files by performing a mock install
+export_datadir = $(top_builddir)/unittests/pytests/materials/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/materials/data/matinitialize.spatialdb
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/data/matinitialize.spatialdb 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/data/matinitialize.spatialdb 2007-03-21 05:45:30 UTC (rev 6327)
@@ -0,0 +1,15 @@
+#SPATIAL.ascii 1
+SimpleDB {
+ num-values = 3
+ value-names = density vs vp
+ value-units = kg/m^3 m/s m/s
+ num-locs = 2
+ data-dim = 1
+ space-dim = 1
+ cs-data = cartesian {
+ to-meters = 1.0
+ space-dim = 1
+ }
+}
+-0.5 2000.0 100.0 180.0
++0.5 3000.0 200.0 400.0
Added: short/3D/PyLith/trunk/unittests/pytests/materials/data/twoelems.mesh
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/data/twoelems.mesh 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/data/twoelems.mesh 2007-03-21 05:45:30 UTC (rev 6327)
@@ -0,0 +1,23 @@
+mesh = {
+ dimension = 1
+ vertices = {
+ dimension = 1
+ count = 3
+ coordinates = {
+ -1.0
+ 0.0
+ 1.0
+ }
+ }
+ cells = {
+ num-corners = 2
+ count = 2
+ simplices = {
+ 0 1
+ 1 2
+ }
+ material-ids = {
+ 54 54
+ }
+ }
+}
Added: short/3D/PyLith/trunk/unittests/pytests/materials/testmaterials.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/testmaterials.py 2007-03-20 21:33:41 UTC (rev 6326)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/testmaterials.py 2007-03-21 05:45:30 UTC (rev 6327)
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/materials/testmaterials.py
+
+## @brief Python application for testing materials code.
+
+from pyre.applications.Script import Script
+
+import unittest
+
+class TestApp(Script):
+ """
+ Test application.
+ """
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="testapp"):
+ """
+ Constructor.
+ """
+ Script.__init__(self, name)
+ return
+
+
+ def main(self):
+ """
+ Run the application.
+ """
+ unittest.TextTestRunner(verbosity=2).run(self._suite())
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _suite(self):
+ """
+ Setup the test suite.
+ """
+
+ suite = unittest.TestSuite()
+
+ from TestMaterial import TestMaterial
+ suite.addTest(unittest.makeSuite(TestMaterial))
+
+ from TestElasticIsotropic3D import TestElasticIsotropic3D
+ suite.addTest(unittest.makeSuite(TestElasticIsotropic3D))
+
+ return suite
+
+
+# ----------------------------------------------------------------------
+if __name__ == '__main__':
+ app = TestApp()
+ app.run()
+
+
+# End of file
Property changes on: short/3D/PyLith/trunk/unittests/pytests/materials/testmaterials.py
___________________________________________________________________
Name: svn:executable
+ *
More information about the cig-commits
mailing list