diff --git a/src/Mod/Fem/App/FemMesh.cpp b/src/Mod/Fem/App/FemMesh.cpp index 1f9a2eb93d..18e9c577d3 100755 --- a/src/Mod/Fem/App/FemMesh.cpp +++ b/src/Mod/Fem/App/FemMesh.cpp @@ -28,6 +28,7 @@ # include # include # include +# include # include # include # include @@ -479,6 +480,32 @@ std::set FemMesh::getNodesByEdge(const TopoDS_Edge &edge) const return result; } +std::set FemMesh::getNodesByVertex(const TopoDS_Vertex &vertex) const +{ + std::set result; + + double limit = BRep_Tool::Tolerance(vertex); + limit *= limit; // use square to improve speed + gp_Pnt pnt = BRep_Tool::Pnt(vertex); + Base::Vector3d node(pnt.X(), pnt.Y(), pnt.Z()); + + // get the current transform of the FemMesh + const Base::Matrix4D Mtrx(getTransform()); + + SMDS_NodeIteratorPtr aNodeIter = myMesh->GetMeshDS()->nodesIterator(); + while (aNodeIter->more()) { + const SMDS_MeshNode* aNode = aNodeIter->next(); + Base::Vector3d vec(aNode->X(),aNode->Y(),aNode->Z()); + vec = Mtrx * vec; + + if (Base::DistanceP2(node, vec) <= limit) { + result.insert(aNode->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 b8421b1f0d..6a157252cf 100755 --- a/src/Mod/Fem/App/FemMesh.h +++ b/src/Mod/Fem/App/FemMesh.h @@ -38,6 +38,7 @@ class SMESH_Hypothesis; class TopoDS_Shape; class TopoDS_Face; class TopoDS_Edge; +class TopoDS_Vertex; namespace Fem { @@ -87,9 +88,11 @@ public: /// retrieving by region growing std::set getSurfaceNodes(long ElemId, short FaceId, float Angle=360)const; /// retrieving by face - std::set getNodesByFace(const TopoDS_Face &face)const; + std::set getNodesByFace(const TopoDS_Face &face) const; /// retrieving by edge - std::set getNodesByEdge(const TopoDS_Edge &edge)const; + std::set getNodesByEdge(const TopoDS_Edge &edge) const; + /// retrieving by vertex + std::set getNodesByVertex(const TopoDS_Vertex &vertex) const; //@} /** @name Placement control */ diff --git a/src/Mod/Fem/App/FemMeshPy.xml b/src/Mod/Fem/App/FemMeshPy.xml index b837d8a791..c0bbb53258 100755 --- a/src/Mod/Fem/App/FemMeshPy.xml +++ b/src/Mod/Fem/App/FemMeshPy.xml @@ -99,6 +99,11 @@ Return a list of node IDs which belong to a TopoEdge + + + Return a list of node IDs which belong to a TopoVertex + + Dictionary of Nodes by ID (int ID:Vector()) diff --git a/src/Mod/Fem/App/FemMeshPyImp.cpp b/src/Mod/Fem/App/FemMeshPyImp.cpp index 698d9f79dc..a96770df9f 100755 --- a/src/Mod/Fem/App/FemMeshPyImp.cpp +++ b/src/Mod/Fem/App/FemMeshPyImp.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include "Mod/Fem/App/FemMesh.h" @@ -558,7 +559,6 @@ PyObject* FemMeshPy::getNodesByFace(PyObject *args) PyErr_SetString(Base::BaseExceptionFreeCADError, e->GetMessageString()); return 0; } - } PyObject* FemMeshPy::getNodesByEdge(PyObject *args) @@ -587,7 +587,34 @@ PyObject* FemMeshPy::getNodesByEdge(PyObject *args) PyErr_SetString(Base::BaseExceptionFreeCADError, e->GetMessageString()); return 0; } - +} + +PyObject* FemMeshPy::getNodesByVertex(PyObject *args) +{ + PyObject *pW; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeVertexPy::Type), &pW)) + return 0; + + try { + const TopoDS_Shape& sh = static_cast(pW)->getTopoShapePtr()->_Shape; + const TopoDS_Vertex& fc = TopoDS::Vertex(sh); + if (sh.IsNull()) { + PyErr_SetString(Base::BaseExceptionFreeCADError, "Vertex is empty"); + return 0; + } + Py::List ret; + std::set resultSet = getFemMeshPtr()->getNodesByVertex(fc); + for (std::set::const_iterator it = resultSet.begin();it!=resultSet.end();++it) + ret.append(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; + } } diff --git a/src/Mod/Fem/MechanicalAnalysis.py b/src/Mod/Fem/MechanicalAnalysis.py index e2f20b5442..fa9d4a05a6 100644 --- a/src/Mod/Fem/MechanicalAnalysis.py +++ b/src/Mod/Fem/MechanicalAnalysis.py @@ -414,8 +414,8 @@ class _JobControlTaskPanel: print ' Line Support (fixed edge) on: ', f n = MeshObject.FemMesh.getNodesByEdge(fo) elif fo.ShapeType == 'Vertex': - print ' Point Support (fixed vertex) on: ', f, ' --> not supported yet' - #n = MeshObject.FemMesh.getNodesByVertex(fo) # ToDo + print ' Point Support (fixed vertex) on: ', f + n = MeshObject.FemMesh.getNodesByVertex(fo) for i in n: inpfile.write( str(i)+',\n') inpfile.write('\n\n') @@ -437,8 +437,8 @@ class _JobControlTaskPanel: print ' Line Load (edge load) on: ', f n = MeshObject.FemMesh.getNodesByEdge(fo) elif fo.ShapeType == 'Vertex': - print ' Point Load (vertex load) on: ', f, ' --> not supported yet' - #n = MeshObject.FemMesh.getNodesByVertex(fo) # ToDo + print ' Point Load (vertex load) on: ', f + n = MeshObject.FemMesh.getNodesByVertex(fo) for i in n: inpfile.write( str(i)+',\n') NbrForceNodes = NbrForceNodes + 1 # NodeSum of mesh-nodes of ALL reference shapes from ForceObject