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