[cig-commits] r13463 - in short/3D/PyLith/trunk: libsrc libsrc/topology libsrc/utils unittests/libtests/topology

brad at geodynamics.org brad at geodynamics.org
Thu Dec 4 13:28:45 PST 2008


Author: brad
Date: 2008-12-04 13:28:45 -0800 (Thu, 04 Dec 2008)
New Revision: 13463

Added:
   short/3D/PyLith/trunk/libsrc/topology/FieldUniform.cc
   short/3D/PyLith/trunk/libsrc/topology/FieldUniform.hh
   short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldUniform.cc
   short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldUniform.hh
Modified:
   short/3D/PyLith/trunk/libsrc/Makefile.am
   short/3D/PyLith/trunk/libsrc/topology/Field.cc
   short/3D/PyLith/trunk/libsrc/topology/Field.hh
   short/3D/PyLith/trunk/libsrc/topology/Field.icc
   short/3D/PyLith/trunk/libsrc/topology/Makefile.am
   short/3D/PyLith/trunk/libsrc/utils/sievetypes.hh
   short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am
   short/3D/PyLith/trunk/unittests/libtests/topology/TestField.cc
   short/3D/PyLith/trunk/unittests/libtests/topology/TestField.hh
Log:
More work on Field. Added FieldUniform.

Modified: short/3D/PyLith/trunk/libsrc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/Makefile.am	2008-12-04 21:27:35 UTC (rev 13462)
+++ short/3D/PyLith/trunk/libsrc/Makefile.am	2008-12-04 21:28:45 UTC (rev 13463)
@@ -94,6 +94,7 @@
 	meshio/VertexFilterVecNorm.cc \
 	topology/Distributor.cc \
 	topology/Field.cc \
+	topology/FieldUniform.cc \
 	topology/FieldsManager.cc \
 	topology/FieldOps.cc \
 	topology/Mesh.cc \

Modified: short/3D/PyLith/trunk/libsrc/topology/Field.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.cc	2008-12-04 21:27:35 UTC (rev 13462)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.cc	2008-12-04 21:28:45 UTC (rev 13463)
@@ -26,6 +26,7 @@
 // ----------------------------------------------------------------------
 // Default constructor.
 pylith::topology::Field::Field(const ALE::Obj<SieveMesh>& mesh) :
+  _mesh(mesh),
   _scale(1.0),
   _name("unknown"),
   _spaceDim(0),
@@ -34,7 +35,7 @@
 { // constructor
   assert(!mesh.isNull());
 
-  _section = new SieveMesh::real_section_type(mesh->comm(), mesh->debug());
+  _section = new SieveRealSection(mesh->comm(), mesh->debug());
 } // constructor
 
 // ----------------------------------------------------------------------
@@ -44,6 +45,35 @@
 } // destructor
 
 // ----------------------------------------------------------------------
+// Create section given atlas.
+void
+pylith::topology::Field::copyLayout(const Field& src)
+{ // createSection
+  _spaceDim = src._spaceDim;
+  _vecFieldType = src._vecFieldType;
+
+  const ALE::Obj<SieveRealSection>& srcSection = src.section();
+  assert(!_section.isNull());
+
+  _section->setAtlas(srcSection->getAtlas());
+  _section->allocateStorage();
+  _section->setBC(srcSection->getBC());
+} // createSection
+
+// ----------------------------------------------------------------------
+// Clear variables associated with section.
+void
+pylith::topology::Field::clear(void)
+{ // clear
+  assert(!_section.isNull());
+  _section->clear();
+
+  _scale = 1.0;
+  _vecFieldType = OTHER;
+  _dimensionsOkay = false;
+} // clear
+
+// ----------------------------------------------------------------------
 // Dimensionalize field.
 void
 pylith::topology::Field::dimensionalize(void)
@@ -55,11 +85,9 @@
     throw std::runtime_error(msg.str());
   } // if
 
-  typedef SieveMesh::real_section_type::chart_type chart_type;
-
   assert(!_section.isNull());
-  const chart_type& chart = _section->getChart();
-  const chart_type::const_iterator chartEnd = chart.end();
+  const SieveRealSection::chart_type& chart = _section->getChart();
+  const SieveRealSection::chart_type::const_iterator chartEnd = chart.end();
 
   // Assume fiber dimension is uniform
   const int fiberDim = _section->getFiberDimension(*chart.begin());
@@ -67,7 +95,7 @@
 
   spatialdata::units::Nondimensional normalizer;
 
-  for (chart_type::const_iterator c_iter = chart.begin();
+  for (SieveRealSection::chart_type::const_iterator c_iter = chart.begin();
        c_iter != chartEnd;
        ++c_iter) {
     assert(fiberDim == _section->getFiberDimension(*c_iter));

Modified: short/3D/PyLith/trunk/libsrc/topology/Field.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.hh	2008-12-04 21:27:35 UTC (rev 13462)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.hh	2008-12-04 21:28:45 UTC (rev 13463)
@@ -70,7 +70,7 @@
    *
    * @returns Sieve section.
    */
-  const ALE::Obj<SieveMesh::real_section_type>& section(void) const;
+  const ALE::Obj<SieveRealSection>& section(void) const;
 
   /** Set name of field.
    *
@@ -132,16 +132,33 @@
    */
   bool addDimensionOkay(void) const;
 
+  /** Create section with same layout (fiber dimension and
+   * constraints) as another section. This allows the layout data
+   * structures to be reused across multiple fields, reducing memory
+   * usage.
+   *
+   * @param sec Section defining layout.
+   */
+  void copyLayout(const Field& src);
+
+  /// Clear variables associated with section.
+  void clear(void);
+
   /** Dimensionalize field. Throws runtime_error if field is not
    * allowed to be dimensionalized.
    */
   void dimensionalize(void);
 
+// PROTECTED MEMBERS ////////////////////////////////////////////////////
+protected :
+
+  const ALE::Obj<SieveMesh>& _mesh; ///< Mesh associated with section
+  ALE::Obj<SieveRealSection> _section; ///< Real section with data
+
 // PRIVATE MEMBERS //////////////////////////////////////////////////////
 private :
 
   double _scale; ///< Dimensional scale associated with field
-  ALE::Obj<SieveMesh::real_section_type> _section; ///< Real section with data
   std::string _name; ///< Name of field
   int _spaceDim; ///< Spatial dimension of domain
   VectorFieldEnum _vecFieldType; ///< Type of vector field

Modified: short/3D/PyLith/trunk/libsrc/topology/Field.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.icc	2008-12-04 21:27:35 UTC (rev 13462)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.icc	2008-12-04 21:28:45 UTC (rev 13463)
@@ -16,7 +16,7 @@
 
 // Get Sieve section.
 inline
-const ALE::Obj<pylith::SieveMesh::real_section_type>&
+const ALE::Obj<pylith::SieveRealSection>&
 pylith::topology::Field::section(void) const {
   return _section;
 }
@@ -91,7 +91,6 @@
   return _dimensionsOkay;
 }
 
-
 #endif
 
 

Added: short/3D/PyLith/trunk/libsrc/topology/FieldUniform.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldUniform.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldUniform.cc	2008-12-04 21:28:45 UTC (rev 13463)
@@ -0,0 +1,72 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "FieldUniform.hh" // implementation of class methods
+
+#include <stdexcept> // USES std::runtime_error
+#include <sstream> // USES std::ostringstream
+#include <cassert> // USES assert()
+
+// ----------------------------------------------------------------------
+// Default constructor.
+pylith::topology::FieldUniform::FieldUniform(const ALE::Obj<SieveMesh>& mesh,
+					     const int fiberDim) :
+  Field(mesh),
+  _fiberDim(fiberDim)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor.
+pylith::topology::FieldUniform::~FieldUniform(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Create section given points.
+void
+pylith::topology::FieldUniform::createSection(
+			const ALE::Obj<SieveMesh::label_sequence>& points)
+{ // createSection
+  assert(!_section.isNull());
+
+  const SieveMesh::point_type pointMin = 
+    *std::min_element(points->begin(), points->end());
+  const SieveMesh::point_type pointMax = 
+    *std::max_element(points->begin(), points->end());
+  _section->setChart(SieveRealSection::chart_type(pointMin, pointMax+1));
+  _section->setFiberDimension(points, _fiberDim);
+  _mesh->allocate(_section);
+} // createSection
+
+// ----------------------------------------------------------------------
+// Create section given chart.
+void
+pylith::topology::FieldUniform::createSection(
+			const SieveRealSection::chart_type& chart)
+{ // createSection
+  assert(!_section.isNull());
+
+  _section->setChart(chart);
+
+  const SieveRealSection::chart_type::const_iterator chartEnd = chart.end();
+  for (SieveRealSection::chart_type::const_iterator c_iter = chart.begin();
+       c_iter != chartEnd;
+       ++c_iter)
+    _section->setFiberDimension(*c_iter, _fiberDim);
+  _mesh->allocate(_section);
+} // createSection
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/topology/FieldUniform.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldUniform.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldUniform.hh	2008-12-04 21:28:45 UTC (rev 13463)
@@ -0,0 +1,83 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file pylith/topology/FieldUniform.hh
+ *
+ * @brief Vector field with uniform fiber dimension (no constraints)
+ * over the vertices or cells of a finite-element mesh.
+ *
+ * Special case of Field with a uniform fiber dimension and no constraints.
+ */
+
+#if !defined(pylith_topology_fielduniform_hh)
+#define pylith_topology_fielduniform_hh
+
+// Include directives ---------------------------------------------------
+#include "Field.hh" // ISA Field
+
+// Forward declarations -------------------------------------------------
+namespace pylith {
+  namespace topology {
+    class FieldUniform;
+    class TestFieldUniform;
+  } // topology
+} // pylith
+
+// FieldUniform ---------------------------------------------------------
+class pylith::topology::FieldUniform : public Field
+{ // FieldUniform
+  friend class TestFieldUniform; // unit testing
+
+// PUBLIC MEMBERS ///////////////////////////////////////////////////////
+public :
+
+  /** Default constructor.
+   *
+   * @param mesh Sieve mesh.
+   */
+  FieldUniform(const ALE::Obj<SieveMesh>& mesh,
+	       const int fiberDim);
+
+  /// Destructor.
+  ~FieldUniform(void);
+
+  /** Create section given points.
+   *
+   * @param points Mesh points over which to define section.
+   */
+  void createSection(const ALE::Obj<SieveMesh::label_sequence>& points);
+
+  /** Create section given chart. This allows a chart to be reused
+   * across multiple fields, reducing memory usage.
+   *
+   * @param chart Chart defining points over which section is defined.
+   */
+  void createSection(const SieveRealSection::chart_type& chart);
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  const int _fiberDim; ///< Fiber dimension
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  FieldUniform(const FieldUniform&); ///< Not implemented
+  const FieldUniform& operator=(const FieldUniform&); ///< Not implemented
+
+}; // FieldUniform
+
+#endif // pylith_topology_fielduniform_hh
+
+
+// End of file 

Modified: short/3D/PyLith/trunk/libsrc/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Makefile.am	2008-12-04 21:27:35 UTC (rev 13462)
+++ short/3D/PyLith/trunk/libsrc/topology/Makefile.am	2008-12-04 21:28:45 UTC (rev 13463)
@@ -17,6 +17,7 @@
 	Distributor.hh \
 	Field.hh \
 	Field.icc \
+	FieldUniform.hh \
 	FieldsManager.hh \
 	FieldOps.hh \
 	Mesh.hh \

Modified: short/3D/PyLith/trunk/libsrc/utils/sievetypes.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/utils/sievetypes.hh	2008-12-04 21:27:35 UTC (rev 13462)
+++ short/3D/PyLith/trunk/libsrc/utils/sievetypes.hh	2008-12-04 21:28:45 UTC (rev 13463)
@@ -26,7 +26,7 @@
 #if NEWPYLITHMESH // For use with pylith::topology::Mesh
   typedef ALE::IMesh<> SieveMesh;
   typedef ALE::IMesh<ALE::LabelSifter<int, SieveMesh::point_type> > SieveSubMesh;
-  typedef ALE::Obj<SieveMesh::real_section_type> SieveRealGenSection;
+  typedef SieveMesh::real_section_type SieveRealSection;
 
 #else
   typedef ALE::IMesh<> Mesh;

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am	2008-12-04 21:27:35 UTC (rev 13462)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/Makefile.am	2008-12-04 21:28:45 UTC (rev 13463)
@@ -22,6 +22,7 @@
 # Primary source files
 testtopology_SOURCES = \
 	TestField.cc \
+	TestFieldUniform.cc \
 	TestFieldsManager.cc \
 	TestMesh.cc \
 	TestMeshOps.cc \
@@ -29,6 +30,7 @@
 
 noinst_HEADERS = \
 	TestField.hh \
+	TestFieldUniform.hh \
 	TestFieldsManager.hh \
 	TestMesh.hh \
 	TestMeshOps.hh

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestField.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestField.cc	2008-12-04 21:27:35 UTC (rev 13462)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestField.cc	2008-12-04 21:28:45 UTC (rev 13463)
@@ -24,12 +24,34 @@
 CPPUNIT_TEST_SUITE_REGISTRATION( pylith::topology::TestField );
 
 // ----------------------------------------------------------------------
+namespace pylith {
+  namespace topology {
+    namespace _TestField {
+      const int spaceDim = 2;
+      const int cellDim = 2;
+      const int nvertices = 4;
+      const int ncells = 1;
+      const int ncorners = 4;
+      const int cells[] = { 0, 1, 2, 3 };
+      const double coordinates[] = {
+	0.0, 0.0,
+	1.0, 0.0,
+	0.0, 1.0,
+	1.0, 1.0,
+      };
+    } // _TestField
+  } // topology
+} // pylith
+
+// ----------------------------------------------------------------------
 // Test constructor.
 void
 pylith::topology::TestField::testConstructor(void)
 { // testConstructor
   Mesh mesh;
   Field field(mesh.sieveMesh());
+
+  CPPUNIT_ASSERT(!field._mesh.isNull());
 } // testConstructor
 
 // ----------------------------------------------------------------------
@@ -119,27 +141,82 @@
 } // testAddDimensionOkay
 
 // ----------------------------------------------------------------------
-// Test dimensionalize().
+// Test copyLayout().
 void
-pylith::topology::TestField::testDimensionalize(void)
-{ // testDimensionalize
+pylith::topology::TestField::testCopyLayout(void)
+{ // testCopyLayout
+  const int fiberDim = 3;
+  const int nconstraints[] = { 0, 2, 1, 3 };
+  const int constraints[] = {
+              // 0
+    0, 3,     // 1
+    2,        // 2
+    0, 1, 2,  // 3
+  };
+    
   Mesh mesh;
+  _buildMesh(&mesh);
   const ALE::Obj<SieveMesh>& sieveMesh = mesh.sieveMesh();
+  const ALE::Obj<SieveMesh::label_sequence>& vertices = 
+    sieveMesh->depthStratum(0);
+
+  // Create field with atlas to use to create new field
+  Field fieldSrc(sieveMesh);
+  { // Setup source field
+    const ALE::Obj<SieveRealSection>& section = fieldSrc.section();
+    const int spaceDim = _TestField::spaceDim;
+    section->setChart(SieveMesh::real_section_type::chart_type(
+		  *std::min_element(vertices->begin(), vertices->end()),
+		  *std::max_element(vertices->begin(), vertices->end())+1));
+    section->setFiberDimension(vertices, fiberDim);
+    int iV=0;
+    for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+	 v_iter != vertices->end();
+	 ++v_iter)
+      section->addConstraintDimension(*v_iter, nconstraints[iV++]);
+    sieveMesh->allocate(section);
+  } // Setup source field
+
   Field field(sieveMesh);
+  field.copyLayout(fieldSrc);
 
-  const int spaceDim = 2;
-  const int cellDim = 2;
-  const int nvertices = 4;
-  const int ncells = 1;
-  const int ncorners = 4;
-  const int cells[] = { 0, 1, 2, 3 };
-  const double coordinates[] = {
-    0.0, 0.0,
-    1.0, 0.0,
-    0.0, 1.0,
-    1.0, 1.0,
-  };
+  const ALE::Obj<SieveRealSection>& section = field.section();
+  int iV = 0;
+  for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter) {
+    CPPUNIT_ASSERT_EQUAL(fiberDim, section->getFiberDimension(*v_iter));
+    CPPUNIT_ASSERT_EQUAL(nconstraints[iV++], 
+			 section->getConstraintDimension(*v_iter));
+  } // for
+} // testCopyLayout
 
+// ----------------------------------------------------------------------
+// Test clear().
+void
+pylith::topology::TestField::testClear(void)
+{ // testAddDimensionOkay
+  Mesh mesh;
+  Field field(mesh.sieveMesh());
+
+  field.spaceDim(3);
+  field.scale(2.0);
+  field.vectorFieldType(Field::TENSOR);
+  field.addDimensionOkay(true);
+  
+  field.clear();
+
+  CPPUNIT_ASSERT_EQUAL(3, field._spaceDim); // no change
+  CPPUNIT_ASSERT_EQUAL(1.0, field._scale);
+  CPPUNIT_ASSERT_EQUAL(Field::OTHER, field._vecFieldType);
+  CPPUNIT_ASSERT_EQUAL(false, field._dimensionsOkay);
+} // testClear
+
+// ----------------------------------------------------------------------
+// Test dimensionalize().
+void
+pylith::topology::TestField::testDimensionalize(void)
+{ // testDimensionalize
   const int fiberDim = 3;
   const double scale = 2.0;
   const double valuesNondim[] = {
@@ -149,27 +226,13 @@
     1.4, 2.5, 3.6,
   };
 
+  Mesh mesh;
+  _buildMesh(&mesh);
+  const ALE::Obj<SieveMesh>& sieveMesh = mesh.sieveMesh();
+  Field field(sieveMesh);
+  const ALE::Obj<SieveRealSection>& section = field.section();
+  const int spaceDim = _TestField::spaceDim;
 
-  ALE::Obj<SieveMesh::sieve_type> sieve = 
-    new SieveMesh::sieve_type(sieveMesh->comm());
-  CPPUNIT_ASSERT(!sieve.isNull());
-
-  ALE::Obj<ALE::Mesh::sieve_type> s = 
-    new ALE::Mesh::sieve_type(sieve->comm(), sieve->debug());
-  
-  const bool interpolate = false;
-  ALE::SieveBuilder<ALE::Mesh>::buildTopology(s, cellDim, ncells, (int*) cells,
-					      nvertices, interpolate, 
-					      ncorners);
-  std::map<SieveMesh::point_type,SieveMesh::point_type> renumbering;
-  ALE::ISieveConverter::convertSieve(*s, *sieve, renumbering);
-  sieveMesh->setSieve(sieve);
-  sieveMesh->stratify();
-  ALE::SieveBuilder<SieveMesh>::buildCoordinates(sieveMesh, spaceDim, 
-						 coordinates);
-
-  const SieveRealGenSection& section = field.section();
-  
   const ALE::Obj<SieveMesh::label_sequence>& vertices = 
     sieveMesh->depthStratum(0);
   section->setChart(SieveMesh::real_section_type::chart_type(
@@ -179,7 +242,6 @@
   sieveMesh->allocate(section);
 
   double_array values(fiberDim);
-
   int i = 0;
   for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
        v_iter != vertices->end();
@@ -209,5 +271,39 @@
 
 } // testDimensionalize
 
+// ----------------------------------------------------------------------
+void
+pylith::topology::TestField::_buildMesh(Mesh* mesh)
+{ // _buildMesh
+  assert(0 != mesh);
 
+  const ALE::Obj<SieveMesh>& sieveMesh = mesh->sieveMesh();
+
+  ALE::Obj<SieveMesh::sieve_type> sieve = 
+    new SieveMesh::sieve_type(sieveMesh->comm());
+  CPPUNIT_ASSERT(!sieve.isNull());
+
+  ALE::Obj<ALE::Mesh::sieve_type> s = 
+    new ALE::Mesh::sieve_type(sieve->comm(), sieve->debug());
+  
+  const int cellDim = _TestField::cellDim;
+  const int ncells = _TestField::ncells;
+  const int* cells = _TestField::cells;
+  const int nvertices = _TestField::nvertices;
+  const int ncorners = _TestField::ncorners;
+  const int spaceDim = _TestField::spaceDim;
+  const double* coordinates = _TestField::coordinates;
+  const bool interpolate = false;
+  ALE::SieveBuilder<ALE::Mesh>::buildTopology(s, cellDim, ncells, (int*) cells,
+					      nvertices, interpolate, 
+					      ncorners);
+  std::map<SieveMesh::point_type,SieveMesh::point_type> renumbering;
+  ALE::ISieveConverter::convertSieve(*s, *sieve, renumbering);
+  sieveMesh->setSieve(sieve);
+  sieveMesh->stratify();
+  ALE::SieveBuilder<SieveMesh>::buildCoordinates(sieveMesh, spaceDim, 
+						 coordinates);
+
+} // _buildMesh
+
 // End of file 

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestField.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestField.hh	2008-12-04 21:27:35 UTC (rev 13462)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestField.hh	2008-12-04 21:28:45 UTC (rev 13463)
@@ -29,6 +29,7 @@
     class TestField;
 
     class Field;
+    class Mesh;
   } // topology
 } // pylith
 
@@ -47,6 +48,8 @@
   CPPUNIT_TEST( testSpaceDim );
   CPPUNIT_TEST( testScale );
   CPPUNIT_TEST( testAddDimensionOkay );
+  CPPUNIT_TEST( testCopyLayout );
+  CPPUNIT_TEST( testClear );
   CPPUNIT_TEST( testDimensionalize );
 
   CPPUNIT_TEST_SUITE_END();
@@ -75,9 +78,24 @@
   /// Test addDimensionOkay().
   void testAddDimensionOkay(void);
 
+  /// Test copyLayout().
+  void testCopyLayout(void);
+
+  /// Test clear().
+  void testClear(void);
+
   /// Test dimensionalize().
   void testDimensionalize(void);
 
+// PRIVATE METHODS /////////////////////////////////////////////////////
+private :
+
+  /** Build mesh.
+   *
+   * @param mesh Finite-element mesh.
+   */
+  void _buildMesh(Mesh* mesh);
+
 }; // class TestField
 
 #endif // pylith_topology_testfield_hh

Added: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldUniform.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldUniform.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldUniform.cc	2008-12-04 21:28:45 UTC (rev 13463)
@@ -0,0 +1,151 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestFieldUniform.hh" // Implementation of class methods
+#include "pylith/topology/FieldUniform.hh" // USES FieldUniform
+
+#include "pylith/topology/Mesh.hh" // USES Mesh
+#include "pylith/utils/array.hh" // USES double_array
+
+#include "spatialdata/geocoords/CSCart.hh" // USES CSCart
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::topology::TestFieldUniform );
+
+// ----------------------------------------------------------------------
+namespace pylith {
+  namespace topology {
+    namespace _TestFieldUniform {
+      const int spaceDim = 2;
+      const int cellDim = 2;
+      const int nvertices = 4;
+      const int ncells = 1;
+      const int ncorners = 4;
+      const int cells[] = { 0, 1, 2, 3 };
+      const double coordinates[] = {
+	0.0, 0.0,
+	1.0, 0.0,
+	0.0, 1.0,
+	1.0, 1.0,
+      };
+    } // _TestFieldUniform
+  } // topology
+} // pylith
+
+// ----------------------------------------------------------------------
+// Test constructor.
+void
+pylith::topology::TestFieldUniform::testConstructor(void)
+{ // testConstructor
+  Mesh mesh;
+  const int fiberDim = 4;
+  FieldUniform field(mesh.sieveMesh(), fiberDim);
+
+  CPPUNIT_ASSERT(!field._mesh.isNull());
+  CPPUNIT_ASSERT_EQUAL(fiberDim, field._fiberDim);
+} // testConstructor
+
+// ----------------------------------------------------------------------
+// Test createSection() with points.
+void
+pylith::topology::TestFieldUniform::testCreateSectionPoints(void)
+{ // testCreateSectionPoints
+  const int fiberDim = 3;
+    
+  Mesh mesh;
+  _buildMesh(&mesh);
+  const ALE::Obj<SieveMesh>& sieveMesh = mesh.sieveMesh();
+  const ALE::Obj<SieveMesh::label_sequence>& vertices = 
+    sieveMesh->depthStratum(0);
+
+  FieldUniform field(sieveMesh, fiberDim);
+  field.createSection(vertices);
+
+  const ALE::Obj<SieveRealSection>& section = field.section();
+  for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter)
+    CPPUNIT_ASSERT_EQUAL(fiberDim, section->getFiberDimension(*v_iter));
+} // testCreateSectionPoints
+
+// ----------------------------------------------------------------------
+// Test createSection() with chart.
+void
+pylith::topology::TestFieldUniform::testCreateSectionChart(void)
+{ // testCreateSectionChart
+  const int fiberDim = 2;
+    
+  Mesh mesh;
+  _buildMesh(&mesh);
+  const ALE::Obj<SieveMesh>& sieveMesh = mesh.sieveMesh();
+  const ALE::Obj<SieveMesh::label_sequence>& vertices = 
+    sieveMesh->depthStratum(0);
+
+  // Create field with to use to create new field
+  FieldUniform fieldSrc(sieveMesh, fiberDim);
+  { // Setup source field
+    const ALE::Obj<SieveRealSection>& section = fieldSrc.section();
+    section->setChart(SieveMesh::real_section_type::chart_type(
+		  *std::min_element(vertices->begin(), vertices->end()),
+		  *std::max_element(vertices->begin(), vertices->end())+1));
+    section->setFiberDimension(vertices, fiberDim);
+    sieveMesh->allocate(section);
+  } // Setup source field
+
+  FieldUniform field(sieveMesh, fiberDim);
+  field.createSection(fieldSrc.section()->getChart());
+
+  const ALE::Obj<SieveRealSection>& section = field.section();
+  for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter)
+    CPPUNIT_ASSERT_EQUAL(fiberDim, section->getFiberDimension(*v_iter));
+} // testCreateSectionChart
+
+// ----------------------------------------------------------------------
+void
+pylith::topology::TestFieldUniform::_buildMesh(Mesh* mesh)
+{ // _buildMesh
+  assert(0 != mesh);
+
+  const ALE::Obj<SieveMesh>& sieveMesh = mesh->sieveMesh();
+
+  ALE::Obj<SieveMesh::sieve_type> sieve = 
+    new SieveMesh::sieve_type(sieveMesh->comm());
+  CPPUNIT_ASSERT(!sieve.isNull());
+
+  ALE::Obj<ALE::Mesh::sieve_type> s = 
+    new ALE::Mesh::sieve_type(sieve->comm(), sieve->debug());
+  
+  const int cellDim = _TestFieldUniform::cellDim;
+  const int ncells = _TestFieldUniform::ncells;
+  const int* cells = _TestFieldUniform::cells;
+  const int nvertices = _TestFieldUniform::nvertices;
+  const int ncorners = _TestFieldUniform::ncorners;
+  const int spaceDim = _TestFieldUniform::spaceDim;
+  const double* coordinates = _TestFieldUniform::coordinates;
+  const bool interpolate = false;
+  ALE::SieveBuilder<ALE::Mesh>::buildTopology(s, cellDim, ncells, (int*) cells,
+					      nvertices, interpolate, 
+					      ncorners);
+  std::map<SieveMesh::point_type,SieveMesh::point_type> renumbering;
+  ALE::ISieveConverter::convertSieve(*s, *sieve, renumbering);
+  sieveMesh->setSieve(sieve);
+  sieveMesh->stratify();
+  ALE::SieveBuilder<SieveMesh>::buildCoordinates(sieveMesh, spaceDim, 
+						 coordinates);
+
+} // _buildMesh
+
+// End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldUniform.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldUniform.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldUniform.hh	2008-12-04 21:28:45 UTC (rev 13463)
@@ -0,0 +1,76 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/topology/TestFieldUniform.hh
+ *
+ * @brief C++ unit testing for FieldUniform.
+ */
+
+#if !defined(pylith_topology_testfielduniform_hh)
+#define pylith_topology_testfielduniform_hh
+
+// Include directives ---------------------------------------------------
+#include <cppunit/extensions/HelperMacros.h>
+
+// Forward declarations -------------------------------------------------
+/// Namespace for pylith package
+namespace pylith {
+  namespace topology {
+    class TestFieldUniform;
+
+    class FieldUniform;
+    class Mesh;
+  } // topology
+} // pylith
+
+// TestFieldUniform -------------------------------------------------------------
+/// C++ unit testing for FieldUniform.
+class pylith::topology::TestFieldUniform : public CppUnit::TestFixture
+{ // class TestFieldUniform
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestFieldUniform );
+
+  CPPUNIT_TEST( testConstructor );
+  CPPUNIT_TEST( testCreateSectionPoints );
+  CPPUNIT_TEST( testCreateSectionChart );
+
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Test constructor.
+  void testConstructor(void);
+
+  /// Test createSection() with points.
+  void testCreateSectionPoints(void);
+
+  /// Test createSection() with chart.
+  void testCreateSectionChart(void);
+
+// PRIVATE METHODS /////////////////////////////////////////////////////
+private :
+
+  /** Build mesh.
+   *
+   * @param mesh Finite-element mesh.
+   */
+  void _buildMesh(Mesh* mesh);
+
+}; // class TestFieldUniform
+
+#endif // pylith_topology_testfielduniform_hh
+
+
+// End of file 



More information about the CIG-COMMITS mailing list