1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : DriverCGNS_Read.cxx
23 // Created : Thu Jun 30 10:33:31 2011
24 // Author : Edward AGAPOV (eap)
26 #include <utilities.h>
28 #include "DriverCGNS_Read.hxx"
30 #include "SMDS_MeshNode.hxx"
31 #include "SMESHDS_Group.hxx"
32 #include "SMESHDS_Mesh.hxx"
33 #include "SMESH_Comment.hxx"
34 #include "SMESH_TypeDefs.hxx"
43 #if CGNS_VERSION < 3100
47 #define NB_ZONE_SIZE_VAL 9
48 #define CGNS_NAME_SIZE 33
49 #define CGNS_STRUCT_RANGE_SZ 6
55 //================================================================================
57 * \brief Data of a zone
62 int _nodeIdShift; // nb nodes in previously read zones
63 int _elemIdShift; // nb faces in previously read zones
64 int _nbNodes, _nbElems;
66 int _sizeX, _sizeY, _sizeZ, _nbCells; // structured
67 cgsize_t _sizes[NB_ZONE_SIZE_VAL];
68 CGNS_ENUMT(ZoneType_t) _type;
69 map< int, int > _nodeReplacementMap;/* key: id of node to replace (in this zone),
70 value: id of node to replace by (in another zone)
71 id values include _nodeIdShift of the zones */
72 void SetSizeAndDim( cgsize_t* sizes, int meshDim )
75 memcpy( _sizes, sizes, NB_ZONE_SIZE_VAL*sizeof(cgsize_t));
77 _sizeY = _meshDim > 1 ? _sizes[1] : 0;
78 _sizeZ = _meshDim > 2 ? _sizes[2] : 0;
79 _nbCells = (_sizeX - 1) * ( _meshDim > 1 ? _sizeY : 1 ) * ( _meshDim > 2 ? _sizeZ : 1 );
81 bool IsStructured() const { return ( _type == CGNS_ENUMV( Structured )); }
82 int IndexSize() const { return IsStructured() ? _meshDim : 1; }
83 string ReadZonesConnection(int file, int base,
84 const map< string, TZoneData >& zonesByName,
86 void ReplaceNodes( cgsize_t* ids, int nbIds, int idShift = 0 ) const;
88 // Methods for a structured zone
90 int NodeID( int i, int j, int k = 1 ) const
92 return _nodeIdShift + (k-1)*_sizeX*_sizeY + (j-1)*_sizeX + i;
94 int NodeID( const gp_XYZ& ijk ) const
96 return NodeID( int(ijk.X()), int(ijk.Y()), int(ijk.Z()));
98 void CellNodes( int i, int j, int k, cgsize_t* ids ) const
100 ids[0] = NodeID( i , j , k );
101 ids[1] = NodeID( i , j+1, k );
102 ids[2] = NodeID( i+1, j+1, k );
103 ids[3] = NodeID( i+1, j , k );
104 ids[4] = NodeID( i , j , k+1);
105 ids[5] = NodeID( i , j+1, k+1);
106 ids[6] = NodeID( i+1, j+1, k+1);
107 ids[7] = NodeID( i+1, j , k+1);
109 void CellNodes( int i, int j, cgsize_t* ids ) const
111 ids[0] = NodeID( i , j );
112 ids[1] = NodeID( i , j+1 );
113 ids[2] = NodeID( i+1, j+1 );
114 ids[3] = NodeID( i+1, j );
116 void IFaceNodes( int i, int j, int k, cgsize_t* ids ) const // face perpendiculaire to X (3D)
118 ids[0] = NodeID( i, j, k );
119 ids[1] = ids[0] + _sizeX*( i==_sizeX ? 1 : _sizeY );
120 ids[2] = ids[0] + _sizeX*( _sizeY + 1 );
121 ids[3] = ids[0] + _sizeX*( i==_sizeX ? _sizeY : 1 );
123 void JFaceNodes( int i, int j, int k, cgsize_t* ids ) const
125 ids[0] = NodeID( i, j, k );
126 ids[1] = ids[0] + ( j==_sizeY ? _sizeX*_sizeY : 1);
127 ids[2] = ids[0] + _sizeX*_sizeY + 1;
128 ids[3] = ids[0] + ( j==_sizeY ? 1 : _sizeX*_sizeY);
130 void KFaceNodes( int i, int j, int k, cgsize_t* ids ) const
132 ids[0] = NodeID( i, j, k );
133 ids[1] = ids[0] + ( k==_sizeZ ? 1 : _sizeX);
134 ids[2] = ids[0] + _sizeX + 1;
135 ids[3] = ids[0] + ( k==_sizeZ ? _sizeX : 1);
137 void IEdgeNodes( int i, int j, int /*k*/, cgsize_t* ids ) const // edge perpendiculaire to X (2D)
139 ids[0] = NodeID( i, j, 0 );
140 ids[1] = ids[0] + _sizeX;
142 void JEdgeNodes( int i, int j, int /*k*/, cgsize_t* ids ) const
144 ids[0] = NodeID( i, j, 0 );
147 #define gpXYZ2IJK(METHOD) \
148 void METHOD( const gp_XYZ& ijk, cgsize_t* ids ) const { \
149 METHOD( int(ijk.X()), int(ijk.Y()), int(ijk.Z()), ids); \
151 gpXYZ2IJK( IFaceNodes )
152 gpXYZ2IJK( JFaceNodes )
153 gpXYZ2IJK( KFaceNodes )
154 gpXYZ2IJK( IEdgeNodes )
155 gpXYZ2IJK( JEdgeNodes )
158 //================================================================================
160 * \brief Iterator over nodes of the structired grid using FORTRAN multidimensional
163 class TPointRangeIterator
165 int _beg[3], _end[3], _cur[3], _dir[3], _dim;
168 TPointRangeIterator( const cgsize_t* range, int dim ):
169 _beg{0,0,0}, _end{0,0,0}, _cur{0,0,0}, _dir{0,0,0}, _dim(dim), _more(false)
171 for ( int i = 0; i < dim; ++i )
174 _end[i] = range[i+dim];
175 _dir[i] = _end[i] < _beg[i] ? -1 : 1;
178 if ( _end[i] - _beg[i] )
188 gp_XYZ res( _cur[0], _cur[1], _cur[2] );
189 for ( int i = 0; i < _dim; ++i )
192 if ( _cur[i]*_dir[i] < _end[i]*_dir[i] )
204 for ( int i = 0; i < _dim; ++i )
205 size *= _dir[i]*(_end[i]-_beg[i]);
208 gp_XYZ Begin() const { return gp_XYZ( _beg[0], _beg[1], _beg[2] ); }
209 //gp_XYZ End() const { return gp_XYZ( _end[0]-1, _end[1]-1, _end[2]-1 ); }
212 //================================================================================
214 * \brief Checks if the two arrays of node IDs describe nodes with equal coordinates
216 //================================================================================
218 bool isEqualNodes( const int* nIds1, const int* nIds2, int nbNodes, SMESHDS_Mesh* mesh )
222 SMESH_TNodeXYZ nn1[2], nn2[2];
223 nn1[0] = mesh->FindNode( nIds1[0] );
224 nn2[0] = mesh->FindNode( nIds2[0] );
225 if ( !nn1[0]._node || !nn2[0]._node )
227 double dist1 = ( nn1[0] - nn2[0] ).Modulus();
228 double dist2 = 0, tol = 1e-7;
231 nn1[1] = mesh->FindNode( nIds1[1] );
232 nn2[1] = mesh->FindNode( nIds2[1] );
233 if ( !nn1[1]._node || !nn2[1]._node )
235 dist2 = ( nn1[1] - nn2[1] ).Modulus();
236 tol = 1e-5 * ( nn1[0] - nn1[1] ).Modulus();
238 return ( dist1 < tol && dist2 < tol );
243 //================================================================================
245 * \brief Reads zone interface connectivity
246 * \param file - file to read
247 * \param base - base to read
248 * \param zone - zone to replace nodes in
249 * \param zonesByName - TZoneData by name
250 * \retval string - warning message
252 * see // http://www.grc.nasa.gov/WWW/cgns/CGNS_docs_current/sids/cnct.html
254 //================================================================================
256 string TZoneData::ReadZonesConnection( int file,
258 const map< string, TZoneData >& zonesByName,
263 char connectName[ CGNS_NAME_SIZE ], donorName [ CGNS_NAME_SIZE ];
265 // ----------------------------
266 // read zone 1 to 1 interfaces
267 // ----------------------------
268 if ( IsStructured() )
271 if ( cg_n1to1 ( file, base, _id, &nb1to1) == CG_OK )
273 cgsize_t range[CGNS_STRUCT_RANGE_SZ], donorRange[CGNS_STRUCT_RANGE_SZ];
274 int transform[3] = {0,0,0};
276 for ( int I = 1; I <= nb1to1; ++I )
278 if ( cg_1to1_read(file, base, _id, I, connectName,
279 donorName, range, donorRange, transform) == CG_OK )
281 map< string, TZoneData>::const_iterator n_z = zonesByName.find( donorName );
282 if ( n_z == zonesByName.end() )
283 continue; // donor zone not yet read
284 const TZoneData& zone2 = n_z->second;
286 // set up matrix to transform ijk of the zone to ijk of the zone2
288 for ( int i = 0; i < _meshDim; ++i )
291 int row = Abs(transform[i]);
293 int val = transform[i] > 0 ? +1 : -1;
297 // fill nodeReplacementMap
298 TPointRangeIterator rangeIt1( range, _meshDim );
299 TPointRangeIterator rangeIt2( donorRange, _meshDim );
300 gp_XYZ begin1 = rangeIt1.Begin(), begin2 = rangeIt2.Begin(), index1, index2;
301 if ( &zone2 == this )
303 // not to read twice the same interface with self
304 TPointRangeIterator rangeIt1bis( range, _meshDim );
305 if ( rangeIt1bis.More() )
307 index1 = rangeIt1bis.Next();
308 index2 = T * ( index1 - begin1 ) + begin2;
309 int node1 = NodeID( index1 );
310 int node2 = zone2.NodeID( index2 );
311 if ( _nodeReplacementMap.count( node2 ) &&
312 _nodeReplacementMap[ node2 ] == node1 )
313 continue; // this interface already read
316 // check if range and donorRange describe the same nodes
318 int ids1[2], ids2[2], nbN = 0;
319 TPointRangeIterator rangeIt1bis( range, _meshDim );
320 index1 = rangeIt1bis.Next();
321 index2 = T * ( index1 - begin1 ) + begin2;
322 ids1[0] = NodeID( index1 );
323 ids2[0] = zone2.NodeID( index2 );
325 if ( rangeIt1bis.More() )
327 index1 = rangeIt1bis.Next();
328 index2 = T * ( index1 - begin1 ) + begin2;
329 ids1[1] = NodeID( index1 );
330 ids2[1] = zone2.NodeID( index2 );
333 if ( !isEqualNodes( &ids1[0], &ids2[0], nbN, mesh ))
336 while ( rangeIt1.More() )
338 index1 = rangeIt1.Next();
339 index2 = T * ( index1 - begin1 ) + begin2;
340 int node1 = NodeID( index1 );
341 int node2 = zone2.NodeID( index2 );
342 _nodeReplacementMap.insert( make_pair( node1, node2 ));
347 error = cg_get_error();
353 error = cg_get_error();
357 // ---------------------------------
358 // read general zone connectivities
359 // ---------------------------------
361 if ( cg_nconns( file, base, _id, &nbConn) == CG_OK )
363 cgsize_t nb, donorNb;
364 CGNS_ENUMT(GridLocation_t) location;
365 CGNS_ENUMT(GridConnectivityType_t) connectType;
366 CGNS_ENUMT(PointSetType_t) ptype, donorPtype;
367 CGNS_ENUMT(ZoneType_t) donorZonetype;
368 CGNS_ENUMT(DataType_t) donorDatatype;
370 for ( int I = 1; I <= nbConn; ++I )
372 if ( cg_conn_info(file, base, _id, I, connectName, &location, &connectType,
373 &ptype, &nb, donorName, &donorZonetype, &donorPtype,
374 &donorDatatype, &donorNb ) == CG_OK )
376 if ( location != CGNS_ENUMV( Vertex ))
377 continue; // we do not support cell-to-cell connectivity
378 if ( ptype != CGNS_ENUMV( PointList ) &&
379 ptype != CGNS_ENUMV( PointRange ))
381 if ( donorPtype != CGNS_ENUMV( PointList ) &&
382 donorPtype != CGNS_ENUMV( PointRange ))
385 map< string, TZoneData>::const_iterator n_z = zonesByName.find( donorName );
386 if ( n_z == zonesByName.end() )
387 continue; // donor zone not yet read
388 const TZoneData& zone2 = n_z->second;
390 vector< cgsize_t > ids( nb * IndexSize() );
391 vector< cgsize_t > donorIds( donorNb * zone2.IndexSize() );
392 if (cg_conn_read ( file, base, _id, I,
393 &ids[0], CGNS_ENUMV(Integer), &donorIds[0]) == CG_OK )
395 for ( int isThisZone = 0; isThisZone < 2; ++isThisZone )
397 const TZoneData& zone = isThisZone ? *this : zone2;
398 CGNS_ENUMT(PointSetType_t) type = isThisZone ? ptype : donorPtype;
399 vector< cgsize_t >& points = isThisZone ? ids : donorIds;
400 if ( type == CGNS_ENUMV( PointRange ))
402 TPointRangeIterator rangeIt( &points[0], zone._meshDim );
404 while ( rangeIt.More() )
405 points.push_back ( NodeID( rangeIt.Next() ));
407 else if ( zone.IsStructured() )
409 vector< cgsize_t > resIDs; resIDs.reserve( points.size() / IndexSize() );
410 for ( size_t i = 0; i < points.size(); i += IndexSize() )
411 resIDs.push_back( zone.NodeID( points[i+0], points[i+1], points[i+2] ));
412 resIDs.swap( points );
414 else if ( zone._nodeIdShift > 0 )
416 for ( size_t i = 0; i < points.size(); ++i )
417 points[i] += zone._nodeIdShift;
420 size_t nbN = std::min( ids.size(), donorIds.size());
421 if ( isEqualNodes( &ids[0], &donorIds[0], nbN, mesh ))
422 for ( size_t i = 0; i < nbN; ++i )
423 _nodeReplacementMap.insert( make_pair( ids[i], donorIds[i] ));
427 error = cg_get_error();
432 error = cg_get_error();
438 error = cg_get_error();
443 //================================================================================
445 * \brief Replaces node ids according to nodeReplacementMap to take into account
446 * connection of zones
448 //================================================================================
450 void TZoneData::ReplaceNodes( cgsize_t* ids, int nbIds, int idShift/* = 0*/ ) const
452 if ( !_nodeReplacementMap.empty() )
454 map< int, int >::const_iterator it, end = _nodeReplacementMap.end();
455 for ( int i = 0; i < nbIds; ++i )
456 if (( it = _nodeReplacementMap.find( ids[i] + idShift)) != end )
463 for ( int i = 0; i < nbIds; ++i )
467 //================================================================================
469 * \brief functions adding an element of a particular type
471 SMDS_MeshElement* add_0D(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
473 return mesh->Add0DElementWithID( ids[0], ID );
475 SMDS_MeshElement* add_BAR_2(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
477 return mesh->AddEdgeWithID( ids[0], ids[1], ID );
479 SMDS_MeshElement* add_BAR_3(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
481 return mesh->AddEdgeWithID( ids[0], ids[1], ids[2], ID );
483 SMDS_MeshElement* add_TRI_3(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
485 return mesh->AddFaceWithID( ids[0], ids[2], ids[1], ID );
487 SMDS_MeshElement* add_TRI_6(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
489 return mesh->AddFaceWithID( ids[0], ids[2], ids[1], ids[5], ids[4], ids[3], ID );
491 SMDS_MeshElement* add_QUAD_4(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
493 return mesh->AddFaceWithID( ids[0], ids[3], ids[2], ids[1], ID );
495 SMDS_MeshElement* add_QUAD_8(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
497 return mesh->AddFaceWithID( ids[0],ids[3],ids[2],ids[1],ids[7],ids[6],ids[5],ids[4], ID );
499 SMDS_MeshElement* add_QUAD_9(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
501 return mesh->AddFaceWithID( ids[0],ids[3],ids[2],ids[1],ids[7],ids[6],ids[5],ids[4],ids[8], ID);
503 SMDS_MeshElement* add_TETRA_4(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
505 return mesh->AddVolumeWithID( ids[0], ids[2], ids[1], ids[3], ID );
507 SMDS_MeshElement* add_TETRA_10(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
509 return mesh->AddVolumeWithID( ids[0],ids[2],ids[1],ids[3],ids[6],
510 ids[5],ids[4],ids[7],ids[9],ids[8], ID );
512 SMDS_MeshElement* add_PYRA_5(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
514 return mesh->AddVolumeWithID( ids[0],ids[3],ids[2],ids[1],ids[4],ID );
516 SMDS_MeshElement* add_PYRA_13(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
518 return mesh->AddVolumeWithID( ids[0],ids[3],ids[2],ids[1],ids[4],ids[8],ids[7],
519 ids[6],ids[5],ids[9],ids[12],ids[11],ids[10], ID );
521 SMDS_MeshElement* add_PENTA_6(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
523 return mesh->AddVolumeWithID( ids[0],ids[2],ids[1],ids[3],ids[5],ids[4], ID );
525 SMDS_MeshElement* add_PENTA_15(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
527 return mesh->AddVolumeWithID( ids[0],ids[2],ids[1],ids[3],ids[5],ids[4],ids[8],ids[7],
528 ids[6],ids[9],ids[11],ids[10],ids[14],ids[13],ids[12], ID );
530 SMDS_MeshElement* add_HEXA_8(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
532 return mesh->AddVolumeWithID( ids[0],ids[3],ids[2],ids[1],ids[4],ids[7],ids[6],ids[5], ID );
534 SMDS_MeshElement* add_HEXA_20(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
536 return mesh->AddVolumeWithID( ids[0],ids[3],ids[2],ids[1],ids[4],ids[7],ids[6],
537 ids[5],ids[11],ids[10],ids[9],ids[8],ids[12],ids[15],
538 ids[14],ids[13],ids[19],ids[18],ids[17],ids[16], ID );
540 SMDS_MeshElement* add_HEXA_27(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
542 return mesh->AddVolumeWithID( ids[0],ids[3],ids[2],ids[1],ids[4],ids[7],ids[6],
543 ids[5],ids[11],ids[10],ids[9],ids[8],ids[12],ids[15],
544 ids[14],ids[13],ids[19],ids[18],ids[17],ids[16],
545 ids[20],ids[24],ids[23],ids[22],ids[21],ids[25],ids[26], ID );
547 SMDS_MeshElement* add_NGON(cgsize_t* ids, SMESHDS_Mesh* mesh, int ID)
549 vector<int> idVec( ids[0] );
550 for ( int i = 0; i < ids[0]; ++i )
551 idVec[ i ] = (int) ids[ i + 1];
552 return mesh->AddPolygonalFaceWithID( idVec, ID );
555 typedef SMDS_MeshElement* (* PAddElemFun) (cgsize_t* ids, SMESHDS_Mesh* mesh, int ID);
557 //================================================================================
559 * \brief Return an array of functions each adding an element of a particular type
561 //================================================================================
563 PAddElemFun* getAddElemFunTable()
565 static vector< PAddElemFun > funVec;
566 if ( funVec.empty() )
568 funVec.resize( NofValidElementTypes, (PAddElemFun)0 );
569 funVec[ CGNS_ENUMV( NODE )] = add_0D ;
570 funVec[ CGNS_ENUMV( BAR_2 )] = add_BAR_2 ;
571 funVec[ CGNS_ENUMV( BAR_3 )] = add_BAR_3 ;
572 funVec[ CGNS_ENUMV( TRI_3 )] = add_TRI_3 ;
573 funVec[ CGNS_ENUMV( TRI_6 )] = add_TRI_6 ;
574 funVec[ CGNS_ENUMV( QUAD_4 )] = add_QUAD_4 ;
575 funVec[ CGNS_ENUMV( QUAD_8 )] = add_QUAD_8 ;
576 funVec[ CGNS_ENUMV( QUAD_9 )] = add_QUAD_9 ;
577 funVec[ CGNS_ENUMV( TETRA_4 )] = add_TETRA_4 ;
578 funVec[ CGNS_ENUMV( TETRA_10 )] = add_TETRA_10;
579 funVec[ CGNS_ENUMV( PYRA_5 )] = add_PYRA_5 ;
580 funVec[ CGNS_ENUMV( PYRA_13 )] = add_PYRA_13 ;
581 funVec[ CGNS_ENUMV( PYRA_14 )] = add_PYRA_13 ;
582 funVec[ CGNS_ENUMV( PENTA_6 )] = add_PENTA_6 ;
583 funVec[ CGNS_ENUMV( PENTA_15 )] = add_PENTA_15;
584 funVec[ CGNS_ENUMV( PENTA_18 )] = add_PENTA_15;
585 funVec[ CGNS_ENUMV( HEXA_8 )] = add_HEXA_8 ;
586 funVec[ CGNS_ENUMV( HEXA_20 )] = add_HEXA_20 ;
587 funVec[ CGNS_ENUMV( HEXA_27 )] = add_HEXA_27 ;
588 funVec[ CGNS_ENUMV( NGON_n )] = add_NGON ;
593 //================================================================================
595 * \brief Finds an existing boundary element
597 //================================================================================
599 const SMDS_MeshElement* findElement(const cgsize_t* nodeIDs,
601 const SMESHDS_Mesh* mesh)
603 const SMDS_MeshNode* nn[4]; // look for quad4 or seg2
604 if (( nn[0] = mesh->FindNode( nodeIDs[0] )))
606 SMDSAbs_ElementType eType = nbNodes==4 ? SMDSAbs_Face : SMDSAbs_Edge;
607 SMDS_ElemIteratorPtr eIt = nn[0]->GetInverseElementIterator( eType );
609 for ( int i = 1; i < nbNodes; ++i )
610 nn[i] = mesh->FindNode( nodeIDs[i] );
611 while ( eIt->more() )
613 const SMDS_MeshElement* e = eIt->next();
614 if ( e->NbNodes() == nbNodes )
617 for ( int i = 1; i < nbNodes && elemOK; ++i )
618 elemOK = ( e->GetNodeIndex( nn[i] ) >= 0 );
629 //================================================================================
631 * \brief Perform reading a myMeshId-th mesh
633 //================================================================================
635 Driver_Mesh::Status DriverCGNS_Read::Perform()
637 MESSAGE("DriverCGNS_Read::Perform");
638 myErrorMessages.clear();
641 if (( aResult = open() ) != DRS_OK )
644 // read nb of meshes (CGNSBase_t)
645 if ( myMeshId < 0 || myMeshId >= GetNbMeshes(aResult))
646 return addMessage( SMESH_Comment("Invalid mesh index :") << myMeshId );
647 MESSAGE("NbMeshes: " << GetNbMeshes(aResult));
649 // read a name and a dimension of the mesh
650 const int cgnsBase = myMeshId + 1;
651 char meshName[CGNS_NAME_SIZE];
652 int meshDim, spaceDim;
653 if ( cg_base_read( _fn, cgnsBase, meshName, &meshDim, &spaceDim) != CG_OK )
654 return addMessage( cg_get_error() );
656 if ( spaceDim < 1 || spaceDim > 3 )
657 return addMessage( SMESH_Comment("Invalid space dimension: ") << spaceDim
658 << " in mesh '" << meshName << "'");
660 myMeshName = meshName;
661 MESSAGE("myMeshName: " << myMeshName);
664 // read nb of domains (Zone_t) in the mesh
666 if ( cg_nzones (_fn, cgnsBase, &nbZones) != CG_OK )
667 return addMessage( cg_get_error() );
670 return addMessage( SMESH_Comment("Empty mesh: '") << meshName << "'");
671 MESSAGE("nbZones: " << nbZones);
673 // read the domains (zones)
674 // ------------------------
675 map< string, TZoneData > zonesByName;
676 char name[CGNS_NAME_SIZE];
677 cgsize_t sizes[NB_ZONE_SIZE_VAL];
678 memset(sizes, 0, NB_ZONE_SIZE_VAL * sizeof(cgsize_t));
680 const SMDS_MeshInfo& meshInfo = myMesh->GetMeshInfo();
681 int groupID = myMesh->GetGroups().size();
683 for ( int iZone = 1; iZone <= nbZones; ++iZone )
685 // size and name of a zone
686 if ( cg_zone_read( _fn, cgnsBase, iZone, name, sizes) != CG_OK) {
687 addMessage( cg_get_error() );
690 TZoneData& zone = zonesByName[ name ];
692 zone._nodeIdShift = meshInfo.NbNodes();
693 zone._elemIdShift = meshInfo.NbElements();
694 zone.SetSizeAndDim( sizes, meshDim );
695 MESSAGE(" zone name: " << name);
697 // mesh type of the zone
698 if ( cg_zone_type ( _fn, cgnsBase, iZone, &zone._type) != CG_OK) {
699 addMessage( cg_get_error() );
703 switch ( zone._type )
705 case CGNS_ENUMV( Unstructured ):
706 MESSAGE(" zone type: unstructured");
708 case CGNS_ENUMV( Structured ):
709 MESSAGE(" zone type: structured");
711 case CGNS_ENUMV( ZoneTypeNull ):
712 addMessage( "Meshes with ZoneTypeNull are not supported");
714 case CGNS_ENUMV( ZoneTypeUserDefined ):
715 addMessage( "Meshes with ZoneTypeUserDefined are not supported");
718 addMessage( "Unknown ZoneType_t");
725 MESSAGE(" Read nodes");
726 if ( cg_ncoords( _fn, cgnsBase, iZone, &spaceDim) != CG_OK ) {
727 addMessage( cg_get_error() );
730 if ( spaceDim < 1 ) {
731 addMessage( SMESH_Comment("No coordinates defined in zone ")
732 << iZone << " of Mesh " << myMeshId );
737 MESSAGE(" Read coordinates");
738 cgsize_t rmin[3] = {1,1,1}; // range of nodes to read
739 cgsize_t rmax[3] = {1,1,1};
740 int nbNodes = rmax[0] = zone._sizes[0];
741 if ( zone.IsStructured())
742 for ( int i = 1; i < meshDim; ++i )
743 nbNodes *= rmax[i] = zone._sizes[i];
745 vector<double> coords[3];
746 for ( int c = 1; c <= spaceDim; ++c)
748 coords[c-1].resize( nbNodes );
750 CGNS_ENUMV( DataType_t ) type;
751 if ( cg_coord_info( _fn, cgnsBase, iZone, c, &type, name) != CG_OK ||
752 cg_coord_read( _fn, cgnsBase, iZone, name, CGNS_ENUMV(RealDouble),
753 rmin, rmax, (void*)&(coords[c-1][0])) != CG_OK)
755 addMessage( cg_get_error() );
760 if ( coords[ spaceDim-1 ].empty() )
761 continue; // there was an error while reading coordinates
763 // fill coords with zero if spaceDim < 3
764 for ( int c = 2; c <= 3; ++c)
765 if ( coords[ c-1 ].empty() )
766 coords[ c-1 ].resize( nbNodes, 0.0 );
769 MESSAGE(" create nodes");
771 for ( int i = 0; i < nbNodes; ++i )
772 myMesh->AddNodeWithID( coords[0][i], coords[1][i], coords[2][i], i+1+zone._nodeIdShift );
774 catch ( std::exception& exc ) // expect std::bad_alloc
776 addMessage( exc.what() );
780 // Read connectivity between zones. Nodes of the zone interface will be
781 // replaced within the zones read later
782 string err = zone.ReadZonesConnection( _fn, cgnsBase, zonesByName, myMesh );
789 MESSAGE(" read elements");
790 if ( zone.IsStructured())
792 int nbI = zone._sizeX - 1, nbJ = zone._sizeY - 1, nbK = zone._sizeZ - 1;
794 if ( meshDim > 2 && nbK > 0 )
796 for ( int k = 1; k <= nbK; ++k )
797 for ( int j = 1; j <= nbJ; ++j )
798 for ( int i = 1; i <= nbI; ++i )
800 zone.CellNodes( i, j, k, nID );
801 zone.ReplaceNodes( nID, 8 );
802 myMesh->AddVolumeWithID(nID[0],nID[1],nID[2],nID[3],nID[4],nID[5],nID[6],nID[7],
803 meshInfo.NbElements()+1);
806 else if ( meshDim > 1 && nbJ > 0 )
808 for ( int j = 1; j <= nbJ; ++j )
809 for ( int i = 1; i <= nbI; ++i )
811 zone.CellNodes( i, j, nID );
812 zone.ReplaceNodes( nID, 4 );
813 myMesh->AddFaceWithID(nID[0],nID[1],nID[2],nID[3], meshInfo.NbElements()+1);
816 else if ( meshDim > 0 && nbI > 0 )
818 nID[0] = zone.NodeID( 1, 0, 0 );
819 for ( int i = 1; i <= nbI; ++i, ++nID[0] )
822 zone.ReplaceNodes( nID, 2 );
823 myMesh->AddEdgeWithID(nID[0],nID[1], meshInfo.NbElements()+1);
829 // elements can be stored in different sections each dedicated to one element type
831 if ( cg_nsections( _fn, cgnsBase, iZone, &nbSections) != CG_OK)
833 addMessage( cg_get_error() );
836 PAddElemFun* addElemFuns = getAddElemFunTable(), curAddElemFun = 0;
837 int nbNotSuppElem = 0; // nb elements of not supported types
838 bool polyhedError = false; // error at polyhedron creation
842 MESSAGE(" read element data");
843 CGNS_ENUMT( ElementType_t ) elemType;
844 cgsize_t start, end; // range of ids of elements of a zone
845 cgsize_t eDataSize = 0;
846 int nbBnd, parent_flag;
847 for ( int iSec = 1; iSec <= nbSections; ++iSec )
849 MESSAGE(" section " << iSec << " of " << nbSections);
850 if ( cg_section_read( _fn, cgnsBase, iZone, iSec, name, &elemType,
851 &start, &end, &nbBnd, &parent_flag) != CG_OK ||
852 cg_ElementDataSize( _fn, cgnsBase, iZone, iSec, &eDataSize ) != CG_OK )
854 addMessage( cg_get_error() );
857 vector< cgsize_t > elemData( eDataSize );
858 if ( cg_elements_read( _fn, cgnsBase, iZone, iSec, &elemData[0], NULL ) != CG_OK )
860 addMessage( cg_get_error() );
865 MESSAGE(" store elements");
866 int pos = 0, cgnsNbNodes = 0, elemID = start + zone._elemIdShift;
867 cg_npe( elemType, &cgnsNbNodes ); // get nb nodes by element type
868 curAddElemFun = addElemFuns[ elemType ];
869 SMDS_MeshElement* newElem = 0;
870 const SMDS_MeshElement* face;
872 while ( pos < eDataSize )
874 CGNS_ENUMT( ElementType_t ) currentType = elemType;
875 if ( currentType == CGNS_ENUMV( MIXED )) {
876 //ElementConnectivity = Etype1, Node11, Node21, ... NodeN1,
877 // Etype2, Node12, Node22, ... NodeN2,
879 // EtypeM, Node1M, Node2M, ... NodeNM
880 currentType = (CGNS_ENUMT(ElementType_t)) elemData[ pos++ ];
881 cg_npe( currentType, &cgnsNbNodes );
882 curAddElemFun = addElemFuns[ currentType ];
884 if ( cgnsNbNodes < 1 ) // poly elements
886 if ( currentType == CGNS_ENUMV( NFACE_n )) // polyhedron
888 //ElementConnectivity = Nfaces1, Face11, Face21, ... FaceN1,
889 // Nfaces2, Face12, Face22, ... FaceN2,
891 // NfacesM, Face1M, Face2M, ... FaceNM
892 const int nbFaces = elemData[ pos++ ];
893 vector<int> quantities( nbFaces );
894 vector<const SMDS_MeshNode*> nodes, faceNodes;
895 nodes.reserve( nbFaces * 4 );
896 for ( int iF = 0; iF < nbFaces; ++iF )
898 const int faceID = std::abs( elemData[ pos++ ]) + zone._elemIdShift;
899 if (( face = myMesh->FindElement( faceID )) && face->GetType() == SMDSAbs_Face )
901 const bool reverse = ( elemData[ pos-1 ] < 0 );
902 const int iQuad = face->IsQuadratic() ? 1 : 0;
903 SMDS_NodeIteratorPtr nIter = face->interlacedNodesIterator();
904 faceNodes.assign( SMDS_MeshElement::iterator( nIter ),
905 SMDS_MeshElement::iterator());
906 if ( iQuad && reverse )
907 nodes.push_back( faceNodes[0] );
909 nodes.insert( nodes.end(), faceNodes.rbegin(), faceNodes.rend() - iQuad );
911 nodes.insert( nodes.end(), faceNodes.begin(), faceNodes.end() );
913 quantities[ iF ] = face->NbNodes();
920 if ( quantities.back() )
922 myMesh->AddPolyhedralVolumeWithID( nodes, quantities, elemID );
925 else if ( currentType == CGNS_ENUMV( NGON_n )) // polygon
927 // ElementConnectivity = Nnodes1, Node11, Node21, ... NodeN1,
928 // Nnodes2, Node12, Node22, ... NodeN2,
930 // NnodesM, Node1M, Node2M, ... NodeNM
931 const int nbNodes = elemData[ pos ];
932 zone.ReplaceNodes( &elemData[pos+1], nbNodes, zone._nodeIdShift );
933 newElem = add_NGON( &elemData[pos ], myMesh, elemID );
937 else // standard elements
939 zone.ReplaceNodes( &elemData[pos], cgnsNbNodes, zone._nodeIdShift );
940 newElem = curAddElemFun( &elemData[pos], myMesh, elemID );
942 nbNotSuppElem += int( newElem && newElem->NbNodes() != cgnsNbNodes );
946 } // loop on elemData
947 } // loop on cgns sections
949 if ( nbNotSuppElem > 0 )
950 addMessage( SMESH_Comment(nbNotSuppElem) << " elements of not supported types"
951 << " have beem converted to close types");
953 addMessage( "Some polyhedral elements have been skipped due to internal(?) errors" );
955 } // reading unstructured elements
957 zone._nbNodes = meshInfo.NbNodes() - zone._nodeIdShift;
958 zone._nbElems = meshInfo.NbElements() - zone._elemIdShift;
960 // -------------------------------------------
961 // Read Boundary Conditions into SMESH groups
962 // -------------------------------------------
964 MESSAGE(" read Boundary Conditions");
966 if ( cg_nbocos( _fn, cgnsBase, iZone, &nbBC) == CG_OK )
968 CGNS_ENUMT( BCType_t ) bcType;
969 CGNS_ENUMT( PointSetType_t ) psType;
970 CGNS_ENUMT( DataType_t ) normDataType;
971 cgsize_t nbPnt, normFlag;
972 int normIndex[3], nbDS;
973 MESSAGE(" nbBC: " << nbBC);
974 for ( int iBC = 1; iBC <= nbBC; ++iBC )
976 MESSAGE(" iBC: " << iBC);
977 if ( cg_boco_info( _fn, cgnsBase, iZone, iBC, name, &bcType, &psType,
978 &nbPnt, normIndex, &normFlag, &normDataType, &nbDS ) != CG_OK )
980 addMessage( cg_get_error() );
983 MESSAGE(" iBC info OK: " << iBC);
984 vector< cgsize_t > ids( nbPnt * zone.IndexSize() );
985 CGNS_ENUMT( GridLocation_t ) location;
986 if ( cg_boco_read( _fn, cgnsBase, iZone, iBC, &ids[0], NULL ) != CG_OK ||
987 cg_boco_gridlocation_read( _fn, cgnsBase, iZone, iBC, &location) != CG_OK )
989 addMessage( cg_get_error() );
992 SMDSAbs_ElementType elemType = SMDSAbs_All;
993 switch ( location ) {
994 case CGNS_ENUMV( Vertex ): elemType = SMDSAbs_Node; break;
995 case CGNS_ENUMV( FaceCenter ): elemType = SMDSAbs_Face; break;
996 case CGNS_ENUMV( IFaceCenter ): elemType = SMDSAbs_Face; break;
997 case CGNS_ENUMV( JFaceCenter ): elemType = SMDSAbs_Face; break;
998 case CGNS_ENUMV( KFaceCenter ): elemType = SMDSAbs_Face; break;
999 case CGNS_ENUMV( EdgeCenter ): elemType = SMDSAbs_Edge; break;
1002 SMESHDS_Group* group = new SMESHDS_Group ( groupID++, myMesh, elemType );
1003 myMesh->AddGroup( group );
1004 SMESH_Comment groupName( name ); groupName << " " << cg_BCTypeName( bcType );
1005 group->SetStoreName( groupName.c_str() );
1006 SMDS_MeshGroup& groupDS = group->SMDSGroup();
1008 if ( elemType == SMDSAbs_Node )
1010 if ( zone.IsStructured() )
1012 vector< cgsize_t > nodeIds;
1013 if ( psType == CGNS_ENUMV( PointRange ))
1015 // nodes are given as (ijkMin, ijkMax)
1016 TPointRangeIterator idIt( & ids[0], meshDim );
1017 nodeIds.reserve( idIt.Size() );
1018 while ( idIt.More() )
1019 nodeIds.push_back( zone.NodeID( idIt.Next() ));
1023 // nodes are given as (ijk1, ijk2, ..., ijkN)
1024 nodeIds.reserve( ids.size() / meshDim );
1025 for ( size_t i = 0; i < ids.size(); i += meshDim )
1026 nodeIds.push_back( zone.NodeID( ids[i], ids[i+1], ids[i+2] ));
1028 ids.swap( nodeIds );
1030 else if ( zone._nodeIdShift )
1032 for ( size_t i = 0; i < ids.size(); ++i )
1033 ids[i] += zone._nodeIdShift;
1035 zone.ReplaceNodes( &ids[0], ids.size() );
1037 for ( size_t i = 0; i < ids.size(); ++i )
1038 if ( const SMDS_MeshNode* n = myMesh->FindNode( ids[i] ))
1041 else // BC applied to elements
1043 if ( zone.IsStructured() )
1045 int axis = 0; // axis perpendiculaire to which boundary elements are oriented
1046 if ( (int) ids.size() >= meshDim * 2 )
1048 for ( ; axis < meshDim; ++axis )
1049 if ( ids[axis] - ids[axis+meshDim] == 0 )
1054 for ( ; axis < meshDim; ++axis )
1055 if ( normIndex[axis] != 0 )
1058 if ( axis == meshDim )
1060 addMessage( SMESH_Comment("Invalid NormalIndex in BC ") << name );
1063 const int nbElemNodesByDim[] = { 1, 2, 4, 8 };
1064 const int nbElemNodes = nbElemNodesByDim[ meshDim ];
1066 if ( psType == CGNS_ENUMV( PointRange ) ||
1067 psType == CGNS_ENUMV( ElementRange ))
1069 // elements are given as (ijkMin, ijkMax)
1070 typedef void (TZoneData::*PGetNodesFun)( const gp_XYZ& ijk, cgsize_t* ids ) const;
1071 PGetNodesFun getNodesFun = 0;
1072 if ( elemType == SMDSAbs_Face && meshDim == 3 )
1074 case 0: getNodesFun = & TZoneData::IFaceNodes; break;
1075 case 1: getNodesFun = & TZoneData::JFaceNodes; break;
1076 case 2: getNodesFun = & TZoneData::KFaceNodes; break;
1078 else if ( elemType == SMDSAbs_Edge && meshDim == 2 )
1080 case 0: getNodesFun = & TZoneData::IEdgeNodes; break;
1081 case 1: getNodesFun = & TZoneData::JEdgeNodes; break;
1085 addMessage( SMESH_Comment("Unsupported BC location in BC ") << name
1086 << " " << cg_GridLocationName( location )
1087 << " in " << meshDim << " mesh");
1090 TPointRangeIterator rangeIt( & ids[0], meshDim );
1091 vector< cgsize_t > elemNodeIds( rangeIt.Size() * nbElemNodes );
1092 for ( int i = 0; rangeIt.More(); i+= nbElemNodes )
1093 (zone.*getNodesFun)( rangeIt.Next(), &elemNodeIds[i] );
1095 ids.swap( elemNodeIds );
1099 // elements are given as (ijk1, ijk2, ..., ijkN)
1100 typedef void (TZoneData::*PGetNodesFun)( int i, int j, int k, cgsize_t* ids ) const;
1101 PGetNodesFun getNodesFun = 0;
1102 if ( elemType == SMDSAbs_Face )
1104 case 0: getNodesFun = & TZoneData::IFaceNodes; break;
1105 case 1: getNodesFun = & TZoneData::JFaceNodes; break;
1106 case 2: getNodesFun = & TZoneData::KFaceNodes; break;
1108 else if ( elemType == SMDSAbs_Edge && meshDim == 2 )
1110 case 0: getNodesFun = & TZoneData::IEdgeNodes; break;
1111 case 1: getNodesFun = & TZoneData::JEdgeNodes; break;
1115 addMessage( SMESH_Comment("Unsupported BC location in BC ") << name
1116 << " " << cg_GridLocationName( location )
1117 << " in " << meshDim << " mesh");
1120 vector< cgsize_t > elemNodeIds( ids.size()/meshDim * nbElemNodes );
1121 for ( size_t i = 0, j = 0; i < ids.size(); i += meshDim, j += nbElemNodes )
1122 (zone.*getNodesFun)( ids[i], ids[i+1], ids[i+2], &elemNodeIds[j] );
1124 ids.swap( elemNodeIds );
1126 zone.ReplaceNodes( &ids[0], ids.size() );
1128 PAddElemFun addElemFun = 0;
1129 switch ( meshDim ) {
1130 case 1: addElemFun = & add_BAR_2; break;
1131 case 2: addElemFun = & add_QUAD_4; break;
1132 case 3: addElemFun = & add_HEXA_8; break;
1134 int elemID = meshInfo.NbElements();
1135 const SMDS_MeshElement* elem = 0;
1136 for ( size_t i = 0; i < ids.size(); i += nbElemNodes )
1138 if ( iZone == 1 || !( elem = findElement( &ids[i], nbElemNodes, myMesh )))
1139 elem = addElemFun( &ids[i], myMesh, ++elemID );
1140 groupDS.Add( elem );
1143 else // unstructured zone
1145 if ( zone._elemIdShift )
1146 for ( size_t i = 0; i < ids.size(); ++i )
1147 ids[i] += zone._elemIdShift;
1149 if ( psType == CGNS_ENUMV( PointRange ) && ids.size() == 2 )
1151 for ( cgsize_t i = ids[0]; i <= ids[1]; ++i )
1152 if ( const SMDS_MeshElement* e = myMesh->FindElement( i ))
1157 for ( size_t i = 0; i < ids.size(); ++i )
1158 if ( const SMDS_MeshElement* e = myMesh->FindElement( ids[i] ))
1162 } // end "BC applied to elements"
1164 // to have group type according to a real elem type
1165 group->SetType( groupDS.GetType() );
1167 } // loop on BCs of the zone
1169 else addMessage( cg_get_error() );
1172 MESSAGE(" read flow solutions");
1174 if ( cg_nsols( _fn, cgnsBase, iZone, &nsols) == CG_OK )
1176 MESSAGE(" nb flow solutions: " << nsols);
1178 else addMessage( cg_get_error() );
1180 MESSAGE(" read discrete data");
1182 if ( cg_ndiscrete( _fn, cgnsBase, iZone, &nbdiscrete) == CG_OK )
1184 MESSAGE(" nb discrete data: " << nbdiscrete);
1185 char nameDiscrete[CGNS_NAME_SIZE];
1186 for (int idisc = 1; idisc <= nbdiscrete; idisc++)
1188 if ( cg_discrete_read( _fn, cgnsBase, iZone, idisc, nameDiscrete) == CG_OK )
1190 MESSAGE(" discrete data #"<< idisc << " name: " << nameDiscrete);
1191 PointSetType_t ptset_type;
1193 if ( cg_discrete_ptset_info( _fn, cgnsBase, iZone, idisc, &ptset_type, &npnts) == CG_OK )
1195 MESSAGE(" discrete data #"<< idisc << " npnts: " << npnts);
1197 else addMessage( cg_get_error() );
1199 else addMessage( cg_get_error() );
1202 else addMessage( cg_get_error() );
1205 MESSAGE(" read subregions");
1207 if ( cg_nsubregs( _fn, cgnsBase, iZone, &nbSubrg) == CG_OK )
1209 MESSAGE(" nb subregions: " << nbSubrg);
1211 else addMessage( cg_get_error() );
1213 MESSAGE(" end zone");
1214 } // loop on the zones of a mesh
1216 MESSAGE("read families");
1218 if ( cg_nfamilies( _fn, cgnsBase, &nbFam) == CG_OK )
1220 MESSAGE("nb families: " << nbFam);
1222 else addMessage( cg_get_error() );
1226 // ------------------------------------------------------------------------
1227 // Make groups for multiple zones and remove free nodes at zone interfaces
1228 // ------------------------------------------------------------------------
1229 map< string, TZoneData >::iterator nameZoneIt = zonesByName.begin();
1230 for ( ; nameZoneIt != zonesByName.end(); ++nameZoneIt )
1232 MESSAGE("nameZone: " << nameZoneIt->first);
1233 TZoneData& zone = nameZoneIt->second;
1234 if ( zone._nbElems == 0 ) continue;
1235 if ( zone._nbElems == meshInfo.NbElements() ) break; // there is only one non-empty zone
1238 SMDSAbs_ElementType elemType = myMesh->GetElementType( zone._elemIdShift + 1,
1240 SMESHDS_Group* group = new SMESHDS_Group ( groupID++, myMesh, elemType );
1241 myMesh->AddGroup( group );
1242 group->SetStoreName( nameZoneIt->first.c_str() );
1243 SMDS_MeshGroup& groupDS = group->SMDSGroup();
1245 for ( int i = 1; i <= zone._nbElems; ++i )
1246 if ( const SMDS_MeshElement* e = myMesh->FindElement( i + zone._elemIdShift ))
1249 // remove free nodes
1250 map< int, int >::iterator nnRmKeepIt = zone._nodeReplacementMap.begin();
1251 for ( ; nnRmKeepIt != zone._nodeReplacementMap.end(); ++nnRmKeepIt )
1252 if ( const SMDS_MeshNode* n = myMesh->FindNode( nnRmKeepIt->first ))
1253 if ( n->NbInverseElements() == 0 )
1254 myMesh->RemoveFreeNode( n, (SMESHDS_SubMesh *)0, /*fromGroups=*/false );
1257 aResult = myErrorMessages.empty() ? DRS_OK : DRS_WARN_SKIP_ELEM;
1260 myMesh->CompactMesh();
1261 MESSAGE("end perform");
1265 //================================================================================
1267 * \brief Constructor
1269 //================================================================================
1271 DriverCGNS_Read::DriverCGNS_Read()
1275 //================================================================================
1277 * \brief Close the cgns file at destruction
1279 //================================================================================
1281 DriverCGNS_Read::~DriverCGNS_Read()
1287 //================================================================================
1289 * \brief Opens myFile
1291 //================================================================================
1293 Driver_Mesh::Status DriverCGNS_Read::open()
1299 int res = cg_open(myFile.c_str(), CG_MODE_READ, &_fn);
1301 int res = cg_open(myFile.c_str(), MODE_READ, &_fn);
1305 addMessage( cg_get_error(), /*fatal = */true );
1308 return _fn >= 0 ? DRS_OK : DRS_FAIL;
1311 //================================================================================
1313 * \brief Reads nb of meshes in myFile
1315 //================================================================================
1317 int DriverCGNS_Read::GetNbMeshes(Status& theStatus)
1319 if (( theStatus = open()) != DRS_OK )
1323 if(cg_nbases( _fn, &nbases) != CG_OK)
1324 theStatus = addMessage( cg_get_error(), /*fatal = */true );