]> SALOME platform Git repositories - plugins/netgenplugin.git/blobdiff - src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx
Salome HOME
updated copyright message
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_NETGEN_3D.cxx
index b7c6d286e50c7d8179c02173e1bba12c488c2f9d..46897d90b84f924d93a0854a58238f0a0f0c86b4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -32,9 +32,6 @@
 
 #include "NETGENPlugin_Hypothesis.hxx"
 
-// TODO: remove use of netgen_param
-#include "NETGENPlugin_DriverParam.hxx"
-
 #include <SMDS_MeshElement.hxx>
 #include <SMDS_MeshNode.hxx>
 #include <SMESHDS_Mesh.hxx>
@@ -201,19 +198,27 @@ bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh&         aMesh,
  */
 //=============================================================================
 
+
 /**
- * @brief Get an iterator on the Surface element with their orientation
+ * @brief Compute the list of already meshed Surface elements and info
+ *        on their orientation and if they are internal
  *
+ * @param aMesh Global Mesh
+ * @param aShape Shape associated to the mesh
+ * @param proxyMesh pointer to mesh used fo find the elements
+ * @param internals information on internal sub shapes
+ * @param helper helper associated to the mesh
+ * @param listElements map of surface element associated with
+ *                     their orientation and internal status
+ * @return true if their was some error
  */
-
 bool NETGENPlugin_NETGEN_3D::getSurfaceElements(
     SMESH_Mesh&         aMesh,
     const TopoDS_Shape& aShape,
     SMESH_ProxyMesh::Ptr proxyMesh,
     NETGENPlugin_Internals &internals,
     SMESH_MesherHelper &helper,
-    netgen_params &aParams,
-    std::map<const SMDS_MeshElement*, tuple<bool, bool>>& listElements
+    std::map<const SMDS_MeshElement*, tuple<bool, bool>, TIDCompare>& listElements
 )
 {
   SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
@@ -236,7 +241,7 @@ bool NETGENPlugin_NETGEN_3D::getSurfaceElements(
     if ( !aSubMeshDSFace ) continue;
 
     SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
-    if ( aParams._quadraticMesh &&
+    if ( _quadraticMesh &&
           dynamic_cast< const SMESH_ProxyMesh::SubMesh*>( aSubMeshDSFace ))
     {
       // add medium nodes of proxy triangles to helper (#16843)
@@ -249,14 +254,10 @@ bool NETGENPlugin_NETGEN_3D::getSurfaceElements(
       const SMDS_MeshElement* elem = iteratorElem->next();
       // check mesh face
       if ( !elem ){
-        aParams._error = COMPERR_BAD_INPUT_MESH;
-        aParams._comment = "Null element encounters";
-        return true;
+        return error( COMPERR_BAD_INPUT_MESH, "Null element encounters");
       }
       if ( elem->NbCornerNodes() != 3 ){
-        aParams._error = COMPERR_BAD_INPUT_MESH;
-        aParams._comment = "Not triangle element encounters";
-        return true;
+        return error( COMPERR_BAD_INPUT_MESH, "Not triangle element encounters");
       }
       listElements[elem] = tuple(isRev, isInternalFace);
     }
@@ -265,6 +266,18 @@ bool NETGENPlugin_NETGEN_3D::getSurfaceElements(
   return false;
 }
 
+/**
+ * @brief Part of Compute: adding already meshed elements
+ *        into netgen structure
+ *
+ * @param aMesh Global mesh
+ * @param aShape Shape associated with the mesh
+ * @param nodeVec Mapping between nodes mesh id and netgen structure id
+ * @param ngLib Wrapper on netgen lib
+ * @param helper helper assocaited to the mesh
+ * @param Netgen_NbOfNodes Number of nodes in netge structure
+ * @return true if there was some error
+ */
 
 bool NETGENPlugin_NETGEN_3D::computeFillNgMesh(
   SMESH_Mesh&         aMesh,
@@ -272,16 +285,15 @@ bool NETGENPlugin_NETGEN_3D::computeFillNgMesh(
   vector< const SMDS_MeshNode* > &nodeVec,
   NETGENPlugin_NetgenLibWrapper &ngLib,
   SMESH_MesherHelper &helper,
-  netgen_params &aParams,
   int &Netgen_NbOfNodes)
 {
   netgen::multithread.terminate = 0;
   netgen::multithread.task = "Volume meshing";
-  aParams._progressByTic = -1.;
+  _progressByTic = -1.;
 
   SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
 
-  aParams._quadraticMesh = helper.IsQuadraticSubMesh(aShape);
+  _quadraticMesh = helper.IsQuadraticSubMesh(aShape);
   helper.SetElementsOnShape( true );
 
   Netgen_NbOfNodes = 0;
@@ -297,6 +309,8 @@ bool NETGENPlugin_NETGEN_3D::computeFillNgMesh(
     SMESH::Controls::TSequenceOfXYZ nodesCoords;
 
     // maps nodes to ng ID
+    // map must be sorted by ID to ensure that we will have the same number of
+    // 3D element if we recompute
     typedef map< const SMDS_MeshNode*, int, TIDCompare > TNodeToIDMap;
     typedef TNodeToIDMap::value_type                     TN2ID;
     TNodeToIDMap nodeToNetgenID;
@@ -311,10 +325,10 @@ bool NETGENPlugin_NETGEN_3D::computeFillNgMesh(
     bool isInternalFace=false;
 
     SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( aMesh ));
-    if ( aParams._viscousLayersHyp )
+    if ( _viscousLayersHyp )
     {
       netgen::multithread.percent = 3;
-      proxyMesh = aParams._viscousLayersHyp->Compute( aMesh, aShape );
+      proxyMesh = _viscousLayersHyp->Compute( aMesh, aShape );
       if ( !proxyMesh )
         return false;
     }
@@ -326,8 +340,10 @@ bool NETGENPlugin_NETGEN_3D::computeFillNgMesh(
       proxyMesh.reset( Adaptor );
     }
 
-    std::map<const SMDS_MeshElement*, tuple<bool, bool>> listElements;
-    bool ret = getSurfaceElements(aMesh, aShape, proxyMesh, internals, helper, aParams, listElements);
+    // map must be sorted by ID to ensure that we will have the same number of
+    // 3D element if we recompute
+    std::map<const SMDS_MeshElement*, tuple<bool, bool>, TIDCompare> listElements;
+    bool ret = getSurfaceElements(aMesh, aShape, proxyMesh, internals, helper, listElements);
     if(ret)
       return ret;
 
@@ -397,12 +413,21 @@ bool NETGENPlugin_NETGEN_3D::computeFillNgMesh(
   return false;
 }
 
+/**
+ * @brief Part of Compute: Setting the netgen parameters from the Hypothesis
+ *
+ * @param aMesh Global mesh
+ * @param ngLib Wrapper on netgen lib
+ * @param occgeo Mapping between nodes mesh id and netgen structure id
+ * @param helper helper assocaited to the mesh
+ * @param endWith end step of netgen
+ * @return true if there was some error
+ */
 bool NETGENPlugin_NETGEN_3D::computePrepareParam(
   SMESH_Mesh&         aMesh,
   NETGENPlugin_NetgenLibWrapper &ngLib,
   netgen::OCCGeometry &occgeo,
   SMESH_MesherHelper &helper,
-  netgen_params &aParams,
   int &endWith)
 
 {
@@ -413,35 +438,33 @@ bool NETGENPlugin_NETGEN_3D::computePrepareParam(
   NETGENPlugin_Mesher aMesher( &aMesh, helper.GetSubShape(), /*isVolume=*/true );
 
 
-  if ( aParams._hypParameters )
+  if ( _hypParameters )
   {
-    aMesher.SetParameters( aParams._hypParameters );
+    aMesher.SetParameters( _hypParameters );
 
-    if ( !aParams._hypParameters->GetLocalSizesAndEntries().empty() ||
-         !aParams._hypParameters->GetMeshSizeFile().empty() )
+    if ( !_hypParameters->GetLocalSizesAndEntries().empty() ||
+         !_hypParameters->GetMeshSizeFile().empty() )
     {
       if ( ! &ngMesh->LocalHFunction() )
       {
         netgen::Point3d pmin, pmax;
         ngMesh->GetBox( pmin, pmax, 0 );
-        ngMesh->SetLocalH( pmin, pmax, aParams._hypParameters->GetGrowthRate() );
+        ngMesh->SetLocalH( pmin, pmax, _hypParameters->GetGrowthRate() );
       }
       aMesher.SetLocalSize( occgeo, *ngMesh );
 
       try {
         ngMesh->LoadLocalMeshSize( netgen::mparam.meshsizefilename );
       } catch (netgen::NgException & ex) {
-        aParams._error = COMPERR_BAD_PARMETERS;
-        aParams._comment = ex.What();
-        return false;
+        return error( COMPERR_BAD_PARMETERS, ex.What() );
       }
     }
-    if ( !aParams._hypParameters->GetOptimize() )
+    if ( !_hypParameters->GetOptimize() )
       endWith = netgen::MESHCONST_MESHVOLUME;
   }
-  else if ( aParams._hypMaxElementVolume )
+  else if ( _hypMaxElementVolume )
   {
-    netgen::mparam.maxh = pow( 72, 1/6. ) * pow( aParams.maxElementVolume, 1/3. );
+    netgen::mparam.maxh = pow( 72, 1/6. ) * pow( _maxElementVolume, 1/3. );
     // limitVolumeSize( ngMesh, mparam.maxh ); // result is unpredictable
   }
   else if ( aMesh.HasShapeToMesh() )
@@ -456,19 +479,29 @@ bool NETGENPlugin_NETGEN_3D::computePrepareParam(
     netgen::mparam.maxh = Dist(pmin, pmax)/2;
   }
 
-  if ( !aParams._hypParameters && aMesh.HasShapeToMesh() )
+  if ( !_hypParameters && aMesh.HasShapeToMesh() )
   {
     netgen::mparam.minh = aMesher.GetDefaultMinSize( helper.GetSubShape(), netgen::mparam.maxh );
   }
   return false;
 }
 
+/**
+ * @brief Part of Compute: call to the netgen mesher
+ *
+ * @param occgeo netgen geometry structure
+ * @param nodeVec Mapping between nodes mesh id and netgen structure id
+ * @param ngMesh netgen mesh structure
+ * @param ngLib Wrapper on netgen lib
+ * @param startWith starting step of netgen
+ * @param endWith end step of netgen
+ * @return true if there was some error
+ */
 bool NETGENPlugin_NETGEN_3D::computeRunMesher(
   netgen::OCCGeometry &occgeo,
   vector< const SMDS_MeshNode* > &nodeVec,
   netgen::Mesh* ngMesh,
   NETGENPlugin_NetgenLibWrapper &ngLib,
-  netgen_params &aParams,
   int &startWith, int &endWith)
 {
   int err = 1;
@@ -483,8 +516,7 @@ bool NETGENPlugin_NETGEN_3D::computeRunMesher(
     if(netgen::multithread.terminate)
       return false;
     if ( err ){
-      aParams._comment = SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task;
-      return true;
+      error(SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task);
     }
   }
   catch (Standard_Failure& ex)
@@ -494,8 +526,7 @@ bool NETGENPlugin_NETGEN_3D::computeRunMesher(
         << ": " << ex.DynamicType()->Name();
     if ( ex.GetMessageString() && strlen( ex.GetMessageString() ))
       str << ": " << ex.GetMessageString();
-    aParams._comment = str;
-    return true;
+    error(str);
   }
   catch (netgen::NgException& exc)
   {
@@ -503,31 +534,36 @@ bool NETGENPlugin_NETGEN_3D::computeRunMesher(
     if ( strlen( netgen::multithread.task ) > 0 )
       str << " at " << netgen::multithread.task;
     str << ": " << exc.What();
-    aParams._comment = str;
-    return true;
+    error(str);
   }
   catch (...)
   {
     SMESH_Comment str("Exception in  netgen::OCCGenerateMesh()");
     if ( strlen( netgen::multithread.task ) > 0 )
       str << " at " << netgen::multithread.task;
-    aParams._comment = str;
-    return true;
+    error(str);
   }
 
   if ( err )
   {
     SMESH_ComputeErrorPtr ce = NETGENPlugin_Mesher::ReadErrors(nodeVec);
     if ( ce && ce->HasBadElems() ){
-      aParams._error = ce->myName;
-      aParams._comment = ce->myComment;
-      return true;
+      error( ce );
     }
   }
 
   return false;
 }
 
+/**
+ * @brief Part of Compute: Adding new element created by mesher to SMESH_Mesh
+ *
+ * @param nodeVec Mapping between nodes mesh id and netgen structure id
+ * @param ngLib Wrapper on netgen lib
+ * @param helper tool associated to the mesh to add element
+ * @param Netgen_NbOfNodes Number of nodes in netgen structure
+ * @return true if there was some error
+ */
 bool NETGENPlugin_NETGEN_3D::computeFillMesh(
   vector< const SMDS_MeshNode* > &nodeVec,
   NETGENPlugin_NetgenLibWrapper &ngLib,
@@ -574,6 +610,14 @@ bool NETGENPlugin_NETGEN_3D::computeFillMesh(
   return false;
 }
 
+
+/**
+ * @brief Compute mesh associate to shape
+ *
+ * @param aMesh The mesh
+ * @param aShape The shape
+ * @return true fi there are some error
+ */
 bool NETGENPlugin_NETGEN_3D::Compute(
   SMESH_Mesh&         aMesh,
   const TopoDS_Shape& aShape)
@@ -586,30 +630,12 @@ bool NETGENPlugin_NETGEN_3D::Compute(
   int endWith   = netgen::MESHCONST_OPTVOLUME;
   int Netgen_NbOfNodes;
 
-  netgen_params aParams;
-
-  aParams._hypParameters = const_cast<NETGENPlugin_Hypothesis*>(_hypParameters);
-  aParams._hypMaxElementVolume = const_cast<StdMeshers_MaxElementVolume*>(_hypMaxElementVolume);
-  aParams.maxElementVolume = _maxElementVolume;
-  aParams._progressByTic = _progressByTic;
-  aParams._quadraticMesh = _quadraticMesh;
-  aParams._viscousLayersHyp = const_cast<StdMeshers_ViscousLayers*>(_viscousLayersHyp);
-
-  bool ret;
-  ret = computeFillNgMesh(aMesh, aShape, nodeVec, ngLib, helper, aParams, Netgen_NbOfNodes);
-  if(ret)
-    return error( aParams._error, aParams._comment);
+  computeFillNgMesh(aMesh, aShape, nodeVec, ngLib, helper, Netgen_NbOfNodes);
 
   netgen::OCCGeometry occgeo;
-  computePrepareParam(aMesh, ngLib, occgeo, helper, aParams, endWith);
-  ret = computeRunMesher(occgeo, nodeVec, ngLib._ngMesh, ngLib, aParams, startWith, endWith);
-  if(ret){
-    if(aParams._error)
-      return error(aParams._error, aParams._comment);
+  computePrepareParam(aMesh, ngLib, occgeo, helper, endWith);
+  computeRunMesher(occgeo, nodeVec, ngLib._ngMesh, ngLib, startWith, endWith);
 
-    error(aParams._comment);
-    return true;
-  }
   computeFillMesh(nodeVec, ngLib, helper, Netgen_NbOfNodes);
 
   return false;