From 70f7808ecb2b13dd19096d4d6a527c24841db38c Mon Sep 17 00:00:00 2001 From: imn Date: Fri, 22 May 2015 19:55:47 +0300 Subject: [PATCH] Added read/write MEDFileData in MeshCollectionDriver --- .../MEDPARTITIONER_MEDPartitioner.cxx | 85 +----- .../MEDPARTITIONER_MEDPartitioner.hxx | 1 - .../MEDPARTITIONER_MeshCollection.cxx | 98 +------ .../MEDPARTITIONER_MeshCollectionDriver.cxx | 275 ++++++++---------- .../MEDPARTITIONER_MeshCollectionDriver.hxx | 17 +- ...RTITIONER_MeshCollectionMedAsciiDriver.cxx | 37 ++- ...RTITIONER_MeshCollectionMedAsciiDriver.hxx | 3 +- 7 files changed, 183 insertions(+), 333 deletions(-) diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx index d032530a6..ff0bb1944 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx @@ -26,6 +26,7 @@ #include "MEDPARTITIONER_Graph.hxx" #include "MEDPARTITIONER_MetisGraph.hxx" #include "MEDPARTITIONER_ScotchGraph.hxx" +#include "MEDPARTITIONER_MeshCollectionDriver.hxx" #include "MEDCouplingUMesh.hxx" #include @@ -52,71 +53,7 @@ MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const std::string& filename, int MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory) { _input_collection=new MeshCollection(); - std::vector cz; // to fill from filedata - - for (int i=0; igetMeshes()->getNumberOfMeshes(); i++) - { - ParaMEDMEM::MEDFileUMesh *mfm = dynamic_cast(filedata->getMeshes()->getMeshAtPos(i)); - std::vector nonEmpty=mfm->getNonEmptyLevels(); - try - { - (_input_collection->getMesh()).push_back(mfm->getLevel0Mesh(false)); - //reading families groups - ParaMEDMEM::DataArrayInt* cellIds(mfm->getFamilyFieldAtLevel(0)->deepCpy()); - (_input_collection->getCellFamilyIds()).push_back(cellIds); - } - catch(...) - { - (_input_collection->getMesh()).push_back(CreateEmptyMEDCouplingUMesh()); // or 0 if you want tests; - ParaMEDMEM::DataArrayInt* empty=ParaMEDMEM::DataArrayInt::New(); - empty->alloc(0,1); - (_input_collection->getCellFamilyIds()).push_back(empty); - } - try - { - if (nonEmpty.size()>1 && nonEmpty[1]==-1) - { - (_input_collection->getFaceMesh()).push_back(mfm->getLevelM1Mesh(false)); - //reading families groups - ParaMEDMEM::DataArrayInt* faceIds(mfm->getFamilyFieldAtLevel(-1)->deepCpy()); - (_input_collection->getFaceFamilyIds()).push_back(faceIds); - } - else - { - throw INTERP_KERNEL::Exception("no faces"); - } - } - catch(...) - { - (_input_collection->getFaceMesh()).push_back(CreateEmptyMEDCouplingUMesh()); // or 0 if you want test; - ParaMEDMEM::DataArrayInt* empty=ParaMEDMEM::DataArrayInt::New(); - (_input_collection->getFaceFamilyIds()).push_back(empty); - } - //reading groups - _input_collection->getFamilyInfo()=mfm->getFamilyInfo(); - _input_collection->getGroupInfo()=mfm->getGroupInfo(); - mfm->decrRef(); - } - std::vector cellglobal; - std::vector nodeglobal; - std::vector faceglobal; - int size = (_input_collection->getMesh()).size(); - cellglobal.resize(size); - nodeglobal.resize(size); - faceglobal.resize(size); - - for ( int idomain = 0; idomain < size; ++idomain ) - { - cellglobal[idomain]=0; - faceglobal[idomain]=0; - nodeglobal[idomain]=0; - if ( (_input_collection->getMesh())[idomain] && (_input_collection->getMesh())[idomain]->getNumberOfNodes() > 0 ) - _input_collection->setNonEmptyMesh(idomain); - } - - ParallelTopology* aPT = new ParallelTopology((_input_collection->getMesh()), cz, cellglobal, nodeglobal, faceglobal); - _input_collection->setTopology(aPT); - + _input_collection->getDriver()->readMEDFileData(filedata); createPartitionCollection(ndomains, library, creates_boundary_faces, create_joints, mesure_memory); } @@ -138,23 +75,7 @@ void MEDPARTITIONER::MEDPartitioner::Write(const std::string& filename) ParaMEDMEM::MEDFileData* MEDPARTITIONER::MEDPartitioner::getMEDFileData() { - return convertToMEDFileData(_output_collection); -} - -ParaMEDMEM::MEDFileData* MEDPARTITIONER::MEDPartitioner::convertToMEDFileData(MeshCollection* collection) -{ - ParaMEDMEM::MEDFileData* newdata=ParaMEDMEM::MEDFileData::New(); - for (int i=0; i<(collection->getMesh()).size(); i++) - { - ParaMEDMEM::MEDFileUMesh *mfm = ParaMEDMEM::MEDFileUMesh::New(); - mfm->setMeshAtLevel(0,(collection->getMesh())[i]); - mfm->setMeshAtLevel(-1,(collection->getFaceMesh())[i]); - mfm->setFamilyFieldArr(0,(collection->getCellFamilyIds())[i]); - mfm->setFamilyFieldArr(-1,(collection->getFaceFamilyIds())[i]); - mfm->setFamilyInfo(collection->getFamilyInfo()); - mfm->setGroupInfo(collection->getGroupInfo()); - } - return newdata; + return _output_collection->getDriver()->getMEDFileData(); } MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight) diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx index d696f225c..96e030cca 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx @@ -51,7 +51,6 @@ namespace MEDPARTITIONER private: MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory); MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory); - ParaMEDMEM::MEDFileData *convertToMEDFileData(MeshCollection* meshcollection); void createPartitionCollection(int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory); MeshCollection* _input_collection; MeshCollection* _output_collection; diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx index 3b09c58f4..da9ce71d7 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx @@ -1869,103 +1869,7 @@ void MEDPARTITIONER::MeshCollection::buildCellGraph(ParaMEDMEM::MEDCouplingSkyLi array=new ParaMEDMEM::MEDCouplingSkyLineArray(index,value); return; } - - int meshDim = mesh->getMeshDimension(); - - ParaMEDMEM::DataArrayInt* indexr=ParaMEDMEM::DataArrayInt::New(); - ParaMEDMEM::DataArrayInt* revConn=ParaMEDMEM::DataArrayInt::New(); - int nbNodes=mesh->getNumberOfNodes(); - mesh->getReverseNodalConnectivity(revConn,indexr); - //problem saturation over 1 000 000 nodes for 1 proc - if (MyGlobals::_Verbose>100) - std::cout << "proc " << MyGlobals::_Rank << " : getReverseNodalConnectivity done on " << nbNodes << " nodes" << std::endl; - const int* indexr_ptr=indexr->getConstPointer(); - const int* revConn_ptr=revConn->getConstPointer(); - - const ParaMEDMEM::DataArrayInt* index; - const ParaMEDMEM::DataArrayInt* conn; - conn=mesh->getNodalConnectivity(); - index=mesh->getNodalConnectivityIndex(); - int nbCells=mesh->getNumberOfCells(); - - if (MyGlobals::_Verbose>100) - std::cout << "proc " << MyGlobals::_Rank << " : getNodalConnectivity done on " << nbNodes << " nodes" << std::endl; - const int* index_ptr=index->getConstPointer(); - const int* conn_ptr=conn->getConstPointer(); - - //creating graph arcs (cell to cell relations) - //arcs are stored in terms of (index,value) notation - // 0 3 5 6 6 - // 1 2 3 2 3 3 - // means 6 arcs (0,1), (0,2), (0,3), (1,2), (1,3), (2,3) - // in present version arcs are not doubled but reflexive (1,1) arcs are present for each cell - - //warning here one node have less than or equal effective number of cell with it - //but cell could have more than effective nodes - //because other equals nodes in other domain (with other global inode) - if (MyGlobals::_Verbose>50) - std::cout<< "proc " << MyGlobals::_Rank << " : creating graph arcs on nbNodes " << _topology->nbNodes() << std::endl; - - vector cell2cell_index(nbCells+1,0); - vector cell2cell; - cell2cell.reserve(3*nbCells); - - for (int icell=0; icell counter; - for (int iconn=index_ptr[icell]; iconn::iterator iter=counter.find(icell2); - if (iter!=counter.end()) (iter->second)++; - else counter.insert(make_pair(icell2,1)); - } - } - for (map::const_iterator iter=counter.begin(); - iter!=counter.end(); - iter++) - if (iter->second >= meshDim) - { - cell2cell_index[icell+1]++; - cell2cell.push_back(iter->first); - } - - - } - indexr->decrRef(); - revConn->decrRef(); - - cell2cell_index[0]=0; - for (int icell=0; icell50) - std::cout << "proc " << MyGlobals::_Rank << " : create skylinearray" << std::endl; - - //filling up index and value to create skylinearray structure - array=new ParaMEDMEM::MEDCouplingSkyLineArray(cell2cell_index,cell2cell); - - if (MyGlobals::_Verbose>100) - { - std::cout << "\nproc " << _domain_selector->rank() << " : end MeshCollection::buildCellGraph " << - cell2cell_index.size()-1 << " " << cell2cell.size() << std::endl; - int max=cell2cell_index.size()>15?15:cell2cell_index.size(); - if (cell2cell_index.size()>1) - { - for (int i=0; igenerateGraph(); } /*! Method creating the cell graph in multidomain mode * diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx index 14eceef6f..2e2408266 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx @@ -85,39 +85,44 @@ int MeshCollectionDriver::readSeq(const char* filename, const char* meshname) } -//================================================================================ -/*! - * \brief Return mesh dimension from distributed med file had being read - */ -//================================================================================ - -void MeshCollectionDriver::readSubdomain(std::vector& cellglobal, - std::vector& faceglobal, - std::vector& nodeglobal, int idomain) +void MeshCollectionDriver::readMEDFileData(const ParaMEDMEM::MEDFileData* filedata) { - std::string meshname=MyGlobals::_Mesh_Names[idomain]; - std::string file=MyGlobals::_File_Names[idomain]; + for (int i=0; igetMeshes()->getNumberOfMeshes(); i++) + { + ParaMEDMEM::MEDFileUMesh *mfm = dynamic_cast(filedata->getMeshes()->getMeshAtPos(i)); + readData(mfm,i); + if (i==0) + _collection->setName(filedata->getMeshes()->getMeshAtPos(i)->getName()); + mfm->decrRef(); + } +} +void MeshCollectionDriver::readFileData(std::string file,std::string meshname,int idomain) const +{ ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(file,meshname); + readData(mfm,idomain); + mfm->decrRef(); +} +void MeshCollectionDriver::readData(ParaMEDMEM::MEDFileUMesh* mfm, int idomain) const +{ std::vector nonEmpty=mfm->getNonEmptyLevels(); - - try - { - (_collection->getMesh())[idomain]=mfm->getLevel0Mesh(false); + try + { + (_collection->getMesh())[idomain]=mfm->getLevel0Mesh(false); //reading families groups ParaMEDMEM::DataArrayInt* cellIds(mfm->getFamilyFieldAtLevel(0)->deepCpy()); (_collection->getCellFamilyIds())[idomain]=cellIds; } catch(...) - { + { (_collection->getMesh())[idomain]=CreateEmptyMEDCouplingUMesh(); // or 0 if you want tests; ParaMEDMEM::DataArrayInt* empty=ParaMEDMEM::DataArrayInt::New(); empty->alloc(0,1); (_collection->getCellFamilyIds())[idomain]=empty; - std::cout << "\nNO Level0Mesh (Cells)\n"; + std::cout<<"\nNO Level0Mesh (Cells)\n"; } - try - { + try + { if (nonEmpty.size()>1 && nonEmpty[1]==-1) { (_collection->getFaceMesh())[idomain]=mfm->getLevelM1Mesh(false); @@ -126,7 +131,6 @@ void MeshCollectionDriver::readSubdomain(std::vector& cellglobal, (_collection->getFaceFamilyIds())[idomain]=faceIds; if (MyGlobals::_Verbose>10) std::cout << "proc " << MyGlobals::_Rank << " : WITH Faces\n"; - } else { @@ -141,75 +145,16 @@ void MeshCollectionDriver::readSubdomain(std::vector& cellglobal, if (MyGlobals::_Verbose>10) std::cout << "proc " << MyGlobals::_Rank << " : WITHOUT Faces\n"; } - //reading groups _collection->getFamilyInfo()=mfm->getFamilyInfo(); _collection->getGroupInfo()=mfm->getGroupInfo(); - mfm->decrRef(); - - std::vector localInformation; - std::string str; - localInformation.push_back(str+"ioldDomain="+IntToStr(idomain)); - localInformation.push_back(str+"meshName="+meshname); - MyGlobals::_General_Informations.push_back(SerializeFromVectorOfString(localInformation)); - std::vector localFields=BrowseAllFieldsOnMesh(file, meshname, idomain); - if (localFields.size()>0) - MyGlobals::_Field_Descriptions.push_back(SerializeFromVectorOfString(localFields)); } - void MeshCollectionDriver::readSubdomain(int idomain) { std::string meshname=MyGlobals::_Mesh_Names[idomain]; std::string file=MyGlobals::_File_Names[idomain]; - - ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(file,meshname); - std::vector nonEmpty=mfm->getNonEmptyLevels(); - try - { - (_collection->getMesh())[idomain]=mfm->getLevel0Mesh(false); - //reading families groups - ParaMEDMEM::DataArrayInt* cellIds(mfm->getFamilyFieldAtLevel(0)->deepCpy()); - (_collection->getCellFamilyIds())[idomain]=cellIds; - } - catch(...) - { - (_collection->getMesh())[idomain]=CreateEmptyMEDCouplingUMesh(); // or 0 if you want tests; - ParaMEDMEM::DataArrayInt* empty=ParaMEDMEM::DataArrayInt::New(); - empty->alloc(0,1); - (_collection->getCellFamilyIds())[idomain]=empty; - std::cout<<"\nNO Level0Mesh (Cells)\n"; - } - try - { - if (nonEmpty.size()>1 && nonEmpty[1]==-1) - { - (_collection->getFaceMesh())[idomain]=mfm->getLevelM1Mesh(false); - //reading families groups - ParaMEDMEM::DataArrayInt* faceIds(mfm->getFamilyFieldAtLevel(-1)->deepCpy()); - (_collection->getFaceFamilyIds())[idomain]=faceIds; - if (MyGlobals::_Verbose>10) - std::cout << "proc " << MyGlobals::_Rank << " : WITH Faces\n"; - } - else - { - throw INTERP_KERNEL::Exception("no faces"); - } - } - catch(...) - { - (_collection->getFaceMesh())[idomain]=CreateEmptyMEDCouplingUMesh(); // or 0 if you want test; - ParaMEDMEM::DataArrayInt* empty=ParaMEDMEM::DataArrayInt::New(); - (_collection->getFaceFamilyIds())[idomain]=empty; - if (MyGlobals::_Verbose>10) - std::cout << "proc " << MyGlobals::_Rank << " : WITHOUT Faces\n"; - } - - //reading groups - _collection->getFamilyInfo()=mfm->getFamilyInfo(); - _collection->getGroupInfo()=mfm->getGroupInfo(); - - mfm->decrRef(); + readFileData(file,meshname,idomain); std::vector localInformation; std::string str; @@ -220,15 +165,11 @@ void MeshCollectionDriver::readSubdomain(int idomain) if (localFields.size()>0) MyGlobals::_Field_Descriptions.push_back(SerializeFromVectorOfString(localFields)); } - - -void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfilename) const +std::vector MeshCollectionDriver::getMeshes(int idomain) const { std::vector meshes; ParaMEDMEM::MEDCouplingUMesh* cellMesh=_collection->getMesh(idomain); ParaMEDMEM::MEDCouplingUMesh* faceMesh=_collection->getFaceMesh(idomain); - //ParaMEDMEM::MEDCouplingUMesh* faceMeshFilter=0; - std::string finalMeshName=ExtractFromDescription(MyGlobals::_General_Informations[0], "finalMeshName="); // std::string cleFilter=Cle1ToStr("filterFaceOnCell",idomain); // ParaMEDMEM::DataArrayInt* filter=0; @@ -239,6 +180,8 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile // faceMeshFilter=(ParaMEDMEM::MEDCouplingUMesh *) faceMesh->buildPartOfMySelf(index,index+filter->getNbOfElems(),true); // faceMesh=faceMeshFilter; // } + // if (faceMeshFilter!=0) + // faceMeshFilter->decrRef(); cellMesh->setName(finalMeshName); meshes.push_back(cellMesh); @@ -248,91 +191,71 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile faceMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-10); meshes.push_back(faceMesh); } - - //ParaMEDMEM::MEDCouplingUMesh* boundaryMesh=0; + // ParaMEDMEM::MEDCouplingUMesh* boundaryMesh=0; // if (MyGlobals::_Creates_Boundary_Faces>0) // { // //try to write Boundary meshes // bool keepCoords=false; //TODO or true // boundaryMesh=(ParaMEDMEM::MEDCouplingUMesh *) cellMesh->buildBoundaryMesh(keepCoords); // boundaryMesh->setName("boundaryMesh"); - // } - - MEDLoader::WriteUMeshes(distfilename, meshes, true); - // if (faceMeshFilter!=0) - // faceMeshFilter->decrRef(); - // if (boundaryMesh!=0) // { // //doing that testMesh becomes second mesh sorted by alphabetical order of name // MEDLoader::WriteUMesh(distfilename, boundaryMesh, false); // boundaryMesh->decrRef(); // } - ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(distfilename, _collection->getMesh(idomain)->getName()); - // if (MyGlobals::_Create_Joints) { - // mfm->setJoints( MyGlobals::_File_Names[0]); - // mfm->writeJoints(distfilename,0); - // } + return meshes; +} +void MeshCollectionDriver::setFileUMesh(ParaMEDMEM::MEDFileUMesh* mfm,int size, int idomain) const +{ mfm->setFamilyInfo(_collection->getFamilyInfo()); mfm->setGroupInfo(_collection->getGroupInfo()); - std::string key=Cle1ToStr("faceFamily_toArray",idomain); - if ( meshes.size() == 2 && + if ( size == 2 && _collection->getMapDataArrayInt().find(key)!=_collection->getMapDataArrayInt().end()) { ParaMEDMEM::DataArrayInt *fam=_collection->getMapDataArrayInt().find(key)->second; mfm->setFamilyFieldArr(-1,fam); } - key=Cle1ToStr("cellFamily_toArray",idomain); if (_collection->getMapDataArrayInt().find(key)!=_collection->getMapDataArrayInt().end()) mfm->setFamilyFieldArr(0,_collection->getMapDataArrayInt().find(key)->second); - - mfm->write(distfilename,0); - key="/inewFieldDouble="+IntToStr(idomain)+"/"; - - std::map::iterator it; - int nbfFieldFound=0; - for (it=_collection->getMapDataArrayDouble().begin() ; it!=_collection->getMapDataArrayDouble().end(); it++) +} +ParaMEDMEM::MEDCouplingFieldDouble* MeshCollectionDriver::getField(std::string key, std::string description, ParaMEDMEM::DataArrayDouble* data, ParaMEDMEM::MEDFileUMesh* mfm, int idomain) const +{ + std::string desc=description; + if (MyGlobals::_Verbose>20) + std::cout << "proc " << MyGlobals::_Rank << " : write field " << desc << std::endl; + std::string meshName, fieldName; + int typeField, DT, IT, entity; + FieldShortDescriptionToData(desc, fieldName, typeField, entity, DT, IT); + double time=StrToDouble(ExtractFromDescription(desc, "time=")); + int typeData=StrToInt(ExtractFromDescription(desc, "typeData=")); + std::string entityName=ExtractFromDescription(desc, "entityName="); + ParaMEDMEM::MEDCouplingFieldDouble* field=0; + if (typeData!=6) + { + std::cout << "WARNING : writeMedFile : typeData " << typeData << " not implemented for fields\n"; + } + if (entityName=="MED_CELL") + { + //there is a field of idomain to write + field=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME); + } + if (entityName=="MED_NODE_ELEMENT") + { + //there is a field of idomain to write + field=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_GAUSS_NE,ParaMEDMEM::ONE_TIME); + } + if (!field) + { + std::cout << "WARNING : writeMedFile : entityName " << entityName << " not implemented for fields\n"; + } + if (field && typeData==6) { - std::string desc=(*it).first; - size_t found=desc.find(key); - if (found==std::string::npos) - continue; - if (MyGlobals::_Verbose>20) - std::cout << "proc " << MyGlobals::_Rank << " : write field " << desc << std::endl; - std::string meshName, fieldName; - int typeField, DT, IT, entity; - FieldShortDescriptionToData(desc, fieldName, typeField, entity, DT, IT); - double time=StrToDouble(ExtractFromDescription(desc, "time=")); - int typeData=StrToInt(ExtractFromDescription(desc, "typeData=")); - std::string entityName=ExtractFromDescription(desc, "entityName="); - ParaMEDMEM::MEDCouplingFieldDouble* field=0; - if (typeData!=6) - { - std::cout << "WARNING : writeMedFile : typeData " << typeData << " not implemented for fields\n"; - continue; - } - if (entityName=="MED_CELL") - { - //there is a field of idomain to write - field=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME); - } - if (entityName=="MED_NODE_ELEMENT") - { - //there is a field of idomain to write - field=ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_GAUSS_NE,ParaMEDMEM::ONE_TIME); - } - if (!field) - { - std::cout << "WARNING : writeMedFile : entityName " << entityName << " not implemented for fields\n"; - continue; - } - nbfFieldFound++; field->setName(fieldName); field->setMesh(mfm->getLevel0Mesh(false)); - ParaMEDMEM::DataArrayDouble *da=(*it).second; - + ParaMEDMEM::DataArrayDouble *da=data; //get information for components etc.. std::vector r1; r1=SelectTagsInVectorOfString(MyGlobals::_General_Informations,"fieldName="+fieldName); @@ -343,17 +266,40 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile int nbc=StrToInt(ExtractFromDescription(r1[0], "nbComponents=")); if (nbc==da->getNumberOfComponents()) { - for (int i=0; isetInfoOnComponent(i,ExtractFromDescription(r1[0], "componentInfo"+IntToStr(i)+"=")); } else { std::cerr << "Problem On field " << fieldName << " : number of components unexpected " << da->getNumberOfComponents() << std::endl; } - field->setArray(da); field->setTime(time,DT,IT); field->checkCoherency(); + } + return field; +} +void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfilename) const +{ + std::vector meshes; + meshes=getMeshes(idomain); + MEDLoader::WriteUMeshes(distfilename, meshes, true); + + ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(distfilename, _collection->getMesh(idomain)->getName()); + setFileUMesh(mfm,meshes.size(),idomain); + + mfm->write(distfilename,0); + std::string key="/inewFieldDouble="+IntToStr(idomain)+"/"; + std::map::iterator it; + int nbfFieldFound=0; + for (it=_collection->getMapDataArrayDouble().begin() ; it!=_collection->getMapDataArrayDouble().end(); it++) + { + size_t found=(*it).first.find(key); + if (found==std::string::npos) + continue; + ParaMEDMEM::MEDCouplingFieldDouble* field=0; + field=getField(key, (*it).first, (*it).second, mfm, idomain); + nbfFieldFound++; try { MEDLoader::WriteField(distfilename,field,false); @@ -362,6 +308,8 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile { //cout trying rewrite all data, only one field defined std::string tmp,newName=distfilename; + std::string fieldName; + fieldName=field->getName(); tmp+="_"+fieldName+"_"+IntToStr(nbfFieldFound)+".med"; newName.replace(newName.find(".med"),4,tmp); std::cout << "WARNING : writeMedFile : create a new file name with only one field because MEDLoader::WriteField throw:" << newName << std::endl; @@ -370,3 +318,38 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile } mfm->decrRef(); } + +ParaMEDMEM::MEDFileData* MeshCollectionDriver::getMEDFileData() +{ + ParaMEDMEM::MEDFileData* newdata=ParaMEDMEM::MEDFileData::New(); + ParaMEDMEM::MEDFileMeshes* meshes(ParaMEDMEM::MEDFileMeshes::New()); + ParaMEDMEM::MEDFileFields* fields(ParaMEDMEM::MEDFileFields::New()); + for (int i=0; i<(_collection->getMesh()).size(); i++) + { + ParaMEDMEM::MEDFileUMesh* m(ParaMEDMEM::MEDFileUMesh::New()); + m->setMeshes(getMeshes(i),true); + meshes->pushMesh(m); + ParaMEDMEM::MEDFileUMesh *mfm = ParaMEDMEM::MEDFileUMesh::New(); + setFileUMesh(mfm,(_collection->getMesh()).size(),i); + meshes->pushMesh(mfm); + std::string key="/inewFieldDouble="+IntToStr(i)+"/"; + std::map::iterator it; + ParaMEDMEM::MEDFileAnyTypeFieldMultiTS* fieldsMTS; + for (it=_collection->getMapDataArrayDouble().begin() ; it!=_collection->getMapDataArrayDouble().end(); it++) + { + size_t found=(*it).first.find(key); + if (found==std::string::npos) + continue; + ParaMEDMEM::MEDCouplingFieldDouble* field=0; + field=getField(key, (*it).first, (*it).second, mfm, i); + ParaMEDMEM::MEDFileField1TS* f1ts(ParaMEDMEM::MEDFileField1TS::New()); + f1ts->setFieldNoProfileSBT(field); + fieldsMTS->pushBackTimeStep(f1ts); + } + fields->pushField(fieldsMTS); + mfm->decrRef(); + } + newdata->setMeshes(meshes); + newdata->setFields(fields); + return newdata; +} diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.hxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.hxx index d4d3a41e2..701e6946c 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.hxx @@ -21,10 +21,15 @@ #define __MEDPARTITIONER_MESHCOLLECTIONDRIVER_HXX__ #include "MEDPARTITIONER.hxx" - +#include "MEDFileData.hxx" #include #include +namespace ParaMEDMEM +{ + class MEDFileData; +} + namespace MEDPARTITIONER { class MeshCollection; @@ -37,12 +42,16 @@ namespace MEDPARTITIONER virtual ~MeshCollectionDriver() { } virtual int read(const char*, ParaDomainSelector* sel=0) = 0; int readSeq(const char*,const char*); + ParaMEDMEM::MEDFileData *getMEDFileData(); virtual void write(const char*, ParaDomainSelector* sel=0) const = 0; + void readMEDFileData(const ParaMEDMEM::MEDFileData* filedata); protected: - void readSubdomain(std::vector& cellglobal, - std::vector& faceglobal, - std::vector& nodeglobal, int idomain); void readSubdomain(int idomain); + void readData(ParaMEDMEM::MEDFileUMesh* mfm, int idomain) const; + void readFileData(std::string file,std::string meshname,int idomain) const; + std::vector getMeshes(int idomain) const; + ParaMEDMEM::MEDCouplingFieldDouble* getField(std::string key, std::string description, ParaMEDMEM::DataArrayDouble* data, ParaMEDMEM::MEDFileUMesh* mfm, int idomain) const; + void setFileUMesh(ParaMEDMEM::MEDFileUMesh* mfm,int size, int idomain) const; void writeMedFile(int idomain, const std::string& distfilename) const; protected: MeshCollection* _collection; diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionMedAsciiDriver.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionMedAsciiDriver.cxx index b1ab04cd8..12a42615c 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionMedAsciiDriver.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionMedAsciiDriver.cxx @@ -52,6 +52,40 @@ MeshCollectionMedAsciiDriver::MeshCollectionMedAsciiDriver(MeshCollection* colle *\param filename ascii file containing the list of MED v2.3 files * */ +int MeshCollectionMedAsciiDriver::read(ParaMEDMEM::MEDFileData* filedata) +{ + readMEDFileData(filedata); + + std::vector cz; // to fill from filedata + std::vector cellglobal; + std::vector nodeglobal; + std::vector faceglobal; + int size = (_collection->getMesh()).size(); + cellglobal.resize(size); + nodeglobal.resize(size); + faceglobal.resize(size); + for ( int idomain = 0; idomain < size; ++idomain ) + { + cellglobal[idomain]=0; + faceglobal[idomain]=0; + nodeglobal[idomain]=0; + if ( (_collection->getMesh())[idomain] && (_collection->getMesh())[idomain]->getNumberOfNodes() > 0 ) + _collection->setNonEmptyMesh(idomain); + } + ParallelTopology* aPT = new ParallelTopology((_collection->getMesh()), cz, cellglobal, nodeglobal, faceglobal); + _collection->setTopology(aPT); + //creation of topology from mesh and connect zones + + return 0; +} + +/*!reads a MED File v>=2.3 + * and mounts the corresponding meshes in memory + * the connect zones are created from the joints + * + *\param filename ascii file containing the list of MED v2.3 files + * */ + int MeshCollectionMedAsciiDriver::read(const char* filename, ParaDomainSelector* domainSelector) { //distributed meshes @@ -105,7 +139,7 @@ int MeshCollectionMedAsciiDriver::read(const char* filename, ParaDomainSelector* throw INTERP_KERNEL::Exception("domain must be written from 1 to N in ASCII file descriptor"); } if ( !domainSelector || domainSelector->isMyDomain(i)) - readSubdomain(cellglobal,faceglobal,nodeglobal, i); + readSubdomain(i); } //loop on domains } //of try @@ -127,7 +161,6 @@ int MeshCollectionMedAsciiDriver::read(const char* filename, ParaDomainSelector* return 0; } - /*! writes the collection of meshes in a MED v2.3 file * with the connect zones being written as joints * \param filename name of the ascii file containing the meshes description diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionMedAsciiDriver.hxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionMedAsciiDriver.hxx index 9148c9fe1..699c0b254 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionMedAsciiDriver.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionMedAsciiDriver.hxx @@ -31,8 +31,9 @@ namespace MEDPARTITIONER MeshCollectionMedAsciiDriver(MeshCollection*); virtual ~MeshCollectionMedAsciiDriver() { } int read(const char*, ParaDomainSelector* sel=0); + int read(ParaMEDMEM::MEDFileData*); void write(const char*, ParaDomainSelector* sel=0) const; - private : + private: std::string _master_filename; }; } -- 2.39.2