]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MeshFormatWriter.cxx
Salome HOME
CS work : MeshGems reader/writer
[tools/medcoupling.git] / src / MEDLoader / MeshFormatWriter.cxx
1 // Copyright (C) 2021  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MeshFormatWriter.hxx"
21 #include "MEDFileMesh.hxx"
22 #include "MEDFileField.hxx"
23 #include "MEDFileData.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
25 #include "libmesh5.hxx"
26 #include "MEDMESHConverterUtilities.hxx"
27 #include <cstring>
28 #include <algorithm>
29 #include <map>
30 #include <cstdlib>
31 #include <fstream>
32
33
34 namespace MEDCoupling {
35   
36 MeshFormatWriter::MeshFormatWriter()
37 {}
38 MeshFormatWriter::MeshFormatWriter(const std::string& meshFileName,
39                                    const std::vector<std::string>& fieldFileNames):_meshFileName(meshFileName),
40                                    _fieldFileNames(fieldFileNames)
41 {}
42 MeshFormatWriter::~MeshFormatWriter()
43 {}
44 void MeshFormatWriter::setMeshFileName(const std::string& meshFileName)
45 {
46     _meshFileName = meshFileName;
47 }
48 void MeshFormatWriter::setFieldFileNames(const std::vector<std::string>& fieldFileNames)
49 {
50     _fieldFileNames = fieldFileNames;
51 }
52 void MeshFormatWriter::setMEDFileDS(MEDCoupling::MEDFileData* mfd)
53 {
54
55     if(!mfd)
56     {
57         addMessage( MeshFormat::Comment(" MEDFileData is nullptr! ") << _meshFileName, /*fatal=*/true );
58         return;
59     }
60     if ( !mfd->getNumberOfMeshes())
61     {
62         addMessage( MeshFormat::Comment("No Mesh in MEDFileData! ") << _meshFileName, /*fatal=*/true );
63         return;
64     }
65     if ( mfd->getNumberOfMeshes() > 1)
66     {
67         addMessage( MeshFormat::Comment("More than One Mesh in File! ") << _meshFileName, /*fatal=*/true );
68         return;
69     }
70
71     MEDCoupling::MEDFileMeshes* meshes  = mfd->getMeshes();
72     _mesh  = meshes->getMeshAtPos(0);
73
74     _mesh->incrRef();
75     MEDCoupling::MEDFileFields* fields = mfd->getFields();
76
77     for (int i = 0; i<fields->getNumberOfFields(); i++ )
78     {
79         MEDCoupling::MEDFileAnyTypeFieldMultiTS* field = fields->getFieldAtPos(i);
80         MEDCoupling::MEDFileFieldMultiTS * f = dynamic_cast<MEDCoupling::MEDFileFieldMultiTS *>(field);
81         _fields.push_back(f);
82     }
83
84
85 }
86
87 void MeshFormatWriter::write()
88 {
89
90     MeshFormat::Localizer loc;
91
92     MEDCoupling::MCAuto<MEDCoupling::MEDCouplingMesh > mesh = _mesh->getMeshAtLevel( 1 );
93     MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh = mesh->buildUnstructured();
94     _dim = umesh->getSpaceDimension();
95
96     if (_dim != 2 && _dim != 3)
97     {
98         addMessage( MeshFormat::Comment("Only 3D or 2D mesh allowed! ") << _meshFileName, /*fatal=*/true );
99         return ;
100     }
101
102
103     _version = sizeof(double) < 8 ? 1 : 2;
104     _writer = MeshFormat::MeshFormatParser();
105     _myCurrentOpenFile = _meshFileName;
106     _myCurrentFileId = _writer.GmfOpenMesh( _meshFileName.c_str(), GmfWrite, _version, _dim );
107     if ( !_myCurrentFileId )
108     {
109         if ( MeshFormat::isMeshExtensionCorrect( _meshFileName ))
110         {
111             addMessage( MeshFormat::Comment("Can't open for writing ") << _meshFileName, /*fatal=*/true );
112             return;
113         }
114
115         else
116         {
117             addMessage( MeshFormat::Comment("Not '.mesh' or '.meshb' extension of file ") << _meshFileName, /*fatal=*/true );
118             return;
119         }
120
121     }
122
123
124     perform();
125     _writer.GmfCloseMesh(_myCurrentFileId);
126     _myCurrentFileId = -1;
127     _myCurrentOpenFile = "";
128     if (_fields.size()) performFields();
129
130
131 }
132
133 MeshFormat::Status MeshFormatWriter::perform()
134 {
135
136
137     MEDCoupling::MCAuto< MEDCoupling::MEDCouplingMesh > mesh1;
138     MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh1;
139     MEDCoupling::MCAuto< MEDCoupling::MEDCouplingMesh > mesh2;
140     MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh2;
141     MEDCoupling::MCAuto< MEDCoupling::MEDCouplingMesh > mesh3;
142     MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3;
143
144     std::vector<int> dims = _mesh->getNonEmptyLevelsExt();
145     int dim = _mesh->getMeshDimension();
146     bool threeDElements = false;
147     bool twoDElements = false;
148     bool OneDElements = false;
149     if (dims.size() != 0)
150     {
151         bool maxLevelDimElments = ( std::find(dims.begin(), dims.end(), 0) != dims.end() );
152         bool nextToMaxLevelDimElments = ( std::find(dims.begin(), dims.end(), -1) != dims.end() );
153         bool nextToNextToMaxLevelDimElments = (std::find(dims.begin(), dims.end(), -2) != dims.end() );
154         threeDElements = (dim == 3) ? maxLevelDimElments : false ;
155         twoDElements =  (dim == 3) ? nextToMaxLevelDimElments : maxLevelDimElments ;
156         OneDElements = (dim == 3) ? nextToNextToMaxLevelDimElments : nextToMaxLevelDimElments;
157     }
158
159     MEDCoupling::mcIdType nbEdgesNSEG2 = 0;
160     MEDCoupling::mcIdType nbEdgesNSEG3 = 0;
161     MEDCoupling::mcIdType nbTRI3 = 0;
162     MEDCoupling::mcIdType nbTRI6 = 0;
163     MEDCoupling::mcIdType nbQUAD4 = 0;
164     MEDCoupling::mcIdType nbQUAD8 = 0;
165     MEDCoupling::mcIdType nbQUAD9 = 0;
166     MEDCoupling::mcIdType nbTETRA4 = 0;
167     MEDCoupling::mcIdType nbTETRA10 = 0;
168     MEDCoupling::mcIdType nbPYRA5 = 0;
169     MEDCoupling::mcIdType nbHEXA8 = 0;
170     MEDCoupling::mcIdType nbHEXA20 = 0;
171     MEDCoupling::mcIdType nbHEXA27 = 0;
172     MEDCoupling::mcIdType nbPENTA6 = 0;
173
174     if (OneDElements)
175     {
176         mesh1 = _mesh->getMeshAtLevel( 1-dim );
177         umesh1 = mesh1->buildUnstructured();
178         nbEdgesNSEG2 = umesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_SEG2);
179
180         nbEdgesNSEG3 = umesh1->getNumberOfCellsWithType(INTERP_KERNEL::NORM_SEG3);
181
182     }
183     if (twoDElements)
184     {
185         mesh2 = _mesh->getMeshAtLevel( 2-dim );
186         umesh2 = mesh2->buildUnstructured();
187         nbTRI3 = umesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TRI3);
188
189         nbTRI6 = umesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TRI6);
190
191         nbQUAD4 = umesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4);
192
193         nbQUAD8 = umesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD8);
194
195         nbQUAD9 = umesh2->getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD9);
196
197     }
198     if (threeDElements)
199     {
200
201         mesh3 = _mesh->getMeshAtLevel( 3-dim );
202         umesh3 = mesh3->buildUnstructured();
203         nbTETRA4 = umesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TETRA4);
204
205         nbTETRA10 = umesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TETRA10);
206
207         nbPYRA5 = umesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_PYRA5);
208
209         nbHEXA8 = umesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8);
210
211         nbHEXA20 = umesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA20);
212
213         nbHEXA27 = umesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA27);
214
215         nbPENTA6 = umesh3->getNumberOfCellsWithType(INTERP_KERNEL::NORM_PENTA6);
216
217     }
218
219
220
221     MEDCoupling::MCAuto< MEDCoupling::MEDCouplingMesh > mesh0 = _mesh->getMeshAtLevel(1);
222     MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh0 = mesh0->buildUnstructured();
223
224     // nodes
225     getNodes(umesh0);
226
227     // edges SEG2
228     if ( nbEdgesNSEG2 > 0)
229     {
230         getNSEG2( nbEdgesNSEG2, umesh1);
231     }
232     //~// nodes of quadratic edges SEG3
233     if ( nbEdgesNSEG3 > 0)
234     {
235         getNSEG3( nbEdgesNSEG3, umesh1);
236     }
237
238     // triangles TRI3
239     if ( nbTRI3 > 0)
240     {
241         getTRI3( nbTRI3, umesh2);
242     }
243
244     // nodes of quadratic triangles
245     // triangles TRI6
246     if ( nbTRI6 > 0)
247     {
248         getTRI6( nbTRI6, umesh2);
249
250     }
251     //~// quadrangles QUAD4
252     if ( nbQUAD4 > 0)
253     {
254         getQUAD4(nbQUAD4, umesh2);
255     }
256
257     //~// quadrangles quadratic QUAD8
258     if ( nbQUAD8 > 0)
259     {
260         getQUAD8( nbQUAD8, umesh2);
261     }
262
263     //~// quadrangles quadratic QUAD9
264     if ( nbQUAD9 > 0)
265     {
266         getQUAD9( nbQUAD9, umesh2);
267     }
268
269     // terahedra TETRA4
270     if ( nbTETRA4 > 0)
271     {
272         getTETRA4( nbTETRA4, umesh3);
273     }
274     //~terahedra TETRA10
275     if ( nbTETRA10 > 0)
276     {
277         getTETRA10( nbTETRA10, umesh3);
278     }
279
280     //~// pyramids 5
281     if ( nbPYRA5 > 0)
282     {
283         getPYRA5(nbPYRA5, umesh3);
284     }
285     //~// hexahedra 8
286     if ( nbHEXA8 > 0)
287     {
288         getHEXA8( nbHEXA8, umesh3);
289     }
290
291     //~// hexahedra 20
292     if ( nbHEXA20 > 0)
293     {
294         getHEXA20( nbHEXA20, umesh3);
295     }
296
297     //~// hexahedra 27
298     if ( nbHEXA27 > 0)
299     {
300         getHEXA27 (nbHEXA27, umesh3);
301     }
302
303     // prism
304     if ( nbPENTA6 > 0)
305     {
306         getPENTA6(nbPENTA6, umesh3);
307     }
308
309     linkFamilyToCells();
310     writeCells();
311
312
313     return MeshFormat::DRS_OK;
314 }
315
316
317 MeshFormat::Status MeshFormatWriter::performFields()
318 {
319
320     MeshFormat::Status status = MeshFormat::Status::DRS_OK;
321
322     if (_fields.size() != _fieldFileNames.size() )
323     {
324         addMessage( MeshFormat::Comment(" Number of fields and number of input *.sol files must be equal ") << _meshFileName, /*fatal=*/true );
325         status = MeshFormat::Status::DRS_FAIL;
326         return status;
327     }
328
329
330     int  dim = _mesh->getMeshDimension();  // dim mesh  field lying to
331     std::vector<std::string>::const_iterator fieldFileIt = _fieldFileNames.begin();
332     int iField = 0;
333     std::vector<int> levs {0} ;
334     for (; fieldFileIt !=_fieldFileNames.end();  ++fieldFileIt)
335     {
336         // Open files
337         _myCurrentOpenFile = *fieldFileIt;
338
339         MEDCoupling::MEDFileFieldMultiTS* f = _fields[iField];
340
341         if(!f)
342             continue;// why???
343         if ( f->getMeshName() == _mesh->getName() )
344         {
345
346             std::vector< std::vector<MEDCoupling::TypeOfField> > fTypes = f->getTypesOfFieldAvailable();
347             std::vector< std::pair<int,int> >  iters = f->getIterations();
348             const std::vector<std::string>& compInfo = f->getInfo();
349             std::pair<int,int> it = iters[0];
350
351             //~// Open File for writing
352             _myCurrentFileId = _writer.GmfOpenMesh( fieldFileIt->c_str(), GmfWrite, _version, _dim );
353
354             if ( fTypes[0].size() == 1 && fTypes[0][0] == MEDCoupling::ON_NODES )
355             {
356                 setFieldOnNodes(f, it.first,  it.second, compInfo.size());
357             }
358             else
359             {
360                 setFieldOnCells( f, it.first,  it.second, levs );
361             }
362             //~// Close File
363             _writer.GmfCloseMesh( _myCurrentFileId );
364         }
365
366
367         iField++;
368     }
369
370     return status;
371 }
372
373 MeshFormat::Status MeshFormatWriter::setFieldOnNodes(MEDCoupling::MEDFileFieldMultiTS * f, int iteration, int order, size_t compSize)
374 {
375
376
377     std::vector<INTERP_KERNEL::NormalizedCellType> types;
378     std::vector< std::vector<MEDCoupling::TypeOfField> > typesF;
379     std::vector< std::vector<std::string> > pfls, locs;
380     std::vector< std::vector< std::pair<mcIdType,mcIdType> > > valsVec;
381     valsVec = f->getFieldSplitedByType( iteration, order, _mesh->getName().c_str(),
382                                         types, typesF, pfls, locs);
383     // believe that there can be only one type in a nodal field,
384     // so do not perform a loop on types
385     const MEDCoupling::DataArrayDouble* valsArray = f->getUndergroundDataArray(iteration, order);
386     int typTab[] = { getGmfSolKwd((int)compSize, _dim) };
387     _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfSolAtVertices, (int)valsVec[0][0].second, 1, typTab);
388     double* valTab0 = new double[compSize];
389     double* valTab;
390     for ( size_t i = valsVec[0][0].first; i < (std::size_t)valsVec[0][0].second; ++i )
391     {
392
393         for ( size_t j = 0; j < compSize; ++j )
394             valTab0[j] = valsArray->getIJ( i, j );
395             
396     if (compSize == 9 || compSize == 4){ // full matrix ==>uper triangular matrix
397       extractSymetricTensor(valTab0, valTab);
398       _writer.GmfSetLin( _myCurrentFileId, MeshFormat::GmfSolAtVertices, valTab);
399       delete [] valTab;
400       
401     }
402     else  
403         _writer.GmfSetLin( _myCurrentFileId, MeshFormat::GmfSolAtVertices, valTab0);
404
405     }
406     delete [] valTab0;
407
408
409
410 }
411
412 MeshFormat::Status MeshFormatWriter::setFieldOnCells(MEDCoupling::MEDFileFieldMultiTS * f, int iteration, int order, std::vector<int> levs )
413 {
414
415     int  dim = _mesh->getMeshDimension();  // dim mesh  field lying to
416     int absDim = f->getNonEmptyLevels(iteration, order,  f->getMeshName(), levs);
417
418     MEDCoupling::MEDCouplingFieldDouble**  cellToNodeFldb  = new MEDCoupling::MEDCouplingFieldDouble* [(int)levs.size()] ;
419     MEDCoupling::MEDCouplingFieldDouble**  fldb  = new MEDCoupling::MEDCouplingFieldDouble* [(int)levs.size()] ;
420
421     for (size_t k = 0; k<levs.size(); k++) fldb[k] = f->field( iteration, order,_mesh );
422
423     // turn it node discretization
424     for (size_t l = 0; l < levs.size(); l++) cellToNodeFldb[l] = fldb[l]->cellToNodeDiscretization() ;
425
426     for(size_t j =0; j < levs.size(); j++ )
427     {
428
429         const mcIdType pointsNumber = cellToNodeFldb[j]->getNumberOfTuples();
430         const mcIdType nbComp = (int) cellToNodeFldb[j]->getNumberOfComponents() ;
431
432         MEDCoupling::DataArrayDouble* timeStamp = cellToNodeFldb[j]->getArray();
433         double* values = timeStamp->getPointer();
434
435         int typ = getGmfSolKwd((int)nbComp, _dim) ;
436         if(typ == -1)
437         {
438             addMessage( MeshFormat::Comment(" error with Number of Component   ") << nbComp, /*fatal=*/true );
439             return MeshFormat::Status::DRS_FAIL;
440         }
441
442         int typTab[] = {typ};
443         _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfSolAtVertices, pointsNumber, 1, typTab);
444
445
446         double *valTab;
447         for (int i = 0; i < pointsNumber ; i++ )
448         {
449
450             double valTab0[10]; //max 3x3 matrix +1 for safety ;)
451
452             std::copy(values, values+nbComp, valTab0);
453
454             if (nbComp == 9 || nbComp == 4) // full matrix ==>uper triangular matrix
455             {
456         extractSymetricTensor(valTab0, valTab);
457                 _writer.GmfSetLin( _myCurrentFileId, MeshFormat::GmfSolAtVertices, valTab);
458                 delete [] valTab;
459             }
460             else //sym mat, scalar or vec
461             {
462                 valTab = new double[nbComp];
463                 std::copy(valTab0, valTab0+nbComp, valTab);
464                 _writer.GmfSetLin( _myCurrentFileId, MeshFormat::GmfSolAtVertices, valTab);
465                 delete [] valTab;
466             }
467             values+=nbComp;
468
469         }
470
471
472     }
473
474     for(size_t i = 0; i < levs.size(); i++ )  fldb[i]->decrRef();
475     for(size_t i = 0; i < levs.size(); i++ )  cellToNodeFldb[i]->decrRef();
476     delete [] cellToNodeFldb;
477     delete [] fldb;
478
479 }
480  /*\
481  |*| extract the upper triangular matrix  of fullTensor
482  |*| if _dim == 2 fill symTensor with values at index 0, 1 & 3 of fullTensor
483  |*| |x0 x1|   
484  |*| |x2 x3|  
485  |*| if _dim == 3 fill symTensor with values at index 0, 1, 2, 4, 5 & 8 of fullTensor
486  |*| |x0 x1 x2|
487  |*| |x3 x4 x5|
488  |*| |x6 x7 x8|
489  \*/
490 void MeshFormatWriter::extractSymetricTensor(double fullTensor[], double*& symTensor)
491 {
492      symTensor = new double[_dim*(_dim+1)/2];
493   for (int ii =0; ii<_dim; ii++)
494     for (int jj =ii; jj<_dim; jj++)
495     {
496       int kk = _dim*(_dim-1)/2- (_dim-ii)*(_dim-ii-1)/2+jj;
497       symTensor[kk] = fullTensor[ii+jj*_dim];
498     }  
499 }
500 int MeshFormatWriter::getGmfSolKwd(const int nbComp, const int dim)
501 {
502     if (nbComp== 1) return GmfSca;
503     else if( dim == nbComp) return GmfVec;
504     else if (dim*(dim+1)/2 == nbComp || dim*dim == nbComp ) return GmfSymMat;
505     //~else if (dim*dim == nbComp) return GmfMat; // Not valid in mg-adapt if not sym
506     else  return -1;
507 }
508 bool MeshFormatWriter::checkFileName()
509 {
510     bool ret = true;
511     return ret;
512 }
513 bool MeshFormatWriter::checkFieldFileName()
514 {
515     bool ret = true;
516     return ret;
517
518 }
519
520 std::string MeshFormatWriter::getMeshFileName() const
521 {
522     return _meshFileName;
523 }
524
525
526 std::vector<std::string> MeshFormatWriter::getFieldFileNames() const
527 {
528     return _fieldFileNames;
529 }
530
531 MeshFormat::Status MeshFormatWriter::addMessage(const std::string& msg,
532         const bool         isFatal/*=false*/)
533 {
534     if ( isFatal )
535         _myErrorMessages.clear(); // warnings are useless if a fatal error encounters
536
537     _myErrorMessages.push_back( msg );
538
539     //~MESSAGE(msg);
540 #ifdef _DEBUG_
541     std::cout << msg << std::endl;
542 #endif
543     return ( _myStatus = isFatal ? MeshFormat::DRS_FAIL : MeshFormat::DRS_WARN_SKIP_ELEM );
544 }
545
546
547 void MeshFormatWriter::forward_shift(std::vector<MEDCoupling::mcIdType> &conn)
548 {
549     std::vector<MEDCoupling::mcIdType>::iterator it = conn.begin();
550     for (; it != conn.end(); ++it) *it = *it+1;
551 }
552
553
554 void MeshFormatWriter::getNodes(MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh0)
555 {
556     MEDCoupling::mcIdType nbNodes = 0;
557     nbNodes = umesh0->getNumberOfNodes();
558
559
560     // nodes
561     MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> coordArray = umesh0->getCoordinatesAndOwner();
562     double* coordPrt = coordArray->getPointer();
563     _writer.GmfSetKwd( _myCurrentFileId, MeshFormat::GmfVertices, nbNodes );
564     double xyz[3];
565     int j = (int)nbNodes;
566
567     int idNode = 0;
568
569     while ( j >0 )
570     {
571
572         std::copy(coordPrt, coordPrt+_dim, xyz);
573
574         MeshFormatNode e(xyz[0], xyz[1], xyz[2], idNode);
575         _idNodeToNode.insert(std::pair <int, MeshFormatNode> (idNode, e));
576
577         coordPrt+= _dim;
578         j--;
579         idNode++;
580     }
581     linkFamilyToNodes();
582     std::map <int, MeshFormatNode>::iterator itNode = _idNodeToNode.begin();
583     for (; itNode!= _idNodeToNode.end(); ++itNode)
584         _dim == 3?  _writer.GmfSetLin( _myCurrentFileId, MeshFormat::GmfVertices, itNode->second.xyz[0],
585                      itNode->second.xyz[1], itNode->second.xyz[2], std::abs(itNode->second._famId) ) :
586                       _writer.GmfSetLin( _myCurrentFileId, MeshFormat::GmfVertices, itNode->second.xyz[0],
587                      itNode->second.xyz[1], std::abs(itNode->second._famId) );
588 }
589
590
591 void MeshFormatWriter::getNSEG2(MEDCoupling::mcIdType nbEdgesNSEG2, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh1)
592 {
593
594     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh1->giveCellsWithType(INTERP_KERNEL::NORM_SEG2);
595     std::map<int, MeshFormatCell> idCellToCell;
596     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
597     {
598         std::vector<MEDCoupling::mcIdType> conn;
599         umesh1->getNodeIdsOfCell(*it,  conn) ;
600         forward_shift(conn);
601
602         MeshFormatCell e(INTERP_KERNEL::NORM_SEG2, (int)*it);
603         e.setConn(conn);
604         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
605     }
606     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_SEG2, idCellToCell) );
607 }
608
609
610 void MeshFormatWriter::getNSEG3( MEDCoupling::mcIdType nbEdgesNSEG3, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh1)
611 {
612
613
614     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh1->giveCellsWithType(INTERP_KERNEL::NORM_SEG3);
615     std::map<int, MeshFormatCell> idCellToCell;
616     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
617     {
618
619         std::vector<MEDCoupling::mcIdType> conn;
620         umesh1->getNodeIdsOfCell(*it,  conn) ;
621         forward_shift(conn);
622         MeshFormatCell e(INTERP_KERNEL::NORM_SEG3, (int)*it);
623         e.setConn(conn);
624         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
625     }
626     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_SEG3, idCellToCell) );
627 }
628
629
630 void MeshFormatWriter::getTRI3( MEDCoupling::mcIdType nbTRI3, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh2)
631 {
632
633     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh2->giveCellsWithType(INTERP_KERNEL::NORM_TRI3);
634     std::map<int, MeshFormatCell> idCellToCell;
635     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
636     {
637         std::vector<MEDCoupling::mcIdType> conn;
638         umesh2->getNodeIdsOfCell(*it,  conn) ;
639         forward_shift(conn);
640         MeshFormatCell e(INTERP_KERNEL::NORM_TRI3, (int)*it);
641         e.setConn(conn);
642         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
643     }
644     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_TRI3, idCellToCell) );
645 }
646
647
648 void MeshFormatWriter::getTRI6( MEDCoupling::mcIdType nbTRI6, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh2)
649 {
650
651     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh2->giveCellsWithType(INTERP_KERNEL::NORM_TRI6);
652     std::map<int, MeshFormatCell> idCellToCell;
653     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
654     {
655         std::vector<MEDCoupling::mcIdType> conn;
656         umesh2->getNodeIdsOfCell(*it,  conn) ;
657         forward_shift(conn);
658         MeshFormatCell e(INTERP_KERNEL::NORM_TRI6, (int)*it);
659         e.setConn(conn);
660         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
661     }
662
663     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_TRI6, idCellToCell) );
664 }
665
666 void MeshFormatWriter::getQUAD4( MEDCoupling::mcIdType nbQUAD4, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh2)
667 {
668
669     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh2->giveCellsWithType(INTERP_KERNEL::NORM_QUAD4);
670     std::map<int, MeshFormatCell> idCellToCell;
671     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
672     {
673         std::vector<MEDCoupling::mcIdType> conn;
674         umesh2->getNodeIdsOfCell(*it,  conn) ;
675         forward_shift(conn);
676         MeshFormatCell e(INTERP_KERNEL::NORM_QUAD4, (int)*it);
677         e.setConn(conn);
678         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
679     }
680     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_QUAD4, idCellToCell) );
681 }
682
683 void MeshFormatWriter::getQUAD8(MEDCoupling::mcIdType nbQUAD8, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh2)
684 {
685
686     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh2->giveCellsWithType(INTERP_KERNEL::NORM_QUAD8);
687     std::map<int, MeshFormatCell> idCellToCell;
688     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
689     {
690         std::vector<MEDCoupling::mcIdType> conn;
691         umesh2->getNodeIdsOfCell(*it,  conn) ;
692         forward_shift(conn);
693         MeshFormatCell e(INTERP_KERNEL::NORM_QUAD8, (int)*it);
694         e.setConn(conn);
695         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
696     }
697     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_QUAD8, idCellToCell) );
698 }
699
700 void MeshFormatWriter::getQUAD9(MEDCoupling::mcIdType nbQUAD9, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh2)
701 {
702
703     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh2->giveCellsWithType(INTERP_KERNEL::NORM_QUAD9);
704     std::map<int, MeshFormatCell> idCellToCell;
705     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
706     {
707         std::vector<MEDCoupling::mcIdType> conn;
708         umesh2->getNodeIdsOfCell(*it,  conn) ;
709         forward_shift(conn);
710         MeshFormatCell e(INTERP_KERNEL::NORM_QUAD9, (int)*it);
711         e.setConn(conn);
712         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
713     }
714
715     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_QUAD9, idCellToCell) );
716 }
717
718 void MeshFormatWriter::getTETRA4(MEDCoupling::mcIdType nbTETRA4, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3)
719 {
720
721     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh3->giveCellsWithType(INTERP_KERNEL::NORM_TETRA4);
722     std::map<int, MeshFormatCell> idCellToCell;
723     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
724     {
725         std::vector<MEDCoupling::mcIdType> conn;
726         umesh3->getNodeIdsOfCell(*it,  conn) ;
727         forward_shift(conn);
728         MeshFormatCell e(INTERP_KERNEL::NORM_TETRA4, (int)*it);
729         e.setConn(conn);
730         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
731     }
732
733     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_TETRA4, idCellToCell) );
734 }
735
736 void MeshFormatWriter::getTETRA10(MEDCoupling::mcIdType nbTETRA10, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3)
737 {
738
739     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh3->giveCellsWithType(INTERP_KERNEL::NORM_TETRA10);
740     std::map<int, MeshFormatCell> idCellToCell;
741     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
742     {
743         std::vector<MEDCoupling::mcIdType> conn;
744         umesh3->getNodeIdsOfCell(*it,  conn) ;
745         forward_shift(conn);
746         MeshFormatCell e(INTERP_KERNEL::NORM_TETRA10, (int)*it);
747         e.setConn(conn);
748         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
749     }
750     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_TETRA10, idCellToCell) );
751 }
752
753 void MeshFormatWriter::getPYRA5(MEDCoupling::mcIdType nbPYRA5, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3)
754 {
755
756     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh3->giveCellsWithType(INTERP_KERNEL::NORM_PYRA5);
757     std::map<int, MeshFormatCell> idCellToCell;
758     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
759     {
760         std::vector<MEDCoupling::mcIdType> conn;
761         umesh3->getNodeIdsOfCell(*it,  conn) ;
762         forward_shift(conn);
763         MeshFormatCell e(INTERP_KERNEL::NORM_PYRA5, (int)*it);
764         e.setConn(conn);
765         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
766     }
767     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_PYRA5, idCellToCell) );
768 }
769
770 void MeshFormatWriter::getHEXA8(MEDCoupling::mcIdType nbHEXA8, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3)
771 {
772
773     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh3->giveCellsWithType(INTERP_KERNEL::NORM_HEXA8);
774     std::map<int, MeshFormatCell> idCellToCell;
775     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
776     {
777         std::vector<MEDCoupling::mcIdType> conn;
778         umesh3->getNodeIdsOfCell(*it,  conn) ;
779         forward_shift(conn);
780         MeshFormatCell e(INTERP_KERNEL::NORM_HEXA8, (int)*it);
781         e.setConn(conn);
782         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
783     }
784     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_HEXA8, idCellToCell) );
785 }
786 void MeshFormatWriter::getHEXA20(MEDCoupling::mcIdType nbHEXA20, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3)
787 {
788
789     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh3->giveCellsWithType(INTERP_KERNEL::NORM_HEXA20);
790     std::map<int, MeshFormatCell> idCellToCell;
791     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
792     {
793         std::vector<MEDCoupling::mcIdType> conn;
794         umesh3->getNodeIdsOfCell(*it,  conn) ;
795         forward_shift(conn);
796         MeshFormatCell e(INTERP_KERNEL::NORM_HEXA20, (int)*it);
797         e.setConn(conn);
798         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
799     }
800     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_HEXA20, idCellToCell) );
801 }
802 void MeshFormatWriter::getHEXA27(MEDCoupling::mcIdType nbHEXA27, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3)
803 {
804
805     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh3->giveCellsWithType(INTERP_KERNEL::NORM_HEXA27);
806     std::map<int, MeshFormatCell> idCellToCell;
807     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
808     {
809         std::vector<MEDCoupling::mcIdType> conn;
810         umesh3->getNodeIdsOfCell(*it,  conn) ;
811         forward_shift(conn);
812         MeshFormatCell e(INTERP_KERNEL::NORM_HEXA27, (int)*it);
813         e.setConn(conn);
814         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
815     }
816     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_HEXA27, idCellToCell) );
817 }
818
819 void MeshFormatWriter::getPENTA6(MEDCoupling::mcIdType nbPENTA6, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3)
820 {
821
822     MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elementId = umesh3->giveCellsWithType(INTERP_KERNEL::NORM_PENTA6);
823     std::map<int, MeshFormatCell> idCellToCell;
824     for ( const mcIdType *it=elementId->begin(); it!=elementId->end(); it++ )
825     {
826         std::vector<MEDCoupling::mcIdType> conn;
827         umesh3->getNodeIdsOfCell(*it,  conn) ;
828         forward_shift(conn);
829         MeshFormatCell e(INTERP_KERNEL::NORM_PENTA6, (int)*it);
830         e.setConn(conn);
831         idCellToCell.insert(std::pair <int, MeshFormatCell> (*it, e));
832     }
833     _typeToIdCellToCell.insert(std::pair <INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >(INTERP_KERNEL::NORM_PENTA6, idCellToCell) );
834 }
835
836
837 void MeshFormatWriter::linkFamilyToNodes()
838 {
839
840     std::map<std::string,mcIdType> famInfos =  _mesh->getFamilyInfo();
841     std::map<std::string,mcIdType>::const_iterator famIt =  famInfos.begin();
842     for (; famIt != famInfos.end(); ++famIt)
843     {
844         if(!famIt->second) continue; //FAMILLE_ZERO
845         MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> nodeIds =  _mesh->getNodeFamilyArr(famIt->first);
846         const MEDCoupling::mcIdType * nodeIdsIt = nodeIds->begin(), * famIDEnd = nodeIds->end();
847         for(; nodeIdsIt< famIDEnd; ++nodeIdsIt) {
848
849             std::map <int, MeshFormatNode>::iterator itNode = _idNodeToNode.find((int)*nodeIdsIt);
850             if (itNode == _idNodeToNode.end()) continue;
851             else itNode->second._famId =(int) famIt->second;
852
853
854         }
855     }
856 }
857
858
859
860 void MeshFormatWriter::linkFamilyToCells()
861 {
862
863     std::vector<int> levs =  _mesh->getNonEmptyLevels();
864     for (size_t iDim = 0; iDim < levs.size(); iDim++ )
865     {
866         int meshDimRelToMax = levs[iDim];
867         MEDCoupling::MCAuto< MEDCoupling::MEDCouplingMesh > mesh = _mesh->getMeshAtLevel( meshDimRelToMax);
868         MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh0 = mesh->buildUnstructured();
869         const MEDCoupling::DataArrayIdType * famIds = _mesh->getFamilyFieldAtLevel(meshDimRelToMax);
870         const MEDCoupling::mcIdType * famID = famIds->begin(), *famIDEnd = famIds->end();
871         for (; famID < famIDEnd; ++famID)
872         {
873             if (!(*famID)) continue; // "FAMILLE_ZERO"
874             std::string famName = _mesh->getFamilyNameGivenId(*famID);
875             MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> cellIds =  _mesh->getFamilyArr( meshDimRelToMax, famName);
876             const MEDCoupling::mcIdType * cellIdsIt = cellIds->begin(), *cellIDEnd = cellIds->end();
877             for(; cellIdsIt< cellIDEnd; ++cellIdsIt)
878             {
879                 INTERP_KERNEL::NormalizedCellType type = umesh0->getTypeOfCell(*cellIdsIt); //TODO
880                 std::map<INTERP_KERNEL::NormalizedCellType, std::map <int, MeshFormatCell> >::iterator itCellMap = _typeToIdCellToCell.find(type);
881                 if (itCellMap == _typeToIdCellToCell.end()) continue;
882                 else
883                 {
884                     std::map <int, MeshFormatCell>::iterator itCell = itCellMap->second.find((int)*cellIdsIt);
885                     if (itCell == itCellMap->second.end()) continue;
886                     else itCell->second._famId = (int)*famID;
887                 }
888
889             }
890
891
892
893         }
894     }
895 }
896 void MeshFormatWriter::writeCells()
897 {
898
899     std::map < INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> >::iterator typeCellMapIt = _typeToIdCellToCell.begin();
900     for (; typeCellMapIt!= _typeToIdCellToCell.end(); ++typeCellMapIt)
901     {
902         std::map<int, MeshFormatCell>::iterator cellMapIt = typeCellMapIt->second.begin();
903         switch (typeCellMapIt->first)
904         {
905         case INTERP_KERNEL::NORM_SEG2 :
906         {
907
908             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfEdges, (int)typeCellMapIt->second.size());
909
910             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
911             {
912                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
913                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfEdges, conn[0], conn[1], std::abs(cellMapIt->second._famId) );
914             }
915             break;
916         }
917         case INTERP_KERNEL::NORM_SEG3 :
918         {
919
920             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfEdges, (int)typeCellMapIt->second.size());
921             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
922             {
923                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
924                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfEdges, conn[0], conn[1], std::abs(cellMapIt->second._famId) );
925             }
926             cellMapIt = typeCellMapIt->second.begin();
927
928             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtEdges, (int)typeCellMapIt->second.size());
929
930             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
931             {
932                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
933                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtEdges, cellMapIt->first+1, 1, conn[2] );
934             }
935             break;
936         }
937         case INTERP_KERNEL::NORM_TRI3 :
938         {
939
940             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfTriangles, (int)typeCellMapIt->second.size());
941
942             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
943             {
944                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
945                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfTriangles, conn[0], conn[1], conn[2], std::abs(cellMapIt->second._famId) );
946             }
947             break;
948         }
949         case INTERP_KERNEL::NORM_TRI6 :
950         {
951
952             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfTriangles, (int)typeCellMapIt->second.size());
953             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
954             {
955                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
956                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfTriangles, conn[0], conn[1], conn[2], std::abs(cellMapIt->second._famId) );
957             }
958
959             cellMapIt = typeCellMapIt->second.begin();
960             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtTriangles, (int)typeCellMapIt->second.size());
961
962             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
963             {
964                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
965                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtTriangles, cellMapIt->first+1, 3, conn[3], conn[4], conn[5] );
966             }
967             break;
968         }
969         case INTERP_KERNEL::NORM_QUAD4 :
970         {
971
972             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfQuadrilaterals, (int)typeCellMapIt->second.size());
973
974             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
975             {
976                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
977                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfQuadrilaterals, conn[0], conn[1], conn[2], conn[3], std::abs(cellMapIt->second._famId) );
978             }
979             break;
980         }
981         case INTERP_KERNEL::NORM_QUAD8 :
982         {
983
984             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfQuadrilaterals, (int)typeCellMapIt->second.size());
985             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
986             {
987                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
988                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfQuadrilaterals, conn[0], conn[1], conn[2], conn[3], std::abs(cellMapIt->second._famId) );
989             }
990             cellMapIt = typeCellMapIt->second.begin();
991             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtQuadrilaterals, (int)typeCellMapIt->second.size());
992
993             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
994             {
995                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
996                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtQuadrilaterals, cellMapIt->first+1, 4, conn[4], conn[5],
997                                   conn[6], conn[7] );
998             }
999             break;
1000         }
1001         case INTERP_KERNEL::NORM_QUAD9 :
1002         {
1003
1004             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfQuadrilaterals, (int)typeCellMapIt->second.size());
1005             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
1006             {
1007                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
1008                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfQuadrilaterals, conn[0], conn[1], conn[2], conn[3], std::abs(cellMapIt->second._famId) );
1009             }
1010             cellMapIt = typeCellMapIt->second.begin();
1011             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtQuadrilaterals, (int)typeCellMapIt->second.size());
1012
1013             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
1014             {
1015                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
1016                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtQuadrilaterals,cellMapIt->first+1, 5, conn[4], conn[5],
1017                                   conn[6], conn[7], conn[8] );
1018             }
1019             break;
1020         }
1021         case INTERP_KERNEL::NORM_TETRA4 :
1022         {
1023
1024             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfTetrahedra, (int)typeCellMapIt->second.size());
1025
1026             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
1027             {
1028                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
1029                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfTetrahedra, conn[0], conn[2], conn[1], conn[3],  std::abs(cellMapIt->second._famId) );
1030             }
1031             break;
1032         }
1033         case INTERP_KERNEL::NORM_TETRA10 :
1034         {
1035
1036             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtTetrahedra, (int)typeCellMapIt->second.size());
1037             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
1038             {
1039                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
1040                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfTetrahedra, conn[0], conn[2], conn[1], conn[3], std::abs(cellMapIt->second._famId) );
1041             }
1042             cellMapIt = typeCellMapIt->second.begin();
1043             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfTetrahedra, (int)typeCellMapIt->second.size());
1044
1045             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
1046             {
1047                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
1048                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtTetrahedra, cellMapIt->first+1, 6, conn[6], conn[5],
1049                                   conn[4], conn[7], conn[8], conn[9] );
1050             }
1051             break;
1052         }
1053         case INTERP_KERNEL::NORM_PYRA5 :
1054         {
1055
1056             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfPyramids, (int)typeCellMapIt->second.size());
1057
1058             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
1059             {
1060                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
1061                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfPyramids, conn[3], conn[2], conn[1], conn[0], conn[4], std::abs(cellMapIt->second._famId) );
1062
1063             }
1064             break;
1065         }
1066         case INTERP_KERNEL::NORM_HEXA8 :
1067         {
1068
1069             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfHexahedra, (int)typeCellMapIt->second.size());
1070
1071             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
1072             {
1073                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
1074                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfHexahedra, conn[0], conn[3], conn[2], conn[1], conn[4], conn[7], conn[6], conn[5], std::abs(cellMapIt->second._famId) );
1075
1076             }
1077             break;
1078         }
1079         case INTERP_KERNEL::NORM_HEXA20 :
1080         {
1081
1082             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfHexahedra, (int)typeCellMapIt->second.size());
1083             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
1084             {
1085                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
1086                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfHexahedra, conn[0], conn[3], conn[2], conn[1],
1087                                   conn[4], conn[7], conn[6], conn[5], std::abs(cellMapIt->second._famId) );
1088             }
1089             cellMapIt = typeCellMapIt->second.begin();
1090             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtHexahedra, (int)typeCellMapIt->second.size());
1091
1092             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
1093             {
1094                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
1095                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtHexahedra,  cellMapIt->first+1, 12, conn[11], conn[10], conn[9],
1096                                   conn[8], conn[15], conn[14], conn[13], conn[12], conn[16], conn[19], conn[18], conn[17] );
1097             }
1098             break;
1099         }
1100         case INTERP_KERNEL::NORM_HEXA27 :
1101         {
1102
1103             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfHexahedra, (int)typeCellMapIt->second.size());
1104             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
1105             {
1106                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
1107                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtHexahedra, conn[0], conn[3], conn[2], conn[1],
1108                                   conn[4], conn[7], conn[6], conn[5], std::abs(cellMapIt->second._famId) );
1109             }
1110             cellMapIt = typeCellMapIt->second.begin();
1111             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtHexahedra, (int)typeCellMapIt->second.size());
1112
1113             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
1114             {
1115                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
1116                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtHexahedra, cellMapIt->first+1, 19, conn[11], conn[10], conn[9],
1117                                   conn[8], conn[15], conn[14], conn[13], conn[12], conn[16], conn[19], conn[18], conn[17],
1118                                   conn[20], conn[24], conn[23], conn[22], conn[21], conn[25], conn[26], std::abs(cellMapIt->second._famId) );
1119             }
1120             break;
1121         }
1122         case INTERP_KERNEL::NORM_PENTA6 :
1123         {
1124
1125             _writer.GmfSetKwd(_myCurrentFileId, MeshFormat::GmfPrisms, (int)typeCellMapIt->second.size());
1126
1127             for (; cellMapIt != typeCellMapIt->second.end(); ++cellMapIt)
1128             {
1129                 std::vector<MEDCoupling::mcIdType> conn = cellMapIt->second.conn;
1130                 _writer.GmfSetLin(_myCurrentFileId, MeshFormat::GmfPrisms, conn[0], conn[2], conn[1], conn[3], conn[5], conn[4], std::abs(cellMapIt->second._famId) );
1131             }
1132             break;
1133         }
1134         }
1135     }
1136 }
1137 }