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