From 11c1cdbc34076d5a088f15ec681216aad8681e44 Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 1 Jul 2013 11:08:35 +0000 Subject: [PATCH] MED file mesh loading on demand. --- src/MEDLoader/MEDFileMesh.cxx | 79 +++++++++++++------- src/MEDLoader/MEDFileMesh.hxx | 2 +- src/MEDLoader/MEDFileMeshElt.cxx | 73 ++++++++++-------- src/MEDLoader/MEDFileMeshElt.hxx | 13 ++-- src/MEDLoader/MEDFileMeshLL.cxx | 15 ++-- src/MEDLoader/MEDFileMeshLL.hxx | 8 +- src/MEDLoader/Swig/MEDLoaderTest3.py | 108 +++++++++++++++++++++++++++ 7 files changed, 221 insertions(+), 77 deletions(-) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 7099c550f..74a40b7f0 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -2125,7 +2125,7 @@ void MEDFileUMesh::loadUMeshFromFile(med_idt fid, const char *mName, int dt, int std::ostringstream oss; oss << "Trying to load as unstructured an existing mesh with name '" << mName << "' !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - loaderl2.loadAll(fid,mid,mName,dt,it); + loaderl2.loadAll(fid,mid,mName,dt,it,mrs); int lev=loaderl2.getNumberOfLevels(); _ms.resize(lev); for(int i=0;iisNodeFamilyFieldReading()) + _fam_coords=loaderl2.getCoordsFamily(); + if(!mrs || mrs->isNodeNumFieldReading()) + _num_coords=loaderl2.getCoordsNum(); + if(!mrs || mrs->isNodeNameFieldReading()) + _name_coords=loaderl2.getCoordsName(); computeRevNum(); } @@ -4331,7 +4334,7 @@ med_geometry_type MEDFileStructuredMesh::GetGeoTypeFromMeshDim(int meshDim) thro return geoTypeReq; } -void MEDFileStructuredMesh::loadStrMeshFromFile(MEDFileStrMeshL2 *strm, med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +void MEDFileStructuredMesh::loadStrMeshFromFile(MEDFileStrMeshL2 *strm, med_idt fid, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs) throw(INTERP_KERNEL::Exception) { setName(strm->getName()); setDescription(strm->getDescription()); @@ -4340,53 +4343,71 @@ void MEDFileStructuredMesh::loadStrMeshFromFile(MEDFileStrMeshL2 *strm, med_idt setOrder(strm->getOrder()); setTimeValue(strm->getTime()); setTimeUnit(strm->getTimeUnit()); - MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups); + MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups,mrs); med_bool chgt=MED_FALSE,trsf=MED_FALSE; int nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf); if(nbOfElt>0) { - _fam_nodes=DataArrayInt::New(); - _fam_nodes->alloc(nbOfElt,1); - MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_fam_nodes->getPointer()); + if(!mrs || mrs->isNodeFamilyFieldReading()) + { + _fam_nodes=DataArrayInt::New(); + _fam_nodes->alloc(nbOfElt,1); + MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_fam_nodes->getPointer()); + } } nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_NUMBER,MED_NODAL,&chgt,&trsf); if(nbOfElt>0) { - _num_nodes=DataArrayInt::New(); - _num_nodes->alloc(nbOfElt,1); - MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_num_nodes->getPointer()); + if(!mrs || mrs->isNodeNumFieldReading()) + { + _num_nodes=DataArrayInt::New(); + _num_nodes->alloc(nbOfElt,1); + MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_num_nodes->getPointer()); + } } int meshDim=getStructuredMesh()->getMeshDimension(); med_geometry_type geoTypeReq=GetGeoTypeFromMeshDim(meshDim); nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf); if(nbOfElt>0) { - _fam_cells=DataArrayInt::New(); - _fam_cells->alloc(nbOfElt,1); - MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_fam_cells->getPointer()); + if(!mrs || mrs->isCellFamilyFieldReading()) + { + _fam_cells=DataArrayInt::New(); + _fam_cells->alloc(nbOfElt,1); + MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_fam_cells->getPointer()); + } } nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_NUMBER,MED_NODAL,&chgt,&trsf); if(nbOfElt>0) { - _num_cells=DataArrayInt::New(); - _num_cells->alloc(nbOfElt,1); - MEDmeshEntityNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_num_cells->getPointer()); + if(!mrs || mrs->isCellNumFieldReading()) + { + _num_cells=DataArrayInt::New(); + _num_cells->alloc(nbOfElt,1); + MEDmeshEntityNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_num_cells->getPointer()); + } } nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_NAME,MED_NODAL,&chgt,&trsf); if(nbOfElt>0) { - _names_cells=DataArrayAsciiChar::New(); - _names_cells->alloc(nbOfElt+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end - MEDmeshEntityNameRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_names_cells->getPointer()); - _names_cells->reAlloc(nbOfElt);//not a bug to avoid the memory corruption due to last \0 at the end + if(!mrs || mrs->isCellNameFieldReading()) + { + _names_cells=DataArrayAsciiChar::New(); + _names_cells->alloc(nbOfElt+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end + MEDmeshEntityNameRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_names_cells->getPointer()); + _names_cells->reAlloc(nbOfElt);//not a bug to avoid the memory corruption due to last \0 at the end + } } nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_NAME,MED_NODAL,&chgt,&trsf); if(nbOfElt>0) { - _names_nodes=DataArrayAsciiChar::New(); - _names_nodes->alloc(nbOfElt+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end - MEDmeshEntityNameRd(fid,mName,dt,it,MED_NODE,MED_NONE,_names_nodes->getPointer()); - _names_nodes->reAlloc(nbOfElt);//not a bug to avoid the memory corruption due to last \0 at the end + if(!mrs || mrs->isNodeNameFieldReading()) + { + _names_nodes=DataArrayAsciiChar::New(); + _names_nodes->alloc(nbOfElt+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end + MEDmeshEntityNameRd(fid,mName,dt,it,MED_NODE,MED_NONE,_names_nodes->getPointer()); + _names_nodes->reAlloc(nbOfElt);//not a bug to avoid the memory corruption due to last \0 at the end + } } } @@ -4620,7 +4641,7 @@ void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const char *mName, int dt, int MEDCouplingCMesh *mesh=loaderl2.getMesh(); mesh->incrRef(); _cmesh=mesh; - loadStrMeshFromFile(&loaderl2,fid,mName,dt,it); + loadStrMeshFromFile(&loaderl2,fid,mName,dt,it,mrs); } /*! @@ -4902,7 +4923,7 @@ void MEDFileCurveLinearMesh::loadCLMeshFromFile(med_idt fid, const char *mName, MEDCouplingCurveLinearMesh *mesh=loaderl2.getMesh(); mesh->incrRef(); _clmesh=mesh; - loadStrMeshFromFile(&loaderl2,fid,mName,dt,it); + loadStrMeshFromFile(&loaderl2,fid,mName,dt,it,mrs); } MEDFileMeshMultiTS *MEDFileMeshMultiTS::New() diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 590ef84fb..1d69a413a 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -306,7 +306,7 @@ namespace ParaMEDMEM protected: void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception); void deepCpyAttributes() throw(INTERP_KERNEL::Exception); - void loadStrMeshFromFile(MEDFileStrMeshL2 *strm, med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); + void loadStrMeshFromFile(MEDFileStrMeshL2 *strm, med_idt fid, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs) throw(INTERP_KERNEL::Exception); void writeStructuredLL(med_idt fid, const char *maa) const throw(INTERP_KERNEL::Exception); virtual const MEDCouplingStructuredMesh *getStructuredMesh() const = 0; static med_geometry_type GetGeoTypeFromMeshDim(int meshDim) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx index 510ea78d2..6321d76bc 100644 --- a/src/MEDLoader/MEDFileMeshElt.cxx +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -19,6 +19,7 @@ // Author : Anthony Geay (CEA/DEN) #include "MEDFileMeshElt.hxx" +#include "MEDFileMeshReadSelector.hxx" #include "MEDCouplingUMesh.hxx" @@ -31,12 +32,12 @@ extern med_geometry_type typmai3[32]; using namespace ParaMEDMEM; -MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType geoElt2) +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; if(!isExisting(fid,mName,dt,it,geoElt,whichEntity)) return 0; - return new MEDFileUMeshPerType(fid,mName,dt,it,mdim,geoElt,geoElt2,whichEntity); + return new MEDFileUMeshPerType(fid,mName,dt,it,mdim,geoElt,geoElt2,whichEntity,mrs); } bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, int dt, int it, med_geometry_type geoElt, med_entity_type& whichEntity) @@ -66,27 +67,27 @@ int MEDFileUMeshPerType::getDim() const } 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):_type(type),_entity(entity) + med_entity_type entity, MEDFileMeshReadSelector *mrs):_type(type),_entity(entity) { med_bool changement,transformation; int curNbOfElem=MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL, &changement,&transformation); if(type!=INTERP_KERNEL::NORM_POLYGON && type!=INTERP_KERNEL::NORM_POLYHED) { - loadFromStaticType(fid,mName,dt,it,mdim,curNbOfElem,geoElt,type,entity); + loadFromStaticType(fid,mName,dt,it,mdim,curNbOfElem,geoElt,type,entity,mrs); return; } if(type==INTERP_KERNEL::NORM_POLYGON) { - loadPolyg(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity); + loadPolyg(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity,mrs); return; } //if(type==INTERP_KERNEL::NORM_POLYHED) - loadPolyh(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity); + loadPolyh(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity,mrs); } void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type, - med_entity_type entity) + med_entity_type entity, MEDFileMeshReadSelector *mrs) { _conn=DataArrayInt::New(); int nbOfNodesPerCell=(geoElt%100); @@ -95,7 +96,7 @@ void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int _conn_index->alloc(curNbOfElem+1,1); INTERP_KERNEL::AutoPtr connTab=new int[(nbOfNodesPerCell)*curNbOfElem]; MEDmeshElementConnectivityRd(fid,mName,dt,it,entity,geoElt,MED_NODAL,MED_FULL_INTERLACE,connTab); - loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity); + loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity,mrs); int *w1=_conn->getPointer(); int *w2=_conn_index->getPointer(); *w2++=0; @@ -109,40 +110,48 @@ void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int } 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) + med_entity_type entity, MEDFileMeshReadSelector *mrs) { med_bool changement,transformation; - _fam=DataArrayInt::New(); - _fam->alloc(curNbOfElem,1); + _fam=0; if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0) - { - if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,entity,geoElt,_fam->getPointer())!=0) - std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,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); + } } - else - 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) { - _num=DataArrayInt::New(); - _num->alloc(curNbOfElem,1); - if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,geoElt,_num->getPointer())!=0) - _num=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; + } } - else - _num=0; + _names=0; if(MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_NAME,MED_NODAL,&changement,&transformation)>0) { - _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 + 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::loadPolyg(med_idt fid, const char *mName, int dt, int it, int mdim, int arraySize, med_geometry_type geoElt, - med_entity_type entity) + med_entity_type entity, MEDFileMeshReadSelector *mrs) { med_bool changement,transformation; med_int curNbOfElem=MEDmeshnEntity(fid,mName,dt,it,entity,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1; @@ -164,11 +173,11 @@ void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int dt, int *w2=*w2-1+i; } *w2=*w2-1+curNbOfElem; - loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,MED_POLYGON,entity); + loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,MED_POLYGON,entity,mrs); } void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, int connFaceLgth, med_geometry_type geoElt, - med_entity_type entity) + med_entity_type entity, MEDFileMeshReadSelector *mrs) { med_bool changement,transformation; med_int indexFaceLgth=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation); @@ -198,7 +207,7 @@ void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int wFinalConn=std::transform(locConn+indexFace[j]-1,locConn+indexFace[j+1]-1,wFinalConn,std::bind2nd(std::plus(),-1)); } } - loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,MED_POLYHEDRON,entity); + loadCommonPart(fid,mName,dt,it,mdim,curNbOfElem,MED_POLYHEDRON,entity,mrs); } void MEDFileUMeshPerType::write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num, const DataArrayAsciiChar *names) diff --git a/src/MEDLoader/MEDFileMeshElt.hxx b/src/MEDLoader/MEDFileMeshElt.hxx index 472239a87..f870ef208 100644 --- a/src/MEDLoader/MEDFileMeshElt.hxx +++ b/src/MEDLoader/MEDFileMeshElt.hxx @@ -31,11 +31,12 @@ namespace ParaMEDMEM { class MEDCouplingUMesh; + class MEDFileMeshReadSelector; class MEDFileUMeshPerType : public RefCountObject { public: - static MEDFileUMeshPerType *New(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType geoElt2); + 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); static bool isExisting(med_idt fid, const char *mName, int dt, int it, med_geometry_type geoElt, med_entity_type& whichEntity); std::size_t getHeapMemorySize() const { return 0; } int getDim() const; @@ -47,14 +48,14 @@ namespace ParaMEDMEM static void write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num, const DataArrayAsciiChar *names); private: 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); + med_entity_type entity, MEDFileMeshReadSelector *mrs); void loadFromStaticType(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type, - med_entity_type entity); + med_entity_type entity, MEDFileMeshReadSelector *mrs); void loadPolyg(med_idt fid, const char *mName, int dt, int it, int mdim, int arraySize, med_geometry_type geoElt, - med_entity_type entity); + 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); - void loadCommonPart(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, med_entity_type entity); + 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); private: MEDCouplingAutoRefCountObjectPtr _conn; MEDCouplingAutoRefCountObjectPtr _conn_index; diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 00eb2c637..5ff4d8669 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -21,6 +21,7 @@ #include "MEDFileMeshLL.hxx" #include "MEDFileMesh.hxx" #include "MEDLoaderBase.hxx" +#include "MEDFileMeshReadSelector.hxx" #include "MEDCouplingUMesh.hxx" @@ -71,7 +72,7 @@ int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const char *mname, ParaMEDMEM: if(!found) { std::ostringstream oss; - oss << "No such meshname (" << mname << ") in file ! Must be in :"; + oss << "No such meshname (" << mname << ") in file ! Must be in : "; std::copy(ms.begin(),ms.end(),std::ostream_iterator(oss,", ")); throw INTERP_KERNEL::Exception(oss.str().c_str()); } @@ -180,8 +181,10 @@ std::vector MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, return infosOnComp; } -void MEDFileMeshL2::ReadFamiliesAndGrps(med_idt fid, const char *meshName, std::map& fams, std::map >& grps) +void MEDFileMeshL2::ReadFamiliesAndGrps(med_idt fid, const char *meshName, std::map& fams, std::map >& grps, MEDFileMeshReadSelector *mrs) { + if(mrs && !(mrs->isCellFamilyFieldReading() || mrs->isNodeFamilyFieldReading())) + return ; char nomfam[MED_NAME_SIZE+1]; med_int numfam; int nfam=MEDnFamily(fid,meshName); @@ -230,7 +233,7 @@ MEDFileUMeshL2::MEDFileUMeshL2() { } -void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const char *mName, int dt, int it) +void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs) { _name.set(mName); int nstep; @@ -242,17 +245,17 @@ void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const char *mName, int dt, in _time=CheckMeshTimeStep(fid,mName,nstep,dt,it); _iteration=dt; _order=it; - loadConnectivity(fid,Mdim,mName,dt,it);//to improve check (dt,it) coherency + loadConnectivity(fid,Mdim,mName,dt,it,mrs);//to improve check (dt,it) coherency loadCoords(fid,mId,infosOnComp,mName,dt,it); } -void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it) +void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs) { _per_type_mesh.resize(1); _per_type_mesh[0].clear(); for(int j=0;j getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception); static int GetMeshIdFromName(med_idt fid, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception); static double CheckMeshTimeStep(med_idt fid, const char *mname, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception); - static void ReadFamiliesAndGrps(med_idt fid, const char *mname, std::map& fams, std::map >& grps); + static void ReadFamiliesAndGrps(med_idt fid, const char *mname, std::map& fams, std::map >& grps, MEDFileMeshReadSelector *mrs); static void WriteFamiliesAndGrps(med_idt fid, const char *mname, const std::map& fams, const std::map >& grps, int tooLongStrPol); protected: MEDFileString _name; @@ -66,8 +68,8 @@ namespace ParaMEDMEM { public: MEDFileUMeshL2(); - void loadAll(med_idt fid, int mId, const char *mName, int dt, int it); - void loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it); + void loadAll(med_idt fid, int mId, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs); + void loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs); void loadCoords(med_idt fid, int mId, const std::vector& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); int getNumberOfLevels() const { return _per_type_mesh.size(); } bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); } diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 38cc037b5..a0508b9b2 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -3125,6 +3125,114 @@ class MEDLoaderTest(unittest.TestCase): mrs.setNodeNumFieldReading(True) self.assertEqual(mrs.getCode(),63) pass + + def testPartialReadOfMeshes(self): + fname="Pyfile70.med" + # building a mesh containing 4 tri3 + 5 quad4 + tri=MEDCouplingUMesh("tri",2) + tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2]) + tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)])) + tris=[tri.deepCpy() for i in xrange(4)] + for i,elt in enumerate(tris): elt.translate([i,0]) + tris=MEDCouplingUMesh.MergeUMeshes(tris) + quad=MEDCouplingUMesh("quad",2) + quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3]) + quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)])) + quads=[quad.deepCpy() for i in xrange(5)] + for i,elt in enumerate(quads): elt.translate([5+i,0]) + quads=MEDCouplingUMesh.MergeUMeshes(quads) + m=MEDCouplingUMesh.MergeUMeshes(tris,quads) + m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"]) + m1=m.buildDescendingConnectivity()[0] + mm=MEDFileUMesh() ; mm.setMeshes([m,m1]) + # + grp0=DataArrayInt([1,2,3,5,6]) ; grp0.setName("grp0") + grp1=DataArrayInt([1,2,3,5,7,8]) ; grp1.setName("grp1") + mm.setGroupsAtLevel(0,[grp0,grp1]) + grp2=DataArrayInt.Range(0,32,2) ; grp2.setName("grp2") + grp3=DataArrayInt.Range(1,32,7) ; grp3.setName("grp3") + mm.setGroupsAtLevel(-1,[grp2,grp3]) + grp4=DataArrayInt.Range(0,32,2) ; grp4.setName("grp4") + grp5=DataArrayInt.Range(1,32,7) ; grp5.setName("grp5") + mm.setGroupsAtLevel(1,[grp4,grp5]) + mm.setRenumFieldArr(0,DataArrayInt.Range(2,11,1)) + mm.setRenumFieldArr(-1,DataArrayInt.Range(3,35,1)) + mm.setRenumFieldArr(1,DataArrayInt.Range(4,36,1)) + # + mm.write(fname,2) + ## + mm=MEDFileMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector()) + ref_heap_mem=mm.getHeapMemorySize() + # + mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(0)) + self.assertEqual(len(mm.getGroupsNames()),0) + self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13)) + self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13)) + self.assertTrue(mm.getFamilyFieldAtLevel(0) is None) + self.assertTrue(mm.getFamilyFieldAtLevel(-1) is None) + self.assertTrue(mm.getFamilyFieldAtLevel(1) is None) + self.assertTrue(mm.getNumberFieldAtLevel(0) is None) + self.assertTrue(mm.getNumberFieldAtLevel(-1) is None) + self.assertTrue(mm.getNumberFieldAtLevel(1) is None) + delta1=ref_heap_mem-mm.getHeapMemorySize() + self.assertTrue(delta1>=4*(32+9)*3+32*4*3) + # + mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(1)) + self.assertEqual(len(mm.getGroupsNames()),6) + self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13)) + self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13)) + self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None) + self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None) + self.assertTrue(mm.getFamilyFieldAtLevel(1) is None) + self.assertTrue(mm.getNumberFieldAtLevel(0) is None) + self.assertTrue(mm.getNumberFieldAtLevel(-1) is None) + self.assertTrue(mm.getNumberFieldAtLevel(1) is None) + delta2=ref_heap_mem-mm.getHeapMemorySize() + self.assertTrue(delta2=4*(32+9)*1+32*4*3) + # + mm=MEDFileUMesh(fname,MEDFileMeshReadSelector(3)) + self.assertEqual(len(mm.getGroupsNames()),6) + self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13)) + self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13)) + self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None) + self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None) + self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None) + self.assertTrue(mm.getNumberFieldAtLevel(0) is None) + self.assertTrue(mm.getNumberFieldAtLevel(-1) is None) + self.assertTrue(mm.getNumberFieldAtLevel(1) is None) + delta3=ref_heap_mem-mm.getHeapMemorySize() + self.assertTrue(delta3=4*(32+9)*1+32*4*1) + # + mm=MEDFileUMesh(fname,"mesh",-1,-1,MEDFileMeshReadSelector(19)) + self.assertEqual(len(mm.getGroupsNames()),6) + self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13)) + self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13)) + self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None) + self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None) + self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None) + self.assertTrue(mm.getNumberFieldAtLevel(0)!=None) + self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None) + self.assertTrue(mm.getNumberFieldAtLevel(1) is None) + delta4=ref_heap_mem-mm.getHeapMemorySize() + self.assertTrue(delta4=32*4*2) + # + mm=MEDFileUMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector(51)) + self.assertEqual(len(mm.getGroupsNames()),6) + self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13)) + self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13)) + self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None) + self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None) + self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None) + self.assertTrue(mm.getNumberFieldAtLevel(0)!=None) + self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None) + self.assertTrue(mm.getNumberFieldAtLevel(1)!=None) + delta5=ref_heap_mem-mm.getHeapMemorySize() + self.assertTrue(delta5