X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FNETGENPlugin%2FNETGENPlugin_Mesher.cxx;h=a5336548afba6d2df5573e73fa2723d642436a97;hb=bc0818fc4c602b9fc07da44394126e47d3611163;hp=86736d5185f1734c7269b0a97a9f56bcc1198d45;hpb=f5389785da839df275c0bada08cda03a0d7b6368;p=plugins%2Fnetgenplugin.git diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx old mode 100644 new mode 100755 index 86736d5..a533654 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2014 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 @@ -6,7 +6,7 @@ // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -83,11 +83,15 @@ namespace netgen { //extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh); extern MeshingParameters mparam; extern volatile multithreadt multithread; + extern bool merge_solids; } #include #include +#ifdef WIN32 +#include +#endif using namespace nglib; using namespace std; @@ -181,22 +185,24 @@ void NETGENPlugin_Mesher::SetDefaultParameters() { netgen::MeshingParameters& mparams = netgen::mparam; // maximal mesh edge size - mparams.maxh = 0;//NETGENPlugin_Hypothesis::GetDefaultMaxSize(); - mparams.minh = 0; + 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(); + 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() ? 1 : 0; + mparams.secondorder = NETGENPlugin_Hypothesis::GetDefaultSecondOrder(); // quad-dominated surface meshing if (_isVolume) - mparams.quad = 0; + mparams.quad = 0; else - mparams.quad = NETGENPlugin_Hypothesis_2D::GetDefaultQuadAllowed() ? 1 : 0; - _fineness = NETGENPlugin_Hypothesis::GetDefaultFineness(); + mparams.quad = NETGENPlugin_Hypothesis_2D::GetDefaultQuadAllowed(); + _fineness = NETGENPlugin_Hypothesis::GetDefaultFineness(); + mparams.uselocalh = NETGENPlugin_Hypothesis::GetDefaultSurfaceCurvature(); + netgen::merge_solids = NETGENPlugin_Hypothesis::GetDefaultFuseEdges(); } //============================================================================= @@ -239,23 +245,25 @@ void NETGENPlugin_Mesher::SetParameters(const NETGENPlugin_Hypothesis* hyp) netgen::MeshingParameters& mparams = netgen::mparam; // Initialize global NETGEN parameters: // maximal mesh segment size - mparams.maxh = hyp->GetMaxSize(); + mparams.maxh = hyp->GetMaxSize(); // maximal mesh element linear size - mparams.minh = hyp->GetMinSize(); + 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(); + 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; + mparams.secondorder = hyp->GetSecondOrder() ? 1 : 0; // quad-dominated surface meshing // only triangles are allowed for volumic mesh (before realizing IMP 0021676) //if (!_isVolume) - mparams.quad = hyp->GetQuadAllowed() ? 1 : 0; - _optimize = hyp->GetOptimize(); - _fineness = hyp->GetFineness(); + mparams.quad = hyp->GetQuadAllowed() ? 1 : 0; + _optimize = hyp->GetOptimize(); + _fineness = hyp->GetFineness(); + mparams.uselocalh = hyp->GetSurfaceCurvature(); + netgen::merge_solids = hyp->GetFuseEdges(); _simpleHyp = NULL; SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen(); @@ -469,11 +477,8 @@ namespace // { // BRepTools::Clean (shape); try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 OCC_CATCH_SIGNALS; -#endif BRepMesh_IncrementalMesh e(shape, 0.01, true); - } catch (Standard_Failure) { @@ -518,8 +523,9 @@ void NETGENPlugin_Mesher::PrepareOCCgeometry(netgen::OCCGeometry& occgeo, // get root submeshes list< SMESH_subMesh* > rootSM; - if ( SMESH_subMesh* sm = mesh.GetSubMeshContaining( shape )) { - rootSM.push_back( sm ); + const int shapeID = mesh.GetMeshDS()->ShapeToIndex( shape ); + if ( shapeID > 0 ) { // SMESH_subMesh with ID 0 may exist, don't use it! + rootSM.push_back( mesh.GetSubMesh( shape )); } else { for ( TopoDS_Iterator it( shape ); it.More(); it.Next() ) @@ -1282,8 +1288,10 @@ void NETGENPlugin_Mesher::AddIntVerticesInSolids(const netgen::OCCGeometry& #ifdef DUMP_TRIANGLES_SCRIPT // create a python script making a mesh containing triangles added for internal vertices ofstream py(DUMP_TRIANGLES_SCRIPT); - py << "from smesh import * "<< endl - << "m = Mesh(name='triangles')" << endl; + py << "import SMESH"<< endl + << "from salome.smesh import smeshBuilder"< sumH / 100.) + + int( segLen[ i ] > sumH / 100.) + + int( segLen[ iNext ] > sumH / 100.)); + if ( nbSeg > 0 ) + RestrictLocalSize( ngMesh, 0.5*(np1+np2), sumH / nbSeg ); } if ( isInternalWire ) { @@ -2084,6 +2095,39 @@ namespace return str; } + //================================================================================ + /*! + * \brief Looks for triangles lying on a SOLID + */ + //================================================================================ + + bool hasBadElemOnSolid( const list& elems, + SMESH_subMesh* solidSM ) + { + TopTools_IndexedMapOfShape solidSubs; + TopExp::MapShapes( solidSM->GetSubShape(), solidSubs ); + SMESHDS_Mesh* mesh = solidSM->GetFather()->GetMeshDS(); + + list::const_iterator e = elems.begin(); + for ( ; e != elems.end(); ++e ) + { + const SMDS_MeshElement* elem = *e; + if ( elem->GetType() != SMDSAbs_Face ) + continue; + int nbNodesOnSolid = 0; + SMDS_NodeIteratorPtr nIt = elem->nodeIterator(); + while ( nIt->more() ) + { + const SMDS_MeshNode* n = nIt->next(); + const TopoDS_Shape& s = mesh->IndexToShape( n->getshapeId() ); + nbNodesOnSolid += ( !s.IsNull() && solidSubs.Contains( s )); + if ( nbNodesOnSolid > 2 ) + return true; + } + } + return false; + } + const double edgeMeshingTime = 0.001; const double faceMeshingTime = 0.019; const double edgeFaceMeshingTime = edgeMeshingTime + faceMeshingTime; @@ -2110,8 +2154,9 @@ bool NETGENPlugin_Mesher::Compute() " growth rate = " << mparams.grading << "\n" " elements per radius = " << mparams.curvaturesafety << "\n" " second order = " << mparams.secondorder << "\n" - " quad allowed = " << mparams.quad); - //cout << " quad allowed = " << mparams.quad<rdbuf() ); #endif - std::cout.rdbuf( netgen::mycout->rdbuf() ); + } _ngMesh = Ng_NewMesh(); } @@ -3617,7 +3678,8 @@ NETGENPlugin_NetgenLibWrapper::~NETGENPlugin_NetgenLibWrapper() Ng_DeleteMesh( _ngMesh ); Ng_Exit(); NETGENPlugin_Mesher::RemoveTmpFiles(); - std::cout.rdbuf( _coutBuffer ); + if ( _coutBuffer ) + std::cout.rdbuf( _coutBuffer ); #ifdef _DEBUG_ if( _isComputeOk ) #endif @@ -3649,7 +3711,11 @@ std::string NETGENPlugin_NetgenLibWrapper::getOutputFileName() TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str(); aGenericName += "NETGEN_"; +#ifndef WIN32 aGenericName += getpid(); +#else + aGenericName += _getpid(); +#endif aGenericName += "_"; aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString()); aGenericName += ".out"; @@ -3665,20 +3731,20 @@ std::string NETGENPlugin_NetgenLibWrapper::getOutputFileName() void NETGENPlugin_NetgenLibWrapper::removeOutputFile() { - string tmpDir = SALOMEDS_Tool::GetDirFromPath( _outputFileName ); - SALOMEDS::ListOfFileNames_var aFiles = new SALOMEDS::ListOfFileNames; - aFiles->length(1); - std::string aFileName = SALOMEDS_Tool::GetNameFromPath( _outputFileName ) + ".out"; - aFiles[0] = aFileName.c_str(); - if ( netgen::mycout) + if ( !_outputFileName.empty() ) { - delete netgen::mycout; - netgen::mycout = 0; - netgen::myerr = 0; + if ( netgen::mycout ) + { + delete netgen::mycout; + netgen::mycout = 0; + netgen::myerr = 0; + } + string tmpDir = SALOMEDS_Tool::GetDirFromPath ( _outputFileName ); + string aFileName = SALOMEDS_Tool::GetNameFromPath( _outputFileName ) + ".out"; + SALOMEDS::ListOfFileNames_var aFiles = new SALOMEDS::ListOfFileNames; + aFiles->length(1); + aFiles[0] = aFileName.c_str(); + + SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.c_str(), aFiles.in(), true ); } - - SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.c_str(), aFiles.in(), true ); -#ifdef _DEBUG_ - //cout << "NOTE: netgen output log was REMOVED " << _outputFileName << endl; -#endif }