Salome HOME
Structure element inside Gauss Points management
[tools/medcoupling.git] / src / MEDLoader / MEDFileMeshLL.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileMeshLL.hxx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileSafeCaller.txx"
25 #include "MEDFileMeshReadSelector.hxx"
26 #include "MEDFileStructureElement.hxx"
27 #include "MEDFileMeshSupport.hxx"
28
29 #include "MEDCouplingUMesh.hxx"
30
31 #include "InterpKernelAutoPtr.hxx"
32 #include "CellModel.hxx"
33
34 #include <set>
35 #include <iomanip>
36
37 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
38 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
39 extern med_geometry_type typmainoeud[1];
40
41 using namespace MEDCoupling;
42
43 const char MEDFileMeshL2::ZE_SEP_FOR_FAMILY_KILLERS[]="!/__\\!";//important start by - because ord('!')==33 the smallest (!=' ') to preserve orders at most.
44
45 int MEDFileMeshL2::ZE_SEP2_FOR_FAMILY_KILLERS=4;
46
47 std::vector<std::string> MeshCls::getAxisInfoOnMesh(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim, MEDFileString& description, MEDFileString& dtunit, MEDFileString& univName) const
48 {
49   med_mesh_type type_maillage;
50   med_int spaceDim;
51   med_sorting_type stype;
52   med_axis_type axistype;
53   int naxis(MEDmeshnAxis(fid,getID()));
54   INTERP_KERNEL::AutoPtr<char> nameTmp(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
55   INTERP_KERNEL::AutoPtr<char> axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
56   INTERP_KERNEL::AutoPtr<char> axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
57   INTERP_KERNEL::AutoPtr<char> univTmp(MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE));
58   if(MEDmeshInfo(fid,getID(),nameTmp,&spaceDim,&Mdim,&type_maillage,description.getPointer(),dtunit.getPointer(),
59       &stype,&nstep,&axistype,axisname,axisunit)!=0)
60     throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !");
61   MEDmeshUniversalNameRd(fid,nameTmp,univName.getPointer());// do not protect  MEDFILESAFECALLERRD0 call : Thanks to fra.med.
62   axType=MEDFileMeshL2::TraduceAxisType(axistype);
63   switch(type_maillage)
64   {
65     case MED_UNSTRUCTURED_MESH:
66       meshType=UNSTRUCTURED;
67       break;
68     case MED_STRUCTURED_MESH:
69       {
70         med_grid_type gt;
71         MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gt));
72         switch(gt)
73         {
74           case MED_CARTESIAN_GRID:
75             meshType=CARTESIAN;
76             break;
77           case MED_CURVILINEAR_GRID:
78             meshType=CURVE_LINEAR;
79             break;
80         case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
81             meshType=CARTESIAN;
82             break;
83           default:
84             throw INTERP_KERNEL::Exception("MEDFileMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
85         }
86         break;
87       }
88     default:
89       throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
90   }
91   //
92   std::vector<std::string> infosOnComp(naxis);
93   for(int i=0;i<naxis;i++)
94     {
95       std::string info(MEDLoaderBase::buildUnionUnit(((char *)axisname)+i*MED_SNAME_SIZE,MED_SNAME_SIZE,((char *)axisunit)+i*MED_SNAME_SIZE,MED_SNAME_SIZE));
96       infosOnComp[i]=info;
97     }
98   return infosOnComp;
99 }
100
101 double MeshCls::checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const
102 {
103   bool found=false;
104   med_int numdt,numit;
105   med_float dtt;
106   std::vector< std::pair<int,int> > p(nstep);
107   for(int i=0;i<nstep;i++)
108     {
109       MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mName.c_str(),i+1,&numdt,&numit,&dtt));
110       p[i]=std::make_pair((int)numdt,(int)numit);
111       found=(numdt==dt) && (numit==it);
112       if (found) break;
113     }
114   if(!found)
115     {
116       std::ostringstream oss; oss << "No such iteration=" << dt << ",order=" << it << " numbers found for mesh '" << mName << "' ! ";
117       oss << "Possibilities are : ";
118       for(int i=0;i<nstep;i++)
119         oss << "(" << p[i].first << "," << p[i].second << "), ";
120       throw INTERP_KERNEL::Exception(oss.str().c_str());
121     }
122   return dtt;
123 }
124
125 std::vector<std::string> StructMeshCls::getAxisInfoOnMesh(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim, MEDFileString& description, MEDFileString& dtunit, MEDFileString& univName) const
126 {
127   INTERP_KERNEL::AutoPtr<char> msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
128   INTERP_KERNEL::AutoPtr<char> zeDescription(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE));
129   med_axis_type medAxType;
130   int nAxis(MEDsupportMeshnAxis(fid,getID()));
131   INTERP_KERNEL::AutoPtr<char> axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]);
132   int spaceDim(0),meshDim(0);
133   MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,getID(),msn,&spaceDim,&meshDim,zeDescription,&medAxType,axisName,axisUnit));
134   std::string descriptionCpp(MEDLoaderBase::buildStringFromFortran(zeDescription,MED_COMMENT_SIZE));
135   description.set(descriptionCpp.c_str());
136   dtunit.clear(); univName.clear(); meshType=UNSTRUCTURED; nstep=1;
137   axType=MEDFileMeshL2::TraduceAxisType(medAxType);
138   //int nmodels(0);
139   //med_bool chgt=MED_FALSE,trsf=MED_FALSE;
140   //nmodels=MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_STRUCT_ELEMENT,MED_GEO_ALL,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf);
141   std::vector<std::string> ret;
142   for(int i=0;i<nAxis;i++)
143     {
144       std::string info(DataArray::BuildInfoFromVarAndUnit(MEDLoaderBase::buildStringFromFortran(axisName+i*MED_SNAME_SIZE,MED_SNAME_SIZE),
145                                                           MEDLoaderBase::buildStringFromFortran(axisUnit+i*MED_SNAME_SIZE,MED_SNAME_SIZE)));
146       ret.push_back(info);
147     }
148   return ret;
149 }
150
151 double StructMeshCls::checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const
152 {
153   return 0.;
154 }
155
156 MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_univ_name(MED_LNAME_SIZE),_dt_unit(MED_LNAME_SIZE)
157 {
158 }
159
160 std::size_t MEDFileMeshL2::getHeapMemorySizeWithoutChildren() const
161 {
162   return 0;
163 }
164
165 std::vector<const BigMemoryObject *> MEDFileMeshL2::getDirectChildrenWithNull() const
166 {
167   return std::vector<const BigMemoryObject *>();
168 }
169
170 INTERP_KERNEL::AutoCppPtr<MeshOrStructMeshCls> MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& dt, int& it, std::string& dtunit1)
171 {
172   med_mesh_type type_maillage;
173   char maillage_description[MED_COMMENT_SIZE+1];
174   char dtunit[MED_LNAME_SIZE+1];
175   med_int spaceDim,dim;
176   char nommaa[MED_NAME_SIZE+1];
177   med_int n=MEDnMesh(fid);
178   char found(0);
179   int ret=-1;
180   med_sorting_type stype;
181   std::vector<std::string> ms;
182   int nstep;
183   med_axis_type axistype;
184   for(int i=0;i<n && found==0;i++)
185     {
186       int naxis(MEDmeshnAxis(fid,i+1));
187       INTERP_KERNEL::AutoPtr<char> axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)),axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
188       MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));      
189       dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit));
190       std::string cur(MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa)));
191       ms.push_back(cur);
192       if(cur==mName)
193         {
194           found=1;
195           ret=i+1;
196         }
197     }
198   if(found==0)
199     {//last chance ! Is it a support mesh ?
200       int nbSM(MEDnSupportMesh(fid));
201       for(int i=0;i<nbSM && found==0;i++)
202         {
203           int naxis(MEDsupportMeshnAxis(fid,i+1));
204           INTERP_KERNEL::AutoPtr<char> axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)),axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
205           MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,maillage_description,&axistype,axisname,axisunit));
206           std::string cur(MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa)));
207           ms.push_back(cur);
208           if(cur==mName)
209             {
210               found=2;
211               ret=i+1;
212             }
213         }
214     }
215   ////////////////////////
216   switch(found)
217     {
218     case 1:
219       {
220         axType=TraduceAxisType(axistype);
221         switch(type_maillage)
222           {
223           case MED_UNSTRUCTURED_MESH:
224             meshType=UNSTRUCTURED;
225             break;
226           case MED_STRUCTURED_MESH:
227             {
228               med_grid_type gt;
229               MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gt));
230               switch(gt)
231                 {
232                 case MED_CARTESIAN_GRID:
233                   meshType=CARTESIAN;
234                   break;
235                 case MED_CURVILINEAR_GRID:
236                   meshType=CURVE_LINEAR;
237                   break;
238                 case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
239                   meshType=CARTESIAN;
240                   break;
241                 default:
242                   throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
243                 }
244               break;
245             }
246           default:
247             throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
248           }
249         med_int numdt,numit;
250         med_float dtt;
251         MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mName.c_str(),1,&numdt,&numit,&dtt));
252         dt=numdt; it=numit;
253         return new MeshCls(ret);
254       }
255     case 2:
256       {
257         meshType=UNSTRUCTURED;
258         dt=MED_NO_DT; it=MED_NO_IT; dtunit1.clear();
259         axType=axType=TraduceAxisType(axistype);
260         return new StructMeshCls(ret);
261       }
262     default:
263       {
264         std::ostringstream oss;
265         oss << "No such meshname (" << mName <<  ") in file ! Must be in : ";
266         std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss,", "));
267         throw INTERP_KERNEL::Exception(oss.str().c_str());
268       }
269     }
270   
271 }
272
273 /*!
274  * non static and non const method because _description, _dt_unit... are set in this method.
275  */
276 std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim)
277 {
278   return mId->getAxisInfoOnMesh(fid,mName,meshType,axType,nstep,Mdim,_description,_dt_unit,_univ_name);
279 }
280
281 void MEDFileMeshL2::ReadFamiliesAndGrps(med_idt fid, const std::string& meshName, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps, MEDFileMeshReadSelector *mrs)
282 {
283   if(mrs && !(mrs->isCellFamilyFieldReading() || mrs->isNodeFamilyFieldReading()))
284     return ;
285   char nomfam[MED_NAME_SIZE+1];
286   med_int numfam;
287   int nfam=MEDnFamily(fid,meshName.c_str());
288   std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > > crudeFams(nfam);
289   for(int i=0;i<nfam;i++)
290     {
291       int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
292       med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
293       INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
294       INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
295       INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
296       INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
297       MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
298       std::string famName(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE));
299       std::vector<std::string> grps(ngro);
300       for(int j=0;j<ngro;j++)
301         grps[j]=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
302       crudeFams[i]=std::pair<std::string,std::pair<int,std::vector<std::string> > >(famName,std::pair<int,std::vector<std::string> >(numfam,grps));
303     }
304   RenameFamiliesFromFileToMemInternal(crudeFams);
305   for(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >::const_iterator it0=crudeFams.begin();it0!=crudeFams.end();it0++)
306     {
307       fams[(*it0).first]=(*it0).second.first;
308       for(std::vector<std::string>::const_iterator it1=(*it0).second.second.begin();it1!=(*it0).second.second.end();it1++)
309         grps[*it1].push_back((*it0).first);
310     }
311 }
312
313 void MEDFileMeshL2::WriteFamiliesAndGrps(med_idt fid, const std::string& mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol)
314 {
315   std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > > crudeFams(fams.size());
316   std::size_t ii(0);
317   for(std::map<std::string,int>::const_iterator it=fams.begin();it!=fams.end();it++,ii++)
318     {
319       std::vector<std::string> grpsOfFam;
320       for(std::map<std::string, std::vector<std::string> >::const_iterator it1=grps.begin();it1!=grps.end();it1++)
321         {
322           if(std::find((*it1).second.begin(),(*it1).second.end(),(*it).first)!=(*it1).second.end())
323             grpsOfFam.push_back((*it1).first);
324         }
325       crudeFams[ii]=std::pair<std::string,std::pair<int,std::vector<std::string> > >((*it).first,std::pair<int,std::vector<std::string> >((*it).second,grpsOfFam));
326     }
327   RenameFamiliesFromMemToFileInternal(crudeFams);
328   for(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >::const_iterator it=crudeFams.begin();it!=crudeFams.end();it++)
329     {
330       int ngro((*it).second.second.size());
331       INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
332       int i=0;
333       for(std::vector<std::string>::const_iterator it2=(*it).second.second.begin();it2!=(*it).second.second.end();it2++,i++)
334         MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,tooLongStrPol);
335       INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
336       MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_NAME_SIZE,famName,tooLongStrPol);
337       int ret=MEDfamilyCr(fid,mname.c_str(),famName,(*it).second.first,ngro,groName);
338       ret++;
339     }
340 }
341
342 void MEDFileMeshL2::RenameFamiliesPatternInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams, RenameFamiliesPatternFunc func)
343 {
344   std::size_t ii(0);
345   std::vector<std::string> fams(crudeFams.size());
346   for(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >::const_iterator it=crudeFams.begin();it!=crudeFams.end();it++,ii++)
347     fams[ii]=(*it).first;
348   if(!func(fams))
349     return ;
350   ii=0;
351   for(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >::iterator it=crudeFams.begin();it!=crudeFams.end();it++,ii++)
352     (*it).first=fams[ii];
353 }
354
355 /*!
356  * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it.
357  * So this method renames families (if needed generaly not !) in order to have a discriminant name for families.
358  */
359 void MEDFileMeshL2::RenameFamiliesFromFileToMemInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams)
360 {
361   RenameFamiliesPatternInternal(crudeFams,RenameFamiliesFromFileToMem);
362 }
363
364 bool MEDFileMeshL2::RenameFamiliesFromFileToMem(std::vector< std::string >& famNames)
365 {
366   std::map<std::string,int> m;
367   std::set<std::string> s;
368   for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
369     {
370       if(s.find(*it)!=s.end())
371         m[*it]=0;
372       s.insert(*it);
373     }
374   if(m.empty())
375     return false;// the general case !
376   for(std::vector< std::string >::iterator it=famNames.begin();it!=famNames.end();it++)
377     {
378       std::map<std::string,int>::iterator it2(m.find(*it));
379       if(it2!=m.end())
380         {
381           std::ostringstream oss; oss << *it << ZE_SEP_FOR_FAMILY_KILLERS << std::setfill('0') << std::setw(ZE_SEP2_FOR_FAMILY_KILLERS) << (*it2).second++;
382           *it=oss.str();
383         }
384     }
385   return true;
386 }
387
388 /*!
389  * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it.
390  * So this method renames families (if needed generaly not !) in order to have a discriminant name for families.
391  */
392 void MEDFileMeshL2::RenameFamiliesFromMemToFileInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams)
393 {
394   RenameFamiliesPatternInternal(crudeFams,RenameFamiliesFromMemToFile);
395 }
396
397 bool MEDFileMeshL2::RenameFamiliesFromMemToFile(std::vector< std::string >& famNames)
398 {
399   bool isSmthingStrange(false);
400   for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
401     {
402       std::size_t found((*it).find(ZE_SEP_FOR_FAMILY_KILLERS));
403       if(found!=std::string::npos)
404         isSmthingStrange=true;
405     }
406   if(!isSmthingStrange)
407     return false;
408   // pattern matching
409   std::map< std::string, std::vector<std::string> > m;
410   for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
411     {
412       std::size_t found((*it).find(ZE_SEP_FOR_FAMILY_KILLERS));
413       if(found!=std::string::npos && found>=1)
414         {
415           std::string s1((*it).substr(found+sizeof(ZE_SEP_FOR_FAMILY_KILLERS)-1));
416           if(s1.size()!=ZE_SEP2_FOR_FAMILY_KILLERS)
417             continue;
418           int k(-1);
419           std::istringstream iss(s1);
420           iss >> k;
421           bool isOK((iss.rdstate() & ( std::istream::failbit | std::istream::eofbit)) == std::istream::eofbit);
422           if(isOK && k>=0)
423             {
424               std::string s0((*it).substr(0,found));
425               m[s0].push_back(*it);
426             }
427         }
428     }
429   if(m.empty())
430     return false;
431   // filtering
432   std::map<std::string,std::string> zeMap;
433   for(std::map< std::string, std::vector<std::string> >::const_iterator it=m.begin();it!=m.end();it++)
434     {
435       if((*it).second.size()==1)
436         continue;
437       for(std::vector<std::string>::const_iterator it1=(*it).second.begin();it1!=(*it).second.end();it1++)
438         zeMap[*it1]=(*it).first;
439     }
440   if(zeMap.empty())
441     return false;
442   // traduce
443   for(std::vector< std::string >::iterator it=famNames.begin();it!=famNames.end();it++)
444     {
445       std::map<std::string,std::string>::iterator it1(zeMap.find(*it));
446       if(it1!=zeMap.end())
447         *it=(*it1).second;
448     }    
449   return true;
450 }
451
452 MEDCoupling::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisType(med_axis_type at)
453 {
454   switch(at)
455     {
456     case MED_CARTESIAN:
457       return AX_CART;
458     case MED_CYLINDRICAL:
459       return AX_CYL;
460     case MED_SPHERICAL:
461       return AX_SPHER;
462     case MED_UNDEF_AXIS_TYPE:
463       return AX_CART;
464     default:
465       throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisType : unrecognized axis type !");
466     }
467 }
468
469 MEDCoupling::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisTypeStruct(med_grid_type gt)
470 {
471   switch(gt)
472     {
473     case MED_CARTESIAN_GRID:
474       return AX_CART;
475     case MED_POLAR_GRID:
476       return AX_CYL;
477     default:
478       throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeStruct : only Cartesian and Cylindrical supported by MED file !");
479     }
480 }
481
482 med_axis_type MEDFileMeshL2::TraduceAxisTypeRev(MEDCoupling::MEDCouplingAxisType at)
483 {
484   switch(at)
485     {
486     case AX_CART:
487       return MED_CARTESIAN;
488     case AX_CYL:
489       return MED_CYLINDRICAL;
490     case AX_SPHER:
491       return MED_SPHERICAL;
492     default:
493       throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRev : unrecognized axis type !");
494     }
495 }
496
497 med_grid_type MEDFileMeshL2::TraduceAxisTypeRevStruct(MEDCoupling::MEDCouplingAxisType at)
498 {
499   switch(at)
500     {
501     case AX_CART:
502       return MED_CARTESIAN_GRID;
503     case AX_CYL:
504       return MED_POLAR_GRID;
505     case AX_SPHER:
506       return MED_POLAR_GRID;
507     default:
508       throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRevStruct : unrecognized axis type !");
509     }
510 }
511
512 MEDFileUMeshL2::MEDFileUMeshL2()
513 {
514 }
515
516 std::vector<std::string> MEDFileUMeshL2::loadCommonPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, int& Mdim)
517 {
518   Mdim=-3;
519   _name.set(mName.c_str());
520   int nstep;
521   MEDCoupling::MEDCouplingMeshType meshType;
522   MEDCoupling::MEDCouplingAxisType dummy3;
523   std::vector<std::string> ret(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim));
524   if(nstep==0)
525     {
526       Mdim=-4;
527       return std::vector<std::string>();
528     }
529   if(meshType!=UNSTRUCTURED)
530     throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !");
531   _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it);
532   _iteration=dt;
533   _order=it;
534   return ret;
535 }
536
537 void MEDFileUMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
538 {
539   int Mdim;
540   std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
541   if(Mdim==-4)
542     return ;
543   loadConnectivity(fid,Mdim,mName,dt,it,mrs);//to improve check (dt,it) coherency
544   loadCoords(fid,infosOnComp,mName,dt,it);
545 }
546
547 void MEDFileUMeshL2::loadPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
548 {
549   int Mdim;
550   std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
551   if(Mdim==-4)
552     return ;
553   loadPartOfConnectivity(fid,Mdim,mName,types,slicPerTyp,dt,it,mrs);
554   med_bool changement,transformation;
555   int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
556   std::vector<bool> fetchedNodeIds(nCoords,false);
557   for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
558     for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
559       (*it1)->getMesh()->computeNodeIdsAlg(fetchedNodeIds);
560   int nMin(std::distance(fetchedNodeIds.begin(),std::find(fetchedNodeIds.begin(),fetchedNodeIds.end(),true)));
561   int nMax(std::distance(fetchedNodeIds.rbegin(),std::find(fetchedNodeIds.rbegin(),fetchedNodeIds.rend(),true)));
562   nMax=nCoords-nMax;
563   for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
564     for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
565       (*it1)->getMesh()->renumberNodesWithOffsetInConn(-nMin);
566   loadPartCoords(fid,infosOnComp,mName,dt,it,nMin,nMax);
567 }
568
569 void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
570 {
571   _per_type_mesh.resize(1);
572   _per_type_mesh[0].clear();
573   for(int j=0;j<MED_N_CELL_FIXED_GEO;j++)
574     {
575       MEDFileUMeshPerType *tmp(MEDFileUMeshPerType::New(fid,mName.c_str(),dt,it,mdim,typmai[j],typmai2[j],mrs));
576       if(tmp)
577         _per_type_mesh[0].push_back(tmp);
578     }
579   sortTypes();
580 }
581
582 void MEDFileUMeshL2::loadPartOfConnectivity(med_idt fid, int mdim, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
583 {
584   std::size_t nbOfTypes(types.size());
585   if(slicPerTyp.size()!=3*nbOfTypes)
586     throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartOfConnectivity : The size of slicPerTyp array is expected to be equal to 3 times size of array types !");
587   std::set<INTERP_KERNEL::NormalizedCellType> types2(types.begin(),types.end());
588   if(types2.size()!=nbOfTypes)
589     throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartOfConnectivity : the geometric types in types array must appear once !");
590   _per_type_mesh.resize(1);
591   _per_type_mesh[0].clear();
592   for(std::size_t ii=0;ii<nbOfTypes;ii++)
593     {
594       int strt(slicPerTyp[3*ii+0]),stp(slicPerTyp[3*ii+1]),step(slicPerTyp[3*ii+2]);
595       MCAuto<MEDFileUMeshPerType> tmp(MEDFileUMeshPerType::NewPart(fid,mName.c_str(),dt,it,mdim,types[ii],strt,stp,step,mrs));
596       _per_type_mesh[0].push_back(tmp);
597     }
598   sortTypes();
599 }
600
601 void MEDFileUMeshL2::loadCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it)
602 {
603   int spaceDim((int)infosOnComp.size());
604   med_bool changement,transformation;
605   int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
606   _coords=DataArrayDouble::New();
607   _coords->alloc(nCoords,spaceDim);
608   double *coordsPtr(_coords->getPointer());
609   if (nCoords)
610     MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,coordsPtr));
611   if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
612     {
613       _fam_coords=DataArrayInt::New();
614       _fam_coords->alloc(nCoords,1);
615       MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer()));
616     }
617   else
618     _fam_coords=0;
619   if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
620     {
621       _num_coords=DataArrayInt::New();
622       _num_coords->alloc(nCoords,1);
623       MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer()));
624     }
625   else
626     _num_coords=0;
627   if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
628     {
629       _name_coords=DataArrayAsciiChar::New();
630       _name_coords->alloc(nCoords+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
631       MEDFILESAFECALLERRD0(MEDmeshEntityNameRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_name_coords->getPointer()));
632       _name_coords->reAlloc(nCoords);//not a bug to avoid the memory corruption due to last \0 at the end
633     }
634   else
635     _name_coords=0;
636   for(int i=0;i<spaceDim;i++)
637     _coords->setInfoOnComponent(i,infosOnComp[i]);
638 }
639
640 void MEDFileUMeshL2::loadPartCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, int nMin, int nMax)
641 {
642   med_bool changement,transformation;
643   int spaceDim((int)infosOnComp.size()),nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
644   _coords=DataArrayDouble::New();
645   int nbNodesToLoad(nMax-nMin);
646   _coords->alloc(nbNodesToLoad,spaceDim);
647   med_filter filter=MED_FILTER_INIT,filter2=MED_FILTER_INIT;
648   MEDfilterBlockOfEntityCr(fid,/*nentity*/nCoords,/*nvaluesperentity*/1,/*nconstituentpervalue*/spaceDim,
649                            MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
650                            /*start*/nMin+1,/*stride*/1,/*count*/1,/*blocksize*/nbNodesToLoad,
651                            /*lastblocksize=useless because count=1*/0,&filter);
652   MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateAdvancedRd,(fid,mName.c_str(),dt,it,&filter,_coords->getPointer()));
653   _part_coords=PartDefinition::New(nMin,nMax,1);
654   MEDfilterClose(&filter);
655   MEDfilterBlockOfEntityCr(fid,nCoords,1,1,MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,
656                            MED_NO_PROFILE,nMin+1,1,1,nbNodesToLoad,0,&filter2);
657   if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
658     {
659       _fam_coords=DataArrayInt::New();
660       _fam_coords->alloc(nbNodesToLoad,1);
661       MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_FAMILY_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_fam_coords->getPointer()));
662     }
663   else
664     _fam_coords=0;
665   if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
666     {
667       _num_coords=DataArrayInt::New();
668       _num_coords->alloc(nbNodesToLoad,1);
669       MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_num_coords->getPointer()));
670     }
671   else
672     _num_coords=0;
673   if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
674     {
675       _name_coords=DataArrayAsciiChar::New();
676       _name_coords->alloc(nbNodesToLoad+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
677       MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NAME,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_name_coords->getPointer()));
678       _name_coords->reAlloc(nbNodesToLoad);//not a bug to avoid the memory corruption due to last \0 at the end
679     }
680   else
681     _name_coords=0;
682   MEDfilterClose(&filter2);
683   _coords->setInfoOnComponents(infosOnComp);
684 }
685
686 void MEDFileUMeshL2::sortTypes()
687 {
688   std::set<int> mdims;
689   std::vector< MCAuto<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
690   _per_type_mesh.clear();
691   for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
692     mdims.insert((*it)->getDim());
693   if(mdims.empty())
694     return;
695   int mdim=*mdims.rbegin();
696   _per_type_mesh.resize(mdim+1);
697   for(int dim=mdim+1;dim!=0;dim--)
698     {
699       std::vector< MCAuto<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
700       for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
701         if((*it)->getDim()==dim-1)
702           elt.push_back(*it);
703     }
704   // suppression of contiguous empty levels at the end of _per_type_mesh.
705   int nbOfUselessLev=0;
706   bool isFirst=true;
707   for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::reverse_iterator it2=_per_type_mesh.rbegin();it2!=_per_type_mesh.rend();it2++)
708     {
709       if((*it2).empty() && isFirst)
710         {
711           nbOfUselessLev++;
712         }
713       else
714         isFirst=false;
715     }
716   _per_type_mesh.resize(_per_type_mesh.size()-nbOfUselessLev);
717 }
718
719 void MEDFileUMeshL2::WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords)
720 {
721   if(!coords)
722     return ;
723   MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->getConstPointer()));
724   if(famCoords)
725     MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->getConstPointer()));
726   if(numCoords)
727     MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->getConstPointer()));
728   if(nameCoords)
729     {
730       if(nameCoords->getNumberOfComponents()!=MED_SNAME_SIZE)
731         {
732           std::ostringstream oss; oss << " MEDFileUMeshL2::WriteCoords : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE;
733           oss << " ! The array has " << nameCoords->getNumberOfComponents() << " components !";
734           throw INTERP_KERNEL::Exception(oss.str().c_str());
735         }
736       MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,nameCoords->getNumberOfTuples(),nameCoords->getConstPointer()));
737     }
738 }
739
740 bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
741 {
742   for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
743     if((*it)->getFam()==0)
744       return false;
745   return true;
746 }
747
748 bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const
749 {
750   for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
751     if((*it)->getNum()==0)
752       return false;
753   return true;
754 }
755
756 bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const
757 {
758   for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
759     if((*it)->getNames()==0)
760       return false;
761   return true;
762 }
763
764 MEDFileCMeshL2::MEDFileCMeshL2():_ax_type(AX_CART)
765 {
766 }
767
768 void MEDFileCMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it)
769 {
770   _name.set(mName.c_str());
771   int nstep;
772   int Mdim;
773   MEDCoupling::MEDCouplingMeshType meshType;
774   MEDCoupling::MEDCouplingAxisType dummy3;
775   std::vector<std::string> infosOnComp(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim));
776   if(meshType!=CARTESIAN)
777     throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
778   _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it);
779   _iteration=dt;
780   _order=it;
781   //
782   med_grid_type gridtype;
783   MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gridtype));
784   if(gridtype!=MED_CARTESIAN_GRID && gridtype!=MED_POLAR_GRID)
785     throw INTERP_KERNEL::Exception("Invalid rectilinear mesh ! Only cartesian and polar are supported !");
786   _ax_type=TraduceAxisTypeStruct(gridtype);
787   _cmesh=MEDCouplingCMesh::New();
788   for(int i=0;i<Mdim;i++)
789     {
790       med_data_type dataTypeReq=GetDataTypeCorrespondingToSpaceId(i);
791       med_bool chgt=MED_FALSE,trsf=MED_FALSE;
792       int nbOfElt(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,dataTypeReq,MED_NO_CMODE,&chgt,&trsf));
793       MCAuto<DataArrayDouble> da=DataArrayDouble::New();
794       da->alloc(nbOfElt,1);
795       da->setInfoOnComponent(0,infosOnComp[i]);
796       MEDFILESAFECALLERRD0(MEDmeshGridIndexCoordinateRd,(fid,mName.c_str(),dt,it,i+1,da->getPointer()));
797       _cmesh->setCoordsAt(i,da);
798     }
799 }
800
801 med_data_type MEDFileCMeshL2::GetDataTypeCorrespondingToSpaceId(int id)
802 {
803   switch(id)
804   {
805     case 0:
806       return MED_COORDINATE_AXIS1;
807     case 1:
808       return MED_COORDINATE_AXIS2;
809     case 2:
810       return MED_COORDINATE_AXIS3;
811     default:
812       throw INTERP_KERNEL::Exception("Invalid meshdim detected in Cartesian Grid !");
813   }
814 }
815
816 MEDFileCLMeshL2::MEDFileCLMeshL2()
817 {
818 }
819
820 void MEDFileCLMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it)
821 {
822   _name.set(mName.c_str());
823   int nstep;
824   int Mdim;
825   MEDCoupling::MEDCouplingMeshType meshType;
826   MEDCoupling::MEDCouplingAxisType dummy3;
827   std::vector<std::string> infosOnComp(getAxisInfoOnMesh(fid,mId,mName,meshType,dummy3,nstep,Mdim));
828   if(meshType!=CURVE_LINEAR)
829     throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
830   _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it);
831   _iteration=dt;
832   _order=it;
833   //
834   _clmesh=MEDCouplingCurveLinearMesh::New();
835   INTERP_KERNEL::AutoPtr<int> stGrid=new int[Mdim];
836   MEDFILESAFECALLERRD0(MEDmeshGridStructRd,(fid,mName.c_str(),dt,it,stGrid));
837   _clmesh->setNodeGridStructure(stGrid,((int *)stGrid)+Mdim);
838   med_bool chgt=MED_FALSE,trsf=MED_FALSE;
839   int nbNodes(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&chgt,&trsf));
840   MCAuto<DataArrayDouble> da=DataArrayDouble::New();
841   da->alloc(nbNodes,infosOnComp.size());
842   da->setInfoOnComponents(infosOnComp);
843   MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,da->getPointer()));
844   _clmesh->setCoords(da);
845 }
846
847 MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0)
848 {
849 }
850
851 /*!
852  * Warning it returns an instance to deallocate !!!!
853  */
854 MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
855 {
856   _st->_num->updateTime();
857   if((MEDCouplingUMesh *)_m==0)
858     {
859       updateTime();
860       _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
861       _m->renumberCells(_st->_num->getConstPointer(),true);
862       return _m.retn();
863     }
864   else
865     {
866       if(_mpt_time==_st->_m_by_types.getTimeOfThis() && _num_time==_st->_num->getTimeOfThis())
867         return _m.retn();
868       else
869         {
870           updateTime();
871           _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
872           _m->renumberCells(_st->_num->getConstPointer(),true);
873           return _m.retn();
874         }
875     }
876 }
877
878 void MEDFileUMeshPermCompute::operator=(MEDCouplingUMesh *m)
879 {
880   _m=m;
881 }
882
883 void MEDFileUMeshPermCompute::updateTime() const
884 {
885   _mpt_time=_st->_m_by_types.getTimeOfThis();
886   _num_time=_st->_num->getTimeOfThis();
887 }
888
889 std::vector<const BigMemoryObject *> MEDFileUMeshPermCompute::getDirectChildrenWithNull() const
890 {
891   std::vector<const BigMemoryObject *> ret;
892   ret.push_back((const MEDCouplingUMesh *)_m);
893   return ret;
894 }
895
896 std::size_t MEDFileUMeshPermCompute::getHeapMemorySizeWithoutChildren() const
897 {
898   return sizeof(MEDFileUMeshPermCompute);
899 }
900
901 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other):RefCountObject(other),_m_by_types(other._m_by_types),_fam(other._fam),_num(other._num),_names(other._names),_rev_num(other._rev_num),_m(this)
902 {
903 }
904
905 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id):_m(this)
906 {
907   const std::vector< MCAuto<MEDFileUMeshPerType> >& v=l2.getLev(id);
908   if(v.empty())
909     return;
910   int sz=v.size();
911   std::vector<const MEDCoupling1GTUMesh *> ms(sz);
912   std::vector<const DataArrayInt *> fams(sz),nums(sz);
913   std::vector<const DataArrayChar *> names(sz);
914   std::vector<const PartDefinition *> pds(sz);
915   for(int i=0;i<sz;i++)
916     {
917       MEDCoupling1GTUMesh *elt(v[i]->getMesh());
918       MCAuto<DataArrayDouble> tmp2=l2.getCoords();
919       elt->setCoords(tmp2);
920       ms[i]=elt;
921       pds[i]=v[i]->getPartDef();
922     }
923   _m_by_types.assignParts(ms);
924   _m_by_types.assignDefParts(pds);
925   if(l2.isFamDefinedOnLev(id))
926     {
927       for(int i=0;i<sz;i++)
928         fams[i]=v[i]->getFam();
929       if(sz!=1)
930         _fam=DataArrayInt::Aggregate(fams);
931       else
932         {
933           fams[0]->incrRef();
934           _fam=const_cast<DataArrayInt *>(fams[0]);
935         }
936     }
937   if(l2.isNumDefinedOnLev(id))
938     {
939       for(int i=0;i<sz;i++)
940         nums[i]=v[i]->getNum();
941       if(sz!=1)
942         _num=DataArrayInt::Aggregate(nums);
943       else
944         {
945           nums[0]->incrRef();
946           _num=const_cast<DataArrayInt *>(nums[0]);
947         }
948       computeRevNum();
949     }
950   if(l2.isNamesDefinedOnLev(id))
951     {
952       for(int i=0;i<sz;i++)
953         names[i]=v[i]->getNames();
954       _names=dynamic_cast<DataArrayAsciiChar *>(DataArrayChar::Aggregate(names));
955     }
956 }
957
958 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m):_m(this)
959 {
960   std::vector< const MEDCoupling1GTUMesh * > v(1);
961   v[0]=m;
962   assignParts(v);
963 }
964
965 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this)
966 {
967   assignMesh(m,true);
968 }
969
970 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m(this)
971 {
972   assignMesh(m,newOrOld);
973 }
974
975 void MEDFileUMeshSplitL1::setName(const std::string& name)
976 {
977   _m_by_types.setName(name);
978 }
979
980 std::size_t MEDFileUMeshSplitL1::getHeapMemorySizeWithoutChildren() const
981 {
982   return 0;
983 }
984
985 std::vector<const BigMemoryObject *> MEDFileUMeshSplitL1::getDirectChildrenWithNull() const
986 {
987   std::vector<const BigMemoryObject *> ret;
988   ret.push_back(&_m_by_types);
989   ret.push_back(&_m);
990   ret.push_back((const DataArrayInt*)_fam);
991   ret.push_back((const DataArrayInt*)_num);
992   ret.push_back((const DataArrayInt*)_rev_num);
993   ret.push_back((const DataArrayAsciiChar*)_names);
994   return ret;
995 }
996
997 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::shallowCpyUsingCoords(DataArrayDouble *coords) const
998 {
999   MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1(*this));
1000   ret->_m_by_types.shallowCpyMeshes();
1001   ret->_m_by_types.setCoords(coords);
1002   return ret.retn();
1003 }
1004
1005 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCopy(DataArrayDouble *coords) const
1006 {
1007   MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1(*this));
1008   ret->_m_by_types=_m_by_types.deepCopy(coords);
1009   if((const DataArrayInt *)_fam)
1010     ret->_fam=_fam->deepCopy();
1011   if((const DataArrayInt *)_num)
1012     ret->_num=_num->deepCopy();
1013   if((const DataArrayInt *)_rev_num)
1014     ret->_rev_num=_rev_num->deepCopy();
1015   if((const DataArrayAsciiChar *)_names)
1016     ret->_names=_names->deepCopy();
1017   return ret.retn();
1018 }
1019
1020 void MEDFileUMeshSplitL1::checkConsistency() const
1021 {
1022   if (!_fam || _fam->getNumberOfTuples() != getSize())
1023     throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): internal family array has an invalid size!");
1024   int nbCells = getSize();
1025   if (_num)
1026     {
1027       _num->checkNbOfTuplesAndComp(nbCells,1,"MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal node numbering array!");
1028       int pos;
1029       int maxValue=_num->getMaxValue(pos);
1030       if (!_rev_num || _rev_num->getNumberOfTuples() != (maxValue+1))
1031         throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal revert node numbering array!");
1032     }
1033   if ((_num && !_rev_num) || (!_num && _rev_num))
1034     throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal numbering arrays (one is null)!");
1035   if (_num && !_num->hasUniqueValues())
1036     throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal node numbering array: duplicates found!");
1037   if (_names)
1038     _names->checkNbOfTuplesAndComp(nbCells,1,"MEDFileUMeshSplitL1::checkConsistency(): internal cell naming array has an invalid size!");
1039
1040   _m_by_types.checkConsistency();
1041 }
1042
1043 bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const
1044 {
1045   if(!_m_by_types.isEqual(other->_m_by_types,eps,what))
1046     return false;
1047   const DataArrayInt *d1=_fam;
1048   const DataArrayInt *d2=other->_fam;
1049   if((d1==0 && d2!=0) || (d1!=0 && d2==0))
1050     {
1051       what="Presence of family arr in one sublevel and not in other!";
1052       return false;
1053     }
1054   if(d1)
1055     if(!d1->isEqual(*d2))
1056       {
1057         what="family arr at a sublevel are not deeply equal !";
1058         return false;
1059       }
1060   d1=_num;
1061   d2=other->_num;
1062   if((d1==0 && d2!=0) || (d1!=0 && d2==0))
1063     {
1064       what="Presence of cell numbering arr in one sublevel and not in other!";
1065       return false;
1066     }
1067   if(d1)
1068     if(!d1->isEqual(*d2))
1069       {
1070         what="Numbering cell arr at a sublevel are not deeply equal !";
1071         return false;
1072       }
1073   const DataArrayAsciiChar *e1=_names;
1074   const DataArrayAsciiChar *e2=other->_names;
1075   if((e1==0 && e2!=0) || (e1!=0 && e2==0))
1076     {
1077       what="Presence of cell names arr in one sublevel and not in other!";
1078       return false;
1079     }
1080   if(e1)
1081     if(!e1->isEqual(*e2))
1082       {
1083         what="Name cell arr at a sublevel are not deeply equal !";
1084         return false;
1085       }
1086   return true;
1087 }
1088
1089 void MEDFileUMeshSplitL1::synchronizeTinyInfo(const MEDFileMesh& master) const
1090 {
1091   _m_by_types.synchronizeTinyInfo(master);
1092 }
1093
1094 void MEDFileUMeshSplitL1::clearNonDiscrAttributes() const
1095 {
1096   _m_by_types.clearNonDiscrAttributes();
1097 }
1098
1099 void MEDFileUMeshSplitL1::ClearNonDiscrAttributes(const MEDCouplingMesh *tmp)
1100 {
1101   if(!tmp)
1102     return ;
1103   (const_cast<MEDCouplingMesh *>(tmp))->setName("");
1104   (const_cast<MEDCouplingMesh *>(tmp))->setDescription("");
1105   (const_cast<MEDCouplingMesh *>(tmp))->setTime(0.,-1,-1);
1106   (const_cast<MEDCouplingMesh *>(tmp))->setTimeUnit("");
1107 }
1108
1109 void MEDFileUMeshSplitL1::setCoords(DataArrayDouble *coords)
1110 {
1111   _m_by_types.setCoords(coords);
1112 }
1113
1114 void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld)
1115 {
1116   if(newOrOld)
1117     {
1118       m->incrRef();
1119       _m=m;
1120       _m_by_types.assignUMesh(dynamic_cast<MEDCouplingUMesh *>(m->deepCopy()));
1121       MCAuto<DataArrayInt> da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
1122       if(!da->isIota(m->getNumberOfCells()))
1123         {
1124           _num=da->invertArrayO2N2N2O(m->getNumberOfCells());
1125           _m.updateTime();
1126           computeRevNum();
1127           _m_by_types.getUmesh()->renumberCells(da->getConstPointer(),false);
1128         }
1129     }
1130   else
1131     {
1132       if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
1133         throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh(): the mesh does not follow the MED file numbering convention! Invoke sortCellsInMEDFileFrmt() first!");
1134       m->incrRef();
1135       _m_by_types.assignUMesh(m);
1136     }
1137   assignCommonPart();
1138 }
1139
1140 void MEDFileUMeshSplitL1::forceComputationOfParts() const
1141 {
1142   _m_by_types.forceComputationOfPartsFromUMesh();
1143 }
1144
1145 void MEDFileUMeshSplitL1::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
1146 {
1147   _m_by_types.assignParts(mParts);
1148   assignCommonPart();
1149 }
1150
1151 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1():_m(this)
1152 {
1153 }
1154
1155 void MEDFileUMeshSplitL1::assignCommonPart()
1156 {
1157   _fam=DataArrayInt::New();
1158   _fam->alloc(_m_by_types.getSize(),1);
1159   _fam->fillWithValue(0);
1160 }
1161
1162 bool MEDFileUMeshSplitL1::empty() const
1163 {
1164   return _m_by_types.empty();
1165 }
1166
1167 bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector<int>& ids) const
1168 {
1169   const DataArrayInt *fam=_fam;
1170   if(!fam)
1171     return false;
1172   return fam->presenceOfValue(ids);
1173 }
1174
1175 int MEDFileUMeshSplitL1::getMeshDimension() const
1176 {
1177   return _m_by_types.getMeshDimension();
1178 }
1179
1180 void MEDFileUMeshSplitL1::simpleRepr(std::ostream& oss) const
1181 {
1182   std::vector<int> code=_m_by_types.getDistributionOfTypes();
1183   int nbOfTypes=code.size()/3;
1184   for(int i=0;i<nbOfTypes;i++)
1185     {
1186       INTERP_KERNEL::NormalizedCellType typ=(INTERP_KERNEL::NormalizedCellType) code[3*i];
1187       oss << "    - Number of cells with type " << INTERP_KERNEL::CellModel::GetCellModel(typ).getRepr() << " : " << code[3*i+1] << std::endl;
1188     }
1189 }
1190
1191 int MEDFileUMeshSplitL1::getSize() const
1192 {
1193   return _m_by_types.getSize();
1194 }
1195
1196 MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const
1197 {
1198   MCAuto<DataArrayInt> eltsToKeep=_fam->findIdsEqualList(idsBg,idsEnd);
1199   MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true);
1200   if(renum)
1201     return renumIfNeeded(m,eltsToKeep->getConstPointer());
1202   return m;
1203 }
1204
1205 DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const
1206 {
1207   MCAuto<DataArrayInt> da=_fam->findIdsEqualList(idsBg,idsEnd);
1208   if(renum)
1209     return renumIfNeededArr(da);
1210   return da.retn();
1211 }
1212
1213 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshSplitL1::getGeoTypes() const
1214 {
1215   return _m_by_types.getGeoTypes();
1216 }
1217
1218 int MEDFileUMeshSplitL1::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
1219 {
1220   return _m_by_types.getNumberOfCellsWithType(ct);
1221 }
1222
1223 MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
1224 {
1225   MCAuto<MEDCouplingUMesh> tmp;
1226   if(renum && ((const DataArrayInt *)_num))
1227     tmp=_m;
1228   else
1229     { tmp=_m_by_types.getUmesh(); if(tmp) tmp->incrRef(); }
1230   return tmp.retn();
1231 }
1232
1233 int MEDFileUMeshSplitL1::getNumberOfCells() const
1234 {
1235   return _m_by_types.getNumberOfCells();
1236 }
1237
1238 DataArrayInt *MEDFileUMeshSplitL1::extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
1239 {
1240   const DataArrayInt *fam(_fam);
1241   if(!fam)
1242     return 0;
1243   int start(0),stop(0);
1244   _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
1245   return fam->selectByTupleIdSafeSlice(start,stop,1);
1246 }
1247
1248 DataArrayInt *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
1249 {
1250   const DataArrayInt *num(_num);
1251   if(!num)
1252     return 0;
1253   int start(0),stop(0);
1254   _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
1255   return num->selectByTupleIdSafeSlice(start,stop,1);
1256 }
1257
1258 DataArrayInt *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField()
1259 {
1260   if((DataArrayInt *)_fam)
1261     return _fam;
1262   int nbOfTuples=_m_by_types.getSize();
1263   _fam=DataArrayInt::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero();
1264   return _fam;
1265 }
1266
1267 const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const
1268 {
1269   return _fam;
1270 }
1271
1272 const DataArrayInt *MEDFileUMeshSplitL1::getNumberField() const
1273 {
1274   return _num;
1275 }
1276
1277 const DataArrayInt *MEDFileUMeshSplitL1::getRevNumberField() const
1278 {
1279   return _rev_num;
1280 }
1281
1282 const DataArrayAsciiChar *MEDFileUMeshSplitL1::getNameField() const
1283 {
1284   return _names;
1285 }
1286
1287 const PartDefinition *MEDFileUMeshSplitL1::getPartDef(INTERP_KERNEL::NormalizedCellType gt) const
1288 {
1289   return _m_by_types.getPartDefOfWithoutComputation(gt);
1290 }
1291
1292 void MEDFileUMeshSplitL1::eraseFamilyField()
1293 {
1294   _fam->fillWithZero();
1295 }
1296
1297 /*!
1298  * This method ignores _m and _m_by_types.
1299  */
1300 void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
1301                                                std::map<std::string, std::vector<std::string> >& groups)
1302 {
1303   std::vector< DataArrayInt * > corr;
1304   _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr);
1305   std::vector< MCAuto<DataArrayInt> > corrMSafe(corr.begin(),corr.end());
1306   std::vector< std::vector<int> > fidsOfGroups;
1307   std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
1308   _fam=DataArrayInt::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups);
1309   int nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells();
1310   std::map<int,std::string> newfams;
1311   std::map<int,int> famIdTrad;
1312   TraduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams);
1313   int *w=_fam->getPointer();
1314   for(int i=0;i<nbOfCells;i++,w++)
1315     *w=famIdTrad[*w];
1316 }
1317
1318 void MEDFileUMeshSplitL1::write(med_idt fid, const std::string& mName, int mdim) const
1319 {
1320   std::vector<MEDCoupling1GTUMesh *> ms(_m_by_types.getParts());
1321   int start=0;
1322   for(std::vector<MEDCoupling1GTUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
1323     {
1324       int nbCells=(*it)->getNumberOfCells();
1325       int end=start+nbCells;
1326       MCAuto<DataArrayInt> fam,num;
1327       MCAuto<DataArrayAsciiChar> names;
1328       if((const DataArrayInt *)_fam)
1329         fam=_fam->subArray(start,end);
1330       if((const DataArrayInt *)_num)
1331         num=_num->subArray(start,end);
1332       if((const DataArrayAsciiChar *)_names)
1333         names=static_cast<DataArrayAsciiChar *>(_names->subArray(start,end));
1334       MEDFileUMeshPerType::Write(fid,mName,mdim,(*it),fam,num,names);
1335       start=end;
1336     }
1337 }
1338
1339 void MEDFileUMeshSplitL1::renumberNodesInConn(const int *newNodeNumbersO2N)
1340 {
1341   _m_by_types.renumberNodesInConnWithoutComputation(newNodeNumbersO2N);
1342 }
1343
1344 void MEDFileUMeshSplitL1::serialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI) const
1345 {
1346   bigArraysI.push_back(_fam);
1347   bigArraysI.push_back(_num);
1348   _m_by_types.serialize(tinyInt,bigArraysI);
1349 }
1350
1351 void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI)
1352 {
1353   _fam=bigArraysI.back(); bigArraysI.pop_back();
1354   _num=bigArraysI.back(); bigArraysI.pop_back();
1355   _m_by_types.unserialize(name,coo,tinyInt,bigArraysI);
1356 }
1357
1358 void MEDFileUMeshSplitL1::changeFamilyIdArr(int oldId, int newId)
1359 {
1360   DataArrayInt *arr=_fam;
1361   if(arr)
1362     arr->changeValue(oldId,newId);
1363 }
1364
1365 void MEDFileUMeshSplitL1::setFamilyArr(DataArrayInt *famArr)
1366 {
1367   if(!famArr)
1368     {
1369       _fam=0;
1370       return ;
1371     }
1372   int sz(_m_by_types.getSize());
1373   famArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setFamilyArr : Problem in size of Family arr ! ");
1374   famArr->incrRef();
1375   _fam=famArr;
1376 }
1377
1378 DataArrayInt *MEDFileUMeshSplitL1::getFamilyField()
1379 {
1380   return _fam;
1381 }
1382
1383 void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr)
1384 {
1385   if(!renumArr)
1386     {
1387       _num=0;
1388       _rev_num=0;
1389       return ;
1390     }
1391   int sz(_m_by_types.getSize());
1392   renumArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setRenumArr : Problem in size of numbering arr ! ");
1393   renumArr->incrRef();
1394   _num=renumArr;
1395   computeRevNum();
1396 }
1397
1398 void MEDFileUMeshSplitL1::setNameArr(DataArrayAsciiChar *nameArr)
1399 {
1400   if(!nameArr)
1401     {
1402       _names=0;
1403       return ;
1404     }
1405   int sz(_m_by_types.getSize());
1406   nameArr->checkNbOfTuplesAndComp(sz,MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! ");
1407   nameArr->incrRef();
1408   _names=nameArr;
1409 }
1410
1411 MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds)
1412 {
1413   if(renum==0)
1414     return m;
1415   if(cellIds==0)
1416     m->renumberCells(renum->getConstPointer(),true);
1417   else
1418     {
1419       MCAuto<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
1420       m->renumberCells(locnum->getConstPointer(),true);
1421     }
1422   return m;
1423 }
1424
1425 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI)
1426 {
1427   MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1);
1428   ret->unserialize(name,coo,tinyInt,bigArraysI);
1429   return ret.retn();
1430 }
1431
1432 MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const
1433 {
1434   return Renumber2(_num,m,cellIds);
1435 }
1436
1437 DataArrayInt *MEDFileUMeshSplitL1::Renumber(const DataArrayInt *renum, const DataArrayInt *da)
1438 {
1439   if((const DataArrayInt *)renum==0)
1440     {
1441       da->incrRef();
1442       return const_cast<DataArrayInt *>(da);
1443     }
1444   return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
1445 }
1446
1447 DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const
1448 {
1449   return Renumber(_num,da);
1450 }
1451
1452 std::vector<int> MEDFileUMeshSplitL1::GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families)
1453 {
1454   int id=-1;
1455   for(std::map<std::string,int>::const_iterator it=families.begin();it!=families.end();it++)
1456     id=std::max(id,(*it).second);
1457   if(id==-1)
1458     id=0;
1459   std::vector<int> ret(nb);
1460   for(int i=1;i<=nb;i++)
1461     ret[i]=id+i;
1462   return ret;
1463 }
1464
1465 void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
1466                                               std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams)
1467 {
1468   std::set<int> allfids;
1469   //tony
1470 }
1471
1472 void MEDFileUMeshSplitL1::computeRevNum() const
1473 {
1474   int pos;
1475   int maxValue=_num->getMaxValue(pos);
1476   _rev_num=_num->invertArrayN2O2O2N(maxValue+1);
1477 }
1478
1479 //=
1480
1481 MEDFileUMeshAggregateCompute::MEDFileUMeshAggregateCompute():_mp_time(0),_m_time(0)
1482 {
1483 }
1484
1485 void MEDFileUMeshAggregateCompute::setName(const std::string& name)
1486 {
1487   if(_m_time>=_mp_time)
1488     {
1489       MEDCouplingUMesh *um(_m);
1490       if(um)
1491         um->setName(name);
1492     }
1493   if(_mp_time>=_m_time)
1494     {
1495       for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1496         {
1497           MEDCoupling1GTUMesh *tmp(*it);
1498           if(tmp)
1499             tmp->setName(name);
1500         }
1501     }
1502 }
1503
1504 void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
1505 {
1506   std::size_t sz(mParts.size());
1507   std::vector< MCAuto<MEDCoupling1GTUMesh> > ret(sz);
1508   for(std::size_t i=0;i<sz;i++)
1509     {
1510       const MEDCoupling1GTUMesh *elt(mParts[i]);
1511       if(!elt)
1512         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignParts : presence of null pointer !");
1513       ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt); elt->incrRef();
1514     }
1515   _m_parts=ret;
1516   _part_def.clear(); _part_def.resize(sz);
1517   _mp_time=std::max(_mp_time,_m_time)+1;
1518   _m=0;
1519 }
1520
1521 void MEDFileUMeshAggregateCompute::assignDefParts(const std::vector<const PartDefinition *>& partDefs)
1522 {
1523   if(_mp_time<_m_time)
1524     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : the parts require a computation !");
1525   std::size_t sz(partDefs.size());
1526   if(_part_def.size()!=partDefs.size() || _part_def.size()!=_m_parts.size())
1527     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : sizes of vectors of part definition mismatch !");
1528   for(std::size_t i=0;i<sz;i++)
1529     {
1530       const PartDefinition *elt(partDefs[i]);
1531       if(elt)
1532         elt->incrRef();
1533       _part_def[i]=const_cast<PartDefinition*>(elt);
1534     }
1535 }
1536
1537 void MEDFileUMeshAggregateCompute::assignUMesh(MEDCouplingUMesh *m)
1538 {
1539   _m=m;
1540   _m_parts.clear();
1541   _m_time=std::max(_mp_time,_m_time)+1;
1542 }
1543
1544 MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const
1545 {
1546   if(_mp_time<=_m_time)
1547     return _m;
1548   std::vector< const MEDCoupling1GTUMesh *> mp(_m_parts.size());
1549   std::copy(_m_parts.begin(),_m_parts.end(),mp.begin());
1550   _m=MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(mp);
1551   _m_parts.clear();//to avoid memory peak !
1552   _m_time=_mp_time+1;//+1 is important ! That is to say that only _m is OK not _m_parts because cleared !
1553   return _m;
1554 }
1555
1556 int MEDFileUMeshAggregateCompute::getNumberOfCells() const
1557 {
1558   if(_mp_time<=_m_time)
1559     return _m->getNumberOfCells();
1560   int ret(0);
1561   for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1562     ret+=(*it)->getNumberOfCells();
1563   return ret;
1564 }
1565
1566 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshAggregateCompute::getGeoTypes() const
1567 {
1568   if(_mp_time>=_m_time)
1569     {
1570       std::size_t sz(_m_parts.size());
1571       std::vector<INTERP_KERNEL::NormalizedCellType> ret(sz);
1572       for(std::size_t i=0;i<sz;i++)
1573         ret[i]=_m_parts[i]->getCellModelEnum();
1574       return ret;
1575     }
1576   else
1577     return _m->getAllGeoTypesSorted();
1578 }
1579
1580 int MEDFileUMeshAggregateCompute::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
1581 {
1582   if(_mp_time>=_m_time)
1583     {
1584       for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1585         {
1586           const MEDCoupling1GTUMesh *elt(*it);
1587           if(elt && elt->getCellModelEnum()==ct)
1588             return elt->getNumberOfCells();
1589         }
1590       return 0;
1591     }
1592   else
1593     return _m->getNumberOfCellsWithType(ct);
1594 }
1595
1596 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::retrievePartsWithoutComputation() const
1597 {
1598   if(_mp_time<_m_time)
1599     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartsWithoutComputation : the parts require a computation !");
1600   //
1601   std::vector<MEDCoupling1GTUMesh *> ret(_m_parts.size());
1602   std::size_t i(0);
1603   for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
1604     {
1605       const MEDCoupling1GTUMesh *elt(*it);
1606       ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt);
1607     }
1608   return ret;
1609 }
1610
1611 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::getParts() const
1612 {
1613   if(_mp_time<_m_time)
1614     forceComputationOfPartsFromUMesh();
1615   return retrievePartsWithoutComputation();
1616 }
1617
1618 MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1619 {
1620   std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1621   std::size_t sz(v.size());
1622   for(std::size_t i=0;i<sz;i++)
1623     {
1624       if(v[i])
1625         if(v[i]->getCellModelEnum()==gt)
1626           return v[i];
1627     }
1628   throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartWithoutComputation : the geometric type is not existing !");
1629 }
1630
1631 void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const
1632 {
1633   start=0; stop=0;
1634   std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1635   std::size_t sz(v.size());
1636   for(std::size_t i=0;i<sz;i++)
1637     {
1638       if(v[i])
1639         {
1640           if(v[i]->getCellModelEnum()==gt)
1641             {
1642               stop=start+v[i]->getNumberOfCells();
1643               return;
1644             }
1645           else
1646             start+=v[i]->getNumberOfCells();
1647         }
1648     }
1649   throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation : the geometric type is not existing !");
1650 }
1651
1652 void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N)
1653 {
1654   if(_mp_time>_m_time)
1655     {
1656       for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1657         {
1658           MEDCoupling1GTUMesh *m(*it);
1659           if(m)
1660             m->renumberNodesInConn(newNodeNumbersO2N);
1661         }
1662     }
1663   else
1664     {
1665       MEDCouplingUMesh *m(getUmesh());
1666       if(!m)
1667         return;
1668       m->renumberNodesInConn(newNodeNumbersO2N);
1669     }
1670 }
1671
1672 void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const
1673 {
1674   const MEDCouplingUMesh *m(_m);
1675   if(!m)
1676     {
1677       if(_m_parts.empty())
1678         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !");
1679       else
1680         return ;// no needs to compte parts they are already here !
1681     }
1682   std::vector<MEDCouplingUMesh *> ms(m->splitByType());
1683   std::vector< MCAuto<MEDCouplingUMesh> > msMSafe(ms.begin(),ms.end());
1684   std::size_t sz(msMSafe.size());
1685   _m_parts.resize(sz);
1686   for(std::size_t i=0;i<sz;i++)
1687     _m_parts[i]=MEDCoupling1GTUMesh::New(ms[i]);
1688   _part_def.clear();
1689   _part_def.resize(_m_parts.size());
1690   _mp_time=std::max(_mp_time,_m_time);
1691 }
1692
1693 const PartDefinition *MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1694 {
1695   if(_mp_time<_m_time)
1696     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : the parts require a computation !");
1697   if(_m_parts.size()!=_part_def.size())
1698     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : size of arrays are expected to be the same !");
1699   std::size_t sz(_m_parts.size());
1700   for(std::size_t i=0;i<sz;i++)
1701     {
1702       const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1703       if(mesh)
1704         if(mesh->getCellModelEnum()==gt)
1705           return _part_def[i];
1706     }
1707   throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : The input geo type is not existing in this !");
1708 }
1709
1710 void MEDFileUMeshAggregateCompute::serialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI) const
1711 {
1712   if(_mp_time<_m_time)
1713     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : the parts require a computation !");
1714   std::size_t sz(_m_parts.size());
1715   tinyInt.push_back((int)sz);
1716   for(std::size_t i=0;i<sz;i++)
1717     {
1718       const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1719       if(!mesh)
1720         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : one part is empty !");
1721       tinyInt.push_back(mesh->getCellModelEnum());
1722       const MEDCoupling1SGTUMesh *mesh1(dynamic_cast<const MEDCoupling1SGTUMesh *>(mesh));
1723       const MEDCoupling1DGTUMesh *mesh2(dynamic_cast<const MEDCoupling1DGTUMesh *>(mesh));
1724       if(mesh1)
1725         {
1726           DataArrayInt *elt(mesh1->getNodalConnectivity());
1727           if(elt)
1728             elt->incrRef();
1729           MCAuto<DataArrayInt> elt1(elt);
1730           bigArraysI.push_back(elt1);
1731         }
1732       else if(mesh2)
1733         {
1734           DataArrayInt *elt1(mesh2->getNodalConnectivity()),*elt2(mesh2->getNodalConnectivityIndex());
1735           if(elt1)
1736             elt1->incrRef();
1737           if(elt2)
1738             elt2->incrRef();
1739           MCAuto<DataArrayInt> elt11(elt1),elt22(elt2);
1740           bigArraysI.push_back(elt11); bigArraysI.push_back(elt22);
1741         }
1742       else
1743         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : unrecognized single geo type mesh !");
1744       const PartDefinition *pd(_part_def[i]);
1745       if(!pd)
1746         tinyInt.push_back(-1);
1747       else
1748         {
1749           std::vector<int> tinyTmp;
1750           pd->serialize(tinyTmp,bigArraysI);
1751           tinyInt.push_back((int)tinyTmp.size());
1752           tinyInt.insert(tinyInt.end(),tinyTmp.begin(),tinyTmp.end());
1753         }
1754     }
1755 }
1756
1757 void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI)
1758 {
1759   int nbParts(tinyInt.back()); tinyInt.pop_back();
1760   _part_def.clear(); _part_def.resize(nbParts);
1761   _m_parts.clear(); _m_parts.resize(nbParts);
1762   for(int i=0;i<nbParts;i++)
1763     {
1764       INTERP_KERNEL::NormalizedCellType tp((INTERP_KERNEL::NormalizedCellType) tinyInt.back()); tinyInt.pop_back();
1765       MCAuto<MEDCoupling1GTUMesh> mesh(MEDCoupling1GTUMesh::New(name,tp));
1766       mesh->setCoords(coo);
1767       MEDCoupling1SGTUMesh *mesh1(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1768       MEDCoupling1DGTUMesh *mesh2(dynamic_cast<MEDCoupling1DGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1769       if(mesh1)
1770         {
1771           mesh1->setNodalConnectivity(bigArraysI.back()); bigArraysI.pop_back();
1772         }
1773       else if(mesh2)
1774         {
1775           MCAuto<DataArrayInt> elt0,elt1;
1776           elt0=bigArraysI.back(); bigArraysI.pop_back();
1777           elt1=bigArraysI.back(); bigArraysI.pop_back();
1778           mesh2->setNodalConnectivity(elt0,elt1);
1779         }
1780       else
1781         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::unserialize : unrecognized single geo type mesh !");
1782       _m_parts[i]=mesh;
1783       int pdid(tinyInt.back()); tinyInt.pop_back();
1784       if(pdid!=-1)
1785         _part_def[i]=PartDefinition::Unserialize(tinyInt,bigArraysI);
1786       _mp_time=std::max(_mp_time,_m_time)+1;
1787     }
1788 }
1789
1790 /*!
1791  * This method returns true if \a this is stored split by type false if stored in a merged unstructured mesh.
1792  */
1793 bool MEDFileUMeshAggregateCompute::isStoredSplitByType() const
1794 {
1795   return _mp_time>=_m_time;
1796 }
1797
1798 std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const
1799 {
1800   if(_mp_time>_m_time)
1801     return getTimeOfParts();
1802   if(_m_time>_mp_time)
1803     return getTimeOfUMesh();
1804   return std::max(getTimeOfParts(),getTimeOfUMesh());
1805 }
1806
1807 std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const
1808 {
1809   std::size_t ret(0);
1810   for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1811     {
1812       const MEDCoupling1GTUMesh *elt(*it);
1813       if(!elt)
1814         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : null obj in parts !");
1815       ret=std::max(ret,elt->getTimeOfThis());
1816     }
1817   if(ret==0)
1818     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : parts is empty !");
1819   return ret;
1820 }
1821
1822 std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const
1823 {
1824   const MEDCouplingUMesh *m(_m);
1825   if(!m)
1826     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfUMesh : unmesh is null !");
1827   return m->getTimeOfThis();
1828 }
1829
1830 std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySizeWithoutChildren() const
1831 {
1832   std::size_t ret(_m_parts.size()*sizeof(MCAuto<MEDCoupling1GTUMesh>));
1833   return ret;
1834 }
1835
1836 std::vector<const BigMemoryObject *> MEDFileUMeshAggregateCompute::getDirectChildrenWithNull() const
1837 {
1838   std::vector<const BigMemoryObject *> ret;
1839   for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1840     ret.push_back((const MEDCoupling1GTUMesh *)*it);
1841   ret.push_back((const MEDCouplingUMesh *)_m);
1842   return ret;
1843 }
1844
1845 MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCopy(DataArrayDouble *coords) const
1846 {
1847   MEDFileUMeshAggregateCompute ret;
1848   ret._m_parts.resize(_m_parts.size());
1849   for(std::size_t i=0;i<_m_parts.size();i++)
1850     {
1851       const MEDCoupling1GTUMesh *elt(_m_parts[i]);
1852       if(elt)
1853         {
1854           ret._m_parts[i]=static_cast<MEDCoupling::MEDCoupling1GTUMesh*>(elt->deepCopy());
1855           ret._m_parts[i]->setCoords(coords);
1856         }
1857     }
1858   ret._mp_time=_mp_time; ret._m_time=_m_time;
1859   if((const MEDCouplingUMesh *)_m)
1860     {
1861       ret._m=static_cast<MEDCoupling::MEDCouplingUMesh*>(_m->deepCopy());
1862       ret._m->setCoords(coords);
1863     }
1864   std::size_t sz(_part_def.size());
1865   ret._part_def.clear(); ret._part_def.resize(sz);
1866   for(std::size_t i=0;i<sz;i++)
1867     {
1868       const PartDefinition *elt(_part_def[i]);
1869       if(elt)
1870         ret._part_def[i]=elt->deepCopy();
1871     }
1872   return ret;
1873 }
1874
1875 void MEDFileUMeshAggregateCompute::shallowCpyMeshes()
1876 {
1877   for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1878     {
1879       const MEDCoupling1GTUMesh *elt(*it);
1880       if(elt)
1881         {
1882           MCAuto<MEDCouplingMesh> elt2(elt->clone(false));
1883           *it=DynamicCastSafe<MEDCouplingMesh,MEDCoupling1GTUMesh>(elt2);
1884         }
1885     }
1886   const MEDCouplingUMesh *m(_m);
1887   if(m)
1888     _m=m->clone(false);
1889 }
1890
1891 bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const
1892 {
1893   const MEDCouplingUMesh *m1(getUmesh());
1894   const MEDCouplingUMesh *m2(other.getUmesh());
1895   if((m1==0 && m2!=0) || (m1!=0 && m2==0))
1896     {
1897       what="Presence of mesh in one sublevel and not in other!";
1898       return false;
1899     }
1900   if(m1)
1901     {
1902       std::string what2;
1903       if(!m1->isEqualIfNotWhy(m2,eps,what2))
1904         {
1905           what=std::string("meshes at a sublevel are not deeply equal (")+what2+std::string(")!");
1906           return false;
1907         }
1908     }
1909   std::size_t sz(_part_def.size());
1910   if(sz!=other._part_def.size())
1911     {
1912       what=std::string("number of subdivision per geo type for part definition is not the same !");
1913       return false;
1914     }
1915   for(std::size_t i=0;i<sz;i++)
1916     {
1917       const PartDefinition *pd0(_part_def[i]),*pd1(other._part_def[i]);
1918       if(!pd0 && !pd1)
1919         continue;
1920       if((!pd0 && pd1) || (pd0 && !pd1))
1921         {
1922           what=std::string("a cell part def is defined only for one among this or other !");
1923           return false;
1924         }
1925       bool ret(pd0->isEqual(pd1,what));
1926       if(!ret)
1927         return false;
1928     }
1929   return true;
1930 }
1931
1932 void MEDFileUMeshAggregateCompute::checkConsistency() const
1933 {
1934   if(_mp_time >= _m_time)
1935     for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();
1936         it!=_m_parts.end(); it++)
1937       (*it)->checkConsistency();
1938   else
1939     _m->checkConsistency();
1940 }
1941
1942 void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const
1943 {
1944   for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1945     MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it);
1946   MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m);
1947 }
1948
1949 void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const
1950 {
1951   for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1952     {
1953       const MEDCoupling1GTUMesh *tmp(*it);
1954       if(tmp)
1955         {
1956           (const_cast<MEDCoupling1GTUMesh *>(tmp))->setName(master.getName().c_str());
1957           (const_cast<MEDCoupling1GTUMesh *>(tmp))->setDescription(master.getDescription().c_str());
1958           (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1959           (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTimeUnit(master.getTimeUnit());
1960         }
1961     }
1962   const MEDCouplingUMesh *m(_m);
1963   if(m)
1964     {
1965       (const_cast<MEDCouplingUMesh *>(m))->setName(master.getName().c_str());
1966       (const_cast<MEDCouplingUMesh *>(m))->setDescription(master.getDescription().c_str());
1967       (const_cast<MEDCouplingUMesh *>(m))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1968       (const_cast<MEDCouplingUMesh *>(m))->setTimeUnit(master.getTimeUnit());
1969     }
1970 }
1971
1972 bool MEDFileUMeshAggregateCompute::empty() const
1973 {
1974   if(_mp_time<_m_time)
1975     return ((const MEDCouplingUMesh *)_m)==0;
1976   //else _mp_time>=_m_time)
1977   return _m_parts.empty();
1978 }
1979
1980 int MEDFileUMeshAggregateCompute::getMeshDimension() const
1981 {
1982   if(_mp_time<_m_time)
1983     {
1984       const MEDCouplingUMesh *m(_m);
1985       if(!m)
1986         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : no umesh in this !");
1987       return m->getMeshDimension();
1988     }
1989   else
1990     {
1991       if(_m_parts.empty())
1992         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh is empty !");
1993       const MEDCoupling1GTUMesh *m(_m_parts[0]);
1994       if(!m)
1995         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh contains null instance !");
1996       return m->getMeshDimension();
1997     }
1998 }
1999
2000 std::vector<int> MEDFileUMeshAggregateCompute::getDistributionOfTypes() const
2001 {
2002   if(_mp_time<_m_time)
2003     {
2004       const MEDCouplingUMesh *m(_m);
2005       if(!m)
2006         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : no umesh in this !");
2007       return m->getDistributionOfTypes();
2008     }
2009   else
2010     {
2011       std::vector<int> ret;
2012       for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2013         {
2014           const MEDCoupling1GTUMesh *tmp(*it);
2015           if(!tmp)
2016             throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : part mesh contains null instance !");
2017           std::vector<int> ret0(tmp->getDistributionOfTypes());
2018           ret.insert(ret.end(),ret0.begin(),ret0.end());
2019         }
2020       return ret;
2021     }
2022 }
2023
2024 int MEDFileUMeshAggregateCompute::getSize() const
2025 {
2026   if(_mp_time<_m_time)
2027     {
2028       const MEDCouplingUMesh *m(_m);
2029       if(!m)
2030         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : no umesh in this !");
2031       return m->getNumberOfCells();
2032     }
2033   else
2034     {
2035       int ret=0;
2036       for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2037         {
2038           const MEDCoupling1GTUMesh *m(*it);
2039           if(!m)
2040             throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : part mesh contains null instance !");
2041           ret+=m->getNumberOfCells();
2042         }
2043       return ret;
2044     }
2045 }
2046
2047 void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords)
2048 {
2049   for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2050     {
2051       MEDCoupling1GTUMesh *tmp(*it);
2052       if(tmp)
2053         (*it)->setCoords(coords);
2054     }
2055   MEDCouplingUMesh *m(_m);
2056   if(m)
2057     m->setCoords(coords);
2058 }
2059
2060 MEDFileEltStruct4Mesh *MEDFileEltStruct4Mesh::New(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs)
2061 {
2062   return new MEDFileEltStruct4Mesh(fid,mName,dt,it,iterOnStEltOfMesh,mrs);
2063 }
2064
2065 std::size_t MEDFileEltStruct4Mesh::getHeapMemorySizeWithoutChildren() const
2066 {
2067   return _geo_type_name.capacity()+_vars.capacity()*sizeof(MCAuto<DataArray>);
2068 }
2069
2070 std::vector<const MEDCoupling::BigMemoryObject*> MEDFileEltStruct4Mesh::getDirectChildrenWithNull() const
2071 {
2072   std::vector<const MEDCoupling::BigMemoryObject*> ret;
2073   ret.push_back(_conn);
2074   ret.push_back(_common);
2075   for(std::vector< MCAuto<DataArray> >::const_iterator it=_vars.begin();it!=_vars.end();it++)
2076     ret.push_back(*it);
2077   return ret;
2078 }
2079
2080 MEDFileEltStruct4Mesh::MEDFileEltStruct4Mesh(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs)
2081 {
2082   med_geometry_type geoType;
2083   INTERP_KERNEL::AutoPtr<char> geoTypeName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2084   MEDFILESAFECALLERRD0(MEDmeshEntityInfo,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,iterOnStEltOfMesh+1,geoTypeName,&geoType));
2085   _geo_type=geoType;
2086   _geo_type_name=MEDLoaderBase::buildStringFromFortran(geoTypeName,MED_NAME_SIZE);
2087   int nCells(0);
2088   {
2089     med_bool chgt=MED_FALSE,trsf=MED_FALSE;
2090     nCells=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,geoType,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf);
2091   }
2092   MCAuto<MEDFileMeshSupports> mss(MEDFileMeshSupports::New(fid));
2093   MCAuto<MEDFileStructureElements> mse(MEDFileStructureElements::New(fid,mss));
2094   int nbEntities(mse->getNumberOfNodesPerSE(_geo_type_name));
2095   _conn=DataArrayInt::New(); _conn->alloc(nCells,nbEntities);
2096   MEDFILESAFECALLERRD0(MEDmeshElementConnectivityRd,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,_geo_type,MED_NODAL,MED_FULL_INTERLACE,_conn->getPointer()));
2097   _common=MEDFileUMeshPerTypeCommon::New();
2098   _common->loadCommonPart(fid,mName.c_str(),dt,it,nCells,geoType,MED_STRUCT_ELEMENT,mrs);
2099   std::vector<std::string> vns(mse->getVarAttsOf(_geo_type_name));
2100   std::size_t sz(vns.size());
2101   _vars.resize(sz);
2102   for(std::size_t i=0;i<sz;i++)
2103     {
2104       const MEDFileSEVarAtt *var(mse->getVarAttOf(_geo_type_name,vns[i]));
2105       MCAuto<DataArray> gen(var->getGenerator());
2106       MCAuto<DataArray> arr(gen->buildNewEmptyInstance());
2107       arr->alloc(nCells,var->getNbOfComponents());
2108       arr->setName(vns[i]);
2109       MEDFILESAFECALLERRD0(MEDmeshStructElementVarAttRd,(fid,mName.c_str(),dt,it,_geo_type,vns[i].c_str(),arr->getVoidStarPointer()));
2110       _vars[i]=arr;
2111     }
2112 }