From: ageay Date: Tue, 25 Oct 2011 13:44:10 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V6_main_FINAL~923 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=421c5d36898619c53cd2f3ccbe67a3d9b6c9bcc1;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 2e0bb2ceb..5dcfcd00d 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -300,6 +300,42 @@ std::vector MEDFileMesh::getFamiliesNames() const return ret; } +/*! + * This method scans every families and for each families shared by only one group, the corresponding family takes the same name than the group. + */ +void MEDFileMesh::assignFamilyNameWithGroupName() throw(INTERP_KERNEL::Exception) +{ + std::map > groups(_groups); + std::map newFams; + for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) + { + std::vector grps=getGroupsOnFamily((*it).first.c_str()); + if(grps.size()==1 && groups[grps[0]].size()==1) + { + if(newFams.find(grps[0])!=newFams.end()) + { + std::ostringstream oss; oss << "MEDFileMesh::assignFamilyNameWithGroupName : Family \"" << grps[0] << "\" already exists !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + newFams[grps[0]]=(*it).second; + std::vector& grps2=groups[grps[0]]; + std::size_t pos=std::distance(grps2.begin(),std::find(grps2.begin(),grps2.end(),(*it).first)); + grps2[pos]=grps[0]; + } + else + { + if(newFams.find((*it).first)!=newFams.end()) + { + std::ostringstream oss; oss << "MEDFileMesh::assignFamilyNameWithGroupName : Family \"" << (*it).first << "\" already exists !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + newFams[(*it).first]=(*it).second; + } + } + _families=newFams; + _groups=groups; +} + void MEDFileMesh::removeGroup(const char *name) throw(INTERP_KERNEL::Exception) { std::string oname(name); @@ -1475,16 +1511,13 @@ void MEDFileUMesh::setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, b c->incrRef(); _coords=c; } - else - { - if(m->getCoords()!=_coords) - throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshAtLevel : Invalid Given Mesh ! The coordinates are not the same ! try to use tryToShareSameCoords !"); - int sz=(-meshDimRelToMax)+1; - if(sz>=(int)_ms.size()) - _ms.resize(sz); - checkMeshDimCoherency(m->getMeshDimension(),meshDimRelToMax); - _ms[sz-1]=new MEDFileUMeshSplitL1(m,newOrOld); - } + if(m->getCoords()!=_coords) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshAtLevel : Invalid Given Mesh ! The coordinates are not the same ! try to use tryToShareSameCoords !"); + int sz=(-meshDimRelToMax)+1; + if(sz>=(int)_ms.size()) + _ms.resize(sz); + checkMeshDimCoherency(m->getMeshDimension(),meshDimRelToMax); + _ms[sz-1]=new MEDFileUMeshSplitL1(m,newOrOld); } else _ms[-meshDimRelToMax]=new MEDFileUMeshSplitL1(m,newOrOld); diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index f85df5314..f90d0bd29 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -78,6 +78,7 @@ namespace ParaMEDMEM void setGroupsOnFamily(const char *famName, const std::vector& grps) throw(INTERP_KERNEL::Exception); std::vector getGroupsNames() const; std::vector getFamiliesNames() const; + void assignFamilyNameWithGroupName() throw(INTERP_KERNEL::Exception); void removeGroup(const char *name) throw(INTERP_KERNEL::Exception); void removeFamily(const char *name) throw(INTERP_KERNEL::Exception); void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 8d30be1c2..b14c4b849 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -309,6 +309,7 @@ namespace ParaMEDMEM void setGroupsOnFamily(const char *famName, const std::vector& grps) throw(INTERP_KERNEL::Exception); std::vector getGroupsNames() const; std::vector getFamiliesNames() const; + void assignFamilyNameWithGroupName() throw(INTERP_KERNEL::Exception); void removeGroup(const char *name) throw(INTERP_KERNEL::Exception); void removeFamily(const char *name) throw(INTERP_KERNEL::Exception); void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 5018668c2..c135a8e8a 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -869,6 +869,41 @@ class MEDLoaderTest(unittest.TestCase): d=MEDFileData.New(fname) self.assertEqual(('GP_MyFirstFieldOnGaussPoint0', 'GP_MyFirstFieldOnGaussPoint1', 'GP_MyFirstFieldOnGaussPoint2'),d.getFields().getFieldAtPos(0).getLocs()) pass + + def testMEDMesh8(self): + m=MEDLoaderDataForTest.build1DMesh_1() + m.convertQuadraticCellsToLinear() + mm=MEDFileUMesh.New() + mm.setMeshAtLevel(0,m) + g1=DataArrayInt.New() ; g1.setValues([0,2],2,1) ; g1.setName("g1") + g2=DataArrayInt.New() ; g2.setValues([1,3],2,1) ; g2.setName("g2") + g3=DataArrayInt.New() ; g3.setValues([1,2,3],3,1) ; g3.setName("g3") + mm.setGroupsAtLevel(0,[g1,g2],False) + self.assertEqual(('g1','g2'),mm.getGroupsNames()) + self.assertEqual(('Family_2','Family_3'),mm.getFamiliesNames()) + self.assertEqual(('Family_2',),mm.getFamiliesOnGroup('g1')) + self.assertEqual(('Family_3',),mm.getFamiliesOnGroup('g2')) + mm.assignFamilyNameWithGroupName() + self.assertEqual(('g1','g2'),mm.getGroupsNames()) + self.assertEqual(('g1','g2'),mm.getFamiliesNames()) + self.assertEqual(('g1',),mm.getFamiliesOnGroup('g1')) + self.assertEqual(('g2',),mm.getFamiliesOnGroup('g2')) + # + mm=MEDFileUMesh.New() + mm.setMeshAtLevel(0,m) + mm.setGroupsAtLevel(0,[g1,g2,g3],False) + self.assertEqual(('g1','g2','g3'),mm.getGroupsNames()) + self.assertEqual(('Family_2', 'Family_4', 'Family_5'),mm.getFamiliesNames()) + self.assertEqual(('Family_2', 'Family_4'),mm.getFamiliesOnGroup('g1')) + self.assertEqual(('Family_5',),mm.getFamiliesOnGroup('g2')) + self.assertEqual(('Family_4','Family_5',),mm.getFamiliesOnGroup('g3')) + mm.assignFamilyNameWithGroupName() # here it does nothing because no such group-family bijection found + self.assertEqual(('g1','g2','g3'),mm.getGroupsNames()) + self.assertEqual(('Family_2', 'Family_4', 'Family_5'),mm.getFamiliesNames()) + self.assertEqual(('Family_2', 'Family_4'),mm.getFamiliesOnGroup('g1')) + self.assertEqual(('Family_5',),mm.getFamiliesOnGroup('g2')) + self.assertEqual(('Family_4','Family_5',),mm.getFamiliesOnGroup('g3')) + pass pass unittest.main()