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