[cig-commits] r9155 - in short/3D/PyLith/trunk: libsrc/bc modulesrc/bc pylith pylith/bc unittests/libtests/bc unittests/pytests/bc

brad at geodynamics.org brad at geodynamics.org
Mon Jan 28 17:49:08 PST 2008


Author: brad
Date: 2008-01-28 17:49:08 -0800 (Mon, 28 Jan 2008)
New Revision: 9155

Modified:
   short/3D/PyLith/trunk/libsrc/bc/DirichletPoints.cc
   short/3D/PyLith/trunk/libsrc/bc/DirichletPoints.hh
   short/3D/PyLith/trunk/libsrc/bc/DirichletPoints.icc
   short/3D/PyLith/trunk/modulesrc/bc/bc.pyxe.src
   short/3D/PyLith/trunk/pylith/Makefile.am
   short/3D/PyLith/trunk/pylith/bc/DirichletPoints.py
   short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletPoints.cc
   short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletPointsMulti.cc
   short/3D/PyLith/trunk/unittests/pytests/bc/TestDirichletPoints.py
Log:
Added rate of change to DirichetPoints. Still need to update unit tests to validate rate of change works.

Modified: short/3D/PyLith/trunk/libsrc/bc/DirichletPoints.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/bc/DirichletPoints.cc	2008-01-29 00:38:45 UTC (rev 9154)
+++ short/3D/PyLith/trunk/libsrc/bc/DirichletPoints.cc	2008-01-29 01:49:08 UTC (rev 9155)
@@ -23,7 +23,9 @@
 
 // ----------------------------------------------------------------------
 // Default constructor.
-pylith::bc::DirichletPoints::DirichletPoints(void)
+pylith::bc::DirichletPoints::DirichletPoints(void) :
+  _tRef(0.0),
+  _dbRate(0)
 { // constructor
 } // constructor
 
@@ -31,6 +33,7 @@
 // Destructor.
 pylith::bc::DirichletPoints::~DirichletPoints(void)
 { // destructor
+  _dbRate = 0;
 } // destructor
 
 // ----------------------------------------------------------------------
@@ -42,6 +45,7 @@
 				   const double_array& upDir)
 { // initialize
   assert(0 != _db);
+  assert(0 != _dbRate);
   assert(!mesh.isNull());
   assert(0 != cs);
 
@@ -78,6 +82,8 @@
   } // for
   _db->open();
   _db->queryVals((const char**) valueNames, numFixedDOF);
+  _dbRate->open();
+  _dbRate->queryVals((const char**) valueNames, numFixedDOF);
   for (int i=0; i < numFixedDOF; ++i) {
     delete[] valueNames[i]; valueNames[i] = 0;
   } // for
@@ -88,13 +94,15 @@
   assert(!coordinates.isNull());
   const int spaceDim = cs->spaceDim();
 
-  _values.resize(numPoints*numFixedDOF);
+  _valuesInitial.resize(numPoints*numFixedDOF);
+  _valuesRate.resize(numPoints*numFixedDOF);
   double_array queryValues(numFixedDOF);
-  for (int iPoint=0, i=0; iPoint < numPoints; ++iPoint) {
+  for (int iPoint=0; iPoint < numPoints; ++iPoint) {
     // Get coordinates of vertex
     const real_section_type::value_type* vCoords = 
       coordinates->restrictPoint(_points[iPoint]);
-    int err = _db->query(&queryValues[0], numFixedDOF, vCoords, spaceDim, cs);
+    int err = _db->query(&queryValues[0], numFixedDOF, vCoords, 
+				spaceDim, cs);
     if (err) {
       std::ostringstream msg;
       msg << "Could not find values at (";
@@ -104,9 +112,23 @@
       throw std::runtime_error(msg.str());
     } // if
     for (int iDOF=0; iDOF < numFixedDOF; ++iDOF)
-      _values[i++] = queryValues[iDOF];
+      _valuesInitial[numFixedDOF*iPoint+iDOF] = queryValues[iDOF];
+
+    err = _dbRate->query(&queryValues[0], numFixedDOF, vCoords, 
+			 spaceDim, cs);
+    if (err) {
+      std::ostringstream msg;
+      msg << "Could not find values at (";
+      for (int i=0; i < spaceDim; ++i)
+	msg << "  " << vCoords[i];
+      msg << ") using spatial database " << _dbRate->label() << ".";
+      throw std::runtime_error(msg.str());
+    } // if
+    for (int iDOF=0; iDOF < numFixedDOF; ++iDOF)
+      _valuesRate[numFixedDOF*iPoint+iDOF] = queryValues[iDOF];
   } // for
   _db->close();
+  _dbRate->close();
 } // initialize
 
 // ----------------------------------------------------------------------
@@ -199,17 +221,20 @@
   if (0 == numFixedDOF)
     return;
 
-
   const int numPoints = _points.size();
   const int fiberDimension = 
     (numPoints > 0) ? field->getFiberDimension(_points[0]) : 0;
   double_array allValues(fiberDimension);
-  for (int iPoint=0, i=0; iPoint < numPoints; ++iPoint) {
+  for (int iPoint=0; iPoint < numPoints; ++iPoint) {
     const Mesh::point_type point = _points[iPoint];
     assert(fiberDimension == field->getFiberDimension(point));
     mesh->restrict(field, point, &allValues[0], fiberDimension);
     for (int iDOF=0; iDOF < numFixedDOF; ++iDOF)
-      allValues[_fixedDOF[iDOF]] = _values[i++];
+      allValues[_fixedDOF[iDOF]] = _valuesInitial[iPoint*numFixedDOF+iDOF];
+    if (t > _tRef)
+      for (int iDOF=0; iDOF < numFixedDOF; ++iDOF)
+	allValues[_fixedDOF[iDOF]] += 
+	  (t-_tRef) * _valuesRate[iPoint*numFixedDOF+iDOF];
     field->updatePointAll(_points[iPoint], &allValues[0]);
   } // for
 } // setField

Modified: short/3D/PyLith/trunk/libsrc/bc/DirichletPoints.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/bc/DirichletPoints.hh	2008-01-29 00:38:45 UTC (rev 9154)
+++ short/3D/PyLith/trunk/libsrc/bc/DirichletPoints.hh	2008-01-29 01:49:08 UTC (rev 9155)
@@ -48,6 +48,12 @@
   /// Destructor.
   ~DirichletPoints(void);
 
+  /** Set database for rate of change of values.
+   *
+   * @param db Spatial database
+   */
+  void dbRate(spatialdata::spatialdb::SpatialDB* const db);
+
   /** Set indices of fixed degrees of freedom. 
    *
    * Note: all points associated with boundary condition has same
@@ -59,6 +65,12 @@
    */
   void fixedDOF(const int_array& flags);
 
+  /** Set time at which rate of change begins.
+   *
+   * @param t Reference time.
+   */
+  void referenceTime(const double t);
+
   /** Initialize boundary condition.
    *
    * @param mesh PETSc mesh
@@ -106,14 +118,20 @@
   // PRIVATE MEMBERS ////////////////////////////////////////////////////
 private :
 
+  double _tRef; /// Time when rate of change for values begins
+  double_array _valuesInitial; ///< Initial values at degrees of freedom
+  double_array _valuesRate; ///< Rate of change of Values at degrees of freedom
+
   std::vector<Mesh::point_type> _points; ///< Locations of boundary condition
-  double_array _values; ///< Values at degrees of freedom
   int_array _fixedDOF; ///< Indices of fixed degrees of freedom
 
   /// Offset in list of fixed DOF at point to get to fixed DOF
   /// associated with this DirichletPoints boundary condition.
   int_array _offsetLocal;
 
+  /// Spatial database with parameters for rate of change values.
+  spatialdata::spatialdb::SpatialDB* _dbRate;
+
 }; // class DirichletPoints
 
 #include "DirichletPoints.icc" // inline methods

Modified: short/3D/PyLith/trunk/libsrc/bc/DirichletPoints.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/bc/DirichletPoints.icc	2008-01-29 00:38:45 UTC (rev 9154)
+++ short/3D/PyLith/trunk/libsrc/bc/DirichletPoints.icc	2008-01-29 01:49:08 UTC (rev 9155)
@@ -14,6 +14,14 @@
 #error "DirichletPoints.icc can only be included from DirichletPoints.hh"
 #endif
 
+// Set database for boundary condition parameters.
+inline
+void
+pylith::bc::DirichletPoints::dbRate(
+			      spatialdata::spatialdb::SpatialDB* const db) {
+  _dbRate = db;
+}
+
 // Set indices of fixed degrees of freedom. 
 inline
 void
@@ -23,5 +31,12 @@
   _fixedDOF = flags;
 } // fixedDOF
 
+// Set time at which rate of change begins.
+inline
+void 
+pylith::bc::DirichletPoints::referenceTime(const double t) {
+  _tRef = t;
+} // referenceTime
 
+
 // End of file 

Modified: short/3D/PyLith/trunk/modulesrc/bc/bc.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/bc/bc.pyxe.src	2008-01-29 00:38:45 UTC (rev 9154)
+++ short/3D/PyLith/trunk/modulesrc/bc/bc.pyxe.src	2008-01-29 01:49:08 UTC (rev 9155)
@@ -39,6 +39,7 @@
   void* malloc(size_t size)
   void free(void* mem)
 
+# ----------------------------------------------------------------------
 cdef void BoundaryCondition_destructor(void* obj):
   """
   Destroy BoundaryCondition object.
@@ -52,7 +53,6 @@
   return
 
 
-# ----------------------------------------------------------------------
 cdef class BoundaryCondition:
 
   cdef void* thisptr # Pointer to C++ object
@@ -260,6 +260,37 @@
     return
 
 
+  property dbRate:
+    def __set__(self, value):
+      """
+      Set spatial database for parameters of rate of change of values.
+      """
+      # create shim for method 'dbRate'
+      #embed{ void DirichletPoints_dbRate_set(void* objVptr, void* dbVptr)
+      try {
+        assert(0 != objVptr);
+        assert(0 != dbVptr);
+        spatialdata::spatialdb::SpatialDB* db =
+          (spatialdata::spatialdb::SpatialDB*) dbVptr;
+        ((pylith::bc::DirichletPoints*) objVptr)->dbRate(db);
+      } catch (const std::exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.what()));
+      } catch (const ALE::Exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.msg().c_str()));
+      } catch (...) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "Caught unknown C++ exception.");
+      } // try/catch
+      #}embed
+      if not value.name == "spatialdata_spatialdb_SpatialDB":
+        raise TypeError, \
+              "Argument must be extension module type " \
+              "'spatialdata::spatialdb::SpatialDB'."
+      DirichletPoints_dbRate_set(self.thisptr, ptrFromHandle(value))
+
+
   property fixedDOF:
     def __set__(self, value):
       """

Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am	2008-01-29 00:38:45 UTC (rev 9154)
+++ short/3D/PyLith/trunk/pylith/Makefile.am	2008-01-29 01:49:08 UTC (rev 9155)
@@ -18,6 +18,7 @@
 	bc/BCIntegrator.py \
 	bc/BoundaryCondition.py \
 	bc/DirichletPoints.py \
+	bc/FixedDOFDB.py \
 	bc/BCSingle.py \
 	bc/BCTwoSides.py \
 	bc/BCFourSides.py \

Modified: short/3D/PyLith/trunk/pylith/bc/DirichletPoints.py
===================================================================
--- short/3D/PyLith/trunk/pylith/bc/DirichletPoints.py	2008-01-29 00:38:45 UTC (rev 9154)
+++ short/3D/PyLith/trunk/pylith/bc/DirichletPoints.py	2008-01-29 01:49:08 UTC (rev 9155)
@@ -58,20 +58,35 @@
     ##
     ## \b Properties
     ## @li \b fixed_dof Indices of fixed DOF (0=1st DOF, 1=2nd DOF, etc).
+    ## @li \b reference_t Reference time for rate of change of values.
     ##
     ## \b Facilities
-    ## @li None
+    ## @li \b initial_db Database of parameters for initial values.
+    ## @li \b rate_db Database of parameters for rate of change of values.
 
     import pyre.inventory
 
     fixedDOF = pyre.inventory.list("fixed_dof", default=[],
                                    validator=validateDOF)
     fixedDOF.meta['tip'] = "Indices of fixed DOF (0=1st DOF, 1=2nd DOF, etc)."
+
+    from pyre.units.time import s
+    tRef = pyre.inventory.dimensional("reference_t", default=0.0*s)
+    tRef.meta['tip'] = "Reference time for rate of change of values."
+
+    from FixedDOFDB import FixedDOFDB
+    db = pyre.inventory.facility("db", factory=FixedDOFDB,
+                                 args=["initial value db"])
+    db.meta['tip'] = "Database of parameters for initial values."
+
+    dbRate = pyre.inventory.facility("rate_db", factory=FixedDOFDB,
+                                 args=["rate of change db"])
+    dbRate.meta['tip'] = "Database of parameters for rate of change of values."
     
 
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
-  def __init__(self, name="dirichlet"):
+  def __init__(self, name="dirichletpoints"):
     """
     Constructor.
     """
@@ -99,6 +114,10 @@
     logEvent = "%sinit" % self._loggingPrefix
     self._logger.eventBegin(logEvent)
     
+    assert(None != self.cppHandle)
+    self.dbRate.initialize()
+    self.cppHandle.dbRate = self.dbRate.cppHandle
+
     BoundaryCondition.initialize(self, totalTime, numTimeSteps)
 
     self._logger.eventEnd(logEvent)    
@@ -112,7 +131,9 @@
     Setup members using inventory.
     """
     BoundaryCondition._configure(self)
+    self.tRef = self.inventory.tRef
     self.fixedDOF = self.inventory.fixedDOF
+    self.dbRate = self.inventory.dbRate
     return
 
 

Modified: short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletPoints.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletPoints.cc	2008-01-29 00:38:45 UTC (rev 9154)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletPoints.cc	2008-01-29 01:49:08 UTC (rev 9155)
@@ -23,6 +23,7 @@
 #include "spatialdata/geocoords/CSCart.hh" // USES CSCart
 #include "spatialdata/spatialdb/SimpleDB.hh" // USES SimpleDB
 #include "spatialdata/spatialdb/SimpleIOAscii.hh" // USES SimpleIOAscii
+#include "spatialdata/spatialdb/UniformDB.hh" // USES UniformDB
 
 // ----------------------------------------------------------------------
 CPPUNIT_TEST_SUITE_REGISTRATION( pylith::bc::TestDirichletPoints );
@@ -94,10 +95,11 @@
 
   // Check values
   const size_t size = numPoints * numFixedDOF;
-  CPPUNIT_ASSERT_EQUAL(size, bc._values.size());
+  CPPUNIT_ASSERT_EQUAL(size, bc._valuesInitial.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);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(_data->values[i], bc._valuesInitial[i], 
+				 tolerance);
 } // testInitialize
 
 // ----------------------------------------------------------------------
@@ -273,11 +275,17 @@
   cs.setSpaceDim((*mesh)->getDimension());
   cs.initialize();
 
-  spatialdata::spatialdb::SimpleDB db("TestDirichletPoints");
+  spatialdata::spatialdb::SimpleDB db("TestDirichletPoints initial");
   spatialdata::spatialdb::SimpleIOAscii dbIO;
   dbIO.filename(_data->dbFilename);
   db.ioHandler(&dbIO);
 
+  spatialdata::spatialdb::UniformDB dbRate("TestDirichletPoints rate");
+  const char* names[] = { "dof-0", "dof-1", "dof-2" };
+  const double values[] = { 0.0, 0.0, 0.0 };
+  const int numValues = 3;
+  dbRate.setData(names, values, numValues);
+
   int_array fixedDOF(_data->fixedDOF, _data->numFixedDOF);
   const double upDirVals[] = { 0.0, 0.0, 1.0 };
   double_array upDir(upDirVals, 3);
@@ -285,6 +293,7 @@
   bc->id(_data->id);
   bc->label(_data->label);
   bc->db(&db);
+  bc->dbRate(&dbRate);
   bc->fixedDOF(fixedDOF);
   bc->initialize(*mesh, &cs, upDir);
 } // _initialize

Modified: short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletPointsMulti.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletPointsMulti.cc	2008-01-29 00:38:45 UTC (rev 9154)
+++ short/3D/PyLith/trunk/unittests/libtests/bc/TestDirichletPointsMulti.cc	2008-01-29 01:49:08 UTC (rev 9155)
@@ -23,6 +23,7 @@
 #include "spatialdata/geocoords/CSCart.hh" // USES CSCart
 #include "spatialdata/spatialdb/SimpleDB.hh" // USES SimpleDB
 #include "spatialdata/spatialdb/SimpleIOAscii.hh" // USES SimpleIOAscii
+#include "spatialdata/spatialdb/UniformDB.hh" // USES UniformDB
 
 // ----------------------------------------------------------------------
 // Setup testing data.
@@ -178,11 +179,17 @@
   cs.initialize();
 
   // Setup boundary condition A
-  spatialdata::spatialdb::SimpleDB db("TestDirichletPointsMulti");
+  spatialdata::spatialdb::SimpleDB db("TestDirichletPointsMulti initial");
   spatialdata::spatialdb::SimpleIOAscii dbIO;
   dbIO.filename(_data->dbFilenameA);
   db.ioHandler(&dbIO);
 
+  spatialdata::spatialdb::UniformDB dbRate("TestDirichletPointsMulti rate");
+  const char* names[] = { "dof-0", "dof-1", "dof-2" };
+  const double values[] = { 0.0, 0.0, 0.0 };
+  const int numValues = 3;
+  dbRate.setData(names, values, numValues);
+
   int_array fixedDOFA(_data->fixedDOFA, _data->numFixedDOFA);
   const double upDirVals[] = { 0.0, 0.0, 1.0 };
   double_array upDir(upDirVals, 3);
@@ -190,6 +197,7 @@
   bcA->id(_data->idA);
   bcA->label(_data->labelA);
   bcA->db(&db);
+  bcA->dbRate(&dbRate);
   bcA->fixedDOF(fixedDOFA);
   bcA->initialize(*mesh, &cs, upDir);
 
@@ -202,6 +210,7 @@
   bcB->id(_data->idB);
   bcB->label(_data->labelB);
   bcB->db(&db);
+  bcB->dbRate(&dbRate);
   bcB->fixedDOF(fixedDOFB);
   bcB->initialize(*mesh, &cs, upDir);
 } // _initialize

Modified: short/3D/PyLith/trunk/unittests/pytests/bc/TestDirichletPoints.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/bc/TestDirichletPoints.py	2008-01-29 00:38:45 UTC (rev 9154)
+++ short/3D/PyLith/trunk/unittests/pytests/bc/TestDirichletPoints.py	2008-01-29 01:49:08 UTC (rev 9155)
@@ -163,6 +163,13 @@
     db.initialize()
     bc.db = db
 
+    from pylith.bc.FixedDOFDB import FixedDOFDB
+    dbRate = FixedDOFDB()
+    dbRate._configure()
+    dbRate.label = "TestDirichletPoints rate tri3"
+    dbRate.initialize()
+    bc.dbRate = dbRate
+
     from spatialdata.geocoords.CSCart import CSCart
     cs = CSCart()
     cs.spaceDim = 2



More information about the cig-commits mailing list