Salome HOME
Merge branch 'assert_compute' of https://codev-tuleap.cea.fr/plugins/git/salome/smesh...
[modules/smesh.git] / src / SMESH / MG_ADAPT.cxx
index d490092d1e833ef2c5b00c32760c4ee402bbd343..50f467fc03304a342577f7476898867cb505d79b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2021  CEA/DEN, EDF R&D
+// Copyright (C) 2020-2022  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
@@ -33,6 +33,7 @@
 
 #include <Utils_SALOME_Exception.hxx>
 #include <Basics_Utils.hxx>
+#include "SMESH_TypeDefs.hxx"
 
 #ifndef WIN32
 #include <unistd.h> // getpid()
@@ -1403,8 +1404,17 @@ void MgAdapt::convertMedFile(std::string& meshFormatMeshFileName, std::string& s
     checkTimeStepRank(medFileIn) ;
     MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> fts( mfd->getFields()->getFieldWithName(fieldName) );
     MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeField1TS> f = fts->getTimeStep(timeStep, rank);
-    MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> tmFts = MEDCoupling::MEDFileFieldMultiTS::New();
-    tmFts->pushBackTimeStep(f);
+    MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> tmFts = MEDCoupling::DynamicCast<MEDCoupling::MEDFileAnyTypeFieldMultiTS,MEDCoupling::MEDFileFieldMultiTS>(fts);
+
+    // if not able to cast to double field, try float field
+    if (!tmFts)
+    {
+      MEDCoupling::MCAuto<MEDCoupling::MEDFileFloatFieldMultiTS>  tmFtsFloat = MEDCoupling::DynamicCast<MEDCoupling::MEDFileAnyTypeFieldMultiTS,MEDCoupling::MEDFileFloatFieldMultiTS>(fts);
+      if (!tmFtsFloat)
+        THROW_SALOME_EXCEPTION("\nUnexpected field type.\n");
+      // convert float field to double
+      tmFts = tmFtsFloat->convertToDouble();
+    }
 
     fields->pushField(tmFts);
 
@@ -1565,9 +1575,9 @@ MgAdapt::Status MgAdapt::addMessage(const std::string& msg,
   _errorMessages.push_back( msg );
 
   //~MESSAGE(msg);
-#ifdef _DEBUG_
-  std::cout << msg << std::endl;
-#endif
+  if (SALOME::VerbosityActivated())
+    std::cout << msg << std::endl;
+
   return ( _status = isFatal ? MgAdapt::DRS_FAIL : MgAdapt::DRS_WARN_SKIP_ELEM );
 }