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);
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);
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()