[cig-commits] r15696 - in short/3D/PyLith/trunk: libsrc/materials modulesrc/materials pylith pylith/materials unittests/pytests/materials

willic3 at geodynamics.org willic3 at geodynamics.org
Sun Sep 27 20:01:30 PDT 2009


Author: willic3
Date: 2009-09-27 20:01:29 -0700 (Sun, 27 Sep 2009)
New Revision: 15696

Added:
   short/3D/PyLith/trunk/modulesrc/materials/MaxwellPlaneStrain.i
   short/3D/PyLith/trunk/pylith/materials/MaxwellPlaneStrain.py
   short/3D/PyLith/trunk/unittests/pytests/materials/TestMaxwellPlaneStrain.py
Modified:
   short/3D/PyLith/trunk/libsrc/materials/MaxwellPlaneStrain.cc
   short/3D/PyLith/trunk/modulesrc/materials/Makefile.am
   short/3D/PyLith/trunk/modulesrc/materials/materials.i
   short/3D/PyLith/trunk/pylith/Makefile.am
   short/3D/PyLith/trunk/unittests/pytests/materials/Makefile.am
   short/3D/PyLith/trunk/unittests/pytests/materials/testmaterials.py
Log:
Put in missing pieces for Maxwell plane strain material model.
I now need to update the manual and add at least one example problem.



Modified: short/3D/PyLith/trunk/libsrc/materials/MaxwellPlaneStrain.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/materials/MaxwellPlaneStrain.cc	2009-09-28 02:23:22 UTC (rev 15695)
+++ short/3D/PyLith/trunk/libsrc/materials/MaxwellPlaneStrain.cc	2009-09-28 03:01:29 UTC (rev 15696)
@@ -432,7 +432,7 @@
     devStressInitial[0];
   stress[1] = meanStressTpdt + mu2 * (_viscousStrain[1] - devStrainInitial[1]) +
     devStressInitial[1];
-  stress[2] = mu2 * (_viscousStrain[2] - devStrainInitial[2]) +
+  stress[2] = mu2 * (_viscousStrain[3] - devStrainInitial[2]) +
     devStressInitial[2];
 
   PetscLogFlops(28);

Modified: short/3D/PyLith/trunk/modulesrc/materials/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/materials/Makefile.am	2009-09-28 02:23:22 UTC (rev 15695)
+++ short/3D/PyLith/trunk/modulesrc/materials/Makefile.am	2009-09-28 03:01:29 UTC (rev 15696)
@@ -27,6 +27,7 @@
 	ElasticPlaneStress.i \
 	ElasticIsotropic3D.i \
 	MaxwellIsotropic3D.i \
+	MaxwellPlaneStrain.i \
 	GenMaxwellIsotropic3D.i \
 	PowerLaw3D.i
 

Added: short/3D/PyLith/trunk/modulesrc/materials/MaxwellPlaneStrain.i
===================================================================
--- short/3D/PyLith/trunk/modulesrc/materials/MaxwellPlaneStrain.i	                        (rev 0)
+++ short/3D/PyLith/trunk/modulesrc/materials/MaxwellPlaneStrain.i	2009-09-28 03:01:29 UTC (rev 15696)
@@ -0,0 +1,205 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file modulesrc/materials/MaxwellPlaneStrain.ii
+ *
+ * @brief Python interface to C++ MaxwellPlaneStrain object.
+ */
+
+namespace pylith {
+  namespace materials {
+
+    class MaxwellPlaneStrain : public ElasticMaterial
+    { // class MaxwellPlaneStrain
+
+      // PUBLIC METHODS /////////////////////////////////////////////////
+    public :
+
+      /// Default constructor
+      MaxwellPlaneStrain(void);
+      
+      /// Destructor
+      ~MaxwellPlaneStrain(void);
+      
+      /** Set current time step.
+       *
+       * @param dt Current time step.
+       */
+      void timeStep(const double dt);
+
+      /** Set whether elastic or inelastic constitutive relations are used.
+       *
+       * @param flag True to use elastic, false to use inelastic.
+       */
+      void useElasticBehavior(const bool flag);
+
+      // PROTECTED METHODS //////////////////////////////////////////////
+    protected :
+
+      /** Compute properties from values in spatial database.
+       *
+       * Order of values in arrays matches order used in dbValues() and
+       * parameterNames().
+       *
+       * @param propValues Array of property values.
+       * @param dbValues Array of database values.
+       */
+      void _dbToProperties(double* const propValues,
+			   const pylith::double_array& dbValues) const;
+      
+      /** Nondimensionalize properties.
+       *
+       * @param values Array of property values.
+       * @param nvalues Number of values.
+       */
+      void _nondimProperties(double* const values,
+			     const int nvalues) const;
+      
+      /** Dimensionalize properties.
+       *
+       * @param values Array of property values.
+       * @param nvalues Number of values.
+       */
+      void _dimProperties(double* const values,
+			  const int nvalues) const;
+      
+      /** Compute initial state variables from values in spatial database.
+       *
+       * @param stateValues Array of state variable values.
+       * @param dbValues Array of database values.
+       */
+      void _dbToStateVars(double* const stateValues,
+			  const pylith::double_array& dbValues) const;
+      
+      // Note: We do not need to dimensionalize or nondimensionalize state
+      // variables because there are strains, which are dimensionless.
+      
+      
+      /** Compute density from properties.
+       *
+       * @param density Array for density.
+       * @param properties Properties at location.
+       * @param numProperties Number of properties.
+       */
+      void _calcDensity(double* const density,
+			const double* properties,
+			const int numProperties,
+			const double* stateVars,
+			const int numStateVars);
+      
+      /** Compute stress tensor from properties and state variables. If
+       * the state variables are from the previous time step, then the
+       * computeStateVars flag should be set to true so that the state
+       * variables are updated (but not stored) when computing the
+       * stresses.
+       *
+       * @param stress Array for stress tensor.
+       * @param stressSize Size of stress tensor.
+       * @param properties Properties at location.
+       * @param numProperties Number of properties.
+       * @param stateVars State variables at location.
+       * @param numStateVars Number of state variables.
+       * @param totalStrain Total strain at location.
+       * @param strainSize Size of strain tensor.
+       * @param initialStress Initial stress tensor at location.
+       * @param initialStressSize Size of initial stress array.
+       * @param initialStrain Initial strain tensor at location.
+       * @param initialStrainSize Size of initial strain array.
+       * @param computeStateVars Flag indicating to compute updated state variables.
+       */
+      void _calcStress(double* const stress,
+		       const int stressSize,
+		       const double* properties,
+		       const int numProperties,
+		       const double* stateVars,
+		       const int numStateVars,
+		       const double* totalStrain,
+		       const int strainSize,
+		       const double* initialStress,
+		       const int initialStressSize,
+		       const double* initialStrain,
+		       const int initialStrainSize,
+		       const bool computeStateVars);
+      
+      /** Compute derivatives of elasticity matrix from properties.
+       *
+       * @param elasticConsts Array for elastic constants.
+       * @param numElasticConsts Number of elastic constants.
+       * @param properties Properties at location.
+       * @param numProperties Number of properties.
+       * @param stateVars State variables at location.
+       * @param numStateVars Number of state variables.
+       * @param totalStrain Total strain at location.
+       * @param strainSize Size of strain tensor.
+       * @param initialStress Initial stress tensor at location.
+       * @param initialStressSize Size of initial stress array.
+       * @param initialStrain Initial strain tensor at location.
+       * @param initialStrainSize Size of initial strain array.
+       */
+      void _calcElasticConsts(double* const elasticConsts,
+			      const int numElasticConsts,
+			      const double* properties,
+			      const int numProperties,
+			      const double* stateVars,
+			      const int numStateVars,
+			      const double* totalStrain,
+			      const int strainSize,
+			      const double* initialStress,
+			      const int initialStressSize,
+			      const double* initialStrain,
+			      const int initialStrainSize);
+      
+      /** Update state variables (for next time step).
+       *
+       * @param stateVars State variables at location.
+       * @param numStateVars Number of state variables.
+       * @param properties Properties at location.
+       * @param numProperties Number of properties.
+       * @param totalStrain Total strain at location.
+       * @param strainSize Size of strain tensor.
+       * @param initialStress Initial stress tensor at location.
+       * @param initialStressSize Size of initial stress array.
+       * @param initialStrain Initial strain tensor at location.
+       * @param initialStrainSize Size of initial strain array.
+       */
+      void _updateStateVars(double* const stateVars,
+			    const int numStateVars,
+			    const double* properties,
+			    const int numProperties,
+			    const double* totalStrain,
+			    const int strainSize,
+			    const double* initialStress,
+			    const int initialStressSize,
+			    const double* initialStrain,
+			    const int initialStrainSize);
+      
+      /** Get stable time step for implicit time integration.
+       *
+       * @param properties Properties at location.
+       * @param numProperties Number of properties.
+       * @param stateVars State variables at location.
+       * @param numStateVars Number of state variables.
+       *
+       * @returns Time step
+       */
+      double _stableTimeStepImplicit(const double* properties,
+				     const int numProperties,
+				     const double* stateVars,
+				     const int numStateVars) const;
+
+    }; // class MaxwellPlaneStrain
+
+  } // materials
+} // pylith
+
+
+// End of file 

Modified: short/3D/PyLith/trunk/modulesrc/materials/materials.i
===================================================================
--- short/3D/PyLith/trunk/modulesrc/materials/materials.i	2009-09-28 02:23:22 UTC (rev 15695)
+++ short/3D/PyLith/trunk/modulesrc/materials/materials.i	2009-09-28 03:01:29 UTC (rev 15696)
@@ -27,6 +27,7 @@
 #include "pylith/materials/ElasticPlaneStress.hh"
 #include "pylith/materials/ElasticIsotropic3D.hh"
 #include "pylith/materials/MaxwellIsotropic3D.hh"
+#include "pylith/materials/MaxwellPlaneStrain.hh"
 #include "pylith/materials/GenMaxwellIsotropic3D.hh"
 #include "pylith/materials/PowerLaw3D.hh"
 
@@ -63,6 +64,7 @@
 %include "ElasticPlaneStress.i"
 %include "ElasticIsotropic3D.i"
 %include "MaxwellIsotropic3D.i"
+%include "MaxwellPlaneStrain.i"
 %include "GenMaxwellIsotropic3D.i"
 %include "PowerLaw3D.i"
 

Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am	2009-09-28 02:23:22 UTC (rev 15695)
+++ short/3D/PyLith/trunk/pylith/Makefile.am	2009-09-28 03:01:29 UTC (rev 15696)
@@ -58,6 +58,7 @@
 	materials/Homogeneous.py \
 	materials/Material.py \
 	materials/MaxwellIsotropic3D.py \
+	materials/MaxwellPlaneStrain.py \
 	materials/PowerLaw3D.py \
 	meshio/__init__.py \
 	meshio/CellFilter.py \

Added: short/3D/PyLith/trunk/pylith/materials/MaxwellPlaneStrain.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/MaxwellPlaneStrain.py	                        (rev 0)
+++ short/3D/PyLith/trunk/pylith/materials/MaxwellPlaneStrain.py	2009-09-28 03:01:29 UTC (rev 15696)
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/materials/MaxwellPlaneStrain.py
+##
+## @brief Python object implementing plane strain linear Maxwell
+## viscoelastic material.
+##
+## Factory: material.
+
+from ElasticMaterial import ElasticMaterial
+from materials import MaxwellPlaneStrain as ModuleMaxwellPlaneStrain
+
+# MaxwellPlaneStrain class
+class MaxwellPlaneStrain(ElasticMaterial, ModuleMaxwellPlaneStrain):
+  """
+  Python object implementing plane strain linear Maxwell viscoelastic
+  material.
+
+  Factory: material.
+  """
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="maxwellplanestrain"):
+    """
+    Constructor.
+    """
+    ElasticMaterial.__init__(self, name)
+    self.availableFields = \
+        {'vertex': \
+           {'info': [],
+            'data': []},
+         'cell': \
+           {'info': ["mu", "lambda", "density", "maxwell_time"],
+            'data': ["total_strain", "viscous_strain", "stress"]}}
+    self._loggingPrefix = "MaMx2D "
+    return
+
+
+  def _createModuleObj(self):
+    """
+    Call constructor for module object for access to C++ object.
+    """
+    ModuleMaxwellPlaneStrain.__init__(self)
+    return
+  
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def material():
+  """
+  Factory associated with MaxwellPlaneStrain.
+  """
+  return MaxwellPlaneStrain()
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/materials/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/Makefile.am	2009-09-28 02:23:22 UTC (rev 15695)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/Makefile.am	2009-09-28 03:01:29 UTC (rev 15696)
@@ -30,6 +30,7 @@
 	TestElasticPlaneStress.py \
 	TestElasticIsotropic3D.py \
 	TestMaxwellIsotropic3D.py \
+	TestMaxwellPlaneStrain.py \
 	TestGenMaxwellIsotropic3D.py \
 	TestPowerLaw3D.py
 

Added: short/3D/PyLith/trunk/unittests/pytests/materials/TestMaxwellPlaneStrain.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/TestMaxwellPlaneStrain.py	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/TestMaxwellPlaneStrain.py	2009-09-28 03:01:29 UTC (rev 15696)
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/materials/TestMaxwellPlaneStrain.py
+
+## @brief Unit testing of MaxwellPlaneStrain object.
+
+import unittest
+
+from pylith.materials.MaxwellPlaneStrain import MaxwellPlaneStrain
+
+# ----------------------------------------------------------------------
+class TestMaxwellPlaneStrain(unittest.TestCase):
+  """
+  Unit testing of MaxwellPlaneStrain object.
+  """
+
+  def setUp(self):
+    """
+    Setup test subject.
+    """
+    self.material = MaxwellPlaneStrain()
+    return
+  
+
+  def test_constructor(self):
+    """
+    Test constructor.
+    """
+    self.assertEqual(2, self.material.dimension())
+    return
+
+
+  def test_useElasticBehavior(self):
+    """
+    Test useElasticBehavior().
+    """
+    self.material.useElasticBehavior(False)
+    return
+
+
+  def testHasStateVars(self):
+    self.failUnless(self.material.hasStateVars())
+    return
+
+
+  def testTensorSize(self):
+    self.assertEqual(3, self.material.tensorSize())
+    return
+
+
+  def testNeedNewJacobian(self):
+    """
+    Test needNewJacobian().
+    """
+    # Default should be False.
+    self.failIf(self.material.needNewJacobian())
+
+    # Changing time step should require new Jacobian.
+    self.material.timeStep(1.0)
+    self.material.timeStep(2.0)
+    self.failUnless(self.material.needNewJacobian())
+    return
+  
+
+  def test_factory(self):
+    """
+    Test factory method.
+    """
+    from pylith.materials.MaxwellPlaneStrain import material
+    m = material()
+    return
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/materials/testmaterials.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/testmaterials.py	2009-09-28 02:23:22 UTC (rev 15695)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/testmaterials.py	2009-09-28 03:01:29 UTC (rev 15696)
@@ -74,6 +74,9 @@
     from TestMaxwellIsotropic3D import TestMaxwellIsotropic3D
     suite.addTest(unittest.makeSuite(TestMaxwellIsotropic3D))
 
+    from TestMaxwellPlaneStrain import TestMaxwellPlaneStrain
+    suite.addTest(unittest.makeSuite(TestMaxwellPlaneStrain))
+
     from TestGenMaxwellIsotropic3D import TestGenMaxwellIsotropic3D
     suite.addTest(unittest.makeSuite(TestGenMaxwellIsotropic3D))
 



More information about the CIG-COMMITS mailing list