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