* This method is here only to add a group on node.
* MEDFileUMesh::setGroupsAtLevel with 1 in the first parameter.
*
- * \param [in] ids node ids of and group name of the new group to add. The ids should be sorted and different each other (MED file norm).
+ * \param [in] ids node ids and group name of the new group to add. The ids should be sorted and different each other (MED file norm).
*/
void MEDFileUMesh::addNodeGroup(const DataArrayInt *ids) throw(INTERP_KERNEL::Exception)
-{
+{
+ const DataArrayDouble *coords=_coords;
+ if(!coords)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::addNodeGroup : no coords set !");
+ int nbOfNodes=coords->getNumberOfTuples();
+ if(!((DataArrayInt *)_fam_coords))
+ { _fam_coords=DataArrayInt::New(); _fam_coords->alloc(nbOfNodes,1); _fam_coords->fillWithZero(); }
+ //
+ addGroupUnderground(ids,_fam_coords);
+}
+
+void MEDFileUMesh::addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<int> levs=getNonEmptyLevelsExt();
+ if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)==levs.end())
+ {
+ std::ostringstream oss; oss << "MEDFileUMesh::addGroup : level " << meshDimRelToMaxExt << " not available ! Should be in ";
+ std::copy(levs.begin(),levs.end(),std::ostream_iterator<int>(oss," ")); oss << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ if(meshDimRelToMaxExt==1)
+ { addNodeGroup(ids); return ; }
+ MEDFileUMeshSplitL1 *lev=getMeshAtLevSafe(meshDimRelToMaxExt);
+ DataArrayInt *fam=lev->getOrCreateAndGetFamilyField();
+ addGroupUnderground(ids,fam);
+}
+
+/*!
+ * \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 NULL (no check of that will be performed)
+ */
+void MEDFileUMesh::addGroupUnderground(const DataArrayInt *ids, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception)
+{
if(!ids)
- throw INTERP_KERNEL::Exception("MEDFileUMesh::addNodeGroup : NULL pointer in input !");
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::addGroup : NULL pointer in input !");
std::string grpName(ids->getName());
if(grpName.empty())
- throw INTERP_KERNEL::Exception("MEDFileUMesh::addNodeGroup : empty group name ! MED file format do not accept empty group name !");
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::addGroup : empty group name ! MED file format do not accept empty group name !");
ids->checkStrictlyMonotonic(true);
+ famArr->incrRef(); MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famArrTmp(famArr);
std::vector<std::string> grpsNames=getGroupsNames();
if(std::find(grpsNames.begin(),grpsNames.end(),grpName)!=grpsNames.end())
{
- std::ostringstream oss; oss << "MEDFileUMesh::addNodeGroup : Group with name \"" << grpName << "\" already exists ! Destroy it before calling this method !";
+ 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());
}
- const DataArrayDouble *coords=_coords;
- if(!coords)
- throw INTERP_KERNEL::Exception("MEDFileUMesh::addNodeGroup : no coords set !");
- int nbOfNodes=coords->getNumberOfTuples();
- if(!((DataArrayInt *)_fam_coords))
- { _fam_coords=DataArrayInt::New(); _fam_coords->alloc(nbOfNodes,1); _fam_coords->fillWithZero(); }
std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > allFamIds=getAllNonNullFamilyIds();
- allFamIds.erase(std::find(allFamIds.begin(),allFamIds.end(),_fam_coords));
- //
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famIds=_fam_coords->selectByTupleIdSafe(ids->begin(),ids->end());
+ allFamIds.erase(std::find(allFamIds.begin(),allFamIds.end(),famArrTmp));
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famIds=famArr->selectByTupleIdSafe(ids->begin(),ids->end());
std::set<int> diffFamIds=famIds->getDifferentValues();
std::vector<int> familyIds;
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerfamiliyIds;
{
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids2Tmp=famIds->getIdsEqual(*famId);
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids2=ids->selectByTupleId(ids2Tmp->begin(),ids2Tmp->end());
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids1=_fam_coords->getIdsEqual(*famId);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids1=famArr->getIdsEqual(*famId);
DataArrayInt *ret0=0,*ret1=0;
ids1->splitInTwoPartsWith(ids2,ret0,ret1);
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret00(ret0),ret11(ret1);
for(std::size_t i=0;i<familyIds.size();i++)
{
DataArrayInt *da=idsPerfamiliyIds[i];
- _fam_coords->setPartOfValuesSimple3(familyIds[i],da->begin(),da->end(),0,1,1);
+ famArr->setPartOfValuesSimple3(familyIds[i],da->begin(),da->end(),0,1,1);
}
_families=families;
_groups=groups;
void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception);
void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception);
void addNodeGroup(const DataArrayInt *ids) throw(INTERP_KERNEL::Exception);
+ void addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids) throw(INTERP_KERNEL::Exception);
void removeMeshAtLevel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception);
void setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld=false) throw(INTERP_KERNEL::Exception);
void setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
void synchronizeTinyInfoOnLeaves() const;
void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception);
std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > getAllNonNullFamilyIds() const;
+ void addGroupUnderground(const DataArrayInt *ids, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception);
private:
std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> > _ms;
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
return tmp.retn();
}
+DataArrayInt *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField() throw(INTERP_KERNEL::Exception)
+{
+ if((DataArrayInt *)_fam)
+ return _fam;
+ MEDCouplingUMesh *m(_m_by_types);
+ if(!m)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField : impossible to create a family field array because no mesh specified on this level !");
+ int nbOfTuples=m->getNumberOfCells();
+ _fam=DataArrayInt::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero();
+ return _fam;
+}
+
const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const
{
return _fam;
MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
MEDCouplingUMesh *getWholeMesh(bool renum) const;
+ DataArrayInt *getOrCreateAndGetFamilyField() throw(INTERP_KERNEL::Exception);
const DataArrayInt *getFamilyField() const;
const DataArrayInt *getNumberField() const;
const DataArrayInt *getRevNumberField() const;
void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
void eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception);
void addNodeGroup(const DataArrayInt *ids) throw(INTERP_KERNEL::Exception);
+ void addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids) throw(INTERP_KERNEL::Exception);
void removeMeshAtLevel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception);
void setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld=false) throw(INTERP_KERNEL::Exception);
void setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
da.setValues([1])
self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
pass
+
+ def testMEDUMeshAddGroup1(self):
+ fname="Pyfile54.med"
+ m=MEDFileUMesh()
+ coo=DataArrayDouble(9) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
+ m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0)
+ for i in xrange(7):
+ m0.insertNextCell(NORM_TRI3,[1,2,1])
+ pass
+ for i in xrange(4):
+ m0.insertNextCell(NORM_QUAD4,[1,1,2,0])
+ pass
+ for i in xrange(2):
+ m0.insertNextCell(NORM_POLYGON,[0,0,1,1,2,2])
+ pass
+ m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
+ m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
+ m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
+ m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
+ m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
+ #
+ mm=m.deepCpy()
+ famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(0,famCoo)
+ da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(1,da0)
+ da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
+ da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
+ mm.setFamilyId("MyFam",2)
+ mm.setFamilyId("MyOtherFam",3)
+ mm.setFamilyId("MyOther-1",-1)
+ mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
+ mm.setFamiliesOnGroup("grpA",["MyOther-1"])
+ #
+ daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
+ mm.addGroup(0,daTest)
+ self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
+ self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
+ for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
+ self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
+ pass
+ self.assertEqual(mm.getFamiliesNames(),('Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
+ self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
+ self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
+ self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
+ for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
+ self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
+ pass
+ self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_8'))
+ da=DataArrayInt([3,12]) ; da.setName("grp0")
+ self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
+ da.setValues([1])
+ self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
+ mm.write(fname,2)
+ mm=MEDFileMesh.New(fname)
+ self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
+ self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
+ for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
+ self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
+ pass
+ self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
+ self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
+ self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
+ self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
+ for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
+ self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
+ pass
+ self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_8','MyOtherFam'))
+ da=DataArrayInt([3,12]) ; da.setName("grp0")
+ self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
+ da.setValues([1])
+ self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
+ pass
pass
unittest.main()