From: Anthony Geay Date: Thu, 19 Jan 2017 16:13:32 +0000 (+0100) Subject: Ready for fields. OK with UsesCase_MEDstructElement_1.med X-Git-Tag: V8_3_0a2~38^2~16 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b4e470d2031b5ead9b21f4f0fbb0b053cd632c91;p=tools%2Fmedcoupling.git Ready for fields. OK with UsesCase_MEDstructElement_1.med --- diff --git a/src/MEDLoader/MEDFileData.cxx b/src/MEDLoader/MEDFileData.cxx index 95db854ad..2a722d0d6 100644 --- a/src/MEDLoader/MEDFileData.cxx +++ b/src/MEDLoader/MEDFileData.cxx @@ -307,11 +307,11 @@ MEDFileData::MEDFileData(med_idt fid) try { readHeader(fid); + _mesh_supports=MEDFileMeshSupports::New(fid); + _struct_elems=MEDFileStructureElements::New(fid,_mesh_supports); _fields=MEDFileFields::New(fid); _meshes=MEDFileMeshes::New(fid); _params=MEDFileParameters::New(fid); - _mesh_supports=MEDFileMeshSupports::New(fid); - _struct_elems=MEDFileStructureElements::New(fid); } catch(INTERP_KERNEL::Exception& e) { diff --git a/src/MEDLoader/MEDFileMeshSupport.cxx b/src/MEDLoader/MEDFileMeshSupport.cxx index 15dcaadc7..2d6d0443b 100644 --- a/src/MEDLoader/MEDFileMeshSupport.cxx +++ b/src/MEDLoader/MEDFileMeshSupport.cxx @@ -83,3 +83,24 @@ void MEDFileMeshSupports::writeLL(med_idt fid) const if((*it).isNotNull()) (*it)->writeLL(fid); } + +const MEDFileUMesh *MEDFileMeshSupports::getSupMeshWithName(const std::string& name) const +{ + std::vector mns; + for(std::vector< MCAuto >::const_iterator it=_supports.begin();it!=_supports.end();it++) + { + if((*it).isNotNull()) + { + std::string na((*it)->getName()); + if(na==name) + return *it; + else + mns.push_back(na); + } + } + std::ostringstream oss; + oss << "MEDFileMeshSupports::getSupMeshWithName : no such name \"" << name << "\". Possibilitities are :"; + std::copy(mns.begin(),mns.end(),std::ostream_iterator(oss,",")); + oss << " !"; + throw INTERP_KERNEL::Exception(oss.str()); +} diff --git a/src/MEDLoader/MEDFileMeshSupport.hxx b/src/MEDLoader/MEDFileMeshSupport.hxx index 868426a45..cf2b394c3 100644 --- a/src/MEDLoader/MEDFileMeshSupport.hxx +++ b/src/MEDLoader/MEDFileMeshSupport.hxx @@ -38,6 +38,7 @@ namespace MEDCoupling std::vector getDirectChildrenWithNull() const; std::size_t getHeapMemorySizeWithoutChildren() const; void writeLL(med_idt fid) const; + const MEDFileUMesh *getSupMeshWithName(const std::string& name) const; private: MEDFileMeshSupports(med_idt fid); MEDFileMeshSupports(); diff --git a/src/MEDLoader/MEDFileStructureElement.cxx b/src/MEDLoader/MEDFileStructureElement.cxx index 417d9d7f0..4ef945d15 100644 --- a/src/MEDLoader/MEDFileStructureElement.cxx +++ b/src/MEDLoader/MEDFileStructureElement.cxx @@ -19,6 +19,7 @@ // Author : Anthony Geay (EDF R&D) #include "MEDFileStructureElement.hxx" +#include "MEDFileMeshSupport.hxx" #include "MEDLoaderBase.hxx" #include "MEDFileMeshLL.hxx" #include "MEDFileSafeCaller.txx" @@ -45,12 +46,12 @@ std::size_t MEDFileSEHolder::getHeapMemorySizeLoc() const //////////////////// -MEDFileSEConstAtt *MEDFileSEConstAtt::New(med_idt fid, MEDFileStructureElement *father, int idCstAtt) +MEDFileSEConstAtt *MEDFileSEConstAtt::New(med_idt fid, MEDFileStructureElement *father, int idCstAtt, const MEDFileUMesh *mesh) { - return new MEDFileSEConstAtt(fid,father,idCstAtt); + return new MEDFileSEConstAtt(fid,father,idCstAtt,mesh); } -MEDFileSEConstAtt::MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *father, int idCstAtt):MEDFileSEHolder(father) +MEDFileSEConstAtt::MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *father, int idCstAtt, const MEDFileUMesh *mesh):MEDFileSEHolder(father) { std::string modelName(getModelName()); INTERP_KERNEL::AutoPtr constattname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),profilename(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); @@ -67,7 +68,26 @@ MEDFileSEConstAtt::MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *fathe _val=MEDFileStructureElement::BuildFrom(constatttype); nbCompo=MEDFileStructureElement::EffectiveNbCompo(constatttype,nbCompo); if(pflSz==0 && getProfile().empty()) - pflSz=1; + { + switch(met) + { + case MED_CELL: + { + std::vector gt(mesh->getAllGeoTypes()); + if(gt.size()!=1) + throw INTERP_KERNEL::Exception("MEDFileSEConstAtt constr : only one cell type expected !"); + pflSz=mesh->getNumberOfCellsWithType(gt[0]); + break; + } + case MED_NODE: + { + pflSz=mesh->getNumberOfNodes(); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDFileSEConstAtt cstr : not recognized entity type !"); + } + } if(constatttype==MED_ATT_NAME) pflSz++; std::cerr << "******* " << pflSz << std::endl; @@ -140,12 +160,12 @@ void MEDFileSEVarAtt::writeLL(med_idt fid) const //////////////////// -MEDFileStructureElement *MEDFileStructureElement::New(med_idt fid, int idSE) +MEDFileStructureElement *MEDFileStructureElement::New(med_idt fid, int idSE, const MEDFileMeshSupports *ms) { - return new MEDFileStructureElement(fid,idSE); + return new MEDFileStructureElement(fid,idSE,ms); } -MEDFileStructureElement::MEDFileStructureElement(med_idt fid, int idSE) +MEDFileStructureElement::MEDFileStructureElement(med_idt fid, int idSE, const MEDFileMeshSupports *ms) { INTERP_KERNEL::AutoPtr modelName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),supportMeshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); med_geometry_type sgeoType; @@ -157,10 +177,11 @@ MEDFileStructureElement::MEDFileStructureElement(med_idt fid, int idSE) MEDFILESAFECALLERRD0(MEDstructElementInfo,(fid,idSE+1,modelName,&_id_type,&_dim,supportMeshName,&entiyType,&nnode,&ncell,&sgeoType,&nConsAttr,&anyPfl,&nVarAttr)); } _name=MEDLoaderBase::buildStringFromFortran(modelName,MED_NAME_SIZE); + _sup_mesh_name=MEDLoaderBase::buildStringFromFortran(supportMeshName,MED_NAME_SIZE); _geo_type=MEDFileMesh::ConvertFromMEDFileGeoType(sgeoType); _cst_att.resize(nConsAttr); for(int i=0;igetSupMeshWithName(_sup_mesh_name)); _var_att.resize(nVarAttr); for(int i=0;i getDirectChildrenWithNull() const; std::size_t getHeapMemorySizeWithoutChildren() const; @@ -54,7 +56,7 @@ class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlon void setProfile(const std::string& name); std::string getProfile() const; private: - MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *father, int idCstAtt); + MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *father, int idCstAtt, const MEDFileUMesh *mesh); private: std::string _pfl; TypeOfField _tof; @@ -79,7 +81,7 @@ class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlon class MEDFileStructureElement : public RefCountObject, public MEDFileWritableStandAlone { public: - MEDLOADER_EXPORT static MEDFileStructureElement *New(med_idt fid, int idSE); + MEDLOADER_EXPORT static MEDFileStructureElement *New(med_idt fid, int idSE, const MEDFileMeshSupports *ms); MEDLOADER_EXPORT std::string getName() const; public: std::vector getDirectChildrenWithNull() const; @@ -89,10 +91,11 @@ class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlon static MCAuto BuildFrom(med_attribute_type mat); static int EffectiveNbCompo(med_attribute_type mat, int nbCompo); private: - MEDFileStructureElement(med_idt fid, int idSE); + MEDFileStructureElement(med_idt fid, int idSE, const MEDFileMeshSupports *ms); private: int _id_type; std::string _name; + std::string _sup_mesh_name; INTERP_KERNEL::NormalizedCellType _geo_type; int _dim; std::vector< MCAuto > _cst_att; @@ -102,14 +105,14 @@ class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlon class MEDFileStructureElements : public RefCountObject, public MEDFileWritableStandAlone { public: - MEDLOADER_EXPORT static MEDFileStructureElements *New(med_idt fid); + MEDLOADER_EXPORT static MEDFileStructureElements *New(med_idt fid, const MEDFileMeshSupports *ms); MEDLOADER_EXPORT static MEDFileStructureElements *New(); public: std::vector getDirectChildrenWithNull() const; std::size_t getHeapMemorySizeWithoutChildren() const; void writeLL(med_idt fid) const; private: - MEDFileStructureElements(med_idt fid); + MEDFileStructureElements(med_idt fid, const MEDFileMeshSupports *ms); MEDFileStructureElements(); ~MEDFileStructureElements(); private: