From 147f2a0b0774b3daaa857ad68453ffa519d5d955 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Thu, 19 Aug 2021 11:57:54 -0400 Subject: [PATCH] [FEM] Possibly fix race conditions Race conditions introduced after using OpenMP in `FemMesh::getNodesByFace` and `FemMesh::getNodesBySolid` because of which nodes were randomly added or removed from sets. Solved by replacing `SMDS_MeshNode::X()` etc., which are not thread safe, with the thread-safe `SMDS_MeshNode::GetXYZ()`. --- src/Mod/Fem/App/FemMesh.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Mod/Fem/App/FemMesh.cpp b/src/Mod/Fem/App/FemMesh.cpp index fafde36335..2843f0fe29 100644 --- a/src/Mod/Fem/App/FemMesh.cpp +++ b/src/Mod/Fem/App/FemMesh.cpp @@ -882,16 +882,18 @@ std::set FemMesh::getNodesBySolid(const TopoDS_Solid &solid) const #pragma omp parallel for schedule(dynamic) for (size_t i = 0; i < nodes.size(); ++i) { const SMDS_MeshNode* aNode = nodes[i]; - Base::Vector3d vec(aNode->X(),aNode->Y(),aNode->Z()); + double xyz[3]; + aNode->GetXYZ(xyz); + Base::Vector3d vec(xyz[0], xyz[1], xyz[2]); // Apply the matrix to hold the BoundBox in absolute space. vec = Mtrx * vec; if (!box.IsOut(gp_Pnt(vec.x,vec.y,vec.z))) { // create a vertex - BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(vec.x,vec.y,vec.z)); + BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(vec.x, vec.y, vec.z)); TopoDS_Shape s = aBuilder.Vertex(); // measure distance - BRepExtrema_DistShapeShape measure(solid,s); + BRepExtrema_DistShapeShape measure(solid, s); measure.Perform(); if (!measure.IsDone() || measure.NbSolution() < 1) continue; @@ -929,16 +931,18 @@ std::set FemMesh::getNodesByFace(const TopoDS_Face &face) const #pragma omp parallel for schedule(dynamic) for (size_t i = 0; i < nodes.size(); ++i) { const SMDS_MeshNode* aNode = nodes[i]; - Base::Vector3d vec(aNode->X(),aNode->Y(),aNode->Z()); + double xyz[3]; + aNode->GetXYZ(xyz); + Base::Vector3d vec(xyz[0], xyz[1], xyz[2]); // Apply the matrix to hold the BoundBox in absolute space. vec = Mtrx * vec; if (!box.IsOut(gp_Pnt(vec.x,vec.y,vec.z))) { // create a vertex - BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(vec.x,vec.y,vec.z)); + BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(vec.x, vec.y, vec.z)); TopoDS_Shape s = aBuilder.Vertex(); // measure distance - BRepExtrema_DistShapeShape measure(face,s); + BRepExtrema_DistShapeShape measure(face, s); measure.Perform(); if (!measure.IsDone() || measure.NbSolution() < 1) continue;