From 5a915d5db60972a49541c3e6ebd76e4ca0ad1f37 Mon Sep 17 00:00:00 2001 From: looooo Date: Thu, 8 Nov 2018 19:27:29 +0100 Subject: [PATCH] add function to retrive femmesh edges by a TopoDS_Edge --- src/Mod/Fem/App/FemMesh.cpp | 28 ++++++++++++++++++++++++++ src/Mod/Fem/App/FemMesh.h | 2 ++ src/Mod/Fem/App/FemMeshPy.xml | 5 +++++ src/Mod/Fem/App/FemMeshPyImp.cpp | 34 ++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) diff --git a/src/Mod/Fem/App/FemMesh.cpp b/src/Mod/Fem/App/FemMesh.cpp index 643b4bca8f..17cdaa4fae 100644 --- a/src/Mod/Fem/App/FemMesh.cpp +++ b/src/Mod/Fem/App/FemMesh.cpp @@ -633,6 +633,34 @@ std::list FemMesh::getFacesByFace(const TopoDS_Face &face) const return result; } +std::list FemMesh::getEdgesByEdge(const TopoDS_Edge &edge) const +{ + std::list result; + std::set nodes_on_edge = getNodesByEdge(edge); + + SMDS_EdgeIteratorPtr edge_iter = myMesh->GetMeshDS()->edgesIterator(); + while (edge_iter->more()) { + const SMDS_MeshEdge* edge = static_cast(edge_iter->next()); + int numNodes = edge->NbNodes(); + + std::set edge_nodes; + for (int i=0; iGetNode(i)->GetID()); + } + + std::vector element_edge_nodes; + std::set_intersection(nodes_on_edge.begin(), nodes_on_edge.end(), edge_nodes.begin(), edge_nodes.end(), + std::back_insert_iterator >(element_edge_nodes)); + + if (element_edge_nodes.size() == static_cast(numNodes)) { + result.push_back(edge->GetID()); + } + } + + result.sort(); + return result; +} + /*! That function returns map containing volume ID and face number * as per CalculiX definition for tetrahedral elements. See CalculiX * documentation for the details. diff --git a/src/Mod/Fem/App/FemMesh.h b/src/Mod/Fem/App/FemMesh.h index d4d4820f62..8a9222b3c9 100644 --- a/src/Mod/Fem/App/FemMesh.h +++ b/src/Mod/Fem/App/FemMesh.h @@ -101,6 +101,8 @@ public: std::list getElementNodes(int id) const; /// retrieving face IDs number by face std::list getFacesByFace(const TopoDS_Face &face) const; + /// retrieving edge IDs number by edge + std::list getEdgesByEdge(const TopoDS_Edge &edge) const; /// retrieving volume IDs and face IDs number by face std::list > 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 93e1ade7aa..60a5bcecd9 100755 --- a/src/Mod/Fem/App/FemMeshPy.xml +++ b/src/Mod/Fem/App/FemMeshPy.xml @@ -93,6 +93,11 @@ Return a list of face IDs which belong to a TopoFace + + + Return a list of edge IDs which belong to a TopoEdge + + Return a dict of volume IDs and face IDs which belong to a TopoFace diff --git a/src/Mod/Fem/App/FemMeshPyImp.cpp b/src/Mod/Fem/App/FemMeshPyImp.cpp index 67c8373737..4e7071d307 100644 --- a/src/Mod/Fem/App/FemMeshPyImp.cpp +++ b/src/Mod/Fem/App/FemMeshPyImp.cpp @@ -711,6 +711,40 @@ PyObject* FemMeshPy::getFacesByFace(PyObject *args) } } + +PyObject* FemMeshPy::getEdgesByEdge(PyObject *args) +{ + PyObject *pW; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeEdgePy::Type), &pW)) + return 0; + + try { + const TopoDS_Shape& sh = static_cast(pW)->getTopoShapePtr()->getShape(); + if (sh.IsNull()) { + PyErr_SetString(Base::BaseExceptionFreeCADError, "Edge is empty"); + return 0; + } + + const TopoDS_Edge& fc = TopoDS::Edge(sh); + + Py::List ret; + std::list resultSet = getFemMeshPtr()->getEdgesByEdge(fc); + for (std::list::const_iterator it = resultSet.begin();it!=resultSet.end();++it) { +#if PY_MAJOR_VERSION >= 3 + ret.append(Py::Long(*it)); +#else + ret.append(Py::Int(*it)); +#endif + } + + return Py::new_reference_to(ret); + } + catch (Standard_Failure& e) { + PyErr_SetString(Base::BaseExceptionFreeCADError, e.GetMessageString()); + return 0; + } +} + PyObject* FemMeshPy::getVolumesByFace(PyObject *args) { PyObject *pW;