mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-02-04 22:54:16 +05:00
22372: EDF 2758 SMESH: Create/Manage groups on a mesh composed of nodes and balls
Cash elements in case of small meshes
This commit is contained in:
parent
1f4550c491
commit
530e2aa3f8
@ -25,8 +25,8 @@
|
|||||||
//
|
//
|
||||||
#include "SMESHDS_GroupOnFilter.hxx"
|
#include "SMESHDS_GroupOnFilter.hxx"
|
||||||
|
|
||||||
#include "SMESHDS_Mesh.hxx"
|
|
||||||
#include "SMDS_SetIterator.hxx"
|
#include "SMDS_SetIterator.hxx"
|
||||||
|
#include "SMESHDS_Mesh.hxx"
|
||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@ -116,7 +116,7 @@ bool SMESHDS_GroupOnFilter::IsEmpty()
|
|||||||
|
|
||||||
bool SMESHDS_GroupOnFilter::Contains (const int theID)
|
bool SMESHDS_GroupOnFilter::Contains (const int theID)
|
||||||
{
|
{
|
||||||
return myPredicate ? myPredicate->IsSatisfy( theID ) : false;
|
return myPredicate && myPredicate->IsSatisfy( theID );
|
||||||
}
|
}
|
||||||
|
|
||||||
//================================================================================
|
//================================================================================
|
||||||
@ -127,7 +127,7 @@ bool SMESHDS_GroupOnFilter::Contains (const int theID)
|
|||||||
|
|
||||||
bool SMESHDS_GroupOnFilter::Contains (const SMDS_MeshElement* elem)
|
bool SMESHDS_GroupOnFilter::Contains (const SMDS_MeshElement* elem)
|
||||||
{
|
{
|
||||||
return myPredicate ? myPredicate->IsSatisfy( elem->GetID() ) : false;
|
return myPredicate && myPredicate->IsSatisfy( elem->GetID() );
|
||||||
}
|
}
|
||||||
|
|
||||||
//================================================================================
|
//================================================================================
|
||||||
@ -135,21 +135,36 @@ namespace // Iterator
|
|||||||
{
|
{
|
||||||
struct TIterator : public SMDS_ElemIterator
|
struct TIterator : public SMDS_ElemIterator
|
||||||
{
|
{
|
||||||
SMESH_PredicatePtr myPredicate;
|
SMESH_PredicatePtr myPredicate;
|
||||||
SMDS_ElemIteratorPtr myElemIt;
|
SMDS_ElemIteratorPtr myElemIt;
|
||||||
const SMDS_MeshElement* myNextElem;
|
const SMDS_MeshElement* myNextElem;
|
||||||
size_t myNbToFind, myNbFound;
|
size_t myNbToFind, myNbFound, myTotalNb;
|
||||||
TIterator( const SMESH_PredicatePtr& filter,
|
vector< const SMDS_MeshElement*>& myFoundElems;
|
||||||
SMDS_ElemIteratorPtr& elems,
|
bool & myFoundElemsOK;
|
||||||
size_t nbToFind):
|
|
||||||
|
TIterator( const SMESH_PredicatePtr& filter,
|
||||||
|
SMDS_ElemIteratorPtr& elems,
|
||||||
|
size_t nbToFind,
|
||||||
|
size_t totalNb,
|
||||||
|
vector< const SMDS_MeshElement*>& foundElems,
|
||||||
|
bool & foundElemsOK):
|
||||||
myPredicate( filter ),
|
myPredicate( filter ),
|
||||||
myElemIt( elems ),
|
myElemIt( elems ),
|
||||||
myNextElem( 0 ),
|
myNextElem( 0 ),
|
||||||
myNbToFind( nbToFind ),
|
myNbToFind( nbToFind ),
|
||||||
myNbFound( 0 )
|
myNbFound( 0 ),
|
||||||
|
myTotalNb( totalNb ),
|
||||||
|
myFoundElems( foundElems ),
|
||||||
|
myFoundElemsOK( foundElemsOK )
|
||||||
{
|
{
|
||||||
|
myFoundElemsOK = false;
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
~TIterator()
|
||||||
|
{
|
||||||
|
if ( !myFoundElemsOK )
|
||||||
|
clearVector( myFoundElems );
|
||||||
|
}
|
||||||
virtual bool more()
|
virtual bool more()
|
||||||
{
|
{
|
||||||
return myNextElem;
|
return myNextElem;
|
||||||
@ -160,14 +175,51 @@ namespace // Iterator
|
|||||||
myNbFound += bool( res );
|
myNbFound += bool( res );
|
||||||
myNextElem = 0;
|
myNextElem = 0;
|
||||||
if ( myNbFound < myNbToFind )
|
if ( myNbFound < myNbToFind )
|
||||||
|
{
|
||||||
while ( myElemIt->more() && !myNextElem )
|
while ( myElemIt->more() && !myNextElem )
|
||||||
{
|
{
|
||||||
myNextElem = myElemIt->next();
|
myNextElem = myElemIt->next();
|
||||||
if ( !myPredicate->IsSatisfy( myNextElem->GetID() ))
|
if ( !myPredicate->IsSatisfy( myNextElem->GetID() ))
|
||||||
myNextElem = 0;
|
myNextElem = 0;
|
||||||
}
|
}
|
||||||
|
if ( myNextElem )
|
||||||
|
myFoundElems.push_back( myNextElem );
|
||||||
|
else
|
||||||
|
keepOrClearElemVec();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
keepOrClearElemVec();
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
void keepOrClearElemVec()
|
||||||
|
{
|
||||||
|
if ( myNbFound == myTotalNb )
|
||||||
|
{
|
||||||
|
myFoundElemsOK = false; // all elems are OK, no need to keep them
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// nb of bytes used for myFoundElems
|
||||||
|
size_t vecMemSize = myFoundElems.size() * sizeof( SMDS_MeshElement* ) / sizeof(char);
|
||||||
|
size_t aMB = 1024 * 1024;
|
||||||
|
if ( vecMemSize < aMB )
|
||||||
|
{
|
||||||
|
myFoundElemsOK = true; // < 1 MB - do not clear
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int freeRamMB = SMDS_Mesh::CheckMemory( /*doNotRaise=*/true );
|
||||||
|
if ( freeRamMB < 0 )
|
||||||
|
myFoundElemsOK = true; // hope it's OK
|
||||||
|
else
|
||||||
|
myFoundElemsOK = ( freeRamMB * aMB > 10 * vecMemSize );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( !myFoundElemsOK )
|
||||||
|
clearVector( myFoundElems );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TEmptyIterator : public SMDS_ElemIterator
|
struct TEmptyIterator : public SMDS_ElemIterator
|
||||||
@ -186,8 +238,9 @@ namespace // Iterator
|
|||||||
SMDS_ElemIteratorPtr SMESHDS_GroupOnFilter::GetElements() const
|
SMDS_ElemIteratorPtr SMESHDS_GroupOnFilter::GetElements() const
|
||||||
{
|
{
|
||||||
size_t nbToFind = std::numeric_limits<size_t>::max();
|
size_t nbToFind = std::numeric_limits<size_t>::max();
|
||||||
|
size_t totalNb = GetMesh()->GetMeshInfo().NbElements( GetType() );
|
||||||
|
|
||||||
SMDS_ElemIteratorPtr elemIt;
|
SMDS_ElemIteratorPtr elemIt; // iterator on all elements to initialize TIterator
|
||||||
if ( myPredicate )
|
if ( myPredicate )
|
||||||
{
|
{
|
||||||
myPredicate->SetMesh( GetMesh() ); // hope myPredicate updates self here if necessary
|
myPredicate->SetMesh( GetMesh() ); // hope myPredicate updates self here if necessary
|
||||||
@ -195,8 +248,11 @@ SMDS_ElemIteratorPtr SMESHDS_GroupOnFilter::GetElements() const
|
|||||||
elemIt = GetMesh()->elementsIterator( GetType() );
|
elemIt = GetMesh()->elementsIterator( GetType() );
|
||||||
if ( IsUpToDate() )
|
if ( IsUpToDate() )
|
||||||
{
|
{
|
||||||
|
if ( myElementsOK )
|
||||||
|
return SMDS_ElemIteratorPtr( new SMDS_ElementVectorIterator( myElements.begin(),
|
||||||
|
myElements.end() ));
|
||||||
nbToFind = Extent();
|
nbToFind = Extent();
|
||||||
if ( nbToFind == GetMesh()->GetMeshInfo().NbElements( GetType() ))
|
if ( nbToFind == totalNb )
|
||||||
return elemIt; // all elements are OK
|
return elemIt; // all elements are OK
|
||||||
for ( size_t i = 0; i < myNbElemToSkip; ++i )
|
for ( size_t i = 0; i < myNbElemToSkip; ++i )
|
||||||
elemIt->next(); // skip w/o check
|
elemIt->next(); // skip w/o check
|
||||||
@ -206,7 +262,11 @@ SMDS_ElemIteratorPtr SMESHDS_GroupOnFilter::GetElements() const
|
|||||||
{
|
{
|
||||||
elemIt = SMDS_ElemIteratorPtr( new TEmptyIterator );
|
elemIt = SMDS_ElemIteratorPtr( new TEmptyIterator );
|
||||||
}
|
}
|
||||||
return SMDS_ElemIteratorPtr ( new TIterator( myPredicate, elemIt, nbToFind ));
|
|
||||||
|
// the iterator fills myElements if all elements are checked
|
||||||
|
SMESHDS_GroupOnFilter* me = const_cast<SMESHDS_GroupOnFilter*>( this );
|
||||||
|
return SMDS_ElemIteratorPtr
|
||||||
|
( new TIterator( myPredicate, elemIt, nbToFind, totalNb, me->myElements, me->myElementsOK ));
|
||||||
}
|
}
|
||||||
|
|
||||||
//================================================================================
|
//================================================================================
|
||||||
@ -323,6 +383,8 @@ void SMESHDS_GroupOnFilter::setChanged(bool changed)
|
|||||||
if ( changed && myMeshModifTime != 0 )
|
if ( changed && myMeshModifTime != 0 )
|
||||||
--myMeshModifTime;
|
--myMeshModifTime;
|
||||||
if ( changed ) {
|
if ( changed ) {
|
||||||
|
clearVector( myElements );
|
||||||
|
myElementsOK = false;
|
||||||
myNbElemToSkip = 0;
|
myNbElemToSkip = 0;
|
||||||
myMeshInfo.assign( SMDSEntity_Last, 0 );
|
myMeshInfo.assign( SMDSEntity_Last, 0 );
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ class SMESHDS_EXPORT SMESHDS_GroupOnFilter: public SMESHDS_GroupBase
|
|||||||
std::vector< int > GetMeshInfo() const;
|
std::vector< int > GetMeshInfo() const;
|
||||||
|
|
||||||
template< typename IDTYPE >
|
template< typename IDTYPE >
|
||||||
int GetElementIds( IDTYPE* ids ) const
|
int GetElementIds( IDTYPE* ids ) const
|
||||||
{
|
{
|
||||||
return getElementIds( (void*)ids, sizeof(IDTYPE));
|
return getElementIds( (void*)ids, sizeof(IDTYPE));
|
||||||
}
|
}
|
||||||
@ -76,8 +76,16 @@ class SMESHDS_EXPORT SMESHDS_GroupOnFilter: public SMESHDS_GroupBase
|
|||||||
const SMDS_MeshElement* setNbElemToSkip( SMDS_ElemIteratorPtr& elIt );
|
const SMDS_MeshElement* setNbElemToSkip( SMDS_ElemIteratorPtr& elIt );
|
||||||
int getElementIds( void* ids, size_t idSize ) const;
|
int getElementIds( void* ids, size_t idSize ) const;
|
||||||
|
|
||||||
|
// We use two ways of optimaization:
|
||||||
|
// 1) The case of little free memory. Remember nb of KO elements (myNbElemToSkip)
|
||||||
|
// to skip before the first OK element. As well remember total nb of OK
|
||||||
|
// elements (myMeshInfo) to stop iteration as all OK elements are found.
|
||||||
|
// 2) The case of enough free memory. Remember all OK elements (myElements).
|
||||||
|
|
||||||
SMESH_PredicatePtr myPredicate;
|
SMESH_PredicatePtr myPredicate;
|
||||||
std::vector< int > myMeshInfo;
|
std::vector< int > myMeshInfo;
|
||||||
|
std::vector< const SMDS_MeshElement*> myElements;
|
||||||
|
bool myElementsOK;
|
||||||
size_t myMeshModifTime; // when myMeshInfo was updated
|
size_t myMeshModifTime; // when myMeshInfo was updated
|
||||||
int myPredicateTic;
|
int myPredicateTic;
|
||||||
size_t myNbElemToSkip;
|
size_t myNbElemToSkip;
|
||||||
|
Loading…
Reference in New Issue
Block a user