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