From b81a3099adb0fac389e698e7b3ec90b59d20d816 Mon Sep 17 00:00:00 2001 From: ageay Date: Tue, 25 Jun 2013 08:17:13 +0000 Subject: [PATCH] On the road of reimplementation of basic MEDLoader API with advanced one. --- src/MEDLoader/MEDFileMesh.cxx | 25 +-- src/MEDLoader/MEDFileMesh.hxx | 2 +- src/MEDLoader/MEDFileMeshLL.cxx | 2 +- src/MEDLoader/MEDLoader.cxx | 217 ++++++--------------------- src/MEDLoader/Swig/MEDLoaderCommon.i | 2 +- src/MEDLoader/Swig/MEDLoaderTest.py | 12 +- src/MEDLoader/Swig/MEDLoaderTest2.py | 2 +- src/MEDLoader/Swig/MEDLoaderTest3.py | 23 +-- 8 files changed, 79 insertions(+), 206 deletions(-) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 48dc0c5e3..0230171c8 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -2666,9 +2666,7 @@ MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMaxExt, const char *grp synchronizeTinyInfoOnLeaves(); std::vector tmp(1); tmp[0]=grp; - MEDCouplingUMesh *ret=getGroups(meshDimRelToMaxExt,tmp,renum); - ret->setName(grp); - return ret; + return getGroups(meshDimRelToMaxExt,tmp,renum); } /*! @@ -2689,7 +2687,10 @@ MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMaxExt, const std::vec { synchronizeTinyInfoOnLeaves(); std::vector fams2=getFamiliesOnGroups(grps); - return getFamilies(meshDimRelToMaxExt,fams2,renum); + MEDCouplingAutoRefCountObjectPtr zeRet=getFamilies(meshDimRelToMaxExt,fams2,renum); + if(grps.size()==1 && ((MEDCouplingUMesh *)zeRet)) + zeRet->setName(grps[0].c_str()); + return zeRet.retn(); } /*! @@ -2711,9 +2712,7 @@ MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMaxExt, const char *fa synchronizeTinyInfoOnLeaves(); std::vector tmp(1); tmp[0]=fam; - MEDCouplingUMesh *ret=getFamilies(meshDimRelToMaxExt,tmp,renum); - ret->setName(fam); - return ret; + return getFamilies(meshDimRelToMaxExt,tmp,renum); } /*! @@ -2743,10 +2742,14 @@ MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMaxExt, const std::v } std::vector famIds=getFamiliesIds(fams); const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); + MEDCouplingAutoRefCountObjectPtr zeRet; if(!famIds.empty()) - return l1->getFamilyPart(&famIds[0],&famIds[0]+famIds.size(),renum); + zeRet=l1->getFamilyPart(&famIds[0],&famIds[0]+famIds.size(),renum); else - return l1->getFamilyPart(0,0,renum); + zeRet=l1->getFamilyPart(0,0,renum); + if(fams.size()==1 && ((MEDCouplingUMesh *)zeRet)) + zeRet->setName(fams[0].c_str()); + return zeRet.retn(); } /*! @@ -3439,7 +3442,7 @@ void MEDFileUMesh::setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m, bool * \throw If names of some meshes in \a ms are equal. * \throw If \a ms includes a mesh with an empty name. */ -void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception) +void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms, bool renum) throw(INTERP_KERNEL::Exception) { if(ms.empty()) throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : expecting a non empty vector !"); @@ -3459,7 +3462,7 @@ void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector corr; MEDCouplingAutoRefCountObjectPtr m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,_zipconn_pol,corr); std::vector< MEDCouplingAutoRefCountObjectPtr > corr3(corr.begin(),corr.end()); - setMeshAtLevel(meshDimRelToMax,m); + setMeshAtLevel(meshDimRelToMax,m,renum); std::vector corr2(corr.begin(),corr.end()); setGroupsAtLevel(meshDimRelToMax,corr2,true); } diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 05b7143bc..4e5158932 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -243,7 +243,7 @@ namespace ParaMEDMEM 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 setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); + void setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms, bool renum=false) throw(INTERP_KERNEL::Exception); void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms, bool renum) throw(INTERP_KERNEL::Exception); void optimizeFamilies() throw(INTERP_KERNEL::Exception); // tools diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 7423fdbde..00eb2c637 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -763,7 +763,7 @@ DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const int *idsBg, const int MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const { MEDCouplingAutoRefCountObjectPtr tmp; - if(renum) + if(renum && ((const DataArrayInt *)_num)) tmp=_m; else tmp=_m_by_types; diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 4126fb9d9..88e97da55 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -21,6 +21,7 @@ #include "MEDLoader.hxx" #include "MEDLoaderBase.hxx" #include "MEDFileUtilities.hxx" +#include "MEDFileMesh.hxx" #include "CellModel.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingMemArray.hxx" @@ -165,7 +166,7 @@ namespace MEDLoaderNS std::vector getIdsFromGroups(const char *fileName, const char *meshName, const std::vector& grps); med_int getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception); void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity); - int readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector& possibilities); + int readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector& possibilities);//to keep void readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list& conn, std::string& desc); int buildMEDSubConnectivityOfOneType(const std::vector& conn, const std::vector& connIndex, const std::vector& families, INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile, std::vector& connIndex4MEDFile, std::vector& connIndexRk24MEDFile, @@ -2069,33 +2070,29 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - std::vector familiesToKeep; - std::vector typesToKeep; - unsigned meshDim; - int *cellRenum; - ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum); - if(cellRenum) + MEDCouplingAutoRefCountObjectPtr mm=MEDFileMesh::New(fileName,meshName); + MEDFileMesh *mmPtr(mm); + MEDFileUMesh *mmuPtr=dynamic_cast(mmPtr); + if(!mmuPtr) { - ret->renumberCells(cellRenum,true); - delete [] cellRenum; + std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); } - return ret; + return mmuPtr->getMeshAtLevel(meshDimRelToMax,true); } ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - std::vector familiesToKeep; - std::vector typesToKeep; - unsigned meshDim; - int *cellRenum; - ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,0,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum); - if(cellRenum) + MEDCouplingAutoRefCountObjectPtr mm=MEDFileMesh::New(fileName); + MEDFileMesh *mmPtr(mm); + MEDFileUMesh *mmuPtr=dynamic_cast(mmPtr); + if(!mmuPtr) { - ret->renumberCells(cellRenum,true); - delete [] cellRenum; + std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); } - return ret; + return mmuPtr->getMeshAtLevel(meshDimRelToMax,true); } int MEDLoader::ReadUMeshDimFromFile(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) @@ -2108,37 +2105,29 @@ int MEDLoader::ReadUMeshDimFromFile(const char *fileName, const char *meshName) ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - std::vector familiesToKeep=MEDLoaderNS::getIdsFromFamilies(fileName,meshName,fams); - std::vector typesToKeep; - unsigned meshDim; - int *cellRenum; - ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum); - if(fams.size()==1) - ret->setName(fams.back().c_str()); - if(cellRenum) + MEDCouplingAutoRefCountObjectPtr mm=MEDFileMesh::New(fileName,meshName); + MEDFileMesh *mmPtr(mm); + MEDFileUMesh *mmuPtr=dynamic_cast(mmPtr); + if(!mmuPtr) { - ret->renumberCells(cellRenum,true); - delete [] cellRenum; + std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); } - return ret; + return mmuPtr->getFamilies(meshDimRelToMax,fams,true); } ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - std::vector familiesToKeep=MEDLoaderNS::getIdsFromGroups(fileName,meshName,grps); - std::vector typesToKeep; - unsigned meshDim; - int *cellRenum; - ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum); - if(grps.size()==1) - ret->setName(grps.back().c_str()); - if(cellRenum) + MEDCouplingAutoRefCountObjectPtr mm=MEDFileMesh::New(fileName,meshName); + MEDFileMesh *mmPtr(mm); + MEDFileUMesh *mmuPtr=dynamic_cast(mmPtr); + if(!mmuPtr) { - ret->renumberCells(cellRenum,true); - delete [] cellRenum; + std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); } - return ret; + return mmuPtr->getGroups(meshDimRelToMax,grps,true); } ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadField(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) @@ -2828,68 +2817,17 @@ void MEDLoaderNS::writeFieldTryingToFitExistingMesh(const char *fileName, const void MEDLoader::WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception) { - std::string meshName(mesh->getName()); - if(meshName.empty()) - throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name !"); - int status=MEDLoaderBase::getStatusOfFile(fileName); - bool isRenumbering; - if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST) - { - std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - std::vector meshV(1); meshV[0]=mesh; - std::vector famV(1); famV[0]=0; - if(writeFromScratch) - { - MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering); - return ; - } - if(status==MEDLoaderBase::NOT_EXIST) - { - MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering); - return; - } - else - { - std::vector meshNames=GetMeshNames(fileName); - if(std::find(meshNames.begin(),meshNames.end(),meshName)==meshNames.end()) - MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,false,isRenumbering); - else - { - std::ostringstream oss; oss << "File \'" << fileName << "\' already exists and has already a mesh called \""; - oss << meshName << "\" !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } + if(!mesh) + throw INTERP_KERNEL::Exception("MEDLoader::WriteUMesh : input mesh is null !"); + int mod=writeFromScratch?2:0; + MEDCouplingAutoRefCountObjectPtr m=MEDFileUMesh::New(); + m->setMeshAtLevel(0,static_cast(mesh->deepCpy()),true); + m->write(fileName,mod); } void MEDLoader::WriteUMeshDep(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception) { - std::string meshName(mesh->getName()); - if(meshName.empty()) - throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name !"); - int status=MEDLoaderBase::getStatusOfFile(fileName); - bool isRenumbering; - if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST) - { - std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - std::vector meshV(1); meshV[0]=mesh; - std::vector famV(1); famV[0]=0; - if(writeFromScratch) - { - MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering); - return ; - } - if(status==MEDLoaderBase::NOT_EXIST) - { - MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering); - return; - } - else - MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,false,isRenumbering); + MEDLoader::WriteUMesh(fileName,mesh,writeFromScratch); } void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshNameC, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception) @@ -2903,85 +2841,16 @@ void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshName std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - if(meshes.empty()) - throw INTERP_KERNEL::Exception("List of meshes must be not empty !"); - const DataArrayDouble *coords=meshes.front()->getCoords(); - for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) - if(coords!=(*iter)->getCoords()) - throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !"); - std::set tmp; - for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) - { - if(tmp.find((*iter)->getName())==tmp.end()) - tmp.insert((*iter)->getName()); - else - throw INTERP_KERNEL::Exception("The names of meshes must be different each other !"); - } - tmp.clear(); - if(writeFromScratch) - { - MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true); - return ; - } - if(status==MEDLoaderBase::NOT_EXIST) - { - MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true); - return; - } - else - { - std::vector meshNames=GetMeshNames(fileName); - if(std::find(meshNames.begin(),meshNames.end(),meshName)==meshNames.end()) - MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,false); - else - { - std::ostringstream oss; oss << "File \'" << fileName << "\' already exists and has already a mesh called \""; - oss << meshName << "\" !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } + MEDCouplingAutoRefCountObjectPtr m=MEDFileUMesh::New(); + m->setGroupsFromScratch(0,meshes,true); + m->setName(meshNameC); + int mod=writeFromScratch?2:0; + m->write(fileName,mod); } void MEDLoader::WriteUMeshesPartitionDep(const char *fileName, const char *meshNameC, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception) { - std::string meshName(meshNameC); - if(meshName.empty()) - throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name : change 2nd parameter !"); - int status=MEDLoaderBase::getStatusOfFile(fileName); - if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST) - { - std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - if(meshes.empty()) - throw INTERP_KERNEL::Exception("List of meshes must be not empty !"); - const DataArrayDouble *coords=meshes.front()->getCoords(); - for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) - if(coords!=(*iter)->getCoords()) - throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !"); - std::set tmp; - for(std::vector::const_iterator iter=meshes.begin();iter!=meshes.end();iter++) - { - if(tmp.find((*iter)->getName())==tmp.end()) - tmp.insert((*iter)->getName()); - else - throw INTERP_KERNEL::Exception("The names of meshes must be different each other !"); - } - tmp.clear(); - if(writeFromScratch) - { - MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true); - return ; - } - if(status==MEDLoaderBase::NOT_EXIST) - { - MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true); - return; - } - else - { - MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,false); - } + WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch); } void MEDLoader::WriteUMeshes(const char *fileName, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception) diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 6c813fc0f..60cac09fb 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -663,7 +663,7 @@ namespace ParaMEDMEM 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 setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); + void setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms, bool renum=false) throw(INTERP_KERNEL::Exception); void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms, bool renum) throw(INTERP_KERNEL::Exception); void optimizeFamilies() throw(INTERP_KERNEL::Exception); DataArrayInt *zipCoords() throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoaderTest.py b/src/MEDLoader/Swig/MEDLoaderTest.py index 486c00aa0..149c40a26 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest.py +++ b/src/MEDLoader/Swig/MEDLoaderTest.py @@ -253,19 +253,19 @@ class MEDLoaderTest(unittest.TestCase): mesh1.setName("3DMesh_1"); self.assertTrue(mesh1_2.isEqual(mesh1,1e-12)); # - vec=["Family_4","Family_2"]; + vec=["Family_-3","Family_-5"]; mesh2_2=MEDLoader.MEDLoader.ReadUMeshFromFamilies(fileName,mnane,0,vec); mesh2_2.setName("mesh2"); self.assertTrue(mesh2_2.isEqual(mesh2,1e-12)); # ret=MEDLoader.MEDLoader.GetMeshFamiliesNamesOnGroup(fileName,"3DToto","3DMesh_1"); self.assertEqual(4,len(ret)); - self.assertEqual(ret[0],"Family_1"); - self.assertEqual(ret[1],"Family_2"); - self.assertEqual(ret[2],"Family_3"); - self.assertEqual(ret[3],"Family_4"); + self.assertEqual(ret[0],"Family_-2"); + self.assertEqual(ret[1],"Family_-3"); + self.assertEqual(ret[2],"Family_-4"); + self.assertEqual(ret[3],"Family_-5"); # - ret1=MEDLoader.MEDLoader.GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_2"); + ret1=MEDLoader.MEDLoader.GetMeshGroupsNamesOnFamily(fileName,"3DToto","Family_-3"); self.assertEqual(2,len(ret1)); self.assertEqual(ret1[0],"3DMesh_1"); self.assertEqual(ret1[1],"mesh2"); diff --git a/src/MEDLoader/Swig/MEDLoaderTest2.py b/src/MEDLoader/Swig/MEDLoaderTest2.py index 84d069197..8661cbccf 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest2.py +++ b/src/MEDLoader/Swig/MEDLoaderTest2.py @@ -249,7 +249,7 @@ class MEDLoaderTest(unittest.TestCase): mesh1.setName("3DMesh_1"); self.assertTrue(mesh1_2.isEqual(mesh1,1e-12)); # - vec=["Family_4","Family_2"]; + vec=["Family_-5","Family_-3"]; mesh2_2=MEDLoader.ReadUMeshFromFamilies(fileName,mnane,0,vec); mesh2_2.setName("mesh2"); self.assertTrue(mesh2_2.isEqual(mesh2,1e-12)); diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index d56948278..1e99f137c 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -38,6 +38,7 @@ class MEDLoaderTest(unittest.TestCase): m2_1=MEDLoader.ReadUMeshFromFile(fileName,mname,-1) self.assertTrue(m2_0.isEqual(m2_1,1e-12)); pass + def testMEDMesh2(self): fileName="Pyfile10.med" mname="3DToto" @@ -57,25 +58,25 @@ class MEDLoaderTest(unittest.TestCase): g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh3","mesh2"]); g1_1.setName(g1_0.getName()) self.assertTrue(g1_0.isEqual(g1_1,1e-12)); - g1_0=medmesh.getFamily(0,"Family_2",True) - g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_2"]); + g1_0=medmesh.getFamily(0,"Family_-3",True) + g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_-3"]); self.assertTrue(g1_0.isEqual(g1_1,1e-12)); - g1_0=medmesh.getFamilies(0,["Family_2","Family_4"],True) - g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_2","Family_4"]); + g1_0=medmesh.getFamilies(0,["Family_-3","Family_-5"],True) + g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_-3","Family_-5"]); g1_1.setName(g1_0.getName()) self.assertTrue(g1_0.isEqual(g1_1,1e-12)); self.assertTrue(g1_0.isEqual(g1_1,1e-12)); medmesh.write(outFileName,2); - self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2",True).getValues()); - self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_2",True).getValues()); - self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"],True).getValues()); - self.assertEqual([19,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"],True).getValues()); + self.assertEqual([1,2,4,13,15],medmesh.getGroupArr(0,"mesh2",True).getValues()); + self.assertEqual([1,2,15],medmesh.getFamilyArr(0,"Family_-3",True).getValues()); + self.assertEqual([1,2,4,13,15],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"],True).getValues()); + self.assertEqual([18,1,2,3,4,13,14,15],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"],True).getValues()); famn=medmesh.getFamilyNameGivenId(0) self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,True); #without renum - self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2",False).getValues()); - self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_2",False).getValues()); - self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"],False).getValues()); + self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2").getValues()); + self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_-3").getValues()); + self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"]).getValues()); self.assertEqual([0,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3","mesh4"],False).getValues()); self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,False); pass -- 2.30.2