Salome HOME
contrĂ´le du nom du champ de la carte de taille
authorGERALD NICOLAS <D68518@dsp0864451.atlas.edf.fr>
Wed, 10 Feb 2021 13:41:44 +0000 (14:41 +0100)
committerGERALD NICOLAS <D68518@dsp0864451.atlas.edf.fr>
Wed, 10 Feb 2021 13:41:44 +0000 (14:41 +0100)
src/SMESH/MG_ADAPT.cxx
src/SMESH/MG_ADAPT.hxx

index 76934c6a748f170ccaae608175e628c979598438..e73758b5d5d56258b76d2d533fb3c851c7776692 100644 (file)
@@ -1152,9 +1152,33 @@ void MgAdapt::copyMgAdaptHypothesisData( const MgAdaptHypothesisData* from)
   data->myVerboseLevel = from->myVerboseLevel;
 }
 
+bool MgAdapt::checkFieldName(std::string fileIn)
+{
+  bool ret = false ;
+  MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(fileIn);
+  std::vector<std::string> fieldNames(mfd->getFields()->getFieldsNames());
+  std::size_t jaux(fieldNames.size());
+  for(std::size_t j=0;j<jaux;j++)
+  {
+    if ( fieldName == fieldNames[j] )
+    { ret = true ; }
+  }
+  if ( ! ret )
+  {
+    std::cout << "Available field names:" << std::endl;
+    for(std::size_t j=0;j<jaux;j++)
+    { std::cout << fieldNames[j] << std::endl;}
+    SALOME::ExceptionStruct es;
+    es.type = SALOME::BAD_PARAM;
+    std::string text = "Field " + fieldName + " is not found." ;
+    es.text = CORBA::string_dup(text.c_str());
+    throw SALOME::SALOME_Exception(es);
+  }
+  return ret ;
+}
+
 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) );
@@ -1165,19 +1189,15 @@ bool MgAdapt::checkTimeStepRank(std::string fileIn)
   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 ;
-    }
+    { ret = true ; }
   }
   if ( ! ret )
   {
-    std::cout << "Available (Time step, Rank) :" << std::endl;
+    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;
+    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());
@@ -1204,14 +1224,18 @@ void MgAdapt::convertMedFile(std::string& meshFormatMeshFileName, std::string& s
 
   if (useBackgroundMap)
   {
-    bool ret = checkTimeStepRank(sizeMapFile) ;
+    bool ret ;
+    ret = checkFieldName(sizeMapFile) ;
+    ret = checkTimeStepRank(sizeMapFile) ;
     meshFormatsizeMapFile = getFileName();
     meshFormatsizeMapFile += ".mesh";
     buildBackGroundMeshAndSolFiles(fieldFileNames, meshFormatsizeMapFile);
   }
   else if(useLocalMap)
   {
-    bool ret = checkTimeStepRank(medFileIn) ;
+    bool ret ;
+    ret = checkFieldName(medFileIn) ;
+    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();
index 0684c28381ecd4f50fe73384002f73daaea4c464..be289729a6b5acb8f08ea7eed48ecb1b4427fde1 100644 (file)
@@ -328,6 +328,7 @@ private :
   void execCmd( const char* cmd, int& err);
   void cleanUp();
   void appendMsgToLogFile(std::string& msg);
+  bool checkFieldName(std::string fileIn) ;
   bool checkTimeStepRank(std::string fileIn) ;
 
 };