bos #20282 EDF 22320 - general compute fails

1) Compute sub-meshes with prescribed order before the rest ones
2) Save sub-mesh order not as ids but as entries, because ids of groups
   within SMESHDS_Mesh can change at study loading if some group is no
   longer used as a base of sub-mesh of group on geometry
This commit is contained in:
eap 2020-12-02 11:51:19 +03:00
parent 053a6ac9d4
commit 4039f267f1
5 changed files with 117 additions and 28 deletions

View File

@ -2414,18 +2414,19 @@ void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
bool SMESH_Mesh::SortByMeshOrder(std::vector<SMESH_subMesh*>& theListToSort) const bool SMESH_Mesh::SortByMeshOrder(std::vector<SMESH_subMesh*>& theListToSort) const
{ {
if ( !_mySubMeshOrder.size() || theListToSort.size() < 2) if ( _mySubMeshOrder.empty() || theListToSort.size() < 2 )
return true; return true;
bool res = false;
std::vector<SMESH_subMesh*> onlyOrderedList, smVec;
// collect all ordered submeshes in one list as pointers
// collect all ordered sub-meshes in smVec as pointers
// and get their positions within theListToSort // and get their positions within theListToSort
std::vector<SMESH_subMesh*> smVec;
typedef std::vector<SMESH_subMesh*>::iterator TPosInList; typedef std::vector<SMESH_subMesh*>::iterator TPosInList;
std::map< int, TPosInList > sortedPos; std::map< size_t, size_t > sortedPos; // index in theListToSort to order
TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end(); TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end();
TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin(); TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin();
bool needSort = false;
for( ; listIdsIt != _mySubMeshOrder.end(); listIdsIt++) for( ; listIdsIt != _mySubMeshOrder.end(); listIdsIt++)
{ {
const TListOfInt& listOfId = *listIdsIt; const TListOfInt& listOfId = *listIdsIt;
@ -2452,27 +2453,46 @@ bool SMESH_Mesh::SortByMeshOrder(std::vector<SMESH_subMesh*>& theListToSort) con
// find smVec items in theListToSort // find smVec items in theListToSort
for ( size_t i = 0; i < smVec.size(); ++i ) for ( size_t i = 0; i < smVec.size(); ++i )
{ {
TPosInList smPos = find( smBeg, smEnd, smVec[i] ); TPosInList smPos = find( smBeg, smEnd, smVec[i] ); // position in theListToSort
if ( smPos != smEnd ) { if ( smPos != smEnd )
sortedPos[ std::distance( smBeg, smPos )] = smPos; {
if ( sortedPos.size() > onlyOrderedList.size() ) size_t posInList = std::distance( smBeg, smPos );
onlyOrderedList.push_back( smVec[i] ); size_t order = sortedPos.size();
sortedPos.insert( std::make_pair( posInList, order ));
if ( posInList != order )
needSort = true;
} }
} }
} }
if (onlyOrderedList.size() < 2) if ( ! needSort )
return res; return false;
res = true;
std::vector<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin(); // set sm of sortedPos from theListToSort to front of orderedSM
std::vector<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end(); // and the rest of theListToSort to orderedSM end
// iterate on ordered sub-meshes and insert them in detected positions std::vector<SMESH_subMesh*> orderedSM;
std::map< int, TPosInList >::iterator i_pos = sortedPos.begin(); orderedSM.reserve( theListToSort.size() );
for ( ; onlyBIt != onlyEIt; ++onlyBIt, ++i_pos ) orderedSM.resize( sortedPos.size() );
*(i_pos->second) = *onlyBIt;
return res; size_t iPrev = 0;
sortedPos.insert( std::make_pair( theListToSort.size(), sortedPos.size() ));
for ( const auto & pos_order : sortedPos )
{
const size_t& posInList = pos_order.first;
const size_t& order = pos_order.second;
if ( order < sortedPos.size() - 1 )
orderedSM[ order ] = theListToSort[ posInList ];
if ( iPrev < posInList )
orderedSM.insert( orderedSM.end(),
theListToSort.begin() + iPrev,
theListToSort.begin() + posInList );
iPrev = posInList + 1;
}
theListToSort.swap( orderedSM );
return true;
} }
//================================================================================ //================================================================================

View File

@ -144,6 +144,11 @@
#include <cstdlib> #include <cstdlib>
#include <memory> #include <memory>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/list.hpp>
#include <boost/serialization/string.hpp>
using namespace std; using namespace std;
using SMESH::TPythonDump; using SMESH::TPythonDump;
using SMESH::TVar; using SMESH::TVar;
@ -4790,7 +4795,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
// store submesh order if any // store submesh order if any
const TListOfListOfInt& theOrderIds = myLocMesh.GetMeshOrder(); const TListOfListOfInt& theOrderIds = myLocMesh.GetMeshOrder();
if ( theOrderIds.size() ) { const bool isNewOrederVersion = true; // old version saves ids, new one, entries
if ( !theOrderIds.empty() && !isNewOrederVersion ) { // keep old version for reference
char order_list[ 30 ]; char order_list[ 30 ];
strcpy( order_list, "Mesh Order" ); strcpy( order_list, "Mesh Order" );
// count number of submesh ids // count number of submesh ids
@ -4821,6 +4827,38 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
// //
delete[] smIDs; delete[] smIDs;
} }
if ( !theOrderIds.empty() && isNewOrederVersion )
{
// convert ids to entries
std::list< std::list< std::string > > orderEntryLists;
for ( const TListOfInt& idList : theOrderIds )
{
orderEntryLists.emplace_back();
std::list< std::string > & entryList = orderEntryLists.back();
for ( const int& id : idList )
{
const TopoDS_Shape& shape = mySMESHDSMesh->IndexToShape( id );
GEOM::GEOM_Object_var go = ShapeToGeomObject( shape );
SALOMEDS::SObject_var so = ObjectToSObject( go );
if ( !so->_is_nil() )
{
CORBA::String_var entry = so->GetID();
entryList.emplace_back( entry.in() );
}
}
}
// convert orderEntryLists to string
std::ostringstream ostream;
boost::archive::text_oarchive( ostream ) << orderEntryLists;
std::string orderEntryString = ostream.str();
// write HDF group
aSize[ 0 ] = orderEntryString.size() + 1;
aDataset = new HDFdataset( "MeshOrder_new", aTopGroup, HDF_STRING, aSize, 1 );
aDataset->CreateOnDisk();
aDataset->WriteOnDisk((char*) orderEntryString.data() );
aDataset->CloseOnDisk();
}
// groups root sub-branch // groups root sub-branch
SALOMEDS::SObject_wrap myGroupsBranch; SALOMEDS::SObject_wrap myGroupsBranch;
@ -5968,7 +6006,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
} }
// read Sub-Mesh ORDER if any // read Sub-Mesh ORDER if any
if ( aTopGroup->ExistInternalObject( "Mesh Order" )) { if ( aTopGroup->ExistInternalObject( "Mesh Order" )) { // old version keeps ids
aDataset = new HDFdataset( "Mesh Order", aTopGroup ); aDataset = new HDFdataset( "Mesh Order", aTopGroup );
aDataset->OpenOnDisk(); aDataset->OpenOnDisk();
size = aDataset->GetSize(); size = aDataset->GetSize();
@ -5986,6 +6024,37 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
myNewMeshImpl->GetImpl().SetMeshOrder( anOrderIds ); myNewMeshImpl->GetImpl().SetMeshOrder( anOrderIds );
delete [] smIDs; delete [] smIDs;
} }
if ( aTopGroup->ExistInternalObject( "MeshOrder_new" )) // new version keeps entries
{
aDataset = new HDFdataset( "MeshOrder_new", aTopGroup );
aDataset->OpenOnDisk();
size = aDataset->GetSize();
std::string dataString; dataString.resize( size );
aDataset->ReadFromDisk((char*) dataString.data() );
aDataset->CloseOnDisk();
std::istringstream istream( dataString.data() );
boost::archive::text_iarchive archive( istream );
std::list< std::list< std::string > > orderEntryLists;
try {
archive >> orderEntryLists;
}
catch (...) {}
TListOfListOfInt anOrderIds;
for ( const std::list< std::string >& entryList : orderEntryLists )
{
anOrderIds.emplace_back();
for ( const std::string & entry : entryList )
{
GEOM::GEOM_Object_var go = GetGeomObjectByEntry( entry );
TopoDS_Shape shape = GeomObjectToShape( go );
if ( SMESH_subMesh* sm = myNewMeshImpl->GetImpl().GetSubMesh( shape ))
anOrderIds.back().emplace_back( sm->GetId() );
}
}
myNewMeshImpl->GetImpl().SetMeshOrder( anOrderIds );
}
} // loop on meshes } // loop on meshes
// update hyps needing full mesh data restored (issue 20918) // update hyps needing full mesh data restored (issue 20918)
@ -6045,7 +6114,6 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
} }
} }
} }
pd << ""; // prevent optimizing pd out
// creation of tree nodes for all data objects in the study // creation of tree nodes for all data objects in the study
// to support tree representation customization and drag-n-drop: // to support tree representation customization and drag-n-drop:

View File

@ -6493,7 +6493,7 @@ class SMESH_DimHyp
TopTools_MapIteratorOfMapOfShape anItr( theToCheck ); TopTools_MapIteratorOfMapOfShape anItr( theToCheck );
for (; !isShared && anItr.More(); anItr.Next() ) for (; !isShared && anItr.More(); anItr.Next() )
{ {
const TopoDS_Shape aSubSh = anItr.Key(); const TopoDS_Shape& aSubSh = anItr.Key();
// check for case when concurrent dimensions are same // check for case when concurrent dimensions are same
isShared = theToFind.Contains( aSubSh ); isShared = theToFind.Contains( aSubSh );
// check for sub-shape with concurrent dimension // check for sub-shape with concurrent dimension

View File

@ -984,7 +984,7 @@ bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theSh
} }
else else
{ {
meshedFaces.push_back( prism.myBottom ); suspectSourceFaces.push_back( prism.myBottom );
if ( prism.myAlgoSM && prism.myAlgoSM->GetAlgo() ) if ( prism.myAlgoSM && prism.myAlgoSM->GetAlgo() )
meshedFace2AlgoSM.Bind( prism.myBottom, prism.myAlgoSM ); meshedFace2AlgoSM.Bind( prism.myBottom, prism.myAlgoSM );
} }

View File

@ -204,7 +204,7 @@ bool StdMeshers_Quadrangle_2D::CheckHypothesis
//============================================================================= //=============================================================================
/*! /*!
* * Compute the mesh on the given shape
*/ */
//============================================================================= //=============================================================================
@ -1606,7 +1606,8 @@ int StdMeshers_Quadrangle_2D::getCorners(const TopoDS_Face& theFace,
//============================================================================= //=============================================================================
/*! /*!
* * Return FaceQuadStruct where sides ordered CCW, top and left sides
* reversed to be co-directed with bottom and right sides
*/ */
//============================================================================= //=============================================================================