From: Anthony Geay Date: Mon, 23 Jan 2017 08:57:30 +0000 (+0100) Subject: Step 6 : Read structure element data from MEDFileUMesh. X-Git-Tag: V8_3_0a2~38^2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5d5f680dee17d1bae83f6b756358bd5af512d4e4;p=tools%2Fmedcoupling.git Step 6 : Read structure element data from MEDFileUMesh. --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 1816ec276..f04d3ba06 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -2846,6 +2846,7 @@ MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWith if(nbPfl>0) { _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc)); + _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1); } } } diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 2e0cfc6cd..7b6c43d6d 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -2347,7 +2347,7 @@ MEDFileUMesh *MEDFileUMesh::LoadPartOf(med_idt fid, const std::string& mName, co std::size_t MEDFileUMesh::getHeapMemorySizeWithoutChildren() const { std::size_t ret(MEDFileMesh::getHeapMemorySizeWithoutChildren()); - ret+=_ms.capacity()*(sizeof(MCAuto)); + ret+=_ms.capacity()*(sizeof(MCAuto))+_elt_str.capacity()*sizeof(MCAuto); return ret; } @@ -2362,6 +2362,8 @@ std::vector MEDFileUMesh::getDirectChildrenWithNull() c ret.push_back((const PartDefinition *)_part_coords); for(std::vector< MCAuto >::const_iterator it=_ms.begin();it!=_ms.end();it++) ret.push_back((const MEDFileUMeshSplitL1*) *it); + for(std::vector< MCAuto >::const_iterator it=_elt_str.begin();it!=_elt_str.end();it++) + ret.push_back((const MEDFileEltStruct4Mesh *)*it); return ret; } @@ -2805,6 +2807,18 @@ void MEDFileUMesh::loadLL(med_idt fid, const std::string& mName, int dt, int it, } loaderl2.loadAll(fid,mid,mName,dt,it,mrs); dispatchLoadedPart(fid,loaderl2,mName,mrs); + // Structure element part... + int nModels(-1); + { + med_bool chgt=MED_FALSE,trsf=MED_FALSE; + nModels=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,MED_GEO_ALL,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf); + } + if(nModels<=0) + return ; + _elt_str.resize(nModels); + std::cerr << "******** " << nModels << std::endl; + for(int i=0;i _name_coords; mutable MCAuto _rev_num_coords; MCAuto _part_coords; + std::vector< MCAuto > _elt_str; }; class MEDFileStructuredMesh : public MEDFileMesh diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx index 1e07175e5..a44dc9882 100644 --- a/src/MEDLoader/MEDFileMeshElt.cxx +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -34,6 +34,66 @@ extern med_geometry_type typmai3[34]; using namespace MEDCoupling; +MEDFileUMeshPerTypeCommon *MEDFileUMeshPerTypeCommon::New() +{ + return new MEDFileUMeshPerTypeCommon; +} + +void MEDFileUMeshPerTypeCommon::loadCommonPart(med_idt fid, const char *mName, int dt, int it, int curNbOfElem, med_geometry_type geoElt, + med_entity_type entity, MEDFileMeshReadSelector *mrs) +{ + med_bool changement,transformation; + _fam=0; + if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) + { + if(!mrs || mrs->isCellFamilyFieldReading()) + { + _fam=DataArrayInt::New(); + _fam->alloc(curNbOfElem,1); + if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,entity,geoElt,_fam->getPointer())!=0) + std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0); + } + } + _num=0; + if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) + { + if(!mrs || mrs->isCellNumFieldReading()) + { + _num=DataArrayInt::New(); + _num->alloc(curNbOfElem,1); + if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,geoElt,_num->getPointer())!=0) + _num=0; + } + } + _names=0; + if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NAME,MED_NODAL,&changement,&transformation)>0) + { + if(!mrs || mrs->isCellNameFieldReading()) + { + _names=DataArrayAsciiChar::New(); + _names->alloc(curNbOfElem+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end + if(MEDmeshEntityNameRd(fid,mName,dt,it,entity,geoElt,_names->getPointer())!=0) + _names=0; + else + _names->reAlloc(curNbOfElem);//not a bug to avoid the memory corruption due to last \0 at the end + } + } +} + +std::size_t MEDFileUMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const +{ + return 0; +} + +std::vector MEDFileUMeshPerTypeCommon::getDirectChildrenWithNull() const +{ + std::vector ret; + ret.push_back((const DataArrayInt *)_num); + ret.push_back((const DataArrayInt *)_fam); + ret.push_back((const DataArrayAsciiChar *)_names); + return ret; +} + MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType geoElt2, MEDFileMeshReadSelector *mrs) { med_entity_type whichEntity; @@ -58,16 +118,13 @@ MEDFileUMeshPerType *MEDFileUMeshPerType::NewPart(med_idt fid, const char *mName std::size_t MEDFileUMeshPerType::getHeapMemorySizeWithoutChildren() const { - return 0; + return MEDFileUMeshPerTypeCommon::getHeapMemorySizeWithoutChildren()+0; } std::vector MEDFileUMeshPerType::getDirectChildrenWithNull() const { - std::vector ret; + std::vector ret(MEDFileUMeshPerTypeCommon::getDirectChildrenWithNull()); ret.push_back((const MEDCoupling1GTUMesh *)_m); - ret.push_back((const DataArrayInt *)_num); - ret.push_back((const DataArrayInt *)_fam); - ret.push_back((const DataArrayAsciiChar *)_names); return ret; } @@ -100,7 +157,7 @@ MEDFileUMeshPerType::MEDFileUMeshPerType() } MEDFileUMeshPerType::MEDFileUMeshPerType(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type, - med_entity_type entity, MEDFileMeshReadSelector *mrs):_entity(entity) + med_entity_type entity, MEDFileMeshReadSelector *mrs) { med_bool changement,transformation; int curNbOfElem(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation)); @@ -145,7 +202,7 @@ void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int MEDFILESAFECALLERRD0(MEDmeshElementConnectivityRd,(fid,mName,dt,it,entity,geoElt,MED_NODAL,MED_FULL_INTERLACE,conn->getPointer())); std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind2nd(std::plus(),-1)); mc->setNodalConnectivity(conn); - loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity,mrs); + loadCommonPart(fid,mName,dt,it,curNbOfElem,geoElt,entity,mrs); } void MEDFileUMeshPerType::loadPartStaticType(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type, @@ -173,47 +230,6 @@ void MEDFileUMeshPerType::loadPartStaticType(med_idt fid, const char *mName, int loadPartOfCellCommonPart(fid,mName,strt,end,step,dt,it,mdim,curNbOfElem,geoElt,entity,mrs); } -void MEDFileUMeshPerType::loadCommonPart(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, - med_entity_type entity, MEDFileMeshReadSelector *mrs) -{ - med_bool changement,transformation; - _fam=0; - if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) - { - if(!mrs || mrs->isCellFamilyFieldReading()) - { - _fam=DataArrayInt::New(); - _fam->alloc(curNbOfElem,1); - if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,entity,geoElt,_fam->getPointer())!=0) - std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0); - } - } - _num=0; - if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NUMBER,MED_NODAL,&changement,&transformation)>0) - { - if(!mrs || mrs->isCellNumFieldReading()) - { - _num=DataArrayInt::New(); - _num->alloc(curNbOfElem,1); - if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,geoElt,_num->getPointer())!=0) - _num=0; - } - } - _names=0; - if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NAME,MED_NODAL,&changement,&transformation)>0) - { - if(!mrs || mrs->isCellNameFieldReading()) - { - _names=DataArrayAsciiChar::New(); - _names->alloc(curNbOfElem+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end - if(MEDmeshEntityNameRd(fid,mName,dt,it,entity,geoElt,_names->getPointer())!=0) - _names=0; - else - _names->reAlloc(curNbOfElem);//not a bug to avoid the memory corruption due to last \0 at the end - } - } -} - void MEDFileUMeshPerType::loadPartOfCellCommonPart(med_idt fid, const char *mName, int strt, int stp, int step, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, med_entity_type entity, MEDFileMeshReadSelector *mrs) { med_bool changement,transformation; @@ -286,7 +302,7 @@ void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int dt, int std::transform(conn->begin(),conn->end(),conn->getPointer(),std::bind2nd(std::plus(),-1)); std::transform(connI->begin(),connI->end(),connI->getPointer(),std::bind2nd(std::plus(),-1)); mc->setNodalConnectivity(conn,connI); - loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity,mrs); + loadCommonPart(fid,mName,dt,it,curNbOfElem,geoElt,entity,mrs); } void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, int connFaceLgth, med_geometry_type geoElt, @@ -322,7 +338,7 @@ void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int } } mc->setNodalConnectivity(conn,connI); - loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,MED_POLYHEDRON,entity,mrs); + loadCommonPart(fid,mName,dt,it,curNbOfElem,MED_POLYHEDRON,entity,mrs); } void MEDFileUMeshPerType::Write(med_idt fid, const std::string& mname, int mdim, const MEDCoupling1GTUMesh *m, const DataArrayInt *fam, const DataArrayInt *num, const DataArrayAsciiChar *names) diff --git a/src/MEDLoader/MEDFileMeshElt.hxx b/src/MEDLoader/MEDFileMeshElt.hxx index 59d304ef6..a093fb69d 100644 --- a/src/MEDLoader/MEDFileMeshElt.hxx +++ b/src/MEDLoader/MEDFileMeshElt.hxx @@ -35,7 +35,21 @@ namespace MEDCoupling class MEDCouplingUMesh; class MEDFileMeshReadSelector; - class MEDFileUMeshPerType : public RefCountObject + class MEDFileUMeshPerTypeCommon : public RefCountObject + { + public: + static MEDFileUMeshPerTypeCommon *New(); + void loadCommonPart(med_idt fid, const char *mName, int dt, int it, int curNbOfElem, med_geometry_type geoElt, + med_entity_type entity, MEDFileMeshReadSelector *mrs); + std::size_t getHeapMemorySizeWithoutChildren() const; + std::vector getDirectChildrenWithNull() const; + protected: + MCAuto _num; + MCAuto _fam; + MCAuto _names; + }; + + class MEDFileUMeshPerType : public MEDFileUMeshPerTypeCommon { public: static MEDFileUMeshPerType *New(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType geoElt2, MEDFileMeshReadSelector *mrs); @@ -64,15 +78,10 @@ namespace MEDCoupling med_entity_type entity, MEDFileMeshReadSelector *mrs); void loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, int connFaceLgth, med_geometry_type geoElt, med_entity_type entity, MEDFileMeshReadSelector *mrs); - void loadCommonPart(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, med_entity_type entity, MEDFileMeshReadSelector *mrs); void loadPartOfCellCommonPart(med_idt fid, const char *mName, int strt, int stp, int step, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, med_entity_type entity, MEDFileMeshReadSelector *mrs); private: MCAuto _m; - MCAuto _num; - MCAuto _fam; - MCAuto _names; MCAuto _pd; - med_entity_type _entity; }; } diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index d525358af..3dc52b7bc 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -23,6 +23,8 @@ #include "MEDLoaderBase.hxx" #include "MEDFileSafeCaller.txx" #include "MEDFileMeshReadSelector.hxx" +#include "MEDFileStructureElement.hxx" +#include "MEDFileMeshSupport.hxx" #include "MEDCouplingUMesh.hxx" @@ -2054,3 +2056,43 @@ void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords) if(m) m->setCoords(coords); } + +MEDFileEltStruct4Mesh *MEDFileEltStruct4Mesh::New(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs) +{ + return new MEDFileEltStruct4Mesh(fid,mName,dt,it,iterOnStEltOfMesh,mrs); +} + +std::size_t MEDFileEltStruct4Mesh::getHeapMemorySizeWithoutChildren() const +{ + return _geo_type_name.capacity(); +} + +std::vector MEDFileEltStruct4Mesh::getDirectChildrenWithNull() const +{ + std::vector ret; + ret.push_back(_conn); + ret.push_back(_common); + return ret; +} + +MEDFileEltStruct4Mesh::MEDFileEltStruct4Mesh(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs) +{ + med_geometry_type geoType; + INTERP_KERNEL::AutoPtr geoTypeName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); + MEDFILESAFECALLERRD0(MEDmeshEntityInfo,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,iterOnStEltOfMesh+1,geoTypeName,&geoType)); + _geo_type=geoType; + _geo_type_name=MEDLoaderBase::buildStringFromFortran(geoTypeName,MED_NAME_SIZE); + int nCells(0); + { + med_bool chgt=MED_FALSE,trsf=MED_FALSE; + nCells=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,geoType,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf); + } + MCAuto mss(MEDFileMeshSupports::New(fid)); + MCAuto mse(MEDFileStructureElements::New(fid,mss)); + int nbOfNodesPerCell(mse->getNumberOfNodesPerCellOf(_geo_type_name)); + _conn=DataArrayInt::New(); _conn->alloc(nCells,nbOfNodesPerCell); + 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,)); +} diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 460e2bd06..adbd78e21 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -321,6 +321,24 @@ namespace MEDCoupling mutable MCAuto _rev_num; MEDFileUMeshPermCompute _m; }; + + class MEDFileEltStruct4Mesh : public RefCountObject + { + public: + static MEDFileEltStruct4Mesh *New(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs); + private: + std::size_t getHeapMemorySizeWithoutChildren() const; + std::vector getDirectChildrenWithNull() const; + private: + ~MEDFileEltStruct4Mesh() { } + private: + MEDFileEltStruct4Mesh(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs); + private: + std::string _geo_type_name; + int _geo_type; + MCAuto _conn; + MCAuto _common; + }; } #endif diff --git a/src/MEDLoader/MEDFileMeshSupport.cxx b/src/MEDLoader/MEDFileMeshSupport.cxx index 2d6d0443b..1e101c0c2 100644 --- a/src/MEDLoader/MEDFileMeshSupport.cxx +++ b/src/MEDLoader/MEDFileMeshSupport.cxx @@ -104,3 +104,9 @@ const MEDFileUMesh *MEDFileMeshSupports::getSupMeshWithName(const std::string& n oss << " !"; throw INTERP_KERNEL::Exception(oss.str()); } + +int MEDFileMeshSupports::getNumberOfNodesPerCellOf(const std::string& name) const +{ + const MEDFileUMesh *sup(getSupMeshWithName(name)); + return sup->getNumberOfNodes(); +} diff --git a/src/MEDLoader/MEDFileMeshSupport.hxx b/src/MEDLoader/MEDFileMeshSupport.hxx index cf2b394c3..c94a9ee7d 100644 --- a/src/MEDLoader/MEDFileMeshSupport.hxx +++ b/src/MEDLoader/MEDFileMeshSupport.hxx @@ -39,6 +39,7 @@ namespace MEDCoupling std::size_t getHeapMemorySizeWithoutChildren() const; void writeLL(med_idt fid) const; const MEDFileUMesh *getSupMeshWithName(const std::string& name) const; + int getNumberOfNodesPerCellOf(const std::string& name) const; private: MEDFileMeshSupports(med_idt fid); MEDFileMeshSupports(); diff --git a/src/MEDLoader/MEDFileStructureElement.cxx b/src/MEDLoader/MEDFileStructureElement.cxx index b268b8857..d2de14def 100644 --- a/src/MEDLoader/MEDFileStructureElement.cxx +++ b/src/MEDLoader/MEDFileStructureElement.cxx @@ -261,6 +261,11 @@ TypeOfField MEDFileStructureElement::getEntity() const return _tof; } +std::string MEDFileStructureElement::getMeshName() const +{ + return _sup_mesh_name; +} + //////////////////// MEDFileStructureElements *MEDFileStructureElements::New(med_idt fid, const MEDFileMeshSupports *ms) @@ -296,6 +301,7 @@ MEDFileStructureElements::MEDFileStructureElements(med_idt fid, const MEDFileMes _elems.resize(nbSE); for(int i=0;igetMeshName()); + return _sup->getNumberOfNodesPerCellOf(meshName); +} + +const MEDFileStructureElement *MEDFileStructureElements::getSEWithName(const std::string& seName) const +{ + for(std::vector< MCAuto >::const_iterator it=_elems.begin();it!=_elems.end();it++) + { + if((*it).isNotNull()) + if((*it)->getName()==seName) + return *it; + } + std::ostringstream oss; oss << "MEDFileStructureElements::getSEWithName : no such structure element with name " << seName << " !"; + throw INTERP_KERNEL::Exception(oss.str()); +} + diff --git a/src/MEDLoader/MEDFileStructureElement.hxx b/src/MEDLoader/MEDFileStructureElement.hxx index 25cf14a0c..cdb56aa09 100644 --- a/src/MEDLoader/MEDFileStructureElement.hxx +++ b/src/MEDLoader/MEDFileStructureElement.hxx @@ -85,6 +85,7 @@ class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlon MEDLOADER_EXPORT std::string getName() const; MEDLOADER_EXPORT int getDynGT() const; MEDLOADER_EXPORT TypeOfField getEntity() const; + MEDLOADER_EXPORT std::string getMeshName() const; public: std::vector getDirectChildrenWithNull() const; std::size_t getHeapMemorySizeWithoutChildren() const; @@ -113,6 +114,8 @@ class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlon MEDLOADER_EXPORT int getNumberOf() const; MEDLOADER_EXPORT std::vector getDynGTAvail() const; 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; public: std::vector getDirectChildrenWithNull() const; std::size_t getHeapMemorySizeWithoutChildren() const; @@ -123,6 +126,7 @@ class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlon ~MEDFileStructureElements(); private: std::vector< MCAuto > _elems; + MCConstAuto _sup; }; }