[cig-commits] r15092 - in short/3D/PyLith/trunk/unittests/libtests: feassemble topology

brad at geodynamics.org brad at geodynamics.org
Sun May 31 14:04:00 PDT 2009


Author: brad
Date: 2009-05-31 14:03:59 -0700 (Sun, 31 May 2009)
New Revision: 15092

Modified:
   short/3D/PyLith/trunk/unittests/libtests/feassemble/TestIntegrator.cc
   short/3D/PyLith/trunk/unittests/libtests/feassemble/TestIntegrator.hh
   short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.cc
   short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.hh
Log:
Added some unit tests for field split.

Modified: short/3D/PyLith/trunk/unittests/libtests/feassemble/TestIntegrator.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/feassemble/TestIntegrator.cc	2009-05-31 03:27:40 UTC (rev 15091)
+++ short/3D/PyLith/trunk/unittests/libtests/feassemble/TestIntegrator.cc	2009-05-31 21:03:59 UTC (rev 15092)
@@ -185,6 +185,20 @@
 } // testResetCellMatrix
 
 // ----------------------------------------------------------------------
+// Test splitFields().
+void
+pylith::feassemble::TestIntegrator::testSplitFields(void)
+{ // testSplitFields
+
+  topology::Mesh mesh;
+  topology::Field<topology::Mesh> field(mesh);
+  
+  ElasticityExplicit integrator;
+  integrator.splitFields(&field);
+  // Expect nothing to happen
+} // testSplitFields
+
+// ----------------------------------------------------------------------
 // Set quadrature information.
 void
 pylith::feassemble::TestIntegrator::_initQuadrature(

Modified: short/3D/PyLith/trunk/unittests/libtests/feassemble/TestIntegrator.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/feassemble/TestIntegrator.hh	2009-05-31 03:27:40 UTC (rev 15091)
+++ short/3D/PyLith/trunk/unittests/libtests/feassemble/TestIntegrator.hh	2009-05-31 21:03:59 UTC (rev 15092)
@@ -50,6 +50,7 @@
   CPPUNIT_TEST( testResetCellVector );
   CPPUNIT_TEST( testInitCellMatrix );
   CPPUNIT_TEST( testResetCellMatrix );
+  CPPUNIT_TEST( testSplitFields );
 
   CPPUNIT_TEST_SUITE_END();
 
@@ -83,6 +84,9 @@
   /// Test _resetCellMatrix().
   void testResetCellMatrix(void);
 
+  /// Test splitFields().
+  void testSplitFields(void);
+
   // PRIVATE METHODS /////////////////////////////////////////////////////
 private :
 

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.cc	2009-05-31 03:27:40 UTC (rev 15091)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.cc	2009-05-31 21:03:59 UTC (rev 15092)
@@ -899,7 +899,144 @@
 } // testScatterVectorToSection
 
 // ----------------------------------------------------------------------
+// Test splitDefault().
 void
+pylith::topology::TestFieldMesh::testSplitDefault(void)
+{ // testSplitDefault
+  const int fiberDim = 2;
+  const int numFibrations = 2;
+  const int nconstraints[] = { 0, 2, 1, 3 };
+  const int constraints[] = {
+              // 0
+    0, 2,     // 1
+    2,        // 2
+    0, 1, 2,  // 3
+  };
+    
+  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());
+
+  // Create field with atlas to use to create new field
+  Field<Mesh> fieldSrc(mesh);
+  { // Setup source field
+    fieldSrc.newSection(Field<Mesh>::VERTICES_FIELD, fiberDim);
+    fieldSrc.splitDefault();
+    const ALE::Obj<Mesh::RealSection>& section = fieldSrc.section();
+    CPPUNIT_ASSERT(!section.isNull());
+    const ALE::Obj<Mesh::RealSection>& sectionSplit =
+      section->getFibration(0);
+    CPPUNIT_ASSERT(!sectionSplit.isNull());
+    int iV=0;
+    for (Mesh::SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+	 v_iter != vertices->end();
+	 ++v_iter, ++iV) {
+      section->addConstraintDimension(*v_iter, nconstraints[iV]);
+      sectionSplit->addConstraintDimension(*v_iter, nconstraints[iV]);
+    } // for
+    fieldSrc.allocate();
+
+    int index = 0;
+    int i = 0;
+    for (Mesh::SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+	 v_iter != vertices->end();
+	 ++v_iter, index += nconstraints[i++]) {
+      section->setConstraintDof(*v_iter, &constraints[index]);
+      sectionSplit->setConstraintDof(*v_iter, &constraints[index]);
+    } // for
+  } // Setup source field
+
+  const ALE::Obj<Mesh::RealSection>& section = fieldSrc.section();
+  CPPUNIT_ASSERT(!section.isNull());
+  CPPUNIT_ASSERT_EQUAL(numFibrations, section->getNumSpaces());
+  const ALE::Obj<Mesh::RealSection>& sectionSplit = section->getFibration(0);
+  CPPUNIT_ASSERT(!sectionSplit.isNull());
+  section->view("FULL FIELD");
+  sectionSplit->view("FIBRATION 0");
+
+  CPPUNIT_ASSERT(!vertices.isNull());
+  int iV = 0;
+  for (Mesh::SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter) {
+    CPPUNIT_ASSERT_EQUAL(fiberDim, sectionSplit->getFiberDimension(*v_iter));
+    CPPUNIT_ASSERT_EQUAL(nconstraints[iV++], 
+			 sectionSplit->getConstraintDimension(*v_iter));
+  } // for
+} // testSplitDefault
+
+// ----------------------------------------------------------------------
+// Test cloneSection() with split field.
+void
+pylith::topology::TestFieldMesh::testCloneSectionSplit(void)
+{ // testCloneSectionSplit
+  const int fiberDim = 3;
+  const int nconstraints[] = { 0, 2, 1, 3 };
+  const int constraints[] = {
+              // 0
+    0, 2,     // 1
+    2,        // 2
+    0, 1, 2,  // 3
+  };
+  const int numFibrations = 2;
+    
+  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());
+
+  // Create field with atlas to use to create new field
+  Field<Mesh> fieldSrc(mesh);
+  { // 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;
+    for (Mesh::SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+	 v_iter != vertices->end();
+	 ++v_iter)
+      section->addConstraintDimension(*v_iter, nconstraints[iV++]);
+    fieldSrc.splitDefault();
+    fieldSrc.allocate();
+
+    int index = 0;
+    int i = 0;
+    for (Mesh::SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+	 v_iter != vertices->end();
+	 ++v_iter, index += nconstraints[i++])
+      section->setConstraintDof(*v_iter, &constraints[index]);
+  } // Setup source field
+
+  Field<Mesh> field(mesh);
+  field.cloneSection(fieldSrc);
+  const ALE::Obj<Mesh::RealSection>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
+  CPPUNIT_ASSERT_EQUAL(numFibrations, section->getNumSpaces());
+  const ALE::Obj<Mesh::RealSection>& sectionSplit = section->getFibration(0);
+  CPPUNIT_ASSERT(!sectionSplit.isNull());
+  section->view("FULL FIELD");
+  sectionSplit->view("FIBRATION 0");
+  int iV = 0;
+  for (Mesh::SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter) {
+    CPPUNIT_ASSERT_EQUAL(fiberDim, sectionSplit->getFiberDimension(*v_iter));
+    CPPUNIT_ASSERT_EQUAL(nconstraints[iV++], 
+			 sectionSplit->getConstraintDimension(*v_iter));
+  } // for
+} // testCloneSectionSplit
+
+// ----------------------------------------------------------------------
+void
 pylith::topology::TestFieldMesh::_buildMesh(Mesh* mesh)
 { // _buildMesh
   assert(0 != mesh);

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.hh	2009-05-31 03:27:40 UTC (rev 15091)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.hh	2009-05-31 21:03:59 UTC (rev 15092)
@@ -65,6 +65,8 @@
   CPPUNIT_TEST( testCreateScatter );
   CPPUNIT_TEST( testScatterSectionToVector );
   CPPUNIT_TEST( testScatterVectorToSection );
+  CPPUNIT_TEST( testSplitDefault );
+  CPPUNIT_TEST( testCloneSectionSplit );
 
   CPPUNIT_TEST_SUITE_END();
 
@@ -149,6 +151,12 @@
   /// Test scatterVectorToSection().
   void testScatterVectorToSection(void);
 
+  /// Test splitDefault().
+  void testSplitDefault(void);
+
+  /// Test cloneSection() with split field.
+  void testCloneSectionSplit(void);
+
 // PRIVATE METHODS /////////////////////////////////////////////////////
 private :
 



More information about the CIG-COMMITS mailing list