[cig-commits] r8642 - in short/3D/PyLith/trunk: modulesrc/bc pylith
pylith/bc
willic3 at geodynamics.org
willic3 at geodynamics.org
Thu Dec 13 10:34:40 PST 2007
Author: willic3
Date: 2007-12-13 10:34:40 -0800 (Thu, 13 Dec 2007)
New Revision: 8642
Added:
short/3D/PyLith/trunk/pylith/bc/Neumann.py
Modified:
short/3D/PyLith/trunk/modulesrc/bc/bc.pyxe.src
short/3D/PyLith/trunk/pylith/Makefile.am
Log:
Added top-level Python for traction BC, along with associated modulesrc
and Makefile changes.
Modified: short/3D/PyLith/trunk/modulesrc/bc/bc.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/bc/bc.pyxe.src 2007-12-13 18:19:48 UTC (rev 8641)
+++ short/3D/PyLith/trunk/modulesrc/bc/bc.pyxe.src 2007-12-13 18:34:40 UTC (rev 8642)
@@ -16,6 +16,7 @@
#include "pylith/feassemble/Integrator.hh"
#include "pylith/bc/AbsorbingDampers.hh"
#include "pylith/bc/Dirichlet.hh"
+#include "pylith/bc/Neumann.hh"
#include "pylith/utils/array.hh"
@@ -741,4 +742,329 @@
AbsorbingDampers_useSolnIncr_set(self.thisptr, flag)
+# ----------------------------------------------------------------------
+cdef class Neumann(BoundaryCondition):
+
+ def __init__(self):
+ """
+ Constructor.
+ """
+ # create shim for constructor
+ #embed{ void* Neumann_constructor()
+ void* result = 0;
+ try {
+ result = (void*)(new pylith::bc::Neumann);
+ assert(0 != result);
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (const ALE::Exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.msg().c_str()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ return result;
+ #}embed
+ BoundaryCondition.__init__(self)
+ self.thisptr = Neumann_constructor()
+ self.handle = self._createHandle()
+ return
+
+
+ BoundaryCondition.__init__(self)
+ self.thisptr = Neumann_constructor()
+ self.handle = self._createHandle()
+
+ def integrateResidual(self, residual, t, fields, mesh):
+ """
+ Integrate contributions to residual term (r) for operator.
+ """
+ # create shim for method 'integrateResidual'
+ #embed{ void Neumann_integrateResidual(void* objVptr, void* residualVptr, double t, void* fieldsVptr, void* meshVptr)
+ try {
+ assert(0 != objVptr);
+ assert(0 != residualVptr);
+ assert(0 != fieldsVptr);
+ assert(0 != meshVptr);
+ ALE::Obj<ALE::Mesh>* mesh =
+ (ALE::Obj<ALE::Mesh>*) meshVptr;
+ ALE::Obj<pylith::real_section_type>* residual =
+ (ALE::Obj<pylith::real_section_type>*) residualVptr;
+ pylith::topology::FieldsManager* fields =
+ (pylith::topology::FieldsManager*) fieldsVptr;
+ ((pylith::bc::Neumann*) objVptr)->integrateResidual(*residual,
+ t, fields, *mesh);
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (const ALE::Exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.msg().c_str()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ #}embed
+ if mesh.name != "pylith_topology_Mesh":
+ raise TypeError, \
+ "Argument must be extension module type 'Mesh'."
+ Neumann_integrateResidual(self.thisptr,
+ PyCObject_AsVoidPtr(residual),
+ t,
+ ptrFromHandle(fields),
+ ptrFromHandle(mesh))
+ return
+
+
+ def integrateJacobian(self, mat, t, fields, mesh):
+ """
+ Compute contributions to Jacobian matrix (A) associated with operator.
+ """
+ # create shim for method 'integrateJacobian'
+ #embed{ void Neumann_integrateJacobian(void* objVptr, void* matVptr, double t, void* fieldsVptr, void* meshVptr)
+ try {
+ assert(0 != objVptr);
+ assert(0 != matVptr);
+ assert(0 != fieldsVptr);
+ assert(0 != meshVptr);
+ ALE::Obj<ALE::Mesh>* mesh =
+ (ALE::Obj<ALE::Mesh>*) meshVptr;
+ PetscMat* mat = (PetscMat*) matVptr;
+ pylith::topology::FieldsManager* fields =
+ (pylith::topology::FieldsManager*) fieldsVptr;
+ ((pylith::bc::Neumann*) objVptr)->integrateJacobian(
+ mat, t, fields, *mesh);
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (const ALE::Exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.msg().c_str()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ #}embed
+ if mesh.name != "pylith_topology_Mesh":
+ raise TypeError, \
+ "Argument 'mesh' must be extension module type 'Mesh'."
+ Neumann_integrateJacobian(self.thisptr,
+ PyCObject_AsVoidPtr(mat),
+ t,
+ ptrFromHandle(fields),
+ ptrFromHandle(mesh))
+ return
+
+
+ def updateState(self, t, fields, mesh):
+ """
+ Update state variables as needed.
+ """
+ # create shim for method 'updateState'
+ #embed{ void Neumann_updateState(void* objVptr, double t, void* fieldsVptr, void* meshVptr)
+ try {
+ assert(0 != objVptr);
+ assert(0 != fieldsVptr);
+ assert(0 != meshVptr);
+ pylith::topology::FieldsManager* fields =
+ (pylith::topology::FieldsManager*) fieldsVptr;
+ ALE::Obj<ALE::Mesh>* mesh =
+ (ALE::Obj<ALE::Mesh>*) meshVptr;
+ ((pylith::bc::Neumann*) objVptr)->updateState(t, fields, *mesh);
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (const ALE::Exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.msg().c_str()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ #}embed
+ if fields.name != "pylith_topology_FieldsManager":
+ raise TypeError, \
+ "Argument 'fields' must be extension module type 'FieldsManager'."
+ if mesh.name != "pylith_topology_Mesh":
+ raise TypeError, \
+ "Argument 'mesh' must be extension module type 'Mesh'."
+ Neumann_updateState(self.thisptr,
+ t,
+ ptrFromHandle(fields),
+ ptrFromHandle(mesh))
+ return
+
+
+ def verifyConfiguration(self, mesh):
+ """
+ Verify compatibility of configuration settings.
+ """
+ # create shim for method 'verifyConfiguration'
+ #embed{ void Neumann_verifyConfiguration(void* objVptr, void* meshVptr)
+ try {
+ assert(0 != objVptr);
+ assert(0 != meshVptr);
+ ALE::Obj<ALE::Mesh>* mesh =
+ (ALE::Obj<ALE::Mesh>*) meshVptr;
+ ((pylith::bc::Neumann*) objVptr)->verifyConfiguration(*mesh);
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (const ALE::Exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.msg().c_str()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ #}embed
+ if mesh.name != "pylith_topology_Mesh":
+ raise TypeError, \
+ "Argument 'mesh' must be extension module type 'Mesh'."
+ Neumann_verifyConfiguration(self.thisptr,
+ ptrFromHandle(mesh))
+ return
+
+
+ def _createHandle(self):
+ """
+ Wrap pointer to C++ object in PyCObject.
+ """
+ return PyCObject_FromVoidPtr(self.thisptr, BoundaryCondition_destructor)
+
+
+ property quadrature:
+ def __set__(self, q):
+ """
+ Set quadrature.
+ """
+ # create shim for method 'quadrature'
+ #embed{ void Neumann_quadrature_set(void* objVptr, void* qVptr)
+ try {
+ assert(0 != objVptr);
+ pylith::feassemble::Quadrature* quadrature =
+ (pylith::feassemble::Quadrature*) qVptr;
+ ((pylith::bc::Neumann*) objVptr)->quadrature(quadrature);
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (const ALE::Exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.msg().c_str()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ #}embed
+ if not q.name == "pylith_feassemble_Quadrature":
+ raise TypeError, \
+ "Argument must be extension module type 'Quadrature'."
+ Neumann_quadrature_set(self.thisptr, ptrFromHandle(q))
+
+
+ property timeStep:
+ def __set__(self, dt):
+ """
+ Set timeStep.
+ """
+ # create shim for method 'timeStep'
+ #embed{ void Neumann_timeStep_set(void* objVptr, double dt)
+ try {
+ assert(0 != objVptr);
+ ((pylith::bc::Neumann*) objVptr)->timeStep(dt);
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (const ALE::Exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.msg().c_str()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ #}embed
+ Neumann_timeStep_set(self.thisptr, dt)
+
+
+ property stableTimeStep:
+ def __get__(self):
+ """
+ Get stable time step.
+ """
+ # create shim for method 'stableTimeStep'
+ #embed{ double Neumann_stableTimeStep_get(void* objVptr)
+ double result = 0.0;
+ try {
+ assert(0 != objVptr);
+ result =
+ ((pylith::bc::Neumann*) objVptr)->stableTimeStep();
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (const ALE::Exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.msg().c_str()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ return result;
+ #}embed
+ return Neumann_stableTimeStep_get(self.thisptr)
+
+
+ property needNewJacobian:
+ def __get__(self):
+ """
+ Set timeStep.
+ """
+ # create shim for method 'needNewJacobian'
+ #embed{ int Neumann_needNewJacobian_get(void* objVptr)
+ int result = 0;
+ try {
+ assert(0 != objVptr);
+ result =
+ ((pylith::bc::Neumann*) objVptr)->needNewJacobian();
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (const ALE::Exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.msg().c_str()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ return result;
+ #}embed
+ return Neumann_needNewJacobian_get(self.thisptr)
+
+
+ property useSolnIncr:
+ def __set__(self, flag):
+ """
+ Set solution increment flag.
+ """
+ # create shim for method 'useSolnIncr'
+ #embed{ void Neumann_useSolnIncr_set(void* objVptr, int flag)
+ try {
+ assert(0 != objVptr);
+ ((pylith::bc::Neumann*) objVptr)->useSolnIncr(flag);
+ } catch (const std::exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.what()));
+ } catch (const ALE::Exception& err) {
+ PyErr_SetString(PyExc_RuntimeError,
+ const_cast<char*>(err.msg().c_str()));
+ } catch (...) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Caught unknown C++ exception.");
+ } // try/catch
+ #}embed
+ Neumann_useSolnIncr_set(self.thisptr, flag)
+
+
# End of file
+
Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am 2007-12-13 18:19:48 UTC (rev 8641)
+++ short/3D/PyLith/trunk/pylith/Makefile.am 2007-12-13 18:34:40 UTC (rev 8642)
@@ -22,6 +22,7 @@
bc/BCTwoSides.py \
bc/BCFourSides.py \
bc/BCSixSides.py \
+ bc/Neumann.py \
faults/__init__.py \
faults/BruneSlipFn.py \
faults/EqKinSrc.py \
Added: short/3D/PyLith/trunk/pylith/bc/Neumann.py
===================================================================
--- short/3D/PyLith/trunk/pylith/bc/Neumann.py 2007-12-13 18:19:48 UTC (rev 8641)
+++ short/3D/PyLith/trunk/pylith/bc/Neumann.py 2007-12-13 18:34:40 UTC (rev 8642)
@@ -0,0 +1,145 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/bc/Neumann.py
+##
+## @brief Python object for managing traction boundary conditions.
+##
+## Factory: boundary_condition
+
+from BoundaryCondition import BoundaryCondition
+from pylith.feassemble.Integrator import Integrator
+
+# Neumann class
+class Neumann(BoundaryCondition, Integrator):
+ """
+ Python object for managing traction boundary conditions.
+
+ Factory: boundary_condition
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(BoundaryCondition.Inventory):
+ """
+ Python object for managing BoundaryCondition facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing BoundaryCondition facilities and properties.
+ ##
+ ## \b Properties
+ ## @li None
+ ##
+ ## \b Facilities
+ ## @li \b quadrature Quadrature object for numerical integration
+
+ import pyre.inventory
+
+ from pylith.feassemble.quadrature.Quadrature import Quadrature
+ quadrature = pyre.inventory.facility("quadrature", factory=Quadrature)
+ quadrature.meta['tip'] = "Quadrature object for numerical integration."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="neumann"):
+ """
+ Constructor.
+ """
+ BoundaryCondition.__init__(self, name)
+ Integrator.__init__(self)
+ self._loggingPrefix = "NeBC "
+ return
+
+
+ def preinitialize(self, mesh):
+ """
+ Do pre-initialization setup.
+ """
+ BoundaryCondition.preinitialize(self, mesh)
+ Integrator.preinitialize(self, mesh)
+ self.quadrature.preinitialize()
+ return
+
+
+ def initialize(self):
+ """
+ Initialize Neumann boundary condition.
+ """
+ logEvent = "%sinit" % self._loggingPrefix
+
+ self._logger.eventBegin(logEvent)
+ self.cppHandle.quadrature = self.quadrature.cppHandle
+ BoundaryCondition.initialize(self)
+ self._logger.eventEnd(logEvent)
+ return
+
+
+ def verifyConfiguration(self):
+ """
+ Verify compatibility of configuration.
+ """
+ BoundaryCondition.verifyConfiguration(self)
+ if self.quadrature.cellDim != self.mesh.dimension()-1:
+ raise ValueError, \
+ "Quadrature scheme and mesh are incompatible.\n" \
+ "Dimension for quadrature: %d\n" \
+ "Dimension of mesh boundary '%s': %d" % \
+ (self.quadrature.cellDim,
+ self.label, self.mesh.dimension()-1)
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Setup members using inventory.
+ """
+ BoundaryCondition._configure(self)
+ self.quadrature = self.inventory.quadrature
+ return
+
+
+ def _createCppHandle(self):
+ """
+ Create handle to corresponding C++ object.
+ """
+ if None == self.cppHandle:
+ import pylith.bc.bc as bindings
+ self.cppHandle = bindings.Neumann()
+ return
+
+
+ def _setupLogging(self):
+ """
+ Setup event logging.
+ """
+ Integrator._setupLogging(self)
+
+ events = ["init"]
+ for event in events:
+ self._logger.registerEvent("%s%s" % (self._loggingPrefix, event))
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def boundary_condition():
+ """
+ Factory associated with Neumann.
+ """
+ return Neumann()
+
+
+# End of file
More information about the cig-commits
mailing list