[cig-commits] r6912 - in short/3D/PyLith/trunk: . libsrc/bc modulesrc modulesrc/bc

brad at geodynamics.org brad at geodynamics.org
Wed May 16 21:23:37 PDT 2007


Author: brad
Date: 2007-05-16 21:23:37 -0700 (Wed, 16 May 2007)
New Revision: 6912

Added:
   short/3D/PyLith/trunk/modulesrc/bc/
   short/3D/PyLith/trunk/modulesrc/bc/Makefile.am
   short/3D/PyLith/trunk/modulesrc/bc/bc.pyxe.src
Modified:
   short/3D/PyLith/trunk/configure.ac
   short/3D/PyLith/trunk/libsrc/bc/BoundaryCondition.hh
   short/3D/PyLith/trunk/modulesrc/Makefile.am
Log:
Added bindings for Dirichlet boundary conditions.

Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac	2007-05-17 01:40:31 UTC (rev 6911)
+++ short/3D/PyLith/trunk/configure.ac	2007-05-17 04:23:37 UTC (rev 6912)
@@ -209,6 +209,7 @@
 		libsrc/utils/Makefile
 		libsrc/topology/Makefile
                 modulesrc/Makefile
+                modulesrc/bc/Makefile
                 modulesrc/faults/Makefile
                 modulesrc/feassemble/Makefile
                 modulesrc/materials/Makefile

Modified: short/3D/PyLith/trunk/libsrc/bc/BoundaryCondition.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/bc/BoundaryCondition.hh	2007-05-17 01:40:31 UTC (rev 6911)
+++ short/3D/PyLith/trunk/libsrc/bc/BoundaryCondition.hh	2007-05-17 04:23:37 UTC (rev 6912)
@@ -116,7 +116,7 @@
   void setConstraints(const ALE::Obj<real_section_type>& field,
 		      const ALE::Obj<ALE::Mesh>& mesh);
 
-  /** Set constrained degrees of freedom in field.
+  /** Integrate boundary condition's contribution to the Jacobian.
    *
    * @param jacobian Matrix for Jacobian of system
    * @param field Solution field
@@ -127,7 +127,7 @@
 			 const ALE::Obj<real_section_type>& field,
 			 const ALE::Obj<ALE::Mesh>& mesh);
 
-  /** Set constrained degrees of freedom in field.
+  /** Integrate boundary condition's contribution to the residual.
    *
    * @param residual Residual field
    * @param fieldT Solution field at time t

Modified: short/3D/PyLith/trunk/modulesrc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/Makefile.am	2007-05-17 01:40:31 UTC (rev 6911)
+++ short/3D/PyLith/trunk/modulesrc/Makefile.am	2007-05-17 04:23:37 UTC (rev 6912)
@@ -11,6 +11,7 @@
 #
 
 SUBDIRS = \
+	bc \
 	faults \
 	feassemble \
 	materials \

Added: short/3D/PyLith/trunk/modulesrc/bc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/bc/Makefile.am	2007-05-17 01:40:31 UTC (rev 6911)
+++ short/3D/PyLith/trunk/modulesrc/bc/Makefile.am	2007-05-17 04:23:37 UTC (rev 6912)
@@ -0,0 +1,47 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+subpackage = bc
+include $(top_srcdir)/subpackage.am
+
+subpkgpyexec_LTLIBRARIES = bcmodule.la
+
+bcmodule_la_LDFLAGS = -module
+
+bcmodule_la_SOURCES = bc.pyxe
+
+nodist_bcmodule_la_SOURCES = \
+	bc.c bc_embed.cpp bc_embed.h
+
+bcmodule_la_LIBADD = \
+	$(top_builddir)/libsrc/libpylith.la \
+	$(PETSC_LIB)
+
+if ENABLE_CUBIT
+  bcmodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
+endif
+
+INCLUDES += -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
+
+bc.pyx bc_embed.cpp  bc_embed.h: bc.pyxe
+	pyrexembed bc.pyxe
+bc.pyxe: $(srcdir)/bc.pyxe.src
+	cp $(srcdir)/bc.pyxe.src $@
+bc_embed.cpp: bc_embed.h
+bc_embed.h: bc.pyx
+
+.pyx.c:
+	pyrexc $<
+
+CLEANFILES = bc.pyxe bc.pyx bc.c *_embed.*
+
+# End of file 

Added: short/3D/PyLith/trunk/modulesrc/bc/bc.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/bc/bc.pyxe.src	2007-05-17 01:40:31 UTC (rev 6911)
+++ short/3D/PyLith/trunk/modulesrc/bc/bc.pyxe.src	2007-05-17 04:23:37 UTC (rev 6912)
@@ -0,0 +1,426 @@
+# -*- Pyrex -*-
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+#header{
+#include "pylith/bc/BoundaryCondition.hh"
+#include "pylith/bc/Dirichlet.hh"
+
+#include "pylith/utils/array.hh"
+
+#include <assert.h>
+#include <stdexcept>
+#include <Python.h>
+#}header
+
+# ----------------------------------------------------------------------
+cdef extern from "Python.h":
+  object PyCObject_FromVoidPtr(void*, void (*destruct)(void*))
+  void* PyCObject_AsVoidPtr(object)
+
+cdef void* ptrFromHandle(obj):
+  """Extract pointer from PyCObject."""
+  return PyCObject_AsVoidPtr(obj.handle)
+
+cdef extern from "stdlib.h":
+  ctypedef unsigned long size_t
+  void* malloc(size_t size)
+  void free(void* mem)
+
+cdef void BoundaryCondition_destructor(void* obj):
+  """
+  Destroy BoundaryCondition object.
+  """
+  # create shim for destructor
+  #embed{ void BoundaryCondition_destructor_cpp(void* objVptr)
+  pylith::bc::BoundaryCondition* pM = (pylith::bc::BoundaryCondition*) objVptr;
+  delete pM;
+  #}embed
+  BoundaryCondition_destructor_cpp(obj)
+  return
+
+
+# ----------------------------------------------------------------------
+cdef class BoundaryCondition:
+
+  cdef void* thisptr # Pointer to C++ object
+  cdef readonly object handle # PyCObject holding pointer to C++ object
+  cdef readonly object name # Identifier for object base type
+
+  def __init__(self):
+    """
+    Constructor.
+    """
+    self.handle = None
+    self.thisptr = NULL
+    self.name = "pylith_bc_BoundaryCondition"
+    return
+
+
+  def initialize(self, mesh, cs):
+    """
+    Initialize boundary condition.
+    """
+    # create shim for method 'initialize'
+    #embed{ void BoundaryCondition_initialize(void* objVptr, void* meshVptr, void* csVptr)
+    try {
+      assert(0 != objVptr);
+      assert(0 != meshVptr);
+      assert(0 != csVptr);
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
+      spatialdata::geocoords::CoordSys* cs =
+        (spatialdata::geocoords::CoordSys*) csVptr;
+      ((pylith::bc::BoundaryCondition*) objVptr)->initialize(*mesh, cs);
+      } 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      
+    #}embed
+
+    if not mesh.name == "pylith_topology_Mesh":
+      raise TypeError, \
+            "Argument must be extension module type " \
+            "'pylith::topology::Mesh'."
+    if not cs.name == "spatialdata_geocoords_CoordSys":
+      raise TypeError, \
+            "Argument must be extension module type " \
+            "'spatialdata::geocoords::CoordSys'."
+    BoundaryCondition_initialize(self.thisptr, ptrFromHandle(mesh), ptrFromHandle(cs))
+    return
+
+
+  def setConstraintSizes(self, field, mesh):
+    """
+    Set number of degrees of freedom that are constrained at points in field.
+    """
+    # create shim for method 'setConstraintSizes'
+    #embed{ void BoundaryCondition_setConstraintSizes(void* objVptr, void* fieldVptr, void* meshVptr)
+    try {
+      assert(0 != objVptr);
+      assert(0 != fieldVptr);
+      assert(0 != meshVptr);
+      ALE::Obj<pylith::real_section_type>* field = (ALE::Obj<pylith::real_section_type>*) fieldVptr;
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
+      ((pylith::bc::BoundaryCondition*) objVptr)->setConstraintSizes(*field, *mesh);
+      } 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      
+    #}embed
+
+    if not mesh.name == "pylith_topology_Mesh":
+      raise TypeError, \
+            "Argument must be extension module type " \
+            "'pylith::topology::Mesh'."
+    BoundaryCondition_setConstraintSizes(self.thisptr,
+                                         PyCObject_AsVoidPtr(field),
+                                         ptrFromHandle(mesh))
+    return
+
+
+  def setConstraints(self, field, mesh):
+    """
+    Set which degrees of freedom that are constrained at points in field.
+    """
+    # create shim for method 'setConstraints'
+    #embed{ void BoundaryCondition_setConstraints(void* objVptr, void* fieldVptr, void* meshVptr)
+    try {
+      assert(0 != objVptr);
+      assert(0 != fieldVptr);
+      assert(0 != meshVptr);
+      ALE::Obj<pylith::real_section_type>* field = (ALE::Obj<pylith::real_section_type>*) fieldVptr;
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
+      ((pylith::bc::BoundaryCondition*) objVptr)->setConstraints(*field, *mesh);
+      } 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      
+    #}embed
+
+    if not mesh.name == "pylith_topology_Mesh":
+      raise TypeError, \
+            "Argument must be extension module type " \
+            "'pylith::topology::Mesh'."
+    BoundaryCondition_setConstraints(self.thisptr, PyCObject_AsVoidPtr(field), ptrFromHandle(mesh))
+    return
+
+
+  def integrateJacobian(self, jacobian, field, mesh):
+    """
+    Integrate boundary condition's contribution to the Jacobian.
+    """
+    # create shim for method 'integrateJacobian'
+    #embed{ void BoundaryCondition_integrateJacobian(void* objVptr, void* jacobianVptr, void* fieldVptr, void* meshVptr)
+    try {
+      assert(0 != objVptr);
+      assert(0 != jacobianVptr);
+      assert(0 != fieldVptr);
+      assert(0 != meshVptr);
+      PetscMat* jacobian = (PetscMat*) jacobianVptr;
+      ALE::Obj<pylith::real_section_type>* field = (ALE::Obj<pylith::real_section_type>*) fieldVptr;
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
+      ((pylith::bc::BoundaryCondition*) objVptr)->integrateJacobian(jacobian, *field, *mesh);
+      } 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      
+    #}embed
+
+    if not mesh.name == "pylith_topology_Mesh":
+      raise TypeError, \
+            "Argument must be extension module type " \
+            "'pylith::topology::Mesh'."
+    BoundaryCondition_integrateJacobian(self.thisptr,
+                                        PyCObject_AsVoidPtr(jacobian),
+                                        PyCObject_AsVoidPtr(field),
+                                        ptrFromHandle(mesh))
+    return
+
+
+  def integrateResidual(self, residual, fieldT, fieldTmdt, mesh):
+    """
+    Integrate boundary condition's contribution to the residual.
+    """
+    # create shim for method 'integrateResidual'
+    #embed{ void BoundaryCondition_integrateResidual(void* objVptr, void* residualVptr, void* fieldTVptr, void* fieldTmdtVptr, void* meshVptr)
+    try {
+      assert(0 != objVptr);
+      assert(0 != residualVptr);
+      assert(0 != fieldTVptr);
+      assert(0 != fieldTmdtVptr);
+      assert(0 != meshVptr);
+      ALE::Obj<pylith::real_section_type>* residual = (ALE::Obj<pylith::real_section_type>*) residualVptr;
+      ALE::Obj<pylith::real_section_type>* fieldT = (ALE::Obj<pylith::real_section_type>*) fieldTVptr;
+      ALE::Obj<pylith::real_section_type>* fieldTmdt = (ALE::Obj<pylith::real_section_type>*) fieldTmdtVptr;
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
+      ((pylith::bc::BoundaryCondition*) objVptr)->integrateResidual(*residual, *fieldT, *fieldTmdt, *mesh);
+      } 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      
+    #}embed
+
+    if not mesh.name == "pylith_topology_Mesh":
+      raise TypeError, \
+            "Argument must be extension module type " \
+            "'pylith::topology::Mesh'."
+    BoundaryCondition_integrateResidual(self.thisptr,
+                                        PyCObject_AsVoidPtr(residual),
+                                        PyCObject_AsVoidPtr(fieldT),
+                                        PyCObject_AsVoidPtr(fieldTmdt),
+                                        ptrFromHandle(mesh))
+    return
+
+
+  def setField(self, t, field, mesh):
+    """
+    Set values in field.
+    """
+    # create shim for method 'setField'
+    #embed{ void BoundaryCondition_setField(void* objVptr, double t, void* fieldVptr, void* meshVptr)
+    try {
+      assert(0 != objVptr);
+      assert(0 != fieldVptr);
+      assert(0 != meshVptr);
+      ALE::Obj<pylith::real_section_type>* field = (ALE::Obj<pylith::real_section_type>*) fieldVptr;
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
+      ((pylith::bc::BoundaryCondition*) objVptr)->setField(t, *field, *mesh);
+      } 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      
+    #}embed
+
+    if not mesh.name == "pylith_topology_Mesh":
+      raise TypeError, \
+            "Argument must be extension module type " \
+            "'pylith::topology::Mesh'."
+    BoundaryCondition_setField(self.thisptr, t, PyCObject_AsVoidPtr(field),
+                               ptrFromHandle(mesh))
+    return
+
+
+  def _createHandle(self):
+    """
+    Wrap pointer to C++ object in PyCObject.
+    """
+    return PyCObject_FromVoidPtr(self.thisptr, BoundaryCondition_destructor)
+
+
+  property id:
+    def __set__(self, value):
+      """
+      Set identifier of material.
+      """
+      # create shim for method 'id'
+      #embed{ void BoundaryCondition_id_set(void* objVptr, int value)
+      try {
+        assert(0 != objVptr);
+        ((pylith::bc::BoundaryCondition*) objVptr)->id(value);
+      } 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
+      #}embed
+      BoundaryCondition_id_set(self.thisptr, value)
+
+    def __get__(self):
+      """
+      Get identifier of material.
+      """
+      # create shim for method 'id'
+      #embed{ int BoundaryCondition_id_get(void* objVptr)
+      int result = 0;
+      try {
+        assert(0 != objVptr);
+        result = ((pylith::bc::BoundaryCondition*) objVptr)->id();
+      } 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
+      return BoundaryCondition_id_get(self.thisptr)
+
+
+  property label:
+    def __set__(self, value):
+      """
+      Set label of material.
+      """
+      # create shim for method 'label'
+      #embed{ void BoundaryCondition_label_set(void* objVptr, char* value)
+      try {
+        assert(0 != objVptr);
+        ((pylith::bc::BoundaryCondition*) objVptr)->label(value);
+      } 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
+      #}embed
+      BoundaryCondition_label_set(self.thisptr, value)
+
+
+  property db:
+    def __set__(self, value):
+      """
+      Set spatial database for parameters.
+      """
+      # create shim for method 'db'
+      #embed{ void BoundaryCondition_db_set(void* objVptr, void* dbVptr)
+      try {
+        assert(0 != objVptr);
+        assert(0 != dbVptr);
+        spatialdata::spatialdb::SpatialDB* db =
+          (spatialdata::spatialdb::SpatialDB*) dbVptr;
+        ((pylith::bc::BoundaryCondition*) objVptr)->db(db);
+      } 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
+      #}embed
+      if not value.name == "spatialdata_spatialdb_SpatialDB":
+        raise TypeError, \
+              "Argument must be extension module type " \
+              "'spatialdata::spatialdb::SpatialDB'."
+      BoundaryCondition_db_set(self.thisptr, ptrFromHandle(value))
+
+
+# ----------------------------------------------------------------------
+cdef class Dirichlet(BoundaryCondition):
+
+  def __init__(self):
+    """
+    Constructor.
+    """
+    # create shim for constructor
+    #embed{ void* Dirichlet_constructor()
+    void* result = 0;
+    try {
+      result = (void*)(new pylith::bc::Dirichlet);
+      assert(0 != result);
+    } 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
+
+    BoundaryCondition.__init__(self)
+    self.thisptr = Dirichlet_constructor()
+    self.handle = self._createHandle()
+    return
+
+
+  property fixedDOF:
+    def __set__(self, value):
+      """
+      Set fixed DOF.
+      """
+      # create shim for method 'fixedDOF'
+      #embed{ void Dirichlet_fixedDOF_set(void* objVptr, int* dofVptr, int numFixedDOF)
+      try {
+        assert(0 != objVptr);
+        assert(0 != dofVptr);
+        pylith::int_array fixedDOF((int*) dofVptr, numFixedDOF);
+        ((pylith::bc::Dirichlet*) objVptr)->fixedDOF(fixedDOF);
+      } 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
+      #}embed
+      cdef int* fixedDOF
+      numFixedDOF = len(value)
+      fixedDOF = <int*> malloc(numFixedDOF*sizeof(int))
+      assert(fixedDOF != NULL)
+      for i from 0 <= i < numFixedDOF:
+        fixedDOF[i] = value[i]
+      Dirichlet_fixedDOF_set(self.thisptr, fixedDOF, numFixedDOF)
+      free(fixedDOF)
+
+
+# End of file 



More information about the cig-commits mailing list