[cig-commits] r6861 - in short/3D/PyLith/trunk: libsrc/meshio unittests/pytests/topology

knepley at geodynamics.org knepley at geodynamics.org
Fri May 11 18:02:25 PDT 2007


Author: knepley
Date: 2007-05-11 18:02:14 -0700 (Fri, 11 May 2007)
New Revision: 6861

Modified:
   short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.cc
   short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.hh
   short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenerator.py
   short/3D/PyLith/trunk/unittests/pytests/topology/testdriver.py
Log:
More progress on VTK output


Modified: short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.cc	2007-05-12 00:37:14 UTC (rev 6860)
+++ short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.cc	2007-05-12 01:02:14 UTC (rev 6861)
@@ -14,15 +14,18 @@
 
 #include "SolutionIOVTK.hh" // implementation of class methods
 
-#include <fstream> // USES std::ofstream
+#include <src/dm/mesh/meshvtk.h> // USES VTKViewer
 #include <assert.h> // USES assert()
 #include <sstream> // USES std::ostringstream
 #include <stdexcept> // USES std::runtime_error
 
+template<typename Bundle, typename Section>
+PetscErrorCode SectionView_Sieve_Ascii(const Obj<Bundle>& bundle, const Obj<Section>& s, const char name[], PetscViewer viewer);
+
 // ----------------------------------------------------------------------
 // Constructor
 pylith::meshio::SolutionIOVTK::SolutionIOVTK(void) :
-  _fout(new std::ofstream)
+  _viewer(NULL)
 { // constructor
 } // constructor
 
@@ -30,7 +33,7 @@
 // Destructor
 pylith::meshio::SolutionIOVTK::~SolutionIOVTK(void)
 { // destructor
-  delete _fout; _fout = 0;
+  if (_viewer) PetscViewerDestroy(_viewer); _viewer = NULL;
 } // destructor  
 
 // ----------------------------------------------------------------------
@@ -38,10 +41,13 @@
 void
 pylith::meshio::SolutionIOVTK::open(const ALE::Obj<ALE::Mesh>& mesh)
 { // open
-  assert(0 != _fout);
+  PetscErrorCode ierr;
 
-  _fout->open(_filename.c_str());
-  if (!_fout->is_open() || !_fout->good()) {
+  ierr = PetscViewerCreate(mesh->comm(), &_viewer);
+  ierr = PetscViewerSetType(_viewer, PETSC_VIEWER_ASCII);
+  ierr = PetscViewerSetFormat(_viewer, PETSC_VIEWER_ASCII_VTK);
+  ierr = PetscViewerFileSetName(_viewer, _filename.c_str());
+  if (ierr) {
     std::ostringstream msg;
     msg << "Could not open VTK file '" << _filename
 	<< "' for solution output.\n";
@@ -57,7 +63,7 @@
 void
 pylith::meshio::SolutionIOVTK::close(void)
 { // close
-  _fout->close();
+  if (_viewer) PetscViewerDestroy(_viewer); _viewer = NULL;
 } // close
 
 // ----------------------------------------------------------------------
@@ -67,12 +73,14 @@
 			        const spatialdata::geocoords::CoordSys* csMesh)
 { // writeTopology
   try {
-    // ADD STUFF HERE
+    PetscErrorCode ierr;
 
+    ierr = VTKViewer::writeHeader(_viewer);
+    ierr = VTKViewer::writeVertices(mesh, _viewer);
+    ierr = VTKViewer::writeElements(mesh, _viewer);
     // Use spatialdata::geocoords::Converter::convert() to convert
     // coordinates of vertices from csMesh to _cs (postpone and wait
     // for more general implementation of SolutionIO?).
-
   } catch (const std::exception& err) {
     std::ostringstream msg;
     msg << "Error while writing topology information to VTK file '"
@@ -96,7 +104,10 @@
 				     const ALE::Obj<ALE::Mesh>& mesh)
 { // writeField
   try {
-    // ADD STUFF HERE
+    PetscErrorCode ierr;
+
+    // Ignore time for now
+    ierr = SectionView_Sieve_Ascii(mesh, field, name, _viewer);
   } catch (const std::exception& err) {
     std::ostringstream msg;
     msg << "Error while writing field '" << name << "' at time " 

Modified: short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.hh	2007-05-12 00:37:14 UTC (rev 6860)
+++ short/3D/PyLith/trunk/libsrc/meshio/SolutionIOVTK.hh	2007-05-12 01:02:14 UTC (rev 6861)
@@ -81,7 +81,7 @@
 
   std::string _filename; ///< Name of VTK file.
 
-  std::ofstream* _fout; ///< Output stream
+  PetscViewer _viewer; ///< Output file
 
 }; // SolutionIOVTK
 

Modified: short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenerator.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenerator.py	2007-05-12 00:37:14 UTC (rev 6860)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenerator.py	2007-05-12 01:02:14 UTC (rev 6861)
@@ -18,6 +18,7 @@
 
 from pylith.topology.MeshGenerator import MeshGenerator
 from pylith.topology.MeshDistributor import MeshDistributor
+from pylith.meshio.SolutionIOVTK import SolutionIOVTK
 
 # ----------------------------------------------------------------------
 class TestMeshGenerator(unittest.TestCase):
@@ -67,11 +68,22 @@
     """
     Test mesh distribution
     """
+    io = SolutionIOVTK()
     generator = MeshGenerator()
     generator.interpolate = True
     mesh = generator.create(generator.createCubeBoundary())
+    io.filename = 'mesh.vtk'
+    #import spatialdata.geocoords.CSCart
+    #io.coordsys = spatialdata.geocoords.CSCart.CSCart()
+    io.open(mesh)
+    io.writeTopology(mesh)
+    io.close()
     distributor = MeshDistributor()
     newMesh = distributor.distributeMesh(mesh)
+    io.filename = 'newMesh.vtk'
+    io.open(newMesh)
+    io.writeTopology(newMesh)
+    io.close()
     self.assertEqual(True, generator.interpolate)
     return
 

Modified: short/3D/PyLith/trunk/unittests/pytests/topology/testdriver.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/testdriver.py	2007-05-12 00:37:14 UTC (rev 6860)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/testdriver.py	2007-05-12 01:02:14 UTC (rev 6861)
@@ -39,6 +39,7 @@
     """
     from pylith.utils.PetscManager import PetscManager
     manager = PetscManager()
+    manager.options.append(('start_in_debugger', '1'))
     manager.initialize()
     unittest.TextTestRunner(verbosity=2).run(self._suite())
     manager.finalize()



More information about the cig-commits mailing list