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