1 // Copyright (C) 2007-2023 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDFileMeshElt.hxx"
22 #include "MEDFileSafeCaller.txx"
23 #include "MEDFileMeshReadSelector.hxx"
24 #include "MEDFileBasis.hxx"
26 #include "MEDCouplingUMesh.hxx"
28 #include "InterpKernelException.hxx"
29 #include "InterpKernelAutoPtr.hxx"
30 #include "CellModel.hxx"
32 #include "MEDFilterEntity.hxx"
37 // From MEDLOader.cxx TU
38 extern med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE];
40 using namespace MEDCoupling;
42 MEDFileUMeshPerTypeCommon *MEDFileUMeshPerTypeCommon::New()
44 return new MEDFileUMeshPerTypeCommon;
47 void MEDFileUMeshPerTypeCommon::loadCommonPart(med_idt fid, const char *mName, int dt, int it, mcIdType curNbOfElem, med_geometry_type geoElt,
48 med_entity_type entity, MEDFileMeshReadSelector *mrs)
50 med_bool changement,transformation;
52 if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
54 if(!mrs || mrs->isCellFamilyFieldReading())
56 MCAuto<DataArrayMedInt> miFam=DataArrayMedInt::New();
57 miFam->alloc(curNbOfElem,1);
58 if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,entity,geoElt,miFam->getPointer())!=0)
59 std::fill(miFam->getPointer(),miFam->getPointer()+curNbOfElem,0);
60 _fam=FromMedIntArray<mcIdType>( miFam );
64 if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
66 if(!mrs || mrs->isCellNumFieldReading())
68 MCAuto<DataArrayMedInt> miNum=DataArrayMedInt::New();
69 miNum->alloc(curNbOfElem,1);
70 if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,geoElt,miNum->getPointer())!=0)
72 _num=FromMedIntArray<mcIdType>(miNum);
76 if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NAME,MED_NODAL,&changement,&transformation)>0)
78 if(!mrs || mrs->isCellNameFieldReading())
80 _names=DataArrayAsciiChar::New();
81 _names->alloc(curNbOfElem+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
82 if(MEDmeshEntityNameRd(fid,mName,dt,it,entity,geoElt,_names->getPointer())!=0)
85 _names->reAlloc(curNbOfElem);//not a bug to avoid the memory corruption due to last \0 at the end
90 std::size_t MEDFileUMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
95 std::vector<const BigMemoryObject *> MEDFileUMeshPerTypeCommon::getDirectChildrenWithNull() const
97 std::vector<const BigMemoryObject *> ret;
98 ret.push_back((const DataArrayIdType *)_num);
99 ret.push_back((const DataArrayIdType *)_fam);
100 ret.push_back((const DataArrayAsciiChar *)_names);
104 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)
106 med_entity_type whichEntity;
107 if(!isExisting(fid,mName,dt,it,geoElt,whichEntity))
109 return new MEDFileUMeshPerType(fid,mName,dt,it,mdim,geoElt,geoElt2,whichEntity,mrs);
113 MEDFileUMeshPerType *MEDFileUMeshPerType::NewPart(med_idt fid, const char *mName, int dt, int it, int mdim, INTERP_KERNEL::NormalizedCellType geoElt2, mcIdType strt, mcIdType stp, mcIdType step, MEDFileMeshReadSelector *mrs)
115 int geoElt2i((int)geoElt2);
116 if(geoElt2i<0 || geoElt2i>=INTERP_KERNEL::NORM_MAXTYPE)
117 throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::NewPart : Not recognized MEDCoupling/MEDLoader geometric type !");
118 med_geometry_type geoElt(typmai3[geoElt2]);
119 med_entity_type whichEntity;
120 if(!isExisting(fid,mName,dt,it,geoElt,whichEntity))
121 throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::NewPart : The specified geo type is not present in the specified mesh !");
122 MCAuto<MEDFileUMeshPerType> ret(new MEDFileUMeshPerType);
123 ret->loadPart(fid,mName,dt,it,mdim,geoElt,geoElt2,whichEntity,strt,stp,step,mrs);
127 MEDFileUMeshPerType *MEDFileUMeshPerType::NewPart(med_idt fid, const char *mName, int dt, int it, int mdim, INTERP_KERNEL::NormalizedCellType geoElt2, const std::vector<mcIdType>& distrib, MEDFileMeshReadSelector *mrs)
129 int geoElt2i((int)geoElt2);
130 if(geoElt2i<0 || geoElt2i>=INTERP_KERNEL::NORM_MAXTYPE)
131 throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::NewPart : Not recognized MEDCoupling/MEDLoader geometric type !");
132 med_geometry_type geoElt(typmai3[geoElt2]);
133 med_entity_type whichEntity;
134 if(!isExisting(fid,mName,dt,it,geoElt,whichEntity))
135 throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::NewPart : The specified geo type is not present in the specified mesh !");
136 MCAuto<MEDFileUMeshPerType> ret(new MEDFileUMeshPerType);
137 ret->loadPart(fid,mName,dt,it,mdim,geoElt,geoElt2,whichEntity,distrib,mrs);
141 std::size_t MEDFileUMeshPerType::getHeapMemorySizeWithoutChildren() const
143 return MEDFileUMeshPerTypeCommon::getHeapMemorySizeWithoutChildren()+0;
146 std::vector<const BigMemoryObject *> MEDFileUMeshPerType::getDirectChildrenWithNull() const
148 std::vector<const BigMemoryObject *> ret(MEDFileUMeshPerTypeCommon::getDirectChildrenWithNull());
149 ret.push_back((const MEDCoupling1GTUMesh *)_m);
153 bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, int dt, int it, med_geometry_type geoElt, med_entity_type& whichEntity)
155 static const med_entity_type entities[3]={MED_CELL,MED_DESCENDING_FACE,MED_DESCENDING_EDGE};
159 med_bool changement,transformation;
160 mcIdType tmp(MEDmeshnEntity(fid,mName,dt,it,entities[i],geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
164 whichEntity=entities[i];
166 std::cerr << "WARNING : MEDFile has been detected to be noncompliant with MED 3 : Please change entity in MEDFile for geotype " << geoElt << std::endl;
172 int MEDFileUMeshPerType::getDim() const
174 return _m->getMeshDimension();
177 MEDFileUMeshPerType::MEDFileUMeshPerType()
181 MEDFileUMeshPerType::MEDFileUMeshPerType(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
182 med_entity_type entity, MEDFileMeshReadSelector *mrs)
184 med_bool changement,transformation;
185 mcIdType curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
186 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(type));
189 loadFromStaticType(fid,mName,dt,it,mdim,curNbOfElem,geoElt,type,entity,mrs);
192 if(type==INTERP_KERNEL::NORM_POLYGON || type==INTERP_KERNEL::NORM_QPOLYG)
194 loadPolyg(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity,mrs);
197 //if(type==INTERP_KERNEL::NORM_POLYHED)
198 loadPolyh(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity,mrs);
201 void MEDFileUMeshPerType::loadPart(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
202 med_entity_type entity, const std::vector<mcIdType>& distrib, MEDFileMeshReadSelector *mrs)
204 med_bool changement,transformation;
205 mcIdType curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
206 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(type));
207 MCAuto<DataArrayIdType> listOfIds=DataArrayIdType::New();
208 listOfIds->useArray(distrib.data(),false,DeallocType::C_DEALLOC,distrib.size(),1);
209 _pd=PartDefinition::New(listOfIds);
212 loadPartStaticType(fid,mName,dt,it,mdim,curNbOfElem,geoElt,type,entity,mrs);
215 throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::loadPart : not implemented yet for the dynamic type !");
218 void MEDFileUMeshPerType::loadPart(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
219 med_entity_type entity, mcIdType strt, mcIdType end, mcIdType step, MEDFileMeshReadSelector *mrs)
221 med_bool changement,transformation;
222 mcIdType curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
223 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(type));
224 _pd=PartDefinition::New(strt,end,step);
227 loadPartStaticType(fid,mName,dt,it,mdim,curNbOfElem,geoElt,type,entity,mrs);
230 throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::loadPart : not implemented yet for the dynamic type !");
234 void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int dt, int it, int mdim, mcIdType curNbOfElem, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
235 med_entity_type entity, MEDFileMeshReadSelector *mrs)
237 _m=MEDCoupling1SGTUMesh::New(mName,type);
238 MEDCoupling1SGTUMesh *mc(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *)_m));
239 MCAuto<DataArrayMedInt> conn(DataArrayMedInt::New());
240 mcIdType nbOfNodesPerCell(mc->getNumberOfNodesPerCell());
241 conn->alloc(nbOfNodesPerCell*curNbOfElem,1);
242 MEDFILESAFECALLERRD0(MEDmeshElementConnectivityRd,(fid,mName,dt,it,entity,geoElt,MED_NODAL,MED_FULL_INTERLACE,conn->getPointer()));
243 std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind(std::plus<med_int>(),std::placeholders::_1,-1));
244 mc->setNodalConnectivity(FromMedIntArray<mcIdType>(conn));
245 loadCommonPart(fid,mName,dt,it,curNbOfElem,geoElt,entity,mrs);
248 void MEDFileUMeshPerType::loadPartStaticType(med_idt fid, const char *mName, int dt, int it, int mdim, mcIdType curNbOfElem, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
249 med_entity_type entity, MEDFileMeshReadSelector *mrs)
251 _m=MEDCoupling1SGTUMesh::New(mName,type);
252 MEDCoupling1SGTUMesh *mc(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *)_m));
253 MCAuto<DataArrayMedInt> conn(DataArrayMedInt::New());
254 mcIdType nbOfNodesPerCell(mc->getNumberOfNodesPerCell());
256 throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::loadPartStaticType : no part definition !");
257 mcIdType nbOfEltsToLoad(_pd->getNumberOfElems());
258 conn->alloc(nbOfNodesPerCell*nbOfEltsToLoad,1);
260 MEDFilterEntity filter;
261 filter.fill(fid,/*nentity*/curNbOfElem,/*nvaluesperentity*/1,/*nconstituentpervalue*/nbOfNodesPerCell,
262 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
264 MEDFILESAFECALLERRD0(MEDmeshElementConnectivityAdvancedRd,(fid,mName,dt,it,entity,geoElt,MED_NODAL,filter.getPtr(),conn->getPointer()));
266 std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind(std::plus<med_int>(),std::placeholders::_1,-1));
267 mc->setNodalConnectivity(FromMedIntArray<mcIdType>(conn));
268 loadPartOfCellCommonPart(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity,mrs);
272 void MEDFileUMeshPerType::loadPartOfCellCommonPart(med_idt fid, const char *mName, int dt, int it, int mdim, mcIdType curNbOfElem, med_geometry_type geoElt, med_entity_type entity, MEDFileMeshReadSelector *mrs)
274 med_bool changement,transformation;
276 throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::loadPartOfCellCommonPart : no part definition !");
277 mcIdType nbOfEltsToLoad(_pd->getNumberOfElems());
279 if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
281 if(!mrs || mrs->isCellFamilyFieldReading())
283 MCAuto<DataArrayMedInt> miFam(DataArrayMedInt::New());
284 miFam->alloc(nbOfEltsToLoad,1);
285 MEDFilterEntity filter;
286 filter.fill(fid,/*nentity*/curNbOfElem,/*nvaluesperentity*/1,/*nconstituentpervalue*/1,
287 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
289 if(MEDmeshEntityAttributeAdvancedRd(fid,mName,MED_FAMILY_NUMBER,dt,it,entity,geoElt,filter.getPtr(),miFam->getPointer())!=0)
290 miFam->fillWithZero();
291 _fam=FromMedIntArray<mcIdType>(miFam);
295 if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
297 if(!mrs || mrs->isCellNumFieldReading())
299 MCAuto<DataArrayMedInt> miNum(DataArrayMedInt::New());
300 miNum->alloc(nbOfEltsToLoad,1);
301 MEDFilterEntity filter;
302 filter.fill(fid,/*nentity*/curNbOfElem,/*nvaluesperentity*/1,/*nconstituentpervalue*/1,
303 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
305 if(MEDmeshEntityAttributeAdvancedRd(fid,mName,MED_NUMBER,dt,it,entity,geoElt,filter.getPtr(),miNum->getPointer())!=0)
306 miNum->fillWithZero();
307 _num=FromMedIntArray<mcIdType>(miNum);
311 if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NAME,MED_NODAL,&changement,&transformation)>0)
313 if(!mrs || mrs->isCellNameFieldReading())
315 _names=DataArrayAsciiChar::New();
316 _names->alloc(nbOfEltsToLoad+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
317 MEDFilterEntity filter;
318 filter.fill(fid,/*nentity*/curNbOfElem,/*nvaluesperentity*/1,/*nconstituentpervalue*/1,
319 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
321 if(MEDmeshEntityAttributeAdvancedRd(fid,mName,MED_NAME,dt,it,entity,geoElt,filter.getPtr(),_names->getPointer())!=0)
324 _names->reAlloc(nbOfEltsToLoad);//not a bug to avoid the memory corruption due to last \0 at the end
329 void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int dt, int it, int mdim, mcIdType arraySize, med_geometry_type geoElt,
330 med_entity_type entity, MEDFileMeshReadSelector *mrs)
332 med_bool changement,transformation;
333 mcIdType curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1);
334 _m=MEDCoupling1DGTUMesh::New(mName,geoElt==MED_POLYGON?INTERP_KERNEL::NORM_POLYGON:INTERP_KERNEL::NORM_QPOLYG);
335 MCAuto<MEDCoupling1DGTUMesh> mc(DynamicCast<MEDCoupling1GTUMesh,MEDCoupling1DGTUMesh>(_m));
336 MCAuto<DataArrayMedInt> conn(DataArrayMedInt::New()),connI(DataArrayMedInt::New());
337 conn->alloc(arraySize,1); connI->alloc(curNbOfElem+1,1);
338 MEDFILESAFECALLERRD0(MEDmeshPolygon2Rd,(fid,mName,dt,it,MED_CELL,geoElt,MED_NODAL,connI->getPointer(),conn->getPointer()));
339 std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind(std::plus<med_int>(),std::placeholders::_1,-1));
340 std::transform(connI->begin(),connI->end(),connI->getPointer(),std::bind(std::plus<med_int>(),std::placeholders::_1,-1));
341 mc->setNodalConnectivity(FromMedIntArray<mcIdType>(conn),FromMedIntArray<mcIdType>(connI));
342 loadCommonPart(fid,mName,dt,it,curNbOfElem,geoElt,entity,mrs);
345 void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, mcIdType connFaceLgth, med_geometry_type geoElt,
346 med_entity_type entity, MEDFileMeshReadSelector *mrs)
348 med_bool changement,transformation;
349 med_int indexFaceLgth(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation));
350 mcIdType curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1);
351 _m=MEDCoupling1DGTUMesh::New(mName,INTERP_KERNEL::NORM_POLYHED);
352 MCAuto<MEDCoupling1DGTUMesh> mc(DynamicCastSafe<MEDCoupling1GTUMesh,MEDCoupling1DGTUMesh>(_m));
353 INTERP_KERNEL::AutoPtr<med_int> index=new med_int[curNbOfElem+1];
354 INTERP_KERNEL::AutoPtr<med_int> indexFace=new med_int[indexFaceLgth];
355 INTERP_KERNEL::AutoPtr<med_int> locConn=new med_int[connFaceLgth];
356 MEDFILESAFECALLERRD0(MEDmeshPolyhedronRd,(fid,mName,dt,it,MED_CELL,MED_NODAL,index,indexFace,locConn));
357 MCAuto<DataArrayIdType> conn(DataArrayIdType::New()),connI(DataArrayIdType::New());
358 mcIdType arraySize=connFaceLgth;
359 for(mcIdType i=0;i<curNbOfElem;i++)
360 arraySize+=index[i+1]-index[i]-1;
361 conn=DataArrayIdType::New();
362 conn->alloc(arraySize,1);
363 mcIdType *wFinalConn=conn->getPointer();
364 connI->alloc(curNbOfElem+1,1);
365 mcIdType *finalIndex(connI->getPointer());
367 for(mcIdType i=0;i<curNbOfElem;i++)
369 finalIndex[i+1]=finalIndex[i]+index[i+1]-index[i]-1+indexFace[index[i+1]-1]-indexFace[index[i]-1];
370 wFinalConn=std::transform(locConn+indexFace[index[i]-1]-1,locConn+indexFace[index[i]]-1,wFinalConn,std::bind(std::plus<mcIdType>(),std::placeholders::_1,-1));
371 for(mcIdType j=index[i];j<index[i+1]-1;j++)
374 wFinalConn=std::transform(locConn+indexFace[j]-1,locConn+indexFace[j+1]-1,wFinalConn,std::bind(std::plus<mcIdType>(),std::placeholders::_1,-1));
377 mc->setNodalConnectivity(conn,connI);
378 loadCommonPart(fid,mName,dt,it,curNbOfElem,MED_POLYHEDRON,entity,mrs);
381 void MEDFileUMeshPerType::Write(med_idt fid, const std::string& mname, int mdim, const MEDCoupling1GTUMesh *m, const DataArrayIdType *fam, const DataArrayIdType *num, const DataArrayAsciiChar *names)
383 mcIdType nbOfCells=m->getNumberOfCells();
387 double timm=m->getTime(dt,it);
388 INTERP_KERNEL::NormalizedCellType ikt=m->getTypeOfCell(0);
389 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(ikt);
390 med_geometry_type curMedType=typmai3[(int)ikt];
393 const MEDCoupling1SGTUMesh *m0(dynamic_cast<const MEDCoupling1SGTUMesh *>(m));
395 throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::Write : internal error #1 !");
396 MCAuto<DataArrayMedInt> arr(DataArrayMedInt_Copy(m0->getNodalConnectivity()));
397 std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind(std::plus<med_int>(),std::placeholders::_1,1));
398 MEDFILESAFECALLERWR0(MEDmeshElementConnectivityWr,(fid,mname.c_str(),dt,it,timm,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,ToMedInt(nbOfCells),arr->begin()));
402 const MEDCoupling1DGTUMesh *m0(dynamic_cast<const MEDCoupling1DGTUMesh *>(m));
404 throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::Write : internal error #2 !");
405 if(ikt==INTERP_KERNEL::NORM_POLYGON || ikt==INTERP_KERNEL::NORM_QPOLYG)
407 MCAuto<DataArrayMedInt> arr(DataArrayMedInt_Copy(m0->getNodalConnectivity())),arrI(DataArrayMedInt_Copy(m0->getNodalConnectivityIndex()));
408 std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind(std::plus<med_int>(),std::placeholders::_1,1));
409 std::transform(arrI->begin(),arrI->end(),arrI->getPointer(),std::bind(std::plus<med_int>(),std::placeholders::_1,1));
410 MEDFILESAFECALLERWR0(MEDmeshPolygon2Wr,(fid,mname.c_str(),dt,it,timm,MED_CELL,ikt==INTERP_KERNEL::NORM_POLYGON?MED_POLYGON:MED_POLYGON2,MED_NODAL,ToMedInt(nbOfCells+1),arrI->begin(),arr->begin()));
414 const mcIdType *conn(m0->getNodalConnectivity()->begin()),*connI(m0->getNodalConnectivityIndex()->begin());
415 mcIdType meshLgth=m0->getNodalConnectivityLength();
416 mcIdType nbOfFaces=ToIdType(std::count(conn,conn+meshLgth,-1)+nbOfCells);
417 INTERP_KERNEL::AutoPtr<med_int> tab1=new med_int[nbOfCells+1];
418 med_int *w1=tab1; *w1=1;
419 INTERP_KERNEL::AutoPtr<med_int> tab2=new med_int[nbOfFaces+1];
420 med_int *w2=tab2; *w2=1;
421 INTERP_KERNEL::AutoPtr<med_int> bigtab=new med_int[meshLgth];
423 for(mcIdType i=0;i<nbOfCells;i++,w1++)
426 for(const mcIdType *w=conn+connI[i];w!=conn+connI[i+1];w2++)
428 const mcIdType *wend=std::find(w,conn+connI[i+1],-1);
429 bt=std::transform(w,wend,bt,std::bind(std::plus<mcIdType>(),std::placeholders::_1,1));
430 std::size_t nbOfNode=std::distance(w,wend);
431 w2[1]=w2[0]+(med_int)nbOfNode;
432 if(wend!=conn+connI[i+1])
438 w1[1]=w1[0]+nbOfFaces2;
440 MEDFILESAFECALLERWR0(MEDmeshPolyhedronWr,(fid,mname.c_str(),dt,it,timm,MED_CELL,MED_NODAL,ToMedInt(nbOfCells+1),tab1,ToMedInt(nbOfFaces+1),tab2,bigtab));
444 MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_CELL,curMedType,ToMedInt(nbOfCells),ToMedIntArray<mcIdType>(fam)->getConstPointer()));
446 MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_CELL,curMedType,ToMedInt(nbOfCells),ToMedIntArray<mcIdType>(num)->getConstPointer()));
449 if(names->getNumberOfComponents()!=MED_SNAME_SIZE)
451 std::ostringstream oss; oss << "MEDFileUMeshPerType::write : expected a name field on cells with number of components set to " << MED_SNAME_SIZE;
452 oss << " ! The array has " << names->getNumberOfComponents() << " components !";
453 throw INTERP_KERNEL::Exception(oss.str().c_str());
455 MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_CELL,curMedType,ToMedInt(nbOfCells),names->getConstPointer()));