Skip to content

Commit

Permalink
update smesh-netgen interface to netgen version 6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
looooo authored and wwmayer committed Oct 11, 2016
1 parent 77cfdff commit 73b6fdf
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 24 deletions.
19 changes: 15 additions & 4 deletions src/3rdParty/salomesmesh/inc/NETGENPlugin_Mesher.hxx
Expand Up @@ -39,10 +39,13 @@
namespace nglib {
#include <nglib.h>
}
#include <meshing.hpp>
#include <occgeom.hpp>

#include <map>
#include <vector>
#include <set>
#include <memory>

class SMESHDS_Mesh;
class SMESH_Comment;
Expand All @@ -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
Expand All @@ -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<nglib::Ng_Mesh> _ngMesh;
#endif

NETGENPlugin_NetgenLibWrapper();
~NETGENPlugin_NetgenLibWrapper();
Expand Down Expand Up @@ -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<netgen::Mesh> _ngMesh;
#endif
netgen::OCCGeometry* _occgeom;

int _curShapeIndex;
Expand Down
89 changes: 73 additions & 16 deletions src/3rdParty/salomesmesh/src/NETGENPlugin/NETGENPlugin_Mesher.cpp
Expand Up @@ -164,7 +164,9 @@ NETGENPlugin_Mesher::~NETGENPlugin_Mesher()
if ( _ptrToMe )
*_ptrToMe = NULL;
_ptrToMe = 0;
#if NETGEN_VERSION < 6
_ngMesh = NULL;
#endif
}

//================================================================================
Expand Down Expand Up @@ -2456,8 +2458,11 @@ bool NETGENPlugin_Mesher::Compute()
// -------------------------
// Generate the mesh
// -------------------------

#if NETGEN_VERSION < 6
_ngMesh = NULL;
// #else
// _ngMesh = std::make_shared<netgen::Mesh>();
#endif
NETGENPlugin_ngMeshInfo initState; // it remembers size of ng mesh equal to size of Smesh

SMESH_Comment comment;
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -2581,14 +2587,19 @@ 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<netgen::Mesh> tmpNgMesh; // = std::make_shared<netgen::Mesh>();
#endif
try
{
OCC_CATCH_SIGNALS;
// compute local H on internal shapes in the main mesh
//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
Expand All @@ -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
Expand All @@ -2614,14 +2630,19 @@ 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;
FillSMesh( intOccgeo, *tmpNgMesh, initState, *_mesh, tmpNodeVec, comment );
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);
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -2710,15 +2736,23 @@ 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
if ( _isViscousLayers2D )
{
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 );
Expand All @@ -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
Expand All @@ -2753,14 +2791,14 @@ bool NETGENPlugin_Mesher::Compute()
try
{
OCC_CATCH_SIGNALS;

#if NETGEN_VERSION > 4
err = netgen::OCCGenerateMesh(occgeo, _ngMesh, mparams, startWith, endWith);
#else
err = netgen::OCCGenerateMesh(occgeo, _ngMesh, startWith, endWith, optstr);
#endif
if(netgen::multithread.terminate)
return false;

comment << text (err);
}
catch (Standard_Failure& ex)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<netgen::Mesh> ngMesh = NULL;
#else
#if NETGEN_VERSION < 6
netgen::Mesh *ngMesh = NULL;
#else
std::shared_ptr<netgen::Mesh> ngMesh; // = std::make_shared<netgen::Mesh>();
#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
Expand All @@ -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 ));
Expand Down Expand Up @@ -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<Ng_Mesh>();
#endif
}

//================================================================================
Expand All @@ -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();
Expand All @@ -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<Ng_Mesh>(mesh);
#endif
}

Expand Down
Expand Up @@ -46,6 +46,8 @@ namespace nglib {
}
#include <meshing.hpp>

#include <iostream>

using namespace std;

//=============================================================================
Expand Down
Expand Up @@ -47,6 +47,7 @@
#include <utilities.h>

#include <list>
#include <memory>
#include <vector>
#include <limits>

Expand Down Expand Up @@ -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 );
Expand All @@ -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:
Expand Down Expand Up @@ -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<netgen::Mesh> 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;
Expand Down

0 comments on commit 73b6fdf

Please sign in to comment.