Salome HOME
*** empty log message ***
[modules/multipr.git] / src / MULTIPR / MULTIPR_MeshDis.cxx
index 361de632f0f14aa9cdefb40dfeaa72c97ef08979..3c0571ea2407921bff3fd159635412867c921df0 100644 (file)
@@ -439,10 +439,12 @@ string MeshDis::getPartInfo(const char* pPartName)
 
 void MeshDis::splitPart(const char* pPartName, int pNbParts, int pPartitionner)
 {
+       cout << "MULTIPR: MeshDis::splitPart()" << endl;
        if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
        if (pNbParts < 2) throw IllegalArgumentException("", __FILE__, __LINE__);
        if ((pPartitionner != MULTIPR_METIS) && (pPartitionner != MULTIPR_SCOTCH)) throw IllegalArgumentException("should be 0=METIS or 1=SCOTCH", __FILE__, __LINE__);
        
+       cout << "MULTIPR: MeshDis::splitPart(): args OK" << endl;
        //---------------------------------------------------------------------
        // Find the MED file corresponding to the given part
        //---------------------------------------------------------------------
@@ -452,6 +454,8 @@ void MeshDis::splitPart(const char* pPartName, int pNbParts, int pPartitionner)
        {
                throw IllegalArgumentException("part not found in this distributed MED file", __FILE__, __LINE__);
        }
+
+       cout << "MULTIPR: MeshDis::splitPart(): find part OK" << endl;
        
        //---------------------------------------------------------------------
        // Load the sequential MED file
@@ -459,6 +463,7 @@ void MeshDis::splitPart(const char* pPartName, int pNbParts, int pPartitionner)
        MEDSPLITTER::MESHCollection* collection;
        collection = new MEDSPLITTER::MESHCollection(part->getMEDFileName(), part->getMeshName());
        
+       cout << "MULTIPR: MeshDis::splitPart(): MEDSPLITTER collection OK" << endl;
        //---------------------------------------------------------------------
        // Partition the group
        //---------------------------------------------------------------------
@@ -478,7 +483,9 @@ void MeshDis::splitPart(const char* pPartName, int pNbParts, int pPartitionner)
        {
                try
                {
+                       cout << "MULTIPR: try to create partition using SCOTCH: #parts=" << pNbParts << endl;
                        topology = collection->createPartition(pNbParts, MEDSPLITTER::Graph::SCOTCH);
+                       cout << "MULTIPR: assigned SCOTCH" << endl;
                }
                catch (...)
                {
@@ -501,6 +508,7 @@ void MeshDis::splitPart(const char* pPartName, int pNbParts, int pPartitionner)
        }
        catch (...)
        {
+               cout << "MEDSPLITTER error: new MESHCollection()" << endl;
                throw RuntimeException("MEDSPLITTER error: new MESHCollection()", __FILE__, __LINE__);
        }
 }
@@ -816,7 +824,7 @@ void MeshDis::readDistributedMED(const char* pMEDfilename)
 /**
  * Retrieves the output of MEDSPLITTER and convert it for MULTIPR.
  */
-int convertMedsplitterToMultipr(ofstream& pFileMaster, const char* pTmpFilename, int pId, MeshDisPart* pPart)
+int convertMedsplitterToMultipr(ofstream& pFileMaster, const char* pTmpFilename, int pId, MeshDisPart* pPart, string pDestPath)
 {
        MULTIPR_LOG("convert" << endl);
        
@@ -869,6 +877,13 @@ int convertMedsplitterToMultipr(ofstream& pFileMaster, const char* pTmpFilename,
                
                //cout << lMeshName << " " << (pId + i) << " " << pPart->getPartName() << "_" << (i + 1) << " " << lPath << " " << lMEDFileName << endl;
                
+               string strDestFilename = pDestPath + multipr::getFilenameWithoutPath(lMEDFileName);
+               if (strcmp(lMEDFileName, strDestFilename.c_str()) != 0)
+               {
+                       multipr::copyFile(lMEDFileName, pDestPath.c_str());
+                       strcpy(lMEDFileName, strDestFilename.c_str());
+               }
+                               
                pFileMaster << lMeshName << " " << (pId + i) << " " << pPart->getPartName() << "_" << (i + 1) << " " << lPath << " " << lMEDFileName << endl;
        }
        
@@ -903,6 +918,8 @@ void MeshDis::writeDistributedMED(const char* pMEDfilenamePrefix)
                strMasterFilename = strPrefix + strExtension;
        }
        
+       string strDestPath = multipr::getPath(strMasterFilename.c_str());
+       
        MULTIPR_LOG("Create master: " << strMasterFilename << endl);
        strcpy(mMEDfilename, strMasterFilename.c_str());
        
@@ -939,6 +956,17 @@ void MeshDis::writeDistributedMED(const char* pMEDfilenamePrefix)
                        {
                                mParts[itPart]->mId = id;
                                id++;
+                               
+                               // copy file in another directory?
+                               string strSrcPath = multipr::getPath(mParts[itPart]->getMEDFileName());
+                               if (strSrcPath != strDestPath)
+                               {
+                                       cout << "Write: KEEP_AS_IT: copy file" << endl;
+                                       string strDestFilename = strDestPath + multipr::getFilenameWithoutPath(mParts[itPart]->getMEDFileName());
+                                       multipr::copyFile(mParts[itPart]->getMEDFileName(), strDestPath.c_str());
+                                       strcpy(mParts[itPart]->mMEDFileName, strDestFilename.c_str());
+                               }
+                               
                                fileMaster << (*mParts[itPart]) << endl;
                                cout << (*mParts[itPart]) << endl;
                                break;
@@ -948,6 +976,10 @@ void MeshDis::writeDistributedMED(const char* pMEDfilenamePrefix)
                        {
                                if (strlen(mParts[itPart]->getMEDFileName()) == 0) throw IOException("MED filename is empty", __FILE__, __LINE__);
                                if (mParts[itPart]->mMesh == NULL) throw IllegalStateException("invalid mesh (shoult not be NULL)", __FILE__, __LINE__);
+                               
+                               string strDestFilename = strDestPath + multipr::getFilenameWithoutPath(mParts[itPart]->getMEDFileName());
+                               strcpy(mParts[itPart]->mMEDFileName, strDestFilename.c_str());
+                               
                                mParts[itPart]->mMesh->writeMED(mParts[itPart]->getMEDFileName());
                                mParts[itPart]->mId = id;
                                id++;
@@ -965,7 +997,7 @@ void MeshDis::writeDistributedMED(const char* pMEDfilenamePrefix)
                                sprintf(tmpFilename, "%s_part", strPrefix.c_str());
                                mParts[itPart]->mCollection->write(tmpFilename);
                                mParts[itPart]->mCollection->castAllFields(*(mParts[itPart]->mOldCollection));
-                               int ret = convertMedsplitterToMultipr(fileMaster, tmpFilename, id, mParts[itPart]);
+                               int ret = convertMedsplitterToMultipr(fileMaster, tmpFilename, id, mParts[itPart], strDestPath);
                                id += ret;
                                remove(mParts[itPart]->getMEDFileName());
                                break;