From 7d27c648c6f4b86e634491519860185ec8a0f13e Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 15 Apr 2011 15:45:41 +0000 Subject: [PATCH] *** empty log message *** --- src/MEDLoader/MEDFileMesh.cxx | 112 ++++++++++++++++++--- src/MEDLoader/MEDFileMesh.hxx | 4 + src/MEDLoader/Swig/MEDLoader.i | 4 + src/MEDLoader/Swig/MEDLoaderDataForTest.py | 86 ++++++++++++++++ src/MEDLoader/Swig/MEDLoaderTest3.py | 28 ++++++ 5 files changed, 218 insertions(+), 16 deletions(-) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 9ec1d9a92..5edf39e81 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -176,6 +176,53 @@ std::vector MEDFileMesh::getFamiliesOnGroup(const char *name) const return (*it).second; } +std::vector MEDFileMesh::getFamiliesIdsOnGroup(const char *name) const throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::map >::const_iterator it=_groups.find(oname); + std::vector 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(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return getFamiliesIds((*it).second); +} + +/*! + * This method sets families at a corresponding groups existing or not. If it existed, it is replaced by new 'fams'. + * Each entry in 'fams' is checked if it is not still existing default id 0 is set. + */ +void MEDFileMesh::setFamiliesOnGroup(const char *name, const std::vector& fams) throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + _groups[oname]=fams; + for(std::vector::const_iterator it1=fams.begin();it1!=fams.end();it1++) + { + std::map::iterator it2=_families.find(*it1); + if(it2==_families.end()) + _families[*it1]=0; + } +} + +/*! + * Behaves as MEDFileMesh::setFamiliesOnGroup, except that if there is presence of a family id in 'famIds' not existing an exception is thrown. + * If several families have same id the first one in lexical order is taken into account. + */ +void MEDFileMesh::setFamiliesIdsOnGroup(const char *name, const std::vector& famIds) throw(INTERP_KERNEL::Exception) +{ + std::string oname(name); + std::vector fams(famIds.size()); + int i=0; + for(std::vector::const_iterator it1=famIds.begin();it1!=famIds.end();it1++,i++) + { + std::string name=getFamilyNameGivenId(*it1); + fams[i]=name; + } + _groups[oname]=fams; +} + std::vector MEDFileMesh::getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception) { std::vector ret; @@ -191,6 +238,33 @@ std::vector MEDFileMesh::getGroupsOnFamily(const char *name) const return ret; } +/*! + * This method expects that family 'famName' is already existing. If not an exception will be thrown. + */ +void MEDFileMesh::setGroupsOnFamily(const char *famName, const std::vector& grps) throw(INTERP_KERNEL::Exception) +{ + std::string fName(famName); + const std::map::const_iterator it=_families.find(fName); + if(it==_families.end()) + { + std::vector fams=getFamiliesNames(); + std::ostringstream oss; oss << "No such familyname \"" << fName << "\" !\nAvailable families are :"; + std::copy(fams.begin(),fams.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + for(std::vector::const_iterator it=grps.begin();it!=grps.end();it++) + { + std::map< std::string, std::vector >::iterator it2=_groups.find(*it); + if(it2!=_groups.end()) + (*it2).second.push_back(fName); + else + { + std::vector grps(1,fName); + _groups[*it]=grps; + } + } +} + std::vector MEDFileMesh::getGroupsNames() const { std::vector ret(_groups.size()); @@ -443,6 +517,25 @@ int MEDFileMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Except return (*it).second; } +std::vector MEDFileMesh::getFamiliesIds(const std::vector& fams) const throw(INTERP_KERNEL::Exception) +{ + std::vector ret(fams.size()); + int i=0; + for(std::vector::const_iterator it=fams.begin();it!=fams.end();it++,i++) + { + std::map::const_iterator it2=_families.find(*it); + if(it2==_families.end()) + { + std::vector fams2=getFamiliesNames(); + std::ostringstream oss; oss << "No such familyname \"" << *it << "\" in input list !\nAvailable families are :"; + std::copy(fams2.begin(),fams2.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + ret[i]=(*it2).second; + } + return ret; +} + int MEDFileMesh::getMaxFamilyId() const throw(INTERP_KERNEL::Exception) { if(_families.empty()) @@ -455,22 +548,9 @@ int MEDFileMesh::getMaxFamilyId() const throw(INTERP_KERNEL::Exception) return ret; } -std::vector MEDFileMesh::getFamiliesIds(const std::vector& famNames) const throw(INTERP_KERNEL::Exception) -{ - std::vector famIds; - for(std::vector::const_iterator it=famNames.begin();it!=famNames.end();it++) - { - std::map::const_iterator it2=_families.find(*it); - if(it2==_families.end()) - { - std::ostringstream oss; oss << "No such family in mesh \"" << _name << "\" : " << *it; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - famIds.push_back((*it2).second); - } - return famIds; -} - +/*! + * Returns the first (in lexical order) family name having family id equal to 'id'. + */ std::string MEDFileMesh::getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception) { for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 7550f8cbf..a046a9a69 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -66,7 +66,11 @@ namespace ParaMEDMEM const std::map& getFamilyInfo() const { return _families; } const std::map >& getGroupInfo() const { return _groups; } std::vector getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getFamiliesIdsOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); + void setFamiliesOnGroup(const char *name, const std::vector& fams) throw(INTERP_KERNEL::Exception); + void setFamiliesIdsOnGroup(const char *name, const std::vector& famIds) throw(INTERP_KERNEL::Exception); std::vector getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception); + void setGroupsOnFamily(const char *famName, const std::vector& grps) throw(INTERP_KERNEL::Exception); std::vector getGroupsNames() const; std::vector getFamiliesNames() const; void removeGroup(const char *name) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 4f05aebf4..f31bb02a2 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -250,7 +250,11 @@ namespace ParaMEDMEM const std::map& getFamilyInfo() const; const std::map >& getGroupInfo() const; std::vector getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getFamiliesIdsOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); + void setFamiliesOnGroup(const char *name, const std::vector& fams) throw(INTERP_KERNEL::Exception); + void setFamiliesIdsOnGroup(const char *name, const std::vector& famIds) throw(INTERP_KERNEL::Exception); std::vector getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception); + void setGroupsOnFamily(const char *famName, const std::vector& grps) throw(INTERP_KERNEL::Exception); std::vector getGroupsNames() const; std::vector getFamiliesNames() const; void removeGroup(const char *name) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoaderDataForTest.py b/src/MEDLoader/Swig/MEDLoaderDataForTest.py index 9816b795a..ba3f59917 100644 --- a/src/MEDLoader/Swig/MEDLoaderDataForTest.py +++ b/src/MEDLoader/Swig/MEDLoaderDataForTest.py @@ -198,6 +198,91 @@ class MEDLoaderDataForTest: ret=m3dsurf.buildExtrudedMesh(m1d,0); return ret; + def buildMultiLevelMesh_1(cls): + coo=[10.,0.,10.,1.25,10.,2.5,10.,3.75,10.,5.,8.75,0.,8.75,1.25,8.75,2.5,8.75,3.75,8.75,5.,7.5,0.,7.5,1.25,7.5,2.5,7.5,3.75,7.5,5.,6.25,0.,6.25,1.25,6.25,2.5,6.25,3.75,6.25,5.,5.,0.,5.,1.25,5.,2.5,5.,3.75,5.,5.,3.75,0.,3.75,1.25,3.75,2.5,3.75,3.75,3.75,5.,2.5,0.,2.5,1.25,2.5,2.5,2.5,3.75,2.5,5.,1.25,0.,1.25,1.25,1.25,2.5,1.25,3.75,1.25,5.,0.,1.25,0.,2.5,0.,3.75,0.,5.,0.,0.,0.,5.,10.,5.,0.,10.,10.,10.,5.,5.,5.,5.,5.,10.,5.,10.,0.625,5.,1.25,5.,1.875,5.,2.5,5.,3.125,5.,3.75,5.,4.375,5.,5.,6.25,5.,7.5,5.,8.75,4.375,10.,3.75,10.,3.125,10.,2.5,10.,1.875,10.,1.25,10.,0.625,10.,0.,8.75,0.,7.5,0.,6.25,4.375,6.25,4.375,7.5,4.375,8.75,3.75,6.25,3.75,7.5,3.75,8.75,3.125,6.25,3.125,7.5,3.125,8.75,2.5,6.25,2.5,7.5,2.5,8.75,1.875,6.25,1.875,7.5,1.875,8.75,1.25,6.25,1.25,7.5,1.25,8.75,0.625,6.25,0.625,7.5,0.625,8.75,5.625,5.,6.25,5.,6.875,5.,7.5,5.,8.125,5.,8.75,5.,9.375,5.,10.,6.25,10.,7.5,10.,8.75,9.375,10.,8.75,10.,8.125,10.,7.5,10.,6.875,10.,6.25,10.,5.625,10.,5.,8.75,5.,7.5,5.,6.25,9.375,6.25,9.375,7.5,9.375,8.75,8.75,6.25,8.75,7.5,8.75,8.75,8.125,6.25,8.125,7.5,8.125,8.75,7.5,6.25,7.5,7.5,7.5,8.75,6.875,6.25,6.875,7.5,6.875,8.75,6.25,6.25,6.25,7.5,6.25,8.75,5.625,6.25,5.625,7.5,5.625,8.75] + coo2=DataArrayDouble.New() + coo2.setValues(coo,135,2) + coo2=coo2.changeNbOfComponents(3,0.) + coo2.setInfoOnComponent(0,"X [INCONNUE]") + coo2.setInfoOnComponent(1,"Y [INCONNUE]") + coo2.setInfoOnComponent(2,"Z [INCONNUE]") + c2tri=[0,1,6,0,6,5,1,2,6,2,7,6,2,3,8,2,8,7,3,4,8,4,9,8,5,6,11,5,11,10,6,7,11,7,12,11,7,8,13,7,13,12,8,9,13,9,14,13,10,11,16,10,16,15,11,12,16,12,17,16,12,13,18,12,18,17,13,14,18,14,19,18,15,16,21,15,21,20,16,17,21,17,22,21,17,18,23,17,23,22,18,19,23,19,24,23,20,21,26,20,26,25,21,22,26,22,27,26,22,23,28,22,28,27,23,24,28,24,29,28,25,26,31,25,31,30,26,27,31,27,32,31,27,28,33,27,33,32,28,29,33,29,34,33,30,31,36,30,36,35,31,32,36,32,37,36,32,33,38,32,38,37,33,34,38,34,39,38,35,36,40,35,40,44,36,37,40,37,41,40,37,38,42,37,42,41,38,39,42,39,43,42] + c2quad4=[46,101,114,100,101,102,115,114,102,103,116,115,103,48,104,116,100,114,117,99,114,115,118,117,115,116,119,118,116,104,105,119,99,117,120,98,117,118,121,120,118,119,122,121,119,105,106,122,98,120,123,97,120,121,124,123,121,122,125,124,122,106,107,125,97,123,126,96,123,124,127,126,124,125,128,127,125,107,108,128,96,126,129,95,126,127,130,129,127,128,131,130,128,108,109,131,95,129,132,94,129,130,133,132,130,131,134,133,131,109,110,134,94,132,113,50,132,133,112,113,133,134,111,112,134,110,51,111,49,60,73,59,60,61,74,73,61,62,75,74,62,52,63,75,59,73,76,58,73,74,77,76,74,75,78,77,75,63,64,78,58,76,79,57,76,77,80,79,77,78,81,80,78,64,65,81,57,79,82,56,79,80,83,82,80,81,84,83,81,65,66,84,56,82,85,55,82,83,86,85,83,84,87,86,84,66,67,87,55,85,88,54,85,86,89,88,86,87,90,89,87,67,68,90,54,88,91,53,88,89,92,91,89,90,93,92,90,68,69,93,53,91,72,45,91,92,71,72,92,93,70,71,93,69,47,70] + m2=MEDCouplingUMesh.New("ma",2) + m2.setCoords(coo2) + m2.allocateCells(128) + nbTri=len(c2tri)/3 + for i in xrange(nbTri): + m2.insertNextCell(NORM_TRI3,3,c2tri[3*i:3*i+3]) + pass + nbQua=len(c2quad4)/4 + for i in xrange(nbQua): + m2.insertNextCell(NORM_QUAD4,4,c2quad4[4*i:4*i+4]) + pass + m2.finishInsertingCells() + m2.setDescription("CREE PAR CODE_ASTER") + m1=MEDCouplingUMesh.New("ma",1) + m1.setCoords(coo2) + c1seg=[0,1,1,2,2,3,3,4,4,9,9,14,14,19,19,24,24,29,29,34,34,39,39,43,43,42,42,41,41,40,40,44,44,35,35,30,30,25,25,20,20,15,15,10,10,5,5,0,43,39,39,34,34,29,29,24,24,19,19,14,14,9,9,4,45,53,53,54,54,55,55,56,56,57,57,58,58,59,59,49,49,60,60,61,61,62,62,52,52,63,63,64,64,65,65,66,66,67,67,68,68,69,69,47,47,70,70,71,71,72,72,45,50,94,94,95,95,96,96,97,97,98,98,99,99,100,100,46,46,101,101,102,102,103,103,48,48,104,104,105,105,106,106,107,107,108,108,109,109,110,110,51,51,111,111,112,112,113,113,50] + m1.allocateCells(80) + for i in xrange(80): + m1.insertNextCell(NORM_SEG2,2,c1seg[2*i:2*i+2]) + pass + m1.finishInsertingCells() + m1.setDescription("CREE PAR CODE_ASTER") + m0=MEDCouplingUMesh.New("ma",0) + m0.setCoords(coo2) + c0pt=[44,0,47,48] + m0.allocateCells(4) + for i in xrange(4): + m0.insertNextCell(NORM_POINT1,1,[c0pt[i]]) + pass + m0.finishInsertingCells() + f2=DataArrayInt.New() + f2.alloc(128,1) + f2[:64]=-1 + f2[64:96]=-2 + f2[96:]=-3 + f1=DataArrayInt.New() + f1.alloc(80,1) + f1[:4]=-8 + f1[4:12]=-9 + f1[12:16]=-10 + f1[16:24]=-11 + f1[24:28]=-12 + f1[28:32]=-13 + f1[32:40]=-14 + f1[40:44]=-15 + f1[44:52]=-16 + f1[52:56]=-17 + f1[56:64]=-18 + f1[64:68]=-19 + f1[68:76]=-20 + f1[76:]=-21 + f0=DataArrayInt.New() + f0.setValues([-4,-5,-6,-7],4,1) + p=DataArrayInt.New() + p.alloc(135,1) + p.fillWithZero() + p1=DataArrayInt.New() + p1.alloc(13,1) + p1.iota(1) + p[[0,4,24,43,44,45,46,47,48,49,50,51,52]]=p1 + n2=DataArrayInt.New() + n2.alloc(128,1) + n2.iota(1) + n1=DataArrayInt.New() + n1.alloc(80,1) + n1.iota(133) + n0=DataArrayInt.New() + n0.alloc(4,1) + n0.iota(129) + fns=['A1A2____________________________', 'A1______________________________', 'A2A4____________________________', 'A2______________________________', 'A3A1____________________________', 'A3C5____________________________', 'A3______________________________', 'A4A3____________________________', 'A4______________________________', 'B1C1____________________________', 'B1______________________________', 'B2B4____________________________', 'B2______________________________', 'B3B1____________________________', 'B3______________________________', 'B4C3____________________________', 'B4______________________________', 'C1C4____________________________', 'C1______________________________', 'C2B2____________________________', 'C2______________________________', 'C3C2____________________________', 'C3______________________________', 'C4B3____________________________', 'C4______________________________', 'C5A4____________________________', 'C5______PMMA____________________', 'FAMILLE_ZERO', 'MESH____APPS____AP1_____________', 'MESH____APPS____AP2_____________', 'MESH____APPS____AP3_____________', 'MESH____APPS____AP4_____________', 'MESH____DALQ1___DALLE___________', 'MESH____DALQ2___DALLE___________', 'MESH____DALT3___DALLE___________'] + fids=[-11, 5, -8, 1, -10, -12, 4, -9, 2, -14, 6, -19, 7, -17, 8, -20, 9, -15, 10, -18, 11, -21, 12, -16, 13, -13, 3, 0, -4, -5, -6, -7, -3, -2, -1] + grpns=['A1', 'A1A2', 'A2', 'A2A4', 'A3', 'A3A1', 'A3C5', 'A4', 'A4A3', 'AP1', 'AP2', 'AP3', 'AP4', 'APPS', 'B1', 'B1C1', 'B2', 'B2B4', 'B3', 'B3B1', 'B4', 'B4C3', 'C1', 'C1C4', 'C2', 'C2B2', 'C3', 'C3C2', 'C4', 'C4B3', 'C5', 'C5A4', 'DALLE', 'DALQ1', 'DALQ2', 'DALT3', 'MESH', 'PMMA'] + famIdsPerGrp=[[5],[-11],[1],[-8],[4],[-10],[-12],[2],[-9],[-4],[-5],[-6],[-7],[-4,-5,-6,-7],[6],[-14],[7],[-19],[8],[-17],[9],[-20],[10],[-15],[11],[-18],[12],[-21],[13],[-16],[3],[-13],[-3,-2,-1],[-3],[-2],[-1],[-4,-5,-6,-7,-3,-2,-1],[3]] + return m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp + def buildVecFieldOnCells_1(cls): mesh=MEDLoaderDataForTest.build3DSurfMesh_1(); nbOfCells=mesh.getNumberOfCells(); @@ -299,6 +384,7 @@ class MEDLoaderDataForTest: build3DMesh_1=classmethod(build3DMesh_1) build3DSurfMesh_1=classmethod(build3DSurfMesh_1) build3DMesh_2=classmethod(build3DMesh_2) + buildMultiLevelMesh_1=classmethod(buildMultiLevelMesh_1) buildVecFieldOnCells_1=classmethod(buildVecFieldOnCells_1) buildVecFieldOnNodes_1=classmethod(buildVecFieldOnNodes_1) buildVecFieldOnGauss_1=classmethod(buildVecFieldOnGauss_1) diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 32781f31a..78e214c38 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -305,6 +305,34 @@ class MEDLoaderTest(unittest.TestCase): m1.setDescription(m.getDescription()) self.assertTrue(m2.isEqual(m1,1e-12)); pass + + def testMEDMesh7(self): + fileName="Pyfile24.med" + m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1() + m=MEDFileUMesh.New() + m.setCoords(m2.getCoords()) + m.setMeshAtLevel(0,m2) + m.setMeshAtLevel(-1,m1) + m.setMeshAtLevel(-2,m0) + m.setFamilyFieldArr(0,f2) + m.setFamilyFieldArr(-1,f1) + m.setFamilyFieldArr(-2,f0) + m.setFamilyFieldArr(1,p) + m.setRenumFieldArr(0,n2) + m.setRenumFieldArr(-1,n1) + m.setRenumFieldArr(-2,n0) + nbOfFams=len(fns) + for i in xrange(nbOfFams): + m.addFamily(fns[i],fids[i]) + pass + nbOfGrps=len(grpns) + for i in xrange(nbOfGrps): + m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i]) + pass + m.setName(m2.getName()) + m.setDescription(m2.getDescription()) + m.write(fileName,2) + pass pass unittest.main() -- 2.39.2