1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : NETGENPlugin_NETGEN_2D_ONLY.cxx
21 // Author : Edward AGAPOV (OCC)
24 #include "NETGENPlugin_NETGEN_2D_ONLY.hxx"
26 #include "NETGENPlugin_Mesher.hxx"
27 #include "NETGENPlugin_Hypothesis_2D.hxx"
29 #include <SMDS_MeshElement.hxx>
30 #include <SMDS_MeshNode.hxx>
31 #include <SMESHDS_Mesh.hxx>
32 #include <SMESH_Comment.hxx>
33 #include <SMESH_Gen.hxx>
34 #include <SMESH_Mesh.hxx>
35 #include <SMESH_MesherHelper.hxx>
36 #include <SMESH_subMesh.hxx>
37 #include <StdMeshers_FaceSide.hxx>
38 #include <StdMeshers_LengthFromEdges.hxx>
39 #include <StdMeshers_MaxElementArea.hxx>
40 #include <StdMeshers_QuadranglePreference.hxx>
41 #include <StdMeshers_ViscousLayers2D.hxx>
43 #include <Precision.hxx>
44 #include <Standard_ErrorHandler.hxx>
45 #include <Standard_Failure.hxx>
47 #include <utilities.h>
62 #include <occgeom.hpp>
63 #include <meshing.hpp>
64 //#include <meshtype.hpp>
67 extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, MeshingParameters&, int, int);
69 extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, int, int, char*);
71 #if defined(NETGEN_V5) && defined(WIN32)
74 extern MeshingParameters mparam;
75 extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh);
79 using namespace netgen;
80 using namespace nglib;
82 //=============================================================================
86 //=============================================================================
88 NETGENPlugin_NETGEN_2D_ONLY::NETGENPlugin_NETGEN_2D_ONLY(int hypId,
90 : SMESH_2D_Algo(hypId, gen)
92 _name = "NETGEN_2D_ONLY";
94 _shapeType = (1 << TopAbs_FACE);// 1 bit /shape type
95 _onlyUnaryInput = false; // treat all FACEs at once
97 _compatibleHypothesis.push_back("MaxElementArea");
98 _compatibleHypothesis.push_back("LengthFromEdges");
99 _compatibleHypothesis.push_back("QuadranglePreference");
100 _compatibleHypothesis.push_back("NETGEN_Parameters_2D");
101 _compatibleHypothesis.push_back("ViscousLayers2D");
103 _hypMaxElementArea = 0;
104 _hypLengthFromEdges = 0;
105 _hypQuadranglePreference = 0;
109 //=============================================================================
113 //=============================================================================
115 NETGENPlugin_NETGEN_2D_ONLY::~NETGENPlugin_NETGEN_2D_ONLY()
117 //MESSAGE("NETGENPlugin_NETGEN_2D_ONLY::~NETGENPlugin_NETGEN_2D_ONLY");
120 //=============================================================================
124 //=============================================================================
126 bool NETGENPlugin_NETGEN_2D_ONLY::CheckHypothesis (SMESH_Mesh& aMesh,
127 const TopoDS_Shape& aShape,
128 Hypothesis_Status& aStatus)
130 _hypMaxElementArea = 0;
131 _hypLengthFromEdges = 0;
132 _hypQuadranglePreference = 0;
136 const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape, false);
140 aStatus = HYP_OK; //SMESH_Hypothesis::HYP_MISSING;
141 return true; // (PAL13464) can work with no hypothesis, LengthFromEdges is default one
144 aStatus = HYP_MISSING;
147 list<const SMESHDS_Hypothesis*>::const_iterator ith;
148 for (ith = hyps.begin(); ith != hyps.end(); ++ith )
150 const SMESHDS_Hypothesis* hyp = (*ith);
152 string hypName = hyp->GetName();
154 if ( hypName == "MaxElementArea")
155 _hypMaxElementArea = static_cast<const StdMeshers_MaxElementArea*> (hyp);
156 else if ( hypName == "LengthFromEdges" )
157 _hypLengthFromEdges = static_cast<const StdMeshers_LengthFromEdges*> (hyp);
158 else if ( hypName == "QuadranglePreference" )
159 _hypQuadranglePreference = static_cast<const StdMeshers_QuadranglePreference*>(hyp);
160 else if ( hypName == "NETGEN_Parameters_2D" )
161 _hypParameters = static_cast<const NETGENPlugin_Hypothesis_2D*>(hyp);
162 else if ( hypName == StdMeshers_ViscousLayers2D::GetHypType() )
165 aStatus = HYP_INCOMPATIBLE;
170 int nbHyps = bool(_hypMaxElementArea) + bool(_hypLengthFromEdges) + bool(_hypParameters );
172 aStatus = HYP_CONCURRENT;
174 error( StdMeshers_ViscousLayers2D::CheckHypothesis( aMesh, aShape, aStatus ));
178 if ( aStatus == HYP_OK && _hypParameters && _hypQuadranglePreference )
180 aStatus = HYP_INCOMPAT_HYPS;
181 return error(SMESH_Comment("\"") << _hypQuadranglePreference->GetName()
182 << "\" and \"" << _hypParameters->GetName()
183 << "\" are incompatible hypotheses");
186 return ( aStatus == HYP_OK );
191 // void limitSize( netgen::Mesh* ngMesh,
192 // const double maxh )
195 // netgen::Point3d pmin, pmax;
196 // ngMesh->GetBox( pmin, pmax, 0 );
197 // const double dx = pmax.X() - pmin.X();
198 // const double dy = pmax.Y() - pmin.Y();
199 // const double dz = pmax.Z() - pmin.Z();
201 // const int nbX = Max( 2, int( dx / maxh * 3 ));
202 // const int nbY = Max( 2, int( dy / maxh * 3 ));
203 // const int nbZ = Max( 2, int( dz / maxh * 3 ));
205 // if ( ! & ngMesh->LocalHFunction() )
206 // ngMesh->SetLocalH( pmin, pmax, 0.1 );
208 // netgen::Point3d p;
209 // for ( int i = 0; i <= nbX; ++i )
211 // p.X() = pmin.X() + i * dx / nbX;
212 // for ( int j = 0; j <= nbY; ++j )
214 // p.Y() = pmin.Y() + j * dy / nbY;
215 // for ( int k = 0; k <= nbZ; ++k )
217 // p.Z() = pmin.Z() + k * dz / nbZ;
218 // ngMesh->RestrictLocalH( p, maxh );
225 //=============================================================================
227 *Here we are going to use the NETGEN mesher
229 //=============================================================================
231 bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh,
232 const TopoDS_Shape& aShape)
234 netgen::multithread.terminate = 0;
235 //netgen::multithread.task = "Surface meshing";
237 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
238 SMESH_MesherHelper helper(aMesh);
239 helper.SetElementsOnShape( true );
241 NETGENPlugin_NetgenLibWrapper ngLib;
242 ngLib._isComputeOk = false;
244 netgen::Mesh ngMeshNoLocSize;
245 netgen::Mesh * ngMeshes[2] = { (netgen::Mesh*) ngLib._ngMesh, & ngMeshNoLocSize };
246 netgen::OCCGeometry occgeoComm;
248 // min / max sizes are set as follows:
249 // if ( _hypParameters )
250 // min and max are defined by the user
251 // else if ( _hypLengthFromEdges )
252 // min = aMesher.GetDefaultMinSize()
253 // max = average segment len of a FACE
254 // else if ( _hypMaxElementArea )
255 // min = aMesher.GetDefaultMinSize()
256 // max = f( _hypMaxElementArea )
258 // min = aMesher.GetDefaultMinSize()
259 // max = max segment len of a FACE
261 NETGENPlugin_Mesher aMesher( &aMesh, aShape, /*isVolume=*/false);
262 aMesher.SetParameters( _hypParameters ); // _hypParameters -> netgen::mparam
263 const bool toOptimize = _hypParameters ? _hypParameters->GetOptimize() : true;
264 if ( _hypMaxElementArea )
266 netgen::mparam.maxh = sqrt( 2. * _hypMaxElementArea->GetMaxArea() / sqrt(3.0) );
268 if ( _hypQuadranglePreference )
269 netgen::mparam.quad = true;
271 // local size is common for all FACEs in aShape?
272 const bool isCommonLocalSize = ( !_hypLengthFromEdges && !_hypMaxElementArea && netgen::mparam.uselocalh );
273 const bool isDefaultHyp = ( !_hypLengthFromEdges && !_hypMaxElementArea && !_hypParameters );
275 if ( isCommonLocalSize ) // compute common local size in ngMeshes[0]
277 //list< SMESH_subMesh* > meshedSM[4]; --> all sub-shapes are added to occgeoComm
278 aMesher.PrepareOCCgeometry( occgeoComm, aShape, aMesh );//, meshedSM );
280 // local size set at MESHCONST_ANALYSE step depends on
281 // minh, face_maxh, grading and curvaturesafety; find minh if not set by the user
282 if ( !_hypParameters || netgen::mparam.minh < DBL_MIN )
284 if ( !_hypParameters )
285 netgen::mparam.maxh = occgeoComm.GetBoundingBox().Diam() / 3.;
286 netgen::mparam.minh = aMesher.GetDefaultMinSize( aShape, netgen::mparam.maxh );
288 // set local size depending on curvature and NOT closeness of EDGEs
289 netgen::occparam.resthcloseedgeenable = false;
290 //netgen::occparam.resthcloseedgefac = 1.0 + netgen::mparam.grading;
291 occgeoComm.face_maxh = netgen::mparam.maxh;
292 netgen::OCCSetLocalMeshSize( occgeoComm, *ngMeshes[0] );
293 occgeoComm.emap.Clear();
294 occgeoComm.vmap.Clear();
296 // set local size according to size of existing segments
297 const double factor = netgen::occparam.resthcloseedgefac;
298 TopTools_IndexedMapOfShape edgeMap;
299 TopExp::MapShapes( aMesh.GetShapeToMesh(), TopAbs_EDGE, edgeMap );
300 for ( int iE = 1; iE <= edgeMap.Extent(); ++iE )
302 const TopoDS_Shape& edge = edgeMap( iE );
303 if ( SMESH_Algo::isDegenerated( TopoDS::Edge( edge )))
305 SMESHDS_SubMesh* smDS = meshDS->MeshElements( edge );
306 if ( !smDS ) continue;
307 SMDS_ElemIteratorPtr segIt = smDS->GetElements();
308 while ( segIt->more() )
310 const SMDS_MeshElement* seg = segIt->next();
311 SMESH_TNodeXYZ n1 = seg->GetNode(0);
312 SMESH_TNodeXYZ n2 = seg->GetNode(1);
313 gp_XYZ p = 0.5 * ( n1 + n2 );
314 netgen::Point3d pi(p.X(), p.Y(), p.Z());
315 ngMeshes[0]->RestrictLocalH( pi, factor * ( n1 - n2 ).Modulus() );
319 // set local size defined on shapes
320 aMesher.SetLocalSize( occgeoComm, *ngMeshes[0] );
321 aMesher.SetLocalSizeForChordalError( occgeoComm, *ngMeshes[0] );
323 ngMeshes[0]->LoadLocalMeshSize( mparam.meshsizefilename );
324 } catch (NgException & ex) {
325 return error( COMPERR_BAD_PARMETERS, ex.What() );
328 netgen::mparam.uselocalh = toOptimize; // restore as it is used at surface optimization
330 // ==================
332 // ==================
334 vector< const SMDS_MeshNode* > nodeVec;
336 TopExp_Explorer fExp( aShape, TopAbs_FACE );
337 for ( int iF = 0; fExp.More(); fExp.Next(), ++iF )
339 TopoDS_Face F = TopoDS::Face( fExp.Current() /*.Oriented( TopAbs_FORWARD )*/);
340 int faceID = meshDS->ShapeToIndex( F );
341 SMESH_ComputeErrorPtr& faceErr = aMesh.GetSubMesh( F )->GetComputeError();
343 _quadraticMesh = helper.IsQuadraticSubMesh( F );
344 const bool ignoreMediumNodes = _quadraticMesh;
346 // build viscous layers if required
347 if ( F.Orientation() != TopAbs_FORWARD &&
348 F.Orientation() != TopAbs_REVERSED )
349 F.Orientation( TopAbs_FORWARD ); // avoid pb with TopAbs_INTERNAL
350 SMESH_ProxyMesh::Ptr proxyMesh = StdMeshers_ViscousLayers2D::Compute( aMesh, F );
354 // ------------------------
355 // get all EDGEs of a FACE
356 // ------------------------
358 StdMeshers_FaceSide::GetFaceWires( F, aMesh, ignoreMediumNodes, faceErr, &helper, proxyMesh );
359 if ( faceErr && !faceErr->IsOK() )
361 int nbWires = wires.size();
365 ( new SMESH_ComputeError
366 ( COMPERR_ALGO_FAILED, "Problem in StdMeshers_FaceSide::GetFaceWires()" ));
369 if ( wires[0]->NbSegments() < 3 ) // ex: a circle with 2 segments
372 ( new SMESH_ComputeError
373 ( COMPERR_BAD_INPUT_MESH, SMESH_Comment("Too few segments: ")<<wires[0]->NbSegments()) );
377 // ----------------------
378 // compute maxh of a FACE
379 // ----------------------
381 if ( !_hypParameters )
383 double edgeLength = 0;
384 if (_hypLengthFromEdges )
386 // compute edgeLength as an average segment length
388 for ( int iW = 0; iW < nbWires; ++iW )
390 edgeLength += wires[ iW ]->Length();
391 nbSegments += wires[ iW ]->NbSegments();
394 edgeLength /= nbSegments;
395 netgen::mparam.maxh = edgeLength;
397 else if ( isDefaultHyp )
399 // set edgeLength by a longest segment
401 for ( int iW = 0; iW < nbWires; ++iW )
403 const UVPtStructVec& points = wires[ iW ]->GetUVPtStruct();
404 if ( points.empty() )
405 return error( COMPERR_BAD_INPUT_MESH );
406 gp_Pnt pPrev = SMESH_TNodeXYZ( points[0].node );
407 for ( size_t i = 1; i < points.size(); ++i )
409 gp_Pnt p = SMESH_TNodeXYZ( points[i].node );
410 maxSeg2 = Max( maxSeg2, p.SquareDistance( pPrev ));
414 edgeLength = sqrt( maxSeg2 ) * 1.05;
415 netgen::mparam.maxh = edgeLength;
417 if ( netgen::mparam.maxh < DBL_MIN )
418 netgen::mparam.maxh = occgeoComm.GetBoundingBox().Diam();
420 if ( !isCommonLocalSize )
422 netgen::mparam.minh = aMesher.GetDefaultMinSize( F, netgen::mparam.maxh );
427 netgen::OCCGeometry occgeom;
429 occgeom.fmap.Add( F );
430 occgeom.CalcBoundingBox();
431 occgeom.facemeshstatus.SetSize(1);
432 occgeom.facemeshstatus = 0;
433 occgeom.face_maxh_modified.SetSize(1);
434 occgeom.face_maxh_modified = 0;
435 occgeom.face_maxh.SetSize(1);
436 occgeom.face_maxh = netgen::mparam.maxh;
438 // -------------------------
440 // -------------------------
442 // MESHCONST_ANALYSE step may lead to a failure, so we make an attempt
443 // w/o MESHCONST_ANALYSE at the second loop
445 enum { LOC_SIZE, NO_LOC_SIZE };
446 int iLoop = isCommonLocalSize ? 0 : 1;
447 for ( ; iLoop < 2; iLoop++ )
449 //bool isMESHCONST_ANALYSE = false;
452 netgen::Mesh * ngMesh = ngMeshes[ iLoop ];
453 ngMesh->DeleteMesh();
455 if ( iLoop == NO_LOC_SIZE )
457 ngMesh->SetGlobalH ( mparam.maxh );
458 ngMesh->SetMinimalH( mparam.minh );
459 Box<3> bb = occgeom.GetBoundingBox();
460 bb.Increase (bb.Diam()/10);
461 ngMesh->SetLocalH (bb.PMin(), bb.PMax(), mparam.grading);
462 aMesher.SetLocalSize( occgeom, *ngMesh );
463 aMesher.SetLocalSizeForChordalError( occgeoComm, *ngMesh );
465 ngMesh->LoadLocalMeshSize( mparam.meshsizefilename );
466 } catch (NgException & ex) {
467 return error( COMPERR_BAD_PARMETERS, ex.What() );
472 faceErr = aMesher.AddSegmentsToMesh( *ngMesh, occgeom, wires, helper, nodeVec,
473 /*overrideMinH=*/!_hypParameters);
474 if ( faceErr && !faceErr->IsOK() )
477 //if ( !isCommonLocalSize )
478 //limitSize( ngMesh, mparam.maxh * 0.8);
480 // -------------------------
481 // Generate surface mesh
482 // -------------------------
484 const int startWith = MESHCONST_MESHSURFACE;
485 const int endWith = toOptimize ? MESHCONST_OPTSURFACE : MESHCONST_MESHSURFACE;
492 err = netgen::OCCGenerateMesh(occgeom, ngMesh, netgen::mparam, startWith, endWith);
495 err = netgen::OCCGenerateMesh(occgeom, ngMesh, startWith, endWith, optstr);
497 if ( netgen::multithread.terminate )
500 str << "Error in netgen::OCCGenerateMesh() at " << netgen::multithread.task;
502 catch (Standard_Failure& ex)
505 str << "Exception in netgen::OCCGenerateMesh()"
506 << " at " << netgen::multithread.task
507 << ": " << ex.DynamicType()->Name();
508 if ( ex.GetMessageString() && strlen( ex.GetMessageString() ))
509 str << ": " << ex.GetMessageString();
513 str << "Exception in netgen::OCCGenerateMesh()"
514 << " at " << netgen::multithread.task;
518 if ( aMesher.FixFaceMesh( occgeom, *ngMesh, 1 ))
520 if ( iLoop == LOC_SIZE )
522 netgen::mparam.minh = netgen::mparam.maxh;
523 netgen::mparam.maxh = 0;
524 for ( size_t iW = 0; iW < wires.size(); ++iW )
526 StdMeshers_FaceSidePtr wire = wires[ iW ];
527 const vector<UVPtStruct>& uvPtVec = wire->GetUVPtStruct();
528 for ( size_t iP = 1; iP < uvPtVec.size(); ++iP )
530 SMESH_TNodeXYZ p( uvPtVec[ iP ].node );
531 netgen::Point3d np( p.X(),p.Y(),p.Z());
532 double segLen = p.Distance( uvPtVec[ iP-1 ].node );
533 double size = ngMesh->GetH( np );
534 netgen::mparam.minh = Min( netgen::mparam.minh, size );
535 netgen::mparam.maxh = Max( netgen::mparam.maxh, segLen );
538 //cerr << "min " << netgen::mparam.minh << " max " << netgen::mparam.maxh << endl;
539 netgen::mparam.minh *= 0.9;
540 netgen::mparam.maxh *= 1.1;
545 faceErr.reset( new SMESH_ComputeError( COMPERR_ALGO_FAILED, str ));
550 // ----------------------------------------------------
551 // Fill the SMESHDS with the generated nodes and faces
552 // ----------------------------------------------------
554 int nbNodes = ngMesh->GetNP();
555 int nbFaces = ngMesh->GetNSE();
557 int nbInputNodes = nodeVec.size()-1;
558 nodeVec.resize( nbNodes+1, 0 );
561 for ( int ngID = nbInputNodes + 1; ngID <= nbNodes; ++ngID )
563 const MeshPoint& ngPoint = ngMesh->Point( ngID );
564 SMDS_MeshNode * node = meshDS->AddNode(ngPoint(0), ngPoint(1), ngPoint(2));
565 nodeVec[ ngID ] = node;
570 vector<const SMDS_MeshNode*> nodes;
571 for ( i = 1; i <= nbFaces ; ++i )
573 const Element2d& elem = ngMesh->SurfaceElement(i);
574 nodes.resize( elem.GetNP() );
575 for (j=1; j <= elem.GetNP(); ++j)
577 int pind = elem.PNum(j);
580 nodes[ j-1 ] = nodeVec[ pind ];
581 if ( nodes[ j-1 ]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE )
583 const PointGeomInfo& pgi = elem.GeomInfoPi(j);
584 meshDS->SetNodeOnFace( nodes[ j-1 ], faceID, pgi.u, pgi.v);
587 if ( j > elem.GetNP() )
589 if ( elem.GetType() == TRIG )
590 helper.AddFace(nodes[0],nodes[1],nodes[2]);
592 helper.AddFace(nodes[0],nodes[1],nodes[2],nodes[3]);
603 void NETGENPlugin_NETGEN_2D_ONLY::CancelCompute()
605 SMESH_Algo::CancelCompute();
606 netgen::multithread.terminate = 1;
609 //================================================================================
611 * \brief Return progress of Compute() [0.,1]
613 //================================================================================
615 double NETGENPlugin_NETGEN_2D_ONLY::GetProgress() const
618 // const char* task1 = "Surface meshing";
619 // //const char* task2 = "Optimizing surface";
620 // double& progress = const_cast<NETGENPlugin_NETGEN_2D_ONLY*>( this )->_progress;
621 // if ( _progressByTic < 0. &&
622 // strncmp( netgen::multithread.task, task1, 3 ) == 0 )
624 // progress = Min( 0.25, SMESH_Algo::GetProgressByTic() ); // [0, 0.25]
626 // else //if ( strncmp( netgen::multithread.task, task2, 3 ) == 0)
628 // if ( _progressByTic < 0 )
630 // NETGENPlugin_NETGEN_2D_ONLY* me = (NETGENPlugin_NETGEN_2D_ONLY*) this;
631 // me->_progressByTic = 0.25 / (_progressTic+1);
633 // const_cast<NETGENPlugin_NETGEN_2D_ONLY*>( this )->_progressTic++;
634 // progress = Max( progress, _progressByTic * _progressTic );
636 // //cout << netgen::multithread.task << " " << _progressTic << endl;
637 // return Min( progress, 0.99 );
640 //=============================================================================
644 //=============================================================================
646 bool NETGENPlugin_NETGEN_2D_ONLY::Evaluate(SMESH_Mesh& aMesh,
647 const TopoDS_Shape& aShape,
648 MapShapeNbElems& aResMap)
650 TopoDS_Face F = TopoDS::Face(aShape);
654 // collect info from edges
655 int nb0d = 0, nb1d = 0;
656 bool IsQuadratic = false;
658 double fullLen = 0.0;
659 TopTools_MapOfShape tmpMap;
660 for (TopExp_Explorer exp(F, TopAbs_EDGE); exp.More(); exp.Next()) {
661 TopoDS_Edge E = TopoDS::Edge(exp.Current());
662 if( tmpMap.Contains(E) )
665 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
666 MapShapeNbElemsItr anIt = aResMap.find(aSubMesh);
667 if( anIt==aResMap.end() ) {
668 SMESH_subMesh *sm = aMesh.GetSubMesh(F);
669 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
670 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
673 std::vector<int> aVec = (*anIt).second;
674 nb0d += aVec[SMDSEntity_Node];
675 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
676 double aLen = SMESH_Algo::EdgeLength(E);
679 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
685 // compute edge length
687 if (( _hypLengthFromEdges ) || ( !_hypLengthFromEdges && !_hypMaxElementArea )) {
689 ELen = fullLen / nb1d;
691 if ( _hypMaxElementArea ) {
692 double maxArea = _hypMaxElementArea->GetMaxArea();
693 ELen = sqrt(2. * maxArea/sqrt(3.0));
696 BRepGProp::SurfaceProperties(F,G);
697 double anArea = G.Mass();
699 const int hugeNb = numeric_limits<int>::max()/10;
700 if ( anArea / hugeNb > ELen*ELen )
702 SMESH_subMesh *sm = aMesh.GetSubMesh(F);
703 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
704 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated.\nToo small element length",this));
707 int nbFaces = (int) ( anArea / ( ELen*ELen*sqrt(3.) / 4 ) );
708 int nbNodes = (int) ( ( nbFaces*3 - (nb1d-1)*2 ) / 6 + 1 );
709 std::vector<int> aVec(SMDSEntity_Last);
710 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i]=0;
712 aVec[SMDSEntity_Node] = nbNodes;
713 aVec[SMDSEntity_Quad_Triangle] = nbFaces;
716 aVec[SMDSEntity_Node] = nbNodes;
717 aVec[SMDSEntity_Triangle] = nbFaces;
719 SMESH_subMesh *sm = aMesh.GetSubMesh(F);
720 aResMap.insert(std::make_pair(sm,aVec));