1 // Copyright (C) 2007-2023 CEA, EDF, 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>
66 NETGENPLUGIN_DLL_HEADER
67 extern MeshingParameters mparam;
69 extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh);
74 using namespace netgen;
75 using namespace nglib;
77 //=============================================================================
81 //=============================================================================
83 NETGENPlugin_NETGEN_2D_ONLY::NETGENPlugin_NETGEN_2D_ONLY(int hypId,
85 : SMESH_2D_Algo(hypId, gen)
87 _name = "NETGEN_2D_ONLY";
89 _shapeType = (1 << TopAbs_FACE);// 1 bit /shape type
90 _onlyUnaryInput = false; // treat all FACEs at once
92 _compatibleHypothesis.push_back("MaxElementArea");
93 _compatibleHypothesis.push_back("LengthFromEdges");
94 _compatibleHypothesis.push_back("QuadranglePreference");
95 _compatibleHypothesis.push_back("NETGEN_Parameters_2D");
96 _compatibleHypothesis.push_back("ViscousLayers2D");
98 _hypMaxElementArea = 0;
99 _hypLengthFromEdges = 0;
100 _hypQuadranglePreference = 0;
104 //=============================================================================
108 //=============================================================================
110 NETGENPlugin_NETGEN_2D_ONLY::~NETGENPlugin_NETGEN_2D_ONLY()
112 //MESSAGE("NETGENPlugin_NETGEN_2D_ONLY::~NETGENPlugin_NETGEN_2D_ONLY");
115 //=============================================================================
119 //=============================================================================
121 bool NETGENPlugin_NETGEN_2D_ONLY::CheckHypothesis (SMESH_Mesh& aMesh,
122 const TopoDS_Shape& aShape,
123 Hypothesis_Status& aStatus)
125 _hypMaxElementArea = 0;
126 _hypLengthFromEdges = 0;
127 _hypQuadranglePreference = 0;
131 const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape, false);
135 aStatus = HYP_OK; //SMESH_Hypothesis::HYP_MISSING;
136 return true; // (PAL13464) can work with no hypothesis, LengthFromEdges is default one
139 aStatus = HYP_MISSING;
142 list<const SMESHDS_Hypothesis*>::const_iterator ith;
143 for (ith = hyps.begin(); ith != hyps.end(); ++ith )
145 const SMESHDS_Hypothesis* hyp = (*ith);
147 string hypName = hyp->GetName();
149 if ( hypName == "MaxElementArea")
150 _hypMaxElementArea = static_cast<const StdMeshers_MaxElementArea*> (hyp);
151 else if ( hypName == "LengthFromEdges" )
152 _hypLengthFromEdges = static_cast<const StdMeshers_LengthFromEdges*> (hyp);
153 else if ( hypName == "QuadranglePreference" )
154 _hypQuadranglePreference = static_cast<const StdMeshers_QuadranglePreference*>(hyp);
155 else if ( hypName == "NETGEN_Parameters_2D" )
156 _hypParameters = static_cast<const NETGENPlugin_Hypothesis_2D*>(hyp);
157 else if ( hypName == StdMeshers_ViscousLayers2D::GetHypType() )
160 aStatus = HYP_INCOMPATIBLE;
165 int nbHyps = bool(_hypMaxElementArea) + bool(_hypLengthFromEdges) + bool(_hypParameters );
167 aStatus = HYP_CONCURRENT;
169 error( StdMeshers_ViscousLayers2D::CheckHypothesis( aMesh, aShape, aStatus ));
173 if ( aStatus == HYP_OK && _hypParameters && _hypQuadranglePreference )
175 aStatus = HYP_INCOMPAT_HYPS;
176 return error(SMESH_Comment("\"") << _hypQuadranglePreference->GetName()
177 << "\" and \"" << _hypParameters->GetName()
178 << "\" are incompatible hypotheses");
181 return ( aStatus == HYP_OK );
186 // void limitSize( netgen::Mesh* ngMesh,
187 // const double maxh )
190 // netgen::Point3d pmin, pmax;
191 // ngMesh->GetBox( pmin, pmax, 0 );
192 // const double dx = pmax.X() - pmin.X();
193 // const double dy = pmax.Y() - pmin.Y();
194 // const double dz = pmax.Z() - pmin.Z();
196 // const int nbX = Max( 2, int( dx / maxh * 3 ));
197 // const int nbY = Max( 2, int( dy / maxh * 3 ));
198 // const int nbZ = Max( 2, int( dz / maxh * 3 ));
200 // if ( ! & ngMesh->LocalHFunction() )
201 // ngMesh->SetLocalH( pmin, pmax, 0.1 );
203 // netgen::Point3d p;
204 // for ( int i = 0; i <= nbX; ++i )
206 // p.X() = pmin.X() + i * dx / nbX;
207 // for ( int j = 0; j <= nbY; ++j )
209 // p.Y() = pmin.Y() + j * dy / nbY;
210 // for ( int k = 0; k <= nbZ; ++k )
212 // p.Z() = pmin.Z() + k * dz / nbZ;
213 // ngMesh->RestrictLocalH( p, maxh );
220 //=============================================================================
222 *Here we are going to use the NETGEN mesher
224 //=============================================================================
226 bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh,
227 const TopoDS_Shape& aShape)
229 netgen::multithread.terminate = 0;
230 //netgen::multithread.task = "Surface meshing";
232 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
233 SMESH_MesherHelper helper(aMesh);
234 helper.SetElementsOnShape( true );
236 NETGENPlugin_NetgenLibWrapper ngLib;
237 ngLib._isComputeOk = false;
239 netgen::Mesh ngMeshNoLocSize;
240 netgen::Mesh * ngMeshes[2] = { (netgen::Mesh*) ngLib._ngMesh, & ngMeshNoLocSize };
241 netgen::OCCGeometry occgeoComm;
243 // min / max sizes are set as follows:
244 // if ( _hypParameters )
245 // min and max are defined by the user
246 // else if ( _hypLengthFromEdges )
247 // min = aMesher.GetDefaultMinSize()
248 // max = average segment len of a FACE
249 // else if ( _hypMaxElementArea )
250 // min = aMesher.GetDefaultMinSize()
251 // max = f( _hypMaxElementArea )
253 // min = aMesher.GetDefaultMinSize()
254 // max = max segment len of a FACE
256 NETGENPlugin_Mesher aMesher( &aMesh, aShape, /*isVolume=*/false);
257 aMesher.SetParameters( _hypParameters ); // _hypParameters -> netgen::mparam
258 const bool toOptimize = _hypParameters ? _hypParameters->GetOptimize() : true;
259 if ( _hypMaxElementArea )
261 netgen::mparam.maxh = sqrt( 2. * _hypMaxElementArea->GetMaxArea() / sqrt(3.0) );
263 if ( _hypQuadranglePreference )
264 netgen::mparam.quad = true;
266 // local size is common for all FACEs in aShape?
267 const bool isCommonLocalSize = ( !_hypLengthFromEdges && !_hypMaxElementArea && netgen::mparam.uselocalh );
268 const bool isDefaultHyp = ( !_hypLengthFromEdges && !_hypMaxElementArea && !_hypParameters );
270 if ( isCommonLocalSize ) // compute common local size in ngMeshes[0]
272 //list< SMESH_subMesh* > meshedSM[4]; --> all sub-shapes are added to occgeoComm
273 aMesher.PrepareOCCgeometry( occgeoComm, aShape, aMesh );//, meshedSM );
275 // local size set at MESHCONST_ANALYSE step depends on
276 // minh, face_maxh, grading and curvaturesafety; find minh if not set by the user
277 if ( !_hypParameters || netgen::mparam.minh < DBL_MIN )
279 if ( !_hypParameters )
280 netgen::mparam.maxh = occgeoComm.GetBoundingBox().Diam() / 3.;
281 netgen::mparam.minh = aMesher.GetDefaultMinSize( aShape, netgen::mparam.maxh );
283 // set local size depending on curvature and NOT closeness of EDGEs
285 const double factor = 2; //netgen::occparam.resthcloseedgefac;
287 const double factor = netgen::occparam.resthcloseedgefac;
288 netgen::occparam.resthcloseedgeenable = false;
289 netgen::occparam.resthcloseedgefac = 1.0 + netgen::mparam.grading;
291 occgeoComm.face_maxh = netgen::mparam.maxh;
293 netgen::OCCParameters occparam;
294 netgen::OCCSetLocalMeshSize( occgeoComm, *ngMeshes[0], netgen::mparam, occparam );
296 netgen::OCCSetLocalMeshSize( occgeoComm, *ngMeshes[0] );
298 occgeoComm.emap.Clear();
299 occgeoComm.vmap.Clear();
301 // set local size according to size of existing segments
302 TopTools_IndexedMapOfShape edgeMap;
303 TopExp::MapShapes( aMesh.GetShapeToMesh(), TopAbs_EDGE, edgeMap );
304 for ( int iE = 1; iE <= edgeMap.Extent(); ++iE )
306 const TopoDS_Shape& edge = edgeMap( iE );
307 if ( SMESH_Algo::isDegenerated( TopoDS::Edge( edge )))
309 SMESHDS_SubMesh* smDS = meshDS->MeshElements( edge );
310 if ( !smDS ) continue;
311 SMDS_ElemIteratorPtr segIt = smDS->GetElements();
312 while ( segIt->more() )
314 const SMDS_MeshElement* seg = segIt->next();
315 SMESH_TNodeXYZ n1 = seg->GetNode(0);
316 SMESH_TNodeXYZ n2 = seg->GetNode(1);
317 gp_XYZ p = 0.5 * ( n1 + n2 );
318 netgen::Point3d pi(p.X(), p.Y(), p.Z());
319 ngMeshes[0]->RestrictLocalH( pi, factor * ( n1 - n2 ).Modulus() );
323 // set local size defined on shapes
324 aMesher.SetLocalSize( occgeoComm, *ngMeshes[0] );
325 aMesher.SetLocalSizeForChordalError( occgeoComm, *ngMeshes[0] );
327 ngMeshes[0]->LoadLocalMeshSize( mparam.meshsizefilename );
328 } catch (NgException & ex) {
329 return error( COMPERR_BAD_PARMETERS, ex.What() );
332 netgen::mparam.uselocalh = toOptimize; // restore as it is used at surface optimization
334 // ==================
336 // ==================
338 vector< const SMDS_MeshNode* > nodeVec;
340 TopExp_Explorer fExp( aShape, TopAbs_FACE );
341 for ( int iF = 0; fExp.More(); fExp.Next(), ++iF )
343 TopoDS_Face F = TopoDS::Face( fExp.Current() /*.Oriented( TopAbs_FORWARD )*/);
344 int faceID = meshDS->ShapeToIndex( F );
345 SMESH_ComputeErrorPtr& faceErr = aMesh.GetSubMesh( F )->GetComputeError();
347 _quadraticMesh = helper.IsQuadraticSubMesh( F );
348 const bool ignoreMediumNodes = _quadraticMesh;
350 // build viscous layers if required
351 if ( F.Orientation() != TopAbs_FORWARD &&
352 F.Orientation() != TopAbs_REVERSED )
353 F.Orientation( TopAbs_FORWARD ); // avoid pb with TopAbs_INTERNAL
354 SMESH_ProxyMesh::Ptr proxyMesh = StdMeshers_ViscousLayers2D::Compute( aMesh, F );
358 // ------------------------
359 // get all EDGEs of a FACE
360 // ------------------------
362 StdMeshers_FaceSide::GetFaceWires( F, aMesh, ignoreMediumNodes, faceErr, &helper, proxyMesh );
363 if ( faceErr && !faceErr->IsOK() )
365 size_t nbWires = wires.size();
369 ( new SMESH_ComputeError
370 ( COMPERR_ALGO_FAILED, "Problem in StdMeshers_FaceSide::GetFaceWires()" ));
373 if ( wires[0]->NbSegments() < 3 ) // ex: a circle with 2 segments
376 ( new SMESH_ComputeError
377 ( COMPERR_BAD_INPUT_MESH, SMESH_Comment("Too few segments: ")<<wires[0]->NbSegments()) );
381 // ----------------------
382 // compute maxh of a FACE
383 // ----------------------
385 if ( !_hypParameters )
387 double edgeLength = 0;
388 if (_hypLengthFromEdges )
390 // compute edgeLength as an average segment length
391 smIdType nbSegments = 0;
392 for ( size_t iW = 0; iW < nbWires; ++iW )
394 edgeLength += wires[ iW ]->Length();
395 nbSegments += wires[ iW ]->NbSegments();
398 edgeLength /= double( nbSegments );
399 netgen::mparam.maxh = edgeLength;
401 else if ( isDefaultHyp )
403 // set edgeLength by a longest segment
405 for ( size_t iW = 0; iW < nbWires; ++iW )
407 const UVPtStructVec& points = wires[ iW ]->GetUVPtStruct();
408 if ( points.empty() )
409 return error( COMPERR_BAD_INPUT_MESH );
410 gp_Pnt pPrev = SMESH_TNodeXYZ( points[0].node );
411 for ( size_t i = 1; i < points.size(); ++i )
413 gp_Pnt p = SMESH_TNodeXYZ( points[i].node );
414 maxSeg2 = Max( maxSeg2, p.SquareDistance( pPrev ));
418 edgeLength = sqrt( maxSeg2 ) * 1.05;
419 netgen::mparam.maxh = edgeLength;
421 if ( netgen::mparam.maxh < DBL_MIN )
422 netgen::mparam.maxh = occgeoComm.GetBoundingBox().Diam();
424 if ( !isCommonLocalSize )
426 netgen::mparam.minh = aMesher.GetDefaultMinSize( F, netgen::mparam.maxh );
431 netgen::OCCGeometry occgeom;
433 occgeom.fmap.Add( F );
434 occgeom.CalcBoundingBox();
435 occgeom.facemeshstatus.SetSize(1);
436 occgeom.facemeshstatus = 0;
437 occgeom.face_maxh_modified.SetSize(1);
438 occgeom.face_maxh_modified = 0;
439 occgeom.face_maxh.SetSize(1);
440 occgeom.face_maxh = netgen::mparam.maxh;
442 // -------------------------
444 // -------------------------
446 // MESHCONST_ANALYSE step may lead to a failure, so we make an attempt
447 // w/o MESHCONST_ANALYSE at the second loop
449 enum { LOC_SIZE, NO_LOC_SIZE };
450 int iLoop = isCommonLocalSize ? 0 : 1;
451 for ( ; iLoop < 2; iLoop++ )
453 //bool isMESHCONST_ANALYSE = false;
456 netgen::Mesh * ngMesh = ngMeshes[ iLoop ];
457 ngMesh->DeleteMesh();
459 if ( iLoop == NO_LOC_SIZE )
461 ngMesh->SetGlobalH ( mparam.maxh );
462 ngMesh->SetMinimalH( mparam.minh );
463 Box<3> bb = occgeom.GetBoundingBox();
464 bb.Increase (bb.Diam()/10);
465 ngMesh->SetLocalH (bb.PMin(), bb.PMax(), mparam.grading);
466 aMesher.SetLocalSize( occgeom, *ngMesh );
467 aMesher.SetLocalSizeForChordalError( occgeoComm, *ngMesh );
469 ngMesh->LoadLocalMeshSize( mparam.meshsizefilename );
470 } catch (NgException & ex) {
471 return error( COMPERR_BAD_PARMETERS, ex.What() );
476 faceErr = aMesher.AddSegmentsToMesh( *ngMesh, occgeom, wires, helper, nodeVec,
477 /*overrideMinH=*/!_hypParameters);
478 if ( faceErr && !faceErr->IsOK() )
481 //if ( !isCommonLocalSize )
482 //limitSize( ngMesh, mparam.maxh * 0.8);
484 // -------------------------
485 // Generate surface mesh
486 // -------------------------
488 const int startWith = MESHCONST_MESHSURFACE;
489 const int endWith = toOptimize ? MESHCONST_OPTSURFACE : MESHCONST_MESHSURFACE;
495 err = ngLib.GenerateMesh(occgeom, startWith, endWith, ngMesh);
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 = (int) 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 smIdType 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<smIdType> aVec = (*anIt).second;
674 nb0d += aVec[SMDSEntity_Node];
675 nb1d += std::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 / double( 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 smIdType nbFaces = (smIdType) ( anArea / ( ELen*ELen*sqrt(3.) / 4 ) );
708 smIdType nbNodes = (smIdType) ( ( nbFaces*3 - (nb1d-1)*2 ) / 6 + 1 );
709 std::vector<smIdType> aVec(SMDSEntity_Last);
710 for(smIdType 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));