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