PAL8021. Correct work with submeshes on shape more complex than SHELL.

This commit is contained in:
eap 2005-02-07 11:11:51 +00:00
parent a9750358c9
commit 658c72bc1d

View File

@ -94,11 +94,24 @@ CORBA::Long SMESH_subMesh_i::GetNumberOfElements()
if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() ) if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
return 0; return 0;
SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS(); ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId];
if ( aSubMeshDS == NULL ) SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS();
return 0;
return aSubMeshDS->NbElements(); int nbElems = aSubMeshDS ? aSubMeshDS->NbElements() : 0;
// volumes are bound to shell
if ( nbElems == 0 && aSubMesh->GetSubShape().ShapeType() <= TopAbs_SOLID )
{
SMESHDS_Mesh* aMeshDS = aSubMesh->GetFather()->GetMeshDS();
TopExp_Explorer exp( aSubMesh->GetSubShape(), TopAbs_SHELL );
for ( ; exp.More(); exp.Next() )
{
aSubMeshDS = aMeshDS->MeshElements( exp.Current() );
if ( aSubMeshDS )
nbElems += aSubMeshDS->NbElements();
}
}
return nbElems;
} }
//============================================================================= //=============================================================================
@ -115,12 +128,36 @@ CORBA::Long SMESH_subMesh_i::GetNumberOfNodes(CORBA::Boolean all)
if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() ) if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
return 0; return 0;
SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS(); ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId];
SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS();
set<int> nodeIds;
// node are bound to shell instead of solid
if ( all && aSubMesh->GetSubShape().ShapeType() <= TopAbs_SOLID )
{
SMESHDS_Mesh* aMeshDS = aSubMesh->GetFather()->GetMeshDS();
TopExp_Explorer exp( aSubMesh->GetSubShape(), TopAbs_SHELL );
for ( ; exp.More(); exp.Next() )
{
aSubMeshDS = aMeshDS->MeshElements( exp.Current() );
if ( aSubMeshDS ) {
SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
while ( eIt->more() ) {
const SMDS_MeshElement* anElem = eIt->next();
SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
while ( nIt->more() )
nodeIds.insert( nIt->next()->GetID() );
}
}
}
return nodeIds.size();
}
if ( aSubMeshDS == NULL ) if ( aSubMeshDS == NULL )
return 0; return 0;
if ( all ) { // all nodes of submesh elements if ( all ) { // all nodes of submesh elements
set<int> nodeIds;
SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements(); SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
while ( eIt->more() ) { while ( eIt->more() ) {
const SMDS_MeshElement* anElem = eIt->next(); const SMDS_MeshElement* anElem = eIt->next();
@ -150,15 +187,41 @@ SMESH::long_array* SMESH_subMesh_i::GetElementsId()
if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() ) if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
return aResult._retn(); return aResult._retn();
SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS(); ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId];
if ( aSubMeshDS == NULL ) SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS();
return aResult._retn();
aResult->length( aSubMeshDS->NbElements() ); int nbElems = aSubMeshDS ? aSubMeshDS->NbElements() : 0;
SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements(); list<SMESHDS_SubMesh*> smList;
for ( int i = 0, n = aSubMeshDS->NbElements(); i < n && anIt->more(); i++ ) if ( nbElems )
aResult[i] = anIt->next()->GetID(); smList.push_back( aSubMeshDS );
// volumes are bound to shell
if ( nbElems == 0 && aSubMesh->GetSubShape().ShapeType() <= TopAbs_SOLID )
{
SMESHDS_Mesh* aMeshDS = aSubMesh->GetFather()->GetMeshDS();
TopExp_Explorer exp( aSubMesh->GetSubShape(), TopAbs_SHELL );
for ( ; exp.More(); exp.Next() )
{
aSubMeshDS = aMeshDS->MeshElements( exp.Current() );
if ( aSubMeshDS ) {
smList.push_back( aSubMeshDS );
nbElems += aSubMeshDS->NbElements();
}
}
}
if ( nbElems )
{
aResult->length( nbElems );
list<SMESHDS_SubMesh*>::iterator sm = smList.begin();
for ( int i = 0; sm != smList.end(); sm++ )
{
aSubMeshDS = *sm;
SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements();
for ( int n = aSubMeshDS->NbElements(); i < n && anIt->more(); i++ )
aResult[i] = anIt->next()->GetID();
}
}
return aResult._retn(); return aResult._retn();
} }
@ -179,19 +242,49 @@ SMESH::long_array* SMESH_subMesh_i::GetElementsByType( SMESH::ElementType theEle
if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() ) if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
return aResult._retn(); return aResult._retn();
SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS(); ::SMESH_subMesh* aSubMesh = _mesh_i->_mapSubMesh[_localId];
if ( aSubMeshDS == NULL ) SMESHDS_SubMesh* aSubMeshDS = aSubMesh->GetSubMeshDS();
return aResult._retn();
// No sense in returning ids of elements along with ids of nodes:
// when theElemType == SMESH::ALL, return node ids only if
// there are no elements
bool retNodes = (theElemType == SMESH::NODE ||
(theElemType == SMESH::ALL && aSubMeshDS->NbElements() == 0));
// PAL5440, return all nodes belonging to elements of submesh // PAL5440, return all nodes belonging to elements of submesh
set<int> nodeIds; set<int> nodeIds;
if ( retNodes ) { int nbElems = aSubMeshDS ? aSubMeshDS->NbElements() : 0;
// volumes may be bound to shell instead of solid
list< SMESHDS_SubMesh* > smList;
if ( nbElems == 0 && aSubMesh->GetSubShape().ShapeType() <= TopAbs_SOLID )
{
SMESHDS_Mesh* aMeshDS = aSubMesh->GetFather()->GetMeshDS();
TopExp_Explorer exp( aSubMesh->GetSubShape(), TopAbs_SHELL );
for ( ; exp.More(); exp.Next() )
{
aSubMeshDS = aMeshDS->MeshElements( exp.Current() );
if ( !aSubMeshDS ) continue;
if ( theElemType == SMESH::NODE )
{
SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
while ( eIt->more() ) {
const SMDS_MeshElement* anElem = eIt->next();
SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
while ( nIt->more() )
nodeIds.insert( nIt->next()->GetID() );
}
}
else
{
smList.push_back( aSubMeshDS );
nbElems += aSubMeshDS->NbElements();
}
}
aSubMeshDS = 0;
}
else
{
if ( nbElems )
smList.push_back( aSubMeshDS );
}
if ( theElemType == SMESH::NODE && aSubMeshDS )
{
SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements(); SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
while ( eIt->more() ) { while ( eIt->more() ) {
const SMDS_MeshElement* anElem = eIt->next(); const SMDS_MeshElement* anElem = eIt->next();
@ -200,28 +293,31 @@ SMESH::long_array* SMESH_subMesh_i::GetElementsByType( SMESH::ElementType theEle
nodeIds.insert( nIt->next()->GetID() ); nodeIds.insert( nIt->next()->GetID() );
} }
} }
if ( theElemType == SMESH::ALL ) if ( theElemType == SMESH::NODE )
aResult->length( aSubMeshDS->NbElements() + nodeIds.size());
else if ( theElemType == SMESH::NODE )
aResult->length( nodeIds.size() ); aResult->length( nodeIds.size() );
else else
aResult->length( aSubMeshDS->NbElements() ); aResult->length( nbElems );
int i = 0, n = aResult->length(); int i = 0, n = aResult->length();
if ( retNodes && !nodeIds.empty() ) { if ( theElemType == SMESH::NODE && !nodeIds.empty() ) {
set<int>::iterator idIt = nodeIds.begin(); set<int>::iterator idIt = nodeIds.begin();
for ( ; i < n && idIt != nodeIds.end() ; i++, idIt++ ) for ( ; i < n && idIt != nodeIds.end() ; i++, idIt++ )
aResult[i] = *idIt; aResult[i] = *idIt;
} }
if ( theElemType == SMESH::ALL || theElemType != SMESH::NODE ) { if ( theElemType != SMESH::NODE ) {
SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements(); list<SMESHDS_SubMesh*>::iterator sm = smList.begin();
while ( i < n && anIt->more() ) { for ( i = 0; sm != smList.end(); sm++ )
const SMDS_MeshElement* anElem = anIt->next(); {
if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType ) aSubMeshDS = *sm;
aResult[i++] = anElem->GetID(); SMDS_ElemIteratorPtr anIt = aSubMeshDS->GetElements();
while ( i < n && anIt->more() ) {
const SMDS_MeshElement* anElem = anIt->next();
if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
aResult[i++] = anElem->GetID();
}
} }
} }
@ -241,20 +337,7 @@ SMESH::long_array* SMESH_subMesh_i::GetNodesId()
{ {
Unexpect aCatch(SALOME_SalomeException); Unexpect aCatch(SALOME_SalomeException);
MESSAGE("SMESH_subMesh_i::GetNodesId"); MESSAGE("SMESH_subMesh_i::GetNodesId");
SMESH::long_array_var aResult = new SMESH::long_array(); SMESH::long_array_var aResult = GetElementsByType( SMESH::NODE );
if ( _mesh_i->_mapSubMesh.find( _localId ) == _mesh_i->_mapSubMesh.end() )
return aResult._retn();
SMESHDS_SubMesh* aSubMeshDS = _mesh_i->_mapSubMesh[_localId]->GetSubMeshDS();
if ( aSubMeshDS == NULL )
return aResult._retn();
aResult->length( aSubMeshDS->NbNodes() );
SMDS_NodeIteratorPtr anIt = aSubMeshDS->GetNodes();
for ( int i = 0, n = aSubMeshDS->NbNodes(); i < n && anIt->more(); i++ )
aResult[i] = anIt->next()->GetID();
return aResult._retn(); return aResult._retn();
} }