[cig-commits] r8648 - short/3D/PyLith/trunk/libsrc/meshio
brad at geodynamics.org
brad at geodynamics.org
Fri Dec 14 19:11:03 PST 2007
Author: brad
Date: 2007-12-14 19:11:02 -0800 (Fri, 14 Dec 2007)
New Revision: 8648
Added:
short/3D/PyLith/trunk/libsrc/meshio/DataWriterVTK.cc
short/3D/PyLith/trunk/libsrc/meshio/DataWriterVTK.hh
short/3D/PyLith/trunk/libsrc/meshio/DataWriterVTK.icc
short/3D/PyLith/trunk/libsrc/meshio/OutputManager.cc
short/3D/PyLith/trunk/libsrc/meshio/OutputManager.hh
Log:
Added missing headers.
Added: short/3D/PyLith/trunk/libsrc/meshio/DataWriterVTK.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/DataWriterVTK.cc 2007-12-14 15:59:18 UTC (rev 8647)
+++ short/3D/PyLith/trunk/libsrc/meshio/DataWriterVTK.cc 2007-12-15 03:11:02 UTC (rev 8648)
@@ -0,0 +1,174 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "DataWriterVTK.hh" // implementation of class methods
+
+#include <petscmesh_viewers.hh> // USES VTKViewer
+#include <assert.h> // USES assert()
+#include <sstream> // USES std::ostringstream
+#include <stdexcept> // USES std::runtime_error
+
+// ----------------------------------------------------------------------
+// Constructor
+pylith::meshio::DataWriterVTK::DataWriterVTK(void) :
+ _filename("output.vtk"),
+ _timeFormat("%f"),
+ _viewer(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+pylith::meshio::DataWriterVTK::~DataWriterVTK(void)
+{ // destructor
+ if (0 != _viewer)
+ PetscViewerDestroy(_viewer);
+ _viewer = 0;
+} // destructor
+
+// ----------------------------------------------------------------------
+// Prepare file for data at a new time step.
+void
+pylith::meshio::DataWriterVTK::openTimeStep(
+ const double t,
+ const ALE::Obj<ALE::Mesh>& mesh,
+ const spatialdata::geocoords::CoordSys* csMesh)
+{ // openTimeStep
+ try {
+ PetscErrorCode err;
+
+ std::ostringstream buffer;
+ const int indexExt = _filename.find(".vtk");
+ char sbuffer[256];
+ sprintf(sbuffer, _timeFormat.c_str(), t);
+ std::string timestamp(sbuffer);
+
+ const int pos = timestamp.find(".");
+ if (pos != timestamp.length())
+ timestamp.erase(pos, 1);
+ buffer
+ << std::string(_filename, 0, indexExt) << "_t" << timestamp << ".vtk";
+
+ err = PetscViewerCreate(mesh->comm(), &_viewer);
+ err = PetscViewerSetType(_viewer, PETSC_VIEWER_ASCII);
+ err = PetscViewerSetFormat(_viewer, PETSC_VIEWER_ASCII_VTK);
+ err = PetscViewerFileSetName(_viewer, buffer.str().c_str());
+ if (err)
+ throw std::runtime_error("Could not open VTK file.");
+
+ err = VTKViewer::writeHeader(_viewer);
+ err = VTKViewer::writeVertices(mesh, _viewer);
+ err = VTKViewer::writeElements(mesh, _viewer);
+ if (err)
+ throw std::runtime_error("Could not write topology.");
+ } catch (const std::exception& err) {
+ std::ostringstream msg;
+ msg << "Error while preparing for writing data to VTK file "
+ << _filename << " at time " << t << ".\n" << err.what();
+ throw std::runtime_error(msg.str());
+ } catch (...) {
+ std::ostringstream msg;
+ msg << "Unknown error while preparing for writing data to VTK file "
+ << _filename << " at time " << t << ".\n";
+ throw std::runtime_error(msg.str());
+ } // try/catch
+} // openTimeStep
+
+// ----------------------------------------------------------------------
+/// Cleanup after writing data for a time step.
+void
+pylith::meshio::DataWriterVTK::closeTimeStep(void)
+{ // closeTimeStep
+ PetscViewerDestroy(_viewer);
+} // closeTimeStep
+
+// ----------------------------------------------------------------------
+// Write field over vertices to file.
+void
+pylith::meshio::DataWriterVTK::writeVertexField(
+ const double t,
+ const ALE::Obj<real_section_type>& field,
+ const char* name,
+ const ALE::Obj<ALE::Mesh>& mesh)
+{ // writeVertexField
+ try {
+ std::ostringstream buffer;
+ buffer.str("");
+ char timestamp[256];
+ sprintf(timestamp, _timeFormat.c_str(), t);
+ buffer << name << "_t" << timestamp;
+
+ // Now we are enforcing a 3D solution
+ // Perhaps we need to push this argument higher
+ const int spaceDim = 3;
+ PetscErrorCode err = SectionView_Sieve_Ascii(mesh, field,
+ buffer.str().c_str(),
+ _viewer, spaceDim);
+ if (err)
+ throw std::runtime_error("Could not write vertex data.");
+ } catch (const std::exception& err) {
+ std::ostringstream msg;
+ msg << "Error while writing field '" << name << "' at time "
+ << t << " to VTK file '" << _filename << "'.\n" << err.what();
+ throw std::runtime_error(msg.str());
+ } catch (...) {
+ std::ostringstream msg;
+ msg << "Error while writing field '" << name << "' at time "
+ << t << " to VTK file '" << _filename << "'.\n";
+ throw std::runtime_error(msg.str());
+ } // try/catch
+} // writeVertexField
+
+// ----------------------------------------------------------------------
+// Write field over cells to file.
+void
+pylith::meshio::DataWriterVTK::writeCellField(
+ const double t,
+ const ALE::Obj<real_section_type>& field,
+ const char* name,
+ const ALE::Obj<ALE::Mesh>& mesh)
+{ // writeCellField
+ try {
+ PetscErrorCode err = 0;
+
+ std::ostringstream buffer;
+ buffer.str("");
+ char timestamp[256];
+ sprintf(timestamp, _timeFormat.c_str(), t);
+ buffer << name << "_t" << timestamp;
+
+ err = PetscViewerPushFormat(_viewer, PETSC_VIEWER_ASCII_VTK_CELL);
+
+ // Get fiber dimension of first cell
+ const ALE::Obj<Mesh::label_sequence>& cells = mesh->heightStratum(0);
+ const int fiberDim = field->getFiberDimension(*cells->begin());
+ err = SectionView_Sieve_Ascii(mesh, field, buffer.str().c_str(),
+ _viewer, fiberDim);
+ if (err)
+ throw std::runtime_error("Could not write cell data.");
+ } catch (const std::exception& err) {
+ std::ostringstream msg;
+ msg << "Error while writing field '" << name << "' at time "
+ << t << " to VTK file '" << _filename << "'.\n" << err.what();
+ throw std::runtime_error(msg.str());
+ } catch (...) {
+ std::ostringstream msg;
+ msg << "Error while writing field '" << name << "' at time "
+ << t << " to VTK file '" << _filename << "'.\n";
+ throw std::runtime_error(msg.str());
+ } // try/catch
+} // writeCellField
+
+
+// End of file
Added: short/3D/PyLith/trunk/libsrc/meshio/DataWriterVTK.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/DataWriterVTK.hh 2007-12-14 15:59:18 UTC (rev 8647)
+++ short/3D/PyLith/trunk/libsrc/meshio/DataWriterVTK.hh 2007-12-15 03:11:02 UTC (rev 8648)
@@ -0,0 +1,106 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file pylith/meshio/DataWriterVTK.hh
+ *
+ * @brief Abstract base class for writing finite-element data to file.
+ */
+
+#if !defined(pylith_meshio_datawritervtk_hh)
+#define pylith_meshio_datawritervtk_hh
+
+#include "DataWriter.hh" // ISA DataWriter
+
+namespace pylith {
+ namespace meshio {
+ class DataWriterVTK;
+ } // meshio
+} // pylith
+
+class pylith::meshio::DataWriterVTK : public DataWriter
+{ // DataWriterVTK
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+ /// Constructor
+ DataWriterVTK(void);
+
+ /// Destructor
+ ~DataWriterVTK(void);
+
+ /** Set filename for VTK file.
+ *
+ * @param filename Name of VTK file.
+ */
+ void filename(const char* filename);
+
+ /** Set time format for time stamp in name of VTK file.
+ *
+ * @param format C style time format for filename.
+ */
+ void timeFormat(const char* format);
+
+ /** Prepare file for data at a new time step.
+ *
+ * @param t Time stamp for new data
+ * @param mesh PETSc mesh object
+ * @param csMesh Coordinate system of mesh geometry
+ */
+ 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 field PETSc field over vertices.
+ * @param mesh Finite-element mesh
+ * @param name Name of field.
+ */
+ void writeVertexField(const double t,
+ 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 field PETSc field over cells.
+ * @param name Name of field.
+ * @param mesh PETSc mesh object.
+ */
+ void writeCellField(const double t,
+ const ALE::Obj<real_section_type>& field,
+ const char* name,
+ const ALE::Obj<ALE::Mesh>& mesh);
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+ std::string _filename; ///< Name of VTK file.
+ std::string _timeFormat; ///< C style time format for time stamp.
+
+ PetscViewer _viewer; ///< Output file
+
+}; // DataWriterVTK
+
+#include "DataWriterVTK.icc" // inline methods
+
+#endif // pylith_meshio_datawritervtk_hh
+
+
+// End of file
Added: short/3D/PyLith/trunk/libsrc/meshio/DataWriterVTK.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/DataWriterVTK.icc 2007-12-14 15:59:18 UTC (rev 8647)
+++ short/3D/PyLith/trunk/libsrc/meshio/DataWriterVTK.icc 2007-12-15 03:11:02 UTC (rev 8648)
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_meshio_datawritervtk_hh)
+#error "DataWriterVTK.icc must be included only from DataWriterVTK.hh"
+#else
+
+// Set filename for VTK file.
+inline
+void
+pylith::meshio::DataWriterVTK::filename(const char* filename) {
+ _filename = filename;
+}
+
+// Set time format for time stamp in name of VTK file.
+inline
+void
+pylith::meshio::DataWriterVTK::timeFormat(const char* format) {
+ _timeFormat = format;
+}
+
+
+#endif
+
+// End of file
Added: short/3D/PyLith/trunk/libsrc/meshio/OutputManager.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/OutputManager.cc 2007-12-14 15:59:18 UTC (rev 8647)
+++ short/3D/PyLith/trunk/libsrc/meshio/OutputManager.cc 2007-12-15 03:11:02 UTC (rev 8648)
@@ -0,0 +1,162 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "OutputManager.hh" // implementation of class methods
+
+#include "DataWriter.hh" // HOLDSA DataWriter
+#if 0 // TEMPORARY
+#include "VertexFilter.hh" // HOLDS VertexFilter
+#include "CellFilter.hh" // HOLDS CellFilter
+#endif // TEMPORARY
+
+// ----------------------------------------------------------------------
+// Constructor
+pylith::meshio::OutputManager::OutputManager(void) :
+ _writer(0),
+ _vertexFilter(0),
+ _cellFilter(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+pylith::meshio::OutputManager::~OutputManager(void)
+{ // destructor
+ delete _writer; _writer = 0;
+#if 0 // TEMPORARY
+ delete _vertexFilter; _vertexFilter = 0;
+ delete _cellFilter; _cellFilter = 0;
+#endif // TEMPORARY
+} // destructor
+
+// ----------------------------------------------------------------------
+// Set which vertex fields to output.
+void
+pylith::meshio::OutputManager::vertexFields(const char** names,
+ const int nfields)
+{ // vertexFields
+ _vertexFields.resize(nfields);
+ for (int i=0; i < nfields; ++i)
+ _vertexFields[i] = names[i];
+} // vertexFields
+
+// ----------------------------------------------------------------------
+// Set which cell fields to output.
+void
+pylith::meshio::OutputManager::cellFields(const char** names,
+ const int nfields)
+{ // cellFields
+ _cellFields.resize(nfields);
+ for (int i=0; i < nfields; ++i)
+ _cellFields[i] = names[i];
+} // cellFields
+
+// ----------------------------------------------------------------------
+// Set filter for vertex data.
+void
+pylith::meshio::OutputManager::vertexFilter(const VertexFilter* filter)
+{ // vertexFilter
+#if 0 // TEMPORARY
+ delete _vertexFilter; _vertexFilter = (0 != filter) ? filter->clone() : 0;
+#endif // TEMPORARY
+} // vertexFilter
+
+// ----------------------------------------------------------------------
+// Set filter for cell data.
+void
+pylith::meshio::OutputManager::cellFilter(const CellFilter* filter)
+{ // cellFilter
+#if 0 // TEMPORARY
+ delete _cellFilter; _cellFilter = (0 != filter) ? filter->clone() : 0;
+#endif // TEMPORARY
+} // cellFilter
+
+// ----------------------------------------------------------------------
+// Prepare for output.
+void
+pylith::meshio::OutputManager::open(
+ const ALE::Obj<ALE::Mesh>& mesh,
+ const spatialdata::geocoords::CoordSys* csMesh)
+{ // open
+ assert(0 != _writer);
+
+ _writer->open(mesh, csMesh);
+} // open
+
+// ----------------------------------------------------------------------
+/// Close output files.
+void
+pylith::meshio::OutputManager::close(void)
+{ // close
+ assert(0 != _writer);
+ _writer->close();
+} // close
+
+// ----------------------------------------------------------------------
+// Write finite-element fields to file.
+void
+pylith::meshio::OutputManager::writeFields(
+ const double t,
+ const topology::FieldsManager* fields,
+ const ALE::Obj<ALE::Mesh>& mesh,
+ const spatialdata::geocoords::CoordSys* csMesh)
+{ // writeFields
+ assert(0 != _writer);
+ _writer->openTimeStep(t, mesh, csMesh);
+
+ const int nvfields = _vertexFields.size();
+ for (int i=0; i < nvfields; ++i) {
+ // Try to get field from mesh
+ if (1) {
+ // ADD STUFF HERE
+ } else if (0 != fields) {
+ // If field is not in mesh, try to get it from fields manager
+ // ADD STUFF HERE
+ } // else
+
+ // Extract values from section
+ // ADD STUFF HERE
+
+ if (0 != _vertexFilter) {
+ // Apply vertex filter
+ // ADD STUFF HERE
+ } // if
+ //_writer->writeVertexField(t, data, _vertexFields[i], mesh);
+ } // for
+
+ const int ncfields = _cellFields.size();
+ for (int i=0; i < ncfields; ++i) {
+ // Try to get field from mesh
+ if (1) {
+ // ADD STUFF HERE
+ } else if (0 != fields) {
+ // If field is not in mesh, try to get it from fields manager
+ // ADD STUFF HERE
+ } // else
+
+ // Extract values from section
+ // ADD STUFF HERE
+
+ if (0 != _cellFilter) {
+ // Apply vertex filter
+ // ADD STUFF HERE
+ } // if
+ //_writer->writeCellField(t, data, _cellFields[i], mesh);
+ } // for
+
+ _writer->closeTimeStep();
+} // writeFields
+
+
+// End of file
Added: short/3D/PyLith/trunk/libsrc/meshio/OutputManager.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/OutputManager.hh 2007-12-14 15:59:18 UTC (rev 8647)
+++ short/3D/PyLith/trunk/libsrc/meshio/OutputManager.hh 2007-12-15 03:11:02 UTC (rev 8648)
@@ -0,0 +1,128 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file pylith/meshio/OutputManager.hh
+ *
+ * @brief C++ object for manager output of finite-element data.
+ */
+
+#if !defined(pylith_meshio_outputmanager_hh)
+#define pylith_meshio_outputmanager_hh
+
+#include "pylith/utils/sievetypes.hh" // USES ALE::Obj, ALE::Mesh, real_section_type
+
+namespace pylith {
+ namespace meshio {
+ class OutputManager;
+
+ class DataWriter; // HOLDS DataWriter
+ class VertexFilter; // HOLDSA VertexFilter
+ class CellFilter; // HOLDSA CellFilter
+ } // meshio
+
+ namespace topology {
+ class FieldsManager; // USES FieldsManager
+ } // topology
+} // pylith
+
+namespace spatialdata {
+ namespace geocoords {
+ class CoordSys; // USES CoordSys
+ } // geocoords
+} // spatialdata
+
+class pylith::meshio::OutputManager
+{ // OutputManager
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+ /// Constructor
+ OutputManager(void);
+
+ /// Destructor
+ ~OutputManager(void);
+
+ /** Set writer to write data to file.
+ *
+ * @param datawriter Writer for data.
+ */
+ void writer(const DataWriter* datawriter);
+
+ /** Set which vertex fields to output.
+ *
+ * @param names Names of fields.
+ * @param nfields Number of fields
+ */
+ void vertexFields(const char** names,
+ const int nfields);
+
+ /** Set which cell fields to output.
+ *
+ * @param names Names of fields.
+ * @param nfields Number of fields
+ */
+ void cellFields(const char** names,
+ const int nfields);
+
+ /** Set filter for vertex data.
+ *
+ * @param filter Filter to apply to vertex data before writing.
+ */
+ void vertexFilter(const VertexFilter* filter);
+
+ /** Set filter for cell data.
+ *
+ * @param filter Filter to apply to cell data before writing.
+ */
+ void cellFilter(const CellFilter* filter);
+
+ /** Prepare for output.
+ *
+ * @param mesh PETSc mesh object
+ * @param csMesh Coordinate system of mesh geometry
+ */
+ void open(const ALE::Obj<ALE::Mesh>& mesh,
+ const spatialdata::geocoords::CoordSys* csMesh);
+
+ /// Close output files.
+ void close(void);
+
+ /** Write finite-element fields to file.
+ *
+ * @param t Time associated with field.
+ * @param fields Fields manager.
+ * @param mesh PETSc mesh object.
+ * @param csMesh Coordinate system of mesh geometry
+ */
+ void writeFields(const double t,
+ const topology::FieldsManager* fields,
+ const ALE::Obj<ALE::Mesh>& mesh,
+ const spatialdata::geocoords::CoordSys* csMesh);
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+
+private :
+
+ std::vector<std::string> _vertexFields; ///< Names of vertex fields to output
+ std::vector<std::string> _cellFields; ///< Names of cell fields to output
+
+ DataWriter* _writer; ///< Writer for data
+ VertexFilter* _vertexFilter; ///< Filter applied to vertex data
+ CellFilter* _cellFilter; ///< Filter applied to cell data
+
+}; // OutputManager
+
+#endif // pylith_meshio_outputmanager_hh
+
+// End of file
More information about the cig-commits
mailing list