From: ageay Date: Thu, 16 Feb 2012 16:02:45 +0000 (+0000) Subject: MEDFileUMesh::getGroupsOnASpecifiedLevel X-Git-Tag: V6_main_FINAL~850 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b97cc1bcf587d968bd0bfbe8a03272fb9930f3a2;p=tools%2Fmedcoupling.git MEDFileUMesh::getGroupsOnASpecifiedLevel --- diff --git a/src/MEDLoader/MEDFileData.cxx b/src/MEDLoader/MEDFileData.cxx index 20c1f82b7..67ad6a0a3 100644 --- a/src/MEDLoader/MEDFileData.cxx +++ b/src/MEDLoader/MEDFileData.cxx @@ -116,7 +116,8 @@ void MEDFileData::write(const char *fileName, int mode) const throw(INTERP_KERNE const MEDFileMeshes *ms=_meshes; if(ms) ms->write(fileName,mode); + int mode2=mode==2?0:mode; const MEDFileFields *fs=_fields; if(fs) - fs->write(fileName,mode); + fs->write(fileName,mode2); } diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index cd2284a5a..9653ab1d8 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -1157,6 +1157,22 @@ std::vector MEDFileUMesh::getFamsNonEmptyLevelsExt(const std::vector MEDFileUMesh::getGroupsOnSpecifiedLev(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + std::vector ret; + std::vector allGrps=getGroupsNames(); + for(std::vector::const_iterator it=allGrps.begin();it!=allGrps.end();it++) + { + std::vector levs=getGrpNonEmptyLevelsExt((*it).c_str()); + if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)!=levs.end()) + ret.push_back(*it); + } + return ret; +} + int MEDFileUMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception) { int lev=0; @@ -2299,10 +2315,14 @@ MEDFileMeshes *MEDFileMeshes::New(const char *fileName) throw(INTERP_KERNEL::Exc void MEDFileMeshes::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) { checkCoherency(); - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_meshes.begin();it!=_meshes.end();it++) + int i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++) { + int mode2=mode; + if(mode==2 && i>0) + mode2=0; (*it)->copyOptionsFrom(*this); - (*it)->write(fileName,mode); + (*it)->write(fileName,mode2); } } diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 8aa496ecf..62f0bf4ce 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -159,6 +159,7 @@ namespace ParaMEDMEM 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); + std::vector getGroupsOnSpecifiedLev(int meshDimRelToMaxExt) 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/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 6cabc1a70..c9d9894ce 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -468,6 +468,7 @@ namespace ParaMEDMEM 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); + std::vector getGroupsOnSpecifiedLev(int meshDimRelToMaxExt) 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 ec772ef66..04843325a 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -346,6 +346,8 @@ class MEDLoaderTest(unittest.TestCase): self.assertEqual((-1,),m.getFamNonEmptyLevels('A4A3____________________________')) self.assertEqual((0,),m.getFamNonEmptyLevels('MESH____DALT3___DALLE___________')) self.assertEqual((0,-1,),m.getFamsNonEmptyLevels(['MESH____DALT3___DALLE___________','A4A3____________________________'])) + self.assertEqual(('A1A2','A2A4','A3A1','A3C5','A4A3','B1C1','B2B4','B3B1','B4C3','C1C4','C2B2','C3C2','C4B3','C5A4'),m.getGroupsOnSpecifiedLev(-1)) + self.assertEqual(('DALLE','DALQ1','DALQ2','DALT3','MESH'),m.getGroupsOnSpecifiedLev(0)) # m.write(fileName,2) pass @@ -364,7 +366,7 @@ class MEDLoaderTest(unittest.TestCase): mm.write("Pyfile19_bis.med",2) ff=MEDFileFieldMultiTS.New("Pyfile19.med","VFieldOnNodes") ff.write("Pyfile19_bis.med",0) - self.assertEqual([('tyty', 'mm'), ('uiop', 'MW')],MEDLoader.GetComponentsNamesOfField("Pyfile19_bis.med","VFieldOnNodes")) + self.assertEqual([('tyty','mm'),('uiop','MW')],MEDLoader.GetComponentsNamesOfField("Pyfile19_bis.med","VFieldOnNodes")) pass #gauss points @@ -557,9 +559,10 @@ class MEDLoaderTest(unittest.TestCase): fs.pushField(ff1) ; fs.pushField(ff21) ; fs.pushField(ff22) d.setFields(fs) # - d.write(fname,0) + fname2="Pyfile29_2.med" + d.write(fname2,2) # - d2=MEDFileData.New(fname) + d2=MEDFileData.New(fname2) self.assertEqual(2,d2.getNumberOfMeshes()) self.assertEqual(3,d2.getNumberOfFields()) self.assertTrue(isinstance(d2.getMeshes().getMeshAtPos(0),MEDFileUMesh))