[cig-commits] r15088 - in short/3D/PyLith/trunk: libsrc/materials unittests/libtests/materials

brad at geodynamics.org brad at geodynamics.org
Fri May 29 21:42:36 PDT 2009


Author: brad
Date: 2009-05-29 21:42:36 -0700 (Fri, 29 May 2009)
New Revision: 15088

Added:
   short/3D/PyLith/trunk/unittests/libtests/materials/TestEffectiveStress.cc
   short/3D/PyLith/trunk/unittests/libtests/materials/TestEffectiveStress.hh
Modified:
   short/3D/PyLith/trunk/libsrc/materials/EffectiveStress.hh
   short/3D/PyLith/trunk/libsrc/materials/EffectiveStress.icc
   short/3D/PyLith/trunk/libsrc/materials/Makefile.am
   short/3D/PyLith/trunk/libsrc/materials/PowerLaw3D.cc
   short/3D/PyLith/trunk/unittests/libtests/materials/Makefile.am
Log:
Added unit tests for EffectiveStress.

Modified: short/3D/PyLith/trunk/libsrc/materials/EffectiveStress.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/materials/EffectiveStress.hh	2009-05-30 01:21:48 UTC (rev 15087)
+++ short/3D/PyLith/trunk/libsrc/materials/EffectiveStress.hh	2009-05-30 04:42:36 UTC (rev 15088)
@@ -50,9 +50,9 @@
    */
   template<typename material_type>
   static
-  double getEffStress(const double effStressInitialGuess,
-		      const double stressScale,
-		      material_type* const material);
+  double calculate(const double effStressInitialGuess,
+		   const double stressScale,
+		   material_type* const material);
 
   // PRIVATE METHODS /////////////////////////////////////////////////////
 private :
@@ -66,9 +66,9 @@
    */
   template<typename material_type>
   static
-  void _bracketEffStress(double* px1,
-			 double* px2,
-			 material_type* const material);
+  void _bracket(double* px1,
+		double* px2,
+		material_type* const material);
 
   /** Solve for effective stress using Newton's method with bisection.
    *
@@ -80,9 +80,9 @@
    */
   template<typename material_type>
   static
-  double _findEffStress(double x1,
-			double x2,
-			material_type* const material);
+  double _search(double x1,
+		 double x2,
+		 material_type* const material);
 
 }; // class EffectiveStress
 

Modified: short/3D/PyLith/trunk/libsrc/materials/EffectiveStress.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/materials/EffectiveStress.icc	2009-05-30 01:21:48 UTC (rev 15087)
+++ short/3D/PyLith/trunk/libsrc/materials/EffectiveStress.icc	2009-05-30 04:42:36 UTC (rev 15088)
@@ -22,7 +22,7 @@
 // Get effective stress from initial guess.
 template<typename material_type>
 double
-pylith::materials::EffectiveStress::getEffStress(
+pylith::materials::EffectiveStress::calculate(
 				 const double effStressInitialGuess,
 				 const double stressScale,
 				 material_type* const material)
@@ -41,10 +41,10 @@
     x2 = stressScale + 0.5 * stressScale;
   } // else
 
-  _bracketEffStress(&x1, &x2, material);
+  _bracket(&x1, &x2, material);
 
   // Find effective stress using Newton's method with bisection.
-  const double effStress = _findEffStress(x1, x2, material);
+  const double effStress = _search(x1, x2, material);
 
   PetscLogFlops(4); // Log flops
 
@@ -55,11 +55,10 @@
 // Bracket effective stress.
 template<typename material_type>
 void
-pylith::materials::EffectiveStress::_bracketEffStress(
-					    double* px1,
-					    double* px2,
-					    material_type* const material)
-{ // _bracketEffStress
+pylith::materials::EffectiveStress::_bracket(double* px1,
+					     double* px2,
+					     material_type* const material)
+{ // _bracket
   // Arbitrary number of iterations to bracket the root
   const int maxIterations = 50;
 
@@ -97,17 +96,16 @@
   PetscLogFlops(5 * iteration);
   if (!bracketed)
     throw std::runtime_error("Unable to bracket effective stress.");
-} // _bracketEffStress
+} // _bracket
 
 // ----------------------------------------------------------------------
 // Find root using Newton's method with bisection.
 template<typename material_type>
 double
-pylith::materials::EffectiveStress::_findEffStress(
-				 const double x1,
-				 const double x2,
-				 material_type* const material)
-{ // _findEffStress
+pylith::materials::EffectiveStress::_search(const double x1,
+					    const double x2,
+					    material_type* const material)
+{ // _search
   // Arbitrary number of iterations to find the root
   const int maxIterations = 100;
 
@@ -185,7 +183,7 @@
   PetscLogFlops(5 + 15 * iteration); // Log flops
 
   return effStress;
-} // _findEffStress
+} // _search
 
 
 // End of file 

Modified: short/3D/PyLith/trunk/libsrc/materials/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/materials/Makefile.am	2009-05-30 01:21:48 UTC (rev 15087)
+++ short/3D/PyLith/trunk/libsrc/materials/Makefile.am	2009-05-30 04:42:36 UTC (rev 15088)
@@ -33,6 +33,7 @@
 	Material.icc \
 	ViscoelasticMaxwell.hh \
 	EffectiveStress.hh \
+	EffectiveStress.icc \
 	materialsfwd.hh
 
 

Modified: short/3D/PyLith/trunk/libsrc/materials/PowerLaw3D.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/materials/PowerLaw3D.cc	2009-05-30 01:21:48 UTC (rev 15087)
+++ short/3D/PyLith/trunk/libsrc/materials/PowerLaw3D.cc	2009-05-30 04:42:36 UTC (rev 15088)
@@ -603,8 +603,8 @@
     const double effStressInitialGuess = effStressT;
 
     double effStressTpdt =
-      EffectiveStress::getEffStress<PowerLaw3D>(effStressInitialGuess,
-						stressScale, this);
+      EffectiveStress::calculate<PowerLaw3D>(effStressInitialGuess,
+					     stressScale, this);
 
     // Compute stresses from effective stress.
     const double effStressTau = (1.0 - alpha) * effStressT +
@@ -1015,8 +1015,8 @@
   const double effStressInitialGuess = effStressT;
 
   const double effStressTpdt =
-    EffectiveStress::getEffStress<PowerLaw3D>(effStressInitialGuess,
-					      stressScale, this);
+    EffectiveStress::calculate<PowerLaw3D>(effStressInitialGuess,
+					   stressScale, this);
   
   // Compute quantities at intermediate time tau used to compute values at
   // end of time step.
@@ -1334,8 +1334,8 @@
   const double effStressInitialGuess = effStressT;
 
   double effStressTpdt =
-    EffectiveStress::getEffStress<PowerLaw3D>(effStressInitialGuess,
-					      stressScale, this);
+    EffectiveStress::calculate<PowerLaw3D>(effStressInitialGuess,
+					   stressScale, this);
 
   // Compute stress and viscous strain and update appropriate state variables.
   const double effStressTau = (1.0 - alpha) * effStressT +

Modified: short/3D/PyLith/trunk/unittests/libtests/materials/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/materials/Makefile.am	2009-05-30 01:21:48 UTC (rev 15087)
+++ short/3D/PyLith/trunk/unittests/libtests/materials/Makefile.am	2009-05-30 04:42:36 UTC (rev 15088)
@@ -30,6 +30,7 @@
 	TestElasticPlaneStress.cc \
 	TestElasticIsotropic3D.cc \
 	TestMaxwellIsotropic3D.cc \
+	TestEffectiveStress.cc \
 	test_materials.cc
 
 #	TestGenMaxwellIsotropic3D.cc 
@@ -45,7 +46,8 @@
 	TestElasticPlaneStress.hh \
 	TestElasticIsotropic3D.hh \
 	TestGenMaxwellIsotropic3D.hh \
-	TestMaxwellIsotropic3D.hh
+	TestMaxwellIsotropic3D.hh \
+	TestEffectiveStress.hh
 
 # Source files associated with testing data
 testmaterials_SOURCES += \

Added: short/3D/PyLith/trunk/unittests/libtests/materials/TestEffectiveStress.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/materials/TestEffectiveStress.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/materials/TestEffectiveStress.cc	2009-05-30 04:42:36 UTC (rev 15088)
@@ -0,0 +1,117 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestEffectiveStress.hh" // Implementation of class methods
+
+#include "pylith/materials/EffectiveStress.hh" // USES EffectiveStress
+
+#include <cmath> // USES pow()
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::materials::TestEffectiveStress );
+
+// ----------------------------------------------------------------------
+namespace pylith {
+  namespace materials {
+    namespace _EffectiveStress {
+      class Linear {
+      public :
+	Linear(void) {};
+	~Linear(void) {};
+	double effStressFunc(const double x) {
+	  return x - 10.0;
+	};
+	double effStressDerivFunc(const double x) {
+	  return 1.0;
+	};
+	double effStressFuncDerivFunc(double* f,
+				      double* df,
+				      const double x) {
+	  *f = effStressFunc(x);
+	  *df = effStressDerivFunc(x);
+	};
+      }; // Linear
+    } // _EffectiveStress
+  } // materials
+} // pylith
+
+// ----------------------------------------------------------------------
+namespace pylith {
+  namespace materials {
+    namespace _EffectiveStress {
+      class Cubic {
+      public :
+	Cubic(void) {};
+	~Cubic(void) {};
+	double effStressFunc(const double x) {
+	  return pow(x - 4.0, 3);
+	};
+	double effStressDerivFunc(const double x) {
+	  return 3.0*pow(x - 4.0, 2);
+	};
+	double effStressFuncDerivFunc(double* f,
+				      double* df,
+				      const double x) {
+	  *f = effStressFunc(x);
+	  *df = effStressDerivFunc(x);
+	};
+      }; // Cubic
+    } // _EffectiveStress
+  } // materials
+} // pylith
+
+// ----------------------------------------------------------------------
+// Test calculate() with linear function.
+void
+pylith::materials::TestEffectiveStress::testCalculateLinear(void)
+{ // testCalculateLinear
+  const double valueE = 10.0;
+  
+  _EffectiveStress::Linear material;
+
+  const int ntests = 4;
+  const double guesses[ntests] = { 0.0, 6.0, 14.0, 20.0 };
+  const double scale = 1.0;
+  const double tolerance = 1.0e-06;
+  for (int i=0; i < ntests; ++i) {
+    const double value =
+      EffectiveStress::calculate<_EffectiveStress::Linear>(guesses[i], scale,
+							   &material);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, value/valueE, tolerance);
+  } // for
+} // testCalculateLinear
+
+// ----------------------------------------------------------------------
+// Test calculate() with cubic function.
+void
+pylith::materials::TestEffectiveStress::testCalculateCubic(void)
+{ // testCalculateCubic
+  const double valueE = 4.0;
+  
+  _EffectiveStress::Cubic material;
+
+  const int ntests = 4;
+  const double guesses[ntests] = { 2.0, 4.0, 6.0, 8.0 };
+  const double scale = 1.0;
+  const double tolerance = 1.0e-06;
+  for (int i=0; i < ntests; ++i) {
+    const double value =
+      EffectiveStress::calculate<_EffectiveStress::Cubic>(guesses[i], scale,
+							   &material);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, value/valueE, tolerance);
+  } // for
+} // testCalculateCubic
+
+
+// End of file

Added: short/3D/PyLith/trunk/unittests/libtests/materials/TestEffectiveStress.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/materials/TestEffectiveStress.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/libtests/materials/TestEffectiveStress.hh	2009-05-30 04:42:36 UTC (rev 15088)
@@ -0,0 +1,58 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/materials/TestEffectiveStress.hh
+ *
+ * @brief C++ TestEffectiveStress object
+ *
+ * C++ unit testing for EffectiveStress.
+ */
+
+#if !defined(pylith_materials_testeffectivestress_hh)
+#define pylith_materials_testeffectivestress_hh
+
+#include <cppunit/extensions/HelperMacros.h>
+
+/// Namespace for pylith package
+namespace pylith {
+  namespace materials {
+    class TestEffectiveStress;
+  } // materials
+} // pylith
+
+/// C++ unit testing for EffectiveStress
+class pylith::materials::TestEffectiveStress : public CppUnit::TestFixture
+{ // class TestEffectiveStress
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestEffectiveStress );
+
+  CPPUNIT_TEST( testCalculateLinear );
+  CPPUNIT_TEST( testCalculateCubic );
+
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Test calculate() with linear function.
+  void testCalculateLinear(void);
+
+  /// Test calculate() with cubic function.
+  void testCalculateCubic(void);
+
+}; // class TestEffectiveStress
+
+#endif // pylith_materials_testeffectivestress_hh
+
+// End of file 



More information about the CIG-COMMITS mailing list