[cig-commits] r6930 - in short/3D/PyLith/trunk: libsrc/topology
modulesrc/topology pylith/topology
unittests/libtests/topology unittests/pytests/topology
brad at geodynamics.org
brad at geodynamics.org
Sat May 19 12:39:37 PDT 2007
Author: brad
Date: 2007-05-19 12:39:35 -0700 (Sat, 19 May 2007)
New Revision: 6930
Added:
short/3D/PyLith/trunk/unittests/pytests/topology/TestFieldsManager.py
Modified:
short/3D/PyLith/trunk/libsrc/topology/FieldsManager.cc
short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
short/3D/PyLith/trunk/pylith/topology/FieldsManager.py
short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.cc
short/3D/PyLith/trunk/unittests/pytests/topology/testdriver.py
Log:
Finished C++ unit tests and added Python unit tests for FieldsManager.
Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsManager.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsManager.cc 2007-05-19 03:58:53 UTC (rev 6929)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsManager.cc 2007-05-19 19:39:35 UTC (rev 6930)
@@ -104,7 +104,6 @@
if (iter != src) {
// Make sure fields are same size
assert(!iter->second.isNull());
- assert(src->second->sizeWithBC() == iter->second->sizeWithBC());
for (real_section_type::chart_type::iterator p_iter=srcBegin;
p_iter != srcEnd;
++p_iter) {
@@ -140,7 +139,6 @@
for (map_real_type::iterator iter=begin; iter != end; ++iter) {
// Make sure fields are same size
assert(!iter->second.isNull());
- assert(field->sizeWithBC() == iter->second->sizeWithBC());
for (real_section_type::chart_type::iterator p_iter=srcBegin;
p_iter != srcEnd;
++p_iter) {
Modified: short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src 2007-05-19 03:58:53 UTC (rev 6929)
+++ short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src 2007-05-19 19:39:35 UTC (rev 6930)
@@ -488,7 +488,7 @@
cdef readonly object handle # PyCObject holding pointer to C++ object
cdef readonly object name # Identifier for object base type
- def __init__(self):
+ def __init__(self, mesh):
"""
Constructor.
"""
Modified: short/3D/PyLith/trunk/pylith/topology/FieldsManager.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/FieldsManager.py 2007-05-19 03:58:53 UTC (rev 6929)
+++ short/3D/PyLith/trunk/pylith/topology/FieldsManager.py 2007-05-19 19:39:35 UTC (rev 6930)
@@ -68,7 +68,7 @@
Copy layout of field to all fields in manager..
"""
assert(None != self.cppHandle)
- return self.cppHandle.copyLayoutFromSrc(label)
+ return self.cppHandle.copyLayoutFromSrc(field)
# End of file
Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.cc 2007-05-19 03:58:53 UTC (rev 6929)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.cc 2007-05-19 19:39:35 UTC (rev 6930)
@@ -19,8 +19,6 @@
#include "pylith/meshio/MeshIOAscii.hh" // USES MeshIOAscii
#include "pylith/utils/sievetypes.hh" // USES PETSc Mesh
-#include <stdexcept> // TEMPORARY
-
// ----------------------------------------------------------------------
CPPUNIT_TEST_SUITE_REGISTRATION( pylith::topology::TestFieldsManager );
@@ -93,7 +91,48 @@
void
pylith::topology::TestFieldsManager::testCopyLayout(void)
{ // testCopyLayout
- throw std::logic_error("Unit test not implemented.");
+ ALE::Obj<Mesh> mesh;
+ _initialize(&mesh);
+ FieldsManager manager(mesh);
+ const int numCells = mesh->heightStratum(0)->size();
+ const int offset = numCells;
+
+ const char* labelA = "field A";
+ manager.addReal(labelA);
+ const int fiberDim = 3;
+ const int fixedDim = 1;
+ const Mesh::point_type fixedPt = offset + 2;
+
+ const ALE::Obj<real_section_type>& fieldA = manager.getReal(labelA);
+ const ALE::Obj<Mesh::label_sequence>& vertices = mesh->depthStratum(0);
+ fieldA->setFiberDimension(vertices, fiberDim);
+ fieldA->setConstraintDimension(fixedPt, 1);
+ mesh->allocate(fieldA);
+ fieldA->setConstraintDof(fixedPt, &fixedDim);
+
+ const char* labelB = "field B";
+ manager.addReal(labelB);
+
+ manager.copyLayout(labelA);
+
+ size_t size = 2;
+ CPPUNIT_ASSERT_EQUAL(size, manager._real.size());
+ const ALE::Obj<real_section_type>& fieldB = manager.getReal(labelB);
+
+ CPPUNIT_ASSERT_EQUAL(fieldA->size(), fieldB->size());
+ CPPUNIT_ASSERT_EQUAL(fieldA->sizeWithBC(), fieldB->sizeWithBC());
+ for (Mesh::label_sequence::iterator v_iter = vertices->begin();
+ v_iter != vertices->end();
+ ++v_iter) {
+ if (*v_iter != fixedPt) {
+ CPPUNIT_ASSERT_EQUAL(fiberDim, fieldB->getFiberDimension(*v_iter));
+ CPPUNIT_ASSERT_EQUAL(0, fieldB->getConstraintDimension(*v_iter));
+ } else {
+ CPPUNIT_ASSERT_EQUAL(fiberDim, fieldB->getFiberDimension(*v_iter));
+ CPPUNIT_ASSERT_EQUAL(1, fieldB->getConstraintDimension(*v_iter));
+ CPPUNIT_ASSERT_EQUAL(fixedDim, fieldB->getConstraintDof(*v_iter)[0]);
+ } // if/else
+ } // for
} // testCopyLayout
// ----------------------------------------------------------------------
@@ -101,7 +140,56 @@
void
pylith::topology::TestFieldsManager::testCopyLayoutFromField(void)
{ // testCopyLayoutFromField
- throw std::logic_error("Unit test not implemented.");
+ ALE::Obj<Mesh> mesh;
+ _initialize(&mesh);
+ FieldsManager manager(mesh);
+ const int numCells = mesh->heightStratum(0)->size();
+ const int offset = numCells;
+
+ const char* labelA = "field A";
+ const ALE::Obj<real_section_type>& fieldA =
+ new real_section_type(mesh->comm(), mesh->debug());
+ const int fiberDim = 3;
+ const int fixedDim = 1;
+ const Mesh::point_type fixedPt = offset + 2;
+
+ const ALE::Obj<Mesh::label_sequence>& vertices = mesh->depthStratum(0);
+ fieldA->setFiberDimension(vertices, fiberDim);
+ fieldA->setConstraintDimension(fixedPt, 1);
+ mesh->allocate(fieldA);
+ fieldA->setConstraintDof(fixedPt, &fixedDim);
+
+ const char* labelB = "field B";
+ manager.addReal(labelB);
+ const char* labelC = "field C";
+ manager.addReal(labelC);
+
+ manager.copyLayout(fieldA);
+
+ size_t size = 2;
+ CPPUNIT_ASSERT_EQUAL(size, manager._real.size());
+ const ALE::Obj<real_section_type>& fieldB = manager.getReal(labelB);
+ const ALE::Obj<real_section_type>& fieldC = manager.getReal(labelC);
+
+ CPPUNIT_ASSERT_EQUAL(fieldA->size(), fieldB->size());
+ CPPUNIT_ASSERT_EQUAL(fieldA->sizeWithBC(), fieldB->sizeWithBC());
+ for (Mesh::label_sequence::iterator v_iter = vertices->begin();
+ v_iter != vertices->end();
+ ++v_iter) {
+ if (*v_iter != fixedPt) {
+ CPPUNIT_ASSERT_EQUAL(fiberDim, fieldB->getFiberDimension(*v_iter));
+ CPPUNIT_ASSERT_EQUAL(0, fieldB->getConstraintDimension(*v_iter));
+ CPPUNIT_ASSERT_EQUAL(fiberDim, fieldC->getFiberDimension(*v_iter));
+ CPPUNIT_ASSERT_EQUAL(0, fieldC->getConstraintDimension(*v_iter));
+ } else {
+ CPPUNIT_ASSERT_EQUAL(fiberDim, fieldB->getFiberDimension(*v_iter));
+ CPPUNIT_ASSERT_EQUAL(1, fieldB->getConstraintDimension(*v_iter));
+ CPPUNIT_ASSERT_EQUAL(fixedDim, fieldB->getConstraintDof(*v_iter)[0]);
+ CPPUNIT_ASSERT_EQUAL(fiberDim, fieldC->getFiberDimension(*v_iter));
+ CPPUNIT_ASSERT_EQUAL(1, fieldC->getConstraintDimension(*v_iter));
+ CPPUNIT_ASSERT_EQUAL(fixedDim, fieldC->getConstraintDof(*v_iter)[0]);
+ } // if/else
+ } // for
} // testCopyLayoutFromField
// ----------------------------------------------------------------------
Added: short/3D/PyLith/trunk/unittests/pytests/topology/TestFieldsManager.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/TestFieldsManager.py 2007-05-19 03:58:53 UTC (rev 6929)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/TestFieldsManager.py 2007-05-19 19:39:35 UTC (rev 6930)
@@ -0,0 +1,157 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/topology/TestFieldsManager.py
+
+## @brief Unit testing of FieldsManager object.
+
+import unittest
+
+from pylith.topology.FieldsManager import FieldsManager
+
+# ----------------------------------------------------------------------
+class TestFieldsManager(unittest.TestCase):
+ """
+ Unit testing of FieldsManager object.
+ """
+
+ def test_constructor(self):
+ """
+ Test constructor.
+ """
+ mesh = self._initialize()
+ from pylith.topology.FieldsManager import FieldsManager
+ manager = FieldsManager(mesh)
+
+ self.assertNotEqual(None, manager.cppHandle)
+ return
+
+
+ def test_addReal(self):
+ """
+ Test addReal().
+
+ WARNING: This is not a rigorous test of initialize() because we
+ don't verify the results.
+ """
+
+ mesh = self._initialize()
+ from pylith.topology.FieldsManager import FieldsManager
+ manager = FieldsManager(mesh)
+ manager.addReal("field")
+
+ # We should really add something here to check to make sure things
+ # actually initialized correctly.
+ return
+
+
+ def test_getReal(self):
+ """
+ Test getReal().
+
+ WARNING: This is not a rigorous test of setConstraintSizes() because we
+ don't verify the results.
+ """
+ mesh = self._initialize()
+ from pylith.topology.FieldsManager import FieldsManager
+ manager = FieldsManager(mesh)
+ manager.addReal("field")
+
+ field = manager.getReal("field")
+
+ # We should really add something here to check to make sure things
+ # actually initialized correctly.
+ return
+
+
+ def test_delReal(self):
+ """
+ Test delReal().
+
+ WARNING: This is not a rigorous test of setConstraints() because we
+ don't verify the results.
+ """
+
+ mesh = self._initialize()
+ from pylith.topology.FieldsManager import FieldsManager
+ manager = FieldsManager(mesh)
+ manager.addReal("field")
+
+ manager.delReal("field")
+
+ # We should really add something here to check to make sure things
+ # actually initialized correctly.
+ return
+
+
+ def test_copyLayout(self):
+ """
+ Test copyLayout().
+
+ WARNING: This is not a rigorous test of setField() because we
+ don't verify the results.
+ """
+
+ mesh = self._initialize()
+ from pylith.topology.FieldsManager import FieldsManager
+ manager = FieldsManager(mesh)
+ manager.addReal("field")
+
+ # We should really add something here to check to make sure things
+ # actually initialized correctly.
+ return
+
+
+ def test_copyLayoutFromSrc(self):
+ """
+ Test copyLayoutFromSrc().
+
+ WARNING: This is not a rigorous test of setField() because we
+ don't verify the results.
+ """
+
+ mesh = self._initialize()
+ field = mesh.createRealSection("field", fiberDim=3)
+ mesh.allocateRealSection(field)
+
+ from pylith.topology.FieldsManager import FieldsManager
+ manager = FieldsManager(mesh)
+ manager.addReal("fieldA")
+ manager.addReal("fieldB")
+
+ manager.copyLayoutFromSrc(field)
+
+ # We should really add something here to check to make sure things
+ # actually initialized correctly.
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _initialize(self):
+ """
+ Initialize mesh.
+ """
+ from spatialdata.geocoords.CSCart import CSCart
+ cs = CSCart()
+ cs.spaceDim = 2
+
+ from pylith.meshio.MeshIOAscii import MeshIOAscii
+ importer = MeshIOAscii()
+ importer.filename = "data/tri3.mesh"
+ importer.coordsys = cs
+ mesh = importer.read(debug=False, interpolate=False)
+
+ return mesh
+
+
+# End of file
Modified: short/3D/PyLith/trunk/unittests/pytests/topology/testdriver.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/testdriver.py 2007-05-19 03:58:53 UTC (rev 6929)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/testdriver.py 2007-05-19 19:39:35 UTC (rev 6930)
@@ -63,6 +63,9 @@
from TestMeshImporter import TestMeshImporter
suite.addTest(unittest.makeSuite(TestMeshImporter))
+ from TestFieldsManager import TestFieldsManager
+ suite.addTest(unittest.makeSuite(TestFieldsManager))
+
return suite
More information about the cig-commits
mailing list