[cig-commits] r4526 - short/3D/PyLith/trunk/playpen/meshio/src

baagaard at geodynamics.org baagaard at geodynamics.org
Thu Sep 14 09:24:19 PDT 2006


Author: baagaard
Date: 2006-09-14 09:24:17 -0700 (Thu, 14 Sep 2006)
New Revision: 4526

Added:
   short/3D/PyLith/trunk/playpen/meshio/src/meshio.txt
Modified:
   short/3D/PyLith/trunk/playpen/meshio/src/Makefile.am
   short/3D/PyLith/trunk/playpen/meshio/src/MeshIOAscii.cc
   short/3D/PyLith/trunk/playpen/meshio/src/MeshIOAscii.hh
   short/3D/PyLith/trunk/playpen/meshio/src/MeshIOAscii.icc
   short/3D/PyLith/trunk/playpen/meshio/src/testascii.cc
Log:
Added meshio.txt for notes.

Modified: short/3D/PyLith/trunk/playpen/meshio/src/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/playpen/meshio/src/Makefile.am	2006-09-14 04:47:43 UTC (rev 4525)
+++ short/3D/PyLith/trunk/playpen/meshio/src/Makefile.am	2006-09-14 16:24:17 UTC (rev 4526)
@@ -13,15 +13,23 @@
 bin_PROGRAMS = testascii
 
 testascii_SOURCES = \
-	MeshIOAscii.cc \
-	PetscMesh.cc \
-	testascii.cc
+	HDF5.cc
 
+#	MeshIO.cc \
+#	MeshIOAscii.cc \
+#	MeshIOHDF5.cc \
+#	PetscMesh.cc \
+#	testascii.cc
+
 noinst_HEADERS = \
+	HDF5.hh \
+	MeshIO.hh \
 	MeshIOAscii.hh \
+	MeshIOHDF5.hh \
 	PetscMesh.hh
 
-testascii_LDADD = $(PETSC_LIB)
+HDF5_LIBS = -lhdf5
+testascii_LDADD = $(PETSC_LIB) $(HDF5_LIBS)
 
 INCLUDES = $(PETSC_INCLUDE)
 

Modified: short/3D/PyLith/trunk/playpen/meshio/src/MeshIOAscii.cc
===================================================================
--- short/3D/PyLith/trunk/playpen/meshio/src/MeshIOAscii.cc	2006-09-14 04:47:43 UTC (rev 4525)
+++ short/3D/PyLith/trunk/playpen/meshio/src/MeshIOAscii.cc	2006-09-14 16:24:17 UTC (rev 4526)
@@ -10,6 +10,7 @@
 // ======================================================================
 //
 
+#include "MeshIO.hh" // MeshIOAscii ISA MeshIO
 #include "MeshIOAscii.hh" // implementation of class methods
 
 #include "PetscMesh.hh"
@@ -22,21 +23,21 @@
 
 // ----------------------------------------------------------------------
 // Constructor
-MeshIOAscii::MeshIOAscii(void) :
+pylith::meshio::MeshIOAscii::MeshIOAscii(void) :
   _filename("")
 { // constructor
 } // constructor
 
 // ----------------------------------------------------------------------
 // Destructor
-MeshIOAscii::~MeshIOAscii(void)
+pylith::meshio::MeshIOAscii::~MeshIOAscii(void)
 { // destructor
 } // destructor
 
 // ----------------------------------------------------------------------
 // Unpickle mesh
 void
-MeshIOAscii::read(ALE::Obj<ALE::PetscMesh>* pMesh) const
+pylith::meshio::MeshIOAscii::read(ALE::Obj<ALE::PetscMesh>* pMesh)
 { // read
   assert(0 != pMesh);
 
@@ -77,6 +78,14 @@
       filein.ignore(maxIgnore, '=');
       filein >> meshDim;
       readDim = true;
+    } else if (0 == strcasecmp(token.c_str(), "use-index-zero")) {
+      filein.ignore(maxIgnore, '=');
+      std::string flag = "";
+      filein >> flag;
+      if (0 == strcasecmp(flag.c_str(), "true"))
+	useIndexZero(true);
+      else
+	useIndexZero(false);
     } else if (0 == strcasecmp(token.c_str(), "vertices")) {
       filein.ignore(maxIgnore, '{');
       _readVertices(filein, &coordinates, &numVertices, &numDims);
@@ -131,7 +140,7 @@
 // ----------------------------------------------------------------------
 // Write mesh to file.
 void
-MeshIOAscii::write(const ALE::Obj<ALE::PetscMesh>& mesh) const
+pylith::meshio::MeshIOAscii::write(const ALE::Obj<ALE::PetscMesh>& mesh) const
 { // write
   std::ofstream fileout(_filename.c_str());
   if (!fileout.is_open() || !fileout.good()) {
@@ -145,13 +154,14 @@
 
   fileout
     << "mesh = {\n"
-    << "  dimension = " << dimension << "\n";
+    << "  dimension = " << dimension << "\n"
+    << "  use-index-zero = " << (useIndexZero() ? "true" : "false") << "\n";
 
   _writeVertices(fileout, mesh);
   _writeElements(fileout, mesh);
 
-  // Loop over charts
-  //_writeChart(fileout, mesh);
+  // LOOP OVER CHARTS
+  // _writeChart(fileout, mesh, nameIter->c_str());
 
   fileout << "}\n";
   fileout.close();
@@ -160,10 +170,10 @@
 // ----------------------------------------------------------------------
 // Read mesh vertices.
 void
-MeshIOAscii::_readVertices(std::istream& filein,
-			   double** pCoordinates,
-			   int* pNumVertices, 
-			   int* pNumDims) const
+pylith::meshio::MeshIOAscii::_readVertices(std::istream& filein,
+					   double** pCoordinates,
+					   int* pNumVertices, 
+					   int* pNumDims) const
 { // _readVertices
   double* coordinates = 0;
   int numDims = 0;
@@ -214,8 +224,8 @@
 // ----------------------------------------------------------------------
 // Write mesh vertices.
 void
-MeshIOAscii::_writeVertices(std::ostream& fileout,
-			    const ALE::Obj<ALE::PetscMesh>& mesh) const
+pylith::meshio::MeshIOAscii::_writeVertices(std::ostream& fileout,
+			       const ALE::Obj<ALE::PetscMesh>& mesh) const
 { // _writeVertices
   ALE::Obj<ALE::PetscMesh::field_type> coords_field = mesh->getCoordinates();
   ALE::Obj<ALE::PetscMesh::bundle_type> vertexBundle = mesh->getBundle(0);
@@ -251,10 +261,10 @@
 // ----------------------------------------------------------------------
 // Read mesh elements.
 void
-MeshIOAscii::_readElements(std::istream& filein,
-			   int** pElements,
-			   int* pNumElements, 
-			   int* pNumCorners) const
+pylith::meshio::MeshIOAscii::_readElements(std::istream& filein,
+					   int** pElements,
+					   int* pNumElements, 
+					   int* pNumCorners) const
 { // _readElements
   int* elements = 0;
   int numElements = 0;
@@ -284,6 +294,13 @@
       assert(0 != elements);
       for (int i=0; i < size; ++i)
 	filein >> elements[i];
+      if (!useIndexZero()) {
+	// if files begins with index 1, then decrement to index 0
+	// for compatibility with Sieve
+	for (int i=0; i < size; ++i)
+	  --elements[i];
+      } // if
+      
       filein.ignore(maxIgnore, '}');
     } else {
       std::ostringstream msg;
@@ -306,8 +323,8 @@
 // ----------------------------------------------------------------------
 // Write mesh elements.
 void
-MeshIOAscii::_writeElements(std::ostream& fileout,
-			    const ALE::Obj<ALE::PetscMesh>& mesh) const
+pylith::meshio::MeshIOAscii::_writeElements(std::ostream& fileout,
+				  const ALE::Obj<ALE::PetscMesh>& mesh) const
 { // _writeElements
   ALE::Obj<ALE::PetscMesh::sieve_type> topology = mesh->getTopology();
   ALE::Obj<ALE::PetscMesh::sieve_type::traits::heightSequence> elements = 
@@ -330,6 +347,7 @@
     << "    num-corners = " << numCorners << "\n"
     << "    simplices = {\n";
 
+  const int offset = (useIndexZero()) ? 0 : 1;
   for(ALE::PetscMesh::sieve_type::traits::heightSequence::iterator e_itor = 
 	elements->begin(); 
       e_itor != elements->end();
@@ -342,7 +360,9 @@
 	  cone->begin(); 
 	c_itor != cone->end(); 
 	++c_itor)
-      fileout << std::setw(8) << vertexBundle->getIndex(patch, *c_itor).prefix;
+      fileout
+	<< std::setw(8)
+	<< offset + vertexBundle->getIndex(patch, *c_itor).prefix;
     fileout << "\n";
   } // for
   fileout
@@ -353,8 +373,8 @@
 // ----------------------------------------------------------------------
 // Read mesh charts.
 void
-MeshIOAscii::_readChart(std::istream& filein,
-			 ALE::Obj<ALE::PetscMesh>* pMesh) const
+pylith::meshio::MeshIOAscii::_readChart(std::istream& filein,
+					ALE::Obj<ALE::PetscMesh>* pMesh) const
 { // _readChart
   std::string name = ""; // Name of chart
   int dimension = 0; // Topology dimension associated with chart
@@ -397,16 +417,37 @@
   if (!filein.good())
     throw std::runtime_error("I/O error while parsing chart settings.");
 
-  // ADD STUFF HERE
+#if 0
+  assert(0 != pMesh);
+  ALE::Obj<ALE::PetscMesh::field_type> chartField = (*pMesh)->getField(name);
+  const int meshDim = (*pMesh)->getDimension();
+  ALE::Obj<std::list<ALE::PetscMesh::point_type> > patchPoints = 
+    std::list<ALE::PetscMesh::point_type>();
+  ALE::PetscMesh::field_type::patch_type patch;
+
+  patchPoints->clear();
+  if (meshDim == dimension) {
+    for (int i=0; i < count; ++i)
+      patchPoints->push_back(ALE::PetscMesh::point_type(0, indices[i]));
+    chartField->setPatch(patchPoints, patch);
+  } else if (0 == dimension) {
+  } // if
+  chartField->setFiberDimensionByHeight(patch, 0, 1);
+  chartField->orderPatches();
+  const double zero = 0;
+  for (int i=0; i < count; ++i)
+    chartField->update(patch, ALE::PetscMesh::point_type(0, i), &zero);
+#endif
 } // _readChart
 
 // ----------------------------------------------------------------------
 // Write mesh chart.
 void
-MeshIOAscii::_writeChart(std::ostream& fileout,
-			 const ALE::Obj<ALE::PetscMesh>& mesh,
-			 const char* name) const
+pylith::meshio::MeshIOAscii::_writeChart(std::ostream& fileout,
+					 const ALE::Obj<ALE::PetscMesh>& mesh,
+					 const char* name) const
 { // _writeChart
+  //_writeChart(fileout, mesh);
   // ADD STUFF HERE
   int count = 0; // TEMPORARY
   int dimension = 0; // TEMPORARY

Modified: short/3D/PyLith/trunk/playpen/meshio/src/MeshIOAscii.hh
===================================================================
--- short/3D/PyLith/trunk/playpen/meshio/src/MeshIOAscii.hh	2006-09-14 04:47:43 UTC (rev 4525)
+++ short/3D/PyLith/trunk/playpen/meshio/src/MeshIOAscii.hh	2006-09-14 16:24:17 UTC (rev 4526)
@@ -10,8 +10,8 @@
 // ======================================================================
 //
 
-#if !defined(meshioascii_hh)
-#define meshioascii_hh
+#if !defined(pylith_meshio_meshioascii_hh)
+#define pylith_meshio_meshioascii_hh
 
 #include <iosfwd> // USES std::istream, std::ostream
 #include <string> // HASA std::string
@@ -19,9 +19,16 @@
 namespace ALE {
   template<typename T> class Obj;
   class PetscMesh;
-}
+} // ALE
 
-class MeshIOAscii
+namespace pylith {
+  namespace meshio {
+    class MeshIO;
+    class MeshIOAscii;
+  } // meshio
+} // pylith
+
+class pylith::meshIO::MeshIOAscii : public pylith::meshIO::MeshIO
 { // MeshIOAscii
   
 // PUBLIC METHODS -------------------------------------------------------
@@ -49,7 +56,7 @@
    *
    * @param pMesh Pointer to PETSc mesh object
    */
-  void read(ALE::Obj<ALE::PetscMesh>* pMesh) const;
+  void read(ALE::Obj<ALE::PetscMesh>* pMesh);
 
   /** Write mesh to file.
    *
@@ -127,7 +134,7 @@
 
 #include "MeshIOAscii.icc" // inline methods
 
-#endif // meshioascii_hh
+#endif // pylith_meshio_meshioascii_hh
 
 // version
 // $Id$

Modified: short/3D/PyLith/trunk/playpen/meshio/src/MeshIOAscii.icc
===================================================================
--- short/3D/PyLith/trunk/playpen/meshio/src/MeshIOAscii.icc	2006-09-14 04:47:43 UTC (rev 4525)
+++ short/3D/PyLith/trunk/playpen/meshio/src/MeshIOAscii.icc	2006-09-14 16:24:17 UTC (rev 4526)
@@ -10,21 +10,21 @@
 // ======================================================================
 //
 
-#if !defined(meshioascii_hh)
+#if !defined(pylith_meshio_meshioascii_hh)
 #error "MeshIOAscii.icc must be included only from MeshIOAscii.icc"
 #else
 
 // Set filename for ASCII file.
 inline
 void
-MeshIOAscii::filename(const char* name) {
+pylith::meshio::MeshIOAscii::filename(const char* name) {
   _filename = name;
 }
 
 // Get filename of ASCII file.
 inline
 const char* 
-MeshIOAscii::filename(void) const {
+pylith::meshio::MeshIOAscii::filename(void) const {
   return _filename.c_str();
 }
 

Added: short/3D/PyLith/trunk/playpen/meshio/src/meshio.txt
===================================================================
--- short/3D/PyLith/trunk/playpen/meshio/src/meshio.txt	2006-09-14 04:47:43 UTC (rev 4525)
+++ short/3D/PyLith/trunk/playpen/meshio/src/meshio.txt	2006-09-14 16:24:17 UTC (rev 4526)
@@ -0,0 +1,24 @@
+Abstract
+
+  public
+
+    read(ALE::PetscMesh*)
+    write(const ALE::PetscMesh&)
+
+  protected, pure virtual
+
+    _open(filename)
+    _readMeshInfo(dimension)
+    _writeMeshInfo(dimension)
+    _readVertices(coordinates, numVertices, numDims)
+    _writeVertices(coordinates, numVertices, numDims)
+    _readElements(elements, numElements, numCorners)
+    _writeElements(elements, numElements, numCorners)
+    _readGroup()
+    _writeGroup()
+    _close()
+
+  protected
+
+    _addGroup(name, dimension, entries, numEntries)
+    _getGroup(name, dimension, entries, numEntries)

Modified: short/3D/PyLith/trunk/playpen/meshio/src/testascii.cc
===================================================================
--- short/3D/PyLith/trunk/playpen/meshio/src/testascii.cc	2006-09-14 04:47:43 UTC (rev 4525)
+++ short/3D/PyLith/trunk/playpen/meshio/src/testascii.cc	2006-09-14 16:24:17 UTC (rev 4526)
@@ -10,6 +10,7 @@
 // ======================================================================
 //
 
+#include "MeshIO.hh"
 #include "MeshIOAscii.hh"
 
 #include "petsc.h" // USES PetscInitialize(), PetscFinalize()



More information about the cig-commits mailing list