[cig-commits] r14840 - in short/3D/PyLith/branches/pylith-swig: libsrc/materials unittests/libtests/materials unittests/libtests/materials/data

brad at geodynamics.org brad at geodynamics.org
Fri May 1 15:48:03 PDT 2009


Author: brad
Date: 2009-05-01 15:48:03 -0700 (Fri, 01 May 2009)
New Revision: 14840

Modified:
   short/3D/PyLith/branches/pylith-swig/libsrc/materials/Material.cc
   short/3D/PyLith/branches/pylith-swig/libsrc/materials/MaxwellIsotropic3D.cc
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/Makefile.am
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestElasticMaterial.cc
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestMaxwellIsotropic3D.cc
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/data/MaxwellIsotropic3DTimeDep.py
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/data/MaxwellIsotropic3DTimeDepData.cc
Log:
Fixed bug in setting up unit test.

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/materials/Material.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/materials/Material.cc	2009-05-01 22:19:35 UTC (rev 14839)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/materials/Material.cc	2009-05-01 22:48:03 UTC (rev 14840)
@@ -72,6 +72,8 @@
 pylith::materials::Material::~Material(void)
 { // destructor
   delete _normalizer; _normalizer = 0;
+  delete _properties; _properties = 0;
+  delete _stateVars; _stateVars = 0;
 
   // Python db object owns databases, so just set pointer to null
   // :KLUDGE: Should use shared pointer

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/materials/MaxwellIsotropic3D.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/materials/MaxwellIsotropic3D.cc	2009-05-01 22:19:35 UTC (rev 14839)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/materials/MaxwellIsotropic3D.cc	2009-05-01 22:48:03 UTC (rev 14840)
@@ -499,9 +499,9 @@
   const double e22 = totalStrain[1] - initialStrain[1];
   const double e33 = totalStrain[2] - initialStrain[2];
   
-  const double traceStrainTpdt = e11 + e22 + e33;
-  const double meanStrainTpdt = traceStrainTpdt / 3.0;
-  const double meanStressTpdt = bulkModulus * traceStrainTpdt;
+  const double e123 = e11 + e22 + e33;
+  const double meanStrainTpdt = e123 / 3.0;
+  const double meanStressTpdt = bulkModulus * e123;
 
   const double diag[] = { 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 };
 

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/Makefile.am	2009-05-01 22:19:35 UTC (rev 14839)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/Makefile.am	2009-05-01 22:48:03 UTC (rev 14840)
@@ -32,7 +32,7 @@
 	TestMaxwellIsotropic3D.cc \
 	test_materials.cc
 
-	TestGenMaxwellIsotropic3D.cc 
+#	TestGenMaxwellIsotropic3D.cc 
 
 
 

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestElasticMaterial.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestElasticMaterial.cc	2009-05-01 22:19:35 UTC (rev 14839)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestElasticMaterial.cc	2009-05-01 22:48:03 UTC (rev 14840)
@@ -195,13 +195,8 @@
   size_t size = data.numLocs*data.numPropsQuadPt;
   CPPUNIT_ASSERT_EQUAL(size, properties.size());
   for (size_t i=0; i < size; ++i)
-    {
-      std::cout << "propertyE: " << propertiesE[i]
-		<< ", property: " << properties[i]
-		<< std::endl;
     CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, properties[i]/propertiesE[i],
 				 tolerance);
-    }
 
   const double* stateVarsE = data.stateVars;
   CPPUNIT_ASSERT( (0 < numVarsQuadPt && 0 != stateVarsE) ||
@@ -359,7 +354,8 @@
 void
 pylith::materials::TestElasticMaterial::testUpdateStateVars(void)
 { // testUpdateStateVars
-  std::cout << "\n\nNeed to implement using material with state variables.\n\n";
+  std::cout << "\n\nWARNING!! WARNING!! WARNING!!\n"
+    "Need to implement using material with state variables.\n\n";
 } // testUpdateStateVars
 
 // ----------------------------------------------------------------------
@@ -417,18 +413,18 @@
   CPPUNIT_ASSERT(0 != _dataElastic);
   const ElasticMaterialData* data = _dataElastic;
 
-  const int numLocs = _data->numLocs;
-  const int numPropsQuadPt = _data->numPropsQuadPt;
-  const int numVarsQuadPt = _data->numVarsQuadPt;
+  const int numLocs = data->numLocs;
+  const int numPropsQuadPt = data->numPropsQuadPt;
+  const int numVarsQuadPt = data->numVarsQuadPt;
   
   double density = 0;
   double_array properties(numPropsQuadPt);
   double_array stateVars(numVarsQuadPt);
 
   for (int iLoc=0; iLoc < numLocs; ++iLoc) {
-    memcpy(&properties[0], &_data->properties[iLoc*numPropsQuadPt],
+    memcpy(&properties[0], &data->properties[iLoc*numPropsQuadPt],
 	   numPropsQuadPt*sizeof(double));
-    memcpy(&stateVars[0], &_data->stateVars[iLoc*numVarsQuadPt],
+    memcpy(&stateVars[0], &data->stateVars[iLoc*numVarsQuadPt],
 	   numVarsQuadPt*sizeof(double));
 
     _matElastic->_calcDensity(&density, 
@@ -453,9 +449,9 @@
 
   const bool computeStateVars = true;
 
-  const int numLocs = _data->numLocs;
-  const int numPropsQuadPt = _data->numPropsQuadPt;
-  const int numVarsQuadPt = _data->numVarsQuadPt;
+  const int numLocs = data->numLocs;
+  const int numPropsQuadPt = data->numPropsQuadPt;
+  const int numVarsQuadPt = data->numVarsQuadPt;
   const int tensorSize = _matElastic->_tensorSize;
   
   double_array stress(tensorSize);
@@ -467,15 +463,15 @@
 
   for (int iLoc=0; iLoc < numLocs; ++iLoc) {
     memcpy(&properties[0], &data->properties[iLoc*numPropsQuadPt],
-	   numPropsQuadPt*sizeof(double));
+	   properties.size()*sizeof(double));
     memcpy(&stateVars[0], &data->stateVars[iLoc*numVarsQuadPt],
-	   numVarsQuadPt*sizeof(double));
+	   stateVars.size()*sizeof(double));
     memcpy(&strain[0], &data->strain[iLoc*tensorSize],
-	   tensorSize*sizeof(double));
+	   strain.size()*sizeof(double));
     memcpy(&initialStress[0], &data->initialStress[iLoc*tensorSize],
-	   tensorSize*sizeof(double));
+	   initialStress.size()*sizeof(double));
     memcpy(&initialStrain[0], &data->initialStrain[iLoc*tensorSize],
-	   tensorSize*sizeof(double));
+	   initialStrain.size()*sizeof(double));
 
     _matElastic->_calcStress(&stress[0], stress.size(),
 			     &properties[0], properties.size(),
@@ -484,23 +480,18 @@
 			     &initialStress[0], initialStress.size(),
 			     &initialStrain[0], initialStrain.size(),
 			     computeStateVars);
-  
+
     const double* stressE = &data->stress[iLoc*tensorSize];
     CPPUNIT_ASSERT(0 != stressE);
 
     const double tolerance = 1.0e-06;
     for (int i=0; i < tensorSize; ++i)
-      {
-	std::cout << "stress: " << stress[i]
-		  << ", stressE: " << stressE[i]
-		  << std::endl;
       if (fabs(stressE[i]) > tolerance)
 	CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, stress[i]/stressE[i], 
 				     tolerance);
       else
 	CPPUNIT_ASSERT_DOUBLES_EQUAL(stressE[i], stress[i],
 				     tolerance);
-      }
   } // for
 } // _testCalcStress
 
@@ -530,9 +521,9 @@
       tensorSize = 6;
       break;
     } // switch
-  const int numLocs = _data->numLocs;
-  const int numPropsQuadPt = _data->numPropsQuadPt;
-  const int numVarsQuadPt = _data->numVarsQuadPt;
+  const int numLocs = data->numLocs;
+  const int numPropsQuadPt = data->numPropsQuadPt;
+  const int numVarsQuadPt = data->numVarsQuadPt;
   
   double_array elasticConsts(numConsts);
   double_array properties(numPropsQuadPt);
@@ -585,9 +576,9 @@
 
   const bool computeStateVars = true;
 
-  const int numLocs = _data->numLocs;
-  const int numPropsQuadPt = _data->numPropsQuadPt;
-  const int numVarsQuadPt = _data->numVarsQuadPt;
+  const int numLocs = data->numLocs;
+  const int numPropsQuadPt = data->numPropsQuadPt;
+  const int numVarsQuadPt = data->numVarsQuadPt;
   const int tensorSize = _matElastic->_tensorSize;
   
   double_array properties(numPropsQuadPt);

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestMaxwellIsotropic3D.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestMaxwellIsotropic3D.cc	2009-05-01 22:19:35 UTC (rev 14839)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestMaxwellIsotropic3D.cc	2009-05-01 22:48:03 UTC (rev 14840)
@@ -116,6 +116,11 @@
 void
 pylith::materials::TestMaxwellIsotropic3D::test_updateStateVarsElastic(void)
 { // test_updateStateVarsElastic
+  // :TODO: Use TestElasticMaterial::test_updateStateVars
+  // instead. This requires moving the calculation of the expected
+  // state vars below to the Python code (where it belongs) and
+  // setting the stateVarsUpdate attribute in the Python object.
+
   MaxwellIsotropic3D material;
   material.useElasticBehavior(true);
 
@@ -208,6 +213,11 @@
 void
 pylith::materials::TestMaxwellIsotropic3D::test_updateStateVarsTimeDep(void)
 { // test_updateStateVarsTimeDep
+  // :TODO: Use TestElasticMaterial::test_updateStateVars
+  // instead. This requires moving the calculation of the expected
+  // state vars below to the Python code (where it belongs) and
+  // setting the stateVarsUpdate attribute in the Python object.
+
   MaxwellIsotropic3D material;
   material.useElasticBehavior(false);
   const double dt = 2.0e+5;

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/data/MaxwellIsotropic3DTimeDep.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/data/MaxwellIsotropic3DTimeDep.py	2009-05-01 22:19:35 UTC (rev 14839)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/data/MaxwellIsotropic3DTimeDep.py	2009-05-01 22:48:03 UTC (rev 14840)
@@ -141,8 +141,8 @@
     totalStrainB = strainB
     viscousStrainA = numpy.array(strainA) - diag*meanStrainA
     viscousStrainB = numpy.array(strainB) - diag*meanStrainB
-    self.stateVars = numpy.array([ [viscousStrainA, totalStrainA],
-                                   [viscousStrainB, totalStrainB] ],
+    self.stateVars = numpy.array([ [totalStrainA, viscousStrainA],
+                                   [totalStrainB, viscousStrainB] ],
                                  dtype=numpy.float64)
     self.stateVarsNondim = self.stateVars # no scaling
     
@@ -153,13 +153,13 @@
                                       dtype=numpy.float64)
 
     (self.elasticConsts[0,:], self.stress[0,:]) = \
-                              self._calcStress(strainA, muA, lambdaA,
-                                               maxwellTimeA, 
+                              self._calcStress(strainA, 
+                                               muA, lambdaA, maxwellTimeA,
                                                totalStrainA, viscousStrainA,
                                                initialStressA, initialStrainA)
     (self.elasticConsts[1,:], self.stress[1,:]) = \
-                              self._calcStress(strainB, muB, lambdaB,
-                                               maxwellTimeB, 
+                              self._calcStress(strainB, 
+                                               muB, lambdaB, maxwellTimeB, 
                                                totalStrainB, viscousStrainB,
                                                initialStressB, initialStrainB)
 
@@ -179,7 +179,7 @@
     diag = [1.0, 1.0, 1.0, 0.0, 0.0, 0.0]
 
     totalStrainR = numpy.array(totalStrainV) - numpy.array(initialStrainV)
-    print totalStrainV
+    print strainV
     print initialStrainV
     print totalStrainR
 

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/data/MaxwellIsotropic3DTimeDepData.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/data/MaxwellIsotropic3DTimeDepData.cc	2009-05-01 22:19:35 UTC (rev 14839)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/data/MaxwellIsotropic3DTimeDepData.cc	2009-05-01 22:48:03 UTC (rev 14840)
@@ -113,12 +113,6 @@
 };
 
 const double pylith::materials::MaxwellIsotropic3DTimeDepData::_stateVars[] = {
- -2.00000000e-05,
- -1.00000000e-05,
-  0.00000000e+00,
-  1.40000000e-04,
-  1.50000000e-04,
-  1.60000000e-04,
   1.10000000e-04,
   1.20000000e-04,
   1.30000000e-04,
@@ -127,16 +121,22 @@
   1.60000000e-04,
  -2.00000000e-05,
  -1.00000000e-05,
- -5.42101086e-20,
-  4.40000000e-04,
-  4.50000000e-04,
-  4.60000000e-04,
+  0.00000000e+00,
+  1.40000000e-04,
+  1.50000000e-04,
+  1.60000000e-04,
   4.10000000e-04,
   4.20000000e-04,
   4.30000000e-04,
   4.40000000e-04,
   4.50000000e-04,
   4.60000000e-04,
+ -2.00000000e-05,
+ -1.00000000e-05,
+ -5.42101086e-20,
+  4.40000000e-04,
+  4.50000000e-04,
+  4.60000000e-04,
 };
 
 const double pylith::materials::MaxwellIsotropic3DTimeDepData::_propertiesNondim[] = {
@@ -151,12 +151,6 @@
 };
 
 const double pylith::materials::MaxwellIsotropic3DTimeDepData::_stateVarsNondim[] = {
- -2.00000000e-05,
- -1.00000000e-05,
-  0.00000000e+00,
-  1.40000000e-04,
-  1.50000000e-04,
-  1.60000000e-04,
   1.10000000e-04,
   1.20000000e-04,
   1.30000000e-04,
@@ -165,16 +159,22 @@
   1.60000000e-04,
  -2.00000000e-05,
  -1.00000000e-05,
- -5.42101086e-20,
-  4.40000000e-04,
-  4.50000000e-04,
-  4.60000000e-04,
+  0.00000000e+00,
+  1.40000000e-04,
+  1.50000000e-04,
+  1.60000000e-04,
   4.10000000e-04,
   4.20000000e-04,
   4.30000000e-04,
   4.40000000e-04,
   4.50000000e-04,
   4.60000000e-04,
+ -2.00000000e-05,
+ -1.00000000e-05,
+ -5.42101086e-20,
+  4.40000000e-04,
+  4.50000000e-04,
+  4.60000000e-04,
 };
 
 const double pylith::materials::MaxwellIsotropic3DTimeDepData::_density[] = {



More information about the CIG-COMMITS mailing list