[cig-commits] r11337 - in short/3D/PyLith/trunk: libsrc/meshio unittests/libtests/meshio

brad at geodynamics.org brad at geodynamics.org
Wed Mar 5 16:10:27 PST 2008


Author: brad
Date: 2008-03-05 16:10:26 -0800 (Wed, 05 Mar 2008)
New Revision: 11337

Added:
   short/3D/PyLith/trunk/unittests/libtests/meshio/TestCellFilterAvg.cc
   short/3D/PyLith/trunk/unittests/libtests/meshio/TestCellFilterAvg.hh
   short/3D/PyLith/trunk/unittests/libtests/meshio/TestVertexFilterVecNorm.cc
   short/3D/PyLith/trunk/unittests/libtests/meshio/TestVertexFilterVecNorm.hh
Modified:
   short/3D/PyLith/trunk/libsrc/meshio/CellFilter.hh
   short/3D/PyLith/trunk/libsrc/meshio/CellFilterAvg.hh
   short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am
Log:
Added C++ unit tests for CellFilterAvg and VertexFilterVecNorm.

Modified: short/3D/PyLith/trunk/libsrc/meshio/CellFilter.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/CellFilter.hh	2008-03-05 23:40:19 UTC (rev 11336)
+++ short/3D/PyLith/trunk/libsrc/meshio/CellFilter.hh	2008-03-06 00:10:26 UTC (rev 11337)
@@ -73,8 +73,8 @@
   filter(VectorFieldEnum* fieldType,
 	 const ALE::Obj<real_section_type>& fieldIn,
 	 const ALE::Obj<ALE::Mesh>& mesh,
-	 const char* label,
-	 const int labelId) = 0;
+	 const char* label =0,
+	 const int labelId =0) = 0;
 
 // PROTECTED METHODS ////////////////////////////////////////////////////
 protected :

Modified: short/3D/PyLith/trunk/libsrc/meshio/CellFilterAvg.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/CellFilterAvg.hh	2008-03-05 23:40:19 UTC (rev 11336)
+++ short/3D/PyLith/trunk/libsrc/meshio/CellFilterAvg.hh	2008-03-06 00:10:26 UTC (rev 11337)
@@ -60,8 +60,8 @@
   filter(VectorFieldEnum* fieldType,
 	 const ALE::Obj<real_section_type>& fieldIn,
 	 const ALE::Obj<ALE::Mesh>& mesh,
-	 const char* label,
-	 const int labelId);
+	 const char* label =0,
+	 const int labelId =0);
 
 // PROTECTED METHODS ////////////////////////////////////////////////////
 protected :

Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am	2008-03-05 23:40:19 UTC (rev 11336)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/Makefile.am	2008-03-06 00:10:26 UTC (rev 11337)
@@ -21,6 +21,7 @@
 
 # Primary source files
 testmeshio_SOURCES = \
+	TestCellFilterAvg.cc \
 	TestDataWriterVTK.cc \
 	TestDataWriterVTKMesh.cc \
 	TestDataWriterVTKMeshLine2.cc \
@@ -48,10 +49,12 @@
 	TestMeshIOLagrit.cc \
 	TestOutputManager.cc \
 	TestOutputSolnSubset.cc \
+	TestVertexFilterVecNorm.cc \
 	test_meshio.cc
 
 
 noinst_HEADERS = \
+	TestCellFilterAvg.hh \
 	TestDataWriterVTK.hh \
 	TestDataWriterVTKMesh.hh \
 	TestDataWriterVTKMeshLine2.hh \
@@ -78,7 +81,8 @@
 	TestMeshIOAscii.hh \
 	TestMeshIOLagrit.hh \
 	TestOutputManager.hh \
-	TestOutputSolnSubset.hh
+	TestOutputSolnSubset.hh \
+	TestVertexFilterVecNorm.hh
 
 
 # Source files associated with testing data

Added: short/3D/PyLith/trunk/unittests/libtests/meshio/TestCellFilterAvg.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestCellFilterAvg.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestCellFilterAvg.cc	2008-03-06 00:10:26 UTC (rev 11337)
@@ -0,0 +1,132 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestCellFilterAvg.hh" // Implementation of class methods
+
+#include "pylith/meshio/CellFilterAvg.hh"
+
+#include "pylith/meshio/MeshIOAscii.hh" // USES MeshIOAscii
+#include "pylith/feassemble/Quadrature2D.hh" // USES Quadrature
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::meshio::TestCellFilterAvg );
+
+// ----------------------------------------------------------------------
+// Test constructor
+void
+pylith::meshio::TestCellFilterAvg::testConstructor(void)
+{ // testConstructor
+  CellFilterAvg filter;
+} // testConstructor
+
+// ----------------------------------------------------------------------
+// Test filter()
+void
+pylith::meshio::TestCellFilterAvg::testFilter(void)
+{ // testFilter
+  const char* filename = "data/quad4.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,
+  };
+  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;
+
+
+
+  const VectorFieldEnum fieldTypeE = SCALAR_FIELD;
+  const int fiberDimE = 1;
+  const double fieldValuesE[] = {
+    (1.5*1.1 + 0.5*1.2)/2.0,
+    (1.5*2.1 + 0.5*2.2)/2.0,
+  };
+
+  MeshIOAscii iohandler;
+  ALE::Obj<Mesh> mesh;
+  iohandler.filename(filename);
+  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
+
+  feassemble::Quadrature2D quadrature;
+  quadrature.initialize(basis, basisDerivRef, quadPtsRef, quadWts,
+			cellDim, numBasis, numQuadPts, spaceDim);
+
+  CellFilterAvg filter;
+  filter.quadrature(&quadrature);
+
+  VectorFieldEnum fieldTypeF = SCALAR_FIELD;
+  const ALE::Obj<real_section_type>& fieldF =
+    filter.filter(&fieldTypeF, field, mesh);
+
+  CPPUNIT_ASSERT_EQUAL(fieldTypeE, fieldTypeF);
+  ipt = 0;
+  for (Mesh::label_sequence::iterator c_iter=cells->begin();
+       c_iter != cellsEnd;
+       ++c_iter, ++ipt) {
+    CPPUNIT_ASSERT_EQUAL(fiberDimE, fieldF->getFiberDimension(*c_iter));
+    const double* values = fieldF->restrictPoint(*c_iter);
+    CPPUNIT_ASSERT(0 != values);
+    const double tolerance = 1.0e-06;
+    for (int i=0; i < fiberDimE; ++i)
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, 
+				   values[i]/fieldValuesE[ipt*fiberDimE+i],
+				   tolerance);
+  } // for
+} // testFilter
+
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/meshio/TestCellFilterAvg.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestCellFilterAvg.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestCellFilterAvg.hh	2008-03-06 00:10:26 UTC (rev 11337)
@@ -0,0 +1,58 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/meshio/TestCellFilterAvg.hh
+ *
+ * @brief C++ TestCellFilterAvg object
+ *
+ * C++ unit testing for CellFilterAvg.
+ */
+
+#if !defined(pylith_meshio_testcellfilteravg_hh)
+#define pylith_meshio_testcellfilteravg_hh
+
+#include <cppunit/extensions/HelperMacros.h>
+
+/// Namespace for pylith package
+namespace pylith {
+  namespace meshio {
+    class TestCellFilterAvg;
+  } // meshio
+} // pylith
+
+/// C++ unit testing for CellFilterAvg
+class pylith::meshio::TestCellFilterAvg : public CppUnit::TestFixture
+{ // class TestCellFilterAvg
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestCellFilterAvg );
+
+  CPPUNIT_TEST( testConstructor );
+  CPPUNIT_TEST( testFilter );
+
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Test constructor
+  void testConstructor(void);
+
+  /// Test filter()
+  void testFilter(void);
+
+}; // class TestCellFilterAvg
+
+#endif // pylith_meshio_testcellfilteravg_hh
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/meshio/TestVertexFilterVecNorm.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestVertexFilterVecNorm.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestVertexFilterVecNorm.cc	2008-03-06 00:10:26 UTC (rev 11337)
@@ -0,0 +1,105 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestVertexFilterVecNorm.hh" // Implementation of class methods
+
+#include "pylith/meshio/VertexFilterVecNorm.hh"
+
+#include "pylith/meshio/MeshIOAscii.hh" // USES MeshIOAscii
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::meshio::TestVertexFilterVecNorm );
+
+// ----------------------------------------------------------------------
+// Test constructor
+void
+pylith::meshio::TestVertexFilterVecNorm::testConstructor(void)
+{ // testConstructor
+  VertexFilterVecNorm filter;
+} // testConstructor
+
+// ----------------------------------------------------------------------
+// Test filter()
+void
+pylith::meshio::TestVertexFilterVecNorm::testFilter(void)
+{ // testFilter
+  const char* filename = "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
+  };
+  const VectorFieldEnum fieldTypeE = SCALAR_FIELD;
+  const int fiberDimE = 1;
+  const double fieldValuesE[] = {
+    sqrt(pow(1.1, 2) + pow(1.2, 2)),
+    sqrt(pow(2.1, 2) + pow(2.2, 2)),
+    sqrt(pow(3.1, 2) + pow(3.2, 2)),
+    sqrt(pow(4.1, 2) + pow(4.2, 2))
+  };
+
+  MeshIOAscii iohandler;
+  ALE::Obj<Mesh> mesh;
+  iohandler.filename(filename);
+  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
+
+  VertexFilterVecNorm filter;
+  VectorFieldEnum fieldTypeF = OTHER_FIELD;
+  const ALE::Obj<real_section_type>& fieldF =
+    filter.filter(&fieldTypeF, field, mesh);
+
+  CPPUNIT_ASSERT_EQUAL(fieldTypeE, fieldTypeF);
+  ipt = 0;
+  for (Mesh::label_sequence::iterator v_iter=vertices->begin();
+       v_iter != verticesEnd;
+       ++v_iter, ++ipt) {
+    CPPUNIT_ASSERT_EQUAL(fiberDimE, fieldF->getFiberDimension(*v_iter));
+    const double* values = fieldF->restrictPoint(*v_iter);
+    CPPUNIT_ASSERT(0 != values);
+    const double tolerance = 1.0e-06;
+    for (int i=0; i < fiberDimE; ++i)
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, 
+				   values[i]/fieldValuesE[ipt*fiberDimE+i],
+				   tolerance);
+  } // for
+} // testFilter
+
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/meshio/TestVertexFilterVecNorm.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestVertexFilterVecNorm.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestVertexFilterVecNorm.hh	2008-03-06 00:10:26 UTC (rev 11337)
@@ -0,0 +1,58 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/meshio/TestVertexFilterVecNorm.hh
+ *
+ * @brief C++ TestVertexFilterVecNorm object
+ *
+ * C++ unit testing for VertexFilterVecNorm.
+ */
+
+#if !defined(pylith_meshio_testvertexfiltervecnorm_hh)
+#define pylith_meshio_testvertexfiltervecnorm_hh
+
+#include <cppunit/extensions/HelperMacros.h>
+
+/// Namespace for pylith package
+namespace pylith {
+  namespace meshio {
+    class TestVertexFilterVecNorm;
+  } // meshio
+} // pylith
+
+/// C++ unit testing for VertexFilterVecNorm
+class pylith::meshio::TestVertexFilterVecNorm : public CppUnit::TestFixture
+{ // class TestVertexFilterVecNorm
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestVertexFilterVecNorm );
+
+  CPPUNIT_TEST( testConstructor );
+  CPPUNIT_TEST( testFilter );
+
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Test constructor
+  void testConstructor(void);
+
+  /// Test filter()
+  void testFilter(void);
+
+}; // class TestVertexFilterVecNorm
+
+#endif // pylith_meshio_testvertexfiltervecnorm_hh
+
+// End of file 



More information about the cig-commits mailing list