[cig-commits] r8645 - in short/3D/PyLith/trunk: libsrc
libsrc/meshio pylith/meshio
brad at geodynamics.org
brad at geodynamics.org
Thu Dec 13 16:07:09 PST 2007
Author: brad
Date: 2007-12-13 16:07:09 -0800 (Thu, 13 Dec 2007)
New Revision: 8645
Added:
short/3D/PyLith/trunk/libsrc/meshio/DataWriter.cc
short/3D/PyLith/trunk/libsrc/meshio/DataWriter.hh
short/3D/PyLith/trunk/pylith/meshio/DataWriter.py
short/3D/PyLith/trunk/pylith/meshio/DataWriterVTK.py
short/3D/PyLith/trunk/pylith/meshio/OutputManager.py
Modified:
short/3D/PyLith/trunk/libsrc/Makefile.am
short/3D/PyLith/trunk/libsrc/meshio/Makefile.am
Log:
Started reorganizing output.
Modified: short/3D/PyLith/trunk/libsrc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/Makefile.am 2007-12-13 18:56:23 UTC (rev 8644)
+++ short/3D/PyLith/trunk/libsrc/Makefile.am 2007-12-14 00:07:09 UTC (rev 8645)
@@ -69,6 +69,7 @@
materials/ElasticPlaneStress.cc \
materials/MaxwellIsotropic3D.cc \
meshio/BinaryIO.cc \
+ meshio/DataWriter.cc \
meshio/GMVFile.cc \
meshio/GMVFileAscii.cc \
meshio/GMVFileBinary.cc \
Added: short/3D/PyLith/trunk/libsrc/meshio/DataWriter.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/DataWriter.cc 2007-12-13 18:56:23 UTC (rev 8644)
+++ short/3D/PyLith/trunk/libsrc/meshio/DataWriter.cc 2007-12-14 00:07:09 UTC (rev 8645)
@@ -0,0 +1,75 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "DataWriter.hh" // implementation of class methods
+
+#include "spatialdata/geocoords/CoordSys.hh" // USES CoordSys
+
+// ----------------------------------------------------------------------
+// Constructor
+pylith::meshio::DataWriter::DataWriter(void) :
+ _cs(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+pylith::meshio::DataWriter::~DataWriter(void)
+{ // destructor
+ delete _cs; _cs = 0;
+} // destructor
+
+// ----------------------------------------------------------------------
+// Set coordinate system for output.
+void
+pylith::meshio::DataWriter::coordsys(const spatialdata::geocoords::CoordSys* cs)
+{ // coordsys
+ delete _cs; _cs = (0 != cs) ? cs->clone() : 0;
+} // coordsys
+
+// ----------------------------------------------------------------------
+// Prepare for writing files.
+void
+pylith::meshio::DataWriter::open(
+ const ALE::Obj<ALE::Mesh>& mesh,
+ const spatialdata::geocoords::CoordSys* csMesh)
+{ // open
+} // open
+
+// ----------------------------------------------------------------------
+// Close output files.
+void
+pylith::meshio::DataWriter::close(void)
+{ // close
+} // close
+
+// ----------------------------------------------------------------------
+// Prepare file for data at a new time step.
+void
+pylith::meshio::DataWriter::openTimeStep(
+ const double t,
+ const ALE::Obj<ALE::Mesh>& mesh,
+ const spatialdata::geocoords::CoordSys* csMesh)
+{ // openTimeStep
+} // openTimeStep
+
+// ----------------------------------------------------------------------
+/// Cleanup after writing data for a time step.
+void
+pylith::meshio::DataWriter::closeTimeStep(void)
+{ // closeTimeStep
+} // closeTimeStep
+
+
+// End of file
Added: short/3D/PyLith/trunk/libsrc/meshio/DataWriter.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/DataWriter.hh 2007-12-13 18:56:23 UTC (rev 8644)
+++ short/3D/PyLith/trunk/libsrc/meshio/DataWriter.hh 2007-12-14 00:07:09 UTC (rev 8645)
@@ -0,0 +1,119 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file pylith/meshio/DataWriter.hh
+ *
+ * @brief Abstract base class for writing finite-element data to file.
+ */
+
+#if !defined(pylith_meshio_datawriter_hh)
+#define pylith_meshio_datawriter_hh
+
+#include "pylith/utils/sievetypes.hh" // USES ALE::Obj, ALE::Mesh, real_section_type
+
+namespace pylith {
+ namespace meshio {
+ class DataWriter;
+ } // meshio
+} // pylith
+
+namespace spatialdata {
+ namespace geocoords {
+ class CoordSys; // HOLDSA CoordSys
+ } // geocoords
+} // spatialdata
+
+class pylith::meshio::DataWriter
+{ // DataWriter
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+ /// Constructor
+ DataWriter(void);
+
+ /// Destructor
+ virtual
+ ~DataWriter(void);
+
+ /** Set coordinate system for output.
+ *
+ * @param cs Coordinate system
+ */
+ void coordsys(const spatialdata::geocoords::CoordSys* cs);
+
+ /** Prepare for writing files.
+ *
+ * @param mesh PETSc mesh object
+ * @param csMesh Coordinate system of mesh geometry
+ */
+ virtual
+ void open(const ALE::Obj<ALE::Mesh>& mesh,
+ const spatialdata::geocoords::CoordSys* csMesh);
+
+ /// Close output files.
+ virtual
+ void close(void);
+
+ /** 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
+ */
+ virtual
+ void openTimeStep(const double t,
+ const ALE::Obj<ALE::Mesh>& mesh,
+ const spatialdata::geocoords::CoordSys* csMesh);
+
+ /// Cleanup after writing data for a time step.
+ virtual
+ 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.
+ */
+ virtual
+ void writeVertexField(const double t,
+ const ALE::Obj<real_section_type>& field,
+ const char* name,
+ const ALE::Obj<ALE::Mesh>& mesh) = 0;
+
+ /** Write field over cells to file.
+ *
+ * @param t Time associated with field.
+ * @param field PETSc field over cells.
+ * @param name Name of field.
+ * @param mesh PETSc mesh object.
+ */
+ virtual
+ void writeCellField(const double t,
+ const ALE::Obj<real_section_type>& field,
+ const char* name,
+ const ALE::Obj<ALE::Mesh>& mesh) = 0;
+
+// PROTECTED MEMBERS ////////////////////////////////////////////////////
+public :
+
+ spatialdata::geocoords::CoordSys* _cs; ///< Coordinate system for output
+
+}; // DataWriter
+
+#endif // pylith_meshio_datawriter_hh
+
+
+// End of file
Modified: short/3D/PyLith/trunk/libsrc/meshio/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/Makefile.am 2007-12-13 18:56:23 UTC (rev 8644)
+++ short/3D/PyLith/trunk/libsrc/meshio/Makefile.am 2007-12-14 00:07:09 UTC (rev 8645)
@@ -14,6 +14,7 @@
include $(top_srcdir)/subpackage.am
subpkginclude_HEADERS = \
+ DataWriter.hh \
MeshIO.hh \
MeshIO.icc \
MeshIOAscii.hh \
Added: short/3D/PyLith/trunk/pylith/meshio/DataWriter.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/DataWriter.py 2007-12-13 18:56:23 UTC (rev 8644)
+++ short/3D/PyLith/trunk/pylith/meshio/DataWriter.py 2007-12-14 00:07:09 UTC (rev 8645)
@@ -0,0 +1,104 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pyre/meshio/DataWriter.py
+##
+## @brief Python abstract base class for writing finite-element data.
+##
+## Factory: output_data_writer
+
+from pyre.components.Component import Component
+
+# DataWriter class
+class DataWriter(Component):
+ """
+ Python abstract base class for writing finite-element data.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(Component.Inventory):
+ """
+ Python object for managing DataWriter facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing DataWriter facilities and properties.
+ ##
+ ## \b Properties
+ ## @li None
+ ##
+ ## \b Facilities
+ ## @li \b coordsys Coordinate system for output.
+
+ import pyre.inventory
+
+ from spatialdata.geocoords.CSCart import CSCart
+ coordsys = pyre.inventory.facility("coordsys", family="coordsys",
+ factory=CSCart)
+ coordsys.meta['tip'] = "Coordinate system for output."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="datawriter"):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name, facility="datawriter")
+ self.cppHandle = None
+ self.coordsys = None
+ self.mesh = None
+ return
+
+
+ def verifyConfiguration(self):
+ """
+ Verify compatibility of configuration.
+ """
+ return
+
+
+ def initialize(self):
+ """
+ Initialize writer.
+ """
+ self._createCppHandle()
+
+ # Initialize coordinate system
+ if self.coordsys is None:
+ raise ValueError, "Coordinate system for output is unknown."
+ self.coordsys.initialize()
+ self.cppHandle.coordsys = self.coordsys
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ Component._configure(self)
+ self.coordsys = self.inventory.coordsys
+ return
+
+
+ def _createCppHandle(self):
+ """
+ Create handle to corresponding C++ object.
+ """
+ raise NotImplementedError("Please implement _createCppHandle() in " \
+ "derived class.")
+
+
+# End of file
Added: short/3D/PyLith/trunk/pylith/meshio/DataWriterVTK.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/DataWriterVTK.py 2007-12-13 18:56:23 UTC (rev 8644)
+++ short/3D/PyLith/trunk/pylith/meshio/DataWriterVTK.py 2007-12-14 00:07:09 UTC (rev 8645)
@@ -0,0 +1,106 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pyre/meshio/DataWriterVTK.py
+##
+## @brief Python object for writing finite-element data to VTK file.
+##
+## Factory: output_data_writer
+
+from DataWriter import DataWriter
+
+# DataWriterVTK class
+class DataWriterVTK(DataWriter):
+ """
+ Python object for writing finite-element data to VTK file.
+
+ Factory: output_data_writer
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(DataWriter.Inventory):
+ """
+ Python object for managing DataWriterVTK facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing DataWriterVTK facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b filename Name of VTK file.
+ ## @li \b timeFormat C style format string for time stamp in filename.
+ ##
+ ## \b Facilities
+ ## @li None
+
+ import pyre.inventory
+
+ filename = pyre.inventory.str("filename", default="output.vtk")
+ filename.meta['tip'] = "Name of VTK file."
+
+ timeFormat = pyre.inventory.str("time_format", default="%f")
+ timeFormat.meta['tip'] = "C style format string for time stamp in filename."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="solutioniovtk"):
+ """
+ Constructor.
+ """
+ DataWriter.__init__(self, name)
+ return
+
+
+ def initialize(self):
+ """
+ Initialize writer.
+ """
+ DataWriter.initialize(self)
+ self.cppHandle.filename = self.filename
+ self.cppHandle.timeFormat = self.timeFormat
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ DataWriter._configure(self)
+ self.filename = self.inventory.filename
+ self.timeFormat = self.inventory.timeFormat
+ return
+
+
+ def _createCppHandle(self):
+ """
+ Create handle to corresponding C++ object.
+ """
+ if None == self.cppHandle:
+ import pylith.meshio.meshio as bindings
+ self.cppHandle = bindings.DataWriterVTK()
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def output_data_writer():
+ """
+ Factory associated with DataWriterVTK.
+ """
+ return DataWriterVTK()
+
+
+# End of file
Added: short/3D/PyLith/trunk/pylith/meshio/OutputManager.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/OutputManager.py 2007-12-13 18:56:23 UTC (rev 8644)
+++ short/3D/PyLith/trunk/pylith/meshio/OutputManager.py 2007-12-14 00:07:09 UTC (rev 8645)
@@ -0,0 +1,213 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pyre/meshio/OutputManager.py
+##
+## @brief Python abstract base class for managing output of
+## finite-element information.
+##
+## Factory: output_manager
+
+from pyre.components.Component import Component
+
+# OutputManager class
+class OutputManager(Component):
+ """
+ Python abstract base class for managing output of finite-element
+ information.
+
+ Factory: output_manager
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(Component.Inventory):
+ """
+ Python object for managing OutputManager facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing OutputManager facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b vertex_fields Fields of vertex data to output.
+ ## @li \b cell_fields Fields of cell data to output.
+ ## @li \b output_freq Flag indicating whether to use 'time_step' or 'skip'
+ ## to set frequency of solution output.
+ ## @li \b time_step Time step between solution output.
+ ## @li \b skip Number of time steps to skip between solution output.
+ ##
+ ## \b Facilities
+ ## @li \b writer Writer for data.
+ ## @li \b vertex_filter Filter for vertex data.
+ ## @li \b cell_filter Filter for cell data.
+
+ import pyre.inventory
+
+ vertexFields = pyre.inventory.list("vertex_fields", default=[])
+ vertexFields.meta['tip'] = "Fields of vertex data to output."
+
+ cellFields = pyre.inventory.list("cell_fields", default=[])
+ cellFields.meta['tip'] = "Fields of cell data to output."
+
+ writer = pyre.inventory.facility("writer", factory=DataWriterVTK,
+ family="data_writer")
+ writer.meta['tip'] = "Writer for data."
+
+ vertexFilter = pyre.inventory.facility("vertex_filter",
+ factory=DataVertexFilter,
+ family="output_vertex_filter")
+ vertexFilter.meta['tip'] = "Filter for vertex data."
+
+ cellFilter = pyre.inventory.facility("cell_filter",
+ factory=DataCellFilter,
+ family="output_cell_filter")
+ cellFilter.meta['tip'] = "Filter for cell data."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="outputmanager"):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name, facility="outputmanager")
+ self._loggingPrefix = "OutM "
+ self._t = None
+ self._istep = None
+ self.cppHandle = None
+ return
+
+
+ def verifyConfiguration(self):
+ """
+ Verify compatibility of configuration.
+ """
+ return
+
+
+ def open(self, mesh):
+ self._setupLogging()
+ logEvent = "%sopen" % self._loggingPrefix
+ self._logger.eventBegin(logEvent)
+
+ self.mesh = mesh # Keep handle to mesh
+ self._sync()
+
+ assert(None != self.cppHandle)
+ assert(None != mesh.cppHandle)
+ assert(None != mesh.coordsys.cppHandle)
+ self.cppHandle.open(mesh.cppHandle, mesh.coordsys.cppHandle)
+
+ self._logger.eventEnd(logEvent)
+ return
+
+
+ def close(self):
+ logEvent = "%sclose" % self._loggingPrefix
+ self._logger.eventBegin(logEvent)
+
+ assert(None != self.cppHandle)
+ self.cppHandle.close()
+
+ self._logger.eventEnd(logEvent)
+ return
+
+
+ def writeFields(self, t, istep, fields=None):
+ logEvent = "%swriteVertex" % self._loggingPrefix
+ self._logger.eventBegin(logEvent)
+
+ write = False
+ if self.istep == None or not "value" in dir(self._t):
+ write = True
+ elif self.outputFreq == "skip":
+ if istep > self._istep + self.skip:
+ write = True
+ elif t >= self._t + self._dt:
+ write = True
+ if write:
+ self._info.log("Writing fields.")
+ assert(None != self.cppHandle)
+ assert(None != mesh.cppHandle)
+ assert(None != mesh.coordsys.cppHandle)
+ self.cppHandle.writeFields(t, fields,
+ self.mesh.cppHandle,
+ self.mesh.coordsys.cppHandle)
+ self._istep = istep
+ self._t = t
+
+ self._logger.eventEnd(logEvent)
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ Component._configure(self)
+ self.vertexFields = self.inventory.vertexFields
+ self.cellFields = self.inventory.cellFields
+ self.writer = self.inventory.writer
+ self.vertexFilter = self.inventory.vertexFilter
+ self.cellFilter = self.inventory.cellFilter
+ return
+
+
+ def _sync(self):
+ """
+ Force synchronization between Python and C++.
+ """
+ if None == self.cppHandle:
+ import pylith.meshio.meshio as bindings
+ self.cppHandle = bindings.OutputManager()
+ self.cppHandle.vertexFields = self.vertexFields
+ self.cppHandle.cellFields = self.cellFields
+ self.cppHandle.vertexFilter = self.vertexFilter
+ self.cppHandle.cellFilter = self.cellFilter
+ return
+
+
+ def _setupLogging(self):
+ """
+ Setup event logging.
+ """
+ if not "_loggingPrefix" in dir(self):
+ self._loggingPrefix = ""
+
+ from pylith.utils.EventLogger import EventLogger
+ logger = EventLogger()
+ logger.setClassName("FE Output")
+ logger.initialize()
+
+ events = ["open",
+ "close",
+ "writeFields"]
+ for event in events:
+ logger.registerEvent("%s%s" % (self._loggingPrefix, event))
+
+ self._logger = logger
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def output_manager():
+ """
+ Factory associated with OutputManager.
+ """
+ return OutputManager()
+
+
+# End of file
More information about the cig-commits
mailing list