From: Anthony Geay Date: Mon, 23 Jan 2017 10:08:15 +0000 (+0100) Subject: Step 6 over. Remaining part : extract structure elements from fields and generate... X-Git-Tag: V8_3_0a2~38^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6ebb06512fe4733596a3e5414d97303d67ee5cc0;p=tools%2Fmedcoupling.git Step 6 over. Remaining part : extract structure elements from fields and generate classical fields from SE fields. --- diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 7b6c43d6d..3d59c0b95 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -2816,7 +2816,6 @@ void MEDFileUMesh::loadLL(med_idt fid, const std::string& mName, int dt, int it, if(nModels<=0) return ; _elt_str.resize(nModels); - std::cerr << "******** " << nModels << std::endl; for(int i=0;i >::const_iterator it=_elt_str.begin();it!=_elt_str.end();it++) + if((*it).isNotNull()) + return true; + return false; +} + +void MEDFileUMesh::killStructureElements() +{ + _elt_str.clear(); +} + /*! * Returns the optional numbers of mesh entities of a given dimension transformed using * DataArrayInt::invertArrayN2O2O2N(). @@ -7094,6 +7106,22 @@ void MEDFileMeshMultiTS::setJoints( MEDFileJoints* joints ) } } +bool MEDFileMeshMultiTS::presenceOfStructureElements() const +{ + for(std::vector< MCAuto >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++) + if((*it).isNotNull()) + if((*it)->presenceOfStructureElements()) + return true; + return false; +} + +void MEDFileMeshMultiTS::killStructureElements() +{ + for(std::vector< MCAuto >::iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++) + if((*it).isNotNull()) + (*it)->killStructureElements(); +} + void MEDFileMeshMultiTS::writeLL(med_idt fid) const { MEDFileJoints *joints(getJoints()); @@ -7387,6 +7415,22 @@ void MEDFileMeshes::checkConsistencyLight() const } } +bool MEDFileMeshes::presenceOfStructureElements() const +{ + for(std::vector< MCAuto >::const_iterator it=_meshes.begin();it!=_meshes.end();it++) + if((*it).isNotNull()) + if((*it)->presenceOfStructureElements()) + return true; + return false; +} + +void MEDFileMeshes::killStructureElements() +{ + for(std::vector< MCAuto >::iterator it=_meshes.begin();it!=_meshes.end();it++) + if((*it).isNotNull()) + (*it)->killStructureElements(); +} + MEDFileMeshesIterator::MEDFileMeshesIterator(MEDFileMeshes *ms):_ms(ms),_iter_id(0),_nb_iter(0) { if(ms) @@ -7442,3 +7486,5 @@ TypeOfField MEDFileMesh::ConvertFromMEDFileEntity(med_entity_type etype) } } } + + diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index c3f3c6776..5cca36ee7 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -91,6 +91,8 @@ namespace MEDCoupling MEDLOADER_EXPORT virtual std::vector getDistributionOfTypes(int meshDimRelToMax) const; MEDLOADER_EXPORT virtual void whichAreNodesFetched(const MEDFileField1TSStructItem& st, const MEDFileFieldGlobsReal *globs, std::vector& nodesFetched) const = 0; MEDLOADER_EXPORT virtual MEDFileMesh *cartesianize() const = 0; + MEDLOADER_EXPORT virtual bool presenceOfStructureElements() const = 0; + MEDLOADER_EXPORT virtual void killStructureElements() { } // MEDLOADER_EXPORT bool areFamsEqual(const MEDFileMesh *other, std::string& what) const; MEDLOADER_EXPORT bool areGrpsEqual(const MEDFileMesh *other, std::string& what) const; @@ -296,6 +298,8 @@ namespace MEDCoupling MEDLOADER_EXPORT int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const; MEDLOADER_EXPORT void whichAreNodesFetched(const MEDFileField1TSStructItem& st, const MEDFileFieldGlobsReal *globs, std::vector& nodesFetched) const; MEDLOADER_EXPORT MEDFileMesh *cartesianize() const; + MEDLOADER_EXPORT bool presenceOfStructureElements() const; + MEDLOADER_EXPORT void killStructureElements(); MEDLOADER_EXPORT std::vector getNonEmptyLevels() const; MEDLOADER_EXPORT std::vector getNonEmptyLevelsExt() const; MEDLOADER_EXPORT std::vector getFamArrNonEmptyLevelsExt() const; @@ -426,6 +430,7 @@ namespace MEDCoupling MEDLOADER_EXPORT std::vector getGeoTypesAtLevel(int meshDimRelToMax) const; MEDLOADER_EXPORT int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const; MEDLOADER_EXPORT void whichAreNodesFetched(const MEDFileField1TSStructItem& st, const MEDFileFieldGlobsReal *globs, std::vector& nodesFetched) const; + MEDLOADER_EXPORT bool presenceOfStructureElements() const { return false; } MEDLOADER_EXPORT virtual const MEDCouplingStructuredMesh *getStructuredMesh() const = 0; // tools MEDLOADER_EXPORT bool unPolyze(std::vector& oldCode, std::vector& newCode, DataArrayInt *& o2nRenumCell); @@ -548,6 +553,8 @@ namespace MEDCoupling MEDLOADER_EXPORT void setOneTimeStep(MEDFileMesh *mesh1TimeStep); MEDLOADER_EXPORT MEDFileJoints *getJoints() const; MEDLOADER_EXPORT void setJoints(MEDFileJoints* joints); + MEDLOADER_EXPORT bool presenceOfStructureElements() const; + MEDLOADER_EXPORT void killStructureElements(); private: ~MEDFileMeshMultiTS() { } void loadFromFile(med_idt fid, const std::string& mName); @@ -585,6 +592,8 @@ namespace MEDCoupling MEDLOADER_EXPORT void pushMesh(MEDFileMesh *mesh); MEDLOADER_EXPORT void setMeshAtPos(int i, MEDFileMesh *mesh); MEDLOADER_EXPORT void destroyMeshAtPos(int i); + MEDLOADER_EXPORT bool presenceOfStructureElements() const; + MEDLOADER_EXPORT void killStructureElements(); private: ~MEDFileMeshes() { } void checkConsistencyLight() const; diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 3dc52b7bc..b3a76b444 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -2064,7 +2064,7 @@ MEDFileEltStruct4Mesh *MEDFileEltStruct4Mesh::New(med_idt fid, const std::string std::size_t MEDFileEltStruct4Mesh::getHeapMemorySizeWithoutChildren() const { - return _geo_type_name.capacity(); + return _geo_type_name.capacity()+_vars.capacity()*sizeof(MCAuto); } std::vector MEDFileEltStruct4Mesh::getDirectChildrenWithNull() const @@ -2072,6 +2072,8 @@ std::vector MEDFileEltStruct4Mesh::getDirec std::vector ret; ret.push_back(_conn); ret.push_back(_common); + for(std::vector< MCAuto >::const_iterator it=_vars.begin();it!=_vars.end();it++) + ret.push_back(*it); return ret; } @@ -2094,5 +2096,16 @@ MEDFileEltStruct4Mesh::MEDFileEltStruct4Mesh(med_idt fid, const std::string& mNa MEDFILESAFECALLERRD0(MEDmeshElementConnectivityRd,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,_geo_type,MED_NODAL,MED_FULL_INTERLACE,_conn->getPointer())); _common=MEDFileUMeshPerTypeCommon::New(); _common->loadCommonPart(fid,mName.c_str(),dt,it,nCells,geoType,MED_STRUCT_ELEMENT,mrs); - //MEDFILESAFECALLERRD0(MEDmeshElementRd,(mName.c_str(),dt,it,MED_STRUCT_ELEMENT,geoType,MED_NODAL,MED_FULL_INTERLACE,conn,)); + std::vector vns(mse->getVarAttsOf(_geo_type_name)); + std::size_t sz(vns.size()); + _vars.resize(sz); + for(std::size_t i=0;igetVarAttOf(_geo_type_name,vns[i])); + MCAuto gen(var->getGenerator()); + MCAuto arr(gen->buildNewEmptyInstance()); + arr->alloc(nCells,var->getNbOfComponents()); + arr->setName(vns[i]); + MEDFILESAFECALLERRD0(MEDmeshStructElementVarAttRd,(fid,mName.c_str(),dt,it,_geo_type,vns[i].c_str(),arr->getVoidStarPointer())); + } } diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index adbd78e21..8a8d31b85 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -338,6 +338,7 @@ namespace MEDCoupling int _geo_type; MCAuto _conn; MCAuto _common; + std::vector< MCAuto > _vars; }; } diff --git a/src/MEDLoader/MEDFileMeshSupport.cxx b/src/MEDLoader/MEDFileMeshSupport.cxx index 1e101c0c2..6958cb02a 100644 --- a/src/MEDLoader/MEDFileMeshSupport.cxx +++ b/src/MEDLoader/MEDFileMeshSupport.cxx @@ -27,6 +27,12 @@ using namespace MEDCoupling; +MEDFileMeshSupports *MEDFileMeshSupports::New(const std::string& fileName) +{ + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid); +} + MEDFileMeshSupports *MEDFileMeshSupports::New(med_idt fid) { return new MEDFileMeshSupports(fid); diff --git a/src/MEDLoader/MEDFileMeshSupport.hxx b/src/MEDLoader/MEDFileMeshSupport.hxx index c94a9ee7d..7f7569422 100644 --- a/src/MEDLoader/MEDFileMeshSupport.hxx +++ b/src/MEDLoader/MEDFileMeshSupport.hxx @@ -32,6 +32,7 @@ namespace MEDCoupling class MEDFileMeshSupports : public RefCountObject, public MEDFileWritableStandAlone { public: + MEDLOADER_EXPORT static MEDFileMeshSupports *New(const std::string& fileName); MEDLOADER_EXPORT static MEDFileMeshSupports *New(med_idt fid); MEDLOADER_EXPORT static MEDFileMeshSupports *New(); public: diff --git a/src/MEDLoader/MEDFileStructureElement.cxx b/src/MEDLoader/MEDFileStructureElement.cxx index d2de14def..e174bf60b 100644 --- a/src/MEDLoader/MEDFileStructureElement.cxx +++ b/src/MEDLoader/MEDFileStructureElement.cxx @@ -34,6 +34,11 @@ std::string MEDFileSEHolder::getModelName() const return _father->getName(); } +std::string MEDFileSEHolder::getName() const +{ + return _name; +} + void MEDFileSEHolder::setName(const std::string& name) { _name=name; @@ -266,8 +271,33 @@ std::string MEDFileStructureElement::getMeshName() const return _sup_mesh_name; } +std::vector MEDFileStructureElement::getVarAtts() const +{ + std::vector ret; + for(std::vector< MCAuto >::const_iterator it=_var_att.begin();it!=_var_att.end();it++) + if((*it).isNotNull()) + ret.push_back((*it)->getName()); + return ret; +} + +const MEDFileSEVarAtt *MEDFileStructureElement::getVarAtt(const std::string& varName) const +{ + for(std::vector< MCAuto >::const_iterator it=_var_att.begin();it!=_var_att.end();it++) + if((*it).isNotNull()) + if((*it)->getName()==varName) + return *it; + std::ostringstream oss; oss << "MEDFileStructureElement::getVarAtt : no var att with name \"" << varName << "\" !"; + throw INTERP_KERNEL::Exception(oss.str()); +} + //////////////////// +MEDFileStructureElements *MEDFileStructureElements::New(const std::string& fileName, const MEDFileMeshSupports *ms) +{ + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,ms); +} + MEDFileStructureElements *MEDFileStructureElements::New(med_idt fid, const MEDFileMeshSupports *ms) { return new MEDFileStructureElements(fid,ms); @@ -360,3 +390,14 @@ const MEDFileStructureElement *MEDFileStructureElements::getSEWithName(const std throw INTERP_KERNEL::Exception(oss.str()); } +std::vector MEDFileStructureElements::getVarAttsOf(const std::string& seName) const +{ + const MEDFileStructureElement *se(getSEWithName(seName)); + return se->getVarAtts(); +} + +const MEDFileSEVarAtt *MEDFileStructureElements::getVarAttOf(const std::string &seName, const std::string& varName) const +{ + const MEDFileStructureElement *se(getSEWithName(seName)); + return se->getVarAtt(varName); +} diff --git a/src/MEDLoader/MEDFileStructureElement.hxx b/src/MEDLoader/MEDFileStructureElement.hxx index cdb56aa09..05efa66b1 100644 --- a/src/MEDLoader/MEDFileStructureElement.hxx +++ b/src/MEDLoader/MEDFileStructureElement.hxx @@ -35,9 +35,11 @@ namespace MEDCoupling class MEDFileSEHolder { + public: + std::string getModelName() const; + std::string getName() const; protected: MEDFileSEHolder(MEDFileStructureElement *father):_father(father) { } - std::string getModelName() const; void setName(const std::string& name); std::size_t getHeapMemorySizeLoc() const; private: @@ -71,6 +73,8 @@ class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlon std::vector getDirectChildrenWithNull() const; std::size_t getHeapMemorySizeWithoutChildren() const; void writeLL(med_idt fid) const; + int getNbOfComponents() const { return _nb_compo; } + MCAuto getGenerator() const { return _gen; } private: MEDFileSEVarAtt(med_idt fid, MEDFileStructureElement *father, int idVarAtt); private: @@ -86,6 +90,8 @@ class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlon MEDLOADER_EXPORT int getDynGT() const; MEDLOADER_EXPORT TypeOfField getEntity() const; MEDLOADER_EXPORT std::string getMeshName() const; + MEDLOADER_EXPORT std::vector getVarAtts() const; + MEDLOADER_EXPORT const MEDFileSEVarAtt *getVarAtt(const std::string& varName) const; public: std::vector getDirectChildrenWithNull() const; std::size_t getHeapMemorySizeWithoutChildren() const; @@ -109,6 +115,7 @@ class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlon class MEDFileStructureElements : public RefCountObject, public MEDFileWritableStandAlone { public: + MEDLOADER_EXPORT static MEDFileStructureElements *New(const std::string& fileName, const MEDFileMeshSupports *ms); MEDLOADER_EXPORT static MEDFileStructureElements *New(med_idt fid, const MEDFileMeshSupports *ms); MEDLOADER_EXPORT static MEDFileStructureElements *New(); MEDLOADER_EXPORT int getNumberOf() const; @@ -116,6 +123,8 @@ class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlon MEDLOADER_EXPORT const MEDFileStructureElement *getWithGT(int idGT) const; MEDLOADER_EXPORT int getNumberOfNodesPerCellOf(const std::string& seName) const; MEDLOADER_EXPORT const MEDFileStructureElement *getSEWithName(const std::string& seName) const; + MEDLOADER_EXPORT std::vector getVarAttsOf(const std::string& seName) const; + MEDLOADER_EXPORT const MEDFileSEVarAtt *getVarAttOf(const std::string &seName, const std::string& varName) const; public: std::vector getDirectChildrenWithNull() const; std::size_t getHeapMemorySizeWithoutChildren() const; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 10057bca1..5e2e86c94 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -1083,6 +1083,8 @@ namespace MEDCoupling void setJoints( MEDFileJoints* joints ); void initializeEquivalences(); void killEquivalences(); + bool presenceOfStructureElements() const throw(INTERP_KERNEL::Exception); + void killStructureElements() throw(INTERP_KERNEL::Exception); %extend { std::string __str__() const throw(INTERP_KERNEL::Exception) @@ -1751,6 +1753,8 @@ namespace MEDCoupling void setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception); void destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception); void cartesianizeMe() throw(INTERP_KERNEL::Exception); + bool presenceOfStructureElements() const throw(INTERP_KERNEL::Exception); + void killStructureElements() throw(INTERP_KERNEL::Exception); %extend { MEDFileMeshes()