From 509fd94196e173f3f83695bded29c083b8d47903 Mon Sep 17 00:00:00 2001 From: ageay Date: Tue, 16 Jul 2013 16:47:16 +0000 Subject: [PATCH] On the road of last imps for MEDReader --- src/MEDLoader/CMakeLists.txt | 1 + src/MEDLoader/MEDFileField.cxx | 161 +++++++++++- src/MEDLoader/MEDFileField.hxx | 8 +- src/MEDLoader/MEDFileFieldOverView.cxx | 347 +++++++++++++++++++++++++ src/MEDLoader/MEDFileFieldOverView.hxx | 119 +++++++++ src/MEDLoader/Makefile.am | 2 +- src/MEDLoader/Swig/MEDLoaderCommon.i | 25 ++ 7 files changed, 659 insertions(+), 4 deletions(-) create mode 100644 src/MEDLoader/MEDFileFieldOverView.cxx create mode 100644 src/MEDLoader/MEDFileFieldOverView.hxx diff --git a/src/MEDLoader/CMakeLists.txt b/src/MEDLoader/CMakeLists.txt index 9584fcf16..aff35f6b9 100644 --- a/src/MEDLoader/CMakeLists.txt +++ b/src/MEDLoader/CMakeLists.txt @@ -50,6 +50,7 @@ SET(medloader_SOURCES MEDFileField.cxx MEDFileParameter.cxx MEDFileData.cxx + MEDFileFieldOverView.cxx MEDFileMeshReadSelector.cxx SauvMedConvertor.cxx SauvReader.cxx diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 143d7baca..20fedf5cc 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -22,6 +22,7 @@ #include "MEDFileMesh.hxx" #include "MEDLoaderBase.hxx" #include "MEDFileUtilities.hxx" +#include "MEDFileFieldOverView.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldDiscretization.hxx" @@ -8233,7 +8234,7 @@ std::vector< std::vector > MEDFileAnyTypeFieldMult throw INTERP_KERNEL::Exception(msg); std::vector< std::pair > curIts=curIt->getIterations(); if(refIts==curIts) - { elt.push_back(curIt); it=lstFMTS.erase(it);} + { elt.push_back(curIt); it=lstFMTS.erase(it); } else it++; } @@ -8242,6 +8243,164 @@ std::vector< std::vector > MEDFileAnyTypeFieldMult return ret; } +/*! + * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time. + * All returned instances in a subvector can be safely loaded, rendered along time + * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ). + * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time. + * All items in \a vectFMTS must lie on the mesh (located by meshname and time step) and compatible with the input mesh \a mesh (having the same name than those in items). + * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once. + * For items in \a vectFMTS that are ON_NODES it is possible to appear several times (more than once or once) in the returned vector. + * + * \param [in] vectFMTS - list of multi times step part all defined each on a same spatial discretization along time and pointing to a mesh whose name is equal to \c mesh->getName(). + * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time. + * + * \throw If an element in \a vectFMTS has not only one spatial discretization set. + * \throw If an element in \a vectFMTS change of spatial discretization along time. + * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh. + * \thorw If some elements in \a vectFMTS do not have the same times steps. + * \throw If mesh is null. + * \throw If an element in \a vectFMTS is null. + * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime + */ +std::vector< std::vector > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector& vectFMTS, const MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception) +{ + static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !"; + if(!mesh) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !"); + std::vector< std::vector > ret; + if(vectFMTS.empty()) + return ret; + std::vector::const_iterator it(vectFMTS.begin()); + MEDFileAnyTypeFieldMultiTS *frstElt(*it); + std::size_t i=0; + std::vector vectFMTSNotNodes; + std::vector vectFMTSNodes; + for(;it!=vectFMTS.end();it++,i++) + { + TypeOfField tof0,tof1; + int ret=CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1); + if(ret>0) + { + if(tof1!=ON_NODES) + vectFMTSNotNodes.push_back(*it); + else + vectFMTSNodes.push_back(*it); + } + else + vectFMTSNotNodes.push_back(*it); + } + std::vector< MEDCouplingAutoRefCountObjectPtr > cmps; + std::vector< std::vector > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps); + ret=retCell; + i=0; + for(std::vector::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++) + { + for(std::vector< std::vector >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++) + { + if((*it0).empty()) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !"); + } + std::vector elt(1,*it2); + ret.push_back(elt); + } + + return ret; +} + +/*! + * WARNING no check here. The caller must be sure that all items in vectFMTS are coherent each other in time steps, only one same spatial discretization and not ON_NODES. + */ +std::vector< std::vector > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr >& cmps) throw(INTERP_KERNEL::Exception) +{ + std::vector< std::vector > ret; + std::list lstFMTS(vectFMTS.begin(),vectFMTS.end()); + while(!lstFMTS.empty()) + { + std::list::iterator it(lstFMTS.begin()); + MEDFileAnyTypeFieldMultiTS *ref(*it); + std::vector elt; + elt.push_back(ref); it=lstFMTS.erase(it); + MEDCouplingAutoRefCountObjectPtr cmp(MEDFileFastCellSupportComparator::New(mesh,ref)); + while(it!=lstFMTS.end()) + { + MEDFileAnyTypeFieldMultiTS *curIt(*it); + if(cmp->isEqual(ref)) + { elt.push_back(curIt); it=lstFMTS.erase(it); } + else + it++; + } + ret.push_back(elt); cmps.push_back(cmp); + } + return ret; +} + +/*! + * This method scan the two main structs along time of \a f0 and \a f1 to see if there are all lying on the same mesh along time than those in \a mesh. + * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other. + * + * \throw If \a f0 or \a f1 has not only one spatial discretization set. + * \throw If \a f0 or \a f1 change of spatial discretization along time. + * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh. + * \thorw If \a f0 and \a f1 do not have the same times steps. + * \throw If mesh is null. + * \throw If \a f0 or \a f1 is null. + * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport + */ +int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1) throw(INTERP_KERNEL::Exception) +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !"); + if(!f0 || !f1) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !"); + if(f0->getMeshName()!=mesh->getName()) + { + std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(f1->getMeshName()!=mesh->getName()) + { + std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + int nts=f0->getNumberOfTS(); + if(nts!=f1->getNumberOfTS()) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !"); + if(nts==0) + return nts; + for(int i=0;i f0cur=f0->getTimeStepAtPos(i); + MEDCouplingAutoRefCountObjectPtr f1cur=f1->getTimeStepAtPos(i); + std::vector tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable()); + if(tofs0.size()!=1 || tofs1.size()!=1) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !"); + if(i!=0) + { + if(tof0!=tofs0[0] || tof1!=tofs1[0]) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !"); + } + else + { tof0=tofs0[0]; tof1=tofs1[0]; } + if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder()) + { + std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh time step (" << f0cur->getMeshIteration() << ","<< f0cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder()) + { + std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh time step (" << f1cur->getMeshIteration() << ","<< f1cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder()) + { + std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : all the time steps must be the same ! it is not the case (" << f0cur->getIteration() << "," << f0cur->getOrder() << ")!=(" << f1cur->getIteration() << "," << f1cur->getOrder() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + return nts; +} + MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator() throw(INTERP_KERNEL::Exception) { return new MEDFileAnyTypeFieldMultiTSIterator(this); diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 22ac23dea..7afac4bf0 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -417,7 +417,7 @@ namespace ParaMEDMEM // void appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception); void appendLoc(const char *locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& w) throw(INTERP_KERNEL::Exception); - protected: + public: MEDFileFieldGlobs *contentNotNull() throw(INTERP_KERNEL::Exception); const MEDFileFieldGlobs *contentNotNull() const throw(INTERP_KERNEL::Exception); protected: @@ -881,7 +881,7 @@ namespace ParaMEDMEM }; class MEDFileAnyTypeFieldMultiTSIterator; - + class MEDFileFastCellSupportComparator; /*! * User class. */ @@ -914,6 +914,8 @@ namespace ParaMEDMEM MEDFileAnyTypeField1TS *getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception); MEDFileAnyTypeField1TS *getTimeStepGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception); static std::vector< std::vector > SplitIntoCommonTimeSeries(const std::vector& vectFMTS) throw(INTERP_KERNEL::Exception); + static std::vector< std::vector > SplitPerCommonSupport(const std::vector& vectFMTS, const MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception); + static int CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1) throw(INTERP_KERNEL::Exception); public:// direct forwarding to MEDFileField1TSWithoutSDA instance _content std::string getName() const; void setName(const char *name); @@ -955,6 +957,8 @@ namespace ParaMEDMEM protected: MEDFileAnyTypeFieldMultiTSWithoutSDA *contentNotNullBase() throw(INTERP_KERNEL::Exception); const MEDFileAnyTypeFieldMultiTSWithoutSDA *contentNotNullBase() const throw(INTERP_KERNEL::Exception); + private: + static std::vector< std::vector > SplitPerCommonSupportNotNodesAlg(const std::vector& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr >& cmps) throw(INTERP_KERNEL::Exception); protected: MEDCouplingAutoRefCountObjectPtr _content; }; diff --git a/src/MEDLoader/MEDFileFieldOverView.cxx b/src/MEDLoader/MEDFileFieldOverView.cxx new file mode 100644 index 000000000..e5a067b80 --- /dev/null +++ b/src/MEDLoader/MEDFileFieldOverView.cxx @@ -0,0 +1,347 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (CEA/DEN) + +#include "MEDFileFieldOverView.hxx" +#include "MEDFileField.hxx" +#include "MEDFileMesh.hxx" + +#include "CellModel.hxx" + +using namespace ParaMEDMEM; + +MEDFileMeshStruct *MEDFileMeshStruct::New(const MEDFileMesh *mesh) +{ + return new MEDFileMeshStruct(mesh); +} + +std::size_t MEDFileMeshStruct::getHeapMemorySize() const +{ + return 0; +} + +MEDFileMeshStruct::MEDFileMeshStruct(const MEDFileMesh *mesh):_mesh(mesh) +{ + std::vector levs=mesh->getNonEmptyLevels(); + _name=mesh->getName(); + _nb_nodes=mesh->getNumberOfNodes(); + _geo_types_distrib.resize(levs.size()); + for(std::vector::const_iterator lev=levs.begin();lev!=levs.end();lev++) + { + MEDCouplingAutoRefCountObjectPtr mLev=mesh->getGenMeshAtLevel(*lev); + _geo_types_distrib[-(*lev)]=mLev->getDistributionOfTypes(); + } +} + +int MEDFileMeshStruct::getNumberOfElemsOfGeoType(INTERP_KERNEL::NormalizedCellType t) const throw(INTERP_KERNEL::Exception) +{ + for(std::vector< std::vector >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++) + { + std::size_t sz=(*it1).size(); + if(sz%3!=0) + throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfElemsOfGeoType : internal error in code !"); + std::size_t nbGeo=sz/3; + for(std::size_t i=0;i& b, const std::string& c, const std::string& d):_geo_type(a),_start_end(b),_pfl(DataArrayInt::New()),_loc(d),_nb_of_entity(-1) +{ + _pfl->setName(c.c_str()); +} + +void MEDFileField1TSStructItem2::checkWithMeshStructForCells(MEDFileMeshStruct *mst, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception) +{ + int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type); + checkInRange(nbOfEnt,1,globs); +} + +void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(MEDFileMeshStruct *mst, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception) +{ + int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); + checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs); +} + +void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(MEDFileMeshStruct *mst, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception) +{ + if(!globs) + throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !"); + if(_loc.empty()) + throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !"); + const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str()); + int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type); + checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs); +} + +/*! + * \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 + */ +void MEDFileField1TSStructItem2::checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception) +{ + _nb_of_entity=nbOfEntity; + if(_pfl->getName().empty()) + { + if(nbOfEntity!=(_start_end.second-_start_end.first)/nip) + throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of node field !"); + return ; + } + else + { + if(!globs) + throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !"); + const DataArrayInt *pfl=globs->getProfile(_pfl->getName().c_str()); + if(!pfl) + throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !"); + if(!pfl->checkAllIdsInRange(0,nbOfEntity)) + throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : The profile specified is invalid !"); + } +} + +bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception) +{ + return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName(); +} + +//= + +MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_type(a),_items(b) +{ +} + +void MEDFileField1TSStructItem::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception) +{ + switch(_type) + { + case ON_NODES: + { + int nbOfEnt=mst->getNumberOfNodes(); + if(_items.size()!=1) + throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !"); + _items[0].checkInRange(nbOfEnt,1,globs); + break ; + } + case ON_CELLS: + { + for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++) + (*it).checkWithMeshStructForCells(mst,globs); + break; + } + case ON_GAUSS_NE: + { + for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++) + (*it).checkWithMeshStructForGaussNE(mst,globs); + break; + } + case ON_GAUSS_PT: + { + for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++) + (*it).checkWithMeshStructForGaussPT(mst,globs); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !"); + } +} + +bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) 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]==other._items[i])) + return false; + return true; +} + +bool MEDFileField1TSStructItem::isEntityCell() const +{ + if(_type==ON_NODES) + return false; + else + return true; +} + +class CmpGeo +{ +public: + CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { } + bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector > & v) const { return _geo_type==v.first; } +private: + INTERP_KERNEL::NormalizedCellType _geo_type; +}; + +MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobs *globs) const throw(INTERP_KERNEL::Exception) +{ + if(!isEntityCell()) + throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !"); + std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector > > m; + std::size_t i=0; + for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++) + { + std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo()))); + if(it0==m.end()) + m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector >((*it).getGeo(),std::vector(1,i))); + (*it0).second.push_back(i); + } + if(m.size()==_items.size()) + { + MEDFileField1TSStructItem ret(*this); + ret._type=ON_CELLS; + return ret; + } + return *this; +} + +//= + +MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileField1TSStruct(ref); +} + +MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref) +{ + _already_checked.push_back(BuildItemFrom(ref)); +} + +void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception) +{ + if(_already_checked.empty()) + throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !"); + _already_checked.back().checkWithMeshStruct(mst,globs); +} + +bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other) throw(INTERP_KERNEL::Exception) +{ + MEDFileField1TSStructItem b(BuildItemFrom(other)); + for(std::vector::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++) + { + if((*it)==b) + return true; + } + return false; +} + +bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other) throw(INTERP_KERNEL::Exception) +{ + if(_already_checked.empty()) + throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !"); + MEDFileField1TSStructItem b(BuildItemFrom(other)); + if(!_already_checked[0].isEntityCell() || !b.isEntityCell()) + throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !"); + return false; +} + +std::size_t MEDFileField1TSStruct::getHeapMemorySize() const +{ + return 0; +} + +MEDFileField1TSStructItem MEDFileField1TSStruct::BuildItemFrom(const MEDFileAnyTypeField1TS *ref) +{ + TypeOfField atype; + std::vector< MEDFileField1TSStructItem2 > anItems; + // + std::vector< std::vector > pfls,locs; + std::vector< std::vector > typesF; + std::vector geoTypes; + std::vector< std::vector > > strtEnds=ref->getFieldSplitedByType(0,geoTypes,typesF,pfls,locs); + std::size_t nbOfGeoTypes(geoTypes.size()); + if(nbOfGeoTypes==0) + throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref !"); + bool isFirst=true; + for(std::size_t i=0;igetNumberOfTS(); + _f1ts_cmps.resize(nbPts); + for(int i=0;i elt=ref->getTimeStepAtPos(i); + _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt); + _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt->contentNotNull()); + } +} + +std::size_t MEDFileFastCellSupportComparator::getHeapMemorySize() const +{ + /*std::size_t part1=sizeof(MEDFileFastCellSupportComparator)+_mesh_name.capacity()+_already_passed_code1.capacity()*sizeof(std::vector)+_already_passed_code2.capacity()*sizeof(void*)+_m_geo_types_distrib.capacity()*sizeof(std::vector); + std::size_t part2=0; + for(std::vector< std::vector >::const_iterator it=_already_passed_code1.begin();it!=_already_passed_code1.end();it++) + part2+=(*it).capacity()*(sizeof(int)+sizeof(const DataArrayInt *)); + for(std::vector< std::vector >::const_iterator it2=_m_geo_types_distrib.begin();it2!=_m_geo_types_distrib.end();it2++) + part2+=(*it2).capacity()*sizeof(int); + return part1+part2;*/ + return 0; +} + +bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception) +{ + int nbPts=other->getNumberOfTS(); + if(nbPts!=(int)_f1ts_cmps.size()) + { + std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqualRegardingPast : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + for(int i=0;i elt=other->getTimeStepAtPos(i); + if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt)) + if(!_f1ts_cmps[i]->isSupportSameAs(elt)) + return false; + } + return true; +} diff --git a/src/MEDLoader/MEDFileFieldOverView.hxx b/src/MEDLoader/MEDFileFieldOverView.hxx new file mode 100644 index 000000000..cd063f43e --- /dev/null +++ b/src/MEDLoader/MEDFileFieldOverView.hxx @@ -0,0 +1,119 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (CEA/DEN) + +#ifndef __MEDFILEFIELDOVERVIEW_HXX__ +#define __MEDFILEFIELDOVERVIEW_HXX__ + +#include "MEDCouplingAutoRefCountObjectPtr.hxx" +#include "MEDCouplingRefCountObject.hxx" + +#include "NormalizedUnstructuredMesh.hxx" +#include "InterpKernelException.hxx" + +#include + +namespace ParaMEDMEM +{ + class DataArrayInt; + class MEDFileMesh; + class MEDFileFieldGlobs; + class MEDFileAnyTypeField1TS; + class MEDFileAnyTypeFieldMultiTS; + + class MEDFileMeshStruct : public RefCountObject + { + public: + static MEDFileMeshStruct *New(const MEDFileMesh *mesh); + std::size_t getHeapMemorySize() const; + int getNumberOfNodes() const { return _nb_nodes; } + int getNumberOfElemsOfGeoType(INTERP_KERNEL::NormalizedCellType t) const throw(INTERP_KERNEL::Exception); + private: + MEDFileMeshStruct(const MEDFileMesh *mesh); + private: + const MEDFileMesh *_mesh; + std::string _name; + int _nb_nodes; + std::vector< std::vector > _geo_types_distrib; + }; + + class MEDFileField1TSStructItem2 + { + public: + MEDFileField1TSStructItem2(INTERP_KERNEL::NormalizedCellType a, const std::pair& b, const std::string& pfl, const std::string& loc); + void checkWithMeshStructForCells(MEDFileMeshStruct *mst, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception); + void checkWithMeshStructForGaussNE(MEDFileMeshStruct *mst, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception); + void checkWithMeshStructForGaussPT(MEDFileMeshStruct *mst, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception); + // + INTERP_KERNEL::NormalizedCellType getGeo() const { return _geo_type; } + //! 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); + private: + INTERP_KERNEL::NormalizedCellType _geo_type; + std::pair _start_end; + MEDCouplingAutoRefCountObjectPtr _pfl; + std::string _loc; + int _nb_of_entity; + }; + + class MEDFileField1TSStructItem + { + public: + MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b); + void checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception); + bool operator==(const MEDFileField1TSStructItem& other) const throw(INTERP_KERNEL::Exception); + bool isEntityCell() const; + // + MEDFileField1TSStructItem simplifyMeOnCellEntity(const MEDFileFieldGlobs *globs) const throw(INTERP_KERNEL::Exception); + private: + TypeOfField _type; + std::vector< MEDFileField1TSStructItem2 > _items; + }; + + class MEDFileField1TSStruct : public RefCountObject + { + public: + static MEDFileField1TSStruct *New(const MEDFileAnyTypeField1TS *ref) throw(INTERP_KERNEL::Exception); + void checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception); + std::size_t getHeapMemorySize() const; + bool isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other) throw(INTERP_KERNEL::Exception); + bool isSupportSameAs(const MEDFileAnyTypeField1TS *other) throw(INTERP_KERNEL::Exception); + private: + MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref); + static MEDFileField1TSStructItem BuildItemFrom(const MEDFileAnyTypeField1TS *ref); + private: + std::vector _already_checked; + }; + + class MEDFileFastCellSupportComparator : public RefCountObject + { + public: + static MEDFileFastCellSupportComparator *New(const MEDFileMesh *m, const MEDFileAnyTypeFieldMultiTS *ref) throw(INTERP_KERNEL::Exception); + bool isEqual(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception); + std::size_t getHeapMemorySize() const; + private: + MEDFileFastCellSupportComparator(const MEDFileMesh *m, const MEDFileAnyTypeFieldMultiTS *ref); + private: + MEDCouplingAutoRefCountObjectPtr _mesh_comp; + std::vector< MEDCouplingAutoRefCountObjectPtr > _f1ts_cmps; + }; +} + +#endif diff --git a/src/MEDLoader/Makefile.am b/src/MEDLoader/Makefile.am index d60916ef4..10d7b44ff 100755 --- a/src/MEDLoader/Makefile.am +++ b/src/MEDLoader/Makefile.am @@ -46,7 +46,7 @@ MEDLoader.cxx MEDLoaderBase.cxx MEDFileUtilities.cxx \ MEDFileMesh.cxx MEDFileMeshElt.cxx MEDFileBasis.cxx \ MEDFileMeshLL.cxx MEDFileField.cxx MEDFileData.cxx \ SauvMedConvertor.cxx SauvReader.cxx SauvWriter.cxx \ -MEDFileParameter.cxx MEDFileMeshReadSelector.cxx +MEDFileParameter.cxx MEDFileMeshReadSelector.cxx MEDFileFieldOverView.cxx libmedloader_la_CPPFLAGS= $(MED3_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ -I$(srcdir)/../INTERP_KERNEL \ diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 8dc2a6b88..43d05e8b8 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -1143,6 +1143,8 @@ namespace ParaMEDMEM void setName(const char *name) throw(INTERP_KERNEL::Exception); std::string getMeshName() throw(INTERP_KERNEL::Exception); void setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception); + int getMeshIteration() const throw(INTERP_KERNEL::Exception); + int getMeshOrder() const throw(INTERP_KERNEL::Exception); int getNumberOfComponents() const throw(INTERP_KERNEL::Exception); bool isDealingTS(int iteration, int order) const throw(INTERP_KERNEL::Exception); void setInfo(const std::vector& infos) throw(INTERP_KERNEL::Exception); @@ -1850,6 +1852,29 @@ namespace ParaMEDMEM } return retPy; } + + static PyObject *MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(PyObject *li, const MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception) + { + std::vector vectFMTS; + convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDFileAnyTypeFieldMultiTS,"MEDFileAnyTypeFieldMultiTS",vectFMTS); + std::vector< std::vector > ret=MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(vectFMTS,mesh); + std::size_t sz=ret.size(); + PyObject *retPy=PyList_New(sz); + for(std::size_t i=0;iincrRef(); + PyList_SetItem(ret1Py,j,convertMEDFileFieldMultiTS(elt,SWIG_POINTER_OWN | 0 )); + } + PyList_SetItem(retPy,i,ret1Py); + } + return retPy; + } } }; -- 2.39.2