From d31f618094c714f43597bde40a6af21935d76551 Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 24 May 2013 11:41:51 +0000 Subject: [PATCH] 0022172: [CEA 790] create the groups corresponding to domains + void SetToMakeGroupsOfDomains(in boolean toMakeGroups); + boolean GetToMakeGroupsOfDomains(); --- idl/GHS3DPlugin_Algorithm.idl | 8 +- src/GHS3DPlugin/GHS3DPluginBuilder.py | 8 + src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx | 244 +++++++++++++------ src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx | 19 +- src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx | 50 ++++ src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx | 10 + src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx | 21 ++ src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx | 7 + 8 files changed, 277 insertions(+), 90 deletions(-) diff --git a/idl/GHS3DPlugin_Algorithm.idl b/idl/GHS3DPlugin_Algorithm.idl index af17c87..55af9a4 100644 --- a/idl/GHS3DPlugin_Algorithm.idl +++ b/idl/GHS3DPlugin_Algorithm.idl @@ -19,7 +19,6 @@ // File : GHS3D_Algorithm.idl // Author : Julia DOROVSKIKH -// $Header$ // #ifndef _GHS3D_Algorithm_IDL_ #define _GHS3D_Algorithm_IDL_ @@ -72,6 +71,13 @@ module GHS3DPlugin */ void SetToMeshHoles(in boolean toMesh); boolean GetToMeshHoles(); + /*! + * To make groups of volumes of different domains when mesh is generated from skin. + * Default is to make groups. + * This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true + */ + void SetToMakeGroupsOfDomains(in boolean toMakeGroups); + boolean GetToMakeGroupsOfDomains(); /*! * Maximal size of memory to be used by the algorithm (in Megabytes). * Negative value means not to use this option diff --git a/src/GHS3DPlugin/GHS3DPluginBuilder.py b/src/GHS3DPlugin/GHS3DPluginBuilder.py index 4e07a2e..08dfb09 100644 --- a/src/GHS3DPlugin/GHS3DPluginBuilder.py +++ b/src/GHS3DPlugin/GHS3DPluginBuilder.py @@ -86,6 +86,14 @@ class GHS3D_Algorithm(Mesh_Algorithm): self.Parameters().SetToMeshHoles(toMesh) pass + ## To make groups of volumes of different domains when mesh is generated from skin. + # Default is to make groups. + # This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true + # @param toMesh "mesh holes" flag value + def SetToMakeGroupsOfDomains(self, toMakeGroups): + self.Parameters().SetToMakeGroupsOfDomains(toMakeGroups) + pass + ## Set Optimization level: # @param level optimization level, one of the following values # - None_Optimization diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index b8a777e..76629fa 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -112,6 +112,8 @@ extern "C" typedef const list TTriaList; +static const char theDomainGroupNamePrefix[] = "Domain_"; + static void removeFile( const TCollection_AsciiString& fileName ) { try { @@ -132,7 +134,7 @@ GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D(int hypId, int studyId, SMESH_Gen* gen) : SMESH_3D_Algo(hypId, studyId, gen) { MESSAGE("GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D"); - _name = "GHS3D_3D"; + _name = Name(); _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type _onlyUnaryInput = false; // Compute() will be called on a compound of solids _iShape=0; @@ -152,9 +154,7 @@ GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D(int hypId, int studyId, SMESH_Gen* gen) if (myStudy) MESSAGE("myStudy->StudyId() = " << myStudy->StudyId()); -#ifdef WITH_SMESH_CANCEL_COMPUTE _compute_canceled = false; -#endif } //============================================================================= @@ -1055,15 +1055,45 @@ static void updateMeshGroups(SMESH_Mesh* theMesh, std::set groupsTo } } +//======================================================================= +//function : removeEmptyGroupsOfDomains +//purpose : remove empty groups named "Domain_nb" created due to +// "To make groups of domains" option. +//======================================================================= + +static void removeEmptyGroupsOfDomains(SMESH_Mesh* mesh, + bool notEmptyAsWell = false) +{ + const char* refName = theDomainGroupNamePrefix; + const size_t refLen = strlen( theDomainGroupNamePrefix ); + + std::list groupIDs = mesh->GetGroupIds(); + std::list::const_iterator id = groupIDs.begin(); + for ( ; id != groupIDs.end(); ++id ) + { + SMESH_Group* group = mesh->GetGroup( *id ); + if ( !group || ( !group->GetGroupDS()->IsEmpty() && !notEmptyAsWell )) + continue; + const char* name = group->GetName(); + char* end; + // check the name + if ( strncmp( name, refName, refLen ) == 0 && // starts from refName; + isdigit( *( name + refLen )) && // refName is followed by a digit; + strtol( name + refLen, &end, 10) && // there are only digits ... + *end == '\0') // ... till a string end. + { + mesh->RemoveGroup( *id ); + } + } +} + //======================================================================= //function : readGMFFile //purpose : read GMF file w/o geometry associated to mesh //======================================================================= static bool readGMFFile(const char* theFile, -#ifdef WITH_SMESH_CANCEL_COMPUTE GHS3DPlugin_GHS3D* theAlgo, -#endif SMESH_MesherHelper* theHelper, TopoDS_Shape theSolid, vector & theNodeByGhs3dId, @@ -1071,8 +1101,8 @@ static bool readGMFFile(const char* theFile, std::vector & aNodeGroupByGhs3dId, std::vector & anEdgeGroupByGhs3dId, std::vector & aFaceGroupByGhs3dId, - std::set & groupsToRemove - ) + std::set & groupsToRemove, + bool toMakeGroupsOfDomains=false) { std::string tmpStr; SMESHDS_Mesh* theMeshDS = theHelper->GetMeshDS(); @@ -1099,13 +1129,14 @@ static bool readGMFFile(const char* theFile, // --------------------------------- int nbElem = 0, nbRef = 0; - int aGMFNodeID = 0/*, shapeID*/; - //int *nodeAssigne; + int aGMFNodeID = 0; const SMDS_MeshNode** GMFNode; #ifdef _DEBUG_ std::map > subdomainId2tetraId; #endif std::map tabRef; + const bool force3d = true; // since there is no geometry + const int noID = 0; tabRef[GmfVertices] = 3; // for new nodes and enforced nodes tabRef[GmfCorners] = 1; @@ -1126,28 +1157,27 @@ static bool readGMFFile(const char* theFile, // Issue 0020682. Avoid creating nodes and tetras at place where // volumic elements already exist SMESH_ElementSearcher* elemSearcher = 0; - vector< const SMDS_MeshElement* > foundVolumes; + std::vector< const SMDS_MeshElement* > foundVolumes; if ( theHelper->GetMesh()->NbVolumes() > 0 ) elemSearcher = SMESH_MeshAlgos::GetElementSearcher( *theHelper->GetMeshDS() ); + // IMP 0022172: [CEA 790] create the groups corresponding to domains + std::vector< std::vector< const SMDS_MeshElement* > > elemsOfDomain; + int nbVertices = GmfStatKwd(InpMsh, GmfVertices) - nbInitialNodes; GMFNode = new const SMDS_MeshNode*[ nbVertices + 1 ]; - //nodeAssigne = new int[ nbVertices + 1 ]; 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; + nbRef = it->second; nbElem = GmfStatKwd(InpMsh, token); if (nbElem > 0) { @@ -1158,6 +1188,7 @@ static bool readGMFFile(const char* theFile, continue; std::vector id (nbElem*tabRef[token]); // node ids + std::vector domainID( nbElem ); // domain if (token == GmfVertices) { (nbElem <= 1) ? tmpStr = " vertex" : tmpStr = " vertices"; @@ -1182,16 +1213,12 @@ static bool readGMFFile(const char* theFile, double x, y, z; const SMDS_MeshNode * aGMFNode; - //shapeID = theMeshDS->ShapeToIndex( theSolid ); for ( int iElem = 0; iElem < nbElem; iElem++ ) { -#ifdef WITH_SMESH_CANCEL_COMPUTE if(theAlgo->computeCanceled()) { GmfCloseMesh(InpMsh); delete [] GMFNode; - //delete [] nodeAssigne; return false; } -#endif if (ver == GmfFloat) { GmfGetLin(InpMsh, token, &VerTab_f[0], &VerTab_f[1], &VerTab_f[2], &dummy); x = VerTab_f[0]; @@ -1210,7 +1237,6 @@ static bool readGMFFile(const char* theFile, aGMFID = iElem -nbInitialNodes +1; GMFNode[ aGMFID ] = aGMFNode; - //nodeAssigne[ aGMFID ] = 0; if (aGMFID-1 < aNodeGroupByGhs3dId.size() && !aNodeGroupByGhs3dId.at(aGMFID-1).empty()) addElemInMeshGroup(theHelper->GetMesh(), aGMFNode, aNodeGroupByGhs3dId.at(aGMFID-1), groupsToRemove); } @@ -1229,22 +1255,22 @@ static bool readGMFFile(const char* theFile, else if (token == GmfEdges && nbElem > 0) { (nbElem <= 1) ? tmpStr = " edge" : tmpStr = " edges"; for ( int iElem = 0; iElem < nbElem; iElem++ ) - GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &dummy); + GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &domainID[iElem]); } else if (token == GmfTriangles && nbElem > 0) { (nbElem <= 1) ? tmpStr = " triangle" : tmpStr = " triangles"; for ( int iElem = 0; iElem < nbElem; iElem++ ) - GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &dummy); + GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &domainID[iElem]); } else if (token == GmfQuadrilaterals && nbElem > 0) { (nbElem <= 1) ? tmpStr = " Quadrilateral" : tmpStr = " Quadrilaterals"; for ( int iElem = 0; iElem < nbElem; iElem++ ) - GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &dummy); + GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &domainID[iElem]); } else if (token == GmfTetrahedra && nbElem > 0) { (nbElem <= 1) ? tmpStr = " Tetrahedron" : tmpStr = " Tetrahedra"; for ( int iElem = 0; iElem < nbElem; iElem++ ) { - GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &dummy); + GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &domainID[iElem]); #ifdef _DEBUG_ subdomainId2tetraId[dummy].insert(iElem+1); // MESSAGE("subdomainId2tetraId["<computeCanceled()) { GmfCloseMesh(InpMsh); delete [] GMFNode; - //delete [] nodeAssigne; return false; } -#endif // Check if elem is already in input mesh. If yes => skip bool fullyCreatedElement = false; // if at least one of the nodes was created for ( int iRef = 0; iRef < nbRef; iRef++ ) @@ -1302,30 +1325,26 @@ static bool readGMFFile(const char* theFile, node [ iRef ] = GMFNode[ aGMFNodeID ]; } } - + aCreatedElem = 0; switch (token) { case GmfEdges: if (fullyCreatedElement) { - aCreatedElem = theHelper->AddEdge( node[0], node[1], /*id =*/0, /*force3d =*/false ); + aCreatedElem = theHelper->AddEdge( node[0], node[1], noID, force3d ); if (anEdgeGroupByGhs3dId.size() && !anEdgeGroupByGhs3dId[iElem].empty()) addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByGhs3dId[iElem], groupsToRemove); } break; case GmfTriangles: if (fullyCreatedElement) { - aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], /*id =*/0, /*force3d =*/false ); - // for ( int iRef = 0; iRef < nbRef; iRef++ ) - // nodeAssigne[ nodeID[ iRef ]] = 1; + aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], noID, force3d ); if (aFaceGroupByGhs3dId.size() && !aFaceGroupByGhs3dId[iElem].empty()) addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, aFaceGroupByGhs3dId[iElem], groupsToRemove); } break; case GmfQuadrilaterals: if (fullyCreatedElement) { - theHelper->AddFace( node[0], node[1], node[2], node[3], /*id =*/0, /*force3d =*/false ); - // for ( int iRef = 0; iRef < nbRef; iRef++ ) - // nodeAssigne[ nodeID[ iRef ]] = 1; + aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], node[3], noID, force3d ); } break; case GmfTetrahedra: @@ -1341,8 +1360,7 @@ static bool readGMFFile(const char* theFile, SMDSAbs_Volume, foundVolumes )) break; } - theHelper->AddVolume( node[1], node[0], node[2], node[3], /*id =*/0, /*force3d =*/false ); -// theMeshDS->SetMeshElementOnShape( aTet, shapeID ); + aCreatedElem = theHelper->AddVolume( node[1], node[0], node[2], node[3], noID, force3d ); break; case GmfHexahedra: if ( elemSearcher ) { @@ -1361,27 +1379,70 @@ static bool readGMFFile(const char* theFile, SMDSAbs_Volume, foundVolumes )) break; } - theHelper->AddVolume( node[0], node[3], node[2], node[1], - node[4], node[7], node[6], node[5], /*id =*/0, /*force3d =*/false ); -// theMeshDS->SetMeshElementOnShape( aTet, shapeID ); + aCreatedElem = theHelper->AddVolume( node[0], node[3], node[2], node[1], + node[4], node[7], node[6], node[5], noID, force3d ); break; default: continue; } - } + if ( aCreatedElem && toMakeGroupsOfDomains ) + { + if ( domainID[iElem] >= (int) elemsOfDomain.size() ) + elemsOfDomain.resize( domainID[iElem] + 1 ); + elemsOfDomain[ domainID[iElem] ].push_back( aCreatedElem ); + } + } // loop on elements of one type break; - } - } - } - - // for ( int i = 0; i < nbVertices; ++i ) { - // if ( !nodeAssigne[ i+1 ]) - // theMeshDS->SetNodeInVolume( GMFNode[ i+1 ], shapeID ); - // } + } // case ... + } // switch (token) + } // loop on tabRef GmfCloseMesh(InpMsh); delete [] GMFNode; - //delete [] nodeAssigne; -#ifdef _DEBUG_ + + // 0022172: [CEA 790] create the groups corresponding to domains + if ( toMakeGroupsOfDomains ) + { + int nbDomains = 0; + for ( size_t i = 0; i < elemsOfDomain.size(); ++i ) + nbDomains += ( elemsOfDomain[i].size() > 0 ); + + if ( nbDomains > 1 ) + for ( size_t iDomain = 0; iDomain < elemsOfDomain.size(); ++iDomain ) + { + std::vector< const SMDS_MeshElement* > & elems = elemsOfDomain[ iDomain ]; + if ( elems.empty() ) continue; + + // find existing groups + std::vector< SMESH_Group* > groupOfType( SMDSAbs_NbElementTypes, (SMESH_Group*)NULL ); + const std::string domainName = ( SMESH_Comment( theDomainGroupNamePrefix ) << iDomain ); + SMESH_Mesh::GroupIteratorPtr groupIt = theHelper->GetMesh()->GetGroups(); + while ( groupIt->more() ) + { + SMESH_Group* group = groupIt->next(); + if ( domainName == group->GetName() && + dynamic_cast< SMESHDS_Group* >( group->GetGroupDS()) ) + groupOfType[ group->GetGroupDS()->GetType() ] = group; + } + // create and fill the groups + size_t iElem = 0; + int groupID; + do + { + SMESH_Group* group = groupOfType[ elems[ iElem ]->GetType() ]; + if ( !group ) + group = theHelper->GetMesh()->AddGroup( elems[ iElem ]->GetType(), + domainName.c_str(), groupID ); + SMDS_MeshGroup& groupDS = + static_cast< SMESHDS_Group* >( group->GetGroupDS() )->SMDSGroup(); + + while ( iElem < elems.size() && groupDS.Add( elems[iElem] )) + ++iElem; + + } while ( iElem < elems.size() ); + } + } + +#ifdef _DEBUG_ MESSAGE("Nb subdomains " << subdomainId2tetraId.size()); std::map >::const_iterator subdomainIt = subdomainId2tetraId.begin(); TCollection_AsciiString aSubdomainFileName = theFile; @@ -2807,9 +2868,7 @@ static bool readResultFile(const int fileOpen, #ifdef WNT const char* fileName, #endif -#ifdef WITH_SMESH_CANCEL_COMPUTE GHS3DPlugin_GHS3D* theAlgo, -#endif SMESH_MesherHelper& theHelper, TopoDS_Shape tabShape[], double** tabBox, @@ -2896,10 +2955,8 @@ static bool readResultFile(const int fileOpen, MESSAGE("nbEnforcedNodes: "<computeCanceled()) return false; -#endif for (int iCoor=0; iCoor < 3; iCoor++) coord[ iCoor ] = strtod(ptr, &ptr); nodeAssigne[ iNode ] = 1; @@ -2919,10 +2976,8 @@ 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 @@ -2979,10 +3034,8 @@ 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); @@ -3363,9 +3416,7 @@ 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 @@ -3397,9 +3448,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, #ifdef WNT aResultFileName.ToCString(), #endif -#ifdef WITH_SMESH_CANCEL_COMPUTE this, -#endif /*theMesh, */helper, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap, aNodeId2NodeIndexMap, toMeshHoles, @@ -3427,6 +3476,9 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, { if ( !_keepFiles ) removeFile( aLogFileName ); + + if ( _hyp && _hyp->GetToMakeGroupsOfDomains() ) + error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since the mesh is on shape" ); } else if ( OSD_File( aLogFileName ).Size() > 0 ) { @@ -3443,11 +3495,9 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } if ( !_keepFiles ) { -#ifdef WITH_SMESH_CANCEL_COMPUTE if (! Ok) if(_compute_canceled) removeFile( aLogFileName ); -#endif removeFile( aFacesFileName ); removeFile( aPointsFileName ); removeFile( aResultFileName ); @@ -3629,9 +3679,7 @@ 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 @@ -3642,16 +3690,16 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // read a result // -------------- GHS3DPlugin_Hypothesis::TSetStrings groupsToRemove = GHS3DPlugin_Hypothesis::GetGroupsToRemove(_hyp); + const bool toMakeGroupsOfDomains = GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains( _hyp ); Ok = readGMFFile(aResultFileName.ToCString(), -#ifdef WITH_SMESH_CANCEL_COMPUTE this, -#endif theHelper, theShape, aNodeByGhs3dId, aNodeToGhs3dIdMap, aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId, - groupsToRemove); + groupsToRemove, toMakeGroupsOfDomains); updateMeshGroups(theHelper->GetMesh(), groupsToRemove); + removeEmptyGroupsOfDomains( theHelper->GetMesh() ); if ( Ok ) { GHS3DPlugin_Hypothesis* that = (GHS3DPlugin_Hypothesis*)this->_hyp; @@ -3666,6 +3714,9 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, { if ( !_keepFiles ) removeFile( aLogFileName ); + + if ( !toMakeGroupsOfDomains && _hyp && _hyp->GetToMakeGroupsOfDomains() ) + error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since 'toMeshHoles' is OFF." ); } else if ( OSD_File( aLogFileName ).Size() > 0 ) { @@ -3682,11 +3733,9 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, if ( !_keepFiles ) { -#ifdef WITH_SMESH_CANCEL_COMPUTE if (! Ok) if(_compute_canceled) removeFile( aLogFileName ); -#endif removeFile( aGMFFileName ); removeFile( aResultFileName ); removeFile( aRequiredVerticesFileName ); @@ -3695,7 +3744,6 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, return Ok; } -#ifdef WITH_SMESH_CANCEL_COMPUTE void GHS3DPlugin_GHS3D::CancelCompute() { _compute_canceled = true; @@ -3709,7 +3757,6 @@ void GHS3DPlugin_GHS3D::CancelCompute() system( cmd.ToCString() ); #endif } -#endif //================================================================================ /*! @@ -3896,10 +3943,8 @@ 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); @@ -4304,9 +4349,7 @@ bool GHS3DPlugin_GHS3D::importGMFMesh(const char* theGMFFileName, SMESH_Mesh& th std::set dummyGroupsToRemove; bool ok = readGMFFile(theGMFFileName, -#ifdef WITH_SMESH_CANCEL_COMPUTE this, -#endif helper, theMesh.GetShapeToMesh(), dummyNodeVector, dummyNodeMap, dummyElemGroup, dummyElemGroup, dummyElemGroup, dummyGroupsToRemove); theMesh.GetMeshDS()->Modified(); return ok; @@ -4364,6 +4407,33 @@ namespace /*visitAncestors=*/true); } }; + + //================================================================================ + /*! + * \brief Sub-mesh event listener removing empty groups created due to "To make + * groups of domains". + */ + struct _GroupsOfDomainsRemover : public SMESH_subMeshEventListener + { + _GroupsOfDomainsRemover(): + SMESH_subMeshEventListener( /*isDeletable = */true, + "GHS3DPlugin_GHS3D::_GroupsOfDomainsRemover" ) {} + /*! + * \brief Treat events of the subMesh + */ + void ProcessEvent(const int event, + const int eventType, + SMESH_subMesh* subMesh, + SMESH_subMeshEventListenerData* data, + const SMESH_Hypothesis* hyp) + { + if (SMESH_subMesh::ALGO_EVENT == eventType && + !subMesh->GetAlgo() ) + { + removeEmptyGroupsOfDomains( subMesh->GetFather(), /*notEmptyAsWell=*/true ); + } + } + }; } //================================================================================ @@ -4392,3 +4462,19 @@ void GHS3DPlugin_GHS3D::SubmeshRestored(SMESH_subMesh* subMesh) } } } + +//================================================================================ +/*! + * \brief Sets an event listener removing empty groups created due to "To make + * groups of domains". + * \param subMesh - submesh where algo is set + * + * This method is called when a submesh gets HYP_OK algo_state. + * After being set, event listener is notified on each event of a submesh. + */ +//================================================================================ + +void GHS3DPlugin_GHS3D::SetEventListener(SMESH_subMesh* subMesh) +{ + subMesh->SetEventListener( new _GroupsOfDomainsRemover(), 0, subMesh ); +} diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx index 285acd8..3489879 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx @@ -64,10 +64,8 @@ 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 void CancelCompute(); + bool computeCanceled() { return _compute_canceled;}; virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, MapShapeNbElems& aResMap); @@ -77,12 +75,16 @@ public: virtual void SubmeshRestored(SMESH_subMesh* subMesh); - bool importGMFMesh(const char* aGMFFileName, SMESH_Mesh& aMesh); + virtual void SetEventListener(SMESH_subMesh* subMesh); + + bool importGMFMesh(const char* aGMFFileName, SMESH_Mesh& aMesh); + + static const char* Name() { return "GHS3D_3D"; } private: - bool storeErrorDescription(const TCollection_AsciiString& logFile, - const _Ghs2smdsConvertor & toSmdsConvertor ); + bool storeErrorDescription(const TCollection_AsciiString& logFile, + const _Ghs2smdsConvertor & toSmdsConvertor ); TopoDS_Shape entryToShape(std::string entry); int _iShape; @@ -93,10 +95,7 @@ private: SALOMEDS::Study_var myStudy; SMESH_Gen_i* smeshGen_i; -#ifdef WITH_SMESH_CANCEL_COMPUTE volatile bool _compute_canceled; -#endif - }; /*! diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx index 437233c..90297a4 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx @@ -42,6 +42,7 @@ GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen) : SMESH_Hypothesis(hypId, studyId, gen), myToMeshHoles(DefaultMeshHoles()), + myToMakeGroupsOfDomains(DefaultToMakeGroupsOfDomains()), myMaximumMemory(-1), myInitialMemory(-1), myOptimizationLevel(DefaultOptimizationLevel()), @@ -97,6 +98,39 @@ bool GHS3DPlugin_Hypothesis::GetToMeshHoles(bool checkFreeOption) const return myToMeshHoles; } +//======================================================================= +//function : SetToMakeGroupsOfDomains +//======================================================================= + +void GHS3DPlugin_Hypothesis::SetToMakeGroupsOfDomains(bool toMakeGroups) +{ + if ( myToMakeGroupsOfDomains != toMakeGroups ) { + myToMakeGroupsOfDomains = toMakeGroups; + NotifySubMeshesHypothesisModification(); + } +} + +//======================================================================= +//function : GetToMakeGroupsOfDomains +//======================================================================= + +bool GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains() const +{ + return myToMakeGroupsOfDomains; +} + +//======================================================================= +//function : GetToMakeGroupsOfDomains +//======================================================================= + +bool GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains(const GHS3DPlugin_Hypothesis* hyp) +{ + bool res; + if ( hyp ) res = hyp->GetToMeshHoles(true) && hyp->GetToMakeGroupsOfDomains(); + else res = DefaultMeshHoles() && DefaultToMakeGroupsOfDomains(); + return res; +} + //======================================================================= //function : SetMaximumMemory //======================================================================= @@ -756,6 +790,15 @@ bool GHS3DPlugin_Hypothesis::DefaultMeshHoles() return false; // PAL19680 } +//======================================================================= +//function : DefaultToMakeGroupsOfDomains +//======================================================================= + +bool GHS3DPlugin_Hypothesis::DefaultToMakeGroupsOfDomains() +{ + return DefaultMeshHoles(); // issue 0022172 +} + //======================================================================= //function : DefaultMaximumMemory //======================================================================= @@ -922,6 +965,7 @@ std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save) save << (int)myToUseFemCorrection << " "; save << (int)myToRemoveCentralPoint << " "; save << myGradation << " "; + save << myToMakeGroupsOfDomains << " "; if (!myTextOption.empty()) { save << "__OPTIONS_BEGIN__ "; save << myTextOption << " "; @@ -1097,6 +1141,12 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load) bool hasEnforcedMeshes = false; isOK = (load >> separator); + if ( isOK && ( separator == "0" || separator == "1" )) + { + myToMakeGroupsOfDomains = ( separator == "1" ); + isOK = (load >> separator); + } + if (isOK) { if (separator == "__OPTIONS_BEGIN__") hasOptions = true; diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx index c756104..7d6b1ad 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx @@ -124,6 +124,13 @@ public: */ void SetToMeshHoles(bool toMesh); bool GetToMeshHoles(bool checkFreeOption = false) const; + /*! + * To make groups of volumes of different domains when mesh is generated from skin. + * Default is to make groups. + * This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true + */ + void SetToMakeGroupsOfDomains(bool toMakeGroups); + bool GetToMakeGroupsOfDomains() const; /*! * Maximal size of memory to be used by the algorithm (in Megabytes) */ @@ -263,9 +270,11 @@ public: static TIDSortedElemGroupMap GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp); static TID2SizeMap GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp); static TSetStrings GetGroupsToRemove(const GHS3DPlugin_Hypothesis* hyp); + static bool GetToMakeGroupsOfDomains(const GHS3DPlugin_Hypothesis* hyp); void ClearGroupsToRemove(); static bool DefaultMeshHoles(); + static bool DefaultToMakeGroupsOfDomains(); static short DefaultMaximumMemory(); static short DefaultInitialMemory(); static short DefaultOptimizationLevel(); @@ -313,6 +322,7 @@ public: private: bool myToMeshHoles; + bool myToMakeGroupsOfDomains; short myMaximumMemory; short myInitialMemory; short myOptimizationLevel; diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx index bedaf31..ce53a9d 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx @@ -90,6 +90,27 @@ CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToMeshHoles() return this->GetImpl()->GetToMeshHoles(); } +//======================================================================= +//function : SetToMakeGroupsOfDomains +//======================================================================= + +void GHS3DPlugin_Hypothesis_i::SetToMakeGroupsOfDomains(CORBA::Boolean toMakeGroups) +{ + ASSERT(myBaseImpl); + this->GetImpl()->SetToMakeGroupsOfDomains(toMakeGroups); + SMESH::TPythonDump() << _this() << ".SetToMakeGroupsOfDomains( " << toMakeGroups << " )"; +} + +//======================================================================= +//function : GetToMakeGroupsOfDomains +//======================================================================= + +CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToMakeGroupsOfDomains() +{ + ASSERT(myBaseImpl); + return this->GetImpl()->GetToMakeGroupsOfDomains(); +} + //======================================================================= //function : SetMaximumMemory //======================================================================= diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx index f3164ad..85f2844 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx @@ -55,6 +55,13 @@ class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis_i: */ void SetToMeshHoles(CORBA::Boolean toMesh); CORBA::Boolean GetToMeshHoles(); + /*! + * To make groups of volumes of different domains when mesh is generated from skin. + * Default is to make groups. + * This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true + */ + void SetToMakeGroupsOfDomains(CORBA::Boolean toMakeGroups); + CORBA::Boolean GetToMakeGroupsOfDomains(); /*! * Maximal size of memory to be used by the algorithm (in Megabytes) */ -- 2.39.2