diff --git a/src/Mod/Fem/App/FemMesh.cpp b/src/Mod/Fem/App/FemMesh.cpp index f7341b54e..4e9b0549b 100644 --- a/src/Mod/Fem/App/FemMesh.cpp +++ b/src/Mod/Fem/App/FemMesh.cpp @@ -126,9 +126,7 @@ void FemMesh::copyMeshData(const FemMesh& mesh) SMDS_NodeIteratorPtr aNodeIter = mesh.myMesh->GetMeshDS()->nodesIterator(); for (;aNodeIter->more();) { const SMDS_MeshNode* aNode = aNodeIter->next(); - int id = aNode->GetID(); double temp[3]; - Base::Console().Message("CopyData Mesh ID: %i\n", aNode->getMeshId()); aNode->GetXYZ(temp); meshds->AddNodeWithID(temp[0],temp[1],temp[2], aNode->GetID()); } @@ -399,6 +397,7 @@ std::set FemMesh::getSurfaceNodes(long ElemId, short FaceId, float Angle) */ std::list > FemMesh::getVolumesByFace(const TopoDS_Face &face) const { + //TODO: This function is broken with SMESH7 as it is impossible to iterate volume faces std::list > result; std::set nodes_on_face = getNodesByFace(face); @@ -431,6 +430,38 @@ std::list > FemMesh::getVolumesByFace(const TopoDS_Face &fac return result; } +/*! That function returns a list of face IDs. + */ +std::list FemMesh::getFacesByFace(const TopoDS_Face &face) const +{ + //TODO: This function is broken with SMESH7 as it is impossible to iterate volume faces + std::list result; + std::set nodes_on_face = getNodesByFace(face); + + SMDS_FaceIteratorPtr face_iter = myMesh->GetMeshDS()->facesIterator(); + while (face_iter->more()) { + const SMDS_MeshFace* face = static_cast(face_iter->next()); + int numNodes = face->NbNodes(); + + std::set face_nodes; + for (int i=0; iGetNode(i)->GetID()); + } + + std::vector element_face_nodes; + std::set_intersection(nodes_on_face.begin(), nodes_on_face.end(), face_nodes.begin(), face_nodes.end(), + std::back_insert_iterator >(element_face_nodes)); + + // For curved faces it is possible that a volume contributes more than one face + if (element_face_nodes.size() == static_cast(numNodes)) { + result.push_back(face->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 3f66b7aa7..be42b2aaa 100644 --- a/src/Mod/Fem/App/FemMesh.h +++ b/src/Mod/Fem/App/FemMesh.h @@ -98,6 +98,8 @@ public: std::set getNodesByVertex(const TopoDS_Vertex &vertex) const; /// retrieving node IDs by element ID std::list getElementNodes(int id) const; + /// retrieving face IDs number by face + std::list getFacesByFace(const TopoDS_Face &face) 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 186b6e46a..b8d3b6c7d 100755 --- a/src/Mod/Fem/App/FemMeshPy.xml +++ b/src/Mod/Fem/App/FemMeshPy.xml @@ -84,6 +84,11 @@ Make a copy of this FEM mesh. + + + Return a list of face IDs which belong to a TopoFace + + 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 d9f848e91..dc32070cb 100644 --- a/src/Mod/Fem/App/FemMeshPyImp.cpp +++ b/src/Mod/Fem/App/FemMeshPyImp.cpp @@ -575,6 +575,37 @@ PyObject* FemMeshPy::setTransform(PyObject *args) Py_Return; } + +PyObject* FemMeshPy::getFacesByFace(PyObject *args) +{ + PyObject *pW; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeFacePy::Type), &pW)) + return 0; + + try { + const TopoDS_Shape& sh = static_cast(pW)->getTopoShapePtr()->_Shape; + if (sh.IsNull()) { + PyErr_SetString(Base::BaseExceptionFreeCADError, "Face is empty"); + return 0; + } + + const TopoDS_Face& fc = TopoDS::Face(sh); + + Py::List ret; + std::list resultSet = getFemMeshPtr()->getFacesByFace(fc); + for (std::list::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; + } +} + PyObject* FemMeshPy::getVolumesByFace(PyObject *args) { PyObject *pW; diff --git a/src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp b/src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp index 6ad9ffdec..95d5a0e20 100644 --- a/src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp +++ b/src/Mod/Fem/App/FemMeshShapeNetgenObject.cpp @@ -76,37 +76,13 @@ App::DocumentObjectExecReturn *FemMeshShapeNetgenObject::execute(void) { #ifdef FCWithNetgen - Fem::FemMesh newMesh, mesh2; - - Base::Console().Message("newMesh ID: %i\n", newMesh.getSMesh()->GetMeshDS()->getMeshId()); - Base::Console().Message("second mesh ID: %i\n", mesh2.getSMesh()->GetMeshDS()->getMeshId()); + Fem::FemMesh newMesh; Part::Feature *feat = Shape.getValue(); TopoDS_Shape shape = feat->Shape.getValue(); - -// newMesh.myMesh->ShapeToMesh(shape); -// SMESH_Gen *myGen = newMesh.getGenerator(); -// meshgen->CreateMesh(0, true); - - int hyp=0; - NETGENPlugin_Mesher myNetGenMesher(newMesh.getSMesh(),shape,true); -/* - NETGENPlugin_SimpleHypothesis_2D * tet2 = new NETGENPlugin_SimpleHypothesis_2D(hyp++,1,myGen); - static_cast(tet2.get())->SetNumberOfSegments(5); - static_cast(tet2.get())->SetLocalLength(0.1); - static_cast(tet2.get())->LengthFromEdges(); - myNetGenMesher.SetParameters(tet2); -*/ -/* - NETGENPlugin_SimpleHypothesis_3D* tet= new NETGENPlugin_SimpleHypothesis_3D(hyp++,1,myGen); - static_cast(tet.get())->LengthFromFaces(); - static_cast(tet.get())->SetMaxElementVolume(0.1); - myNetGenMesher.SetParameters( tet); -*/ - - NETGENPlugin_Hypothesis* tet= new NETGENPlugin_Hypothesis(hyp++,1,newMesh.getGenerator()); + NETGENPlugin_Hypothesis* tet= new NETGENPlugin_Hypothesis(0,1,newMesh.getGenerator()); tet->SetMaxSize(MaxSize.getValue()); tet->SetSecondOrder(SecondOrder.getValue()); tet->SetOptimize(Optimize.getValue()); diff --git a/src/Mod/Fem/FemMeshTools.py b/src/Mod/Fem/FemMeshTools.py index 17b06b2f5..60429ab31 100644 --- a/src/Mod/Fem/FemMeshTools.py +++ b/src/Mod/Fem/FemMeshTools.py @@ -426,8 +426,8 @@ def get_ref_facenodes_table(femmesh, femelement_table, ref_face): ve_ref_face_nodes.append(nodeID) face_table[veID] = ve_ref_face_nodes # { volumeID : ( facenodeID, ... , facenodeID ) } only the ref_face nodes else: # the femmesh has face_data - volume_faces = femmesh.getVolumesByFace(ref_face) # (mv, mf) - for mv, mf in volume_faces: + faces = femmesh.getFacesByFace(ref_face) # (mv, mf) + for mf in faces: face_table[mf] = femmesh.getElementNodes(mf) elif is_face_femmesh(femmesh): ref_face_nodes = femmesh.getNodesByFace(ref_face)