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