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