#include "MEDPARTITIONER_Graph.hxx"
#include "MEDPARTITIONER_MetisGraph.hxx"
#include "MEDPARTITIONER_ScotchGraph.hxx"
+#include "MEDPARTITIONER_MeshCollectionDriver.hxx"
#include "MEDCouplingUMesh.hxx"
#include <iostream>
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<MEDPARTITIONER::ConnectZone*> cz; // to fill from filedata
-
- for (int i=0; i<filedata->getMeshes()->getNumberOfMeshes(); i++)
- {
- ParaMEDMEM::MEDFileUMesh *mfm = dynamic_cast<ParaMEDMEM::MEDFileUMesh *>(filedata->getMeshes()->getMeshAtPos(i));
- std::vector<int> 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<int*> cellglobal;
- std::vector<int*> nodeglobal;
- std::vector<int*> 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);
}
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)
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 <int> cell2cell_index(nbCells+1,0);
- vector <int> cell2cell;
- cell2cell.reserve(3*nbCells);
-
- for (int icell=0; icell<nbCells;icell++)
- {
- map<int,int > counter;
- for (int iconn=index_ptr[icell]; iconn<index_ptr[icell+1];iconn++)
- {
- int inode=conn_ptr[iconn];
- for (int iconnr=indexr_ptr[inode]; iconnr<indexr_ptr[inode+1];iconnr++)
- {
- int icell2=revConn_ptr[iconnr];
- map<int,int>::iterator iter=counter.find(icell2);
- if (iter!=counter.end()) (iter->second)++;
- else counter.insert(make_pair(icell2,1));
- }
- }
- for (map<int,int>::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; icell<nbCells;icell++)
- cell2cell_index[icell+1]=cell2cell_index[icell]+cell2cell_index[icell+1];
-
-
- if (MyGlobals::_Verbose>50)
- 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; i<max; ++i)
- std::cout<<cell2cell_index[i]<<" ";
- std::cout << "... " << cell2cell_index[cell2cell_index.size()-1] << std::endl;
- for (int i=0; i<max; ++i)
- std::cout<< cell2cell[i] << " ";
- int ll=cell2cell_index[cell2cell_index.size()-1]-1;
- std::cout << "... (" << ll << ") " << cell2cell[ll-1] << " " << cell2cell[ll] << std::endl;
- }
- }
-
+ array=mesh->generateGraph();
}
/*! Method creating the cell graph in multidomain mode
*
}
-//================================================================================
-/*!
- * \brief Return mesh dimension from distributed med file had being read
- */
-//================================================================================
-
-void MeshCollectionDriver::readSubdomain(std::vector<int*>& cellglobal,
- std::vector<int*>& faceglobal,
- std::vector<int*>& 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; i<filedata->getMeshes()->getNumberOfMeshes(); i++)
+ {
+ ParaMEDMEM::MEDFileUMesh *mfm = dynamic_cast<ParaMEDMEM::MEDFileUMesh *>(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<int> 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);
(_collection->getFaceFamilyIds())[idomain]=faceIds;
if (MyGlobals::_Verbose>10)
std::cout << "proc " << MyGlobals::_Rank << " : WITH Faces\n";
-
}
else
{
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<std::string> 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<std::string> 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<int> 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<std::string> localInformation;
std::string str;
if (localFields.size()>0)
MyGlobals::_Field_Descriptions.push_back(SerializeFromVectorOfString(localFields));
}
-
-
-void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfilename) const
+std::vector<const ParaMEDMEM::MEDCouplingUMesh*> MeshCollectionDriver::getMeshes(int idomain) const
{
std::vector<const ParaMEDMEM::MEDCouplingUMesh*> 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;
// faceMeshFilter=(ParaMEDMEM::MEDCouplingUMesh *) faceMesh->buildPartOfMySelf(index,index+filter->getNbOfElems(),true);
// faceMesh=faceMeshFilter;
// }
+ // if (faceMeshFilter!=0)
+ // faceMeshFilter->decrRef();
cellMesh->setName(finalMeshName);
meshes.push_back(cellMesh);
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<std::string,ParaMEDMEM::DataArrayDouble*>::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<std::string> r1;
r1=SelectTagsInVectorOfString(MyGlobals::_General_Informations,"fieldName="+fieldName);
int nbc=StrToInt(ExtractFromDescription(r1[0], "nbComponents="));
if (nbc==da->getNumberOfComponents())
{
- for (int i=0; i<nbc; i++)
+ for (int i=0; i<nbc; i++)
da->setInfoOnComponent(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<const ParaMEDMEM::MEDCouplingUMesh*> 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<std::string,ParaMEDMEM::DataArrayDouble*>::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);
{
//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;
}
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<std::string,ParaMEDMEM::DataArrayDouble*>::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;
+}