Salome HOME
50% of work performed of porting tests.
[tools/medcoupling.git] / src / MEDPartitioner / MEDPARTITIONER_MeshCollectionDriver.cxx
index c2c997d0e060d096b196ddc4ccd7113cd872f0e5..ce0bc4d777836b5b04b83269ae935d7d4ba72cd4 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2014  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
@@ -97,7 +97,7 @@ void MeshCollectionDriver::readSubdomain(std::vector<int*>& cellglobal,
   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());
+  ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(file,meshname);
   std::vector<int> nonEmpty=mfm->getNonEmptyLevels();
   
   try 
@@ -163,7 +163,7 @@ 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.c_str(),meshname.c_str());
+  ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(file,meshname);
   std::vector<int> nonEmpty=mfm->getNonEmptyLevels();
   
   try 
@@ -228,19 +228,19 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile
   std::vector<const ParaMEDMEM::MEDCouplingUMesh*> meshes;
   ParaMEDMEM::MEDCouplingUMesh* cellMesh=_collection->getMesh(idomain);
   ParaMEDMEM::MEDCouplingUMesh* faceMesh=_collection->getFaceMesh(idomain);
-  ParaMEDMEM::MEDCouplingUMesh* faceMeshFilter=0;
+  //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());
+  // 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);
   meshes.push_back(cellMesh);
   
   faceMesh->checkCoherency();
@@ -250,60 +250,45 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile
       meshes.push_back(faceMesh);
     }
   
-  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.c_str(), 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.c_str(), boundaryMesh, false);
-      boundaryMesh->decrRef();
-    }
-  ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(distfilename.c_str(), _collection->getMesh(idomain)->getName());
-  
+  //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());
+
   mfm->setFamilyInfo(_collection->getFamilyInfo());
   mfm->setGroupInfo(_collection->getGroupInfo());
-  
+
   std::string key=Cle1ToStr("faceFamily_toArray",idomain);
-  if (_collection->getMapDataArrayInt().find(key)!=_collection->getMapDataArrayInt().end())
+  if ( meshes.size() == 2 &&
+      _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; i<nbTuples; i++)
-            pfamFilter[i]=pfam[index[i]];
-          fam=famFilter;
-          mfm->setFamilyFieldArr(-1,fam);
-          famFilter->decrRef();
-        }
+      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.c_str(),0);
+
+  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++)
@@ -342,7 +327,7 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile
           continue;
         }
       nbfFieldFound++;
-      field->setName(fieldName.c_str());
+      field->setName(fieldName);
       field->setMesh(mfm->getLevel0Mesh(false));
       ParaMEDMEM::DataArrayDouble *da=(*it).second;
     
@@ -352,12 +337,12 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile
       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());
+      //not saved in file? field->setDescription(ExtractFromDescription(r1[0], "fieldDescription="));
       int nbc=StrToInt(ExtractFromDescription(r1[0], "nbComponents="));
       if (nbc==da->getNumberOfComponents())
         {
           for (int i=0; i<nbc; i++) 
-            da->setInfoOnComponent(i,ExtractFromDescription(r1[0], "componentInfo"+IntToStr(i)+"=").c_str());
+            da->setInfoOnComponent(i,ExtractFromDescription(r1[0], "componentInfo"+IntToStr(i)+"="));
         }
       else
         {
@@ -369,7 +354,7 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile
       field->checkCoherency();
       try
         {
-          MEDLoader::WriteField(distfilename.c_str(),field,false);
+          MEDLoader::WriteField(distfilename,field,false);
         }
       catch(INTERP_KERNEL::Exception& e)
         {
@@ -378,7 +363,7 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile
           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);
+          MEDLoader::WriteField(newName,field,true);
         }
     }
   mfm->decrRef();