X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDPartitioner%2FMEDPARTITIONER_MeshCollectionDriver.cxx;h=8b6340e82bc6f37cbfff9faa0c3efcc503656ecc;hb=ffb8188e28b2b60ee207a8644286821bc4e8fcdc;hp=c2c997d0e060d096b196ddc4ccd7113cd872f0e5;hpb=10f37bf6f33a762626d7f1093b2f5450c1688667;p=tools%2Fmedcoupling.git diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx index c2c997d0e..8b6340e82 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -17,16 +17,23 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "MEDPARTITIONER_ParallelTopology.hxx" #include "MEDPARTITIONER_MeshCollectionDriver.hxx" + +#include "MEDPARTITIONER_ConnectZone.hxx" #include "MEDPARTITIONER_MeshCollection.hxx" #include "MEDPARTITIONER_ParaDomainSelector.hxx" +#include "MEDPARTITIONER_ParallelTopology.hxx" #include "MEDPARTITIONER_Utils.hxx" -#include "MEDCouplingUMesh.hxx" #include "MEDCouplingFieldDouble.hxx" -#include "MEDLoader.hxx" +#include "MEDCouplingRefCountObject.hxx" +#include "MEDCouplingSkyLineArray.hxx" +#include "MEDCouplingUMesh.hxx" +#include "MEDFileData.hxx" +#include "MEDFileField.hxx" +#include "MEDFileJoint.hxx" #include "MEDFileMesh.hxx" +#include "MEDLoader.hxx" #include #include @@ -59,14 +66,14 @@ int MeshCollectionDriver::readSeq(const char* filename, const char* meshname) MyGlobals::_File_Names.resize(1); MyGlobals::_File_Names[0]=std::string(filename); - ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(filename,meshname); + MEDCoupling::MEDFileUMesh* mfm=MEDCoupling::MEDFileUMesh::New(filename,meshname); //puts the only mesh in the mesh vector (_collection->getMesh()).push_back(mfm->getLevel0Mesh(false)); (_collection->getFaceMesh()).push_back(mfm->getLevelM1Mesh(false)); //reading family ids - ParaMEDMEM::DataArrayInt* cellIds(mfm->getFamilyFieldAtLevel(0)->deepCpy()); - ParaMEDMEM::DataArrayInt* faceIds(mfm->getFamilyFieldAtLevel(-1)->deepCpy()); + MEDCoupling::DataArrayIdType* cellIds(mfm->getFamilyFieldAtLevel(0)->deepCopy()); + MEDCoupling::DataArrayIdType* faceIds(mfm->getFamilyFieldAtLevel(-1)->deepCopy()); (_collection->getCellFamilyIds()).push_back(cellIds); (_collection->getFaceFamilyIds()).push_back(faceIds); @@ -77,117 +84,76 @@ int MeshCollectionDriver::readSeq(const char* filename, const char* meshname) (_collection->getCZ()).clear(); ParallelTopology* aPT = new ParallelTopology((_collection->getMesh())); - _collection->setTopology(aPT); + _collection->setTopology(aPT, true); _collection->setName(meshname); _collection->setDomainNames(meshname); return 0; } -//================================================================================ -/*! - * \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 MEDCoupling::MEDFileData* filedata) { - std::string meshname=MyGlobals::_Mesh_Names[idomain]; - std::string file=MyGlobals::_File_Names[idomain]; + const int nbDomains = filedata->getMeshes()->getNumberOfMeshes(); + _collection->getMesh() .resize( nbDomains, 0 ); + _collection->getFaceMesh() .resize( nbDomains, 0 ); + _collection->getCellFamilyIds().resize( nbDomains, 0 ); + _collection->getFaceFamilyIds().resize( nbDomains, 0 ); - ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(file.c_str(),meshname.c_str()); - 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"; + for (int i=0; i(filedata->getMeshes()->getMeshAtPos(i)); + readData(mfm,i); + if ( mfm && mfm->getMeshDimension() > 0 ) + _collection->setNonEmptyMesh( i ); } - 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(...) + ParallelTopology* aPT = new ParallelTopology(_collection->getMesh()); + _collection->setTopology(aPT, true); + if ( nbDomains > 0 ) { - (_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"; + _collection->setName( filedata->getMeshes()->getMeshAtPos(0)->getName() ); + _collection->setDomainNames( _collection->getName() ); } - - //reading groups - _collection->getFamilyInfo()=mfm->getFamilyInfo(); - _collection->getGroupInfo()=mfm->getGroupInfo(); + if ( ParaDomainSelector* domainSelector = _collection->getParaDomainSelector() ) + if ( _collection->isParallelMode() ) + { + //to know nb of cells on each proc to compute global cell ids from locally global + domainSelector->gatherNbOf(_collection->getMesh()); + } +} +void MeshCollectionDriver::readFileData(std::string file,std::string meshname,int idomain) const +{ + MEDCoupling::MEDFileUMesh* mfm=MEDCoupling::MEDFileUMesh::New(file,meshname); + readData(mfm,idomain); 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) +void MeshCollectionDriver::readData(MEDCoupling::MEDFileUMesh* mfm, int idomain) const { - std::string meshname=MyGlobals::_Mesh_Names[idomain]; - std::string file=MyGlobals::_File_Names[idomain]; - - ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(file.c_str(),meshname.c_str()); 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()); + MEDCoupling::DataArrayIdType* cellIds(mfm->getFamilyFieldAtLevel(0)->deepCopy()); (_collection->getCellFamilyIds())[idomain]=cellIds; } catch(...) - { + { (_collection->getMesh())[idomain]=CreateEmptyMEDCouplingUMesh(); // or 0 if you want tests; - ParaMEDMEM::DataArrayInt* empty=ParaMEDMEM::DataArrayInt::New(); + MEDCoupling::DataArrayIdType* empty=MEDCoupling::DataArrayIdType::New(); empty->alloc(0,1); (_collection->getCellFamilyIds())[idomain]=empty; std::cout<<"\nNO Level0Mesh (Cells)\n"; } - try - { + try + { if (nonEmpty.size()>1 && nonEmpty[1]==-1) { (_collection->getFaceMesh())[idomain]=mfm->getLevelM1Mesh(false); //reading families groups - ParaMEDMEM::DataArrayInt* faceIds(mfm->getFamilyFieldAtLevel(-1)->deepCpy()); + MEDCoupling::DataArrayIdType* faceIds(mfm->getFamilyFieldAtLevel(-1)->deepCopy()); (_collection->getFaceFamilyIds())[idomain]=faceIds; if (MyGlobals::_Verbose>10) std::cout << "proc " << MyGlobals::_Rank << " : WITH Faces\n"; @@ -200,17 +166,21 @@ void MeshCollectionDriver::readSubdomain(int idomain) catch(...) { (_collection->getFaceMesh())[idomain]=CreateEmptyMEDCouplingUMesh(); // or 0 if you want test; - ParaMEDMEM::DataArrayInt* empty=ParaMEDMEM::DataArrayInt::New(); + MEDCoupling::DataArrayIdType* empty=MEDCoupling::DataArrayIdType::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(); +void MeshCollectionDriver::readSubdomain(int idomain) +{ + std::string meshname=MyGlobals::_Mesh_Names[idomain]; + std::string file=MyGlobals::_File_Names[idomain]; + readFileData(file,meshname,idomain); std::vector localInformation; std::string str; @@ -218,168 +188,275 @@ void MeshCollectionDriver::readSubdomain(int 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) + if (localFields.size()>0) MyGlobals::_Field_Descriptions.push_back(SerializeFromVectorOfString(localFields)); } - -void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfilename) const +MEDCoupling::MEDFileMesh* MeshCollectionDriver::getMesh(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; - if (_collection->getMapDataArrayInt().find(cleFilter)!=_collection->getMapDataArrayInt().end()) - { - filter=_collection->getMapDataArrayInt().find(cleFilter)->second; - int* index=filter->getPointer(); - faceMeshFilter=(ParaMEDMEM::MEDCouplingUMesh *) faceMesh->buildPartOfMySelf(index,index+filter->getNbOfElems(),true); - faceMesh=faceMeshFilter; - } - cellMesh->setName(finalMeshName.c_str()); - meshes.push_back(cellMesh); - - faceMesh->checkCoherency(); - if (faceMesh->getNumberOfCells()>0) + MEDCoupling::MEDFileUMesh* mfm = MEDCoupling::MEDFileUMesh::New(); + + MEDCoupling::MEDCouplingUMesh* cellMesh=_collection->getMesh(idomain); + MEDCoupling::MEDCouplingUMesh* faceMesh=_collection->getFaceMesh(idomain); + // std::string cleFilter=Cle1ToStr("filterFaceOnCell",idomain); + // MEDCoupling::DataArrayInt* filter=0; + // if (_collection->getMapDataArrayInt().find(cleFilter)!=_collection->getMapDataArrayInt().end()) + // { + // filter=_collection->getMapDataArrayInt().find(cleFilter)->second; + // int* index=filter->getPointer(); + // faceMeshFilter=(MEDCoupling::MEDCouplingUMesh *) faceMesh->buildPartOfMySelf(index,index+filter->getNbOfElems(),true); + // faceMesh=faceMeshFilter; + // } + // if (faceMeshFilter!=0) + // faceMeshFilter->decrRef(); + std::string finalMeshName=""; + if (MyGlobals::_General_Informations.size()!=0) { - faceMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-10); - meshes.push_back(faceMesh); + std::size_t found=MyGlobals::_General_Informations[0].find("finalMeshName="); + if ((found!=std::string::npos) && (found>0)) + { + finalMeshName=ExtractFromDescription(MyGlobals::_General_Informations[0], "finalMeshName="); + } } - - ParaMEDMEM::MEDCouplingUMesh* boundaryMesh=0; - if (MyGlobals::_Creates_Boundary_Faces>0) + if (finalMeshName.empty()) { - //try to write Boundary meshes - bool keepCoords=false; //TODO or true - boundaryMesh=(ParaMEDMEM::MEDCouplingUMesh *) cellMesh->buildBoundaryMesh(keepCoords); - boundaryMesh->setName("boundaryMesh"); + finalMeshName=_collection->getName(); } - - MEDLoader::WriteUMeshes(distfilename.c_str(), meshes, true); - if (faceMeshFilter!=0) - faceMeshFilter->decrRef(); - - if (boundaryMesh!=0) + cellMesh->setName(finalMeshName); + mfm->setMeshAtLevel( 0, cellMesh ); + + faceMesh->checkConsistencyLight(); + if (faceMesh->getNumberOfCells()>0) { - //doing that testMesh becomes second mesh sorted by alphabetical order of name - MEDLoader::WriteUMesh(distfilename.c_str(), boundaryMesh, false); - boundaryMesh->decrRef(); + faceMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-10); + faceMesh->setName(finalMeshName); + mfm->setMeshAtLevel( -1, faceMesh ); } - ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(distfilename.c_str(), _collection->getMesh(idomain)->getName()); - + + // MEDCoupling::MEDCouplingUMesh* boundaryMesh=0; + // if (MyGlobals::_Create_Boundary_Faces>0) + // { + // //try to write Boundary meshes + // bool keepCoords=false; //TODO or true + // boundaryMesh=(MEDCoupling::MEDCouplingUMesh *) cellMesh->buildBoundaryMesh(keepCoords); + // boundaryMesh->setName("boundaryMesh"); + // if (boundaryMesh!=0) + // { + // //doing that testMesh becomes second mesh sorted by alphabetical order of name + // WriteUMesh(distfilename, boundaryMesh, false); + // boundaryMesh->decrRef(); + // } + mfm->setFamilyInfo(_collection->getFamilyInfo()); mfm->setGroupInfo(_collection->getGroupInfo()); - std::string key=Cle1ToStr("faceFamily_toArray",idomain); - if (_collection->getMapDataArrayInt().find(key)!=_collection->getMapDataArrayInt().end()) - { - ParaMEDMEM::DataArrayInt *fam=_collection->getMapDataArrayInt().find(key)->second; - ParaMEDMEM::DataArrayInt *famFilter=0; - if (filter!=0) - { - int* index=filter->getPointer(); - int nbTuples=filter->getNbOfElems(); - //not the good one...buildPartOfMySelf do not exist for DataArray - //Filter=fam->renumberAndReduce(index, filter->getNbOfElems()); - famFilter=ParaMEDMEM::DataArrayInt::New(); - famFilter->alloc(nbTuples,1); - int* pfamFilter=famFilter->getPointer(); - int* pfam=fam->getPointer(); - for (int i=0; isetFamilyFieldArr(-1,fam); - famFilter->decrRef(); - } - } - + if ( faceMesh->getNumberOfCells()>0 && _collection->getMapDataArrayInt().find(key)!=_collection->getMapDataArrayInt().end()) + mfm->setFamilyFieldArr(-1,_collection->getMapDataArrayInt().find(key)->second); key=Cle1ToStr("cellFamily_toArray",idomain); if (_collection->getMapDataArrayInt().find(key)!=_collection->getMapDataArrayInt().end()) mfm->setFamilyFieldArr(0,_collection->getMapDataArrayInt().find(key)->second); - - mfm->write(distfilename.c_str(),0); - key="/inewFieldDouble="+IntToStr(idomain)+"/"; - - std::map::iterator it; - int nbfFieldFound=0; - for (it=_collection->getMapDataArrayDouble().begin() ; it!=_collection->getMapDataArrayDouble().end(); it++) + + // add joints + + using MEDCoupling::MCAuto; + using MEDCoupling::MEDCouplingSkyLineArray; + using MEDCoupling::MEDFileJoint; + using MEDCoupling::MEDFileJointCorrespondence; + using MEDCoupling::MEDFileJointOneStep; + using MEDCoupling::MEDFileJoints; + using MEDCoupling::MEDFileJoints; + + if ( _collection->getCZ().size() > 0 ) { - 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) + MCAuto< MEDFileJoints > joints = MEDFileJoints::New(); + + for ( size_t i = 0; i < _collection->getCZ().size(); ++i ) { - std::cout << "WARNING : writeMedFile : entityName " << entityName << " not implemented for fields\n"; - continue; + ConnectZone* cz = _collection->getCZ()[i]; + if ( !cz || + cz->getLocalDomainNumber() != idomain ) + continue; + { + std::ostringstream oss; + oss << "joint_" << cz->getDistantDomainNumber(); + cz->setName( oss.str() ); + } + { + std::ostringstream oss; + oss << "connect_zone_" << i; + cz->setDescription( oss.str() ); + } + + MCAuto< MEDFileJoint> + joint = MEDFileJoint::New( cz->getName(), finalMeshName, + finalMeshName, cz->getDistantDomainNumber() ); + joint->setDescription( cz->getDescription() ); + joints->pushJoint( joint ); + + MCAuto< MEDFileJointOneStep> j1st = MEDFileJointOneStep::New(); + joint->pushStep( j1st ); + + const MEDCouplingSkyLineArray * nodeCorr = cz->getNodeCorresp(); + if ( nodeCorr ) + { + MCAuto< MEDFileJointCorrespondence > + corr = MEDFileJointCorrespondence::New( nodeCorr->getValuesArray() ); + j1st->pushCorrespondence( corr ); + } + + std::vector< std::pair< mcIdType,mcIdType > > types = cz->getEntities(); + INTERP_KERNEL::NormalizedCellType t1, t2; + for ( size_t it = 0; it < types.size(); ++it ) + { + const MEDCouplingSkyLineArray * cellCorr = + cz->getEntityCorresp( types[it].first, types[it].second ); + if ( cellCorr && cellCorr->getNumberOf() > 0 ) + { + t1 = INTERP_KERNEL::NormalizedCellType( types[it].first ); + t2 = INTERP_KERNEL::NormalizedCellType( types[it].second ); + MCAuto< MEDFileJointCorrespondence> + corr = MEDFileJointCorrespondence::New( cellCorr->getValuesArray(), t1, t2 ); + j1st->pushCorrespondence( corr ); + } + } } - nbfFieldFound++; - field->setName(fieldName.c_str()); - field->setMesh(mfm->getLevel0Mesh(false)); - ParaMEDMEM::DataArrayDouble *da=(*it).second; - + mfm->setJoints( joints ); + } + + return mfm; +} + +MEDCoupling::MEDCouplingFieldDouble* MeshCollectionDriver::getField(std::string key, std::string description, MEDCoupling::DataArrayDouble* data, MEDCoupling::MEDFileMesh* 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="); + MEDCoupling::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=MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_CELLS,MEDCoupling::ONE_TIME); + } + if (entityName=="MED_NODE_ELEMENT") + { + //there is a field of idomain to write + field=MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_GAUSS_NE,MEDCoupling::ONE_TIME); + } + if (!field) + { + std::cout << "WARNING : writeMedFile : entityName " << entityName << " not implemented for fields\n"; + } + if (field && typeData==6) + { + field->setName(fieldName); + field->setMesh(mfm->getMeshAtLevel(0)); + MEDCoupling::DataArrayDouble *da=data; //get information for components etc.. std::vector r1; r1=SelectTagsInVectorOfString(MyGlobals::_General_Informations,"fieldName="+fieldName); r1=SelectTagsInVectorOfString(r1,"typeField="+IntToStr(typeField)); r1=SelectTagsInVectorOfString(r1,"DT="+IntToStr(DT)); r1=SelectTagsInVectorOfString(r1,"IT="+IntToStr(IT)); - //not saved in file? field->setDescription(ExtractFromDescription(r1[0], "fieldDescription=").c_str()); - int nbc=StrToInt(ExtractFromDescription(r1[0], "nbComponents=")); + //not saved in file? field->setDescription(ExtractFromDescription(r1[0], "fieldDescription=")); + std::size_t nbc=StrToInt(ExtractFromDescription(r1[0], "nbComponents=")); if (nbc==da->getNumberOfComponents()) { - for (int i=0; isetInfoOnComponent(i,ExtractFromDescription(r1[0], "componentInfo"+IntToStr(i)+"=").c_str()); + for (unsigned 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(); + field->checkConsistencyLight(); + } + return field; +} + +void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfilename) const +{ + MEDCoupling::MEDFileMesh* mfm = getMesh( idomain ); + mfm->write(distfilename,2); + + 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; + MEDCoupling::MEDCouplingFieldDouble* field=0; + field = getField(key, (*it).first, (*it).second, mfm, idomain); + nbfFieldFound++; try { - MEDLoader::WriteField(distfilename.c_str(),field,false); + WriteField(distfilename,field,false); } catch(INTERP_KERNEL::Exception& e) { //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; - MEDLoader::WriteField(newName.c_str(),field,true); + std::cout << "WARNING : writeMedFile : create a new file name with only one field because WriteField throw:" << newName << std::endl; + WriteField(newName,field,true); } } mfm->decrRef(); } + +MEDCoupling::MEDFileData* MeshCollectionDriver::getMEDFileData() +{ + MEDCoupling::MEDFileData* newdata = MEDCoupling::MEDFileData::New(); + + MEDCoupling::MCAuto meshes; + MEDCoupling::MCAuto fields; + meshes = MEDCoupling::MEDFileMeshes::New(); + fields = MEDCoupling::MEDFileFields::New(); + + for (unsigned int i=0; i<_collection->getMesh().size(); i++) + { + MEDCoupling::MEDFileMesh* mfm = getMesh( i ); + meshes->pushMesh(mfm); + + std::string key="/inewFieldDouble="+IntToStr(i)+"/"; + std::map::iterator it; + MEDCoupling::MEDFileFieldMultiTS* fieldsMTS = MEDCoupling::MEDFileFieldMultiTS::New(); + for (it=_collection->getMapDataArrayDouble().begin() ; it!=_collection->getMapDataArrayDouble().end(); it++) + { + size_t found=(*it).first.find(key); + if (found==std::string::npos) + continue; + MEDCoupling::MEDCouplingFieldDouble* field=0; + field=getField(key, (*it).first, (*it).second, mfm, i); + MEDCoupling::MEDFileField1TS* f1ts = MEDCoupling::MEDFileField1TS::New(); + f1ts->setFieldNoProfileSBT(field); + fieldsMTS->pushBackTimeStep(f1ts); + + field->decrRef(); + f1ts->decrRef(); + } + fields->pushField(fieldsMTS); + + fieldsMTS->decrRef(); + mfm->decrRef(); + } + newdata->setMeshes(meshes); + newdata->setFields(fields); + return newdata; +}