1 // Copyright (C) 2007-2019 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 NETGENPLUGIN_DLL_HEADER
72 extern MeshingParameters mparam;
73 extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh);
77 using namespace netgen;
78 using namespace nglib;
80 //=============================================================================
84 //=============================================================================
86 NETGENPlugin_NETGEN_2D_ONLY::NETGENPlugin_NETGEN_2D_ONLY(int hypId,
88 : SMESH_2D_Algo(hypId, gen)
90 _name = "NETGEN_2D_ONLY";
92 _shapeType = (1 << TopAbs_FACE);// 1 bit /shape type
93 _onlyUnaryInput = false; // treat all FACEs at once
95 _compatibleHypothesis.push_back("MaxElementArea");
96 _compatibleHypothesis.push_back("LengthFromEdges");
97 _compatibleHypothesis.push_back("QuadranglePreference");
98 _compatibleHypothesis.push_back("NETGEN_Parameters_2D");
99 _compatibleHypothesis.push_back("ViscousLayers2D");
101 _hypMaxElementArea = 0;
102 _hypLengthFromEdges = 0;
103 _hypQuadranglePreference = 0;
107 //=============================================================================
111 //=============================================================================
113 NETGENPlugin_NETGEN_2D_ONLY::~NETGENPlugin_NETGEN_2D_ONLY()
115 //MESSAGE("NETGENPlugin_NETGEN_2D_ONLY::~NETGENPlugin_NETGEN_2D_ONLY");
118 //=============================================================================
122 //=============================================================================
124 bool NETGENPlugin_NETGEN_2D_ONLY::CheckHypothesis (SMESH_Mesh& aMesh,
125 const TopoDS_Shape& aShape,
126 Hypothesis_Status& aStatus)
128 _hypMaxElementArea = 0;
129 _hypLengthFromEdges = 0;
130 _hypQuadranglePreference = 0;
134 const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape, false);
138 aStatus = HYP_OK; //SMESH_Hypothesis::HYP_MISSING;
139 return true; // (PAL13464) can work with no hypothesis, LengthFromEdges is default one
142 aStatus = HYP_MISSING;
145 list<const SMESHDS_Hypothesis*>::const_iterator ith;
146 for (ith = hyps.begin(); ith != hyps.end(); ++ith )
148 const SMESHDS_Hypothesis* hyp = (*ith);
150 string hypName = hyp->GetName();
152 if ( hypName == "MaxElementArea")
153 _hypMaxElementArea = static_cast<const StdMeshers_MaxElementArea*> (hyp);
154 else if ( hypName == "LengthFromEdges" )
155 _hypLengthFromEdges = static_cast<const StdMeshers_LengthFromEdges*> (hyp);
156 else if ( hypName == "QuadranglePreference" )
157 _hypQuadranglePreference = static_cast<const StdMeshers_QuadranglePreference*>(hyp);
158 else if ( hypName == "NETGEN_Parameters_2D" )
159 _hypParameters = static_cast<const NETGENPlugin_Hypothesis_2D*>(hyp);
160 else if ( hypName == StdMeshers_ViscousLayers2D::GetHypType() )
163 aStatus = HYP_INCOMPATIBLE;
168 int nbHyps = bool(_hypMaxElementArea) + bool(_hypLengthFromEdges) + bool(_hypParameters );
170 aStatus = HYP_CONCURRENT;
172 error( StdMeshers_ViscousLayers2D::CheckHypothesis( aMesh, aShape, aStatus ));
176 if ( aStatus == HYP_OK && _hypParameters && _hypQuadranglePreference )
178 aStatus = HYP_INCOMPAT_HYPS;
179 return error(SMESH_Comment("\"") << _hypQuadranglePreference->GetName()
180 << "\" and \"" << _hypParameters->GetName()
181 << "\" are incompatible hypotheses");
184 return ( aStatus == HYP_OK );
189 // void limitSize( netgen::Mesh* ngMesh,
190 // const double maxh )
193 // netgen::Point3d pmin, pmax;
194 // ngMesh->GetBox( pmin, pmax, 0 );
195 // const double dx = pmax.X() - pmin.X();
196 // const double dy = pmax.Y() - pmin.Y();
197 // const double dz = pmax.Z() - pmin.Z();
199 // const int nbX = Max( 2, int( dx / maxh * 3 ));
200 // const int nbY = Max( 2, int( dy / maxh * 3 ));
201 // const int nbZ = Max( 2, int( dz / maxh * 3 ));
203 // if ( ! & ngMesh->LocalHFunction() )
204 // ngMesh->SetLocalH( pmin, pmax, 0.1 );
206 // netgen::Point3d p;
207 // for ( int i = 0; i <= nbX; ++i )
209 // p.X() = pmin.X() + i * dx / nbX;
210 // for ( int j = 0; j <= nbY; ++j )
212 // p.Y() = pmin.Y() + j * dy / nbY;
213 // for ( int k = 0; k <= nbZ; ++k )
215 // p.Z() = pmin.Z() + k * dz / nbZ;
216 // ngMesh->RestrictLocalH( p, maxh );
223 //=============================================================================
225 *Here we are going to use the NETGEN mesher
227 //=============================================================================
229 bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh,
230 const TopoDS_Shape& aShape)
232 netgen::multithread.terminate = 0;
233 //netgen::multithread.task = "Surface meshing";
235 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
236 SMESH_MesherHelper helper(aMesh);
237 helper.SetElementsOnShape( true );
239 NETGENPlugin_NetgenLibWrapper ngLib;
240 ngLib._isComputeOk = false;
242 netgen::Mesh ngMeshNoLocSize;
243 netgen::Mesh * ngMeshes[2] = { (netgen::Mesh*) ngLib._ngMesh, & ngMeshNoLocSize };
244 netgen::OCCGeometry occgeoComm;
246 // min / max sizes are set as follows:
247 // if ( _hypParameters )
248 // min and max are defined by the user
249 // else if ( _hypLengthFromEdges )
250 // min = aMesher.GetDefaultMinSize()
251 // max = average segment len of a FACE
252 // else if ( _hypMaxElementArea )
253 // min = aMesher.GetDefaultMinSize()
254 // max = f( _hypMaxElementArea )
256 // min = aMesher.GetDefaultMinSize()
257 // max = max segment len of a FACE
259 NETGENPlugin_Mesher aMesher( &aMesh, aShape, /*isVolume=*/false);
260 aMesher.SetParameters( _hypParameters ); // _hypParameters -> netgen::mparam
261 const bool toOptimize = _hypParameters ? _hypParameters->GetOptimize() : true;
262 if ( _hypMaxElementArea )
264 netgen::mparam.maxh = sqrt( 2. * _hypMaxElementArea->GetMaxArea() / sqrt(3.0) );
266 if ( _hypQuadranglePreference )
267 netgen::mparam.quad = true;
269 // local size is common for all FACEs in aShape?
270 const bool isCommonLocalSize = ( !_hypLengthFromEdges && !_hypMaxElementArea && netgen::mparam.uselocalh );
271 const bool isDefaultHyp = ( !_hypLengthFromEdges && !_hypMaxElementArea && !_hypParameters );
273 if ( isCommonLocalSize ) // compute common local size in ngMeshes[0]
275 //list< SMESH_subMesh* > meshedSM[4]; --> all sub-shapes are added to occgeoComm
276 aMesher.PrepareOCCgeometry( occgeoComm, aShape, aMesh );//, meshedSM );
278 // local size set at MESHCONST_ANALYSE step depends on
279 // minh, face_maxh, grading and curvaturesafety; find minh if not set by the user
280 if ( !_hypParameters || netgen::mparam.minh < DBL_MIN )
282 if ( !_hypParameters )
283 netgen::mparam.maxh = occgeoComm.GetBoundingBox().Diam() / 3.;
284 netgen::mparam.minh = aMesher.GetDefaultMinSize( aShape, netgen::mparam.maxh );
286 // set local size depending on curvature and NOT closeness of EDGEs
287 netgen::occparam.resthcloseedgeenable = false;
288 //netgen::occparam.resthcloseedgefac = 1.0 + netgen::mparam.grading;
289 occgeoComm.face_maxh = netgen::mparam.maxh;
290 netgen::OCCSetLocalMeshSize( occgeoComm, *ngMeshes[0] );
291 occgeoComm.emap.Clear();
292 occgeoComm.vmap.Clear();
294 // set local size according to size of existing segments
295 const double factor = netgen::occparam.resthcloseedgefac;
296 TopTools_IndexedMapOfShape edgeMap;
297 TopExp::MapShapes( aMesh.GetShapeToMesh(), TopAbs_EDGE, edgeMap );
298 for ( int iE = 1; iE <= edgeMap.Extent(); ++iE )
300 const TopoDS_Shape& edge = edgeMap( iE );
301 if ( SMESH_Algo::isDegenerated( TopoDS::Edge( edge )))
303 SMESHDS_SubMesh* smDS = meshDS->MeshElements( edge );
304 if ( !smDS ) continue;
305 SMDS_ElemIteratorPtr segIt = smDS->GetElements();
306 while ( segIt->more() )
308 const SMDS_MeshElement* seg = segIt->next();
309 SMESH_TNodeXYZ n1 = seg->GetNode(0);
310 SMESH_TNodeXYZ n2 = seg->GetNode(1);
311 gp_XYZ p = 0.5 * ( n1 + n2 );
312 netgen::Point3d pi(p.X(), p.Y(), p.Z());
313 ngMeshes[0]->RestrictLocalH( pi, factor * ( n1 - n2 ).Modulus() );
317 // set local size defined on shapes
318 aMesher.SetLocalSize( occgeoComm, *ngMeshes[0] );
319 aMesher.SetLocalSizeForChordalError( occgeoComm, *ngMeshes[0] );
321 ngMeshes[0]->LoadLocalMeshSize( mparam.meshsizefilename );
322 } catch (NgException & ex) {
323 return error( COMPERR_BAD_PARMETERS, ex.What() );
326 netgen::mparam.uselocalh = toOptimize; // restore as it is used at surface optimization
328 // ==================
330 // ==================
332 vector< const SMDS_MeshNode* > nodeVec;
334 TopExp_Explorer fExp( aShape, TopAbs_FACE );
335 for ( int iF = 0; fExp.More(); fExp.Next(), ++iF )
337 TopoDS_Face F = TopoDS::Face( fExp.Current() /*.Oriented( TopAbs_FORWARD )*/);
338 int faceID = meshDS->ShapeToIndex( F );
339 SMESH_ComputeErrorPtr& faceErr = aMesh.GetSubMesh( F )->GetComputeError();
341 _quadraticMesh = helper.IsQuadraticSubMesh( F );
342 const bool ignoreMediumNodes = _quadraticMesh;
344 // build viscous layers if required
345 if ( F.Orientation() != TopAbs_FORWARD &&
346 F.Orientation() != TopAbs_REVERSED )
347 F.Orientation( TopAbs_FORWARD ); // avoid pb with TopAbs_INTERNAL
348 SMESH_ProxyMesh::Ptr proxyMesh = StdMeshers_ViscousLayers2D::Compute( aMesh, F );
352 // ------------------------
353 // get all EDGEs of a FACE
354 // ------------------------
356 StdMeshers_FaceSide::GetFaceWires( F, aMesh, ignoreMediumNodes, faceErr, &helper, proxyMesh );
357 if ( faceErr && !faceErr->IsOK() )
359 int nbWires = wires.size();
363 ( new SMESH_ComputeError
364 ( COMPERR_ALGO_FAILED, "Problem in StdMeshers_FaceSide::GetFaceWires()" ));
367 if ( wires[0]->NbSegments() < 3 ) // ex: a circle with 2 segments
370 ( new SMESH_ComputeError
371 ( COMPERR_BAD_INPUT_MESH, SMESH_Comment("Too few segments: ")<<wires[0]->NbSegments()) );
375 // ----------------------
376 // compute maxh of a FACE
377 // ----------------------
379 if ( !_hypParameters )
381 double edgeLength = 0;
382 if (_hypLengthFromEdges )
384 // compute edgeLength as an average segment length
386 for ( int iW = 0; iW < nbWires; ++iW )
388 edgeLength += wires[ iW ]->Length();
389 nbSegments += wires[ iW ]->NbSegments();
392 edgeLength /= nbSegments;
393 netgen::mparam.maxh = edgeLength;
395 else if ( isDefaultHyp )
397 // set edgeLength by a longest segment
399 for ( int iW = 0; iW < nbWires; ++iW )
401 const UVPtStructVec& points = wires[ iW ]->GetUVPtStruct();
402 if ( points.empty() )
403 return error( COMPERR_BAD_INPUT_MESH );
404 gp_Pnt pPrev = SMESH_TNodeXYZ( points[0].node );
405 for ( size_t i = 1; i < points.size(); ++i )
407 gp_Pnt p = SMESH_TNodeXYZ( points[i].node );
408 maxSeg2 = Max( maxSeg2, p.SquareDistance( pPrev ));
412 edgeLength = sqrt( maxSeg2 ) * 1.05;
413 netgen::mparam.maxh = edgeLength;
415 if ( netgen::mparam.maxh < DBL_MIN )
416 netgen::mparam.maxh = occgeoComm.GetBoundingBox().Diam();
418 if ( !isCommonLocalSize )
420 netgen::mparam.minh = aMesher.GetDefaultMinSize( F, netgen::mparam.maxh );
425 netgen::OCCGeometry occgeom;
427 occgeom.fmap.Add( F );
428 occgeom.CalcBoundingBox();
429 occgeom.facemeshstatus.SetSize(1);
430 occgeom.facemeshstatus = 0;
431 occgeom.face_maxh_modified.SetSize(1);
432 occgeom.face_maxh_modified = 0;
433 occgeom.face_maxh.SetSize(1);
434 occgeom.face_maxh = netgen::mparam.maxh;
436 // -------------------------
438 // -------------------------
440 // MESHCONST_ANALYSE step may lead to a failure, so we make an attempt
441 // w/o MESHCONST_ANALYSE at the second loop
443 enum { LOC_SIZE, NO_LOC_SIZE };
444 int iLoop = isCommonLocalSize ? 0 : 1;
445 for ( ; iLoop < 2; iLoop++ )
447 //bool isMESHCONST_ANALYSE = false;
450 netgen::Mesh * ngMesh = ngMeshes[ iLoop ];
451 ngMesh->DeleteMesh();
453 if ( iLoop == NO_LOC_SIZE )
455 ngMesh->SetGlobalH ( mparam.maxh );
456 ngMesh->SetMinimalH( mparam.minh );
457 Box<3> bb = occgeom.GetBoundingBox();
458 bb.Increase (bb.Diam()/10);
459 ngMesh->SetLocalH (bb.PMin(), bb.PMax(), mparam.grading);
460 aMesher.SetLocalSize( occgeom, *ngMesh );
461 aMesher.SetLocalSizeForChordalError( occgeoComm, *ngMesh );
463 ngMesh->LoadLocalMeshSize( mparam.meshsizefilename );
464 } catch (NgException & ex) {
465 return error( COMPERR_BAD_PARMETERS, ex.What() );
470 faceErr = aMesher.AddSegmentsToMesh( *ngMesh, occgeom, wires, helper, nodeVec,
471 /*overrideMinH=*/!_hypParameters);
472 if ( faceErr && !faceErr->IsOK() )
475 //if ( !isCommonLocalSize )
476 //limitSize( ngMesh, mparam.maxh * 0.8);
478 // -------------------------
479 // Generate surface mesh
480 // -------------------------
482 const int startWith = MESHCONST_MESHSURFACE;
483 const int endWith = toOptimize ? MESHCONST_OPTSURFACE : MESHCONST_MESHSURFACE;
490 err = netgen::OCCGenerateMesh(occgeom, ngMesh, netgen::mparam, startWith, endWith);
493 err = netgen::OCCGenerateMesh(occgeom, ngMesh, startWith, endWith, optstr);
495 if ( netgen::multithread.terminate )
498 str << "Error in netgen::OCCGenerateMesh() at " << netgen::multithread.task;
500 catch (Standard_Failure& ex)
503 str << "Exception in netgen::OCCGenerateMesh()"
504 << " at " << netgen::multithread.task
505 << ": " << ex.DynamicType()->Name();
506 if ( ex.GetMessageString() && strlen( ex.GetMessageString() ))
507 str << ": " << ex.GetMessageString();
511 str << "Exception in netgen::OCCGenerateMesh()"
512 << " at " << netgen::multithread.task;
516 if ( aMesher.FixFaceMesh( occgeom, *ngMesh, 1 ))
518 if ( iLoop == LOC_SIZE )
520 netgen::mparam.minh = netgen::mparam.maxh;
521 netgen::mparam.maxh = 0;
522 for ( size_t iW = 0; iW < wires.size(); ++iW )
524 StdMeshers_FaceSidePtr wire = wires[ iW ];
525 const vector<UVPtStruct>& uvPtVec = wire->GetUVPtStruct();
526 for ( size_t iP = 1; iP < uvPtVec.size(); ++iP )
528 SMESH_TNodeXYZ p( uvPtVec[ iP ].node );
529 netgen::Point3d np( p.X(),p.Y(),p.Z());
530 double segLen = p.Distance( uvPtVec[ iP-1 ].node );
531 double size = ngMesh->GetH( np );
532 netgen::mparam.minh = Min( netgen::mparam.minh, size );
533 netgen::mparam.maxh = Max( netgen::mparam.maxh, segLen );
536 //cerr << "min " << netgen::mparam.minh << " max " << netgen::mparam.maxh << endl;
537 netgen::mparam.minh *= 0.9;
538 netgen::mparam.maxh *= 1.1;
543 faceErr.reset( new SMESH_ComputeError( COMPERR_ALGO_FAILED, str ));
548 // ----------------------------------------------------
549 // Fill the SMESHDS with the generated nodes and faces
550 // ----------------------------------------------------
552 int nbNodes = ngMesh->GetNP();
553 int nbFaces = ngMesh->GetNSE();
555 int nbInputNodes = nodeVec.size()-1;
556 nodeVec.resize( nbNodes+1, 0 );
559 for ( int ngID = nbInputNodes + 1; ngID <= nbNodes; ++ngID )
561 const MeshPoint& ngPoint = ngMesh->Point( ngID );
562 SMDS_MeshNode * node = meshDS->AddNode(ngPoint(0), ngPoint(1), ngPoint(2));
563 nodeVec[ ngID ] = node;
568 vector<const SMDS_MeshNode*> nodes;
569 for ( i = 1; i <= nbFaces ; ++i )
571 const Element2d& elem = ngMesh->SurfaceElement(i);
572 nodes.resize( elem.GetNP() );
573 for (j=1; j <= elem.GetNP(); ++j)
575 int pind = elem.PNum(j);
578 nodes[ j-1 ] = nodeVec[ pind ];
579 if ( nodes[ j-1 ]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE )
581 const PointGeomInfo& pgi = elem.GeomInfoPi(j);
582 meshDS->SetNodeOnFace( nodes[ j-1 ], faceID, pgi.u, pgi.v);
585 if ( j > elem.GetNP() )
587 if ( elem.GetType() == TRIG )
588 helper.AddFace(nodes[0],nodes[1],nodes[2]);
590 helper.AddFace(nodes[0],nodes[1],nodes[2],nodes[3]);
601 void NETGENPlugin_NETGEN_2D_ONLY::CancelCompute()
603 SMESH_Algo::CancelCompute();
604 netgen::multithread.terminate = 1;
607 //================================================================================
609 * \brief Return progress of Compute() [0.,1]
611 //================================================================================
613 double NETGENPlugin_NETGEN_2D_ONLY::GetProgress() const
616 // const char* task1 = "Surface meshing";
617 // //const char* task2 = "Optimizing surface";
618 // double& progress = const_cast<NETGENPlugin_NETGEN_2D_ONLY*>( this )->_progress;
619 // if ( _progressByTic < 0. &&
620 // strncmp( netgen::multithread.task, task1, 3 ) == 0 )
622 // progress = Min( 0.25, SMESH_Algo::GetProgressByTic() ); // [0, 0.25]
624 // else //if ( strncmp( netgen::multithread.task, task2, 3 ) == 0)
626 // if ( _progressByTic < 0 )
628 // NETGENPlugin_NETGEN_2D_ONLY* me = (NETGENPlugin_NETGEN_2D_ONLY*) this;
629 // me->_progressByTic = 0.25 / (_progressTic+1);
631 // const_cast<NETGENPlugin_NETGEN_2D_ONLY*>( this )->_progressTic++;
632 // progress = Max( progress, _progressByTic * _progressTic );
634 // //cout << netgen::multithread.task << " " << _progressTic << endl;
635 // return Min( progress, 0.99 );
638 //=============================================================================
642 //=============================================================================
644 bool NETGENPlugin_NETGEN_2D_ONLY::Evaluate(SMESH_Mesh& aMesh,
645 const TopoDS_Shape& aShape,
646 MapShapeNbElems& aResMap)
648 TopoDS_Face F = TopoDS::Face(aShape);
652 // collect info from edges
653 int nb0d = 0, nb1d = 0;
654 bool IsQuadratic = false;
656 double fullLen = 0.0;
657 TopTools_MapOfShape tmpMap;
658 for (TopExp_Explorer exp(F, TopAbs_EDGE); exp.More(); exp.Next()) {
659 TopoDS_Edge E = TopoDS::Edge(exp.Current());
660 if( tmpMap.Contains(E) )
663 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
664 MapShapeNbElemsItr anIt = aResMap.find(aSubMesh);
665 if( anIt==aResMap.end() ) {
666 SMESH_subMesh *sm = aMesh.GetSubMesh(F);
667 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
668 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
671 std::vector<int> aVec = (*anIt).second;
672 nb0d += aVec[SMDSEntity_Node];
673 nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
674 double aLen = SMESH_Algo::EdgeLength(E);
677 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
683 // compute edge length
685 if (( _hypLengthFromEdges ) || ( !_hypLengthFromEdges && !_hypMaxElementArea )) {
687 ELen = fullLen / nb1d;
689 if ( _hypMaxElementArea ) {
690 double maxArea = _hypMaxElementArea->GetMaxArea();
691 ELen = sqrt(2. * maxArea/sqrt(3.0));
694 BRepGProp::SurfaceProperties(F,G);
695 double anArea = G.Mass();
697 const int hugeNb = numeric_limits<int>::max()/10;
698 if ( anArea / hugeNb > ELen*ELen )
700 SMESH_subMesh *sm = aMesh.GetSubMesh(F);
701 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
702 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated.\nToo small element length",this));
705 int nbFaces = (int) ( anArea / ( ELen*ELen*sqrt(3.) / 4 ) );
706 int nbNodes = (int) ( ( nbFaces*3 - (nb1d-1)*2 ) / 6 + 1 );
707 std::vector<int> aVec(SMDSEntity_Last);
708 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i]=0;
710 aVec[SMDSEntity_Node] = nbNodes;
711 aVec[SMDSEntity_Quad_Triangle] = nbFaces;
714 aVec[SMDSEntity_Node] = nbNodes;
715 aVec[SMDSEntity_Triangle] = nbFaces;
717 SMESH_subMesh *sm = aMesh.GetSubMesh(F);
718 aResMap.insert(std::make_pair(sm,aVec));