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