Salome HOME
Remove DataArrayInt::isIdentity-> DataArrayInt::isIdentity2 for everybody. Remove...
[tools/medcoupling.git] / src / MEDLoader / MEDFileFieldOverView.cxx
1 // Copyright (C) 2007-2015  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 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileFieldOverView.hxx"
22 #include "MEDFileField.hxx"
23 #include "MEDFileMesh.hxx"
24
25 #include "MEDCouplingFieldDiscretization.hxx"
26 #include "CellModel.hxx"
27
28 using namespace ParaMEDMEM;
29
30 const unsigned char MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE[MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE_LGTH]=
31 {1,3,21,5,9,7,22,34,23,28,255,255,255,255,10,14,13,255,12,255,24,255,16,27,255,26,255,29,255,255,25,42,36,4};
32
33 const unsigned char MEDMeshMultiLev::HEXA27_PERM_ARRAY[27]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,24,22,21,23,20,25,26};
34
35 const char MEDFileField1TSStructItem2::NEWLY_CREATED_PFL_NAME[]="???";
36
37 MEDFileMeshStruct *MEDFileMeshStruct::New(const MEDFileMesh *mesh)
38 {
39   return new MEDFileMeshStruct(mesh);
40 }
41
42 std::size_t MEDFileMeshStruct::getHeapMemorySizeWithoutChildren() const
43 {
44   std::size_t ret(0);
45   for(std::vector< std::vector<int> >::const_iterator it0=_geo_types_distrib.begin();it0!=_geo_types_distrib.end();it0++)
46     ret+=(*it0).capacity()*sizeof(int);
47   ret+=_geo_types_distrib.capacity()*sizeof(std::vector<int>);
48   return ret;
49 }
50
51 std::vector<const BigMemoryObject *> MEDFileMeshStruct::getDirectChildrenWithNull() const
52 {
53   return std::vector<const BigMemoryObject *>();
54 }
55
56 MEDFileMeshStruct::MEDFileMeshStruct(const MEDFileMesh *mesh):_mesh(mesh)
57 {
58   std::vector<int> levs(mesh->getNonEmptyLevels());
59   _name=mesh->getName();
60   _nb_nodes=mesh->getNumberOfNodes();
61   if(!levs.empty())
62     {
63       _geo_types_distrib.resize(-(*std::min_element(levs.begin(),levs.end()))+1);
64       for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
65         _geo_types_distrib[-(*lev)]=mesh->getDistributionOfTypes(*lev);
66     }
67 }
68
69 int MEDFileMeshStruct::getLevelOfGeoType(INTERP_KERNEL::NormalizedCellType t) const
70 {
71   int j=0;
72   for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++,j--)
73     {
74       std::size_t sz=(*it1).size();
75       if(sz%3!=0)
76         throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : internal error in code !");
77       std::size_t nbGeo=sz/3;
78       for(std::size_t i=0;i<nbGeo;i++)
79         if((*it1)[3*i]==(int)t)
80           return j;
81     }
82   throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : The specified geometric type is not present in the mesh structure !");
83 }
84
85 /*!
86  * \sa MEDFileMeshStruct::doesManageGeoType
87  */
88 int MEDFileMeshStruct::getNumberOfElemsOfGeoType(INTERP_KERNEL::NormalizedCellType t) const
89 {
90   for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++)
91     {
92       std::size_t sz=(*it1).size();
93       if(sz%3!=0)
94         throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfElemsOfGeoType : internal error in code !");
95       std::size_t nbGeo=sz/3;
96       for(std::size_t i=0;i<nbGeo;i++)
97         if((*it1)[3*i]==(int)t)
98           return (*it1)[3*i+1];
99     }
100   throw INTERP_KERNEL::Exception("The specified geometric type is not present in the mesh structure !");
101 }
102
103 /*!
104  * \sa MEDFileMeshStruct::getNumberOfElemsOfGeoType
105  */
106 bool MEDFileMeshStruct::doesManageGeoType(INTERP_KERNEL::NormalizedCellType t) const
107 {
108   for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++)
109     {
110       std::size_t sz=(*it1).size();
111       if(sz%3!=0)
112         throw INTERP_KERNEL::Exception("MEDFileMeshStruct::doesManageGeoType : internal error in code !");
113       std::size_t nbGeo=sz/3;
114       for(std::size_t i=0;i<nbGeo;i++)
115         if((*it1)[3*i]==(int)t)
116           return true;
117     }
118   return false;
119 }
120
121 void MEDFileMeshStruct::appendIfImplicitType(INTERP_KERNEL::NormalizedCellType t)
122 {
123   if(!_mesh->hasImplicitPart())
124     throw INTERP_KERNEL::Exception("MEDFileMeshStruct::appendIfImplicitType : by default no implicit geo type can be appended !");
125   static const char MSG[]="MEDFileMeshStruct::appendIfImplicitType : the distribution does not looks like structured standard !";
126   if(_geo_types_distrib.size()!=1)
127     throw INTERP_KERNEL::Exception(MSG);
128   std::size_t sz(_geo_types_distrib[0].size());
129   if(sz%3!=0)
130     throw INTERP_KERNEL::Exception("MEDFileMeshStruct::appendIfImplicitType : internal error in code !");
131   std::size_t nbGeo(sz/3);
132   if(nbGeo!=1)
133     throw INTERP_KERNEL::Exception(MSG);
134   std::vector<int> arr(3); arr[0]=(int)t; arr[1]=_mesh->buildImplicitPartIfAny(t); arr[2]=-1;
135   _geo_types_distrib.push_back(arr);
136 }
137
138
139 int MEDFileMeshStruct::getNumberOfLevs() const
140 {
141   return (int)_geo_types_distrib.size();
142 }
143
144 int MEDFileMeshStruct::getNumberOfGeoTypesInLev(int relativeLev) const
145 {
146   int pos(-relativeLev);
147   if(pos<0 || pos>=(int)_geo_types_distrib.size())
148     throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : invalid level specified !");
149   std::size_t sz=_geo_types_distrib[pos].size();
150   if(sz%3!=0)
151     throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : internal error in code !");
152   return (int)(sz/3);
153 }
154
155 //=
156
157 std::size_t MEDMeshMultiLev::getHeapMemorySizeWithoutChildren() const
158 {
159   return 0;
160 }
161
162 std::vector<const BigMemoryObject *> MEDMeshMultiLev::getDirectChildrenWithNull() const
163 {
164   return std::vector<const BigMemoryObject *>();
165 }
166
167 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<int>& levs)
168 {
169   if(!m)
170     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : null input pointer !");
171   const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
172   if(um)
173     return MEDUMeshMultiLev::New(um,levs);
174   const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
175   if(cm)
176     return MEDCMeshMultiLev::New(cm,levs);
177   const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
178   if(clm)
179     return MEDCurveLinearMeshMultiLev::New(clm,levs);
180   throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
181 }
182
183 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
184 {
185   if(!m)
186     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : null input pointer !");
187   const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
188   if(um)
189     return MEDUMeshMultiLev::New(um,gts,pfls,nbEntities);
190   const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
191   if(cm)
192     return MEDCMeshMultiLev::New(cm,gts,pfls,nbEntities);
193   const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
194   if(clm)
195     return MEDCurveLinearMeshMultiLev::New(clm,gts,pfls,nbEntities);
196   throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
197 }
198
199 MEDMeshMultiLev *MEDMeshMultiLev::NewOnlyOnNode(const MEDFileMesh *m, const DataArrayInt *pflOnNode)
200 {
201   MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(MEDMeshMultiLev::New(m,m->getNonEmptyLevels()));
202   ret->selectPartOfNodes(pflOnNode);
203   return ret.retn();
204 }
205
206 void MEDMeshMultiLev::setNodeReduction(const DataArrayInt *nr)
207 {
208   if(nr)
209     nr->incrRef();
210   _node_reduction=const_cast<DataArrayInt*>(nr);
211 }
212
213 void MEDMeshMultiLev::setCellReduction(const DataArrayInt *cr)
214 {
215   if(_pfls.size()!=1)
216     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::setCellReduction : can be used only for single geo type mesh !");
217   _pfls[0]=const_cast<DataArrayInt*>(cr);
218   if(cr)
219     cr->incrRef();
220 }
221
222 bool MEDMeshMultiLev::isFastlyTheSameStruct(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs) const
223 {
224   if(fst.getType()==ON_NODES)
225     {
226       if(fst.getNumberOfItems()!=1)
227         throw INTERP_KERNEL::Exception("MEDMeshMultiLev::isFastlyTheSameStruct : unexpected situation for nodes !");
228       const MEDFileField1TSStructItem2& p(fst[0]);
229       std::string pflName(p.getPflName());
230       const DataArrayInt *nr(_node_reduction);
231       if(pflName.empty() && !nr)
232         return true;
233       if(!pflName.empty() && !nr)
234         return false;
235       if(pflName==nr->getName())
236         return true;
237       return false;
238     }
239   else
240     {
241       std::size_t sz(fst.getNumberOfItems());
242       if(sz!=_geo_types.size())
243         return false;
244       int strt(0);
245       for(std::size_t i=0;i<sz;i++)
246         {
247           const MEDFileField1TSStructItem2& p(fst[i]);
248           if(!p.isFastlyEqual(strt,_geo_types[i],getPflNameOfId(i).c_str()))
249             return false;
250         }
251       return true;
252     }
253 }
254
255 DataArray *MEDMeshMultiLev::buildDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
256 {
257   MEDCouplingAutoRefCountObjectPtr<DataArray> ret(const_cast<DataArray *>(vals)); ret->incrRef();
258   if(isFastlyTheSameStruct(fst,globs))
259     return ret.retn();
260   else
261     return constructDataArray(fst,globs,vals);
262 }
263
264 /*!
265  * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
266  * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure.
267  */
268 void MEDMeshMultiLev::retrieveFamilyIdsOnCells(DataArrayInt *& famIds, bool& isWithoutCopy) const
269 {
270   const DataArrayInt *fids(_cell_fam_ids);
271   if(!fids)
272     { famIds=0; isWithoutCopy=true; return ; }
273   std::size_t sz(_geo_types.size());
274   bool presenceOfPfls(false);
275   for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
276     {
277       const DataArrayInt *pfl(_pfls[i]);
278       if(pfl)
279         presenceOfPfls=true;
280     }
281   if(!presenceOfPfls)
282     { famIds=const_cast<DataArrayInt *>(fids); famIds->incrRef(); isWithoutCopy=_mesh->isObjectInTheProgeny(famIds); return ; }
283   //bad luck the slowest part
284   isWithoutCopy=false;
285   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > retSafe(sz);
286   std::vector< const DataArrayInt *> ret(sz);
287   int start(0);
288   for(std::size_t i=0;i<sz;i++)
289     {
290       const DataArrayInt *pfl(_pfls[i]);
291       int lgth(_nb_entities[i]);
292       if(pfl)
293         {
294           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(fids->selectByTupleId2(start,start+lgth,1));
295           retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
296         }
297       else
298         {
299           retSafe[i]=fids->selectByTupleId2(start,start+lgth,1);
300         }
301       ret[i]=retSafe[i];
302       start+=lgth;
303     }
304   famIds=DataArrayInt::Aggregate(ret);
305 }
306
307 /*!
308  * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
309  * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure.
310  */
311 void MEDMeshMultiLev::retrieveNumberIdsOnCells(DataArrayInt *& numIds, bool& isWithoutCopy) const
312 {
313   const DataArrayInt *nids(_cell_num_ids);
314   if(!nids)
315     { numIds=0; isWithoutCopy=true; return ; }
316   std::size_t sz(_geo_types.size());
317   bool presenceOfPfls(false);
318   for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
319     {
320       const DataArrayInt *pfl(_pfls[i]);
321       if(pfl)
322         presenceOfPfls=true;
323     }
324   if(!presenceOfPfls)
325     { numIds=const_cast<DataArrayInt *>(nids); numIds->incrRef(); isWithoutCopy=_mesh->isObjectInTheProgeny(numIds); return ; }
326   //bad luck the slowest part
327   isWithoutCopy=false;
328   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > retSafe(sz);
329   std::vector< const DataArrayInt *> ret(sz);
330   int start(0);
331   for(std::size_t i=0;i<sz;i++)
332     {
333       const DataArrayInt *pfl(_pfls[i]);
334       int lgth(_nb_entities[i]);
335       if(pfl)
336         {
337           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(nids->selectByTupleId2(start,start+lgth,1));
338           retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
339         }
340       else
341         {
342           retSafe[i]=nids->selectByTupleId2(start,start+lgth,1);
343         }
344       ret[i]=retSafe[i];
345       start+=lgth;
346     }
347   numIds=DataArrayInt::Aggregate(ret);
348 }
349
350 /*!
351  * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
352  * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure.
353  */
354 void MEDMeshMultiLev::retrieveFamilyIdsOnNodes(DataArrayInt *& famIds, bool& isWithoutCopy) const
355 {
356   const DataArrayInt *fids(_node_fam_ids);
357   if(!fids)
358     { famIds=0; isWithoutCopy=true; return ; }
359   const DataArrayInt *nr(_node_reduction);
360   if(nr)
361     {
362       isWithoutCopy=false;
363       famIds=fids->selectByTupleIdSafe(nr->begin(),nr->end());
364     }
365   else
366     {
367       famIds=const_cast<DataArrayInt *>(fids); famIds->incrRef();
368       isWithoutCopy=_mesh->isObjectInTheProgeny(famIds);
369     }
370 }
371
372 /*!
373  * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
374  * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure.
375  */
376 void MEDMeshMultiLev::retrieveNumberIdsOnNodes(DataArrayInt *& numIds, bool& isWithoutCopy) const
377 {
378   const DataArrayInt *fids(_node_num_ids);
379   if(!fids)
380     { numIds=0; isWithoutCopy=true; return ; }
381   const DataArrayInt *nr(_node_reduction);
382   if(nr)
383     {
384       isWithoutCopy=false;
385       numIds=fids->selectByTupleIdSafe(nr->begin(),nr->end());
386     }
387   else
388     {
389       numIds=const_cast<DataArrayInt *>(fids); numIds->incrRef();
390       isWithoutCopy=_mesh->isObjectInTheProgeny(numIds);
391     }
392 }
393
394 std::vector< INTERP_KERNEL::NormalizedCellType > MEDMeshMultiLev::getGeoTypes() const
395 {
396   return _geo_types;
397 }
398
399 void MEDMeshMultiLev::setFamilyIdsOnCells(DataArrayInt *famIds)
400 {
401   _cell_fam_ids=famIds;
402   if(famIds)
403     famIds->incrRef();
404 }
405
406 void MEDMeshMultiLev::setNumberIdsOnCells(DataArrayInt *numIds)
407 {
408   _cell_num_ids=numIds;
409   if(numIds)
410     numIds->incrRef();
411 }
412
413 void MEDMeshMultiLev::setFamilyIdsOnNodes(DataArrayInt *famIds)
414 {
415   _node_fam_ids=famIds;
416   if(famIds)
417     famIds->incrRef();
418 }
419
420 void MEDMeshMultiLev::setNumberIdsOnNodes(DataArrayInt *numIds)
421 {
422   _node_num_ids=numIds;
423   if(numIds)
424     numIds->incrRef();
425 }
426
427 std::string MEDMeshMultiLev::getPflNameOfId(int id) const
428 {
429   std::size_t sz(_pfls.size());
430   if(id<0 || id>=(int)sz)
431     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getPflNameOfId : invalid input id !");
432   const DataArrayInt *pfl(_pfls[id]);
433   if(!pfl)
434     return std::string("");
435   return pfl->getName();
436 }
437
438 /*!
439  * Returns the number of cells having geometric type \a t.
440  * The profiles are **NOT** taken into account here.
441  */
442 int MEDMeshMultiLev::getNumberOfCells(INTERP_KERNEL::NormalizedCellType t) const
443 {
444   std::size_t sz(_nb_entities.size());
445   for(std::size_t i=0;i<sz;i++)
446     if(_geo_types[i]==t)
447       return _nb_entities[i];
448   throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getNumberOfCells : not existing geometric type in this !");
449 }
450
451 int MEDMeshMultiLev::getNumberOfNodes() const
452 {
453   return _nb_nodes;
454 }
455
456 DataArray *MEDMeshMultiLev::constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
457 {
458   if(fst.getType()==ON_NODES)
459     {
460       if(fst.getNumberOfItems()!=1)
461         throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes !");
462       const MEDFileField1TSStructItem2& p(fst[0]);
463       std::string pflName(p.getPflName());
464       const DataArrayInt *nr(_node_reduction);
465       if(pflName.empty() && !nr)
466         return vals->deepCpy();
467       if(pflName.empty() && nr)
468         throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 2 !");
469       if(!pflName.empty() && nr)
470         {
471           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
472           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(nr->deepCpy());
473           p1->sort(true); p2->sort(true);
474           if(!p1->isEqualWithoutConsideringStr(*p2))
475             throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : it appears that a profile on nodes does not cover the cells correctly !");
476           p1=DataArrayInt::FindPermutationFromFirstToSecond(globs->getProfile(pflName.c_str()),nr);
477           MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
478           ret->renumberInPlace(p1->begin());
479           return ret.retn();
480         }
481       if(!pflName.empty() && !nr)
482         {
483           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
484           p1->sort(true);
485           if(!p1->isIdentity2(getNumberOfNodes()))
486             throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 4 !");
487           MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
488           ret->renumberInPlace(globs->getProfile(pflName.c_str())->begin());
489           return ret.retn();
490         }
491       throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 5 !");
492     }
493   else
494     {
495       std::size_t sz(fst.getNumberOfItems());
496       std::set<INTERP_KERNEL::NormalizedCellType> s(_geo_types.begin(),_geo_types.end());
497       if(s.size()!=_geo_types.size())
498         throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 2 !");
499       std::vector< const DataArray *> arr(s.size());
500       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arrSafe(s.size());
501       int iii(0);
502       int nc(vals->getNumberOfComponents());
503       std::vector<std::string> compInfo(vals->getInfoOnComponents());
504       for(std::vector< INTERP_KERNEL::NormalizedCellType >::const_iterator it=_geo_types.begin();it!=_geo_types.end();it++,iii++)
505         {
506           const DataArrayInt *thisP(_pfls[iii]);
507           std::vector<const MEDFileField1TSStructItem2 *> ps;
508           for(std::size_t i=0;i<sz;i++)
509             {
510               const MEDFileField1TSStructItem2& p(fst[i]);
511               if(p.getGeo()==*it)
512                 ps.push_back(&p);
513             }
514           if(ps.empty())
515             throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 1 !");
516           if(ps.size()==1)
517             {
518               int nbi(ps[0]->getNbOfIntegrationPts(globs));
519               const DataArrayInt *otherP(ps[0]->getPfl(globs));
520               const std::pair<int,int>& strtStop(ps[0]->getStartStop());
521               MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
522               if(!thisP && !otherP)
523                 {
524                   arrSafe[iii]=ret; arr[iii]=ret;
525                   continue;
526                 }
527               if(thisP && otherP)
528                 {
529                   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->invertArrayN2O2O2N(getNumberOfCells(ps[0]->getGeo())));
530                   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(thisP->deepCpy());
531                   p2->transformWithIndArr(p1->begin(),p1->end());
532                   //p1=p2->getIdsNotEqual(-1);
533                   //p1=p2->selectByTupleIdSafe(p1->begin(),p1->end());
534                   ret->rearrange(nbi*nc); ret=ret->selectByTupleIdSafe(p2->begin(),p2->end()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
535                   arrSafe[iii]=ret; arr[iii]=ret;
536                   continue;
537                 }
538               if(!thisP && otherP)
539                 {
540                   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->deepCpy());
541                   p1->sort(true);
542                   p1->checkAllIdsInRange(0,getNumberOfCells(ps[0]->getGeo()));
543                   p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,p1);
544                   ret->rearrange(nbi*nc); ret->renumberInPlace(p1->begin()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
545                   arrSafe[iii]=ret; arr[iii]=ret;
546                   continue;
547                 }
548               throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 3 !");
549             }
550           else
551             {
552               std::vector< const DataArrayInt * >otherPS(ps.size());
553               std::vector< const DataArray * > arr2(ps.size());
554               std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arr2Safe(ps.size());
555               std::vector< const DataArrayInt * > nbis(ps.size());
556               std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > nbisSafe(ps.size());
557               int jj(0);
558               for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
559                 {
560                   int nbi((*it2)->getNbOfIntegrationPts(globs));
561                   const DataArrayInt *otherPfl((*it2)->getPfl(globs));
562                   const std::pair<int,int>& strtStop((*it2)->getStartStop());
563                   MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
564                   if(!otherPfl)
565                     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 4 !");
566                   arr2[jj]=ret2; arr2Safe[jj]=ret2; otherPS[jj]=otherPfl;
567                   nbisSafe[jj]=DataArrayInt::New(); nbisSafe[jj]->alloc(otherPfl->getNumberOfTuples(),1); nbisSafe[jj]->fillWithValue(nbi);
568                   nbis[jj]=nbisSafe[jj];
569                 }
570               MEDCouplingAutoRefCountObjectPtr<DataArray> arr3(DataArray::Aggregate(arr2));
571               MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherP(DataArrayInt::Aggregate(otherPS));
572               MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbis(DataArrayInt::Aggregate(nbis));
573               MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherPN(otherP->invertArrayN2O2O2N(getNumberOfCells(*it)));
574               MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1;
575               if(thisP)
576                 p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,thisP);
577               else
578                 p1=otherP->deepCpy();
579               MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbisN(zenbis->renumber(p1->begin()));
580               zenbisN->computeOffsets2();
581               jj=0;
582               for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
583                 {
584                   //int nbi((*it2)->getNbOfIntegrationPts(globs));
585                   const DataArrayInt *otherPfl((*it2)->getPfl(globs));
586                   const std::pair<int,int>& strtStop((*it2)->getStartStop());
587                   MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
588                   //
589                   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(otherPfl->deepCpy());
590                   p2->transformWithIndArr(otherPN->begin(),otherPN->end());
591                   p2->transformWithIndArr(p1->begin(),p1->end());
592                   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsN(p2->buildExplicitArrByRanges(zenbisN));
593                   arr3->setPartOfValuesBase3(ret2,idsN->begin(),idsN->end(),0,nc,1);
594                 }
595               arrSafe[iii]=arr3; arr[iii]=arr3;
596               continue;
597             }
598         }
599       return DataArray::Aggregate(arr);
600     }
601 }
602
603 /*!
604  * This method is called to add NORM_POINT1 cells in \a this so that orphan nodes in \a verticesToAdd will be fetched.
605  */
606 void MEDMeshMultiLev::appendVertices(const DataArrayInt *verticesToAdd, DataArrayInt *nr)
607 {
608   int nbOfVertices(verticesToAdd->getNumberOfTuples());
609   std::size_t sz(_pfls.size());
610   _pfls.resize(sz+1);
611   _geo_types.resize(sz+1,INTERP_KERNEL::NORM_POINT1);
612   _nb_entities.resize(sz+1,nbOfVertices);
613   _node_reduction=nr; nr->incrRef();
614   _nb_nodes+=nbOfVertices;
615   const DataArrayInt *cf(_cell_fam_ids),*cn(_cell_num_ids),*nf(_node_fam_ids),*nn(_node_num_ids);
616   if(cf)
617     {
618       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp;
619       std::vector<const DataArrayInt *> a(2);
620       a[0]=cf;
621       if(nf)
622         tmp=nf->selectByTupleIdSafe(verticesToAdd->begin(),verticesToAdd->end());
623       else
624         {
625           tmp=DataArrayInt::New(); tmp->alloc(nbOfVertices,1); tmp->fillWithZero();
626         }
627       a[1]=tmp;
628       _cell_fam_ids=DataArrayInt::Aggregate(a);
629     }
630   if(cn)
631     {
632       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp;
633       std::vector<const DataArrayInt *> a(2);
634       a[0]=cn;
635       if(nn)
636         tmp=nn->selectByTupleIdSafe(verticesToAdd->begin(),verticesToAdd->end());
637       else
638         {
639           tmp=DataArrayInt::New(); tmp->alloc(nbOfVertices,1); tmp->fillWithZero();
640         }
641       a[1]=tmp;
642       _cell_num_ids=DataArrayInt::Aggregate(a);
643     }
644 }
645
646 MEDMeshMultiLev::MEDMeshMultiLev(const MEDFileMesh *mesh):_mesh(mesh),_nb_nodes(0)
647 {
648 }
649
650 MEDMeshMultiLev::MEDMeshMultiLev(const MEDFileMesh *mesh, int nbNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):_mesh(mesh),_geo_types(gts),_nb_entities(nbEntities),_nb_nodes(nbNodes)
651 {
652   std::size_t sz(_geo_types.size());
653   if(sz!=pfls.size() || sz!=nbEntities.size())
654     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
655   _pfls.resize(sz);
656   for(std::size_t i=0;i<sz;i++)
657     {
658       if(pfls[i])
659         pfls[i]->incrRef();
660       _pfls[i]=const_cast<DataArrayInt *>(pfls[i]);
661     }
662 }
663
664 MEDMeshMultiLev::MEDMeshMultiLev(const MEDMeshMultiLev& other):RefCountObject(other),_mesh(other._mesh),_pfls(other._pfls),_geo_types(other._geo_types),_nb_entities(other._nb_entities),_node_reduction(other._node_reduction),_nb_nodes(other._nb_nodes),_cell_fam_ids(other._cell_fam_ids),_cell_num_ids(other._cell_num_ids),_node_fam_ids(other._node_fam_ids),_node_num_ids(other._node_num_ids)
665 {
666 }
667
668 //=
669
670 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs)
671 {
672   return new MEDUMeshMultiLev(m,levs);
673 }
674
675 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs):MEDMeshMultiLev(m)
676 {
677   if(!m)
678     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
679   std::vector<MEDCoupling1GTUMesh *> v;
680   for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
681     {
682       std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
683       v.insert(v.end(),vTmp.begin(),vTmp.end());
684     }
685   std::size_t sz(v.size());
686   if(v.empty())
687     {
688       _coords=m->getCoords(); _coords->incrRef();
689     }
690   _parts.resize(sz);
691   _pfls.resize(sz);
692   _geo_types.resize(sz);
693   _nb_entities.resize(sz);
694   for(std::size_t i=0;i<sz;i++)
695     {
696       MEDCoupling1GTUMesh *obj(v[i]);
697       if(obj)
698         obj->incrRef();
699       else
700         throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
701       _parts[i]=obj;
702       _geo_types[i]=obj->getCellModelEnum();
703       _nb_entities[i]=obj->getNumberOfCells();
704     }
705   // ids fields management
706   bool cellFamIdsNoCpy(levs.size()==1);
707   if(cellFamIdsNoCpy)
708     {
709       const DataArrayInt *tmp(m->getFamilyFieldAtLevel(levs[0]));
710       if(tmp)
711         {
712           tmp->incrRef();
713           _cell_fam_ids=(const_cast<DataArrayInt *>(tmp));
714         }
715     }
716   else
717     {
718       std::vector<const DataArrayInt *> tmps(levs.size());
719       bool f(true);
720       for(std::size_t i=0;i<levs.size();i++)
721         {
722           tmps[i]=m->getFamilyFieldAtLevel(levs[i]);
723           if(!tmps[i])
724             f=false;
725         }
726       if(f && !tmps.empty())
727         _cell_fam_ids=DataArrayInt::Aggregate(tmps);
728     }
729   bool cellNumIdsNoCpy(levs.size()==1);
730   if(cellNumIdsNoCpy)
731     {
732       const DataArrayInt *tmp(m->getNumberFieldAtLevel(levs[0]));
733       if(tmp)
734         {
735           tmp->incrRef();
736           _cell_num_ids=(const_cast<DataArrayInt *>(tmp));
737         }
738     }
739   else
740     {
741       std::vector<const DataArrayInt *> tmps(levs.size());
742       bool n(true);
743       for(std::size_t i=0;i<levs.size();i++)
744         {
745           tmps[i]=m->getNumberFieldAtLevel(levs[i]);
746           if(!tmps[i])
747             n=false;
748         }
749       if(n && !tmps.empty())
750         _cell_num_ids=DataArrayInt::Aggregate(tmps);
751     }
752   // node part
753   {
754     const DataArrayInt *tmp(m->getFamilyFieldAtLevel(1));
755     if(tmp)
756       {
757         tmp->incrRef();
758         _node_fam_ids=(const_cast<DataArrayInt *>(tmp));
759       }
760   }
761   {
762     const DataArrayInt *tmp(m->getNumberFieldAtLevel(1));
763     if(tmp)
764       {
765         tmp->incrRef();
766         _node_num_ids=(const_cast<DataArrayInt *>(tmp));
767       }
768   }
769 }
770
771 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
772 {
773   return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
774 }
775
776 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(m,m->getNumberOfNodes(),gts,pfls,nbEntities)
777 {
778   std::size_t sz(gts.size());
779   if(sz<1)
780     throw INTERP_KERNEL::Exception("constructor of MEDUMeshMultiLev : number of different geo type must be >= 1 !");
781   unsigned dim(INTERP_KERNEL::CellModel::GetCellModel(gts[0]).getDimension());
782   _parts.resize(sz);
783   bool isSameDim(true),isNoPfl(true);
784   for(std::size_t i=0;i<sz;i++)
785     {
786       MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
787       if(INTERP_KERNEL::CellModel::GetCellModel(gts[i]).getDimension()!=dim)
788         isSameDim=false;
789       if(pfls[i])
790         isNoPfl=false;
791       if(elt)
792         elt->incrRef();
793       _parts[i]=elt;
794     }
795   // ids fields management
796   int lev((int)dim-m->getMeshDimension());
797   if(isSameDim && isNoPfl && m->getGeoTypesAtLevel(lev)==gts)//optimized part
798     {
799       const DataArrayInt *famIds(m->getFamilyFieldAtLevel(lev));
800       if(famIds)
801         { _cell_fam_ids=const_cast<DataArrayInt*>(famIds); famIds->incrRef(); }
802       const DataArrayInt *numIds(m->getNumberFieldAtLevel(lev));
803       if(numIds)
804         { _cell_num_ids=const_cast<DataArrayInt*>(numIds); numIds->incrRef(); }
805       famIds=m->getFamilyFieldAtLevel(1);
806       if(famIds)
807         { _node_fam_ids=const_cast<DataArrayInt*>(famIds); famIds->incrRef(); }
808       numIds=m->getNumberFieldAtLevel(1);
809       if(numIds)
810         { _node_num_ids=const_cast<DataArrayInt*>(numIds); numIds->incrRef(); }
811       return ;
812     }
813   //
814   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > famIdsSafe(sz);
815   std::vector<const DataArrayInt *> famIds(sz);
816   bool f(true);
817   for(std::size_t i=0;i<sz;i++)
818     {
819       famIdsSafe[i]=m->extractFamilyFieldOnGeoType(gts[i]);
820       famIds[i]=famIdsSafe[i];
821       if(!famIds[i])
822         f=false;
823     }
824   if(f)
825     _cell_fam_ids=DataArrayInt::Aggregate(famIds);
826   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > numIdsSafe(sz);
827   std::vector<const DataArrayInt *> numIds(sz);
828   bool n(true);
829   for(std::size_t i=0;i<sz;i++)
830     {
831       numIdsSafe[i]=m->extractNumberFieldOnGeoType(gts[i]);
832       numIds[i]=numIdsSafe[i];
833       if(!numIds[i])
834         n=false;
835     }
836   if(n)
837     _cell_num_ids=DataArrayInt::Aggregate(numIds);
838   // node ids management
839   const DataArrayInt *nodeFamIds(m->getFamilyFieldAtLevel(1));
840   if(nodeFamIds)
841     { _node_fam_ids=const_cast<DataArrayInt*>(nodeFamIds); nodeFamIds->incrRef(); }
842   const DataArrayInt *nodeNumIds(m->getNumberFieldAtLevel(1));
843   if(nodeNumIds)
844     { _node_num_ids=const_cast<DataArrayInt*>(nodeNumIds); nodeNumIds->incrRef(); }
845 }
846
847 void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
848 {
849   if(!pflNodes || !pflNodes->isAllocated())
850     return ;
851   std::size_t sz(_parts.size());
852   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a(sz);
853   std::vector< const DataArrayInt *> aa(sz);
854   for(std::size_t i=0;i<sz;i++)
855     {
856       const DataArrayInt *pfl(_pfls[i]);
857       MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m(_parts[i]);
858       if(pfl)
859         m=dynamic_cast<MEDCoupling1GTUMesh *>(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
860       DataArrayInt *cellIds=0;
861       m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
862       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
863       MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
864       int tmp=-1;
865       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(m2->getNodeIdsInUse(tmp));
866       a[i]=o2n->invertArrayO2N2N2O(tmp); aa[i]=a[i];
867       if(pfl)
868         _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
869       else
870         _pfls[i]=cellIdsSafe;
871     }
872   if(!aa.empty())
873     _node_reduction=DataArrayInt::Aggregate(aa);//general case
874   else
875     _node_reduction=pflNodes->deepCpy();//case where no cells in read mesh.
876   _node_reduction->sort(true);
877   _node_reduction=_node_reduction->buildUnique();
878   if(_node_reduction->getNumberOfTuples()==pflNodes->getNumberOfTuples())
879     return ;//This is the classical case where the input node profile corresponds perfectly to a subset of cells in _parts
880   if(_node_reduction->getNumberOfTuples()>pflNodes->getNumberOfTuples())
881     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::selectPartOfNodes : internal error in MEDCoupling during cell select from a list of nodes !");
882   // Here the cells available in _parts is not enough to cover all the nodes in pflNodes. So adding vertices cells in _parts...
883   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflNodes2(pflNodes->deepCpy());
884   pflNodes2->sort(true);
885   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diff(pflNodes2->buildSubstractionOptimized(_node_reduction));
886   appendVertices(diff,pflNodes2);
887 }
888
889 MEDMeshMultiLev *MEDUMeshMultiLev::prepare() const
890 {
891   return new MEDUMeshMultiLev(*this);
892 }
893
894 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDUMeshMultiLev& other):MEDMeshMultiLev(other),_parts(other._parts),_coords(other._coords)
895 {
896 }
897
898 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>& part):MEDMeshMultiLev(other)
899 {
900   _parts.resize(1);
901   _parts[0]=part;
902   _geo_types.resize(1); _geo_types[0]=part->getCellModelEnum();
903   _nb_entities.resize(1); _nb_entities[0]=part->getNumberOfCells();
904   _pfls.resize(1); _pfls[0]=0;
905 }
906
907 /*! 
908  * To be called only once ! Because due to some optimizations (sometimes aggressive) the internal state can be changed...
909  * If returned value is false output pointer \a coords is not the internal pointer. If returned value is true output pointer \a coords is directly the internal pointer.
910  * If true is returned, the \a coords output parameter should be used with care (non const method call) to avoid to change the internal state of MEDFileUMesh instance.
911  */
912 bool MEDUMeshMultiLev::buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayInt *&cellLocations, DataArrayInt *& cells, DataArrayInt *&faceLocations, DataArrayInt *&faces) const
913 {
914   const DataArrayDouble *tmp(0);
915   if(_parts.empty())
916     tmp=_coords;
917   else
918     tmp=_parts[0]->getCoords();
919   if(!tmp)
920     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : the coordinates are null !");
921   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a(const_cast<DataArrayDouble *>(tmp)); tmp->incrRef();
922   int szBCE(0),szD(0),szF(0);
923   bool isPolyh(false);
924   int iii(0);
925   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
926     {
927       const MEDCoupling1GTUMesh *cur(*it);
928       if(!cur)
929         throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : a part is null !");
930       //
931       const DataArrayInt *pfl(_pfls[iii]);
932       MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
933       if(!pfl)
934         { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
935       else
936         { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
937       //
938       int curNbCells(cur->getNumberOfCells());
939       szBCE+=curNbCells;
940       if((*it)->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
941         szD+=cur->getNodalConnectivity()->getNumberOfTuples()+curNbCells;
942       else
943         {
944           isPolyh=true;
945           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp2(cur->computeEffectiveNbOfNodesPerCell());
946           szD+=tmp2->accumulate(0)+curNbCells;
947           szF+=2*curNbCells+cur->getNodalConnectivity()->getNumberOfTuples();
948         }
949     }
950   MEDCouplingAutoRefCountObjectPtr<DataArrayByte> b(DataArrayByte::New()); b->alloc(szBCE,1); char *bPtr(b->getPointer());
951   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(DataArrayInt::New()); c->alloc(szBCE,1); int *cPtr(c->getPointer());
952   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d(DataArrayInt::New()); d->alloc(szD,1); int *dPtr(d->getPointer());
953   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> e(DataArrayInt::New()),f(DataArrayInt::New()); int *ePtr(0),*fPtr(0);
954   if(isPolyh)
955     { e->alloc(szBCE,1); ePtr=e->getPointer(); f->alloc(szF,1); fPtr=f->getPointer(); }
956   int k(0);
957   iii=0;
958   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
959     {
960       const MEDCoupling1GTUMesh *cur(*it);
961       //
962       const DataArrayInt *pfl(_pfls[iii]);
963       MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
964       if(!pfl)
965         { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
966       else
967         { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
968       //
969       int curNbCells(cur->getNumberOfCells());
970       int gt((int)cur->getCellModelEnum());
971       if(gt<0 || gt>=PARAMEDMEM_2_VTKTYPE_LGTH)
972         throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : invalid geometric type !");
973       unsigned char gtvtk(PARAMEDMEM_2_VTKTYPE[gt]);
974       if(gtvtk==255)
975         throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : no VTK type for the requested INTERP_KERNEL geometric type !");
976       std::fill(bPtr,bPtr+curNbCells,gtvtk); bPtr+=curNbCells;
977       const MEDCoupling1SGTUMesh *scur(dynamic_cast<const MEDCoupling1SGTUMesh *>(cur));
978       const MEDCoupling1DGTUMesh *dcur(dynamic_cast<const MEDCoupling1DGTUMesh *>(cur));
979       const int *connPtr(cur->getNodalConnectivity()->begin());
980       if(!scur && !dcur)
981         throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : internal error !");
982       if(scur)
983         {
984           if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA27)
985             {
986               int nnpc(scur->getNumberOfNodesPerCell());
987               for(int i=0;i<curNbCells;i++,connPtr+=nnpc)
988                 {
989                   *dPtr++=nnpc;
990                   dPtr=std::copy(connPtr,connPtr+nnpc,dPtr);
991                   *cPtr++=k; k+=nnpc+1;
992                 }
993             }
994           else
995             {
996               for(int i=0;i<curNbCells;i++,connPtr+=27)
997                 {
998                   *dPtr++=27;
999                   for(int j=0;j<27;j++,dPtr++)
1000                     *dPtr=connPtr[HEXA27_PERM_ARRAY[j]];
1001                   *cPtr++=k; k+=28;
1002                 }
1003             }
1004           if(isPolyh)
1005             { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
1006         }
1007       else
1008         {
1009           const int *connIPtr(dcur->getNodalConnectivityIndex()->begin());
1010           if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1011             {
1012               for(int i=0;i<curNbCells;i++,connIPtr++)
1013                 {
1014                   *dPtr++=connIPtr[1]-connIPtr[0];
1015                   dPtr=std::copy(connPtr+connIPtr[0],connPtr+connIPtr[1],dPtr);
1016                   *cPtr++=k; k+=connIPtr[1]-connIPtr[0]+1;
1017                 }
1018             }
1019           else
1020             {
1021               for(int i=0;i<curNbCells;i++,connIPtr++)
1022                 {
1023                   std::set<int> s(connPtr+connIPtr[0],connPtr+connIPtr[1]); s.erase(-1);
1024                   *dPtr++=(int)s.size();
1025                   dPtr=std::copy(s.begin(),s.end(),dPtr);
1026                   *cPtr++=k; k+=(int)s.size()+1;
1027                 }
1028             }
1029           if(isPolyh)
1030             {
1031               connIPtr=dcur->getNodalConnectivityIndex()->begin();
1032               if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1033                 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
1034               else
1035                 {
1036                   int kk(0);
1037                   for(int i=0;i<curNbCells;i++,connIPtr++)
1038                     {
1039                       int nbFace(std::count(connPtr+connIPtr[0],connPtr+connIPtr[1],-1)+1);
1040                       *fPtr++=nbFace;
1041                       const int *work(connPtr+connIPtr[0]);
1042                       for(int j=0;j<nbFace;j++)
1043                         {
1044                           const int *work2=std::find(work,connPtr+connIPtr[1],-1);
1045                           *fPtr++=std::distance(work,work2);
1046                           fPtr=std::copy(work,work2,fPtr);
1047                           work=work2+1;
1048                         }
1049                       *ePtr++=kk; kk+=connIPtr[1]-connIPtr[0]+2;
1050                     }
1051                 }
1052             }
1053         }
1054     }
1055   if(!isPolyh)
1056     reorderNodesIfNecessary(a,d,0);
1057   else
1058     reorderNodesIfNecessary(a,d,f);
1059   if(a->getNumberOfComponents()!=3)
1060     a=a->changeNbOfComponents(3,0.);
1061   coords=a.retn(); types=b.retn(); cellLocations=c.retn(); cells=d.retn();
1062   if(!isPolyh)
1063     { faceLocations=0; faces=0; }
1064   else
1065     { faceLocations=e.retn(); faces=f.retn(); }
1066   return _mesh->isObjectInTheProgeny(coords);
1067 }
1068
1069 void MEDUMeshMultiLev::reorderNodesIfNecessary(MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& coords, DataArrayInt *nodalConnVTK, DataArrayInt *polyhedNodalConnVTK) const
1070 {
1071   const DataArrayInt *nr(_node_reduction);
1072   if(!nr)
1073     return ;
1074   if(nodalConnVTK->empty() && !polyhedNodalConnVTK)
1075     {
1076       coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
1077       return ;
1078     }
1079   int sz(coords->getNumberOfTuples());
1080   std::vector<bool> b(sz,false);
1081   const int *work(nodalConnVTK->begin()),*endW(nodalConnVTK->end());
1082   while(work!=endW)
1083     {
1084       int nb(*work++);
1085       for(int i=0;i<nb && work!=endW;i++,work++)
1086         {
1087           if(*work>=0 && *work<sz)
1088             b[*work]=true;
1089           else
1090             throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error !");
1091         }
1092     }
1093   if(polyhedNodalConnVTK)
1094     {
1095       work=polyhedNodalConnVTK->begin(); endW=polyhedNodalConnVTK->end();
1096       while(work!=endW)
1097         {
1098           int nb(*work++);
1099           for(int i=0;i<nb && work!=endW;i++)
1100             {
1101               int nb2(*work++);
1102               for(int j=0;j<nb2 && work!=endW;j++,work++)
1103                 {
1104                   if(*work>=0 && *work<sz)
1105                     b[*work]=true;
1106                   else
1107                     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #2 !");
1108                 }
1109             }
1110         }
1111     }
1112   int szExp(std::count(b.begin(),b.end(),true));
1113   if(szExp!=nr->getNumberOfTuples())
1114     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #3 !");
1115   // Go renumbering !
1116   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(DataArrayInt::New()); o2n->alloc(sz,1);
1117   int *o2nPtr(o2n->getPointer());
1118   int newId(0);
1119   for(int i=0;i<sz;i++,o2nPtr++)
1120     if(b[i]) *o2nPtr=newId++; else *o2nPtr=-1;
1121   const int *o2nPtrc(o2n->begin());
1122   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(nr->getNumberOfTuples()));
1123   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> perm(DataArrayInt::FindPermutationFromFirstToSecond(n2o,nr));
1124   const int *permPtr(perm->begin());
1125   int *work2(nodalConnVTK->getPointer()),*endW2(nodalConnVTK->getPointer()+nodalConnVTK->getNumberOfTuples());
1126   while(work2!=endW2)
1127     {
1128       int nb(*work2++);
1129       for(int i=0;i<nb && work2!=endW2;i++,work2++)
1130         *work2=permPtr[o2nPtrc[*work2]];
1131     }
1132   if(polyhedNodalConnVTK)
1133     {
1134       work2=polyhedNodalConnVTK->getPointer(); endW2=polyhedNodalConnVTK->getPointer()+polyhedNodalConnVTK->getNumberOfTuples();
1135       while(work2!=endW2)
1136         {
1137           int nb(*work2++);
1138           for(int i=0;i<nb && work2!=endW2;i++)
1139             {
1140               int nb2(*work2++);
1141               for(int j=0;j<nb2 && work2!=endW2;j++,work2++)
1142                 *work2=permPtr[o2nPtrc[*work2]];
1143             }
1144         }
1145     }
1146   coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
1147 }
1148
1149
1150 void MEDUMeshMultiLev::appendVertices(const DataArrayInt *verticesToAdd, DataArrayInt *nr)
1151 {
1152   int nbOfCells(verticesToAdd->getNumberOfTuples());//it is not a bug cells are NORM_POINT1
1153   MEDMeshMultiLev::appendVertices(verticesToAdd,nr);
1154   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> elt(MEDCoupling1SGTUMesh::New("",INTERP_KERNEL::NORM_POINT1));
1155   elt->allocateCells(nbOfCells);
1156   for(int i=0;i<nbOfCells;i++)
1157     {
1158       int pt(verticesToAdd->getIJ(i,0));
1159       elt->insertNextCell(&pt,&pt+1);
1160     }
1161   if(_parts.empty())
1162     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::appendVertices : parts are empty !");
1163   elt->setCoords(_parts[0]->getCoords());
1164   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> elt2((MEDCoupling1SGTUMesh *)elt); elt2->incrRef();
1165   _parts.push_back(elt2);
1166 }
1167
1168 //=
1169
1170 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, const std::vector<int>& lev):MEDMeshMultiLev(m),_is_internal(true)
1171 {
1172   initStdFieldOfIntegers(m);
1173 }
1174
1175 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, int nbOfNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(m,nbOfNodes,gts,pfls,nbEntities),_is_internal(true)
1176 {
1177   initStdFieldOfIntegers(m);
1178 }
1179
1180 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other),_is_internal(true),_face_fam_ids(other._face_fam_ids),_face_num_ids(other._face_num_ids)
1181 {
1182 }
1183
1184 void MEDStructuredMeshMultiLev::initStdFieldOfIntegers(const MEDFileStructuredMesh *m)
1185 {
1186   // ids fields management
1187   const DataArrayInt *tmp(0);
1188   tmp=m->getFamilyFieldAtLevel(0);
1189   if(tmp)
1190     {
1191       tmp->incrRef();
1192       _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1193     }
1194   tmp=m->getNumberFieldAtLevel(0);
1195   if(tmp)
1196     {
1197       tmp->incrRef();
1198       _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1199     }
1200   //
1201   tmp=0;
1202   tmp=m->getFamilyFieldAtLevel(1);
1203   if(tmp)
1204     {
1205       tmp->incrRef();
1206       _node_fam_ids=const_cast<DataArrayInt *>(tmp);
1207     }
1208   tmp=m->getNumberFieldAtLevel(1);
1209   if(tmp)
1210     {
1211       tmp->incrRef();
1212       _node_num_ids=const_cast<DataArrayInt *>(tmp);
1213     }
1214   // faces (if any)
1215   tmp=m->getFamilyFieldAtLevel(-1);
1216   if(tmp)
1217     {
1218       tmp->incrRef();
1219       _face_fam_ids=const_cast<DataArrayInt *>(tmp);
1220     }
1221   tmp=m->getNumberFieldAtLevel(-1);
1222   if(tmp)
1223     {
1224       tmp->incrRef();
1225       _face_num_ids=const_cast<DataArrayInt *>(tmp);
1226     }
1227 }
1228
1229 void MEDStructuredMeshMultiLev::moveFaceToCell() const
1230 {
1231   const_cast<MEDStructuredMeshMultiLev *>(this)->_cell_fam_ids=_face_fam_ids; const_cast<MEDStructuredMeshMultiLev *>(this)->_face_fam_ids=0;
1232   const_cast<MEDStructuredMeshMultiLev *>(this)->_cell_num_ids=_face_num_ids; const_cast<MEDStructuredMeshMultiLev *>(this)->_face_num_ids=0;
1233 }
1234
1235 bool MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase(MEDMeshMultiLev *&ret) const
1236 {
1237   ret=0;
1238   if(_geo_types.empty())
1239     return false;
1240   if(_geo_types.size()!=1)
1241     throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase only one geo types supported at most supported for the moment !");
1242   INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(_mesh->getMeshDimension()));
1243   if(_geo_types[0]==gt)
1244     return false;
1245   MEDCoupling1GTUMesh *facesIfPresent((static_cast<const MEDFileStructuredMesh *>(_mesh))->getImplicitFaceMesh());
1246   if(!facesIfPresent)
1247     return false;
1248   const DataArrayInt *pfl(0),*nr(_node_reduction);
1249   if(!_pfls.empty())
1250     pfl=_pfls[0];
1251   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> facesIfPresent2(facesIfPresent); facesIfPresent->incrRef();
1252   moveFaceToCell();
1253   MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret2(new MEDUMeshMultiLev(*this,facesIfPresent2));
1254   if(pfl)
1255     ret2->setCellReduction(pfl);
1256   if(nr)
1257     throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase : case is not treated yet for node reduction on implicit unstructured mesh.");
1258   ret=ret2.retn();
1259   return true;
1260 }
1261
1262 void MEDStructuredMeshMultiLev::dealWithImplicitUnstructuredMesh(const MEDFileMesh *m)
1263 {
1264   const DataArrayInt *tmp(0);
1265   tmp=m->getFamilyFieldAtLevel(-1);
1266   if(tmp)
1267     {
1268       tmp->incrRef();
1269       _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1270     }
1271   tmp=m->getNumberFieldAtLevel(-1);
1272   if(tmp)
1273     {
1274       tmp->incrRef();
1275       _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1276     }
1277 }
1278
1279 void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
1280 {
1281   if(!pflNodes || !pflNodes->isAllocated())
1282     return ;
1283   std::vector<int> ngs(getNodeGridStructure());
1284   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
1285   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(ngs.size())));
1286   m->setNodalConnectivity(conn);
1287   const DataArrayInt *pfl(_pfls[0]);
1288   if(pfl)
1289     {
1290       m=dynamic_cast<MEDCoupling1SGTUMesh *>(m->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1291     }
1292   DataArrayInt *cellIds=0;
1293   m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
1294   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
1295   MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
1296   int tmp=-1;
1297   _node_reduction=m2->getNodeIdsInUse(tmp);
1298   if(pfl)
1299     _pfls[0]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
1300   else
1301     _pfls[0]=cellIdsSafe;
1302 }
1303
1304 //=
1305
1306 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs)
1307 {
1308   return new MEDCMeshMultiLev(m,levs);
1309 }
1310
1311 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
1312 {
1313   return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
1314 }
1315
1316 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1317 {
1318   if(!m)
1319     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
1320   if(levs.size()!=1 || levs[0]!=0)
1321     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
1322   int sdim(m->getSpaceDimension());
1323   _coords.resize(sdim);
1324   for(int i=0;i<sdim;i++)
1325     {
1326       DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1327       if(!elt)
1328         throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1329       elt->incrRef();
1330       _coords[i]=elt;
1331     }
1332 }
1333
1334 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDStructuredMeshMultiLev(m,m->getNumberOfNodes(),gts,pfls,nbEntities)
1335 {
1336   if(!m)
1337     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
1338   if(gts.size()!=1 || pfls.size()!=1)
1339     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1340   int mdim(m->getMeshDimension());
1341   INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(mdim));
1342   if(gt==gts[0])
1343     {
1344       _coords.resize(mdim);
1345       for(int i=0;i<mdim;i++)
1346         {
1347           DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1348           if(!elt)
1349             throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1350           _coords[i]=elt; _coords[i]->incrRef();
1351         }
1352     }
1353   else
1354     dealWithImplicitUnstructuredMesh(m);
1355 }
1356
1357 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords)
1358 {
1359 }
1360
1361 std::vector<int> MEDCMeshMultiLev::getNodeGridStructure() const
1362 {
1363   std::vector<int> ret(_coords.size());
1364   for(std::size_t i=0;i<_coords.size();i++)
1365     ret[i]=_coords[i]->getNumberOfTuples();
1366   return ret;
1367 }
1368
1369 MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const
1370 {
1371   MEDMeshMultiLev *retSpecific(0);
1372   if(prepareForImplicitUnstructuredMeshCase(retSpecific))
1373     return retSpecific;
1374   const DataArrayInt *pfl(0),*nr(_node_reduction);
1375   if(!_pfls.empty())
1376     pfl=_pfls[0];
1377   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1378   std::vector<int> cgs,ngs(getNodeGridStructure());
1379   cgs.resize(ngs.size());
1380   std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1381   if(pfl)
1382     {
1383       std::vector< std::pair<int,int> > cellParts;
1384       MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret2;
1385       if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1386         {
1387           MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1388           ret->_is_internal=false;
1389           if(nr)
1390             { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1391           ret->_nb_entities[0]=pfl->getNumberOfTuples();
1392           ret->_pfls[0]=0;
1393           std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > coords(_coords.size());
1394           for(std::size_t i=0;i<_coords.size();i++)
1395             coords[i]=_coords[i]->selectByTupleId2(cellParts[i].first,cellParts[i].second+1,1);
1396           ret->_coords=coords;
1397           ret2=(MEDCMeshMultiLev *)ret; ret2->incrRef();
1398         }
1399       else
1400         {
1401           MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> m(MEDCouplingCMesh::New());
1402           for(std::size_t i=0;i<ngs.size();i++)
1403             m->setCoordsAt(i,_coords[i]);
1404           MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1405           MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1406           MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1407           if(nr)
1408             { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1409           ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1410         }
1411       const DataArrayInt *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1412       if(famIds)
1413         {
1414           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1415           ret2->setFamilyIdsOnCells(tmp);
1416         }
1417       if(numIds)
1418         {
1419           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1420           ret2->setNumberIdsOnCells(tmp);
1421         }
1422       return ret2.retn();
1423
1424     }
1425   else
1426     {
1427       MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1428       if(nr)
1429         { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1430       return ret.retn();
1431     }
1432 }
1433
1434 /*!
1435  * \a param [out] isInternal if true the returned pointers are those in main data structure. If false those pointers have been built espacially for that method.
1436  */
1437 std::vector< DataArrayDouble * > MEDCMeshMultiLev::buildVTUArrays(bool& isInternal) const
1438 {
1439   isInternal=_is_internal;
1440   std::size_t sz(_coords.size());
1441   std::vector< DataArrayDouble * > ret(sz);
1442   for(std::size_t i=0;i<sz;i++)
1443     {
1444       ret[i]=const_cast<DataArrayDouble *>((const DataArrayDouble *)_coords[i]);
1445       ret[i]->incrRef();
1446     }
1447   return ret;
1448 }
1449
1450 //=
1451
1452 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1453 {
1454   return new MEDCurveLinearMeshMultiLev(m,levs);
1455 }
1456
1457 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
1458 {
1459   return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
1460 }
1461
1462 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1463 {
1464   if(!m)
1465     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
1466   if(levs.size()!=1 || levs[0]!=0)
1467     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
1468   DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1469   if(!coords)
1470     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1471   coords->incrRef();
1472   _coords=coords;
1473   _structure=m->getMesh()->getNodeGridStructure();
1474 }
1475
1476 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDStructuredMeshMultiLev(m,m->getNumberOfNodes(),gts,pfls,nbEntities)
1477 {
1478   if(!m)
1479     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1480   if(gts.size()!=1 || pfls.size()!=1)
1481     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1482   INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1483   if(gt==gts[0])
1484     {
1485       DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1486       if(!coords)
1487         throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1488       coords->incrRef();
1489       _coords=coords;
1490       _structure=m->getMesh()->getNodeGridStructure();
1491     }
1492   else
1493     dealWithImplicitUnstructuredMesh(m);
1494 }
1495
1496 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure)
1497 {
1498 }
1499
1500 std::vector<int> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const
1501 {
1502   return _structure;
1503 }
1504
1505 MEDMeshMultiLev *MEDCurveLinearMeshMultiLev::prepare() const
1506 {
1507   MEDMeshMultiLev *retSpecific(0);
1508   if(prepareForImplicitUnstructuredMeshCase(retSpecific))
1509     return retSpecific;
1510   const DataArrayInt *pfl(0),*nr(_node_reduction);
1511   if(!_pfls.empty())
1512     pfl=_pfls[0];
1513   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1514   std::vector<int> cgs,ngs(getNodeGridStructure());
1515   cgs.resize(ngs.size());
1516   std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1517   if(pfl)
1518     {
1519       std::vector< std::pair<int,int> > cellParts,nodeParts;
1520       MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret2;
1521       if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1522         {
1523           nodeParts=cellParts;
1524           std::vector<int> st(ngs.size());
1525           for(std::size_t i=0;i<ngs.size();i++)
1526             {
1527               nodeParts[i].second++;
1528               st[i]=nodeParts[i].second-nodeParts[i].first;
1529             }
1530           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p(MEDCouplingStructuredMesh::BuildExplicitIdsFrom(ngs,nodeParts));
1531           MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1532           ret->_is_internal=false;
1533           if(nr)
1534             { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1535           ret->_nb_entities[0]=pfl->getNumberOfTuples();
1536           ret->_pfls[0]=0;
1537           ret->_coords=_coords->selectByTupleIdSafe(p->begin(),p->end());
1538           ret->_structure=st;
1539           ret2=(MEDCurveLinearMeshMultiLev *)ret; ret2->incrRef();
1540         }
1541       else
1542         {
1543           MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> m(MEDCouplingCurveLinearMesh::New());
1544           m->setCoords(_coords); m->setNodeGridStructure(&_structure[0],&_structure[0]+_structure.size());
1545           MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1546           MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1547           MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1548           if(nr)
1549             { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1550           ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1551         }
1552       const DataArrayInt *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1553       if(famIds)
1554         {
1555           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1556           ret2->setFamilyIdsOnCells(tmp);
1557         }
1558       if(numIds)
1559         {
1560           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1561           ret2->setNumberIdsOnCells(tmp);
1562         }
1563       return ret2.retn();
1564     }
1565   else
1566     {
1567       MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1568       if(nr)
1569         { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1570       return ret.retn();
1571     }
1572 }
1573
1574 void MEDCurveLinearMeshMultiLev::buildVTUArrays(DataArrayDouble *&coords, std::vector<int>& nodeStrct, bool& isInternal) const
1575 {
1576   isInternal=_is_internal;
1577   nodeStrct=_structure;
1578   const DataArrayDouble *coo(_coords);
1579   if(!coo)
1580     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev::buildVTUArrays : null pointer on coordinates !");
1581   coords=const_cast<DataArrayDouble *>(coo); coords->incrRef();
1582 }
1583
1584 //=
1585
1586 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2()
1587 {
1588 }
1589
1590 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2(INTERP_KERNEL::NormalizedCellType a, const std::pair<int,int>& b, const std::string& c, const std::string& d):_geo_type(a),_start_end(b),_pfl(DataArrayInt::New()),_loc(d),_nb_of_entity(-1)
1591 {
1592   _pfl->setName(c.c_str());
1593 }
1594
1595 void MEDFileField1TSStructItem2::checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1596 {
1597   if(!mst->doesManageGeoType(_geo_type))
1598     {
1599       MEDFileMeshStruct *mstUnConstCasted(const_cast<MEDFileMeshStruct *>(mst));
1600       mstUnConstCasted->appendIfImplicitType(_geo_type);
1601     }
1602   int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1603   checkInRange(nbOfEnt,1,globs);
1604 }
1605
1606 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1607 {
1608   int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1609   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1610   checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs);
1611 }
1612
1613 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1614 {
1615   if(!globs)
1616     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !");
1617   if(_loc.empty())
1618     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !");
1619   const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str());
1620   int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1621   checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs);
1622 }
1623
1624 int MEDFileField1TSStructItem2::getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const
1625 {
1626   if(_loc.empty())
1627     {
1628       if(getPflName().empty())
1629         return (_start_end.second-_start_end.first)/_nb_of_entity;
1630       else
1631         return (_start_end.second-_start_end.first)/getPfl(globs)->getNumberOfTuples();
1632     }
1633   else
1634     {
1635       const MEDFileFieldLoc& loc(globs->getLocalization(_loc.c_str()));
1636       return loc.getNumberOfGaussPoints();
1637     }
1638 }
1639
1640 std::string MEDFileField1TSStructItem2::getPflName() const
1641 {
1642   return _pfl->getName();
1643 }
1644
1645 const DataArrayInt *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const
1646 {
1647   if(!_pfl->isAllocated())
1648     {
1649       if(_pfl->getName().empty())
1650         return 0;
1651       else
1652         return globs->getProfile(_pfl->getName().c_str());
1653     }
1654   else
1655     return _pfl;
1656 }
1657
1658 /*!
1659  * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possiblity.
1660  * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES
1661  */
1662 void MEDFileField1TSStructItem2::checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs)
1663 {
1664   _nb_of_entity=nbOfEntity;
1665   if(_pfl->getName().empty())
1666     {
1667       if(nbOfEntity!=(_start_end.second-_start_end.first)/nip)
1668         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of field !");
1669       return ;
1670     }
1671   else
1672     {
1673       if(!globs)
1674         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !");
1675       const DataArrayInt *pfl=globs->getProfile(_pfl->getName().c_str());
1676       if(!pfl)
1677         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !");
1678       pfl->checkAllIdsInRange(0,nbOfEntity);
1679     }
1680 }
1681
1682 bool MEDFileField1TSStructItem2::isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const std::string& pflName) const
1683 {
1684   if(startExp!=_start_end.first)
1685     return false;
1686   if(gt!=_geo_type)
1687     return false;
1688   if(getPflName()!=pflName)
1689     return false;
1690   startExp=_start_end.second;
1691   return true;
1692 }
1693
1694 bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const
1695 {
1696   //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
1697   //idem for _loc. It is not an effective attribute for support comparison.
1698   return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
1699 }
1700
1701 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1702 {
1703   if(_geo_type!=other._geo_type)
1704     return false;
1705   if(_nb_of_entity!=other._nb_of_entity)
1706     return false;
1707   if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
1708     return false;
1709   if(_pfl->getName().empty() && other._pfl->getName().empty())
1710     return true;
1711   const DataArrayInt *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
1712   return pfl1->isEqualWithoutConsideringStr(*pfl2);
1713 }
1714
1715 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1716 {
1717   return isCellSupportEqual(other,globs);
1718 }
1719
1720 /*!
1721  * \a objs must be non empty. \a objs should contain items having same geometric type.
1722  */
1723 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs)
1724 {
1725   if(objs.empty())
1726     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
1727   if(objs.size()==1)
1728     return MEDFileField1TSStructItem2(*objs[0]);
1729   INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
1730   int nbEntityRef(objs[0]->_nb_of_entity);
1731   std::size_t sz(objs.size());
1732   std::vector<const DataArrayInt *> arrs(sz);
1733   for(std::size_t i=0;i<sz;i++)
1734     {
1735       const MEDFileField1TSStructItem2 *obj(objs[i]);
1736       if(gt!=obj->_geo_type)
1737         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
1738       if(nbEntityRef!=obj->_nb_of_entity)
1739         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
1740       if(obj->_pfl->getName().empty())
1741         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
1742       arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
1743     }
1744   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::Aggregate(arrs));
1745   arr->sort();
1746   int oldNbTuples(arr->getNumberOfTuples());
1747   arr=arr->buildUnique();
1748   if(oldNbTuples!=arr->getNumberOfTuples())
1749     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
1750   if(arr->isIdentity2(nbEntityRef))
1751     {
1752       std::pair<int,int> p(0,nbEntityRef);
1753       std::string a,b;
1754       MEDFileField1TSStructItem2 ret(gt,p,a,b);
1755       ret._nb_of_entity=nbEntityRef;
1756       return ret;
1757     }
1758   else
1759     {
1760       arr->setName(NEWLY_CREATED_PFL_NAME);
1761       std::pair<int,int> p(0,oldNbTuples);
1762       std::string a,b;
1763       MEDFileField1TSStructItem2 ret(gt,p,a,b);
1764       ret._nb_of_entity=nbEntityRef;
1765       ret._pfl=arr;
1766       return ret;
1767     }
1768 }
1769
1770 std::size_t MEDFileField1TSStructItem2::getHeapMemorySizeWithoutChildren() const
1771 {
1772   std::size_t ret(_loc.capacity());
1773   return ret;
1774 }
1775
1776 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem2::getDirectChildrenWithNull() const
1777 {
1778   std::vector<const BigMemoryObject *> ret;
1779   ret.push_back((const DataArrayInt *)_pfl);
1780   return ret;
1781 }
1782
1783 //=
1784
1785 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
1786 {
1787 }
1788
1789 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1790 {
1791   switch(_type)
1792   {
1793     case ON_NODES:
1794       {
1795         int nbOfEnt=mst->getNumberOfNodes();
1796         if(_items.size()!=1)
1797           throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
1798         _items[0].checkInRange(nbOfEnt,1,globs);
1799         break ;
1800       }
1801     case ON_CELLS:
1802       {
1803         for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1804           (*it).checkWithMeshStructForCells(mst,globs);
1805         break;
1806       }
1807     case ON_GAUSS_NE:
1808       {
1809         for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1810           (*it).checkWithMeshStructForGaussNE(mst,globs);
1811         break;
1812       }
1813     case ON_GAUSS_PT:
1814       {
1815         for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1816           (*it).checkWithMeshStructForGaussPT(mst,globs);
1817         break;
1818       }
1819     default:
1820       throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
1821   }
1822 }
1823
1824 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const
1825 {
1826   if(_type!=other._type)
1827     return false;
1828   if(_items.size()!=other._items.size())
1829     return false;
1830   for(std::size_t i=0;i<_items.size();i++)
1831     if(!(_items[i]==other._items[i]))
1832       return false;
1833   return true;
1834 }
1835
1836 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1837 {
1838   if(_type!=other._type)
1839     return false;
1840   if(_items.size()!=other._items.size())
1841     return false;
1842   for(std::size_t i=0;i<_items.size();i++)
1843     if(!(_items[i].isCellSupportEqual(other._items[i],globs)))
1844       return false;
1845   return true;
1846 }
1847
1848 bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1849 {
1850   if(_type!=other._type)
1851     return false;
1852   if(_items.size()!=other._items.size())
1853     return false;
1854   for(std::size_t i=0;i<_items.size();i++)
1855     if(!(_items[i].isNodeSupportEqual(other._items[i],globs)))
1856       return false;
1857   return true;
1858 }
1859
1860 bool MEDFileField1TSStructItem::isEntityCell() const
1861 {
1862   if(_type==ON_NODES)
1863     return false;
1864   else
1865     return true;
1866 }
1867
1868 class CmpGeo
1869 {
1870 public:
1871   CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
1872   bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
1873 private:
1874   INTERP_KERNEL::NormalizedCellType _geo_type;
1875 };
1876
1877 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const
1878 {
1879   if(!isEntityCell())
1880     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
1881   std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
1882   std::size_t i=0;
1883   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1884     {
1885       std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
1886       if(it0==m.end())
1887         m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
1888       else
1889         (*it0).second.push_back(i);
1890     }
1891   if(m.size()==_items.size())
1892     {
1893       MEDFileField1TSStructItem ret(*this);
1894       ret._type=ON_CELLS;
1895       return ret;
1896     }
1897   std::size_t sz(m.size());
1898   std::vector< MEDFileField1TSStructItem2 > items(sz);
1899   for(i=0;i<sz;i++)
1900     {
1901       const std::vector<std::size_t>& ids=m[i].second;
1902       std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
1903       for(std::size_t j=0;j<ids.size();j++)
1904         objs[j]=&_items[ids[j]];
1905       items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
1906     }
1907   MEDFileField1TSStructItem ret(ON_CELLS,items);
1908   ret._computed=true;
1909   return ret;
1910 }
1911
1912 /*!
1913  * \a this is expected to be ON_CELLS and simplified.
1914  */
1915 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const
1916 {
1917   if(other._type!=ON_NODES)
1918     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
1919   if(other._items.size()!=1)
1920     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
1921   int theFirstLevFull;
1922   bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
1923   const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
1924   int nbOfNodes(meshSt->getNumberOfNodes());
1925   if(otherNodeIt.getPflName().empty())
1926     {//on all nodes
1927       if(!ret0)
1928         return false;
1929       std::vector<bool> nodesFetched(nbOfNodes,false);
1930       meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1931       if(std::find(nodesFetched.begin(),nodesFetched.end(),false)==nodesFetched.end())
1932         return theFirstLevFull==0;
1933       else
1934         return false;
1935     }
1936   else
1937     {
1938       const DataArrayInt *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
1939       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpyPfl(pfl->deepCpy());
1940       cpyPfl->sort();
1941       if(cpyPfl->isIdentity2(nbOfNodes))
1942         {//on all nodes also !
1943           if(!ret0)
1944             return false;
1945           return theFirstLevFull==0;
1946         }
1947       std::vector<bool> nodesFetched(nbOfNodes,false);
1948       meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1949       return cpyPfl->isFittingWith(nodesFetched);
1950     }
1951 }
1952
1953 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const
1954 {
1955   if(_type!=ON_CELLS)
1956     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
1957   if(_items.empty())
1958     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
1959   int nbOfLevs(meshSt->getNumberOfLevs());
1960   if(nbOfLevs==0)
1961     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
1962   std::vector<int> levs(nbOfLevs);
1963   theFirstLevFull=1;
1964   std::set<INTERP_KERNEL::NormalizedCellType> gts;
1965   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1966     {
1967       if(!(*it).getPflName().empty())
1968         return false;
1969       INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
1970       if(gts.find(gt)!=gts.end())
1971         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
1972       gts.insert(gt);
1973       int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
1974       levs[-pos]++;
1975     }
1976   for(int i=0;i<nbOfLevs;i++)
1977     if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
1978       { theFirstLevFull=-i; return true; }
1979   return false;
1980 }
1981
1982 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const
1983 {
1984   if(i>=_items.size())
1985     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
1986   return _items[i];
1987 }
1988
1989 std::size_t MEDFileField1TSStructItem::getHeapMemorySizeWithoutChildren() const
1990 {
1991   std::size_t ret(_items.size()*sizeof(MEDFileField1TSStructItem2));
1992   return ret;
1993 }
1994
1995 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem::getDirectChildrenWithNull() const
1996 {
1997   std::vector<const BigMemoryObject *> ret;
1998   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1999     ret.push_back(&(*it));
2000   return ret;
2001 }
2002
2003 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
2004 {
2005   std::size_t sz(_items.size());
2006   std::vector<INTERP_KERNEL::NormalizedCellType> a0(sz);
2007   std::vector<const DataArrayInt *> a1(sz);
2008   std::vector<int> a2(sz);
2009   std::size_t i(0);
2010   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
2011     {
2012       a0[i]=(*it).getGeo();
2013       a1[i]=(*it).getPfl(globs);
2014       a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
2015     }
2016   return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
2017 }
2018
2019 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStructItem::getGeoTypes(const MEDFileMesh *m) const
2020 {
2021   std::vector<INTERP_KERNEL::NormalizedCellType> ret;
2022   if(_type==ON_NODES)
2023     {
2024       if(!_items.empty() && _items[0].getPflName().empty())
2025         {
2026           if(m)
2027             return m->getAllGeoTypes();
2028           else
2029             return ret;
2030         }
2031       else
2032         return ret;
2033     }
2034   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
2035     {
2036       INTERP_KERNEL::NormalizedCellType elt((*it).getGeo());
2037       std::vector<INTERP_KERNEL::NormalizedCellType>::iterator it2(std::find(ret.begin(),ret.end(),elt));
2038       if(it2==ret.end())
2039         ret.push_back(elt);
2040     }
2041   return ret;
2042 }
2043
2044 MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
2045 {
2046   std::vector< MEDFileField1TSStructItem2 > anItems;
2047   //
2048   std::vector< std::vector<std::string> > pfls,locs;
2049   std::vector< std::vector<TypeOfField> > typesF;
2050   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2051   std::vector< std::vector<std::pair<int,int> > > strtEnds=ref->getFieldSplitedByType(std::string(),geoTypes,typesF,pfls,locs);
2052   std::size_t nbOfGeoTypes(geoTypes.size());
2053   if(nbOfGeoTypes==0)
2054     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref  !");
2055   if(typesF[0].empty())
2056     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 bis !");
2057   TypeOfField atype(typesF[0][0]);
2058   for(std::size_t i=0;i<nbOfGeoTypes;i++)
2059     {
2060       std::size_t sz=typesF[i].size();
2061       if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
2062         throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
2063       //
2064       for(std::size_t j=0;j<sz;j++)
2065         {
2066           if(atype==typesF[i][j])
2067             anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
2068           else
2069             throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
2070         }
2071     }
2072   MEDFileField1TSStructItem ret(atype,anItems);
2073   try
2074     {
2075       ret.checkWithMeshStruct(meshSt,ref);
2076     }
2077   catch(INTERP_KERNEL::Exception& e)
2078     {
2079       std::ostringstream oss; oss << e.what() << " (" << MEDCouplingFieldDiscretization::GetTypeOfFieldRepr(ret.getType()) << ")";
2080       throw INTERP_KERNEL::Exception(oss.str().c_str());
2081     }
2082   return ret;
2083 }
2084
2085 //=
2086
2087 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
2088 {
2089   return new MEDFileField1TSStruct(ref,mst);
2090 }
2091
2092 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
2093 {
2094   _already_checked.push_back(MEDFileField1TSStructItem::BuildItemFrom(ref,mst));
2095 }
2096
2097 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
2098 {
2099   if(_already_checked.empty())
2100     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
2101   _already_checked.back().checkWithMeshStruct(mst,globs);
2102 }
2103
2104 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const
2105 {
2106   MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,mst));
2107   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2108     {
2109       if((*it)==b)
2110         return true;
2111     }
2112   return false;
2113 }
2114
2115 /*!
2116  * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
2117  */
2118 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
2119 {
2120   if(_already_checked.empty())
2121     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
2122   MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
2123   if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
2124     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
2125   MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other));
2126   int found=-1,i=0;
2127   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2128     if((*it).isComputed())
2129       { found=i; break; }
2130   bool ret(false);
2131   if(found==-1)
2132     {
2133       MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
2134       ret=this1.isCellSupportEqual(other1,other);
2135       if(ret)
2136         _already_checked.push_back(this1);
2137     }
2138   else
2139     ret=_already_checked[found].isCellSupportEqual(other1,other);
2140   if(ret)
2141     _already_checked.push_back(b);
2142   return ret;
2143 }
2144
2145 /*!
2146  * \param [in] other - a field with only one spatial discretization : ON_NODES.
2147  */
2148 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
2149 {
2150   if(_already_checked.empty())
2151     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
2152   MEDFileField1TSStructItem other1(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
2153   if(_already_checked[0].isEntityCell())
2154     {
2155       int found=-1,i=0;
2156       for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2157         if((*it).isComputed())
2158           { found=i; break; }
2159       bool ret(false);
2160       if(found==-1)
2161         {
2162           MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
2163           ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other);
2164           if(ret)
2165             _already_checked.push_back(this1);
2166         }
2167       else
2168         ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other);
2169       if(ret)
2170         _already_checked.push_back(other1);
2171       return ret;
2172     }
2173   else
2174     return _already_checked[0].isNodeSupportEqual(other1,other);
2175 }
2176
2177 std::size_t MEDFileField1TSStruct::getHeapMemorySizeWithoutChildren() const
2178 {
2179   std::size_t ret(_already_checked.capacity()*sizeof(MEDFileField1TSStructItem));
2180   return ret;
2181 }
2182
2183 std::vector<const BigMemoryObject *> MEDFileField1TSStruct::getDirectChildrenWithNull() const
2184 {
2185   std::vector<const BigMemoryObject *> ret;
2186   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2187     ret.push_back(&(*it));
2188   return ret;
2189 }
2190
2191 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
2192 {
2193   if(_already_checked.empty())
2194     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
2195   int pos0(-1),pos1(-1);
2196   if(presenceOfCellDiscr(pos0))
2197     {
2198       MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
2199       if(presenceOfPartialNodeDiscr(pos1))
2200         ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
2201       return ret.retn();
2202     }
2203   else
2204     {
2205       if(!presenceOfPartialNodeDiscr(pos1))
2206         {//we have only all nodes, no cell definition info -> all existing levels !;
2207           return MEDMeshMultiLev::New(mst->getTheMesh(),mst->getTheMesh()->getNonEmptyLevels());
2208         }
2209       else
2210         return MEDMeshMultiLev::NewOnlyOnNode(mst->getTheMesh(),_already_checked[pos1][0].getPfl(globs));
2211     }
2212 }
2213
2214 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const
2215 {
2216   int b0,b1;
2217   bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
2218   int d0,d1;
2219   bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1)); 
2220   if(a0!=c0 || a1!=c1)
2221     return false;
2222   if(a0)
2223     if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
2224       return false;
2225   if(a1)
2226     if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
2227       return false;
2228   return true;
2229 }
2230
2231 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStruct::getGeoTypes(const MEDFileMesh *m) const
2232 {
2233   std::vector<INTERP_KERNEL::NormalizedCellType> ret;
2234   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2235     {
2236       std::vector<INTERP_KERNEL::NormalizedCellType> ret2((*it).getGeoTypes(m));
2237       for(std::vector<INTERP_KERNEL::NormalizedCellType>::const_iterator it2=ret2.begin();it2!=ret2.end();it2++)
2238         {
2239           if(*it2==INTERP_KERNEL::NORM_ERROR)
2240             continue;
2241           std::vector<INTERP_KERNEL::NormalizedCellType>::iterator it3(std::find(ret.begin(),ret.end(),*it2));
2242           if(it3==ret.end())
2243             ret.push_back(*it2);
2244         }
2245     }
2246   return ret;
2247 }
2248
2249 /*!
2250  * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
2251  * If true is returned the pos of the easiest is returned. The easiest is the first element in \a this having the less splitted subparts.
2252  */
2253 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const
2254 {
2255   std::size_t refSz(std::numeric_limits<std::size_t>::max());
2256   bool ret(false);
2257   int i(0);
2258   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2259     {
2260       if((*it).getType()!=ON_NODES)
2261         {
2262           ret=true;
2263           std::size_t sz((*it).getNumberOfItems());
2264           if(refSz>sz)
2265             { pos=i; refSz=sz; }
2266         }
2267     }
2268   if(refSz==0)
2269     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
2270   return ret;
2271 }
2272
2273 /*!
2274  * Returns true if presence in \a this of discretization ON_NODES.
2275  * If true is returned the pos of the first element containing the single subpart.
2276  */
2277 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const
2278 {
2279   int i(0);
2280   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2281     {
2282       if((*it).getType()==ON_NODES)
2283         {
2284           std::size_t sz((*it).getNumberOfItems());
2285           if(sz==1)
2286             {
2287               if(!(*it)[0].getPflName().empty())
2288                 { pos=i; return true; }
2289             }
2290           else
2291             throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
2292         }
2293     }
2294   return false;
2295 }
2296
2297 //=
2298
2299 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2300 {
2301   return new MEDFileFastCellSupportComparator(m,ref);
2302 }
2303
2304 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2305 {
2306   if(!m)
2307     throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
2308   _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
2309   int nbPts=ref->getNumberOfTS();
2310   _f1ts_cmps.resize(nbPts);
2311   for(int i=0;i<nbPts;i++)
2312     {
2313       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
2314       try
2315         {
2316           _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
2317           _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt);
2318         }
2319       catch(INTERP_KERNEL::Exception& e)
2320         {
2321           std::ostringstream oss; oss << "Problem in field with name \"" << ref->getName() << "\"" << std::endl;
2322           oss << "More Details : " << e.what();
2323           throw INTERP_KERNEL::Exception(oss.str().c_str());
2324         }
2325     }
2326 }
2327
2328 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySizeWithoutChildren() const
2329 {
2330   std::size_t ret(_f1ts_cmps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct>));
2331   return ret;
2332 }
2333
2334 std::vector<const BigMemoryObject *> MEDFileFastCellSupportComparator::getDirectChildrenWithNull() const
2335 {
2336   std::vector<const BigMemoryObject *> ret;
2337   const MEDFileMeshStruct *mst(_mesh_comp);
2338   if(mst)
2339     ret.push_back(mst);
2340   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
2341     ret.push_back((const MEDFileField1TSStruct *)*it);
2342   return ret;
2343 }
2344
2345 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other)
2346 {
2347   int nbPts=other->getNumberOfTS();
2348   if(nbPts!=(int)_f1ts_cmps.size())
2349     {
2350       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in  input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2351       throw INTERP_KERNEL::Exception(oss.str().c_str());
2352     }
2353   for(int i=0;i<nbPts;i++)
2354     {
2355       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2356       if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
2357         if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
2358           return false;
2359     }
2360   return true;
2361 }
2362
2363 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other)
2364 {
2365   int nbPts=other->getNumberOfTS();
2366   if(nbPts!=(int)_f1ts_cmps.size())
2367     {
2368       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in  input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2369       throw INTERP_KERNEL::Exception(oss.str().c_str());
2370     }
2371   for(int i=0;i<nbPts;i++)
2372     {
2373       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2374       if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
2375         return false;
2376     }
2377   return true;
2378 }
2379
2380 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2381 {
2382   if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2383     {
2384       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2385       throw INTERP_KERNEL::Exception(oss.str().c_str());
2386     }
2387   const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2388   if(!obj)
2389     {
2390       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
2391       throw INTERP_KERNEL::Exception(oss.str().c_str());
2392     }
2393   return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
2394 }
2395
2396 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2397 {
2398   if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
2399     {
2400       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
2401       throw INTERP_KERNEL::Exception(oss.str().c_str());
2402     }
2403   const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2404   const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
2405   return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);
2406 }
2407
2408 int MEDFileFastCellSupportComparator::getNumberOfTS() const
2409 {
2410   return _f1ts_cmps.size();
2411 }
2412
2413 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileFastCellSupportComparator::getGeoTypesAt(int timeStepId, const MEDFileMesh *m) const
2414 {
2415   if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2416     {
2417       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2418       throw INTERP_KERNEL::Exception(oss.str().c_str());
2419     }
2420   const MEDFileField1TSStruct *elt(_f1ts_cmps[timeStepId]);
2421   if(!elt)
2422     {
2423       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " points to a NULL pointer !";
2424       throw INTERP_KERNEL::Exception(oss.str().c_str());
2425     }
2426   return elt->getGeoTypes(m);
2427 }