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