synchronizeTinyInfoOnLeaves();
std::vector<std::string> tmp(1);
tmp[0]=grp;
- MEDCouplingUMesh *ret=getGroups(meshDimRelToMaxExt,tmp,renum);
- ret->setName(grp);
- return ret;
+ return getGroups(meshDimRelToMaxExt,tmp,renum);
}
/*!
{
synchronizeTinyInfoOnLeaves();
std::vector<std::string> fams2=getFamiliesOnGroups(grps);
- return getFamilies(meshDimRelToMaxExt,fams2,renum);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> zeRet=getFamilies(meshDimRelToMaxExt,fams2,renum);
+ if(grps.size()==1 && ((MEDCouplingUMesh *)zeRet))
+ zeRet->setName(grps[0].c_str());
+ return zeRet.retn();
}
/*!
synchronizeTinyInfoOnLeaves();
std::vector<std::string> tmp(1);
tmp[0]=fam;
- MEDCouplingUMesh *ret=getFamilies(meshDimRelToMaxExt,tmp,renum);
- ret->setName(fam);
- return ret;
+ return getFamilies(meshDimRelToMaxExt,tmp,renum);
}
/*!
}
std::vector<int> famIds=getFamiliesIds(fams);
const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> 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();
}
/*!
* \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<const MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception)
+void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum) throw(INTERP_KERNEL::Exception)
{
if(ms.empty())
throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : expecting a non empty vector !");
std::vector<DataArrayInt *> corr;
MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,_zipconn_pol,corr);
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corr3(corr.begin(),corr.end());
- setMeshAtLevel(meshDimRelToMax,m);
+ setMeshAtLevel(meshDimRelToMax,m,renum);
std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
setGroupsAtLevel(meshDimRelToMax,corr2,true);
}
#include "MEDLoader.hxx"
#include "MEDLoaderBase.hxx"
#include "MEDFileUtilities.hxx"
+#include "MEDFileMesh.hxx"
#include "CellModel.hxx"
#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingMemArray.hxx"
std::vector<int> getIdsFromGroups(const char *fileName, const char *meshName, const std::vector<std::string>& 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<int>& possibilities);
+ int readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector<int>& possibilities);//to keep
void readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn, std::string& desc);
int buildMEDSubConnectivityOfOneType(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families, INTERP_KERNEL::NormalizedCellType type,
std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
{
CheckFileForRead(fileName);
- std::vector<int> familiesToKeep;
- std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
- unsigned meshDim;
- int *cellRenum;
- ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
- if(cellRenum)
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
+ MEDFileMesh *mmPtr(mm);
+ MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(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<int> familiesToKeep;
- std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
- unsigned meshDim;
- int *cellRenum;
- ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,0,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
- if(cellRenum)
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName);
+ MEDFileMesh *mmPtr(mm);
+ MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(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)
ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception)
{
CheckFileForRead(fileName);
- std::vector<int> familiesToKeep=MEDLoaderNS::getIdsFromFamilies(fileName,meshName,fams);
- std::vector<INTERP_KERNEL::NormalizedCellType> 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<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
+ MEDFileMesh *mmPtr(mm);
+ MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(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<std::string>& grps) throw(INTERP_KERNEL::Exception)
{
CheckFileForRead(fileName);
- std::vector<int> familiesToKeep=MEDLoaderNS::getIdsFromGroups(fileName,meshName,grps);
- std::vector<INTERP_KERNEL::NormalizedCellType> 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<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
+ MEDFileMesh *mmPtr(mm);
+ MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(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)
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<const ParaMEDMEM::MEDCouplingUMesh *> meshV(1); meshV[0]=mesh;
- std::vector<const ParaMEDMEM::DataArrayInt *> 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<std::string> 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<MEDFileUMesh> m=MEDFileUMesh::New();
+ m->setMeshAtLevel(0,static_cast<MEDCouplingUMesh *>(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<const ParaMEDMEM::MEDCouplingUMesh *> meshV(1); meshV[0]=mesh;
- std::vector<const ParaMEDMEM::DataArrayInt *> 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<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
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 ParaMEDMEM::MEDCouplingUMesh *>::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<std::string> tmp;
- for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::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<std::string> 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<MEDFileUMesh> 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<const ParaMEDMEM::MEDCouplingUMesh *>& 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 ParaMEDMEM::MEDCouplingUMesh *>::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<std::string> tmp;
- for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::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<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
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"
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