X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FDriverCGNS%2FDriverCGNS_Write.cxx;h=06abf1dad98d7bf046d68c803753993d564ad7c5;hp=844bb863fb224023fed8656ba464d80ec2b2e729;hb=9435e2aab85ca83ccdb09dd4d60fc21e75f37281;hpb=911ca90c3d986ebefe41bf070c8f6506d0a69208 diff --git a/src/DriverCGNS/DriverCGNS_Write.cxx b/src/DriverCGNS/DriverCGNS_Write.cxx index 844bb863f..06abf1dad 100644 --- a/src/DriverCGNS/DriverCGNS_Write.cxx +++ b/src/DriverCGNS/DriverCGNS_Write.cxx @@ -25,6 +25,7 @@ #include "DriverCGNS_Write.hxx" +#include "SMDS_IteratorOnIterators.hxx" #include "SMDS_MeshNode.hxx" #include "SMDS_VolumeTool.hxx" #include "SMESHDS_GroupBase.hxx" @@ -330,7 +331,24 @@ Driver_Mesh::Status DriverCGNS_Write::Perform() // write into a section all successive elements of one geom type int iSec; vector< cgsize_t > elemData; - SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator(); + SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator(); + vector< SMDS_ElemIteratorPtr > elemItVec; + if ( _elementsByType ) + { + // create an iterator returning all elements by type + for ( int type = SMDSEntity_Node + 1; type < SMDSEntity_Last; ++type ) + { + if ( type == SMDSEntity_Ball ) + continue; // not supported + elemIt = myMesh->elementEntityIterator( SMDSAbs_EntityType( type )); + if ( elemIt->more() ) + elemItVec.push_back( elemIt ); + } + typedef SMDS_IteratorOnIterators< const SMDS_MeshElement*, + vector< SMDS_ElemIteratorPtr > > TVecIterator; + elemIt.reset( new TVecIterator( elemItVec )); + } + const SMDS_MeshElement* elem = elemIt->next(); while ( elem ) { @@ -397,6 +415,15 @@ Driver_Mesh::Status DriverCGNS_Write::Perform() elem = elemIt->more() ? elemIt->next() : 0; continue; } + else // skip NOT SUPPORTED elements + { + while ( elemIt->more() ) + { + elem = elemIt->next(); + if ( elem->GetEntityType() != elemType ) + break; + } + } SMESH_Comment sectionName( cg_ElementTypeName( cgType )); sectionName << " " << startID << " - " << cgID-1; @@ -405,6 +432,7 @@ Driver_Mesh::Status DriverCGNS_Write::Perform() cgID-1, /*nbndry=*/0, &elemData[0], &iSec) != CG_OK ) return addMessage( cg_get_error(), /*fatal = */true ); } + // Write polyhedral volumes // ------------------------- @@ -534,21 +562,21 @@ Driver_Mesh::Status DriverCGNS_Write::Perform() switch ( meshDim ) { case 3: switch ( group->GetType() ) { - case SMDSAbs_Volume: location = CGNS_ENUMV( FaceCenter ); break; // !!! - case SMDSAbs_Face: location = CGNS_ENUMV( FaceCenter ); break; // OK - case SMDSAbs_Edge: location = CGNS_ENUMV( EdgeCenter ); break; // OK + case SMDSAbs_Volume: location = CGNS_ENUMV( CellCenter ); break; + case SMDSAbs_Face: location = CGNS_ENUMV( FaceCenter ); break; + case SMDSAbs_Edge: location = CGNS_ENUMV( EdgeCenter ); break; default:; } break; case 2: switch ( group->GetType() ) { - case SMDSAbs_Face: location = CGNS_ENUMV( FaceCenter ); break; // ??? - case SMDSAbs_Edge: location = CGNS_ENUMV( EdgeCenter ); break; // OK + case SMDSAbs_Face: location = CGNS_ENUMV( CellCenter ); break; + case SMDSAbs_Edge: location = CGNS_ENUMV( EdgeCenter ); break; default:; } break; case 1: - location = CGNS_ENUMV( EdgeCenter ); break; // ??? + location = CGNS_ENUMV( CellCenter ); break; break; } } @@ -556,9 +584,16 @@ Driver_Mesh::Status DriverCGNS_Write::Perform() // try to extract type of boundary condition from the group name string name = group->GetStoreName(); CGNS_ENUMT( BCType_t ) bcType = getBCType( name ); - while ( !groupNames.insert( name ).second ) - name = (SMESH_Comment( "Group_") << groupNames.size()); - + if ( !groupNames.insert( name ).second ) // assure name uniqueness + { + int index = 1; + string newName; + do { + newName = SMESH_Comment( name ) << "_" << index++; + } + while ( !groupNames.insert( newName ).second ); + name = newName; + } // write IDs of elements vector< cgsize_t > pnts; pnts.reserve( group->Extent() ); @@ -568,6 +603,8 @@ Driver_Mesh::Status DriverCGNS_Write::Perform() const SMDS_MeshElement* elem = elemIt->next(); pnts.push_back( cgnsID( elem, elem2cgIDByEntity[ elem->GetEntityType() ])); } + if ( pnts.size() == 0 ) + continue; // can't store empty group int iBC; if ( cg_boco_write( _fn, iBase, iZone, name.c_str(), bcType, CGNS_ENUMV( PointList ), pnts.size(), &pnts[0], &iBC) != CG_OK ) @@ -589,7 +626,7 @@ Driver_Mesh::Status DriverCGNS_Write::Perform() */ //================================================================================ -DriverCGNS_Write::DriverCGNS_Write(): _fn(0) +DriverCGNS_Write::DriverCGNS_Write(): _fn(0), _elementsByType( false ) { }