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