[cig-commits] r6462 - in short/3D/PyLith/trunk: . examples/twotri3 modulesrc/topology pylith/problems

brad at geodynamics.org brad at geodynamics.org
Thu Mar 29 13:03:02 PDT 2007


Author: brad
Date: 2007-03-29 13:03:01 -0700 (Thu, 29 Mar 2007)
New Revision: 6462

Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/examples/twotri3/pylithapp.cfg
   short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
   short/3D/PyLith/trunk/pylith/problems/Explicit.py
   short/3D/PyLith/trunk/pylith/problems/TimeDependent.py
Log:
Added creating/getting sections from Mesh. Added spatial dimension of problem to TimeDependent.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2007-03-29 17:14:40 UTC (rev 6461)
+++ short/3D/PyLith/trunk/TODO	2007-03-29 20:03:01 UTC (rev 6462)
@@ -2,6 +2,9 @@
 MAIN PRIORITIES (Brad)
 ======================================================================
 
+Error checking
+  add isNull() assertions before using ALE::Obj.
+
 1. Finish implementing ExplicitElasticity
    a. C++
    b. Python object

Modified: short/3D/PyLith/trunk/examples/twotri3/pylithapp.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/twotri3/pylithapp.cfg	2007-03-29 17:14:40 UTC (rev 6461)
+++ short/3D/PyLith/trunk/examples/twotri3/pylithapp.cfg	2007-03-29 20:03:01 UTC (rev 6462)
@@ -31,6 +31,7 @@
 [pylithapp.eqdeformation]
 total_time = 1.0*s
 default_dt = 1.0*s
+dimension = 2
 
 # ----------------------------------------------------------------------
 # materials

Modified: short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-03-29 17:14:40 UTC (rev 6461)
+++ short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-03-29 20:03:01 UTC (rev 6462)
@@ -43,6 +43,18 @@
   MeshPtr_destructor_cpp(obj)
   return
 
+cdef void RealSection_destructor(void* obj):
+  """
+  Destroy real section.
+  """
+  #embed{ void RealSection_destructor_cpp(void* pObj)
+  typedef ALE::Mesh::real_section_type real_section_type;
+  ALE::Obj<real_section_type>* section = (ALE::Obj<real_section_type>*) pObj;
+  delete section;
+  #}embed
+  RealSection_destructor_cpp(obj)
+  return
+
 # ----------------------------------------------------------------------
 cdef class Mesh:
 
@@ -75,6 +87,69 @@
     return
 
 
+  def getRealSection(self, label):
+    """
+    Get real section from mesh.
+    """
+    # create shim for getRealSection
+    #embed{ void* Mesh_getRealSection(void* pObj, char* label)
+    typedef ALE::Mesh::real_section_type real_section_type;
+    
+    void* result = 0;
+    try {
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) pObj;
+      assert(0 != mesh);
+      result =
+        (void*) new ALE::Obj<real_section_type>((*mesh)->getRealSection(label));
+    } catch (const std::exception& err) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      const_cast<char*>(err.what()));
+    } catch (...) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      "Caught unknown C++ exception.");
+    } // try/catch
+    return result;
+    #}embed
+    cdef void* ptr
+    ptr = Mesh_getRealSection(self.thisptr, label)
+    return PyCObject_FromVoidPtr(ptr, RealSection_destructor)
+    
+
+  def createRealSection(self, label, fiberDim):
+    """
+    Create real section in mesh.
+    """
+    # create shim for createRealSection
+    #embed{ void* Mesh_createRealSection(void* pObj, char* label, int fiberDim)
+    typedef ALE::Mesh::real_section_type real_section_type;
+    
+    void* result = 0;
+    try {
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) pObj;
+      assert(0 != mesh);
+      ALE::Obj<real_section_type>* pSection =
+        new ALE::Obj<real_section_type>((*mesh)->getRealSection(label));
+      assert(0 != *pSection);
+      ALE::Obj<real_section_type>& section = *pSection;
+      assert(!section.isNull());
+      const ALE::Mesh::topology_type::patch_type patch = 0;      
+      section->setFiberDimensionByDepth(patch, 0, fiberDim);
+      section->allocate();
+      result = (void*) *pSection;
+    } catch (const std::exception& err) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      const_cast<char*>(err.what()));
+    } catch (...) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      "Caught unknown C++ exception.");
+    } // try/catch
+    return result;
+    #}embed
+    cdef void* ptr
+    ptr = Mesh_createRealSection(self.thisptr, label, fiberDim)
+    return PyCObject_FromVoidPtr(ptr, RealSection_destructor)
+    
+
   def _createHandle(self):
     """
     Wrap pointer to C++ object in PyCObject.

Modified: short/3D/PyLith/trunk/pylith/problems/Explicit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Explicit.py	2007-03-29 17:14:40 UTC (rev 6461)
+++ short/3D/PyLith/trunk/pylith/problems/Explicit.py	2007-03-29 20:03:01 UTC (rev 6462)
@@ -61,7 +61,7 @@
     return
 
 
-  def initialize(self, mesh, materialsBin):
+  def initialize(self, mesh, materialsBin, spaceDim):
     """
     Create explicit integrators for each element family.
     """
@@ -70,17 +70,28 @@
     self._info.log("Initializing integrators.")
     self.integrators = []
     for material in materialsBin.materials:
+      if material.quadrature.spaceDim != spaceDim:
+        raise ValueError, \
+              "Spatial dimension of problem is '%d' but quadrature " \
+              "for material '%s' is for spatial dimension '%d'." % \
+              (spaceDim, material.label, material.quadrature.spaceDim)
       integrator = ExplicitElasticity()
       integrator.initQuadrature(material.quadrature)
       integrator.initMaterial(mesh, material)
       self.integrators.append(integrator)
 
     self._info.log("Creating fields and matrices.")
-    # ADD STUFF HERE
+    # self.jacobian = mesh.cppHandle.getPetscMat()
+    self.dispT = mesh.cppHandle.createRealSection("dispT", spaceDim)
+    self.dispTmdt = mesh.cppHandle.createRealSection("dispTmdt", spaceDim)
+    self.dispTpdt = mesh.cppHandle.createRealSection("dispTpdt", spaceDim)
+    self.constant = mesh.cppHandle.createRealSection("constant", spaceDim)
+    self.coordinates = mesh.cppHandle.getRealSection("coordinates")
 
     self._info.log("Integrating Jacobian of operator.")
     #for integrator in integrators:
-    #  integrator.integrateJacobian(jacobian, dispT, coords) 
+    #  integrator.integrateJacobian(self.jacobian, self.dispT,
+    #                               self.coordinates) 
     return
 
 
@@ -107,8 +118,10 @@
     Advance to next time step.
     """
     self._info.log("Integrating constant term in operator.")
+    # Need to zero out sections
     #for integrator in self.integrators:
-    #  integrator.integrateConstant(constant, dispT, dispTmdt, coords)
+    #  integrator.integrateConstant(self.constant, self.dispT, self.dispTmdt,
+    #                               self.coordinates)
 
     self._info.log("Solving equations.")
     # solve

Modified: short/3D/PyLith/trunk/pylith/problems/TimeDependent.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeDependent.py	2007-03-29 17:14:40 UTC (rev 6461)
+++ short/3D/PyLith/trunk/pylith/problems/TimeDependent.py	2007-03-29 20:03:01 UTC (rev 6462)
@@ -40,6 +40,7 @@
     ## \b Properties
     ## @li \b total_time Time duration for simulation.
     ## @li \b default_dt Default time step.
+    ## @li \b dimension Spatial dimension of problem space.
     ##
     ## \b Facilities
     ## @li \b formulation Formulation for solving PDE.
@@ -56,6 +57,10 @@
                                  validator=pyre.inventory.greater(0.0*second))
     dt.meta['tip'] = "Default time step for simulation."
 
+    dimension = pyre.inventory.int("dimension", default=3,
+                                   validator=pyre.inventory.choice([1,2,3]))
+    dimension.meta['tip'] = "Spatial dimension of problem space."
+
     from Explicit import Explicit
     formulation = pyre.inventory.facility("formulation",
                                           family="pde_formulation",
@@ -86,7 +91,7 @@
     """
     self._info.log("Initializing problem.")
     self.mesh = mesh
-    self.formulation.initialize(mesh, self.materials)
+    self.formulation.initialize(mesh, self.materials, self.dimension)
     return
 
 
@@ -148,6 +153,7 @@
     Problem._configure(self)
     self.totalTime = self.inventory.totalTime
     self.dt = self.inventory.dt
+    self.dimension = self.inventory.dimension
     self.formulation = self.inventory.formulation
     self.checkpointTimer = self.inventory.checkpointTimer
     return



More information about the cig-commits mailing list