Salome HOME
Bug correction of families on faces for cartesian meshes.
[tools/medcoupling.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, const std::vector<int>& lev):MEDMeshMultiLev(m),_is_internal(true)
1186 {
1187   initStdFieldOfIntegers(m);
1188 }
1189
1190 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)
1191 {
1192   initStdFieldOfIntegers(m);
1193 }
1194
1195 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other),_is_internal(true),_face_fam_ids(other._face_fam_ids),_face_fam_ids_nocpy(other._face_fam_ids_nocpy),_face_num_ids(other._face_num_ids),_face_num_ids_nocpy(other._face_num_ids_nocpy)
1196 {
1197 }
1198
1199 void MEDStructuredMeshMultiLev::initStdFieldOfIntegers(const MEDFileStructuredMesh *m)
1200 {
1201   // ids fields management
1202   _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
1203   const DataArrayInt *tmp(0);
1204   tmp=m->getFamilyFieldAtLevel(0);
1205   if(tmp)
1206     {
1207       tmp->incrRef();
1208       _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1209     }
1210   tmp=m->getNumberFieldAtLevel(0);
1211   if(tmp)
1212     {
1213       tmp->incrRef();
1214       _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1215     }
1216   //
1217   _node_fam_ids_nocpy=true; _node_num_ids_nocpy=true;
1218   tmp=0;
1219   tmp=m->getFamilyFieldAtLevel(1);
1220   if(tmp)
1221     {
1222       tmp->incrRef();
1223       _node_fam_ids=const_cast<DataArrayInt *>(tmp);
1224     }
1225   tmp=m->getNumberFieldAtLevel(1);
1226   if(tmp)
1227     {
1228       tmp->incrRef();
1229       _node_num_ids=const_cast<DataArrayInt *>(tmp);
1230     }
1231   // faces (if any)
1232   _face_fam_ids_nocpy=true; _face_num_ids_nocpy=true;
1233   tmp=m->getFamilyFieldAtLevel(-1);
1234   if(tmp)
1235     {
1236       tmp->incrRef();
1237       _face_fam_ids=const_cast<DataArrayInt *>(tmp);
1238     }
1239   tmp=m->getNumberFieldAtLevel(-1);
1240   if(tmp)
1241     {
1242       tmp->incrRef();
1243       _face_num_ids=const_cast<DataArrayInt *>(tmp);
1244     }
1245 }
1246
1247 void MEDStructuredMeshMultiLev::moveFaceToCell() const
1248 {
1249   const_cast<MEDStructuredMeshMultiLev *>(this)->_cell_fam_ids_nocpy=_face_fam_ids_nocpy;
1250   const_cast<MEDStructuredMeshMultiLev *>(this)->_cell_num_ids_nocpy=_face_num_ids_nocpy;
1251   const_cast<MEDStructuredMeshMultiLev *>(this)->_cell_fam_ids=_face_fam_ids; const_cast<MEDStructuredMeshMultiLev *>(this)->_face_fam_ids=0;
1252   const_cast<MEDStructuredMeshMultiLev *>(this)->_cell_num_ids=_face_num_ids; const_cast<MEDStructuredMeshMultiLev *>(this)->_face_num_ids=0;
1253 }
1254
1255 bool MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase(MEDMeshMultiLev *&ret) const
1256 {
1257   ret=0;
1258   if(_geo_types.empty())
1259     return false;
1260   if(_geo_types.size()!=1)
1261     throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase only one geo types supported at most supported for the moment !");
1262   INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(_mesh->getMeshDimension()));
1263   if(_geo_types[0]==gt)
1264     return false;
1265   MEDCoupling1GTUMesh *facesIfPresent((static_cast<const MEDFileStructuredMesh *>(_mesh))->getImplicitFaceMesh());
1266   if(!facesIfPresent)
1267     return false;
1268   const DataArrayInt *pfl(0),*nr(_node_reduction);
1269   if(!_pfls.empty())
1270     pfl=_pfls[0];
1271   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> facesIfPresent2(facesIfPresent); facesIfPresent->incrRef();
1272   moveFaceToCell();
1273   MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret2(new MEDUMeshMultiLev(*this,facesIfPresent2));
1274   if(pfl)
1275     ret2->setCellReduction(pfl);
1276   if(nr)
1277     throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase : case is not treated yet for node reduction on implicit unstructured mesh.");
1278   ret=ret2.retn();
1279   return true;
1280 }
1281
1282 void MEDStructuredMeshMultiLev::dealWithImplicitUnstructuredMesh(const MEDFileMesh *m)
1283 {
1284   _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
1285   const DataArrayInt *tmp(0);
1286   tmp=m->getFamilyFieldAtLevel(-1);
1287   if(tmp)
1288     {
1289       tmp->incrRef();
1290       _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1291     }
1292   tmp=m->getNumberFieldAtLevel(-1);
1293   if(tmp)
1294     {
1295       tmp->incrRef();
1296       _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1297     }
1298 }
1299
1300 void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
1301 {
1302   if(!pflNodes || !pflNodes->isAllocated())
1303     return ;
1304   std::vector<int> ngs(getNodeGridStructure());
1305   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
1306   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(ngs.size())));
1307   m->setNodalConnectivity(conn);
1308   const DataArrayInt *pfl(_pfls[0]);
1309   if(pfl)
1310     {
1311       m=dynamic_cast<MEDCoupling1SGTUMesh *>(m->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1312     }
1313   DataArrayInt *cellIds=0;
1314   m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
1315   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
1316   MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
1317   int tmp=-1;
1318   _node_reduction=m2->getNodeIdsInUse(tmp);
1319   if(pfl)
1320     _pfls[0]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
1321   else
1322     _pfls[0]=cellIdsSafe;
1323 }
1324
1325 //=
1326
1327 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs)
1328 {
1329   return new MEDCMeshMultiLev(m,levs);
1330 }
1331
1332 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
1333 {
1334   return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
1335 }
1336
1337 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1338 {
1339   if(!m)
1340     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
1341   if(levs.size()!=1 || levs[0]!=0)
1342     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
1343   int sdim(m->getSpaceDimension());
1344   _coords.resize(sdim);
1345   for(int i=0;i<sdim;i++)
1346     {
1347       DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1348       if(!elt)
1349         throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1350       elt->incrRef();
1351       _coords[i]=elt;
1352     }
1353 }
1354
1355 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)
1356 {
1357   if(!m)
1358     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
1359   if(gts.size()!=1 || pfls.size()!=1)
1360     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1361   int mdim(m->getMeshDimension());
1362   INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(mdim));
1363   if(gt==gts[0])
1364     {
1365       _coords.resize(mdim);
1366       for(int i=0;i<mdim;i++)
1367         {
1368           DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1369           if(!elt)
1370             throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1371           _coords[i]=elt; _coords[i]->incrRef();
1372         }
1373     }
1374   else
1375     dealWithImplicitUnstructuredMesh(m);
1376 }
1377
1378 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords)
1379 {
1380 }
1381
1382 std::vector<int> MEDCMeshMultiLev::getNodeGridStructure() const
1383 {
1384   std::vector<int> ret(_coords.size());
1385   for(std::size_t i=0;i<_coords.size();i++)
1386     ret[i]=_coords[i]->getNumberOfTuples();
1387   return ret;
1388 }
1389
1390 MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const
1391 {
1392   MEDMeshMultiLev *retSpecific(0);
1393   if(prepareForImplicitUnstructuredMeshCase(retSpecific))
1394     return retSpecific;
1395   const DataArrayInt *pfl(0),*nr(_node_reduction);
1396   if(!_pfls.empty())
1397     pfl=_pfls[0];
1398   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1399   std::vector<int> cgs,ngs(getNodeGridStructure());
1400   cgs.resize(ngs.size());
1401   std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1402   if(pfl)
1403     {
1404       std::vector< std::pair<int,int> > cellParts;
1405       MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret2;
1406       if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1407         {
1408           MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1409           ret->_is_internal=false;
1410           if(nr)
1411             { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1412           ret->_nb_entities[0]=pfl->getNumberOfTuples();
1413           ret->_pfls[0]=0;
1414           std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > coords(_coords.size());
1415           for(std::size_t i=0;i<_coords.size();i++)
1416             coords[i]=_coords[i]->selectByTupleId2(cellParts[i].first,cellParts[i].second+1,1);
1417           ret->_coords=coords;
1418           ret2=(MEDCMeshMultiLev *)ret; ret2->incrRef();
1419         }
1420       else
1421         {
1422           MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> m(MEDCouplingCMesh::New());
1423           for(std::size_t i=0;i<ngs.size();i++)
1424             m->setCoordsAt(i,_coords[i]);
1425           MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1426           MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1427           MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1428           if(nr)
1429             { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1430           ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1431         }
1432       const DataArrayInt *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1433       if(famIds)
1434         {
1435           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1436           ret2->setFamilyIdsOnCells(tmp,false);
1437         }
1438       if(numIds)
1439         {
1440           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1441           ret2->setNumberIdsOnCells(tmp,false);
1442         }
1443       return ret2.retn();
1444
1445     }
1446   else
1447     {
1448       MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1449       if(nr)
1450         { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1451       return ret.retn();
1452     }
1453 }
1454
1455 /*!
1456  * \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.
1457  */
1458 std::vector< DataArrayDouble * > MEDCMeshMultiLev::buildVTUArrays(bool& isInternal) const
1459 {
1460   isInternal=_is_internal;
1461   std::size_t sz(_coords.size());
1462   std::vector< DataArrayDouble * > ret(sz);
1463   for(std::size_t i=0;i<sz;i++)
1464     {
1465       ret[i]=const_cast<DataArrayDouble *>((const DataArrayDouble *)_coords[i]);
1466       ret[i]->incrRef();
1467     }
1468   return ret;
1469 }
1470
1471 //=
1472
1473 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1474 {
1475   return new MEDCurveLinearMeshMultiLev(m,levs);
1476 }
1477
1478 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
1479 {
1480   return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
1481 }
1482
1483 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1484 {
1485   if(!m)
1486     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
1487   if(levs.size()!=1 || levs[0]!=0)
1488     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
1489   DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1490   if(!coords)
1491     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1492   coords->incrRef();
1493   _coords=coords;
1494   _structure=m->getMesh()->getNodeGridStructure();
1495 }
1496
1497 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)
1498 {
1499   if(!m)
1500     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1501   if(gts.size()!=1 || pfls.size()!=1)
1502     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1503   INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1504   if(gt==gts[0])
1505     {
1506       DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1507       if(!coords)
1508         throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1509       coords->incrRef();
1510       _coords=coords;
1511       _structure=m->getMesh()->getNodeGridStructure();
1512     }
1513   else
1514     dealWithImplicitUnstructuredMesh(m);
1515 }
1516
1517 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure)
1518 {
1519 }
1520
1521 std::vector<int> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const
1522 {
1523   return _structure;
1524 }
1525
1526 MEDMeshMultiLev *MEDCurveLinearMeshMultiLev::prepare() const
1527 {
1528   MEDMeshMultiLev *retSpecific(0);
1529   if(prepareForImplicitUnstructuredMeshCase(retSpecific))
1530     return retSpecific;
1531   const DataArrayInt *pfl(0),*nr(_node_reduction);
1532   if(!_pfls.empty())
1533     pfl=_pfls[0];
1534   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1535   std::vector<int> cgs,ngs(getNodeGridStructure());
1536   cgs.resize(ngs.size());
1537   std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1538   if(pfl)
1539     {
1540       std::vector< std::pair<int,int> > cellParts,nodeParts;
1541       MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret2;
1542       if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1543         {
1544           nodeParts=cellParts;
1545           std::vector<int> st(ngs.size());
1546           for(std::size_t i=0;i<ngs.size();i++)
1547             {
1548               nodeParts[i].second++;
1549               st[i]=nodeParts[i].second-nodeParts[i].first;
1550             }
1551           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p(MEDCouplingStructuredMesh::BuildExplicitIdsFrom(ngs,nodeParts));
1552           MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1553           ret->_is_internal=false;
1554           if(nr)
1555             { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1556           ret->_nb_entities[0]=pfl->getNumberOfTuples();
1557           ret->_pfls[0]=0;
1558           ret->_coords=_coords->selectByTupleIdSafe(p->begin(),p->end());
1559           ret->_structure=st;
1560           ret2=(MEDCurveLinearMeshMultiLev *)ret; ret2->incrRef();
1561         }
1562       else
1563         {
1564           MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> m(MEDCouplingCurveLinearMesh::New());
1565           m->setCoords(_coords); m->setNodeGridStructure(&_structure[0],&_structure[0]+_structure.size());
1566           MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1567           MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1568           MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1569           if(nr)
1570             { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1571           ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1572         }
1573       const DataArrayInt *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1574       if(famIds)
1575         {
1576           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1577           ret2->setFamilyIdsOnCells(tmp,false);
1578         }
1579       if(numIds)
1580         {
1581           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1582           ret2->setNumberIdsOnCells(tmp,false);
1583         }
1584       return ret2.retn();
1585     }
1586   else
1587     {
1588       MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1589       if(nr)
1590         { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1591       return ret.retn();
1592     }
1593 }
1594
1595 void MEDCurveLinearMeshMultiLev::buildVTUArrays(DataArrayDouble *&coords, std::vector<int>& nodeStrct, bool& isInternal) const
1596 {
1597   isInternal=_is_internal;
1598   nodeStrct=_structure;
1599   const DataArrayDouble *coo(_coords);
1600   if(!coo)
1601     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev::buildVTUArrays : null pointer on coordinates !");
1602   coords=const_cast<DataArrayDouble *>(coo); coords->incrRef();
1603 }
1604
1605 //=
1606
1607 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2()
1608 {
1609 }
1610
1611 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)
1612 {
1613   _pfl->setName(c.c_str());
1614 }
1615
1616 void MEDFileField1TSStructItem2::checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1617 {
1618   if(!mst->doesManageGeoType(_geo_type))
1619     {
1620       MEDFileMeshStruct *mstUnConstCasted(const_cast<MEDFileMeshStruct *>(mst));
1621       mstUnConstCasted->appendIfImplicitType(_geo_type);
1622     }
1623   int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1624   checkInRange(nbOfEnt,1,globs);
1625 }
1626
1627 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1628 {
1629   int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1630   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1631   checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs);
1632 }
1633
1634 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1635 {
1636   if(!globs)
1637     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !");
1638   if(_loc.empty())
1639     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !");
1640   const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str());
1641   int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1642   checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs);
1643 }
1644
1645 int MEDFileField1TSStructItem2::getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const
1646 {
1647   if(_loc.empty())
1648     {
1649       if(getPflName().empty())
1650         return (_start_end.second-_start_end.first)/_nb_of_entity;
1651       else
1652         return (_start_end.second-_start_end.first)/getPfl(globs)->getNumberOfTuples();
1653     }
1654   else
1655     {
1656       const MEDFileFieldLoc& loc(globs->getLocalization(_loc.c_str()));
1657       return loc.getNumberOfGaussPoints();
1658     }
1659 }
1660
1661 std::string MEDFileField1TSStructItem2::getPflName() const
1662 {
1663   return _pfl->getName();
1664 }
1665
1666 const DataArrayInt *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const
1667 {
1668   if(!_pfl->isAllocated())
1669     {
1670       if(_pfl->getName().empty())
1671         return 0;
1672       else
1673         return globs->getProfile(_pfl->getName().c_str());
1674     }
1675   else
1676     return _pfl;
1677 }
1678
1679 /*!
1680  * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possiblity.
1681  * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES
1682  */
1683 void MEDFileField1TSStructItem2::checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs)
1684 {
1685   _nb_of_entity=nbOfEntity;
1686   if(_pfl->getName().empty())
1687     {
1688       if(nbOfEntity!=(_start_end.second-_start_end.first)/nip)
1689         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of node field !");
1690       return ;
1691     }
1692   else
1693     {
1694       if(!globs)
1695         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !");
1696       const DataArrayInt *pfl=globs->getProfile(_pfl->getName().c_str());
1697       if(!pfl)
1698         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !");
1699       pfl->checkAllIdsInRange(0,nbOfEntity);
1700     }
1701 }
1702
1703 bool MEDFileField1TSStructItem2::isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const std::string& pflName) const
1704 {
1705   if(startExp!=_start_end.first)
1706     return false;
1707   if(gt!=_geo_type)
1708     return false;
1709   if(getPflName()!=pflName)
1710     return false;
1711   startExp=_start_end.second;
1712   return true;
1713 }
1714
1715 bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const
1716 {
1717   //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
1718   //idem for _loc. It is not an effective attribute for support comparison.
1719   return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
1720 }
1721
1722 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1723 {
1724   if(_geo_type!=other._geo_type)
1725     return false;
1726   if(_nb_of_entity!=other._nb_of_entity)
1727     return false;
1728   if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
1729     return false;
1730   if(_pfl->getName().empty() && other._pfl->getName().empty())
1731     return true;
1732   const DataArrayInt *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
1733   return pfl1->isEqualWithoutConsideringStr(*pfl2);
1734 }
1735
1736 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1737 {
1738   return isCellSupportEqual(other,globs);
1739 }
1740
1741 /*!
1742  * \a objs must be non empty. \a objs should contain items having same geometric type.
1743  */
1744 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs)
1745 {
1746   if(objs.empty())
1747     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
1748   if(objs.size()==1)
1749     return MEDFileField1TSStructItem2(*objs[0]);
1750   INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
1751   int nbEntityRef(objs[0]->_nb_of_entity);
1752   std::size_t sz(objs.size());
1753   std::vector<const DataArrayInt *> arrs(sz);
1754   for(std::size_t i=0;i<sz;i++)
1755     {
1756       const MEDFileField1TSStructItem2 *obj(objs[i]);
1757       if(gt!=obj->_geo_type)
1758         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
1759       if(nbEntityRef!=obj->_nb_of_entity)
1760         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
1761       if(obj->_pfl->getName().empty())
1762         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
1763       arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
1764     }
1765   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::Aggregate(arrs));
1766   arr->sort();
1767   int oldNbTuples(arr->getNumberOfTuples());
1768   arr=arr->buildUnique();
1769   if(oldNbTuples!=arr->getNumberOfTuples())
1770     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
1771   if(arr->isIdentity() && oldNbTuples==nbEntityRef)
1772     {
1773       std::pair<int,int> p(0,nbEntityRef);
1774       std::string a,b;
1775       MEDFileField1TSStructItem2 ret(gt,p,a,b);
1776       ret._nb_of_entity=nbEntityRef;
1777       return ret;
1778     }
1779   else
1780     {
1781       arr->setName(NEWLY_CREATED_PFL_NAME);
1782       std::pair<int,int> p(0,oldNbTuples);
1783       std::string a,b;
1784       MEDFileField1TSStructItem2 ret(gt,p,a,b);
1785       ret._nb_of_entity=nbEntityRef;
1786       ret._pfl=arr;
1787       return ret;
1788     }
1789 }
1790
1791 std::size_t MEDFileField1TSStructItem2::getHeapMemorySizeWithoutChildren() const
1792 {
1793   std::size_t ret(_loc.capacity());
1794   return ret;
1795 }
1796
1797 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem2::getDirectChildren() const
1798 {
1799   std::vector<const BigMemoryObject *> ret;
1800   const DataArrayInt *pfl(_pfl);
1801   if(pfl)
1802     ret.push_back(pfl);
1803   return ret;
1804 }
1805
1806 //=
1807
1808 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
1809 {
1810 }
1811
1812 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1813 {
1814   switch(_type)
1815   {
1816     case ON_NODES:
1817       {
1818         int nbOfEnt=mst->getNumberOfNodes();
1819         if(_items.size()!=1)
1820           throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
1821         _items[0].checkInRange(nbOfEnt,1,globs);
1822         break ;
1823       }
1824     case ON_CELLS:
1825       {
1826         for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1827           (*it).checkWithMeshStructForCells(mst,globs);
1828         break;
1829       }
1830     case ON_GAUSS_NE:
1831       {
1832         for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1833           (*it).checkWithMeshStructForGaussNE(mst,globs);
1834         break;
1835       }
1836     case ON_GAUSS_PT:
1837       {
1838         for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1839           (*it).checkWithMeshStructForGaussPT(mst,globs);
1840         break;
1841       }
1842     default:
1843       throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
1844   }
1845 }
1846
1847 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const
1848 {
1849   if(_type!=other._type)
1850     return false;
1851   if(_items.size()!=other._items.size())
1852     return false;
1853   for(std::size_t i=0;i<_items.size();i++)
1854     if(!(_items[i]==other._items[i]))
1855       return false;
1856   return true;
1857 }
1858
1859 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1860 {
1861   if(_type!=other._type)
1862     return false;
1863   if(_items.size()!=other._items.size())
1864     return false;
1865   for(std::size_t i=0;i<_items.size();i++)
1866     if(!(_items[i].isCellSupportEqual(other._items[i],globs)))
1867       return false;
1868   return true;
1869 }
1870
1871 bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1872 {
1873   if(_type!=other._type)
1874     return false;
1875   if(_items.size()!=other._items.size())
1876     return false;
1877   for(std::size_t i=0;i<_items.size();i++)
1878     if(!(_items[i].isNodeSupportEqual(other._items[i],globs)))
1879       return false;
1880   return true;
1881 }
1882
1883 bool MEDFileField1TSStructItem::isEntityCell() const
1884 {
1885   if(_type==ON_NODES)
1886     return false;
1887   else
1888     return true;
1889 }
1890
1891 class CmpGeo
1892 {
1893 public:
1894   CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
1895   bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
1896 private:
1897   INTERP_KERNEL::NormalizedCellType _geo_type;
1898 };
1899
1900 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const
1901 {
1902   if(!isEntityCell())
1903     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
1904   std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
1905   std::size_t i=0;
1906   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1907     {
1908       std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
1909       if(it0==m.end())
1910         m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
1911       else
1912         (*it0).second.push_back(i);
1913     }
1914   if(m.size()==_items.size())
1915     {
1916       MEDFileField1TSStructItem ret(*this);
1917       ret._type=ON_CELLS;
1918       return ret;
1919     }
1920   std::size_t sz(m.size());
1921   std::vector< MEDFileField1TSStructItem2 > items(sz);
1922   for(i=0;i<sz;i++)
1923     {
1924       const std::vector<std::size_t>& ids=m[i].second;
1925       std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
1926       for(std::size_t j=0;j<ids.size();j++)
1927         objs[j]=&_items[ids[j]];
1928       items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
1929     }
1930   MEDFileField1TSStructItem ret(ON_CELLS,items);
1931   ret._computed=true;
1932   return ret;
1933 }
1934
1935 /*!
1936  * \a this is expected to be ON_CELLS and simplified.
1937  */
1938 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const
1939 {
1940   if(other._type!=ON_NODES)
1941     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
1942   if(other._items.size()!=1)
1943     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
1944   int theFirstLevFull;
1945   bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
1946   const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
1947   if(otherNodeIt.getPflName().empty())
1948     {//on all nodes
1949       if(!ret0)
1950         return false;
1951       return theFirstLevFull==0;
1952     }
1953   else
1954     {
1955       const DataArrayInt *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
1956       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpyPfl(pfl->deepCpy());
1957       cpyPfl->sort();
1958       int nbOfNodes(meshSt->getNumberOfNodes());
1959       if(cpyPfl->isIdentity() && cpyPfl->getNumberOfTuples()==nbOfNodes)
1960         {//on all nodes also !
1961           if(!ret0)
1962             return false;
1963           return theFirstLevFull==0;
1964         }
1965       std::vector<bool> nodesFetched(nbOfNodes,false);
1966       meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1967       return cpyPfl->isFittingWith(nodesFetched);
1968     }
1969 }
1970
1971 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const
1972 {
1973   if(_type!=ON_CELLS)
1974     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
1975   if(_items.empty())
1976     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
1977   int nbOfLevs(meshSt->getNumberOfLevs());
1978   if(nbOfLevs==0)
1979     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
1980   std::vector<int> levs(nbOfLevs);
1981   theFirstLevFull=1;
1982   std::set<INTERP_KERNEL::NormalizedCellType> gts;
1983   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1984     {
1985       if(!(*it).getPflName().empty())
1986         return false;
1987       INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
1988       if(gts.find(gt)!=gts.end())
1989         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
1990       gts.insert(gt);
1991       int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
1992       levs[-pos]++;
1993     }
1994   for(int i=0;i<nbOfLevs;i++)
1995     if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
1996       { theFirstLevFull=-i; return true; }
1997   return false;
1998 }
1999
2000 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const
2001 {
2002   if(i>=_items.size())
2003     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
2004   return _items[i];
2005 }
2006
2007 std::size_t MEDFileField1TSStructItem::getHeapMemorySizeWithoutChildren() const
2008 {
2009   std::size_t ret(_items.size()*sizeof(MEDFileField1TSStructItem2));
2010   return ret;
2011 }
2012
2013 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem::getDirectChildren() const
2014 {
2015   std::vector<const BigMemoryObject *> ret;
2016   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
2017     ret.push_back(&(*it));
2018   return ret;
2019 }
2020
2021 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
2022 {
2023   std::size_t sz(_items.size());
2024   std::vector<INTERP_KERNEL::NormalizedCellType> a0(sz);
2025   std::vector<const DataArrayInt *> a1(sz);
2026   std::vector<int> a2(sz);
2027   std::size_t i(0);
2028   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
2029     {
2030       a0[i]=(*it).getGeo();
2031       a1[i]=(*it).getPfl(globs);
2032       a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
2033     }
2034   return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
2035 }
2036
2037 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStructItem::getGeoTypes(const MEDFileMesh *m) const
2038 {
2039   std::vector<INTERP_KERNEL::NormalizedCellType> ret;
2040   if(_type==ON_NODES)
2041     {
2042       if(!_items.empty() && _items[0].getPflName().empty())
2043         {
2044           if(m)
2045             return m->getAllGeoTypes();
2046           else
2047             return ret;
2048         }
2049       else
2050         return ret;
2051     }
2052   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
2053     {
2054       INTERP_KERNEL::NormalizedCellType elt((*it).getGeo());
2055       std::vector<INTERP_KERNEL::NormalizedCellType>::iterator it2(std::find(ret.begin(),ret.end(),elt));
2056       if(it2==ret.end())
2057         ret.push_back(elt);
2058     }
2059   return ret;
2060 }
2061
2062 MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
2063 {
2064   TypeOfField atype;
2065   std::vector< MEDFileField1TSStructItem2 > anItems;
2066   //
2067   std::vector< std::vector<std::string> > pfls,locs;
2068   std::vector< std::vector<TypeOfField> > typesF;
2069   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2070   std::vector< std::vector<std::pair<int,int> > > strtEnds=ref->getFieldSplitedByType(std::string(),geoTypes,typesF,pfls,locs);
2071   std::size_t nbOfGeoTypes(geoTypes.size());
2072   if(nbOfGeoTypes==0)
2073     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref  !");
2074   bool isFirst=true;
2075   for(std::size_t i=0;i<nbOfGeoTypes;i++)
2076     {
2077       std::size_t sz=typesF[i].size();
2078       if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
2079         throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
2080       //
2081       if(isFirst)
2082         atype=typesF[i][0];
2083       isFirst=false;
2084       //
2085       for(std::size_t j=0;j<sz;j++)
2086         {
2087           if(atype==typesF[i][j])
2088             anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
2089           else
2090             throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
2091         }
2092     }
2093   MEDFileField1TSStructItem ret(atype,anItems);
2094   ret.checkWithMeshStruct(meshSt,ref);
2095   return ret;
2096 }
2097
2098 //=
2099
2100 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
2101 {
2102   return new MEDFileField1TSStruct(ref,mst);
2103 }
2104
2105 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
2106 {
2107   _already_checked.push_back(MEDFileField1TSStructItem::BuildItemFrom(ref,mst));
2108 }
2109
2110 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
2111 {
2112   if(_already_checked.empty())
2113     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
2114   _already_checked.back().checkWithMeshStruct(mst,globs);
2115 }
2116
2117 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const
2118 {
2119   MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,mst));
2120   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2121     {
2122       if((*it)==b)
2123         return true;
2124     }
2125   return false;
2126 }
2127
2128 /*!
2129  * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
2130  */
2131 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
2132 {
2133   if(_already_checked.empty())
2134     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
2135   MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
2136   if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
2137     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
2138   MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other));
2139   int found=-1,i=0;
2140   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2141     if((*it).isComputed())
2142       { found=i; break; }
2143   bool ret(false);
2144   if(found==-1)
2145     {
2146       MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
2147       ret=this1.isCellSupportEqual(other1,other);
2148       if(ret)
2149         _already_checked.push_back(this1);
2150     }
2151   else
2152     ret=_already_checked[found].isCellSupportEqual(other1,other);
2153   if(ret)
2154     _already_checked.push_back(b);
2155   return ret;
2156 }
2157
2158 /*!
2159  * \param [in] other - a field with only one spatial discretization : ON_NODES.
2160  */
2161 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
2162 {
2163   if(_already_checked.empty())
2164     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
2165   MEDFileField1TSStructItem other1(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
2166   if(_already_checked[0].isEntityCell())
2167     {
2168       int found=-1,i=0;
2169       for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2170         if((*it).isComputed())
2171           { found=i; break; }
2172       bool ret(false);
2173       if(found==-1)
2174         {
2175           MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
2176           ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other);
2177           if(ret)
2178             _already_checked.push_back(this1);
2179         }
2180       else
2181         ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other);
2182       if(ret)
2183         _already_checked.push_back(other1);
2184       return ret;
2185     }
2186   else
2187     return _already_checked[0].isNodeSupportEqual(other1,other);
2188 }
2189
2190 std::size_t MEDFileField1TSStruct::getHeapMemorySizeWithoutChildren() const
2191 {
2192   std::size_t ret(_already_checked.capacity()*sizeof(MEDFileField1TSStructItem));
2193   return ret;
2194 }
2195
2196 std::vector<const BigMemoryObject *> MEDFileField1TSStruct::getDirectChildren() const
2197 {
2198   std::vector<const BigMemoryObject *> ret;
2199   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2200     ret.push_back(&(*it));
2201   return ret;
2202 }
2203
2204 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
2205 {
2206   if(_already_checked.empty())
2207     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
2208   int pos0(-1),pos1(-1);
2209   if(presenceOfCellDiscr(pos0))
2210     {
2211       MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
2212       if(presenceOfPartialNodeDiscr(pos1))
2213         ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
2214       return ret.retn();
2215     }
2216   else
2217     {
2218       if(!presenceOfPartialNodeDiscr(pos1))
2219         {//we have only all nodes, no cell definition info -> all existing levels !;
2220           return MEDMeshMultiLev::New(mst->getTheMesh(),mst->getTheMesh()->getNonEmptyLevels());
2221         }
2222       else
2223         return MEDMeshMultiLev::NewOnlyOnNode(mst->getTheMesh(),_already_checked[pos1][0].getPfl(globs));
2224     }
2225 }
2226
2227 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const
2228 {
2229   int b0,b1;
2230   bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
2231   int d0,d1;
2232   bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1)); 
2233   if(a0!=c0 || a1!=c1)
2234     return false;
2235   if(a0)
2236     if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
2237       return false;
2238   if(a1)
2239     if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
2240       return false;
2241   return true;
2242 }
2243
2244 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStruct::getGeoTypes(const MEDFileMesh *m) const
2245 {
2246   std::vector<INTERP_KERNEL::NormalizedCellType> ret;
2247   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2248     {
2249       std::vector<INTERP_KERNEL::NormalizedCellType> ret2((*it).getGeoTypes(m));
2250       for(std::vector<INTERP_KERNEL::NormalizedCellType>::const_iterator it2=ret2.begin();it2!=ret2.end();it2++)
2251         {
2252           if(*it2==INTERP_KERNEL::NORM_ERROR)
2253             continue;
2254           std::vector<INTERP_KERNEL::NormalizedCellType>::iterator it3(std::find(ret.begin(),ret.end(),*it2));
2255           if(it3==ret.end())
2256             ret.push_back(*it2);
2257         }
2258     }
2259   return ret;
2260 }
2261
2262 /*!
2263  * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
2264  * 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.
2265  */
2266 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const
2267 {
2268   std::size_t refSz(std::numeric_limits<std::size_t>::max());
2269   bool ret(false);
2270   int i(0);
2271   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2272     {
2273       if((*it).getType()!=ON_NODES)
2274         {
2275           ret=true;
2276           std::size_t sz((*it).getNumberOfItems());
2277           if(refSz>sz)
2278             { pos=i; refSz=sz; }
2279         }
2280     }
2281   if(refSz==0)
2282     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
2283   return ret;
2284 }
2285
2286 /*!
2287  * Returns true if presence in \a this of discretization ON_NODES.
2288  * If true is returned the pos of the first element containing the single subpart.
2289  */
2290 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const
2291 {
2292   int i(0);
2293   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2294     {
2295       if((*it).getType()==ON_NODES)
2296         {
2297           std::size_t sz((*it).getNumberOfItems());
2298           if(sz==1)
2299             {
2300               if(!(*it)[0].getPflName().empty())
2301                 { pos=i; return true; }
2302             }
2303           else
2304             throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
2305         }
2306     }
2307   return false;
2308 }
2309
2310 //=
2311
2312 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2313 {
2314   return new MEDFileFastCellSupportComparator(m,ref);
2315 }
2316
2317 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2318 {
2319   if(!m)
2320     throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
2321   _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
2322   int nbPts=ref->getNumberOfTS();
2323   _f1ts_cmps.resize(nbPts);
2324   for(int i=0;i<nbPts;i++)
2325     {
2326       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
2327       _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
2328       _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt);
2329     }
2330 }
2331
2332 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySizeWithoutChildren() const
2333 {
2334   std::size_t ret(_f1ts_cmps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct>));
2335   return ret;
2336 }
2337
2338 std::vector<const BigMemoryObject *> MEDFileFastCellSupportComparator::getDirectChildren() const
2339 {
2340   std::vector<const BigMemoryObject *> ret;
2341   const MEDFileMeshStruct *mst(_mesh_comp);
2342   if(mst)
2343     ret.push_back(mst);
2344   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
2345     {
2346       const MEDFileField1TSStruct *cur(*it);
2347       if(cur)
2348         ret.push_back(cur);
2349     }
2350   return ret;
2351 }
2352
2353 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other)
2354 {
2355   int nbPts=other->getNumberOfTS();
2356   if(nbPts!=(int)_f1ts_cmps.size())
2357     {
2358       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in  input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2359       throw INTERP_KERNEL::Exception(oss.str().c_str());
2360     }
2361   for(int i=0;i<nbPts;i++)
2362     {
2363       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2364       if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
2365         if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
2366           return false;
2367     }
2368   return true;
2369 }
2370
2371 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other)
2372 {
2373   int nbPts=other->getNumberOfTS();
2374   if(nbPts!=(int)_f1ts_cmps.size())
2375     {
2376       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in  input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2377       throw INTERP_KERNEL::Exception(oss.str().c_str());
2378     }
2379   for(int i=0;i<nbPts;i++)
2380     {
2381       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2382       if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
2383         return false;
2384     }
2385   return true;
2386 }
2387
2388 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2389 {
2390   if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2391     {
2392       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2393       throw INTERP_KERNEL::Exception(oss.str().c_str());
2394     }
2395   const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2396   if(!obj)
2397     {
2398       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
2399       throw INTERP_KERNEL::Exception(oss.str().c_str());
2400     }
2401   return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
2402 }
2403
2404 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2405 {
2406   if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
2407     {
2408       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
2409       throw INTERP_KERNEL::Exception(oss.str().c_str());
2410     }
2411   const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2412   const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
2413   return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);
2414 }
2415
2416 int MEDFileFastCellSupportComparator::getNumberOfTS() const
2417 {
2418   return _f1ts_cmps.size();
2419 }
2420
2421 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileFastCellSupportComparator::getGeoTypesAt(int timeStepId, const MEDFileMesh *m) const
2422 {
2423   if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2424     {
2425       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2426       throw INTERP_KERNEL::Exception(oss.str().c_str());
2427     }
2428   const MEDFileField1TSStruct *elt(_f1ts_cmps[timeStepId]);
2429   if(!elt)
2430     {
2431       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " points to a NULL pointer !";
2432       throw INTERP_KERNEL::Exception(oss.str().c_str());
2433     }
2434   return elt->getGeoTypes(m);
2435 }