From: Anthony Geay Date: Thu, 11 Oct 2018 13:32:16 +0000 (+0200) Subject: Reduce number of MEDfieldnProfile invokations X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b1b0c3512662548fc87935f99d373dfa65413575;p=tools%2Fmedcoupling.git Reduce number of MEDfieldnProfile invokations --- diff --git a/src/MEDLoader/MEDFileEntities.cxx b/src/MEDLoader/MEDFileEntities.cxx index 79190c99c..ec3348a62 100644 --- a/src/MEDLoader/MEDFileEntities.cxx +++ b/src/MEDLoader/MEDFileEntities.cxx @@ -22,6 +22,14 @@ using namespace MEDCoupling; +MEDFileStaticEntities::MEDFileStaticEntities(const std::vector< std::pair >& entities) +{ + std::size_t sz(entities.size()); + _entities.resize(sz); + for(std::size_t i=0;i > *entities) { if(!entities) diff --git a/src/MEDLoader/MEDFileEntities.hxx b/src/MEDLoader/MEDFileEntities.hxx index 2558bc45e..ea49f1003 100644 --- a/src/MEDLoader/MEDFileEntities.hxx +++ b/src/MEDLoader/MEDFileEntities.hxx @@ -43,12 +43,13 @@ namespace MEDCoupling class MEDLOADER_EXPORT MEDFileStaticEntities : public MEDFileEntities { public: - MEDFileStaticEntities(const std::vector< std::pair >& entities):_entities(entities) { } - const std::vector< std::pair >& getEntries() const { return _entities; } + MEDFileStaticEntities(const std::vector< std::pair >& entities):_entities(entities) { } + MEDFileStaticEntities(const std::vector< std::pair >& entities); + const std::vector< std::pair >& getEntries() const { return _entities; } std::vector getDynGTAvail() const; bool areAllStaticTypesPresent() const; private: - std::vector< std::pair > _entities; + std::vector< std::pair > _entities; }; class MEDLOADER_EXPORT MEDFileAllStaticEntites : public MEDFileEntities diff --git a/src/MEDLoader/MEDFileFieldInternal.cxx b/src/MEDLoader/MEDFileFieldInternal.cxx index abcccc792..d7c33b2cf 100644 --- a/src/MEDLoader/MEDFileFieldInternal.cxx +++ b/src/MEDLoader/MEDFileFieldInternal.cxx @@ -1728,9 +1728,9 @@ med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfF ////////////////////////////////////////////////// -MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd) +MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const std::vector< std::pair >& nbProfiles , const MEDFileFieldNameScope& nasc, const PartDefinition *pd) { - return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd); + return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nbProfiles,nasc,pd); } MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) @@ -1812,13 +1812,21 @@ MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath { } -MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType) +MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const std::vector< std::pair >& nbProfiles, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType) { - INTERP_KERNEL::AutoPtr pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + _field_pm_pt_pd.resize(std::accumulate(nbProfiles.begin(),nbProfiles.end(),0,[](int p1, const std::pair& p2) { return p1+p2.first; })); + std::size_t i(0); + for(auto it : nbProfiles) + { + for(int j=0;j pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); INTERP_KERNEL::AutoPtr locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); med_geometry_type mgeoti; med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti)); - int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName)); _field_pm_pt_pd.resize(nbProfiles); for(int i=0;i MEDFileFieldPerMeshPerType::Aggregate(int &start, const std::vector >& pms, const std::vector< std::vector< std::pair > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector > >& extractInfo) @@ -3029,7 +3037,7 @@ public: virtual bool finished() const = 0; virtual void next() = 0; virtual int current() const = 0; - virtual med_entity_type currentET() const = 0; + virtual std::vector currentET() const = 0; }; class MFFPMIterSimple : public MFFPMIter @@ -3037,10 +3045,10 @@ class MFFPMIterSimple : public MFFPMIter public: MFFPMIterSimple():_pos(0) { } void begin() { _pos=0; } - bool finished() const { return _pos/2>=MED_N_CELL_FIXED_GEO; } + bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; } void next() { _pos++; } - int current() const { return _pos/2; } - med_entity_type currentET() const { return _pos%2==0?MED_CELL:MED_NODE_ELEMENT; } + int current() const { return _pos; } + std::vector currentET() const { return {MED_CELL,MED_NODE_ELEMENT}; } private: int _pos; }; @@ -3050,10 +3058,10 @@ class MFFPMIterSimpleLegacy : public MFFPMIter public: MFFPMIterSimpleLegacy():_pos(0) { } void begin() { _pos=0; } - bool finished() const { return _pos/2>=MED_N_CELL_FIXED_GEO; } + bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; } void next() { _pos++; } - int current() const { return _pos/2; } - med_entity_type currentET() const { return _pos%2==0?MED_DESCENDING_FACE:MED_DESCENDING_EDGE; } + int current() const { return _pos; } + std::vector currentET() const { return {MED_DESCENDING_FACE,MED_DESCENDING_EDGE}; } private: int _pos; }; @@ -3061,13 +3069,15 @@ private: class MFFPMIter2 : public MFFPMIter { public: - MFFPMIter2(const std::vector& cts, const std::vector& entityType); + MFFPMIter2(const std::vector& cts, const std::vector& entityType, bool presenceOfNodes); void begin() { _it=_ids.begin(); } bool finished() const { return _it==_ids.end(); } void next() { _it++; } int current() const { return *_it; } - med_entity_type currentET() const { return _entityType[std::distance(_ids.begin(),_it)]; } + std::vector currentET() const { return {_entityType[std::distance(_ids.begin(),_it)]}; } + bool presenceOfNodes() const { return _presenceOfNodes; } private: + bool _presenceOfNodes; std::vector _ids; std::vector::const_iterator _it; std::vector _entityType; @@ -3085,14 +3095,17 @@ MFFPMIter *NewCellImpl(const MEDFileEntities *entities) { std::vector tmp; std::vector tmp2; - const std::vector< std::pair >& myEnt(entities2->getEntries()); - for(std::vector< std::pair >::const_iterator it=myEnt.begin();it!=myEnt.end();it++) - { - if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT) + const std::vector< std::pair >& myEnt(entities2->getEntries()); + bool presenceOfNodes(false); + for(std::vector< std::pair >::const_iterator it=myEnt.begin();it!=myEnt.end();it++) + if((*it).first!=MED_NODE) + { tmp.push_back((*it).second); - tmp2.push_back((*it).first==ON_CELLS || (*it).first==ON_GAUSS_PT?MED_CELL:MED_NODE_ELEMENT); - } - return new MFFPMIter2(tmp,tmp2); + tmp2.push_back((*it).first); + } + else + presenceOfNodes=true; + return new MFFPMIter2(tmp,tmp2,presenceOfNodes); } return new TSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in } @@ -3117,9 +3130,9 @@ bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities) const MEDFileStaticEntities *entities2(dynamic_cast(entities)); if(entities2) { - const std::vector< std::pair >& myEnt(entities2->getEntries()); - for(std::vector< std::pair >::const_iterator it=myEnt.begin();it!=myEnt.end();it++) - if((*it).first==ON_NODES) + const std::vector< std::pair >& myEnt(entities2->getEntries()); + for(std::vector< std::pair >::const_iterator it=myEnt.begin();it!=myEnt.end();it++) + if((*it).first==MED_NODE) return true; return false; } @@ -3127,7 +3140,7 @@ bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities) } } -MFFPMIter2::MFFPMIter2(const std::vector& cts, const std::vector& entityType):_entityType(entityType) +MFFPMIter2::MFFPMIter2(const std::vector& cts, const std::vector& entityType, bool presenceOfNodes):_presenceOfNodes(presenceOfNodes),_entityType(entityType) { std::size_t sz(cts.size()); _ids.resize(sz); @@ -3152,13 +3165,19 @@ MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWith INTERP_KERNEL::AutoCppPtr iter0(MFFPMIter::NewCell(entities)); for(iter0->begin();!iter0->finished();iter0->next()) { - int nbProfile (MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),iter0->currentET(),typmai[iter0->current()],pflName,locName)); - if(nbProfile>0) + std::vector< std::pair > nbProfiles; + for(auto entity : iter0->currentET()) + { + int nbProfile(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),entity,typmai[iter0->current()],pflName,locName)); + if(nbProfile>0) + nbProfiles.push_back(std::pair(nbProfile,entity)); + } + if(!nbProfiles.empty()) { const PartDefinition *pd(0); if(mmu) pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]); - _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd)); + _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nbProfiles,nasc,pd)); setMeshName(meshName); } } @@ -3170,7 +3189,7 @@ MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWith const PartDefinition *pd(0); if(mmu) pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR); - _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd)); + _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,{{nbProfile,MED_NODE}},nasc,pd)); setMeshName(meshName); } } @@ -3192,10 +3211,16 @@ MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWith iter0=MFFPMIter::NewCellLegacy(entities); for(iter0->begin();!iter0->finished();iter0->next()) { - int nbProfile(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),iter0->currentET(),typmai[iter0->current()],pflName,locName)); - if(nbProfile>0) + std::vector< std::pair > nbProfiles; + for(auto entity : iter0->currentET()) + { + int nbProfile(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),entity,typmai[iter0->current()],pflName,locName)); + if(nbProfile>0) + nbProfiles.push_back(std::pair(nbProfile,entity)); + } + if(!nbProfiles.empty()) { - _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,NULL)); + _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nbProfiles,nasc,nullptr)); setMeshName(meshName); } } diff --git a/src/MEDLoader/MEDFileFieldInternal.hxx b/src/MEDLoader/MEDFileFieldInternal.hxx index a1f179f9b..8bf6f9ad2 100644 --- a/src/MEDLoader/MEDFileFieldInternal.hxx +++ b/src/MEDLoader/MEDFileFieldInternal.hxx @@ -287,7 +287,7 @@ namespace MEDCoupling { public: static MEDFileFieldPerMeshPerType *New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType); - static MEDFileFieldPerMeshPerType *NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd); + static MEDFileFieldPerMeshPerType *NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const std::vector< std::pair >& nbProfiles, const MEDFileFieldNameScope& nasc, const PartDefinition *pd); static MCAuto Aggregate(int &start, const std::vector< std::pair >& pms, const std::vector< std::vector< std::pair > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector > >& extractInfo); public:// overload of abstract methods void getDimension(int& dim) const; @@ -298,7 +298,7 @@ namespace MEDCoupling MEDFileFieldPerMeshPerType *deepCopy(MEDFileFieldPerMesh *father) const; void getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair >& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const; private: - MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd); + MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const std::vector< std::pair >& nbProfiles, const MEDFileFieldNameScope& nasc, const PartDefinition *pd); MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt); private: INTERP_KERNEL::NormalizedCellType _geo_type; diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 48464da2d..8fba22484 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -7581,12 +7581,37 @@ TypeOfField MEDFileMesh::ConvertFromMEDFileEntity(med_entity_type etype) return ON_NODES; case MED_CELL: return ON_CELLS; + case MED_NODE_ELEMENT: + return ON_GAUSS_NE; + case MED_DESCENDING_FACE: + return ON_CELLS; + case MED_DESCENDING_EDGE: + return ON_CELLS; default: { - std::ostringstream oss; oss << "EDFileMesh::ConvertFromMEDFileEntity : not recognized entity " << etype << " !"; + std::ostringstream oss; oss << "MEDFileMesh::ConvertFromMEDFileEntity : not recognized entity " << etype << " !"; throw INTERP_KERNEL::Exception(oss.str()); } } } +med_entity_type MEDFileMesh::ConvertToMEDFileEntity(TypeOfField etype) +{ + switch(etype) + { + case ON_NODES: + return MED_NODE; + case ON_CELLS: + return MED_CELL; + case ON_GAUSS_NE: + return MED_NODE_ELEMENT; + case ON_GAUSS_PT: + return MED_CELL; + default: + { + std::ostringstream oss; oss << "MEDFileMesh::ConvertToMEDFileEntity : not recognized entity " << etype << " !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + } +} diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 9b1efb29d..1bc0ba310 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -202,6 +202,7 @@ namespace MEDCoupling void initializeEquivalences() { _equiv=MEDFileEquivalences::New(this); } static INTERP_KERNEL::NormalizedCellType ConvertFromMEDFileGeoType(med_geometry_type geoType); static TypeOfField ConvertFromMEDFileEntity(med_entity_type etype); + static med_entity_type ConvertToMEDFileEntity(TypeOfField etype); protected: MEDFileMesh(); //! protected because no way in MED file API to specify this name