From 814c144ecb462fd4c0e7b4b46b02c6650b4dc29e Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 9 May 2015 00:15:05 +0200 Subject: [PATCH] + FEM: add a couple of methods to Python interface --- src/Mod/Fem/App/FemMesh.cpp | 11 +++++ src/Mod/Fem/App/FemMesh.h | 2 + src/Mod/Fem/App/FemMeshPy.xml | 28 ++++++++++-- src/Mod/Fem/App/FemMeshPyImp.cpp | 78 +++++++++++++++++++++++++++++++- 4 files changed, 115 insertions(+), 4 deletions(-) diff --git a/src/Mod/Fem/App/FemMesh.cpp b/src/Mod/Fem/App/FemMesh.cpp index 00bca3d89..680614d04 100755 --- a/src/Mod/Fem/App/FemMesh.cpp +++ b/src/Mod/Fem/App/FemMesh.cpp @@ -625,6 +625,17 @@ std::set FemMesh::getNodesByVertex(const TopoDS_Vertex &vertex) const return result; } +std::set FemMesh::getElementNodes(int id) const +{ + std::set result; + const SMDS_MeshElement* elem = myMesh->GetMeshDS()->FindElement(id); + if (elem) { + for (int i = 0; i < elem->NbNodes(); i++) + result.insert(elem->GetNode(i)->GetID()); + } + return result; +} + void FemMesh::readNastran(const std::string &Filename) { Base::TimeInfo Start; diff --git a/src/Mod/Fem/App/FemMesh.h b/src/Mod/Fem/App/FemMesh.h index e5d73413d..ab87354b0 100755 --- a/src/Mod/Fem/App/FemMesh.h +++ b/src/Mod/Fem/App/FemMesh.h @@ -93,6 +93,8 @@ public: std::set getNodesByEdge(const TopoDS_Edge &edge) const; /// retrieving by vertex std::set getNodesByVertex(const TopoDS_Vertex &vertex) const; + /// retrieving node IDs by element ID + std::set getElementNodes(int id) const; /// retrieving volume IDs and face IDs number by face std::map getVolumesByFace(const TopoDS_Face &face) const; /// retrieving volume IDs and CalculiX face number by face diff --git a/src/Mod/Fem/App/FemMeshPy.xml b/src/Mod/Fem/App/FemMeshPy.xml index 43281e32d..77bc9405d 100755 --- a/src/Mod/Fem/App/FemMeshPy.xml +++ b/src/Mod/Fem/App/FemMeshPy.xml @@ -114,6 +114,11 @@ Return a list of node IDs which belong to a TopoVertex + + + Return a tuple of node IDs to a given element ID + + Dictionary of Nodes by ID (int ID:Vector()) @@ -126,13 +131,25 @@ + + + Tuple of edge IDs + + + Number of edges in the Mesh. - + + + Tuple of face IDs + + + + Number of Faces in the Mesh. @@ -156,8 +173,13 @@ - - + + + Tuple of volume IDs + + + + Number of Volumes in the Mesh. diff --git a/src/Mod/Fem/App/FemMeshPyImp.cpp b/src/Mod/Fem/App/FemMeshPyImp.cpp index f23f65373..732e86715 100755 --- a/src/Mod/Fem/App/FemMeshPyImp.cpp +++ b/src/Mod/Fem/App/FemMeshPyImp.cpp @@ -683,6 +683,28 @@ PyObject* FemMeshPy::getNodesByVertex(PyObject *args) } } +PyObject* FemMeshPy::getElementNodes(PyObject *args) +{ + int id; + if (!PyArg_ParseTuple(args, "i", &id)) + return 0; + + try { + std::set resultSet = getFemMeshPtr()->getElementNodes(id); + Py::Tuple ret(resultSet.size()); + int index = 0; + for (std::set::const_iterator it = resultSet.begin();it!=resultSet.end();++it) + ret.setItem(index++, Py::Int(*it)); + + return Py::new_reference_to(ret); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(Base::BaseExceptionFreeCADError, e->GetMessageString()); + return 0; + } +} + // ===== Atributes ============================================================ @@ -714,12 +736,48 @@ Py::Int FemMeshPy::getNodeCount(void) const return Py::Int(getFemMeshPtr()->getSMesh()->NbNodes()); } +Py::Tuple FemMeshPy::getEdges(void) const +{ + std::set ids; + SMDS_EdgeIteratorPtr aEdgeIter = getFemMeshPtr()->getSMesh()->GetMeshDS()->edgesIterator(); + while (aEdgeIter->more()) { + const SMDS_MeshEdge* aEdge = aEdgeIter->next(); + ids.insert(aEdge->GetID()); + } + + Py::Tuple tuple(ids.size()); + int index = 0; + for (std::set::iterator it = ids.begin(); it != ids.end(); ++it) { + tuple.setItem(index++, Py::Int(*it)); + } + + return tuple; +} + Py::Int FemMeshPy::getEdgeCount(void) const { return Py::Int(getFemMeshPtr()->getSMesh()->NbEdges()); } -Py::Int FemMeshPy::getFacesCount(void) const +Py::Tuple FemMeshPy::getFaces(void) const +{ + std::set ids; + SMDS_FaceIteratorPtr aFaceIter = getFemMeshPtr()->getSMesh()->GetMeshDS()->facesIterator(); + while (aFaceIter->more()) { + const SMDS_MeshFace* aFace = aFaceIter->next(); + ids.insert(aFace->GetID()); + } + + Py::Tuple tuple(ids.size()); + int index = 0; + for (std::set::iterator it = ids.begin(); it != ids.end(); ++it) { + tuple.setItem(index++, Py::Int(*it)); + } + + return tuple; +} + +Py::Int FemMeshPy::getFaceCount(void) const { return Py::Int(getFemMeshPtr()->getSMesh()->NbFaces()); } @@ -739,6 +797,24 @@ Py::Int FemMeshPy::getPolygonCount(void) const return Py::Int(getFemMeshPtr()->getSMesh()->NbPolygons()); } +Py::Tuple FemMeshPy::getVolumes(void) const +{ + std::set ids; + SMDS_VolumeIteratorPtr aVolIter = getFemMeshPtr()->getSMesh()->GetMeshDS()->volumesIterator(); + while (aVolIter->more()) { + const SMDS_MeshVolume* aVol = aVolIter->next(); + ids.insert(aVol->GetID()); + } + + Py::Tuple tuple(ids.size()); + int index = 0; + for (std::set::iterator it = ids.begin(); it != ids.end(); ++it) { + tuple.setItem(index++, Py::Int(*it)); + } + + return tuple; +} + Py::Int FemMeshPy::getVolumeCount(void) const { return Py::Int(getFemMeshPtr()->getSMesh()->NbVolumes());