From: gdd Date: Mon, 2 May 2011 16:14:25 +0000 (+0000) Subject: Merge from V6_3_BR X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4cea5e025c3376557bae43a0a6b7955ef13afae4;p=plugins%2Fghs3dplugin.git Merge from V6_3_BR --- diff --git a/configure.ac b/configure.ac index 5bf9edf..78ddc3b 100644 --- a/configure.ac +++ b/configure.ac @@ -27,7 +27,7 @@ # Modified by : Marc Tajchman (CEA) # Created from configure.in.base # -AC_INIT([Salome2 Project GHS3DPLUGIN module],[6.2.0], [webmaster.salome@opencascade.com], [SalomeGHS3DPLUGIN]) +AC_INIT([Salome2 Project GHS3DPLUGIN module],[6.3.0], [webmaster.salome@opencascade.com], [SalomeGHS3DPLUGIN]) AC_CONFIG_AUX_DIR(adm_local/unix/config_files) AC_CANONICAL_HOST AC_CANONICAL_TARGET @@ -389,6 +389,10 @@ if test "X$GMAKE" = "Xyes"; then else AC_SUBST(SETX) SETX="set -x" fi + +dnl Build with SMESH cancel compute feature +AC_DEFINE(WITH_SMESH_CANCEL_COMPUTE) + echo echo --------------------------------------------- echo generating Makefiles and configure files diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index 10dc94c..4c5ced2 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -139,6 +139,9 @@ GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D(int hypId, int studyId, SMESH_Gen* gen) _compatibleHypothesis.push_back("GHS3D_Parameters"); _compatibleHypothesis.push_back( StdMeshers_ViscousLayers::GetHypType() ); _requireShape = false; // can work without shape +#ifdef WITH_SMESH_CANCEL_COMPUTE + _compute_canceled = false; +#endif } //============================================================================= @@ -962,10 +965,14 @@ void getShape(Mesh* mesh, Shape shape, Tab *t_Shape) { //======================================================================= -static bool readGMFFile(const char* theFile, SMESH_MesherHelper* theHelper, - TIDSortedNodeSet & theEnforcedNodes, - TIDSortedElemSet & theEnforcedTriangles, - TIDSortedElemSet & theEnforcedQuadrangles) +static bool readGMFFile(const char* theFile, +#ifdef WITH_SMESH_CANCEL_COMPUTE + GHS3DPlugin_GHS3D* theAlgo, +#endif + SMESH_MesherHelper* theHelper, + TIDSortedNodeSet & theEnforcedNodes, + TIDSortedElemSet & theEnforcedTriangles, + TIDSortedElemSet & theEnforcedQuadrangles) { SMESHDS_Mesh* theMesh = theHelper->GetMeshDS(); @@ -1003,6 +1010,14 @@ static bool readGMFFile(const char* theFile, SMESH_MesherHelper* theHelper, std::map ::const_iterator it = tabRef.begin(); for ( ; it != tabRef.end() ; ++it) { +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(theAlgo->computeCanceled()) { + GmfCloseMesh(InpMsh); + delete [] GMFNode; + delete [] nodeAssigne; + return false; + } +#endif int dummy; GmfKwdCod token = it->first; nbRef = it->second; @@ -1026,6 +1041,14 @@ static bool readGMFFile(const char* theFile, SMESH_MesherHelper* theHelper, SMDS_MeshNode * aGMFNode; for ( int iElem = 0; iElem < nbElem; iElem++ ) { +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(theAlgo->computeCanceled()) { + GmfCloseMesh(InpMsh); + delete [] GMFNode; + delete [] nodeAssigne; + return false; + } +#endif aGMFID = iElem + 1; if (ver == GmfFloat) { GmfGetLin(InpMsh, token, &VerTab_f[nbElem][0], &VerTab_f[nbElem][1], &VerTab_f[nbElem][2], &dummy); @@ -1091,6 +1114,14 @@ static bool readGMFFile(const char* theFile, SMESH_MesherHelper* theHelper, for ( int iElem = 0; iElem < nbElem; iElem++ ) { +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(theAlgo->computeCanceled()) { + GmfCloseMesh(InpMsh); + delete [] GMFNode; + delete [] nodeAssigne; + return false; + } +#endif for ( int iRef = 0; iRef < nbRef; iRef++ ) { aGMFNodeID = id[iElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID @@ -1127,9 +1158,18 @@ static bool readGMFFile(const char* theFile, SMESH_MesherHelper* theHelper, } shapeID = theHelper->GetSubShapeID(); - for ( int i = 0; i < nbVertices; ++i ) + for ( int i = 0; i < nbVertices; ++i ) { +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(theAlgo->computeCanceled()) { + GmfCloseMesh(InpMsh); + delete [] GMFNode; + delete [] nodeAssigne; + return false; + } +#endif if ( !nodeAssigne[ i+1 ]) theMesh->SetNodeInVolume( GMFNode[ i+1 ], shapeID ); + } GmfCloseMesh(InpMsh); delete [] GMFNode; @@ -2213,6 +2253,10 @@ static bool writePoints (ofstream & theFile, int nbEnforcedVertices = theEnforcedVertices.size(); int nbEnforcedNodes = theEnforcedNodes.size(); + int aGhs3dID = 1; + SMDS_NodeIteratorPtr it = theMesh->nodesIterator(); + const SMDS_MeshNode* node; + // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D // The problem is in nodes on degenerated edges, we need to skip them if ( theHelper.HasDegeneratedEdges() ) @@ -2228,13 +2272,26 @@ static bool writePoints (ofstream & theFile, } } } + + const bool isQuadMesh = + theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) || + theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) || + theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC ); + if ( isQuadMesh ) + { + // descrease nbNodes by nb of medium nodes + while ( it->more() ) + { + node = it->next(); + if ( !theHelper.IsDegenShape( node->getshapeId() )) + nbNodes -= int( theHelper.IsMedium( node )); + } + it = theMesh->nodesIterator(); + } + const char* space = " "; const int dummyint = 0; - int aGhs3dID = 1; - SMDS_NodeIteratorPtr it = theMesh->nodesIterator(); - const SMDS_MeshNode* node; - // NB_NODES std::cout << std::endl; std::cout << "The initial 2D mesh contains :" << std::endl; @@ -2253,8 +2310,8 @@ static bool writePoints (ofstream & theFile, while ( it->more() ) { node = it->next(); - if ( node->GetPosition()->GetTypeOfPosition() == SMDS_TOP_EDGE && - theHelper.IsDegenShape( node->getshapeId() )) // Issue 020674 + if (( isQuadMesh && theHelper.IsMedium( node )) || // Issue 0021238 + theHelper.IsDegenShape( node->getshapeId() )) // Issue 0020674 continue; theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID )); @@ -2361,6 +2418,9 @@ static bool writePoints (ofstream & theFile, static bool readResultFile(const int fileOpen, #ifdef WNT const char* fileName, +#endif +#ifdef WITH_SMESH_CANCEL_COMPUTE + GHS3DPlugin_GHS3D* theAlgo, #endif SMESH_MesherHelper& theMesh, // SMESH_Mesh& theMesh, @@ -2388,7 +2448,7 @@ static bool readResultFile(const int fileOpen, int fileStat; int nbElems, nbNodes, nbInputNodes; - int nodeId/*, triangleId*/; + int nodeId; int nbTriangle; int ID, shapeID, ghs3dShapeID; int IdShapeRef = 1; @@ -2400,7 +2460,6 @@ static bool readResultFile(const int fileOpen, const SMDS_MeshNode **node; tab = new int[3]; - //tabID = new int[nbShape]; nodeID = new int[4]; coord = new double[3]; node = new const SMDS_MeshNode*[4]; @@ -2449,6 +2508,10 @@ static bool readResultFile(const int fileOpen, MESSAGE("nbEnforcedVertices: "<computeCanceled()) + return false; +#endif for (int iCoor=0; iCoor < 3; iCoor++) coord[ iCoor ] = strtod(ptr, &ptr); nodeAssigne[ iNode ] = 1; @@ -2468,6 +2531,10 @@ static bool readResultFile(const int fileOpen, tabID = new int[nbTriangle]; for (int i=0; i < nbTriangle; i++) { +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(theAlgo->computeCanceled()) + return false; +#endif tabID[i] = 0; // find the solid corresponding to GHS3D sub-domain following // the technique proposed in GHS3D manual in chapter @@ -2520,6 +2587,10 @@ static bool readResultFile(const int fileOpen, // Associating the tetrahedrons to the shapes shapeID = compoundID; for (int iElem = 0; iElem < nbElems; iElem++) { +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(theAlgo->computeCanceled()) + return false; +#endif for (int iNode = 0; iNode < 4; iNode++) { ID = strtol(tetraPtr, &tetraPtr, 10); itOnNode = theGhs3dIdToNodeMap.find(ID); @@ -2571,7 +2642,8 @@ static bool readResultFile(const int fileOpen, } } if ( toMeshHoles || shapeID != HOLE_ID ) { - aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] ); + aTet = theMesh.AddVolume( node[1], node[0], node[2], node[3], + /*id=*/0, /*force3d=*/false); theMeshDS->SetMeshElementOnShape( aTet, shapeID ); } #ifdef _DEBUG_ @@ -2831,6 +2903,10 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, std::cout << "Ghs3d execution..." << std::endl; std::cout << cmd << std::endl; +#ifdef WITH_SMESH_CANCEL_COMPUTE + _compute_canceled = false; +#endif + system( cmd.ToCString() ); // run std::cout << std::endl; @@ -2853,9 +2929,18 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, Ok = false; } else { + bool toMeshHoles = + _hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles(); + + helper.IsQuadraticSubMesh( theShape ); + helper.SetElementsOnShape( false ); + Ok = readResultFile( fileOpen, #ifdef WNT aResultFileName.ToCString(), +#endif +#ifdef WITH_SMESH_CANCEL_COMPUTE + this, #endif /*theMesh, */helper, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap, toMeshHoles, @@ -2922,7 +3007,12 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // #endif removeFile( aSmdsToGhs3dIdMapFileName ); // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) - removeFile( aResultFileName ); + +#ifdef WITH_SMESH_CANCEL_COMPUTE + if (! Ok) + if(_compute_canceled) + removeFile( aLogFileName ); +#endif } std::cout << "<" << aResultFileName.ToCString() << "> GHS3D output file "; if ( !Ok ) @@ -2943,12 +3033,12 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, */ //============================================================================= bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, - SMESH_MesherHelper* aHelper) + SMESH_MesherHelper* theHelper) { MESSAGE("GHS3DPlugin_GHS3D::Compute()"); //SMESHDS_Mesh* meshDS = theMesh.GetMeshDS(); - TopoDS_Shape theShape = aHelper->GetSubShape(); + TopoDS_Shape theShape = theHelper->GetSubShape(); // a unique working file name // to avoid access to the same files by eg different users @@ -2958,27 +3048,27 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log TCollection_AsciiString aResultFileName; bool Ok; -#if GHS3D_VERSION < 42 - TCollection_AsciiString aFacesFileName, aPointsFileName; - TCollection_AsciiString aBadResFileName, aBbResFileName; - aFacesFileName = aGenericName + ".faces"; // in faces - aPointsFileName = aGenericName + ".points"; // in points - aResultFileName = aGenericName + ".noboite";// out points and volumes - aBadResFileName = aGenericName + ".boite"; // out bad result - aBbResFileName = aGenericName + ".bb"; // out vertex stepsize - - // ----------------- - // make input files - // ----------------- - - ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out); - ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out); - Ok = aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open(); - if (!Ok) { - INFOS( "Can't write into " << aFacesFileName); - return error( SMESH_Comment("Can't write into ") << aFacesFileName); - } -#else +// #if GHS3D_VERSION < 42 +// TCollection_AsciiString aFacesFileName, aPointsFileName; +// TCollection_AsciiString aBadResFileName, aBbResFileName; +// aFacesFileName = aGenericName + ".faces"; // in faces +// aPointsFileName = aGenericName + ".points"; // in points +// aResultFileName = aGenericName + ".noboite";// out points and volumes +// aBadResFileName = aGenericName + ".boite"; // out bad result +// aBbResFileName = aGenericName + ".bb"; // out vertex stepsize +// +// // ----------------- +// // make input files +// // ----------------- +// +// ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out); +// ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out); +// Ok = aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open(); +// if (!Ok) { +// INFOS( "Can't write into " << aFacesFileName); +// return error( SMESH_Comment("Can't write into ") << aFacesFileName); +// } +// #else TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName; #ifdef _DEBUG_ aGMFFileName = aGenericName + ".mesh"; // GMF mesh file @@ -2991,7 +3081,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, aRequiredVerticesFileName = aGenericName + "_required.meshb"; // GMF required vertices mesh file aSolFileName = aGenericName + ".solb"; // GMF solution file #endif -#endif +// #endif std::map nodeID2nodeIndexMap; GHS3DPlugin_Hypothesis::TEnforcedVertexValues enforcedVertices = GHS3DPlugin_Hypothesis::GetEnforcedVertices(_hyp); @@ -3010,58 +3100,62 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, aQuad2Trias->Compute( theMesh ); proxyMesh.reset( aQuad2Trias ); } -#if GHS3D_VERSION < 42 - Ok = (writeFaces ( aFacesFile, *proxyMesh, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId, - enforcedEdges, enforcedTriangles, enforcedQuadrangles ) && - writePoints( aPointsFile, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId, - nodeIDToSizeMap, enforcedVertices, enforcedNodes)); - int nbEnforcedVertices = enforcedVertices.size(); - int nbEnforcedNodes = enforcedNodes.size(); -#else +// #if GHS3D_VERSION < 42 +// Ok = (writeFaces ( aFacesFile, *proxyMesh, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId, +// enforcedEdges, enforcedTriangles, enforcedQuadrangles ) && +// writePoints( aPointsFile, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId, +// nodeIDToSizeMap, enforcedVertices, enforcedNodes)); +// int nbEnforcedVertices = enforcedVertices.size(); +// int nbEnforcedNodes = enforcedNodes.size(); +// #else Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), *proxyMesh, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId, enforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles, enforcedVertices); -#endif +// #endif } TIDSortedNodeSet enforcedNodesFromEnforcedElem; for (int i=0;i" ) + aLogFileName; // dump into file std::cout << std::endl; std::cout << "Ghs3d execution..." << std::endl; std::cout << cmd << std::endl; +#ifdef WITH_SMESH_CANCEL_COMPUTE + _compute_canceled = false; +#endif + system( cmd.ToCString() ); // run std::cout << std::endl; @@ -3070,28 +3164,35 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // -------------- // read a result // -------------- -#if GHS3D_VERSION < 42 - int fileOpen = open( aResultFileName.ToCString(), O_RDONLY); - if ( fileOpen < 0 ) { - std::cout << std::endl; - std::cout << "Error when opening the " << aResultFileName.ToCString() << " file" << std::endl; - std::cout << "Log: " << aLogFileName << std::endl; - std::cout << std::endl; - Ok = false; - } - else { - Ok = readResultFile( fileOpen, -#ifdef WNT - aResultFileName.ToCString(), +// #if GHS3D_VERSION < 42 +// int fileOpen = open( aResultFileName.ToCString(), O_RDONLY); +// if ( fileOpen < 0 ) { +// std::cout << std::endl; +// std::cout << "Error when opening the " << aResultFileName.ToCString() << " file" << std::endl; +// std::cout << "Log: " << aLogFileName << std::endl; +// std::cout << std::endl; +// Ok = false; +// } +// else { +// Ok = readResultFile( fileOpen, +// #ifdef WNT +// aResultFileName.ToCString(), +// #endif +// #ifdef WITH_SMESH_CANCEL_COMPUTE +// this, +// #endif +// theMesh, theShape ,aNodeByGhs3dId, anEnforcedNodeByGhs3dId, +// nbEnforcedVertices, nbEnforcedNodes, +// enforcedEdges, enforcedTriangles, enforcedQuadrangles ); +// } +// #else + Ok = readGMFFile(aResultFileName.ToCString(), +#ifdef WITH_SMESH_CANCEL_COMPUTE + this, #endif - theMesh, theShape ,aNodeByGhs3dId, anEnforcedNodeByGhs3dId, - nbEnforcedVertices, nbEnforcedNodes, - enforcedEdges, enforcedTriangles, enforcedQuadrangles ); - } -#else - Ok = readGMFFile(aResultFileName.ToCString(), aHelper, + theHelper, enforcedNodesFromEnforcedElem, enforcedTriangles, enforcedQuadrangles); -#endif +// #endif // --------------------- // remove working files @@ -3114,19 +3215,40 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" ); error(COMPERR_ALGO_FAILED, "ghs3d: command not found" ); } -#if GHS3D_VERSION < 42 +// #if GHS3D_VERSION < 42 if ( !_keepFiles ) { - removeFile( aFacesFileName ); - removeFile( aPointsFileName ); - removeFile( aResultFileName ); - removeFile( aBadResFileName ); - removeFile( aBbResFileName ); - } +#ifdef WITH_SMESH_CANCEL_COMPUTE + if (! Ok) + if(_compute_canceled) + removeFile( aLogFileName ); #endif +// removeFile( aFacesFileName ); +// removeFile( aPointsFileName ); +// removeFile( aResultFileName ); +// removeFile( aBadResFileName ); +// removeFile( aBbResFileName ); + } +// #endif return Ok; } +#ifdef WITH_SMESH_CANCEL_COMPUTE +void GHS3DPlugin_GHS3D::CancelCompute() +{ + _compute_canceled = true; +#ifdef WNT +#else + TCollection_AsciiString aGenericName + = (char*) GHS3DPlugin_Hypothesis::GetFileName(_hyp).c_str(); + TCollection_AsciiString cmd = + TCollection_AsciiString("ps ux | grep ") + aGenericName; + cmd += TCollection_AsciiString(" | grep -v grep | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1"); + system( cmd.ToCString() ); +#endif +} +#endif + //================================================================================ /*! * \brief Provide human readable text by error code reported by ghs3d @@ -3312,6 +3434,10 @@ static char* getIds( char* ptr, int nbIds, vector& ids ) bool GHS3DPlugin_GHS3D::storeErrorDescription(const TCollection_AsciiString& logFile, const _Ghs2smdsConvertor & toSmdsConvertor ) { +#ifdef WITH_SMESH_CANCEL_COMPUTE + if(_compute_canceled) + return error(SMESH_Comment("interruption initiated by user")); +#endif // open file #ifdef WNT int file = ::_open (logFile.ToCString(), _O_RDONLY|_O_BINARY); @@ -3708,5 +3834,9 @@ bool GHS3DPlugin_GHS3D::importGMFMesh(const char* theGMFFileName, SMESH_Mesh& th SMESH_MesherHelper* helper = new SMESH_MesherHelper(theMesh ); TIDSortedElemSet dummyElemSet; TIDSortedNodeSet dummyNodeSet; - return readGMFFile(theGMFFileName, helper, dummyNodeSet , dummyElemSet, dummyElemSet); + return readGMFFile(theGMFFileName, +#ifdef WITH_SMESH_CANCEL_COMPUTE + this, +#endif + helper, dummyNodeSet , dummyElemSet, dummyElemSet); } diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx index 7c8358f..3888942 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx @@ -62,6 +62,11 @@ public: virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape); +#ifdef WITH_SMESH_CANCEL_COMPUTE + virtual void CancelCompute(); + bool computeCanceled() { return _compute_canceled;}; +#endif + virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, MapShapeNbElems& aResMap); @@ -80,6 +85,11 @@ private: bool _keepFiles; const GHS3DPlugin_Hypothesis* _hyp; const StdMeshers_ViscousLayers* _viscousLayersHyp; + +#ifdef WITH_SMESH_CANCEL_COMPUTE + volatile bool _compute_canceled; +#endif + }; /*!