[cig-commits] r9006 - in short/3D/PyLith/trunk: . libsrc/meshio libsrc/topology modulesrc/meshio pylith/meshio pylith/problems unittests/pytests/topology

brad at geodynamics.org brad at geodynamics.org
Sun Jan 13 13:10:19 PST 2008


Author: brad
Date: 2008-01-13 13:10:19 -0800 (Sun, 13 Jan 2008)
New Revision: 9006

Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/libsrc/meshio/SolutionIO.hh
   short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.cc
   short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.hh
   short/3D/PyLith/trunk/libsrc/topology/Distributor.cc
   short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src
   short/3D/PyLith/trunk/pylith/meshio/SolutionIO.py
   short/3D/PyLith/trunk/pylith/problems/Formulation.py
   short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenSimple.py
Log:
Prepared for switch from SolutionIO to OutputManager and DataWriter (make interface to SolutionIO compatible with OutputManager).

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2008-01-13 21:08:29 UTC (rev 9005)
+++ short/3D/PyLith/trunk/TODO	2008-01-13 21:10:19 UTC (rev 9006)
@@ -10,23 +10,24 @@
      a. Implement solution output for full mesh
         i. C++ OutputManager
         ii. Bindings for OutputManager, DataWriter, DataWriterVTK
-     b. Implement output of fault data.
+     b. Implement output of partition information.
+     c. Implement output of fault data.
         i. Translation of field names to section labels.
         ii. Compatibility of fault mesh and sections defined over fault.
         iii. FaultCohesiveKin: writeInfo(),writeTimeStep()
-     c. Implement output of material information.
+     d. Implement output of material information.
         i. CellFilterAvg (average data over quadrature points)
-     d. Implement output of Neumann information.
+     e. Implement output of Neumann information.
         i. BoundaryCondition::writeInfo()?
-     e. Implement output of Dirichlet information.
+     f. Implement output of Dirichlet information.
         i. DirichletBoundary versus DirichletPoints
-     f. Implement output of solution subset (ground surface).
+     g. Implement output of solution subset (ground surface).
         i. OutputSubdomain
         ii. OutputPoints
-     g. OutputManager/DataWriter
+     h. OutputManager/DataWriter
         i. Implement support for writing vertex coordinates in another 
            coordinate system.
-     h. DataWriterHDF5
+     i. DataWriterHDF5
 
      Use Cases
 

Modified: short/3D/PyLith/trunk/libsrc/meshio/SolutionIO.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/SolutionIO.hh	2008-01-13 21:08:29 UTC (rev 9005)
+++ short/3D/PyLith/trunk/libsrc/meshio/SolutionIO.hh	2008-01-13 21:10:19 UTC (rev 9006)
@@ -69,39 +69,45 @@
   virtual
   void close(void) = 0;
 
-  /** Write solution topology to file.
+  /** Prepare file for data at a new time step.
    *
-   * @param mesh PETSc mesh object.
-   * @param 
+   * @param t Time stamp for new data
+   * @param mesh PETSc mesh object
+   * @param csMesh Coordinate system of mesh geometry
    */
   virtual
-  void writeTopology(const ALE::Obj<ALE::Mesh>& mesh,
-		     const spatialdata::geocoords::CoordSys* csMesh) = 0;
+  void openTimeStep(const double t,
+		    const ALE::Obj<ALE::Mesh>& mesh,
+		    const spatialdata::geocoords::CoordSys* csMesh) = 0;
 
+  /// Cleanup after writing data for a time step.
+  virtual
+  void closeTimeStep(void) = 0;
+
   /** Write field over vertices to file.
    *
    * @param t Time associated with field.
+   * @param name Name of field.
    * @param field PETSc field over vertices.
-   * @param name Name of field.
    * @param mesh PETSc mesh object.
    */
   virtual
   void writeVertexField(const double t,
+			const char* name,
 			const ALE::Obj<real_section_type>& field,
-			const char* name,
 			const ALE::Obj<ALE::Mesh>& mesh) = 0;
 
   /** Write field over cells to file.
    *
    * @param t Time associated with field.
+   * @param name Name of field.
    * @param field PETSc field over cells.
-   * @param name Name of field.
    * @param mesh PETSc mesh object.
    */
   virtual
   void writeCellField(const double t,
+		      const char* name,
 		      const ALE::Obj<real_section_type>& field,
-		      const char* name,
 		      const ALE::Obj<ALE::Mesh>& mesh) = 0;
 
 // PROTECTED MEMBERS ////////////////////////////////////////////////////

Modified: short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.cc	2008-01-13 21:08:29 UTC (rev 9005)
+++ short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.cc	2008-01-13 21:10:19 UTC (rev 9006)
@@ -74,39 +74,29 @@
 } // close
 
 // ----------------------------------------------------------------------
-// Write solution topology to file.
+// Prepare file for data at a new time step.
 void
-pylith::meshio::SolutionIOVTK::writeTopology(const ALE::Obj<ALE::Mesh>& mesh,
-			        const spatialdata::geocoords::CoordSys* csMesh)
-{ // writeTopology
-  #if 0
-  try {
-    PetscErrorCode err = 0;
+pylith::meshio::SolutionIOVTK::openTimeStep(
+			       const double t,
+			       const ALE::Obj<ALE::Mesh>& mesh,
+			       const spatialdata::geocoords::CoordSys* csMesh)
+{ // openTimeStep
+} // openTimeStep
 
-    err = VTKViewer::writeHeader(_viewer);
-    err = VTKViewer::writeVertices(mesh, _viewer);
-    err = VTKViewer::writeElements(mesh, _viewer);
-  } catch (const std::exception& err) {
-    std::ostringstream msg;
-    msg << "Error while writing topology information to VTK file '"
-	<< _filename << "'.\n" << err.what();
-    throw std::runtime_error(msg.str());
-  } catch (...) { 
-    std::ostringstream msg;
-    msg << "Error while writing topology information to VTK file '"
-	<< _filename << "'.\n";
-    throw std::runtime_error(msg.str());
-  } // try/catch
-#endif
-} // writeTopology
+// ----------------------------------------------------------------------
+// Cleanup after writing data for a time step.
+void
+pylith::meshio::SolutionIOVTK::closeTimeStep(void)
+{ // closeTimeStep
+} // closeTimeStep
 
 // ----------------------------------------------------------------------
 // Write field over vertices to file.
 void
 pylith::meshio::SolutionIOVTK::writeVertexField(
 				     const double t,
-				     const ALE::Obj<real_section_type>& field,
 				     const char* name,
+				     const ALE::Obj<real_section_type>& field,
 				     const ALE::Obj<ALE::Mesh>& mesh)
 { // writeVertexField
 
@@ -172,8 +162,8 @@
 void
 pylith::meshio::SolutionIOVTK::writeCellField(
 				     const double t,
-				     const ALE::Obj<real_section_type>& field,
 				     const char* name,
+				     const ALE::Obj<real_section_type>& field,
 				     const ALE::Obj<ALE::Mesh>& mesh)
 { // writeVertexField
 

Modified: short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.hh	2008-01-13 21:08:29 UTC (rev 9005)
+++ short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.hh	2008-01-13 21:10:19 UTC (rev 9006)
@@ -68,36 +68,41 @@
   /// Close output files.
   void close(void);
 
-  /** Write solution topology to file.
+  /** Prepare file for data at a new time step.
    *
-   * @param mesh PETSc mesh object.
-   * @param 
+   * @param t Time stamp for new data
+   * @param mesh PETSc mesh object
+   * @param csMesh Coordinate system of mesh geometry
    */
-  void writeTopology(const ALE::Obj<ALE::Mesh>& mesh,
-		     const spatialdata::geocoords::CoordSys* csMesh);
+  void openTimeStep(const double t,
+		    const ALE::Obj<ALE::Mesh>& mesh,
+		    const spatialdata::geocoords::CoordSys* csMesh);
 
+  /// Cleanup after writing data for a time step.
+  void closeTimeStep(void);
+
   /** Write field over vertices to file.
    *
    * @param t Time associated with field.
+   * @param name Name of field.
    * @param field PETSc field over vertices.
-   * @param name Name of field.
    * @param mesh PETSc mesh object.
    */
   void writeVertexField(const double t,
+			const char* name,
 			const ALE::Obj<real_section_type>& field,
-			const char* name,
 			const ALE::Obj<ALE::Mesh>& mesh);
 
   /** Write field over cells to file.
    *
    * @param t Time associated with field.
+   * @param name Name of field.
    * @param field PETSc field over cells.
-   * @param name Name of field.
    * @param mesh PETSc mesh object.
    */
   void writeCellField(const double t,
+		      const char* name,
 		      const ALE::Obj<real_section_type>& field,
-		      const char* name,
 		      const ALE::Obj<ALE::Mesh>& mesh);
 
 // PRIVATE MEMBERS //////////////////////////////////////////////////////

Modified: short/3D/PyLith/trunk/libsrc/topology/Distributor.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Distributor.cc	2008-01-13 21:08:29 UTC (rev 9005)
+++ short/3D/PyLith/trunk/libsrc/topology/Distributor.cc	2008-01-13 21:10:19 UTC (rev 9006)
@@ -76,7 +76,7 @@
 
   partition->view("PARTITION");
   const double t = 0.0;
-  writer->writeCellField(t, partition, "partition", mesh);
+  writer->writeCellField(t, "partition", partition, mesh);
 } // write
 
 

Modified: short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src	2008-01-13 21:08:29 UTC (rev 9005)
+++ short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src	2008-01-13 21:10:19 UTC (rev 9006)
@@ -628,12 +628,12 @@
     return
 
 
-  def writeTopology(self, mesh, cs):
+  def openTimeStep(self, t, mesh, cs):
     """
-    Write solution topology to file.
+    Prepare for writing solution to file.
     """
-    # create shim for method 'writeTopology'
-    #embed{ void SolutionIO_writeTopology(void* objVptr, void* meshVptr, void* csVptr)
+    # create shim for method 'openTimeStep'
+    #embed{ void SolutionIO_openTimeStep(void* objVptr, double t, void* meshVptr, void* csVptr)
     try {
       assert(0 != objVptr);
       assert(0 != meshVptr);
@@ -641,7 +641,7 @@
       ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
       spatialdata::geocoords::CoordSys* cs =
         (spatialdata::geocoords::CoordSys*) csVptr;
-      ((pylith::meshio::SolutionIO*) objVptr)->writeTopology(*mesh, cs);
+      ((pylith::meshio::SolutionIO*) objVptr)->openTimeStep(t, *mesh, cs);
     } catch (const std::exception& err) {
       PyErr_SetString(PyExc_RuntimeError,
                       const_cast<char*>(err.what()));
@@ -659,16 +659,41 @@
     if not cs.name == "spatialdata_geocoords_CoordSys":
       raise TypeError, \
             "Argument must be extension module type 'CoordSys'."
-    SolutionIO_writeTopology(self.thisptr, ptrFromHandle(mesh), ptrFromHandle(cs))
+    SolutionIO_openTimeStep(self.thisptr, t, 
+                            ptrFromHandle(mesh), ptrFromHandle(cs))
     return
 
 
-  def writeVertexField(self, t, field, name, mesh):
+  def closeTimeStep(self):
     """
+    Prepare for writing solution to file.
+    """
+    # create shim for method 'closeTimeStep'
+    #embed{ void SolutionIO_closeTimeStep(void* objVptr)
+    try {
+      assert(0 != objVptr);
+      ((pylith::meshio::SolutionIO*) objVptr)->closeTimeStep();
+    } 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
+    SolutionIO_closeTimeStep(self.thisptr)
+    return
+
+
+  def writeVertexField(self, t, name, field, mesh):
+    """
     Write field over vertices to file.
     """
     # create shim for method 'writeVertxField'
-    #embed{ void SolutionIO_writeVertexField(void* objVptr, double t, void* fieldVptr, char* name, void* meshVptr)
+    #embed{ void SolutionIO_writeVertexField(void* objVptr, double t, char* name, void* fieldVptr, void* meshVptr)
     try {
       assert(0 != objVptr);
       assert(0 != fieldVptr);
@@ -677,8 +702,8 @@
       ALE::Obj<pylith::real_section_type>* field =
         (ALE::Obj<pylith::real_section_type>*) fieldVptr;
       ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
-      ((pylith::meshio::SolutionIO*) objVptr)->writeVertexField(t, *field,
-                                                                name, *mesh);
+      ((pylith::meshio::SolutionIO*) objVptr)->writeVertexField(t, name,
+                                                                *field, *mesh);
     } catch (const std::exception& err) {
       PyErr_SetString(PyExc_RuntimeError,
                       const_cast<char*>(err.what()));
@@ -695,17 +720,17 @@
             "Argument must be extension module type 'Mesh'."
     cdef void* fieldVptr
     fieldVptr = PyCObject_AsVoidPtr(field)
-    SolutionIO_writeVertexField(self.thisptr, t, fieldVptr, name,
+    SolutionIO_writeVertexField(self.thisptr, t, name, fieldVptr, 
                                 ptrFromHandle(mesh))
     return
 
 
-  def writeCellField(self, t, field, name, mesh):
+  def writeCellField(self, t, name, field, mesh):
     """
     Write field over cells to file.
     """
     # create shim for method 'writeCellField'
-    #embed{ void SolutionIO_writeCellField(void* objVptr, double t, void* fieldVptr, char* name, void* meshVptr)
+    #embed{ void SolutionIO_writeCellField(void* objVptr, double t, char* name, void* fieldVptr, void* meshVptr)
     try {
       assert(0 != objVptr);
       assert(0 != fieldVptr);
@@ -714,7 +739,7 @@
       ALE::Obj<pylith::real_section_type>* field =
         (ALE::Obj<pylith::real_section_type>*) fieldVptr;
       ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
-      ((pylith::meshio::SolutionIO*) objVptr)->writeCellField(t, *field, name,
+      ((pylith::meshio::SolutionIO*) objVptr)->writeCellField(t, name, *field,
                                                               *mesh);
     } catch (const std::exception& err) {
       PyErr_SetString(PyExc_RuntimeError,
@@ -732,7 +757,7 @@
             "Argument must be extension module type 'Mesh'."
     cdef void* fieldVptr
     fieldVptr = PyCObject_AsVoidPtr(field)
-    SolutionIO_writeCellField(self.thisptr, t, fieldVptr, name,
+    SolutionIO_writeCellField(self.thisptr, t, name, fieldVptr,
                               ptrFromHandle(mesh))
     return
 

Modified: short/3D/PyLith/trunk/pylith/meshio/SolutionIO.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/SolutionIO.py	2008-01-13 21:08:29 UTC (rev 9005)
+++ short/3D/PyLith/trunk/pylith/meshio/SolutionIO.py	2008-01-13 21:10:19 UTC (rev 9006)
@@ -131,44 +131,63 @@
     return
 
 
-  def writeTopology(self):
+  def openTimeStep(self, t, istep):
     """
-    Write solution topology to file.
+    Prepare for writing solution to file.
     """
-    logEvent = "%swriteTopo" % self._loggingPrefix
+    logEvent = "%sopenStep" % self._loggingPrefix
     self._logger.eventBegin(logEvent)    
-    self._info.log("Writing solution topology.")
+    self._info.log("Preparing for writing solution to file.")
 
+    write = False
+    if self.istep == None or not "value" in dir(self.t):
+      write = True
+    elif self.outputFreq == "skip":
+      if istep > self.istep + self.skip:
+        write = True
+    elif t >= self.t + self.dt:
+      write = True
+    self.writeFlag = write
+
     assert(self.cppHandle != None)
     assert(self.mesh.cppHandle != None)
     assert(self.mesh.coordsys.cppHandle != None)
-    self.cppHandle.writeTopology(self.mesh.cppHandle,
-                                 self.mesh.coordsys.cppHandle)
+    self.cppHandle.openTimeStep(t.value,
+                                self.mesh.cppHandle,
+                                self.mesh.coordsys.cppHandle)
 
     self._logger.eventEnd(logEvent)    
     return
 
 
-  def writeVertexField(self, t, istep, field, name):
+  def closeTimeStep(self):
     """
+    Cleanup after writing solution to file.
+    """
+    logEvent = "%scloseStep" % self._loggingPrefix
+    self._logger.eventBegin(logEvent)    
+    self._info.log("Cleaning up afterwriting solution to file.")
+
+    self.writeFlag = False
+    assert(self.cppHandle != None)
+    self.cppHandle.closeTimeStep()
+
+    self._logger.eventEnd(logEvent)    
+    return
+
+
+  def writeVertexField(self, t, istep, name, field):
+    """
     Write field over vertices at time t to file.
     """
     logEvent = "%swriteVertex" % self._loggingPrefix
     self._logger.eventBegin(logEvent)    
 
-    write = False
-    if self.istep == None or not "value" in dir(self.t):
-      write = True
-    elif self.outputFreq == "skip":
-      if istep > self.istep + self.skip:
-        write = True
-    elif t >= self.t + self.dt:
-      write = True
-    if write:
+    if self.writeFlag:
       self._info.log("Writing solution field '%s'." % name)
       assert(self.cppHandle != None)
       assert(self.mesh.cppHandle != None)
-      self.cppHandle.writeVertexField(t.value, field, name,
+      self.cppHandle.writeVertexField(t.value, name, field,
                                       self.mesh.cppHandle)
       self.istep = istep
       self.t = t
@@ -177,26 +196,19 @@
     return
 
 
-  def writeCellField(self, t, istep, field, name):
+  def writeCellField(self, t, istep, name, field):
     """
     Write field over cells at time t to file.
     """
     logEvent = "%swriteCell" % self._loggingPrefix
     self._logger.eventBegin(logEvent)    
 
-    write = False
-    if self.istep == None or not "value" in dir(self.t):
-      write = True
-    elif self.outputFreq == "skip":
-      if istep > self.istep + self.skip:
-        write = True
-    elif t >= self.t + self.dt:
-      write = True
-    if write:
+    if self.writeFlag:
       self._info.log("Writing solution field '%s'." % name)
       assert(self.cppHandle != None)
       assert(self.mesh.cppHandle != None)
-      self.cppHandle.writeCellField(t.value, field, name, self.mesh.cppHandle)
+      self.cppHandle.writeCellField(t.value, name, field, 
+                                    self.mesh.cppHandle)
       self.istep = istep
       self.t = t
 
@@ -244,12 +256,13 @@
 
     from pylith.utils.EventLogger import EventLogger
     logger = EventLogger()
-    logger.setClassName("FE Integrator")
+    logger.setClassName("FE Output")
     logger.initialize()
 
     events = ["open",
               "close",
-              "writeTopo",
+              "openStep",
+              "closeStep",
               "writeVertex",
               "writeCell"]
     for event in events:

Modified: short/3D/PyLith/trunk/pylith/problems/Formulation.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Formulation.py	2008-01-13 21:08:29 UTC (rev 9005)
+++ short/3D/PyLith/trunk/pylith/problems/Formulation.py	2008-01-13 21:10:19 UTC (rev 9006)
@@ -192,7 +192,6 @@
     self._info.log("Setting up solution output.")
     for output in self.output.bin:
       output.open(self.mesh)
-      output.writeTopology()
     self._debug.log(resourceUsageString())
 
     self._info.log("Creating solution field.")
@@ -250,7 +249,9 @@
     self._info.log("Writing solution field.")
     field = self.fields.getSolution()
     for output in self.output.bin:
-      output.writeVertexField(t+dt, self._istep, field, self.solnField['label'])
+      output.openTimeStep(t+dt, self._istep)
+      output.writeVertexField(t+dt, self._istep, self.solnField['label'], field)
+      output.closeTimeStep()
     self._istep += 1
 
     self._logger.eventEnd(logEvent)

Modified: short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenSimple.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenSimple.py	2008-01-13 21:08:29 UTC (rev 9005)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenSimple.py	2008-01-13 21:10:19 UTC (rev 9006)
@@ -49,7 +49,10 @@
     io.coordsys = CSCart()
     mesh.coordsys = CSCart()
     io.open(mesh)
-    io.writeTopology()
+    from pyre.units.time import s
+    t = 0.0*s
+    io.openTimeStep(0.0, 0, mesh)
+    io.closeTimeStep()
     io.close()
 
     from pylith.topology.Distributor import Distributor
@@ -58,7 +61,8 @@
     newMesh = distributor.distribute(mesh)
     io.filename = 'newMesh.vtk'
     io.open(newMesh)
-    io.writeTopology()
+    io.openTimeStep(0.0, 0, mesh)
+    io.closeTimeStep()
     io.close()
     return
 



More information about the cig-commits mailing list