[cig-commits] r6761 - in short/3D/PyLith/trunk: . libsrc libsrc/meshio libsrc/utils modulesrc/meshio pylith pylith/meshio

brad at geodynamics.org brad at geodynamics.org
Wed May 2 19:57:04 PDT 2007


Author: brad
Date: 2007-05-02 19:56:55 -0700 (Wed, 02 May 2007)
New Revision: 6761

Added:
   short/3D/PyLith/trunk/libsrc/meshio/GMVFile.cc
   short/3D/PyLith/trunk/libsrc/meshio/GMVFile.hh
   short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.cc
   short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.hh
   short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.icc
   short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.cc
   short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.hh
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.hh
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.icc
   short/3D/PyLith/trunk/pylith/meshio/MeshIOLagrit.py
Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/libsrc/Makefile.am
   short/3D/PyLith/trunk/libsrc/meshio/Makefile.am
   short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
   short/3D/PyLith/trunk/libsrc/utils/Makefile.am
   short/3D/PyLith/trunk/libsrc/utils/arrayfwd.hh
   short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src
   short/3D/PyLith/trunk/pylith/Makefile.am
   short/3D/PyLith/trunk/pylith/meshio/MeshIOAscii.py
   short/3D/PyLith/trunk/pylith/meshio/__init__.py
Log:
Started work on implementing importing a mesh from LaGriT using GMV and Pset files.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/TODO	2007-05-03 02:56:55 UTC (rev 6761)
@@ -37,14 +37,13 @@
        (1) Unit tests
 
      iv. FaultCohesiveKin
-       (1) initialize(), integrateResidual(), integrateJacobian()
        (2) Add Python unit tests
        (3) Add C++ unit tests
 
 1. Finish implementing ExplicitElasticity and Explicit
    a. Replace integrateConstant() with integrateResidual()
 
-     {f}-[A]{u} {u} is "guess" (zero for explicit)
+     {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)

Modified: short/3D/PyLith/trunk/libsrc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/Makefile.am	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/Makefile.am	2007-05-03 02:56:55 UTC (rev 6761)
@@ -47,13 +47,18 @@
 	materials/ElasticMaterial.cc \
 	materials/ElasticPlaneStrain.cc \
 	materials/ElasticPlaneStress.cc \
+	meshio/GMVFile.cc \
+	meshio/GMVFileAscii.cc \
+	meshio/GMVFileBinary.cc \
 	meshio/MeshIO.cc \
-	meshio/MeshIOAscii.cc
+	meshio/MeshIOAscii.cc \
+	meshio/MeshIOLagrit.cc \
+	utils/Endian.cc
 
 
 INCLUDES = -I$(top_builddir)/include
 INCLUDES += $(PETSC_INCLUDE)
 
-AM_CPPFLAGS = $(PETSC_SIEVE_FLAGS)
+AM_CPPFLAGS = $(PYTHON_EGG_CPPFLAGS) -I$(PYTHON_INCDIR) $(PETSC_SIEVE_FLAGS)
 
 # End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/GMVFile.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/GMVFile.cc	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/meshio/GMVFile.cc	2007-05-03 02:56:55 UTC (rev 6761)
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "GMVFile.hh" // implementation of class methods
+
+#include "GMVFileAscii.hh"
+
+#include <fstream> // uses std::fstream
+#include <sstream> // uses std::ostringstream
+#include <stdexcept> // USES std::runtime_error
+
+// ----------------------------------------------------------------
+pylith::meshio::GMVFile::GMVFile(const char* filename) :
+  _filename(filename)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------
+pylith::meshio::GMVFile::~GMVFile(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------
+bool
+pylith::meshio::GMVFile::isAscii(const char* filename)
+{ // isAscii
+  std::ifstream fin(filename);
+  if (!(fin.is_open() && fin.good())) {
+    std::ostringstream msg;
+    msg << "Could not open GMV file '" << filename << "' for reading.";
+    throw std::runtime_error(msg.str());
+  } // if
+  const int headerLen = strlen(GMVFileAscii::header())+1;
+  char buffer[headerLen];
+  fin.get(buffer, headerLen, '\n');
+  fin.close();
+  return (0 == strcmp(GMVFileAscii::header(), buffer)) ? true : false;
+} // isAscii
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/GMVFile.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/GMVFile.hh	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/meshio/GMVFile.hh	2007-05-03 02:56:55 UTC (rev 6761)
@@ -0,0 +1,58 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_gmvfile_hh)
+#define pylith_meshio_gmvfile_hh
+
+#include <string> // HASA std::string
+
+namespace pylith {
+  namespace meshio {
+  class GMVFile;
+  } // meshio
+} // pylith
+
+class pylith::meshio::GMVFile
+{ // GMVFile
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /** Constructor with name of GMV file.
+   *
+   * @param filename Name of GMV file
+   */
+  GMVFile(const char* name);
+
+  /// Default destructor.
+  ~GMVFile(void);
+
+  /** Is GMV file ascii?
+   *
+   * @param filename Name of GMV file.
+   *
+   * @returns True if GMV file is ascii, false otherwise
+   */
+  static
+  bool isAscii(const char* filename);
+
+// PROTECTED MEMBERS ////////////////////////////////////////////////////
+protected :
+
+  std::string _filename; ///< Name of GMV file
+  
+}; // GMVFile
+
+#endif // pylith_meshio_gmvfile_hh
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.cc	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.cc	2007-05-03 02:56:55 UTC (rev 6761)
@@ -0,0 +1,311 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include "GMVFileAscii.hh" // implementation of class methods
+
+#include "pylith/utils/array.hh" // USES double_array, int_array
+
+#include "journal/info.h" // USES journal::info_t
+
+#include <fstream> // USES std::ifstream
+#include <iomanip> // USES std::setw()
+#include <string> // USES std::string
+#include <sstream> // USES std::ostringstream
+#include <stdexcept> // USES std::exception
+#include <iostream> // USES std::cout
+
+// ----------------------------------------------------------------------
+const char* pylith::meshio::GMVFileAscii::_HEADER = "gmvinput ascii";
+
+// ----------------------------------------------------------------------
+// Constructor with name of GMV file.
+pylith::meshio::GMVFileAscii::GMVFileAscii(const char* filename) :
+  GMVFile(filename)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Default destructor 
+pylith::meshio::GMVFileAscii::~GMVFileAscii(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Read ASCII GMV file.
+void
+pylith::meshio::GMVFileAscii::read(double_array* coordinates,
+				   int_array* cells,
+				   int_array* materialIds,
+				   int* meshDim,
+				   int* spaceDim,
+				   int* numVertices,
+				   int* numCells,
+				   int* numCorners)
+{ // read
+  assert(0 != coordinates);
+  assert(0 != cells);
+  assert(0 != materialIds);
+  assert(0 != meshDim);
+  assert(0 != spaceDim);
+  assert(0 != numVertices);
+  assert(0 != numCells);
+  assert(0 != numCorners);
+
+  *meshDim = 3;
+
+  journal::info_t info("gmvfile");
+
+  std::ifstream fin(_filename.c_str(), std::ios::in);
+  if (!(fin.is_open() && fin.good())) {
+    std::ostringstream msg;
+    msg
+      << "Could not open ASCII GMV file '" << _filename
+      << "' for reading.";
+    throw std::runtime_error(msg.str());
+  } // if
+    
+  info << "Reading ASCII GMV file '" << _filename << "'." << journal::endl;
+
+  _readHeader(fin);
+
+  std::string token;
+  while (fin >> token) {
+    if (token == "nodes")
+      _readVertices(fin, coordinates, numVertices, spaceDim);
+    else if (token == "cells")
+      _readCells(fin, cells, numCells, numCorners);
+    else if (token == "variable")
+      _readVariables(fin, *numVertices, *numCells);
+    else if (token == "flags")
+      _readFlags(fin, *numVertices, *numCells);
+    else if (token == "material")
+      _readMaterials(fin, materialIds, *numVertices, *numCells);
+  } // while
+
+  assert(coordinates->size() == (*numVertices) * (*spaceDim));
+  assert(cells->size() == (*numCells) * (*numCorners));
+  assert(materialIds->size() == *numCells);
+} // read
+
+// ----------------------------------------------------------------------
+// Write ASCII GMV file.
+void
+pylith::meshio::GMVFileAscii::write(const double_array& coordinates,
+				    const int_array& cells,
+				    const int_array& materialIds,
+				    const int meshDim,
+				    const int spaceDim,
+				    const int numVertices,
+				    const int numCells,
+				    const int numCorners)
+{ // write
+  assert(coordinates.size() == numVertices * spaceDim);
+  assert(cells.size() == numCells * numCorners);
+  assert(materialIds.size() == numCells);
+
+#if 0
+  _writeHeader();
+  _writeVertices(coordinates);
+  _writeCells(cells);
+  _writeMaterials(materialIds);
+#endif
+} // write
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::GMVFileAscii::_readHeader(std::ifstream& fin)
+{ // _readHeader
+  const int headerLen = strlen(_HEADER)+1;
+  char buffer[headerLen];
+  fin.get(buffer, headerLen, '\n');
+  if (0 != strcmp(_HEADER, buffer)) {
+    std::ostringstream msg;
+    msg
+      << "Header in ASCII GMV file '" << buffer
+      << "' does not match anticipated header '"
+      << _HEADER << "'";
+    throw std::runtime_error(msg.str());
+  } // if
+} // _readHeader
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::GMVFileAscii::_readVertices(std::ifstream& fin,
+					    double_array* coordinates,
+					    int* numVertices,
+					    int* spaceDim)
+{ // _readVertices
+  assert(0 != coordinates);
+  assert(0 != numVertices);
+  assert(0 != spaceDim);
+
+  *spaceDim = 3;
+
+  journal::info_t info("gmvfile");
+
+  fin >> *numVertices;
+  info << "Reading " << *numVertices << " nodes." << journal::endl;
+
+  coordinates->resize(*numVertices * (*spaceDim));
+  // NOTE: Order of loops is different than what we usually have
+  for (int iDim=0; iDim < *spaceDim; ++iDim)
+    for (int iVertex=0; iVertex < *numVertices; ++iVertex)
+      fin >> (*coordinates)[iVertex*(*spaceDim)+iDim];
+
+  info << "Done." << journal::endl;
+} // readVertices
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::GMVFileAscii::_readCells(std::ifstream& fin,
+					 int_array* cells,
+					 int* numCells,
+					 int* numCorners)
+{ // readCells
+  assert(0 != cells);
+  assert(0 != numCells);
+  assert(0 != numCorners);
+
+  journal::info_t info("gmvfile");
+
+  fin >> *numCells;
+  std::string cellString = "";
+  info << "Reading " << numCells << " cells." << journal::endl;
+  for (int iCell=0; iCell < *numCells; ++iCell) {
+    std::string cellStringCur;
+    int numCornersCur = 0;
+    fin >> cellStringCur;
+    fin >> numCornersCur;
+    if (0 != numCorners) {
+      if (cellStringCur != cellString) {
+	std::ostringstream msg;
+	msg 
+	  << "Mutiple element types not supported. Found element types '"
+	  << cellString << "' and '" << cellStringCur << "' in GMV file '"
+	  << _filename << "'.";
+	throw std::runtime_error(msg.str());
+      } // if
+      assert(*numCorners == numCornersCur);
+    } else {
+      cellString = cellStringCur;
+      *numCorners = numCornersCur;
+      cells->resize((*numCells) * (*numCorners));
+    } // if/else
+    for (int iCorner=0; iCorner < *numCorners; ++iCorner)
+      fin >> (*cells)[iCell*(*numCorners)+iCorner];
+  } // for
+
+  info << "Done." << journal::endl;
+} // readCells
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::GMVFileAscii::_readVariables(std::ifstream& fin,
+					     const int numVertices,
+					     const int numCells)
+{ // _readVariables
+  journal::info_t info("gmvfile");
+
+  info << "Reading variables..." << journal::endl;
+
+  std::string varName;
+  fin >> varName;
+  while("endvars" != varName && !fin.eof() && fin.good()) {
+    int varType = 0;
+    fin >> varType;
+    if (1 == varType) { // variables/attributes associated with vertices
+      const int numVars = 1;
+      double_array vals(numVertices*numVars);
+      for (int iVertex=0; iVertex < numVertices; ++iVertex)
+	fin >> vals[iVertex];
+    } else { // variables/attributes associated with cells
+      const int numVars = 1;
+      double_array vals(numCells*numVars);
+      for (int iCell=0; iCell < numCells; ++iCell)
+	fin >> vals[iCell];
+    } // else
+    fin >> varName;
+  } // while
+
+  info << "Done." << journal::endl;
+} // _readVariables
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::GMVFileAscii::_readFlags(std::ifstream& fin,
+					 const int numVertices,
+					 const int numCells)
+{ // _readFlags
+  journal::info_t info("gmvfile");
+
+  info << "Reading flags..." << journal::endl;
+
+  std::string varName;
+  fin >> varName;
+  while("endflag" != varName && !fin.eof() && fin.good()) {
+    int varType = 0;
+    int numFlags = 0;
+    fin >> numFlags >> varType;
+    for (int iFlag=0; iFlag < numFlags; ++iFlag) {
+      std::string flagName;
+      fin >> flagName;
+    } // for
+    if (1 == varType) { // flag associated with vertices
+      int flag;
+      for (int iVertex=0; iVertex < numVertices; ++iVertex)
+	fin >> flag;
+    } else { // flag associated with cells
+      int flag;
+      for (int iCell=0; iCell < numCells; ++iCell)
+	fin >> flag;
+    } // else
+    fin >> varName;
+  } // while
+
+  info << "Done." << journal::endl;
+} // _readFlags
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::GMVFileAscii::_readMaterials(std::ifstream& fin,
+					     int_array* materialIds,
+					     const int numVertices,
+					     const int numCells)
+{ // _readMaterials
+  assert(0 != materialIds);
+
+  journal::info_t info("gmvfile");
+  info << "Reading materials..." << journal::endl;
+
+  int numMaterials = 0;
+  int dataType = 0;
+  fin >> numMaterials >> dataType;
+
+  std::string name;
+  for (int iMat=0; iMat < numMaterials; ++iMat)
+    fin >> name;
+
+  if (0 == dataType) { // material associated with elements
+    materialIds->resize(numCells);
+    for (int iCell=0; iCell < numCells; ++iCell)
+      fin >> (*materialIds)[iCell];
+  } else { // material associated with nodes
+    int_array materials(numVertices);
+    for (int iVertex=0; iVertex < numVertices; ++iVertex)
+      fin >> materials[iVertex];
+  } // else
+
+  info << "Done." << journal::endl;
+} // _readMaterials
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.hh	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.hh	2007-05-03 02:56:55 UTC (rev 6761)
@@ -0,0 +1,164 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_gmvfileascii_hh)
+#define pylith_meshio_gmvfileascii_hh
+
+#include "GMVFile.hh" // ISA GMVFile
+
+#include "pylith/utils/arrayfwd.hh" // USES int_array, double_array
+#include <iosfwd>
+
+namespace pylith {
+  namespace meshio {
+    class GMVFileAscii;
+  } // meshio
+} // pylith
+
+class pylith::meshio::GMVFileAscii : public GMVFile
+{ // GMVFileAscii
+
+public :
+  // PUBLIC METHODS ///////////////////////////////////////////////
+
+  /** Constructor with name of GMV file.
+   *
+   * @param filename Name of GMV file
+   */
+  GMVFileAscii(const char* name);
+
+  /// Default destructor 
+  ~GMVFileAscii(void);
+
+  /** Get header.
+   *
+   * @returns Header that appears in ASCII GMV file
+   */
+  static const char* header(void);
+
+  /** Read ASCII GMV file.
+   *
+   * @coordinates Coordinates of vertices.
+   * @param cells Indices of cell vertices.
+   * @param materialIds Material identifiers for each cell.
+   * @param meshDim Dimension of cells in mesh.
+   * @param numVertices Number of vertices in mesh.
+   * @param numCells Number of cells in mesh.
+   * @param numCorners Number of vertices in each cell.
+   */
+  void read(double_array* coordinates,
+	    int_array* cells,
+	    int_array* materialIds,
+	    int* meshDim,
+	    int* spaceDim,
+	    int* numVertices,
+	    int* numCells,
+	    int* numCorners);
+
+  /** Write ASCII GMV file.
+   *
+   * @coordinates Coordinates of vertices.
+   * @param cells Indices of cell vertices.
+   * @param materialIds Material identifiers for each cell.
+   * @param meshDim Dimension of cells in mesh.
+   * @param spaceDim Number of coordinates per vertex.
+   * @param numVertices Number of vertices in mesh.
+   * @param numCells Number of cells in mesh.
+   * @param numCorners Number of vertices in each cell.
+   */
+  void write(const double_array& coordinates,
+	     const int_array& cells,
+	     const int_array& materialIds,
+	     const int meshDim,
+	     const int spaceDim,
+	     const int numVertices,
+	     const int numCells,
+	     const int numCorners);
+
+ private :
+  // PRIVATE METHODS //////////////////////////////////////////////
+  
+  /** Read header.
+   *
+   * @param fin Input file stream
+   */
+  void _readHeader(std::ifstream& fin);
+
+  /** Read vertices.
+   *
+   * @param fin Input file stream.
+   * @param coordinates Coordinates of vertices.
+   * @param numVertices Number of vertices.
+   */
+  void _readVertices(std::ifstream& fin,
+		     double_array* coordinates,
+		     int* numVertices,
+		     int* spaceDim);
+
+  /** Read cells.
+   *
+   * @param fin Input file stream
+   * @param cells Indices of cell vertices.
+   * @param numCells Number of cells in mesh.
+   * @param numCorners Number of vertices in each cell.
+   */
+  void _readCells(std::ifstream& fin,
+		  int_array* cells,
+		  int* numCells,
+		  int* numCorners);
+
+  /** Read and discard variables associated with vertices.
+   *
+   * @param fin Input file stream
+   * @param numVertices Number of vertices in mesh.
+   * @param numCells Number of cells in mesh.
+   */
+  void _readVariables(std::ifstream& fin,
+		      const int numVertices,
+		      const int numCells);
+
+  /** Read and discard material flags for vertices.
+   *
+   * @param fin Input file stream
+   * @param numVertices Number of vertices in mesh.
+   * @param numCells Number of cells in mesh.
+   */
+  void _readFlags(std::ifstream& fin,
+		  const int numVertices,
+		  const int numCells);
+
+  /** Read material values for cells.
+   *
+   * @param fin Input file stream
+   * @param materialIds Material identifiers for each cell.
+   * @param numVertices Number of vertices in mesh.
+   * @param numCells Number of cells in mesh.
+   */
+  void _readMaterials(std::ifstream& fin,
+		      int_array* materialIds,
+		      const int numVertices,
+		      const int numCells);
+
+private :
+  // PRIVATE METHODS //////////////////////////////////////////////
+  
+  /** Header in ascii GMV file */
+  static const char* _HEADER;
+
+}; // GMVFileInAscii
+
+#include "GMVFileAscii.icc" // inline methods
+
+#endif // pylith_meshio_gmvfileascii
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.icc	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/meshio/GMVFileAscii.icc	2007-05-03 02:56:55 UTC (rev 6761)
@@ -0,0 +1,28 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_gmvfileascii_hh)
+#error "GMVFileAscii.icc must be included only from GMVFileAscii.icc"
+#else
+
+// ----------------------------------------------------------------
+// Get header.
+inline
+const char*
+pylith::meshio::GMVFileAscii::header(void)
+{ // header
+  return _HEADER;
+} // header
+
+#endif
+
+// End of file

Added: short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.cc	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.cc	2007-05-03 02:56:55 UTC (rev 6761)
@@ -0,0 +1,347 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include "GMVFileBinary.hh" // implementation of class methods
+
+#include "pylith/utils/array.hh" // USES double_array, int_array
+#include "pylith/utils/Endian.hh" // USES Endian
+
+#include "journal/info.h" // USES journal::info_t
+
+#include <fstream> // USES std::ifstream
+#include <iomanip> // USES std::setw()
+#include <string> // USES std::string
+#include <sstream> // USES std::ostringstream
+#include <stdexcept> // USES std::exception
+#include <iostream> // USES std::cout
+
+// ----------------------------------------------------------------------
+const char* pylith::meshio::GMVFileBinary::_HEADER = "gmvinputieee    ";
+
+// ----------------------------------------------------------------------
+// Constructor with name of GMV file.
+pylith::meshio::GMVFileBinary::GMVFileBinary(const char* filename,
+					     const bool flipEndian) :
+  GMVFile(filename),
+  _flipEndian(flipEndian)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Default destructor 
+pylith::meshio::GMVFileBinary::~GMVFileBinary(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Read ASCII GMV file.
+void
+pylith::meshio::GMVFileBinary::read(double_array* coordinates,
+				    int_array* cells,
+				    int_array* materialIds,
+				    int* meshDim,
+				    int* spaceDim,
+				    int* numVertices,
+				    int* numCells,
+				    int* numCorners)
+{ // read
+  assert(0 != coordinates);
+  assert(0 != cells);
+  assert(0 != materialIds);
+  assert(0 != meshDim);
+  assert(0 != spaceDim);
+  assert(0 != numVertices);
+  assert(0 != numCells);
+  assert(0 != numCorners);
+
+  *meshDim = 3;
+
+  journal::info_t info("gmvfile");
+
+  std::ifstream fin(_filename.c_str(), std::ios::in | std::ios::binary);
+  if (!(fin.is_open() && fin.good())) {
+    std::ostringstream msg;
+    msg
+      << "Could not open ASCII GMV file '" << _filename
+      << "' for reading.";
+    throw std::runtime_error(msg.str());
+  } // if
+    
+  info << "Reading binary GMV file '" << _filename << "'." << journal::endl;
+
+  _readHeader(fin);
+
+  std::string token;
+  while (fin >> token) {
+    if (token == "nodes")
+      _readVertices(fin, coordinates, numVertices, spaceDim);
+    else if (token == "cells")
+      _readCells(fin, cells, numCells, numCorners);
+    else if (token == "variable")
+      _readVariables(fin, *numVertices, *numCells);
+    else if (token == "flags")
+      _readFlags(fin, *numVertices, *numCells);
+    else if (token == "material")
+      _readMaterials(fin, materialIds, *numVertices, *numCells);
+  } // while
+
+  assert(coordinates->size() == (*numVertices) * (*spaceDim));
+  assert(cells->size() == (*numCells) * (*numCorners));
+  assert(materialIds->size() == *numCells);
+} // read
+
+// ----------------------------------------------------------------------
+// Write ASCII GMV file.
+void
+pylith::meshio::GMVFileBinary::write(const double_array& coordinates,
+				     const int_array& cells,
+				     const int_array& materialIds,
+				     const int meshDim,
+				     const int spaceDim,
+				     const int numVertices,
+				     const int numCells,
+				     const int numCorners)
+{ // write
+  assert(coordinates.size() == numVertices * spaceDim);
+  assert(cells.size() == numCells * numCorners);
+  assert(materialIds.size() == numCells);
+
+#if 0
+  _writeHeader();
+  _writeVertices(coordinates);
+  _writeCells(cells);
+  _writeMaterials(materialIds);
+#endif
+} // write
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::GMVFileBinary::_readHeader(std::ifstream& fin)
+{ // _readHeader
+  std::string header = _readString(fin, strlen(_HEADER));
+  std::string headerE = _HEADER;
+  headerE = headerE.substr(0, headerE.find_first_of(" "));
+  if (headerE != header) {
+    std::ostringstream msg;
+    msg
+      << "Header in binary GMV file '" << header
+      << "' does not match anticipated header '" << headerE << "'.";
+    throw std::runtime_error(msg.str());
+  } // if
+} // _readHeader
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::GMVFileBinary::_readVertices(std::ifstream& fin,
+					     double_array* coordinates,
+					     int* numVertices,
+					     int* spaceDim)
+{ // _readVertices
+  assert(0 != coordinates);
+  assert(0 != numVertices);
+  assert(0 != spaceDim);
+
+  *spaceDim = 3;
+
+  journal::info_t info("gmvfile");
+
+  fin.read((char*) numVertices, sizeof(int));
+  if (_flipEndian)
+    utils::Endian::swapByteOrder((char*) numVertices, 1, sizeof(int));
+      
+  info << "Reading " << *numVertices << " nodes." << journal::endl;
+
+  const int size = (*numVertices) * (*spaceDim);
+  float_array buffer(size);
+
+  fin.read((char*) &buffer[0], size*sizeof(float));
+  if (_flipEndian)
+    utils::Endian::swapByteOrder((char*) &buffer[0], size, sizeof(float));
+
+  coordinates->resize(size);
+  // switch from column major to row major order
+  for (int iDim=0, i=0; iDim < *spaceDim; ++iDim)
+    for (int iVertex=0; iVertex < *numVertices; ++iVertex)
+      (*coordinates)[iVertex*(*spaceDim)+iDim] = buffer[i++];
+  
+  info << "Done." << journal::endl;
+} // _readNodes
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::GMVFileBinary::_readCells(std::ifstream& fin,
+					  int_array* cells,
+					  int* numCells,
+					  int* numCorners)
+{ // readCells
+  assert(0 != cells);
+  assert(0 != numCells);
+  assert(0 != numCorners);
+
+  journal::info_t info("gmvfile");
+
+  fin.read((char*) numCells, sizeof(int));
+  if (_flipEndian)
+    utils::Endian::swapByteOrder((char*) numCells, 1, sizeof(int));
+  info << "Reading " << *numCells << " cells." << journal::endl;
+  std::string cellString = "";
+  for (int iCell=0; iCell < *numCells; ++iCell) {
+    const int stringLen = 8;
+    char cellStringCur[stringLen+1];
+    int numCornersCur = 0;
+    fin.read((char*) cellStringCur, sizeof(char)*stringLen);
+    cellStringCur[stringLen] = '\0';
+    fin.read((char*) &numCornersCur, sizeof(int));
+    if (_flipEndian)
+      utils::Endian::swapByteOrder((char*) numCornersCur, 1, sizeof(int));
+    if (0 != *numCorners) {
+      if (cellStringCur != cellString) {
+	std::ostringstream msg;
+	msg 
+	  << "Mutiple element types not supported. Found element types '"
+	  << cellString << "' and '" << cellStringCur << "' in GMV file '"
+	  << _filename << "'.";
+	throw std::runtime_error(msg.str());
+      } // if
+      assert(*numCorners == numCornersCur);
+    } else {
+      cellString = cellStringCur;
+      *numCorners = numCornersCur;
+      cells->resize((*numCells) * (*numCorners));
+    } // if/else
+    fin.read((char*) &(*cells)[iCell*numCornersCur], 
+	     sizeof(int)*numCornersCur);
+  } // for
+  if (_flipEndian)
+    utils::Endian::swapByteOrder((char*) &(*cells)[0], 
+				 (*numCells)*(*numCorners), sizeof(int));
+  info << "Done." << journal::endl;
+} // readCells
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::GMVFileBinary::_readVariables(std::ifstream& fin,
+					      const int numVertices,
+					      const int numCells)
+{ // _readVariables
+  journal::info_t info("gmvfile");
+  info << "Reading variables..." << journal::endl;
+  
+  const int varNameLen = 8;
+  std::string varName = _readString(fin, varNameLen);
+  while("endvars" != varName && !fin.eof() && fin.good()) {
+    int varType = 0;
+    fin.read((char*) &varType, sizeof(int));
+    if (1 == varType) { // variable/attribute associated with vertices
+      float_array vals(numVertices);
+      fin.read((char*) &vals[0], sizeof(float)*numVertices);
+    } else { // variable/attribute associated with cells
+      float_array vals(numCells);
+      fin.read((char*) &vals[0], sizeof(float)*numCells);
+    } // else
+    varName = _readString(fin, varNameLen);
+  } // while
+
+  std::cout << "Done." << std::endl;
+} // _readVariables
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::GMVFileBinary::_readFlags(std::ifstream& fin,
+					  const int numVertices,
+					  const int numCells)
+{ // _readFlags
+  journal::info_t info("gmvfile");
+  info << "Reading flags..." << journal::endl;
+
+  const int varNameLen = 8;
+  std::string varName = _readString(fin, varNameLen);
+  while("endflag" != varName && !fin.eof() && fin.good()) {
+    int numFlags = 0;
+    fin.read((char*) &numFlags, sizeof(int));
+    int varType = 0;
+    fin.read((char*) &varType, sizeof(int));
+    for (int iFlag=0; iFlag < numFlags; ++iFlag) {
+      const int flagNameLen = 8;
+      std::string flagName = _readString(fin, flagNameLen);
+    } // for
+    if (1 == varType) { // flag associated with vertices
+      int_array buffer(numVertices);
+      fin.read((char*) &buffer[0], sizeof(int)*numVertices);
+    } else { // flag associated with cells
+      int_array buffer(numVertices);
+      fin.read((char*) &buffer[0], sizeof(int)*numCells);
+    } // else
+    varName = _readString(fin, varNameLen);
+  } // while
+  
+  std::cout << "Done." << std::endl;
+} // _readFlags
+
+// ----------------------------------------------------------------------
+void
+pylith::meshio::GMVFileBinary::_readMaterials(std::ifstream& fin,
+					      int_array* materialIds,
+					      const int numVertices,
+					      const int numCells)
+{ // _readMaterials
+  assert(0 != materialIds);
+
+  journal::info_t info("gmvfile");
+  info << "Reading materials..." << journal::endl;
+
+  int numMaterials = 0;
+  fin.read((char*) &numMaterials, sizeof(int));
+  int dataType = 0;
+  fin.read((char*) &dataType, sizeof(int));
+
+  for (int iMat=0; iMat < numMaterials; ++iMat) {
+    const int nameLen = 8;
+    std::string name = _readString(fin, nameLen);
+  } // for
+
+  if (0 == dataType) { // materials associated with cells
+    materialIds->resize(numCells);
+    fin.read((char*) &(*materialIds)[0], sizeof(int)*numCells);
+    if (_flipEndian)
+      utils::Endian::swapByteOrder((char*) &(*materialIds)[0], numCells,
+				   sizeof(int));
+  } else { // materials associated with vertices
+    int_array buffer(numVertices);
+    fin.read((char*) &buffer[0], sizeof(int)*numVertices);
+  } // else
+
+  std::cout << "Done." << std::endl;
+} // _readMaterials
+
+// ----------------------------------------------------------------------
+// Read fixed length string from file.
+std::string
+pylith::meshio::GMVFileBinary::_readString(std::ifstream& fin,
+					   const int numChars)
+{ // _readString
+  char* buffer = (numChars > 0) ? new char[numChars+1] : 0;
+  fin.read(buffer, sizeof(char)*numChars);
+  buffer[numChars] = '\0';
+
+  // get string from buffer
+  std::string bufstring(buffer);
+  delete[] buffer; buffer = 0;
+
+  // remove whitespace
+  const int iLast = bufstring.find_first_of(" ");
+
+  return bufstring.substr(0, iLast);
+} // _readString
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.hh	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/meshio/GMVFileBinary.hh	2007-05-03 02:56:55 UTC (rev 6761)
@@ -0,0 +1,176 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_gmvfilebinary_hh)
+#define pylith_meshio_gmvfilebinary_hh
+
+#include "GMVFile.hh" // ISA GMVFile
+
+#include "pylith/utils/arrayfwd.hh" // USES int_array, double_array
+#include <iosfwd>
+
+namespace pylith {
+  namespace meshio {
+    class GMVFileBinary;
+  } // meshio
+} // pylith
+
+class pylith::meshio::GMVFileBinary : public GMVFile
+{ // GMVFileBinary
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+  /** Constructor with name of GMV file.
+   *
+   * @param filename Name of GMV file
+   * @param flipEndian Flip endian type when reading/writing.
+   */
+  GMVFileBinary(const char* filename,
+		const bool flipEndian =false);
+
+  /// Default destructor 
+  ~GMVFileBinary(void);
+
+  /** Get header.
+   *
+   * @returns Header that appears in BINARY GMV file
+   */
+  static
+  const char* header(void);
+
+  /** Read BINARY GMV file.
+   *
+   * @coordinates Coordinates of vertices.
+   * @param cells Indices of cell vertices.
+   * @param materialIds Material identifiers for each cell.
+   * @param meshDim Dimension of cells in mesh.
+   * @param numVertices Number of vertices in mesh.
+   * @param numCells Number of cells in mesh.
+   * @param numCorners Number of vertices in each cell.
+   */
+  void read(double_array* coordinates,
+	    int_array* cells,
+	    int_array* materialIds,
+	    int* meshDim,
+	    int* spaceDim,
+	    int* numVertices,
+	    int* numCells,
+	    int* numCorners);
+
+  /** Write BINARY GMV file.
+   *
+   * @coordinates Coordinates of vertices.
+   * @param cells Indices of cell vertices.
+   * @param materialIds Material identifiers for each cell.
+   * @param meshDim Dimension of cells in mesh.
+   * @param spaceDim Number of coordinates per vertex.
+   * @param numVertices Number of vertices in mesh.
+   * @param numCells Number of cells in mesh.
+   * @param numCorners Number of vertices in each cell.
+   */
+  void write(const double_array& coordinates,
+	     const int_array& cells,
+	     const int_array& materialIds,
+	     const int meshDim,
+	     const int spaceDim,
+	     const int numVertices,
+	     const int numCells,
+	     const int numCorners);
+
+// PRIVATE METHODS //////////////////////////////////////////////////////
+private :
+  
+  /** Read header.
+   *
+   * @param fin Input file stream
+   */
+  void _readHeader(std::ifstream& fin);
+
+  /** Read vertices.
+   *
+   * @param fin Input file stream.
+   * @param coordinates Coordinates of vertices.
+   * @param numVertices Number of vertices.
+   */
+  void _readVertices(std::ifstream& fin,
+		     double_array* coordinates,
+		     int* numVertices,
+		     int* spaceDim);
+
+  /** Read cells.
+   *
+   * @param fin Input file stream
+   * @param cells Indices of cell vertices.
+   * @param numCells Number of cells in mesh.
+   * @param numCorners Number of vertices in each cell.
+   */
+  void _readCells(std::ifstream& fin,
+		  int_array* cells,
+		  int* numCells,
+		  int* numCorners);
+
+  /** Read and discard variables associated with vertices.
+   *
+   * @param fin Input file stream
+   * @param numVertices Number of vertices in mesh.
+   * @param numCells Number of cells in mesh.
+   */
+  void _readVariables(std::ifstream& fin,
+		      const int numVertices,
+		      const int numCells);
+
+  /** Read and discard material flags for vertices.
+   *
+   * @param fin Input file stream
+   * @param numVertices Number of vertices in mesh.
+   * @param numCells Number of cells in mesh.
+   */
+  void _readFlags(std::ifstream& fin,
+		  const int numVertices,
+		  const int numCells);
+
+  /** Read material values for cells.
+   *
+   * @param fin Input file stream
+   * @param materialIds Material identifiers for each cell.
+   * @param numVertices Number of vertices in mesh.
+   * @param numCells Number of cells in mesh.
+   */
+  void _readMaterials(std::ifstream& fin,
+		      int_array* materialIds,
+		      const int numVertices,
+		      const int numCells);
+
+  /** Read fixed length string from file.
+   *
+   * @param fin Input file stream
+   * @param numChars Number of characters in string.
+   */
+  static
+  std::string _readString(std::ifstream& fin,
+			  const int numChars);
+  
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+  
+  /// Header in binary GMV file.
+  static const char* _HEADER;
+
+  bool _flipEndian; ///< True if need to change endian when reading/writing
+
+}; // GMVFileBinary
+
+#endif // pylith_meshio_gmvfilebinary
+
+
+// End of file 

Modified: short/3D/PyLith/trunk/libsrc/meshio/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/Makefile.am	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/meshio/Makefile.am	2007-05-03 02:56:55 UTC (rev 6761)
@@ -17,9 +17,15 @@
 	MeshIO.hh \
 	MeshIO.icc \
 	MeshIOAscii.hh \
-	MeshIOAscii.icc
+	MeshIOAscii.icc \
+	MeshIOLagrit.hh \
+	MeshIOLagrit.icc
 
-noinst_HEADERS =
+noinst_HEADERS = \
+	GMVFile.hh \
+	GMVFileAscii.hh \
+	GMVFileAscii.icc \
+	GMVFileBinary.hh
 
 # export
 clean-local: clean-subpkgincludeHEADERS

Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc	2007-05-03 02:56:55 UTC (rev 6761)
@@ -15,7 +15,6 @@
 #include "MeshIOAscii.hh" // implementation of class methods
 
 #include "pylith/utils/array.hh" // USES double_array, int_array, string_vector
-#include "pylith/utils/sievetypes.hh" // USES PETSc mesh
 
 #include <fstream> // USES std::ifstream, std::ofstream
 #include <stdexcept> // USES std::runtime_error

Added: short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.cc	2007-05-03 02:56:55 UTC (rev 6761)
@@ -0,0 +1,76 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "MeshIOLagrit.hh" // implementation of class methods
+
+#include "GMVFileAscii.hh" // USES GMVFileAscii
+#include "GMVFileBinary.hh" // USES GMVFileBinary
+
+#include "pylith/utils/array.hh" // USES double_array, int_array
+
+// ----------------------------------------------------------------------
+// Constructor
+pylith::meshio::MeshIOLagrit::MeshIOLagrit(void) :
+  _filenameGmv(""),
+  _filenamePset(""),
+  _flipEndian(false)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+pylith::meshio::MeshIOLagrit::~MeshIOLagrit(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Unpickle mesh
+void
+pylith::meshio::MeshIOLagrit::_read(void)
+{ // _read
+  int meshDim = 0;
+  int spaceDim = 0;
+  int numVertices = 0;
+  int numCells = 0;
+  int numCorners = 0;
+  double_array coordinates;
+  int_array cells;
+  int_array materialIds;
+
+  if (GMVFile::isAscii(_filenameGmv.c_str())) {
+    GMVFileAscii filein(_filenameGmv.c_str());
+    filein.read(&coordinates, &cells, &materialIds, 
+		&meshDim, &spaceDim, &numVertices, &numCells, &numCorners);
+  } else {
+    GMVFileBinary filein(_filenameGmv.c_str(), _flipEndian);
+    filein.read(&coordinates, &cells, &materialIds, 
+		&meshDim, &spaceDim, &numVertices, &numCells, &numCorners);
+  } // if/else
+  _buildMesh(coordinates, numVertices, spaceDim,
+	     cells, numCells, numCorners, meshDim);
+  _setMaterials(materialIds);
+
+#if 0
+  if (PsetFile::_isPsetAscii(_filenamePset)) {
+    PsetFileAscii filein(_filenamePset);
+    filein.read();
+  } else {
+    PsetFileBinary filein(_filenamePset);
+    filein.read();
+  } // if/else
+#endif
+} // _read
+
+  
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.hh	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.hh	2007-05-03 02:56:55 UTC (rev 6761)
@@ -0,0 +1,153 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_meshiolagrit_hh)
+#define pylith_meshio_meshiolagrit_hh
+
+#include "MeshIO.hh" // ISA MeshIO
+
+#include <string> // HASA std::string
+
+namespace pylith {
+  namespace meshio {
+    class MeshIOLagrit;
+  } // meshio
+} // pylith
+
+class pylith::meshio::MeshIOLagrit : public MeshIO
+{ // MeshIOLagrit
+// PUBLIC METHODS -------------------------------------------------------
+public :
+
+  /// Constructor
+  MeshIOLagrit(void);
+
+  /// Destructor
+  ~MeshIOLagrit(void);
+
+  /** Set filename for mesh GMV file.
+   *
+   * @param filename Name of file
+   */
+  void filenameGmv(const char* name);
+
+  /** Get filename of mesh GMV file.
+   *
+   * @returns Name of file
+   */
+  const char* filenameGmv(void) const;
+
+  /** Set filename for PSET mesh file.
+   *
+   * @param filename Name of file
+   */
+  void filenamePset(const char* name);
+
+  /** Get filename of PSET mesh file.
+   *
+   * @returns Name of file
+   */
+  const char* filenamePset(void) const;
+
+  /** Set flag to write ASCII or binary files.
+   *
+   * @param flag True if writing ASCII, false if writing binary
+   */
+  void writerAscii(const bool flag);
+
+  /** Get flag for writing ASCII or binary files.
+   *
+   * @returns True if writing ASCII, false if writing binary.
+   */
+  bool writeAscii(void) const;
+
+  /** Set flag to flip endian type when reading/writing from binary files.
+   *
+   * @param flag True if flipping endian, false otherwise
+   */
+  void flipEndian(const bool flag);
+
+  /** Get flag for flipping endian type when reading/writing from binary files.
+   *
+   * @returns True if flipping endian, false othewise.
+   */
+  bool flipEndian(void) const;
+
+// PROTECTED METHODS ----------------------------------------------------
+protected :
+
+  /// Write mesh
+  void _write(void) const;
+
+  /// Read mesh
+  void _read(void);
+
+// PRIVATE METHODS ------------------------------------------------------
+private :
+
+  /** Header in ascii GMV file */
+  static const char* GMVASCIIHEADER;
+
+  /** Header in binary GMV file */
+  static const char* GMVBINARYHEADER;
+
+  /** Is GMV file an ASCII file?
+   *
+   * @returns true if GMV file is ASCII, false if binary
+   */
+  bool _isGmvAscii(void) const;
+
+  /// Read ASCII GMV file.
+  void _readGmvAscii(void);
+
+  /// Read binary GMV file.
+  void _readGmvBinary(void);
+
+  /// Write ASCII GMV file.
+  void _writeGmvAscii(void) const;
+
+  /// Read binary GMV file.
+  void _writeGmvBinary(void) const;
+
+  /** Is PSET file an ASCII file?
+   *
+   * @returns true if PSET file is ASCII, false if binary
+   */
+  bool _isPsetAscii(void) const;
+
+  /// Read ASCII PSET file.
+  void _readPsetAscii(void);
+
+  /// Read binary PSET file.
+  void _readPsetBinary(void);
+
+  /// Write ASCII PSET file.
+  void _writePsetAscii(void) const;
+
+  /// Write binary PSET file.
+  void _writePsetBinary(void) const;
+
+  // PRIVATE MEMBERS ----------------------------------------------------
+private :
+
+  std::string _filenameGmv; ///< Name of GMV file
+  std::string _filenamePset; ///< Name of PSET file
+  bool _writeAscii; ///< True if writing ASCII, false if writing binary
+  bool _flipEndian; ///< True if need to change endian when reading/writing
+
+}; // MeshIOLagrit
+
+#include "MeshIOLagrit.icc" // inline methods
+
+#endif // pylith_meshio_meshiolagrit_hh
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.icc	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOLagrit.icc	2007-05-03 02:56:55 UTC (rev 6761)
@@ -0,0 +1,75 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_meshiolagrit_hh)
+#error "MeshIOLagrit.icc must be included only from MeshIOLagrit.icc"
+#else
+
+// Set filename for mesh GMV file.
+inline
+void
+pylith::meshio::MeshIOLagrit::filenameGmv(const char* name) {
+  _filenameGmv = name;
+}
+
+// Get filename of mesh GMV file.
+inline
+const char* 
+pylith::meshio::MeshIOLagrit::filenameGmv(void) const {
+  return _filenameGmv.c_str();
+}
+
+// Set filename for mesh PSET file.
+inline
+void
+pylith::meshio::MeshIOLagrit::filenamePset(const char* name) {
+  _filenamePset = name;
+}
+
+// Get filename of mesh PSET file.
+inline
+const char* 
+pylith::meshio::MeshIOLagrit::filenamePset(void) const {
+  return _filenamePset.c_str();
+}
+
+// Set flag to write ASCII or binary files.
+inline
+void
+pylith::meshio::MeshIOLagrit::writerAscii(const bool flag) {
+  _writeAscii = flag;
+}
+
+// Get flag for writing ASCII or binary files.
+inline
+bool
+pylith::meshio::MeshIOLagrit::writeAscii(void) const {
+  return _writeAscii;
+}
+
+// Set flag to flip endian type when reading/writing from binary files.
+inline
+void
+pylith::meshio::MeshIOLagrit::flipEndian(const bool flag) {
+  _flipEndian = flag;
+}
+
+// Get flag for flipping endian type when reading/writing from binary files.
+inline
+bool
+pylith::meshio::MeshIOLagrit::flipEndian(void) const {
+  return _flipEndian;
+}
+
+#endif
+
+// End of file

Modified: short/3D/PyLith/trunk/libsrc/utils/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/utils/Makefile.am	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/utils/Makefile.am	2007-05-03 02:56:55 UTC (rev 6761)
@@ -14,6 +14,7 @@
 include $(top_srcdir)/subpackage.am
 
 subpkginclude_HEADERS = \
+	Endian.hh \
 	array.hh \
 	arrayfwd.hh \
 	petscfwd.h \

Modified: short/3D/PyLith/trunk/libsrc/utils/arrayfwd.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/utils/arrayfwd.hh	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/libsrc/utils/arrayfwd.hh	2007-05-03 02:56:55 UTC (rev 6761)
@@ -51,6 +51,9 @@
   /// Alias for std::valarray<int>
   typedef std::valarray<int> int_array;
 
+  /// Alias for std::valarray<float>
+  typedef std::valarray<float> float_array;
+
   /// Alias for std::valarray<double>
   typedef std::valarray<double> double_array;
 

Modified: short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/modulesrc/meshio/meshio.pyxe.src	2007-05-03 02:56:55 UTC (rev 6761)
@@ -13,6 +13,7 @@
 #header{
 #include "pylith/meshio/MeshIO.hh"
 #include "pylith/meshio/MeshIOAscii.hh"
+#include "pylith/meshio/MeshIOLagrit.hh"
 
 #include <stdexcept>
 #include <assert.h>
@@ -286,4 +287,147 @@
       return MeshIOAscii_filename_get(self.thisptr)
 
 
+# ----------------------------------------------------------------------
+cdef class MeshIOLagrit(MeshIO):
+
+  def __init__(self):
+    """Constructor."""
+    # create shim for constructor
+    #embed{ void* MeshIOLagrit_constructor()
+    void* result = 0;
+    try {
+      result = (void*)(new pylith::meshio::MeshIOLagrit);
+      assert(0 != result);
+    } catch (const std::exception& err) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      const_cast<char*>(err.what()));
+    } catch (...) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      "Caught unknown C++ exception.");
+    } // try/catch
+    return result;
+    #}embed
+
+    MeshIO.__init__(self)
+    self.thisptr = MeshIOLagrit_constructor()
+    self.handle = self._createHandle()
+    return
+
+
+  property filenameGmv:
+    def __set__(self, name):
+      """Set filename."""
+      # create shim for method 'filenameGmv'
+      #embed{ void MeshIOLagrit_filenameGmv_set(void* objVptr, char* name)
+      try {
+        assert(0 != objVptr);
+        ((pylith::meshio::MeshIOLagrit*) objVptr)->filenameGmv(name);
+      } catch (const std::exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.what()));
+      } catch (...) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "Caught unknown C++ exception.");
+      } // try/catch
+      #}embed
+      MeshIOLagrit_filenameGmv_set(self.thisptr, name)
+
+    def __get__(self):
+      """Get filename."""
+      # create shim for method 'filenameGmv'
+      #embed{ char* MeshIOLagrit_filenameGmv_get(void* objVptr)
+      char* result = 0;
+      try {
+        assert(0 != objVptr);
+        result = (char*) ((pylith::meshio::MeshIOLagrit*) objVptr)->filenameGmv();
+        assert(0 != result);
+      } catch (const std::exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.what()));
+      } catch (...) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "Caught unknown C++ exception.");
+      } // try/catch
+      return result;
+      #}embed
+      return MeshIOLagrit_filenameGmv_get(self.thisptr)
+
+
+  property filenamePset:
+    def __set__(self, name):
+      """Set filename."""
+      # create shim for method 'filenamePset'
+      #embed{ void MeshIOLagrit_filenamePset_set(void* objVptr, char* name)
+      try {
+        assert(0 != objVptr);
+        ((pylith::meshio::MeshIOLagrit*) objVptr)->filenamePset(name);
+      } catch (const std::exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.what()));
+      } catch (...) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "Caught unknown C++ exception.");
+      } // try/catch
+      #}embed
+      MeshIOLagrit_filenamePset_set(self.thisptr, name)
+
+    def __get__(self):
+      """Get filename."""
+      # create shim for method 'filenamePset'
+      #embed{ char* MeshIOLagrit_filenamePset_get(void* objVptr)
+      char* result = 0;
+      try {
+        assert(0 != objVptr);
+        result = (char*) ((pylith::meshio::MeshIOLagrit*) objVptr)->filenamePset();
+        assert(0 != result);
+      } catch (const std::exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.what()));
+      } catch (...) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "Caught unknown C++ exception.");
+      } // try/catch
+      return result;
+      #}embed
+      return MeshIOLagrit_filenamePset_get(self.thisptr)
+
+
+  property flipEndian:
+    def __set__(self, flag):
+      """Set flip endian flag."""
+      # create shim for method 'flipEndian'
+      #embed{ void MeshIOLagrit_flipEndian_set(void* objVptr, int flag)
+      try {
+        assert(0 != objVptr);
+        ((pylith::meshio::MeshIOLagrit*) objVptr)->flipEndian(flag);
+      } catch (const std::exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.what()));
+      } catch (...) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "Caught unknown C++ exception.");
+      } // try/catch
+      #}embed
+      MeshIOLagrit_flipEndian_set(self.thisptr, flag)
+
+    def __get__(self):
+      """Get flip endian flag."""
+      # create shim for method 'flipEndian'
+      #embed{ int MeshIOLagrit_flipEndian_get(void* objVptr)
+      int result = 0;
+      try {
+        assert(0 != objVptr);
+        result = ((pylith::meshio::MeshIOLagrit*) objVptr)->flipEndian();
+      } catch (const std::exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.what()));
+      } catch (...) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "Caught unknown C++ exception.");
+      } // try/catch
+      return result;
+      #}embed
+      return MeshIOLagrit_flipEndian_get(self.thisptr)
+
+
 # End of file 

Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/pylith/Makefile.am	2007-05-03 02:56:55 UTC (rev 6761)
@@ -48,6 +48,7 @@
 	materials/MaterialsBin.py \
 	meshio/MeshIO.py \
 	meshio/MeshIOAscii.py \
+	meshio/MeshIOLagrit.py \
 	meshio/__init__.py \
 	problems/__init__.py \
 	problems/EqDeformation.py \

Modified: short/3D/PyLith/trunk/pylith/meshio/MeshIOAscii.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/MeshIOAscii.py	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/pylith/meshio/MeshIOAscii.py	2007-05-03 02:56:55 UTC (rev 6761)
@@ -42,7 +42,7 @@
     ## @li \b filename Name of mesh file
     ##
     ## \b Facilities
-    ## @li None
+    ## @li coordsys Coordinate system associated with mesh.
 
     import pyre.inventory
 

Added: short/3D/PyLith/trunk/pylith/meshio/MeshIOLagrit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/MeshIOLagrit.py	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/pylith/meshio/MeshIOLagrit.py	2007-05-03 02:56:55 UTC (rev 6761)
@@ -0,0 +1,110 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pyre/meshio/MeshIOLagrit.py
+##
+## @brief Python object for reading/writing finite-element mesh from
+## LaGriT.
+##
+## Factory: mesh_io
+
+from MeshIO import MeshIO
+
+# MeshIOLagrit class
+class MeshIOLagrit(MeshIO):
+  """
+  Python object for reading/writing finite-element mesh from LaGriT.
+
+  Factory: mesh_io
+  """
+
+  # INVENTORY //////////////////////////////////////////////////////////
+
+  class Inventory(MeshIO.Inventory):
+    """
+    Python object for managing MeshIOLagrit facilities and properties.
+    """
+
+    ## @class Inventory
+    ## Python object for managing MeshIOLagrit facilities and properties.
+    ##
+    ## \b Properties
+    ## @li \b filename_gmv Name of mesh GMV file.
+    ## @li \b filename_pset Name of mesh PSET file.
+    ## @li \b flip_endian Flip endian type when reading/writing binary files.
+    ##
+    ## \b Facilities
+    ## @li coordsys Coordinate system associated with mesh.
+
+    import pyre.inventory
+
+    filenameGmv = pyre.inventory.str("filename_gmv", default="mesh.gmv")
+    filenameGmv.meta['tip'] = "Name of mesh GMV file."
+
+    filenamePset = pyre.inventory.str("filename_pset", default="mesh.pset")
+    filenamePset.meta['tip'] = "Name of mesh PSET file."
+
+    flipEndian = pyre.inventory.bool("flip_endian", default=False)
+    flipEndian.meta['tip'] = "Flip endian type when reading/writing binary " \
+                             "files."
+
+    from spatialdata.geocoords.CSCart import CSCart
+    coordsys = pyre.inventory.facility("coordsys", family="coordsys",
+                                       factory=CSCart)
+    coordsys.meta['tip'] = "Coordinate system associated with mesh."
+  
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="meshiogmv"):
+    """
+    Constructor.
+    """
+    MeshIO.__init__(self, name)
+    import pylith.meshio.meshio as bindings
+    self.cppHandle = bindings.MeshIOLagrit()
+    return
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Set members based using inventory.
+    """
+    MeshIO._configure(self)
+    self.filenameGmv = self.inventory.filenameGmv
+    self.filenamePset = self.inventory.filenamePset
+    self.coordsys = self.inventory.coordsys
+    return
+
+
+  def _sync(self):
+    """
+    Force synchronization between Python and C++.
+    """
+    MeshIO._sync(self)
+    self.cppHandle.filenameGmv = self.filenameGmv
+    self.cppHandle.filenamePset = self.filenamePset
+    return
+  
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def mesh_io():
+  """
+  Factory associated with MeshIOLagrit.
+  """
+  return MeshIOLagrit()
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/pylith/meshio/__init__.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/__init__.py	2007-05-03 00:05:55 UTC (rev 6760)
+++ short/3D/PyLith/trunk/pylith/meshio/__init__.py	2007-05-03 02:56:55 UTC (rev 6761)
@@ -15,7 +15,8 @@
 ## @brief Python PyLith meshio module initialization
 
 __all__ = ['MeshIO',
-           'MeshIOAscii']
+           'MeshIOAscii',
+           'MeshIOLagrit']
 
 
 # End of file



More information about the cig-commits mailing list