Salome HOME
Reverted to SALOME current CMake build procedure.
[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(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 mesh does not follow the MED file numbering convention! Invoke sortCellsInMEDFileFrmt() first!");
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 int MEDFileUMeshSplitL1::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
915 {
916   return _m_by_types.getNumberOfCellsWithType(ct);
917 }
918
919 MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
920 {
921   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp;
922   if(renum && ((const DataArrayInt *)_num))
923     tmp=_m;
924   else
925     { tmp=_m_by_types.getUmesh(); if(tmp) tmp->incrRef(); }
926   return tmp.retn();
927 }
928
929 int MEDFileUMeshSplitL1::getNumberOfCells() const
930 {
931   return _m_by_types.getNumberOfCells();
932 }
933
934 DataArrayInt *MEDFileUMeshSplitL1::extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
935 {
936   const DataArrayInt *fam(_fam);
937   if(!fam)
938     return 0;
939   int start(0),stop(0);
940   _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
941   return fam->selectByTupleId2(start,stop,1);
942 }
943
944 DataArrayInt *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
945 {
946   const DataArrayInt *num(_num);
947   if(!num)
948     return 0;
949   int start(0),stop(0);
950   _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
951   return num->selectByTupleId2(start,stop,1);
952 }
953
954 DataArrayInt *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField()
955 {
956   if((DataArrayInt *)_fam)
957     return _fam;
958   int nbOfTuples=_m_by_types.getSize();
959   _fam=DataArrayInt::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero();
960   return _fam;
961 }
962
963 const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const
964 {
965   return _fam;
966 }
967
968 const DataArrayInt *MEDFileUMeshSplitL1::getNumberField() const
969 {
970   return _num;
971 }
972
973 const DataArrayInt *MEDFileUMeshSplitL1::getRevNumberField() const
974 {
975   return _rev_num;
976 }
977
978 const DataArrayAsciiChar *MEDFileUMeshSplitL1::getNameField() const
979 {
980   return _names;
981 }
982
983 const PartDefinition *MEDFileUMeshSplitL1::getPartDef(INTERP_KERNEL::NormalizedCellType gt) const
984 {
985   return _m_by_types.getPartDefOfWithoutComputation(gt);
986 }
987
988 void MEDFileUMeshSplitL1::eraseFamilyField()
989 {
990   _fam->fillWithZero();
991 }
992
993 /*!
994  * This method ignores _m and _m_by_types.
995  */
996 void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
997                                                std::map<std::string, std::vector<std::string> >& groups)
998 {
999   std::vector< DataArrayInt * > corr;
1000   _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr);
1001   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corrMSafe(corr.begin(),corr.end());
1002   std::vector< std::vector<int> > fidsOfGroups;
1003   std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
1004   _fam=DataArrayInt::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups);
1005   int nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells();
1006   std::map<int,std::string> newfams;
1007   std::map<int,int> famIdTrad;
1008   TraduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams);
1009   int *w=_fam->getPointer();
1010   for(int i=0;i<nbOfCells;i++,w++)
1011     *w=famIdTrad[*w];
1012 }
1013
1014 void MEDFileUMeshSplitL1::write(med_idt fid, const std::string& mName, int mdim) const
1015 {
1016   std::vector<MEDCoupling1GTUMesh *> ms(_m_by_types.getParts());
1017   int start=0;
1018   for(std::vector<MEDCoupling1GTUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
1019     {
1020       int nbCells=(*it)->getNumberOfCells();
1021       int end=start+nbCells;
1022       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam,num;
1023       MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> names;
1024       if((const DataArrayInt *)_fam)
1025         fam=_fam->substr(start,end);
1026       if((const DataArrayInt *)_num)
1027         num=_num->substr(start,end);
1028       if((const DataArrayAsciiChar *)_names)
1029         names=static_cast<DataArrayAsciiChar *>(_names->substr(start,end));
1030       MEDFileUMeshPerType::Write(fid,mName,mdim,(*it),fam,num,names);
1031       start=end;
1032     }
1033 }
1034
1035 void MEDFileUMeshSplitL1::renumberNodesInConn(const int *newNodeNumbersO2N)
1036 {
1037   _m_by_types.renumberNodesInConnWithoutComputation(newNodeNumbersO2N);
1038 }
1039
1040 void MEDFileUMeshSplitL1::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
1041 {
1042   bigArraysI.push_back(_fam);
1043   bigArraysI.push_back(_num);
1044   _m_by_types.serialize(tinyInt,bigArraysI);
1045 }
1046
1047 void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
1048 {
1049   _fam=bigArraysI.back(); bigArraysI.pop_back();
1050   _num=bigArraysI.back(); bigArraysI.pop_back();
1051   _m_by_types.unserialize(name,coo,tinyInt,bigArraysI);
1052 }
1053
1054 void MEDFileUMeshSplitL1::changeFamilyIdArr(int oldId, int newId)
1055 {
1056   DataArrayInt *arr=_fam;
1057   if(arr)
1058     arr->changeValue(oldId,newId);
1059 }
1060
1061 void MEDFileUMeshSplitL1::setFamilyArr(DataArrayInt *famArr)
1062 {
1063   if(!famArr)
1064     {
1065       _fam=0;
1066       return ;
1067     }
1068   int sz(_m_by_types.getSize());
1069   famArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setFamilyArr : Problem in size of Family arr ! ");
1070   famArr->incrRef();
1071   _fam=famArr;
1072 }
1073
1074 DataArrayInt *MEDFileUMeshSplitL1::getFamilyField()
1075 {
1076   return _fam;
1077 }
1078
1079 void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr)
1080 {
1081   if(!renumArr)
1082     {
1083       _num=0;
1084       _rev_num=0;
1085       return ;
1086     }
1087   int sz(_m_by_types.getSize());
1088   renumArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setRenumArr : Problem in size of numbering arr ! ");
1089   renumArr->incrRef();
1090   _num=renumArr;
1091   computeRevNum();
1092 }
1093
1094 void MEDFileUMeshSplitL1::setNameArr(DataArrayAsciiChar *nameArr)
1095 {
1096   if(!nameArr)
1097     {
1098       _names=0;
1099       return ;
1100     }
1101   int sz(_m_by_types.getSize());
1102   nameArr->checkNbOfTuplesAndComp(sz,MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! ");
1103   nameArr->incrRef();
1104   _names=nameArr;
1105 }
1106
1107 MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds)
1108 {
1109   if(renum==0)
1110     return m;
1111   if(cellIds==0)
1112     m->renumberCells(renum->getConstPointer(),true);
1113   else
1114     {
1115       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
1116       m->renumberCells(locnum->getConstPointer(),true);
1117     }
1118   return m;
1119 }
1120
1121 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
1122 {
1123   MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1);
1124   ret->unserialize(name,coo,tinyInt,bigArraysI);
1125   return ret.retn();
1126 }
1127
1128 MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const
1129 {
1130   return Renumber2(_num,m,cellIds);
1131 }
1132
1133 DataArrayInt *MEDFileUMeshSplitL1::Renumber(const DataArrayInt *renum, const DataArrayInt *da)
1134 {
1135   if((const DataArrayInt *)renum==0)
1136     {
1137       da->incrRef();
1138       return const_cast<DataArrayInt *>(da);
1139     }
1140   return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
1141 }
1142
1143 DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const
1144 {
1145   return Renumber(_num,da);
1146 }
1147
1148 std::vector<int> MEDFileUMeshSplitL1::GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families)
1149 {
1150   int id=-1;
1151   for(std::map<std::string,int>::const_iterator it=families.begin();it!=families.end();it++)
1152     id=std::max(id,(*it).second);
1153   if(id==-1)
1154     id=0;
1155   std::vector<int> ret(nb);
1156   for(int i=1;i<=nb;i++)
1157     ret[i]=id+i;
1158   return ret;
1159 }
1160
1161 void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
1162                                               std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams)
1163 {
1164   std::set<int> allfids;
1165   //tony
1166 }
1167
1168 void MEDFileUMeshSplitL1::computeRevNum() const
1169 {
1170   int pos;
1171   int maxValue=_num->getMaxValue(pos);
1172   _rev_num=_num->invertArrayN2O2O2N(maxValue+1);
1173 }
1174
1175 //=
1176
1177 MEDFileUMeshAggregateCompute::MEDFileUMeshAggregateCompute():_mp_time(0),_m_time(0)
1178 {
1179 }
1180
1181 void MEDFileUMeshAggregateCompute::setName(const std::string& name)
1182 {
1183   if(_m_time>=_mp_time)
1184     {
1185       MEDCouplingUMesh *um(_m);
1186       if(um)
1187         um->setName(name);
1188     }
1189   if(_mp_time>=_m_time)
1190     {
1191       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1192         {
1193           MEDCoupling1GTUMesh *tmp(*it);
1194           if(tmp)
1195             tmp->setName(name);
1196         }
1197     }
1198 }
1199
1200 void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
1201 {
1202   std::size_t sz(mParts.size());
1203   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > ret(sz);
1204   for(std::size_t i=0;i<sz;i++)
1205     {
1206       const MEDCoupling1GTUMesh *elt(mParts[i]);
1207       if(!elt)
1208         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignParts : presence of null pointer !");
1209       ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt); elt->incrRef();
1210     }
1211   _m_parts=ret;
1212   _part_def.clear(); _part_def.resize(sz);
1213   _mp_time=std::max(_mp_time,_m_time)+1;
1214   _m=0;
1215 }
1216
1217 void MEDFileUMeshAggregateCompute::assignDefParts(const std::vector<const PartDefinition *>& partDefs)
1218 {
1219   if(_mp_time<_m_time)
1220     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : the parts require a computation !");
1221   std::size_t sz(partDefs.size());
1222   if(_part_def.size()!=partDefs.size() || _part_def.size()!=_m_parts.size())
1223     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : sizes of vectors of part definition mismatch !");
1224   for(std::size_t i=0;i<sz;i++)
1225     {
1226       const PartDefinition *elt(partDefs[i]);
1227       if(elt)
1228         elt->incrRef();
1229       _part_def[i]=const_cast<PartDefinition*>(elt);
1230     }
1231 }
1232
1233 void MEDFileUMeshAggregateCompute::assignUMesh(MEDCouplingUMesh *m)
1234 {
1235   _m=m;
1236   _m_parts.clear();
1237   _m_time=std::max(_mp_time,_m_time)+1;
1238 }
1239
1240 MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const
1241 {
1242   if(_mp_time<=_m_time)
1243     return _m;
1244   std::vector< const MEDCoupling1GTUMesh *> mp(_m_parts.size());
1245   std::copy(_m_parts.begin(),_m_parts.end(),mp.begin());
1246   _m=MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(mp);
1247   _m_parts.clear();//to avoid memory peak !
1248   _m_time=_mp_time+1;//+1 is important ! That is to say that only _m is OK not _m_parts because cleared !
1249   return _m;
1250 }
1251
1252 int MEDFileUMeshAggregateCompute::getNumberOfCells() const
1253 {
1254   if(_mp_time<=_m_time)
1255     return _m->getNumberOfCells();
1256   int ret(0);
1257   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1258     ret+=(*it)->getNumberOfCells();
1259   return ret;
1260 }
1261
1262 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshAggregateCompute::getGeoTypes() const
1263 {
1264   if(_mp_time>=_m_time)
1265     {
1266       std::size_t sz(_m_parts.size());
1267       std::vector<INTERP_KERNEL::NormalizedCellType> ret(sz);
1268       for(std::size_t i=0;i<sz;i++)
1269         ret[i]=_m_parts[i]->getCellModelEnum();
1270       return ret;
1271     }
1272   else
1273     return _m->getAllGeoTypesSorted();
1274 }
1275
1276 int MEDFileUMeshAggregateCompute::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
1277 {
1278   if(_mp_time>=_m_time)
1279     {
1280       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1281         {
1282           const MEDCoupling1GTUMesh *elt(*it);
1283           if(elt && elt->getCellModelEnum()==ct)
1284             return elt->getNumberOfCells();
1285         }
1286       return 0;
1287     }
1288   else
1289     return _m->getNumberOfCellsWithType(ct);
1290 }
1291
1292 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::retrievePartsWithoutComputation() const
1293 {
1294   if(_mp_time<_m_time)
1295     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartsWithoutComputation : the parts require a computation !");
1296   //
1297   std::vector<MEDCoupling1GTUMesh *> ret(_m_parts.size());
1298   std::size_t i(0);
1299   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
1300     {
1301       const MEDCoupling1GTUMesh *elt(*it);
1302       ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt);
1303     }
1304   return ret;
1305 }
1306
1307 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::getParts() const
1308 {
1309   if(_mp_time<_m_time)
1310     forceComputationOfPartsFromUMesh();
1311   return retrievePartsWithoutComputation();
1312 }
1313
1314 MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1315 {
1316   std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1317   std::size_t sz(v.size());
1318   for(std::size_t i=0;i<sz;i++)
1319     {
1320       if(v[i])
1321         if(v[i]->getCellModelEnum()==gt)
1322           return v[i];
1323     }
1324   throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartWithoutComputation : the geometric type is not existing !");
1325 }
1326
1327 void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const
1328 {
1329   start=0; stop=0;
1330   std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1331   std::size_t sz(v.size());
1332   for(std::size_t i=0;i<sz;i++)
1333     {
1334       if(v[i])
1335         {
1336           if(v[i]->getCellModelEnum()==gt)
1337             {
1338               stop=start+v[i]->getNumberOfCells();
1339               return;
1340             }
1341           else
1342             start+=v[i]->getNumberOfCells();
1343         }
1344     }
1345   throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation : the geometric type is not existing !");
1346 }
1347
1348 void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N)
1349 {
1350   if(_mp_time>_m_time)
1351     {
1352       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1353         {
1354           MEDCoupling1GTUMesh *m(*it);
1355           if(m)
1356             m->renumberNodesInConn(newNodeNumbersO2N);
1357         }
1358     }
1359   else
1360     {
1361       MEDCouplingUMesh *m(getUmesh());
1362       if(!m)
1363         return;
1364       m->renumberNodesInConn(newNodeNumbersO2N);
1365     }
1366 }
1367
1368 void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const
1369 {
1370   const MEDCouplingUMesh *m(_m);
1371   if(!m)
1372     {
1373       if(_m_parts.empty())
1374         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !");
1375       else
1376         return ;// no needs to compte parts they are already here !
1377     }
1378   std::vector<MEDCouplingUMesh *> ms(m->splitByType());
1379   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > msMSafe(ms.begin(),ms.end());
1380   std::size_t sz(msMSafe.size());
1381   _m_parts.resize(sz);
1382   for(std::size_t i=0;i<sz;i++)
1383     _m_parts[i]=MEDCoupling1GTUMesh::New(ms[i]);
1384   _part_def.clear();
1385   _part_def.resize(_m_parts.size());
1386   _mp_time=std::max(_mp_time,_m_time);
1387 }
1388
1389 const PartDefinition *MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1390 {
1391   if(_mp_time<_m_time)
1392     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : the parts require a computation !");
1393   if(_m_parts.size()!=_part_def.size())
1394     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : size of arrays are expected to be the same !");
1395   std::size_t sz(_m_parts.size());
1396   for(std::size_t i=0;i<sz;i++)
1397     {
1398       const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1399       if(mesh)
1400         if(mesh->getCellModelEnum()==gt)
1401           return _part_def[i];
1402     }
1403   throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : The input geo type is not existing in this !");
1404 }
1405
1406 void MEDFileUMeshAggregateCompute::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
1407 {
1408   if(_mp_time<_m_time)
1409     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : the parts require a computation !");
1410   std::size_t sz(_m_parts.size());
1411   tinyInt.push_back((int)sz);
1412   for(std::size_t i=0;i<sz;i++)
1413     {
1414       const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1415       if(!mesh)
1416         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : one part is empty !");
1417       tinyInt.push_back(mesh->getCellModelEnum());
1418       const MEDCoupling1SGTUMesh *mesh1(dynamic_cast<const MEDCoupling1SGTUMesh *>(mesh));
1419       const MEDCoupling1DGTUMesh *mesh2(dynamic_cast<const MEDCoupling1DGTUMesh *>(mesh));
1420       if(mesh1)
1421         {
1422           DataArrayInt *elt(mesh1->getNodalConnectivity());
1423           if(elt)
1424             elt->incrRef();
1425           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt1(elt);
1426           bigArraysI.push_back(elt1);
1427         }
1428       else if(mesh2)
1429         {
1430           DataArrayInt *elt1(mesh2->getNodalConnectivity()),*elt2(mesh2->getNodalConnectivityIndex());
1431           if(elt1)
1432             elt1->incrRef();
1433           if(elt2)
1434             elt2->incrRef();
1435           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt11(elt1),elt22(elt2);
1436           bigArraysI.push_back(elt11); bigArraysI.push_back(elt22);
1437         }
1438       else
1439         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : unrecognized single geo type mesh !");
1440       const PartDefinition *pd(_part_def[i]);
1441       if(!pd)
1442         tinyInt.push_back(-1);
1443       else
1444         {
1445           std::vector<int> tinyTmp;
1446           pd->serialize(tinyTmp,bigArraysI);
1447           tinyInt.push_back((int)tinyTmp.size());
1448           tinyInt.insert(tinyInt.end(),tinyTmp.begin(),tinyTmp.end());
1449         }
1450     }
1451 }
1452
1453 void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
1454 {
1455   int nbParts(tinyInt.back()); tinyInt.pop_back();
1456   _part_def.clear(); _part_def.resize(nbParts);
1457   _m_parts.clear(); _m_parts.resize(nbParts);
1458   for(int i=0;i<nbParts;i++)
1459     {
1460       INTERP_KERNEL::NormalizedCellType tp((INTERP_KERNEL::NormalizedCellType) tinyInt.back()); tinyInt.pop_back();
1461       MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> mesh(MEDCoupling1GTUMesh::New(name,tp));
1462       mesh->setCoords(coo);
1463       MEDCoupling1SGTUMesh *mesh1(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1464       MEDCoupling1DGTUMesh *mesh2(dynamic_cast<MEDCoupling1DGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1465       if(mesh1)
1466         {
1467           mesh1->setNodalConnectivity(bigArraysI.back()); bigArraysI.pop_back();
1468         }
1469       else if(mesh2)
1470         {
1471           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt0,elt1;
1472           elt0=bigArraysI.back(); bigArraysI.pop_back();
1473           elt1=bigArraysI.back(); bigArraysI.pop_back();
1474           mesh2->setNodalConnectivity(elt0,elt1);
1475         }
1476       else
1477         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::unserialize : unrecognized single geo type mesh !");
1478       _m_parts[i]=mesh;
1479       int pdid(tinyInt.back()); tinyInt.pop_back();
1480       if(pdid!=-1)
1481         _part_def[i]=PartDefinition::Unserialize(tinyInt,bigArraysI);
1482       _mp_time=std::max(_mp_time,_m_time)+1;
1483     }
1484 }
1485
1486 /*!
1487  * This method returns true if \a this is stored split by type false if stored in a merged unstructured mesh.
1488  */
1489 bool MEDFileUMeshAggregateCompute::isStoredSplitByType() const
1490 {
1491   return _mp_time>=_m_time;
1492 }
1493
1494 std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const
1495 {
1496   if(_mp_time>_m_time)
1497     return getTimeOfParts();
1498   if(_m_time>_mp_time)
1499     return getTimeOfUMesh();
1500   return std::max(getTimeOfParts(),getTimeOfUMesh());
1501 }
1502
1503 std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const
1504 {
1505   std::size_t ret(0);
1506   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1507     {
1508       const MEDCoupling1GTUMesh *elt(*it);
1509       if(!elt)
1510         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : null obj in parts !");
1511       ret=std::max(ret,elt->getTimeOfThis());
1512     }
1513   if(ret==0)
1514     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : parts is empty !");
1515   return ret;
1516 }
1517
1518 std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const
1519 {
1520   const MEDCouplingUMesh *m(_m);
1521   if(!m)
1522     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfUMesh : unmesh is null !");
1523   return m->getTimeOfThis();
1524 }
1525
1526 std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySizeWithoutChildren() const
1527 {
1528   std::size_t ret(_m_parts.size()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>));
1529   return ret;
1530 }
1531
1532 std::vector<const BigMemoryObject *> MEDFileUMeshAggregateCompute::getDirectChildrenWithNull() const
1533 {
1534   std::vector<const BigMemoryObject *> ret;
1535   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1536     ret.push_back((const MEDCoupling1GTUMesh *)*it);
1537   ret.push_back((const MEDCouplingUMesh *)_m);
1538   return ret;
1539 }
1540
1541 MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDouble *coords) const
1542 {
1543   MEDFileUMeshAggregateCompute ret;
1544   ret._m_parts.resize(_m_parts.size());
1545   for(std::size_t i=0;i<_m_parts.size();i++)
1546     {
1547       const MEDCoupling1GTUMesh *elt(_m_parts[i]);
1548       if(elt)
1549         {
1550           ret._m_parts[i]=static_cast<ParaMEDMEM::MEDCoupling1GTUMesh*>(elt->deepCpy());
1551           ret._m_parts[i]->setCoords(coords);
1552         }
1553     }
1554   ret._mp_time=_mp_time; ret._m_time=_m_time;
1555   if((const MEDCouplingUMesh *)_m)
1556     {
1557       ret._m=static_cast<ParaMEDMEM::MEDCouplingUMesh*>(_m->deepCpy());
1558       ret._m->setCoords(coords);
1559     }
1560   std::size_t sz(_part_def.size());
1561   ret._part_def.clear(); ret._part_def.resize(sz);
1562   for(std::size_t i=0;i<sz;i++)
1563     {
1564       const PartDefinition *elt(_part_def[i]);
1565       if(elt)
1566         ret._part_def[i]=elt->deepCpy();
1567     }
1568   return ret;
1569 }
1570
1571 bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const
1572 {
1573   const MEDCouplingUMesh *m1(getUmesh());
1574   const MEDCouplingUMesh *m2(other.getUmesh());
1575   if((m1==0 && m2!=0) || (m1!=0 && m2==0))
1576     {
1577       what="Presence of mesh in one sublevel and not in other!";
1578       return false;
1579     }
1580   if(m1)
1581     {
1582       std::string what2;
1583       if(!m1->isEqualIfNotWhy(m2,eps,what2))
1584         {
1585           what=std::string("meshes at a sublevel are not deeply equal (")+what2+std::string(")!");
1586           return false;
1587         }
1588     }
1589   std::size_t sz(_part_def.size());
1590   if(sz!=other._part_def.size())
1591     {
1592       what=std::string("number of subdivision per geo type for part definition is not the same !");
1593       return false;
1594     }
1595   for(std::size_t i=0;i<sz;i++)
1596     {
1597       const PartDefinition *pd0(_part_def[i]),*pd1(other._part_def[i]);
1598       if(!pd0 && !pd1)
1599         continue;
1600       if((!pd0 && pd1) || (pd0 && !pd1))
1601         {
1602           what=std::string("a cell part def is defined only for one among this or other !");
1603           return false;
1604         }
1605       bool ret(pd0->isEqual(pd1,what));
1606       if(!ret)
1607         return false;
1608     }
1609   return true;
1610 }
1611
1612 void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const
1613 {
1614   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1615     MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it);
1616   MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m);
1617 }
1618
1619 void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const
1620 {
1621   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1622     {
1623       const MEDCoupling1GTUMesh *tmp(*it);
1624       if(tmp)
1625         {
1626           (const_cast<MEDCoupling1GTUMesh *>(tmp))->setName(master.getName().c_str());
1627           (const_cast<MEDCoupling1GTUMesh *>(tmp))->setDescription(master.getDescription().c_str());
1628           (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1629           (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTimeUnit(master.getTimeUnit());
1630         }
1631     }
1632   const MEDCouplingUMesh *m(_m);
1633   if(m)
1634     {
1635       (const_cast<MEDCouplingUMesh *>(m))->setName(master.getName().c_str());
1636       (const_cast<MEDCouplingUMesh *>(m))->setDescription(master.getDescription().c_str());
1637       (const_cast<MEDCouplingUMesh *>(m))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1638       (const_cast<MEDCouplingUMesh *>(m))->setTimeUnit(master.getTimeUnit());
1639     }
1640 }
1641
1642 bool MEDFileUMeshAggregateCompute::empty() const
1643 {
1644   if(_mp_time<_m_time)
1645     return ((const MEDCouplingUMesh *)_m)==0;
1646   //else _mp_time>=_m_time)
1647   return _m_parts.empty();
1648 }
1649
1650 int MEDFileUMeshAggregateCompute::getMeshDimension() const
1651 {
1652   if(_mp_time<_m_time)
1653     {
1654       const MEDCouplingUMesh *m(_m);
1655       if(!m)
1656         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : no umesh in this !");
1657       return m->getMeshDimension();
1658     }
1659   else
1660     {
1661       if(_m_parts.empty())
1662         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh is empty !");
1663       const MEDCoupling1GTUMesh *m(_m_parts[0]);
1664       if(!m)
1665         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh contains null instance !");
1666       return m->getMeshDimension();
1667     }
1668 }
1669
1670 std::vector<int> MEDFileUMeshAggregateCompute::getDistributionOfTypes() const
1671 {
1672   if(_mp_time<_m_time)
1673     {
1674       const MEDCouplingUMesh *m(_m);
1675       if(!m)
1676         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : no umesh in this !");
1677       return m->getDistributionOfTypes();
1678     }
1679   else
1680     {
1681       std::vector<int> ret;
1682       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1683         {
1684           const MEDCoupling1GTUMesh *tmp(*it);
1685           if(!tmp)
1686             throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : part mesh contains null instance !");
1687           std::vector<int> ret0(tmp->getDistributionOfTypes());
1688           ret.insert(ret.end(),ret0.begin(),ret0.end());
1689         }
1690       return ret;
1691     }
1692 }
1693
1694 int MEDFileUMeshAggregateCompute::getSize() const
1695 {
1696   if(_mp_time<_m_time)
1697     {
1698       const MEDCouplingUMesh *m(_m);
1699       if(!m)
1700         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : no umesh in this !");
1701       return m->getNumberOfCells();
1702     }
1703   else
1704     {
1705       int ret=0;
1706       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1707         {
1708           const MEDCoupling1GTUMesh *m(*it);
1709           if(!m)
1710             throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : part mesh contains null instance !");
1711           ret+=m->getNumberOfCells();
1712         }
1713       return ret;
1714     }
1715 }
1716
1717 void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords)
1718 {
1719   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1720     {
1721       MEDCoupling1GTUMesh *tmp(*it);
1722       if(tmp)
1723         (*it)->setCoords(coords);
1724     }
1725   MEDCouplingUMesh *m(_m);
1726   if(m)
1727     m->setCoords(coords);
1728 }