From: ageay Date: Wed, 3 Feb 2010 11:37:13 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V5_1_main_FINAL~225 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=040ac96b8c90e34bc4862e1aff50d4be05720a98;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i index 67667974c..e9dceeffc 100644 --- a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i +++ b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i @@ -40,6 +40,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::New; %newobject ParaMEDMEM::MEDCouplingUMesh::New; %newobject ParaMEDMEM::MEDCouplingFieldDouble::New; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::mergeFields; %newobject ParaMEDMEM::MEDCouplingUMesh::clone; %newobject ParaMEDMEM::DataArrayDouble::deepCopy; %newobject ParaMEDMEM::DataArrayDouble::performCpy; @@ -181,6 +182,7 @@ namespace ParaMEDMEM NatureOfField getNature() const { return _nature; } void setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception); void updateTime(); + static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); %extend { void setValues(PyObject *li) { @@ -194,6 +196,16 @@ namespace ParaMEDMEM else PyErr_SetString(PyExc_TypeError,"setValuesCpy : field must contain an array behind"); } + PyObject *getTime() + { + int tmp1,tmp2; + double tmp0=self->getTime(tmp1,tmp2); + PyObject *res = PyList_New(3); + PyList_SetItem(res,0,SWIG_From_double(tmp0)); + PyList_SetItem(res,1,SWIG_From_int(tmp1)); + PyList_SetItem(res,2,SWIG_From_int(tmp2)); + return res; + } } }; } diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 18c241cb1..6d09a3e75 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -75,7 +75,7 @@ INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2] = { INTERP using namespace ParaMEDMEM; -namespace MEDLoader +namespace MEDLoaderNS { class FieldPerTypeCopier { @@ -153,525 +153,526 @@ void MEDLoader::MEDFieldDoublePerCellType::releaseArray() delete [] _values; } -namespace MEDLoader + +std::string MEDLoaderNS::buildStringFromFortran(const char *expr, int lgth) { - std::string buildStringFromFortran(const char *expr, int lgth) - { - std::string ret(expr,lgth); - std::string whiteSpaces(WHITE_SPACES); - std::size_t lgthReal=strlen(ret.c_str()); - std::string ret2=ret.substr(0,lgthReal); - std::size_t found=ret2.find_last_not_of(whiteSpaces); - if (found!=std::string::npos) - ret2.erase(found+1); - else - ret2.clear();//ret is all whitespace - return ret2; - } + std::string ret(expr,lgth); + std::string whiteSpaces(WHITE_SPACES); + std::size_t lgthReal=strlen(ret.c_str()); + std::string ret2=ret.substr(0,lgthReal); + std::size_t found=ret2.find_last_not_of(whiteSpaces); + if (found!=std::string::npos) + ret2.erase(found+1); + else + ret2.clear();//ret is all whitespace + return ret2; +} - std::vector getMeshNamesFid(med_idt fid) - { - med_maillage type_maillage; - char maillage_description[MED_TAILLE_DESC+1]; - med_int dim; - char nommaa[MED_TAILLE_NOM+1]; - med_int n=MEDnMaa(fid); - std::vector ret(n); - for(int i=0;i MEDLoaderNS::getMeshNamesFid(med_idt fid) +{ + med_maillage type_maillage; + char maillage_description[MED_TAILLE_DESC+1]; + med_int dim; + char nommaa[MED_TAILLE_NOM+1]; + med_int n=MEDnMaa(fid); + std::vector ret(n); + for(int i=0;i GetMeshNames(const char *fileName) - { - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - std::vector ret=getMeshNamesFid(fid); - MEDfermer(fid); - return ret; - } +std::vector MEDLoader::GetMeshNames(const char *fileName) +{ + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + std::vector ret=MEDLoaderNS::getMeshNamesFid(fid); + MEDfermer(fid); + return ret; +} - std::vector GetMeshFamilyNames(const char *fileName, const char *meshName) - { - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nfam=MEDnFam(fid,(char *)meshName); - std::vector ret(nfam); - char nomfam[MED_TAILLE_NOM+1]; - med_int numfam; - for(int i=0;i MEDLoader::GetMeshFamilyNames(const char *fileName, const char *meshName) +{ + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_int nfam=MEDnFam(fid,(char *)meshName); + std::vector ret(nfam); + char nomfam[MED_TAILLE_NOM+1]; + med_int numfam; + for(int i=0;i GetMeshGroupsNames(const char *fileName, const char *meshName) - { - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nfam=MEDnFam(fid,(char *)meshName); - std::vector ret; - char nomfam[MED_TAILLE_NOM+1]; - med_int numfam; - for(int i=0;i MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) +{ + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_int nfam=MEDnFam(fid,(char *)meshName); + std::vector ret; + char nomfam[MED_TAILLE_NOM+1]; + med_int numfam; + for(int i=0;i GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) - { - std::vector ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); - // - med_type_champ typcha; - //med_int nbpdtnor=0,pflsize,*pflval,lnsize; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; - med_float dt=0.0; - med_booleen local; - //char pflname[MED_TAILLE_NOM+1]=""; - //char locname[MED_TAILLE_NOM+1]=""; - char maa_ass[MED_TAILLE_NOM+1]=""; - char dt_unit[MED_TAILLE_PNOM+1]=""; - char nomcha[MED_TAILLE_NOM+1]=""; - // - for(int i=0;i0) - { - MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa); - std::string curMeshName=buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1); - if(curMeshName==meshName) - { - found=true; - ret.push_back(curFieldName); - } - } - } - } - MEDfermer(fid); - return ret; - } +std::vector MEDLoader::GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) +{ + std::vector ret; + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_int nbFields=MEDnChamp(fid,0); + // + med_type_champ typcha; + //med_int nbpdtnor=0,pflsize,*pflval,lnsize; + med_int ngauss=0; + med_int numdt=0,numo=0,nbrefmaa; + med_float dt=0.0; + med_booleen local; + //char pflname[MED_TAILLE_NOM+1]=""; + //char locname[MED_TAILLE_NOM+1]=""; + char maa_ass[MED_TAILLE_NOM+1]=""; + char dt_unit[MED_TAILLE_PNOM+1]=""; + char nomcha[MED_TAILLE_NOM+1]=""; + // + for(int i=0;i0) + { + MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa); + std::string curMeshName=MEDLoaderNS::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1); + if(curMeshName==meshName) + { + found=true; + ret.push_back(curFieldName); + } + } + } + } + MEDfermer(fid); + return ret; +} - std::vector GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) - { - std::vector ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); - // - med_type_champ typcha; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; - med_float dt=0.0; - med_booleen local; - char maa_ass[MED_TAILLE_NOM+1]=""; - char dt_unit[MED_TAILLE_PNOM+1]=""; - char nomcha[MED_TAILLE_NOM+1]=""; - // - for(int i=0;i0) - { - MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa); - std::string curMeshName=buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1); - if(curMeshName==meshName) - { - found=true; - ret.push_back(curFieldName); - } - } - } - MEDfermer(fid); - return ret; - } +std::vector MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) +{ + std::vector ret; + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_int nbFields=MEDnChamp(fid,0); + // + med_type_champ typcha; + med_int ngauss=0; + med_int numdt=0,numo=0,nbrefmaa; + med_float dt=0.0; + med_booleen local; + char maa_ass[MED_TAILLE_NOM+1]=""; + char dt_unit[MED_TAILLE_PNOM+1]=""; + char nomcha[MED_TAILLE_NOM+1]=""; + // + for(int i=0;i0) + { + MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa); + std::string curMeshName=MEDLoaderNS::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1); + if(curMeshName==meshName) + { + found=true; + ret.push_back(curFieldName); + } + } + } + MEDfermer(fid); + return ret; +} - std::vector< std::pair > GetCellFieldIterations(const char *fileName, const char *fieldName) - { - std::vector< std::pair > ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); - // - med_type_champ typcha; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; - med_float dt=0.0; - med_booleen local; - char maa_ass[MED_TAILLE_NOM+1]=""; - char dt_unit[MED_TAILLE_PNOM+1]=""; - char nomcha[MED_TAILLE_NOM+1]=""; - // - for(int i=0;i > MEDLoader::GetCellFieldIterations(const char *fileName, const char *fieldName) +{ + std::vector< std::pair > ret; + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_int nbFields=MEDnChamp(fid,0); + // + med_type_champ typcha; + med_int ngauss=0; + med_int numdt=0,numo=0,nbrefmaa; + med_float dt=0.0; + med_booleen local; + char maa_ass[MED_TAILLE_NOM+1]=""; + char dt_unit[MED_TAILLE_PNOM+1]=""; + char nomcha[MED_TAILLE_NOM+1]=""; + // + for(int i=0;i > GetNodeFieldIterations(const char *fileName, const char *fieldName) - { - std::vector< std::pair > ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); - // - med_type_champ typcha; - med_int ngauss=0; - med_int numdt=0,numo=0,nbrefmaa; - med_float dt=0.0; - med_booleen local; - char maa_ass[MED_TAILLE_NOM+1]=""; - char dt_unit[MED_TAILLE_PNOM+1]=""; - char nomcha[MED_TAILLE_NOM+1]=""; - // - for(int i=0;i > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *fieldName) +{ + std::vector< std::pair > ret; + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_int nbFields=MEDnChamp(fid,0); + // + med_type_champ typcha; + med_int ngauss=0; + med_int numdt=0,numo=0,nbrefmaa; + med_float dt=0.0; + med_booleen local; + char maa_ass[MED_TAILLE_NOM+1]=""; + char dt_unit[MED_TAILLE_PNOM+1]=""; + char nomcha[MED_TAILLE_NOM+1]=""; + // + for(int i=0;i& field, - int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField, double& time) - { - time=0.; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nbFields=MEDnChamp(fid,0); - // - med_type_champ typcha; - char nomcha[MED_TAILLE_NOM+1]=""; - char pflname [MED_TAILLE_NOM+1]=""; - char locname [MED_TAILLE_NOM+1]=""; - std::map tabEnt; - std::map tabType; - std::map tabTypeLgth; - tabEnt[ON_CELLS]=MED_MAILLE; - tabType[ON_CELLS]=typmai; - tabTypeLgth[ON_CELLS]=MED_NBR_GEOMETRIE_MAILLE+2; - tabEnt[ON_NODES]=MED_NOEUD; - tabType[ON_NODES]=typmainoeud; - tabTypeLgth[ON_NODES]=1; - // - for(int i=0;i0) - { - int nval=MEDnVal(fid,(char *)fieldName,tabEnt[typeOfOutField],tabType[typeOfOutField][j],iteration,order,(char *)meshName,MED_COMPACT); - double *valr=new double[ncomp*nval]; - MEDchampLire(fid,(char *)meshName,(char *)fieldName,(unsigned char*)valr,MED_FULL_INTERLACE,MED_ALL,locname, - pflname,MED_COMPACT,tabEnt[typeOfOutField],tabType[typeOfOutField][j],iteration,order); - field.push_back(MEDFieldDoublePerCellType(typmai2[j],valr,ncomp,nval)); - } - } - } - } - MEDfermer(fid); - } +void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName, std::list& field, + int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField, double& time) +{ + time=0.; + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_int nbFields=MEDnChamp(fid,0); + // + med_type_champ typcha; + char nomcha[MED_TAILLE_NOM+1]=""; + char pflname [MED_TAILLE_NOM+1]=""; + char locname [MED_TAILLE_NOM+1]=""; + std::map tabEnt; + std::map tabType; + std::map tabTypeLgth; + tabEnt[ON_CELLS]=MED_MAILLE; + tabType[ON_CELLS]=typmai; + tabTypeLgth[ON_CELLS]=MED_NBR_GEOMETRIE_MAILLE+2; + tabEnt[ON_NODES]=MED_NOEUD; + tabType[ON_NODES]=typmainoeud; + tabTypeLgth[ON_NODES]=1; + // + for(int i=0;i0) + { + int nval=MEDnVal(fid,(char *)fieldName,tabEnt[typeOfOutField],tabType[typeOfOutField][j],iteration,order,(char *)meshName,MED_COMPACT); + double *valr=new double[ncomp*nval]; + MEDchampLire(fid,(char *)meshName,(char *)fieldName,(unsigned char*)valr,MED_FULL_INTERLACE,MED_ALL,locname, + pflname,MED_COMPACT,tabEnt[typeOfOutField],tabType[typeOfOutField][j],iteration,order); + field.push_back(MEDLoader::MEDFieldDoublePerCellType(typmai2[j],valr,ncomp,nval)); + } + } + } + } + MEDfermer(fid); +} - std::vector getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector& fams) - { - std::vector ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nfam=MEDnFam(fid,(char *)meshName); - char nomfam[MED_TAILLE_NOM+1]; - med_int numfam; - for(int i=0;i MEDLoaderNS::getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector& fams) +{ + std::vector ret; + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_int nfam=MEDnFam(fid,(char *)meshName); + char nomfam[MED_TAILLE_NOM+1]; + med_int numfam; + for(int i=0;i getIdsFromGroups(const char *fileName, const char *meshName, const std::vector& grps) - { - std::vector ret; - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - med_int nfam=MEDnFam(fid,(char *)meshName); - char nomfam[MED_TAILLE_NOM+1]; - med_int numfam; - for(int i=0;i MEDLoaderNS::getIdsFromGroups(const char *fileName, const char *meshName, const std::vector& grps) +{ + std::vector ret; + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + med_int nfam=MEDnFam(fid,(char *)meshName); + char nomfam[MED_TAILLE_NOM+1]; + med_int numfam; + for(int i=0;i meshes=getMeshNamesFid(fid); - if(meshes.empty()) - throw INTERP_KERNEL::Exception("No mesh in file"); - trueMeshName=meshes[0]; - return 1; - } - std::string meshNameStr(meshName); - std::vector meshes=getMeshNamesFid(fid); - if(meshes.empty()) - throw INTERP_KERNEL::Exception("No mesh in file"); - std::vector::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr); - if(iter==meshes.end()) - { - std::ostringstream os2; - os2 << "MeshName '" << meshName << "' not in file : meshes available : "; - std::copy(meshes.begin(),meshes.end(),std::ostream_iterator(os2," ")); - throw INTERP_KERNEL::Exception(os2.str().c_str()); - } - trueMeshName=meshName; - return iter-meshes.begin()+1; - } +med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception) +{ + if(meshName==0) + { + std::vector meshes=getMeshNamesFid(fid); + if(meshes.empty()) + throw INTERP_KERNEL::Exception("No mesh in file"); + trueMeshName=meshes[0]; + return 1; + } + std::string meshNameStr(meshName); + std::vector meshes=getMeshNamesFid(fid); + if(meshes.empty()) + throw INTERP_KERNEL::Exception("No mesh in file"); + std::vector::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr); + if(iter==meshes.end()) + { + std::ostringstream os2; + os2 << "MeshName '" << meshName << "' not in file : meshes available : "; + std::copy(meshes.begin(),meshes.end(),std::ostream_iterator(os2," ")); + throw INTERP_KERNEL::Exception(os2.str().c_str()); + } + trueMeshName=meshName; + return iter-meshes.begin()+1; +} - /*! - * This methods allows to merger all entities and to considerate only cell types. - */ - void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entite_maillage& whichEntity) - { - if(nbOfElemCell>=nbOfElemFace) - { - whichEntity=MED_MAILLE; - nbOfElem=nbOfElemCell; - } - else - { - whichEntity=MED_FACE; - nbOfElem=nbOfElemFace; - } - } +/*! + * This methods allows to merger all entities and to considerate only cell types. + */ +void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entite_maillage& whichEntity) +{ + if(nbOfElemCell>=nbOfElemFace) + { + whichEntity=MED_MAILLE; + nbOfElem=nbOfElemCell; + } + else + { + whichEntity=MED_FACE; + nbOfElem=nbOfElemFace; + } +} - void readUMeshDataInMedFile(med_idt fid, med_int meshId, double *&coords, int& nCoords, int& spaceDim, std::list& conn) - { - char nommaa[MED_TAILLE_NOM+1]; - char maillage_description[MED_TAILLE_DESC+1]; - char comp[3*MED_TAILLE_PNOM+1]; - char unit[3*MED_TAILLE_PNOM+1]; - med_maillage type_maillage; - med_int Mdim; - MEDmaaInfo(fid,meshId,nommaa,&Mdim,&type_maillage,maillage_description); - spaceDim=(int)Mdim; - nCoords=MEDnEntMaa(fid,nommaa,MED_COOR,MED_NOEUD,(med_geometrie_element)0,(med_connectivite)0); - coords=new double[nCoords*spaceDim]; - med_repere repere; - MEDcoordLire(fid,nommaa,Mdim,coords,MED_FULL_INTERLACE,MED_ALL,NULL,0,&repere,comp,unit); - med_booleen inoele, inuele; - for(int i=0;i0) - { - int *connTab=new int[(curMedType%100)*curNbOfElem]; - int *fam=new int[curNbOfElem]; - MEDLoader::MEDConnOfOneElemType elem(typmai2[i],connTab,0,fam,curNbOfElem,-1); - int *tmp=new int[curNbOfElem]; - char *noms=new char[MED_TAILLE_PNOM*curNbOfElem+1]; - MEDelementsLire(fid,nommaa,Mdim,connTab,MED_FULL_INTERLACE,noms,&inoele,tmp,&inuele,fam,curNbOfElem,whichEntity,curMedType,MED_NOD); - delete [] tmp; - delete [] noms; - //trying to read global numbering - int *globArr=new int[curNbOfElem]; - if(MEDglobalNumLire(fid,nommaa,globArr,curNbOfElem,whichEntity,curMedType)==0) - elem.setGlobal(globArr); - else - delete [] globArr; - conn.push_back(elem); - } - } - int curNbOfPolyElem; - int curNbOfPolyElemM=MEDnEntMaa(fid,nommaa,MED_CONN,MED_MAILLE,MED_POLYGONE,MED_NOD); - int curNbOfPolyElemF=MEDnEntMaa(fid,nommaa,MED_CONN,MED_FACE,MED_POLYGONE,MED_NOD); - med_entite_maillage whichPolyEntity; - dispatchElems(curNbOfPolyElemM,curNbOfPolyElemF,curNbOfPolyElem,whichPolyEntity); - if(curNbOfPolyElem>0) - { - med_int arraySize; - MEDpolygoneInfo(fid,nommaa,whichPolyEntity,MED_NOD,&arraySize); - int *index=new int[curNbOfPolyElem+1]; - int *locConn=new int[arraySize]; - int *fam=new int[curNbOfPolyElem]; - MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYGON,locConn,index,fam,curNbOfPolyElem,arraySize); - MEDpolygoneConnLire(fid,nommaa,index,curNbOfPolyElem+1,locConn,whichPolyEntity,MED_NOD); - MEDfamLire(fid,nommaa,fam,curNbOfPolyElem,MED_MAILLE,MED_POLYGONE); - conn.push_back(elem); - } - curNbOfPolyElem=MEDnEntMaa(fid,nommaa,MED_CONN,MED_MAILLE,MED_POLYEDRE,MED_NOD); - if(curNbOfPolyElem>0) - { - med_int indexFaceLgth,connFaceLgth; - MEDpolyedreInfo(fid,nommaa,MED_NOD,&indexFaceLgth,&connFaceLgth); - int *index=new int[curNbOfPolyElem+1]; - int *indexFace=new int[indexFaceLgth]; - int *locConn=new int[connFaceLgth]; - int *fam=new int[curNbOfPolyElem]; - MEDpolyedreConnLire(fid,nommaa,index,curNbOfPolyElem+1,indexFace,indexFaceLgth,locConn,MED_NOD); - MEDfamLire(fid,nommaa,fam,curNbOfPolyElem,MED_MAILLE,MED_POLYEDRE); - int arraySize=connFaceLgth; - for(int i=0;i& conn) +{ + char nommaa[MED_TAILLE_NOM+1]; + char maillage_description[MED_TAILLE_DESC+1]; + char comp[3*MED_TAILLE_PNOM+1]; + char unit[3*MED_TAILLE_PNOM+1]; + med_maillage type_maillage; + med_int Mdim; + MEDmaaInfo(fid,meshId,nommaa,&Mdim,&type_maillage,maillage_description); + spaceDim=(int)Mdim; + nCoords=MEDnEntMaa(fid,nommaa,MED_COOR,MED_NOEUD,(med_geometrie_element)0,(med_connectivite)0); + coords=new double[nCoords*spaceDim]; + med_repere repere; + MEDcoordLire(fid,nommaa,Mdim,coords,MED_FULL_INTERLACE,MED_ALL,NULL,0,&repere,comp,unit); + med_booleen inoele, inuele; + for(int i=0;i0) + { + int *connTab=new int[(curMedType%100)*curNbOfElem]; + int *fam=new int[curNbOfElem]; + MEDLoader::MEDConnOfOneElemType elem(typmai2[i],connTab,0,fam,curNbOfElem,-1); + int *tmp=new int[curNbOfElem]; + char *noms=new char[MED_TAILLE_PNOM*curNbOfElem+1]; + MEDelementsLire(fid,nommaa,Mdim,connTab,MED_FULL_INTERLACE,noms,&inoele,tmp,&inuele,fam,curNbOfElem,whichEntity,curMedType,MED_NOD); + delete [] tmp; + delete [] noms; + //trying to read global numbering + int *globArr=new int[curNbOfElem]; + if(MEDglobalNumLire(fid,nommaa,globArr,curNbOfElem,whichEntity,curMedType)==0) + elem.setGlobal(globArr); + else + delete [] globArr; + conn.push_back(elem); + } + } + int curNbOfPolyElem; + int curNbOfPolyElemM=MEDnEntMaa(fid,nommaa,MED_CONN,MED_MAILLE,MED_POLYGONE,MED_NOD); + int curNbOfPolyElemF=MEDnEntMaa(fid,nommaa,MED_CONN,MED_FACE,MED_POLYGONE,MED_NOD); + med_entite_maillage whichPolyEntity; + MEDLoaderNS::dispatchElems(curNbOfPolyElemM,curNbOfPolyElemF,curNbOfPolyElem,whichPolyEntity); + if(curNbOfPolyElem>0) + { + med_int arraySize; + MEDpolygoneInfo(fid,nommaa,whichPolyEntity,MED_NOD,&arraySize); + int *index=new int[curNbOfPolyElem+1]; + int *locConn=new int[arraySize]; + int *fam=new int[curNbOfPolyElem]; + MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYGON,locConn,index,fam,curNbOfPolyElem,arraySize); + MEDpolygoneConnLire(fid,nommaa,index,curNbOfPolyElem+1,locConn,whichPolyEntity,MED_NOD); + MEDfamLire(fid,nommaa,fam,curNbOfPolyElem,MED_MAILLE,MED_POLYGONE); + conn.push_back(elem); + } + curNbOfPolyElem=MEDnEntMaa(fid,nommaa,MED_CONN,MED_MAILLE,MED_POLYEDRE,MED_NOD); + if(curNbOfPolyElem>0) + { + med_int indexFaceLgth,connFaceLgth; + MEDpolyedreInfo(fid,nommaa,MED_NOD,&indexFaceLgth,&connFaceLgth); + int *index=new int[curNbOfPolyElem+1]; + int *indexFace=new int[indexFaceLgth]; + int *locConn=new int[connFaceLgth]; + int *fam=new int[curNbOfPolyElem]; + MEDpolyedreConnLire(fid,nommaa,index,curNbOfPolyElem+1,indexFace,indexFaceLgth,locConn,MED_NOD); + MEDfamLire(fid,nommaa,fam,curNbOfPolyElem,MED_MAILLE,MED_POLYEDRE); + int arraySize=connFaceLgth; + for(int i=0;i unsigned calculateHighestMeshDim(const std::list& conn) { @@ -719,128 +720,131 @@ namespace MEDLoader } } } +} - class FieldPerTypeAccumulator - { - public: - int operator()(int res, const MEDLoader::MEDFieldDoublePerCellType& elt) { return res+elt.getNbOfTuple(); } - }; +class FieldPerTypeAccumulator +{ +public: + int operator()(int res, const MEDLoader::MEDFieldDoublePerCellType& elt) { return res+elt.getNbOfTuple(); } +}; - ParaMEDMEM::DataArrayDouble *buildArrayFromRawData(const std::list& fieldPerType) - { - ParaMEDMEM::DataArrayDouble *ret=ParaMEDMEM::DataArrayDouble::New(); - int totalNbOfTuple=std::accumulate(fieldPerType.begin(),fieldPerType.end(),0,FieldPerTypeAccumulator()); - int nbOfComp=(*fieldPerType.begin()).getNbComp(); - double *ptr=new double[nbOfComp*totalNbOfTuple]; - ret->useArray(ptr,true,ParaMEDMEM::CPP_DEALLOC,totalNbOfTuple,nbOfComp); - std::for_each(fieldPerType.begin(),fieldPerType.end(),FieldPerTypeCopier(ptr)); - return ret; - } +ParaMEDMEM::DataArrayDouble *MEDLoaderNS::buildArrayFromRawData(const std::list& fieldPerType) +{ + ParaMEDMEM::DataArrayDouble *ret=ParaMEDMEM::DataArrayDouble::New(); + int totalNbOfTuple=std::accumulate(fieldPerType.begin(),fieldPerType.end(),0,FieldPerTypeAccumulator()); + int nbOfComp=(*fieldPerType.begin()).getNbComp(); + double *ptr=new double[nbOfComp*totalNbOfTuple]; + ret->useArray(ptr,true,ParaMEDMEM::CPP_DEALLOC,totalNbOfTuple,nbOfComp); + std::for_each(fieldPerType.begin(),fieldPerType.end(),FieldPerTypeCopier(ptr)); + return ret; +} - class PolyCounterForFams - { - public: - PolyCounterForFams(int id, const int *index):_id(id),_index(index),_count(0),_sigma(0) { } - void operator()(int val) { if(val==_id) _sigma+=_index[_count+1]-_index[_count]; _count++; } - int getSigma() const { return _sigma; } - private: - int _id; - const int *_index; - int _count; - int _sigma; - }; +class PolyCounterForFams +{ +public: + PolyCounterForFams(int id, const int *index):_id(id),_index(index),_count(0),_sigma(0) { } + void operator()(int val) { if(val==_id) _sigma+=_index[_count+1]-_index[_count]; _count++; } + int getSigma() const { return _sigma; } +private: + int _id; + const int *_index; + int _count; + int _sigma; +}; - void tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list& medConnFrmt, +void MEDLoaderNS::tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list& medConnFrmt, DataArrayInt* &conn, DataArrayInt* &connIndex, const std::vector& familiesToKeep) - { - bool keepAll=familiesToKeep.empty(); - if(medConnFrmt.empty()) - { - conn=0; - connIndex=0; - return ; - } - std::list::const_iterator iter=medConnFrmt.begin(); - int totalNbOfCells=0; - int totalNbOfMedConn=0; - for(;iter!=medConnFrmt.end();iter++) - { - const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::getCellModel((*iter).getType()); +{ + bool keepAll=familiesToKeep.empty(); + if(medConnFrmt.empty()) + { + conn=0; + connIndex=0; + return ; + } + std::list::const_iterator iter=medConnFrmt.begin(); + int totalNbOfCells=0; + int totalNbOfMedConn=0; + for(;iter!=medConnFrmt.end();iter++) + { + const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::getCellModel((*iter).getType()); + if(keepAll) + totalNbOfCells+=(*iter).getLength(); + else + for(std::vector::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++) + totalNbOfCells+=std::count((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),*iter2); + if(!cellMod.isDynamic()) if(keepAll) - totalNbOfCells+=(*iter).getLength(); + totalNbOfMedConn+=(*iter).getLength()*cellMod.getNumberOfNodes(); else for(std::vector::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++) - totalNbOfCells+=std::count((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),*iter2); - if(!cellMod.isDynamic()) - if(keepAll) - totalNbOfMedConn+=(*iter).getLength()*cellMod.getNumberOfNodes(); - else - for(std::vector::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++) - totalNbOfMedConn+=std::count((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),*iter2)*cellMod.getNumberOfNodes(); + totalNbOfMedConn+=std::count((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),*iter2)*cellMod.getNumberOfNodes(); + else + if(keepAll) + totalNbOfMedConn+=(*iter).getConnLength(); else + for(std::vector::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++) + { + PolyCounterForFams res=std::for_each((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),PolyCounterForFams(*iter2,(*iter).getIndex())); + totalNbOfMedConn+=res.getSigma(); + } + } + connIndex=DataArrayInt::New(); + conn=DataArrayInt::New(); + connIndex->alloc(totalNbOfCells+1,1); + int *connIdxPtr=connIndex->getPointer(); + int connFillId=0; + conn->alloc(totalNbOfMedConn+totalNbOfCells,1); + int *connPtr=conn->getPointer(); + for(iter=medConnFrmt.begin();iter!=medConnFrmt.end();iter++) + { + INTERP_KERNEL::NormalizedCellType type=(*iter).getType(); + const int *sourceConn=(*iter).getArray(); + const int *sourceIndex=(*iter).getIndex(); + const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::getCellModel(type); + int nbOfCellsInCurType; + int nbOfNodesIn1Cell=cellMod.getNumberOfNodes(); + nbOfCellsInCurType=(*iter).getLength(); + bool isDyn=cellMod.isDynamic(); + int *tmpConnPtr; + for(int i=0;i::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++) - { - PolyCounterForFams res=std::for_each((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),PolyCounterForFams(*iter2,(*iter).getIndex())); - totalNbOfMedConn+=res.getSigma(); - } - } - connIndex=DataArrayInt::New(); - conn=DataArrayInt::New(); - connIndex->alloc(totalNbOfCells+1,1); - int *connIdxPtr=connIndex->getPointer(); - int connFillId=0; - conn->alloc(totalNbOfMedConn+totalNbOfCells,1); - int *connPtr=conn->getPointer(); - for(iter=medConnFrmt.begin();iter!=medConnFrmt.end();iter++) - { - INTERP_KERNEL::NormalizedCellType type=(*iter).getType(); - const int *sourceConn=(*iter).getArray(); - const int *sourceIndex=(*iter).getIndex(); - const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::getCellModel(type); - int nbOfCellsInCurType; - int nbOfNodesIn1Cell=cellMod.getNumberOfNodes(); - nbOfCellsInCurType=(*iter).getLength(); - bool isDyn=cellMod.isDynamic(); - int *tmpConnPtr; - for(int i=0;i(),1)); - else - tmpConnPtr=std::transform(sourceConn,sourceConn+sourceIndex[i+1]-sourceIndex[i],connPtr,std::bind2nd(std::minus(),1)); - connIdxPtr++; - nbOfNodesIn1Cell=tmpConnPtr-connPtr; - connFillId+=nbOfNodesIn1Cell+1; - connPtr=tmpConnPtr; - } - else if(std::find(familiesToKeep.begin(),familiesToKeep.end(),(*iter).getFam()[i])!=familiesToKeep.end()) - { - *connIdxPtr=connFillId; - *connPtr++=type; - if(!isDyn) - tmpConnPtr=std::transform(sourceConn,sourceConn+nbOfNodesIn1Cell,connPtr,std::bind2nd(std::minus(),1)); - else - tmpConnPtr=std::transform(sourceConn,sourceConn+sourceIndex[i+1]-sourceIndex[i],connPtr,std::bind2nd(std::minus(),1)); - connIdxPtr++; - nbOfNodesIn1Cell=tmpConnPtr-connPtr; - connFillId+=nbOfNodesIn1Cell+1; - connPtr=tmpConnPtr; - } - sourceConn+=nbOfNodesIn1Cell; - } - *connIdxPtr=connFillId; - } - } - + { + *connIdxPtr=connFillId; + *connPtr++=type; + if(!isDyn) + tmpConnPtr=std::transform(sourceConn,sourceConn+nbOfNodesIn1Cell,connPtr,std::bind2nd(std::minus(),1)); + else + tmpConnPtr=std::transform(sourceConn,sourceConn+sourceIndex[i+1]-sourceIndex[i],connPtr,std::bind2nd(std::minus(),1)); + connIdxPtr++; + nbOfNodesIn1Cell=tmpConnPtr-connPtr; + connFillId+=nbOfNodesIn1Cell+1; + connPtr=tmpConnPtr; + } + else if(std::find(familiesToKeep.begin(),familiesToKeep.end(),(*iter).getFam()[i])!=familiesToKeep.end()) + { + *connIdxPtr=connFillId; + *connPtr++=type; + if(!isDyn) + tmpConnPtr=std::transform(sourceConn,sourceConn+nbOfNodesIn1Cell,connPtr,std::bind2nd(std::minus(),1)); + else + tmpConnPtr=std::transform(sourceConn,sourceConn+sourceIndex[i+1]-sourceIndex[i],connPtr,std::bind2nd(std::minus(),1)); + connIdxPtr++; + nbOfNodesIn1Cell=tmpConnPtr-connPtr; + connFillId+=nbOfNodesIn1Cell+1; + connPtr=tmpConnPtr; + } + sourceConn+=nbOfNodesIn1Cell; + } + *connIdxPtr=connFillId; + } +} + +namespace MEDLoaderNS +{ template void releaseMEDFileCoreFrmt(typename std::list& medConnFrmt) { @@ -848,162 +852,162 @@ namespace MEDLoader (*iter).releaseArray(); medConnFrmt.clear(); } +} - /*! - * This method builds a sub set of connectivity for a given type 'type'. - * @param conn input containing connectivity with MEDCoupling format. - * @param connIndex input containing connectivity index in MEDCoupling format. - * @param type input specifying which cell types will be extracted in conn4MEDFile. - * @param conn4MEDFile output containing the connectivity directly understandable by MEDFile; conn4MEDFile has to be empty before this method called. - * @param connIndex4MEDFile output containing index connectivity understandable by MEDFile; only used by polygons and polyhedrons (it is face nodal connec). - * @param connIndexRk24MEDFile output containing index of rank 2 understandable by MEDFile; only used by polyhedrons. - * @return nb of elements extracted. - */ - int buildMEDSubConnectivityOfOneTypeStaticTypes(DataArrayInt *conn, DataArrayInt *connIndex, INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile) - { - int ret=0; - int nbOfElem=connIndex->getNbOfElems()-1; - const int *connPtr=conn->getPointer(); - const int *connIdxPtr=connIndex->getPointer(); - for(int i=0;i(),1)); - return ret; - } +/*! + * This method builds a sub set of connectivity for a given type 'type'. + * @param conn input containing connectivity with MEDCoupling format. + * @param connIndex input containing connectivity index in MEDCoupling format. + * @param type input specifying which cell types will be extracted in conn4MEDFile. + * @param conn4MEDFile output containing the connectivity directly understandable by MEDFile; conn4MEDFile has to be empty before this method called. + * @param connIndex4MEDFile output containing index connectivity understandable by MEDFile; only used by polygons and polyhedrons (it is face nodal connec). + * @param connIndexRk24MEDFile output containing index of rank 2 understandable by MEDFile; only used by polyhedrons. + * @return nb of elements extracted. + */ +int MEDLoaderNS::buildMEDSubConnectivityOfOneTypeStaticTypes(DataArrayInt *conn, DataArrayInt *connIndex, INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile) +{ + int ret=0; + int nbOfElem=connIndex->getNbOfElems()-1; + const int *connPtr=conn->getPointer(); + const int *connIdxPtr=connIndex->getPointer(); + for(int i=0;i(),1)); + return ret; +} - int buildMEDSubConnectivityOfOneTypesPolyg(DataArrayInt *conn, DataArrayInt *connIndex, std::vector& conn4MEDFile, std::vector& connIndex4MEDFile) - { - int ret=0; - int nbOfElem=connIndex->getNbOfElems()-1; - const int *connPtr=conn->getPointer(); - const int *connIdxPtr=connIndex->getPointer(); - connIndex4MEDFile.push_back(1); - for(int i=0;i(),1)); - return ret; - } +int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyg(DataArrayInt *conn, DataArrayInt *connIndex, std::vector& conn4MEDFile, std::vector& connIndex4MEDFile) +{ + int ret=0; + int nbOfElem=connIndex->getNbOfElems()-1; + const int *connPtr=conn->getPointer(); + const int *connIdxPtr=connIndex->getPointer(); + connIndex4MEDFile.push_back(1); + for(int i=0;i(),1)); + return ret; +} - int buildMEDSubConnectivityOfOneTypesPolyh(DataArrayInt *conn, DataArrayInt *connIndex, std::vector& conn4MEDFile, std::vector& connIndex4MEDFile, std::vector& connIndexRk24MEDFile) - { - return 0; - } +int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyh(DataArrayInt *conn, DataArrayInt *connIndex, std::vector& conn4MEDFile, std::vector& connIndex4MEDFile, std::vector& connIndexRk24MEDFile) +{ + return 0; +} - /*! - * This method builds a sub set of connectivity for a given type 'type'. - * @param conn input containing connectivity with MEDCoupling format. - * @param connIndex input containing connectivity index in MEDCoupling format. - * @param type input specifying which cell types will be extracted in conn4MEDFile. - * @param conn4MEDFile output containing the connectivity directly understandable by MEDFile; conn4MEDFile has to be empty before this method called. - * @param connIndex4MEDFile output containing index connectivity understandable by MEDFile; only used by polygons and polyhedrons (it is face nodal connec). - * @param connIndexRk24MEDFile output containing index of rank 2 understandable by MEDFile; only used by polyhedrons. - * @return nb of elements extracted. - */ - int buildMEDSubConnectivityOfOneType(DataArrayInt *conn, DataArrayInt *connIndex, INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile, - std::vector& connIndex4MEDFile, std::vector& connIndexRk24MEDFile) - { +/*! + * This method builds a sub set of connectivity for a given type 'type'. + * @param conn input containing connectivity with MEDCoupling format. + * @param connIndex input containing connectivity index in MEDCoupling format. + * @param type input specifying which cell types will be extracted in conn4MEDFile. + * @param conn4MEDFile output containing the connectivity directly understandable by MEDFile; conn4MEDFile has to be empty before this method called. + * @param connIndex4MEDFile output containing index connectivity understandable by MEDFile; only used by polygons and polyhedrons (it is face nodal connec). + * @param connIndexRk24MEDFile output containing index of rank 2 understandable by MEDFile; only used by polyhedrons. + * @return nb of elements extracted. + */ +int MEDLoaderNS::buildMEDSubConnectivityOfOneType(DataArrayInt *conn, DataArrayInt *connIndex, INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile, + std::vector& connIndex4MEDFile, std::vector& connIndexRk24MEDFile) +{ - const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::getCellModel(type); - if(!cellMod.isDynamic()) - return buildMEDSubConnectivityOfOneTypeStaticTypes(conn,connIndex,type,conn4MEDFile); - else - { - if(type==INTERP_KERNEL::NORM_POLYGON) - return buildMEDSubConnectivityOfOneTypesPolyg(conn,connIndex,conn4MEDFile,connIndex4MEDFile); - else - return buildMEDSubConnectivityOfOneTypesPolyh(conn,connIndex,conn4MEDFile,connIndex4MEDFile,connIndexRk24MEDFile); - } - } + const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::getCellModel(type); + if(!cellMod.isDynamic()) + return buildMEDSubConnectivityOfOneTypeStaticTypes(conn,connIndex,type,conn4MEDFile); + else + { + if(type==INTERP_KERNEL::NORM_POLYGON) + return buildMEDSubConnectivityOfOneTypesPolyg(conn,connIndex,conn4MEDFile,connIndex4MEDFile); + else + return buildMEDSubConnectivityOfOneTypesPolyh(conn,connIndex,conn4MEDFile,connIndex4MEDFile,connIndexRk24MEDFile); + } +} - /*! - * @param ids is a in vector containing families ids whose cells have to be kept. If empty all cells are kept. - * @param typesToKeep is a in vector that indicates which types to keep after dimension filtering. - * @param meshDimExtract out parameter that gives the mesh dimension. - */ - MEDCouplingUMesh *readUMeshFromFileLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& ids, - const std::vector& typesToKeep, unsigned& meshDimExtract) throw(INTERP_KERNEL::Exception) - { +/*! + * @param ids is a in vector containing families ids whose cells have to be kept. If empty all cells are kept. + * @param typesToKeep is a in vector that indicates which types to keep after dimension filtering. + * @param meshDimExtract out parameter that gives the mesh dimension. + */ +MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& ids, + const std::vector& typesToKeep, unsigned& meshDimExtract) throw(INTERP_KERNEL::Exception) +{ //Extraction data from MED file. - med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); - std::string trueMeshName; - med_int mid=getIdFromMeshName(fid,meshName,trueMeshName); - double *coords; - int nCoords; - int spaceDim; - std::list conn; - readUMeshDataInMedFile(fid,mid,coords,nCoords,spaceDim,conn); - meshDimExtract=calculateHighestMeshDim(conn); - meshDimExtract=meshDimExtract+meshDimRelToMax; - keepSpecifiedMeshDim(conn,meshDimExtract); - keepTypes(conn,typesToKeep); - MEDfermer(fid); - //Put data in returned data structure. - MEDCouplingUMesh *ret=MEDCouplingUMesh::New(); - ret->setName(trueMeshName.c_str()); - ret->setMeshDimension(meshDimExtract); - // - DataArrayDouble *coordsArr=DataArrayDouble::New(); - coordsArr->useArray(coords,true,ParaMEDMEM::CPP_DEALLOC,nCoords,spaceDim); - ret->setCoords(coordsArr); - coordsArr->decrRef(); - // - DataArrayInt *connArr,*connIndexArr; - tradMEDFileCoreFrmt2MEDCouplingUMesh(conn,connArr,connIndexArr,ids); - ret->setConnectivity(connArr,connIndexArr); - //clean-up - if(connArr) - connArr->decrRef(); - if(connIndexArr) - connIndexArr->decrRef(); - releaseMEDFileCoreFrmt(conn); - return ret; - } + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + std::string trueMeshName; + med_int mid=getIdFromMeshName(fid,meshName,trueMeshName); + double *coords; + int nCoords; + int spaceDim; + std::list conn; + readUMeshDataInMedFile(fid,mid,coords,nCoords,spaceDim,conn); + meshDimExtract=MEDLoaderNS::calculateHighestMeshDim(conn); + meshDimExtract=meshDimExtract+meshDimRelToMax; + MEDLoaderNS::keepSpecifiedMeshDim(conn,meshDimExtract); + MEDLoaderNS::keepTypes(conn,typesToKeep); + MEDfermer(fid); + //Put data in returned data structure. + MEDCouplingUMesh *ret=MEDCouplingUMesh::New(); + ret->setName(trueMeshName.c_str()); + ret->setMeshDimension(meshDimExtract); + // + DataArrayDouble *coordsArr=DataArrayDouble::New(); + coordsArr->useArray(coords,true,ParaMEDMEM::CPP_DEALLOC,nCoords,spaceDim); + ret->setCoords(coordsArr); + coordsArr->decrRef(); + // + DataArrayInt *connArr,*connIndexArr; + tradMEDFileCoreFrmt2MEDCouplingUMesh(conn,connArr,connIndexArr,ids); + ret->setConnectivity(connArr,connIndexArr); + //clean-up + if(connArr) + connArr->decrRef(); + if(connIndexArr) + connIndexArr->decrRef(); + releaseMEDFileCoreFrmt(conn); + return ret; +} - ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order, - ParaMEDMEM::TypeOfField typeOfOutField) - { - std::list fieldPerCellType; - double time; - readFieldDoubleDataInMedFile(fileName,meshName,fieldName,fieldPerCellType,iteration,order,typeOfOutField,time); - std::vector familiesToKeep; - std::vector typesToKeep; - if(typeOfOutField==ON_CELLS) - for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) - typesToKeep.push_back((*iter).getType()); - unsigned meshDim; - ParaMEDMEM::MEDCouplingUMesh *mesh=readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); - if(typeOfOutField==ON_CELLS) - keepSpecifiedMeshDim(fieldPerCellType,meshDim); - ParaMEDMEM::MEDCouplingFieldDouble *ret=ParaMEDMEM::MEDCouplingFieldDouble::New(typeOfOutField,ONE_TIME); - ret->setName(fieldName); - ret->setTime(time,iteration,order); - ret->setMesh(mesh); - mesh->decrRef(); - ParaMEDMEM::DataArrayDouble *arr=buildArrayFromRawData(fieldPerCellType); - ret->setArray(arr); - arr->decrRef(); - releaseMEDFileCoreFrmt(fieldPerCellType); - return ret; - } +ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order, + ParaMEDMEM::TypeOfField typeOfOutField) +{ + std::list fieldPerCellType; + double time; + readFieldDoubleDataInMedFile(fileName,meshName,fieldName,fieldPerCellType,iteration,order,typeOfOutField,time); + std::vector familiesToKeep; + std::vector typesToKeep; + if(typeOfOutField==ON_CELLS) + for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) + typesToKeep.push_back((*iter).getType()); + unsigned meshDim; + ParaMEDMEM::MEDCouplingUMesh *mesh=readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); + if(typeOfOutField==ON_CELLS) + MEDLoaderNS::keepSpecifiedMeshDim(fieldPerCellType,meshDim); + ParaMEDMEM::MEDCouplingFieldDouble *ret=ParaMEDMEM::MEDCouplingFieldDouble::New(typeOfOutField,ONE_TIME); + ret->setName(fieldName); + ret->setTime(time,iteration,order); + ret->setMesh(mesh); + mesh->decrRef(); + ParaMEDMEM::DataArrayDouble *arr=buildArrayFromRawData(fieldPerCellType); + ret->setArray(arr); + arr->decrRef(); + releaseMEDFileCoreFrmt(fieldPerCellType); + return ret; } MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception) @@ -1011,7 +1015,7 @@ MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, const char std::vector familiesToKeep; std::vector typesToKeep; unsigned meshDim; - return readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); + return MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); } ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception) @@ -1019,36 +1023,36 @@ ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, std::vector familiesToKeep; std::vector typesToKeep; unsigned meshDim; - return readUMeshFromFileLev1(fileName,0,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); + return MEDLoaderNS::readUMeshFromFileLev1(fileName,0,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); } ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams) { - std::vector familiesToKeep=getIdsFromFamilies(fileName,meshName,fams); + std::vector familiesToKeep=MEDLoaderNS::getIdsFromFamilies(fileName,meshName,fams); std::vector typesToKeep; unsigned meshDim; - return readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); + return MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); } ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps) { - std::vector familiesToKeep=getIdsFromGroups(fileName,meshName,grps); + std::vector familiesToKeep=MEDLoaderNS::getIdsFromGroups(fileName,meshName,grps); std::vector typesToKeep; unsigned meshDim; - return readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); + return MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); } ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) { - return readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_CELLS); + return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_CELLS); } ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) { - return readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_NODES); + return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_NODES); } -void MEDLoader::writeUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh) +void MEDLoader::WriteUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh) { med_idt fid=MEDouvrir((char *)fileName,MED_CREATION); std::string meshName(mesh->getName()); @@ -1076,7 +1080,7 @@ void MEDLoader::writeUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *m std::vector medConn; std::vector medConnIndex; std::vector medConnIndex2; - int nbOfElt=buildMEDSubConnectivityOfOneType(conn,connIndex,curType,medConn,medConnIndex,medConnIndex2); + int nbOfElt=MEDLoaderNS::buildMEDSubConnectivityOfOneType(conn,connIndex,curType,medConn,medConnIndex,medConnIndex2); if(curMedType!=MED_POLYGONE && curMedType!=MED_POLYEDRE) MEDconnEcr(fid,maa,mesh->getMeshDimension(),&medConn[0],MED_FULL_INTERLACE,nbOfElt,MED_MAILLE,curMedType,MED_NOD); else @@ -1100,6 +1104,6 @@ void MEDLoader::writeUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *m MEDfermer(fid); } -void MEDLoader::writeField(const char *fileName, const char *meshName, ParaMEDMEM::MEDCouplingFieldDouble *f) +void MEDLoader::WriteField(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f) { } diff --git a/src/MEDLoader/MEDLoader.hxx b/src/MEDLoader/MEDLoader.hxx index 5e8e0824a..71065e217 100644 --- a/src/MEDLoader/MEDLoader.hxx +++ b/src/MEDLoader/MEDLoader.hxx @@ -32,8 +32,9 @@ namespace ParaMEDMEM class MEDCouplingFieldDouble; } -namespace MEDLoader +class MEDLoader { +public: class MEDConnOfOneElemType { public: @@ -73,21 +74,23 @@ namespace MEDLoader INTERP_KERNEL::NormalizedCellType _type; }; // - std::vector GetMeshNames(const char *fileName); - std::vector GetMeshGroupsNames(const char *fileName, const char *meshName); - std::vector GetMeshFamilyNames(const char *fileName, const char *meshName); - std::vector GetCellFieldNamesOnMesh(const char *fileName, const char *meshName); - std::vector GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName); - std::vector< std::pair > GetCellFieldIterations(const char *fileName, const char *fieldName); - std::vector< std::pair > GetNodeFieldIterations(const char *fileName, const char *fieldName); - ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams); - ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps); - ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); - ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); - ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); - ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); - void writeUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh); - void writeField(const char *fileName, const char *meshName, ParaMEDMEM::MEDCouplingFieldDouble *f); -} + static std::vector GetMeshNames(const char *fileName); + static std::vector GetMeshGroupsNames(const char *fileName, const char *meshName); + static std::vector GetMeshFamilyNames(const char *fileName, const char *meshName); + static std::vector GetCellFieldNamesOnMesh(const char *fileName, const char *meshName); + static std::vector GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName); + static std::vector< std::pair > GetCellFieldIterations(const char *fileName, const char *fieldName); + static std::vector< std::pair > GetNodeFieldIterations(const char *fileName, const char *fieldName); + static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams); + static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps); + 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 *ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); + static void WriteUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh); + static void WriteField(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f); +private: + MEDLoader(); +}; #endif diff --git a/src/MEDLoader/Swig/libMEDLoader_Swig.i b/src/MEDLoader/Swig/libMEDLoader_Swig.i index 398b5d84e..b4994f056 100644 --- a/src/MEDLoader/Swig/libMEDLoader_Swig.i +++ b/src/MEDLoader/Swig/libMEDLoader_Swig.i @@ -19,6 +19,9 @@ // %module libMEDLoader_Swig +%include std_vector.i +%include std_string.i + %include "MEDCouplingTypemaps.i" %include "libMEDCoupling_Swig.i" @@ -26,11 +29,40 @@ #include "MEDLoader.hxx" %} +#if SWIG_VERSION >= 0x010329 +%template() std::vector; +#endif + %newobject MEDLoader::ReadUMeshFromFile; +%newobject MEDLoader::ReadFieldDoubleCell; -namespace MEDLoader +class MEDLoader { - ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); - ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); -} - +public: + static std::vector GetMeshNames(const char *fileName); + static std::vector GetMeshGroupsNames(const char *fileName, const char *meshName); + static std::vector GetMeshFamilyNames(const char *fileName, const char *meshName); + static std::vector GetCellFieldNamesOnMesh(const char *fileName, const char *meshName); + static std::vector GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName); + %extend + { + static PyObject *GetCellFieldIterations(const char *fileName, const char *fieldName) + { + std::vector< std::pair > res=MEDLoader::GetCellFieldIterations(fileName,fieldName); + PyObject *ret=PyList_New(res.size()); + int rk=0; + for(std::vector< std::pair >::const_iterator iter=res.begin();iter!=res.end();iter++,rk++) + { + PyObject *elt=PyTuple_New(2); + PyTuple_SetItem(elt,0,SWIG_From_int((*iter).first)); + PyTuple_SetItem(elt,1,SWIG_From_int((*iter).second)); + PyList_SetItem(ret,rk,elt); + } + return ret; + } + } + //std::vector< std::pair > GetNodeFieldIterations(const char *fileName, const char *fieldName); + 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 *ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); +};