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