1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 //=============================================================================
24 // File : NETGENPlugin_NETGEN_3D.cxx
25 // Moved here from SMESH_NETGEN_3D.cxx
26 // Created : lundi 27 Janvier 2003
27 // Author : Nadir BOUHAMOU (CEA)
29 //=============================================================================
31 #include "NETGENPlugin_NETGEN_3D.hxx"
33 #include "NETGENPlugin_Hypothesis.hxx"
35 #include <SMDS_MeshElement.hxx>
36 #include <SMDS_MeshNode.hxx>
37 #include <SMESHDS_Mesh.hxx>
38 #include <SMESH_Comment.hxx>
39 #include <SMESH_ControlsDef.hxx>
40 #include <SMESH_Gen.hxx>
41 #include <SMESH_Mesh.hxx>
42 #include <SMESH_MeshEditor.hxx>
43 #include <SMESH_MesherHelper.hxx>
44 #include <SMESH_subMesh.hxx>
45 #include <StdMeshers_MaxElementVolume.hxx>
46 #include <StdMeshers_QuadToTriaAdaptor.hxx>
47 #include <StdMeshers_ViscousLayers.hxx>
49 #include <BRepGProp.hxx>
50 #include <BRep_Tool.hxx>
51 #include <GProp_GProps.hxx>
53 #include <TopExp_Explorer.hxx>
54 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <Standard_Failure.hxx>
58 #include <Standard_ErrorHandler.hxx>
60 #include <utilities.h>
73 #include <occgeom.hpp>
74 #include <ngexception.hpp>
80 extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, MeshingParameters&, int, int);
82 extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, int, int, char*);
85 NETGENPLUGIN_DLL_HEADER
86 extern MeshingParameters mparam;
88 NETGENPLUGIN_DLL_HEADER
89 extern volatile multithreadt multithread;
91 using namespace nglib;
94 //=============================================================================
98 //=============================================================================
100 NETGENPlugin_NETGEN_3D::NETGENPlugin_NETGEN_3D(int hypId, SMESH_Gen* gen)
101 : SMESH_3D_Algo(hypId, gen)
104 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
105 _compatibleHypothesis.push_back("MaxElementVolume");
106 _compatibleHypothesis.push_back("NETGEN_Parameters");
107 _compatibleHypothesis.push_back("ViscousLayers");
109 _maxElementVolume = 0.;
111 _hypMaxElementVolume = NULL;
112 _hypParameters = NULL;
113 _viscousLayersHyp = NULL;
115 _requireShape = false; // can work without shape
118 //=============================================================================
122 //=============================================================================
124 NETGENPlugin_NETGEN_3D::~NETGENPlugin_NETGEN_3D()
128 //=============================================================================
132 //=============================================================================
134 bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh& aMesh,
135 const TopoDS_Shape& aShape,
136 Hypothesis_Status& aStatus)
138 _hypMaxElementVolume = NULL;
139 _hypParameters = NULL;
140 _viscousLayersHyp = NULL;
141 _maxElementVolume = DBL_MAX;
143 // for correct work of GetProgress():
144 netgen::multithread.percent = 0.;
145 netgen::multithread.task = "Volume meshing";
146 _progressByTic = -1.;
148 list<const SMESHDS_Hypothesis*>::const_iterator itl;
149 //const SMESHDS_Hypothesis* theHyp;
151 const list<const SMESHDS_Hypothesis*>& hyps =
152 GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliary=*/false);
153 list <const SMESHDS_Hypothesis* >::const_iterator h = hyps.begin();
154 if ( h == hyps.end())
156 aStatus = SMESH_Hypothesis::HYP_OK;
157 return true; // can work with no hypothesis
161 for ( ; h != hyps.end(); ++h )
163 if ( !_hypMaxElementVolume )
164 _hypMaxElementVolume = dynamic_cast< const StdMeshers_MaxElementVolume*> ( *h );
165 if ( !_viscousLayersHyp ) // several _viscousLayersHyp's allowed
166 _viscousLayersHyp = dynamic_cast< const StdMeshers_ViscousLayers*> ( *h );
167 if ( ! _hypParameters )
168 _hypParameters = dynamic_cast< const NETGENPlugin_Hypothesis*> ( *h );
170 if ( *h != _hypMaxElementVolume &&
171 *h != _viscousLayersHyp &&
172 *h != _hypParameters &&
173 !dynamic_cast< const StdMeshers_ViscousLayers*>(*h)) // several VL hyps allowed
174 aStatus = HYP_INCOMPATIBLE;
176 if ( _hypMaxElementVolume && _hypParameters )
177 aStatus = HYP_INCOMPATIBLE;
178 else if ( aStatus == HYP_OK && _viscousLayersHyp )
179 error( _viscousLayersHyp->CheckHypothesis( aMesh, aShape, aStatus ));
181 if ( _hypMaxElementVolume )
182 _maxElementVolume = _hypMaxElementVolume->GetMaxVolume();
184 return aStatus == HYP_OK;
187 //=============================================================================
189 *Here we are going to use the NETGEN mesher
191 //=============================================================================
193 bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh,
194 const TopoDS_Shape& aShape)
196 netgen::multithread.terminate = 0;
197 netgen::multithread.task = "Volume meshing";
198 _progressByTic = -1.;
200 SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
202 SMESH_MesherHelper helper(aMesh);
203 _quadraticMesh = helper.IsQuadraticSubMesh(aShape);
204 helper.SetElementsOnShape( true );
206 int Netgen_NbOfNodes = 0;
207 double Netgen_point[3];
208 int Netgen_triangle[3];
210 NETGENPlugin_NetgenLibWrapper ngLib;
211 Ng_Mesh * Netgen_mesh = ngLib._ngMesh;
213 // vector of nodes in which node index == netgen ID
214 vector< const SMDS_MeshNode* > nodeVec;
216 const int invalid_ID = -1;
218 SMESH::Controls::Area areaControl;
219 SMESH::Controls::TSequenceOfXYZ nodesCoords;
221 // maps nodes to ng ID
222 typedef map< const SMDS_MeshNode*, int, TIDCompare > TNodeToIDMap;
223 typedef TNodeToIDMap::value_type TN2ID;
224 TNodeToIDMap nodeToNetgenID;
226 // find internal shapes
227 NETGENPlugin_Internals internals( aMesh, aShape, /*is3D=*/true );
229 // ---------------------------------
230 // Feed the Netgen with surface mesh
231 // ---------------------------------
233 TopAbs_ShapeEnum mainType = aMesh.GetShapeToMesh().ShapeType();
234 bool checkReverse = ( mainType == TopAbs_COMPOUND || mainType == TopAbs_COMPSOLID );
236 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( aMesh ));
237 if ( _viscousLayersHyp )
239 netgen::multithread.percent = 3;
240 proxyMesh = _viscousLayersHyp->Compute( aMesh, aShape );
244 if ( aMesh.NbQuadrangles() > 0 )
246 netgen::multithread.percent = 6;
247 StdMeshers_QuadToTriaAdaptor* Adaptor = new StdMeshers_QuadToTriaAdaptor;
248 Adaptor->Compute(aMesh,aShape,proxyMesh.get());
249 proxyMesh.reset( Adaptor );
252 for ( TopExp_Explorer exFa( aShape, TopAbs_FACE ); exFa.More(); exFa.Next())
254 const TopoDS_Shape& aShapeFace = exFa.Current();
255 int faceID = meshDS->ShapeToIndex( aShapeFace );
256 bool isInternalFace = internals.isInternalShape( faceID );
258 if ( checkReverse && !isInternalFace &&
259 helper.NbAncestors(aShapeFace, aMesh, aShape.ShapeType()) > 1 )
260 // IsReversedSubMesh() can work wrong on strongly curved faces,
261 // so we use it as less as possible
262 isRev = helper.IsReversedSubMesh( TopoDS::Face( aShapeFace ));
264 const SMESHDS_SubMesh * aSubMeshDSFace = proxyMesh->GetSubMesh( aShapeFace );
265 if ( !aSubMeshDSFace ) continue;
266 SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
267 while ( iteratorElem->more() ) // loop on elements on a geom face
270 const SMDS_MeshElement* elem = iteratorElem->next();
272 return error( COMPERR_BAD_INPUT_MESH, "Null element encounters");
273 if ( elem->NbCornerNodes() != 3 )
274 return error( COMPERR_BAD_INPUT_MESH, "Not triangle element encounters");
276 // Add nodes of triangles and triangles them-selves to netgen mesh
278 // add three nodes of triangle
279 bool hasDegen = false;
280 for ( int iN = 0; iN < 3; ++iN )
282 const SMDS_MeshNode* node = elem->GetNode( iN );
283 const int shapeID = node->getshapeId();
284 if ( node->GetPosition()->GetTypeOfPosition() == SMDS_TOP_EDGE &&
285 helper.IsDegenShape( shapeID ))
287 // ignore all nodes on degeneraged edge and use node on its vertex instead
288 TopoDS_Shape vertex = TopoDS_Iterator( meshDS->IndexToShape( shapeID )).Value();
289 node = SMESH_Algo::VertexNode( TopoDS::Vertex( vertex ), meshDS );
292 int& ngID = nodeToNetgenID.insert(TN2ID( node, invalid_ID )).first->second;
293 if ( ngID == invalid_ID )
295 ngID = ++Netgen_NbOfNodes;
296 Netgen_point [ 0 ] = node->X();
297 Netgen_point [ 1 ] = node->Y();
298 Netgen_point [ 2 ] = node->Z();
299 Ng_AddPoint(Netgen_mesh, Netgen_point);
301 Netgen_triangle[ isRev ? 2-iN : iN ] = ngID;
304 if ( hasDegen && (Netgen_triangle[0] == Netgen_triangle[1] ||
305 Netgen_triangle[0] == Netgen_triangle[2] ||
306 Netgen_triangle[2] == Netgen_triangle[1] ))
309 Ng_AddSurfaceElement(Netgen_mesh, NG_TRIG, Netgen_triangle);
311 if ( isInternalFace && !proxyMesh->IsTemporary( elem ))
313 swap( Netgen_triangle[1], Netgen_triangle[2] );
314 Ng_AddSurfaceElement(Netgen_mesh, NG_TRIG, Netgen_triangle);
316 } // loop on elements on a face
317 } // loop on faces of a SOLID or SHELL
319 // insert old nodes into nodeVec
320 nodeVec.resize( nodeToNetgenID.size() + 1, 0 );
321 TNodeToIDMap::iterator n_id = nodeToNetgenID.begin();
322 for ( ; n_id != nodeToNetgenID.end(); ++n_id )
323 nodeVec[ n_id->second ] = n_id->first;
324 nodeToNetgenID.clear();
326 if ( internals.hasInternalVertexInSolid() )
328 netgen::OCCGeometry occgeo;
329 NETGENPlugin_Mesher::AddIntVerticesInSolids( occgeo,
330 (netgen::Mesh&) *Netgen_mesh,
336 // -------------------------
337 // Generate the volume mesh
338 // -------------------------
340 return ( ngLib._isComputeOk = compute( aMesh, helper, nodeVec, Netgen_mesh));
345 // void limitVolumeSize( netgen::Mesh* ngMesh,
348 // // get average h of faces
351 // for (int i = 1; i <= ngMesh->GetNSE(); i++)
353 // const netgen::Element2d& face = ngMesh->SurfaceElement(i);
354 // for (int j=1; j <= face.GetNP(); ++j)
356 // const netgen::PointIndex & i1 = face.PNumMod(j);
357 // const netgen::PointIndex & i2 = face.PNumMod(j+1);
360 // const netgen::Point3d & p1 = ngMesh->Point( i1 );
361 // const netgen::Point3d & p2 = ngMesh->Point( i2 );
362 // faceh += netgen::Dist2( p1, p2 );
367 // faceh = Sqrt( faceh / nbh );
370 // if ( faceh < 0.5 * maxh ) compareh = -1;
371 // else if ( faceh > 1.5 * maxh ) compareh = 1;
372 // else compareh = 0;
373 // // cerr << "faceh " << faceh << endl;
374 // // cerr << "init maxh " << maxh << endl;
375 // // cerr << "compareh " << compareh << endl;
377 // if ( compareh > 0 )
381 // // cerr << "maxh " << maxh << endl;
384 // netgen::Point3d pmin, pmax;
385 // ngMesh->GetBox( pmin, pmax, 0 );
386 // const double dx = pmax.X() - pmin.X();
387 // const double dy = pmax.Y() - pmin.Y();
388 // const double dz = pmax.Z() - pmin.Z();
390 // if ( ! & ngMesh->LocalHFunction() )
391 // ngMesh->SetLocalH( pmin, pmax, compareh <= 0 ? 0.1 : 0.5 );
393 // // adjusted by SALOME_TESTS/Grids/smesh/bugs_08/I8
394 // const int nbX = Max( 2, int( dx / maxh * 2 ));
395 // const int nbY = Max( 2, int( dy / maxh * 2 ));
396 // const int nbZ = Max( 2, int( dz / maxh * 2 ));
398 // netgen::Point3d p;
399 // for ( int i = 0; i <= nbX; ++i )
401 // p.X() = pmin.X() + i * dx / nbX;
402 // for ( int j = 0; j <= nbY; ++j )
404 // p.Y() = pmin.Y() + j * dy / nbY;
405 // for ( int k = 0; k <= nbZ; ++k )
407 // p.Z() = pmin.Z() + k * dz / nbZ;
408 // ngMesh->RestrictLocalH( p, maxh );
415 //================================================================================
417 * \brief set parameters and generate the volume mesh
419 //================================================================================
421 bool NETGENPlugin_NETGEN_3D::compute(SMESH_Mesh& aMesh,
422 SMESH_MesherHelper& helper,
423 vector< const SMDS_MeshNode* >& nodeVec,
424 Ng_Mesh * Netgen_mesh)
426 netgen::multithread.terminate = 0;
428 netgen::Mesh* ngMesh = (netgen::Mesh*)Netgen_mesh;
429 int Netgen_NbOfNodes = Ng_GetNP(Netgen_mesh);
434 int startWith = netgen::MESHCONST_MESHVOLUME;
435 int endWith = netgen::MESHCONST_OPTVOLUME;
438 NETGENPlugin_Mesher aMesher( &aMesh, helper.GetSubShape(), /*isVolume=*/true );
439 netgen::OCCGeometry occgeo;
441 if ( _hypParameters )
443 aMesher.SetParameters( _hypParameters );
445 if ( !_hypParameters->GetLocalSizesAndEntries().empty() ||
446 !_hypParameters->GetMeshSizeFile().empty() )
448 if ( ! &ngMesh->LocalHFunction() )
450 netgen::Point3d pmin, pmax;
451 ngMesh->GetBox( pmin, pmax, 0 );
452 ngMesh->SetLocalH( pmin, pmax, _hypParameters->GetGrowthRate() );
454 aMesher.SetLocalSize( occgeo, *ngMesh );
457 ngMesh->LoadLocalMeshSize( netgen::mparam.meshsizefilename );
458 } catch (netgen::NgException & ex) {
459 return error( COMPERR_BAD_PARMETERS, ex.What() );
462 if ( !_hypParameters->GetOptimize() )
463 endWith = netgen::MESHCONST_MESHVOLUME;
465 else if ( _hypMaxElementVolume )
467 netgen::mparam.maxh = pow( 72, 1/6. ) * pow( _maxElementVolume, 1/3. );
468 // limitVolumeSize( ngMesh, netgen::mparam.maxh ); // result is unpredictable
470 else if ( aMesh.HasShapeToMesh() )
472 aMesher.PrepareOCCgeometry( occgeo, helper.GetSubShape(), aMesh );
473 netgen::mparam.maxh = occgeo.GetBoundingBox().Diam()/2;
477 netgen::Point3d pmin, pmax;
478 ngMesh->GetBox (pmin, pmax);
479 netgen::mparam.maxh = Dist(pmin, pmax)/2;
482 if ( !_hypParameters && aMesh.HasShapeToMesh() )
484 netgen::mparam.minh = aMesher.GetDefaultMinSize( helper.GetSubShape(), netgen::mparam.maxh );
492 ngMesh->CalcLocalH(netgen::mparam.grading);
493 err = netgen::OCCGenerateMesh(occgeo, ngMesh, netgen::mparam, startWith, endWith);
495 ngMesh->CalcLocalH();
496 err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr);
498 if(netgen::multithread.terminate)
501 error(SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task);
503 catch (Standard_Failure& ex)
505 SMESH_Comment str("Exception in netgen::OCCGenerateMesh()");
506 str << " at " << netgen::multithread.task
507 << ": " << ex.DynamicType()->Name();
508 if ( ex.GetMessageString() && strlen( ex.GetMessageString() ))
509 str << ": " << ex.GetMessageString();
512 catch (netgen::NgException exc)
514 SMESH_Comment str("NgException");
515 if ( strlen( netgen::multithread.task ) > 0 )
516 str << " at " << netgen::multithread.task;
517 str << ": " << exc.What();
522 SMESH_Comment str("Exception in netgen::OCCGenerateMesh()");
523 if ( strlen( netgen::multithread.task ) > 0 )
524 str << " at " << netgen::multithread.task;
528 int Netgen_NbOfNodesNew = Ng_GetNP(Netgen_mesh);
529 int Netgen_NbOfTetra = Ng_GetNE(Netgen_mesh);
531 // -------------------------------------------------------------------
532 // Feed back the SMESHDS with the generated Nodes and Volume Elements
533 // -------------------------------------------------------------------
537 SMESH_ComputeErrorPtr ce = NETGENPlugin_Mesher::ReadErrors(nodeVec);
538 if ( ce && ce->HasBadElems() )
542 bool isOK = ( /*status == NG_OK &&*/ Netgen_NbOfTetra > 0 );// get whatever built
545 double Netgen_point[3];
546 int Netgen_tetrahedron[4];
548 // create and insert new nodes into nodeVec
549 nodeVec.resize( Netgen_NbOfNodesNew + 1, 0 );
550 int nodeIndex = Netgen_NbOfNodes + 1;
551 for ( ; nodeIndex <= Netgen_NbOfNodesNew; ++nodeIndex )
553 Ng_GetPoint( Netgen_mesh, nodeIndex, Netgen_point );
554 nodeVec.at(nodeIndex) = helper.AddNode(Netgen_point[0], Netgen_point[1], Netgen_point[2]);
557 // create tetrahedrons
558 for ( int elemIndex = 1; elemIndex <= Netgen_NbOfTetra; ++elemIndex )
560 Ng_GetVolumeElement(Netgen_mesh, elemIndex, Netgen_tetrahedron);
563 helper.AddVolume (nodeVec.at( Netgen_tetrahedron[0] ),
564 nodeVec.at( Netgen_tetrahedron[1] ),
565 nodeVec.at( Netgen_tetrahedron[2] ),
566 nodeVec.at( Netgen_tetrahedron[3] ));
577 //================================================================================
579 * \brief Compute tetrahedral mesh from 2D mesh without geometry
581 //================================================================================
583 bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh,
584 SMESH_MesherHelper* aHelper)
586 const int invalid_ID = -1;
588 netgen::multithread.terminate = 0;
589 _progressByTic = -1.;
591 SMESH_MesherHelper::MType MeshType = aHelper->IsQuadraticMesh();
592 if ( MeshType == SMESH_MesherHelper::COMP )
593 return error( COMPERR_BAD_INPUT_MESH,
594 SMESH_Comment("Mesh with linear and quadratic elements given"));
596 aHelper->SetIsQuadratic( MeshType == SMESH_MesherHelper::QUADRATIC );
598 // ---------------------------------
599 // Feed the Netgen with surface mesh
600 // ---------------------------------
602 int Netgen_NbOfNodes = 0;
603 double Netgen_point[3];
604 int Netgen_triangle[3];
606 NETGENPlugin_NetgenLibWrapper ngLib;
607 Ng_Mesh * Netgen_mesh = ngLib._ngMesh;
609 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( aMesh ));
610 if ( aMesh.NbQuadrangles() > 0 )
612 StdMeshers_QuadToTriaAdaptor* Adaptor = new StdMeshers_QuadToTriaAdaptor;
613 Adaptor->Compute(aMesh);
614 proxyMesh.reset( Adaptor );
617 // maps nodes to ng ID
618 typedef map< const SMDS_MeshNode*, int, TIDCompare > TNodeToIDMap;
619 typedef TNodeToIDMap::value_type TN2ID;
620 TNodeToIDMap nodeToNetgenID;
622 SMDS_ElemIteratorPtr fIt = proxyMesh->GetFaces();
626 const SMDS_MeshElement* elem = fIt->next();
628 return error( COMPERR_BAD_INPUT_MESH, "Null element encounters");
629 if ( elem->NbCornerNodes() != 3 )
630 return error( COMPERR_BAD_INPUT_MESH, "Not triangle element encounters");
632 // add three nodes of triangle
633 for ( int iN = 0; iN < 3; ++iN )
635 const SMDS_MeshNode* node = elem->GetNode( iN );
636 int& ngID = nodeToNetgenID.insert(TN2ID( node, invalid_ID )).first->second;
637 if ( ngID == invalid_ID )
639 ngID = ++Netgen_NbOfNodes;
640 Netgen_point [ 0 ] = node->X();
641 Netgen_point [ 1 ] = node->Y();
642 Netgen_point [ 2 ] = node->Z();
643 Ng_AddPoint(Netgen_mesh, Netgen_point);
645 Netgen_triangle[ iN ] = ngID;
647 Ng_AddSurfaceElement(Netgen_mesh, NG_TRIG, Netgen_triangle);
649 proxyMesh.reset(); // delete tmp faces
651 // vector of nodes in which node index == netgen ID
652 vector< const SMDS_MeshNode* > nodeVec ( nodeToNetgenID.size() + 1 );
653 // insert old nodes into nodeVec
654 TNodeToIDMap::iterator n_id = nodeToNetgenID.begin();
655 for ( ; n_id != nodeToNetgenID.end(); ++n_id )
656 nodeVec.at( n_id->second ) = n_id->first;
657 nodeToNetgenID.clear();
659 // -------------------------
660 // Generate the volume mesh
661 // -------------------------
663 return ( ngLib._isComputeOk = compute( aMesh, *aHelper, nodeVec, Netgen_mesh));
666 void NETGENPlugin_NETGEN_3D::CancelCompute()
668 SMESH_Algo::CancelCompute();
669 netgen::multithread.terminate = 1;
672 //================================================================================
674 * \brief Return Compute progress
676 //================================================================================
678 double NETGENPlugin_NETGEN_3D::GetProgress() const
681 const char* volMeshing = "Volume meshing";
682 const char* dlnMeshing = "Delaunay meshing";
683 const double meshingRatio = 0.15;
684 const_cast<NETGENPlugin_NETGEN_3D*>( this )->_progressTic++;
686 if ( _progressByTic < 0. &&
687 ( strncmp( netgen::multithread.task, dlnMeshing, 3 ) == 0 ||
688 strncmp( netgen::multithread.task, volMeshing, 3 ) == 0 ))
690 res = 0.001 + meshingRatio * netgen::multithread.percent / 100.;
691 //cout << netgen::multithread.task << " " <<_progressTic << "-" << netgen::multithread.percent << endl;
693 else // different otimizations
695 if ( _progressByTic < 0. )
696 ((NETGENPlugin_NETGEN_3D*)this)->_progressByTic = meshingRatio / _progressTic;
697 res = _progressByTic * _progressTic;
698 //cout << netgen::multithread.task << " " << _progressTic << " " << res << endl;
700 return Min ( res, 0.98 );
703 //=============================================================================
707 //=============================================================================
709 bool NETGENPlugin_NETGEN_3D::Evaluate(SMESH_Mesh& aMesh,
710 const TopoDS_Shape& aShape,
711 MapShapeNbElems& aResMap)
713 int nbtri = 0, nbqua = 0;
714 double fullArea = 0.0;
715 for (TopExp_Explorer expF(aShape, TopAbs_FACE); expF.More(); expF.Next()) {
716 TopoDS_Face F = TopoDS::Face( expF.Current() );
717 SMESH_subMesh *sm = aMesh.GetSubMesh(F);
718 MapShapeNbElemsItr anIt = aResMap.find(sm);
719 if( anIt==aResMap.end() ) {
720 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
721 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
724 std::vector<int> aVec = (*anIt).second;
725 nbtri += Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
726 nbqua += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
728 BRepGProp::SurfaceProperties(F,G);
729 double anArea = G.Mass();
733 // collect info from edges
734 int nb0d_e = 0, nb1d_e = 0;
735 bool IsQuadratic = false;
737 TopTools_MapOfShape tmpMap;
738 for (TopExp_Explorer expF(aShape, TopAbs_EDGE); expF.More(); expF.Next()) {
739 TopoDS_Edge E = TopoDS::Edge(expF.Current());
740 if( tmpMap.Contains(E) )
743 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(expF.Current());
744 MapShapeNbElemsItr anIt = aResMap.find(aSubMesh);
745 if( anIt==aResMap.end() ) {
746 SMESH_ComputeErrorPtr& smError = aSubMesh->GetComputeError();
747 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,
748 "Submesh can not be evaluated",this));
751 std::vector<int> aVec = (*anIt).second;
752 nb0d_e += aVec[SMDSEntity_Node];
753 nb1d_e += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
755 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
761 double ELen_face = sqrt(2.* ( fullArea/(nbtri+nbqua*2) ) / sqrt(3.0) );
762 double ELen_vol = pow( 72, 1/6. ) * pow( _maxElementVolume, 1/3. );
763 double ELen = Min(ELen_vol,ELen_face*2);
766 BRepGProp::VolumeProperties(aShape,G);
767 double aVolume = G.Mass();
768 double tetrVol = 0.1179*ELen*ELen*ELen;
769 double CoeffQuality = 0.9;
770 int nbVols = int( aVolume/tetrVol/CoeffQuality );
771 int nb1d_f = (nbtri*3 + nbqua*4 - nb1d_e) / 2;
772 int nb1d_in = (nbVols*6 - nb1d_e - nb1d_f ) / 5;
773 std::vector<int> aVec(SMDSEntity_Last);
774 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i]=0;
776 aVec[SMDSEntity_Node] = nb1d_in/6 + 1 + nb1d_in;
777 aVec[SMDSEntity_Quad_Tetra] = nbVols - nbqua*2;
778 aVec[SMDSEntity_Quad_Pyramid] = nbqua;
781 aVec[SMDSEntity_Node] = nb1d_in/6 + 1;
782 aVec[SMDSEntity_Tetra] = nbVols - nbqua*2;
783 aVec[SMDSEntity_Pyramid] = nbqua;
785 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
786 aResMap.insert(std::make_pair(sm,aVec));