Salome HOME
On the highway to MEDReader
[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 MEDFileFieldGlobs *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 MEDFileFieldGlobs *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 MEDFileFieldGlobs *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 MEDFileFieldGlobs *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 MEDFileFieldGlobs *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 MEDFileFieldGlobs *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 MEDFileFieldGlobs *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 MEDFileFieldGlobs *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 MEDFileFieldGlobs *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->contentNotNull()));
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->contentNotNull()));
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->contentNotNull()));
570       ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other->contentNotNull());
571       if(ret)
572         _already_checked.push_back(this1);
573     }
574   else
575     ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other->contentNotNull());
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->contentNotNull());
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     }
646 }
647
648 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
649 {
650   int b0,b1;
651   bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
652   int d0,d1;
653   bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1)); 
654   if(a0!=c0 || a1!=c1)
655     return false;
656   if(a0)
657     if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
658       return false;
659   if(a1)
660     if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
661       return false;
662   return true;
663 }
664
665 /*!
666  * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
667  * 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.
668  */
669 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const throw(INTERP_KERNEL::Exception)
670 {
671   std::size_t refSz(std::numeric_limits<std::size_t>::max());
672   bool ret(false);
673   int i(0);
674   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
675     {
676       if((*it).getType()!=ON_NODES)
677         {
678           ret=true;
679           std::size_t sz((*it).getNumberOfItems());
680           if(refSz>sz)
681             { pos=i; refSz=sz; }
682         }
683     }
684   if(refSz==0)
685     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
686   return ret;
687 }
688
689 /*!
690  * Returns true if presence in \a this of discretization ON_NODES.
691  * If true is returned the pos of the first element containing the single subpart.
692  */
693 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const throw(INTERP_KERNEL::Exception)
694 {
695   int i(0);
696   for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
697     {
698       if((*it).getType()==ON_NODES)
699         {
700           std::size_t sz((*it).getNumberOfItems());
701           if(sz==1)
702             {
703               if(!(*it)[0].getPflName().empty())
704                 { pos=i; return true; }
705             }
706           else
707             throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
708         }
709     }
710   return false;
711 }
712
713 //=
714
715 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref) throw(INTERP_KERNEL::Exception)
716 {
717   return new MEDFileFastCellSupportComparator(m,ref);
718 }
719
720 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
721 {
722   if(!m)
723     throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
724   _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
725   int nbPts=ref->getNumberOfTS();
726   _f1ts_cmps.resize(nbPts);
727   for(int i=0;i<nbPts;i++)
728     {
729       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
730       _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
731       _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt->contentNotNull());
732     }
733 }
734
735 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySize() const
736 {
737   std::size_t ret(0);
738   const MEDFileMeshStruct *mst(_mesh_comp);
739   if(mst)
740     ret+=mst->getHeapMemorySize();
741   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
742     {
743       const MEDFileField1TSStruct *cur(*it);
744       if(cur)
745         ret+=cur->getHeapMemorySize()+sizeof(MEDFileField1TSStruct);
746     }
747   ret+=_f1ts_cmps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct>);
748   return ret;
749 }
750
751 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception)
752 {
753   int nbPts=other->getNumberOfTS();
754   if(nbPts!=(int)_f1ts_cmps.size())
755     {
756       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in  input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
757       throw INTERP_KERNEL::Exception(oss.str().c_str());
758     }
759   for(int i=0;i<nbPts;i++)
760     {
761       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
762       if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
763         if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
764           return false;
765     }
766   return true;
767 }
768
769 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception)
770 {
771   int nbPts=other->getNumberOfTS();
772   if(nbPts!=(int)_f1ts_cmps.size())
773     {
774       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in  input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
775       throw INTERP_KERNEL::Exception(oss.str().c_str());
776     }
777   for(int i=0;i<nbPts;i++)
778     {
779       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
780       if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
781         return false;
782     }
783   return true;
784 }
785
786 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
787 {
788   if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
789     {
790       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
791       throw INTERP_KERNEL::Exception(oss.str().c_str());
792     }
793   const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
794   if(!obj)
795     {
796       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
797       throw INTERP_KERNEL::Exception(oss.str().c_str());
798     }
799   return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
800 }
801
802 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
803 {
804   if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
805     {
806       std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
807       throw INTERP_KERNEL::Exception(oss.str().c_str());
808     }
809   const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
810   const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
811   return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);
812 }
813
814 //=
815
816 std::size_t MEDMeshMultiLev::getHeapMemorySize() const
817 {
818   return 0;
819 }
820
821 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
822 {
823   if(!m)
824     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : null input pointer !");
825   const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
826   if(um)
827     return MEDUMeshMultiLev::New(um,levs);
828   const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
829   if(cm)
830     return MEDCMeshMultiLev::New(cm,levs);
831   const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
832   if(clm)
833     return MEDCurveLinearMeshMultiLev::New(clm,levs);
834   throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
835 }
836
837 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)
838 {
839   if(!m)
840     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : null input pointer !");
841   const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
842   if(um)
843     return MEDUMeshMultiLev::New(um,gts,pfls,nbEntities);
844   const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
845   if(cm)
846     return MEDCMeshMultiLev::New(cm,gts,pfls,nbEntities);
847   const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
848   if(clm)
849     return MEDCurveLinearMeshMultiLev::New(clm,gts,pfls,nbEntities);
850   throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
851 }
852
853 void MEDMeshMultiLev::setNodeReduction(const DataArrayInt *nr)
854 {
855   if(nr)
856     nr->incrRef();
857   _node_reduction=const_cast<DataArrayInt*>(nr);
858 }
859
860 MEDMeshMultiLev::MEDMeshMultiLev()
861 {
862 }
863
864 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)
865 {
866   std::size_t sz(_geo_types.size());
867   if(sz!=pfls.size() || sz!=nbEntities.size())
868     throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
869   _pfls.resize(sz);
870   for(std::size_t i=0;i<sz;i++)
871     {
872       if(pfls[i])
873         pfls[i]->incrRef();
874       _pfls[i]=const_cast<DataArrayInt *>(pfls[i]);
875     }
876 }
877
878 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
879 {
880   return new MEDUMeshMultiLev(m,levs);
881 }
882
883 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs)
884 {
885   if(!m)
886     throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
887   std::vector<MEDCoupling1GTUMesh *> v;
888   for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
889     {
890       std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
891       v.insert(v.end(),vTmp.begin(),vTmp.end());
892     }
893   std::size_t sz(v.size());
894   _parts.resize(sz);
895   _pfls.resize(sz);
896   _geo_types.resize(sz);
897   for(std::size_t i=0;i<sz;i++)
898     {
899       MEDCoupling1GTUMesh *obj(v[i]);
900       if(obj)
901         obj->incrRef();
902       else
903         throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
904       _parts[i]=obj;
905       _geo_types[i]=obj->getCellModelEnum();
906     }
907 }
908
909 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)
910 {
911   return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
912 }
913
914 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)
915 {
916   std::size_t sz(gts.size());
917   _parts.resize(sz);
918   for(std::size_t i=0;i<sz;i++)
919     {
920       MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
921       if(elt)
922         elt->incrRef();
923       _parts[i]=elt;
924     }
925 }
926
927 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
928 {
929   return new MEDCMeshMultiLev(m,levs);
930 }
931
932 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)
933 {
934   return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
935 }
936
937 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs)
938 {
939   if(!m)
940     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
941   if(levs.size()!=1 || levs[0]!=0)
942     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
943   int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
944   _coords.resize(mdim);
945   for(int i=0;i<mdim;i++)
946     {
947       DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
948       if(!elt)
949         throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
950       _coords[i]=elt;
951     }
952 }
953
954 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities)
955 {
956   if(!m)
957     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
958   if(gts.size()!=1 || pfls.size()!=1)
959     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
960   int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
961   if(mdim!=gts[0])
962     throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
963   _coords.resize(mdim);
964   for(int i=0;i<mdim;i++)
965     {
966       DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
967       if(!elt)
968         throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
969       _coords[i]=elt;
970     }
971 }
972
973 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
974 {
975   return new MEDCurveLinearMeshMultiLev(m,levs);
976 }
977
978 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)
979 {
980   return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
981 }
982
983 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
984 {
985   if(!m)
986     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
987   if(levs.size()!=1 || levs[0]!=0)
988     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
989   DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
990   if(!coords)
991     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
992   coords->incrRef();
993   _coords=coords;
994   _structure=m->getMesh()->getNodeGridStructure();
995 }
996
997 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities)
998 {
999   if(!m)
1000     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1001   if(gts.size()!=1 || pfls.size()!=1)
1002     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1003   int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1004   if(mdim!=gts[0])
1005     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
1006   DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1007   if(!coords)
1008     throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1009   coords->incrRef();
1010   _coords=coords;
1011   _structure=m->getMesh()->getNodeGridStructure();
1012 }