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