From cce42b80fd26a2f361bc4c9248e0df5c18deb4fe Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 22 Feb 2011 14:32:46 +0000 Subject: [PATCH] Restore lost modifications done for 0020748: Add Gradation in Netgen 2D hypothesis --- src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx | 234 ++++++++++---------- src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx | 15 +- 2 files changed, 124 insertions(+), 125 deletions(-) diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx index 4ab0a21..8bec2ec 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx @@ -30,7 +30,7 @@ // #include "NETGENPlugin_NETGEN_3D.hxx" -#include "NETGENPlugin_Mesher.hxx" +#include "NETGENPlugin_Hypothesis.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" @@ -39,10 +39,10 @@ #include "SMESH_ControlsDef.hxx" #include "SMESH_Gen.hxx" #include "SMESH_Mesh.hxx" -#include "SMESH_MeshEditor.hxx" #include "SMESH_MesherHelper.hxx" -#include "StdMeshers_MaxElementVolume.hxx" +#include "SMESH_MeshEditor.hxx" #include "StdMeshers_QuadToTriaAdaptor.hxx" +#include "StdMeshers_MaxElementVolume.hxx" #include "StdMeshers_ViscousLayers.hxx" #include @@ -66,13 +66,16 @@ Netgen include files */ -#ifndef OCCGEOMETRY #define OCCGEOMETRY -#endif #include namespace nglib { #include } +namespace netgen { + extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, int, int, char*); + extern MeshingParameters mparam; + extern volatile multithreadt multithread; +} using namespace nglib; using namespace std; @@ -82,18 +85,22 @@ using namespace std; */ //============================================================================= -NETGENPlugin_NETGEN_3D::NETGENPlugin_NETGEN_3D(int hypId, int studyId, SMESH_Gen* gen) +NETGENPlugin_NETGEN_3D::NETGENPlugin_NETGEN_3D(int hypId, int studyId, + SMESH_Gen* gen) : SMESH_3D_Algo(hypId, studyId, gen) { MESSAGE("NETGENPlugin_NETGEN_3D::NETGENPlugin_NETGEN_3D"); _name = "NETGEN_3D"; _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type _compatibleHypothesis.push_back("MaxElementVolume"); + _compatibleHypothesis.push_back("NETGEN_Parameters"); _compatibleHypothesis.push_back("ViscousLayers"); _maxElementVolume = 0.; _hypMaxElementVolume = NULL; + _hypParameters = NULL; + _viscousLayersHyp = NULL; _requireShape = false; // can work without shape } @@ -122,9 +129,13 @@ bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh& aMesh, MESSAGE("NETGENPlugin_NETGEN_3D::CheckHypothesis"); _hypMaxElementVolume = NULL; - _viscousLayersHyp = NULL; + _hypParameters = NULL; + _viscousLayersHyp = NULL; _maxElementVolume = DBL_MAX; + list::const_iterator itl; + const SMESHDS_Hypothesis* theHyp; + const list& hyps = GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliary=*/false); list ::const_iterator h = hyps.begin(); @@ -141,11 +152,16 @@ bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh& aMesh, _hypMaxElementVolume = dynamic_cast< const StdMeshers_MaxElementVolume*> ( *h ); if ( !_viscousLayersHyp ) _viscousLayersHyp = dynamic_cast< const StdMeshers_ViscousLayers*> ( *h ); + if ( ! _hypParameters ) + _hypParameters = dynamic_cast< const NETGENPlugin_Hypothesis*> ( *h ); if ( *h != _hypMaxElementVolume && - *h != _viscousLayersHyp ) + *h != _viscousLayersHyp && + *h != _hypParameters) aStatus = HYP_INCOMPATIBLE; } + if ( _hypMaxElementVolume && _hypParameters ) + aStatus = HYP_INCOMPATIBLE; if ( _hypMaxElementVolume ) _maxElementVolume = _hypMaxElementVolume->GetMaxVolume(); @@ -171,13 +187,9 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, helper.SetElementsOnShape( true ); int Netgen_NbOfNodes = 0; - int Netgen_param2ndOrder = 0; - double Netgen_paramFine = 1.; - double Netgen_paramSize = pow( 72, 1/6. ) * pow( _maxElementVolume, 1/3. ); double Netgen_point[3]; int Netgen_triangle[3]; - int Netgen_tetrahedron[4]; NETGENPlugin_NetgenLibWrapper ngLib; Ng_Mesh * Netgen_mesh = ngLib._ngMesh; @@ -187,6 +199,9 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, { const int invalid_ID = -1; + SMESH::Controls::Area areaControl; + SMESH::Controls::TSequenceOfXYZ nodesCoords; + // maps nodes to ng ID typedef map< const SMDS_MeshNode*, int, TIDCompare > TNodeToIDMap; typedef TNodeToIDMap::value_type TN2ID; @@ -297,7 +312,6 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, (netgen::Mesh&) *Netgen_mesh, nodeVec, internals); - Netgen_NbOfNodes = Ng_GetNP(Netgen_mesh); } } @@ -305,42 +319,83 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, // Generate the volume mesh // ------------------------- - Ng_Meshing_Parameters Netgen_param; + return compute( aMesh, helper, nodeVec, Netgen_mesh); +} + +//================================================================================ +/*! + * \brief set parameters and generate the volume mesh + */ +//================================================================================ - Netgen_param.secondorder = Netgen_param2ndOrder; - Netgen_param.fineness = Netgen_paramFine; - Netgen_param.maxh = Netgen_paramSize; +bool NETGENPlugin_NETGEN_3D::compute(SMESH_Mesh& aMesh, + SMESH_MesherHelper& helper, + vector< const SMDS_MeshNode* >& nodeVec, + Ng_Mesh * Netgen_mesh) +{ + netgen::Mesh* ngMesh = (netgen::Mesh*)Netgen_mesh; + int Netgen_NbOfNodes = Ng_GetNP(Netgen_mesh); - Ng_Result status; + char *optstr = 0; + int startWith = netgen::MESHCONST_MESHVOLUME; + int endWith = netgen::MESHCONST_OPTVOLUME; + int err = 1; - try { + NETGENPlugin_Mesher aMesher( &aMesh, helper.GetSubShape(), /*isVolume=*/true ); + netgen::OCCGeometry occgeo; + + if ( _hypParameters ) + { + aMesher.SetParameters( _hypParameters ); + if ( !_hypParameters->GetOptimize() ) + endWith = netgen::MESHCONST_MESHVOLUME; + } + else if ( _hypMaxElementVolume ) + { + netgen::mparam.maxh = pow( 72, 1/6. ) * pow( _maxElementVolume, 1/3. ); + } + else if ( aMesh.HasShapeToMesh() ) + { + aMesher.PrepareOCCgeometry( occgeo, helper.GetSubShape(), aMesh ); + netgen::mparam.maxh = occgeo.GetBoundingBox().Diam()/2; + } + else + { + netgen::Point3d pmin, pmax; + ngMesh->GetBox (pmin, pmax); + netgen::mparam.maxh = Dist(pmin, pmax)/2; + } + + try + { #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 OCC_CATCH_SIGNALS; #endif - status = Ng_GenerateVolumeMesh(Netgen_mesh, &Netgen_param); + ngMesh->CalcLocalH(); + err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); + if ( err ) + error(SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task); } - catch (Standard_Failure& exc) { - error(COMPERR_OCC_EXCEPTION, exc.GetMessageString()); - status = NG_VOLUME_FAILURE; - } - catch (...) { - error("Exception in Ng_GenerateVolumeMesh()"); - status = NG_VOLUME_FAILURE; + catch (Standard_Failure& ex) + { + SMESH_Comment str("Exception in netgen::OCCGenerateMesh()"); + str << " at " << netgen::multithread.task + << ": " << ex.DynamicType()->Name(); + if ( ex.GetMessageString() && strlen( ex.GetMessageString() )) + str << ": " << ex.GetMessageString(); + error(str); } - if ( GetComputeError()->IsOK() ) { - switch ( status ) { - case NG_SURFACE_INPUT_ERROR:error( status, "NG_SURFACE_INPUT_ERROR"); - case NG_VOLUME_FAILURE: error( status, "NG_VOLUME_FAILURE"); - case NG_STL_INPUT_ERROR: error( status, "NG_STL_INPUT_ERROR"); - case NG_SURFACE_FAILURE: error( status, "NG_SURFACE_FAILURE"); - case NG_FILE_NOT_FOUND: error( status, "NG_FILE_NOT_FOUND"); - }; + catch (...) + { + SMESH_Comment str("Exception in netgen::OCCGenerateMesh()"); + str << " at " << netgen::multithread.task; + error(str); } int Netgen_NbOfNodesNew = Ng_GetNP(Netgen_mesh); int Netgen_NbOfTetra = Ng_GetNE(Netgen_mesh); - MESSAGE("End of Volume Mesh Generation. status=" << status << + MESSAGE("End of Volume Mesh Generation. err=" << err << ", nb new nodes: " << Netgen_NbOfNodesNew - Netgen_NbOfNodes << ", nb tetra: " << Netgen_NbOfTetra); @@ -348,16 +403,19 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, // Feed back the SMESHDS with the generated Nodes and Volume Elements // ------------------------------------------------------------------- - if ( status == NG_VOLUME_FAILURE ) + if ( err ) { - SMESH_ComputeErrorPtr err = NETGENPlugin_Mesher::readErrors(nodeVec); - if ( err && !err->myBadElements.empty() ) - error( err ); + SMESH_ComputeErrorPtr ce = NETGENPlugin_Mesher::readErrors(nodeVec); + if ( ce && !ce->myBadElements.empty() ) + error( ce ); } bool isOK = ( /*status == NG_OK &&*/ Netgen_NbOfTetra > 0 );// get whatever built if ( isOK ) { + double Netgen_point[3]; + int Netgen_tetrahedron[4]; + // create and insert new nodes into nodeVec nodeVec.resize( Netgen_NbOfNodesNew + 1, 0 ); int nodeIndex = Netgen_NbOfNodes + 1; @@ -371,14 +429,20 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, for ( int elemIndex = 1; elemIndex <= Netgen_NbOfTetra; ++elemIndex ) { Ng_GetVolumeElement(Netgen_mesh, elemIndex, Netgen_tetrahedron); - helper.AddVolume (nodeVec.at( Netgen_tetrahedron[0] ), - nodeVec.at( Netgen_tetrahedron[1] ), - nodeVec.at( Netgen_tetrahedron[2] ), - nodeVec.at( Netgen_tetrahedron[3] )); + try + { + helper.AddVolume (nodeVec.at( Netgen_tetrahedron[0] ), + nodeVec.at( Netgen_tetrahedron[1] ), + nodeVec.at( Netgen_tetrahedron[2] ), + nodeVec.at( Netgen_tetrahedron[3] )); + } + catch (...) + { + } } } - return (status == NG_OK); + return !err; } //================================================================================ @@ -472,85 +536,9 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, // Generate the volume mesh // ------------------------- - Ng_Meshing_Parameters Netgen_param; - - Netgen_param.secondorder = Netgen_param2ndOrder; - Netgen_param.fineness = Netgen_paramFine; - Netgen_param.maxh = Netgen_paramSize; - - Ng_Result status; - - try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 - OCC_CATCH_SIGNALS; -#endif - status = Ng_GenerateVolumeMesh(Netgen_mesh, &Netgen_param); - } - catch (Standard_Failure& exc) { - error(COMPERR_OCC_EXCEPTION, exc.GetMessageString()); - status = NG_VOLUME_FAILURE; - } - catch (...) { - error("Exception in Ng_GenerateVolumeMesh()"); - status = NG_VOLUME_FAILURE; - } - if ( GetComputeError()->IsOK() ) { - switch ( status ) { - case NG_SURFACE_INPUT_ERROR:error( status, "NG_SURFACE_INPUT_ERROR"); - case NG_VOLUME_FAILURE: error( status, "NG_VOLUME_FAILURE"); - case NG_STL_INPUT_ERROR: error( status, "NG_STL_INPUT_ERROR"); - case NG_SURFACE_FAILURE: error( status, "NG_SURFACE_FAILURE"); - case NG_FILE_NOT_FOUND: error( status, "NG_FILE_NOT_FOUND"); - }; - } - - int Netgen_NbOfNodesNew = Ng_GetNP(Netgen_mesh); - - int Netgen_NbOfTetra = Ng_GetNE(Netgen_mesh); - - MESSAGE("End of Volume Mesh Generation. status=" << status << - ", nb new nodes: " << Netgen_NbOfNodesNew - Netgen_NbOfNodes << - ", nb tetra: " << Netgen_NbOfTetra); - - // ------------------------------------------------------------------- - // Feed back the SMESHDS with the generated Nodes and Volume Elements - // ------------------------------------------------------------------- - - if ( status == NG_VOLUME_FAILURE ) - { - SMESH_ComputeErrorPtr err = NETGENPlugin_Mesher::readErrors(nodeVec); - if ( err && !err->myBadElements.empty() ) - error( err ); - } - - bool isOK = ( Netgen_NbOfTetra > 0 );// get whatever built - if ( isOK ) - { - // create and insert new nodes into nodeVec - nodeVec.resize( Netgen_NbOfNodesNew + 1 ); - int nodeIndex = Netgen_NbOfNodes + 1; - - for ( ; nodeIndex <= Netgen_NbOfNodesNew; ++nodeIndex ) - { - Ng_GetPoint( Netgen_mesh, nodeIndex, Netgen_point ); - nodeVec.at(nodeIndex) = aHelper->AddNode(Netgen_point[0],Netgen_point[1],Netgen_point[2]); - } - - // create tetrahedrons - for ( int elemIndex = 1; elemIndex <= Netgen_NbOfTetra; ++elemIndex ) - { - Ng_GetVolumeElement(Netgen_mesh, elemIndex, Netgen_tetrahedron); - aHelper->AddVolume (nodeVec.at( Netgen_tetrahedron[0] ), - nodeVec.at( Netgen_tetrahedron[1] ), - nodeVec.at( Netgen_tetrahedron[2] ), - nodeVec.at( Netgen_tetrahedron[3] )); - } - } - - return (status == NG_OK); + return compute( aMesh, *aHelper, nodeVec, Netgen_mesh); } - //============================================================================= /*! * @@ -638,3 +626,5 @@ bool NETGENPlugin_NETGEN_3D::Evaluate(SMESH_Mesh& aMesh, return true; } + + diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx index 39cd271..54ba49f 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx @@ -32,16 +32,18 @@ #define _NETGENPlugin_NETGEN_3D_HXX_ #include "NETGENPlugin_Defs.hxx" +#include "NETGENPlugin_Mesher.hxx" #include "SMESH_3D_Algo.hxx" #include "Utils_SALOME_Exception.hxx" class StdMeshers_ViscousLayers; class StdMeshers_MaxElementVolume; +class NETGENPlugin_Hypothesis; class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_3D: public SMESH_3D_Algo { -public: + public: NETGENPlugin_NETGEN_3D(int hypId, int studyId, SMESH_Gen* gen); virtual ~NETGENPlugin_NETGEN_3D(); @@ -54,14 +56,21 @@ public: virtual bool Compute(SMESH_Mesh& aMesh, SMESH_MesherHelper* aHelper); - + virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, MapShapeNbElems& aResMap); -protected: + protected: + + bool compute(SMESH_Mesh& mesh, + SMESH_MesherHelper& helper, + vector< const SMDS_MeshNode* >& nodeVec, + nglib::Ng_Mesh* ngMesh); + double _maxElementVolume; + const NETGENPlugin_Hypothesis * _hypParameters; const StdMeshers_MaxElementVolume* _hypMaxElementVolume; const StdMeshers_ViscousLayers* _viscousLayersHyp; }; -- 2.39.2