[cig-commits] r15916 - in short/3D/PyLith/branches/pylith-friction: libsrc/bc unittests/libtests/bc

brad at geodynamics.org brad at geodynamics.org
Sun Nov 1 12:48:25 PST 2009


Author: brad
Date: 2009-11-01 12:48:25 -0800 (Sun, 01 Nov 2009)
New Revision: 15916

Modified:
   short/3D/PyLith/branches/pylith-friction/libsrc/bc/AbsorbingDampers.cc
   short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampers.cc
   short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampers.hh
   short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersHex8.hh
   short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersLine2.hh
   short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersQuad4.hh
   short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersTet4.hh
   short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersTri3.hh
   short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/test_bc.cc
Log:
Added C++ unit tests for integrating lumped Jacobian for AbsorbingDampers.

Modified: short/3D/PyLith/branches/pylith-friction/libsrc/bc/AbsorbingDampers.cc
===================================================================
--- short/3D/PyLith/branches/pylith-friction/libsrc/bc/AbsorbingDampers.cc	2009-10-31 22:49:45 UTC (rev 15915)
+++ short/3D/PyLith/branches/pylith-friction/libsrc/bc/AbsorbingDampers.cc	2009-11-01 20:48:25 UTC (rev 15916)
@@ -511,6 +511,10 @@
   const double dt = _dt;
   assert(dt > 0);
 
+  // Allocate matrix for cell values.
+  _initCellMatrix();
+  _initCellVector();
+
   // Get sections
   const ALE::Obj<SubRealSection>& dampersSection =
     _parameters->get("damping constants").section();
@@ -518,6 +522,7 @@
 
   const topology::Field<topology::Mesh>& solution = fields->solution();
   const ALE::Obj<SieveMesh>& sieveMesh = solution.mesh().sieveMesh();
+  assert(!sieveMesh.isNull());
   const ALE::Obj<RealSection>& solutionSection = solution.section();
   assert(!solutionSection.isNull());
 
@@ -534,9 +539,6 @@
 				coordinatesCell.size(), &coordinatesCell[0]);
 #endif
 
-  // Allocate matrix for cell values.
-  _initCellMatrix();
-
   for (SieveSubMesh::label_sequence::iterator c_iter=cellsBegin;
        c_iter != cellsEnd;
        ++c_iter) {
@@ -581,7 +583,7 @@
     
     // Assemble cell contribution into lumped matrix.
     jacobianVisitor.clear();
-    sieveMesh->updateClosure(*c_iter, jacobianVisitor);
+    sieveSubMesh->updateClosure(*c_iter, jacobianVisitor);
   } // for
 
   _needNewJacobian = false;

Modified: short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampers.cc
===================================================================
--- short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampers.cc	2009-10-31 22:49:45 UTC (rev 15915)
+++ short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampers.cc	2009-11-01 20:48:25 UTC (rev 15916)
@@ -277,7 +277,81 @@
 } // testIntegrateJacobian
 
 // ----------------------------------------------------------------------
+// Test integrateJacobianLumped().
 void
+pylith::bc::TestAbsorbingDampers::testIntegrateJacobianLumped(void)
+{ // testIntegrateJacobianLumped
+  CPPUNIT_ASSERT(0 != _data);
+
+  topology::Mesh mesh;
+  AbsorbingDampers bc;
+  topology::SolutionFields fields(mesh);
+  _initialize(&mesh, &bc, &fields);
+
+  topology::Field<topology::Mesh> jacobian(mesh);
+  jacobian.label("Jacobian");
+  jacobian.vectorFieldType(topology::FieldBase::VECTOR);
+  jacobian.newSection(topology::FieldBase::VERTICES_FIELD, _data->spaceDim);
+  jacobian.allocate();
+
+  const ALE::Obj<SieveMesh>& sieveMesh = mesh.sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
+
+  const topology::SubMesh& boundaryMesh = *bc._boundaryMesh;
+  const ALE::Obj<SieveSubMesh>& submesh = boundaryMesh.sieveMesh();
+  CPPUNIT_ASSERT(!submesh.isNull());
+
+  topology::Field<topology::Mesh>& solution = fields.solution();
+  const ALE::Obj<RealSection>& solutionSection = solution.section();
+  CPPUNIT_ASSERT(!solutionSection.isNull());
+
+  const double t = 1.0;
+  bc.integrateJacobian(jacobian, t, &fields);
+  CPPUNIT_ASSERT_EQUAL(false, bc.needNewJacobian());
+  jacobian.complete();
+
+  const double* valsMatrixE = _data->valsJacobian;
+  const int totalNumVertices = sieveMesh->depthStratum(0)->size();
+  const int sizeE = totalNumVertices * _data->spaceDim;
+  double_array valsE(sizeE);
+  const int spaceDim = _data->spaceDim;
+  for (int iVertex=0; iVertex < totalNumVertices; ++iVertex)
+    for (int iDim=0; iDim < spaceDim; ++iDim) {
+      const int indexRow = (iVertex*spaceDim+iDim)*totalNumVertices*spaceDim;
+      double value = 0.0;
+      for (int jVertex=0; jVertex < totalNumVertices; ++jVertex)
+	value += valsMatrixE[indexRow + jVertex*spaceDim+iDim];
+      valsE[iVertex*spaceDim+iDim] = value;
+    } // for
+
+#if 0 // DEBUGGING
+  jacobian.view("JACOBIAN");
+  std::cout << "\n\nJACOBIAN FULL" << std::endl;
+  const int n = totalNumVertices*spaceDim;
+  for (int r=0; r < n; ++r) {
+    for (int c=0; c < n; ++c) 
+      std::cout << "  " << valsMatrixE[r*n+c];
+    std::cout << "\n";
+  } // for
+#endif // DEBUGGING
+
+  const ALE::Obj<RealSection>& jacobianSection = jacobian.section();
+  CPPUNIT_ASSERT(!jacobianSection.isNull());
+  const double* vals = jacobianSection->restrictSpace();
+  const int size = jacobianSection->sizeWithBC();
+  CPPUNIT_ASSERT_EQUAL(sizeE, size);
+
+  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);
+
+} // testIntegrateJacobianLumped
+
+// ----------------------------------------------------------------------
+void
 pylith::bc::TestAbsorbingDampers::_initialize(topology::Mesh* mesh,
 					      AbsorbingDampers* const bc,
 					      topology::SolutionFields* fields) const

Modified: short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampers.hh
===================================================================
--- short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampers.hh	2009-10-31 22:49:45 UTC (rev 15915)
+++ short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampers.hh	2009-11-01 20:48:25 UTC (rev 15916)
@@ -71,6 +71,9 @@
   /// Test integrateJacobian().
   void testIntegrateJacobian(void);
 
+  /// Test integrateJacobianLumped().
+  void testIntegrateJacobianLumped(void);
+
   // PROTECTED MEMBERS //////////////////////////////////////////////////
 protected :
 

Modified: short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersHex8.hh
===================================================================
--- short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersHex8.hh	2009-10-31 22:49:45 UTC (rev 15915)
+++ short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersHex8.hh	2009-11-01 20:48:25 UTC (rev 15916)
@@ -40,6 +40,7 @@
   CPPUNIT_TEST( testInitialize );
   CPPUNIT_TEST( testIntegrateResidual );
   CPPUNIT_TEST( testIntegrateJacobian );
+  CPPUNIT_TEST( testIntegrateJacobianLumped );
 
   CPPUNIT_TEST_SUITE_END();
 

Modified: short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersLine2.hh
===================================================================
--- short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersLine2.hh	2009-10-31 22:49:45 UTC (rev 15915)
+++ short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersLine2.hh	2009-11-01 20:48:25 UTC (rev 15916)
@@ -39,6 +39,7 @@
   CPPUNIT_TEST( testInitialize );
   CPPUNIT_TEST( testIntegrateResidual );
   CPPUNIT_TEST( testIntegrateJacobian );
+  CPPUNIT_TEST( testIntegrateJacobianLumped );
   CPPUNIT_TEST_SUITE_END();
 
   // PUBLIC METHODS /////////////////////////////////////////////////////

Modified: short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersQuad4.hh
===================================================================
--- short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersQuad4.hh	2009-10-31 22:49:45 UTC (rev 15915)
+++ short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersQuad4.hh	2009-11-01 20:48:25 UTC (rev 15916)
@@ -39,6 +39,7 @@
   CPPUNIT_TEST( testInitialize );
   CPPUNIT_TEST( testIntegrateResidual );
   CPPUNIT_TEST( testIntegrateJacobian );
+  CPPUNIT_TEST( testIntegrateJacobianLumped );
   CPPUNIT_TEST_SUITE_END();
 
   // PUBLIC METHODS /////////////////////////////////////////////////////

Modified: short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersTet4.hh
===================================================================
--- short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersTet4.hh	2009-10-31 22:49:45 UTC (rev 15915)
+++ short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersTet4.hh	2009-11-01 20:48:25 UTC (rev 15916)
@@ -39,6 +39,7 @@
   CPPUNIT_TEST( testInitialize );
   CPPUNIT_TEST( testIntegrateResidual );
   CPPUNIT_TEST( testIntegrateJacobian );
+  CPPUNIT_TEST( testIntegrateJacobianLumped );
   CPPUNIT_TEST_SUITE_END();
 
   // PUBLIC METHODS /////////////////////////////////////////////////////

Modified: short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersTri3.hh
===================================================================
--- short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersTri3.hh	2009-10-31 22:49:45 UTC (rev 15915)
+++ short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/TestAbsorbingDampersTri3.hh	2009-11-01 20:48:25 UTC (rev 15916)
@@ -39,6 +39,7 @@
   CPPUNIT_TEST( testInitialize );
   CPPUNIT_TEST( testIntegrateResidual );
   CPPUNIT_TEST( testIntegrateJacobian );
+  CPPUNIT_TEST( testIntegrateJacobianLumped );
   CPPUNIT_TEST_SUITE_END();
 
   // PUBLIC METHODS /////////////////////////////////////////////////////

Modified: short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/test_bc.cc
===================================================================
--- short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/test_bc.cc	2009-10-31 22:49:45 UTC (rev 15915)
+++ short/3D/PyLith/branches/pylith-friction/unittests/libtests/bc/test_bc.cc	2009-11-01 20:48:25 UTC (rev 15916)
@@ -64,6 +64,9 @@
 
     // Finalize PETSc
     err = PetscFinalize(); CHKERRQ(err);
+  } catch (const std::exception& err) {
+    std::cerr << "Error: " << err.what() << std::endl;
+    abort();
   } catch (...) {
     abort();
   } // catch



More information about the CIG-COMMITS mailing list