]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Tue, 25 Oct 2011 13:44:10 +0000 (13:44 +0000)
committerageay <ageay>
Tue, 25 Oct 2011 13:44:10 +0000 (13:44 +0000)
src/MEDLoader/MEDFileMesh.cxx
src/MEDLoader/MEDFileMesh.hxx
src/MEDLoader/Swig/MEDLoader.i
src/MEDLoader/Swig/MEDLoaderTest3.py

index 2e0bb2ceb76b3c23c47ecec6cf96833b3fa47ba8..5dcfcd00d6efac4d9c183c890e623a59bc447c59 100644 (file)
@@ -300,6 +300,42 @@ std::vector<std::string> 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<std::string, std::vector<std::string> > groups(_groups);
+  std::map<std::string,int> newFams;
+  for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
+    {
+      std::vector<std::string> 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<std::string>& 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);
index f85df5314c27bf0841ba7bafb453c7d7b2d770a4..f90d0bd293ce63696543fea551b198cece6ca1d9 100644 (file)
@@ -78,6 +78,7 @@ namespace ParaMEDMEM
     void setGroupsOnFamily(const char *famName, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception);
     std::vector<std::string> getGroupsNames() const;
     std::vector<std::string> 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);
index 8d30be1c247b66e2782fdc207175447763e43794..b14c4b849d0d3c6bb068a7e35cf0b727d6b1b1a6 100644 (file)
@@ -309,6 +309,7 @@ namespace ParaMEDMEM
     void setGroupsOnFamily(const char *famName, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception);
     std::vector<std::string> getGroupsNames() const;
     std::vector<std::string> 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);
index 5018668c2757e40be73c7ca9f5d207b6fe5a2575..c135a8e8a6eb614d0450405b145157f0e41a442a 100644 (file)
@@ -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()