From f97fd0025dbc8726d8404d83532b70f04acb129e Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 10 Dec 2010 11:37:02 +0000 Subject: [PATCH] *** empty log message *** --- src/MEDLoader/MEDFileMesh.cxx | 53 +++++++++++++++----------- src/MEDLoader/MEDFileMesh.hxx | 2 + src/MEDLoader/MEDFileMeshLL.cxx | 11 ++++-- src/MEDLoader/MEDFileMeshLL.hxx | 1 + src/MEDLoader/Swig/MEDLoader.i | 14 ++++++- src/MEDLoader/Swig/MEDLoaderTest.py | 4 +- src/MEDLoader/Swig/MEDLoaderTest3.py | 4 ++ src/MEDLoader/Swig/MEDLoaderTypemaps.i | 39 +++++++++++++++++++ 8 files changed, 98 insertions(+), 30 deletions(-) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 98aacab85..b970bc51b 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -152,6 +152,31 @@ int MEDFileUMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Excep return (*it).second; } +std::vector MEDFileUMesh::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; +} + +std::string MEDFileUMesh::getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception) +{ + for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) + if((*it).second==id) + return (*it).first; + std::ostringstream oss; oss << "MEDFileUMesh::getFamilyNameGivenId : no such family id : " << id; + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + int MEDFileUMesh::getMeshDimension() const { int lev=0; @@ -350,34 +375,14 @@ DataArrayInt *MEDFileUMesh::getFamilyArr(int meshDimRelToMax, const char *fam) c MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMax, const std::vector& fams) const throw(INTERP_KERNEL::Exception) { - std::vector famIds; - for(std::vector::const_iterator it=fams.begin();it!=fams.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); - } + std::vector famIds=getFamiliesIds(fams); const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMax); return l1->getFamilyPart(famIds); } DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMax, const std::vector& fams) const throw(INTERP_KERNEL::Exception) { - std::vector famIds; - for(std::vector::const_iterator it=fams.begin();it!=fams.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); - } + std::vector famIds=getFamiliesIds(fams); const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMax); return l1->getFamilyPartArr(famIds); } @@ -419,7 +424,9 @@ DataArrayInt *MEDFileUMesh::getNodeFamilyArr(const char *fam) const throw(INTERP DataArrayInt *MEDFileUMesh::getNodeFamiliesArr(const std::vector& fams) const throw(INTERP_KERNEL::Exception) { - return 0; + std::vector famIds=getFamiliesIds(fams); + DataArrayInt *da=_fam_coords->getIdsEqualList(famIds); + return MEDFileUMeshSplitL1::renumber(_num_coords,da); } MEDCouplingUMesh *MEDFileUMesh::getMeshAtRank(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index b10731bcf..8b25c801f 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -59,6 +59,8 @@ namespace ParaMEDMEM int getNumberOfLevels() const { return _ms.size(); } int getNumberOfNonEmptyLevels() const; int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception); + std::vector getFamiliesIds(const std::vector& famNames) const throw(INTERP_KERNEL::Exception); + std::string getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception); int getMeshDimension() const; std::vector getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception); std::vector getGroupsNames() const; diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 701641e7e..3625d7c87 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -377,16 +377,21 @@ MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const return m; } -DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(DataArrayInt *da) const +DataArrayInt *MEDFileUMeshSplitL1::renumber(const DataArrayInt *renum, DataArrayInt *da) { - if((const DataArrayInt *)_num==0) + if((const DataArrayInt *)renum==0) return da; - MEDCouplingAutoRefCountObjectPtr locnum=_num->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples()); + MEDCouplingAutoRefCountObjectPtr locnum=renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples()); da->decrRef(); locnum->incrRef(); return locnum; } +DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(DataArrayInt *da) const +{ + return renumber(_num,da); +} + std::vector MEDFileUMeshSplitL1::getNewFamiliesNumber(int nb, const std::map& families) { int id=-1; diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 3ed1e994b..90704a757 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -95,6 +95,7 @@ namespace ParaMEDMEM static std::vector getNewFamiliesNumber(int nb, const std::map& families); static void traduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, std::map& famIdTrad, std::map& newfams); + static DataArrayInt *renumber(const DataArrayInt *renum, DataArrayInt *da); private: MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const; DataArrayInt *renumIfNeededArr(DataArrayInt *da) const; diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 59cdce0a5..2ed7fa83d 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -179,9 +179,19 @@ public: PyList_SetItem(ret,i,PyInt_FromLong((int)v[i])); return ret; } + static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector grps; + converPyListToVecString(li,grps); + return MEDLoader::ReadUMeshFromGroups(fileName,meshName,meshDimRelToMax,grps); + } + static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector fams; + converPyListToVecString(li,fams); + return MEDLoader::ReadUMeshFromFamilies(fileName,meshName,meshDimRelToMax,fams); + } } - static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams) throw(INTERP_KERNEL::Exception); - static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingFieldDouble *ReadField(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoaderTest.py b/src/MEDLoader/Swig/MEDLoaderTest.py index bfb8f1462..f3dec1cae 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest.py +++ b/src/MEDLoader/Swig/MEDLoaderTest.py @@ -245,7 +245,7 @@ class MEDLoaderTest(unittest.TestCase): grps.index("mesh4"); grps.index("3DMesh_1"); # - vec=["mesh2"]; + vec=("mesh2",); mesh2_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); self.assertTrue(mesh2_2.isEqual(mesh2,1e-12)); vec=["mesh3"]; @@ -254,7 +254,7 @@ class MEDLoaderTest(unittest.TestCase): vec=["mesh4"]; mesh4_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); self.assertTrue(mesh4_2.isEqual(mesh4,1e-12)); - vec=["3DMesh_1"]; + vec="3DMesh_1"; mesh1_2=MEDLoader.MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec); mesh1.setName("3DMesh_1"); self.assertTrue(mesh1_2.isEqual(mesh1,1e-12)); diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 36d97f68c..06be3aa8b 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -68,6 +68,10 @@ class MEDLoaderTest(unittest.TestCase): self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_2").getValues()); self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"]).getValues()); self.assertEqual([2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3"]).getValues()); + famn=medmesh.getFamilyNameGivenId(0) + self.assertEqual(range(60),medmesh.getNodeFamilyArr(famn).getValues()); + # without renum + pass pass diff --git a/src/MEDLoader/Swig/MEDLoaderTypemaps.i b/src/MEDLoader/Swig/MEDLoaderTypemaps.i index e36250335..b6f40fa23 100644 --- a/src/MEDLoader/Swig/MEDLoaderTypemaps.i +++ b/src/MEDLoader/Swig/MEDLoaderTypemaps.i @@ -102,6 +102,45 @@ static std::vector > convertTimePairIdsFromPy(PyObject *pyLi) return ret; } +static void converPyListToVecString(PyObject *pyLi, std::vector& v) +{ + if(PyList_Check(pyLi)) + { + int size=PyList_Size(pyLi); + v.resize(size); + for(int i=0;i& li) { int sz=li.size(); -- 2.39.2