[cig-commits] r6917 - in short/3D/PyLith/trunk: . libsrc/bc unittests/libtests unittests/libtests/bc unittests/libtests/bc/data

brad at geodynamics.org brad at geodynamics.org
Thu May 17 15:18:02 PDT 2007


Author: brad
Date: 2007-05-17 15:18:01 -0700 (Thu, 17 May 2007)
New Revision: 6917

Added:
   short/3D/PyLith/trunk/unittests/libtests/bc/
   short/3D/PyLith/trunk/unittests/libtests/bc/Makefile.am
   short/3D/PyLith/trunk/unittests/libtests/bc/TestBoundaryCondition.cc
   short/3D/PyLith/trunk/unittests/libtests/bc/TestBoundaryCondition.hh
   short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichlet.cc
   short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichlet.hh
   short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletLine2.cc
   short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletLine2.hh
   short/3D/PyLith/trunk/unittests/libtests/bc/data/
   short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletData.cc
   short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletData.hh
   short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletDataLine2.cc
   short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletDataLine2.hh
   short/3D/PyLith/trunk/unittests/libtests/bc/data/Makefile.am
   short/3D/PyLith/trunk/unittests/libtests/bc/data/line2.spatialdb
   short/3D/PyLith/trunk/unittests/libtests/bc/data/meshLine2.txt
   short/3D/PyLith/trunk/unittests/libtests/bc/test_bc.cc
Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/configure.ac
   short/3D/PyLith/trunk/libsrc/bc/Dirichlet.cc
   short/3D/PyLith/trunk/libsrc/bc/Dirichlet.icc
   short/3D/PyLith/trunk/unittests/libtests/Makefile.am
Log:
Started implementing unit tests for Dirichlet boundary condition. Fixed bugs using 1-D line tests.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/TODO	2007-05-17 22:18:01 UTC (rev 6917)
@@ -14,12 +14,25 @@
   simulation where we don't support it.
 
 1. Implement Dirichlet boundary conditions
-   a. C++
-   b. Python
    c. C++ unit tests
    d. Python unit tests
 
-2. Add dualBasis to Quadrature.
+2. Finish implementing ExplicitElasticity and Explicit
+   a. Replace integrateConstant() with integrateResidual()
+
+     {f}-[A]{u}, {u} is "guess" (zero for explicit)
+
+   a. Double check loops for integrateResidual() and integrateJacobian()
+   b. Create unit test (construction of residual term and Jacobian)
+
+   c. Add unit test for IntegratorElasticity::calcTotalStrain
+
+2a.
+
+  Add feature to materials and integrators wherein they indicate if
+  the Jacobian needs to be reformed at the current time step.
+
+3. Add dualBasis to Quadrature.
    a. Python
      ReferenceCell
      FIATSimplex
@@ -29,7 +42,7 @@
    c. C++ unit tests
    d. Python unit tests
 
-3. Implement faults for kinematic source
+4. Implement faults for kinematic source
    a. Creation of cohesive cells
      i. Add tests for interpolated meshes.
         Double check consistency in ordering of vertices (positive/negative).
@@ -74,16 +87,6 @@
          constructor
          initialize()
 
-4. Finish implementing ExplicitElasticity and Explicit
-   a. Replace integrateConstant() with integrateResidual()
-
-     {f}-[A]{u}, {u} is "guess" (zero for explicit)
-
-   a. Double check loops for integrateResidual() and integrateJacobian()
-   b. Create unit test (construction of residual term and Jacobian)
-
-   c. Add unit test for IntegratorElasticity::calcTotalStrain
-
 5. Implement absorbing boundary conditions
 
 6. Create suite of simple full test cases

Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/configure.ac	2007-05-17 22:18:01 UTC (rev 6917)
@@ -220,6 +220,8 @@
 		applications/Makefile
 		unittests/Makefile
 		unittests/libtests/Makefile
+		unittests/libtests/bc/Makefile
+		unittests/libtests/bc/data/Makefile
 		unittests/libtests/faults/Makefile
 		unittests/libtests/faults/data/Makefile
 		unittests/libtests/feassemble/Makefile

Modified: short/3D/PyLith/trunk/libsrc/bc/Dirichlet.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/bc/Dirichlet.cc	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/libsrc/bc/Dirichlet.cc	2007-05-17 22:18:01 UTC (rev 6917)
@@ -58,7 +58,7 @@
   for(int_section_type::chart_type::iterator c_iter = chart.begin();
       c_iter != chart.end();
       ++c_iter)
-    _points[i] = *c_iter;
+    _points[i++] = *c_iter;
 
   // Get values for degrees of freedom
   const int numFixedDOF = _fixedDOF.size();

Modified: short/3D/PyLith/trunk/libsrc/bc/Dirichlet.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/bc/Dirichlet.icc	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/libsrc/bc/Dirichlet.icc	2007-05-17 22:18:01 UTC (rev 6917)
@@ -18,6 +18,8 @@
 inline
 void
 pylith::bc::Dirichlet::fixedDOF(const int_array& flags) {
+  const size_t size = flags.size();
+  _fixedDOF.resize(size);
   _fixedDOF = flags;
 } // fixedDOF
 

Modified: short/3D/PyLith/trunk/unittests/libtests/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/Makefile.am	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/Makefile.am	2007-05-17 22:18:01 UTC (rev 6917)
@@ -11,6 +11,7 @@
 #
 
 SUBDIRS = \
+	bc \
 	faults \
 	feassemble \
 	materials \

Added: short/3D/PyLith/trunk/unittests/libtests/bc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/Makefile.am	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/Makefile.am	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,57 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+subpackage = bc
+include $(top_srcdir)/subpackage.am
+
+SUBDIRS = data
+
+TESTS = testbc
+
+check_PROGRAMS = testbc
+
+# Primary source files
+testbc_SOURCES = \
+	TestBoundaryCondition.cc \
+	TestDirichlet.cc \
+	TestDirichletLine2.cc \
+	test_bc.cc
+
+noinst_HEADERS = \
+	TestBoundaryCondition.hh \
+	TestDirichletLine2.hh \
+	TestDirichlet.hh
+
+# Source files associated with testing data
+testbc_SOURCES += \
+	data/DirichletData.cc \
+	data/DirichletDataLine2.cc
+
+noinst_HEADERS += \
+	data/DirichletData.hh \
+	data/DirichletDataLine2.hh
+
+testbc_LDFLAGS = $(PETSC_LIB) $(PYTHON_BLDLIBRARY)
+
+AM_CPPFLAGS = $(PETSC_SIEVE_FLAGS) $(PETSC_INCLUDE)
+
+testbc_LDADD = \
+	-lcppunit -ldl \
+	$(top_builddir)/libsrc/libpylith.la \
+	-lspatialdata
+
+if ENABLE_CUBIT
+  testbc_LDADD += -lnetcdf_c++ -lnetcdf
+endif
+
+
+# End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/bc/TestBoundaryCondition.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/TestBoundaryCondition.cc	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/TestBoundaryCondition.cc	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,65 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestBoundaryCondition.hh" // Implementation of class methods
+
+#include "pylith/bc/Dirichlet.hh" // USES Dirichlet
+
+#include "spatialdata/spatialdb/SimpleDB.hh" // USES SimpleDB
+
+#include <string> // USES std::string
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::bc::TestBoundaryCondition );
+
+// ----------------------------------------------------------------------
+// Test id().
+void
+pylith::bc::TestBoundaryCondition::testID(void)
+{ // testID
+  const int id = 346;
+  Dirichlet bc;
+  bc.id(id);
+  
+  CPPUNIT_ASSERT(id == bc.id());
+} // testID
+
+// ----------------------------------------------------------------------
+// Test label().
+void
+pylith::bc::TestBoundaryCondition::testLabel(void)
+{ // testLabel
+  const std::string label = "the_database";
+  Dirichlet bc;
+  bc.label(label.c_str());
+  
+  CPPUNIT_ASSERT_EQUAL(label, bc.label());
+} // testLabel
+    
+// ----------------------------------------------------------------------
+// Test db().
+void
+pylith::bc::TestBoundaryCondition::testDB(void)
+{ // testDB
+  const std::string label = "my db";
+  spatialdata::spatialdb::SimpleDB db(label.c_str());
+  Dirichlet bc;
+  bc.db(&db);
+  
+  CPPUNIT_ASSERT(0 != bc._db);
+  CPPUNIT_ASSERT_EQUAL(label, std::string(bc._db->label()));
+} // testDB
+    
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/bc/TestBoundaryCondition.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/TestBoundaryCondition.hh	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/TestBoundaryCondition.hh	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,60 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/bc/TestBoundaryCondition.hh
+ *
+ * @brief C++ TestBoundaryCondition object
+ *
+ * C++ unit testing for BoundaryCondition.
+ */
+
+#if !defined(pylith_bc_testboundarycondition_hh)
+#define pylith_bc_testboundarycondition_hh
+
+#include <cppunit/extensions/HelperMacros.h>
+
+/// Namespace for pylith package
+namespace pylith {
+  namespace bc {
+    class TestBoundaryCondition;
+  } // bc
+} // pylith
+
+/// C++ unit testing for BoundaryCondition
+class pylith::bc::TestBoundaryCondition : public CppUnit::TestFixture
+{ // class TestBoundaryCondition
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestBoundaryCondition );
+  CPPUNIT_TEST( testID );
+  CPPUNIT_TEST( testLabel );
+  CPPUNIT_TEST( testDB );
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Test id()
+  void testID(void);
+
+  /// Test label()
+  void testLabel(void);
+
+  /// Test db()
+  void testDB(void);
+
+}; // class TestBoundaryCondition
+
+#endif // pylith_bc_testboundarycondition_hh
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichlet.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichlet.cc	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichlet.cc	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,236 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestDirichlet.hh" // Implementation of class methods
+
+#include "pylith/bc/Dirichlet.hh" // USES Dirichlet
+
+#include "data/DirichletData.hh" // USES DirichletData
+#include "pylith/meshio/MeshIOAscii.hh" // USES MeshIOAscii
+#include "pylith/utils/sievetypes.hh" // USES PETSc Mesh
+
+#include "spatialdata/geocoords/CSCart.hh" // USES CSCart
+#include "spatialdata/spatialdb/SimpleDB.hh" // USES SimpleDB
+#include "spatialdata/spatialdb/SimpleIOAscii.hh" // USES SimpleIOAscii
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::bc::TestDirichlet );
+
+// ----------------------------------------------------------------------
+// Test constructor.
+void
+pylith::bc::TestDirichlet::testConstructor(void)
+{ // testConstructor
+  Dirichlet bc;
+} // testConstructor
+
+// ----------------------------------------------------------------------
+// Test fixedDOF()
+void
+pylith::bc::TestDirichlet::testFixedDOF(void)
+{ // testfixedDOF
+  Dirichlet bc;
+  
+  const size_t numDOF = 4;
+  const int dof[] = { 0, 2, 3, 5 };
+  int_array fixedDOF(dof, numDOF);
+  bc.fixedDOF(fixedDOF);
+
+  CPPUNIT_ASSERT_EQUAL(numDOF, bc._fixedDOF.size());
+  for (int i=0; i < numDOF; ++i)
+    CPPUNIT_ASSERT_EQUAL(fixedDOF[i], bc._fixedDOF[i]);
+} // testFixedDOF
+
+// ----------------------------------------------------------------------
+// Test initialize().
+void
+pylith::bc::TestDirichlet::testInitialize(void)
+{ // testInitialize
+  ALE::Obj<Mesh> mesh;
+  Dirichlet bc;
+  _initialize(&mesh, &bc);
+
+  CPPUNIT_ASSERT(0 != _data);
+
+  const int numCells = mesh->heightStratum(0)->size();
+
+  // Check points
+  const int offset = numCells;
+  const size_t numPoints = _data->numConstrainedPts;
+  CPPUNIT_ASSERT_EQUAL(numPoints, bc._points.size());
+  for (int i=0; i < numPoints; ++i)
+    CPPUNIT_ASSERT_EQUAL(_data->constrainedPoints[i]+offset, bc._points[i]);
+
+  // Check values
+  const int numFixedDOF = _data->numFixedDOF;
+  const size_t size = numPoints * numFixedDOF;
+  CPPUNIT_ASSERT_EQUAL(size, bc._values.size());
+  const double tolerance = 1.0e-06;
+  for (int i=0; i < size; ++i)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(_data->values[i], bc._values[i], tolerance);
+} // testInitialize
+
+// ----------------------------------------------------------------------
+// Test setConstraintSizes().
+void
+pylith::bc::TestDirichlet::testSetConstraintSizes(void)
+{ // testSetConstraintSizes
+  ALE::Obj<Mesh> mesh;
+  Dirichlet bc;
+  _initialize(&mesh, &bc);
+
+  const ALE::Obj<real_section_type>& field = mesh->getRealSection("field");
+  const ALE::Obj<Mesh::label_sequence>& vertices = mesh->depthStratum(0);
+  field->setFiberDimension(vertices, _data->numDOF);
+  bc.setConstraintSizes(field, mesh);
+
+  CPPUNIT_ASSERT(0 != _data);
+
+  const int numCells = mesh->heightStratum(0)->size();
+  const int offset = numCells;
+  int iConstraint = 0;
+  for (Mesh::label_sequence::iterator v_iter = vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter) {
+    if (*v_iter != _data->constrainedPoints[iConstraint] + offset) {
+      CPPUNIT_ASSERT_EQUAL(_data->numDOF, field->getFiberDimension(*v_iter));
+      CPPUNIT_ASSERT_EQUAL(0, field->getConstraintDimension(*v_iter));
+    } else {
+      CPPUNIT_ASSERT_EQUAL(_data->numDOF, field->getFiberDimension(*v_iter));
+      CPPUNIT_ASSERT_EQUAL(_data->numFixedDOF, 
+			   field->getConstraintDimension(*v_iter));
+      ++iConstraint;
+    } // if/else
+  } // for
+} // testSetConstraintSizes
+
+// ----------------------------------------------------------------------
+// Test setConstraints().
+void
+pylith::bc::TestDirichlet::testSetConstraints(void)
+{ // testSetConstraints
+  ALE::Obj<Mesh> mesh;
+  Dirichlet bc;
+  _initialize(&mesh, &bc);
+
+  const ALE::Obj<real_section_type>& field = mesh->getRealSection("field");
+  const ALE::Obj<Mesh::label_sequence>& vertices = mesh->depthStratum(0);
+  field->setFiberDimension(vertices, _data->numDOF);
+  bc.setConstraintSizes(field, mesh);
+  mesh->allocate(field);
+  bc.setConstraints(field, mesh);
+
+  // No accessor in real_section_type to verify constraints are set
+  // correctly. For now, rely on testSetField test.
+} // testSetConstraints
+
+// ----------------------------------------------------------------------
+// Test setField().
+void
+pylith::bc::TestDirichlet::testSetField(void)
+{ // testSetField
+  ALE::Obj<Mesh> mesh;
+  Dirichlet bc;
+  _initialize(&mesh, &bc);
+
+  const ALE::Obj<real_section_type>& field = mesh->getRealSection("field");
+  const ALE::Obj<Mesh::label_sequence>& vertices = mesh->depthStratum(0);
+  field->setFiberDimension(vertices, _data->numDOF);
+  bc.setConstraintSizes(field, mesh);
+  mesh->allocate(field);
+  bc.setConstraints(field, mesh);
+
+  CPPUNIT_ASSERT(0 != _data);
+  const double tolerance = 1.0e-06;
+
+  // All values should be zero.
+  field->zero();
+  for (Mesh::label_sequence::iterator v_iter = vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter) {
+    const int fiberDim = field->getFiberDimension(*v_iter);
+    const real_section_type::value_type* values = 
+      mesh->restrict(field, *v_iter);
+    for (int i=0; i < fiberDim; ++i)
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, values[i], tolerance);
+  } // for
+
+  // Only unconstrained values should be zero.
+  const double t = 1.0;
+  bc.setField(t, field, mesh);
+
+  const int numCells = mesh->heightStratum(0)->size();
+  const int offset = numCells;
+  const int numFixedDOF = _data->numFixedDOF;
+  int iConstraint = 0;
+  for (Mesh::label_sequence::iterator v_iter = vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter) {
+    const int fiberDim = field->getFiberDimension(*v_iter);
+    const real_section_type::value_type* values = 
+      mesh->restrict(field, *v_iter);
+    if (*v_iter != _data->constrainedPoints[iConstraint] + offset) {
+      for (int i=0; i < fiberDim; ++i)
+	CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, values[i], tolerance);
+    } else {
+      int iiConstraint = 0;
+      for (int i=0; i < fiberDim; ++i) {
+	if (i == _data->fixedDOF[iiConstraint]) {
+	  const int index = iConstraint * numFixedDOF + iiConstraint;
+	  CPPUNIT_ASSERT_DOUBLES_EQUAL(_data->values[index],
+				       values[i],
+				       tolerance);
+	  ++iiConstraint;
+	} else {
+	CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, values[i], tolerance);
+	} // if/else
+      } // for
+      ++iConstraint;
+    } // if/else
+  } // for
+} // testSetField
+
+// ----------------------------------------------------------------------
+void
+pylith::bc::TestDirichlet::_initialize(ALE::Obj<Mesh>* mesh,
+				       Dirichlet* const bc) const
+{ // _initialize
+  CPPUNIT_ASSERT(0 != _data);
+  CPPUNIT_ASSERT(0 != bc);
+
+  meshio::MeshIOAscii iohandler;
+  iohandler.filename(_data->meshFilename);
+  iohandler.read(mesh);
+  CPPUNIT_ASSERT(!mesh->isNull());
+
+  spatialdata::geocoords::CSCart cs;
+  cs.setSpaceDim((*mesh)->getDimension());
+  cs.initialize();
+
+  spatialdata::spatialdb::SimpleDB db;
+  spatialdata::spatialdb::SimpleIOAscii dbIO;
+  dbIO.filename(_data->dbFilename);
+  db.ioHandler(&dbIO);
+
+  int_array fixedDOF(_data->fixedDOF, _data->numFixedDOF);
+
+  bc->id(_data->id);
+  bc->label(_data->label);
+  bc->db(&db);
+  bc->fixedDOF(fixedDOF);
+  bc->initialize(*mesh, &cs);
+} // _initialize
+
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichlet.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichlet.hh	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichlet.hh	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,90 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/bc/TestDirichlet.hh
+ *
+ * @brief C++ TestDirichlet object.
+ *
+ * C++ unit testing for Dirichlet.
+ */
+
+#if !defined(pylith_bc_testdirichlet_hh)
+#define pylith_bc_testdirichlet_hh
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "pylith/utils/sievefwd.hh" // USES PETSc Mesh
+
+/// Namespace for pylith package
+namespace pylith {
+  namespace bc {
+    class TestDirichlet;
+
+    class Dirichlet;
+    class DirichletData;
+  } // bc
+} // pylith
+
+/// C++ unit testing for Dirichlet.
+class pylith::bc::TestDirichlet : public CppUnit::TestFixture
+{ // class TestDirichlet
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestDirichlet );
+  CPPUNIT_TEST( testConstructor );
+  CPPUNIT_TEST( testFixedDOF );
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Test constructor.
+  void testConstructor(void);
+
+  /// Test fixedDOF().
+  void testFixedDOF(void);
+
+  /// Test initialize().
+  void testInitialize(void);
+
+  /// Test setConstraintSizes().
+  void testSetConstraintSizes(void);
+
+  /// Test setConstraints().
+  void testSetConstraints(void);
+
+  /// Test setField().
+  void testSetField(void);
+
+  // PROTECTED MEMBERS //////////////////////////////////////////////////
+protected :
+
+  DirichletData* _data; ///< Data for testing
+
+  // PRIVATE METHODS ////////////////////////////////////////////////////
+private :
+
+  /** Initialize Dirichlet boundary condition.
+   *
+   * @param mesh PETSc mesh to initialize
+   * @param bc Dirichlet boundary condition to initialize.
+   */
+  void _initialize(ALE::Obj<ALE::Mesh>* mesh,
+		   Dirichlet* const bc) const;
+
+}; // class TestDirichlet
+
+#endif // pylith_bc_dirichlet_hh
+
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletLine2.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletLine2.cc	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletLine2.cc	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,39 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestDirichletLine2.hh" // Implementation of class methods
+
+#include "data/DirichletDataLine2.hh" // USES DirichletDataLine2
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::bc::TestDirichletLine2 );
+
+// ----------------------------------------------------------------------
+// Setup testing data.
+void
+pylith::bc::TestDirichletLine2::setUp(void)
+{ // setUp
+  _data = new DirichletDataLine2();
+} // setUp
+
+// ----------------------------------------------------------------------
+// Tear down testing data.
+void
+pylith::bc::TestDirichletLine2::tearDown(void)
+{ // tearDown
+  delete _data;
+} // tearDown
+
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletLine2.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletLine2.hh	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletLine2.hh	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,59 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/bc/TestDirichlet.hh
+ *
+ * @brief C++ TestDirichlet object.
+ *
+ * C++ unit testing for Dirichlet for mesh with 1-D line cells.
+ */
+
+#if !defined(pylith_bc_testdirichletline2_hh)
+#define pylith_bc_testdirichletlin2_hh
+
+#include "TestDirichlet.hh" // ISA TestDirichlet
+
+/// Namespace for pylith package
+namespace pylith {
+  namespace bc {
+    class TestDirichletLine2;
+  } // bc
+} // pylith
+
+/// C++ unit testing for Dirichlet for mesh with 1-D line cells.
+class pylith::bc::TestDirichletLine2 : public TestDirichlet
+{ // class TestDirichlet
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestDirichletLine2 );
+  CPPUNIT_TEST( testInitialize );
+  CPPUNIT_TEST( testSetConstraintSizes );
+  CPPUNIT_TEST( testSetConstraints );
+  CPPUNIT_TEST( testSetField );
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Setup testing data.
+  void setUp(void);
+
+  /// Tear down testing data.
+  void tearDown(void);
+
+}; // class TestDirichletLine2
+
+#endif // pylith_bc_dirichletline2_hh
+
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletData.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletData.cc	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletData.cc	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,38 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include "DirichletData.hh"
+
+// ----------------------------------------------------------------------
+// Constructor
+pylith::bc::DirichletData::DirichletData(void) :
+  numDOF(0),
+  numFixedDOF(0),
+  numConstrainedPts(0),
+  id(0),
+  label(0),
+  fixedDOF(0),
+  constrainedPoints(0),
+  values(0),
+  meshFilename(0),
+  dbFilename(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+pylith::bc::DirichletData::~DirichletData(void)
+{ // destructor
+} // destructor
+
+
+// End of file

Added: short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletData.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletData.hh	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletData.hh	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,54 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_bc_dirichletdata_hh)
+#define pylith_bc_dirichletdata_hh
+
+namespace pylith {
+  namespace bc {
+     class DirichletData;
+  } // pylith
+} // bc
+
+class pylith::bc::DirichletData
+{
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+  
+  /// Constructor
+  DirichletData(void);
+
+  /// Destructor
+  ~DirichletData(void);
+
+// PUBLIC MEMBERS ///////////////////////////////////////////////////////
+public:
+
+  int numDOF; ///< Number of degrees of freedom at each point.
+  int numFixedDOF; ///< Number of fixedDOF at constrained points.
+  int numConstrainedPts; ///< Number of points constrained.
+
+  int id; ///< Boundary condition identifier
+  char* label; ///< Label for boundary condition group
+
+  int* fixedDOF; ///< Degrees of freedom that are constrained at each point
+  int* constrainedPoints; ///< Array of indices of constrained points.
+  double* values; ///< Values at constrained points.
+
+  char* meshFilename; ///< Filename for input mesh.
+  char* dbFilename; ///< Filename of simple spatial database.
+};
+
+#endif // pylith_bc_cohesivedata_hh
+
+// End of file

Added: short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletDataLine2.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletDataLine2.cc	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletDataLine2.cc	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,65 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/* Mesh: meshLine2.txt
+ *
+ * Dirichlet BC at vertices 0 and 2.
+ *
+ * Fixed DOF: { 0 }
+ *
+ * Values
+ *   0: 1.1 [constrained]
+ *   1: 0.8 [solution]
+ *   2: 2.2 [constrained]
+ */
+
+#include "DirichletDataLine2.hh"
+
+const int pylith::bc::DirichletDataLine2::_id = 0;
+
+const char* pylith::bc::DirichletDataLine2::_label = "bc0";
+
+const int pylith::bc::DirichletDataLine2::_numDOF = 1;
+const int pylith::bc::DirichletDataLine2::_numFixedDOF = 1;
+const int pylith::bc::DirichletDataLine2::_fixedDOF[] = { 0 };
+
+const int pylith::bc::DirichletDataLine2::_numConstrainedPts = 2;
+const int pylith::bc::DirichletDataLine2::_constrainedPoints[] = { 0, 2 };
+const double pylith::bc::DirichletDataLine2::_values[] = { 1.1, 2.2 };
+
+const char* pylith::bc::DirichletDataLine2::_meshFilename = 
+  "data/meshLine2.txt";
+const char* pylith::bc::DirichletDataLine2::_dbFilename =
+  "data/line2.spatialdb";
+
+pylith::bc::DirichletDataLine2::DirichletDataLine2(void)
+{ // constructor
+  id = _id;
+  label = const_cast<char*>(_label);
+
+  numDOF = _numDOF;
+  numFixedDOF = _numFixedDOF;
+  fixedDOF = const_cast<int*>(_fixedDOF);
+
+  numConstrainedPts = _numConstrainedPts;
+  constrainedPoints = const_cast<int*>(_constrainedPoints);
+  values = const_cast<double*>(_values);
+
+  meshFilename = const_cast<char*>(_meshFilename);
+  dbFilename = const_cast<char*>(_dbFilename);
+} // constructor
+
+pylith::bc::DirichletDataLine2::~DirichletDataLine2(void)
+{}
+
+
+// End of file

Added: short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletDataLine2.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletDataLine2.hh	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/data/DirichletDataLine2.hh	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,58 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_bc_dirichletdataline2_hh)
+#define pylith_bc_dirichletdataline2_hh
+
+#include "DirichletData.hh"
+
+namespace pylith {
+  namespace bc {
+     class DirichletDataLine2;
+  } // pylith
+} // bc
+
+class pylith::bc::DirichletDataLine2 : public DirichletData
+{
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public: 
+
+  /// Constructor
+  DirichletDataLine2(void);
+
+  /// Destructor
+  ~DirichletDataLine2(void);
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private:
+
+  static const int _numDOF; ///< Number of degrees of freedom at each point.
+
+  static const int _numFixedDOF; ///< Number of fixedDOF at constrained points.
+  static const int _numConstrainedPts; ///< Number of points constrained.
+
+  static const int _id; ///< Boundary condition identifier
+  static const char* _label; /// Label for boundary condition group
+
+  static const int _fixedDOF[]; ///< Degrees of freedom constrained at points
+
+  static const int _constrainedPoints[]; ///< Array of indices of constrained pts.
+  static const double _values[]; ///< Values at constrained points.
+
+  static const char* _meshFilename; ///< Filename of input mesh.
+  static const char* _dbFilename; ///< Filename of simple spatial database.
+};
+
+#endif // pylith_bc_dirichletdataline2_hh
+
+// End of file

Added: short/3D/PyLith/trunk/unittests/libtests/bc/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/data/Makefile.am	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/data/Makefile.am	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,31 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+noinst_DATA = \
+	meshLine2.txt \
+	line2.spatialdb
+
+noinst_TMP =
+
+# 'export' the input files by performing a mock install
+export_datadir = $(top_builddir)/unittests/libtests/bc/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/libtests/bc/data/line2.spatialdb
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/data/line2.spatialdb	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/data/line2.spatialdb	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,15 @@
+#SPATIAL.ascii 1
+SimpleDB {
+  num-values = 1
+  value-names =  dof-0
+  value-units =  m
+  num-locs = 2
+  data-dim = 1
+  space-dim = 1
+  cs-data = cartesian {
+    to-meters = 1.0
+    space-dim = 1
+  }
+}
+-1.0  1.1
++1.0  2.2

Added: short/3D/PyLith/trunk/unittests/libtests/bc/data/meshLine2.txt
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/data/meshLine2.txt	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/data/meshLine2.txt	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,33 @@
+mesh = {
+  dimension = 1
+  use-index-zero = true
+  vertices = {
+    dimension = 1
+    count = 3
+    coordinates = {
+             0     -1.0
+             1      0.0
+             2      1.0
+    }
+  }
+  cells = {
+    count = 2
+    num-corners = 2
+    simplices = {
+             0       0       1
+             1       1       2
+    }
+    material-ids = {
+             0   0
+             1   0
+    }
+  }
+  group = {
+    name = bc0
+    type = vertices
+    count = 2
+    indices = {
+      0  2
+    }
+  }
+}

Added: short/3D/PyLith/trunk/unittests/libtests/bc/test_bc.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/test_bc.cc	2007-05-17 19:45:17 UTC (rev 6916)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/test_bc.cc	2007-05-17 22:18:01 UTC (rev 6917)
@@ -0,0 +1,67 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include "petsc.h"
+
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <cppunit/BriefTestProgressListener.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/TestRunner.h>
+#include <cppunit/TextOutputter.h>
+
+#include <stdlib.h> // USES abort()
+
+int
+main(int argc,
+     char* argv[])
+{ // main
+  CppUnit::TestResultCollector result;
+
+  try {
+    // Initialize PETSc
+    PetscErrorCode err = PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL);
+    CHKERRQ(err);
+
+    // Create event manager and test controller
+    CppUnit::TestResult controller;
+
+    // Add listener to collect test results
+    controller.addListener(&result);
+
+    // Add listener to show progress as tests run
+    CppUnit::BriefTestProgressListener progress;
+    controller.addListener(&progress);
+
+    // Add top suite to test runner
+    CppUnit::TestRunner runner;
+    runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
+    runner.run(controller);
+
+    // Print tests
+    CppUnit::TextOutputter outputter(&result, std::cerr);
+    outputter.write();
+
+    // Finalize PETSc
+    err = PetscFinalize();
+    CHKERRQ(err);
+  } catch (...) {
+    abort();
+  } // catch
+
+  return (result.wasSuccessful() ? 0 : 1);
+} // main
+
+
+// End of file



More information about the cig-commits mailing list