# -*- Pyrex -*- # # ====================================================================== # # Brad T. Aagaard # U.S. Geological Survey # # {LicenseText} # # ====================================================================== # #header{ #include "pylith/bc/BoundaryCondition.hh" #include "pylith/feassemble/Constraint.hh" #include "pylith/bc/Dirichlet.hh" #include "pylith/utils/array.hh" #include #include #include #}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* mesh = (ALE::Obj*) 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(err.what())); } catch (const ALE::Exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.msg().c_str())); } 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 _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(err.what())); } catch (const ALE::Exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.msg().c_str())); } 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(err.what())); } catch (const ALE::Exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.msg().c_str())); } 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(err.what())); } catch (const ALE::Exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.msg().c_str())); } 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(err.what())); } catch (const ALE::Exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.msg().c_str())); } 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(err.what())); } catch (const ALE::Exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.msg().c_str())); } 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(err.what())); } catch (const ALE::Exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.msg().c_str())); } catch (...) { PyErr_SetString(PyExc_RuntimeError, "Caught unknown C++ exception."); } // try/catch #}embed cdef int* fixedDOF numFixedDOF = len(value) fixedDOF = 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) 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 Dirichlet_setConstraintSizes(void* objVptr, void* fieldVptr, void* meshVptr) try { assert(0 != objVptr); assert(0 != fieldVptr); assert(0 != meshVptr); ALE::Obj* field = (ALE::Obj*) fieldVptr; ALE::Obj* mesh = (ALE::Obj*) meshVptr; ((pylith::bc::Dirichlet*) objVptr)->setConstraintSizes(*field, *mesh); } catch (const std::exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.what())); } catch (const ALE::Exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.msg().c_str())); } 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'." Dirichlet_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 Dirichlet_setConstraints(void* objVptr, void* fieldVptr, void* meshVptr) try { assert(0 != objVptr); assert(0 != fieldVptr); assert(0 != meshVptr); ALE::Obj* field = (ALE::Obj*) fieldVptr; ALE::Obj* mesh = (ALE::Obj*) meshVptr; ((pylith::bc::Dirichlet*) objVptr)->setConstraints(*field, *mesh); } catch (const std::exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.what())); } catch (const ALE::Exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.msg().c_str())); } 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'." Dirichlet_setConstraints(self.thisptr, PyCObject_AsVoidPtr(field), ptrFromHandle(mesh)) return def setField(self, t, field, mesh): """ Set values in field. """ # create shim for method 'setField' #embed{ void Dirichlet_setField(void* objVptr, double t, void* fieldVptr, void* meshVptr) try { assert(0 != objVptr); assert(0 != fieldVptr); assert(0 != meshVptr); ALE::Obj* field = (ALE::Obj*) fieldVptr; ALE::Obj* mesh = (ALE::Obj*) meshVptr; ((pylith::bc::Dirichlet*) objVptr)->setField(t, *field, *mesh); } catch (const std::exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.what())); } catch (const ALE::Exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.msg().c_str())); } 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'." Dirichlet_setField(self.thisptr, t, PyCObject_AsVoidPtr(field), ptrFromHandle(mesh)) return property useSolnIncr: def __set__(self, flag): """ Set solution increment flag. """ # create shim for method 'useSolnIncr' #embed{ void Dirichlet_useSolnIncr_set(void* objVptr, int flag) try { assert(0 != objVptr); ((pylith::bc::Dirichlet*) objVptr)->useSolnIncr(flag); } catch (const std::exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.what())); } catch (const ALE::Exception& err) { PyErr_SetString(PyExc_RuntimeError, const_cast(err.msg().c_str())); } catch (...) { PyErr_SetString(PyExc_RuntimeError, "Caught unknown C++ exception."); } // try/catch #}embed Dirichlet_useSolnIncr_set(self.thisptr, flag) # End of file