From: eap Date: Thu, 30 Nov 2017 16:51:51 +0000 (+0300) Subject: 23514: EDF 16031 - SMESH freezes X-Git-Tag: V9_0_0~1^2~3^2 X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=commitdiff_plain;h=ccb5e3c25bf204e839c0094f50f543eacedba5e6 23514: EDF 16031 - SMESH freezes Optimize loading a study with multiple mesh groups --- diff --git a/src/DriverMED/DriverMED_Family.cxx b/src/DriverMED/DriverMED_Family.cxx index f6d67ea59..a11ba4860 100644 --- a/src/DriverMED/DriverMED_Family.cxx +++ b/src/DriverMED/DriverMED_Family.cxx @@ -93,7 +93,7 @@ DriverMED_Family return myType; } -const std::set< SMDSAbs_ElementType >& +const ElemTypeSet& DriverMED_Family ::GetTypes() const { diff --git a/src/DriverMED/DriverMED_Family.h b/src/DriverMED/DriverMED_Family.h index 1325617f1..c71ea7254 100644 --- a/src/DriverMED/DriverMED_Family.h +++ b/src/DriverMED/DriverMED_Family.h @@ -36,6 +36,7 @@ #include "SMESHDS_SubMesh.hxx" #include "MED_Common.hxx" +#include #include #include #include @@ -58,10 +59,11 @@ #define NIG_BALL_FAMILY INT_MAX-5 #define NIG_GROUP_PREFIX "NOT_IN_GRP" -typedef std::list DriverMED_FamilyPtrList; -typedef std::map SMESHDS_SubMeshPtrMap; -typedef std::list SMESHDS_GroupBasePtrList; -typedef std::set ElementsSet; +typedef std::list DriverMED_FamilyPtrList; +typedef std::map SMESHDS_SubMeshPtrMap; +typedef std::list SMESHDS_GroupBasePtrList; +typedef std::set ElementsSet; +typedef boost::container::flat_set< SMDSAbs_ElementType > ElemTypeSet; class MESHDRIVERMED_EXPORT DriverMED_Family { @@ -113,7 +115,7 @@ class MESHDRIVERMED_EXPORT DriverMED_Family void SetType(const SMDSAbs_ElementType theType); SMDSAbs_ElementType GetType(); - const std::set< SMDSAbs_ElementType >& GetTypes() const; + const ElemTypeSet& GetTypes() const; bool MemberOf(std::string theGroupName) const; @@ -126,9 +128,8 @@ class MESHDRIVERMED_EXPORT DriverMED_Family //! Split on some parts (families) on the basis of the elements type. static - DriverMED_FamilyPtrList - SplitByType(SMESHDS_SubMesh* theSubMesh, - const int theId); + DriverMED_FamilyPtrList SplitByType(SMESHDS_SubMesh* theSubMesh, + const int theId); /*! Remove from elements, common with , @@ -143,12 +144,12 @@ class MESHDRIVERMED_EXPORT DriverMED_Family private: - int myId; - SMDSAbs_ElementType myType; - ElementsSet myElements; - MED::TStringSet myGroupNames; - int myGroupAttributVal; - std::set myTypes; // Issue 0020576 + int myId; + SMDSAbs_ElementType myType; + ElementsSet myElements; + MED::TStringSet myGroupNames; + int myGroupAttributVal; + ElemTypeSet myTypes; // Issue 0020576 }; #endif diff --git a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx index b3c91db53..000316955 100644 --- a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx @@ -1092,8 +1092,8 @@ list DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes() set::const_iterator aGrNamesIter = aGroupNames.begin(); for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++) { - const set< SMDSAbs_ElementType >& types = aFamily->GetTypes(); - set< SMDSAbs_ElementType >::const_iterator type = types.begin(); + const ElemTypeSet& types = aFamily->GetTypes(); + ElemTypeSet::const_iterator type = types.begin(); for ( ; type != types.end(); ++type ) { TNameAndType aNameAndType = make_pair( *aGrNamesIter, *type ); @@ -1109,28 +1109,51 @@ list DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes() void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup) { - string aGroupName (theGroup->GetStoreName()); + TFamilyVec * famVecPtr; + + if ( myGroups2FamiliesMap.IsEmpty() ) // PAL23514 + { + TFamilyVec famVector( 1 ); + map::iterator famIter = myFamilies.begin(); + for ( ; famIter != myFamilies.end(); famIter++ ) + { + DriverMED_FamilyPtr family = famIter->second; + const MED::TStringSet& groups = family->GetGroupNames(); + famVector[ 0 ] = family; + MED::TStringSet::const_iterator grpIter = groups.begin(); + for ( ; grpIter != groups.end(); ++grpIter ) + { + TCollection_AsciiString groupName = grpIter->c_str(); + if (( famVecPtr = myGroups2FamiliesMap.ChangeSeek( groupName ))) + famVecPtr->push_back( family ); + else + myGroups2FamiliesMap.Bind( groupName, famVector ); + } + } + } + + const char* aGroupName = theGroup->GetStoreName(); if(MYDEBUG) MESSAGE("Get Group " << aGroupName); - map::iterator aFamsIter = myFamilies.begin(); - for (; aFamsIter != myFamilies.end(); aFamsIter++) + if (( famVecPtr = myGroups2FamiliesMap.ChangeSeek( aGroupName ))) { - DriverMED_FamilyPtr aFamily = (*aFamsIter).second; - if (aFamily->GetTypes().count( theGroup->GetType() ) && aFamily->MemberOf(aGroupName)) + for ( size_t i = 0; i < famVecPtr->size(); ++i ) { - const ElementsSet& anElements = aFamily->GetElements(); - ElementsSet::const_iterator anElemsIter = anElements.begin(); - for (; anElemsIter != anElements.end(); anElemsIter++) + DriverMED_FamilyPtr aFamily = (*famVecPtr)[i]; + if ( aFamily->GetTypes().count( theGroup->GetType() )) { - const SMDS_MeshElement * element = *anElemsIter; - if ( element->GetType() == theGroup->GetType() ) // Issue 0020576 - theGroup->SMDSGroup().Add(element); + const ElementsSet& anElements = aFamily->GetElements(); + ElementsSet::const_iterator anElemsIter = anElements.begin(); + for (; anElemsIter != anElements.end(); anElemsIter++) + { + const SMDS_MeshElement * element = *anElemsIter; + if ( element->GetType() == theGroup->GetType() ) // Issue 0020576 + theGroup->SMDSGroup().Add(element); + } + int aGroupAttrVal = aFamily->GetGroupAttributVal(); + if( aGroupAttrVal != 0 ) + theGroup->SetColorGroup(aGroupAttrVal); } - int aGroupAttrVal = aFamily->GetGroupAttributVal(); - if( aGroupAttrVal != 0) - theGroup->SetColorGroup(aGroupAttrVal); -// if ( element ) -- Issue 0020576 -// theGroup->SetType( theGroup->SMDSGroup().GetType() ); } } } diff --git a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.h b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.h index bd8fa80b0..ba7994e42 100644 --- a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.h +++ b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.h @@ -36,11 +36,16 @@ #include #include +#include +#include + class SMESHDS_Mesh; class SMESHDS_Group; class SMESHDS_SubMesh; -typedef std::pair< std::string, SMDSAbs_ElementType > TNameAndType; +typedef std::vector< DriverMED_FamilyPtr > TFamilyVec; +typedef std::pair< std::string, SMDSAbs_ElementType > TNameAndType; +typedef NCollection_DataMap< TCollection_AsciiString, TFamilyVec > TName2Falilies; class MESHDRIVERMED_EXPORT DriverMED_R_SMESHDS_Mesh: public Driver_SMESHDS_Mesh { @@ -56,9 +61,9 @@ class MESHDRIVERMED_EXPORT DriverMED_R_SMESHDS_Mesh: public Driver_SMESHDS_Mesh void SetMeshName(std::string theMeshName); private: - std::string myMeshName; + std::string myMeshName; std::map myFamilies; - + TName2Falilies myGroups2FamiliesMap; }; #endif diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index f6877fa47..65d22dab7 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -23,30 +23,31 @@ // Author : Paul RASCLE, EDF // Module : SMESH +#include +#include +#include +#include +#include +#include +#include #include #include +#include +#include +#include +#include #include -#include -#include #include -#include -#include -#include -#include +#include #include -#include +#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include #ifdef WIN32 @@ -4682,18 +4683,23 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, if ( aTopGroup->ExistInternalObject( name_group ) ) { aGroup = new HDFgroup( name_group, aTopGroup ); aGroup->OpenOnDisk(); - // get number of groups - int aNbSubObjects = aGroup->nInternalObjects(); - for ( int j = 0; j < aNbSubObjects; j++ ) { - char name_dataset[ HDF_NAME_MAX_LEN+1 ]; - aGroup->InternalObjectIndentify( j, name_dataset ); - // check if it is an group - if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) { + // PAL23514: get all names from the HDFgroup to avoid iteration on its contents + // within aGroup->ExistInternalObject( name ) + std::vector< std::string > subNames; + TColStd_MapOfAsciiString mapOfNames; + aGroup->GetAllObjects( subNames ); + for ( size_t iN = 0; iN < subNames.size(); ++iN ) + mapOfNames.Add( subNames[ iN ].c_str() ); + // loop on groups + for ( size_t j = 0; j < subNames.size(); j++ ) { + const std::string& name_dataset = subNames[ j ]; + // check if it is a group + if ( name_dataset.substr( 0, 5 ) == "Group" ) { // --> get group id - int subid = atoi( string( name_dataset ).substr( 5 ).c_str() ); + int subid = atoi( name_dataset.substr( 5 ).c_str() ); if ( subid <= 0 ) continue; - aDataset = new HDFdataset( name_dataset, aGroup ); + aDataset = new HDFdataset( name_dataset.c_str(), aGroup ); aDataset->OpenOnDisk(); // Retrieve actual group name @@ -4706,7 +4712,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, TopoDS_Shape aShape; char aRefName[ 30 ]; sprintf( aRefName, "Ref on shape %d", subid); - if ( aGroup->ExistInternalObject( aRefName ) ) { + if ( mapOfNames.Contains( aRefName )) + { // load mesh "Ref on shape" - it's an entry to SObject aDataset = new HDFdataset( aRefName, aGroup ); aDataset->OpenOnDisk(); @@ -4727,8 +4734,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, // Try to read a filter of SMESH_GroupOnFilter SMESH::Filter_var filter; SMESH_PredicatePtr predicate; - std::string hdfGrpName = "Filter " + SMESH_Comment(subid); - if ( aGroup->ExistInternalObject( hdfGrpName.c_str() )) + std::string hdfGrpName = ( SMESH_Comment( "Filter ") << subid ); + if ( mapOfNames.Contains( hdfGrpName.c_str() )) { aDataset = new HDFdataset( hdfGrpName.c_str(), aGroup ); aDataset->OpenOnDisk(); @@ -4769,13 +4776,13 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, if ( !aGroupBaseDS ) continue; - aGroupBaseDS->SetStoreName( name_dataset ); + aGroupBaseDS->SetStoreName( name_dataset.c_str() ); // ouv : NPAL12872 // Read color of the group char aGroupColorName[ 30 ]; sprintf( aGroupColorName, "ColorGroup %d", subid); - if ( aGroup->ExistInternalObject( aGroupColorName ) ) + if ( mapOfNames.Contains( aGroupColorName )) { aDataset = new HDFdataset( aGroupColorName, aGroup ); aDataset->OpenOnDisk(); diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index 1e869462c..ef9842298 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -61,56 +62,53 @@ class SALOME_LifeCycleCORBA; // ========================================================== class SMESH_I_EXPORT StudyContext { + typedef NCollection_DataMap< int, std::string > TInt2StringMap; + typedef NCollection_DataMap< int, int > TInt2IntMap; public: // constructor StudyContext() {} - // destructor - ~StudyContext() - { - mapIdToIOR.clear(); - mapIdToId.clear(); - } + // register object in the internal map and return its id int addObject( std::string theIOR ) { int nextId = getNextId(); - mapIdToIOR[ nextId ] = theIOR; + mapIdToIOR.Bind( nextId, theIOR ); return nextId; } // find the object id in the internal map by the IOR int findId( std::string theIOR ) { - std::map::iterator imap; + TInt2StringMap::iterator imap; for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) { - if ( imap->second == theIOR ) - return imap->first; + if ( *imap == theIOR ) + return imap.Iterator().Key(); } return 0; } // get object's IOR by id std::string getIORbyId( const int theId ) { - if ( mapIdToIOR.find( theId ) != mapIdToIOR.end() ) - return mapIdToIOR[ theId ]; - return std::string( "" ); + if ( mapIdToIOR.IsBound( theId ) ) + return mapIdToIOR( theId ); + return std::string(); } // get object's IOR by old id std::string getIORbyOldId( const int theOldId ) { - if ( mapIdToId.find( theOldId ) != mapIdToId.end() ) - return getIORbyId( mapIdToId[ theOldId ] ); - return std::string( "" ); + if ( mapIdToId.IsBound( theOldId ) ) + return getIORbyId( mapIdToId( theOldId )); + return std::string(); } // maps old object id to the new one (used when restoring data) void mapOldToNew( const int oldId, const int newId ) { - mapIdToId[ oldId ] = newId; + mapIdToId.Bind( oldId, newId ); } // get old id by a new one int getOldId( const int newId ) { - std::map::iterator imap; + TInt2IntMap::iterator imap; for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) { - if ( imap->second == newId ) - return imap->first; + if ( *imap == newId ) + return imap.Iterator().Key(); } return 0; } @@ -120,13 +118,13 @@ private: int getNextId() { int id = 1; - while( mapIdToIOR.find( id ) != mapIdToIOR.end() ) + while( mapIdToIOR.IsBound( id ) ) id++; return id; } - std::map mapIdToIOR; // persistent-to-transient map - std::map mapIdToId; // to translate object from persistent to transient form + TInt2StringMap mapIdToIOR; // persistent-to-transient map + TInt2IntMap mapIdToId; // to translate object from persistent to transient form }; // =========================================================== @@ -565,7 +563,7 @@ public: // Return an object that previously had an oldID template - typename TInterface::_var_type GetObjectByOldId( const int oldID ) + typename TInterface::_var_type GetObjectByOldId( const int oldID ) { if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) { std::string ior = myStudyContext->getIORbyOldId( oldID ); diff --git a/src/SMESH_I/SMESH_PreMeshInfo.cxx b/src/SMESH_I/SMESH_PreMeshInfo.cxx index 3d8980ff9..c7e753d89 100644 --- a/src/SMESH_I/SMESH_PreMeshInfo.cxx +++ b/src/SMESH_I/SMESH_PreMeshInfo.cxx @@ -287,10 +287,12 @@ namespace */ //================================================================================ -void SMESH_PreMeshInfo::hdf2meshInfo( const std::string& name, - HDFgroup* hdfGroup) +void SMESH_PreMeshInfo::hdf2meshInfo( const std::string& name, + HDFgroup* hdfGroup, + const TColStd_MapOfAsciiString& allHdfNames) { - if ( hdfGroup->ExistInternalObject( name.c_str()) ) + //if ( hdfGroup->ExistInternalObject( name.c_str()) ) PAL23514 + if ( allHdfNames.Contains( name.c_str() )) { HDFdataset* dataset = new HDFdataset( name.c_str(), hdfGroup ); dataset->OpenOnDisk(); @@ -419,7 +421,17 @@ bool SMESH_PreMeshInfo::readPreInfoFromHDF() HDFgroup* infoHdfGroup = new HDFgroup( hdfGroupName, aFile ); infoHdfGroup->OpenOnDisk(); - _mesh->changePreMeshInfo()->hdf2meshInfo( "Mesh", infoHdfGroup ); + // PAL23514: get all names from the HDFgroup to avoid iteration on its contents + // within aGroup->ExistInternalObject( name ) + TColStd_MapOfAsciiString mapOfNames; + { + std::vector< std::string > subNames; + infoHdfGroup->GetAllObjects( subNames ); + for ( size_t iN = 0; iN < subNames.size(); ++iN ) + mapOfNames.Add( subNames[ iN ].c_str() ); + } + + _mesh->changePreMeshInfo()->hdf2meshInfo( "Mesh", infoHdfGroup, mapOfNames ); // read SMESH_PreMeshInfo of groups map::const_iterator i2group = _mesh->_mapGroups.begin(); @@ -432,7 +444,7 @@ bool SMESH_PreMeshInfo::readPreInfoFromHDF() if ( SMESHDS_GroupBase* group = group_i->GetGroupDS() ) { const std::string name = group->GetStoreName(); - group_i->changePreMeshInfo()->hdf2meshInfo( name, infoHdfGroup ); + group_i->changePreMeshInfo()->hdf2meshInfo( name, infoHdfGroup, mapOfNames ); } } } @@ -444,7 +456,9 @@ bool SMESH_PreMeshInfo::readPreInfoFromHDF() if ( SMESH_subMesh_i* sm = SMESH::DownCast( id2sm->second )) { sm->changePreMeshInfo() = newInstance(); - sm->changePreMeshInfo()->hdf2meshInfo( SMESH_Comment( sm->GetId()), infoHdfGroup ); + sm->changePreMeshInfo()->hdf2meshInfo( SMESH_Comment( sm->GetId()), + infoHdfGroup, + mapOfNames ); } } } diff --git a/src/SMESH_I/SMESH_PreMeshInfo.hxx b/src/SMESH_I/SMESH_PreMeshInfo.hxx index e0469a978..62492c7d4 100644 --- a/src/SMESH_I/SMESH_PreMeshInfo.hxx +++ b/src/SMESH_I/SMESH_PreMeshInfo.hxx @@ -33,6 +33,7 @@ #include CORBA_SERVER_HEADER(SALOMEDS) #include +#include class DriverMED_R_SMESHDS_Mesh; class HDFfile; @@ -101,7 +102,9 @@ private: // reading from the new study, for which SaveToFile() was called bool readPreInfoFromHDF(); - void hdf2meshInfo( const std::string& dataSetName, HDFgroup* infoHdfGroup ); + void hdf2meshInfo( const std::string& dataSetName, + HDFgroup* infoHdfGroup, + const TColStd_MapOfAsciiString& allHdfNames); // reading from the old study, for which SaveToFile() was not called bool readMeshInfo();