[cig-commits] r14387 - in short/3D/PyLith/branches/pylith-swig: . libsrc/topology unittests/libtests/topology

brad at geodynamics.org brad at geodynamics.org
Wed Mar 18 17:30:11 PDT 2009


Author: brad
Date: 2009-03-18 17:30:11 -0700 (Wed, 18 Mar 2009)
New Revision: 14387

Modified:
   short/3D/PyLith/branches/pylith-swig/TODO
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.cc
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.hh
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldMesh.cc
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldMesh.hh
Log:
Worked on scatter stuff for Field and updating C++ unit tests.

Modified: short/3D/PyLith/branches/pylith-swig/TODO
===================================================================
--- short/3D/PyLith/branches/pylith-swig/TODO	2009-03-18 23:45:50 UTC (rev 14386)
+++ short/3D/PyLith/branches/pylith-swig/TODO	2009-03-19 00:30:11 UTC (rev 14387)
@@ -5,14 +5,15 @@
 0. SWIG conversion
 
     libsrc/topology/Field
-      createScatter() [use ALE::Obj<PetscVecScatter> to share scatter]
+      createScatter()
       When copying layout, copy VecScatter. [Fields]
-      scatterSectionToVector()
-      scatterVectorToSection()
 
     libtests/topology/Field
       createVector()
       vector()
+      createScatter()
+      scatterVectorToSection()
+      scatterSectionToVector()
 
   Cleanup logging. Constraints and Integrators should log at the C++
   level using the C++ EventLogger. Add finer grain logging at C++

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.cc	2009-03-18 23:45:50 UTC (rev 14386)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.cc	2009-03-19 00:30:11 UTC (rev 14387)
@@ -32,6 +32,7 @@
   _name("unknown"),
   _mesh(mesh),
   _vector(0),
+  _scatter(0),
   _vecFieldType(OTHER),
   _dimensionsOkay(false)
 { // constructor
@@ -42,10 +43,16 @@
 template<typename mesh_type>
 pylith::topology::Field<mesh_type>::~Field(void)
 { // destructor
+  PetscErrorCode err = 0;
   if (0 != _vector) {
-    PetscErrorCode err = VecDestroy(_vector); _vector = 0;
+    err = VecDestroy(_vector); _vector = 0;
     CHECK_PETSC_ERROR(err);
   } // if
+
+  if (0 != _scatter) {
+    err = VecScatterDestroy(_scatter); _scatter = 0;
+    CHECK_PETSC_ERROR(err);
+  } // if
 } // destructor
 
 // ----------------------------------------------------------------------
@@ -154,6 +161,12 @@
     _section->setAtlas(srcSection->getAtlas());
     _section->allocateStorage();
     _section->setBC(srcSection->getBC());
+
+    if (0 != src._scatter) {
+      _scatter = src._scatter;
+      PetscErrorCode err = PetscObjectReference((PetscObject) _scatter);
+      CHECK_PETSC_ERROR(err);
+    } // if
   } // if
 } // newSection
 
@@ -427,6 +440,9 @@
 void
 pylith::topology::Field<mesh_type>::createScatter(void)
 { // createScatter
+  assert(!_section.isNull());
+  assert(!_mesh.sieveMesh().isNull());
+
   PetscErrorCode err = 0;
   if (0 != _scatter) {
     err = VecScatterDestroy(_scatter); _scatter = 0;
@@ -444,19 +460,32 @@
 void
 pylith::topology::Field<mesh_type>::scatterSectionToVector(void)
 { // scatterSectionToVector
-  assert(0 != _scatter);
   assert(!_section.isNull());
-  assert(0 != _vector);
 
+  if (0 == _scatter)
+    createScatter();
+  if (0 == _vector)
+    createVector();
+
   PetscErrorCode err = 0;
   PetscVec localVec = 0;
   err = VecCreateSeqWithArray(PETSC_COMM_SELF,
 			      _section->sizeWithBC(), _section->restrictSpace(),
 			      &localVec); CHECK_PETSC_ERROR(err);
+  std::cout << "BEFORE LOCALVEC: " << std::endl;
+  VecView(localVec, PETSC_VIEWER_STDOUT_SELF);
+  std::cout << "BEFORE _VECTOR: " << std::endl;
+  VecView(_vector, PETSC_VIEWER_STDOUT_SELF);
   err = VecScatterBegin(_scatter, _vector, localVec, 
 			INSERT_VALUES, SCATTER_REVERSE); CHECK_PETSC_ERROR(err);
   err = VecScatterEnd(_scatter, _vector, localVec,
 		      INSERT_VALUES, SCATTER_REVERSE); CHECK_PETSC_ERROR(err);
+
+  std::cout << "AFTER LOCALVEC: " << std::endl;
+  VecView(localVec, PETSC_VIEWER_STDOUT_SELF);
+  std::cout << "AFTER _VECTOR: " << std::endl;
+  VecView(_vector, PETSC_VIEWER_STDOUT_SELF);
+
   err = VecDestroy(localVec); CHECK_PETSC_ERROR(err);
 } // scatterSectionToVector
 
@@ -467,10 +496,13 @@
 void
 pylith::topology::Field<mesh_type>::scatterVectorToSection(void)
 { // scatterVectorToSection
-  assert(0 != _scatter);
   assert(!_section.isNull());
-  assert(0 != _vector);
 
+  if (0 == _scatter)
+    createScatter();
+  if (0 == _vector)
+    createVector();
+
   PetscErrorCode err = 0;
   PetscVec localVec = 0;
   err = VecCreateSeqWithArray(PETSC_COMM_SELF,

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.hh	2009-03-18 23:45:50 UTC (rev 14386)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.hh	2009-03-19 00:30:11 UTC (rev 14387)
@@ -222,11 +222,11 @@
   void createScatter(void);
 
   /// Scatter section information across processors to update the
-  ///  PETSc vector view of the field.
+  /// PETSc vector view of the field.
   void scatterSectionToVector(void);
 
   /// Scatter PETSc vector information across processors to update the
-  /// section view of the field.
+  /// Sieve section view of the field.
   void scatterVectorToSection(void);
 
 // PRIVATE MEMBERS //////////////////////////////////////////////////////

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldMesh.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldMesh.cc	2009-03-18 23:45:50 UTC (rev 14386)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldMesh.cc	2009-03-19 00:30:11 UTC (rev 14387)
@@ -97,7 +97,6 @@
 { // testNewSection
   Mesh mesh;
   _buildMesh(&mesh);
-  const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
 
   Field<Mesh> field(mesh);
   field.newSection();
@@ -115,10 +114,12 @@
   Mesh mesh;
   _buildMesh(&mesh);
   const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
 
   Field<Mesh> field(mesh);
   const ALE::Obj<Mesh::SieveMesh::label_sequence>& vertices = 
     sieveMesh->depthStratum(0);
+  CPPUNIT_ASSERT(!vertices.isNull());
   field.newSection(vertices, fiberDim);
   const ALE::Obj<Mesh::RealSection>& section = field.section();
   CPPUNIT_ASSERT(!section.isNull());
@@ -140,6 +141,7 @@
   Mesh mesh;
   _buildMesh(&mesh);
   const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
 
   Field<Mesh> field(mesh);
   field.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
@@ -172,6 +174,7 @@
   Mesh mesh;
   _buildMesh(&mesh);
   const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
 
   // Create field with atlas to use to create new field
   Field<Mesh> fieldSrc(mesh);
@@ -183,6 +186,7 @@
   Field<Mesh> field(mesh);
   field.newSection(chart, fiberDim);
   const ALE::Obj<Mesh::RealSection>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
   const ALE::Obj<Mesh::SieveMesh::label_sequence>& vertices = 
     sieveMesh->depthStratum(0);
   CPPUNIT_ASSERT(!vertices.isNull());
@@ -209,6 +213,7 @@
   Mesh mesh;
   _buildMesh(&mesh);
   const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
 
   const ALE::Obj<Mesh::SieveMesh::label_sequence>& vertices = 
     sieveMesh->depthStratum(0);
@@ -219,6 +224,7 @@
   { // Setup source field
     fieldSrc.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
     const ALE::Obj<Mesh::RealSection>& section = fieldSrc.section();
+    CPPUNIT_ASSERT(!section.isNull());
     int iV=0;
 
     CPPUNIT_ASSERT(!vertices.isNull());
@@ -233,6 +239,7 @@
   Field<Mesh> field(mesh);
   field.newSection(fieldSrc);
   const ALE::Obj<Mesh::RealSection>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
   int iV = 0;
   for (Mesh::SieveMesh::label_sequence::iterator v_iter=vertices->begin();
        v_iter != vertices->end();
@@ -279,13 +286,16 @@
   Mesh mesh;
   _buildMesh(&mesh);
   const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
   const ALE::Obj<Mesh::SieveMesh::label_sequence>& vertices = 
     sieveMesh->depthStratum(0);
+  CPPUNIT_ASSERT(!vertices.isNull());
 
   Field<Mesh> field(mesh);
   field.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
   field.allocate();
   const ALE::Obj<Mesh::RealSection>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
 
   double_array values(fiberDim);
   int i = 0;
@@ -326,13 +336,16 @@
   Mesh mesh;
   _buildMesh(&mesh);
   const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
   const ALE::Obj<Mesh::SieveMesh::label_sequence>& vertices = 
     sieveMesh->depthStratum(0);
+  CPPUNIT_ASSERT(!vertices.isNull());
 
   Field<Mesh> field(mesh);
   field.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
   field.allocate();
   const ALE::Obj<Mesh::RealSection>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
 
   double_array values(fiberDim);
   int i = 0;
@@ -374,13 +387,16 @@
   Mesh mesh;
   _buildMesh(&mesh);
   const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
   const ALE::Obj<Mesh::SieveMesh::label_sequence>& vertices = 
     sieveMesh->depthStratum(0);
+  CPPUNIT_ASSERT(!vertices.isNull());
 
   Field<Mesh> field(mesh);
   field.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
   field.allocate();
   const ALE::Obj<Mesh::RealSection>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
 
   double_array values(fiberDim);
   int i = 0;
@@ -424,14 +440,17 @@
   Mesh mesh;
   _buildMesh(&mesh);
   const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
   const ALE::Obj<Mesh::SieveMesh::label_sequence>& vertices = 
     sieveMesh->depthStratum(0);
+  CPPUNIT_ASSERT(!vertices.isNull());
 
   Field<Mesh> fieldSrc(mesh);
   { // Setup source field
     fieldSrc.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
     fieldSrc.allocate();
     const ALE::Obj<Mesh::RealSection>& section = fieldSrc.section();
+    CPPUNIT_ASSERT(!section.isNull());
     
     double_array values(fiberDim);
     int i = 0;
@@ -448,6 +467,7 @@
   field.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
   field.allocate();
   const ALE::Obj<Mesh::RealSection>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
 
   field.copy(fieldSrc);
 
@@ -487,14 +507,17 @@
   Mesh mesh;
   _buildMesh(&mesh);
   const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
   const ALE::Obj<Mesh::SieveMesh::label_sequence>& vertices = 
     sieveMesh->depthStratum(0);
+  CPPUNIT_ASSERT(!vertices.isNull());
 
   Field<Mesh> fieldSrc(mesh);
   { // Setup source field
     fieldSrc.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
     fieldSrc.allocate();
     const ALE::Obj<Mesh::RealSection>& section = fieldSrc.section();
+    CPPUNIT_ASSERT(!section.isNull());
     
     double_array values(fiberDim);
     int i = 0;
@@ -511,6 +534,7 @@
   field.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
   field.allocate();
   const ALE::Obj<Mesh::RealSection>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
   { // Setup destination field
 
     double_array values(fiberDim);
@@ -558,12 +582,15 @@
   Mesh mesh;
   _buildMesh(&mesh);
   const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
   Field<Mesh> field(mesh);
   field.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
   field.allocate();
   const ALE::Obj<Mesh::RealSection>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
   const ALE::Obj<Mesh::SieveMesh::label_sequence>& vertices = 
     sieveMesh->depthStratum(0);
+  CPPUNIT_ASSERT(!vertices.isNull());
 
   double_array values(fiberDim);
   int i = 0;
@@ -610,12 +637,15 @@
   Mesh mesh;
   _buildMesh(&mesh);
   const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
   Field<Mesh> field(mesh);
   field.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
   field.allocate();
   const ALE::Obj<Mesh::RealSection>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
   const ALE::Obj<Mesh::SieveMesh::label_sequence>& vertices = 
     sieveMesh->depthStratum(0);
+  CPPUNIT_ASSERT(!vertices.isNull());
 
   double_array values(fiberDim);
   int i = 0;
@@ -631,7 +661,140 @@
 } // testView
 
 // ----------------------------------------------------------------------
+// Test createVector().
 void
+pylith::topology::TestFieldMesh::testCreateVector(void)
+{ // testCreateVector
+  const int fiberDim = 3;
+
+  Mesh mesh;
+  _buildMesh(&mesh);
+  const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
+  Field<Mesh> field(mesh);
+  field.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
+  field.allocate();
+  
+  const ALE::Obj<Mesh::SieveMesh::label_sequence>& vertices = 
+    sieveMesh->depthStratum(0);
+  CPPUNIT_ASSERT(!vertices.isNull());
+  const int sizeE = vertices->size() * fiberDim;
+
+  field.createVector();
+
+  CPPUNIT_ASSERT(0 != field._vector);
+  int size = 0;
+  VecGetSize(field._vector, &size);
+  CPPUNIT_ASSERT_EQUAL(sizeE, size);
+
+  // Make sure we can do multiple calls to createVector().
+  field.createVector();
+  CPPUNIT_ASSERT(0 != field._vector);
+} // testCreateVector
+
+// ----------------------------------------------------------------------
+// Test vector().
+void
+pylith::topology::TestFieldMesh::testVector(void)
+{ // testVector
+  const int fiberDim = 3;
+
+  Mesh mesh;
+  _buildMesh(&mesh);
+  Field<Mesh> field(mesh);
+  field.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
+  field.allocate();
+  
+  CPPUNIT_ASSERT(0 == field._vector);
+  field.createVector();
+  CPPUNIT_ASSERT(0 != field._vector);
+  const PetscVec vector = field.vector();
+  CPPUNIT_ASSERT_EQUAL(field._vector, vector);
+} // testVector
+
+// ----------------------------------------------------------------------
+// Test createScatter().
+void
+pylith::topology::TestFieldMesh::testCreateScatter(void)
+{ // testCreateScatter
+  const int fiberDim = 3;
+
+  Mesh mesh;
+  _buildMesh(&mesh);
+  Field<Mesh> field(mesh);
+  field.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
+  field.allocate();
+  
+  CPPUNIT_ASSERT(0 == field._scatter);
+  field.createScatter();
+  CPPUNIT_ASSERT(0 != field._scatter);
+
+  // Make sure we can do multiple calls to createScatter().
+  field.createScatter();
+  CPPUNIT_ASSERT(0 != field._scatter);
+} // testCreateScatter
+
+// ----------------------------------------------------------------------
+// Test scatterSectionToVector().
+void
+pylith::topology::TestFieldMesh::testScatterSectionToVector(void)
+{ // testScatterSectionToVector
+  const int fiberDim = 3;
+  const double valuesE[] = {
+    1.1, 2.2, 3.3,
+    1.2, 2.3, 3.4,
+    1.3, 2.4, 3.5,
+    1.4, 2.5, 3.6,
+  };
+
+  Mesh mesh;
+  _buildMesh(&mesh);
+  const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  Field<Mesh> field(mesh);
+  field.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
+  field.allocate();
+  const ALE::Obj<Mesh::RealSection>& section = field.section();
+  const ALE::Obj<Mesh::SieveMesh::label_sequence>& vertices = 
+    sieveMesh->depthStratum(0);
+
+  double_array values(fiberDim);
+  int i = 0;
+  for (Mesh::SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter) {
+    for (int iDim=0; iDim < fiberDim; ++iDim)
+      values[iDim] = valuesE[i++];
+    section->updatePoint(*v_iter, &values[0]);
+  } // for
+
+  field.scatterSectionToVector();
+  CPPUNIT_ASSERT(0 != field._vector);
+  CPPUNIT_ASSERT(0 != field._scatter);
+  const PetscVec vec = field.vector();
+  std::cout << "VEC: " << std::endl;
+  VecView(vec, PETSC_VIEWER_STDOUT_SELF);
+  int size = 0;
+  VecGetSize(vec, &size);
+  double* valuesVec = 0;
+  VecGetArray(vec, &valuesVec);
+
+  const double tolerance = 1.0e-06;
+  const int sizeE = vertices->size() * fiberDim;
+  CPPUNIT_ASSERT_EQUAL(sizeE, size);
+  for (int i=0; i < sizeE; ++i)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesE[i], valuesVec[i], tolerance);
+  VecRestoreArray(vec, &valuesVec);
+} // testScatterSectionToVector
+
+// ----------------------------------------------------------------------
+// Test scatterVectorToSection().
+void
+pylith::topology::TestFieldMesh::testScatterVectorToSection(void)
+{ // testScatterVectorToSection
+} // testScatterVectorToSection
+
+// ----------------------------------------------------------------------
+void
 pylith::topology::TestFieldMesh::_buildMesh(Mesh* mesh)
 { // _buildMesh
   assert(0 != mesh);

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldMesh.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldMesh.hh	2009-03-18 23:45:50 UTC (rev 14386)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldMesh.hh	2009-03-19 00:30:11 UTC (rev 14387)
@@ -57,6 +57,11 @@
   CPPUNIT_TEST( testOperatorAdd );
   CPPUNIT_TEST( testDimensionalize );
   CPPUNIT_TEST( testView );
+  CPPUNIT_TEST( testCreateVector );
+  CPPUNIT_TEST( testVector );
+  CPPUNIT_TEST( testCreateScatter );
+  CPPUNIT_TEST( testScatterSectionToVector );
+  CPPUNIT_TEST( testScatterVectorToSection );
 
   CPPUNIT_TEST_SUITE_END();
 
@@ -114,6 +119,21 @@
   /// Test view().
   void testView(void);
 
+  /// Test createVector().
+  void testCreateVector(void);
+
+  /// Test vector().
+  void testVector(void);
+
+  /// Test createScatter().
+  void testCreateScatter(void);
+
+  /// Test scatterSectionToVector().
+  void testScatterSectionToVector(void);
+
+  /// Test scatterVectorToSection().
+  void testScatterVectorToSection(void);
+
 // PRIVATE METHODS /////////////////////////////////////////////////////
 private :
 



More information about the CIG-COMMITS mailing list