[cig-commits] r11334 - in short/3D/PyLith/trunk: libsrc libsrc/meshio unittests/libtests/meshio unittests/libtests/meshio/data
brad at geodynamics.org
brad at geodynamics.org
Wed Mar 5 15:13:37 PST 2008
Author: brad
Date: 2008-03-05 15:13:36 -0800 (Wed, 05 Mar 2008)
New Revision: 11334
Added:
short/3D/PyLith/trunk/libsrc/meshio/VertexFilterVecNorm.cc
short/3D/PyLith/trunk/libsrc/meshio/VertexFilterVecNorm.hh
short/3D/PyLith/trunk/unittests/libtests/meshio/TestOutputManager.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/TestOutputManager.hh
short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_cell_filter_t12.vtk
short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_cell_t12.vtk
short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_t12.vtk
short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_vertex_filter_t12.vtk
short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_vertex_t12.vtk
Modified:
short/3D/PyLith/trunk/libsrc/Makefile.am
short/3D/PyLith/trunk/libsrc/meshio/CellFilter.hh
short/3D/PyLith/trunk/libsrc/meshio/CellFilterAvg.cc
short/3D/PyLith/trunk/libsrc/meshio/CellFilterAvg.hh
short/3D/PyLith/trunk/libsrc/meshio/DataWriter.hh
short/3D/PyLith/trunk/libsrc/meshio/Makefile.am
short/3D/PyLith/trunk/libsrc/meshio/OutputManager.cc
short/3D/PyLith/trunk/libsrc/meshio/OutputManager.hh
short/3D/PyLith/trunk/libsrc/meshio/VertexFilter.hh
short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am
short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTK.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTK.hh
short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am
Log:
Added VertexFilterVecNorm (compute vector norm for vertices in vertex field). C++ unit testing of OutputManager. Fixed some bugs in output filters.
Modified: short/3D/PyLith/trunk/libsrc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/Makefile.am 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/libsrc/Makefile.am 2008-03-05 23:13:36 UTC (rev 11334)
@@ -88,6 +88,7 @@
meshio/PsetFileAscii.cc \
meshio/PsetFileBinary.cc \
meshio/VertexFilter.cc \
+ meshio/VertexFilterVecNorm.cc \
topology/FieldsManager.cc \
topology/Distributor.cc \
utils/EventLogger.cc
Modified: short/3D/PyLith/trunk/libsrc/meshio/CellFilter.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/CellFilter.hh 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/libsrc/meshio/CellFilter.hh 2008-03-05 23:13:36 UTC (rev 11334)
@@ -21,6 +21,7 @@
#define pylith_meshio_cellfilter_hh
#include "pylith/utils/sievetypes.hh" // USES ALE::Mesh, real_section_type
+#include "pylith/utils/vectorfields.hh" // USES VectorFieldEnum
namespace pylith {
namespace meshio {
@@ -57,8 +58,9 @@
*/
void quadrature(const feassemble::Quadrature* q);
- /** Filter field.
+ /** Filter field. Field type of filtered field is returned via an argument.
*
+ * @param fieldType Field type of filtered field.
* @param fieldIn Field to filter.
* @param mesh PETSc mesh.
* @param label Label identifying cells.
@@ -68,7 +70,8 @@
*/
virtual
const ALE::Obj<real_section_type>&
- filter(const ALE::Obj<real_section_type>& fieldIn,
+ filter(VectorFieldEnum* fieldType,
+ const ALE::Obj<real_section_type>& fieldIn,
const ALE::Obj<ALE::Mesh>& mesh,
const char* label,
const int labelId) = 0;
Modified: short/3D/PyLith/trunk/libsrc/meshio/CellFilterAvg.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/CellFilterAvg.cc 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/libsrc/meshio/CellFilterAvg.cc 2008-03-05 23:13:36 UTC (rev 11334)
@@ -47,11 +47,13 @@
// Filter field.
const ALE::Obj<pylith::real_section_type>&
pylith::meshio::CellFilterAvg::filter(
+ VectorFieldEnum* fieldType,
const ALE::Obj<real_section_type>& fieldIn,
const ALE::Obj<ALE::Mesh>& mesh,
const char* label,
const int labelId)
{ // filter
+ assert(0 != fieldType);
assert(0 != _quadrature);
const int numQuadPts = _quadrature->numQuadPts();
@@ -67,6 +69,13 @@
const int fiberDim = totalFiberDim / numQuadPts;
assert(fiberDim * numQuadPts == totalFiberDim);
+ if (1 == fiberDim)
+ *fieldType = SCALAR_FIELD;
+ else if (mesh->getDimension() == fiberDim)
+ *fieldType = VECTOR_FIELD;
+ else
+ *fieldType = OTHER_FIELD;
+
// Allocation field if necessary
if (_fieldAvg.isNull() ||
fiberDim != _fieldAvg->getFiberDimension(*cells->begin())) {
Modified: short/3D/PyLith/trunk/libsrc/meshio/CellFilterAvg.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/CellFilterAvg.hh 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/libsrc/meshio/CellFilterAvg.hh 2008-03-05 23:13:36 UTC (rev 11334)
@@ -46,8 +46,9 @@
*/
CellFilter* clone(void) const;
- /** Filter field.
+ /** Filter field. Field type of filtered field is returned via an argument.
*
+ * @param fieldType Field type of filtered field.
* @param fieldIn Field to filter.
* @param mesh PETSc mesh.
* @param label Label identifying cells.
@@ -56,7 +57,8 @@
* @returns Averaged field.
*/
const ALE::Obj<real_section_type>&
- filter(const ALE::Obj<real_section_type>& fieldIn,
+ filter(VectorFieldEnum* fieldType,
+ const ALE::Obj<real_section_type>& fieldIn,
const ALE::Obj<ALE::Mesh>& mesh,
const char* label,
const int labelId);
Modified: short/3D/PyLith/trunk/libsrc/meshio/DataWriter.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/DataWriter.hh 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/libsrc/meshio/DataWriter.hh 2008-03-05 23:13:36 UTC (rev 11334)
@@ -125,7 +125,7 @@
const char* name,
const ALE::Obj<real_section_type>& field,
const VectorFieldEnum fieldType,
- const ALE::Obj<ALE::Mesh>& mesh,
+ const ALE::Obj<ALE::Mesh>& mesh,
const char* label =0,
const int labelId =0) = 0;
Modified: short/3D/PyLith/trunk/libsrc/meshio/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/Makefile.am 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/libsrc/meshio/Makefile.am 2008-03-05 23:13:36 UTC (rev 11334)
@@ -27,7 +27,8 @@
MeshIOLagrit.icc \
OutputManager.hh \
OutputSolnSubset.hh \
- VertexFilter.hh
+ VertexFilter.hh \
+ VertexFilterVecNorm.hh
if ENABLE_CUBIT
subpkginclude_HEADERS += \
Modified: short/3D/PyLith/trunk/libsrc/meshio/OutputManager.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/OutputManager.cc 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/libsrc/meshio/OutputManager.cc 2008-03-05 23:13:36 UTC (rev 11334)
@@ -130,10 +130,12 @@
{ // appendVertexField
assert(0 != name);
+ VectorFieldEnum fieldTypeFiltered = fieldType;
const ALE::Obj<real_section_type>& fieldFiltered =
- (0 == _vertexFilter) ? field : _vertexFilter->filter(field, mesh);
+ (0 == _vertexFilter) ?
+ field : _vertexFilter->filter(&fieldTypeFiltered, field, mesh);
- _writer->writeVertexField(t, name, fieldFiltered, fieldType, mesh);
+ _writer->writeVertexField(t, name, fieldFiltered, fieldTypeFiltered, mesh);
} // appendVertexField
// ----------------------------------------------------------------------
@@ -150,10 +152,14 @@
{ // appendCellField
assert(0 != name);
+ VectorFieldEnum fieldTypeFiltered = fieldType;
const ALE::Obj<real_section_type>& fieldFiltered =
- (0 == _cellFilter) ? field : _cellFilter->filter(field, mesh, label, labelId);
+ (0 == _cellFilter) ?
+ field : _cellFilter->filter(&fieldTypeFiltered, field,
+ mesh, label, labelId);
- _writer->writeCellField(t, name, fieldFiltered, fieldType, mesh, label, labelId);
+ _writer->writeCellField(t, name, fieldFiltered, fieldTypeFiltered,
+ mesh, label, labelId);
} // appendCellField
Modified: short/3D/PyLith/trunk/libsrc/meshio/OutputManager.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/OutputManager.hh 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/libsrc/meshio/OutputManager.hh 2008-03-05 23:13:36 UTC (rev 11334)
@@ -25,6 +25,7 @@
namespace pylith {
namespace meshio {
class OutputManager;
+ class TestOutputManager; // unit testing
class DataWriter; // HOLDS DataWriter
class CellFilter; // HOLDSA CellFilter
@@ -43,6 +44,7 @@
// PUBLIC METHODS ///////////////////////////////////////////////////////
public :
+ friend class TestOutputManager; // unit testing
/// Constructor
OutputManager(void);
@@ -104,8 +106,8 @@
* @param labelId Value of label defining which cells to include.
*/
void openTimeStep(const double t,
- const ALE::Obj<ALE::Mesh>& mesh,
- const spatialdata::geocoords::CoordSys* csMesh,
+ const ALE::Obj<ALE::Mesh>& mesh,
+ const spatialdata::geocoords::CoordSys* csMesh,
const char* label =0,
const int labelId =0);
Modified: short/3D/PyLith/trunk/libsrc/meshio/VertexFilter.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/VertexFilter.hh 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/libsrc/meshio/VertexFilter.hh 2008-03-05 23:13:36 UTC (rev 11334)
@@ -21,6 +21,7 @@
#define pylith_meshio_vertexfilter_hh
#include "pylith/utils/sievetypes.hh" // USES ALE::Mesh, real_section_type
+#include "pylith/utils/vectorfields.hh" // USES VectorFieldEnum
namespace pylith {
namespace meshio {
@@ -48,14 +49,16 @@
virtual
VertexFilter* clone(void) const = 0;
- /** Filter field.
+ /** Filter field. Field type of filtered field is returned via an argument.
*
+ * @param fieldType Field type of filtered field.
* @param fieldIn Field to filter.
* @param mesh PETSc mesh.
*/
virtual
const ALE::Obj<real_section_type>&
- filter(const ALE::Obj<real_section_type>& fieldIn,
+ filter(VectorFieldEnum* fieldType,
+ const ALE::Obj<real_section_type>& fieldIn,
const ALE::Obj<ALE::Mesh>& mesh) = 0;
// PROTECTED METHODS ////////////////////////////////////////////////////
Added: short/3D/PyLith/trunk/libsrc/meshio/VertexFilterVecNorm.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/VertexFilterVecNorm.cc (rev 0)
+++ short/3D/PyLith/trunk/libsrc/meshio/VertexFilterVecNorm.cc 2008-03-05 23:13:36 UTC (rev 11334)
@@ -0,0 +1,91 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "VertexFilterVecNorm.hh" // implementation of class methods
+
+// ----------------------------------------------------------------------
+// Constructor
+pylith::meshio::VertexFilterVecNorm::VertexFilterVecNorm(void)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+pylith::meshio::VertexFilterVecNorm::~VertexFilterVecNorm(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Copy constructor.
+pylith::meshio::VertexFilterVecNorm::VertexFilterVecNorm(const VertexFilterVecNorm& f) :
+ VertexFilter(f)
+{ // copy constructor
+} // copy constructor
+
+// ----------------------------------------------------------------------
+// Create copy of filter.
+pylith::meshio::VertexFilter*
+pylith::meshio::VertexFilterVecNorm::clone(void) const
+{ // clone
+ return new VertexFilterVecNorm(*this);
+} // clone
+
+// ----------------------------------------------------------------------
+// Filter field.
+const ALE::Obj<pylith::real_section_type>&
+pylith::meshio::VertexFilterVecNorm::filter(
+ VectorFieldEnum* fieldType,
+ const ALE::Obj<real_section_type>& fieldIn,
+ const ALE::Obj<ALE::Mesh>& mesh)
+{ // filter
+ assert(0 != fieldType);
+ *fieldType = SCALAR_FIELD;
+
+ const ALE::Obj<Mesh::label_sequence>& vertices = mesh->depthStratum(0);
+ assert(!vertices.isNull());
+ const Mesh::label_sequence::iterator verticesEnd = vertices->end();
+
+ const int totalFiberDim = fieldIn->getFiberDimension(*vertices->begin());
+ const int fiberDim = fieldIn->getFiberDimension(*vertices->begin());
+
+ // Allocation field if necessary
+ if (_fieldVecNorm.isNull() ||
+ 1 != _fieldVecNorm->getFiberDimension(*vertices->begin())) {
+ _fieldVecNorm = new real_section_type(mesh->comm(), mesh->debug());
+ _fieldVecNorm->setFiberDimension(vertices, 1);
+ mesh->allocate(_fieldVecNorm);
+ } // if
+
+ double norm = 0.0;
+
+ // Loop over vertices
+ for (Mesh::label_sequence::iterator v_iter=vertices->begin();
+ v_iter != verticesEnd;
+ ++v_iter) {
+ const real_section_type::value_type* values =
+ fieldIn->restrictPoint(*v_iter);
+
+ norm = 0.0;
+ for (int i=0; i < fiberDim; ++i)
+ norm += values[i]*values[i];
+ norm = sqrt(norm);
+
+ _fieldVecNorm->updatePoint(*v_iter, &norm);
+ } // for
+
+ return _fieldVecNorm;
+} // filter
+
+
+// End of file
Added: short/3D/PyLith/trunk/libsrc/meshio/VertexFilterVecNorm.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/VertexFilterVecNorm.hh (rev 0)
+++ short/3D/PyLith/trunk/libsrc/meshio/VertexFilterVecNorm.hh 2008-03-05 23:13:36 UTC (rev 11334)
@@ -0,0 +1,86 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file pylith/meshio/VertexFilterVecNorm.hh
+ *
+ * @brief C++ object for computing vector norms for fields over
+ * vertices when outputing finite-element data.
+ */
+
+#if !defined(pylith_meshio_cellfiltervecnorm_hh)
+#define pylith_meshio_cellfiltervecnorm_hh
+
+#include "VertexFilter.hh" // ISA VertexFilter
+
+namespace pylith {
+ namespace meshio {
+ class VertexFilterVecNorm;
+ } // meshio
+} // pylith
+
+class pylith::meshio::VertexFilterVecNorm : public VertexFilter
+{ // VertexFilterVecNorm
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+ /// Constructor
+ VertexFilterVecNorm(void);
+
+ /// Destructor
+ ~VertexFilterVecNorm(void);
+
+ /** Create copy of filter.
+ *
+ * @returns Copy of filter.
+ */
+ VertexFilter* clone(void) const;
+
+ /** Filter field. Field type of filtered field is returned via an argument.
+ *
+ * @param fieldType Field type of filtered field.
+ * @param fieldIn Field to filter.
+ * @param mesh PETSc mesh.
+ */
+ const ALE::Obj<real_section_type>&
+ filter(VectorFieldEnum* fieldType,
+ const ALE::Obj<real_section_type>& fieldIn,
+ const ALE::Obj<ALE::Mesh>& mesh);
+
+// PROTECTED METHODS ////////////////////////////////////////////////////
+protected :
+
+ /** Copy constructor.
+ *
+ * @param f Filter to copy.
+ * @returns Pointer to this.
+ */
+ VertexFilterVecNorm(const VertexFilterVecNorm& f);
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+ /// Not implemented.
+ const VertexFilter& operator=(const VertexFilter&);
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+ ALE::Obj<real_section_type> _fieldVecNorm; ///< Filtered vertex field
+
+}; // VertexFilterVecNorm
+
+#endif // pylith_meshio_cellfiltervecnorm_hh
+
+
+// End of file
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am 2008-03-05 23:13:36 UTC (rev 11334)
@@ -46,6 +46,7 @@
TestMeshIO.cc \
TestMeshIOAscii.cc \
TestMeshIOLagrit.cc \
+ TestOutputManager.cc \
test_meshio.cc
@@ -74,7 +75,8 @@
TestDataWriterVTKBCMeshHex8.hh \
TestMeshIO.hh \
TestMeshIOAscii.hh \
- TestMeshIOLagrit.hh
+ TestMeshIOLagrit.hh \
+ TestOutputManager.hh
# Source files associated with testing data
@@ -226,7 +228,12 @@
tet4_bc_cell_t10.vtk \
hex8_bc_t10.vtk \
hex8_bc_vertex_t10.vtk \
- hex8_bc_cell_t10.vtk
+ hex8_bc_cell_t10.vtk \
+ output_t12.vtk \
+ output_vertex_t12.vtk \
+ output_vertex_filter_t12.vtk \
+ output_cell_t12.vtk \
+ output_cell_filter_t12.vtk
CLEANFILES = $(noinst_tmp)
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTK.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTK.cc 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTK.cc 2008-03-05 23:13:36 UTC (rev 11334)
@@ -116,7 +116,7 @@
CPPUNIT_ASSERT(false == writer._wroteVertexHeader);
CPPUNIT_ASSERT(false == writer._wroteCellHeader);
- _checkFile(_data->timestepFilename);
+ checkFile(_data->timestepFilename, t, _data->timeFormat);
} // testTimeStep
// ----------------------------------------------------------------------
@@ -164,7 +164,7 @@
CPPUNIT_ASSERT(false == writer._wroteVertexHeader);
CPPUNIT_ASSERT(false == writer._wroteCellHeader);
- _checkFile(_data->vertexFilename);
+ checkFile(_data->vertexFilename, t, _data->timeFormat);
} // testWriteVertexField
// ----------------------------------------------------------------------
@@ -220,7 +220,7 @@
CPPUNIT_ASSERT(false == writer._wroteCellHeader);
CPPUNIT_ASSERT(false == writer._wroteCellHeader);
- _checkFile(_data->cellFilename);
+ checkFile(_data->cellFilename, t, _data->timeFormat);
} // testWriteCellField
// ----------------------------------------------------------------------
@@ -306,10 +306,10 @@
// ----------------------------------------------------------------------
// Check VTK file against archived file.
void
-pylith::meshio::TestDataWriterVTK::_checkFile(const char* filenameRoot) const
-{ // _checkFile
- CPPUNIT_ASSERT(0 != _data);
- const double t = _data->time;
+pylith::meshio::TestDataWriterVTK::checkFile(const char* filenameRoot,
+ const double t,
+ const char* timeFormat)
+{ // checkFile
const std::string& fileroot = filenameRoot;
@@ -317,7 +317,7 @@
const int indexExt = fileroot.find(".vtk");
// Add time stamp to filename
char sbuffer[256];
- sprintf(sbuffer, _data->timeFormat, t);
+ sprintf(sbuffer, timeFormat, t);
std::string timestamp(sbuffer);
const int pos = timestamp.find(".");
if (pos != timestamp.length())
@@ -352,7 +352,7 @@
fileInE.close();
fileIn.close();
-} // _checkFile
+} // checkFile
// End of file
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTK.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTK.hh 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestDataWriterVTK.hh 2008-03-05 23:13:36 UTC (rev 11334)
@@ -76,6 +76,20 @@
/// Test writeCellField.
void testWriteCellField(void);
+ // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+ /** Check VTK file against archived file.
+ *
+ * @param filename Name of file to check.
+ * @param t Time for file.
+ * @param timeFormat Format of timestamp in filename.
+ */
+ static
+ void checkFile(const char* filename,
+ const double t,
+ const char* timeFormat);
+
// PROTECTED MEMBERS //////////////////////////////////////////////////
protected :
@@ -99,12 +113,6 @@
void
_createCellFields(std::vector< ALE::Obj<real_section_type> >* fields) const;
- /** Check VTK file against archived file.
- *
- * @param filename Name of file to check.
- */
- void _checkFile(const char* filename) const;
-
}; // class TestDataWriterVTK
#endif // pylith_meshio_testdatawritervtk_hh
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/TestOutputManager.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestOutputManager.cc (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestOutputManager.cc 2008-03-05 23:13:36 UTC (rev 11334)
@@ -0,0 +1,347 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestOutputManager.hh" // Implementation of class methods
+
+#include "pylith/meshio/OutputManager.hh"
+
+#include "TestDataWriterVTK.hh" // USES TestDataWriterVTK::checkFile()
+
+#include "pylith/meshio/CellFilterAvg.hh" // USES CellFilterAvg
+#include "pylith/meshio/VertexFilterVecNorm.hh" // USES VertexFilterVecNorm
+#include "pylith/meshio/DataWriterVTK.hh" // USES DataWriterVTK
+
+#include "pylith/meshio/MeshIOAscii.hh" // USES MeshIOAscii
+#include "pylith/feassemble/Quadrature2D.hh" // USES Quadrature
+
+#include "spatialdata/geocoords/CSCart.hh" // USES CSCart
+
+#include <math.h> // USES sqrt()
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::meshio::TestOutputManager );
+
+// ----------------------------------------------------------------------
+// Test constructor
+void
+pylith::meshio::TestOutputManager::testConstructor(void)
+{ // testConstructor
+ OutputManager manager;
+} // testConstructor
+
+// ----------------------------------------------------------------------
+// Test coordsys()
+void
+pylith::meshio::TestOutputManager::testCoordsys(void)
+{ // testCoordsys
+ OutputManager manager;
+
+ CPPUNIT_ASSERT(0 == manager._coordsys);
+
+ spatialdata::geocoords::CSCart cs;
+ manager.coordsys(&cs);
+ CPPUNIT_ASSERT(0 != manager._coordsys);
+} // testCoordsys
+
+// ----------------------------------------------------------------------
+// Test writer()
+void
+pylith::meshio::TestOutputManager::testWriter(void)
+{ // testWriter
+ OutputManager manager;
+
+ CPPUNIT_ASSERT(0 == manager._writer);
+
+ DataWriterVTK writer;
+ manager.writer(&writer);
+ CPPUNIT_ASSERT(0 != manager._writer);
+} // testWriter
+
+// ----------------------------------------------------------------------
+// Test vertexFilter()
+void
+pylith::meshio::TestOutputManager::testVertexFilter(void)
+{ // testVertexFilter
+ OutputManager manager;
+
+ CPPUNIT_ASSERT(0 == manager._vertexFilter);
+ CPPUNIT_ASSERT(0 == manager._cellFilter);
+
+ VertexFilterVecNorm filter;
+ manager.vertexFilter(&filter);
+ CPPUNIT_ASSERT(0 != manager._vertexFilter);
+ CPPUNIT_ASSERT(0 == manager._cellFilter);
+} // testVertexFilter
+
+// ----------------------------------------------------------------------
+// Test cellFilter().
+void
+pylith::meshio::TestOutputManager::testCellFilter(void)
+{ // testCellFilter
+ OutputManager manager;
+
+ CPPUNIT_ASSERT(0 == manager._vertexFilter);
+ CPPUNIT_ASSERT(0 == manager._cellFilter);
+
+ CellFilterAvg filter;
+ manager.cellFilter(&filter);
+ CPPUNIT_ASSERT(0 != manager._cellFilter);
+ CPPUNIT_ASSERT(0 == manager._vertexFilter);
+} // testCellFilter
+
+// ----------------------------------------------------------------------
+// Test open() and close().
+void
+pylith::meshio::TestOutputManager::testOpenClose(void)
+{ // testOpenClose
+ OutputManager manager;
+
+ MeshIOAscii iohandler;
+ ALE::Obj<Mesh> mesh;
+ iohandler.filename("data/tri3.mesh");
+ iohandler.read(&mesh);
+ CPPUNIT_ASSERT(!mesh.isNull());
+ mesh->getFactory()->clear();
+
+ spatialdata::geocoords::CSCart cs;
+ const int numTimeSteps = 1;
+
+ // TODO Replace DataVTKWriter with writer that has nontrivial
+ // open()/close().
+ DataWriterVTK writer;
+ manager.writer(&writer);
+
+ manager.open(mesh, &cs, numTimeSteps);
+ manager.close();
+} // testOpenClose
+
+// ----------------------------------------------------------------------
+// Test openTimeStep() and closeTimeStep().
+void
+pylith::meshio::TestOutputManager::testOpenCloseTimeStep(void)
+{ // testOpenCloseTimeStep
+ OutputManager manager;
+
+ MeshIOAscii iohandler;
+ ALE::Obj<Mesh> mesh;
+ iohandler.filename("data/tri3.mesh");
+ iohandler.read(&mesh);
+ CPPUNIT_ASSERT(!mesh.isNull());
+ mesh->getFactory()->clear();
+
+ spatialdata::geocoords::CSCart cs;
+ const int numTimeSteps = 1;
+ const double t = 1.2;
+ const char* filenameRoot = "output.vtk";
+ const char* timeFormat = "%3.1f";
+
+ DataWriterVTK writer;
+ writer.filename(filenameRoot);
+ writer.timeFormat(timeFormat);
+ manager.writer(&writer);
+
+ manager.open(mesh, &cs, numTimeSteps);
+ manager.openTimeStep(t, mesh, &cs);
+ manager.closeTimeStep();
+ manager.close();
+
+ TestDataWriterVTK::checkFile(filenameRoot, t, timeFormat);
+} // testOpenCloseTimeStep
+
+// ----------------------------------------------------------------------
+// Test appendVertexField().
+void
+pylith::meshio::TestOutputManager::testAppendVertexField(void)
+{ // testAppendVertexField
+ OutputManager manager;
+
+ const char* meshFilename = "data/tri3.mesh";
+ const int fiberDim = 2;
+ const int nvertices = 4;
+ const char* fieldName = "field data";
+ const VectorFieldEnum fieldType = VECTOR_FIELD;
+ const double fieldValues[] = {
+ 1.1, 1.2,
+ 2.1, 2.2,
+ 3.1, 3.2,
+ 4.1, 4.2
+ };
+
+ MeshIOAscii iohandler;
+ ALE::Obj<Mesh> mesh;
+ iohandler.filename(meshFilename);
+ iohandler.read(&mesh);
+ CPPUNIT_ASSERT(!mesh.isNull());
+ mesh->getFactory()->clear();
+
+ // Set vertex field
+ const ALE::Obj<Mesh::label_sequence>& vertices = mesh->depthStratum(0);
+ const Mesh::label_sequence::iterator verticesEnd = vertices->end();
+
+ ALE::Obj<real_section_type> field =
+ new real_section_type(mesh->comm(), mesh->debug());
+ field->setFiberDimension(vertices, fiberDim);
+ mesh->allocate(field);
+
+ CPPUNIT_ASSERT_EQUAL(nvertices, int(vertices->size()));
+
+ int ipt = 0;
+ for (Mesh::label_sequence::iterator v_iter=vertices->begin();
+ v_iter != verticesEnd;
+ ++v_iter, ++ipt) {
+ const double* values = &fieldValues[ipt*fiberDim];
+ field->updatePoint(*v_iter, values);
+ } // for
+
+ spatialdata::geocoords::CSCart cs;
+ const int numTimeSteps = 1;
+ const double t = 1.2;
+ const char* filenameRoot = "output_vertex.vtk";
+ const char* filenameRootF = "output_vertex_filter.vtk";
+ const char* timeFormat = "%3.1f";
+
+ DataWriterVTK writer;
+ writer.filename(filenameRoot);
+ writer.timeFormat(timeFormat);
+ manager.writer(&writer);
+
+ manager.open(mesh, &cs, numTimeSteps);
+ manager.openTimeStep(t, mesh, &cs);
+ manager.appendVertexField(t, fieldName, field, fieldType, mesh);
+ manager.closeTimeStep();
+ manager.close();
+
+ TestDataWriterVTK::checkFile(filenameRoot, t, timeFormat);
+
+ VertexFilterVecNorm filter;
+ manager.vertexFilter(&filter);
+ writer.filename(filenameRootF);
+ manager.writer(&writer);
+
+ manager.open(mesh, &cs, numTimeSteps);
+ manager.openTimeStep(t, mesh, &cs);
+ manager.appendVertexField(t, fieldName, field, fieldType, mesh);
+ manager.closeTimeStep();
+ manager.close();
+
+ TestDataWriterVTK::checkFile(filenameRootF, t, timeFormat);
+} // testAppendVertexField
+
+// ----------------------------------------------------------------------
+// Test appendCellField().
+void
+pylith::meshio::TestOutputManager::testAppendCellField(void)
+{ // testAppendCellField
+ OutputManager manager;
+
+ const char* meshFilename = "data/tri3.mesh";
+ const int fiberDim = 2;
+ const int ncells = 2;
+ const char* fieldName = "field data";
+ const VectorFieldEnum fieldType = OTHER_FIELD;
+ const double fieldValues[] = {
+ 1.1, 1.2,
+ 2.1, 2.2,
+ };
+
+ MeshIOAscii iohandler;
+ ALE::Obj<Mesh> mesh;
+ iohandler.filename(meshFilename);
+ iohandler.read(&mesh);
+ CPPUNIT_ASSERT(!mesh.isNull());
+ mesh->getFactory()->clear();
+
+ // Set cell field
+ const ALE::Obj<Mesh::label_sequence>& cells = mesh->heightStratum(0);
+ const Mesh::label_sequence::iterator cellsEnd = cells->end();
+
+ ALE::Obj<real_section_type> field =
+ new real_section_type(mesh->comm(), mesh->debug());
+ field->setFiberDimension(cells, fiberDim);
+ mesh->allocate(field);
+
+ CPPUNIT_ASSERT_EQUAL(ncells, int(cells->size()));
+
+ int ipt = 0;
+ for (Mesh::label_sequence::iterator c_iter=cells->begin();
+ c_iter != cellsEnd;
+ ++c_iter, ++ipt) {
+ const double* values = &fieldValues[ipt*fiberDim];
+ field->updatePoint(*c_iter, values);
+ } // for
+
+ spatialdata::geocoords::CSCart cs;
+ const int numTimeSteps = 1;
+ const double t = 1.2;
+ const char* filenameRoot = "output_cell.vtk";
+ const char* filenameRootF = "output_cell_filter.vtk";
+ const char* timeFormat = "%3.1f";
+
+ DataWriterVTK writer;
+ writer.filename(filenameRoot);
+ writer.timeFormat(timeFormat);
+ manager.writer(&writer);
+
+ manager.open(mesh, &cs, numTimeSteps);
+ manager.openTimeStep(t, mesh, &cs);
+ manager.appendCellField(t, fieldName, field, fieldType, mesh);
+ manager.closeTimeStep();
+ manager.close();
+
+ TestDataWriterVTK::checkFile(filenameRoot, t, timeFormat);
+
+ const int cellDim = 2;
+ const int numBasis = 4;
+ const int numQuadPts = 2;
+ const int spaceDim = 2;
+ const double basis[] = {
+ 1.0, 1.0,
+ 1.0, 1.0,
+ 1.0, 1.0,
+ 1.0, 1.0,
+ };
+ const double basisDerivRef[] = {
+ 1.0, 1.0, 1.0, 1.0,
+ 1.0, 1.0, 1.0, 1.0,
+ 1.0, 1.0, 1.0, 1.0,
+ 1.0, 1.0, 1.0, 1.0,
+ };
+ const double quadPtsRef[] = {
+ 1.0, 0.0,
+ -1.0, 0.0,};
+ const double quadWts[] = { 1.5, 0.5 };
+ const double minJacobian = 1.0;
+
+ feassemble::Quadrature2D quadrature;
+ quadrature.initialize(basis, basisDerivRef, quadPtsRef, quadWts,
+ cellDim, numBasis, numQuadPts, spaceDim);
+
+
+ CellFilterAvg filter;
+ filter.quadrature(&quadrature);
+ manager.cellFilter(&filter);
+ writer.filename(filenameRootF);
+ manager.writer(&writer);
+
+ manager.open(mesh, &cs, numTimeSteps);
+ manager.openTimeStep(t, mesh, &cs);
+ manager.appendCellField(t, fieldName, field, fieldType, mesh);
+ manager.closeTimeStep();
+ manager.close();
+
+ TestDataWriterVTK::checkFile(filenameRootF, t, timeFormat);
+} // testAppendCellField
+
+
+// End of file
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/TestOutputManager.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestOutputManager.hh (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestOutputManager.hh 2008-03-05 23:13:36 UTC (rev 11334)
@@ -0,0 +1,86 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/meshio/TestOutputManager.hh
+ *
+ * @brief C++ TestOutputManager object
+ *
+ * C++ unit testing for OutputManager.
+ */
+
+#if !defined(pylith_meshio_testoutputmanager_hh)
+#define pylith_meshio_testoutputmanager_hh
+
+#include <cppunit/extensions/HelperMacros.h>
+
+/// Namespace for pylith package
+namespace pylith {
+ namespace meshio {
+ class TestOutputManager;
+ } // meshio
+} // pylith
+
+/// C++ unit testing for OutputManager
+class pylith::meshio::TestOutputManager : public CppUnit::TestFixture
+{ // class TestOutputManager
+
+ // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+ CPPUNIT_TEST_SUITE( TestOutputManager );
+
+ CPPUNIT_TEST( testConstructor );
+ CPPUNIT_TEST( testCoordsys );
+ CPPUNIT_TEST( testWriter );
+ CPPUNIT_TEST( testVertexFilter );
+ CPPUNIT_TEST( testCellFilter );
+ CPPUNIT_TEST( testOpenClose );
+ CPPUNIT_TEST( testOpenCloseTimeStep );
+ CPPUNIT_TEST( testAppendVertexField );
+ CPPUNIT_TEST( testAppendCellField );
+
+ CPPUNIT_TEST_SUITE_END();
+
+ // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+ /// Test constructor
+ void testConstructor(void);
+
+ /// Test coordsys()
+ void testCoordsys(void);
+
+ /// Test writer()
+ void testWriter(void);
+
+ /// Test vertexFilter()
+ void testVertexFilter(void);
+
+ /// Test cellFilter().
+ void testCellFilter(void);
+
+ /// Test open() and close().
+ void testOpenClose(void);
+
+ /// Test openTimeStep() and closeTimeStep().
+ void testOpenCloseTimeStep(void);
+
+ /// Test appendVertexField().
+ void testAppendVertexField(void);
+
+ /// Test appendCellField().
+ void testAppendCellField(void);
+
+}; // class TestOutputManager
+
+#endif // pylith_meshio_testoutputmanager_hh
+
+// End of file
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am 2008-03-05 21:45:31 UTC (rev 11333)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/Makefile.am 2008-03-05 23:13:36 UTC (rev 11334)
@@ -79,7 +79,12 @@
tet4_bc_cell_t10.vtk \
hex8_bc_t10.vtk \
hex8_bc_vertex_t10.vtk \
- hex8_bc_cell_t10.vtk
+ hex8_bc_cell_t10.vtk \
+ output_t12.vtk \
+ output_vertex_t12.vtk \
+ output_vertex_filter_t12.vtk \
+ output_cell_t12.vtk \
+ output_cell_filter_t12.vtk
noinst_TMP =
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_cell_filter_t12.vtk
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_cell_filter_t12.vtk (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_cell_filter_t12.vtk 2008-03-05 23:13:36 UTC (rev 11334)
@@ -0,0 +1,20 @@
+# vtk DataFile Version 2.0
+Simplicial Mesh Example
+ASCII
+DATASET UNSTRUCTURED_GRID
+POINTS 4 double
+-1 0 0.0
+0 -1 0.0
+0 1 0.0
+1 0 0.0
+CELLS 2 8
+3 0 1 2
+3 1 3 2
+CELL_TYPES 2
+5
+5
+CELL_DATA 2
+SCALARS field data double 1
+LOOKUP_TABLE default
+1.125
+2.125
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_cell_t12.vtk
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_cell_t12.vtk (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_cell_t12.vtk 2008-03-05 23:13:36 UTC (rev 11334)
@@ -0,0 +1,20 @@
+# vtk DataFile Version 2.0
+Simplicial Mesh Example
+ASCII
+DATASET UNSTRUCTURED_GRID
+POINTS 4 double
+-1 0 0.0
+0 -1 0.0
+0 1 0.0
+1 0 0.0
+CELLS 2 8
+3 0 1 2
+3 1 3 2
+CELL_TYPES 2
+5
+5
+CELL_DATA 2
+SCALARS field data double 2
+LOOKUP_TABLE default
+1.1 1.2
+2.1 2.2
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_t12.vtk
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_t12.vtk (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_t12.vtk 2008-03-05 23:13:36 UTC (rev 11334)
@@ -0,0 +1,15 @@
+# vtk DataFile Version 2.0
+Simplicial Mesh Example
+ASCII
+DATASET UNSTRUCTURED_GRID
+POINTS 4 double
+-1 0 0.0
+0 -1 0.0
+0 1 0.0
+1 0 0.0
+CELLS 2 8
+3 0 1 2
+3 1 3 2
+CELL_TYPES 2
+5
+5
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_vertex_filter_t12.vtk
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_vertex_filter_t12.vtk (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_vertex_filter_t12.vtk 2008-03-05 23:13:36 UTC (rev 11334)
@@ -0,0 +1,22 @@
+# vtk DataFile Version 2.0
+Simplicial Mesh Example
+ASCII
+DATASET UNSTRUCTURED_GRID
+POINTS 4 double
+-1 0 0.0
+0 -1 0.0
+0 1 0.0
+1 0 0.0
+CELLS 2 8
+3 0 1 2
+3 1 3 2
+CELL_TYPES 2
+5
+5
+POINT_DATA 4
+SCALARS field data double 1
+LOOKUP_TABLE default
+1.62788
+3.04138
+4.45533
+5.86941
Added: short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_vertex_t12.vtk
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_vertex_t12.vtk (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/data/output_vertex_t12.vtk 2008-03-05 23:13:36 UTC (rev 11334)
@@ -0,0 +1,21 @@
+# vtk DataFile Version 2.0
+Simplicial Mesh Example
+ASCII
+DATASET UNSTRUCTURED_GRID
+POINTS 4 double
+-1 0 0.0
+0 -1 0.0
+0 1 0.0
+1 0 0.0
+CELLS 2 8
+3 0 1 2
+3 1 3 2
+CELL_TYPES 2
+5
+5
+POINT_DATA 4
+VECTORS field data double
+1.1 1.2 0.0
+2.1 2.2 0.0
+3.1 3.2 0.0
+4.1 4.2 0.0
More information about the cig-commits
mailing list