[cig-commits] r19102 - in short/3D/PyLith/trunk: libsrc/pylith/meshio pylith pylith/meshio
brad at geodynamics.org
brad at geodynamics.org
Thu Oct 20 12:23:42 PDT 2011
Author: brad
Date: 2011-10-20 12:23:42 -0700 (Thu, 20 Oct 2011)
New Revision: 19102
Added:
short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputSolnPoints.cc
short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputSolnPoints.hh
short/3D/PyLith/trunk/pylith/meshio/DataWriterVTKPoints.py
short/3D/PyLith/trunk/pylith/meshio/OutputSolnPoints.py
short/3D/PyLith/trunk/pylith/meshio/PointsList.py
Modified:
short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputManager.hh
short/3D/PyLith/trunk/pylith/Makefile.am
short/3D/PyLith/trunk/pylith/meshio/__init__.py
Log:
Started work on output at arbitrary points.
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputManager.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputManager.hh 2011-10-20 17:28:30 UTC (rev 19101)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputManager.hh 2011-10-20 19:23:42 UTC (rev 19102)
@@ -91,12 +91,14 @@
* (=0 means use all cells in mesh).
* @param labelId Value of label defining which cells to include.
*/
+ virtual
void open(const mesh_type& mesh,
const int numTimeSteps,
const char* label =0,
const int labelId =0);
/// Close output files.
+ virtual
void close(void);
/** Setup file for writing fields at time step.
@@ -107,12 +109,14 @@
* (=0 means use all cells in mesh).
* @param labelId Value of label defining which cells to include.
*/
+ virtual
void openTimeStep(const PylithScalar t,
const mesh_type& mesh,
const char* label =0,
const int labelId =0);
/// End writing fields at time step.
+ virtual
void closeTimeStep(void);
/** Append finite-element vertex field to file.
@@ -121,6 +125,7 @@
* @param field Vertex field.
* @param mesh Mesh for output.
*/
+ virtual
void appendVertexField(const PylithScalar t,
field_type& field,
const mesh_type& mesh);
@@ -133,6 +138,7 @@
* (=0 means use all cells in mesh).
* @param labelId Value of label defining which cells to include.
*/
+ virtual
void appendCellField(const PylithScalar t,
field_type& field,
const char* label =0,
Added: short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputSolnPoints.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputSolnPoints.cc (rev 0)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputSolnPoints.cc 2011-10-20 19:23:42 UTC (rev 19102)
@@ -0,0 +1,71 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard, U.S. Geological Survey
+// Charles A. Williams, GNS Science
+// Matthew G. Knepley, University of Chicago
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010-2011 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "OutputSolnPoints.hh" // implementation of class methods
+
+#include "pylith/topology/Mesh.hh" // USES Mesh
+
+// ----------------------------------------------------------------------
+// Constructor
+pylith::meshio::OutputSolnPoints::OutputSolnPoints(void) :
+ _mesh(0),
+ _pointsMesh(0),
+ _interpolator(0)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+pylith::meshio::OutputSolnPoints::~OutputSolnPoints(void)
+{ // destructor
+ deallocate();
+} // destructor
+
+// ----------------------------------------------------------------------
+// Deallocate PETSc and local data structures.
+void
+pylith::meshio::OutputSolnPoints::deallocate(void)
+{ // deallocate
+ OutputManager<topology::Mesh, topology::Field<topology::Mesh> >::deallocate();
+
+ if (_interpolator) {
+ assert(_mesh);
+ DMMeshInterpolationDestroy(_mesh->sieveMesh(), _interpolator);
+ delete _interpolater; _interpolator = 0;
+ } // if
+
+ delete _mesh; _mesh = 0;
+ delete _pointsMesh; _pointsMesh = 0;
+} // deallocate
+
+// ----------------------------------------------------------------------
+// Get mesh associated with points.
+const pylith::topology::Mesh&
+pylith::meshio::OutputSolnPoints::createPointsMesh(const PylithScalar* points,
+ const int numPoints,
+ const int spaceDim)
+{ // createPointsMesh
+ // delete _pointsMesh; _pointsMesh = new topology::Mesh();
+ assert(_pointsMesh);
+ return *_pointsMesh;
+} // createPointsMesh
+
+
+// End of file
Added: short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputSolnPoints.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputSolnPoints.hh (rev 0)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputSolnPoints.hh 2011-10-20 19:23:42 UTC (rev 19102)
@@ -0,0 +1,89 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard, U.S. Geological Survey
+// Charles A. Williams, GNS Science
+// Matthew G. Knepley, University of Chicago
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010-2011 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ======================================================================
+//
+
+/**
+ * @file libsrc/meshio/OutputSolnPoints.hh
+ *
+ * @brief C++ object for managing output of finite-element data over a
+ * subdomain.
+ */
+
+#if !defined(pylith_meshio_outputsolnpoints_hh)
+#define pylith_meshio_outputsolnpoints_hh
+
+// Include directives ---------------------------------------------------
+#include "meshiofwd.hh" // forward declarations
+
+#include "pylith/topology/SubMesh.hh" // ISA OutputManager<Mesh>
+#include "pylith/topology/Field.hh" // ISA OutputManager<Field<Mesh>>
+#include "OutputManager.hh" // ISA OutputManager
+
+#include <string> // HASA std::string
+
+// OutputSolnPoints -----------------------------------------------------
+/** @brief C++ object for managing output of finite-element data over
+ * a subdomain.
+ */
+class pylith::meshio::OutputSolnPoints :
+ public OutputManager<topology::Mesh, topology::Field<topology::Mesh> >
+{ // OutputSolnPoints
+ friend class TestOutputSolnPoints; // unit testing
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+ /// Constructor
+ OutputSolnPoints(void);
+
+ /// Destructor
+ ~OutputSolnPoints(void);
+
+ /// Deallocate PETSc and local data structures.
+ void deallocate(void);
+
+ /** Get mesh associated with points.
+ *
+ * @returns Mesh associated with points.
+ */
+ const topology::Mesh& createPointsMesh(const PylithScalar* points,
+ const int numPoints,
+ const int spaceDim);
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+ OutputSolnPoints(const OutputSolnPoints&); ///< Not implemented.
+ const OutputSolnPoints& operator=(const OutputSolnPoints&); ///< Not implemented
+
+// PRIVATE TYPEDEFS /////////////////////////////////////////////////////
+private :
+
+ typedef DMMeshInterpolationInfo PetscDMMeshInterpolationInfo;
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+ topology::Mesh* _mesh; ///< Domain mesh.
+ topology::Mesh* _pointsMesh; ///< Mesh for points (no cells).
+ PetscDMMeshInterpolationInfo* _interpolator;
+
+}; // OutputSolnPoints
+
+#endif // pylith_meshio_outputsolnpoints_hh
+
+// End of file
Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am 2011-10-20 17:28:30 UTC (rev 19101)
+++ short/3D/PyLith/trunk/pylith/Makefile.am 2011-10-20 19:23:42 UTC (rev 19102)
@@ -94,6 +94,7 @@
meshio/DataWriterVTKMesh.py \
meshio/DataWriterVTKSubMesh.py \
meshio/DataWriterVTKSubSubMesh.py \
+ meshio/DataWriterVTKPoints.py \
meshio/MeshIOObj.py \
meshio/MeshIOAscii.py \
meshio/MeshIOLagrit.py \
@@ -108,6 +109,8 @@
meshio/OutputMatElastic.py \
meshio/OutputNeumann.py \
meshio/OutputSolnSubset.py \
+ meshio/OutputSolnPoints.py \
+ meshio/PointsList.py \
meshio/SingleOutput.py \
meshio/VertexFilter.py \
meshio/VertexFilterVecNormMesh.py \
Added: short/3D/PyLith/trunk/pylith/meshio/DataWriterVTKPoints.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/DataWriterVTKPoints.py (rev 0)
+++ short/3D/PyLith/trunk/pylith/meshio/DataWriterVTKPoints.py 2011-10-20 19:23:42 UTC (rev 19102)
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010-2011 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pyre/meshio/DataWriterVTKPoints.py
+##
+## @brief Python object for writing finite-element solution at
+## arbitrary points to VTK file.
+
+from DataWriterVTK import DataWriterVTK
+from meshio import PointsDataWriterVTK as ModuleDataWriterVTK
+
+# DataWriterVTKPoints class
+class DataWriterVTKPoints(DataWriterVTK, ModuleDataWriterVTK):
+ """
+ Python object for writing finite-element data to VTK file.
+
+ Inventory
+
+ Factory: output_data_writer
+ """
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="datawritervtkpoints"):
+ """
+ Constructor.
+ """
+ DataWriterVTK.__init__(self, name)
+ ModuleDataWriterVTK.__init__(self)
+ return
+
+
+ def initialize(self, normalizer):
+ """
+ Initialize writer.
+ """
+ DataWriterVTK.initialize(self, normalizer)
+
+ timeScale = normalizer.timeScale()
+ timeConstantN = normalizer.nondimensionalize(self.timeConstant,
+ timeScale)
+
+ ModuleDataWriterVTK.filename(self, self.filename)
+ ModuleDataWriterVTK.timeScale(self, timeScale.value)
+ ModuleDataWriterVTK.timeFormat(self, self.timeFormat)
+ ModuleDataWriterVTK.timeConstant(self, timeConstantN)
+ ModuleDataWriterVTK.precision(self, self.precision)
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def data_writer():
+ """
+ Factory associated with DataWriter.
+ """
+ return DataWriterVTKPoints()
+
+
+# End of file
Added: short/3D/PyLith/trunk/pylith/meshio/OutputSolnPoints.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/OutputSolnPoints.py (rev 0)
+++ short/3D/PyLith/trunk/pylith/meshio/OutputSolnPoints.py 2011-10-20 19:23:42 UTC (rev 19102)
@@ -0,0 +1,241 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010-2011 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pyre/meshio/OutputSolnPoints.py
+##
+## @brief Python object for managing output of finite-element solution
+## information over a subdomain.
+##
+## Factory: output_manager
+
+from OutputManager import OutputManager
+from meshio import OutputSolnPoints as ModuleOutputSolnPoints
+
+# Validator for filename
+def validateFilename(value):
+ """
+ Validate filename with list of points.
+ """
+ if 0 == len(value):
+ raise ValueError("Filename for list of points not specified.")
+ return value
+
+
+# OutputSolnPoints class
+class OutputSolnPoints(OutputManager, ModuleOutputSolnPoints):
+ """
+ Python object for managing output of finite-element solution
+ information over a subdomain.
+
+ @class Inventory
+ Python object for managing OutputSolnPoints facilities and properties.
+
+ \b Properties
+ @li \b vertex_data_fields Names of vertex data fields to output.
+
+ \b Facilities
+ @li \b reader Reader for list of points.
+ @li \b writer Writer for data.
+
+ Factory: output_manager
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ import pyre.inventory
+
+ vertexDataFields = pyre.inventory.list("vertex_data_fields",
+ default=["displacement"])
+ vertexDataFields.meta['tip'] = "Names of vertex data fields to output."
+
+ from PointsList import PointsList
+ reader = pyre.inventory.facility("reader", factory=PointsList, family="points_list")
+ reader.meta['tip'] = "Reader for points list."
+
+ from DataWriterVTKPoints import DataWriterVTKPoints
+ writer = pyre.inventory.facility("writer", factory=DataWriterVTKPoints,
+ family="data_writer")
+ writer.meta['tip'] = "Writer for data."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="outputsolnpoints"):
+ """
+ Constructor.
+ """
+ OutputManager.__init__(self, name)
+ self.availableFields = \
+ {'vertex': \
+ {'info': [],
+ 'data': ["displacement","velocity"]},
+ 'cell': \
+ {'info': [],
+ 'data': []}}
+ return
+
+
+ def preinitialize(self):
+ """
+ Do
+ """
+ OutputManager.preinitialize(self, dataProvider=self)
+ return
+
+
+ def verifyConfiguration(self, mesh):
+ """
+ Verify compatibility of configuration.
+ """
+ OutputManager.verifyConfiguration(self, mesh)
+ ModuleOutputSolnPoints.verifyConfiguration(self, mesh)
+ return
+
+
+ def initialize(self, mesh, normalizer):
+ """
+ Initialize output manager.
+ """
+ logEvent = "%sinit" % self._loggingPrefix
+ self._eventLogger.eventBegin(logEvent)
+
+ points = self.reader.read()
+ self.mesh = ModuleOutputSolnPoints.createPointsMesh(self, points)
+ OutputManager.initialize(self, normalizer)
+
+ self._eventLogger.eventEnd(logEvent)
+ return
+
+
+ def getDataMesh(self):
+ """
+ Get mesh associated with data fields.
+ """
+ return (self.mesh, None, None)
+
+
+ def getVertexField(self, name, fields):
+ """
+ Get vertex field.
+ """
+ field = None
+ fieldType = None
+ if name == "displacement":
+ field = fields.get("disp(t)")
+ elif name == "velocity":
+ field = fields.get("velocity(t)")
+ else:
+ raise ValueError, "Vertex field '%s' not available." % name
+ return field
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ try:
+ OutputManager._configure(self)
+ ModuleOutputSolnPoints.label(self, self.label)
+ ModuleOutputSolnPoints.coordsys(self, self.inventory.coordsys)
+ ModuleOutputSolnPoints.writer(self, self.inventory.writer)
+ from pylith.utils.NullComponent import NullComponent
+ if not isinstance(self.inventory.vertexFilter, NullComponent):
+ ModuleOutputSolnPoints.vertexFilter(self, self.inventory.vertexFilter)
+ if not isinstance(self.inventory.cellFilter, NullComponent):
+ ModuleOutputSolnPoints.cellFilter(self, self.inventory.cellFilter)
+ except ValueError, err:
+ aliases = ", ".join(self.aliases)
+ raise ValueError("Error while configuring output over points "
+ "(%s):\n%s" % (aliases, err.message))
+
+ return
+
+
+ def _createModuleObj(self):
+ """
+ Create handle to C++ object.
+ """
+ ModuleOutputSolnPoints.__init__(self)
+ return
+
+
+ def _open(self, mesh, nsteps, label, labelId):
+ """
+ Call C++ open();
+ """
+ if label != None and labelId != None:
+ ModuleOutputSolnPoints.open(self, mesh, nsteps, label, labelId)
+ else:
+ ModuleOutputSolnPoints.open(self, mesh, nsteps)
+ return
+
+
+ def _openTimeStep(self, t, mesh, label, labelId):
+ """
+ Call C++ openTimeStep();
+ """
+ if label != None and labelId != None:
+ ModuleOutputSolnPoints.openTimeStep(self, t, mesh, label, labelId)
+ else:
+ ModuleOutputSolnPoints.openTimeStep(self, t, mesh)
+ return
+
+
+ def _appendVertexField(self, t, field, mesh):
+ """
+ Call C++ appendVertexField();
+ """
+ ModuleOutputSolnPoints.appendVertexField(self, t, field, mesh)
+ return
+
+ def _appendCellField(self, t, field):
+ """
+ Call C++ appendCellField();
+ """
+ raise NotImplementedError("Output of cell field not implemented for arbitrary points.")
+ return
+
+
+ def _closeTimeStep(self):
+ """
+ Call C++ closeTimeStep().
+ """
+ ModuleOutputSolnPoints.closeTimeStep(self)
+ return
+
+
+ def _close(self):
+ """
+ Call C++ close().
+ """
+ ModuleOutputSolnPoints.close(self)
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def output_manager():
+ """
+ Factory associated with OutputManager.
+ """
+ return OutputSolnPoints()
+
+
+# End of file
Added: short/3D/PyLith/trunk/pylith/meshio/PointsList.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/PointsList.py (rev 0)
+++ short/3D/PyLith/trunk/pylith/meshio/PointsList.py 2011-10-20 19:23:42 UTC (rev 19102)
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010-2011 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pyre/meshio/PointsList.py
+##
+## @brief Python object for reading list of points from a file.
+##
+## Factory: output_manager
+
+from pyre.components.Component import Component
+
+# Validator for filename
+def validateFilename(value):
+ """
+ Validate filename with list of points.
+ """
+ if 0 == len(value):
+ raise ValueError("Filename for list of points not specified.")
+ return value
+
+
+# PointsList class
+class PointsList(Component):
+ """
+ Python object for reading a list of points from a file.
+
+ @class Inventory
+ Python object for managing PointsList facilities and properties.
+
+ \b Properties
+ @li \b filename Filename for list of points.
+ @li \b comment_delimiter Delimiter for comments.
+ @li \b value_delimiter Delimiter used to separate values.
+
+ \b Facilities
+ @li None
+
+ Factory: points_list
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ import pyre.inventory
+
+ filename = pyre.inventory.str("filename", default="", validator=validateFilename)
+ filename.meta['tip'] = "Filename for list of points."
+
+ commentDelimiter = pyre.inventory.str("comment_delimiter", default="#")
+ commentDelimiter.meta['tip'] = "Delimiter for comments."
+
+ valueDelimiter = pyre.inventory.str("value_delimiter", default="")
+ valueDelimiter.meta['tip'] = "Delimiter used to separate values."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="pointslist"):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name)
+ return
+
+
+ def read(self):
+ """
+ Read points from file.
+ """
+ import numpy
+ if len(self.valueDelimiter) == 0:
+ points = numpy.loadtxt(self.filename, comments=self.commentDelimiter)
+ else:
+ points = numpy.loadtxt(self.filename,
+ comments=self.commentDelimiter, delimiter=self.valueDelimiter)
+ return points
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ try:
+ Component._configure(self)
+ self.filename = self.inventory.filename
+ self.commentDelimiter = self.inventory.commentDelimiter
+ except ValueError, err:
+ aliases = ", ".join(self.aliases)
+ raise ValueError("Error while configuring points list "
+ "(%s):\n%s" % (aliases, err.message))
+
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def points_list():
+ """
+ Factory associated with PointsList.
+ """
+ return PointsList()
+
+
+# End of file
Modified: short/3D/PyLith/trunk/pylith/meshio/__init__.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/__init__.py 2011-10-20 17:28:30 UTC (rev 19101)
+++ short/3D/PyLith/trunk/pylith/meshio/__init__.py 2011-10-20 19:23:42 UTC (rev 19102)
@@ -28,6 +28,7 @@
'DataWriterVTKMesh',
'DataWriterVTKSubMesh',
'DataWriterVTKSubSubMesh',
+ 'DataWriterVTKPoints',
'MeshIOObj',
'MeshIOAscii',
'MeshIOCubit',
@@ -41,6 +42,8 @@
'OutputNeumann'
'OutputSoln',
'OutputSolnSubset',
+ 'OutputSolnPoints',
+ 'PointsList',
'SingleOutput',
'VertexFilter',
'VertexFilterVecNormMesh',
More information about the CIG-COMMITS
mailing list