Salome HOME
844bb863fb224023fed8656ba464d80ec2b2e729
[modules/smesh.git] / src / DriverCGNS / DriverCGNS_Write.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File      : DriverCGNS_Write.cxx
23 // Created   : Fri Aug  5 17:43:54 2011
24 // Author    : Edward AGAPOV (eap)
25
26 #include "DriverCGNS_Write.hxx"
27
28 #include "SMDS_MeshNode.hxx"
29 #include "SMDS_VolumeTool.hxx"
30 #include "SMESHDS_GroupBase.hxx"
31 #include "SMESHDS_Mesh.hxx"
32 #include "SMESH_Comment.hxx"
33
34 #include <limits>
35 #include <cgnslib.h>
36
37 #if CGNS_VERSION < 3100
38 # define cgsize_t int
39 #endif
40
41 using namespace std;
42
43 namespace
44 {
45   //================================================================================
46   /*!
47    * \brief Return interlace and type of CGNS element for the given SMDSAbs_EntityType
48    */
49   //================================================================================
50
51   const int* getInterlaceAndType( const SMDSAbs_EntityType      smType,
52                                   CGNS_ENUMT( ElementType_t ) & cgType )
53   {
54     static vector< const int* >                 interlaces;
55     static vector< CGNS_ENUMT( ElementType_t )> cgTypes; 
56     if ( interlaces.empty() )
57     {
58       interlaces.resize( SMDSEntity_Last, 0 );
59       cgTypes.resize( SMDSEntity_Last, CGNS_ENUMV( ElementTypeNull ));
60       {
61         static int ids[] = {0};
62         interlaces[SMDSEntity_0D] = ids;
63         cgTypes   [SMDSEntity_0D] = CGNS_ENUMV( NODE );
64       }
65       {
66         static int ids[] = { 0, 1 };
67         interlaces[SMDSEntity_Edge] = ids;
68         cgTypes   [SMDSEntity_Edge] = CGNS_ENUMV( BAR_2 );
69       }
70       {
71         static int ids[] = { 0, 1, 2 };
72         interlaces[SMDSEntity_Quad_Edge] = ids;
73         cgTypes   [SMDSEntity_Quad_Edge] = CGNS_ENUMV( BAR_3 );
74       }
75       {
76         static int ids[] = { 0, 2, 1 };
77         interlaces[SMDSEntity_Triangle] = ids;
78         cgTypes   [SMDSEntity_Triangle] = CGNS_ENUMV( TRI_3 );
79       }
80       {
81         static int ids[] = { 0, 2, 1, 5, 4, 3 };
82         interlaces[SMDSEntity_Quad_Triangle] = ids;
83         cgTypes   [SMDSEntity_Quad_Triangle] = CGNS_ENUMV( TRI_6 );
84         interlaces[SMDSEntity_BiQuad_Triangle] = ids;
85         cgTypes   [SMDSEntity_BiQuad_Triangle] = CGNS_ENUMV( TRI_6 );
86       }
87       {
88         static int ids[] = { 0, 3, 2, 1 };
89         interlaces[SMDSEntity_Quadrangle] = ids;
90         cgTypes   [SMDSEntity_Quadrangle] = CGNS_ENUMV( QUAD_4 );
91       }
92       {
93         static int ids[] = { 0,3,2,1,7,6,5,4 };
94         interlaces[SMDSEntity_Quad_Quadrangle] = ids;
95         cgTypes   [SMDSEntity_Quad_Quadrangle] = CGNS_ENUMV( QUAD_8 );
96       }
97       {
98         static int ids[] = { 0,3,2,1,7,6,5,4,8 };
99         interlaces[SMDSEntity_BiQuad_Quadrangle] = ids;
100         cgTypes   [SMDSEntity_BiQuad_Quadrangle] = CGNS_ENUMV( QUAD_9 );
101       }
102       {
103         static int ids[] = { 0, 2, 1, 3 };
104         interlaces[SMDSEntity_Tetra] = ids;
105         cgTypes   [SMDSEntity_Tetra] = CGNS_ENUMV( TETRA_4 );
106       }
107       {
108         static int ids[] = { 0,2,1,3,6,5,4,7,9,8 };
109         interlaces[SMDSEntity_Quad_Tetra] = ids;
110         cgTypes   [SMDSEntity_Quad_Tetra] = CGNS_ENUMV( TETRA_10 );
111       }
112       {
113         static int ids[] = { 0,3,2,1,4 };
114         interlaces[SMDSEntity_Pyramid] = ids;
115         cgTypes   [SMDSEntity_Pyramid] = CGNS_ENUMV( PYRA_5 );
116       }
117       {
118         static int ids[] = { 0,3,2,1,4,8,7,6,5,9,12,11,10 };
119         interlaces[SMDSEntity_Quad_Pyramid] = ids;
120         cgTypes   [SMDSEntity_Quad_Pyramid] = CGNS_ENUMV( PYRA_13 );
121       }
122       {
123         static int ids[] = { 0,2,1,3,5,4 };
124         interlaces[SMDSEntity_Penta] = ids;
125         cgTypes   [SMDSEntity_Penta] = CGNS_ENUMV( PENTA_6 );
126       }
127       {
128         static int ids[] = { 0,2,1,3,5,4,8,7,6,9,11,10,14,13,12 };
129         interlaces[SMDSEntity_Quad_Penta] = ids;
130         cgTypes   [SMDSEntity_Quad_Penta] = CGNS_ENUMV( PENTA_15 );
131       }
132       {
133         static int ids[] = { 0,3,2,1,4,7,6,5 };
134         interlaces[SMDSEntity_Hexa] = ids;
135         cgTypes   [SMDSEntity_Hexa] = CGNS_ENUMV( HEXA_8 );
136       }
137       {
138         static int ids[] = { 0,3,2,1,4,7,6,5,11,10,9,8,12,15,14,13,19,18,17,16 };
139         interlaces[SMDSEntity_Quad_Hexa] = ids;
140         cgTypes   [SMDSEntity_Quad_Hexa] = CGNS_ENUMV( HEXA_20 );
141       }
142       {
143         static int ids[] = { 0,3,2,1,4,7,6,5,11,10,9,8,12,15,14,13,19,18,17,16,
144                              20, 24,23,22,21, 25, 26};
145         interlaces[SMDSEntity_TriQuad_Hexa] = ids;
146         cgTypes   [SMDSEntity_TriQuad_Hexa] = CGNS_ENUMV( HEXA_27 );
147       }
148       {
149         cgTypes[SMDSEntity_Polygon]         = CGNS_ENUMV( NGON_n );
150         cgTypes[SMDSEntity_Quad_Polygon]    = CGNS_ENUMV( NGON_n );
151         cgTypes[SMDSEntity_Polyhedra]       = CGNS_ENUMV( NFACE_n );
152         cgTypes[SMDSEntity_Hexagonal_Prism] = CGNS_ENUMV( NFACE_n );
153       }
154     }
155     cgType  = cgTypes[ smType ];
156     return interlaces[ smType ];
157   }
158
159   //================================================================================
160   /*!
161    * \brief Cut off type of boundary condition from the group name
162    */
163   //================================================================================
164
165   CGNS_ENUMT( BCType_t ) getBCType( string& groupName )
166   {
167     CGNS_ENUMT( BCType_t ) bcType = CGNS_ENUMV( BCGeneral ); // default type
168
169     // boundary condition type starts from "BC"
170     size_t bcBeg = groupName.find("BC");
171     if ( bcBeg != string::npos )
172     {
173       for ( int t = 0; t < NofValidBCTypes; ++t )
174       {
175         CGNS_ENUMT( BCType_t ) type = CGNS_ENUMT( BCType_t )( t );
176         string typeName = cg_BCTypeName( type );
177         if ( typeName == &groupName[0] + bcBeg )
178         {
179           bcType = type;
180           while ( bcBeg > 0 && isspace( bcBeg-1 ))
181             --bcBeg;
182           if ( bcBeg == 0 )
183             groupName = "Group";
184           else
185             groupName = groupName.substr( 0, bcBeg-1 );
186         }
187       }
188     }
189     return bcType;
190   }
191
192   //================================================================================
193   /*!
194    * \brief Sortable face of a polyhedron
195    */
196   struct TPolyhedFace
197   {
198     int _id; // id of NGON_n
199     vector< int > _nodes; // lowest node IDs used for sorting
200
201     TPolyhedFace( const SMDS_MeshNode** nodes, const int nbNodes, int ID):_id(ID)
202     {
203       set< int > ids;
204       for ( int i = 0; i < nbNodes; ++i )
205         ids.insert( nodes[i]->GetID() );
206
207       _nodes.resize( 3 ); // std::min( nbNodes, 4 )); hope 3 nodes is enough
208       set< int >::iterator idIt = ids.begin();
209       for ( size_t j = 0; j < _nodes.size(); ++j, ++idIt )
210         _nodes[j] = *idIt;
211     }
212     bool operator< (const TPolyhedFace& o ) const
213     {
214       return _nodes < o._nodes;
215     }
216   };
217   //================================================================================
218   /*!
219    * \brief Return CGNS id of an element
220    */
221   //================================================================================
222
223   cgsize_t cgnsID( const SMDS_MeshElement*                         elem,
224                    const map< const SMDS_MeshElement*, cgsize_t >& elem2cgID )
225   {
226     map< const SMDS_MeshElement*, cgsize_t >::const_iterator e2id = elem2cgID.find( elem );
227     return ( e2id == elem2cgID.end() ? elem->GetID() : e2id->second );
228   }
229
230 } // namespace
231
232 //================================================================================
233 /*!
234  * \brief Write the mesh into the CGNS file
235  */
236 //================================================================================
237
238 Driver_Mesh::Status DriverCGNS_Write::Perform()
239 {
240   myErrorMessages.clear();
241
242   if ( !myMesh || myMesh->GetMeshInfo().NbElements() < 1 )
243     return addMessage( !myMesh ? "NULL mesh" : "Empty mesh (no elements)", /*fatal = */true );
244
245   // open the file
246   if ( cg_open(myFile.c_str(), CG_MODE_MODIFY, &_fn) != CG_OK &&
247        cg_open(myFile.c_str(), CG_MODE_WRITE,  &_fn) != CG_OK )
248     return addMessage( cg_get_error(), /*fatal = */true );
249
250   // create a Base
251   // --------------
252
253   const int spaceDim = 3;
254   int        meshDim = 1;
255   if ( myMesh->NbFaces()   > 0 ) meshDim = 2;
256   if ( myMesh->NbVolumes() > 0 ) meshDim = 3;
257
258   if ( myMeshName.empty() )
259   {
260     int nbases = 0;
261     if ( cg_nbases( _fn, &nbases) == CG_OK )
262       myMeshName = ( SMESH_Comment("Base_") << nbases+1 );
263     else
264       myMeshName = "Base_0";
265   }
266   int iBase;
267   if ( cg_base_write( _fn, myMeshName.c_str(), meshDim, spaceDim, &iBase ))
268     return addMessage( cg_get_error(), /*fatal = */true );
269
270   // create a Zone
271   // --------------
272
273   int nbCells = myMesh->NbEdges();
274   if ( meshDim == 3 )
275     nbCells = myMesh->NbVolumes();
276   else if ( meshDim == 2 )
277     nbCells = myMesh->NbFaces();
278
279   cgsize_t size[9] = { myMesh->NbNodes(), nbCells, /*NBoundVertex=*/0, 0,0,0,0,0,0 };
280   int iZone;
281   if ( cg_zone_write( _fn, iBase, "SMESH_Mesh", size,
282                       CGNS_ENUMV( Unstructured ), &iZone) != CG_OK )
283     return addMessage( cg_get_error(), /*fatal = */true );
284
285   // Map to store only elements whose an SMDS ID differs from a CGNS one
286   typedef map< const SMDS_MeshElement*, cgsize_t > TElem2cgIDMap;
287   vector< TElem2cgIDMap > elem2cgIDByEntity( SMDSEntity_Last );
288   TElem2cgIDMap::iterator elem2cgIDIter;
289
290   TElem2cgIDMap & n2cgID = elem2cgIDByEntity[ SMDSEntity_Node ];
291
292   // Write nodes
293   // ------------
294   {
295     vector< double > coords( myMesh->NbNodes() );
296     int iC;
297     // X
298     SMDS_NodeIteratorPtr nIt = myMesh->nodesIterator( /*idInceasingOrder=*/true );
299     for ( int i = 0; nIt->more(); ++i ) coords[i] = nIt->next()->X();
300     if ( cg_coord_write( _fn, iBase, iZone, CGNS_ENUMV(RealDouble),
301                           "CoordinateX", &coords[0], &iC) != CG_OK )
302       return addMessage( cg_get_error(), /*fatal = */true );
303     // Y
304     nIt = myMesh->nodesIterator( /*idInceasingOrder=*/true );
305     for ( int i = 0; nIt->more(); ++i ) coords[i] = nIt->next()->Y();
306     if ( cg_coord_write( _fn, iBase, iZone, CGNS_ENUMV(RealDouble),
307                           "CoordinateY", &coords[0], &iC) != CG_OK )
308       return addMessage( cg_get_error(), /*fatal = */true );
309     // Z
310     nIt = myMesh->nodesIterator( /*idInceasingOrder=*/true );
311     for ( int i = 0; nIt->more(); ++i ) coords[i] = nIt->next()->Z();
312     if ( cg_coord_write( _fn, iBase, iZone, CGNS_ENUMV(RealDouble),
313                           "CoordinateZ", &coords[0], &iC) != CG_OK )
314       return addMessage( cg_get_error(), /*fatal = */true );
315
316     // store CGNS ids of nodes
317     nIt = myMesh->nodesIterator( /*idInceasingOrder=*/true );
318     for ( int i = 0; nIt->more(); ++i )
319     {
320       const SMDS_MeshElement* n = nIt->next();
321       if ( n->GetID() != i+1 )
322         n2cgID.insert( n2cgID.end(), make_pair( n, i+1 ));
323     }
324   }
325   // Write elements
326   // ---------------
327   
328   cgsize_t cgID = 1, startID;
329
330   // write into a section all successive elements of one geom type
331   int iSec;
332   vector< cgsize_t > elemData;
333   SMDS_ElemIteratorPtr  elemIt = myMesh->elementsIterator();
334   const SMDS_MeshElement* elem = elemIt->next();
335   while ( elem )
336   {
337     const SMDSAbs_EntityType elemType = elem->GetEntityType();
338     CGNS_ENUMT( ElementType_t ) cgType;
339     const int* interlace = getInterlaceAndType( elemType, cgType );
340
341     TElem2cgIDMap & elem2cgID = elem2cgIDByEntity[ elemType ];
342
343     elemData.clear();
344     startID = cgID;
345
346     if ( interlace ) // STANDARD elements
347     {
348       int cgnsNbNodes; // get nb nodes by element type, that can be less that elem->NbNodes()
349       cg_npe( cgType, &cgnsNbNodes );
350       do
351       {
352         for ( int i = 0; i < cgnsNbNodes; ++i )
353           elemData.push_back( cgnsID( elem->GetNode( interlace[i] ), n2cgID ));
354         if ( elem->GetID() != cgID )
355           elem2cgID.insert( elem2cgID.end(), make_pair( elem, cgID ));
356         ++cgID;
357         elem = elemIt->more() ? elemIt->next() : 0;
358       }
359       while ( elem && elem->GetEntityType() == elemType );
360     }
361     else if ( elemType == SMDSEntity_Polygon ) // POLYGONS
362       do
363       {
364         elemData.push_back( elem->NbNodes() );
365         for ( int i = 0, nb = elem->NbNodes(); i < nb; ++i )
366           elemData.push_back( cgnsID( elem->GetNode(i), n2cgID ));
367         if ( elem->GetID() != cgID )
368           elem2cgID.insert( elem2cgID.end(), make_pair( elem, cgID ));
369         ++cgID;
370         elem = elemIt->more() ? elemIt->next() : 0;
371       }
372       while ( elem && elem->GetEntityType() == elemType );
373
374     else if ( elemType == SMDSEntity_Quad_Polygon ) // QUADRATIC POLYGONS
375       do // write as linear NGON_n
376       {
377         elemData.push_back( elem->NbNodes() );
378         interlace = & SMDS_MeshCell::interlacedSmdsOrder( SMDSEntity_Quad_Polygon,
379                                                           elem->NbNodes() )[0];
380         for ( int i = 0, nb = elem->NbNodes(); i < nb; ++i )
381           elemData.push_back( cgnsID( elem->GetNode( interlace[i] ), n2cgID ));
382         if ( elem->GetID() != cgID )
383           elem2cgID.insert( elem2cgID.end(), make_pair( elem, cgID ));
384         ++cgID;
385         elem = elemIt->more() ? elemIt->next() : 0;
386       }
387       while ( elem && elem->GetEntityType() == elemType );
388
389     else if ( elemType == SMDSEntity_Polyhedra ||
390               elemType == SMDSEntity_Hexagonal_Prism) // POLYHEDRA
391     {
392       // to save polyhedrons after all
393       const SMDS_MeshInfo& meshInfo = myMesh->GetMeshInfo();
394       if ( meshInfo.NbPolyhedrons() == meshInfo.NbElements() - cgID + 1 )
395         break; // only polyhedrons remain
396       while ( elem && elem->GetEntityType() == elemType )
397         elem = elemIt->more() ? elemIt->next() : 0;
398       continue;
399     }
400
401     SMESH_Comment sectionName( cg_ElementTypeName( cgType ));
402     sectionName << " " << startID << " - " << cgID-1;
403
404     if ( cg_section_write(_fn, iBase, iZone, sectionName.c_str(), cgType, startID,
405                           cgID-1, /*nbndry=*/0, &elemData[0], &iSec) != CG_OK )
406       return addMessage( cg_get_error(), /*fatal = */true );
407   }
408   // Write polyhedral volumes
409   // -------------------------
410
411   if ( myMesh->GetMeshInfo().NbElements() > cgID-1 ) // polyhedra or hexagonal prisms remain
412   {
413     // the polyhedron (NFACE_n) is described as a set of signed face IDs,
414     // so first we are to write all polygones (NGON_n) bounding polyhedrons
415
416     vector< cgsize_t > faceData;
417     set< TPolyhedFace > faces;
418     set< TPolyhedFace >::iterator faceInSet;
419     vector<const SMDS_MeshNode *> faceNodesVec;
420     int nbPolygones = 0, faceID;
421
422     SMDS_VolumeTool vol;
423
424     elemData.clear();
425
426     int nbPolyhTreated = 0;
427
428     TElem2cgIDMap * elem2cgID = 0;
429     TElem2cgIDMap & n2cgID    = elem2cgIDByEntity[ SMDSEntity_Node ];
430
431     SMDS_ElemIteratorPtr elemIt = myMesh->elementsIterator();
432     while ( elemIt->more() )
433     {
434       elem = elemIt->next();
435       SMDSAbs_EntityType type = elem->GetEntityType();
436       if ( type == SMDSEntity_Polyhedra ||
437            type == SMDSEntity_Hexagonal_Prism )
438       {
439         ++nbPolyhTreated;
440         vol.Set( elem );
441         vol.SetExternalNormal();
442         const int nbFaces = vol.NbFaces();
443         elemData.push_back( nbFaces );
444         for ( int iF = 0; iF < nbFaces; ++iF )
445         {
446           const int nbNodes = vol.NbFaceNodes( iF );
447           const SMDS_MeshNode** faceNodes = vol.GetFaceNodes( iF );
448           faceNodesVec.assign( faceNodes, faceNodes + nbNodes );
449           if (( elem = myMesh->FindElement( faceNodesVec, SMDSAbs_Face, /*noMedium=*/false)))
450           {
451             // a face of the polyhedron is present in the mesh
452             faceID = cgnsID( elem, elem2cgIDByEntity[ elem->GetEntityType() ]);
453           }
454           else if ( vol.IsFreeFace( iF ))
455           {
456             // the face is not shared by volumes
457             faceID = cgID++;
458             ++nbPolygones;
459             faceData.push_back( nbNodes );
460             for ( int i = 0; i < nbNodes; ++i )
461               faceData.push_back( cgnsID( faceNodes[i], n2cgID ));
462           }
463           else
464           {
465             TPolyhedFace face( faceNodes, nbNodes, cgID );
466             faceInSet = faces.insert( faces.end(), face );
467             if ( faceInSet->_id == cgID ) // the face encounters for the 1st time
468             {
469               faceID = cgID++;
470               ++nbPolygones;
471               faceData.push_back( nbNodes );
472               for ( int i = 0; i < nbNodes; ++i )
473                 faceData.push_back( cgnsID( faceNodes[i], n2cgID ));
474             }
475             else
476             {
477               // the face encounters for the 2nd time; we hope it won't encounter once more,
478               // for that we can erase it from the set of faces
479               faceID = -faceInSet->_id;
480               faces.erase( faceInSet );
481             }
482           }
483           elemData.push_back( faceID );
484         }
485       }
486     }
487
488     if ( nbPolygones > 0 )
489     {
490       if ( cg_section_write(_fn, iBase, iZone, "Faces of Polyhedrons",
491                              CGNS_ENUMV( NGON_n ), cgID - nbPolygones, cgID-1,
492                              /*nbndry=*/0, &faceData[0], &iSec) != CG_OK )
493         return addMessage( cg_get_error(), /*fatal = */true );
494     }
495     
496     if ( cg_section_write(_fn, iBase, iZone, "Polyhedrons", 
497                              CGNS_ENUMV( NFACE_n ), cgID, cgID+nbPolyhTreated-1,
498                            /*nbndry=*/0, &elemData[0], &iSec) != CG_OK )
499       return addMessage( cg_get_error(), /*fatal = */true );
500
501     if ( !myMesh->GetGroups().empty() )
502     {
503       // store CGNS ids of polyhedrons
504       elem2cgID = &elem2cgIDByEntity[ SMDSEntity_Polyhedra ];
505       elemIt = myMesh->elementsIterator();
506       while ( elemIt->more() )
507       {
508         elem = elemIt->next();
509         if ( elem->GetEntityType() == SMDSEntity_Polyhedra )
510         {
511           if ( elem->GetID() != cgID )
512             elem2cgID->insert( elem2cgID->end(), make_pair( elem, cgID ));
513           ++cgID;
514         }
515       }
516     }
517   } // write polyhedral volumes
518
519
520   // Write groups as boundary conditions
521   // ------------------------------------
522
523   const set<SMESHDS_GroupBase*>& groups = myMesh->GetGroups();
524   set<SMESHDS_GroupBase*>::const_iterator grpIt = groups.begin();
525   set< string > groupNames; groupNames.insert(""); // to avoid duplicated and empty names
526   for ( ; grpIt != groups.end(); ++grpIt )
527   {
528     const SMESHDS_GroupBase* group = *grpIt;
529
530     // write BC location (default is Vertex)
531     CGNS_ENUMT( GridLocation_t ) location = CGNS_ENUMV( Vertex );
532     if ( group->GetType() != SMDSAbs_Node )
533     {
534       switch ( meshDim ) {
535       case 3:
536         switch ( group->GetType() ) {
537         case SMDSAbs_Volume: location = CGNS_ENUMV( FaceCenter ); break; // !!!
538         case SMDSAbs_Face:   location = CGNS_ENUMV( FaceCenter ); break; // OK
539         case SMDSAbs_Edge:   location = CGNS_ENUMV( EdgeCenter ); break; // OK
540         default:;
541         }
542         break;
543       case 2:
544         switch ( group->GetType() ) {
545         case SMDSAbs_Face: location = CGNS_ENUMV( FaceCenter ); break; // ???
546         case SMDSAbs_Edge: location = CGNS_ENUMV( EdgeCenter ); break; // OK
547         default:;
548         }
549         break;
550       case 1:
551         location = CGNS_ENUMV( EdgeCenter ); break; // ???
552         break;
553       }
554     }
555
556     // try to extract type of boundary condition from the group name
557     string name = group->GetStoreName();
558     CGNS_ENUMT( BCType_t ) bcType = getBCType( name );
559     while ( !groupNames.insert( name ).second )
560       name = (SMESH_Comment( "Group_") << groupNames.size());
561
562     // write IDs of elements
563     vector< cgsize_t > pnts;
564     pnts.reserve( group->Extent() );
565     SMDS_ElemIteratorPtr elemIt = group->GetElements();
566     while ( elemIt->more() )
567     {
568       const SMDS_MeshElement* elem = elemIt->next();
569       pnts.push_back( cgnsID( elem, elem2cgIDByEntity[ elem->GetEntityType() ]));
570     }
571     int iBC;
572     if ( cg_boco_write( _fn, iBase, iZone, name.c_str(), bcType,
573                         CGNS_ENUMV( PointList ), pnts.size(), &pnts[0], &iBC) != CG_OK )
574       return addMessage( cg_get_error(), /*fatal = */true);
575
576     // write BC location
577     if ( location != CGNS_ENUMV( Vertex ))
578     {
579       if ( cg_boco_gridlocation_write( _fn, iBase, iZone, iBC, location) != CG_OK )
580         return addMessage( cg_get_error(), /*fatal = */false);
581     }
582   }
583   return DRS_OK;
584 }
585
586 //================================================================================
587 /*!
588  * \brief Constructor
589  */
590 //================================================================================
591
592 DriverCGNS_Write::DriverCGNS_Write(): _fn(0)
593 {
594 }
595
596 //================================================================================
597 /*!
598  * \brief Close the cgns file at destruction
599  */
600 //================================================================================
601
602 DriverCGNS_Write::~DriverCGNS_Write()
603 {
604   if ( _fn > 0 )
605     cg_close( _fn );
606 }