From 4074002279f1ca79b31bcd1465f19a19a98f73ac Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 19 Jan 2017 09:28:39 +0100 Subject: [PATCH] Stucture element have been read --- src/MEDCoupling/MEDCouplingMemArray.hxx | 2 + src/MEDLoader/MEDFileMesh.cxx | 22 ++- src/MEDLoader/MEDFileMesh.hxx | 3 +- src/MEDLoader/MEDFileStructureElement.cxx | 191 +++++++++++++++++++++- src/MEDLoader/MEDFileStructureElement.hxx | 55 ++++++- 5 files changed, 266 insertions(+), 7 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index ee2e6fcf9..cb80c8058 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -148,6 +148,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void setInfoOnComponent(int i, const std::string& info); MEDCOUPLING_EXPORT std::size_t getNumberOfComponents() const { return _info_on_compo.size(); } MEDCOUPLING_EXPORT void setPartOfValuesBase3(const DataArray *aBase, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true); + MEDCOUPLING_EXPORT virtual void *getVoidStarPointer() = 0; MEDCOUPLING_EXPORT virtual DataArray *deepCopy() const = 0; MEDCOUPLING_EXPORT virtual DataArray *buildNewEmptyInstance() const = 0; MEDCOUPLING_EXPORT virtual bool isAllocated() const = 0; @@ -215,6 +216,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); } MEDCOUPLING_EXPORT std::size_t getNbOfElems() const { return _mem.getNbOfElem(); } bool empty() const; + MEDCOUPLING_EXPORT void *getVoidStarPointer() { return getPointer(); } MEDCOUPLING_EXPORT const T *getConstPointer() const { return _mem.getConstPointer(); } MEDCOUPLING_EXPORT const T *begin() const { return getConstPointer(); } MEDCOUPLING_EXPORT const T *end() const { return getConstPointer()+getNbOfElems(); } diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 24b61d534..2e0cfc6cd 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -7400,13 +7400,31 @@ MEDFileMesh *MEDFileMeshesIterator::nextt() return 0; } -INTERP_KERNEL::NormalizedCellType MEDFileMesh::ConvertFromMEDFile(med_geometry_type geoType) +INTERP_KERNEL::NormalizedCellType MEDFileMesh::ConvertFromMEDFileGeoType(med_geometry_type geoType) { med_geometry_type *pos(std::find(typmai,typmai+MED_N_CELL_FIXED_GEO,geoType)); if(pos==typmai+MED_N_CELL_FIXED_GEO) { - std::ostringstream oss; oss << "MEDFileMesh::ConvertFromMEDFile : no entry with " << geoType << " !"; + if(geoType==MED_NO_GEOTYPE) + return INTERP_KERNEL::NORM_ERROR; + std::ostringstream oss; oss << "MEDFileMesh::ConvertFromMEDFileGeoType : no entry with " << geoType << " !"; throw INTERP_KERNEL::Exception(oss.str()); } return typmai2[std::distance(typmai,pos)]; } + +TypeOfField MEDFileMesh::ConvertFromMEDFileEntity(med_entity_type etype) +{ + switch(etype) + { + case MED_NODE: + return ON_NODES; + case MED_CELL: + return ON_CELLS; + default: + { + std::ostringstream oss; oss << "EDFileMesh::ConvertFromMEDFileEntity : not recognized entity " << etype << " !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + } +} diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 88c859a3b..18500d82c 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -195,7 +195,8 @@ namespace MEDCoupling const MEDFileEquivalences *getEquivalences() const { return _equiv; } void killEquivalences() { _equiv=(MEDFileEquivalences *)0; } void initializeEquivalences() { _equiv=MEDFileEquivalences::New(this); } - static INTERP_KERNEL::NormalizedCellType ConvertFromMEDFile(med_geometry_type geoType); + static INTERP_KERNEL::NormalizedCellType ConvertFromMEDFileGeoType(med_geometry_type geoType); + static TypeOfField ConvertFromMEDFileEntity(med_entity_type etype); protected: MEDFileMesh(); //! protected because no way in MED file API to specify this name diff --git a/src/MEDLoader/MEDFileStructureElement.cxx b/src/MEDLoader/MEDFileStructureElement.cxx index 140c9e9cc..417d9d7f0 100644 --- a/src/MEDLoader/MEDFileStructureElement.cxx +++ b/src/MEDLoader/MEDFileStructureElement.cxx @@ -27,6 +27,119 @@ using namespace MEDCoupling; + +std::string MEDFileSEHolder::getModelName() const +{ + return _father->getName(); +} + +void MEDFileSEHolder::setName(const std::string& name) +{ + _name=name; +} + +std::size_t MEDFileSEHolder::getHeapMemorySizeLoc() const +{ + return _name.capacity(); +} + +//////////////////// + +MEDFileSEConstAtt *MEDFileSEConstAtt::New(med_idt fid, MEDFileStructureElement *father, int idCstAtt) +{ + return new MEDFileSEConstAtt(fid,father,idCstAtt); +} + +MEDFileSEConstAtt::MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *father, int idCstAtt):MEDFileSEHolder(father) +{ + std::string modelName(getModelName()); + INTERP_KERNEL::AutoPtr constattname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),profilename(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); + med_attribute_type constatttype; + int nbCompo; + med_entity_type met; + int pflSz; + MEDFILESAFECALLERRD0(MEDstructElementConstAttInfo,(fid,modelName.c_str(),idCstAtt+1,constattname,&constatttype,&nbCompo,&met,profilename,&pflSz)); + std::string name(MEDLoaderBase::buildStringFromFortran(constattname,MED_NAME_SIZE)); + setName(name); + setProfile(MEDLoaderBase::buildStringFromFortran(profilename,MED_NAME_SIZE)); + _tof=MEDFileMesh::ConvertFromMEDFileEntity(met); + // + _val=MEDFileStructureElement::BuildFrom(constatttype); + nbCompo=MEDFileStructureElement::EffectiveNbCompo(constatttype,nbCompo); + if(pflSz==0 && getProfile().empty()) + pflSz=1; + if(constatttype==MED_ATT_NAME) + pflSz++; + std::cerr << "******* " << pflSz << std::endl; + _val->alloc(pflSz,nbCompo); + MEDFILESAFECALLERRD0(MEDstructElementConstAttRd,(fid,modelName.c_str(),name.c_str(),_val->getVoidStarPointer())); + if(constatttype==MED_ATT_NAME) + { pflSz--; _val->reAlloc(pflSz); } +} + +std::vector MEDFileSEConstAtt::getDirectChildrenWithNull() const +{ + std::vector ret; + ret.push_back(_val); + return ret; +} + +std::size_t MEDFileSEConstAtt::getHeapMemorySizeWithoutChildren() const +{ + return getHeapMemorySizeLoc()+_pfl.capacity(); +} + +void MEDFileSEConstAtt::writeLL(med_idt fid) const +{ +} + +void MEDFileSEConstAtt::setProfile(const std::string& name) +{ + _pfl=name; +} + +std::string MEDFileSEConstAtt::getProfile() const +{ + return _pfl; +} + +//////////////////// + +MEDFileSEVarAtt *MEDFileSEVarAtt::New(med_idt fid, MEDFileStructureElement *father, int idVarAtt) +{ + return new MEDFileSEVarAtt(fid,father,idVarAtt); +} + +MEDFileSEVarAtt::MEDFileSEVarAtt(med_idt fid, MEDFileStructureElement *father, int idVarAtt):MEDFileSEHolder(father) +{ + std::string modelName(getModelName()); + INTERP_KERNEL::AutoPtr varattname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),profilename(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); + med_attribute_type varatttype; + { + int pflSz; + MEDFILESAFECALLERRD0(MEDstructElementVarAttInfo,(fid,modelName.c_str(),idVarAtt+1,varattname,&varatttype,&_nb_compo)); + } + setName(MEDLoaderBase::buildStringFromFortran(varattname,MED_NAME_SIZE)); + _gen=MEDFileStructureElement::BuildFrom(varatttype); + _gen->alloc(0,1); +} + +std::vector MEDFileSEVarAtt::getDirectChildrenWithNull() const +{ + return std::vector(); +} + +std::size_t MEDFileSEVarAtt::getHeapMemorySizeWithoutChildren() const +{ + return getHeapMemorySizeLoc(); +} + +void MEDFileSEVarAtt::writeLL(med_idt fid) const +{ +} + +//////////////////// + MEDFileStructureElement *MEDFileStructureElement::New(med_idt fid, int idSE) { return new MEDFileStructureElement(fid,idSE); @@ -41,12 +154,84 @@ MEDFileStructureElement::MEDFileStructureElement(med_idt fid, int idSE) { med_bool anyPfl; int nnode(0),ncell(0); - MEDstructElementInfo(fid,idSE+1,modelName,&_id_type,&_dim,supportMeshName,&entiyType,&nnode,&ncell,&sgeoType,&nConsAttr,&anyPfl,&nVarAttr); + MEDFILESAFECALLERRD0(MEDstructElementInfo,(fid,idSE+1,modelName,&_id_type,&_dim,supportMeshName,&entiyType,&nnode,&ncell,&sgeoType,&nConsAttr,&anyPfl,&nVarAttr)); } - _model_name=MEDLoaderBase::buildStringFromFortran(modelName,MED_NAME_SIZE); - _geo_type=MEDFileMesh::ConvertFromMEDFile(sgeoType); + _name=MEDLoaderBase::buildStringFromFortran(modelName,MED_NAME_SIZE); + _geo_type=MEDFileMesh::ConvertFromMEDFileGeoType(sgeoType); + _cst_att.resize(nConsAttr); + for(int i=0;i MEDFileStructureElement::getDirectChildrenWithNull() const +{ + std::vector ret; + for(std::vector< MCAuto >::const_iterator it=_cst_att.begin();it!=_cst_att.end();it++) + ret.push_back(*it); + for(std::vector< MCAuto >::const_iterator it=_var_att.begin();it!=_var_att.end();it++) + ret.push_back(*it); + return ret; +} + +std::size_t MEDFileStructureElement::getHeapMemorySizeWithoutChildren() const +{ + return _name.capacity()+_cst_att.capacity()*sizeof(MCAuto)+_var_att.capacity()*sizeof(MCAuto); } +void MEDFileStructureElement::writeLL(med_idt fid) const +{ +} + +std::string MEDFileStructureElement::getName() const +{ + return _name; +} + +MCAuto MEDFileStructureElement::BuildFrom(med_attribute_type mat) +{ + MCAuto ret; + switch(mat) + { + case MED_ATT_INT: + { + ret=DataArrayInt::New(); + break; + } + case MED_ATT_FLOAT64: + { + ret=DataArrayDouble::New(); + break; + } + case MED_ATT_NAME: + { + ret=DataArrayAsciiChar::New(); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDFileStructureElement::BuildFrom : not recognized type ! Only INT and FLOAT64 !"); + } + return ret; +} + +int MEDFileStructureElement::EffectiveNbCompo(med_attribute_type mat, int nbCompo) +{ + switch(mat) + { + case MED_ATT_INT: + case MED_ATT_FLOAT64: + return nbCompo; + case MED_ATT_NAME: + return nbCompo*MED_NAME_SIZE; + default: + throw INTERP_KERNEL::Exception("MEDFileStructureElement::BuildFrom : not recognized type ! Only INT and FLOAT64 !"); + } +} + +//////////////////// + MEDFileStructureElements *MEDFileStructureElements::New(med_idt fid) { return new MEDFileStructureElements(fid); diff --git a/src/MEDLoader/MEDFileStructureElement.hxx b/src/MEDLoader/MEDFileStructureElement.hxx index 7944eab2f..5d9b2ea02 100644 --- a/src/MEDLoader/MEDFileStructureElement.hxx +++ b/src/MEDLoader/MEDFileStructureElement.hxx @@ -29,21 +29,74 @@ namespace MEDCoupling { + class MEDFileStructureElement; + + class MEDFileSEHolder + { + protected: + MEDFileSEHolder(MEDFileStructureElement *father):_father(father) { } + std::string getModelName() const; + void setName(const std::string& name); + std::size_t getHeapMemorySizeLoc() const; + private: + MEDFileStructureElement *_father; + std::string _name; + }; + +class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlone, public MEDFileSEHolder + { + public: + static MEDFileSEConstAtt *New(med_idt fid, MEDFileStructureElement *father, int idCstAtt); + public: + std::vector getDirectChildrenWithNull() const; + std::size_t getHeapMemorySizeWithoutChildren() const; + void writeLL(med_idt fid) const; + void setProfile(const std::string& name); + std::string getProfile() const; + private: + MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *father, int idCstAtt); + private: + std::string _pfl; + TypeOfField _tof; + MCAuto _val; + }; + + class MEDFileSEVarAtt : public RefCountObject, public MEDFileWritableStandAlone, public MEDFileSEHolder + { + public: + static MEDFileSEVarAtt *New(med_idt fid, MEDFileStructureElement *father, int idVarAtt); + public: + std::vector getDirectChildrenWithNull() const; + std::size_t getHeapMemorySizeWithoutChildren() const; + void writeLL(med_idt fid) const; + private: + MEDFileSEVarAtt(med_idt fid, MEDFileStructureElement *father, int idVarAtt); + private: + int _nb_compo; + MCAuto _gen; + }; + class MEDFileStructureElement : public RefCountObject, public MEDFileWritableStandAlone { public: MEDLOADER_EXPORT static MEDFileStructureElement *New(med_idt fid, int idSE); + MEDLOADER_EXPORT std::string getName() const; public: std::vector getDirectChildrenWithNull() const; std::size_t getHeapMemorySizeWithoutChildren() const; void writeLL(med_idt fid) const; + public: + static MCAuto BuildFrom(med_attribute_type mat); + static int EffectiveNbCompo(med_attribute_type mat, int nbCompo); private: MEDFileStructureElement(med_idt fid, int idSE); private: int _id_type; - std::string _model_name; + std::string _name; INTERP_KERNEL::NormalizedCellType _geo_type; int _dim; + std::vector< MCAuto > _cst_att; + std::vector< MCAuto > _var_att; }; class MEDFileStructureElements : public RefCountObject, public MEDFileWritableStandAlone -- 2.39.2