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