Salome HOME
On the highway to MEDReader :
[modules/med.git] / src / MEDLoader / MEDFileMeshLL.cxx
1 // Copyright (C) 2007-2013  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.
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 "MEDFileMeshReadSelector.hxx"
25
26 #include "MEDCouplingUMesh.hxx"
27
28 #include "InterpKernelAutoPtr.hxx"
29 #include "CellModel.hxx"
30
31 #include <set>
32
33 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
34 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
35 extern med_geometry_type typmainoeud[1];
36
37 using namespace ParaMEDMEM;
38
39 MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_univ_name(MED_LNAME_SIZE),_dt_unit(MED_LNAME_SIZE)
40 {
41 }
42
43 int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const char *mname, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception)
44 {
45   med_mesh_type type_maillage;
46   char maillage_description[MED_COMMENT_SIZE+1];
47   char dtunit[MED_LNAME_SIZE+1];
48   med_int spaceDim,dim;
49   char nommaa[MED_NAME_SIZE+1];
50   med_int n=MEDnMesh(fid);
51   bool found=false;
52   int ret=-1;
53   med_sorting_type stype;
54   std::vector<std::string> ms;
55   int nstep;
56   med_axis_type axistype;
57   for(int i=0;i<n && !found;i++)
58     {
59       int naxis=MEDmeshnAxis(fid,i+1);
60       INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
61       INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
62       MEDmeshInfo(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit);
63       dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit));
64       std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
65       ms.push_back(cur);
66       if(cur==mname)
67         {
68           found=true;
69           ret=i+1;
70         }
71     }
72   if(!found)
73     {
74       std::ostringstream oss;
75       oss << "No such meshname (" << mname <<  ") in file ! Must be in : ";
76       std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss,", "));
77       throw INTERP_KERNEL::Exception(oss.str().c_str());
78     }
79   switch(type_maillage)
80     {
81     case MED_UNSTRUCTURED_MESH:
82       meshType=UNSTRUCTURED;
83       break;
84     case MED_STRUCTURED_MESH:
85       {
86         med_grid_type gt;
87         MEDmeshGridTypeRd(fid,mname,&gt);
88         switch(gt)
89           {
90           case MED_CARTESIAN_GRID:
91             meshType=CARTESIAN;
92             break;
93           case MED_CURVILINEAR_GRID:
94             meshType=CURVE_LINEAR;
95             break;
96           default:
97             throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
98           }
99         break;
100       }
101     default:
102       throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !");
103     }
104   med_int numdt,numit;
105   med_float dtt;
106   MEDmeshComputationStepInfo(fid,mname,1,&numdt,&numit,&dtt);
107   dt=numdt; it=numit;
108   return ret;
109 }
110
111 double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const char *mName, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception)
112 {
113   bool found=false;
114   med_int numdt,numit;
115   med_float dtt;
116   std::vector< std::pair<int,int> > p(nstep);
117   for(int i=0;i<nstep;i++)
118     {
119       MEDmeshComputationStepInfo(fid,mName,i+1,&numdt,&numit,&dtt);
120       p[i]=std::make_pair<int,int>(numdt,numit);
121       found=(numdt==dt) && (numit==numit);
122     }
123   if(!found)
124     {
125       std::ostringstream oss; oss << "No such iteration=" << dt << ",order=" << it << " numbers found for mesh '" << mName << "' ! ";
126       oss << "Possibilities are : ";
127       for(int i=0;i<nstep;i++)
128         oss << "(" << p[i].first << "," << p[i].second << "), ";
129       throw INTERP_KERNEL::Exception(oss.str().c_str());
130     }
131   return dtt;
132 }
133
134 std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception)
135 {
136   med_mesh_type type_maillage;
137   med_int spaceDim;
138   med_sorting_type stype;
139   med_axis_type axistype;
140   int naxis=MEDmeshnAxis(fid,mId);
141   INTERP_KERNEL::AutoPtr<char> nameTmp=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
142   INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
143   INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
144   INTERP_KERNEL::AutoPtr<char> univTmp=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
145   if(MEDmeshInfo(fid,mId,nameTmp,&spaceDim,&Mdim,&type_maillage,_description.getPointer(),_dt_unit.getPointer(),
146                  &stype,&nstep,&axistype,axisname,axisunit)!=0)
147     throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !");
148   MEDmeshUniversalNameRd(fid,nameTmp,_univ_name.getPointer());
149   switch(type_maillage)
150     {
151     case MED_UNSTRUCTURED_MESH:
152       meshType=UNSTRUCTURED;
153       break;
154     case MED_STRUCTURED_MESH:
155       {
156         med_grid_type gt;
157         MEDmeshGridTypeRd(fid,mName,&gt);
158         switch(gt)
159           {
160           case MED_CARTESIAN_GRID:
161             meshType=CARTESIAN;
162             break;
163           case MED_CURVILINEAR_GRID:
164             meshType=CURVE_LINEAR;
165             break;
166           default:
167             throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
168           }
169         break;
170       }
171     default:
172       throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !");
173     }
174   //
175   std::vector<std::string> infosOnComp(naxis);
176   for(int i=0;i<naxis;i++)
177     {
178       std::string info=MEDLoaderBase::buildUnionUnit(((char *)axisname)+i*MED_SNAME_SIZE,MED_SNAME_SIZE,((char *)axisunit)+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
179       infosOnComp[i]=info;
180     }
181   return infosOnComp;
182 }
183
184 void MEDFileMeshL2::ReadFamiliesAndGrps(med_idt fid, const char *meshName, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps, MEDFileMeshReadSelector *mrs)
185 {
186   if(mrs && !(mrs->isCellFamilyFieldReading() || mrs->isNodeFamilyFieldReading()))
187     return ;
188   char nomfam[MED_NAME_SIZE+1];
189   med_int numfam;
190   int nfam=MEDnFamily(fid,meshName);
191   for(int i=0;i<nfam;i++)
192     {
193       int ngro=MEDnFamilyGroup(fid,meshName,i+1);
194       med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
195       INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
196       INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
197       INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
198       INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
199       MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
200       std::string famName=MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE);
201       fams[famName]=numfam;
202       for(int j=0;j<ngro;j++)
203         {
204           std::string groupname=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
205           grps[groupname].push_back(famName);
206         }
207     }
208 }
209
210 void MEDFileMeshL2::WriteFamiliesAndGrps(med_idt fid, const char *mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol)
211 {
212   for(std::map<std::string,int>::const_iterator it=fams.begin();it!=fams.end();it++)
213     {
214       std::vector<std::string> grpsOfFam;
215       for(std::map<std::string, std::vector<std::string> >::const_iterator it1=grps.begin();it1!=grps.end();it1++)
216         {
217           if(std::find((*it1).second.begin(),(*it1).second.end(),(*it).first)!=(*it1).second.end())
218             grpsOfFam.push_back((*it1).first);
219         }
220       int ngro=grpsOfFam.size();
221       INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
222       int i=0;
223       for(std::vector<std::string>::const_iterator it2=grpsOfFam.begin();it2!=grpsOfFam.end();it2++,i++)
224         MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,tooLongStrPol);
225       INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
226       MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_NAME_SIZE,famName,tooLongStrPol);
227       int ret=MEDfamilyCr(fid,mname,famName,(*it).second,ngro,groName);
228       ret++;
229     }
230 }
231
232 MEDFileUMeshL2::MEDFileUMeshL2()
233 {
234 }
235
236 void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs)
237 {
238   _name.set(mName);
239   int nstep;
240   int Mdim;
241   ParaMEDMEM::MEDCouplingMeshType meshType;
242   std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim);
243   if(meshType!=UNSTRUCTURED)
244     throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !");
245   _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
246   _iteration=dt;
247   _order=it;
248   loadConnectivity(fid,Mdim,mName,dt,it,mrs);//to improve check (dt,it) coherency
249   loadCoords(fid,mId,infosOnComp,mName,dt,it);
250 }
251
252 void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs)
253 {
254   _per_type_mesh.resize(1);
255   _per_type_mesh[0].clear();
256   for(int j=0;j<MED_N_CELL_FIXED_GEO;j++)
257     {
258       MEDFileUMeshPerType *tmp=MEDFileUMeshPerType::New(fid,mName,dt,it,mdim,typmai[j],typmai2[j],mrs);
259       if(tmp)
260         _per_type_mesh[0].push_back(tmp);
261     }
262   sortTypes();
263 }
264
265 void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
266 {
267   int spaceDim=infosOnComp.size();
268   med_bool changement,transformation;
269   int nCoords=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
270   _coords=DataArrayDouble::New();
271   _coords->alloc(nCoords,spaceDim);
272   double *coordsPtr=_coords->getPointer();
273   MEDmeshNodeCoordinateRd(fid,mName,dt,it,MED_FULL_INTERLACE,coordsPtr);
274   if(MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
275     {
276       _fam_coords=DataArrayInt::New();
277       _fam_coords->alloc(nCoords,1);
278       MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer());
279     }
280   else
281     _fam_coords=0;
282   if(MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
283     {
284       _num_coords=DataArrayInt::New();
285       _num_coords->alloc(nCoords,1);
286       MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer());
287     }
288   else
289     _num_coords=0;
290   if(MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
291     {
292       _name_coords=DataArrayAsciiChar::New();
293       _name_coords->alloc(nCoords+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
294       MEDmeshEntityNameRd(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,_name_coords->getPointer());
295       _name_coords->reAlloc(nCoords);//not a bug to avoid the memory corruption due to last \0 at the end
296     }
297   else
298     _name_coords=0;
299   for(int i=0;i<spaceDim;i++)
300     _coords->setInfoOnComponent(i,infosOnComp[i].c_str());
301 }
302
303 void MEDFileUMeshL2::sortTypes()
304 {
305   std::set<int> mdims;
306   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
307   _per_type_mesh.clear();
308   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
309     mdims.insert((*it)->getDim());
310   if(mdims.empty())
311     return;
312   int mdim=*mdims.rbegin();
313   _per_type_mesh.resize(mdim+1);
314   for(int dim=mdim+1;dim!=0;dim--)
315     {
316       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
317       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
318         if((*it)->getDim()==dim-1)
319           elt.push_back(*it);
320     }
321   // suppression of contiguous empty levels at the end of _per_type_mesh.
322   int nbOfUselessLev=0;
323   bool isFirst=true;
324   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > >::reverse_iterator it2=_per_type_mesh.rbegin();it2!=_per_type_mesh.rend();it2++)
325     {
326       if((*it2).empty() && isFirst)
327         {
328           nbOfUselessLev++;
329         }
330       else
331         isFirst=false;
332     }
333   _per_type_mesh.resize(_per_type_mesh.size()-nbOfUselessLev);
334 }
335
336 void MEDFileUMeshL2::WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords)
337 {
338   if(!coords)
339     return ;
340   MEDmeshNodeCoordinateWr(fid,mname,dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->getConstPointer());
341   if(famCoords)
342     MEDmeshEntityFamilyNumberWr(fid,mname,dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->getConstPointer());
343   if(numCoords)
344     MEDmeshEntityNumberWr(fid,mname,dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->getConstPointer());
345   if(nameCoords)
346     {
347       if(nameCoords->getNumberOfComponents()!=MED_SNAME_SIZE)
348         {
349           std::ostringstream oss; oss << " MEDFileUMeshL2::WriteCoords : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE;
350           oss << " ! The array has " << nameCoords->getNumberOfComponents() << " components !";
351           throw INTERP_KERNEL::Exception(oss.str().c_str());
352         }
353       MEDmeshEntityNameWr(fid,mname,dt,it,MED_NODE,MED_NO_GEOTYPE,nameCoords->getNumberOfTuples(),nameCoords->getConstPointer());
354     }
355 }
356
357 bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
358 {
359   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
360     if((*it)->getFam()==0)
361       return false;
362   return true;
363 }
364
365 bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const
366 {
367   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
368     if((*it)->getNum()==0)
369       return false;
370   return true;
371 }
372
373 bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const
374 {
375   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
376     if((*it)->getNames()==0)
377       return false;
378   return true;
379 }
380
381 MEDFileCMeshL2::MEDFileCMeshL2()
382 {
383 }
384
385 void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
386 {
387   _name.set(mName);
388   int nstep;
389   int Mdim;
390   ParaMEDMEM::MEDCouplingMeshType meshType;
391   std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim);
392   if(meshType!=CARTESIAN)
393     throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
394   _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
395   _iteration=dt;
396   _order=it;
397   //
398   med_grid_type gridtype;
399   MEDmeshGridTypeRd(fid,mName,&gridtype);
400   if(gridtype!=MED_CARTESIAN_GRID)
401     throw INTERP_KERNEL::Exception("Invalid structured mesh ! Expected cartesian mesh type !");
402   _cmesh=MEDCouplingCMesh::New();
403   for(int i=0;i<Mdim;i++)
404     {
405       med_data_type dataTypeReq=GetDataTypeCorrespondingToSpaceId(i);
406       med_bool chgt=MED_FALSE,trsf=MED_FALSE;
407       int nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,dataTypeReq,MED_NO_CMODE,&chgt,&trsf);
408       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=DataArrayDouble::New();
409       da->alloc(nbOfElt,1);
410       da->setInfoOnComponent(0,infosOnComp[i].c_str());
411       MEDmeshGridIndexCoordinateRd(fid,mName,dt,it,i+1,da->getPointer());
412       _cmesh->setCoordsAt(i,da);
413     }
414 }
415
416 med_data_type MEDFileCMeshL2::GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception)
417 {
418   switch(id)
419     {
420     case 0:
421       return MED_COORDINATE_AXIS1;
422     case 1:
423       return MED_COORDINATE_AXIS2;
424     case 2:
425       return MED_COORDINATE_AXIS3;
426     default:
427       throw INTERP_KERNEL::Exception("Invalid meshdim detected in Cartesian Grid !");
428     }
429 }
430
431 MEDFileCLMeshL2::MEDFileCLMeshL2()
432 {
433 }
434
435 void MEDFileCLMeshL2::loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
436 {
437   _name.set(mName);
438   int nstep;
439   int Mdim;
440   ParaMEDMEM::MEDCouplingMeshType meshType;
441   std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim);
442   if(meshType!=CURVE_LINEAR)
443     throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
444   _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
445   _iteration=dt;
446   _order=it;
447   //
448   _clmesh=MEDCouplingCurveLinearMesh::New();
449   INTERP_KERNEL::AutoPtr<int> stGrid=new int[Mdim];
450   MEDmeshGridStructRd(fid,mName,dt,it,stGrid);
451   _clmesh->setNodeGridStructure(stGrid,((int *)stGrid)+Mdim);
452   med_bool chgt=MED_FALSE,trsf=MED_FALSE;
453   int nbNodes=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&chgt,&trsf);
454   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=DataArrayDouble::New();
455   da->alloc(nbNodes,infosOnComp.size());
456   da->setInfoOnComponents(infosOnComp);
457   MEDmeshNodeCoordinateRd(fid,mName,dt,it,MED_FULL_INTERLACE,da->getPointer());
458   _clmesh->setCoords(da);
459 }
460
461 MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0)
462 {
463 }
464
465 /*!
466  * Warning it returns an instance to deallocate !!!!
467  */
468 MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
469 {
470   _st->_num->updateTime();
471   if((MEDCouplingUMesh *)_m==0)
472     {
473       updateTime();
474       _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCpy());
475       _m->renumberCells(_st->_num->getConstPointer(),true);
476       return _m.retn();
477     }
478   else
479     {
480       if(_mpt_time==_st->_m_by_types.getTimeOfThis() && _num_time==_st->_num->getTimeOfThis())
481         return _m.retn();
482       else
483         {
484           updateTime();
485           _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCpy());
486           _m->renumberCells(_st->_num->getConstPointer(),true);
487           return _m.retn();
488         }
489     }
490 }
491
492 void MEDFileUMeshPermCompute::operator=(MEDCouplingUMesh *m)
493 {
494   _m=m;
495 }
496
497 void MEDFileUMeshPermCompute::updateTime() const
498 {
499   _mpt_time=_st->_m_by_types.getTimeOfThis();
500   _num_time=_st->_num->getTimeOfThis();
501 }
502
503 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other):_m_by_types(other._m_by_types),_fam(other._fam),_num(other._num),_names(other._names),_rev_num(other._rev_num),_m(this)
504 {
505 }
506
507 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id):_m(this)
508 {
509   const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& v=l2.getLev(id);
510   if(v.empty())
511     return;
512   int sz=v.size();
513   std::vector<const MEDCoupling1GTUMesh *> ms(sz);
514   std::vector<const DataArrayInt *> fams(sz),nums(sz);
515   std::vector<const DataArrayChar *> names(sz); 
516   for(int i=0;i<sz;i++)
517     {
518       MEDCoupling1GTUMesh *elt(v[i]->getMesh());
519       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp2=l2.getCoords();
520       elt->setCoords(tmp2);
521       ms[i]=elt;
522     }
523   _m_by_types.assignParts(ms);
524   if(l2.isFamDefinedOnLev(id))
525     {
526       for(int i=0;i<sz;i++)
527         fams[i]=v[i]->getFam();
528       _fam=DataArrayInt::Aggregate(fams);
529     }
530   if(l2.isNumDefinedOnLev(id))
531     {
532       for(int i=0;i<sz;i++)
533         nums[i]=v[i]->getNum();
534       _num=DataArrayInt::Aggregate(nums);
535       computeRevNum();
536     }
537   if(l2.isNamesDefinedOnLev(id))
538     {
539       for(int i=0;i<sz;i++)
540         names[i]=v[i]->getNames();
541       _names=dynamic_cast<DataArrayAsciiChar *>(DataArrayChar::Aggregate(names));
542     }
543 }
544
545 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this)
546 {
547   assignMesh(m,true);
548 }
549
550 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m(this)
551 {
552   assignMesh(m,newOrOld);
553 }
554
555 std::size_t MEDFileUMeshSplitL1::getHeapMemorySize() const
556 {
557   std::size_t ret=0;
558   ret+=_m_by_types.getHeapMemorySize();
559   if((const DataArrayInt*)_fam)
560     ret+=_fam->getHeapMemorySize();
561   if((const DataArrayInt*)_num)
562     ret+=_num->getHeapMemorySize();
563   if((const DataArrayInt*)_rev_num)
564     ret+=_rev_num->getHeapMemorySize();
565   if((const DataArrayAsciiChar*)_names)
566     ret+=_names->getHeapMemorySize();
567   return ret;
568 }
569
570 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCpy(DataArrayDouble *coords) const
571 {
572   MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> ret=new MEDFileUMeshSplitL1(*this);
573   ret->_m_by_types=_m_by_types.deepCpy(coords);
574   if((const DataArrayInt *)_fam)
575     ret->_fam=_fam->deepCpy();
576   if((const DataArrayInt *)_num)
577     ret->_num=_num->deepCpy();
578   if((const DataArrayInt *)_rev_num)
579     ret->_rev_num=_rev_num->deepCpy();
580   if((const DataArrayAsciiChar *)_names)
581     ret->_names=_names->deepCpy();
582   return ret.retn();
583 }
584
585 bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const
586 {
587   if(!_m_by_types.isEqual(other->_m_by_types,eps,what))
588     return false;
589   const DataArrayInt *d1=_fam;
590   const DataArrayInt *d2=other->_fam;
591   if((d1==0 && d2!=0) || (d1!=0 && d2==0))
592     {
593       what="Presence of family arr in one sublevel and not in other!";
594       return false;
595     }
596   if(d1)
597     if(!d1->isEqual(*d2))
598       {
599         what="family arr at a sublevel are not deeply equal !";
600         return false;
601       }
602   d1=_num;
603   d2=other->_num;
604   if((d1==0 && d2!=0) || (d1!=0 && d2==0))
605     {
606       what="Presence of cell numbering arr in one sublevel and not in other!";
607       return false;
608     }
609   if(d1)
610     if(!d1->isEqual(*d2))
611       {
612         what="Numbering cell arr at a sublevel are not deeply equal !";
613         return false;
614       }
615   const DataArrayAsciiChar *e1=_names;
616   const DataArrayAsciiChar *e2=other->_names;
617   if((e1==0 && e2!=0) || (e1!=0 && e2==0))
618     {
619       what="Presence of cell names arr in one sublevel and not in other!";
620       return false;
621     }
622   if(e1)
623     if(!e1->isEqual(*e2))
624       {
625         what="Name cell arr at a sublevel are not deeply equal !";
626         return false;
627       }
628   return true;
629 }
630
631 void MEDFileUMeshSplitL1::synchronizeTinyInfo(const MEDFileMesh& master) const
632 {
633   _m_by_types.synchronizeTinyInfo(master);
634 }
635
636 void MEDFileUMeshSplitL1::clearNonDiscrAttributes() const
637 {
638   _m_by_types.clearNonDiscrAttributes();
639 }
640
641 void MEDFileUMeshSplitL1::ClearNonDiscrAttributes(const MEDCouplingMesh *tmp)
642 {
643   if(!tmp)
644     return ;
645   (const_cast<MEDCouplingMesh *>(tmp))->setName("");
646   (const_cast<MEDCouplingMesh *>(tmp))->setDescription("");
647   (const_cast<MEDCouplingMesh *>(tmp))->setTime(0.,-1,-1);
648   (const_cast<MEDCouplingMesh *>(tmp))->setTimeUnit("");
649 }
650
651 void MEDFileUMeshSplitL1::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception)
652 {
653   _m_by_types.setCoords(coords);
654 }
655
656 void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception)
657 {
658   if(newOrOld)
659     {
660       m->incrRef();
661       _m=m;
662       _m_by_types.assignUMesh(dynamic_cast<MEDCouplingUMesh *>(m->deepCpy()));
663       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
664       if(!da->isIdentity())
665         {
666           _num=da->invertArrayO2N2N2O(m->getNumberOfCells());
667           _m.updateTime();
668           computeRevNum();
669           _m_by_types.getUmesh()->renumberCells(da->getConstPointer(),false);
670         }
671     }
672   else
673     {
674       if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
675         throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh : the mode of mesh setting expects to follow the MED file numbering convention ! it is not the case !");
676       m->incrRef();
677       _m_by_types.assignUMesh(m);
678     }
679   _fam=DataArrayInt::New();
680   _fam->alloc(m->getNumberOfCells(),1);
681   _fam->fillWithValue(0);
682 }
683
684 bool MEDFileUMeshSplitL1::empty() const
685 {
686   return _m_by_types.empty();
687 }
688
689 bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector<int>& ids) const
690 {
691   const DataArrayInt *fam=_fam;
692   if(!fam)
693     return false;
694   return fam->presenceOfValue(ids);
695 }
696
697 int MEDFileUMeshSplitL1::getMeshDimension() const
698 {
699   return _m_by_types.getMeshDimension();
700 }
701
702 void MEDFileUMeshSplitL1::simpleRepr(std::ostream& oss) const
703 {
704   std::vector<int> code=_m_by_types.getDistributionOfTypes();
705   int nbOfTypes=code.size()/3;
706   for(int i=0;i<nbOfTypes;i++)
707     {
708       INTERP_KERNEL::NormalizedCellType typ=(INTERP_KERNEL::NormalizedCellType) code[3*i];
709       oss << "    - Number of cells with type " << INTERP_KERNEL::CellModel::GetCellModel(typ).getRepr() << " : " << code[3*i+1] << std::endl;
710     }
711 }
712
713 int MEDFileUMeshSplitL1::getSize() const throw(INTERP_KERNEL::Exception)
714 {
715   return _m_by_types.getSize();
716 }
717
718 MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const
719 {
720   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> eltsToKeep=_fam->getIdsEqualList(idsBg,idsEnd);
721   MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true);
722   if(renum)
723     return renumIfNeeded(m,eltsToKeep->getConstPointer());
724   return m;
725 }
726
727 DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const
728 {
729   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam->getIdsEqualList(idsBg,idsEnd);
730   if(renum)
731     return renumIfNeededArr(da);
732   return da.retn();
733 }
734
735 MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
736 {
737   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp;
738   if(renum && ((const DataArrayInt *)_num))
739     tmp=_m;
740   else
741     { tmp=_m_by_types.getUmesh(); if(tmp) tmp->incrRef(); }
742   return tmp.retn();
743 }
744
745 DataArrayInt *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField() throw(INTERP_KERNEL::Exception)
746 {
747   if((DataArrayInt *)_fam)
748     return _fam;
749   int nbOfTuples=_m_by_types.getSize();
750   _fam=DataArrayInt::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero();
751   return _fam;
752 }
753
754 const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const
755 {
756   return _fam;
757 }
758
759 const DataArrayInt *MEDFileUMeshSplitL1::getNumberField() const
760 {
761   return _num;
762 }
763
764 const DataArrayInt *MEDFileUMeshSplitL1::getRevNumberField() const
765 {
766   return _rev_num;
767 }
768
769 const DataArrayAsciiChar *MEDFileUMeshSplitL1::getNameField() const
770 {
771   return _names;
772 }
773
774 void MEDFileUMeshSplitL1::eraseFamilyField()
775 {
776   _fam->fillWithZero();
777 }
778
779 /*!
780  * This method ignores _m and _m_by_types.
781  */
782 void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
783                                                std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception)
784 {
785   std::vector< DataArrayInt * > corr;
786   _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr);
787   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corrMSafe(corr.begin(),corr.end());
788   std::vector< std::vector<int> > fidsOfGroups;
789   std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
790   _fam=DataArrayInt::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups);
791   int nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells();
792   std::map<int,std::string> newfams;
793   std::map<int,int> famIdTrad;
794   TraduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams);
795   int *w=_fam->getPointer();
796   for(int i=0;i<nbOfCells;i++,w++)
797     *w=famIdTrad[*w];
798 }
799
800 void MEDFileUMeshSplitL1::write(med_idt fid, const char *mName, int mdim) const
801 {
802   std::vector<MEDCoupling1GTUMesh *> ms(_m_by_types.getParts());
803   int start=0;
804   for(std::vector<MEDCoupling1GTUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
805     {
806       int nbCells=(*it)->getNumberOfCells();
807       int end=start+nbCells;
808       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam,num;
809       MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> names;
810       if((const DataArrayInt *)_fam)
811         fam=_fam->substr(start,end);
812       if((const DataArrayInt *)_num)
813         num=_num->substr(start,end);
814       if((const DataArrayAsciiChar *)_names)
815         names=static_cast<DataArrayAsciiChar *>(_names->substr(start,end));
816       MEDFileUMeshPerType::Write(fid,mName,mdim,(*it),fam,num,names);
817       start=end;
818     }
819 }
820
821 void MEDFileUMeshSplitL1::renumberNodesInConn(const int *newNodeNumbersO2N) throw(INTERP_KERNEL::Exception)
822 {
823   MEDCouplingUMesh *m(_m_by_types.getUmesh());
824   if(!m)
825     return;
826   m->renumberNodesInConn(newNodeNumbersO2N);
827 }
828
829 void MEDFileUMeshSplitL1::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception)
830 {
831   DataArrayInt *arr=_fam;
832   if(arr)
833     arr->changeValue(oldId,newId);
834 }
835
836 void MEDFileUMeshSplitL1::setFamilyArr(DataArrayInt *famArr)
837 {
838   if(!famArr)
839     {
840       _fam=0;
841       return ;
842     }
843   int sz(_m_by_types.getSize());
844   famArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setFamilyArr : Problem in size of Family arr ! ");
845   famArr->incrRef();
846   _fam=famArr;
847 }
848
849 void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr)
850 {
851   if(!renumArr)
852     {
853       _num=0;
854       _rev_num=0;
855       return ;
856     }
857   int sz(_m_by_types.getSize());
858   renumArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setRenumArr : Problem in size of numbering arr ! ");
859   renumArr->incrRef();
860   _num=renumArr;
861   computeRevNum();
862 }
863
864 void MEDFileUMeshSplitL1::setNameArr(DataArrayAsciiChar *nameArr)
865 {
866   if(!nameArr)
867     {
868       _names=0;
869       return ;
870     }
871   int sz(_m_by_types.getSize());
872   nameArr->checkNbOfTuplesAndComp(sz,MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! ");
873   nameArr->incrRef();
874   _names=nameArr;
875 }
876
877 MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds)
878 {
879   if(renum==0)
880     return m;
881   if(cellIds==0)
882     m->renumberCells(renum->getConstPointer(),true);
883   else
884     {
885       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
886       m->renumberCells(locnum->getConstPointer(),true);
887     }
888   return m;
889 }
890
891 MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const
892 {
893   return Renumber2(_num,m,cellIds);
894 }
895
896 DataArrayInt *MEDFileUMeshSplitL1::Renumber(const DataArrayInt *renum, const DataArrayInt *da)
897 {
898   if((const DataArrayInt *)renum==0)
899     {
900       da->incrRef();
901       return const_cast<DataArrayInt *>(da);
902     }
903   return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
904 }
905
906 DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const
907 {
908   return Renumber(_num,da);
909 }
910
911 std::vector<int> MEDFileUMeshSplitL1::GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families)
912 {
913   int id=-1;
914   for(std::map<std::string,int>::const_iterator it=families.begin();it!=families.end();it++)
915     id=std::max(id,(*it).second);
916   if(id==-1)
917     id=0;
918   std::vector<int> ret(nb);
919   for(int i=1;i<=nb;i++)
920     ret[i]=id+i;
921   return ret;
922 }
923
924 void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
925                                               std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams)
926 {
927   std::set<int> allfids;
928   //tony
929 }
930
931 void MEDFileUMeshSplitL1::computeRevNum() const
932 {
933   int pos;
934   int maxValue=_num->getMaxValue(pos);
935   _rev_num=_num->invertArrayN2O2O2N(maxValue+1);
936 }
937
938 //=
939
940 MEDFileUMeshAggregateCompute::MEDFileUMeshAggregateCompute():_mp_time(0),_m_time(0)
941 {
942 }
943
944 void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
945 {
946   std::size_t sz(mParts.size());
947   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > ret(sz);
948   for(std::size_t i=0;i<sz;i++)
949     {
950       const MEDCoupling1GTUMesh *elt(mParts[i]);
951       if(!elt)
952         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignParts : presence of null pointer !");
953       ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt); elt->incrRef();
954     }
955   _m_parts=ret;
956   _mp_time=std::max(_mp_time,_m_time)+1;
957   _m=0;
958 }
959
960 void MEDFileUMeshAggregateCompute::assignUMesh(MEDCouplingUMesh *m)
961 {
962   _m=m;
963   _m_parts.clear();
964   _m_time=std::max(_mp_time,_m_time)+1;
965 }
966
967 MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const
968 {
969   if(_mp_time<=_m_time)
970     return _m;
971   std::vector< const MEDCoupling1GTUMesh *> mp(_m_parts.size());
972   std::copy(_m_parts.begin(),_m_parts.end(),mp.begin());
973   _m=MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(mp);
974   _m_parts.clear();//to avoid memory peak !
975   _m_time=_mp_time+1;//+1 is important ! That is to say that only _m is OK not _m_parts because cleared !
976   return _m;
977 }
978
979 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::getParts() const
980 {
981   if(_mp_time>=_m_time)
982     {
983       std::vector<MEDCoupling1GTUMesh *> ret(_m_parts.size());
984       std::size_t i(0);
985       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
986         {
987           const MEDCoupling1GTUMesh *elt(*it);
988           ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt);
989         }
990       return ret;
991     }
992   forceComputationOfPartsFromUMesh();
993   std::vector<MEDCoupling1GTUMesh *> ret(_m_parts.size());
994   std::size_t i(0);
995   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
996     {
997       const MEDCoupling1GTUMesh *elt(*it);
998       ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt);
999     }
1000   return ret;
1001 }
1002
1003 void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const
1004 {
1005   const MEDCouplingUMesh *m(_m);
1006   if(!m)
1007     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !");
1008   std::vector<MEDCouplingUMesh *> ms(m->splitByType());
1009   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > msMSafe(ms.begin(),ms.end());
1010   std::size_t sz(msMSafe.size());
1011   _m_parts.resize(sz);
1012   for(std::size_t i=0;i<sz;i++)
1013     _m_parts[i]=MEDCoupling1GTUMesh::New(ms[i]);
1014   _mp_time=std::max(_mp_time,_m_time)+1;
1015 }
1016
1017 std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const
1018 {
1019   if(_mp_time>_m_time)
1020     return getTimeOfParts();
1021   if(_m_time>_mp_time)
1022     return getTimeOfUMesh();
1023   return std::max(getTimeOfParts(),getTimeOfUMesh());
1024 }
1025
1026 std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const
1027 {
1028   std::size_t ret(0);
1029   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1030     {
1031       const MEDCoupling1GTUMesh *elt(*it);
1032       if(!elt)
1033         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : null obj in parts !");
1034       ret=std::max(ret,elt->getTimeOfThis());
1035     }
1036   if(ret==0)
1037     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : parts is empty !");
1038   return ret;
1039 }
1040
1041 std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const
1042 {
1043   const MEDCouplingUMesh *m(_m);
1044   if(!m)
1045     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfUMesh : unmesh is null !");
1046   return m->getTimeOfThis();
1047 }
1048
1049 /*!
1050  * Coordinates pointer is not counted because father instance already count it !
1051  */
1052 std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySize() const
1053
1054   std::size_t ret(0);
1055   ret+=_m_parts.size()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>);
1056   std::size_t sz(_m_parts.size());
1057   for(std::size_t i=0;i<sz;i++)
1058     {
1059       const MEDCoupling1GTUMesh *pt(_m_parts[i]);
1060       if(pt)
1061         {
1062           ret+=pt->getHeapMemorySize();
1063           const DataArrayDouble *coo(pt->getCoords());
1064           if(coo)
1065             ret-=coo->getHeapMemorySize();
1066         }
1067     }
1068   const MEDCouplingUMesh *m(_m);
1069   if(m)
1070     {
1071       ret+=m->getHeapMemorySize();
1072       const DataArrayDouble *coo(m->getCoords());
1073       if(coo)
1074             ret-=coo->getHeapMemorySize();
1075     }
1076   return ret;
1077 }
1078
1079 MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDouble *coords) const
1080 {
1081   MEDFileUMeshAggregateCompute ret;
1082   ret._m_parts.resize(_m_parts.size());
1083   for(std::size_t i=0;i<_m_parts.size();i++)
1084     {
1085       const MEDCoupling1GTUMesh *elt(_m_parts[i]);
1086       if(elt)
1087         {
1088           ret._m_parts[i]=static_cast<ParaMEDMEM::MEDCoupling1GTUMesh*>(elt->deepCpy());
1089           ret._m_parts[i]->setCoords(coords);
1090         }
1091     }
1092   ret._mp_time=_mp_time; ret._m_time=_m_time;
1093   if((const MEDCouplingUMesh *)_m)
1094     {
1095       ret._m=static_cast<ParaMEDMEM::MEDCouplingUMesh*>(_m->deepCpy());
1096       ret._m->setCoords(coords);
1097     }
1098   return ret;
1099 }
1100
1101 bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const
1102 {
1103   const MEDCouplingUMesh *m1(getUmesh());
1104   const MEDCouplingUMesh *m2(other.getUmesh());
1105   if((m1==0 && m2!=0) || (m1!=0 && m2==0))
1106     {
1107       what="Presence of mesh in one sublevel and not in other!";
1108       return false;
1109     }
1110   if(m1)
1111     {
1112       std::string what2;
1113       if(!m1->isEqualIfNotWhy(m2,eps,what2))
1114         {
1115           what=std::string("meshes at a sublevel are not deeply equal (")+what2+std::string(")!");
1116           return false;
1117         }
1118     }
1119   return true;
1120 }
1121
1122 void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const
1123 {
1124   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1125     MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it);
1126   MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m);
1127 }
1128
1129 void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const
1130 {
1131   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1132     {
1133       const MEDCoupling1GTUMesh *tmp(*it);
1134       if(tmp)
1135         {
1136           (const_cast<MEDCoupling1GTUMesh *>(tmp))->setName(master.getName());
1137           (const_cast<MEDCoupling1GTUMesh *>(tmp))->setDescription(master.getDescription());
1138           (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1139           (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTimeUnit(master.getTimeUnit());
1140         }
1141     }
1142   const MEDCouplingUMesh *m(_m);
1143   if(m)
1144     {
1145       (const_cast<MEDCouplingUMesh *>(m))->setName(master.getName());
1146       (const_cast<MEDCouplingUMesh *>(m))->setDescription(master.getDescription());
1147       (const_cast<MEDCouplingUMesh *>(m))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1148       (const_cast<MEDCouplingUMesh *>(m))->setTimeUnit(master.getTimeUnit());
1149     }
1150 }
1151
1152 bool MEDFileUMeshAggregateCompute::empty() const
1153 {
1154   if(_mp_time<_m_time)
1155     return ((const MEDCouplingUMesh *)_m)==0;
1156   //else _mp_time>=_m_time)
1157   return _m_parts.empty();
1158   
1159 }
1160
1161 int MEDFileUMeshAggregateCompute::getMeshDimension() const
1162 {
1163   if(_mp_time<_m_time)
1164     {
1165       const MEDCouplingUMesh *m(_m);
1166       if(!m)
1167         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : no umesh in this !");
1168       return m->getMeshDimension();
1169     }
1170   else
1171     {
1172       if(_m_parts.empty())
1173         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh is empty !");
1174       const MEDCoupling1GTUMesh *m(_m_parts[0]);
1175       if(!m)
1176         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh contains null instance !");
1177       return m->getMeshDimension();
1178     }
1179 }
1180
1181 std::vector<int> MEDFileUMeshAggregateCompute::getDistributionOfTypes() const
1182 {
1183   if(_mp_time<_m_time)
1184     {
1185       const MEDCouplingUMesh *m(_m);
1186       if(!m)
1187         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : no umesh in this !");
1188       return m->getDistributionOfTypes();
1189     }
1190   else
1191     {
1192       std::vector<int> ret;
1193       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1194         {
1195           const MEDCoupling1GTUMesh *tmp(*it);
1196           if(!tmp)
1197             throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : part mesh contains null instance !");
1198           std::vector<int> ret0(tmp->getDistributionOfTypes());
1199           ret.insert(ret.end(),ret0.begin(),ret0.end());
1200         }
1201       return ret;
1202     }
1203 }
1204
1205 int MEDFileUMeshAggregateCompute::getSize() const throw(INTERP_KERNEL::Exception)
1206 {
1207   if(_mp_time<_m_time)
1208     {
1209       const MEDCouplingUMesh *m(_m);
1210       if(!m)
1211         throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : no umesh in this !");
1212       return m->getNumberOfCells();
1213     }
1214   else
1215     {
1216       int ret=0;
1217       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1218         {
1219           const MEDCoupling1GTUMesh *m(*it);
1220           if(!m)
1221             throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : part mesh contains null instance !");
1222           ret+=m->getNumberOfCells();
1223         }
1224       return ret;
1225     }
1226 }
1227
1228 void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception)
1229 {
1230   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1231     {
1232       MEDCoupling1GTUMesh *tmp(*it);
1233       if(tmp)
1234         (*it)->setCoords(coords);
1235     }
1236   MEDCouplingUMesh *m(_m);
1237   if(m)
1238     m->setCoords(coords);
1239 }