X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FNETGENPlugin%2FNETGENPlugin_NETGEN_2D_ONLY.cxx;h=16213e86aa9a684bfe210312eae33dc5754e5d2f;hb=refs%2Fheads%2FV9_11_BR;hp=a8b57bea551d4689d786e2d23d6e2c63b2c98fa1;hpb=e7d8354cb48d29960ef8ffc159a3a1559204d928;p=plugins%2Fnetgenplugin.git diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx index a8b57be..16213e8 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -63,13 +63,11 @@ namespace nglib { #include //#include namespace netgen { -#ifdef NETGEN_V5 - extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, MeshingParameters&, int, int); -#else - extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, int, int, char*); -#endif + NETGENPLUGIN_DLL_HEADER extern MeshingParameters mparam; +#ifdef NETGEN_V5 extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh); +#endif } using namespace std; @@ -78,17 +76,16 @@ using namespace nglib; //============================================================================= /*! - * + * */ //============================================================================= NETGENPlugin_NETGEN_2D_ONLY::NETGENPlugin_NETGEN_2D_ONLY(int hypId, - int studyId, SMESH_Gen* gen) - : SMESH_2D_Algo(hypId, studyId, gen) + : SMESH_2D_Algo(hypId, gen) { _name = "NETGEN_2D_ONLY"; - + _shapeType = (1 << TopAbs_FACE);// 1 bit /shape type _onlyUnaryInput = false; // treat all FACEs at once @@ -106,18 +103,18 @@ NETGENPlugin_NETGEN_2D_ONLY::NETGENPlugin_NETGEN_2D_ONLY(int hypId, //============================================================================= /*! - * + * */ //============================================================================= NETGENPlugin_NETGEN_2D_ONLY::~NETGENPlugin_NETGEN_2D_ONLY() { - MESSAGE("NETGENPlugin_NETGEN_2D_ONLY::~NETGENPlugin_NETGEN_2D_ONLY"); + //MESSAGE("NETGENPlugin_NETGEN_2D_ONLY::~NETGENPlugin_NETGEN_2D_ONLY"); } //============================================================================= /*! - * + * */ //============================================================================= @@ -167,7 +164,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::CheckHypothesis (SMESH_Mesh& aMesh, int nbHyps = bool(_hypMaxElementArea) + bool(_hypLengthFromEdges) + bool(_hypParameters ); if ( nbHyps > 1 ) - aStatus = HYP_CONCURENT; + aStatus = HYP_CONCURRENT; else if ( hasVL ) error( StdMeshers_ViscousLayers2D::CheckHypothesis( aMesh, aShape, aStatus )); else @@ -184,41 +181,41 @@ bool NETGENPlugin_NETGEN_2D_ONLY::CheckHypothesis (SMESH_Mesh& aMesh, return ( aStatus == HYP_OK ); } -namespace -{ - void limitSize( netgen::Mesh* ngMesh, - const double maxh ) - { - // get bnd box - netgen::Point3d pmin, pmax; - ngMesh->GetBox( pmin, pmax, 0 ); - const double dx = pmax.X() - pmin.X(); - const double dy = pmax.Y() - pmin.Y(); - const double dz = pmax.Z() - pmin.Z(); - - const int nbX = Max( 2, int( dx / maxh * 3 )); - const int nbY = Max( 2, int( dy / maxh * 3 )); - const int nbZ = Max( 2, int( dz / maxh * 3 )); - - if ( ! & ngMesh->LocalHFunction() ) - ngMesh->SetLocalH( pmin, pmax, 0.1 ); - - netgen::Point3d p; - for ( int i = 0; i <= nbX; ++i ) - { - p.X() = pmin.X() + i * dx / nbX; - for ( int j = 0; j <= nbY; ++j ) - { - p.Y() = pmin.Y() + j * dy / nbY; - for ( int k = 0; k <= nbZ; ++k ) - { - p.Z() = pmin.Z() + k * dz / nbZ; - ngMesh->RestrictLocalH( p, maxh ); - } - } - } - } -} +// namespace +// { +// void limitSize( netgen::Mesh* ngMesh, +// const double maxh ) +// { +// // get bnd box +// netgen::Point3d pmin, pmax; +// ngMesh->GetBox( pmin, pmax, 0 ); +// const double dx = pmax.X() - pmin.X(); +// const double dy = pmax.Y() - pmin.Y(); +// const double dz = pmax.Z() - pmin.Z(); + +// const int nbX = Max( 2, int( dx / maxh * 3 )); +// const int nbY = Max( 2, int( dy / maxh * 3 )); +// const int nbZ = Max( 2, int( dz / maxh * 3 )); + +// if ( ! & ngMesh->LocalHFunction() ) +// ngMesh->SetLocalH( pmin, pmax, 0.1 ); + +// netgen::Point3d p; +// for ( int i = 0; i <= nbX; ++i ) +// { +// p.X() = pmin.X() + i * dx / nbX; +// for ( int j = 0; j <= nbY; ++j ) +// { +// p.Y() = pmin.Y() + j * dy / nbY; +// for ( int k = 0; k <= nbZ; ++k ) +// { +// p.Z() = pmin.Z() + k * dz / nbZ; +// ngMesh->RestrictLocalH( p, maxh ); +// } +// } +// } +// } +// } //============================================================================= /*! @@ -284,22 +281,30 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, netgen::mparam.minh = aMesher.GetDefaultMinSize( aShape, netgen::mparam.maxh ); } // set local size depending on curvature and NOT closeness of EDGEs +#ifdef NETGEN_V6 + const double factor = 2; //netgen::occparam.resthcloseedgefac; +#else + const double factor = netgen::occparam.resthcloseedgefac; netgen::occparam.resthcloseedgeenable = false; - //netgen::occparam.resthcloseedgefac = 1.0 + netgen::mparam.grading; + netgen::occparam.resthcloseedgefac = 1.0 + netgen::mparam.grading; +#endif occgeoComm.face_maxh = netgen::mparam.maxh; +#ifdef NETGEN_V6 + netgen::OCCParameters occparam; + netgen::OCCSetLocalMeshSize( occgeoComm, *ngMeshes[0], netgen::mparam, occparam ); +#else netgen::OCCSetLocalMeshSize( occgeoComm, *ngMeshes[0] ); +#endif occgeoComm.emap.Clear(); occgeoComm.vmap.Clear(); // set local size according to size of existing segments - const double factor = netgen::occparam.resthcloseedgefac; TopTools_IndexedMapOfShape edgeMap; TopExp::MapShapes( aMesh.GetShapeToMesh(), TopAbs_EDGE, edgeMap ); for ( int iE = 1; iE <= edgeMap.Extent(); ++iE ) { const TopoDS_Shape& edge = edgeMap( iE ); - if ( SMESH_Algo::isDegenerated( TopoDS::Edge( edge ))/* || - helper.IsSubShape( edge, aShape )*/) + if ( SMESH_Algo::isDegenerated( TopoDS::Edge( edge ))) continue; SMESHDS_SubMesh* smDS = meshDS->MeshElements( edge ); if ( !smDS ) continue; @@ -314,6 +319,15 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, ngMeshes[0]->RestrictLocalH( pi, factor * ( n1 - n2 ).Modulus() ); } } + + // set local size defined on shapes + aMesher.SetLocalSize( occgeoComm, *ngMeshes[0] ); + aMesher.SetLocalSizeForChordalError( occgeoComm, *ngMeshes[0] ); + try { + ngMeshes[0]->LoadLocalMeshSize( mparam.meshsizefilename ); + } catch (NgException & ex) { + return error( COMPERR_BAD_PARMETERS, ex.What() ); + } } netgen::mparam.uselocalh = toOptimize; // restore as it is used at surface optimization @@ -345,10 +359,10 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, // get all EDGEs of a FACE // ------------------------ TSideVector wires = - StdMeshers_FaceSide::GetFaceWires( F, aMesh, ignoreMediumNodes, faceErr, proxyMesh ); + StdMeshers_FaceSide::GetFaceWires( F, aMesh, ignoreMediumNodes, faceErr, &helper, proxyMesh ); if ( faceErr && !faceErr->IsOK() ) continue; - int nbWires = wires.size(); + size_t nbWires = wires.size(); if ( nbWires == 0 ) { faceErr.reset @@ -374,21 +388,21 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, if (_hypLengthFromEdges ) { // compute edgeLength as an average segment length - int nbSegments = 0; - for ( int iW = 0; iW < nbWires; ++iW ) + smIdType nbSegments = 0; + for ( size_t iW = 0; iW < nbWires; ++iW ) { edgeLength += wires[ iW ]->Length(); nbSegments += wires[ iW ]->NbSegments(); } if ( nbSegments ) - edgeLength /= nbSegments; + edgeLength /= double( nbSegments ); netgen::mparam.maxh = edgeLength; } else if ( isDefaultHyp ) { // set edgeLength by a longest segment double maxSeg2 = 0; - for ( int iW = 0; iW < nbWires; ++iW ) + for ( size_t iW = 0; iW < nbWires; ++iW ) { const UVPtStructVec& points = wires[ iW ]->GetUVPtStruct(); if ( points.empty() ) @@ -449,6 +463,13 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, Box<3> bb = occgeom.GetBoundingBox(); bb.Increase (bb.Diam()/10); ngMesh->SetLocalH (bb.PMin(), bb.PMax(), mparam.grading); + aMesher.SetLocalSize( occgeom, *ngMesh ); + aMesher.SetLocalSizeForChordalError( occgeoComm, *ngMesh ); + try { + ngMesh->LoadLocalMeshSize( mparam.meshsizefilename ); + } catch (NgException & ex) { + return error( COMPERR_BAD_PARMETERS, ex.What() ); + } } nodeVec.clear(); @@ -471,12 +492,8 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, try { OCC_CATCH_SIGNALS; -#ifdef NETGEN_V5 - err = netgen::OCCGenerateMesh(occgeom, ngMesh, netgen::mparam, startWith, endWith); -#else - char *optstr = 0; - err = netgen::OCCGenerateMesh(occgeom, ngMesh, startWith, endWith, optstr); -#endif + err = ngLib.GenerateMesh(occgeom, startWith, endWith, ngMesh); + if ( netgen::multithread.terminate ) return false; if ( err ) @@ -498,11 +515,13 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, } if ( err ) { + if ( aMesher.FixFaceMesh( occgeom, *ngMesh, 1 )) + break; if ( iLoop == LOC_SIZE ) { netgen::mparam.minh = netgen::mparam.maxh; netgen::mparam.maxh = 0; - for ( int iW = 0; iW < wires.size(); ++iW ) + for ( size_t iW = 0; iW < wires.size(); ++iW ) { StdMeshers_FaceSidePtr wire = wires[ iW ]; const vector& uvPtVec = wire->GetUVPtStruct(); @@ -535,7 +554,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, int nbNodes = ngMesh->GetNP(); int nbFaces = ngMesh->GetNSE(); - int nbInputNodes = nodeVec.size()-1; + int nbInputNodes = (int) nodeVec.size()-1; nodeVec.resize( nbNodes+1, 0 ); // add nodes @@ -567,11 +586,10 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, } if ( j > elem.GetNP() ) { - SMDS_MeshFace* face = 0; if ( elem.GetType() == TRIG ) - face = helper.AddFace(nodes[0],nodes[1],nodes[2]); + helper.AddFace(nodes[0],nodes[1],nodes[2]); else - face = helper.AddFace(nodes[0],nodes[1],nodes[2],nodes[3]); + helper.AddFace(nodes[0],nodes[1],nodes[2],nodes[3]); } } @@ -634,7 +652,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Evaluate(SMESH_Mesh& aMesh, return false; // collect info from edges - int nb0d = 0, nb1d = 0; + smIdType nb0d = 0, nb1d = 0; bool IsQuadratic = false; bool IsFirst = true; double fullLen = 0.0; @@ -652,9 +670,9 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Evaluate(SMESH_Mesh& aMesh, smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this)); return false; } - std::vector aVec = (*anIt).second; + std::vector aVec = (*anIt).second; nb0d += aVec[SMDSEntity_Node]; - nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]); + nb1d += std::max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]); double aLen = SMESH_Algo::EdgeLength(E); fullLen += aLen; if(IsFirst) { @@ -666,9 +684,9 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Evaluate(SMESH_Mesh& aMesh, // compute edge length double ELen = 0; - if (_hypLengthFromEdges || !_hypLengthFromEdges && !_hypMaxElementArea) { + if (( _hypLengthFromEdges ) || ( !_hypLengthFromEdges && !_hypMaxElementArea )) { if ( nb1d > 0 ) - ELen = fullLen / nb1d; + ELen = fullLen / double( nb1d ); } if ( _hypMaxElementArea ) { double maxArea = _hypMaxElementArea->GetMaxArea(); @@ -686,10 +704,10 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Evaluate(SMESH_Mesh& aMesh, smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated.\nToo small element length",this)); return false; } - int nbFaces = (int) ( anArea / ( ELen*ELen*sqrt(3.) / 4 ) ); - int nbNodes = (int) ( ( nbFaces*3 - (nb1d-1)*2 ) / 6 + 1 ); - std::vector aVec(SMDSEntity_Last); - for(int i=SMDSEntity_Node; i aVec(SMDSEntity_Last); + for(smIdType i=SMDSEntity_Node; i