From: ageay Date: Fri, 19 Jul 2013 15:32:47 +0000 (+0000) Subject: On the highway to MEDReader : X-Git-Tag: B4PolyhIntersect~72 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ff35258615518d41d02c82e8d32569c1f0a9fdc9;p=modules%2Fmed.git On the highway to MEDReader : - umesh is no more used as base mesh to store chunks coming from MEDFile It saves memory and allows to go to VTK data structure without overhead for MEDReader. --- diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index 8a8034b61..2fa8f049e 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -616,9 +616,8 @@ bool MEDCoupling1SGTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *o return true; } -void MEDCoupling1SGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) +void MEDCoupling1SGTUMesh::checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception) { - MEDCouplingPointSet::checkCoherency(); const DataArrayInt *c1(_conn); if(c1) { @@ -632,6 +631,12 @@ void MEDCoupling1SGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception throw INTERP_KERNEL::Exception("Nodal connectivity array not defined !"); } +void MEDCoupling1SGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingPointSet::checkCoherency(); + checkCoherencyOfConnectivity(); +} + void MEDCoupling1SGTUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception) { checkCoherency(); @@ -1649,14 +1654,8 @@ void MEDCoupling1DGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, do } } -/*! - * If \a this pass this method, you are sure that connectivity arrays are not null, with exactly one component, no name, no component name, allocated. - * In addition you are sure that the length of nodal connectivity index array is bigger than or equal to one. - * In addition you are also sure that length of nodal connectivity is coherent with the content of the last value in the index array. - */ -void MEDCoupling1DGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) +void MEDCoupling1DGTUMesh::checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception) { - MEDCouplingPointSet::checkCoherency(); const DataArrayInt *c1(_conn); if(c1) { @@ -1702,11 +1701,22 @@ void MEDCoupling1DGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception int szOfC1Exp=_conn_indx->back(); if(sz2getNumberOfTuples() << " !"; + std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::checkCoherencyOfConnectivity : The expected length of nodal connectivity array regarding index is " << szOfC1Exp << " but the actual size of it is " << c1->getNumberOfTuples() << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } } +/*! + * If \a this pass this method, you are sure that connectivity arrays are not null, with exactly one component, no name, no component name, allocated. + * In addition you are sure that the length of nodal connectivity index array is bigger than or equal to one. + * In addition you are also sure that length of nodal connectivity is coherent with the content of the last value in the index array. + */ +void MEDCoupling1DGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingPointSet::checkCoherency(); + checkCoherencyOfConnectivity(); +} + void MEDCoupling1DGTUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception) { checkCoherency(); @@ -1735,7 +1745,7 @@ void MEDCoupling1DGTUMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL int MEDCoupling1DGTUMesh::getNumberOfCells() const { - checkCoherency();//do not remove + checkCoherencyOfConnectivity();//do not remove return _conn_indx->getNumberOfTuples()-1; } diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx index 748992d3f..723234f49 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx @@ -71,6 +71,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT virtual void allocateCells(int nbOfCells=0) throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT virtual void insertNextCell(const int *nodalConnOfCellBg, const int *nodalConnOfCellEnd) throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT virtual DataArrayInt *getNodalConnectivity() const throw(INTERP_KERNEL::Exception) = 0; + MEDCOUPLING_EXPORT virtual void checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception) = 0; protected: MEDCOUPLING_EXPORT MEDCoupling1GTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm); MEDCOUPLING_EXPORT MEDCoupling1GTUMesh(const MEDCoupling1GTUMesh& other, bool recDeepCpy); @@ -121,6 +122,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void renumberNodesInConn(const int *newNodeNumbersO2N); MEDCOUPLING_EXPORT void fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const; // overload of MEDCoupling1GTUMesh + MEDCOUPLING_EXPORT void checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void allocateCells(int nbOfCells=0) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void insertNextCell(const int *nodalConnOfCellBg, const int *nodalConnOfCellEnd) throw(INTERP_KERNEL::Exception); public://specific @@ -188,6 +190,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void renumberNodesInConn(const int *newNodeNumbersO2N); MEDCOUPLING_EXPORT void fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const; // overload of MEDCoupling1GTUMesh + MEDCOUPLING_EXPORT void checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void allocateCells(int nbOfCells=0) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void insertNextCell(const int *nodalConnOfCellBg, const int *nodalConnOfCellEnd) throw(INTERP_KERNEL::Exception); public://specific diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 01b9c156f..f90c9c49a 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -3129,7 +3129,7 @@ MEDCouplingPointSet *MEDCouplingUMesh::buildPartOfMySelfKeepCoords2(int start, i */ MEDCouplingPointSet *MEDCouplingUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const { - checkFullyDefined(); + checkConnectivityFullyDefined(); int ncell=getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingUMesh::New(); ret->_mesh_dim=_mesh_dim; @@ -6671,7 +6671,7 @@ DataArrayInt *MEDCouplingUMesh::rearrange2ConsecutiveCellTypes() */ std::vector MEDCouplingUMesh::splitByType() const { - checkFullyDefined(); + checkConnectivityFullyDefined(); const int *conn=_nodal_connec->getConstPointer(); const int *connI=_nodal_connec_index->getConstPointer(); int nbOfCells=getNumberOfCells(); diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index dd1ae5fbc..dad36a1bb 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -2765,6 +2765,7 @@ namespace ParaMEDMEM INTERP_KERNEL::NormalizedCellType getCellModelEnum() const throw(INTERP_KERNEL::Exception); int getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception); virtual void allocateCells(int nbOfCells=0) throw(INTERP_KERNEL::Exception); + virtual void checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception); %extend { virtual void insertNextCell(PyObject *li) throw(INTERP_KERNEL::Exception) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 638681ece..986265c53 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -1962,7 +1962,7 @@ MEDFileMesh *MEDFileUMesh::deepCpy() const throw(INTERP_KERNEL::Exception) for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++) { if((const MEDFileUMeshSplitL1 *)(*it)) - ret->_ms[i]=(*it)->deepCpy(); + ret->_ms[i]=(*it)->deepCpy(ret->_coords); } return ret.retn(); } @@ -2983,7 +2983,6 @@ void MEDFileUMesh::checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const * \param [in] coords - the new node coordinates array. * \throw If \a coords == \c NULL. */ - void MEDFileUMesh::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception) { if(!coords) @@ -2995,6 +2994,9 @@ void MEDFileUMesh::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Excep _fam_coords=DataArrayInt::New(); _fam_coords->alloc(nbOfTuples,1); _fam_coords->fillWithZero(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_ms.begin();it!=_ms.end();it++) + if((MEDFileUMeshSplitL1 *)(*it)) + (*it)->setCoords(coords); } /*! diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx index 6321d76bc..0725d6890 100644 --- a/src/MEDLoader/MEDFileMeshElt.cxx +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -62,17 +62,17 @@ bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, int dt, int int MEDFileUMeshPerType::getDim() const { - const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_type); - return cm.getDimension(); + return _m->getMeshDimension(); } 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):_type(type),_entity(entity) + med_entity_type entity, MEDFileMeshReadSelector *mrs):_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) + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); + if(!cm.isDynamic()) { loadFromStaticType(fid,mName,dt,it,mdim,curNbOfElem,geoElt,type,entity,mrs); return; @@ -89,24 +89,15 @@ MEDFileUMeshPerType::MEDFileUMeshPerType(med_idt fid, const char *mName, int dt, 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, MEDFileMeshReadSelector *mrs) { - _conn=DataArrayInt::New(); - int nbOfNodesPerCell=(geoElt%100); - _conn->alloc((nbOfNodesPerCell+1)*curNbOfElem,1); - _conn_index=DataArrayInt::New(); - _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); + _m=MEDCoupling1SGTUMesh::New(mName,type); + MEDCoupling1SGTUMesh *mc(dynamic_cast((MEDCoupling1GTUMesh *)_m)); + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()); + int nbOfNodesPerCell=mc->getNumberOfNodesPerCell(); + conn->alloc(nbOfNodesPerCell*curNbOfElem,1); + 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); - int *w1=_conn->getPointer(); - int *w2=_conn_index->getPointer(); - *w2++=0; - const int *wi=connTab; - for(int i=0;i(),-1)); - *w2=w2[-1]+nbOfNodesPerCell+1; - } } void MEDFileUMeshPerType::loadCommonPart(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, @@ -155,24 +146,14 @@ void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int dt, int { med_bool changement,transformation; med_int curNbOfElem=MEDmeshnEntity(fid,mName,dt,it,entity,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1; - _conn_index=DataArrayInt::New(); - _conn_index->alloc(curNbOfElem+1,1); - _conn=DataArrayInt::New(); - _conn->alloc(arraySize+curNbOfElem,1); - INTERP_KERNEL::AutoPtr locConn=new int[arraySize]; - MEDmeshPolygonRd(fid,mName,dt,it,MED_CELL,MED_NODAL,_conn_index->getPointer(),locConn); - int *w1=_conn->getPointer(); - int *w2=_conn_index->getPointer(); - const int *wi=locConn; - for(int i=0;i(),-1)); - wi=wi2; - *w2=*w2-1+i; - } - *w2=*w2-1+curNbOfElem; + _m=MEDCoupling1DGTUMesh::New(mName,INTERP_KERNEL::NORM_POLYGON); + MEDCoupling1DGTUMesh *mc(dynamic_cast((MEDCoupling1GTUMesh *)_m)); + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()),connI(DataArrayInt::New()); + conn->alloc(arraySize,1); connI->alloc(curNbOfElem+1,1); + MEDmeshPolygonRd(fid,mName,dt,it,MED_CELL,MED_NODAL,connI->getPointer(),conn->getPointer()); + 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,MED_POLYGON,entity,mrs); } @@ -182,24 +163,25 @@ void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int med_bool changement,transformation; med_int indexFaceLgth=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation); int curNbOfElem=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1; + _m=MEDCoupling1DGTUMesh::New(mName,INTERP_KERNEL::NORM_POLYHED); + MEDCoupling1DGTUMesh *mc(dynamic_cast((MEDCoupling1GTUMesh *)_m)); INTERP_KERNEL::AutoPtr index=new int[curNbOfElem+1]; INTERP_KERNEL::AutoPtr indexFace=new int[indexFaceLgth]; INTERP_KERNEL::AutoPtr locConn=new int[connFaceLgth]; MEDmeshPolyhedronRd(fid,mName,dt,it,MED_CELL,MED_NODAL,index,indexFace,locConn); + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()),connI(DataArrayInt::New()); int arraySize=connFaceLgth; for(int i=0;ialloc(arraySize+curNbOfElem,1); - int *wFinalConn=_conn->getPointer(); - _conn_index=DataArrayInt::New(); - _conn_index->alloc(curNbOfElem+1,1); - int *finalIndex=_conn_index->getPointer(); + conn=DataArrayInt::New(); + conn->alloc(arraySize,1); + int *wFinalConn=conn->getPointer(); + connI->alloc(curNbOfElem+1,1); + int *finalIndex(connI->getPointer()); finalIndex[0]=0; for(int i=0;i(),-1)); for(int j=index[i];j(),-1)); } } + mc->setNodalConnectivity(conn,connI); 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) +void MEDFileUMeshPerType::Write(med_idt fid, const char *mname, int mdim, const MEDCoupling1GTUMesh *m, const DataArrayInt *fam, const DataArrayInt *num, const DataArrayAsciiChar *names) { int nbOfCells=m->getNumberOfCells(); if(nbOfCells<1) @@ -220,46 +203,42 @@ void MEDFileUMeshPerType::write(med_idt fid, const char *mname, int mdim, const INTERP_KERNEL::NormalizedCellType ikt=m->getTypeOfCell(0); const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(ikt); med_geometry_type curMedType=typmai3[(int)ikt]; - const int *conn=m->getNodalConnectivity()->getConstPointer(); - const int *connI=m->getNodalConnectivityIndex()->getConstPointer(); - if(ikt!=INTERP_KERNEL::NORM_POLYGON && ikt!=INTERP_KERNEL::NORM_POLYHED) + if(!cm.isDynamic()) { - int nbNodesPerCell=cm.getNumberOfNodes(); - INTERP_KERNEL::AutoPtr tab=new int[nbNodesPerCell*nbOfCells]; - int *w=tab; - for(int i=0;i(),1)); - MEDmeshElementConnectivityWr(fid,mname,dt,it,timm,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,nbOfCells,tab); + const MEDCoupling1SGTUMesh *m0(dynamic_cast(m)); + if(!m0) + throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::Write : internal error #1 !"); + MEDCouplingAutoRefCountObjectPtr arr(m0->getNodalConnectivity()->deepCpy()); + std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind2nd(std::plus(),1)); + MEDmeshElementConnectivityWr(fid,mname,dt,it,timm,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,nbOfCells,arr->begin()); } else { + const MEDCoupling1DGTUMesh *m0(dynamic_cast(m)); + if(!m0) + throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::Write : internal error #2 !"); if(ikt==INTERP_KERNEL::NORM_POLYGON) { - INTERP_KERNEL::AutoPtr tab1=new int[nbOfCells+1]; - INTERP_KERNEL::AutoPtr tab2=new int[m->getMeshLength()]; - int *wI=tab1; *wI=1; - int *w=tab2; - for(int i=0;i(),1)); - } - MEDmeshPolygonWr(fid,mname,dt,it,timm,MED_CELL,MED_NODAL,nbOfCells+1,tab1,tab2); + MEDCouplingAutoRefCountObjectPtr arr(m0->getNodalConnectivity()->deepCpy()),arrI(m0->getNodalConnectivityIndex()->deepCpy()); + std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind2nd(std::plus(),1)); + std::transform(arrI->begin(),arrI->end(),arrI->getPointer(),std::bind2nd(std::plus(),1)); + MEDmeshPolygonWr(fid,mname,dt,it,timm,MED_CELL,MED_NODAL,nbOfCells+1,arrI->begin(),arr->begin()); } else { - int meshLgth=m->getMeshLength(); + const int *conn(m0->getNodalConnectivity()->begin()),*connI(m0->getNodalConnectivityIndex()->begin()); + int meshLgth=m0->getNodalConnectivityLength(); int nbOfFaces=std::count(conn,conn+meshLgth,-1)+nbOfCells; INTERP_KERNEL::AutoPtr tab1=new int[nbOfCells+1]; int *w1=tab1; *w1=1; INTERP_KERNEL::AutoPtr tab2=new int[nbOfFaces+1]; int *w2=tab2; *w2=1; - INTERP_KERNEL::AutoPtr bigtab=new int[meshLgth-nbOfCells]; + INTERP_KERNEL::AutoPtr bigtab=new int[meshLgth]; int *bt=bigtab; for(int i=0;i(),1)); diff --git a/src/MEDLoader/MEDFileMeshElt.hxx b/src/MEDLoader/MEDFileMeshElt.hxx index f870ef208..af728268a 100644 --- a/src/MEDLoader/MEDFileMeshElt.hxx +++ b/src/MEDLoader/MEDFileMeshElt.hxx @@ -22,6 +22,7 @@ #define __MEDFILEMESHELT_HXX__ #include "MEDCouplingMemArray.hxx" +#include "MEDCoupling1GTUMesh.hxx" #include "MEDCouplingAutoRefCountObjectPtr.hxx" #include "NormalizedUnstructuredMesh.hxx" @@ -40,12 +41,11 @@ namespace ParaMEDMEM 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; - const DataArrayInt *getNodal() const { return _conn; } - const DataArrayInt *getNodalIndex() const { return _conn_index; } + MEDCoupling1GTUMesh *getMesh() const { return const_cast((const MEDCoupling1GTUMesh *)_m); } const DataArrayInt *getFam() const { return _fam; } const DataArrayInt *getNum() const { return _num; } const DataArrayAsciiChar *getNames() const { return _names; } - static void write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num, const DataArrayAsciiChar *names); + static void Write(med_idt fid, const char *mname, int mdim, const MEDCoupling1GTUMesh *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, MEDFileMeshReadSelector *mrs); @@ -57,12 +57,10 @@ namespace ParaMEDMEM 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; + MEDCouplingAutoRefCountObjectPtr _m; MEDCouplingAutoRefCountObjectPtr _num; MEDCouplingAutoRefCountObjectPtr _fam; MEDCouplingAutoRefCountObjectPtr _names; - INTERP_KERNEL::NormalizedCellType _type; med_entity_type _entity; }; } diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 5ff4d8669..ea4206e0d 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -467,23 +467,22 @@ MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st): */ MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const { - _st->_m_by_types->updateTime(); _st->_num->updateTime(); if((MEDCouplingUMesh *)_m==0) { updateTime(); - _m=static_cast(_st->_m_by_types->deepCpy()); + _m=static_cast(_st->_m_by_types.getUmesh()->deepCpy()); _m->renumberCells(_st->_num->getConstPointer(),true); return _m.retn(); } else { - if(_mpt_time==_st->_m_by_types->getTimeOfThis() && _num_time==_st->_num->getTimeOfThis()) + if(_mpt_time==_st->_m_by_types.getTimeOfThis() && _num_time==_st->_num->getTimeOfThis()) return _m.retn(); else { updateTime(); - _m=static_cast(_st->_m_by_types->deepCpy()); + _m=static_cast(_st->_m_by_types.getUmesh()->deepCpy()); _m->renumberCells(_st->_num->getConstPointer(),true); return _m.retn(); } @@ -497,7 +496,7 @@ void MEDFileUMeshPermCompute::operator=(MEDCouplingUMesh *m) void MEDFileUMeshPermCompute::updateTime() const { - _mpt_time=_st->_m_by_types->getTimeOfThis(); + _mpt_time=_st->_m_by_types.getTimeOfThis(); _num_time=_st->_num->getTimeOfThis(); } @@ -511,45 +510,35 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *m if(v.empty()) return; int sz=v.size(); - std::vector< MEDCouplingAutoRefCountObjectPtr > msMSafe(sz); - std::vector ms(sz); + std::vector ms(sz); + std::vector fams(sz),nums(sz); + std::vector names(sz); for(int i=0;i tmp=MEDCouplingUMesh::New("",v[i]->getDim()); + MEDCoupling1GTUMesh *elt(v[i]->getMesh()); MEDCouplingAutoRefCountObjectPtr tmp2=l2.getCoords(); - tmp->setCoords(tmp2); - tmp->setConnectivity(const_cast(v[i]->getNodal()),const_cast(v[i]->getNodalIndex())); - ms[i]=tmp; msMSafe[i]=tmp; + elt->setCoords(tmp2); + ms[i]=elt; } - _m_by_types=MEDCouplingUMesh::MergeUMeshesOnSameCoords(ms); - _m_by_types->setName(mName); + _m_by_types.assignParts(ms); if(l2.isFamDefinedOnLev(id)) { - int nbOfCells=_m_by_types->getNumberOfCells(); - _fam=DataArrayInt::New(); - _fam->alloc(nbOfCells,1); - int *w=_fam->getPointer(); for(int i=0;igetFam()->getConstPointer(),v[i]->getFam()->getConstPointer()+v[i]->getFam()->getNumberOfTuples(),w); + fams[i]=v[i]->getFam(); + _fam=DataArrayInt::Aggregate(fams); } if(l2.isNumDefinedOnLev(id)) { - int nbOfCells=_m_by_types->getNumberOfCells(); - _num=DataArrayInt::New(); - _num->alloc(nbOfCells,1); - int *w=_num->getPointer(); for(int i=0;igetNum()->getConstPointer(),v[i]->getNum()->getConstPointer()+v[i]->getNum()->getNumberOfTuples(),w); + nums[i]=v[i]->getNum(); + _num=DataArrayInt::Aggregate(nums); computeRevNum(); } if(l2.isNamesDefinedOnLev(id)) { - int nbOfCells=_m_by_types->getNumberOfCells(); - _names=DataArrayAsciiChar::New(); - _names->alloc(nbOfCells,MED_SNAME_SIZE); - char *w=_names->getPointer(); for(int i=0;igetNames()->getConstPointer(),v[i]->getNames()->getConstPointer()+v[i]->getNames()->getNbOfElems(),w); + names[i]=v[i]->getNames(); + _names=dynamic_cast(DataArrayChar::Aggregate(names)); } } @@ -566,12 +555,7 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m( std::size_t MEDFileUMeshSplitL1::getHeapMemorySize() const { std::size_t ret=0; - if((const MEDCouplingUMesh *)_m_by_types) - { - ret+=_m_by_types->getHeapMemorySize(); - if((const DataArrayDouble *)_m_by_types->getCoords()) - ret-=_m_by_types->getCoords()->getHeapMemorySize(); - } + ret+=_m_by_types.getHeapMemorySize(); if((const DataArrayInt*)_fam) ret+=_fam->getHeapMemorySize(); if((const DataArrayInt*)_num) @@ -583,11 +567,10 @@ std::size_t MEDFileUMeshSplitL1::getHeapMemorySize() const return ret; } -MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCpy() const +MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCpy(DataArrayDouble *coords) const { MEDCouplingAutoRefCountObjectPtr ret=new MEDFileUMeshSplitL1(*this); - if((const MEDCouplingUMesh*)_m_by_types) - ret->_m_by_types=static_cast(_m_by_types->deepCpy()); + ret->_m_by_types=_m_by_types.deepCpy(coords); if((const DataArrayInt *)_fam) ret->_fam=_fam->deepCpy(); if((const DataArrayInt *)_num) @@ -601,19 +584,8 @@ MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCpy() const bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const { - const MEDCouplingUMesh *m1=_m_by_types; - const MEDCouplingUMesh *m2=other->_m_by_types; - if((m1==0 && m2!=0) || (m1!=0 && m2==0)) - { - what="Presence of mesh in one sublevel and not in other!"; - return false; - } - if(m1) - if(!m1->isEqual(m2,eps)) - { - what="meshes at a sublevel are not deeply equal !"; - return false; - } + if(!_m_by_types.isEqual(other->_m_by_types,eps,what)) + return false; const DataArrayInt *d1=_fam; const DataArrayInt *d2=other->_fam; if((d1==0 && d2!=0) || (d1!=0 && d2==0)) @@ -658,18 +630,12 @@ bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, void MEDFileUMeshSplitL1::synchronizeTinyInfo(const MEDFileMesh& master) const { - const MEDCouplingUMesh *tmp=_m_by_types; - if(!tmp) - return ; - (const_cast(tmp))->setName(master.getName()); - (const_cast(tmp))->setDescription(master.getDescription()); - (const_cast(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder()); - (const_cast(tmp))->setTimeUnit(master.getTimeUnit()); + _m_by_types.synchronizeTinyInfo(master); } void MEDFileUMeshSplitL1::clearNonDiscrAttributes() const { - ClearNonDiscrAttributes(_m_by_types); + _m_by_types.clearNonDiscrAttributes(); } void MEDFileUMeshSplitL1::ClearNonDiscrAttributes(const MEDCouplingMesh *tmp) @@ -682,20 +648,25 @@ void MEDFileUMeshSplitL1::ClearNonDiscrAttributes(const MEDCouplingMesh *tmp) (const_cast(tmp))->setTimeUnit(""); } +void MEDFileUMeshSplitL1::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception) +{ + _m_by_types.setCoords(coords); +} + void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception) { if(newOrOld) { m->incrRef(); _m=m; - _m_by_types=(MEDCouplingUMesh *)m->deepCpy(); - MEDCouplingAutoRefCountObjectPtr da=_m_by_types->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO); + _m_by_types.assignUMesh(dynamic_cast(m->deepCpy())); + MEDCouplingAutoRefCountObjectPtr da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO); if(!da->isIdentity()) { _num=da->invertArrayO2N2N2O(m->getNumberOfCells()); _m.updateTime(); computeRevNum(); - _m_by_types->renumberCells(da->getConstPointer(),false); + _m_by_types.getUmesh()->renumberCells(da->getConstPointer(),false); } } else @@ -703,7 +674,7 @@ void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(I if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO)) throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh : the mode of mesh setting expects to follow the MED file numbering convention ! it is not the case !"); m->incrRef(); - _m_by_types=m; + _m_by_types.assignUMesh(m); } _fam=DataArrayInt::New(); _fam->alloc(m->getNumberOfCells(),1); @@ -712,7 +683,7 @@ void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(I bool MEDFileUMeshSplitL1::empty() const { - return ((const MEDCouplingUMesh *)_m_by_types)==0; + return _m_by_types.empty(); } bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector& ids) const @@ -725,12 +696,12 @@ bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector& ids) const int MEDFileUMeshSplitL1::getMeshDimension() const { - return _m_by_types->getMeshDimension(); + return _m_by_types.getMeshDimension(); } void MEDFileUMeshSplitL1::simpleRepr(std::ostream& oss) const { - std::vector code=_m_by_types->getDistributionOfTypes(); + std::vector code=_m_by_types.getDistributionOfTypes(); int nbOfTypes=code.size()/3; for(int i=0;igetNumberOfCells(); + return _m_by_types.getSize(); } MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const { MEDCouplingAutoRefCountObjectPtr eltsToKeep=_fam->getIdsEqualList(idsBg,idsEnd); - MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true); + MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true); if(renum) return renumIfNeeded(m,eltsToKeep->getConstPointer()); return m; @@ -769,7 +738,7 @@ MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const if(renum && ((const DataArrayInt *)_num)) tmp=_m; else - tmp=_m_by_types; + { tmp=_m_by_types.getUmesh(); if(tmp) tmp->incrRef(); } return tmp.retn(); } @@ -777,10 +746,7 @@ DataArrayInt *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField() throw(INTERP_K { if((DataArrayInt *)_fam) return _fam; - MEDCouplingUMesh *m(_m_by_types); - if(!m) - throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField : impossible to create a family field array because no mesh specified on this level !"); - int nbOfTuples=m->getNumberOfCells(); + int nbOfTuples=_m_by_types.getSize(); _fam=DataArrayInt::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero(); return _fam; } @@ -833,10 +799,9 @@ void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector ms=_m_by_types->splitByType(); - std::vector< MEDCouplingAutoRefCountObjectPtr > msMSafe(ms.begin(),ms.end()); + std::vector ms(_m_by_types.getParts()); int start=0; - for(std::vector::const_iterator it=ms.begin();it!=ms.end();it++) + for(std::vector::const_iterator it=ms.begin();it!=ms.end();it++) { int nbCells=(*it)->getNumberOfCells(); int end=start+nbCells; @@ -848,14 +813,14 @@ void MEDFileUMeshSplitL1::write(med_idt fid, const char *mName, int mdim) const num=_num->substr(start,end); if((const DataArrayAsciiChar *)_names) names=static_cast(_names->substr(start,end)); - MEDFileUMeshPerType::write(fid,mName,mdim,(*it),fam,num,names); + MEDFileUMeshPerType::Write(fid,mName,mdim,(*it),fam,num,names); start=end; } } void MEDFileUMeshSplitL1::renumberNodesInConn(const int *newNodeNumbersO2N) throw(INTERP_KERNEL::Exception) { - MEDCouplingUMesh *m(_m_by_types); + MEDCouplingUMesh *m(_m_by_types.getUmesh()); if(!m) return; m->renumberNodesInConn(newNodeNumbersO2N); @@ -875,10 +840,8 @@ void MEDFileUMeshSplitL1::setFamilyArr(DataArrayInt *famArr) _fam=0; return ; } - MEDCouplingUMesh *mbt(_m_by_types); - if(!mbt) - throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::setFamilyArr : no mesh defined on this level !"); - famArr->checkNbOfTuplesAndComp(mbt->getNumberOfCells(),1,"MEDFileUMeshSplitL1::setFamilyArr : Problem in size of Family arr ! "); + int sz(_m_by_types.getSize()); + famArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setFamilyArr : Problem in size of Family arr ! "); famArr->incrRef(); _fam=famArr; } @@ -891,10 +854,8 @@ void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr) _rev_num=0; return ; } - MEDCouplingUMesh *mbt(_m_by_types); - if(!mbt) - throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::setRenumArr : no mesh defined on this level !"); - renumArr->checkNbOfTuplesAndComp(mbt->getNumberOfCells(),1,"MEDFileUMeshSplitL1::setRenumArr : Problem in size of numbering arr ! "); + int sz(_m_by_types.getSize()); + renumArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setRenumArr : Problem in size of numbering arr ! "); renumArr->incrRef(); _num=renumArr; computeRevNum(); @@ -907,10 +868,8 @@ void MEDFileUMeshSplitL1::setNameArr(DataArrayAsciiChar *nameArr) _names=0; return ; } - MEDCouplingUMesh *mbt(_m_by_types); - if(!mbt) - throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::setNameArr : no mesh defined on this level !"); - nameArr->checkNbOfTuplesAndComp(mbt->getNumberOfCells(),MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! "); + int sz(_m_by_types.getSize()); + nameArr->checkNbOfTuplesAndComp(sz,MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! "); nameArr->incrRef(); _names=nameArr; } @@ -966,7 +925,7 @@ void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector& famIdTrad, std::map& newfams) { std::set allfids; - + //tony } void MEDFileUMeshSplitL1::computeRevNum() const @@ -975,3 +934,306 @@ void MEDFileUMeshSplitL1::computeRevNum() const int maxValue=_num->getMaxValue(pos); _rev_num=_num->invertArrayN2O2O2N(maxValue+1); } + +//= + +MEDFileUMeshAggregateCompute::MEDFileUMeshAggregateCompute():_mp_time(0),_m_time(0) +{ +} + +void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts) +{ + std::size_t sz(mParts.size()); + std::vector< MEDCouplingAutoRefCountObjectPtr > ret(sz); + for(std::size_t i=0;i(elt); elt->incrRef(); + } + _m_parts=ret; + _mp_time=std::max(_mp_time,_m_time)+1; + _m=0; +} + +void MEDFileUMeshAggregateCompute::assignUMesh(MEDCouplingUMesh *m) +{ + _m=m; + _m_parts.clear(); + _m_time=std::max(_mp_time,_m_time)+1; +} + +MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const +{ + if(_mp_time<=_m_time) + return _m; + std::vector< const MEDCoupling1GTUMesh *> mp(_m_parts.size()); + std::copy(_m_parts.begin(),_m_parts.end(),mp.begin()); + _m=MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(mp); + _m_parts.clear();//to avoid memory peak ! + _m_time=_mp_time+1;//+1 is important ! That is to say that only _m is OK not _m_parts because cleared ! + return _m; +} + +std::vector MEDFileUMeshAggregateCompute::getParts() const +{ + if(_mp_time>=_m_time) + { + std::vector ret(_m_parts.size()); + std::size_t i(0); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++) + { + const MEDCoupling1GTUMesh *elt(*it); + ret[i]=const_cast(elt); + } + return ret; + } + forceComputationOfPartsFromUMesh(); + std::vector ret(_m_parts.size()); + std::size_t i(0); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++) + { + const MEDCoupling1GTUMesh *elt(*it); + ret[i]=const_cast(elt); + } + return ret; +} + +void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const +{ + const MEDCouplingUMesh *m(_m); + if(!m) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !"); + std::vector ms(m->splitByType()); + std::vector< MEDCouplingAutoRefCountObjectPtr > msMSafe(ms.begin(),ms.end()); + std::size_t sz(msMSafe.size()); + _m_parts.resize(sz); + for(std::size_t i=0;i_m_time) + return getTimeOfParts(); + if(_m_time>_mp_time) + return getTimeOfUMesh(); + return std::max(getTimeOfParts(),getTimeOfUMesh()); +} + +std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const +{ + std::size_t ret(0); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + { + const MEDCoupling1GTUMesh *elt(*it); + if(!elt) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : null obj in parts !"); + ret=std::max(ret,elt->getTimeOfThis()); + } + if(ret==0) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : parts is empty !"); + return ret; +} + +std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const +{ + const MEDCouplingUMesh *m(_m); + if(!m) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfUMesh : unmesh is null !"); + return m->getTimeOfThis(); +} + +/*! + * Coordinates pointer is not counted because father instance already count it ! + */ +std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySize() const +{ + std::size_t ret(0); + ret+=_m_parts.size()*sizeof(MEDCouplingAutoRefCountObjectPtr); + std::size_t sz(_m_parts.size()); + for(std::size_t i=0;igetHeapMemorySize(); + const DataArrayDouble *coo(pt->getCoords()); + if(coo) + ret-=coo->getHeapMemorySize(); + } + } + const MEDCouplingUMesh *m(_m); + if(m) + { + ret+=m->getHeapMemorySize(); + const DataArrayDouble *coo(m->getCoords()); + if(coo) + ret-=coo->getHeapMemorySize(); + } + return ret; +} + +MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDouble *coords) const +{ + MEDFileUMeshAggregateCompute ret; + ret._m_parts.resize(_m_parts.size()); + for(std::size_t i=0;i<_m_parts.size();i++) + { + const MEDCoupling1GTUMesh *elt(_m_parts[i]); + if(elt) + { + ret._m_parts[i]=static_cast(elt->deepCpy()); + ret._m_parts[i]->setCoords(coords); + } + } + ret._mp_time=_mp_time; ret._m_time=_m_time; + if((const MEDCouplingUMesh *)_m) + { + ret._m=static_cast(_m->deepCpy()); + ret._m->setCoords(coords); + } + return ret; +} + +bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const +{ + const MEDCouplingUMesh *m1(getUmesh()); + const MEDCouplingUMesh *m2(other.getUmesh()); + if((m1==0 && m2!=0) || (m1!=0 && m2==0)) + { + what="Presence of mesh in one sublevel and not in other!"; + return false; + } + if(m1) + { + std::string what2; + if(!m1->isEqualIfNotWhy(m2,eps,what2)) + { + what=std::string("meshes at a sublevel are not deeply equal (")+what2+std::string(")!"); + return false; + } + } + return true; +} + +void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it); + MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m); +} + +void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + { + const MEDCoupling1GTUMesh *tmp(*it); + if(tmp) + { + (const_cast(tmp))->setName(master.getName()); + (const_cast(tmp))->setDescription(master.getDescription()); + (const_cast(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder()); + (const_cast(tmp))->setTimeUnit(master.getTimeUnit()); + } + } + const MEDCouplingUMesh *m(_m); + if(m) + { + (const_cast(m))->setName(master.getName()); + (const_cast(m))->setDescription(master.getDescription()); + (const_cast(m))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder()); + (const_cast(m))->setTimeUnit(master.getTimeUnit()); + } +} + +bool MEDFileUMeshAggregateCompute::empty() const +{ + if(_mp_time<_m_time) + return ((const MEDCouplingUMesh *)_m)==0; + //else _mp_time>=_m_time) + return _m_parts.empty(); + +} + +int MEDFileUMeshAggregateCompute::getMeshDimension() const +{ + if(_mp_time<_m_time) + { + const MEDCouplingUMesh *m(_m); + if(!m) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : no umesh in this !"); + return m->getMeshDimension(); + } + else + { + if(_m_parts.empty()) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh is empty !"); + const MEDCoupling1GTUMesh *m(_m_parts[0]); + if(!m) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh contains null instance !"); + return m->getMeshDimension(); + } +} + +std::vector MEDFileUMeshAggregateCompute::getDistributionOfTypes() const +{ + if(_mp_time<_m_time) + { + const MEDCouplingUMesh *m(_m); + if(!m) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : no umesh in this !"); + return m->getDistributionOfTypes(); + } + else + { + std::vector ret; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + { + const MEDCoupling1GTUMesh *tmp(*it); + if(!tmp) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : part mesh contains null instance !"); + std::vector ret0(tmp->getDistributionOfTypes()); + ret.insert(ret.end(),ret0.begin(),ret0.end()); + } + return ret; + } +} + +int MEDFileUMeshAggregateCompute::getSize() const throw(INTERP_KERNEL::Exception) +{ + if(_mp_time<_m_time) + { + const MEDCouplingUMesh *m(_m); + if(!m) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : no umesh in this !"); + return m->getNumberOfCells(); + } + else + { + int ret=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++) + { + const MEDCoupling1GTUMesh *m(*it); + if(!m) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : part mesh contains null instance !"); + ret+=m->getNumberOfCells(); + } + return ret; + } +} + +void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception) +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_m_parts.begin();it!=_m_parts.end();it++) + { + MEDCoupling1GTUMesh *tmp(*it); + if(tmp) + (*it)->setCoords(coords); + } + MEDCouplingUMesh *m(_m); + if(m) + m->setCoords(coords); +} diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 815fa08a9..896398aa4 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -26,6 +26,7 @@ #include "MEDCouplingUMesh.hxx" #include "MEDCouplingCMesh.hxx" +#include "MEDCoupling1GTUMesh.hxx" #include "MEDCouplingCurveLinearMesh.hxx" #include "MEDCouplingAutoRefCountObjectPtr.hxx" @@ -130,11 +131,41 @@ namespace ParaMEDMEM void updateTime() const; private: const MEDFileUMeshSplitL1 *_st; - mutable unsigned int _mpt_time; - mutable unsigned int _num_time; + mutable std::size_t _mpt_time; + mutable std::size_t _num_time; mutable MEDCouplingAutoRefCountObjectPtr _m; }; + class MEDFileUMeshAggregateCompute + { + public: + MEDFileUMeshAggregateCompute(); + void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts); + void assignUMesh(MEDCouplingUMesh *m); + MEDCouplingUMesh *getUmesh() const; + std::vector getParts() const; + std::size_t getTimeOfThis() const; + std::size_t getHeapMemorySize() const; + MEDFileUMeshAggregateCompute deepCpy(DataArrayDouble *coords) const; + bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const; + void clearNonDiscrAttributes() const; + void synchronizeTinyInfo(const MEDFileMesh& master) const; + bool empty() const; + int getMeshDimension() const; + std::vector getDistributionOfTypes() const; + int getSize() const throw(INTERP_KERNEL::Exception); + void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); + private: + void forceComputationOfPartsFromUMesh() const; + std::size_t getTimeOfParts() const; + std::size_t getTimeOfUMesh() const; + private: + mutable std::vector< MEDCouplingAutoRefCountObjectPtr > _m_parts; + mutable std::size_t _mp_time; + mutable std::size_t _m_time; + mutable MEDCouplingAutoRefCountObjectPtr _m; + }; + class MEDFileUMeshSplitL1 : public RefCountObject { friend class MEDFileUMeshPermCompute; @@ -144,7 +175,8 @@ namespace ParaMEDMEM MEDFileUMeshSplitL1(MEDCouplingUMesh *m); MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld); std::size_t getHeapMemorySize() const; - MEDFileUMeshSplitL1 *deepCpy() const; + MEDFileUMeshSplitL1 *deepCpy(DataArrayDouble *coords) const; + void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const; void clearNonDiscrAttributes() const; void synchronizeTinyInfo(const MEDFileMesh& master) const; @@ -185,7 +217,7 @@ namespace ParaMEDMEM DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const; void computeRevNum() const; private: - MEDCouplingAutoRefCountObjectPtr _m_by_types; + MEDFileUMeshAggregateCompute _m_by_types; MEDCouplingAutoRefCountObjectPtr _fam; MEDCouplingAutoRefCountObjectPtr _num; MEDCouplingAutoRefCountObjectPtr _names; diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 4e998d646..4769c1bee 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -3162,7 +3162,12 @@ class MEDLoaderTest(unittest.TestCase): mm.write(fname,2) ## mm=MEDFileMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector()) + b4_ref_heap_mem=mm.getHeapMemorySize() + mm.getMeshAtLevel(0)## please let this line : force to move 1GTUMesh -> UMesh + mm.getMeshAtLevel(-1)## please let this line : force to move 1GTUMesh -> UMesh ref_heap_mem=mm.getHeapMemorySize() + # check the gain of memory using 1GTUMesh instead of UMesh + self.assertTrue(ref_heap_mem-b4_ref_heap_mem>=(32+9)*4*2-32)# 32+9=nbCells 4=sizeof(int) 2=the types+index -32=loss linked to vector # mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(0)) self.assertEqual(len(mm.getGroupsNames()),0)