Salome HOME
All getName method return std::string now
[modules/med.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 char MEDFileField1TSStructItem2::NEWLY_CREATED_PFL_NAME[]="???";
30
31 MEDFileMeshStruct *MEDFileMeshStruct::New(const MEDFileMesh *mesh)
32 {
33   return new MEDFileMeshStruct(mesh);
34 }
35
36 std::size_t MEDFileMeshStruct::getHeapMemorySize() const
37 {
38   std::size_t ret(0);
39   for(std::vector< std::vector<int> >::const_iterator it0=_geo_types_distrib.begin();it0!=_geo_types_distrib.end();it0++)
40     ret+=(*it0).capacity()*sizeof(int);
41   ret+=_geo_types_distrib.capacity()*sizeof(std::vector<int>);
42   return ret;
43 }
44
45 MEDFileMeshStruct::MEDFileMeshStruct(const MEDFileMesh *mesh):_mesh(mesh)
46 {
47   std::vector<int> levs=mesh->getNonEmptyLevels();
48   _name=mesh->getName();
49   _nb_nodes=mesh->getNumberOfNodes();
50   _geo_types_distrib.resize(levs.size());
51   for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
52     {
53       MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mLev=mesh->getGenMeshAtLevel(*lev);
54       _geo_types_distrib[-(*lev)]=mLev->getDistributionOfTypes();
55     }
56 }
57
58 int MEDFileMeshStruct::getLevelOfGeoType(INTERP_KERNEL::NormalizedCellType t) const throw(INTERP_KERNEL::Exception)
59 {
60   int j=0;
61   for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++,j--)
62     {
63       std::size_t sz=(*it1).size();
64       if(sz%3!=0)
65         throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : internal error in code !");
66       std::size_t nbGeo=sz/3;
67       for(std::size_t i=0;i<nbGeo;i++)
68         if((*it1)[3*i]==(int)t)
69           return j;
70     }
71   throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : The specified geometric type is not present in the mesh structure !");
72 }
73
74 int MEDFileMeshStruct::getNumberOfElemsOfGeoType(INTERP_KERNEL::NormalizedCellType t) const throw(INTERP_KERNEL::Exception)
75 {
76   for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++)
77     {
78       std::size_t sz=(*it1).size();
79       if(sz%3!=0)
80         throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfElemsOfGeoType : internal error in code !");
81       std::size_t nbGeo=sz/3;
82       for(std::size_t i=0;i<nbGeo;i++)
83         if((*it1)[3*i]==(int)t)
84           return (*it1)[3*i+1];
85     }
86   throw INTERP_KERNEL::Exception("The specified geometric type is not present in the mesh structure !");
87 }
88
89 int MEDFileMeshStruct::getNumberOfLevs() const
90 {
91   return (int)_geo_types_distrib.size();
92 }
93
94 int MEDFileMeshStruct::getNumberOfGeoTypesInLev(int relativeLev) const throw(INTERP_KERNEL::Exception)
95 {
96   int pos(-relativeLev);
97   if(pos<0 || pos>=_geo_types_distrib.size())
98     throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : invalid level specified !");
99   std::size_t sz=_geo_types_distrib[pos].size();
100   if(sz%3!=0)
101     throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : internal error in code !");
102   return (int)(sz/3);
103 }
104
105 //=
106
107 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2()
108 {
109 }
110
111 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)
112 {
113   _pfl->setName(c.c_str());
114 }
115
116 void MEDFileField1TSStructItem2::checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
117 {
118   int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
119   checkInRange(nbOfEnt,1,globs);
120 }
121
122 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
123 {
124   int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
125   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
126   checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs);
127 }
128
129 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
130 {
131   if(!globs)
132     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !");
133   if(_loc.empty())
134     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !");
135   const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str());
136   int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
137   checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs);
138 }
139
140 std::string MEDFileField1TSStructItem2::getPflName() const
141 {
142   return _pfl->getName();
143 }
144
145 const DataArrayInt *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const
146 {
147   if(!_pfl->isAllocated())
148     {
149       if(_pfl->getName().empty())
150         return 0;
151       else
152         return globs->getProfile(_pfl->getName().c_str());
153     }
154   else
155     return _pfl;
156 }
157
158 /*!
159  * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possiblity.
160  * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES
161  */
162 void MEDFileField1TSStructItem2::checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
163 {
164   _nb_of_entity=nbOfEntity;
165   if(_pfl->getName().empty())
166     {
167       if(nbOfEntity!=(_start_end.second-_start_end.first)/nip)
168         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of node field !");
169       return ;
170     }
171   else
172     {
173       if(!globs)
174         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !");
175       const DataArrayInt *pfl=globs->getProfile(_pfl->getName().c_str());
176       if(!pfl)
177         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !");
178       pfl->checkAllIdsInRange(0,nbOfEntity);
179     }
180 }
181
182 bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception)
183 {
184   //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
185   //idem for _loc. It is not an effective attribute for support comparison.
186   return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
187 }
188
189 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
190 {
191   if(_geo_type!=other._geo_type)
192     return false;
193   if(_nb_of_entity!=other._nb_of_entity)
194     return false;
195   if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
196     return false;
197   if(_pfl->getName().empty() && other._pfl->getName().empty())
198     return true;
199   const DataArrayInt *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
200   return pfl1->isEqualWithoutConsideringStr(*pfl2);
201 }
202
203 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
204 {
205   return isCellSupportEqual(other,globs);
206 }
207
208 /*!
209  * \a objs must be non empty. \a objs should contain items having same geometric type.
210  */
211 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
212 {
213   if(objs.empty())
214     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
215   if(objs.size()==1)
216     return MEDFileField1TSStructItem2(*objs[0]);
217   INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
218   int nbEntityRef(objs[0]->_nb_of_entity);
219   std::size_t sz(objs.size());
220   std::vector<const DataArrayInt *> arrs(sz);
221   for(std::size_t i=0;i<sz;i++)
222     {
223       const MEDFileField1TSStructItem2 *obj(objs[i]);
224       if(gt!=obj->_geo_type)
225         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
226       if(nbEntityRef!=obj->_nb_of_entity)
227         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
228       if(obj->_pfl->getName().empty())
229         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
230       arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
231     }
232   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::Aggregate(arrs));
233   arr->sort();
234   int oldNbTuples(arr->getNumberOfTuples());
235   arr=arr->buildUnique();
236   if(oldNbTuples!=arr->getNumberOfTuples())
237     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
238   if(arr->isIdentity() && oldNbTuples==nbEntityRef)
239     {
240       std::pair<int,int> p(0,nbEntityRef);
241       std::string a,b;
242       MEDFileField1TSStructItem2 ret(gt,p,a,b);
243       ret._nb_of_entity=nbEntityRef;
244       return ret;
245     }
246   else
247     {
248       arr->setName(NEWLY_CREATED_PFL_NAME);
249       std::pair<int,int> p(0,oldNbTuples);
250       std::string a,b;
251       MEDFileField1TSStructItem2 ret(gt,p,a,b);
252       ret._nb_of_entity=nbEntityRef;
253       ret._pfl=arr;
254       return ret;
255     }
256 }
257
258 std::size_t MEDFileField1TSStructItem2::getHeapMemorySize() const
259 {
260   std::size_t ret(0);
261   const DataArrayInt *pfl(_pfl);
262   if(pfl)
263     ret+=pfl->getHeapMemorySize();
264   ret+=_loc.capacity();
265   return ret;
266 }
267
268 //=
269
270 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
271 {
272 }
273
274 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
275 {
276   switch(_type)
277     {
278     case ON_NODES:
279       {
280         int nbOfEnt=mst->getNumberOfNodes();
281         if(_items.size()!=1)
282           throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
283         _items[0].checkInRange(nbOfEnt,1,globs);
284         break ;
285       }
286     case ON_CELLS:
287       {
288         for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
289           (*it).checkWithMeshStructForCells(mst,globs);
290         break;
291       }
292     case ON_GAUSS_NE:
293       {
294         for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
295           (*it).checkWithMeshStructForGaussNE(mst,globs);
296         break;
297       }
298     case ON_GAUSS_PT:
299       {
300         for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
301           (*it).checkWithMeshStructForGaussPT(mst,globs);
302         break;
303       }
304     default:
305       throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
306     }
307 }
308
309 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const throw(INTERP_KERNEL::Exception)
310 {
311   if(_type!=other._type)
312     return false;
313   if(_items.size()!=other._items.size())
314     return false;
315   for(std::size_t i=0;i<_items.size();i++)
316     if(!(_items[i]==other._items[i]))
317       return false;
318   return true;
319 }
320
321 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
322 {
323   if(_type!=other._type)
324     return false;
325   if(_items.size()!=other._items.size())
326     return false;
327   for(std::size_t i=0;i<_items.size();i++)
328     if(!(_items[i].isCellSupportEqual(other._items[i],globs)))
329       return false;
330   return true;
331 }
332
333 bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
334 {
335   if(_type!=other._type)
336     return false;
337   if(_items.size()!=other._items.size())
338     return false;
339   for(std::size_t i=0;i<_items.size();i++)
340     if(!(_items[i].isNodeSupportEqual(other._items[i],globs)))
341       return false;
342   return true;
343 }
344
345 bool MEDFileField1TSStructItem::isEntityCell() const
346 {
347   if(_type==ON_NODES)
348     return false;
349   else
350     return true;
351 }
352
353 class CmpGeo
354 {
355 public:
356   CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
357   bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
358 private:
359   INTERP_KERNEL::NormalizedCellType _geo_type;
360 };
361
362 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
363 {
364   if(!isEntityCell())
365     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
366   std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
367   std::size_t i=0;
368   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
369     {
370       std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
371       if(it0==m.end())
372         m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
373       else
374         (*it0).second.push_back(i);
375     }
376   if(m.size()==_items.size())
377     {
378       MEDFileField1TSStructItem ret(*this);
379       ret._type=ON_CELLS;
380       return ret;
381     }
382   std::size_t sz(m.size());
383   std::vector< MEDFileField1TSStructItem2 > items(sz);
384   for(i=0;i<sz;i++)
385     {
386       const std::vector<std::size_t>& ids=m[i].second;
387       std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
388       for(std::size_t j=0;j<ids.size();j++)
389         objs[j]=&_items[ids[j]];
390       items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
391     }
392   MEDFileField1TSStructItem ret(ON_CELLS,items);
393   ret._computed=true;
394   return ret;
395 }
396
397 /*!
398  * \a this is expected to be ON_CELLS and simplified.
399  */
400 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
401 {
402   if(other._type!=ON_NODES)
403     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
404   if(other._items.size()!=1)
405     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
406   int theFirstLevFull;
407   bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
408   const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
409   if(otherNodeIt.getPflName().empty())
410     {//on all nodes
411       if(!ret0)
412         return false;
413       return theFirstLevFull==0;
414     }
415   else
416     {
417       const DataArrayInt *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
418       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpyPfl(pfl->deepCpy());
419       cpyPfl->sort();
420       int nbOfNodes(meshSt->getNumberOfNodes());
421       if(cpyPfl->isIdentity() && cpyPfl->getNumberOfTuples()==nbOfNodes)
422         {//on all nodes also !
423           if(!ret0)
424             return false;
425           return theFirstLevFull==0;
426         }
427       std::vector<bool> nodesFetched(nbOfNodes,false);
428       meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
429       return cpyPfl->isFittingWith(nodesFetched);
430     }
431 }
432
433 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const throw(INTERP_KERNEL::Exception)
434 {
435   if(_type!=ON_CELLS)
436     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
437   if(_items.empty())
438     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
439   int nbOfLevs(meshSt->getNumberOfLevs());
440   if(nbOfLevs==0)
441     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
442   std::vector<int> levs(nbOfLevs);
443   theFirstLevFull=1;
444   int nbOfGT=0;
445   std::set<INTERP_KERNEL::NormalizedCellType> gts;
446   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
447     {
448       if(!(*it).getPflName().empty())
449         return false;
450       INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
451       if(gts.find(gt)!=gts.end())
452         throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
453       gts.insert(gt);
454       int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
455       levs[-pos]++;
456     }
457   for(int i=0;i<nbOfLevs;i++)
458     if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
459       { theFirstLevFull=-i; return true; }
460   return false;
461 }
462
463 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const throw(INTERP_KERNEL::Exception)
464 {
465   if(i<0 || i>=_items.size())
466     throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
467   return _items[i];
468 }
469
470 std::size_t MEDFileField1TSStructItem::getHeapMemorySize() const
471 {
472   std::size_t ret(0);
473   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
474     ret+=(*it).getHeapMemorySize();
475   ret+=_items.size()*sizeof(MEDFileField1TSStructItem2);
476   return ret;
477 }
478
479 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
480 {
481   std::vector<INTERP_KERNEL::NormalizedCellType> a0;
482   std::vector<const DataArrayInt *> a1;
483   std::vector<int> a2;
484   std::size_t i(0);
485   for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
486     {
487       a0[i]=(*it).getGeo();
488       a1[i]=(*it).getPfl(globs);
489       a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
490     }
491   return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
492 }
493
494 //=
495
496 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst) throw(INTERP_KERNEL::Exception)
497 {
498   return new MEDFileField1TSStruct(ref,mst);
499 }
500
501 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
502 {
503   _already_checked.push_back(BuildItemFrom(ref,mst));
504 }
505
506 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
507 {
508   if(_already_checked.empty())
509     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
510   _already_checked.back().checkWithMeshStruct(mst,globs);
511 }
512
513 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const throw(INTERP_KERNEL::Exception)
514 {
515   MEDFileField1TSStructItem b(BuildItemFrom(other,mst));
516   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
517     {
518       if((*it)==b)
519         return true;
520     }
521   return false;
522 }
523
524 /*!
525  * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
526  */
527 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt) throw(INTERP_KERNEL::Exception)
528 {
529   if(_already_checked.empty())
530     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
531   MEDFileField1TSStructItem b(BuildItemFrom(other,meshSt));
532   if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
533     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
534   MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other));
535   int found=-1,i=0;
536   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
537     if((*it).isComputed())
538       { found=i; break; }
539   bool ret(false);
540   if(found==-1)
541     {
542       MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
543       ret=this1.isCellSupportEqual(other1,other);
544       if(ret)
545         _already_checked.push_back(this1);
546     }
547   else
548     ret=_already_checked[found].isCellSupportEqual(other1,other);
549   if(ret)
550     _already_checked.push_back(b);
551   return ret;
552 }
553
554 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt) throw(INTERP_KERNEL::Exception)
555 {
556   if(_already_checked.empty())
557     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
558   if(!_already_checked[0].isEntityCell())
559     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : only available on cell entities !");
560   MEDFileField1TSStructItem other1(BuildItemFrom(other,meshSt));
561   //
562   int found=-1,i=0;
563   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
564     if((*it).isComputed())
565       { found=i; break; }
566   bool ret(false);
567   if(found==-1)
568     {
569       MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
570       ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other);
571       if(ret)
572         _already_checked.push_back(this1);
573     }
574   else
575     ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other);
576   if(ret)
577     _already_checked.push_back(other1);
578   return ret;
579 }
580
581 std::size_t MEDFileField1TSStruct::getHeapMemorySize() const
582 {
583   std::size_t ret(0);
584   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
585     ret+=(*it).getHeapMemorySize();
586   ret+=_already_checked.capacity()*sizeof(MEDFileField1TSStructItem);
587   return ret;
588 }
589
590 MEDFileField1TSStructItem MEDFileField1TSStruct::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
591 {
592   TypeOfField atype;
593   std::vector< MEDFileField1TSStructItem2 > anItems;
594   //
595   std::vector< std::vector<std::string> > pfls,locs;
596   std::vector< std::vector<TypeOfField> > typesF;
597   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
598   std::vector< std::vector<std::pair<int,int> > > strtEnds=ref->getFieldSplitedByType(0,geoTypes,typesF,pfls,locs);
599   std::size_t nbOfGeoTypes(geoTypes.size());
600   if(nbOfGeoTypes==0)
601     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref  !");
602   bool isFirst=true;
603   for(std::size_t i=0;i<nbOfGeoTypes;i++)
604     {
605       std::size_t sz=typesF[i].size();
606       if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
607         throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
608       //
609       if(isFirst)
610         atype=typesF[i][0];
611       isFirst=false;
612       //
613       for(std::size_t j=0;j<sz;j++)
614         {
615           if(atype==typesF[i][j])
616             anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
617           else
618             throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
619         }
620     }
621   MEDFileField1TSStructItem ret(atype,anItems);
622   ret.checkWithMeshStruct(meshSt,ref);
623   return ret;
624 }
625
626 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
627 {
628   if(_already_checked.empty())
629     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
630   int pos0(-1),pos1(-1);
631   if(presenceOfCellDiscr(pos0))
632     {
633       MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
634       if(presenceOfPartialNodeDiscr(pos1))
635         ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
636       return ret.retn();
637     }
638   else
639     {
640       if(!presenceOfPartialNodeDiscr(pos1))
641         {//we have only all nodes, no cell definition info -> level 0;
642           std::vector<int> levs(1,0);
643           return MEDMeshMultiLev::New(mst->getTheMesh(),levs);
644         }
645       else
646         return MEDMeshMultiLev::NewOnlyOnNode(mst->getTheMesh(),_already_checked[pos1][0].getPfl(globs));
647     }
648 }
649
650 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
651 {
652   int b0,b1;
653   bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
654   int d0,d1;
655   bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1)); 
656   if(a0!=c0 || a1!=c1)
657     return false;
658   if(a0)
659     if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
660       return false;
661   if(a1)
662     if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
663       return false;
664   return true;
665 }
666
667 /*!
668  * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
669  * 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.
670  */
671 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const throw(INTERP_KERNEL::Exception)
672 {
673   std::size_t refSz(std::numeric_limits<std::size_t>::max());
674   bool ret(false);
675   int i(0);
676   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
677     {
678       if((*it).getType()!=ON_NODES)
679         {
680           ret=true;
681           std::size_t sz((*it).getNumberOfItems());
682           if(refSz>sz)
683             { pos=i; refSz=sz; }
684         }
685     }
686   if(refSz==0)
687     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
688   return ret;
689 }
690
691 /*!
692  * Returns true if presence in \a this of discretization ON_NODES.
693  * If true is returned the pos of the first element containing the single subpart.
694  */
695 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const throw(INTERP_KERNEL::Exception)
696 {
697   int i(0);
698   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
699     {
700       if((*it).getType()==ON_NODES)
701         {
702           std::size_t sz((*it).getNumberOfItems());
703           if(sz==1)
704             {
705               if(!(*it)[0].getPflName().empty())
706                 { pos=i; return true; }
707             }
708           else
709             throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
710         }
711     }
712   return false;
713 }
714
715 //=
716
717 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref) throw(INTERP_KERNEL::Exception)
718 {
719   return new MEDFileFastCellSupportComparator(m,ref);
720 }
721
722 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
723 {
724   if(!m)
725     throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
726   _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
727   int nbPts=ref->getNumberOfTS();
728   _f1ts_cmps.resize(nbPts);
729   for(int i=0;i<nbPts;i++)
730     {
731       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
732       _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
733       _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt);
734     }
735 }
736
737 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySize() const
738 {
739   std::size_t ret(0);
740   const MEDFileMeshStruct *mst(_mesh_comp);
741   if(mst)
742     ret+=mst->getHeapMemorySize();
743   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
744     {
745       const MEDFileField1TSStruct *cur(*it);
746       if(cur)
747         ret+=cur->getHeapMemorySize()+sizeof(MEDFileField1TSStruct);
748     }
749   ret+=_f1ts_cmps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct>);
750   return ret;
751 }
752
753 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception)
754 {
755   int nbPts=other->getNumberOfTS();
756   if(nbPts!=(int)_f1ts_cmps.size())
757     {
758       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in  input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
759       throw INTERP_KERNEL::Exception(oss.str().c_str());
760     }
761   for(int i=0;i<nbPts;i++)
762     {
763       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
764       if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
765         if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
766           return false;
767     }
768   return true;
769 }
770
771 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception)
772 {
773   int nbPts=other->getNumberOfTS();
774   if(nbPts!=(int)_f1ts_cmps.size())
775     {
776       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in  input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
777       throw INTERP_KERNEL::Exception(oss.str().c_str());
778     }
779   for(int i=0;i<nbPts;i++)
780     {
781       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
782       if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
783         return false;
784     }
785   return true;
786 }
787
788 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
789 {
790   if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
791     {
792       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
793       throw INTERP_KERNEL::Exception(oss.str().c_str());
794     }
795   const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
796   if(!obj)
797     {
798       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
799       throw INTERP_KERNEL::Exception(oss.str().c_str());
800     }
801   return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
802 }
803
804 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
805 {
806   if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
807     {
808       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
809       throw INTERP_KERNEL::Exception(oss.str().c_str());
810     }
811   const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
812   const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
813   return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);
814 }
815
816 //=
817
818 std::size_t MEDMeshMultiLev::getHeapMemorySize() const
819 {
820   return 0;
821 }
822
823 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
824 {
825   if(!m)
826     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : null input pointer !");
827   const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
828   if(um)
829     return MEDUMeshMultiLev::New(um,levs);
830   const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
831   if(cm)
832     return MEDCMeshMultiLev::New(cm,levs);
833   const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
834   if(clm)
835     return MEDCurveLinearMeshMultiLev::New(clm,levs);
836   throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
837 }
838
839 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception)
840 {
841   if(!m)
842     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : null input pointer !");
843   const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
844   if(um)
845     return MEDUMeshMultiLev::New(um,gts,pfls,nbEntities);
846   const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
847   if(cm)
848     return MEDCMeshMultiLev::New(cm,gts,pfls,nbEntities);
849   const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
850   if(clm)
851     return MEDCurveLinearMeshMultiLev::New(clm,gts,pfls,nbEntities);
852   throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
853 }
854
855 MEDMeshMultiLev *MEDMeshMultiLev::NewOnlyOnNode(const MEDFileMesh *m, const DataArrayInt *pflOnNode) throw(INTERP_KERNEL::Exception)
856 {
857   std::vector<int> levs(1,0);
858   MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(MEDMeshMultiLev::New(m,levs));
859   ret->selectPartOfNodes(pflOnNode);
860   return ret.retn();
861 }
862
863 void MEDMeshMultiLev::setNodeReduction(const DataArrayInt *nr)
864 {
865   if(nr)
866     nr->incrRef();
867   _node_reduction=const_cast<DataArrayInt*>(nr);
868 }
869
870 MEDMeshMultiLev::MEDMeshMultiLev()
871 {
872 }
873
874 MEDMeshMultiLev::MEDMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):_geo_types(gts),_nb_entities(nbEntities)
875 {
876   std::size_t sz(_geo_types.size());
877   if(sz!=pfls.size() || sz!=nbEntities.size())
878     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
879   _pfls.resize(sz);
880   for(std::size_t i=0;i<sz;i++)
881     {
882       if(pfls[i])
883         pfls[i]->incrRef();
884       _pfls[i]=const_cast<DataArrayInt *>(pfls[i]);
885     }
886 }
887
888 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
889 {
890   return new MEDUMeshMultiLev(m,levs);
891 }
892
893 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs)
894 {
895   if(!m)
896     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
897   std::vector<MEDCoupling1GTUMesh *> v;
898   for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
899     {
900       std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
901       v.insert(v.end(),vTmp.begin(),vTmp.end());
902     }
903   std::size_t sz(v.size());
904   _parts.resize(sz);
905   _pfls.resize(sz);
906   _geo_types.resize(sz);
907   for(std::size_t i=0;i<sz;i++)
908     {
909       MEDCoupling1GTUMesh *obj(v[i]);
910       if(obj)
911         obj->incrRef();
912       else
913         throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
914       _parts[i]=obj;
915       _geo_types[i]=obj->getCellModelEnum();
916     }
917 }
918
919 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception)
920 {
921   return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
922 }
923
924 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities)
925 {
926   std::size_t sz(gts.size());
927   _parts.resize(sz);
928   for(std::size_t i=0;i<sz;i++)
929     {
930       MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
931       if(elt)
932         elt->incrRef();
933       _parts[i]=elt;
934     }
935 }
936
937 void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes) throw(INTERP_KERNEL::Exception)
938 {
939    if(!pflNodes || !pflNodes->isAllocated())
940      return ;
941    /*std::vector<int> ngs(getNodeGridStructure());
942   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
943   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",GMEDCouplingStructuredMesh::etGeoTypeGivenMeshDimension(ngs.size())));
944   m->setNodalConnectivity(conn);
945   DataArrayInt *cellIds=0;
946   m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
947   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
948   MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
949   int tmp=-1;
950   _node_reduction=m2->getNodeIdsInUse(tmp);*/
951 }
952
953 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
954 {
955   return new MEDCMeshMultiLev(m,levs);
956 }
957
958 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception)
959 {
960   return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
961 }
962
963 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs)
964 {
965   if(!m)
966     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
967   if(levs.size()!=1 || levs[0]!=0)
968     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
969   int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
970   _coords.resize(mdim);
971   for(int i=0;i<mdim;i++)
972     {
973       DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
974       if(!elt)
975         throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
976       _coords[i]=elt;
977     }
978 }
979
980 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDStructuredMeshMultiLev(gts,pfls,nbEntities)
981 {
982   if(!m)
983     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
984   if(gts.size()!=1 || pfls.size()!=1)
985     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
986   int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
987   if(mdim!=gts[0])
988     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
989   _coords.resize(mdim);
990   for(int i=0;i<mdim;i++)
991     {
992       DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
993       if(!elt)
994         throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
995       _coords[i]=elt;
996     }
997 }
998
999 std::vector<int> MEDCMeshMultiLev::getNodeGridStructure() const throw(INTERP_KERNEL::Exception)
1000 {
1001   std::vector<int> ret(_coords.size());
1002   for(std::size_t i=0;i<_coords.size();i++)
1003     ret[i]=_coords[i]->getNumberOfTuples();
1004   return ret;
1005 }
1006
1007 //=
1008
1009 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
1010 {
1011   return new MEDCurveLinearMeshMultiLev(m,levs);
1012 }
1013
1014 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception)
1015 {
1016   return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
1017 }
1018
1019 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1020 {
1021   if(!m)
1022     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
1023   if(levs.size()!=1 || levs[0]!=0)
1024     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
1025   DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1026   if(!coords)
1027     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1028   coords->incrRef();
1029   _coords=coords;
1030   _structure=m->getMesh()->getNodeGridStructure();
1031 }
1032
1033 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDStructuredMeshMultiLev(gts,pfls,nbEntities)
1034 {
1035   if(!m)
1036     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1037   if(gts.size()!=1 || pfls.size()!=1)
1038     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1039   int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1040   if(mdim!=gts[0])
1041     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
1042   DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1043   if(!coords)
1044     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1045   coords->incrRef();
1046   _coords=coords;
1047   _structure=m->getMesh()->getNodeGridStructure();
1048 }
1049
1050 std::vector<int> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const throw(INTERP_KERNEL::Exception)
1051 {
1052   return _structure;
1053 }
1054
1055 //=
1056
1057 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev()
1058 {
1059 }
1060
1061 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities)
1062 {
1063 }
1064
1065 void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes) throw(INTERP_KERNEL::Exception)
1066 {
1067   if(!pflNodes || !pflNodes->isAllocated())
1068     return ;
1069   std::vector<int> ngs(getNodeGridStructure());
1070   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
1071   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(ngs.size())));
1072   m->setNodalConnectivity(conn);
1073   DataArrayInt *cellIds=0;
1074   m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
1075   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
1076   MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
1077   int tmp=-1;
1078   _node_reduction=m2->getNodeIdsInUse(tmp);
1079 }