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