From: ageay Date: Fri, 20 Aug 2010 09:33:27 +0000 (+0000) Subject: MEDLoader manages cell renumbering and multi fields on same mesh fetching. X-Git-Tag: V5_1_main_FINAL~59 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=597ba9f3be9f84a0a4a8f26efd67aa919a1e0f3c;p=tools%2Fmedcoupling.git MEDLoader manages cell renumbering and multi fields on same mesh fetching. --- diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index c2536b6fc..6738e30fe 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -58,7 +58,7 @@ med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2] = { MED_POINT1, med_geometrie_element typmainoeud[1] = { MED_NONE }; -INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2] = { INTERP_KERNEL::NORM_ERROR, +INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2] = { INTERP_KERNEL::NORM_POINT0, INTERP_KERNEL::NORM_SEG2, INTERP_KERNEL::NORM_SEG3, INTERP_KERNEL::NORM_TRI3, @@ -152,31 +152,35 @@ namespace MEDLoaderNS void readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list& conn); int buildMEDSubConnectivityOfOneType(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile, std::vector& connIndex4MEDFile, std::vector& connIndexRk24MEDFile, - std::vector& fam4MEDFile); + std::vector& fam4MEDFile, std::vector& renumber); MEDCouplingUMesh *readUMeshFromFileLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& ids, - const std::vector& typesToKeep, unsigned& meshDimExtract) throw(INTERP_KERNEL::Exception); + const std::vector& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception); void tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list& medConnFrmt, + const std::vector& familiesToKeep, DataArrayInt* &conn, DataArrayInt* &connIndex, - const std::vector& familiesToKeep); + int *&cellRenum); ParaMEDMEM::DataArrayDouble *buildArrayFromRawData(const std::list& fieldPerType, const std::vector& infos); int buildMEDSubConnectivityOfOneTypesPolyg(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, - std::vector& conn4MEDFile, std::vector& connIndex4MEDFile, std::vector& fam4MEDFile); + std::vector& conn4MEDFile, std::vector& connIndex4MEDFile, std::vector& fam4MEDFile, std::vector& renumber); int buildMEDSubConnectivityOfOneTypesPolyh(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, std::vector& conn4MEDFile, std::vector& connIndex4MEDFile, std::vector& connIndexRk24MEDFile, - std::vector& fam4MEDFile); + std::vector& fam4MEDFile, std::vector& renumber); int buildMEDSubConnectivityOfOneTypeStaticTypes(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, - INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile, std::vector& fam4MEDFile); + INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile, std::vector& fam4MEDFile, std::vector& renumber); ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField); + ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev2(const char *fileName, ParaMEDMEM::TypeOfField typeOfOutField, unsigned meshDim, const int *renumCell, const ParaMEDMEM::MEDCouplingUMesh *mesh, + const std::vector& infos, const char *fieldName, int iteration, int order, double time, + std::list& fieldPerCellType); med_idt appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, med_int& numdt, med_int& numo, med_float& dt); void appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f); void appendNodeProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshNodeIds); void appendCellProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIds); void prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *cellIds, std::list& split); void fillGaussDataOnField(const char *fileName, const std::list& data, MEDCouplingFieldDouble *f); - void writeUMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, const DataArrayInt *families, bool forceFromScratch); + void writeUMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, const DataArrayInt *families, bool forceFromScratch, bool &isRenumbering); void writeUMeshesDirectly(const char *fileName, const char *meshName, const std::vector& meshes, bool forceFromScratch); void writeFieldAndMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch); void writeFieldTryingToFitExistingMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f); @@ -185,7 +189,7 @@ namespace MEDLoaderNS /*! * This method sets the epsilon value used for node comparison when trying to buid a profile for a field on node/cell on an already written mesh. */ -void MEDLoader::setEpsilonForNodeComp(double val) +void MEDLoader::setEpsilonForNodeComp(double val) throw(INTERP_KERNEL::Exception) { _EPS_FOR_NODE_COMP=val; } @@ -193,7 +197,7 @@ void MEDLoader::setEpsilonForNodeComp(double val) /*! * This method sets the policy comparison when trying to fit the already written mesh on a field. The semantic of the policy is specified in MEDCouplingUMesh::zipConnectivityTraducer. */ -void MEDLoader::setCompPolicyForCell(int val) +void MEDLoader::setCompPolicyForCell(int val) throw(INTERP_KERNEL::Exception) { _COMP_FOR_CELL=val; } @@ -202,7 +206,7 @@ void MEDLoader::setCompPolicyForCell(int val) * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file. * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown. */ -void MEDLoader::setTooLongStrPolicy(int val) +void MEDLoader::setTooLongStrPolicy(int val) throw(INTERP_KERNEL::Exception) { _TOO_LONG_STR=val; } @@ -294,7 +298,7 @@ void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list MEDLoader::GetMeshNames(const char *fileName) +std::vector MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception) { med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); std::vector ret=MEDLoaderNS::getMeshNamesFid(fid); @@ -302,7 +306,7 @@ std::vector MEDLoader::GetMeshNames(const char *fileName) return ret; } -std::vector MEDLoader::GetMeshFamilyNames(const char *fileName, const char *meshName) +std::vector MEDLoader::GetMeshFamilyNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) { med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); med_int nfam=MEDnFam(fid,(char *)meshName); @@ -329,7 +333,7 @@ std::vector MEDLoader::GetMeshFamilyNames(const char *fileName, con return ret; } -std::vector MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) +std::vector MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) { med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); med_int nfam=MEDnFam(fid,(char *)meshName); @@ -360,7 +364,7 @@ std::vector MEDLoader::GetMeshGroupsNames(const char *fileName, con return ret; } -std::vector MEDLoader::GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) +std::vector MEDLoader::GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) { std::vector ret; med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); @@ -410,7 +414,7 @@ std::vector MEDLoader::GetCellFieldNamesOnMesh(const char *fileName return ret; } -std::vector MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) +std::vector MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) { std::vector ret; med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); @@ -454,7 +458,7 @@ std::vector MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName return ret; } -std::vector< std::pair > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) +std::vector< std::pair > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) { switch(type) { @@ -467,7 +471,7 @@ std::vector< std::pair > MEDLoader::GetFieldIterations(ParaMEDMEM::Type } } -std::vector< std::pair > MEDLoader::GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) +std::vector< std::pair > MEDLoader::GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) { std::string meshNameCpp(meshName); std::vector< std::pair > ret; @@ -518,7 +522,7 @@ std::vector< std::pair > MEDLoader::GetCellFieldIterations(const char * return ret; } -std::vector< std::pair > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) +std::vector< std::pair > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) { std::string meshNameCpp(meshName); std::vector< std::pair > ret; @@ -858,7 +862,7 @@ void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayD delete [] noms; //trying to read global numbering int *globArr=new int[curNbOfElem]; - if(MEDglobalNumLire(fid,nommaa,globArr,curNbOfElem,whichEntity,curMedType)==0) + if(MEDnumLire(fid,nommaa,globArr,curNbOfElem,whichEntity,curMedType)==0) elem.setGlobal(globArr); else delete [] globArr; @@ -877,9 +881,14 @@ void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayD int *index=new int[curNbOfPolyElem+1]; int *locConn=new int[arraySize]; int *fam=new int[curNbOfPolyElem]; + int *globArr=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); + MEDfamLire(fid,nommaa,fam,curNbOfPolyElem,whichPolyEntity,MED_POLYGONE); + if(MEDnumLire(fid,nommaa,globArr,curNbOfPolyElem,whichPolyEntity,MED_POLYGONE)==0) + elem.setGlobal(globArr); + else + delete [] globArr; conn.push_back(elem); } curNbOfPolyElem=MEDnEntMaa(fid,nommaa,MED_CONN,MED_MAILLE,MED_POLYEDRE,MED_NOD); @@ -891,6 +900,7 @@ void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayD int *indexFace=new int[indexFaceLgth]; int *locConn=new int[connFaceLgth]; int *fam=new int[curNbOfPolyElem]; + int *globArr=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; @@ -914,6 +924,10 @@ void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayD delete [] locConn; delete [] indexFace; MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYHED,finalConn,finalIndex,fam,curNbOfPolyElem,arraySize); + if(MEDnumLire(fid,nommaa,globArr,curNbOfPolyElem,MED_MAILLE,MED_POLYEDRE)==0) + elem.setGlobal(globArr); + else + delete [] globArr; conn.push_back(elem); } } @@ -1002,23 +1016,33 @@ private: int _sigma; }; +/*! + * This method fills unstructured connectivity using basic MED file format 'medConnFrmt'. + * If in each elements of 'medConnFrmt' a renumbering cell array is found the aggregate array 'cellRenum' is returned. + */ void MEDLoaderNS::tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list& medConnFrmt, + const std::vector& familiesToKeep, DataArrayInt* &conn, DataArrayInt* &connIndex, - const std::vector& familiesToKeep) + int *&cellRenum) { bool keepAll=familiesToKeep.empty(); if(medConnFrmt.empty()) { conn=0; connIndex=0; + cellRenum=0; return ; } std::list::const_iterator iter=medConnFrmt.begin(); int totalNbOfCells=0; int totalNbOfMedConn=0; + bool renumber=true; + cellRenum=0; for(;iter!=medConnFrmt.end();iter++) { + if((*iter).getGlobal()==0) + renumber=false; const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::getCellModel((*iter).getType()); if(keepAll) totalNbOfCells+=(*iter).getLength(); @@ -1048,11 +1072,15 @@ void MEDLoaderNS::tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::listalloc(totalNbOfMedConn+totalNbOfCells,1); int *connPtr=conn->getPointer(); + if(renumber) + cellRenum=new int[totalNbOfCells]; + int *renumW=cellRenum; 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 int *globalNum=(*iter).getGlobal(); const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::getCellModel(type); int nbOfCellsInCurType; int nbOfNodesIn1Cell=cellMod.getNumberOfNodes(); @@ -1062,9 +1090,11 @@ void MEDLoaderNS::tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list(),1)); else @@ -1075,12 +1105,14 @@ void MEDLoaderNS::tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list(),1)); - else + else//The duplication of code is motivated by the line underneath. tmpConnPtr=std::transform((*iter).getArray()+sourceIndex[i]-1,(*iter).getArray()+sourceIndex[i+1]-1,connPtr,std::bind2nd(std::minus(),1)); connIdxPtr++; nbOfNodesIn1Cell=tmpConnPtr-connPtr; @@ -1117,7 +1149,7 @@ namespace MEDLoaderNS * @return nb of elements extracted. */ int MEDLoaderNS::buildMEDSubConnectivityOfOneTypeStaticTypes(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile, - std::vector& fam4MEDFile) + std::vector& fam4MEDFile, std::vector& renumber) { int ret=0; int nbOfElem=connIndex->getNbOfElems()-1; @@ -1134,6 +1166,7 @@ int MEDLoaderNS::buildMEDSubConnectivityOfOneTypeStaticTypes(const DataArrayInt conn4MEDFile.insert(conn4MEDFile.end(),connPtr+1,connPtr+delta); if(families) fam4MEDFile.push_back(famPtr[i]); + renumber.push_back(i+1); ret++; } connIdxPtr++; @@ -1144,7 +1177,7 @@ int MEDLoaderNS::buildMEDSubConnectivityOfOneTypeStaticTypes(const DataArrayInt } int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyg(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, std::vector& conn4MEDFile, std::vector& connIndex4MEDFile, - std::vector& fam4MEDFile) + std::vector& fam4MEDFile, std::vector& renumber) { int ret=0; int nbOfElem=connIndex->getNbOfElems()-1; @@ -1163,6 +1196,7 @@ int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyg(const DataArrayInt *conn connIndex4MEDFile.push_back(connIndex4MEDFile.back()+delta-1); if(families) fam4MEDFile.push_back(famPtr[i]); + renumber.push_back(i+1); ret++; } connIdxPtr++; @@ -1174,7 +1208,7 @@ int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyg(const DataArrayInt *conn int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyh(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, std::vector& conn4MEDFile, std::vector& connIndex4MEDFile, std::vector& connIndexRk24MEDFile, - std::vector& fam4MEDFile) + std::vector& fam4MEDFile, std::vector& renumber) { int ret=0; int nbOfElem=connIndex->getNbOfElems()-1; @@ -1205,6 +1239,7 @@ int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyh(const DataArrayInt *conn connIndexRk24MEDFile.push_back(connIndexRk24MEDFile.back()+nbOfFacesOfPolyh); if(families) fam4MEDFile.push_back(famPtr[i]); + renumber.push_back(i+1); ret++; } connIdxPtr++; @@ -1228,18 +1263,18 @@ int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyh(const DataArrayInt *conn */ int MEDLoaderNS::buildMEDSubConnectivityOfOneType(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile, - std::vector& connIndex4MEDFile, std::vector& connIndexRk24MEDFile, std::vector& fam4MEDFile) + std::vector& connIndex4MEDFile, std::vector& connIndexRk24MEDFile, std::vector& fam4MEDFile, std::vector& renumber) { const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::getCellModel(type); if(!cellMod.isDynamic()) - return buildMEDSubConnectivityOfOneTypeStaticTypes(conn,connIndex,families,type,conn4MEDFile,fam4MEDFile); + return buildMEDSubConnectivityOfOneTypeStaticTypes(conn,connIndex,families,type,conn4MEDFile,fam4MEDFile,renumber); else { if(type==INTERP_KERNEL::NORM_POLYGON) - return buildMEDSubConnectivityOfOneTypesPolyg(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,fam4MEDFile); + return buildMEDSubConnectivityOfOneTypesPolyg(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,fam4MEDFile,renumber); else - return buildMEDSubConnectivityOfOneTypesPolyh(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,connIndexRk24MEDFile,fam4MEDFile); + return buildMEDSubConnectivityOfOneTypesPolyh(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,connIndexRk24MEDFile,fam4MEDFile,renumber); } } @@ -1247,9 +1282,10 @@ int MEDLoaderNS::buildMEDSubConnectivityOfOneType(const DataArrayInt *conn, cons * @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. + * @param cellRenum out parameter that specifies the renumbering (if !=0) of cells in file. */ 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) + const std::vector& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception) { //Extraction data from MED file. med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); @@ -1274,7 +1310,7 @@ MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const coords->decrRef(); // DataArrayInt *connArr,*connIndexArr; - tradMEDFileCoreFrmt2MEDCouplingUMesh(conn,connArr,connIndexArr,ids); + tradMEDFileCoreFrmt2MEDCouplingUMesh(conn,ids,connArr,connIndexArr,cellRenum); ret->setConnectivity(connArr,connIndexArr); //clean-up if(connArr) @@ -1285,23 +1321,14 @@ MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const return ret; } -ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order, - ParaMEDMEM::TypeOfField typeOfOutField) +ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char *fileName, ParaMEDMEM::TypeOfField typeOfOutField, unsigned meshDim, const int *cellRenum, const ParaMEDMEM::MEDCouplingUMesh *mesh, + const std::vector& infos, const char *fieldName, int iteration, int order, double time, + std::list& fieldPerCellType) { - std::list fieldPerCellType; - double time; - std::vector infos; - readFieldDoubleDataInMedFile(fileName,meshName,fieldName,iteration,order,typeOfOutField,fieldPerCellType,time,infos); - std::vector familiesToKeep; - std::vector typesToKeep; - if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE) - 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 || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE) MEDLoaderNS::keepSpecifiedMeshDim(fieldPerCellType,meshDim); //for profiles + ParaMEDMEM::MEDCouplingUMesh *newMesh=0; for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) { const std::vector& cellIds=(*iter).getCellIdPerType(); @@ -1309,24 +1336,59 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char { std::vector ci(cellIds.size()); std::transform(cellIds.begin(),cellIds.end(),ci.begin(),std::bind2nd(std::plus(),-1)); - ParaMEDMEM::MEDCouplingUMesh *mesh2=mesh->keepSpecifiedCells((*iter).getType(),ci); - mesh->decrRef(); - mesh=mesh2; + ParaMEDMEM::MEDCouplingUMesh *mesh2; + if(newMesh) + mesh2=newMesh->keepSpecifiedCells((*iter).getType(),ci); + else + mesh2=mesh->keepSpecifiedCells((*iter).getType(),ci); + if(newMesh) + newMesh->decrRef(); + newMesh=mesh2; } } // ParaMEDMEM::MEDCouplingFieldDouble *ret=ParaMEDMEM::MEDCouplingFieldDouble::New(typeOfOutField,ONE_TIME); ret->setName(fieldName); ret->setTime(time,iteration,order); - ret->setMesh(mesh); - mesh->decrRef(); + if(newMesh) + { + ret->setMesh(newMesh); + newMesh->decrRef(); + } + else + ret->setMesh(mesh); ParaMEDMEM::DataArrayDouble *arr=buildArrayFromRawData(fieldPerCellType,infos); ret->setArray(arr); arr->decrRef(); // if(typeOfOutField==ON_GAUSS_PT) fillGaussDataOnField(fileName,fieldPerCellType,ret); - // + if(cellRenum) + ret->renumberCellsWithoutMesh(cellRenum,true); + 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; + std::vector infos; + readFieldDoubleDataInMedFile(fileName,meshName,fieldName,iteration,order,typeOfOutField,fieldPerCellType,time,infos); + std::vector familiesToKeep; + std::vector typesToKeep; + if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE) + for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) + typesToKeep.push_back((*iter).getType()); + unsigned meshDim; + int *cellRenum; + ParaMEDMEM::MEDCouplingUMesh *mesh=readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum); + ParaMEDMEM::MEDCouplingFieldDouble *ret=readFieldDoubleLev2(fileName,typeOfOutField,meshDim,cellRenum,mesh,infos,fieldName,iteration,order,time,fieldPerCellType); + if(cellRenum) + mesh->renumberCells(cellRenum,true); + mesh->decrRef(); + //clean-up + delete [] cellRenum; releaseMEDFileCoreFrmt(fieldPerCellType); return ret; } @@ -1336,7 +1398,14 @@ MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, const char std::vector familiesToKeep; std::vector typesToKeep; unsigned meshDim; - return MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); + int *cellRenum; + ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum); + if(cellRenum) + { + ret->renumberCells(cellRenum,true); + delete [] cellRenum; + } + return ret; } ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception) @@ -1344,38 +1413,57 @@ ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, std::vector familiesToKeep; std::vector typesToKeep; unsigned meshDim; - return MEDLoaderNS::readUMeshFromFileLev1(fileName,0,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); + int *cellRenum; + ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,0,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum); + if(cellRenum) + { + ret->renumberCells(cellRenum,true); + delete [] cellRenum; + } + return ret; } -int MEDLoader::ReadUMeshDimFromFile(const char *fileName, const char *meshName) +int MEDLoader::ReadUMeshDimFromFile(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) { std::vector poss; return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss); } -ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams) +ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams) throw(INTERP_KERNEL::Exception) { std::vector familiesToKeep=MEDLoaderNS::getIdsFromFamilies(fileName,meshName,fams); std::vector typesToKeep; unsigned meshDim; - ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,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) + { + ret->renumberCells(cellRenum,true); + delete [] cellRenum; + } return ret; } -ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps) +ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps) throw(INTERP_KERNEL::Exception) { std::vector familiesToKeep=MEDLoaderNS::getIdsFromGroups(fileName,meshName,grps); std::vector typesToKeep; unsigned meshDim; - ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,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) + { + ret->renumberCells(cellRenum,true); + delete [] cellRenum; + } return ret; } -ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDouble(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) +ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDouble(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) { switch(type) { @@ -1392,27 +1480,99 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDouble(ParaMEDMEM::TypeO } } -ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) +std::vector MEDLoader::ReadFieldsDoubleOnSameMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, + const std::vector >& its) throw(INTERP_KERNEL::Exception) +{ + std::vector ret(its.size()); + if(its.empty()) + return ret; + //Retrieving mesh of rank 0 and field on rank 0 too. + std::list fieldPerCellType; + double time; + std::vector infos; + MEDLoaderNS::readFieldDoubleDataInMedFile(fileName,meshName,fieldName,its[0].first,its[0].second,type,fieldPerCellType,time,infos); + std::vector familiesToKeep; + std::vector typesToKeep; + if(type==ON_CELLS || type==ON_GAUSS_PT || type==ON_GAUSS_NE) + for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) + typesToKeep.push_back((*iter).getType()); + unsigned meshDim; + int *cellRenum; + ParaMEDMEM::MEDCouplingUMesh *m1=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum); + ret[0]=MEDLoaderNS::readFieldDoubleLev2(fileName,type,meshDim,cellRenum,m1,infos,fieldName,its[0].first,its[0].second,time,fieldPerCellType); + if(cellRenum) + m1->renumberCells(cellRenum,true); + MEDLoaderNS::releaseMEDFileCoreFrmt(fieldPerCellType); + // + for(int itId=1;itId fieldPerCellType; + double time; + std::vector infos; + MEDLoaderNS::readFieldDoubleDataInMedFile(fileName,meshName,fieldName,its[itId].first,its[itId].second,type,fieldPerCellType,time,infos); + std::vector familiesToKeep; + std::vector typesToKeep; + if(type==ON_CELLS || type==ON_GAUSS_PT || type==ON_GAUSS_NE) + for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) + typesToKeep.push_back((*iter).getType()); + ret[itId]=MEDLoaderNS::readFieldDoubleLev2(fileName,type,meshDim,cellRenum,m1,infos,fieldName,its[itId].first,its[itId].second,time,fieldPerCellType); + //clean-up + MEDLoaderNS::releaseMEDFileCoreFrmt(fieldPerCellType); + } + m1->decrRef(); + delete [] cellRenum; + return ret; +} + +std::vector MEDLoader::ReadFieldsDoubleCellOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, + const std::vector >& its) throw(INTERP_KERNEL::Exception) +{ + return ReadFieldsDoubleOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its); +} + +std::vector MEDLoader::ReadFieldsDoubleNodeOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, + const std::vector >& its) throw(INTERP_KERNEL::Exception) +{ + return ReadFieldsDoubleOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its); +} + +std::vector MEDLoader::ReadFieldsDoubleGaussOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, + const std::vector >& its) throw(INTERP_KERNEL::Exception) +{ + return ReadFieldsDoubleOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its); +} + +std::vector MEDLoader::ReadFieldsDoubleGaussNEOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, + const std::vector >& its) throw(INTERP_KERNEL::Exception) +{ + return ReadFieldsDoubleOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its); +} + +ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) { 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) +ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) { return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_NODES); } -ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) +ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) { return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_GAUSS_PT); } -ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) +ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) { return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_GAUSS_NE); } -void MEDLoaderNS::writeUMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, const DataArrayInt *families, bool forceFromScratch) +/*! + * @param families input parameter that specifies the field on int on each cells of 'mesh'. + * @param isRenumbering output parameter that specifies if a renumbering of mesh has been needed. + */ +void MEDLoaderNS::writeUMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, const DataArrayInt *families, bool forceFromScratch, bool &isRenumbering) { med_idt fid=MEDouvrir((char *)fileName,forceFromScratch?MED_CREATION:MED_LECTURE_ECRITURE); std::string meshName(mesh->getName()); @@ -1421,6 +1581,7 @@ void MEDLoaderNS::writeUMeshDirectly(const char *fileName, const ParaMEDMEM::MED MEDfermer(fid); throw INTERP_KERNEL::Exception("MEDCouplingMesh must have a not null name !"); } + isRenumbering=!mesh->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); char *maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); char *desc=MEDLoaderBase::buildEmptyString(MED_TAILLE_DESC); MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_TAILLE_NOM,maa,MEDLoader::_TOO_LONG_STR); @@ -1429,8 +1590,8 @@ void MEDLoaderNS::writeUMeshDirectly(const char *fileName, const ParaMEDMEM::MED MEDmaaCr(fid,maa,spaceDim,MED_NON_STRUCTURE,desc); MEDdimEspaceCr(fid,maa,spaceDim); std::set allTypes(mesh->getAllTypes()); - DataArrayInt *conn=mesh->getNodalConnectivity(); - DataArrayInt *connIndex=mesh->getNodalConnectivityIndex(); + const DataArrayInt *conn=mesh->getNodalConnectivity(); + const DataArrayInt *connIndex=mesh->getNodalConnectivityIndex(); char familyName[MED_TAILLE_NOM+1]; std::fill(familyName,familyName+MED_TAILLE_NOM+1,'\0'); const char DftFamilyName[]="DftFamily"; @@ -1445,7 +1606,8 @@ void MEDLoaderNS::writeUMeshDirectly(const char *fileName, const ParaMEDMEM::MED std::vector medConnIndex; std::vector medConnIndex2; std::vector fam; - int nbOfElt=MEDLoaderNS::buildMEDSubConnectivityOfOneType(conn,connIndex,families,curType,medConn,medConnIndex,medConnIndex2,fam); + std::vector renumber; + int nbOfElt=MEDLoaderNS::buildMEDSubConnectivityOfOneType(conn,connIndex,families,curType,medConn,medConnIndex,medConnIndex2,fam,renumber); if(curMedType!=MED_POLYGONE && curMedType!=MED_POLYEDRE) MEDconnEcr(fid,maa,mesh->getMeshDimension(),&medConn[0],MED_FULL_INTERLACE,nbOfElt,MED_MAILLE,curMedType,MED_NOD); else @@ -1460,6 +1622,8 @@ void MEDLoaderNS::writeUMeshDirectly(const char *fileName, const ParaMEDMEM::MED } if(families) MEDfamEcr(fid,maa,&fam[0],nbOfElt,MED_MAILLE,curMedType); + if(isRenumbering) + MEDnumEcr(fid,maa,&renumber[0],nbOfElt,MED_MAILLE,curMedType); } } MEDfamCr(fid,maa,familyName,0,0,0,0,0,0,0); @@ -1501,7 +1665,8 @@ void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const char *meshNam DataArrayInt *arr2=DataArrayInt::makePartition(corr,m->getNumberOfCells(),fidsOfGroups); for(std::vector< DataArrayInt * >::iterator it=corr.begin();it!=corr.end();it++) (*it)->decrRef(); - writeUMeshDirectly(fileName,m,arr2,forceFromScratch); + bool isRenumbering; + writeUMeshDirectly(fileName,m,arr2,forceFromScratch,isRenumbering); // families creation std::set familyIds; for(std::vector< std::vector >::const_iterator it1=fidsOfGroups.begin();it1!=fidsOfGroups.end();it1++) @@ -1624,10 +1789,26 @@ med_idt MEDLoaderNS::appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM return fid; } -void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) +void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f2) { med_int numdt,numo; med_float dt; + //renumbering + const ParaMEDMEM::MEDCouplingFieldDouble *f=f2; + const MEDCouplingMesh *mesh=f->getMesh(); + const MEDCouplingUMesh *meshC=dynamic_cast(mesh); + if(!meshC) + throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !"); + bool renum=!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); + if(renum) + { + ParaMEDMEM::MEDCouplingFieldDouble *f3=f2->clone(true); + DataArrayInt *da=meshC->getRenumArrForConsctvCellTypesSpe(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); + f3->renumberCells(da->getConstPointer(),false); + da->decrRef(); + f=f3; + } + //end renumbering int nbComp=f->getNumberOfComponents(); med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); const double *pt=f->getArray()->getConstPointer(); @@ -1700,6 +1881,8 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::ME } delete [] nommaa; MEDfermer(fid); + if(renum) + ((ParaMEDMEM::MEDCouplingFieldDouble *)f)->decrRef(); } /*! @@ -1713,7 +1896,7 @@ void MEDLoaderNS::prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCoupling const MEDCouplingUMesh *meshC=dynamic_cast(mesh); if(!meshC) throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !"); - if(!meshC->checkConsecutiveCellTypes()) + if(!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2)) throw INTERP_KERNEL::Exception("Unstructuded mesh has not consecutive cell types !"); const int *connI=meshC->getNodalConnectivityIndex()->getConstPointer(); const int *conn=meshC->getNodalConnectivity()->getConstPointer(); @@ -1737,6 +1920,7 @@ void MEDLoaderNS::prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCoupling void MEDLoaderNS::writeFieldAndMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch) { + f->checkCoherency(); std::string meshName(f->getMesh()->getName()); if(meshName.empty()) throw INTERP_KERNEL::Exception("Trying to write a mesh (f->getMesh()) with no name ! MED file format needs a not empty mesh name !"); @@ -1744,8 +1928,24 @@ void MEDLoaderNS::writeFieldAndMeshDirectly(const char *fileName, const ParaMEDM if(fieldName.empty()) throw INTERP_KERNEL::Exception("Trying to write a field with no name ! MED file format needs a not empty field name !"); MEDCouplingUMesh *mesh=dynamic_cast((MEDCouplingMesh *)f->getMesh()); - writeUMeshDirectly(fileName,mesh,0,forceFromScratch); - appendFieldDirectly(fileName,f); + if(mesh) + { + bool isRenumbering; + writeUMeshDirectly(fileName,mesh,0,forceFromScratch,isRenumbering); + if(isRenumbering) + { + ParaMEDMEM::MEDCouplingFieldDouble *f2=f->clone(true); + DataArrayInt *da=mesh->getRenumArrForConsctvCellTypesSpe(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2); + f2->renumberCells(da->getConstPointer(),false); + da->decrRef(); + appendFieldDirectly(fileName,f2); + f2->decrRef(); + } + else + appendFieldDirectly(fileName,f); + return ; + } + throw INTERP_KERNEL::Exception("The mesh underlying field is not unstructured ! Only unstructured mesh supported for writting now !"); } /*! @@ -1819,12 +2019,13 @@ void MEDLoaderNS::writeFieldTryingToFitExistingMesh(const char *fileName, const m->decrRef(); } -void MEDLoader::WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) +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 !"; @@ -1832,19 +2033,19 @@ void MEDLoader::WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUM } if(writeFromScratch) { - MEDLoaderNS::writeUMeshDirectly(fileName,mesh,0,true); + MEDLoaderNS::writeUMeshDirectly(fileName,mesh,0,true,isRenumbering); return ; } if(status==MEDLoaderBase::NOT_EXIST) { - MEDLoaderNS::writeUMeshDirectly(fileName,mesh,0,true); + MEDLoaderNS::writeUMeshDirectly(fileName,mesh,0,true,isRenumbering); return; } else { std::vector meshNames=GetMeshNames(fileName); if(std::find(meshNames.begin(),meshNames.end(),meshName)==meshNames.end()) - MEDLoaderNS::writeUMeshDirectly(fileName,mesh,0,false); + MEDLoaderNS::writeUMeshDirectly(fileName,mesh,0,false,isRenumbering); else { std::ostringstream oss; oss << "File \'" << fileName << "\' already exists and has already a mesh called \""; @@ -1854,7 +2055,7 @@ void MEDLoader::WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUM } } -void MEDLoader::WriteUMeshes(const char *fileName, const char *meshNameC, const std::vector& meshes, bool writeFromScratch) +void MEDLoader::WriteUMeshes(const char *fileName, const char *meshNameC, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception) { std::string meshName(meshNameC); if(meshName.empty()) @@ -1904,7 +2105,7 @@ void MEDLoader::WriteUMeshes(const char *fileName, const char *meshNameC, const } } -void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) +void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception) { int status=MEDLoaderBase::getStatusOfFile(fileName); if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST) @@ -1936,7 +2137,7 @@ void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFi } } -void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) +void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception) { f->checkCoherency(); int status=MEDLoaderBase::getStatusOfFile(fileName); diff --git a/src/MEDLoader/MEDLoader.hxx b/src/MEDLoader/MEDLoader.hxx index f1992d788..8ff9cad17 100644 --- a/src/MEDLoader/MEDLoader.hxx +++ b/src/MEDLoader/MEDLoader.hxx @@ -49,6 +49,7 @@ class MEDLOADER_EXPORT MEDLoader int *getIndex() const { return _index; } int *getFam() const { return _fam; } void setGlobal(int *global); + const int *getGlobal() const { return _global; } void releaseArray(); private: int _lgth; @@ -81,31 +82,41 @@ class MEDLOADER_EXPORT MEDLoader INTERP_KERNEL::NormalizedCellType _type; }; // - static void setEpsilonForNodeComp(double val); - static void setCompPolicyForCell(int val); - static void setTooLongStrPolicy(int val); - 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 > GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName); - static std::vector< std::pair > GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName); - static std::vector< std::pair > GetNodeFieldIterations(const char *fileName, const char *meshName, 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 void setEpsilonForNodeComp(double val) throw(INTERP_KERNEL::Exception); + static void setCompPolicyForCell(int val) throw(INTERP_KERNEL::Exception); + static void setTooLongStrPolicy(int val) throw(INTERP_KERNEL::Exception); + static std::vector GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception); + static std::vector GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetMeshFamilyNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector< std::pair > GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); + static std::vector< std::pair > GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); + static std::vector< std::pair > GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); - static int ReadUMeshDimFromFile(const char *fileName, const char *meshName); - static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDouble(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); - 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 ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); - static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); - static void WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch); - static void WriteUMeshes(const char *fileName, const char *meshName, const std::vector& meshes, bool writeFromScratch); - static void WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch); - static void WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f); + static int ReadUMeshDimFromFile(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDouble(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + static std::vector ReadFieldsDoubleOnSameMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, + const std::vector >& its) throw(INTERP_KERNEL::Exception); + static std::vector ReadFieldsDoubleCellOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, + const std::vector >& its) throw(INTERP_KERNEL::Exception); + static std::vector ReadFieldsDoubleNodeOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, + const std::vector >& its) throw(INTERP_KERNEL::Exception); + static std::vector ReadFieldsDoubleGaussOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, + const std::vector >& its) throw(INTERP_KERNEL::Exception); + static std::vector ReadFieldsDoubleGaussNEOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, + const std::vector >& its) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + static void WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception); + static void WriteUMeshes(const char *fileName, const char *meshName, const std::vector& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception); + static void WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception); + static void WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception); private: MEDLoader(); public: diff --git a/src/MEDLoader/Swig/libMEDLoader_Swig.i b/src/MEDLoader/Swig/libMEDLoader_Swig.i index ad3b08d1d..c4aae1cb7 100644 --- a/src/MEDLoader/Swig/libMEDLoader_Swig.i +++ b/src/MEDLoader/Swig/libMEDLoader_Swig.i @@ -19,20 +19,22 @@ %module libMEDLoader_Swig -%include std_vector.i -%include std_string.i +#define MEDCOUPLING_EXPORT +#define MEDLOADER_EXPORT -%include "MEDCouplingTypemaps.i" %include "libMEDCoupling_Swig.i" %{ #include "MEDLoader.hxx" +#include "MEDLoaderTypemaps.i" %} #if SWIG_VERSION >= 0x010329 %template() std::vector; #endif +%newobject MEDLoader::ReadUMeshFromFamilies; +%newobject MEDLoader::ReadUMeshFromGroups; %newobject MEDLoader::ReadUMeshFromFile; %newobject MEDLoader::ReadFieldDouble; %newobject MEDLoader::ReadFieldDoubleCell; @@ -43,17 +45,17 @@ class MEDLoader { public: - static void setEpsilonForNodeComp(double val); - static void setCompPolicyForCell(int val); - static void setTooLongStrPolicy(int val); - 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 void setEpsilonForNodeComp(double val) throw(INTERP_KERNEL::Exception); + static void setCompPolicyForCell(int val) throw(INTERP_KERNEL::Exception); + static void setTooLongStrPolicy(int val) throw(INTERP_KERNEL::Exception); + static std::vector GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception); + static std::vector GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetMeshFamilyNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); + static std::vector GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception); %extend { - static PyObject *GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) + static PyObject *GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) { std::vector< std::pair > res=MEDLoader::GetFieldIterations(type,fileName,meshName,fieldName); PyObject *ret=PyList_New(res.size()); @@ -68,7 +70,7 @@ public: return ret; } - static PyObject *GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) + static PyObject *GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) { std::vector< std::pair > res=MEDLoader::GetCellFieldIterations(fileName,meshName,fieldName); PyObject *ret=PyList_New(res.size()); @@ -82,7 +84,7 @@ public: } return ret; } - static PyObject *GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) + static PyObject *GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) { std::vector< std::pair > res=MEDLoader::GetNodeFieldIterations(fileName,meshName,fieldName); PyObject *ret=PyList_New(res.size()); @@ -96,15 +98,29 @@ public: } return ret; } + static PyObject *ReadFieldsDoubleOnSameMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, + const char *fieldName, PyObject *liIts) throw(INTERP_KERNEL::Exception) + { + std::vector > its=convertTimePairIdsFromPy(liIts); + std::vector res=MEDLoader::ReadFieldsDoubleOnSameMesh(type,fileName,meshName,meshDimRelToMax,fieldName,its); + return convertFieldDoubleVecToPy(res); + } + static void WriteUMeshes(const char *fileName, const char *meshName, PyObject *li, bool writeFromScratch) throw(INTERP_KERNEL::Exception) + { + std::vector v=convertFieldDoubleVecFromPy(li); + MEDLoader::WriteUMeshes(fileName,meshName,v,writeFromScratch); + } } + static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception); - static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDouble(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); - 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 ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); - static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); - static void WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch); - static void WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch); - static void WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDouble(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + static void WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception); + static void WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception); + static void WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception); }; diff --git a/src/MEDLoader/Test/MEDLoaderTest.cxx b/src/MEDLoader/Test/MEDLoaderTest.cxx index 170b36063..7814638f5 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.cxx +++ b/src/MEDLoader/Test/MEDLoaderTest.cxx @@ -24,6 +24,8 @@ #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingMemArray.hxx" +#include + using namespace ParaMEDMEM; void MEDLoaderTest::testMesh1DRW() @@ -284,7 +286,7 @@ void MEDLoaderTest::testMultiMeshRW1() // MEDCouplingUMesh *mesh5=MEDLoader::ReadUMeshFromFile(fileName,mnane); mesh1->setName(mnane); - const int part3[18]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18}; + const int part3[18]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17}; MEDCouplingUMesh *mesh6=(MEDCouplingUMesh *)mesh5->buildPartOfMySelf(part3,part3+18,true); mesh6->setName(mnane); mesh5->decrRef(); @@ -396,6 +398,100 @@ void MEDLoaderTest::testLittleStrings1() CPPUNIT_ASSERT(s=="azertty"); } +void MEDLoaderTest::testMesh3DSurfShuffleRW() +{ + const char fileName[]="file15.med"; + MEDCouplingUMesh *mesh=build3DSurfMesh_1(); + const int renumber1[6]={2,5,1,0,3,4}; + mesh->renumberCells(renumber1,false); + mesh->checkCoherency(); + MEDLoader::WriteUMesh(fileName,mesh,true); + MEDCouplingUMesh *mesh_rw=MEDLoader::ReadUMeshFromFile(fileName,mesh->getName(),0); + CPPUNIT_ASSERT(mesh->isEqual(mesh_rw,1e-12)); + mesh_rw->decrRef(); + mesh->decrRef(); +} + +void MEDLoaderTest::testFieldShuffleRW1() +{ + const char fileName[]="file16.med"; + MEDCouplingUMesh *mesh=build3DSurfMesh_1(); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); + f1->setName("FieldOnCellsShuffle"); + f1->setMesh(mesh); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(6,2); + f1->setArray(array); + array->decrRef(); + double *tmp=array->getPointer(); + const double arr1[12]={71.,171.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.}; + std::copy(arr1,arr1+12,tmp); + f1->setTime(3.14,2,7); + f1->checkCoherency(); + // + const int renumber1[6]={2,1,5,0,3,4}; + f1->renumberCells(renumber1,false); + MEDLoader::WriteField(fileName,f1,true); + MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldDoubleCell(fileName,mesh->getName(),0,f1->getName(),2,7); + CPPUNIT_ASSERT(f2->isEqual(f1,1e-12,1e-12)); + f2->decrRef(); + // + mesh->decrRef(); + f1->decrRef(); +} + +void MEDLoaderTest::testMultiFieldShuffleRW1() +{ + const char fileName[]="file17.med"; + MEDCouplingUMesh *m=build3DMesh_2(); + CPPUNIT_ASSERT_EQUAL(20,m->getNumberOfCells()); + CPPUNIT_ASSERT_EQUAL(45,m->getNumberOfNodes()); + const int polys[3]={1,4,6}; + std::vector poly2(polys,polys+3); + m->convertToPolyTypes(poly2); + const int renum[20]={1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11}; + m->renumberCells(renum,false); + m->orientCorrectlyPolyhedrons(); + // Writing + MEDLoader::WriteUMesh(fileName,m,true); + MEDCouplingFieldDouble *f1Tmp=m->getMeasureField(false); + MEDCouplingFieldDouble *f1=f1Tmp->buildNewTimeReprFromThis(ONE_TIME,false); + f1Tmp->decrRef(); + f1->setTime(0.,1,2); + MEDCouplingFieldDouble *f_1=f1->cloneWithMesh(true); + MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + f1->applyFunc("2*x"); + f1->setTime(0.01,3,4); + MEDCouplingFieldDouble *f_2=f1->cloneWithMesh(true); + MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + f1->applyFunc("2*x/3"); + f1->setTime(0.02,5,6); + MEDCouplingFieldDouble *f_3=f1->cloneWithMesh(true); + MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1); + f1->decrRef(); + // Reading + std::vector > its; + its.push_back(std::pair(1,2)); + its.push_back(std::pair(3,4)); + its.push_back(std::pair(5,6)); + std::vector fs=MEDLoader::ReadFieldsDoubleOnSameMesh(ON_CELLS,fileName,f_1->getMesh()->getName(),0,f_1->getName(),its); + CPPUNIT_ASSERT_EQUAL(3,(int)fs.size()); + const MEDCouplingMesh *mm=fs[0]->getMesh(); + CPPUNIT_ASSERT(fs[0]->isEqual(f_1,1e-12,1e-12)); + CPPUNIT_ASSERT(fs[1]->isEqual(f_2,1e-12,1e-12)); + CPPUNIT_ASSERT(fs[2]->isEqual(f_3,1e-12,1e-12)); + CPPUNIT_ASSERT(mm==fs[1]->getMesh());// <- important for the test + CPPUNIT_ASSERT(mm==fs[2]->getMesh());// <- important for the test + for(std::vector::iterator iter=fs.begin();iter!=fs.end();iter++) + (*iter)->decrRef(); + // + f_1->decrRef(); + f_2->decrRef(); + f_3->decrRef(); + // + m->decrRef(); +} + MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1() { double coords[6]={ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 }; @@ -466,7 +562,10 @@ MEDCouplingUMesh *MEDLoaderTest::build2DMesh_1() MEDCouplingUMesh *MEDLoaderTest::build2DMesh_2() { - double targetCoords[24]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + double targetCoords[24]={ + -0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7, + -0.05,0.95, 0.2,1.2, 0.45,0.95 + }; int targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4}; MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New(); targetMesh->setMeshDimension(2); @@ -490,7 +589,10 @@ MEDCouplingUMesh *MEDLoaderTest::build2DMesh_2() MEDCouplingUMesh *MEDLoaderTest::build3DSurfMesh_1() { - double targetCoords[36]={-0.3,-0.3,-0.3, 0.2,-0.3,-0.3, 0.7,-0.3,-0.3, -0.3,0.2,-0.3, 0.2,0.2,-0.3, 0.7,0.2,-0.3, -0.3,0.7,-0.3, 0.2,0.7,-0.3, 0.7,0.7,-0.3 }; + double targetCoords[36]={ + -0.3,-0.3,-0.3, 0.2,-0.3,-0.3, 0.7,-0.3,-0.3, -0.3,0.2,-0.3, 0.2,0.2,-0.3, 0.7,0.2,-0.3, -0.3,0.7,-0.3, 0.2,0.7,-0.3, 0.7,0.7,-0.3 + ,-0.05,0.95,-0.3, 0.2,1.2,-0.3, 0.45,0.95,-0.3 + }; int targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4}; MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New(); targetMesh->setMeshDimension(2); @@ -582,6 +684,26 @@ MEDCouplingUMesh *MEDLoaderTest::build3DMesh_1() return ret; } +MEDCouplingUMesh *MEDLoaderTest::build3DMesh_2() +{ + MEDCouplingUMesh *m3dsurfBase=build3DSurfMesh_1(); + int numbers[5]={0,1,3,4,5}; + MEDCouplingUMesh *m3dsurf=(MEDCouplingUMesh *)m3dsurfBase->buildPartOfMySelf(numbers,numbers+5,false); + m3dsurfBase->decrRef(); + MEDCouplingUMesh *m1dBase=build1DMesh_1(); + int numbers2[4]={0,1,2,3}; + MEDCouplingUMesh *m1d=(MEDCouplingUMesh *)m1dBase->buildPartOfMySelf(numbers2,numbers2+4,false); + m1dBase->decrRef(); + m1d->changeSpaceDimension(3); + const double vec[3]={0.,1.,0.}; + const double pt[3]={0.,0.,0.}; + m1d->rotate(pt,vec,-M_PI/2.); + MEDCouplingUMesh *ret=m3dsurf->buildExtrudedMeshFromThis(m1d,0); + m1d->decrRef(); + m3dsurf->decrRef(); + return ret; +} + MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnCells_1() { MEDCouplingUMesh *mesh=build3DSurfMesh_1(); @@ -692,3 +814,4 @@ MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGaussNE_1() m->decrRef(); return f; } + diff --git a/src/MEDLoader/Test/MEDLoaderTest.hxx b/src/MEDLoader/Test/MEDLoaderTest.hxx index 11cc57d2b..d8d50c2dd 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.hxx +++ b/src/MEDLoader/Test/MEDLoaderTest.hxx @@ -43,6 +43,9 @@ namespace ParaMEDMEM CPPUNIT_TEST( testFieldGaussRW1 ); CPPUNIT_TEST( testFieldGaussNERW1 ); CPPUNIT_TEST( testLittleStrings1 ); + CPPUNIT_TEST( testMesh3DSurfShuffleRW ); + CPPUNIT_TEST( testFieldShuffleRW1 ); + CPPUNIT_TEST( testMultiFieldShuffleRW1 ); CPPUNIT_TEST_SUITE_END(); public: void testMesh1DRW(); @@ -58,6 +61,9 @@ namespace ParaMEDMEM void testFieldGaussRW1(); void testFieldGaussNERW1(); void testLittleStrings1(); + void testMesh3DSurfShuffleRW(); + void testFieldShuffleRW1(); + void testMultiFieldShuffleRW1(); private: MEDCouplingUMesh *build1DMesh_1(); MEDCouplingUMesh *build2DCurveMesh_1(); @@ -65,6 +71,7 @@ namespace ParaMEDMEM MEDCouplingUMesh *build2DMesh_2(); MEDCouplingUMesh *build3DSurfMesh_1(); MEDCouplingUMesh *build3DMesh_1(); + MEDCouplingUMesh *build3DMesh_2(); MEDCouplingFieldDouble *buildVecFieldOnCells_1(); MEDCouplingFieldDouble *buildVecFieldOnNodes_1(); MEDCouplingFieldDouble *buildVecFieldOnGauss_1();