From 6a09489c80868addea31d0a86fdd61447566fb1f Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 22 Jul 2013 11:01:19 +0000 Subject: [PATCH] On the highway to MEDReader --- src/MEDLoader/MEDFileField.cxx | 3 +- src/MEDLoader/MEDFileFieldOverView.cxx | 313 +++++++++++++++++++++++-- src/MEDLoader/MEDFileFieldOverView.hxx | 81 ++++++- src/MEDLoader/MEDFileMesh.cxx | 23 ++ src/MEDLoader/MEDFileMesh.hxx | 2 + src/MEDLoader/MEDFileMeshLL.cxx | 37 ++- src/MEDLoader/MEDFileMeshLL.hxx | 4 + src/MEDLoader/Swig/MEDLoaderCommon.i | 16 ++ 8 files changed, 438 insertions(+), 41 deletions(-) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 00dbb7b36..8ee6fde59 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -8327,7 +8327,8 @@ std::vector< std::vector > MEDFileAnyTypeFieldMult MEDFileAnyTypeFieldMultiTS *ref(*it); std::vector elt; elt.push_back(ref); it=lstFMTS.erase(it); - MEDCouplingAutoRefCountObjectPtr cmp(MEDFileFastCellSupportComparator::New(mesh,ref)); + MEDCouplingAutoRefCountObjectPtr mst(MEDFileMeshStruct::New(mesh)); + MEDCouplingAutoRefCountObjectPtr cmp(MEDFileFastCellSupportComparator::New(mst,ref)); while(it!=lstFMTS.end()) { MEDFileAnyTypeFieldMultiTS *curIt(*it); diff --git a/src/MEDLoader/MEDFileFieldOverView.cxx b/src/MEDLoader/MEDFileFieldOverView.cxx index f619e410c..379556249 100644 --- a/src/MEDLoader/MEDFileFieldOverView.cxx +++ b/src/MEDLoader/MEDFileFieldOverView.cxx @@ -26,6 +26,8 @@ using namespace ParaMEDMEM; +const char MEDFileField1TSStructItem2::NEWLY_CREATED_PFL_NAME[]="???"; + MEDFileMeshStruct *MEDFileMeshStruct::New(const MEDFileMesh *mesh) { return new MEDFileMeshStruct(mesh); @@ -140,6 +142,19 @@ std::string MEDFileField1TSStructItem2::getPflName() const return _pfl->getName(); } +const DataArrayInt *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const +{ + if(!_pfl->isAllocated()) + { + if(_pfl->getName().empty()) + return 0; + else + return globs->getProfile(_pfl->getName().c_str()); + } + else + return _pfl; +} + /*! * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possiblity. * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES @@ -171,7 +186,7 @@ bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& ot return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName(); } -bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception) +bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception) { if(_geo_type!=other._geo_type) return false; @@ -181,7 +196,13 @@ bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructI return false; if(_pfl->getName().empty() && other._pfl->getName().empty()) return true; - return _pfl->isEqualWithoutConsideringStr(*other._pfl); + const DataArrayInt *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs)); + return pfl1->isEqualWithoutConsideringStr(*pfl2); +} + +bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception) +{ + return isCellSupportEqual(other,globs); } /*! @@ -224,7 +245,7 @@ MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const } else { - arr->setName("???"); + arr->setName(NEWLY_CREATED_PFL_NAME); std::pair p(0,oldNbTuples); std::string a,b; MEDFileField1TSStructItem2 ret(gt,p,a,b); @@ -297,14 +318,26 @@ bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& othe return true; } -bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other) const throw(INTERP_KERNEL::Exception) +bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception) +{ + if(_type!=other._type) + return false; + if(_items.size()!=other._items.size()) + return false; + for(std::size_t i=0;i<_items.size();i++) + if(!(_items[i].isCellSupportEqual(other._items[i],globs))) + return false; + return true; +} + +bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception) { if(_type!=other._type) return false; if(_items.size()!=other._items.size()) return false; for(std::size_t i=0;i<_items.size();i++) - if(!(_items[i].isCellSupportEqual(other._items[i]))) + if(!(_items[i].isNodeSupportEqual(other._items[i],globs))) return false; return true; } @@ -443,9 +476,19 @@ std::size_t MEDFileField1TSStructItem::getHeapMemorySize() const return ret; } -MEDCouplingMesh *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception) +MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception) { - return 0;//tony + std::vector a0; + std::vector a1; + std::vector a2; + std::size_t i(0); + for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++) + { + a0[i]=(*it).getGeo(); + a1[i]=(*it).getPfl(globs); + a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo()); + } + return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2); } //= @@ -497,12 +540,12 @@ bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, if(found==-1) { MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other->contentNotNull())); - ret=this1.isCellSupportEqual(other1); + ret=this1.isCellSupportEqual(other1,other); if(ret) _already_checked.push_back(this1); } else - ret=_already_checked[found].isCellSupportEqual(other1); + ret=_already_checked[found].isCellSupportEqual(other1,other); if(ret) _already_checked.push_back(b); return ret; @@ -580,27 +623,45 @@ MEDFileField1TSStructItem MEDFileField1TSStruct::BuildItemFrom(const MEDFileAnyT return ret; } -MEDCouplingMesh *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception) +MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception) { if(_already_checked.empty()) throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !"); int pos0(-1),pos1(-1); if(presenceOfCellDiscr(pos0)) { - if(!presenceOfPartialNodeDiscr(pos1)) - return _already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs); - else - throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : tony do it very soon !"); + MEDCouplingAutoRefCountObjectPtr ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs)); + if(presenceOfPartialNodeDiscr(pos1)) + ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs)); + return ret.retn(); } else { if(!presenceOfPartialNodeDiscr(pos1)) {//we have only all nodes, no cell definition info -> level 0; - return mst->getTheMesh()->getGenMeshAtLevel(0); + std::vector levs(1,0); + return MEDMeshMultiLev::New(mst->getTheMesh(),levs); } } } +bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception) +{ + int b0,b1; + bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1)); + int d0,d1; + bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1)); + if(a0!=c0 || a1!=c1) + return false; + if(a0) + if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs)) + return false; + if(a1) + if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs)) + return false; + return true; +} + /*! * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE. * If true is returned the pos of the easiest is returned. The easiest is the first element in \a this having the less splitted subparts. @@ -651,14 +712,16 @@ bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const throw(INT //= -MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMesh *m, const MEDFileAnyTypeFieldMultiTS *ref) throw(INTERP_KERNEL::Exception) +MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref) throw(INTERP_KERNEL::Exception) { return new MEDFileFastCellSupportComparator(m,ref); } -MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMesh *m, const MEDFileAnyTypeFieldMultiTS *ref) +MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref) { - _mesh_comp=MEDFileMeshStruct::New(m); + if(!m) + throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !"); + _mesh_comp=const_cast(m); _mesh_comp->incrRef(); int nbPts=ref->getNumberOfTS(); _f1ts_cmps.resize(nbPts); for(int i=0;i=(int)_f1ts_cmps.size()) { @@ -735,3 +798,215 @@ MEDCouplingMesh *MEDFileFastCellSupportComparator::buildFromScratchDataSetSuppor } return obj->buildFromScratchDataSetSupport(_mesh_comp,globs); } + +bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception) +{ + if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size()) + { + std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]); + const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]); + return objRef->isDataSetSupportFastlyEqualTo(*obj,globs); +} + +//= + +std::size_t MEDMeshMultiLev::getHeapMemorySize() const +{ + return 0; +} + +MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector& levs) throw(INTERP_KERNEL::Exception) +{ + if(!m) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : null input pointer !"); + const MEDFileUMesh *um(dynamic_cast(m)); + if(um) + return MEDUMeshMultiLev::New(um,levs); + const MEDFileCMesh *cm(dynamic_cast(m)); + if(cm) + return MEDCMeshMultiLev::New(cm,levs); + const MEDFileCurveLinearMesh *clm(dynamic_cast(m)); + if(clm) + return MEDCurveLinearMeshMultiLev::New(clm,levs); + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !"); +} + +MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities) throw(INTERP_KERNEL::Exception) +{ + if(!m) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : null input pointer !"); + const MEDFileUMesh *um(dynamic_cast(m)); + if(um) + return MEDUMeshMultiLev::New(um,gts,pfls,nbEntities); + const MEDFileCMesh *cm(dynamic_cast(m)); + if(cm) + return MEDCMeshMultiLev::New(cm,gts,pfls,nbEntities); + const MEDFileCurveLinearMesh *clm(dynamic_cast(m)); + if(clm) + return MEDCurveLinearMeshMultiLev::New(clm,gts,pfls,nbEntities); + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !"); +} + +void MEDMeshMultiLev::setNodeReduction(const DataArrayInt *nr) +{ + if(nr) + nr->incrRef(); + _node_reduction=const_cast(nr); +} + +MEDMeshMultiLev::MEDMeshMultiLev() +{ +} + +MEDMeshMultiLev::MEDMeshMultiLev(const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):_geo_types(gts),_nb_entities(nbEntities) +{ + std::size_t sz(_geo_types.size()); + if(sz!=pfls.size() || sz!=nbEntities.size()) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !"); + _pfls.resize(sz); + for(std::size_t i=0;iincrRef(); + _pfls[i]=const_cast(pfls[i]); + } +} + +MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector& levs) throw(INTERP_KERNEL::Exception) +{ + return new MEDUMeshMultiLev(m,levs); +} + +MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector& levs) +{ + if(!m) + throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !"); + std::vector v; + for(std::vector::const_iterator it=levs.begin();it!=levs.end();it++) + { + std::vector vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it)); + v.insert(v.end(),vTmp.begin(),vTmp.end()); + } + std::size_t sz(v.size()); + _parts.resize(sz); + _pfls.resize(sz); + _geo_types.resize(sz); + for(std::size_t i=0;iincrRef(); + else + throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !"); + _parts[i]=obj; + _geo_types[i]=obj->getCellModelEnum(); + } +} + +MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities) throw(INTERP_KERNEL::Exception) +{ + return new MEDUMeshMultiLev(m,gts,pfls,nbEntities); +} + +MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities) +{ + std::size_t sz(gts.size()); + _parts.resize(sz); + for(std::size_t i=0;igetDirectUndergroundSingleGeoTypeMesh(gts[i])); + if(elt) + elt->incrRef(); + _parts[i]=elt; + } +} + +MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector& levs) throw(INTERP_KERNEL::Exception) +{ + return new MEDCMeshMultiLev(m,levs); +} + +MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities) throw(INTERP_KERNEL::Exception) +{ + return new MEDCMeshMultiLev(m,gts,pfls,nbEntities); +} + +MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector& levs) +{ + if(!m) + throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !"); + if(levs.size()!=1 || levs[0]!=0) + throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !"); + int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension())); + _coords.resize(mdim); + for(int i=0;i(m->getMesh()->getCoordsAt(i))); + if(!elt) + throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !"); + _coords[i]=elt; + } +} + +MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities) +{ + if(!m) + throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !"); + if(gts.size()!=1 || pfls.size()!=1) + throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !"); + int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension())); + if(mdim!=gts[0]) + throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !"); + _coords.resize(mdim); + for(int i=0;i(m->getMesh()->getCoordsAt(i))); + if(!elt) + throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !"); + _coords[i]=elt; + } +} + +MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector& levs) throw(INTERP_KERNEL::Exception) +{ + return new MEDCurveLinearMeshMultiLev(m,levs); +} + +MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities) throw(INTERP_KERNEL::Exception) +{ + return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities); +} + +MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector& levs) +{ + if(!m) + throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !"); + if(levs.size()!=1 || levs[0]!=0) + throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !"); + DataArrayDouble *coords(const_cast(m->getMesh()->getCoords())); + if(!coords) + throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !"); + coords->incrRef(); + _coords=coords; + _structure=m->getMesh()->getNodeGridStructure(); +} + +MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities) +{ + if(!m) + throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !"); + if(gts.size()!=1 || pfls.size()!=1) + throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !"); + int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension())); + if(mdim!=gts[0]) + throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !"); + DataArrayDouble *coords(const_cast(m->getMesh()->getCoords())); + if(!coords) + throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !"); + coords->incrRef(); + _coords=coords; + _structure=m->getMesh()->getNodeGridStructure(); +} diff --git a/src/MEDLoader/MEDFileFieldOverView.hxx b/src/MEDLoader/MEDFileFieldOverView.hxx index 4b864b8ee..1a3f2714e 100644 --- a/src/MEDLoader/MEDFileFieldOverView.hxx +++ b/src/MEDLoader/MEDFileFieldOverView.hxx @@ -23,6 +23,7 @@ #include "MEDCouplingAutoRefCountObjectPtr.hxx" #include "MEDCouplingRefCountObject.hxx" +#include "MEDCoupling1GTUMesh.hxx" #include "NormalizedUnstructuredMesh.hxx" #include "InterpKernelException.hxx" @@ -34,6 +35,9 @@ namespace ParaMEDMEM class DataArrayInt; class MEDCouplingMesh; class MEDFileMesh; + class MEDFileUMesh; + class MEDFileCMesh; + class MEDFileCurveLinearMesh; class MEDFileFieldGlobs; class MEDFileFieldGlobsReal; class MEDFileAnyTypeField1TS; @@ -57,6 +61,61 @@ namespace ParaMEDMEM std::string _name; int _nb_nodes; std::vector< std::vector > _geo_types_distrib; + }; + + class MEDMeshMultiLev : public RefCountObject + { + public: + std::size_t getHeapMemorySize() const; + public: + static MEDMeshMultiLev *New(const MEDFileMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities) throw(INTERP_KERNEL::Exception); + static MEDMeshMultiLev *New(const MEDFileMesh *m, const std::vector& levs) throw(INTERP_KERNEL::Exception); + void setNodeReduction(const DataArrayInt *nr); + protected: + MEDMeshMultiLev(); + MEDMeshMultiLev(const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities); + protected: + std::vector< MEDCouplingAutoRefCountObjectPtr > _pfls; + std::vector< INTERP_KERNEL::NormalizedCellType > _geo_types; + std::vector _nb_entities; + MEDCouplingAutoRefCountObjectPtr _node_reduction; + }; + + class MEDUMeshMultiLev : public MEDMeshMultiLev + { + public: + static MEDUMeshMultiLev *New(const MEDFileUMesh *m, const std::vector& levs) throw(INTERP_KERNEL::Exception); + static MEDUMeshMultiLev *New(const MEDFileUMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities) throw(INTERP_KERNEL::Exception); + private: + MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector& levs); + MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities); + private: + std::vector< MEDCouplingAutoRefCountObjectPtr > _parts; + }; + + class MEDCMeshMultiLev : public MEDMeshMultiLev + { + public: + static MEDCMeshMultiLev *New(const MEDFileCMesh *m, const std::vector& levs) throw(INTERP_KERNEL::Exception); + static MEDCMeshMultiLev *New(const MEDFileCMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities) throw(INTERP_KERNEL::Exception); + private: + MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector& levs); + MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities); + private: + std::vector< MEDCouplingAutoRefCountObjectPtr > _coords; + }; + + class MEDCurveLinearMeshMultiLev : public MEDMeshMultiLev + { + public: + static MEDCurveLinearMeshMultiLev *New(const MEDFileCurveLinearMesh *m, const std::vector& levs) throw(INTERP_KERNEL::Exception); + static MEDCurveLinearMeshMultiLev *New(const MEDFileCurveLinearMesh *m, const std::vector& gts, const std::vector& pfls , const std::vector& nbEntities) throw(INTERP_KERNEL::Exception); + private: + MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector& levs); + MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities); + private: + MEDCouplingAutoRefCountObjectPtr _coords; + std::vector _structure; }; class MEDFileField1TSStructItem2 : public RefCountObject @@ -70,13 +129,17 @@ namespace ParaMEDMEM // std::size_t getHeapMemorySize() const; // + const DataArrayInt *getPfl(const MEDFileFieldGlobsReal *globs) const; INTERP_KERNEL::NormalizedCellType getGeo() const { return _geo_type; } std::string getPflName() const; //! warning this method also set _nb_of_entity attribute ! void checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception); bool operator==(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception); - bool isCellSupportEqual(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception); + bool isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); + bool isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); static MEDFileField1TSStructItem2 BuildAggregationOf(const std::vector& objs, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception); + public: + static const char NEWLY_CREATED_PFL_NAME[]; private: INTERP_KERNEL::NormalizedCellType _geo_type; std::pair _start_end; @@ -98,11 +161,12 @@ namespace ParaMEDMEM std::size_t getNumberOfItems() const { return _items.size(); } const MEDFileField1TSStructItem2& operator[](std::size_t i) const throw(INTERP_KERNEL::Exception); // - bool isCellSupportEqual(const MEDFileField1TSStructItem& other) const throw(INTERP_KERNEL::Exception); + bool isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); + bool isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); MEDFileField1TSStructItem simplifyMeOnCellEntity(const MEDFileFieldGlobs *globs) const throw(INTERP_KERNEL::Exception); bool isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobs *globs) const throw(INTERP_KERNEL::Exception); bool isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const throw(INTERP_KERNEL::Exception); - MEDCouplingMesh *buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); + MEDMeshMultiLev *buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); private: bool _computed; TypeOfField _type; @@ -118,7 +182,8 @@ namespace ParaMEDMEM bool isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const throw(INTERP_KERNEL::Exception); bool isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt) throw(INTERP_KERNEL::Exception); bool isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt) throw(INTERP_KERNEL::Exception); - MEDCouplingMesh *buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); + MEDMeshMultiLev *buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); + bool isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); private: MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst); static MEDFileField1TSStructItem BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt); @@ -131,14 +196,14 @@ namespace ParaMEDMEM class MEDFileFastCellSupportComparator : public RefCountObject { public: - static MEDFileFastCellSupportComparator *New(const MEDFileMesh *m, const MEDFileAnyTypeFieldMultiTS *ref) throw(INTERP_KERNEL::Exception); - MEDCouplingMesh *buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); - bool isDataSetSupportEqualToThePreviousOne(int timeStepId) const throw(INTERP_KERNEL::Exception); + static MEDFileFastCellSupportComparator *New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref) throw(INTERP_KERNEL::Exception); + MEDMeshMultiLev *buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); + bool isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); bool isEqual(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception); bool isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception); std::size_t getHeapMemorySize() const; private: - MEDFileFastCellSupportComparator(const MEDFileMesh *m, const MEDFileAnyTypeFieldMultiTS *ref); + MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref); private: MEDCouplingAutoRefCountObjectPtr _mesh_comp; std::vector< MEDCouplingAutoRefCountObjectPtr > _f1ts_cmps; diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 986265c53..08fdeff0f 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -2934,6 +2934,29 @@ MEDCouplingUMesh *MEDFileUMesh::getLevelM3Mesh(bool renum) const throw(INTERP_KE return getMeshAtLevel(-3,renum); } +/*! + * This method returns a vector of mesh parts containing each exactly one geometric type. + * This method will never launch an automatic computation of split by type (an INTERP_KERNEL::Exception will be then thrown). + * This method is only for memory aware users. + */ +std::vector MEDFileUMesh::getDirectUndergroundSingleGeoTypeMeshes(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) +{ + const MEDFileUMeshSplitL1 *sp(getMeshAtLevSafe(meshDimRelToMax)); + return sp->getDirectUndergroundSingleGeoTypeMeshes(); +} + +/*! + * This method returns the part of \a this having the geometric type \a gt. + * If such part is not existing an exception will be thrown. + */ +MEDCoupling1GTUMesh *MEDFileUMesh::getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception) +{ + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(gt); + int lev=(int)cm.getDimension()-getMeshDimension(); + const MEDFileUMeshSplitL1 *sp(getMeshAtLevSafe(lev)); + return sp->getDirectUndergroundSingleGeoTypeMesh(gt); +} + const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) { if(meshDimRelToMaxExt==1) diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index f6fde1113..2df119a3c 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -238,6 +238,8 @@ namespace ParaMEDMEM MEDCouplingUMesh *getLevelM1Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getLevelM2Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getLevelM3Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); + std::vector getDirectUndergroundSingleGeoTypeMeshes(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception); + MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception); // void setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception); void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index ea4206e0d..c5983997e 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -976,20 +976,11 @@ MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const return _m; } -std::vector MEDFileUMeshAggregateCompute::getParts() const +std::vector MEDFileUMeshAggregateCompute::getPartsWithoutComputation() const throw(INTERP_KERNEL::Exception) { - 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(); + if(_mp_time<_m_time) + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartsWithoutComputation : the parts require a computation !"); + // 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++) @@ -1000,6 +991,26 @@ std::vector MEDFileUMeshAggregateCompute::getParts() cons return ret; } +std::vector MEDFileUMeshAggregateCompute::getParts() const +{ + if(_mp_time<_m_time) + forceComputationOfPartsFromUMesh(); + return getPartsWithoutComputation(); +} + +MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::getPartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception) +{ + std::vector v(getPartsWithoutComputation()); + std::size_t sz(v.size()); + for(std::size_t i=0;igetCellModelEnum()==gt) + return v[i]; + } + throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartWithoutComputation : the geometric type is not existing !"); +} + void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const { const MEDCouplingUMesh *m(_m); diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 896398aa4..9338ea825 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -144,6 +144,8 @@ namespace ParaMEDMEM void assignUMesh(MEDCouplingUMesh *m); MEDCouplingUMesh *getUmesh() const; std::vector getParts() const; + std::vector getPartsWithoutComputation() const throw(INTERP_KERNEL::Exception); + MEDCoupling1GTUMesh *getPartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception); std::size_t getTimeOfThis() const; std::size_t getHeapMemorySize() const; MEDFileUMeshAggregateCompute deepCpy(DataArrayDouble *coords) const; @@ -189,6 +191,8 @@ namespace ParaMEDMEM MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const; DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const; MEDCouplingUMesh *getWholeMesh(bool renum) const; + std::vector getDirectUndergroundSingleGeoTypeMeshes() const throw(INTERP_KERNEL::Exception) { return _m_by_types.getPartsWithoutComputation(); } + MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception) { return _m_by_types.getPartWithoutComputation(gt); } DataArrayInt *getOrCreateAndGetFamilyField() throw(INTERP_KERNEL::Exception); const DataArrayInt *getFamilyField() const; const DataArrayInt *getNumberField() const; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 43d05e8b8..d6a0a2083 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -97,6 +97,7 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileUMesh::getLevelM1Mesh; %newobject ParaMEDMEM::MEDFileUMesh::getLevelM2Mesh; %newobject ParaMEDMEM::MEDFileUMesh::getLevelM3Mesh; +%newobject ParaMEDMEM::MEDFileUMesh::getDirectUndergroundSingleGeoTypeMesh; %newobject ParaMEDMEM::MEDFileUMesh::zipCoords; %newobject ParaMEDMEM::MEDFileCMesh::New; %newobject ParaMEDMEM::MEDFileCurveLinearMesh::New; @@ -686,6 +687,7 @@ namespace ParaMEDMEM MEDCouplingUMesh *getLevelM1Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getLevelM2Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getLevelM3Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception); + MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception); // void setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception); void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); @@ -767,6 +769,20 @@ namespace ParaMEDMEM PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(ret2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } + + PyObject *getDirectUndergroundSingleGeoTypeMeshes(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) + { + std::vector tmp(self->getDirectUndergroundSingleGeoTypeMeshes(meshDimRelToMax)); + std::size_t sz(tmp.size()); + PyObject *ret=PyList_New(sz); + for(std::size_t i=0;iincrRef(); + PyList_SetItem(ret,i,convertMesh(tmp[i], SWIG_POINTER_OWN | 0 )); + } + return ret; + } } }; -- 2.39.2