From: ageay Date: Wed, 18 May 2011 11:34:53 +0000 (+0000) Subject: Some new usefull methods. X-Git-Tag: EndWorkDidier~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=da4d3899a9a8336ab8a50106879060f4fa2b5c54;p=tools%2Fmedcoupling.git Some new usefull methods. --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 4747eb89e..3a760b346 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -2343,6 +2343,11 @@ void DataArrayInt::renumberInPlaceR(const int *new2Old) declareAsNew(); } +/*! + * This method expects that 'this' is allocated, if not an exception is thrown. + * This method in case of success returns a newly created array the user should deal with. + * In the case of having a renumber array in "old to new" format. More info on renumbering \ref MEDCouplingArrayRenumbering "here". + */ DataArrayInt *DataArrayInt::renumber(const int *old2New) const { int nbTuples=getNumberOfTuples(); @@ -2997,6 +3002,24 @@ DataArrayInt *DataArrayInt::getIdsNotEqualList(const std::vector& vals) con return ret; } +/*! + * This method expects to be called when number of components of this is equal to one. + * This method returns true if it exists a tuple so that the value is contained in 'vals'. + * If not any tuple contains one of the values contained in 'vals' false is returned. + */ +bool DataArrayInt::presenceOfValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception) +{ + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !"); + std::set vals2(vals.begin(),vals.end()); + const int *cptr=getConstPointer(); + int nbOfTuples=getNumberOfTuples(); + bool found=false; + for(const int *w=cptr;w!=cptr+nbOfTuples && !found;w++) + found=(vals2.find(*w)!=vals2.end()); + return found; +} + DataArrayInt *DataArrayInt::Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2) { int nbOfComp=a1->getNumberOfComponents(); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 49d5eedf2..2a3d293ed 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -316,6 +316,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *getIdsNotEqual(int val) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *getIdsEqualList(const std::vector& vals) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *getIdsNotEqualList(const std::vector& vals) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool presenceOfValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 7c8451813..7e0f570cb 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -176,6 +176,23 @@ std::vector MEDFileMesh::getFamiliesOnGroup(const char *name) const return (*it).second; } +std::vector MEDFileMesh::getFamiliesOnGroups(const std::vector& grps) const throw(INTERP_KERNEL::Exception) +{ + std::set fams; + for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++) + { + std::map >::const_iterator it2=_groups.find(*it); + if(it2==_groups.end()) + { + std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + fams.insert((*it2).second.begin(),(*it2).second.end()); + } + std::vector fams2(fams.begin(),fams.end()); + return fams2; +} + std::vector MEDFileMesh::getFamiliesIdsOnGroup(const char *name) const throw(INTERP_KERNEL::Exception) { std::string oname(name); @@ -571,18 +588,7 @@ DataArrayInt *MEDFileMesh::getGroupArr(int meshDimRelToMaxExt, const char *grp, DataArrayInt *MEDFileMesh::getGroupsArr(int meshDimRelToMaxExt, const std::vector& grps, bool renum) const throw(INTERP_KERNEL::Exception) { - std::set fams; - for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++) - { - std::map >::const_iterator it2=_groups.find(*it); - if(it2==_groups.end()) - { - std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - fams.insert((*it2).second.begin(),(*it2).second.end()); - } - std::vector fams2(fams.begin(),fams.end()); + std::vector fams2=getFamiliesOnGroups(grps); return getFamiliesArr(meshDimRelToMaxExt,fams2,renum); } @@ -947,6 +953,99 @@ std::vector MEDFileUMesh::getNonEmptyLevelsExt() const return ret0; } +/*! + * This methods returns all relative mesh levels where group 'grp' is defined \b excluded \b nodes. + * To include nodes call MEDFileUMesh::getGrpNonEmptyLevelsExt method. + */ +std::vector MEDFileUMesh::getGrpNonEmptyLevels(const char *grp) const throw(INTERP_KERNEL::Exception) +{ + std::vector fams=getFamiliesOnGroup(grp); + return getFamsNonEmptyLevels(fams); +} + +/*! + * This method is a generalization of MEDFileUMesh::getGrpNonEmptyLevelsExt. It looks at the node level to state if the group 'grp' has a part lying on node. + */ +std::vector MEDFileUMesh::getGrpNonEmptyLevelsExt(const char *grp) const throw(INTERP_KERNEL::Exception) +{ + std::vector fams=getFamiliesOnGroup(grp); + return getFamsNonEmptyLevelsExt(fams); +} + +/*! + * This methods returns all relative mesh levels where family 'fam' is defined \b excluded \b nodes. + * To include nodes call MEDFileUMesh::getFamNonEmptyLevelsExt method. + */ +std::vector MEDFileUMesh::getFamNonEmptyLevels(const char *fam) const throw(INTERP_KERNEL::Exception) +{ + std::vector fams(1,std::string(fam)); + return getFamsNonEmptyLevels(fams); +} + +/*! + * This method is a generalization of MEDFileUMesh::getFamNonEmptyLevels. It looks at the node level to state if the family 'fam' has a part lying on node. + */ +std::vector MEDFileUMesh::getFamNonEmptyLevelsExt(const char *fam) const throw(INTERP_KERNEL::Exception) +{ + std::vector fams(1,std::string(fam)); + return getFamsNonEmptyLevelsExt(fams); +} + +/*! + * This methods returns all relative mesh levels where groups 'grps' are defined \b excluded \b nodes. + * To include nodes call MEDFileUMesh::getGrpsNonEmptyLevelsExt method. + */ +std::vector MEDFileUMesh::getGrpsNonEmptyLevels(const std::vector& grps) const throw(INTERP_KERNEL::Exception) +{ + std::vector fams=getFamiliesOnGroups(grps); + return getFamsNonEmptyLevels(fams); +} + +/*! + * This method is a generalization of MEDFileUMesh::getGrpsNonEmptyLevels. It looks at the node level to state if the families 'fams' has a part lying on node. + */ +std::vector MEDFileUMesh::getGrpsNonEmptyLevelsExt(const std::vector& grps) const throw(INTERP_KERNEL::Exception) +{ + std::vector fams=getFamiliesOnGroups(grps); + return getFamsNonEmptyLevelsExt(fams); +} + +/*! + * This methods returns all relative mesh levels where families 'fams' are defined \b excluded \b nodes. + * To include nodes call MEDFileUMesh::getFamsNonEmptyLevelsExt method. + */ +std::vector MEDFileUMesh::getFamsNonEmptyLevels(const std::vector& fams) const throw(INTERP_KERNEL::Exception) +{ + std::vector ret; + std::vector levs=getNonEmptyLevels(); + std::vector famIds=getFamiliesIds(fams); + for(std::vector::const_iterator it=levs.begin();it!=levs.end();it++) + if(_ms[-(*it)]->presenceOfOneFams(famIds)) + ret.push_back(*it); + return ret; +} + +/*! + * This method is a generalization of MEDFileUMesh::getFamsNonEmptyLevels. It looks at the node level to state if the families 'fams' has a part lying on node. + */ +std::vector MEDFileUMesh::getFamsNonEmptyLevelsExt(const std::vector& fams) const throw(INTERP_KERNEL::Exception) +{ + std::vector ret0=getFamsNonEmptyLevels(fams); + const DataArrayInt *famCoords=_fam_coords; + if(!famCoords) + return ret0; + std::vector famIds=getFamiliesIds(fams); + if(famCoords->presenceOfValue(famIds)) + { + std::vector ret(ret0.size()+1); + ret[0]=1; + std::copy(ret0.begin(),ret0.end(),ret.begin()+1); + return ret; + } + else + return ret0; +} + int MEDFileUMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception) { int lev=0; @@ -1023,18 +1122,7 @@ MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMaxExt, const char *grp MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMaxExt, const std::vector& grps, bool renum) const throw(INTERP_KERNEL::Exception) { synchronizeTinyInfoOnLeaves(); - std::set fams; - for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++) - { - std::map >::const_iterator it2=_groups.find(*it); - if(it2==_groups.end()) - { - std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - fams.insert((*it2).second.begin(),(*it2).second.end()); - } - std::vector fams2(fams.begin(),fams.end()); + std::vector fams2=getFamiliesOnGroups(grps); return getFamilies(meshDimRelToMaxExt,fams2,renum); } diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 1e2fd6dbe..edc45f2ea 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -67,6 +67,7 @@ namespace ParaMEDMEM const std::map& getFamilyInfo() const { return _families; } const std::map >& getGroupInfo() const { return _groups; } std::vector getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getFamiliesOnGroups(const std::vector& grps) const throw(INTERP_KERNEL::Exception); std::vector getFamiliesIdsOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); void setFamiliesOnGroup(const char *name, const std::vector& fams) throw(INTERP_KERNEL::Exception); void setFamiliesIdsOnGroup(const char *name, const std::vector& famIds) throw(INTERP_KERNEL::Exception); @@ -137,6 +138,14 @@ namespace ParaMEDMEM const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); std::vector getNonEmptyLevels() const; std::vector getNonEmptyLevelsExt() const; + std::vector getGrpNonEmptyLevels(const char *grp) const throw(INTERP_KERNEL::Exception); + std::vector getGrpNonEmptyLevelsExt(const char *grp) const throw(INTERP_KERNEL::Exception); + std::vector getFamNonEmptyLevels(const char *fam) const throw(INTERP_KERNEL::Exception); + std::vector getFamNonEmptyLevelsExt(const char *fam) const throw(INTERP_KERNEL::Exception); + std::vector getGrpsNonEmptyLevels(const std::vector& grps) const throw(INTERP_KERNEL::Exception); + std::vector getGrpsNonEmptyLevelsExt(const std::vector& grps) const throw(INTERP_KERNEL::Exception); + std::vector getFamsNonEmptyLevels(const std::vector& fams) const throw(INTERP_KERNEL::Exception); + std::vector getFamsNonEmptyLevelsExt(const std::vector& fams) const throw(INTERP_KERNEL::Exception); DataArrayDouble *getCoords() const; MEDCouplingUMesh *getGroup(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getGroups(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 83caf3aa2..9ce105d77 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -552,6 +552,14 @@ bool MEDFileUMeshSplitL1::empty() const return ((const MEDCouplingUMesh *)_m_by_types)==0; } +bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector& ids) const +{ + const DataArrayInt *fam=_fam; + if(!fam) + return false; + return fam->presenceOfValue(ids); +} + int MEDFileUMeshSplitL1::getMeshDimension() const { return _m_by_types->getMeshDimension(); diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index c6b4a5fd5..8cf4de732 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -126,6 +126,7 @@ namespace ParaMEDMEM void synchronizeTinyInfo(const MEDFileMesh& master) const; void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception); bool empty() const; + bool presenceOfOneFams(const std::vector& ids) const; int getMeshDimension() const; int getSize() const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *getFamilyPart(const std::vector& ids, bool renum) const; diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index e26d9db62..6791c9586 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -266,6 +266,7 @@ namespace ParaMEDMEM const std::map& getFamilyInfo() const; const std::map >& getGroupInfo() const; std::vector getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getFamiliesOnGroups(const std::vector& grps) const throw(INTERP_KERNEL::Exception); std::vector getFamiliesIdsOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); void setFamiliesOnGroup(const char *name, const std::vector& fams) throw(INTERP_KERNEL::Exception); void setFamiliesIdsOnGroup(const char *name, const std::vector& famIds) throw(INTERP_KERNEL::Exception); @@ -373,6 +374,14 @@ namespace ParaMEDMEM // std::vector getNonEmptyLevels() const; std::vector getNonEmptyLevelsExt() const; + std::vector getGrpNonEmptyLevels(const char *grp) const throw(INTERP_KERNEL::Exception); + std::vector getGrpNonEmptyLevelsExt(const char *grp) const throw(INTERP_KERNEL::Exception); + std::vector getFamNonEmptyLevels(const char *fam) const throw(INTERP_KERNEL::Exception); + std::vector getFamNonEmptyLevelsExt(const char *fam) const throw(INTERP_KERNEL::Exception); + std::vector getGrpsNonEmptyLevels(const std::vector& grps) const throw(INTERP_KERNEL::Exception); + std::vector getGrpsNonEmptyLevelsExt(const std::vector& grps) const throw(INTERP_KERNEL::Exception); + std::vector getFamsNonEmptyLevels(const std::vector& fams) const throw(INTERP_KERNEL::Exception); + std::vector getFamsNonEmptyLevelsExt(const std::vector& fams) const throw(INTERP_KERNEL::Exception); DataArrayDouble *getCoords() const; MEDCouplingUMesh *getGroup(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 07eb86dc4..9393d482f 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -331,6 +331,15 @@ class MEDLoaderTest(unittest.TestCase): pass m.setName(m2.getName()) m.setDescription(m2.getDescription()) + # + self.assertEqual((-1,),m.getGrpNonEmptyLevels("A2A4")) + self.assertEqual((),m.getGrpNonEmptyLevels("A1")) + self.assertEqual((-2,),m.getGrpNonEmptyLevels("AP2")) + self.assertEqual((-1,-2),m.getGrpsNonEmptyLevels(["A2A4","AP2"])) + self.assertEqual((-1,),m.getFamNonEmptyLevels('A4A3____________________________')) + self.assertEqual((0,),m.getFamNonEmptyLevels('MESH____DALT3___DALLE___________')) + self.assertEqual((0,-1,),m.getFamsNonEmptyLevels(['MESH____DALT3___DALLE___________','A4A3____________________________'])) + # m.write(fileName,2) pass