From 73b6fdfed772d6c1ff5be83f2f20ee508b3ede6d Mon Sep 17 00:00:00 2001 From: looooo Date: Wed, 14 Sep 2016 22:42:52 +0200 Subject: [PATCH] update smesh-netgen interface to netgen version 6.1 --- .../salomesmesh/inc/NETGENPlugin_Mesher.hxx | 19 +++- .../src/NETGENPlugin/NETGENPlugin_Mesher.cpp | 89 +++++++++++++++---- .../NETGENPlugin/NETGENPlugin_NETGEN_2D.cpp | 2 + .../NETGENPlugin_NETGEN_2D_ONLY.cpp | 11 ++- .../NETGENPlugin/NETGENPlugin_NETGEN_3D.cpp | 17 +++- 5 files changed, 114 insertions(+), 24 deletions(-) diff --git a/src/3rdParty/salomesmesh/inc/NETGENPlugin_Mesher.hxx b/src/3rdParty/salomesmesh/inc/NETGENPlugin_Mesher.hxx index a5d0dba1f..fa5e801ce 100644 --- a/src/3rdParty/salomesmesh/inc/NETGENPlugin_Mesher.hxx +++ b/src/3rdParty/salomesmesh/inc/NETGENPlugin_Mesher.hxx @@ -39,10 +39,13 @@ namespace nglib { #include } +#include +#include #include #include #include +#include class SMESHDS_Mesh; class SMESH_Comment; @@ -53,10 +56,10 @@ class TopoDS_Shape; class NETGENPlugin_Hypothesis; class NETGENPlugin_SimpleHypothesis_2D; class NETGENPlugin_Internals; -namespace netgen { - class OCCGeometry; - class Mesh; -} +// namespace netgen { +// class OCCGeometry; +// class Mesh; +// } //============================================================================= /*! * \brief Struct storing nb of entities in netgen mesh @@ -82,7 +85,11 @@ struct NETGENPlugin_ngMeshInfo struct NETGENPLUGIN_EXPORT NETGENPlugin_NetgenLibWrapper { bool _isComputeOk; +#if NETGEN_VERSION < 6 nglib::Ng_Mesh * _ngMesh; +#else + std::shared_ptr _ngMesh; +#endif NETGENPlugin_NetgenLibWrapper(); ~NETGENPlugin_NetgenLibWrapper(); @@ -197,7 +204,11 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_Mesher bool _optimize; int _fineness; bool _isViscousLayers2D; +#if NETGEN_VERSION < 6 netgen::Mesh* _ngMesh; +#else + std::shared_ptr _ngMesh; +#endif netgen::OCCGeometry* _occgeom; int _curShapeIndex; diff --git a/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_Mesher.cpp b/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_Mesher.cpp index b33ca154b..c4fdf588c 100644 --- a/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_Mesher.cpp +++ b/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_Mesher.cpp @@ -164,7 +164,9 @@ NETGENPlugin_Mesher::~NETGENPlugin_Mesher() if ( _ptrToMe ) *_ptrToMe = NULL; _ptrToMe = 0; +#if NETGEN_VERSION < 6 _ngMesh = NULL; +#endif } //================================================================================ @@ -2456,8 +2458,11 @@ bool NETGENPlugin_Mesher::Compute() // ------------------------- // Generate the mesh // ------------------------- - +#if NETGEN_VERSION < 6 _ngMesh = NULL; +// #else +// _ngMesh = std::make_shared(); +#endif NETGENPlugin_ngMeshInfo initState; // it remembers size of ng mesh equal to size of Smesh SMESH_Comment comment; @@ -2501,6 +2506,7 @@ bool NETGENPlugin_Mesher::Compute() try { OCC_CATCH_SIGNALS; + #if NETGEN_VERSION > 4 err = netgen::OCCGenerateMesh(occgeo, _ngMesh, mparams, startWith, endWith); #else @@ -2518,7 +2524,7 @@ bool NETGENPlugin_Mesher::Compute() err = 0; //- MESHCONST_ANALYSE isn't so important step if ( !_ngMesh ) return false; - ngLib.setMesh(( Ng_Mesh*) _ngMesh ); + ngLib.setMesh(( Ng_Mesh*) _ngMesh.get() ); _ngMesh->ClearFaceDescriptors(); // we make descriptors our-self @@ -2581,7 +2587,11 @@ bool NETGENPlugin_Mesher::Compute() intOccgeo.shape = occgeo.shape; intOccgeo.face_maxh.SetSize(intOccgeo.fmap.Extent()); intOccgeo.face_maxh = netgen::mparam.maxh; +#if NETGEN_VERSION < 6 netgen::Mesh *tmpNgMesh = NULL; +#else + std::shared_ptr tmpNgMesh; // = std::make_shared(); +#endif try { OCC_CATCH_SIGNALS; @@ -2589,6 +2599,7 @@ bool NETGENPlugin_Mesher::Compute() //OCCSetLocalMeshSize(intOccgeo, *_ngMesh); it deletes _ngMesh->localH // let netgen create a temporary mesh + #if NETGEN_VERSION > 4 netgen::OCCGenerateMesh(intOccgeo, tmpNgMesh, mparams, startWith, endWith); #else @@ -2598,10 +2609,15 @@ bool NETGENPlugin_Mesher::Compute() return false; // copy LocalH from the main to temporary mesh +#if NETGEN_VERSION < 6 initState.transferLocalH( _ngMesh, tmpNgMesh ); - +#else + initState.transferLocalH( _ngMesh.get(), tmpNgMesh.get() ); +#endif // compute mesh on internal edges startWith = endWith = netgen::MESHCONST_MESHEDGES; + + #if NETGEN_VERSION > 4 err = netgen::OCCGenerateMesh(intOccgeo, tmpNgMesh, mparams, startWith, endWith); #else @@ -2614,7 +2630,11 @@ bool NETGENPlugin_Mesher::Compute() comment << text(ex); err = 1; } +#if NETGEN_VERSION < 6 initState.restoreLocalH( tmpNgMesh ); +#else + initState.restoreLocalH( tmpNgMesh.get() ); +#endif // fill SMESH by netgen mesh vector< const SMDS_MeshNode* > tmpNodeVec; @@ -2622,6 +2642,7 @@ bool NETGENPlugin_Mesher::Compute() err = ( err || !comment.empty() ); #if NETGEN_VERSION > 5 + // nglib::Ng_DeleteMesh((nglib::Ng_Mesh*)tmpNgMesh.get()); tmpNgMesh.reset(); #else nglib::Ng_DeleteMesh((nglib::Ng_Mesh*)tmpNgMesh); @@ -2634,7 +2655,11 @@ bool NETGENPlugin_Mesher::Compute() err = ! ( FillNgMesh(occgeo, *_ngMesh, nodeVec, meshedSM[ MeshDim_0D ]) && FillNgMesh(occgeo, *_ngMesh, nodeVec, meshedSM[ MeshDim_1D ], &quadHelper)); } +#if NETGEN_VERSION < 6 initState = NETGENPlugin_ngMeshInfo(_ngMesh); +#else + initState = NETGENPlugin_ngMeshInfo(_ngMesh.get()); +#endif // Compute 1d mesh if (!err) @@ -2643,6 +2668,7 @@ bool NETGENPlugin_Mesher::Compute() try { OCC_CATCH_SIGNALS; + #if NETGEN_VERSION > 4 err = netgen::OCCGenerateMesh(occgeo, _ngMesh, mparams, startWith, endWith); #else @@ -2710,7 +2736,11 @@ bool NETGENPlugin_Mesher::Compute() FillSMesh( occgeo, *_ngMesh, initState, *_mesh, nodeVec, comment ); // add segments to faces with internal vertices AddIntVerticesInFaces( occgeo, *_ngMesh, nodeVec, internals ); +#if NETGEN_VERSION < 6 initState = NETGENPlugin_ngMeshInfo(_ngMesh); +#else + initState = NETGENPlugin_ngMeshInfo(_ngMesh.get()); +#endif } // Build viscous layers @@ -2718,7 +2748,11 @@ bool NETGENPlugin_Mesher::Compute() { if ( !internals.hasInternalVertexInFace() ) { FillSMesh( occgeo, *_ngMesh, initState, *_mesh, nodeVec, comment ); +#if NETGEN_VERSION < 6 initState = NETGENPlugin_ngMeshInfo(_ngMesh); +#else + initState = NETGENPlugin_ngMeshInfo(_ngMesh.get()); +#endif } SMESH_ProxyMesh::Ptr viscousMesh; SMESH_MesherHelper helper( *_mesh ); @@ -2744,7 +2778,11 @@ bool NETGENPlugin_Mesher::Compute() if ( !error ) error = SMESH_ComputeError::New(); } +#if NETGEN_VERSION < 6 initState = NETGENPlugin_ngMeshInfo(_ngMesh); +#else + initState = NETGENPlugin_ngMeshInfo(_ngMesh.get()); +#endif } // Let netgen compute 2D mesh @@ -2753,6 +2791,7 @@ bool NETGENPlugin_Mesher::Compute() try { OCC_CATCH_SIGNALS; + #if NETGEN_VERSION > 4 err = netgen::OCCGenerateMesh(occgeo, _ngMesh, mparams, startWith, endWith); #else @@ -2760,7 +2799,6 @@ bool NETGENPlugin_Mesher::Compute() #endif if(netgen::multithread.terminate) return false; - comment << text (err); } catch (Standard_Failure& ex) @@ -2812,7 +2850,12 @@ bool NETGENPlugin_Mesher::Compute() } // fill _ngMesh with faces of sub-meshes err = ! ( FillNgMesh(occgeo, *_ngMesh, nodeVec, meshedSM[ MeshDim_2D ], &quadHelper)); + +#if NETGEN_VERSION < 6 initState = NETGENPlugin_ngMeshInfo(_ngMesh); +#else + initState = NETGENPlugin_ngMeshInfo(_ngMesh.get()); +#endif //toPython( _ngMesh, "/tmp/ngPython.py"); } if (!err && _isVolume) @@ -2832,6 +2875,7 @@ bool NETGENPlugin_Mesher::Compute() } _ngMesh->SetGlobalH (mparams.maxh); mparams.grading = 0.4; + #if NETGEN_VERSION > 4 _ngMesh->CalcLocalH(mparams.grading); #else @@ -2848,13 +2892,18 @@ bool NETGENPlugin_Mesher::Compute() AddIntVerticesInSolids( occgeo, *_ngMesh, nodeVec, internals ); // duplicate mesh faces on internal faces FixIntFaces( occgeo, *_ngMesh, internals ); +#if NETGEN_VERSION < 6 initState = NETGENPlugin_ngMeshInfo(_ngMesh); +#else + initState = NETGENPlugin_ngMeshInfo(_ngMesh.get()); +#endif } // Let netgen compute 3D mesh startWith = endWith = netgen::MESHCONST_MESHVOLUME; try { OCC_CATCH_SIGNALS; + #if NETGEN_VERSION > 4 err = netgen::OCCGenerateMesh(occgeo, _ngMesh, mparams, startWith, endWith); #else @@ -2887,6 +2936,7 @@ bool NETGENPlugin_Mesher::Compute() try { OCC_CATCH_SIGNALS; + #if NETGEN_VERSION > 4 err = netgen::OCCGenerateMesh(occgeo, _ngMesh, mparams, startWith, endWith); #else @@ -3099,16 +3149,17 @@ bool NETGENPlugin_Mesher::Evaluate(MapShapeNbElems& aResMap) // let netgen create _ngMesh and calculate element size on not meshed shapes NETGENPlugin_NetgenLibWrapper ngLib; -#if NETGEN_VERSION > 5 - shared_ptr ngMesh = NULL; -#else +#if NETGEN_VERSION < 6 netgen::Mesh *ngMesh = NULL; +#else + std::shared_ptr ngMesh; // = std::make_shared(); #endif #if NETGEN_VERSION < 5 char *optstr = 0; #endif int startWith = netgen::MESHCONST_ANALYSE; int endWith = netgen::MESHCONST_MESHEDGES; + #if NETGEN_VERSION > 4 int err = netgen::OCCGenerateMesh(occgeo, ngMesh, mparams, startWith, endWith); #else @@ -3117,8 +3168,11 @@ bool NETGENPlugin_Mesher::Evaluate(MapShapeNbElems& aResMap) if(netgen::multithread.terminate) return false; - - ngLib.setMesh(( Ng_Mesh*) ngMesh ); +#if NETGEN_VERSION < 6 + ngLib.setMesh(( Ng_Mesh*) ngMesh); +#else + ngLib.setMesh(( Ng_Mesh*) ngMesh.get()); +#endif if (err) { if ( SMESH_subMesh* sm = _mesh->GetSubMeshContaining( _shape )) sm->GetComputeError().reset( new SMESH_ComputeError( COMPERR_ALGO_FAILED )); @@ -3976,8 +4030,11 @@ NETGENPlugin_NetgenLibWrapper::NETGENPlugin_NetgenLibWrapper() std::cout.rdbuf( netgen::mycout->rdbuf() ); #endif } - +#if NETGEN_VERSION < 6 _ngMesh = Ng_NewMesh(); +#else + _ngMesh = std::make_shared(); +#endif } //================================================================================ @@ -3988,10 +4045,10 @@ NETGENPlugin_NetgenLibWrapper::NETGENPlugin_NetgenLibWrapper() NETGENPlugin_NetgenLibWrapper::~NETGENPlugin_NetgenLibWrapper() { -#if NETGEN_VERSION > 5 - _ngMesh.reset(); -#else +#if NETGEN_VERSION < 6 Ng_DeleteMesh( _ngMesh ); +#else + _ngMesh.reset(); #endif Ng_Exit(); NETGENPlugin_Mesher::RemoveTmpFiles(); @@ -4012,11 +4069,11 @@ NETGENPlugin_NetgenLibWrapper::~NETGENPlugin_NetgenLibWrapper() void NETGENPlugin_NetgenLibWrapper::setMesh( Ng_Mesh* mesh ) { if ( _ngMesh ) -#if NETGEN_VERSION > 5 - _ngMesh.reset(mesh); -#else +#if NETGEN_VERSION < 6 Ng_DeleteMesh( _ngMesh ); _ngMesh = mesh; +#else + _ngMesh = std::make_shared(mesh); #endif } diff --git a/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cpp b/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cpp index 6e52d3ecc..f1a6693ea 100644 --- a/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cpp +++ b/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_2D.cpp @@ -46,6 +46,8 @@ namespace nglib { } #include +#include + using namespace std; //============================================================================= diff --git a/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cpp b/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cpp index 9b6beec1e..a2221af54 100644 --- a/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cpp +++ b/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cpp @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -234,7 +235,6 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, { netgen::multithread.terminate = 0; //netgen::multithread.task = "Surface meshing"; - SMESHDS_Mesh* meshDS = aMesh.GetMeshDS(); SMESH_MesherHelper helper(aMesh); helper.SetElementsOnShape( true ); @@ -243,7 +243,11 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, ngLib._isComputeOk = false; netgen::Mesh ngMeshNoLocSize; +#if NETGEN_VERSION < 6 netgen::Mesh * ngMeshes[2] = { (netgen::Mesh*) ngLib._ngMesh, & ngMeshNoLocSize }; +#else + netgen::Mesh * ngMeshes[2] = { (netgen::Mesh*) ngLib._ngMesh.get(), & ngMeshNoLocSize }; +#endif netgen::OCCGeometry occgeoComm; // min / max sizes are set as follows: @@ -474,7 +478,10 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, try { OCC_CATCH_SIGNALS; -#if NETGEN_VERSION > 4 +#if NETGEN_VERSION >=6 + std::shared_ptr mesh_ptr(ngMesh, [](netgen::Mesh*){}); + err = netgen::OCCGenerateMesh(occgeom, mesh_ptr, netgen::mparam, startWith, endWith); +#elif NETGEN_VERSION > 4 err = netgen::OCCGenerateMesh(occgeom, ngMesh, netgen::mparam, startWith, endWith); #else char *optstr = 0; diff --git a/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cpp b/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cpp index d4600a129..97deb8606 100644 --- a/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cpp +++ b/src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cpp @@ -75,7 +75,9 @@ namespace nglib { #include } namespace netgen { -#if NETGEN_VERSION > 4 +#if NETGEN_VERSION > 5 + DLL_HEADER extern int OCCGenerateMesh (OCCGeometry&, shared_ptr&, MeshingParameters&, int, int); +#elif NETGEN_VERSION > 4 DLL_HEADER extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, MeshingParameters&, int, int); #else DLL_HEADER extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, int, int, char*); @@ -208,7 +210,11 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, int Netgen_triangle[3]; NETGENPlugin_NetgenLibWrapper ngLib; +#if NETGEN_VERSION < 6 Ng_Mesh * Netgen_mesh = ngLib._ngMesh; +#else + Ng_Mesh * Netgen_mesh = ngLib._ngMesh.get(); +#endif // vector of nodes in which node index == netgen ID vector< const SMDS_MeshNode* > nodeVec; @@ -470,7 +476,10 @@ bool NETGENPlugin_NETGEN_3D::compute(SMESH_Mesh& aMesh, { OCC_CATCH_SIGNALS; -#if NETGEN_VERSION > 4 +#if NETGEN_VERSION >=6 + std::shared_ptr mesh_ptr(ngMesh, [](netgen::Mesh*){}); + err = netgen::OCCGenerateMesh(occgeo, mesh_ptr, netgen::mparam, startWith, endWith); +#elif NETGEN_VERSION > 4 ngMesh->CalcLocalH(netgen::mparam.grading); err = netgen::OCCGenerateMesh(occgeo, ngMesh, netgen::mparam, startWith, endWith); #else @@ -595,7 +604,11 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, int Netgen_tetrahedron[4]; NETGENPlugin_NetgenLibWrapper ngLib; +#if NETGEN_VERSION < 6 Ng_Mesh * Netgen_mesh = ngLib._ngMesh; +#else + Ng_Mesh * Netgen_mesh = ngLib._ngMesh.get(); +#endif SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( aMesh )); if ( aMesh.NbQuadrangles() > 0 )