Salome HOME
ContrĂ´le du choix des pas de temps
[modules/smesh.git] / src / SMESH / MG_ADAPT.cxx
index 64030554123fd51a5d62048d71994a6d79ac317b..76934c6a748f170ccaae608175e628c979598438 100644 (file)
 #include "MEDFileField.hxx"
 #include "MEDCouplingFieldDouble.hxx"
 
+#include <SALOME_NamingService.hxx>
+#include <Utils_SALOME_Exception.hxx>
+#include "Utils_CorbaException.hxx"
+
 #include <utilities.h>
 #include <iostream>
 #include <unistd.h>
@@ -219,9 +223,21 @@ MgAdaptHypothesisData* MgAdapt::getData() const
 }
 void MgAdapt::setMedFileIn(std::string fileName)
 {
-  medFileIn  = fileName;
-  if (medFileOut == "") // default MED file Out
-    medFileOut = remove_extension( fileName )+ ".adapt.med";
+  if ( isFileExist(fileName) )
+  {
+    medFileIn = fileName;
+
+    if (medFileOut == "") // default MED file Out
+      medFileOut = remove_extension( fileName )+ ".adapt.med";
+  }
+  else
+  {
+    SALOME::ExceptionStruct es;
+    es.type = SALOME::BAD_PARAM;
+    std::string text = "\nThe file " + fileName + " does not exist.\n" ;
+    es.text = CORBA::string_dup(text.c_str());
+    throw SALOME::SALOME_Exception(es);
+  }
 }
 
 std::string MgAdapt::getMedFileIn()
@@ -233,7 +249,6 @@ void MgAdapt::setMedFileOut(std::string fileOut)
 {
   medFileOut = fileOut;
 }
-
 std::string MgAdapt::getMedFileOut()
 {
   return medFileOut;
@@ -363,7 +378,18 @@ bool MgAdapt::getRemoveOnSuccess()
 }
 void MgAdapt::setSizeMapFile(std::string mapFile)
 {
-  sizeMapFile = mapFile;
+  if ( mapFile == "" || isFileExist(mapFile) )
+  {
+    sizeMapFile = mapFile;
+  }
+  else
+  {
+    SALOME::ExceptionStruct es;
+    es.type = SALOME::BAD_PARAM;
+    std::string text = "\nThe file " + mapFile + " does not exist.\n" ;
+    es.text = CORBA::string_dup(text.c_str());
+    throw SALOME::SALOME_Exception(es);
+  }
 }
 std::string MgAdapt::getSizeMapFile()
 {
@@ -428,7 +454,6 @@ bool MgAdapt::getPrintLogInFile()
   return printLogInFile;
 }
 
-
 bool MgAdapt::setAll()
 {
 
@@ -1127,6 +1152,39 @@ void MgAdapt::copyMgAdaptHypothesisData( const MgAdaptHypothesisData* from)
   data->myVerboseLevel = from->myVerboseLevel;
 }
 
+bool MgAdapt::checkTimeStepRank(std::string fileIn)
+{
+  INFOS("checkTimeStepRank");
+  bool ret = false ;
+  MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(fileIn);
+  MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> fts = dynamic_cast<MEDCoupling::MEDFileFieldMultiTS *>( mfd->getFields()->getFieldWithName(fieldName) );
+//   std::cout << "--- timeStep " << timeStep << std::endl;
+//   std::cout << "--- rank " << rank << std::endl;
+  std::vector<double> timevalue;
+  std::vector< std::pair<int,int> > timesteprank = fts->getTimeSteps(timevalue);
+  std::size_t jaux(timesteprank.size());
+  for(std::size_t j=0;j<jaux;j++)
+  {
+//     std::cout << "--- l[j]first  " << timesteprank[j].first << std::endl;
+//     std::cout << "--- l[j]second " << timesteprank[j].second << std::endl;
+    if ( ( timeStep == timesteprank[j].first ) & ( rank == timesteprank[j].second ) )
+    {
+      ret = true ;
+    }
+  }
+  if ( ! ret )
+  {
+    std::cout << "Available (Time step, Rank) :" << std::endl;
+    for(std::size_t j=0;j<jaux;j++)
+    { std::cout << "(Time step = " << timesteprank[j].first << ", Rank = " << timesteprank[j].second << ")" << std::endl;}
+   SALOME::ExceptionStruct es;
+    es.type = SALOME::BAD_PARAM;
+    std::string text = "(Time step = " + std::to_string(timeStep) + ", Rank = " + std::to_string(rank) + ") is not found." ;
+    es.text = CORBA::string_dup(text.c_str());
+    throw SALOME::SALOME_Exception(es);
+  }
+  return ret ;
+}
 
 void MgAdapt::convertMedFile(std::string& meshFormatMeshFileName, std::string& solFormatFieldFileName, std::string& meshFormatsizeMapFile)
 {
@@ -1146,12 +1204,14 @@ void MgAdapt::convertMedFile(std::string& meshFormatMeshFileName, std::string& s
 
   if (useBackgroundMap)
   {
+    bool ret = checkTimeStepRank(sizeMapFile) ;
     meshFormatsizeMapFile = getFileName();
     meshFormatsizeMapFile += ".mesh";
     buildBackGroundMeshAndSolFiles(fieldFileNames, meshFormatsizeMapFile);
   }
   else if(useLocalMap)
   {
+    bool ret = checkTimeStepRank(medFileIn) ;
     MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> fts = dynamic_cast<MEDCoupling::MEDFileFieldMultiTS *>( mfd->getFields()->getFieldWithName(fieldName) );
     MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeField1TS> f = fts->getTimeStep(timeStep, rank);
     MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> tmFts = MEDCoupling::MEDFileFieldMultiTS::New();
@@ -1315,8 +1375,11 @@ med_idt MgAdapt::openMedFile(const std::string aFile)
   med_idt medIdt = MEDfileOpen(aFile.c_str(),MED_ACC_RDONLY);
   if (medIdt <0)
   {
-    //~addMessage( ToComment(" error: Can't open  ") << aFile, /*fatal=*/true );
-    ;
+    SALOME::ExceptionStruct es;
+    es.type = SALOME::BAD_PARAM;
+    std::string text = "\nThe med file " + aFile + " cannot be opened.\n" ;
+    es.text = CORBA::string_dup(text.c_str());
+    throw SALOME::SALOME_Exception(es);
   }
   return medIdt;
 }