[cig-commits] r14315 - in short/3D/PyLith/branches/pylith-swig/modulesrc: . materials

brad at geodynamics.org brad at geodynamics.org
Fri Mar 13 14:54:03 PDT 2009


Author: brad
Date: 2009-03-13 14:54:02 -0700 (Fri, 13 Mar 2009)
New Revision: 14315

Added:
   short/3D/PyLith/branches/pylith-swig/modulesrc/materials/ElasticMaterial.i
   short/3D/PyLith/branches/pylith-swig/modulesrc/materials/ElasticStrain1D.i
   short/3D/PyLith/branches/pylith-swig/modulesrc/materials/Material.i
   short/3D/PyLith/branches/pylith-swig/modulesrc/materials/materials.i
Modified:
   short/3D/PyLith/branches/pylith-swig/modulesrc/
   short/3D/PyLith/branches/pylith-swig/modulesrc/materials/
Log:
Started working on materials SWIG stuff.


Property changes on: short/3D/PyLith/branches/pylith-swig/modulesrc
___________________________________________________________________
Name: svn:ignore
   + Makefile.in



Property changes on: short/3D/PyLith/branches/pylith-swig/modulesrc/materials
___________________________________________________________________
Name: svn:ignore
   + Makefile.in
materials.py
materials_wrap.cxx


Added: short/3D/PyLith/branches/pylith-swig/modulesrc/materials/ElasticMaterial.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/materials/ElasticMaterial.i	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/materials/ElasticMaterial.i	2009-03-13 21:54:02 UTC (rev 14315)
@@ -0,0 +1,183 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file modulesrc/materials/ElasticMaterial.i
+ *
+ * Python interface to C++ abstract base ElasticMaterial.
+ */
+
+namespace pylith {
+  namespace materials {
+
+    class ElasticMaterial : public Material
+    { // class ElasticMaterial
+
+      // PUBLIC METHODS /////////////////////////////////////////////////
+    public :
+
+      /** Default constructor.
+       *
+       * @param dimension Spatial dimension associated with material.
+       * @param tensorSize Array of names of database values for material.
+       * @param numElasticConsts Number of elastic constants.
+       * @param metadata Metadata for physical properties and state variables.
+       */
+      ElasticMaterial(const int dimension,
+		      const int tensorSize,
+		      const int numElasticConsts,
+		      const Metadata& metadata);
+
+      /// Destructor.
+      virtual
+      ~ElasticMaterial(void);
+
+      /** Set database for initial stress state.
+       *
+       * @param db Spatial database.
+       */
+      void dbInitialStress(spatialdata::spatialdb::SpatialDB* db);
+      
+      /** Set database for initial strain state.
+       *
+       * @param db Spatial database.
+       */
+      void dbInitialStrain(spatialdata::spatialdb::SpatialDB* db);
+
+      /** Get flag indicating whether material implements an empty
+       * _updateProperties() method.
+       *
+       * @returns False if _updateProperties() is empty, true otherwise.
+       */
+      bool hasStateVars(void) const;
+
+      /** Get stable time step for implicit time integration.
+       *
+       * @pre Must call retrievePropsAndVars for cell before calling
+       * stableTimeStep().
+       *
+       * Default is MAXFLOAT (or 1.0e+30 if MAXFLOAT is not defined in math.h).
+       *
+       * @returns Time step
+       */
+      virtual
+      double stableTimeStepImplicit(void) const;
+
+      /** Set whether elastic or inelastic constitutive relations are used.
+       *
+       * @param flag True to use elastic, false to use inelastic.
+       */
+      virtual
+      void useElasticBehavior(const bool flag);
+
+      // PROTECTED METHODS //////////////////////////////////////////////
+    protected :
+
+      /** Compute density from properties.
+       *
+       * @param density Array for density.
+       * @param properties Properties at location.
+       * @param numProperties Number of properties.
+       */
+      virtual
+      void _calcDensity(double* const density,
+			const double* properties,
+			const int numProperties,
+			const double* stateVars,
+			const int numStateVars) = 0;
+      
+      /** 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.
+       */
+      virtual
+      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) = 0;
+      
+      /** 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.
+       */
+      virtual
+      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) = 0;
+      
+      /** 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
+       */
+      virtual
+      double _stableTimeStepImplicit(const double* properties,
+				     const int numProperties,
+				     const double* stateVars,
+				     const int numStateVars) const = 0;
+      
+    }; // class ElasticMaterial
+
+  } // materials
+} // pylith
+
+
+// End of file

Added: short/3D/PyLith/branches/pylith-swig/modulesrc/materials/ElasticStrain1D.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/materials/ElasticStrain1D.i	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/materials/ElasticStrain1D.i	2009-03-13 21:54:02 UTC (rev 14315)
@@ -0,0 +1,39 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file modulesrc/materials/ElasticStrain1D.i
+ *
+ * Python interface to C++ ElasticStrain1D object.
+ */
+
+namespace pylith {
+  namespace materials {
+
+    class ElasticStrain1D : public ElasticMaterial
+    { // class ElasticStrain1D
+
+      // PUBLIC METHODS /////////////////////////////////////////////////
+    public :
+
+      /// Default constructor
+      ElasticStrain1D(void);
+
+      /// Destructor
+      ~ElasticStrain1D(void);
+
+    }; // class ElasticStrain1D
+
+  } // materials
+} // pylith
+
+
+// End of file

Added: short/3D/PyLith/branches/pylith-swig/modulesrc/materials/Material.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/materials/Material.i	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/materials/Material.i	2009-03-13 21:54:02 UTC (rev 14315)
@@ -0,0 +1,155 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file modulesrc/materials/Material.i
+ *
+ * Python interface to C++ abstract base Material.
+ */
+
+namespace pylith {
+  namespace materials {
+
+    class Material
+    { // class Material
+
+      // PUBLIC METHODS /////////////////////////////////////////////////
+    public :
+      
+      /** Default constructor.
+       *
+       * @param dimension Spatial dimension associated with material.
+       * @param tensorSize Array of names of database values for material.
+       * @param metadata Metadata for physical properties and state variables.
+       */
+      Material(const int dimension,
+	       const int tensorSize,
+	       const pylith::materials::Metadata& metadata);
+
+      /// Destructor.
+      virtual
+      ~Material(void);
+
+      /** Get spatial dimension of material.
+       *
+       * @returns Spatial dimension.
+       */
+      int dimension(void) const;
+      
+      /** Set identifier of material.
+       *
+       * @param value Material identifier
+       */
+      void id(const int value);
+      
+      /** Get identifier of material.
+       *
+       * @returns Material identifier
+       */
+      int id(void) const;
+      
+      /** Set label of material.
+       *
+       * @param value Label of material
+       */
+      void label(const char* value);
+      
+      /** Get label of material.
+       *
+       * @returns Label of material
+       */
+      const std::string& label(void) const;
+      
+      /** Set current time step.
+       *
+       * @param dt Current time step.
+       */
+      virtual
+      void timeStep(const double dt);
+      
+      /** Get current time step.
+       *
+       * @returns Current time step.
+       */
+      double timeStep(void) const;
+      
+      /** Set database for physical property parameters.
+       *
+       * @param value Pointer to database.
+       */
+      void dbProperties(spatialdata::spatialdb::SpatialDB* value);
+      
+      /** Set database for initial state variables.
+       *
+       * @param value Pointer to database.
+       */
+      void dbInitialState(spatialdata::spatialdb::SpatialDB* value);
+      
+      /** Set scales used to nondimensionalize physical properties.
+       *
+       * @param dim Nondimensionalizer
+       */
+      void normalizer(const spatialdata::units::Nondimensional& dim);
+      
+      /** Get size of stress/strain tensor associated with material.
+       *
+       * @returns Size of array holding stress/strain tensor.
+       */
+      int tensorSize(void) const;
+      
+      /** Get flag indicating whether Jacobian matrix must be reformed for
+       * current state.
+       *
+       * @returns True if Jacobian matrix must be reformed, false otherwise.
+       */
+      bool needNewJacobian(void) const;
+      
+      /// Reset flag indicating whether Jacobian matrix must be reformed for
+      /// current state.
+      void resetNeedNewJacobian(void);
+      
+      // PROTECTED METHODS //////////////////////////////////////////////
+    protected :
+      
+      /** Compute properties from values in spatial database.
+       *
+       * @param propValues Array of property values.
+       * @param dbValues Array of database values.
+       */
+      virtual
+      void _dbToProperties(double* const propValues,
+			   const double_array& dbValues) const = 0;
+      
+      /** Nondimensionalize properties.
+       *
+       * @param values Array of property values.
+       * @param nvalues Number of values.
+       */
+      virtual
+      void _nondimProperties(double* const values,
+			     const int nvalues) const = 0;
+      
+      /** Dimensionalize properties.
+       *
+       * @param values Array of property values.
+       * @param nvalues Number of values.
+       */
+      virtual
+      void _dimProperties(double* const values,
+			  const int nvalues) const = 0;
+
+    }; // class Material
+
+  } // materials
+} // pylith
+
+
+// End of file 

Added: short/3D/PyLith/branches/pylith-swig/modulesrc/materials/materials.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/materials/materials.i	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/materials/materials.i	2009-03-13 21:54:02 UTC (rev 14315)
@@ -0,0 +1,57 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+// SWIG interface
+%module materials
+
+// Header files for module C++ code
+%{
+#include "pylith/materials/materialsfwd.hh" // forward declarations
+
+#include "spatialdata/spatialdb/spatialdbfwd.hh" // forward declarations
+#include "spatialdata/units/unitsfwd.hh" // forward declarations
+
+#include "pylith/materials/ElasticMaterial.hh"
+#include "pylith/materials/ElasticStrain1D.hh"
+
+#include "pylith/utils/arrayfwd.hh"
+%}
+
+%include "exception.i"
+%exception {
+  try {
+    $action
+  } catch (const std::exception& err) {
+    SWIG_exception(SWIG_RuntimeError, err.what());
+  } // try/catch
+ } // exception
+
+%include "typemaps.i"
+%include "../include/doublearray.i"
+
+// Numpy interface stuff
+%{
+#define SWIG_FILE_WITH_INIT
+%}
+%include "../include/numpy.i"
+%init %{
+import_array();
+%}
+
+// Interfaces
+%include "Material.i"
+%include "ElasticMaterial.i"
+%include "ElasticStrain1D.i"
+
+
+// End of file
+



More information about the CIG-COMMITS mailing list