Salome HOME
f219d829d022c1a794ac89645c5ce08c0f9542d5
[tools/medcoupling.git] / src / MEDLoader / MEDFileFieldOverView.cxx
1 // Copyright (C) 2007-2013  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.
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,255,4};
31
32 const char MEDFileField1TSStructItem2::NEWLY_CREATED_PFL_NAME[]="???";
33
34 MEDFileMeshStruct *MEDFileMeshStruct::New(const MEDFileMesh *mesh)
35 {
36   return new MEDFileMeshStruct(mesh);
37 }
38
39 std::size_t MEDFileMeshStruct::getHeapMemorySizeWithoutChildren() const
40 {
41   std::size_t ret(0);
42   for(std::vector< std::vector<int> >::const_iterator it0=_geo_types_distrib.begin();it0!=_geo_types_distrib.end();it0++)
43     ret+=(*it0).capacity()*sizeof(int);
44   ret+=_geo_types_distrib.capacity()*sizeof(std::vector<int>);
45   return ret;
46 }
47
48 std::vector<const BigMemoryObject *> MEDFileMeshStruct::getDirectChildren() const
49 {
50   return std::vector<const BigMemoryObject *>();
51 }
52
53 MEDFileMeshStruct::MEDFileMeshStruct(const MEDFileMesh *mesh):_mesh(mesh)
54 {
55   std::vector<int> levs=mesh->getNonEmptyLevels();
56   _name=mesh->getName();
57   _nb_nodes=mesh->getNumberOfNodes();
58   _geo_types_distrib.resize(levs.size());
59   for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
60     _geo_types_distrib[-(*lev)]=mesh->getDistributionOfTypes(*lev);
61 }
62
63 int MEDFileMeshStruct::getLevelOfGeoType(INTERP_KERNEL::NormalizedCellType t) const
64 {
65   int j=0;
66   for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++,j--)
67     {
68       std::size_t sz=(*it1).size();
69       if(sz%3!=0)
70         throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : internal error in code !");
71       std::size_t nbGeo=sz/3;
72       for(std::size_t i=0;i<nbGeo;i++)
73         if((*it1)[3*i]==(int)t)
74           return j;
75     }
76   throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : The specified geometric type is not present in the mesh structure !");
77 }
78
79 int MEDFileMeshStruct::getNumberOfElemsOfGeoType(INTERP_KERNEL::NormalizedCellType t) const
80 {
81   for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++)
82     {
83       std::size_t sz=(*it1).size();
84       if(sz%3!=0)
85         throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfElemsOfGeoType : internal error in code !");
86       std::size_t nbGeo=sz/3;
87       for(std::size_t i=0;i<nbGeo;i++)
88         if((*it1)[3*i]==(int)t)
89           return (*it1)[3*i+1];
90     }
91   throw INTERP_KERNEL::Exception("The specified geometric type is not present in the mesh structure !");
92 }
93
94 int MEDFileMeshStruct::getNumberOfLevs() const
95 {
96   return (int)_geo_types_distrib.size();
97 }
98
99 int MEDFileMeshStruct::getNumberOfGeoTypesInLev(int relativeLev) const
100 {
101   int pos(-relativeLev);
102   if(pos<0 || pos>=(int)_geo_types_distrib.size())
103     throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : invalid level specified !");
104   std::size_t sz=_geo_types_distrib[pos].size();
105   if(sz%3!=0)
106     throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : internal error in code !");
107   return (int)(sz/3);
108 }
109
110 //=
111
112 std::size_t MEDMeshMultiLev::getHeapMemorySizeWithoutChildren() const
113 {
114   return 0;
115 }
116
117 std::vector<const BigMemoryObject *> MEDMeshMultiLev::getDirectChildren() const
118 {
119   return std::vector<const BigMemoryObject *>();
120 }
121
122 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<int>& levs)
123 {
124   if(!m)
125     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : null input pointer !");
126   const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
127   if(um)
128     return MEDUMeshMultiLev::New(um,levs);
129   const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
130   if(cm)
131     return MEDCMeshMultiLev::New(cm,levs);
132   const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
133   if(clm)
134     return MEDCurveLinearMeshMultiLev::New(clm,levs);
135   throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
136 }
137
138 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
139 {
140   if(!m)
141     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : null input pointer !");
142   const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
143   if(um)
144     return MEDUMeshMultiLev::New(um,gts,pfls,nbEntities);
145   const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
146   if(cm)
147     return MEDCMeshMultiLev::New(cm,gts,pfls,nbEntities);
148   const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
149   if(clm)
150     return MEDCurveLinearMeshMultiLev::New(clm,gts,pfls,nbEntities);
151   throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
152 }
153
154 MEDMeshMultiLev *MEDMeshMultiLev::NewOnlyOnNode(const MEDFileMesh *m, const DataArrayInt *pflOnNode)
155 {
156   std::vector<int> levs(1,0);
157   MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(MEDMeshMultiLev::New(m,levs));
158   ret->selectPartOfNodes(pflOnNode);
159   return ret.retn();
160 }
161
162 void MEDMeshMultiLev::setNodeReduction(const DataArrayInt *nr)
163 {
164   if(nr)
165     nr->incrRef();
166   _node_reduction=const_cast<DataArrayInt*>(nr);
167 }
168
169 bool MEDMeshMultiLev::isFastlyTheSameStruct(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs) const
170 {
171   if(fst.getType()==ON_NODES)
172     {
173       if(fst.getNumberOfItems()!=1)
174         throw INTERP_KERNEL::Exception("MEDMeshMultiLev::isFastlyTheSameStruct : unexpected situation for nodes !");
175       const MEDFileField1TSStructItem2& p(fst[0]);
176       std::string pflName(p.getPflName());
177       const DataArrayInt *nr(_node_reduction);
178       if(pflName.empty() && !nr)
179         return true;
180       if(pflName==nr->getName())
181         return true;
182       return false;
183     }
184   else
185     {
186       std::size_t sz(fst.getNumberOfItems());
187       if(sz!=_geo_types.size())
188         return false;
189       int strt(0);
190       for(std::size_t i=0;i<sz;i++)
191         {
192           const MEDFileField1TSStructItem2& p(fst[i]);
193           if(!p.isFastlyEqual(strt,_geo_types[i],getPflNameOfId(i).c_str()))
194             return false;
195         }
196       return true;
197     }
198 }
199
200 DataArray *MEDMeshMultiLev::buildDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
201 {
202   MEDCouplingAutoRefCountObjectPtr<DataArray> ret(const_cast<DataArray *>(vals)); ret->incrRef();
203   if(isFastlyTheSameStruct(fst,globs))
204     return ret.retn();
205   else
206     return constructDataArray(fst,globs,vals);
207 }
208
209 /*!
210  * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
211  * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure.
212  */
213 void MEDMeshMultiLev::retrieveFamilyIdsOnCells(DataArrayInt *& famIds, bool& isWithoutCopy) const
214 {
215   const DataArrayInt *fids(_cell_fam_ids);
216   if(!fids)
217     { famIds=0; isWithoutCopy=true; return ; }
218   std::size_t sz(_geo_types.size());
219   bool presenceOfPfls(false);
220   for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
221     {
222       const DataArrayInt *pfl(_pfls[i]);
223       if(pfl)
224         presenceOfPfls=true;
225     }
226   if(!presenceOfPfls)
227     { famIds=const_cast<DataArrayInt *>(fids); famIds->incrRef(); isWithoutCopy=_cell_fam_ids_nocpy; return ; }
228   //bad luck the slowest part
229   isWithoutCopy=false;
230   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > retSafe(sz);
231   std::vector< const DataArrayInt *> ret(sz);
232   int start(0);
233   for(std::size_t i=0;i<sz;i++)
234     {
235       const DataArrayInt *pfl(_pfls[i]);
236       int lgth(_nb_entities[i]);
237       if(pfl)
238         {
239           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(fids->selectByTupleId2(start,start+lgth,1));
240           retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
241         }
242       else
243         {
244           retSafe[i]=fids->selectByTupleId2(start,start+lgth,1);
245         }
246       ret[i]=retSafe[i];
247       start+=lgth;
248     }
249   famIds=DataArrayInt::Aggregate(ret);
250 }
251
252 /*!
253  * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
254  * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure.
255  */
256 void MEDMeshMultiLev::retrieveNumberIdsOnCells(DataArrayInt *& numIds, bool& isWithoutCopy) const
257 {
258   const DataArrayInt *nids(_cell_num_ids);
259   if(!nids)
260     { numIds=0; isWithoutCopy=true; return ; }
261   std::size_t sz(_geo_types.size());
262   bool presenceOfPfls(false);
263   for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
264     {
265       const DataArrayInt *pfl(_pfls[i]);
266       if(pfl)
267         presenceOfPfls=true;
268     }
269   if(!presenceOfPfls)
270     { numIds=const_cast<DataArrayInt *>(nids); numIds->incrRef(); isWithoutCopy=_cell_num_ids_nocpy; return ; }
271   //bad luck the slowest part
272   isWithoutCopy=false;
273   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > retSafe(sz);
274   std::vector< const DataArrayInt *> ret(sz);
275   int start(0);
276   for(std::size_t i=0;i<sz;i++)
277     {
278       const DataArrayInt *pfl(_pfls[i]);
279       int lgth(_nb_entities[i]);
280       if(pfl)
281         {
282           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(nids->selectByTupleId2(start,start+lgth,1));
283           retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
284         }
285       else
286         {
287           retSafe[i]=nids->selectByTupleId2(start,start+lgth,1);
288         }
289       ret[i]=retSafe[i];
290       start+=lgth;
291     }
292   numIds=DataArrayInt::Aggregate(ret);
293 }
294
295 std::string MEDMeshMultiLev::getPflNameOfId(int id) const
296 {
297   std::size_t sz(_pfls.size());
298   if(id<0 || id>=(int)sz)
299     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getPflNameOfId : invalid input id !");
300   const DataArrayInt *pfl(_pfls[id]);
301   if(!pfl)
302     return std::string("");
303   return pfl->getName();
304 }
305
306 /*!
307  * Returns the number of cells having geometric type \a t.
308  * The profiles are **NOT** taken into account here.
309  */
310 int MEDMeshMultiLev::getNumberOfCells(INTERP_KERNEL::NormalizedCellType t) const
311 {
312   std::size_t sz(_nb_entities.size());
313   for(std::size_t i=0;i<sz;i++)
314     if(_geo_types[i]==t)
315         return _nb_entities[i];
316   throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getNumberOfCells : not existing geometric type in this !");
317 }
318
319 int MEDMeshMultiLev::getNumberOfNodes() const
320 {
321   return _nb_nodes;
322 }
323
324 DataArray *MEDMeshMultiLev::constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
325 {
326   if(fst.getType()==ON_NODES)
327     {
328       if(fst.getNumberOfItems()!=1)
329         throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes !");
330       const MEDFileField1TSStructItem2& p(fst[0]);
331       std::string pflName(p.getPflName());
332       const DataArrayInt *nr(_node_reduction);
333       if(pflName.empty() && !nr)
334         return vals->deepCpy();
335       if(pflName.empty() && nr)
336          throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 2 !");
337       if(!pflName.empty() && nr)
338         {
339           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
340           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(nr->deepCpy());
341           p1->sort(true); p2->sort(true);
342           if(!p1->isEqualWithoutConsideringStr(*p2))
343             throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 3 !");
344           p1=DataArrayInt::FindPermutationFromFirstToSecond(globs->getProfile(pflName.c_str()),nr);
345           MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
346           ret->renumberInPlace(p1->begin());
347           return ret.retn();
348         }
349       if(!pflName.empty() && !nr)
350         {
351           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
352           p1->sort(true);
353           if(!p1->isIdentity() || p1->getNumberOfTuples()!=getNumberOfNodes())
354             throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 4 !");
355           MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
356           ret->renumberInPlace(globs->getProfile(pflName.c_str())->begin());
357           return ret.retn();
358         }
359       throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 5 !");
360     }
361   else
362     {
363       std::size_t sz(fst.getNumberOfItems());
364       std::set<INTERP_KERNEL::NormalizedCellType> s(_geo_types.begin(),_geo_types.end());
365       if(s.size()!=_geo_types.size())
366         throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 2 !");
367       std::vector< const DataArray *> arr(s.size());
368       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arrSafe(s.size());
369       int iii(0);
370       int nc(vals->getNumberOfComponents());
371       std::vector<std::string> compInfo(vals->getInfoOnComponents());
372       for(std::vector< INTERP_KERNEL::NormalizedCellType >::const_iterator it=_geo_types.begin();it!=_geo_types.end();it++,iii++)
373         {
374           const DataArrayInt *thisP(_pfls[iii]);
375           std::vector<const MEDFileField1TSStructItem2 *> ps;
376           for(std::size_t i=0;i<sz;i++)
377             {
378               const MEDFileField1TSStructItem2& p(fst[i]);
379               if(p.getGeo()==*it)
380                 ps.push_back(&p);
381             }
382           if(ps.empty())
383             throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 1 !");
384           if(ps.size()==1)
385             {
386               int nbi(ps[0]->getNbOfIntegrationPts(globs));
387               const DataArrayInt *otherP(ps[0]->getPfl(globs));
388               const std::pair<int,int>& strtStop(ps[0]->getStartStop());
389               MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
390               if(!thisP && !otherP)
391                 {
392                   arrSafe[iii]=ret; arr[iii]=ret;
393                   continue;
394                 }
395               if(thisP && otherP)
396                 {
397                   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->invertArrayN2O2O2N(getNumberOfCells(ps[0]->getGeo())));
398                   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(thisP->deepCpy());
399                   p2->transformWithIndArr(p1->begin(),p1->end());
400                   //p1=p2->getIdsNotEqual(-1);
401                   //p1=p2->selectByTupleIdSafe(p1->begin(),p1->end());
402                   ret->rearrange(nbi*nc); ret=ret->selectByTupleIdSafe(p2->begin(),p2->end()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
403                   arrSafe[iii]=ret; arr[iii]=ret;
404                   continue;
405                 }
406               if(!thisP && otherP)
407                 {
408                   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->deepCpy());
409                   p1->sort(true);
410                   p1->checkAllIdsInRange(0,getNumberOfCells(ps[0]->getGeo()));
411                   p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,p1);
412                   ret->rearrange(nbi*nc); ret->renumberInPlace(p1->begin()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
413                   arrSafe[iii]=ret; arr[iii]=ret;
414                   continue;
415                 }
416               throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 3 !");
417             }
418           else
419             {
420               std::vector< const DataArrayInt * >otherPS(ps.size());
421               std::vector< const DataArray * > arr2(ps.size());
422               std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arr2Safe(ps.size());
423               std::vector< const DataArrayInt * > nbis(ps.size());
424               std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > nbisSafe(ps.size());
425               int jj(0);
426               for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
427                 {
428                   int nbi((*it2)->getNbOfIntegrationPts(globs));
429                   const DataArrayInt *otherPfl((*it2)->getPfl(globs));
430                   const std::pair<int,int>& strtStop((*it2)->getStartStop());
431                   MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
432                   if(!otherPfl)
433                     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 4 !");
434                   arr2[jj]=ret2; arr2Safe[jj]=ret2; otherPS[jj]=otherPfl;
435                   nbisSafe[jj]=DataArrayInt::New(); nbisSafe[jj]->alloc(otherPfl->getNumberOfTuples(),1); nbisSafe[jj]->fillWithValue(nbi);
436                   nbis[jj]=nbisSafe[jj];
437                 }
438               MEDCouplingAutoRefCountObjectPtr<DataArray> arr3(DataArray::Aggregate(arr2));
439               MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherP(DataArrayInt::Aggregate(otherPS));
440               MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbis(DataArrayInt::Aggregate(nbis));
441               MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherPN(otherP->invertArrayN2O2O2N(getNumberOfCells(*it)));
442               MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1;
443               if(thisP)
444                 p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,thisP);
445               else
446                 p1=otherP->deepCpy();
447               MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbisN(zenbis->renumber(p1->begin()));
448               zenbisN->computeOffsets2();
449               jj=0;
450               for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
451                 {
452                   //int nbi((*it2)->getNbOfIntegrationPts(globs));
453                   const DataArrayInt *otherPfl((*it2)->getPfl(globs));
454                   const std::pair<int,int>& strtStop((*it2)->getStartStop());
455                   MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
456                   //
457                   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(otherPfl->deepCpy());
458                   p2->transformWithIndArr(otherPN->begin(),otherPN->end());
459                   p2->transformWithIndArr(p1->begin(),p1->end());
460                   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsN(p2->buildExplicitArrByRanges(zenbisN));
461                   arr3->setPartOfValuesBase3(ret2,idsN->begin(),idsN->end(),0,nc,1);
462                 }
463               arrSafe[iii]=arr3; arr[iii]=arr3;
464               continue;
465             }
466         }
467       return DataArray::Aggregate(arr);
468     }
469 }
470
471 MEDMeshMultiLev::MEDMeshMultiLev():_nb_nodes(0),_cell_fam_ids_nocpy(false)
472 {
473 }
474
475 MEDMeshMultiLev::MEDMeshMultiLev(int nbNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):_geo_types(gts),_nb_entities(nbEntities),_nb_nodes(nbNodes),_cell_fam_ids_nocpy(false),_cell_num_ids_nocpy(false)
476 {
477   std::size_t sz(_geo_types.size());
478   if(sz!=pfls.size() || sz!=nbEntities.size())
479     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
480   _pfls.resize(sz);
481   for(std::size_t i=0;i<sz;i++)
482     {
483       if(pfls[i])
484         pfls[i]->incrRef();
485       _pfls[i]=const_cast<DataArrayInt *>(pfls[i]);
486     }
487 }
488
489 MEDMeshMultiLev::MEDMeshMultiLev(const MEDMeshMultiLev& other):RefCountObject(other),_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)
490 {
491 }
492
493 //=
494
495 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs)
496 {
497   return new MEDUMeshMultiLev(m,levs);
498 }
499
500 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs)
501 {
502   if(!m)
503     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
504   std::vector<MEDCoupling1GTUMesh *> v;
505   for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
506     {
507       std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
508       v.insert(v.end(),vTmp.begin(),vTmp.end());
509     }
510   std::size_t sz(v.size());
511   _parts.resize(sz);
512   _pfls.resize(sz);
513   _geo_types.resize(sz);
514   _nb_entities.resize(sz);
515   for(std::size_t i=0;i<sz;i++)
516     {
517       MEDCoupling1GTUMesh *obj(v[i]);
518       if(obj)
519         obj->incrRef();
520       else
521         throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
522       _parts[i]=obj;
523       _geo_types[i]=obj->getCellModelEnum();
524       _nb_entities[i]=obj->getNumberOfCells();
525     }
526   // ids fields management
527   _cell_fam_ids_nocpy=(levs.size()==1);
528   if(_cell_fam_ids_nocpy)
529     {
530       const DataArrayInt *tmp(m->getFamilyFieldAtLevel(levs[0]));
531       if(tmp)
532         {
533           tmp->incrRef();
534           _cell_fam_ids=(const_cast<DataArrayInt *>(tmp));
535         }
536     }
537   else
538     {
539       std::vector<const DataArrayInt *> tmps(levs.size());
540       bool f(true);
541       for(std::size_t i=0;i<levs.size();i++)
542         {
543           tmps[i]=m->getFamilyFieldAtLevel(levs[i]);
544           if(!tmps[i])
545             f=false;
546         }
547       if(f)
548         _cell_fam_ids=DataArrayInt::Aggregate(tmps);
549     }
550   _cell_num_ids_nocpy=(levs.size()==1);
551   if(_cell_num_ids_nocpy)
552     {
553       const DataArrayInt *tmp(m->getNumberFieldAtLevel(levs[0]));
554       if(tmp)
555         {
556           tmp->incrRef();
557           _cell_num_ids=(const_cast<DataArrayInt *>(tmp));
558         }
559     }
560   else
561     {
562       std::vector<const DataArrayInt *> tmps(levs.size());
563       bool n(true);
564       for(std::size_t i=0;i<levs.size();i++)
565         {
566           tmps[i]=m->getNumberFieldAtLevel(levs[i]);
567           if(!tmps[i])
568             n=false;
569         }
570       if(n)
571         _cell_num_ids=DataArrayInt::Aggregate(tmps);
572     }
573 }
574
575 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
576 {
577   return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
578 }
579
580 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->getNumberOfNodes(),gts,pfls,nbEntities)
581 {
582   std::size_t sz(gts.size());
583   _parts.resize(sz);
584   for(std::size_t i=0;i<sz;i++)
585     {
586       MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
587       if(elt)
588         elt->incrRef();
589       _parts[i]=elt;
590     }
591   // ids fields management
592   _cell_fam_ids_nocpy=false;
593   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > famIdsSafe(sz);
594   std::vector<const DataArrayInt *> famIds(sz);
595   bool f(true);
596   for(std::size_t i=0;i<sz;i++)
597     {
598       famIdsSafe[i]=m->extractFamilyFieldOnGeoType(gts[i]);
599       famIds[i]=famIdsSafe[i];
600       if(!famIds[i])
601         f=false;
602     }
603   if(f)
604     _cell_fam_ids=DataArrayInt::Aggregate(famIds);
605   _cell_num_ids_nocpy=false;
606   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > numIdsSafe(sz);
607   std::vector<const DataArrayInt *> numIds(sz);
608   bool n(true);
609   for(std::size_t i=0;i<sz;i++)
610     {
611       numIdsSafe[i]=m->extractNumberFieldOnGeoType(gts[i]);
612       numIds[i]=numIdsSafe[i];
613       if(!numIds[i])
614         n=false;
615     }
616   if(n)
617     _cell_num_ids=DataArrayInt::Aggregate(numIds);
618 }
619
620 void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
621 {
622    if(!pflNodes || !pflNodes->isAllocated())
623      return ;
624    std::size_t sz(_parts.size());
625    std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a(sz);
626    std::vector< const DataArrayInt *> aa(sz);
627    for(std::size_t i=0;i<sz;i++)
628      {
629        
630        const DataArrayInt *pfl(_pfls[i]);
631        MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m(_parts[i]);
632        if(pfl)
633          m=dynamic_cast<MEDCoupling1GTUMesh *>(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
634        DataArrayInt *cellIds=0;
635        m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
636        MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
637        MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
638        int tmp=-1;
639        MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(m2->getNodeIdsInUse(tmp));
640        a[i]=o2n->invertArrayO2N2N2O(tmp); aa[i]=a[i];
641        if(pfl)
642          _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
643        else
644          _pfls[i]=cellIdsSafe;
645      }
646    _node_reduction=DataArrayInt::Aggregate(aa);
647    _node_reduction->sort(true);
648    _node_reduction=_node_reduction->buildUnique();
649 }
650
651 MEDMeshMultiLev *MEDUMeshMultiLev::prepare() const
652 {
653   return new MEDUMeshMultiLev(*this);
654 }
655
656 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDUMeshMultiLev& other):MEDMeshMultiLev(other),_parts(other._parts)
657 {
658 }
659
660 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>& part):MEDMeshMultiLev(other)
661 {
662   _parts.resize(1);
663   _parts[0]=part;
664   _geo_types.resize(1); _geo_types[0]=part->getCellModelEnum();
665   _nb_entities.resize(1); _nb_entities[0]=part->getNumberOfCells();
666   _pfls.resize(1); _pfls[0]=0;
667 }
668
669 /*! 
670  * 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.
671  * 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.
672  */
673 bool MEDUMeshMultiLev::buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayInt *&cellLocations, DataArrayInt *& cells, DataArrayInt *&faceLocations, DataArrayInt *&faces) const
674 {
675   if(_parts.empty())
676     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : empty array !");
677   if(!(const MEDCoupling1GTUMesh *)_parts[0])
678     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : first part is null !");
679   const DataArrayDouble *tmp(_parts[0]->getCoords());
680   if(!tmp)
681     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : the coordinates are null !");
682   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a(const_cast<DataArrayDouble *>(tmp)); tmp->incrRef();
683   int szBCE(0),szD(0),szF(0);
684   bool isPolyh(false);
685   int iii(0);
686   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
687     {
688       const MEDCoupling1GTUMesh *cur(*it);
689       if(!cur)
690         throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : a part is null !");
691       //
692       const DataArrayInt *pfl(_pfls[iii]);
693       MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
694       if(!pfl)
695         { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
696       else
697         { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
698       //
699       int curNbCells(cur->getNumberOfCells());
700       szBCE+=curNbCells;
701       if((*it)->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
702         szD+=cur->getNodalConnectivity()->getNumberOfTuples()+curNbCells;
703       else
704         {
705           isPolyh=true;
706           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp2(cur->computeEffectiveNbOfNodesPerCell());
707           szD+=tmp2->accumulate(0)+curNbCells;
708           szF+=2*curNbCells+cur->getNodalConnectivity()->getNumberOfTuples();
709         }
710     }
711   MEDCouplingAutoRefCountObjectPtr<DataArrayByte> b(DataArrayByte::New()); b->alloc(szBCE,1); char *bPtr(b->getPointer());
712   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(DataArrayInt::New()); c->alloc(szBCE,1); int *cPtr(c->getPointer());
713   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d(DataArrayInt::New()); d->alloc(szD,1); int *dPtr(d->getPointer());
714   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> e(DataArrayInt::New()),f(DataArrayInt::New()); int *ePtr(0),*fPtr(0);
715   if(isPolyh)
716     { e->alloc(szBCE,1); ePtr=e->getPointer(); f->alloc(szF,1); fPtr=f->getPointer(); }
717   int k(0);
718   iii=0;
719   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
720     {
721       const MEDCoupling1GTUMesh *cur(*it);
722       //
723       const DataArrayInt *pfl(_pfls[iii]);
724       MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
725       if(!pfl)
726         { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
727       else
728         { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
729       //
730       int curNbCells(cur->getNumberOfCells());
731       int gt((int)cur->getCellModelEnum());
732       if(gt<0 || gt>=PARAMEDMEM_2_VTKTYPE_LGTH)
733         throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : invalid geometric type !");
734       unsigned char gtvtk(PARAMEDMEM_2_VTKTYPE[gt]);
735       if(gtvtk==255)
736         throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : no VTK type for the requested INTERP_KERNEL geometric type !");
737       std::fill(bPtr,bPtr+curNbCells,gtvtk); bPtr+=curNbCells;
738       const MEDCoupling1SGTUMesh *scur(dynamic_cast<const MEDCoupling1SGTUMesh *>(cur));
739       const MEDCoupling1DGTUMesh *dcur(dynamic_cast<const MEDCoupling1DGTUMesh *>(cur));
740       const int *connPtr(cur->getNodalConnectivity()->begin());
741       if(!scur && !dcur)
742         throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : internal error !");
743       if(scur)
744         {
745           int nnpc(scur->getNumberOfNodesPerCell());
746           for(int i=0;i<curNbCells;i++,connPtr+=nnpc)
747             {
748               *dPtr++=nnpc;
749               dPtr=std::copy(connPtr,connPtr+nnpc,dPtr);
750               *cPtr=k+nnpc; k=*cPtr++;
751             }
752           if(isPolyh)
753             { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
754         }
755       else
756         {
757           const int *connIPtr(dcur->getNodalConnectivityIndex()->begin());
758           if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
759             {
760               for(int i=0;i<curNbCells;i++,connIPtr++)
761                 {
762                   *dPtr++=connIPtr[1]-connIPtr[0];
763                   dPtr=std::copy(connPtr+connIPtr[0],connPtr+connIPtr[1],dPtr);
764                   *cPtr=k+connIPtr[1]-connIPtr[0]; k=*cPtr++;
765                 }
766             }
767           else
768             {
769               for(int i=0;i<curNbCells;i++,connIPtr++)
770                 {
771                   std::set<int> s(connPtr+connIPtr[0],connPtr+connIPtr[1]); s.erase(-1);
772                   *dPtr++=(int)s.size();
773                   dPtr=std::copy(s.begin(),s.end(),dPtr);
774                   *cPtr=k+(int)s.size(); k=*cPtr++;
775                 }
776             }
777           if(isPolyh)
778             {
779               connIPtr=dcur->getNodalConnectivityIndex()->begin();
780               if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
781                 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
782               else
783                 {
784                   int kk(0);
785                   for(int i=0;i<curNbCells;i++,connIPtr++)
786                     {
787                       int nbFace(std::count(connPtr+connIPtr[0],connPtr+connIPtr[1],-1)+1);
788                       *fPtr++=nbFace;
789                       const int *work(connPtr+connIPtr[0]);
790                       for(int j=0;j<nbFace;j++)
791                         {
792                           const int *work2=std::find(work,connPtr+connIPtr[1],-1);
793                           *fPtr++=std::distance(work,work2);
794                           fPtr=std::copy(work,work2,fPtr);
795                           work=work2+1;
796                         }
797                       *ePtr++=kk; kk+=connIPtr[1]-connIPtr[0]+2;
798                     }
799                 }
800             }
801         }
802     }
803   if(!isPolyh)
804     reorderNodesIfNecessary(a,d,0);
805   else
806     reorderNodesIfNecessary(a,d,f);
807   if(a->getNumberOfComponents()!=3)
808     a=a->changeNbOfComponents(3,0.);
809   coords=a.retn(); types=b.retn(); cellLocations=c.retn(); cells=d.retn();
810   if(!isPolyh)
811     { faceLocations=0; faces=0; }
812   else
813     { faceLocations=e.retn(); faces=f.retn(); }
814   return tmp==((DataArrayDouble *)a);
815 }
816
817 void MEDUMeshMultiLev::reorderNodesIfNecessary(MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& coords, DataArrayInt *nodalConnVTK, DataArrayInt *polyhedNodalConnVTK) const
818 {
819   const DataArrayInt *nr(_node_reduction);
820   if(!nr)
821     return ;
822   int sz(coords->getNumberOfTuples());
823   std::vector<bool> b(sz,false);
824   const int *work(nodalConnVTK->begin()),*endW(nodalConnVTK->end());
825   while(work!=endW)
826     {
827       int nb(*work++);
828       for(int i=0;i<nb && work!=endW;i++,work++)
829         {
830           if(*work>=0 && *work<sz)
831             b[*work]=true;
832           else
833             throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error !");
834         }
835     }
836   if(polyhedNodalConnVTK)
837     {
838       work=polyhedNodalConnVTK->begin(); endW=polyhedNodalConnVTK->end();
839       while(work!=endW)
840         {
841           int nb(*work++);
842           for(int i=0;i<nb && work!=endW;i++)
843             {
844               int nb2(*work++);
845               for(int j=0;j<nb2 && work!=endW;j++,work++)
846                 {
847                   if(*work>=0 && *work<sz)
848                     b[*work]=true;
849                   else
850                     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #2 !");
851                 }
852             }
853         }
854     }
855   int szExp(std::count(b.begin(),b.end(),true));
856   if(szExp!=nr->getNumberOfTuples())
857     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #3 !");
858   // Go renumbering !
859   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(DataArrayInt::New()); o2n->alloc(sz,1);
860   int *o2nPtr(o2n->getPointer());
861   int newId(0);
862   for(int i=0;i<sz;i++,o2nPtr++)
863     if(b[i]) *o2nPtr=newId++; else *o2nPtr=-1;
864   const int *o2nPtrc(o2n->begin());
865   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(nr->getNumberOfTuples()));
866   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> perm(DataArrayInt::FindPermutationFromFirstToSecond(n2o,nr));
867   const int *permPtr(perm->begin());
868   int *work2(nodalConnVTK->getPointer()),*endW2(nodalConnVTK->getPointer()+nodalConnVTK->getNumberOfTuples());
869   while(work2!=endW2)
870     {
871       int nb(*work2++);
872       for(int i=0;i<nb && work2!=endW2;i++,work2++)
873         *work2=permPtr[o2nPtrc[*work2]];
874     }
875   if(polyhedNodalConnVTK)
876     {
877       work2=polyhedNodalConnVTK->getPointer(); endW2=polyhedNodalConnVTK->getPointer()+polyhedNodalConnVTK->getNumberOfTuples();
878       while(work2!=endW2)
879         {
880           int nb(*work2++);
881           for(int i=0;i<nb && work2!=endW2;i++)
882             {
883               int nb2(*work2++);
884               for(int j=0;j<nb2 && work2!=endW2;j++,work2++)
885                 *work2=permPtr[o2nPtrc[*work2]];
886             }
887         }
888     }
889   coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
890 }
891
892 //=
893
894 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev()
895 {
896 }
897
898 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(int nbOfNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(nbOfNodes,gts,pfls,nbEntities)
899 {
900 }
901
902 void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
903 {
904   if(!pflNodes || !pflNodes->isAllocated())
905     return ;
906   std::vector<int> ngs(getNodeGridStructure());
907   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
908   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(ngs.size())));
909   m->setNodalConnectivity(conn);
910   const DataArrayInt *pfl(_pfls[0]);
911   if(pfl)
912     {
913       m=dynamic_cast<MEDCoupling1SGTUMesh *>(m->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
914     }
915   DataArrayInt *cellIds=0;
916   m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
917   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
918   MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
919   int tmp=-1;
920   _node_reduction=m2->getNodeIdsInUse(tmp);
921   if(pfl)
922     _pfls[0]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
923   else
924     _pfls[0]=cellIdsSafe;
925 }
926
927 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other)
928 {
929 }
930
931 //=
932
933 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs)
934 {
935   return new MEDCMeshMultiLev(m,levs);
936 }
937
938 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
939 {
940   return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
941 }
942
943 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs)
944 {
945   if(!m)
946     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
947   if(levs.size()!=1 || levs[0]!=0)
948     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
949   int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
950   _coords.resize(mdim);
951   for(int i=0;i<mdim;i++)
952     {
953       DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
954       if(!elt)
955         throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
956       _coords[i]=elt;
957     }
958   // ids fields management
959   _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
960   const DataArrayInt *tmp(0);
961   tmp=m->getFamilyFieldAtLevel(0);
962   if(tmp)
963     {
964       tmp->incrRef();
965       _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
966     }
967   tmp=m->getNumberFieldAtLevel(0);
968   if(tmp)
969     {
970       tmp->incrRef();
971       _cell_num_ids=const_cast<DataArrayInt *>(tmp);
972     }
973 }
974
975 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->getNumberOfNodes(),gts,pfls,nbEntities)
976 {
977   if(!m)
978     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
979   if(gts.size()!=1 || pfls.size()!=1)
980     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
981   int mdim(m->getMeshDimension());
982   INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(mdim));
983   if(gt!=gts[0])
984     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
985   _coords.resize(mdim);
986   for(int i=0;i<mdim;i++)
987     {
988       DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
989       if(!elt)
990         throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
991       _coords[i]=elt; _coords[i]->incrRef();
992     }
993   // ids fields management
994   _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
995   const DataArrayInt *tmp(0);
996   tmp=m->getFamilyFieldAtLevel(0);
997   if(tmp)
998     {
999       tmp->incrRef();
1000       _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1001     }
1002   tmp=m->getNumberFieldAtLevel(0);
1003   if(tmp)
1004     {
1005       tmp->incrRef();
1006       _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1007     }
1008 }
1009
1010 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords)
1011 {
1012 }
1013
1014 std::vector<int> MEDCMeshMultiLev::getNodeGridStructure() const
1015 {
1016   std::vector<int> ret(_coords.size());
1017   for(std::size_t i=0;i<_coords.size();i++)
1018     ret[i]=_coords[i]->getNumberOfTuples();
1019   return ret;
1020 }
1021
1022 MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const
1023 {
1024   const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction);
1025   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1026   std::vector<int> cgs,ngs(getNodeGridStructure());
1027   cgs.resize(ngs.size());
1028   std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1029   if(pfl)
1030     {
1031       std::vector< std::pair<int,int> > cellParts;
1032       if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1033         {
1034           MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1035           if(nr)
1036             { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1037           ret->_nb_entities[0]=pfl->getNumberOfTuples();
1038           ret->_pfls[0]=0;
1039           std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > coords(_coords.size());
1040           for(std::size_t i=0;i<_coords.size();i++)
1041             coords[i]=_coords[i]->selectByTupleId2(cellParts[i].first,cellParts[i].second+1,1);
1042           ret->_coords=coords;
1043           return ret.retn();
1044         }
1045       else
1046         {
1047           MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> m(MEDCouplingCMesh::New());
1048           for(std::size_t i=0;i<ngs.size();i++)
1049             m->setCoordsAt(i,_coords[i]);
1050           MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1051           MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1052           MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1053           if(nr)
1054             { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1055           return ret.retn();
1056         }
1057     }
1058   else
1059     {
1060       MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1061       if(nr)
1062         { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1063       return ret.retn();
1064     }
1065 }
1066
1067 std::vector< DataArrayDouble * > MEDCMeshMultiLev::buildVTUArrays() const
1068 {
1069   std::size_t sz(_coords.size());
1070   std::vector< DataArrayDouble * > ret(sz);
1071   for(std::size_t i=0;i<sz;i++)
1072     {
1073       ret[i]=const_cast<DataArrayDouble *>((const DataArrayDouble *)_coords[i]);
1074       ret[i]->incrRef();
1075     }
1076   return ret;
1077 }
1078
1079 //=
1080
1081 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1082 {
1083   return new MEDCurveLinearMeshMultiLev(m,levs);
1084 }
1085
1086 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
1087 {
1088   return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
1089 }
1090
1091 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1092 {
1093   if(!m)
1094     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
1095   if(levs.size()!=1 || levs[0]!=0)
1096     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
1097   DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1098   if(!coords)
1099     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1100   coords->incrRef();
1101   _coords=coords;
1102   _structure=m->getMesh()->getNodeGridStructure();
1103   // ids fields management
1104   _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
1105   const DataArrayInt *tmp(0);
1106   tmp=m->getFamilyFieldAtLevel(0);
1107   if(tmp)
1108     {
1109       tmp->incrRef();
1110       _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1111     }
1112   tmp=m->getNumberFieldAtLevel(0);
1113   if(tmp)
1114     {
1115       tmp->incrRef();
1116       _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1117     }
1118 }
1119
1120 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->getNumberOfNodes(),gts,pfls,nbEntities)
1121 {
1122   if(!m)
1123     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1124   if(gts.size()!=1 || pfls.size()!=1)
1125     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1126   int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1127   if(mdim!=gts[0])
1128     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
1129   DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1130   if(!coords)
1131     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1132   coords->incrRef();
1133   _coords=coords;
1134   _structure=m->getMesh()->getNodeGridStructure();
1135   // ids fields management
1136   _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
1137   const DataArrayInt *tmp(0);
1138   tmp=m->getFamilyFieldAtLevel(0);
1139   if(tmp)
1140     {
1141       tmp->incrRef();
1142       _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1143     }
1144   tmp=m->getNumberFieldAtLevel(0);
1145   if(tmp)
1146     {
1147       tmp->incrRef();
1148       _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1149     }
1150 }
1151
1152 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure)
1153 {
1154 }
1155
1156 std::vector<int> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const
1157 {
1158   return _structure;
1159 }
1160
1161 MEDMeshMultiLev *MEDCurveLinearMeshMultiLev::prepare() const
1162 {
1163   const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction);
1164   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1165   std::vector<int> cgs,ngs(getNodeGridStructure());
1166   cgs.resize(ngs.size());
1167   std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1168   if(pfl)
1169     {
1170       std::vector< std::pair<int,int> > cellParts,nodeParts;
1171       if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1172         {
1173           nodeParts=cellParts;
1174           std::vector<int> st(ngs.size());
1175           for(std::size_t i=0;i<ngs.size();i++)
1176             {
1177               nodeParts[i].second++;
1178               st[i]=nodeParts[i].second-nodeParts[i].first;
1179             }
1180           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p(MEDCouplingStructuredMesh::BuildExplicitIdsFrom(ngs,nodeParts));
1181           MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1182           if(nr)
1183             { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1184           ret->_nb_entities[0]=pfl->getNumberOfTuples();
1185           ret->_pfls[0]=0;
1186           ret->_coords=_coords->selectByTupleIdSafe(p->begin(),p->end());
1187           ret->_structure=st;
1188           return ret.retn();
1189         }
1190       else
1191         {
1192           MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> m(MEDCouplingCurveLinearMesh::New());
1193           m->setCoords(_coords); m->setNodeGridStructure(&_structure[0],&_structure[0]+_structure.size());
1194           MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1195           MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1196           MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1197           if(nr)
1198             { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1199           return ret.retn();
1200         }
1201     }
1202   else
1203     {
1204       MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1205       if(nr)
1206         { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1207       return ret.retn();
1208     }
1209 }
1210
1211 void MEDCurveLinearMeshMultiLev::buildVTUArrays(DataArrayDouble *&coords, std::vector<int>& nodeStrct) const
1212 {
1213   nodeStrct=_structure;
1214   const DataArrayDouble *coo(_coords);
1215   if(!coo)
1216     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev::buildVTUArrays : null pointer on coordinates !");
1217   coords=const_cast<DataArrayDouble *>(coo); coords->incrRef();
1218 }
1219
1220 //=
1221
1222 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2()
1223 {
1224 }
1225
1226 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)
1227 {
1228   _pfl->setName(c.c_str());
1229 }
1230
1231 void MEDFileField1TSStructItem2::checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1232 {
1233   int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1234   checkInRange(nbOfEnt,1,globs);
1235 }
1236
1237 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1238 {
1239   int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1240   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1241   checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs);
1242 }
1243
1244 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1245 {
1246   if(!globs)
1247     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !");
1248   if(_loc.empty())
1249     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !");
1250   const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str());
1251   int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1252   checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs);
1253 }
1254
1255 int MEDFileField1TSStructItem2::getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const
1256 {
1257   if(_loc.empty())
1258     {
1259       if(getPflName().empty())
1260         return (_start_end.second-_start_end.first)/_nb_of_entity;
1261       else
1262         return (_start_end.second-_start_end.first)/getPfl(globs)->getNumberOfTuples();
1263     }
1264   else
1265     {
1266       const MEDFileFieldLoc& loc(globs->getLocalization(_loc.c_str()));
1267       return loc.getNumberOfGaussPoints();
1268     }
1269 }
1270
1271 std::string MEDFileField1TSStructItem2::getPflName() const
1272 {
1273   return _pfl->getName();
1274 }
1275
1276 const DataArrayInt *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const
1277 {
1278   if(!_pfl->isAllocated())
1279     {
1280       if(_pfl->getName().empty())
1281         return 0;
1282       else
1283         return globs->getProfile(_pfl->getName().c_str());
1284     }
1285   else
1286     return _pfl;
1287 }
1288
1289 /*!
1290  * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possiblity.
1291  * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES
1292  */
1293 void MEDFileField1TSStructItem2::checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs)
1294 {
1295   _nb_of_entity=nbOfEntity;
1296   if(_pfl->getName().empty())
1297     {
1298       if(nbOfEntity!=(_start_end.second-_start_end.first)/nip)
1299         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of node field !");
1300       return ;
1301     }
1302   else
1303     {
1304       if(!globs)
1305         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !");
1306       const DataArrayInt *pfl=globs->getProfile(_pfl->getName().c_str());
1307       if(!pfl)
1308         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !");
1309       pfl->checkAllIdsInRange(0,nbOfEntity);
1310     }
1311 }
1312
1313 bool MEDFileField1TSStructItem2::isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const char *pflName) const
1314 {
1315   if(startExp!=_start_end.first)
1316     return false;
1317   if(gt!=_geo_type)
1318     return false;
1319   if(getPflName()!=pflName)
1320     return false;
1321   startExp=_start_end.second;
1322   return true;
1323 }
1324
1325 bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception)
1326 {
1327   //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
1328   //idem for _loc. It is not an effective attribute for support comparison.
1329   return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
1330 }
1331
1332 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1333 {
1334   if(_geo_type!=other._geo_type)
1335     return false;
1336   if(_nb_of_entity!=other._nb_of_entity)
1337     return false;
1338   if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
1339     return false;
1340   if(_pfl->getName().empty() && other._pfl->getName().empty())
1341     return true;
1342   const DataArrayInt *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
1343   return pfl1->isEqualWithoutConsideringStr(*pfl2);
1344 }
1345
1346 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1347 {
1348   return isCellSupportEqual(other,globs);
1349 }
1350
1351 /*!
1352  * \a objs must be non empty. \a objs should contain items having same geometric type.
1353  */
1354 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs)
1355 {
1356   if(objs.empty())
1357     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
1358   if(objs.size()==1)
1359     return MEDFileField1TSStructItem2(*objs[0]);
1360   INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
1361   int nbEntityRef(objs[0]->_nb_of_entity);
1362   std::size_t sz(objs.size());
1363   std::vector<const DataArrayInt *> arrs(sz);
1364   for(std::size_t i=0;i<sz;i++)
1365     {
1366       const MEDFileField1TSStructItem2 *obj(objs[i]);
1367       if(gt!=obj->_geo_type)
1368         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
1369       if(nbEntityRef!=obj->_nb_of_entity)
1370         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
1371       if(obj->_pfl->getName().empty())
1372         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
1373       arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
1374     }
1375   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::Aggregate(arrs));
1376   arr->sort();
1377   int oldNbTuples(arr->getNumberOfTuples());
1378   arr=arr->buildUnique();
1379   if(oldNbTuples!=arr->getNumberOfTuples())
1380     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
1381   if(arr->isIdentity() && oldNbTuples==nbEntityRef)
1382     {
1383       std::pair<int,int> p(0,nbEntityRef);
1384       std::string a,b;
1385       MEDFileField1TSStructItem2 ret(gt,p,a,b);
1386       ret._nb_of_entity=nbEntityRef;
1387       return ret;
1388     }
1389   else
1390     {
1391       arr->setName(NEWLY_CREATED_PFL_NAME);
1392       std::pair<int,int> p(0,oldNbTuples);
1393       std::string a,b;
1394       MEDFileField1TSStructItem2 ret(gt,p,a,b);
1395       ret._nb_of_entity=nbEntityRef;
1396       ret._pfl=arr;
1397       return ret;
1398     }
1399 }
1400
1401 std::size_t MEDFileField1TSStructItem2::getHeapMemorySizeWithoutChildren() const
1402 {
1403   std::size_t ret(_loc.capacity());
1404   return ret;
1405 }
1406
1407 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem2::getDirectChildren() const
1408 {
1409   std::vector<const BigMemoryObject *> ret;
1410   const DataArrayInt *pfl(_pfl);
1411   if(pfl)
1412     ret.push_back(pfl);
1413   return ret;
1414 }
1415
1416 //=
1417
1418 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
1419 {
1420 }
1421
1422 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1423 {
1424   switch(_type)
1425     {
1426     case ON_NODES:
1427       {
1428         int nbOfEnt=mst->getNumberOfNodes();
1429         if(_items.size()!=1)
1430           throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
1431         _items[0].checkInRange(nbOfEnt,1,globs);
1432         break ;
1433       }
1434     case ON_CELLS:
1435       {
1436         for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1437           (*it).checkWithMeshStructForCells(mst,globs);
1438         break;
1439       }
1440     case ON_GAUSS_NE:
1441       {
1442         for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1443           (*it).checkWithMeshStructForGaussNE(mst,globs);
1444         break;
1445       }
1446     case ON_GAUSS_PT:
1447       {
1448         for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1449           (*it).checkWithMeshStructForGaussPT(mst,globs);
1450         break;
1451       }
1452     default:
1453       throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
1454     }
1455 }
1456
1457 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const throw(INTERP_KERNEL::Exception)
1458 {
1459   if(_type!=other._type)
1460     return false;
1461   if(_items.size()!=other._items.size())
1462     return false;
1463   for(std::size_t i=0;i<_items.size();i++)
1464     if(!(_items[i]==other._items[i]))
1465       return false;
1466   return true;
1467 }
1468
1469 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1470 {
1471   if(_type!=other._type)
1472     return false;
1473   if(_items.size()!=other._items.size())
1474     return false;
1475   for(std::size_t i=0;i<_items.size();i++)
1476     if(!(_items[i].isCellSupportEqual(other._items[i],globs)))
1477       return false;
1478   return true;
1479 }
1480
1481 bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1482 {
1483   if(_type!=other._type)
1484     return false;
1485   if(_items.size()!=other._items.size())
1486     return false;
1487   for(std::size_t i=0;i<_items.size();i++)
1488     if(!(_items[i].isNodeSupportEqual(other._items[i],globs)))
1489       return false;
1490   return true;
1491 }
1492
1493 bool MEDFileField1TSStructItem::isEntityCell() const
1494 {
1495   if(_type==ON_NODES)
1496     return false;
1497   else
1498     return true;
1499 }
1500
1501 class CmpGeo
1502 {
1503 public:
1504   CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
1505   bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
1506 private:
1507   INTERP_KERNEL::NormalizedCellType _geo_type;
1508 };
1509
1510 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const
1511 {
1512   if(!isEntityCell())
1513     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
1514   std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
1515   std::size_t i=0;
1516   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1517     {
1518       std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
1519       if(it0==m.end())
1520         m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
1521       else
1522         (*it0).second.push_back(i);
1523     }
1524   if(m.size()==_items.size())
1525     {
1526       MEDFileField1TSStructItem ret(*this);
1527       ret._type=ON_CELLS;
1528       return ret;
1529     }
1530   std::size_t sz(m.size());
1531   std::vector< MEDFileField1TSStructItem2 > items(sz);
1532   for(i=0;i<sz;i++)
1533     {
1534       const std::vector<std::size_t>& ids=m[i].second;
1535       std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
1536       for(std::size_t j=0;j<ids.size();j++)
1537         objs[j]=&_items[ids[j]];
1538       items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
1539     }
1540   MEDFileField1TSStructItem ret(ON_CELLS,items);
1541   ret._computed=true;
1542   return ret;
1543 }
1544
1545 /*!
1546  * \a this is expected to be ON_CELLS and simplified.
1547  */
1548 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const
1549 {
1550   if(other._type!=ON_NODES)
1551     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
1552   if(other._items.size()!=1)
1553     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
1554   int theFirstLevFull;
1555   bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
1556   const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
1557   if(otherNodeIt.getPflName().empty())
1558     {//on all nodes
1559       if(!ret0)
1560         return false;
1561       return theFirstLevFull==0;
1562     }
1563   else
1564     {
1565       const DataArrayInt *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
1566       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpyPfl(pfl->deepCpy());
1567       cpyPfl->sort();
1568       int nbOfNodes(meshSt->getNumberOfNodes());
1569       if(cpyPfl->isIdentity() && cpyPfl->getNumberOfTuples()==nbOfNodes)
1570         {//on all nodes also !
1571           if(!ret0)
1572             return false;
1573           return theFirstLevFull==0;
1574         }
1575       std::vector<bool> nodesFetched(nbOfNodes,false);
1576       meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1577       return cpyPfl->isFittingWith(nodesFetched);
1578     }
1579 }
1580
1581 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const
1582 {
1583   if(_type!=ON_CELLS)
1584     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
1585   if(_items.empty())
1586     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
1587   int nbOfLevs(meshSt->getNumberOfLevs());
1588   if(nbOfLevs==0)
1589     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
1590   std::vector<int> levs(nbOfLevs);
1591   theFirstLevFull=1;
1592   std::set<INTERP_KERNEL::NormalizedCellType> gts;
1593   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1594     {
1595       if(!(*it).getPflName().empty())
1596         return false;
1597       INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
1598       if(gts.find(gt)!=gts.end())
1599         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
1600       gts.insert(gt);
1601       int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
1602       levs[-pos]++;
1603     }
1604   for(int i=0;i<nbOfLevs;i++)
1605     if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
1606       { theFirstLevFull=-i; return true; }
1607   return false;
1608 }
1609
1610 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const throw(INTERP_KERNEL::Exception)
1611 {
1612   if(i>=_items.size())
1613     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
1614   return _items[i];
1615 }
1616
1617 std::size_t MEDFileField1TSStructItem::getHeapMemorySizeWithoutChildren() const
1618 {
1619   std::size_t ret(_items.size()*sizeof(MEDFileField1TSStructItem2));
1620   return ret;
1621 }
1622
1623 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem::getDirectChildren() const
1624 {
1625   std::vector<const BigMemoryObject *> ret;
1626   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1627     ret.push_back(&(*it));
1628   return ret;
1629 }
1630
1631 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
1632 {
1633   std::size_t sz(_items.size());
1634   std::vector<INTERP_KERNEL::NormalizedCellType> a0(sz);
1635   std::vector<const DataArrayInt *> a1(sz);
1636   std::vector<int> a2(sz);
1637   std::size_t i(0);
1638   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1639     {
1640       a0[i]=(*it).getGeo();
1641       a1[i]=(*it).getPfl(globs);
1642       a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
1643     }
1644   return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
1645 }
1646
1647 MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
1648 {
1649   TypeOfField atype;
1650   std::vector< MEDFileField1TSStructItem2 > anItems;
1651   //
1652   std::vector< std::vector<std::string> > pfls,locs;
1653   std::vector< std::vector<TypeOfField> > typesF;
1654   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
1655   std::vector< std::vector<std::pair<int,int> > > strtEnds=ref->getFieldSplitedByType(0,geoTypes,typesF,pfls,locs);
1656   std::size_t nbOfGeoTypes(geoTypes.size());
1657   if(nbOfGeoTypes==0)
1658     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref  !");
1659   bool isFirst=true;
1660   for(std::size_t i=0;i<nbOfGeoTypes;i++)
1661     {
1662       std::size_t sz=typesF[i].size();
1663       if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
1664         throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
1665       //
1666       if(isFirst)
1667         atype=typesF[i][0];
1668       isFirst=false;
1669       //
1670       for(std::size_t j=0;j<sz;j++)
1671         {
1672           if(atype==typesF[i][j])
1673             anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
1674           else
1675             throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
1676         }
1677     }
1678   MEDFileField1TSStructItem ret(atype,anItems);
1679   ret.checkWithMeshStruct(meshSt,ref);
1680   return ret;
1681 }
1682
1683 //=
1684
1685 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
1686 {
1687   return new MEDFileField1TSStruct(ref,mst);
1688 }
1689
1690 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
1691 {
1692   _already_checked.push_back(MEDFileField1TSStructItem::BuildItemFrom(ref,mst));
1693 }
1694
1695 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1696 {
1697   if(_already_checked.empty())
1698     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
1699   _already_checked.back().checkWithMeshStruct(mst,globs);
1700 }
1701
1702 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const
1703 {
1704   MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,mst));
1705   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
1706     {
1707       if((*it)==b)
1708         return true;
1709     }
1710   return false;
1711 }
1712
1713 /*!
1714  * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
1715  */
1716 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
1717 {
1718   if(_already_checked.empty())
1719     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
1720   MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
1721   if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
1722     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
1723   MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other));
1724   int found=-1,i=0;
1725   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1726     if((*it).isComputed())
1727       { found=i; break; }
1728   bool ret(false);
1729   if(found==-1)
1730     {
1731       MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
1732       ret=this1.isCellSupportEqual(other1,other);
1733       if(ret)
1734         _already_checked.push_back(this1);
1735     }
1736   else
1737     ret=_already_checked[found].isCellSupportEqual(other1,other);
1738   if(ret)
1739     _already_checked.push_back(b);
1740   return ret;
1741 }
1742
1743 /*!
1744  * \param [in] other - a field with only one spatial discretization : ON_NODES.
1745  */
1746 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
1747 {
1748   if(_already_checked.empty())
1749     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
1750   MEDFileField1TSStructItem other1(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
1751   if(_already_checked[0].isEntityCell())
1752     {
1753       int found=-1,i=0;
1754       for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1755         if((*it).isComputed())
1756           { found=i; break; }
1757       bool ret(false);
1758       if(found==-1)
1759         {
1760           MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
1761           ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other);
1762           if(ret)
1763             _already_checked.push_back(this1);
1764         }
1765       else
1766         ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other);
1767       if(ret)
1768         _already_checked.push_back(other1);
1769       return ret;
1770     }
1771   else
1772     return _already_checked[0].isNodeSupportEqual(other1,other);
1773 }
1774
1775 std::size_t MEDFileField1TSStruct::getHeapMemorySizeWithoutChildren() const
1776 {
1777   std::size_t ret(_already_checked.capacity()*sizeof(MEDFileField1TSStructItem));
1778   return ret;
1779 }
1780
1781 std::vector<const BigMemoryObject *> MEDFileField1TSStruct::getDirectChildren() const
1782 {
1783   std::vector<const BigMemoryObject *> ret;
1784   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
1785     ret.push_back(&(*it));
1786   return ret;
1787 }
1788
1789 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
1790 {
1791   if(_already_checked.empty())
1792     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
1793   int pos0(-1),pos1(-1);
1794   if(presenceOfCellDiscr(pos0))
1795     {
1796       MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
1797       if(presenceOfPartialNodeDiscr(pos1))
1798         ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
1799       return ret.retn();
1800     }
1801   else
1802     {
1803       if(!presenceOfPartialNodeDiscr(pos1))
1804         {//we have only all nodes, no cell definition info -> level 0;
1805           std::vector<int> levs(1,0);
1806           return MEDMeshMultiLev::New(mst->getTheMesh(),levs);
1807         }
1808       else
1809         return MEDMeshMultiLev::NewOnlyOnNode(mst->getTheMesh(),_already_checked[pos1][0].getPfl(globs));
1810     }
1811 }
1812
1813 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const
1814 {
1815   int b0,b1;
1816   bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
1817   int d0,d1;
1818   bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1)); 
1819   if(a0!=c0 || a1!=c1)
1820     return false;
1821   if(a0)
1822     if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
1823       return false;
1824   if(a1)
1825     if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
1826       return false;
1827   return true;
1828 }
1829
1830 /*!
1831  * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
1832  * 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.
1833  */
1834 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const
1835 {
1836   std::size_t refSz(std::numeric_limits<std::size_t>::max());
1837   bool ret(false);
1838   int i(0);
1839   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1840     {
1841       if((*it).getType()!=ON_NODES)
1842         {
1843           ret=true;
1844           std::size_t sz((*it).getNumberOfItems());
1845           if(refSz>sz)
1846             { pos=i; refSz=sz; }
1847         }
1848     }
1849   if(refSz==0)
1850     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
1851   return ret;
1852 }
1853
1854 /*!
1855  * Returns true if presence in \a this of discretization ON_NODES.
1856  * If true is returned the pos of the first element containing the single subpart.
1857  */
1858 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const
1859 {
1860   int i(0);
1861   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1862     {
1863       if((*it).getType()==ON_NODES)
1864         {
1865           std::size_t sz((*it).getNumberOfItems());
1866           if(sz==1)
1867             {
1868               if(!(*it)[0].getPflName().empty())
1869                 { pos=i; return true; }
1870             }
1871           else
1872             throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
1873         }
1874     }
1875   return false;
1876 }
1877
1878 //=
1879
1880 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
1881 {
1882   return new MEDFileFastCellSupportComparator(m,ref);
1883 }
1884
1885 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
1886 {
1887   if(!m)
1888     throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
1889   _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
1890   int nbPts=ref->getNumberOfTS();
1891   _f1ts_cmps.resize(nbPts);
1892   for(int i=0;i<nbPts;i++)
1893     {
1894       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
1895       _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
1896       _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt);
1897     }
1898 }
1899
1900 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySizeWithoutChildren() const
1901 {
1902   std::size_t ret(_f1ts_cmps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct>));
1903   return ret;
1904 }
1905
1906 std::vector<const BigMemoryObject *> MEDFileFastCellSupportComparator::getDirectChildren() const
1907 {
1908   std::vector<const BigMemoryObject *> ret;
1909   const MEDFileMeshStruct *mst(_mesh_comp);
1910   if(mst)
1911     ret.push_back(mst);
1912   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
1913     {
1914       const MEDFileField1TSStruct *cur(*it);
1915       if(cur)
1916         ret.push_back(cur);
1917     }
1918   return ret;
1919 }
1920
1921 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other)
1922 {
1923   int nbPts=other->getNumberOfTS();
1924   if(nbPts!=(int)_f1ts_cmps.size())
1925     {
1926       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in  input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
1927       throw INTERP_KERNEL::Exception(oss.str().c_str());
1928     }
1929   for(int i=0;i<nbPts;i++)
1930     {
1931       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
1932       if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
1933         if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
1934           return false;
1935     }
1936   return true;
1937 }
1938
1939 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other)
1940 {
1941   int nbPts=other->getNumberOfTS();
1942   if(nbPts!=(int)_f1ts_cmps.size())
1943     {
1944       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in  input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
1945       throw INTERP_KERNEL::Exception(oss.str().c_str());
1946     }
1947   for(int i=0;i<nbPts;i++)
1948     {
1949       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
1950       if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
1951         return false;
1952     }
1953   return true;
1954 }
1955
1956 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const
1957 {
1958   if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
1959     {
1960       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
1961       throw INTERP_KERNEL::Exception(oss.str().c_str());
1962     }
1963   const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
1964   if(!obj)
1965     {
1966       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
1967       throw INTERP_KERNEL::Exception(oss.str().c_str());
1968     }
1969   return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
1970 }
1971
1972 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const
1973 {
1974   if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
1975     {
1976       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
1977       throw INTERP_KERNEL::Exception(oss.str().c_str());
1978     }
1979   const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
1980   const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
1981   return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);
1982 }