Salome HOME
Fixed installation issue on Windows
[modules/smesh.git] / src / SMESH / SMESH_Mesh.cxx
index a7bd39126142b3b6b0750e004123f6fe3af2e91a..8d545cc58155d5a2427824b476fa03ca486c54d5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #ifdef WITH_CGNS
 #include "DriverCGNS_Read.hxx"
 #include "DriverCGNS_Write.hxx"
+#include "DriverStructuredCGNS_Write.hxx"
 #endif
 
 #include <GEOMUtils.hxx>
 
-#undef _Precision_HeaderFile
+//#undef _Precision_HeaderFile
 #include <BRepBndLib.hxx>
 #include <BRepPrimAPI_MakeBox.hxx>
 #include <Bnd_Box.hxx>
 #include <pthread.h>
 #endif
 
+#ifndef WIN32
 #include <boost/filesystem.hpp>
 namespace fs=boost::filesystem;
+#endif
 
 // maximum stored group name length in MED file
 #define MAX_MED_GROUP_NAME_LENGTH 80
 
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
-
 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
 
 typedef SMESH_HypoFilter THypType;
@@ -112,7 +109,7 @@ SMESH_Mesh::SMESH_Mesh(int               theLocalId,
                        SMESHDS_Document* theDocument):
   _groupId( 0 ), _nbSubShapes( 0 )
 {
-  if(MYDEBUG) MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
+  MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
   _id            = theLocalId;
   _gen           = theGen;
   _document    = theDocument;
@@ -124,9 +121,6 @@ SMESH_Mesh::SMESH_Mesh(int               theLocalId,
   _callUp        = NULL;
   _meshDS->ShapeToMesh( PseudoShape() );
   _subMeshHolder = new SubMeshHolder;
-  // Temporary folder that will be used by parallel computation
-  tmp_folder = fs::temp_directory_path()/fs::unique_path(fs::path("SMESH_%%%%-%%%%"));
-  fs::create_directories(tmp_folder);
 
   // assure unique persistent ID
   if ( _document->NbMeshes() > 1 )
@@ -174,13 +168,11 @@ namespace
 #ifndef WIN32
   void deleteMeshDS(SMESHDS_Mesh* meshDS)
   {
-    //cout << "deleteMeshDS( " << meshDS << endl;
     delete meshDS;
   }
 #else
   static void* deleteMeshDS(void* meshDS)
   {
-    //cout << "deleteMeshDS( " << meshDS << endl;
     SMESHDS_Mesh* m = (SMESHDS_Mesh*)meshDS;
     if(m) {
       delete m;
@@ -198,7 +190,7 @@ namespace
 
 SMESH_Mesh::~SMESH_Mesh()
 {
-  if(MYDEBUG) MESSAGE("SMESH_Mesh::~SMESH_Mesh");
+  MESSAGE("SMESH_Mesh::~SMESH_Mesh");
 
   if ( _document ) // avoid destructing _meshDS from ~SMESH_Gen()
     _document->RemoveMesh( _id );
@@ -240,9 +232,6 @@ SMESH_Mesh::~SMESH_Mesh()
     pthread_t thread;
     int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_meshDS);
 #endif
-
-  fs::remove_all(tmp_folder);
-
   }
 }
 
@@ -285,7 +274,7 @@ SMESH_Mesh* SMESH_Mesh::FindMesh( int meshId ) const
 
 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
 {
-  if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
+  MESSAGE("SMESH_Mesh::ShapeToMesh");
 
   if ( !aShape.IsNull() && _isShapeToMesh ) {
     if ( aShape.ShapeType() != TopAbs_COMPOUND && // group contents is allowed to change
@@ -539,10 +528,12 @@ int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
   myReader.SetFile(theFileName);
   myReader.SetMeshName(theMeshName);
   Driver_Mesh::Status status = myReader.Perform();
-#ifdef _DEBUG_
-  SMESH_ComputeErrorPtr er = myReader.GetError();
-  if ( er && !er->IsOK() ) std::cout << er->myComment << std::endl;
-#endif
+
+  if (SALOME::VerbosityActivated())
+  {
+    SMESH_ComputeErrorPtr er = myReader.GetError();
+    if ( er && !er->IsOK() ) std::cout << er->myComment << std::endl;
+  }
 
   // Reading groups (sub-meshes are out of scope of MED import functionality)
   std::list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
@@ -647,7 +638,7 @@ SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
                           int                  anHypId,
                           std::string*         anError  )
 {
-  if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
+  MESSAGE("SMESH_Mesh::AddHypothesis");
 
   if ( anError )
     anError->clear();
@@ -671,7 +662,7 @@ SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
     std::string hypName = anHyp->GetName();
     if ( hypName == "NotConformAllowed" )
     {
-      if(MYDEBUG) MESSAGE( "Hypothesis <NotConformAllowed> can be only global" );
+      MESSAGE( "Hypothesis <NotConformAllowed> can be only global" );
       return SMESH_Hypothesis::HYP_INCOMPATIBLE;
     }
   }
@@ -726,8 +717,8 @@ SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
   HasModificationsToDiscard(); // to reset _isModified flag if a mesh becomes empty
   GetMeshDS()->Modified();
 
-  if(MYDEBUG) subMesh->DumpAlgoState(true);
-  if(MYDEBUG) SCRUTE(ret);
+  if(SALOME::VerbosityActivated()) subMesh->DumpAlgoState(true);
+  SCRUTE(ret);
   return ret;
 }
 
@@ -741,14 +732,14 @@ SMESH_Hypothesis::Hypothesis_Status
 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
                              int                    anHypId)
 {
-  if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
+  MESSAGE("SMESH_Mesh::RemoveHypothesis");
 
   StudyContextStruct *sc = _gen->GetStudyContext();
   if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
     throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
 
   SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
-  if(MYDEBUG) { SCRUTE(anHyp->GetType()); }
+  SCRUTE(anHyp->GetType());
 
   // shape
 
@@ -796,8 +787,8 @@ SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
   HasModificationsToDiscard(); // to reset _isModified flag if mesh become empty
   GetMeshDS()->Modified();
 
-  if(MYDEBUG) subMesh->DumpAlgoState(true);
-  if(MYDEBUG) SCRUTE(ret);
+  if(SALOME::VerbosityActivated()) subMesh->DumpAlgoState(true);
+  SCRUTE(ret);
   return ret;
 }
 
@@ -1696,6 +1687,51 @@ void SMESH_Mesh::ExportCGNS(const char *        file,
   if ( res != Driver_Mesh::DRS_OK )
     throw SALOME_Exception("Export failed");
 }
+//================================================================================
+/*!
+ * \brief Export the mesh to the StructuredCGNS file
+ */
+//================================================================================
+
+void SMESH_Mesh::ExportStructuredCGNS(const char * file, const SMESHDS_Mesh* meshPart, const char * meshName)
+{
+
+  int res = Driver_Mesh::DRS_OK;
+  SMESH_TRY;
+
+#ifdef WITH_CGNS
+  auto myMesh =  meshPart ? (SMESHDS_Mesh*) meshPart : _meshDS;
+  
+  if ( myMesh->HasSomeStructuredGridFilled() )
+  {
+    DriverStructuredCGNS_Write writer;
+    writer.SetFile( file );
+    writer.SetMesh( const_cast<SMESHDS_Mesh*>( myMesh ));
+    writer.SetMeshName( SMESH_Comment("Mesh_") << myMesh->GetPersistentId());
+    if ( meshName && meshName[0] )
+      writer.SetMeshName( meshName );
+
+    res = writer.Perform();
+    if ( res != Driver_Mesh::DRS_OK )
+    {
+      SMESH_ComputeErrorPtr err = writer.GetError();
+      if ( err && !err->IsOK() && !err->myComment.empty() )
+        throw SALOME_Exception(("Export failed: " + err->myComment ).c_str() );
+    }
+  }
+
+#endif
+  SMESH_CATCH( SMESH::throwSalomeEx );
+
+  if ( res == Driver_Mesh::DRS_TOO_LARGE_MESH )
+  {
+    std::cout << "\n\n\n Going into too large mesh file path\n\n\n\n";
+    throw TooLargeForExport("CGNS");
+  }
+
+  if ( res != Driver_Mesh::DRS_OK )
+    throw SALOME_Exception("Export failed");
+}
 
 //================================================================================
 /*!
@@ -1757,9 +1793,8 @@ double SMESH_Mesh::GetComputeProgress() const
         rate = algo->GetProgress();
       }
       catch (...) {
-#ifdef _DEBUG_
-        std::cerr << "Exception in " << algo->GetName() << "::GetProgress()" << std::endl;
-#endif
+        if (SALOME::VerbosityActivated())
+          std::cerr << "Exception in " << algo->GetName() << "::GetProgress()" << std::endl;
       }
       if ( 0. < rate && rate < 1.001 )
       {
@@ -1770,7 +1805,6 @@ double SMESH_Mesh::GetComputeProgress() const
         rate = algo->GetProgressByTic();
         computedCost += algoDoneCost + rate * algoNotDoneCost;
       }
-      // cout << "rate: "<<rate << " algoNotDoneCost: " << algoNotDoneCost << endl;
     }
 
   // get cost of already treated sub-meshes
@@ -1791,9 +1825,6 @@ double SMESH_Mesh::GetComputeProgress() const
       }
     }
   }
-  // cout << "Total: " << totalCost
-  //      << " computed: " << computedCost << " progress: " << computedCost / totalCost
-  //      << " nbElems: " << GetMeshDS()->GetMeshInfo().NbElements() << endl;
   return computedCost / totalCost;
 }
 
@@ -2036,7 +2067,7 @@ int SMESH_Mesh::NbMeshes() const // nb meshes in the Study
 
 bool SMESH_Mesh::IsNotConformAllowed() const
 {
-  if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
+  MESSAGE("SMESH_Mesh::IsNotConformAllowed");
 
   static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
   return GetHypothesis( _meshDS->ShapeToMesh(), filter, false );