Salome HOME
typo-fix by Kunda
[tools/medcoupling.git] / src / MEDLoader / MEDFileMeshElt.cxx
1 // Copyright (C) 2007-2016  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 "MEDFileMeshElt.hxx"
22 #include "MEDFileSafeCaller.txx"
23 #include "MEDFileMeshReadSelector.hxx"
24
25 #include "MEDCouplingUMesh.hxx"
26
27 #include "InterpKernelException.hxx"
28 #include "InterpKernelAutoPtr.hxx"
29 #include "CellModel.hxx"
30
31 #include <iostream>
32
33 extern med_geometry_type typmai3[34];
34
35 using namespace MEDCoupling;
36
37 MEDFileUMeshPerTypeCommon *MEDFileUMeshPerTypeCommon::New()
38 {
39   return new MEDFileUMeshPerTypeCommon;
40 }
41
42 void MEDFileUMeshPerTypeCommon::loadCommonPart(med_idt fid, const char *mName, int dt, int it, int curNbOfElem, med_geometry_type geoElt,
43                                                med_entity_type entity, MEDFileMeshReadSelector *mrs)
44 {
45   med_bool changement,transformation;
46   _fam=0;
47   if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
48     {    
49       if(!mrs || mrs->isCellFamilyFieldReading())
50         {
51           _fam=DataArrayInt::New();
52           _fam->alloc(curNbOfElem,1);
53           if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,entity,geoElt,_fam->getPointer())!=0)
54             std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0);
55         }
56     }
57   _num=0;
58   if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
59     {
60       if(!mrs || mrs->isCellNumFieldReading())
61         {
62           _num=DataArrayInt::New();
63           _num->alloc(curNbOfElem,1);
64           if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,geoElt,_num->getPointer())!=0)
65             _num=0;
66         }
67     }
68   _names=0;
69   if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NAME,MED_NODAL,&changement,&transformation)>0)
70     {
71       if(!mrs || mrs->isCellNameFieldReading())
72         {
73           _names=DataArrayAsciiChar::New();
74           _names->alloc(curNbOfElem+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
75           if(MEDmeshEntityNameRd(fid,mName,dt,it,entity,geoElt,_names->getPointer())!=0)
76             _names=0;
77           else
78             _names->reAlloc(curNbOfElem);//not a bug to avoid the memory corruption due to last \0 at the end
79         }
80     }
81 }
82
83 std::size_t MEDFileUMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
84 {
85   return 0;
86 }
87
88 std::vector<const BigMemoryObject *> MEDFileUMeshPerTypeCommon::getDirectChildrenWithNull() const
89 {
90   std::vector<const BigMemoryObject *> ret;
91   ret.push_back((const DataArrayInt *)_num);
92   ret.push_back((const DataArrayInt *)_fam);
93   ret.push_back((const DataArrayAsciiChar *)_names);
94   return ret;
95 }
96
97 MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType geoElt2, MEDFileMeshReadSelector *mrs)
98 {
99   med_entity_type whichEntity;
100   if(!isExisting(fid,mName,dt,it,geoElt,whichEntity))
101     return 0;
102   return new MEDFileUMeshPerType(fid,mName,dt,it,mdim,geoElt,geoElt2,whichEntity,mrs);
103 }
104
105 MEDFileUMeshPerType *MEDFileUMeshPerType::NewPart(med_idt fid, const char *mName, int dt, int it, int mdim, INTERP_KERNEL::NormalizedCellType geoElt2, int strt, int stp, int step, MEDFileMeshReadSelector *mrs)
106 {
107   int geoElt2i((int)geoElt2);
108   if(geoElt2i<0 || geoElt2i>=34)
109     throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::NewPart : Not recognized MEDCoupling/MEDLoader geometric type !");
110   med_geometry_type geoElt(typmai3[geoElt2]);
111   med_entity_type whichEntity;
112   if(!isExisting(fid,mName,dt,it,geoElt,whichEntity))
113     throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::NewPart : The specified geo type is not present in the specified mesh !");
114   MCAuto<MEDFileUMeshPerType> ret(new MEDFileUMeshPerType);
115   ret->loadPart(fid,mName,dt,it,mdim,geoElt,geoElt2,whichEntity,strt,stp,step,mrs);
116   return ret.retn();
117 }
118
119 std::size_t MEDFileUMeshPerType::getHeapMemorySizeWithoutChildren() const
120 {
121   return MEDFileUMeshPerTypeCommon::getHeapMemorySizeWithoutChildren()+0;
122 }
123
124 std::vector<const BigMemoryObject *> MEDFileUMeshPerType::getDirectChildrenWithNull() const
125 {
126   std::vector<const BigMemoryObject *> ret(MEDFileUMeshPerTypeCommon::getDirectChildrenWithNull());
127   ret.push_back((const MEDCoupling1GTUMesh *)_m);
128   return ret;
129 }
130
131 bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, int dt, int it, med_geometry_type geoElt, med_entity_type& whichEntity)
132 {
133   static const med_entity_type entities[3]={MED_CELL,MED_DESCENDING_FACE,MED_DESCENDING_EDGE};
134   int nbOfElt=0;
135   for(int i=0;i<3;i++)
136     {
137       med_bool changement,transformation;
138       int tmp(MEDmeshnEntity(fid,mName,dt,it,entities[i],geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
139       if(tmp>nbOfElt)
140         {
141           nbOfElt=tmp;
142           whichEntity=entities[i];
143           if(i>0)
144             std::cerr << "WARNING : MEDFile has been detected to be noncompliant with MED 3 : Please change entity in MEDFile for geotype " <<  geoElt << std::endl;
145         }
146     }
147   return nbOfElt>0;
148 }
149
150 int MEDFileUMeshPerType::getDim() const
151 {
152   return _m->getMeshDimension();
153 }
154
155 MEDFileUMeshPerType::MEDFileUMeshPerType()
156 {
157 }
158
159 MEDFileUMeshPerType::MEDFileUMeshPerType(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
160                                          med_entity_type entity, MEDFileMeshReadSelector *mrs)
161 {
162   med_bool changement,transformation;
163   int curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
164   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(type));
165   if(!cm.isDynamic())
166     {
167       loadFromStaticType(fid,mName,dt,it,mdim,curNbOfElem,geoElt,type,entity,mrs);
168       return;
169     }
170   if(type==INTERP_KERNEL::NORM_POLYGON || type==INTERP_KERNEL::NORM_QPOLYG)
171     {
172       loadPolyg(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity,mrs);
173       return;
174     }
175   //if(type==INTERP_KERNEL::NORM_POLYHED)
176   loadPolyh(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity,mrs);
177 }
178
179 void MEDFileUMeshPerType::loadPart(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
180                                    med_entity_type entity, int strt, int end, int step, MEDFileMeshReadSelector *mrs)
181 {
182   med_bool changement,transformation;
183   int curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
184   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(type));
185   _pd=PartDefinition::New(strt,end,step);
186   if(!cm.isDynamic())
187     {
188       loadPartStaticType(fid,mName,dt,it,mdim,curNbOfElem,geoElt,type,entity,strt,end,step,mrs);
189     }
190   else
191     throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::loadPart : not implemented yet for the dynamic type !");
192 }
193
194 void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
195                                              med_entity_type entity, MEDFileMeshReadSelector *mrs)
196 {
197   _m=MEDCoupling1SGTUMesh::New(mName,type);
198   MEDCoupling1SGTUMesh *mc(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *)_m));
199   MCAuto<DataArrayInt> conn(DataArrayInt::New());
200   int nbOfNodesPerCell(mc->getNumberOfNodesPerCell());
201   conn->alloc(nbOfNodesPerCell*curNbOfElem,1);
202   MEDFILESAFECALLERRD0(MEDmeshElementConnectivityRd,(fid,mName,dt,it,entity,geoElt,MED_NODAL,MED_FULL_INTERLACE,conn->getPointer()));
203   std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind2nd(std::plus<int>(),-1));
204   mc->setNodalConnectivity(conn);
205   loadCommonPart(fid,mName,dt,it,curNbOfElem,geoElt,entity,mrs);
206 }
207
208 void MEDFileUMeshPerType::loadPartStaticType(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
209                                              med_entity_type entity, int strt, int end, int step, MEDFileMeshReadSelector *mrs)
210 {
211   if(strt<0)
212     throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::loadPartStaticType : start pos is negative !");
213   if(end>curNbOfElem)
214     throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::loadPartStaticType : end is after the authorized range !");
215   int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(strt,end,step,"MEDFileUMeshPerType::loadPartStaticType"));
216   _m=MEDCoupling1SGTUMesh::New(mName,type);
217   MEDCoupling1SGTUMesh *mc(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *)_m));
218   MCAuto<DataArrayInt> conn(DataArrayInt::New());
219   int nbOfNodesPerCell(mc->getNumberOfNodesPerCell());
220   conn->alloc(nbOfNodesPerCell*nbOfEltsToLoad,1);
221   med_filter filter=MED_FILTER_INIT;
222   MEDfilterBlockOfEntityCr(fid,/*nentity*/curNbOfElem,/*nvaluesperentity*/1,/*nconstituentpervalue*/nbOfNodesPerCell,
223                            MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
224                            /*start*/strt+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
225                            /*lastblocksize=useless because count=1*/0,&filter);
226   MEDFILESAFECALLERRD0(MEDmeshElementConnectivityAdvancedRd,(fid,mName,dt,it,entity,geoElt,MED_NODAL,&filter,conn->getPointer()));
227   MEDfilterClose(&filter);
228   std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind2nd(std::plus<int>(),-1));
229   mc->setNodalConnectivity(conn);
230   loadPartOfCellCommonPart(fid,mName,strt,end,step,dt,it,mdim,curNbOfElem,geoElt,entity,mrs);
231 }
232
233 void MEDFileUMeshPerType::loadPartOfCellCommonPart(med_idt fid, const char *mName, int strt, int stp, int step, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, med_entity_type entity, MEDFileMeshReadSelector *mrs)
234 {
235   med_bool changement,transformation;
236   _fam=0;
237   int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(strt,stp,step,"MEDFileUMeshPerType::loadPartOfCellCommonPart"));
238   if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
239     {
240       if(!mrs || mrs->isCellFamilyFieldReading())
241         {
242           _fam=DataArrayInt::New();
243           _fam->alloc(nbOfEltsToLoad,1);
244           med_filter filter=MED_FILTER_INIT;
245           MEDfilterBlockOfEntityCr(fid,/*nentity*/curNbOfElem,/*nvaluesperentity*/1,/*nconstituentpervalue*/1,
246                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
247                                    /*start*/strt+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
248                                    /*lastblocksize=useless because count=1*/0,&filter);
249           if(MEDmeshEntityAttributeAdvancedRd(fid,mName,MED_FAMILY_NUMBER,dt,it,entity,geoElt,&filter,_fam->getPointer())!=0)
250             _fam->fillWithZero();
251           MEDfilterClose(&filter);
252         }
253     }
254   _num=0;
255   if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
256     {
257       if(!mrs || mrs->isCellNumFieldReading())
258         {
259           _num=DataArrayInt::New();
260           _num->alloc(nbOfEltsToLoad,1);
261           med_filter filter=MED_FILTER_INIT;
262           MEDfilterBlockOfEntityCr(fid,/*nentity*/curNbOfElem,/*nvaluesperentity*/1,/*nconstituentpervalue*/1,
263                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
264                                    /*start*/strt+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
265                                    /*lastblocksize=useless because count=1*/0,&filter);
266           if(MEDmeshEntityAttributeAdvancedRd(fid,mName,MED_NUMBER,dt,it,entity,geoElt,&filter,_num->getPointer())!=0)
267             _num->fillWithZero();
268           MEDfilterClose(&filter);
269         }
270     }
271   _names=0;
272   if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NAME,MED_NODAL,&changement,&transformation)>0)
273     {
274       if(!mrs || mrs->isCellNameFieldReading())
275         {
276           _names=DataArrayAsciiChar::New();
277           _names->alloc(nbOfEltsToLoad+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
278           med_filter filter=MED_FILTER_INIT;
279           MEDfilterBlockOfEntityCr(fid,/*nentity*/curNbOfElem,/*nvaluesperentity*/1,/*nconstituentpervalue*/1,
280                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
281                                    /*start*/strt+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
282                                    /*lastblocksize=useless because count=1*/0,&filter);
283           if(MEDmeshEntityAttributeAdvancedRd(fid,mName,MED_NAME,dt,it,entity,geoElt,&filter,_names->getPointer())!=0)
284             _names=0;
285           else
286             _names->reAlloc(nbOfEltsToLoad);//not a bug to avoid the memory corruption due to last \0 at the end
287           MEDfilterClose(&filter);
288         }
289     }
290 }
291
292 void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int dt, int it, int mdim, int arraySize, med_geometry_type geoElt,
293                                     med_entity_type entity, MEDFileMeshReadSelector *mrs)
294 {
295   med_bool changement,transformation;
296   med_int curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1);
297   _m=MEDCoupling1DGTUMesh::New(mName,geoElt==MED_POLYGON?INTERP_KERNEL::NORM_POLYGON:INTERP_KERNEL::NORM_QPOLYG);
298   MCAuto<MEDCoupling1DGTUMesh> mc(DynamicCast<MEDCoupling1GTUMesh,MEDCoupling1DGTUMesh>(_m));
299   MCAuto<DataArrayInt> conn(DataArrayInt::New()),connI(DataArrayInt::New());
300   conn->alloc(arraySize,1); connI->alloc(curNbOfElem+1,1);
301   MEDFILESAFECALLERRD0(MEDmeshPolygon2Rd,(fid,mName,dt,it,MED_CELL,geoElt,MED_NODAL,connI->getPointer(),conn->getPointer()));
302   std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind2nd(std::plus<int>(),-1));
303   std::transform(connI->begin(),connI->end(),connI->getPointer(),std::bind2nd(std::plus<int>(),-1));
304   mc->setNodalConnectivity(conn,connI);
305   loadCommonPart(fid,mName,dt,it,curNbOfElem,geoElt,entity,mrs);
306 }
307
308 void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, int connFaceLgth, med_geometry_type geoElt,
309                                     med_entity_type entity, MEDFileMeshReadSelector *mrs)
310 {
311   med_bool changement,transformation;
312   med_int indexFaceLgth(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation));
313   int curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1);
314   _m=MEDCoupling1DGTUMesh::New(mName,INTERP_KERNEL::NORM_POLYHED);
315   MCAuto<MEDCoupling1DGTUMesh> mc(DynamicCastSafe<MEDCoupling1GTUMesh,MEDCoupling1DGTUMesh>(_m));
316   INTERP_KERNEL::AutoPtr<int> index=new int[curNbOfElem+1];
317   INTERP_KERNEL::AutoPtr<int> indexFace=new int[indexFaceLgth];
318   INTERP_KERNEL::AutoPtr<int> locConn=new int[connFaceLgth];
319   MEDFILESAFECALLERRD0(MEDmeshPolyhedronRd,(fid,mName,dt,it,MED_CELL,MED_NODAL,index,indexFace,locConn));
320   MCAuto<DataArrayInt> conn(DataArrayInt::New()),connI(DataArrayInt::New());
321   int arraySize=connFaceLgth;
322   for(int i=0;i<curNbOfElem;i++)
323     arraySize+=index[i+1]-index[i]-1;
324   conn=DataArrayInt::New();
325   conn->alloc(arraySize,1);
326   int *wFinalConn=conn->getPointer();
327   connI->alloc(curNbOfElem+1,1);
328   int *finalIndex(connI->getPointer());
329   finalIndex[0]=0;
330   for(int i=0;i<curNbOfElem;i++)
331     {
332       finalIndex[i+1]=finalIndex[i]+index[i+1]-index[i]-1+indexFace[index[i+1]-1]-indexFace[index[i]-1];
333       wFinalConn=std::transform(locConn+indexFace[index[i]-1]-1,locConn+indexFace[index[i]]-1,wFinalConn,std::bind2nd(std::plus<int>(),-1));
334       for(int j=index[i];j<index[i+1]-1;j++)
335         {
336           *wFinalConn++=-1;
337           wFinalConn=std::transform(locConn+indexFace[j]-1,locConn+indexFace[j+1]-1,wFinalConn,std::bind2nd(std::plus<int>(),-1));
338         }
339     }
340   mc->setNodalConnectivity(conn,connI);
341   loadCommonPart(fid,mName,dt,it,curNbOfElem,MED_POLYHEDRON,entity,mrs);
342 }
343
344 void MEDFileUMeshPerType::Write(med_idt fid, const std::string& mname, int mdim, const MEDCoupling1GTUMesh *m, const DataArrayInt *fam, const DataArrayInt *num, const DataArrayAsciiChar *names)
345 {
346   int nbOfCells=m->getNumberOfCells();
347   if(nbOfCells<1)
348     return ;
349   int dt,it;
350   double timm=m->getTime(dt,it);
351   INTERP_KERNEL::NormalizedCellType ikt=m->getTypeOfCell(0);
352   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(ikt);
353   med_geometry_type curMedType=typmai3[(int)ikt];
354   if(!cm.isDynamic())
355     {
356       const MEDCoupling1SGTUMesh *m0(dynamic_cast<const MEDCoupling1SGTUMesh *>(m));
357       if(!m0)
358         throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::Write : internal error #1 !");
359       MCAuto<DataArrayInt> arr(m0->getNodalConnectivity()->deepCopy());
360       std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind2nd(std::plus<int>(),1));
361       MEDFILESAFECALLERWR0(MEDmeshElementConnectivityWr,(fid,mname.c_str(),dt,it,timm,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,nbOfCells,arr->begin()));
362     }
363   else
364     {
365       const MEDCoupling1DGTUMesh *m0(dynamic_cast<const MEDCoupling1DGTUMesh *>(m));
366       if(!m0)
367         throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::Write : internal error #2 !");
368       if(ikt==INTERP_KERNEL::NORM_POLYGON || ikt==INTERP_KERNEL::NORM_QPOLYG)
369         {
370           MCAuto<DataArrayInt> arr(m0->getNodalConnectivity()->deepCopy()),arrI(m0->getNodalConnectivityIndex()->deepCopy());
371           std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind2nd(std::plus<int>(),1));
372           std::transform(arrI->begin(),arrI->end(),arrI->getPointer(),std::bind2nd(std::plus<int>(),1));
373           MEDFILESAFECALLERWR0(MEDmeshPolygon2Wr,(fid,mname.c_str(),dt,it,timm,MED_CELL,ikt==INTERP_KERNEL::NORM_POLYGON?MED_POLYGON:MED_POLYGON2,MED_NODAL,nbOfCells+1,arrI->begin(),arr->begin()));
374         }
375       else
376         {
377           const int *conn(m0->getNodalConnectivity()->begin()),*connI(m0->getNodalConnectivityIndex()->begin());
378           int meshLgth=m0->getNodalConnectivityLength();
379           int nbOfFaces=std::count(conn,conn+meshLgth,-1)+nbOfCells;
380           INTERP_KERNEL::AutoPtr<int> tab1=new int[nbOfCells+1];
381           int *w1=tab1; *w1=1;
382           INTERP_KERNEL::AutoPtr<int> tab2=new int[nbOfFaces+1];
383           int *w2=tab2; *w2=1;
384           INTERP_KERNEL::AutoPtr<int> bigtab=new int[meshLgth];
385           int *bt=bigtab;
386           for(int i=0;i<nbOfCells;i++,w1++)
387             {
388               int nbOfFaces2=0;
389               for(const int *w=conn+connI[i];w!=conn+connI[i+1];w2++)
390                 {
391                   const int *wend=std::find(w,conn+connI[i+1],-1);
392                   bt=std::transform(w,wend,bt,std::bind2nd(std::plus<int>(),1));
393                   int nbOfNode=std::distance(w,wend);
394                   w2[1]=w2[0]+nbOfNode;
395                   if(wend!=conn+connI[i+1])
396                     w=wend+1;
397                   else
398                     w=wend;
399                   nbOfFaces2++;
400                 }
401               w1[1]=w1[0]+nbOfFaces2;
402             }
403           MEDFILESAFECALLERWR0(MEDmeshPolyhedronWr,(fid,mname.c_str(),dt,it,timm,MED_CELL,MED_NODAL,nbOfCells+1,tab1,nbOfFaces+1,tab2,bigtab));
404         }
405     }
406   if(fam)
407     MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_CELL,curMedType,nbOfCells,fam->getConstPointer()));
408   if(num)
409     MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_CELL,curMedType,nbOfCells,num->getConstPointer()));
410   if(names)
411     {
412       if(names->getNumberOfComponents()!=MED_SNAME_SIZE)
413         {
414           std::ostringstream oss; oss << "MEDFileUMeshPerType::write : expected a name field on cells with number of components set to " << MED_SNAME_SIZE;
415           oss << " ! The array has " << names->getNumberOfComponents() << " components !";
416           throw INTERP_KERNEL::Exception(oss.str().c_str());
417         }
418       MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_CELL,curMedType,nbOfCells,names->getConstPointer()));
419     }
420 }