X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDFileMeshElt.cxx;h=7beaf1d10c14ce510d129dbd325bfe76ba6cb7fb;hb=19a65812ae7b522811413fff6e642d1273b13d48;hp=92e49111f9e673ae12f148b9a55c2374017ce5fa;hpb=3b1d77efdd048ef4aad858e96138bf79318119df;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx index 92e49111f..7beaf1d10 100644 --- a/src/MEDLoader/MEDFileMeshElt.cxx +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -21,6 +21,7 @@ #include "MEDFileMeshElt.hxx" #include "MEDFileSafeCaller.txx" #include "MEDFileMeshReadSelector.hxx" +#include "MEDFileBasis.hxx" #include "MEDCouplingUMesh.hxx" @@ -30,10 +31,73 @@ #include -extern med_geometry_type typmai3[34]; +// From MEDLOader.cxx TU +extern med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE]; using namespace MEDCoupling; +MEDFileUMeshPerTypeCommon *MEDFileUMeshPerTypeCommon::New() +{ + return new MEDFileUMeshPerTypeCommon; +} + +void MEDFileUMeshPerTypeCommon::loadCommonPart(med_idt fid, const char *mName, int dt, int it, mcIdType curNbOfElem, med_geometry_type geoElt, + med_entity_type entity, MEDFileMeshReadSelector *mrs) +{ + med_bool changement,transformation; + _fam=0; + if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) + { + if(!mrs || mrs->isCellFamilyFieldReading()) + { + MCAuto miFam=DataArrayMedInt::New(); + miFam->alloc(curNbOfElem,1); + if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,entity,geoElt,miFam->getPointer())!=0) + std::fill(miFam->getPointer(),miFam->getPointer()+curNbOfElem,0); + _fam=FromMedIntArray( miFam ); + } + } + _num=0; + if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) + { + if(!mrs || mrs->isCellNumFieldReading()) + { + MCAuto miNum=DataArrayMedInt::New(); + miNum->alloc(curNbOfElem,1); + if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,geoElt,miNum->getPointer())!=0) + miNum=0; + _num=FromMedIntArray(miNum); + } + } + _names=0; + if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NAME,MED_NODAL,&changement,&transformation)>0) + { + if(!mrs || mrs->isCellNameFieldReading()) + { + _names=DataArrayAsciiChar::New(); + _names->alloc(curNbOfElem+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end + if(MEDmeshEntityNameRd(fid,mName,dt,it,entity,geoElt,_names->getPointer())!=0) + _names=0; + else + _names->reAlloc(curNbOfElem);//not a bug to avoid the memory corruption due to last \0 at the end + } + } +} + +std::size_t MEDFileUMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const +{ + return 0; +} + +std::vector MEDFileUMeshPerTypeCommon::getDirectChildrenWithNull() const +{ + std::vector ret; + ret.push_back((const DataArrayIdType *)_num); + ret.push_back((const DataArrayIdType *)_fam); + ret.push_back((const DataArrayAsciiChar *)_names); + return ret; +} + 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) { med_entity_type whichEntity; @@ -42,10 +106,10 @@ MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, in return new MEDFileUMeshPerType(fid,mName,dt,it,mdim,geoElt,geoElt2,whichEntity,mrs); } -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) +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) { int geoElt2i((int)geoElt2); - if(geoElt2i<0 || geoElt2i>=34) + if(geoElt2i<0 || geoElt2i>=INTERP_KERNEL::NORM_MAXTYPE) throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::NewPart : Not recognized MEDCoupling/MEDLoader geometric type !"); med_geometry_type geoElt(typmai3[geoElt2]); med_entity_type whichEntity; @@ -58,33 +122,30 @@ MEDFileUMeshPerType *MEDFileUMeshPerType::NewPart(med_idt fid, const char *mName std::size_t MEDFileUMeshPerType::getHeapMemorySizeWithoutChildren() const { - return 0; + return MEDFileUMeshPerTypeCommon::getHeapMemorySizeWithoutChildren()+0; } std::vector MEDFileUMeshPerType::getDirectChildrenWithNull() const { - std::vector ret; + std::vector ret(MEDFileUMeshPerTypeCommon::getDirectChildrenWithNull()); ret.push_back((const MEDCoupling1GTUMesh *)_m); - ret.push_back((const DataArrayInt *)_num); - ret.push_back((const DataArrayInt *)_fam); - ret.push_back((const DataArrayAsciiChar *)_names); return ret; } bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, int dt, int it, med_geometry_type geoElt, med_entity_type& whichEntity) { static const med_entity_type entities[3]={MED_CELL,MED_DESCENDING_FACE,MED_DESCENDING_EDGE}; - int nbOfElt=0; + mcIdType nbOfElt=0; for(int i=0;i<3;i++) { med_bool changement,transformation; - int tmp(MEDmeshnEntity(fid,mName,dt,it,entities[i],geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation)); + mcIdType tmp(MEDmeshnEntity(fid,mName,dt,it,entities[i],geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation)); if(tmp>nbOfElt) { nbOfElt=tmp; whichEntity=entities[i]; if(i>0) - std::cerr << "WARNING : MEDFile has been detected to be no compilant with MED 3 : Please change entity in MEDFile for geotype " << geoElt << std::endl; + std::cerr << "WARNING : MEDFile has been detected to be noncompliant with MED 3 : Please change entity in MEDFile for geotype " << geoElt << std::endl; } } return nbOfElt>0; @@ -100,10 +161,10 @@ MEDFileUMeshPerType::MEDFileUMeshPerType() } MEDFileUMeshPerType::MEDFileUMeshPerType(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type, - med_entity_type entity, MEDFileMeshReadSelector *mrs):_entity(entity) + med_entity_type entity, MEDFileMeshReadSelector *mrs) { med_bool changement,transformation; - int curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation)); + mcIdType curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation)); const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(type)); if(!cm.isDynamic()) { @@ -120,10 +181,10 @@ MEDFileUMeshPerType::MEDFileUMeshPerType(med_idt fid, const char *mName, int dt, } void MEDFileUMeshPerType::loadPart(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type, - med_entity_type entity, int strt, int end, int step, MEDFileMeshReadSelector *mrs) + med_entity_type entity, mcIdType strt, mcIdType end, mcIdType step, MEDFileMeshReadSelector *mrs) { med_bool changement,transformation; - int curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation)); + mcIdType curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation)); const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(type)); _pd=PartDefinition::New(strt,end,step); if(!cm.isDynamic()) @@ -134,104 +195,64 @@ void MEDFileUMeshPerType::loadPart(med_idt fid, const char *mName, int dt, int i throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::loadPart : not implemented yet for the dynamic type !"); } -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, +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, med_entity_type entity, MEDFileMeshReadSelector *mrs) { _m=MEDCoupling1SGTUMesh::New(mName,type); MEDCoupling1SGTUMesh *mc(dynamic_cast((MEDCoupling1GTUMesh *)_m)); - MCAuto conn(DataArrayInt::New()); - int nbOfNodesPerCell(mc->getNumberOfNodesPerCell()); + MCAuto conn(DataArrayMedInt::New()); + mcIdType nbOfNodesPerCell(mc->getNumberOfNodesPerCell()); conn->alloc(nbOfNodesPerCell*curNbOfElem,1); MEDFILESAFECALLERRD0(MEDmeshElementConnectivityRd,(fid,mName,dt,it,entity,geoElt,MED_NODAL,MED_FULL_INTERLACE,conn->getPointer())); - std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind2nd(std::plus(),-1)); - mc->setNodalConnectivity(conn); - loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity,mrs); + std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind(std::plus(),std::placeholders::_1,-1)); + mc->setNodalConnectivity(FromMedIntArray(conn)); + loadCommonPart(fid,mName,dt,it,curNbOfElem,geoElt,entity,mrs); } -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, - med_entity_type entity, int strt, int end, int step, MEDFileMeshReadSelector *mrs) +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, + med_entity_type entity, mcIdType strt, mcIdType end, mcIdType step, MEDFileMeshReadSelector *mrs) { if(strt<0) throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::loadPartStaticType : start pos is negative !"); if(end>curNbOfElem) throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::loadPartStaticType : end is after the authorized range !"); - int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(strt,end,step,"MEDFileUMeshPerType::loadPartStaticType")); + mcIdType nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(strt,end,step,"MEDFileUMeshPerType::loadPartStaticType")); _m=MEDCoupling1SGTUMesh::New(mName,type); MEDCoupling1SGTUMesh *mc(dynamic_cast((MEDCoupling1GTUMesh *)_m)); - MCAuto conn(DataArrayInt::New()); - int nbOfNodesPerCell(mc->getNumberOfNodesPerCell()); + MCAuto conn(DataArrayMedInt::New()); + mcIdType nbOfNodesPerCell(mc->getNumberOfNodesPerCell()); conn->alloc(nbOfNodesPerCell*nbOfEltsToLoad,1); med_filter filter=MED_FILTER_INIT; - MEDfilterBlockOfEntityCr(fid,/*nentity*/curNbOfElem,/*nvaluesperentity*/1,/*nconstituentpervalue*/nbOfNodesPerCell, + MEDfilterBlockOfEntityCr(fid,/*nentity*/ToMedInt(curNbOfElem),/*nvaluesperentity*/1,/*nconstituentpervalue*/ToMedInt(nbOfNodesPerCell), MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE, - /*start*/strt+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad, + /*start*/ToMedInt(strt+1),/*stride*/ToMedInt(step),/*count*/1,/*blocksize*/ToMedInt(nbOfEltsToLoad), /*lastblocksize=useless because count=1*/0,&filter); MEDFILESAFECALLERRD0(MEDmeshElementConnectivityAdvancedRd,(fid,mName,dt,it,entity,geoElt,MED_NODAL,&filter,conn->getPointer())); MEDfilterClose(&filter); - std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind2nd(std::plus(),-1)); - mc->setNodalConnectivity(conn); + std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind(std::plus(),std::placeholders::_1,-1)); + mc->setNodalConnectivity(FromMedIntArray(conn)); loadPartOfCellCommonPart(fid,mName,strt,end,step,dt,it,mdim,curNbOfElem,geoElt,entity,mrs); } -void MEDFileUMeshPerType::loadCommonPart(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, - med_entity_type entity, MEDFileMeshReadSelector *mrs) -{ - med_bool changement,transformation; - _fam=0; - if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) - { - if(!mrs || mrs->isCellFamilyFieldReading()) - { - _fam=DataArrayInt::New(); - _fam->alloc(curNbOfElem,1); - if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,entity,geoElt,_fam->getPointer())!=0) - std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0); - } - } - _num=0; - if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) - { - if(!mrs || mrs->isCellNumFieldReading()) - { - _num=DataArrayInt::New(); - _num->alloc(curNbOfElem,1); - if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,geoElt,_num->getPointer())!=0) - _num=0; - } - } - _names=0; - if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NAME,MED_NODAL,&changement,&transformation)>0) - { - if(!mrs || mrs->isCellNameFieldReading()) - { - _names=DataArrayAsciiChar::New(); - _names->alloc(curNbOfElem+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end - if(MEDmeshEntityNameRd(fid,mName,dt,it,entity,geoElt,_names->getPointer())!=0) - _names=0; - else - _names->reAlloc(curNbOfElem);//not a bug to avoid the memory corruption due to last \0 at the end - } - } -} - -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) +void MEDFileUMeshPerType::loadPartOfCellCommonPart(med_idt fid, const char *mName, mcIdType strt, mcIdType stp, mcIdType step, int dt, int it, int mdim, mcIdType curNbOfElem, med_geometry_type geoElt, med_entity_type entity, MEDFileMeshReadSelector *mrs) { med_bool changement,transformation; _fam=0; - int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(strt,stp,step,"MEDFileUMeshPerType::loadPartOfCellCommonPart")); + mcIdType nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(strt,stp,step,"MEDFileUMeshPerType::loadPartOfCellCommonPart")); if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) { if(!mrs || mrs->isCellFamilyFieldReading()) { - _fam=DataArrayInt::New(); - _fam->alloc(nbOfEltsToLoad,1); + MCAuto miFam(DataArrayMedInt::New()); + miFam->alloc(nbOfEltsToLoad,1); med_filter filter=MED_FILTER_INIT; - MEDfilterBlockOfEntityCr(fid,/*nentity*/curNbOfElem,/*nvaluesperentity*/1,/*nconstituentpervalue*/1, + MEDfilterBlockOfEntityCr(fid,/*nentity*/ToMedInt(curNbOfElem),/*nvaluesperentity*/1,/*nconstituentpervalue*/1, MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE, - /*start*/strt+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad, + /*start*/ToMedInt(strt+1),/*stride*/ToMedInt(step),/*count*/1,/*blocksize*/ToMedInt(nbOfEltsToLoad), /*lastblocksize=useless because count=1*/0,&filter); - if(MEDmeshEntityAttributeAdvancedRd(fid,mName,MED_FAMILY_NUMBER,dt,it,entity,geoElt,&filter,_fam->getPointer())!=0) - _fam->fillWithZero(); + if(MEDmeshEntityAttributeAdvancedRd(fid,mName,MED_FAMILY_NUMBER,dt,it,entity,geoElt,&filter,miFam->getPointer())!=0) + miFam->fillWithZero(); + _fam=FromMedIntArray(miFam); MEDfilterClose(&filter); } } @@ -240,15 +261,16 @@ void MEDFileUMeshPerType::loadPartOfCellCommonPart(med_idt fid, const char *mNam { if(!mrs || mrs->isCellNumFieldReading()) { - _num=DataArrayInt::New(); - _num->alloc(nbOfEltsToLoad,1); + MCAuto miNum(DataArrayMedInt::New()); + miNum->alloc(nbOfEltsToLoad,1); med_filter filter=MED_FILTER_INIT; - MEDfilterBlockOfEntityCr(fid,/*nentity*/curNbOfElem,/*nvaluesperentity*/1,/*nconstituentpervalue*/1, + MEDfilterBlockOfEntityCr(fid,/*nentity*/ToMedInt(curNbOfElem),/*nvaluesperentity*/1,/*nconstituentpervalue*/1, MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE, - /*start*/strt+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad, + /*start*/ToMedInt(strt+1),/*stride*/ToMedInt(step),/*count*/1,/*blocksize*/ToMedInt(nbOfEltsToLoad), /*lastblocksize=useless because count=1*/0,&filter); - if(MEDmeshEntityAttributeAdvancedRd(fid,mName,MED_NUMBER,dt,it,entity,geoElt,&filter,_num->getPointer())!=0) - _num->fillWithZero(); + if(MEDmeshEntityAttributeAdvancedRd(fid,mName,MED_NUMBER,dt,it,entity,geoElt,&filter,miNum->getPointer())!=0) + miNum->fillWithZero(); + _num=FromMedIntArray(miNum); MEDfilterClose(&filter); } } @@ -260,9 +282,9 @@ void MEDFileUMeshPerType::loadPartOfCellCommonPart(med_idt fid, const char *mNam _names=DataArrayAsciiChar::New(); _names->alloc(nbOfEltsToLoad+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end med_filter filter=MED_FILTER_INIT; - MEDfilterBlockOfEntityCr(fid,/*nentity*/curNbOfElem,/*nvaluesperentity*/1,/*nconstituentpervalue*/1, + MEDfilterBlockOfEntityCr(fid,/*nentity*/ToMedInt(curNbOfElem),/*nvaluesperentity*/1,/*nconstituentpervalue*/1, MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE, - /*start*/strt+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad, + /*start*/ToMedInt(strt+1),/*stride*/ToMedInt(step),/*count*/1,/*blocksize*/ToMedInt(nbOfEltsToLoad), /*lastblocksize=useless because count=1*/0,&filter); if(MEDmeshEntityAttributeAdvancedRd(fid,mName,MED_NAME,dt,it,entity,geoElt,&filter,_names->getPointer())!=0) _names=0; @@ -273,61 +295,61 @@ void MEDFileUMeshPerType::loadPartOfCellCommonPart(med_idt fid, const char *mNam } } -void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int dt, int it, int mdim, int arraySize, med_geometry_type geoElt, +void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int dt, int it, int mdim, mcIdType arraySize, med_geometry_type geoElt, med_entity_type entity, MEDFileMeshReadSelector *mrs) { med_bool changement,transformation; - med_int curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1); + mcIdType curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1); _m=MEDCoupling1DGTUMesh::New(mName,geoElt==MED_POLYGON?INTERP_KERNEL::NORM_POLYGON:INTERP_KERNEL::NORM_QPOLYG); MCAuto mc(DynamicCast(_m)); - MCAuto conn(DataArrayInt::New()),connI(DataArrayInt::New()); + MCAuto conn(DataArrayMedInt::New()),connI(DataArrayMedInt::New()); conn->alloc(arraySize,1); connI->alloc(curNbOfElem+1,1); MEDFILESAFECALLERRD0(MEDmeshPolygon2Rd,(fid,mName,dt,it,MED_CELL,geoElt,MED_NODAL,connI->getPointer(),conn->getPointer())); - std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind2nd(std::plus(),-1)); - std::transform(connI->begin(),connI->end(),connI->getPointer(),std::bind2nd(std::plus(),-1)); - mc->setNodalConnectivity(conn,connI); - loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity,mrs); + std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind(std::plus(),std::placeholders::_1,-1)); + std::transform(connI->begin(),connI->end(),connI->getPointer(),std::bind(std::plus(),std::placeholders::_1,-1)); + mc->setNodalConnectivity(FromMedIntArray(conn),FromMedIntArray(connI)); + loadCommonPart(fid,mName,dt,it,curNbOfElem,geoElt,entity,mrs); } -void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, int connFaceLgth, med_geometry_type geoElt, +void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, mcIdType connFaceLgth, med_geometry_type geoElt, med_entity_type entity, MEDFileMeshReadSelector *mrs) { med_bool changement,transformation; med_int indexFaceLgth(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)); - int curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1); + mcIdType curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1); _m=MEDCoupling1DGTUMesh::New(mName,INTERP_KERNEL::NORM_POLYHED); MCAuto mc(DynamicCastSafe(_m)); - INTERP_KERNEL::AutoPtr index=new int[curNbOfElem+1]; - INTERP_KERNEL::AutoPtr indexFace=new int[indexFaceLgth]; - INTERP_KERNEL::AutoPtr locConn=new int[connFaceLgth]; + INTERP_KERNEL::AutoPtr index=new med_int[curNbOfElem+1]; + INTERP_KERNEL::AutoPtr indexFace=new med_int[indexFaceLgth]; + INTERP_KERNEL::AutoPtr locConn=new med_int[connFaceLgth]; MEDFILESAFECALLERRD0(MEDmeshPolyhedronRd,(fid,mName,dt,it,MED_CELL,MED_NODAL,index,indexFace,locConn)); - MCAuto conn(DataArrayInt::New()),connI(DataArrayInt::New()); - int arraySize=connFaceLgth; - for(int i=0;i conn(DataArrayIdType::New()),connI(DataArrayIdType::New()); + mcIdType arraySize=connFaceLgth; + for(mcIdType i=0;ialloc(arraySize,1); - int *wFinalConn=conn->getPointer(); + mcIdType *wFinalConn=conn->getPointer(); connI->alloc(curNbOfElem+1,1); - int *finalIndex(connI->getPointer()); + mcIdType *finalIndex(connI->getPointer()); finalIndex[0]=0; - for(int i=0;i(),-1)); - for(int j=index[i];j(),std::placeholders::_1,-1)); + for(mcIdType j=index[i];j(),-1)); + wFinalConn=std::transform(locConn+indexFace[j]-1,locConn+indexFace[j+1]-1,wFinalConn,std::bind(std::plus(),std::placeholders::_1,-1)); } } mc->setNodalConnectivity(conn,connI); - loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,MED_POLYHEDRON,entity,mrs); + loadCommonPart(fid,mName,dt,it,curNbOfElem,MED_POLYHEDRON,entity,mrs); } -void MEDFileUMeshPerType::Write(med_idt fid, const std::string& mname, int mdim, const MEDCoupling1GTUMesh *m, const DataArrayInt *fam, const DataArrayInt *num, const DataArrayAsciiChar *names) +void MEDFileUMeshPerType::Write(med_idt fid, const std::string& mname, int mdim, const MEDCoupling1GTUMesh *m, const DataArrayIdType *fam, const DataArrayIdType *num, const DataArrayAsciiChar *names) { - int nbOfCells=m->getNumberOfCells(); + mcIdType nbOfCells=m->getNumberOfCells(); if(nbOfCells<1) return ; int dt,it; @@ -340,9 +362,9 @@ void MEDFileUMeshPerType::Write(med_idt fid, const std::string& mname, int mdim, const MEDCoupling1SGTUMesh *m0(dynamic_cast(m)); if(!m0) throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::Write : internal error #1 !"); - MCAuto arr(m0->getNodalConnectivity()->deepCopy()); - std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind2nd(std::plus(),1)); - MEDFILESAFECALLERWR0(MEDmeshElementConnectivityWr,(fid,mname.c_str(),dt,it,timm,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,nbOfCells,arr->begin())); + MCAuto arr(DataArrayMedInt_Copy(m0->getNodalConnectivity())); + std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind(std::plus(),std::placeholders::_1,1)); + MEDFILESAFECALLERWR0(MEDmeshElementConnectivityWr,(fid,mname.c_str(),dt,it,timm,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,ToMedInt(nbOfCells),arr->begin())); } else { @@ -351,31 +373,31 @@ void MEDFileUMeshPerType::Write(med_idt fid, const std::string& mname, int mdim, throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::Write : internal error #2 !"); if(ikt==INTERP_KERNEL::NORM_POLYGON || ikt==INTERP_KERNEL::NORM_QPOLYG) { - MCAuto arr(m0->getNodalConnectivity()->deepCopy()),arrI(m0->getNodalConnectivityIndex()->deepCopy()); - std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind2nd(std::plus(),1)); - std::transform(arrI->begin(),arrI->end(),arrI->getPointer(),std::bind2nd(std::plus(),1)); - 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())); + MCAuto arr(DataArrayMedInt_Copy(m0->getNodalConnectivity())),arrI(DataArrayMedInt_Copy(m0->getNodalConnectivityIndex())); + std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind(std::plus(),std::placeholders::_1,1)); + std::transform(arrI->begin(),arrI->end(),arrI->getPointer(),std::bind(std::plus(),std::placeholders::_1,1)); + 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())); } else { - const int *conn(m0->getNodalConnectivity()->begin()),*connI(m0->getNodalConnectivityIndex()->begin()); - int meshLgth=m0->getNodalConnectivityLength(); - int nbOfFaces=std::count(conn,conn+meshLgth,-1)+nbOfCells; - INTERP_KERNEL::AutoPtr tab1=new int[nbOfCells+1]; - int *w1=tab1; *w1=1; - INTERP_KERNEL::AutoPtr tab2=new int[nbOfFaces+1]; - int *w2=tab2; *w2=1; - INTERP_KERNEL::AutoPtr bigtab=new int[meshLgth]; - int *bt=bigtab; - for(int i=0;igetNodalConnectivity()->begin()),*connI(m0->getNodalConnectivityIndex()->begin()); + mcIdType meshLgth=m0->getNodalConnectivityLength(); + mcIdType nbOfFaces=ToIdType(std::count(conn,conn+meshLgth,-1)+nbOfCells); + INTERP_KERNEL::AutoPtr tab1=new med_int[nbOfCells+1]; + med_int *w1=tab1; *w1=1; + INTERP_KERNEL::AutoPtr tab2=new med_int[nbOfFaces+1]; + med_int *w2=tab2; *w2=1; + INTERP_KERNEL::AutoPtr bigtab=new med_int[meshLgth]; + med_int *bt=bigtab; + for(mcIdType i=0;i(),1)); - int nbOfNode=std::distance(w,wend); - w2[1]=w2[0]+nbOfNode; + const mcIdType *wend=std::find(w,conn+connI[i+1],-1); + bt=std::transform(w,wend,bt,std::bind(std::plus(),std::placeholders::_1,1)); + std::size_t nbOfNode=std::distance(w,wend); + w2[1]=w2[0]+(med_int)nbOfNode; if(wend!=conn+connI[i+1]) w=wend+1; else @@ -384,13 +406,13 @@ void MEDFileUMeshPerType::Write(med_idt fid, const std::string& mname, int mdim, } w1[1]=w1[0]+nbOfFaces2; } - MEDFILESAFECALLERWR0(MEDmeshPolyhedronWr,(fid,mname.c_str(),dt,it,timm,MED_CELL,MED_NODAL,nbOfCells+1,tab1,nbOfFaces+1,tab2,bigtab)); + MEDFILESAFECALLERWR0(MEDmeshPolyhedronWr,(fid,mname.c_str(),dt,it,timm,MED_CELL,MED_NODAL,ToMedInt(nbOfCells+1),tab1,ToMedInt(nbOfFaces+1),tab2,bigtab)); } } if(fam) - MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_CELL,curMedType,nbOfCells,fam->getConstPointer())); + MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_CELL,curMedType,ToMedInt(nbOfCells),ToMedIntArray(fam)->getConstPointer())); if(num) - MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_CELL,curMedType,nbOfCells,num->getConstPointer())); + MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_CELL,curMedType,ToMedInt(nbOfCells),ToMedIntArray(num)->getConstPointer())); if(names) { if(names->getNumberOfComponents()!=MED_SNAME_SIZE) @@ -399,6 +421,6 @@ void MEDFileUMeshPerType::Write(med_idt fid, const std::string& mname, int mdim, oss << " ! The array has " << names->getNumberOfComponents() << " components !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_CELL,curMedType,nbOfCells,names->getConstPointer())); + MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_CELL,curMedType,ToMedInt(nbOfCells),names->getConstPointer())); } }