+ key = ShapesWithLocalSize.FindIndex(GeomShape);
+ if (GeomType == TopAbs_VERTEX) {
+ VertexId2LocalSize[key] = LocalSize;
+ } else if (GeomType == TopAbs_EDGE) {
+ EdgeId2LocalSize[key] = LocalSize;
+ } else if (GeomType == TopAbs_FACE) {
+ FaceId2LocalSize[key] = LocalSize;
+ } else if (GeomType == TopAbs_SOLID) {
+ SolidId2LocalSize[key] = LocalSize;
+ }
+ return;
+ }
+
+ //================================================================================
+ /*!
+ * \brief Return faceNgID or faceNgID-1 depending on side the given proxy face lies
+ * \param [in] f - proxy face
+ * \param [in] solidSMDSIDs - IDs of SOLIDs sharing the FACE on which face lies
+ * \param [in] faceNgID - NETGEN ID of the FACE
+ * \return int - NETGEN ID of the FACE
+ */
+ //================================================================================
+
+ int getFaceNgID( const SMDS_MeshElement* face,
+ const int * solidSMDSIDs,
+ const int faceNgID )
+ {
+ for ( int i = 0; i < 3; ++i )
+ {
+ const SMDS_MeshNode* n = face->GetNode( i );
+ const int shapeID = n->GetShapeID();
+ if ( shapeID == solidSMDSIDs[0] )
+ return faceNgID - 1;
+ if ( shapeID == solidSMDSIDs[1] )
+ return faceNgID;
+ }
+ std::vector<const SMDS_MeshNode*> fNodes( face->begin_nodes(), face->end_nodes() );
+ std::vector<const SMDS_MeshElement*> vols;
+ if ( SMDS_Mesh::GetElementsByNodes( fNodes, vols, SMDSAbs_Volume ))
+ for ( size_t i = 0; i < vols.size(); ++i )
+ {
+ const int shapeID = vols[i]->GetShapeID();
+ if ( shapeID == solidSMDSIDs[0] )
+ return faceNgID - 1;
+ if ( shapeID == solidSMDSIDs[1] )
+ return faceNgID;
+ }
+ return faceNgID;
+ }
+
+} // namespace
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+NETGENPlugin_Mesher::NETGENPlugin_Mesher (SMESH_Mesh* mesh,
+ const TopoDS_Shape& aShape,
+ const bool isVolume)
+ : _mesh (mesh),
+ _shape (aShape),
+ _isVolume(isVolume),
+ _optimize(true),
+ _fineness(NETGENPlugin_Hypothesis::GetDefaultFineness()),
+ _isViscousLayers2D(false),
+ _chordalError(-1), // means disabled
+ _ngMesh(NULL),
+ _occgeom(NULL),
+ _curShapeIndex(-1),
+ _progressTic(1),
+ _totalTime(1.0),
+ _simpleHyp(NULL),
+ _viscousLayersHyp(NULL),
+ _ptrToMe(NULL)
+{
+ SetDefaultParameters();
+ ShapesWithLocalSize.Clear();
+ VertexId2LocalSize.clear();
+ EdgeId2LocalSize.clear();
+ FaceId2LocalSize.clear();
+ SolidId2LocalSize.clear();
+ ControlPoints.clear();
+ ShapesWithControlPoints.clear();
+}
+
+//================================================================================
+/*!
+ * Destructor
+ */
+//================================================================================
+
+NETGENPlugin_Mesher::~NETGENPlugin_Mesher()
+{
+ if ( _ptrToMe )
+ *_ptrToMe = NULL;
+ _ptrToMe = 0;
+ _ngMesh = NULL;
+}
+
+//================================================================================
+/*!
+ * Set pointer to NETGENPlugin_Mesher* field of the holder, that will be
+ * nullified at destruction of this
+ */
+//================================================================================
+
+void NETGENPlugin_Mesher::SetSelfPointer( NETGENPlugin_Mesher ** ptr )
+{
+ if ( _ptrToMe )
+ *_ptrToMe = NULL;
+
+ _ptrToMe = ptr;
+
+ if ( _ptrToMe )
+ *_ptrToMe = this;
+}
+
+//================================================================================
+/*!
+ * \brief Initialize global NETGEN parameters with default values
+ */
+//================================================================================
+
+void NETGENPlugin_Mesher::SetDefaultParameters()
+{
+ netgen::MeshingParameters& mparams = netgen::mparam;
+ mparams = netgen::MeshingParameters();
+ // maximal mesh edge size
+ mparams.maxh = 0;//NETGENPlugin_Hypothesis::GetDefaultMaxSize();
+ mparams.minh = 0;
+ // minimal number of segments per edge
+ mparams.segmentsperedge = NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge();
+ // rate of growth of size between elements
+ mparams.grading = NETGENPlugin_Hypothesis::GetDefaultGrowthRate();
+ // safety factor for curvatures (elements per radius)
+ mparams.curvaturesafety = NETGENPlugin_Hypothesis::GetDefaultNbSegPerRadius();
+ // create elements of second order
+ mparams.secondorder = NETGENPlugin_Hypothesis::GetDefaultSecondOrder();
+ // quad-dominated surface meshing
+ if (_isVolume)
+ mparams.quad = 0;
+ else
+ mparams.quad = NETGENPlugin_Hypothesis_2D::GetDefaultQuadAllowed();
+ _fineness = NETGENPlugin_Hypothesis::GetDefaultFineness();
+ mparams.uselocalh = NETGENPlugin_Hypothesis::GetDefaultSurfaceCurvature();
+ netgen::merge_solids = NETGENPlugin_Hypothesis::GetDefaultFuseEdges();
+
+#ifdef NETGEN_V6
+
+ mparams.nthreads = std::thread::hardware_concurrency();
+
+ if ( getenv( "SALOME_NETGEN_DISABLE_MULTITHREADING" ))
+ {
+ mparams.nthreads = 1;
+ mparams.parallel_meshing = false;
+ }
+
+#endif
+}
+
+//=============================================================================
+/*!
+ * Pass parameters to NETGEN
+ */
+//=============================================================================
+void NETGENPlugin_Mesher::SetParameters(const NETGENPlugin_Hypothesis* hyp)
+{
+ if (hyp)
+ {
+ netgen::MeshingParameters& mparams = netgen::mparam;
+ // Initialize global NETGEN parameters:
+ // maximal mesh segment size
+ mparams.maxh = hyp->GetMaxSize();
+ // maximal mesh element linear size
+ mparams.minh = hyp->GetMinSize();
+ // minimal number of segments per edge
+ mparams.segmentsperedge = hyp->GetNbSegPerEdge();
+ // rate of growth of size between elements
+ mparams.grading = hyp->GetGrowthRate();
+ // safety factor for curvatures (elements per radius)
+ mparams.curvaturesafety = hyp->GetNbSegPerRadius();
+ // create elements of second order
+ mparams.secondorder = hyp->GetSecondOrder() ? 1 : 0;
+ // quad-dominated surface meshing
+ mparams.quad = hyp->GetQuadAllowed() ? 1 : 0;
+ _optimize = hyp->GetOptimize();
+ _fineness = hyp->GetFineness();
+ mparams.uselocalh = hyp->GetSurfaceCurvature();
+ netgen::merge_solids = hyp->GetFuseEdges();
+ _chordalError = hyp->GetChordalErrorEnabled() ? hyp->GetChordalError() : -1.;
+ mparams.optsteps2d = _optimize ? hyp->GetNbSurfOptSteps() : 0;
+ mparams.optsteps3d = _optimize ? hyp->GetNbVolOptSteps() : 0;
+ mparams.elsizeweight = hyp->GetElemSizeWeight();
+ mparams.opterrpow = hyp->GetWorstElemMeasure();
+ mparams.delaunay = hyp->GetUseDelauney();
+ mparams.checkoverlap = hyp->GetCheckOverlapping();
+ mparams.checkchartboundary = hyp->GetCheckChartBoundary();
+ _simpleHyp = NULL;
+ // mesh size file
+#ifdef NETGEN_V6
+ // std::string
+ mparams.meshsizefilename = hyp->GetMeshSizeFile();
+#else
+ // const char*
+ mparams.meshsizefilename= hyp->GetMeshSizeFile().empty() ? 0 : hyp->GetMeshSizeFile().c_str();
+#endif
+ const NETGENPlugin_Hypothesis::TLocalSize& localSizes = hyp->GetLocalSizesAndEntries();
+ if ( !localSizes.empty() )