From: Anthony Geay Date: Fri, 20 Jan 2017 09:52:44 +0000 (+0100) Subject: Refacto step 2 of MEDFileField classes X-Git-Tag: V8_3_0a2~38^2~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=05c7d7249901246b526bb3579f2c022d4de2a748;p=tools%2Fmedcoupling.git Refacto step 2 of MEDFileField classes --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index c00af683c..296c87f17 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -662,6 +662,11 @@ TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const return _type; } +INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const +{ + return _father->getGeoType(); +} + void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set& types) const { types.insert(_type); @@ -672,11 +677,6 @@ void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType) _type=newType; } -INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const -{ - return _father->getGeoType(); -} - int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const { return _father->getNumberOfComponents(); @@ -1049,6 +1049,10 @@ MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectO //////////////////////////////////// +MEDFileFieldPerMeshPerTypeCommon::~MEDFileFieldPerMeshPerTypeCommon() + { + } + void MEDFileFieldPerMeshPerTypeCommon::setFather(MEDFileFieldPerMesh *father) { _father=father; @@ -1266,16 +1270,9 @@ const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerTypeCommon::getFather() const return _father; } -void MEDFileFieldPerMeshPerTypeCommon::getDimension(int& dim) const -{ - const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type)); - int curDim((int)cm.getDimension()); - dim=std::max(dim,curDim); -} - bool MEDFileFieldPerMeshPerTypeCommon::isUniqueLevel(int& dim) const { - const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type)); + const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType())); int curDim((int)cm.getDimension()); if(dim!=std::numeric_limits::max()) { @@ -1325,33 +1322,6 @@ std::string MEDFileFieldPerMeshPerTypeCommon::getMeshName() const return _father->getMeshName(); } -void MEDFileFieldPerMeshPerTypeCommon::simpleRepr(int bkOffset, std::ostream& oss, int id) const -{ - const char startLine[]=" ## "; - std::string startLine2(bkOffset,' '); - std::string startLine3(startLine2); - startLine3+=startLine; - if(_geo_type!=INTERP_KERNEL::NORM_ERROR) - { - const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); - oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl; - } - else - oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl; - oss << startLine3 << "Entry is defined on " << _field_pm_pt_pd.size() << " localizations." << std::endl; - int i=0; - for(std::vector< MCAuto >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++) - { - const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it); - if(cur) - cur->simpleRepr(bkOffset,oss,i); - else - { - oss << startLine2 << " ## " << "Localization #" << i << " is empty !" << std::endl; - } - } -} - void MEDFileFieldPerMeshPerTypeCommon::getSizes(int& globalSz, int& nbOfEntries) const { for(std::vector< MCAuto >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++) @@ -1361,12 +1331,6 @@ void MEDFileFieldPerMeshPerTypeCommon::getSizes(int& globalSz, int& nbOfEntries) nbOfEntries+=(int)_field_pm_pt_pd.size(); } -INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeCommon::getGeoType() const -{ - return _geo_type; -} - - int MEDFileFieldPerMeshPerTypeCommon::getNumberOfComponents() const { return _father->getNumberOfComponents(); @@ -1475,15 +1439,13 @@ MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGive { if(_field_pm_pt_pd.empty()) { - const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); - std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !"; + std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !"; throw INTERP_KERNEL::Exception(oss.str()); } if(locId>=0 && locId<(int)_field_pm_pt_pd.size()) return _field_pm_pt_pd[locId]; - const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId; - oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !"; + oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !"; throw INTERP_KERNEL::Exception(oss2.str().c_str()); return static_cast(0); } @@ -1492,31 +1454,17 @@ const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLe { if(_field_pm_pt_pd.empty()) { - const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); - std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !"; + std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !"; throw INTERP_KERNEL::Exception(oss.str()); } if(locId>=0 && locId<(int)_field_pm_pt_pd.size()) return _field_pm_pt_pd[locId]; - const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId; - oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !"; + oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !"; throw INTERP_KERNEL::Exception(oss2.str().c_str()); return static_cast(0); } -void MEDFileFieldPerMeshPerTypeCommon::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair >& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const -{ - if(_geo_type!=INTERP_KERNEL::NORM_ERROR) - { - const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); - if(meshDim!=(int)cm.getDimension()) - return ; - } - for(std::vector< MCAuto >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++) - (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes); -} - void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair,std::pair > >& entries) const { int i=0; @@ -1576,26 +1524,6 @@ bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t i return true; } -MEDFileFieldPerMeshPerTypeCommon::MEDFileFieldPerMeshPerTypeCommon(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):_father(fath),_geo_type(geoType) -{ - INTERP_KERNEL::AutoPtr 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 >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++) @@ -1659,6 +1587,87 @@ MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPer return ret.retn(); } +void MEDFileFieldPerMeshPerType::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair >& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const +{ + if(_geo_type!=INTERP_KERNEL::NORM_ERROR) + { + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); + if(meshDim!=(int)cm.getDimension()) + return ; + } + for(std::vector< MCAuto >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++) + (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes); +} + +INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const +{ + return _geo_type; +} + +void MEDFileFieldPerMeshPerType::getDimension(int& dim) const +{ + const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type)); + int curDim((int)cm.getDimension()); + dim=std::max(dim,curDim); +} + +void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const +{ + const char startLine[]=" ## "; + std::string startLine2(bkOffset,' '); + std::string startLine3(startLine2); + startLine3+=startLine; + if(_geo_type!=INTERP_KERNEL::NORM_ERROR) + { + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); + oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl; + } + else + oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl; + oss << startLine3 << "Entry is defined on " << _field_pm_pt_pd.size() << " localizations." << std::endl; + int i=0; + for(std::vector< MCAuto >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++) + { + const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it); + if(cur) + cur->simpleRepr(bkOffset,oss,i); + else + { + oss << startLine2 << " ## " << "Localization #" << i << " is empty !" << std::endl; + } + } +} + +std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const +{ + const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type)); + return std::string(cm.getRepr()); +} + +MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt) +{ +} + +MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType) +{ + INTERP_KERNEL::AutoPtr 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 MEDFileFieldPerMeshPerTypePerDisc::Agg MCAuto MEDFileFieldPerMeshPerTypeCommon::Aggregate(int &start, const std::vector >& pms, const std::vector< std::vector< std::pair > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector > >& extractInfo) { - MCAuto ret(new MEDFileFieldPerMeshPerType(father,gt)); + MCAuto ret(MEDFileFieldPerMeshPerType::New(father,gt)); std::map > > m; for(std::vector >::const_iterator it=pms.begin();it!=pms.end();it++) { diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 4ccfc6ca3..f3dffd08b 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -196,7 +196,6 @@ namespace MEDCoupling void loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc); void loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc); void writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const; - void getDimension(int& dim) const; bool isUniqueLevel(int& dim) const; void fillTypesOfFieldAvailable(std::set& types) const; void fillFieldSplitedByType(std::vector< std::pair >& dads, std::vector& types, std::vector& pfls, std::vector& locs) const; @@ -204,9 +203,7 @@ namespace MEDCoupling int getOrder() const; double getTime() const; std::string getMeshName() const; - void simpleRepr(int bkOffset, std::ostream& oss, int id) const; void getSizes(int& globalSz, int& nbOfEntries) const; - INTERP_KERNEL::NormalizedCellType getGeoType() const; int getNumberOfComponents() const; bool presenceOfMultiDiscPerGeoType() const; DataArray *getOrCreateAndGetArray(); @@ -221,14 +218,20 @@ namespace MEDCoupling MEDFileFieldPerMeshPerTypePerDisc *getLeafGivenLocId(int locId); const MEDFileFieldPerMeshPerTypePerDisc *getLeafGivenLocId(int locId) const; int getNumberOfLoc() const { return _field_pm_pt_pd.size(); } - void getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair >& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) 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; void fillValues(int& startEntryId, std::vector< std::pair,std::pair > >& entries) const; void setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves); bool keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair >& its); bool keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair >& its); static med_entity_type ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType); 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); - MEDFileFieldPerMeshPerTypeCommon(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):_father(father),_geo_type(gt) { } + MEDFileFieldPerMeshPerTypeCommon(MEDFileFieldPerMesh *father):_father(father) { } + public: + virtual ~MEDFileFieldPerMeshPerTypeCommon(); + virtual void getDimension(int& dim) const = 0; + virtual INTERP_KERNEL::NormalizedCellType getGeoType() const = 0; + virtual void simpleRepr(int bkOffset, std::ostream& oss, int id) const = 0; + virtual std::string getGeoTypeRepr() const = 0; protected: void setFather(MEDFileFieldPerMesh *father); void deepCopyElements(); @@ -236,11 +239,10 @@ namespace MEDCoupling std::vector addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells); std::vector addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells); std::vector addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells); - MEDFileFieldPerMeshPerTypeCommon(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd); private: MEDFileFieldPerMesh *_father; + protected: std::vector< MCAuto > _field_pm_pt_pd; - INTERP_KERNEL::NormalizedCellType _geo_type; }; class MEDFileFieldPerMeshPerType : public MEDFileFieldPerMeshPerTypeCommon @@ -248,10 +250,18 @@ 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); - MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father,gt) { } 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; + public: + void getDimension(int& dim) const; + INTERP_KERNEL::NormalizedCellType getGeoType() const; + void simpleRepr(int bkOffset, std::ostream& oss, int id) const; + std::string getGeoTypeRepr() const; + private: + MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd); + MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt); private: - MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fid,fath,type,geoType,nasc,pd) { } + INTERP_KERNEL::NormalizedCellType _geo_type; }; class MEDFileMesh;