return ret;
}
+void MEDFileMesh::removeGroupAtLevel(int meshDimRelToMaxExt, const std::string& name)
+{
+ std::map<std::string, std::vector<std::string> >::iterator it(_groups.find(name));
+ std::vector<std::string> grps(getGroupsNames());
+ if(it==_groups.end())
+ {
+ std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
+ std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ const std::vector<std::string> &famsOnGrp((*it).second);
+ std::vector<int> famIds(getFamiliesIdsOnGroup(name));
+ const DataArrayInt *famArr(getFamilyFieldAtLevel(meshDimRelToMaxExt));
+ if(!famArr)
+ return ;
+ MCAuto<DataArrayInt> vals(famArr->getDifferentValues());
+ MCAuto<DataArrayInt> famIds2(DataArrayInt::NewFromStdVector(famIds));
+ MCAuto<DataArrayInt> idsToKill(famIds2->buildIntersection(vals));
+ if(idsToKill->empty())
+ return ;
+ std::vector<std::string> newFamsOnGrp;
+ for(std::vector<std::string>::const_iterator it=famsOnGrp.begin();it!=famsOnGrp.end();it++)
+ {
+ if(!idsToKill->presenceOfValue(getFamilyId(*it)))
+ newFamsOnGrp.push_back(*it);
+ }
+ (*it).second=newFamsOnGrp;
+}
+
/*!
* Removes a group from \a this mesh.
* \param [in] name - the name of the group to remove.
*/
void MEDFileMesh::removeGroup(const std::string& name)
{
- std::string oname(name);
- std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
- std::vector<std::string> grps=getGroupsNames();
+ std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(name);
+ std::vector<std::string> grps(getGroupsNames());
if(it==_groups.end())
{
std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
}
}
+void MEDFileMesh::checkNoGroupClash(const DataArrayInt *famArr, const std::string& grpName) const
+{
+ std::vector<std::string> grpsNames(getGroupsNames());
+ if(std::find(grpsNames.begin(),grpsNames.end(),grpName)==grpsNames.end())
+ return ;
+ std::vector<int> famIds(getFamiliesIdsOnGroup(grpName));
+ if(famArr->presenceOfValue(famIds))
+ {
+ std::ostringstream oss; oss << "MEDFileUMesh::addGroup : Group with name \"" << grpName << "\" already exists at specified level ! Destroy it before calling this method !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+}
+
/*!
* \param [in] ids ids and group name of the new group to add. The ids should be sorted and different each other (MED file norm).
* \parma [in,out] famArr family array on level of interest to be renumbered. The input pointer should be not \c NULL (no check of that will be performed)
if(grpName.empty())
throw INTERP_KERNEL::Exception("MEDFileUMesh::addGroup : empty group name ! MED file format do not accept empty group name !");
ids->checkStrictlyMonotonic(true);
- famArr->incrRef(); MCAuto<DataArrayInt> famArrTmp(famArr);
- std::vector<std::string> grpsNames=getGroupsNames();
- if(std::find(grpsNames.begin(),grpsNames.end(),grpName)!=grpsNames.end())
- {
- std::ostringstream oss; oss << "MEDFileUMesh::addGroup : Group with name \"" << grpName << "\" already exists ! Destroy it before calling this method !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
+ checkNoGroupClash(famArr,grpName);
+ MCAuto<DataArrayInt> famArrTmp; famArrTmp.takeRef(famArr);
std::list< MCAuto<DataArrayInt> > allFamIds(getAllNonNullFamilyIds());
allFamIds.erase(std::find(allFamIds.begin(),allFamIds.end(),famArrTmp));
MCAuto<DataArrayInt> famIds=famArr->selectByTupleIdSafe(ids->begin(),ids->end());
famArr->setPartOfValuesSimple3(familyIds[i],da->begin(),da->end(),0,1,1);
}
_families=families;
+ std::map<std::string, std::vector<std::string> >::iterator itt(groups.find(grpName));
+ if(itt!=groups.end())
+ {
+ std::vector<std::string>& famsOnGrp((*itt).second);
+ famsOnGrp.insert(famsOnGrp.end(),fams.begin(),fams.end());
+ }
+ else
+ groups[grpName]=fams;
_groups=groups;
- _groups[grpName]=fams;
}
void MEDFileMesh::changeAllGroupsContainingFamily(const std::string& familyNameToChange, const std::vector<std::string>& newFamiliesNames)
if(!coords)
throw INTERP_KERNEL::Exception("MEDFileUMesh::addNodeGroup : no coords set !");
int nbOfNodes(coords->getNumberOfTuples());
- if(!((DataArrayInt *)_fam_coords))
+ if(_fam_coords.isNull())
{ _fam_coords=DataArrayInt::New(); _fam_coords->alloc(nbOfNodes,1); _fam_coords->fillWithZero(); }
//
addGroupUnderground(true,ids,_fam_coords);
self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3").isIota(162))
self.assertTrue(f1ts.getProfile("pfl_NORM_QUAD4").isIota(81))
pass
+
+ def testRmGroupAtSpeLevelAndMultiLevGrpCreation(self):
+ """ Here multi level groups are created"""
+ arr=DataArrayDouble(11) ; arr.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
+ m=m.buildUnstructured()
+ m.setName("mesh")
+ m1=m.buildDescendingConnectivity()[0]
+ mm=MEDFileUMesh()
+ mm[0]=m ; mm[-1]=m1
+ ################
+ grpName="grp0"
+ grp0_0=DataArrayInt([0,1,2,6]) ; grp0_0.setName(grpName)
+ grp0_1=DataArrayInt([0,1,2,7]) ; grp0_1.setName(grpName)
+ grp1=DataArrayInt([1,2,3,5,6]) ; grp1.setName("grp1")
+ grp2=DataArrayInt([2,3,5,8]) ; grp2.setName("grp2")
+ ################ ajouter un groupe sur plusieurs niveau
+ mm.addGroup(0,grp1)
+ mm.addGroup(-1,grp2)
+ mm.addGroup(0,grp0_0)
+ mm.addGroup(-1,grp0_1)
+ self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(0,-1))
+ self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
+ self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
+ self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
+ self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
+ self.assertRaises(InterpKernelException,mm.addGroup,-1,grp0_1) # raise
+ self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
+ self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
+ self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
+ self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
+ mm.removeGroupAtLevel(0,grpName)
+ self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(-1,))
+ self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
+ self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
+ self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
+ mm.removeGroupAtLevel(-1,grpName)
+ self.assertEqual(mm.getGrpNonEmptyLevels(grpName),())
+ self.assertRaises(InterpKernelException,mm.removeGroupAtLevel,-2,grpName)
+ mm.addGroup(-1,grp0_1)
+ mm.addGroup(0,grp0_0)
+ self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(0,-1))
+ self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
+ self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
+ self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
+ self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
+ pass
pass