[cig-commits] r16628 - in short/3D/PyLith/trunk: . libsrc/feassemble unittests/libtests/feassemble

brad at geodynamics.org brad at geodynamics.org
Tue May 4 16:01:00 PDT 2010


Author: brad
Date: 2010-05-04 16:00:59 -0700 (Tue, 04 May 2010)
New Revision: 16628

Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/libsrc/feassemble/ElasticityExplicitTet4.cc
   short/3D/PyLith/trunk/unittests/libtests/feassemble/TestElasticityExplicitTet4.cc
   short/3D/PyLith/trunk/unittests/libtests/feassemble/TestElasticityExplicitTet4.hh
Log:
Added integrateResidualLumped() unit test for ElasticityExplicitTet4. Fixed bug exposed by unit test.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2010-05-04 21:07:28 UTC (rev 16627)
+++ short/3D/PyLith/trunk/TODO	2010-05-04 23:00:59 UTC (rev 16628)
@@ -99,9 +99,6 @@
 
 Unit tests
 
-  ElasticityExplicitTet4
-    integrateResidualLumped()
-
   AbsorbingDampers
     integrateResidualLumped()
   FaultCohesiveDyn

Modified: short/3D/PyLith/trunk/libsrc/feassemble/ElasticityExplicitTet4.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/feassemble/ElasticityExplicitTet4.cc	2010-05-04 21:07:28 UTC (rev 16627)
+++ short/3D/PyLith/trunk/libsrc/feassemble/ElasticityExplicitTet4.cc	2010-05-04 23:00:59 UTC (rev 16628)
@@ -523,12 +523,12 @@
     _logger->eventBegin(stateVarsEvent);
 #endif
 
+    // Get state variables for cell.
+    _material->retrievePropsAndVars(*c_iter);
+
     // Get density at quadrature points for this cell
     const double_array& density = _material->calcDensity();
 
-    // Get state variables for cell.
-    _material->retrievePropsAndVars(*c_iter);
-
 #if defined(DETAILED_EVENT_LOGGING)
     _logger->eventEnd(stateVarsEvent);
     _logger->eventBegin(computeEvent);
@@ -634,18 +634,30 @@
 
     assert(_cellVector.size() == 12);
     assert(stressCell.size() == 6);
-    _cellVector[0] -= (d1*stressCell[5]+c1*stressCell[3]+b1*stressCell[0]) * volume;
-    _cellVector[1] -= (d1*stressCell[4]+b1*stressCell[3]+c1*stressCell[1]) * volume;
-    _cellVector[2] -= (b1*stressCell[5]+c1*stressCell[4]+d1*stressCell[2]) * volume;
-    _cellVector[3] -= (d2*stressCell[5]+c2*stressCell[3]+b2*stressCell[0]) * volume;
-    _cellVector[4] -= (d2*stressCell[4]+b2*stressCell[3]+c2*stressCell[1]) * volume;
-    _cellVector[5] -= (b2*stressCell[5]+c2*stressCell[4]+d2*stressCell[2]) * volume;
-    _cellVector[6] -= (d3*stressCell[5]+c3*stressCell[3]+b3*stressCell[0]) * volume;
-    _cellVector[7] -= (d3*stressCell[4]+b3*stressCell[3]+c3*stressCell[1]) * volume;
-    _cellVector[8] -= (b3*stressCell[5]+c3*stressCell[4]+d3*stressCell[2]) * volume;
-    _cellVector[9] -= (d4*stressCell[5]+c4*stressCell[3]+b4*stressCell[0]) * volume;
-    _cellVector[10] -= (d4*stressCell[4]+b4*stressCell[3]+c4*stressCell[1]) * volume;
-    _cellVector[11] -= (b4*stressCell[5]+c4*stressCell[4]+d4*stressCell[2]) * volume;
+    _cellVector[0] -= 
+      (d1*stressCell[5]+c1*stressCell[3]+b1*stressCell[0]) * volume;
+    _cellVector[1] -= 
+      (d1*stressCell[4]+b1*stressCell[3]+c1*stressCell[1]) * volume;
+    _cellVector[2] -= 
+      (b1*stressCell[5]+c1*stressCell[4]+d1*stressCell[2]) * volume;
+    _cellVector[3] -= 
+      (d2*stressCell[5]+c2*stressCell[3]+b2*stressCell[0]) * volume;
+    _cellVector[4] -= 
+      (d2*stressCell[4]+b2*stressCell[3]+c2*stressCell[1]) * volume;
+    _cellVector[5] -= 
+      (b2*stressCell[5]+c2*stressCell[4]+d2*stressCell[2]) * volume;
+    _cellVector[6] -= 
+      (d3*stressCell[5]+c3*stressCell[3]+b3*stressCell[0]) * volume;
+    _cellVector[7] -= 
+      (d3*stressCell[4]+b3*stressCell[3]+c3*stressCell[1]) * volume;
+    _cellVector[8] -= 
+      (b3*stressCell[5]+c3*stressCell[4]+d3*stressCell[2]) * volume;
+    _cellVector[9] -= 
+      (d4*stressCell[5]+c4*stressCell[3]+b4*stressCell[0]) * volume;
+    _cellVector[10] -= 
+      (d4*stressCell[4]+b4*stressCell[3]+c4*stressCell[1]) * volume;
+    _cellVector[11] -= 
+      (b4*stressCell[5]+c4*stressCell[4]+d4*stressCell[2]) * volume;
 
 #if defined(DETAILED_EVENT_LOGGING)
     PetscLogFlops(84);

Modified: short/3D/PyLith/trunk/unittests/libtests/feassemble/TestElasticityExplicitTet4.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/feassemble/TestElasticityExplicitTet4.cc	2010-05-04 21:07:28 UTC (rev 16627)
+++ short/3D/PyLith/trunk/unittests/libtests/feassemble/TestElasticityExplicitTet4.cc	2010-05-04 23:00:59 UTC (rev 16628)
@@ -207,6 +207,46 @@
 } // testIntegrateResidual
 
 // ----------------------------------------------------------------------
+// Test integrateResidual().
+void
+pylith::feassemble::TestElasticityExplicitTet4::testIntegrateResidualLumped(void)
+{ // testIntegrateResidualLumped
+  CPPUNIT_ASSERT(0 != _data);
+
+  topology::Mesh mesh;
+  ElasticityExplicitTet4 integrator;
+  topology::SolutionFields fields(mesh);
+  _initialize(&mesh, &integrator, &fields);
+
+  topology::Field<topology::Mesh>& residual = fields.get("residual");
+  const double t = 1.0;
+  integrator.integrateResidualLumped(residual, t, &fields);
+
+  const double* valsE = _data->valsResidualLumped;
+  const int sizeE = _data->spaceDim * _data->numVertices;
+
+  const ALE::Obj<RealSection>& residualSection = residual.section();
+  CPPUNIT_ASSERT(!residualSection.isNull());
+  const double* vals = residualSection->restrictSpace();
+  const int size = residualSection->sizeWithBC();
+  CPPUNIT_ASSERT_EQUAL(sizeE, size);
+
+#if 1 // DEBUGGING
+  residual.view("RESIDUAL");
+  std::cout << "EXPECTED RESIDUAL" << std::endl;
+  for (int i=0; i < size; ++i)
+    std::cout << "  " << valsE[i] << std::endl;
+#endif // DEBUGGING
+
+  const double tolerance = 1.0e-06;
+  for (int i=0; i < size; ++i)
+    if (fabs(valsE[i]) > 1.0)
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vals[i]/valsE[i], tolerance);
+    else
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(valsE[i], vals[i], tolerance);
+} // testIntegrateResidualLumped
+
+// ----------------------------------------------------------------------
 // Test integrateJacobian().
 void
 pylith::feassemble::TestElasticityExplicitTet4::testIntegrateJacobian(void)

Modified: short/3D/PyLith/trunk/unittests/libtests/feassemble/TestElasticityExplicitTet4.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/feassemble/TestElasticityExplicitTet4.hh	2010-05-04 21:07:28 UTC (rev 16627)
+++ short/3D/PyLith/trunk/unittests/libtests/feassemble/TestElasticityExplicitTet4.hh	2010-05-04 23:00:59 UTC (rev 16628)
@@ -33,7 +33,7 @@
 namespace pylith {
   namespace feassemble {
     class TestElasticityExplicitTet4;
-    class IntegratorData;
+    class ElasticityExplicitData;
   } // feassemble
 } // pylith
 
@@ -51,6 +51,7 @@
   CPPUNIT_TEST( testUseSolnIncr );
   CPPUNIT_TEST( testInitialize );
   CPPUNIT_TEST( testIntegrateResidual );
+  CPPUNIT_TEST( testIntegrateResidualLumped );
   CPPUNIT_TEST( testIntegrateJacobian );
   CPPUNIT_TEST( testIntegrateJacobianLumped );
   CPPUNIT_TEST( testUpdateStateVars );
@@ -88,6 +89,9 @@
   /// Test integrateResidual().
   void testIntegrateResidual(void);
 
+  /// Test integrateResidualLumped().
+  void testIntegrateResidualLumped(void);
+
   /// Test integrateJacobian().
   void testIntegrateJacobian(void);
 
@@ -103,7 +107,7 @@
   // PROTECTED MEMBERS //////////////////////////////////////////////////
 protected :
 
-  IntegratorData* _data; ///< Data for testing.
+  ElasticityExplicitData* _data; ///< Data for testing.
   materials::ElasticMaterial* _material; ///< Elastic material.
   Quadrature<topology::Mesh>* _quadrature; ///< Quadrature information.
   spatialdata::spatialdb::GravityField* _gravityField; ///< Gravity field.



More information about the CIG-COMMITS mailing list