1 // Copyright (C) 2004-2013 CEA/DEN, EDF R&D
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.
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 //=============================================================================
21 // File : GHS3DPlugin_GHS3D.cxx
23 // Author : Edward AGAPOV, modified by Lioka RAZAFINDRAZAKA (CEA) 09/02/2007
25 //=============================================================================
27 #include "GHS3DPlugin_GHS3D.hxx"
28 #include "GHS3DPlugin_Hypothesis.hxx"
30 #include <Basics_Utils.hxx>
32 //#include <SMESH_Gen.hxx>
33 #include <SMESH_Client.hxx>
34 #include <SMESH_Mesh.hxx>
35 #include <SMESH_Comment.hxx>
36 #include <SMESH_MesherHelper.hxx>
37 #include <SMESH_MeshEditor.hxx>
38 #include <SMESH_OctreeNode.hxx>
39 #include <SMESH_Group.hxx>
40 #include <SMESH_subMeshEventListener.hxx>
41 #include <SMESH_HypoFilter.hxx>
42 #include <SMESH_MeshAlgos.hxx>
44 #include <SMDS_MeshElement.hxx>
45 #include <SMDS_MeshNode.hxx>
46 #include <SMDS_FaceOfNodes.hxx>
47 #include <SMDS_VolumeOfNodes.hxx>
49 #include <SMESHDS_Group.hxx>
51 #include <StdMeshers_QuadToTriaAdaptor.hxx>
52 #include <StdMeshers_ViscousLayers.hxx>
54 #include <BRepAdaptor_Surface.hxx>
55 #include <BRepBndLib.hxx>
56 #include <BRepBuilderAPI_MakeVertex.hxx>
57 #include <BRepClass3d_SolidClassifier.hxx>
58 #include <BRepExtrema_DistShapeShape.hxx>
59 #include <BRepGProp.hxx>
60 #include <BRepTools.hxx>
61 #include <BRep_Tool.hxx>
62 #include <Bnd_Box.hxx>
63 #include <GProp_GProps.hxx>
64 #include <GeomAPI_ProjectPointOnSurf.hxx>
65 #include <OSD_File.hxx>
66 #include <Precision.hxx>
67 #include <Quantity_Parameter.hxx>
68 #include <Standard_ErrorHandler.hxx>
69 #include <Standard_Failure.hxx>
70 #include <Standard_ProgramError.hxx>
72 #include <TopExp_Explorer.hxx>
73 #include <TopTools_IndexedMapOfShape.hxx>
74 #include <TopTools_ListIteratorOfListOfShape.hxx>
75 #include <TopTools_MapOfShape.hxx>
77 #include <TopoDS_Shape.hxx>
78 #include <TopoDS_Solid.hxx>
80 #include <utilities.h>
85 #include <sys/sysinfo.h>
89 //#include <Standard_Stream.hxx>
92 #define castToNode(n) static_cast<const SMDS_MeshNode *>( n );
105 #include <sys/mman.h>
107 #include <sys/stat.h>
113 typedef const list<const SMDS_MeshFace*> TTriaList;
115 static const char theDomainGroupNamePrefix[] = "Domain_";
117 static void removeFile( const TCollection_AsciiString& fileName )
120 OSD_File( fileName ).Remove();
122 catch ( Standard_ProgramError ) {
123 MESSAGE("Can't remove file: " << fileName.ToCString() << " ; file does not exist or permission denied");
127 //=============================================================================
131 //=============================================================================
133 GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D(int hypId, int studyId, SMESH_Gen* gen)
134 : SMESH_3D_Algo(hypId, studyId, gen)
136 MESSAGE("GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D");
138 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
139 _onlyUnaryInput = false; // Compute() will be called on a compound of solids
142 _compatibleHypothesis.push_back( GHS3DPlugin_Hypothesis::GetHypType());
143 _compatibleHypothesis.push_back( StdMeshers_ViscousLayers::GetHypType() );
144 _requireShape = false; // can work without shape_studyId
146 smeshGen_i = SMESH_Gen_i::GetSMESHGen();
147 CORBA::Object_var anObject = smeshGen_i->GetNS()->Resolve("/myStudyManager");
148 SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject);
150 MESSAGE("studyid = " << _studyId);
153 myStudy = aStudyMgr->GetStudyByID(_studyId);
155 MESSAGE("myStudy->StudyId() = " << myStudy->StudyId());
157 _compute_canceled = false;
160 //=============================================================================
164 //=============================================================================
166 GHS3DPlugin_GHS3D::~GHS3DPlugin_GHS3D()
168 MESSAGE("GHS3DPlugin_GHS3D::~GHS3DPlugin_GHS3D");
171 //=============================================================================
175 //=============================================================================
177 bool GHS3DPlugin_GHS3D::CheckHypothesis ( SMESH_Mesh& aMesh,
178 const TopoDS_Shape& aShape,
179 Hypothesis_Status& aStatus )
181 aStatus = SMESH_Hypothesis::HYP_OK;
184 _viscousLayersHyp = 0;
186 _removeLogOnSuccess = true;
187 _logInStandardOutput = false;
189 const list <const SMESHDS_Hypothesis * >& hyps =
190 GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliary=*/false);
191 list <const SMESHDS_Hypothesis* >::const_iterator h = hyps.begin();
192 for ( ; h != hyps.end(); ++h )
195 _hyp = dynamic_cast< const GHS3DPlugin_Hypothesis*> ( *h );
196 if ( !_viscousLayersHyp )
197 _viscousLayersHyp = dynamic_cast< const StdMeshers_ViscousLayers*> ( *h );
201 _keepFiles = _hyp->GetKeepFiles();
202 _removeLogOnSuccess = _hyp->GetRemoveLogOnSuccess();
203 _logInStandardOutput = _hyp->GetStandardOutputLog();
210 //=======================================================================
211 //function : entryToShape
213 //=======================================================================
215 TopoDS_Shape GHS3DPlugin_GHS3D::entryToShape(std::string entry)
217 MESSAGE("GHS3DPlugin_GHS3D::entryToShape "<<entry );
218 GEOM::GEOM_Object_var aGeomObj;
219 TopoDS_Shape S = TopoDS_Shape();
220 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
221 if (!aSObj->_is_nil() ) {
222 CORBA::Object_var obj = aSObj->GetObject();
223 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
226 if ( !aGeomObj->_is_nil() )
227 S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
231 //=======================================================================
232 //function : findShape
234 //=======================================================================
236 static TopoDS_Shape findShape(const SMDS_MeshNode *aNode[],
238 const TopoDS_Shape shape[],
241 TopAbs_State * state = 0)
244 int j, iShape, nbNode = 4;
246 for ( j=0; j<nbNode; j++ ) {
247 gp_XYZ p ( aNode[j]->X(), aNode[j]->Y(), aNode[j]->Z() );
248 if ( aNode[j]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE ) {
255 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
256 if (state) *state = SC.State();
257 if ( SC.State() != TopAbs_IN || aShape.IsNull() || aShape.ShapeType() != TopAbs_SOLID) {
258 for (iShape = 0; iShape < nShape; iShape++) {
259 aShape = shape[iShape];
260 if ( !( aPnt.X() < box[iShape][0] || box[iShape][1] < aPnt.X() ||
261 aPnt.Y() < box[iShape][2] || box[iShape][3] < aPnt.Y() ||
262 aPnt.Z() < box[iShape][4] || box[iShape][5] < aPnt.Z()) ) {
263 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
264 if (state) *state = SC.State();
265 if (SC.State() == TopAbs_IN)
273 //=======================================================================
274 //function : readMapIntLine
276 //=======================================================================
278 static char* readMapIntLine(char* ptr, int tab[]) {
280 std::cout << std::endl;
282 for ( int i=0; i<17; i++ ) {
283 intVal = strtol(ptr, &ptr, 10);
290 //================================================================================
292 * \brief returns true if a triangle defined by the nodes is a temporary face on a
293 * side facet of pyramid and defines sub-domian inside the pyramid
295 //================================================================================
297 static bool isTmpFace(const SMDS_MeshNode* node1,
298 const SMDS_MeshNode* node2,
299 const SMDS_MeshNode* node3)
301 // find a pyramid sharing the 3 nodes
302 //const SMDS_MeshElement* pyram = 0;
303 SMDS_ElemIteratorPtr vIt1 = node1->GetInverseElementIterator(SMDSAbs_Volume);
304 while ( vIt1->more() )
306 const SMDS_MeshElement* pyram = vIt1->next();
307 if ( pyram->NbCornerNodes() != 5 ) continue;
309 if ( (i2 = pyram->GetNodeIndex( node2 )) >= 0 &&
310 (i3 = pyram->GetNodeIndex( node3 )) >= 0 )
312 // Triangle defines sub-domian inside the pyramid if it's
313 // normal points out of the pyram
315 // make i2 and i3 hold indices of base nodes of the pyram while
316 // keeping the nodes order in the triangle
319 i2 = i3, i3 = pyram->GetNodeIndex( node1 );
320 else if ( i3 == iApex )
321 i3 = i2, i2 = pyram->GetNodeIndex( node1 );
323 int i3base = (i2+1) % 4; // next index after i2 within the pyramid base
324 return ( i3base != i3 );
330 //=======================================================================
331 //function : findShapeID
332 //purpose : find the solid corresponding to GHS3D sub-domain following
333 // the technique proposed in GHS3D manual (available within
334 // ghs3d installation) in chapter "B.4 Subdomain (sub-region) assignment".
335 // In brief: normal of the triangle defined by the given nodes
336 // points out of the domain it is associated to
337 //=======================================================================
339 static int findShapeID(SMESH_Mesh& mesh,
340 const SMDS_MeshNode* node1,
341 const SMDS_MeshNode* node2,
342 const SMDS_MeshNode* node3,
343 const bool toMeshHoles)
345 const int invalidID = 0;
346 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
348 // face the nodes belong to
349 const SMDS_MeshElement * face = meshDS->FindFace(node1,node2,node3);
351 return isTmpFace(node1, node2, node3) ? HOLE_ID : invalidID;
353 std::cout << "bnd face " << face->GetID() << " - ";
355 // geom face the face assigned to
356 SMESH_MeshEditor editor(&mesh);
357 int geomFaceID = editor.FindShape( face );
359 return isTmpFace(node1, node2, node3) ? HOLE_ID : invalidID;
360 TopoDS_Shape shape = meshDS->IndexToShape( geomFaceID );
361 if ( shape.IsNull() || shape.ShapeType() != TopAbs_FACE )
363 TopoDS_Face geomFace = TopoDS::Face( shape );
365 // solids bounded by geom face
366 TopTools_IndexedMapOfShape solids, shells;
367 TopTools_ListIteratorOfListOfShape ansIt = mesh.GetAncestors(geomFace);
368 for ( ; ansIt.More(); ansIt.Next() ) {
369 switch ( ansIt.Value().ShapeType() ) {
371 solids.Add( ansIt.Value() ); break;
373 shells.Add( ansIt.Value() ); break;
377 // analyse found solids
378 if ( solids.Extent() == 0 || shells.Extent() == 0)
381 const TopoDS_Solid& solid1 = TopoDS::Solid( solids(1) );
382 if ( solids.Extent() == 1 )
385 return meshDS->ShapeToIndex( solid1 );
387 //////////// UNCOMMENT AS SOON AS
388 //////////// http://tracker.dev.opencascade.org/view.php?id=23129
389 //////////// IS SOLVED
390 // - Are we at a hole boundary face?
391 // if ( shells(1).IsSame( BRepTools::OuterShell( solid1 )) )
392 // { // - No, but maybe a hole is bound by two shapes? Does shells(1) touches another shell?
393 // bool touch = false;
394 // TopExp_Explorer eExp( shells(1), TopAbs_EDGE );
395 // // check if any edge of shells(1) belongs to another shell
396 // for ( ; eExp.More() && !touch; eExp.Next() ) {
397 // ansIt = mesh.GetAncestors( eExp.Current() );
398 // for ( ; ansIt.More() && !touch; ansIt.Next() ) {
399 // if ( ansIt.Value().ShapeType() == TopAbs_SHELL )
400 // touch = ( !ansIt.Value().IsSame( shells(1) ));
404 // return meshDS->ShapeToIndex( solid1 );
407 // find orientation of geom face within the first solid
408 TopExp_Explorer fExp( solid1, TopAbs_FACE );
409 for ( ; fExp.More(); fExp.Next() )
410 if ( geomFace.IsSame( fExp.Current() )) {
411 geomFace = TopoDS::Face( fExp.Current() );
415 return invalidID; // face not found
417 // normale to triangle
418 gp_Pnt node1Pnt ( node1->X(), node1->Y(), node1->Z() );
419 gp_Pnt node2Pnt ( node2->X(), node2->Y(), node2->Z() );
420 gp_Pnt node3Pnt ( node3->X(), node3->Y(), node3->Z() );
421 gp_Vec vec12( node1Pnt, node2Pnt );
422 gp_Vec vec13( node1Pnt, node3Pnt );
423 gp_Vec meshNormal = vec12 ^ vec13;
424 if ( meshNormal.SquareMagnitude() < DBL_MIN )
427 // get normale to geomFace at any node
428 bool geomNormalOK = false;
430 const SMDS_MeshNode* nodes[3] = { node1, node2, node3 };
431 SMESH_MesherHelper helper( mesh ); helper.SetSubShape( geomFace );
432 for ( int i = 0; !geomNormalOK && i < 3; ++i )
434 // find UV of i-th node on geomFace
435 const SMDS_MeshNode* nNotOnSeamEdge = 0;
436 if ( helper.IsSeamShape( nodes[i]->getshapeId() )) {
437 if ( helper.IsSeamShape( nodes[(i+1)%3]->getshapeId() ))
438 nNotOnSeamEdge = nodes[(i+2)%3];
440 nNotOnSeamEdge = nodes[(i+1)%3];
443 gp_XY uv = helper.GetNodeUV( geomFace, nodes[i], nNotOnSeamEdge, &uvOK );
444 // check that uv is correct
447 TopoDS_Shape nodeShape = helper.GetSubShapeByNode( nodes[i], meshDS );
448 if ( !nodeShape.IsNull() )
449 switch ( nodeShape.ShapeType() )
451 case TopAbs_FACE: tol = BRep_Tool::Tolerance( TopoDS::Face( nodeShape )); break;
452 case TopAbs_EDGE: tol = BRep_Tool::Tolerance( TopoDS::Edge( nodeShape )); break;
453 case TopAbs_VERTEX: tol = BRep_Tool::Tolerance( TopoDS::Vertex( nodeShape )); break;
456 gp_Pnt nodePnt ( nodes[i]->X(), nodes[i]->Y(), nodes[i]->Z() );
457 BRepAdaptor_Surface surface( geomFace );
458 uvOK = ( nodePnt.Distance( surface.Value( uv.X(), uv.Y() )) < 2 * tol );
460 // normale to geomFace at UV
462 surface.D1( uv.X(), uv.Y(), nodePnt, du, dv );
463 geomNormal = du ^ dv;
464 if ( geomFace.Orientation() == TopAbs_REVERSED )
465 geomNormal.Reverse();
466 geomNormalOK = ( geomNormal.SquareMagnitude() > DBL_MIN * 1e3 );
474 bool isReverse = ( meshNormal * geomNormal ) < 0;
476 return meshDS->ShapeToIndex( solid1 );
478 if ( solids.Extent() == 1 )
479 return HOLE_ID; // we are inside a hole
481 return meshDS->ShapeToIndex( solids(2) );
484 // //=======================================================================
485 // //function : countShape
487 // //=======================================================================
489 // template < class Mesh, class Shape >
490 // static int countShape( Mesh* mesh, Shape shape ) {
491 // TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
492 // TopTools_MapOfShape mapShape;
494 // for ( ; expShape.More(); expShape.Next() ) {
495 // if (mapShape.Add(expShape.Current())) {
502 // //=======================================================================
503 // //function : getShape
505 // //=======================================================================
507 // template < class Mesh, class Shape, class Tab >
508 // void getShape(Mesh* mesh, Shape shape, Tab *t_Shape) {
509 // TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
510 // TopTools_MapOfShape mapShape;
511 // for ( int i=0; expShape.More(); expShape.Next() ) {
512 // if (mapShape.Add(expShape.Current())) {
513 // t_Shape[i] = expShape.Current();
520 // // //=======================================================================
521 // // //function : findEdgeID
523 // // //=======================================================================
525 // static int findEdgeID(const SMDS_MeshNode* aNode,
526 // const SMESHDS_Mesh* theMesh,
528 // const TopoDS_Shape* t_Edge) {
530 // TopoDS_Shape aPntShape, foundEdge;
531 // TopoDS_Vertex aVertex;
532 // gp_Pnt aPnt( aNode->X(), aNode->Y(), aNode->Z() );
534 // int foundInd, ind;
535 // double nearest = RealLast(), *t_Dist;
536 // double epsilon = Precision::Confusion();
538 // t_Dist = new double[ nEdge ];
539 // aPntShape = BRepBuilderAPI_MakeVertex( aPnt ).Shape();
540 // aVertex = TopoDS::Vertex( aPntShape );
542 // for ( ind=0; ind < nEdge; ind++ ) {
543 // BRepExtrema_DistShapeShape aDistance ( aVertex, t_Edge[ind] );
544 // t_Dist[ind] = aDistance.Value();
545 // if ( t_Dist[ind] < nearest ) {
546 // nearest = t_Dist[ind];
547 // foundEdge = t_Edge[ind];
549 // if ( nearest < epsilon )
555 // return theMesh->ShapeToIndex( foundEdge );
559 // // =======================================================================
560 // // function : readGMFFile
561 // // purpose : read GMF file with geometry associated to mesh
562 // // =======================================================================
564 // static bool readGMFFile(const int fileOpen,
565 // const char* theFileName,
566 // SMESH_Mesh& theMesh,
567 // const int nbShape,
568 // const TopoDS_Shape* tabShape,
570 // map <int,const SMDS_MeshNode*>& theGhs3dIdToNodeMap,
572 // int nbEnforcedVertices,
573 // int nbEnforcedNodes)
575 // TopoDS_Shape aShape;
576 // TopoDS_Vertex aVertex;
577 // SMESHDS_Mesh* theMeshDS = theMesh.GetMeshDS();
578 // int nbElem = 0, nbRef = 0, IdShapeRef = 1;
580 // int aGMFNodeID = 0;
582 // nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() );
583 // int tetraShapeID = compoundID;
584 // double epsilon = Precision::Confusion();
585 // int *nodeAssigne, *GMFNodeAssigne;
586 // SMDS_MeshNode** GMFNode;
587 // TopoDS_Shape *tabCorner, *tabEdge;
588 // std::map <GmfKwdCod,int> tabRef;
592 // MESSAGE("Read " << theFileName << " file");
593 // int InpMsh = GmfOpenMesh(theFileName, GmfRead, &ver, &dim);
597 // // ===========================
598 // // Fill the tabID array: BEGIN
599 // // ===========================
602 // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2)
604 // Kernel_Utils::Localizer loc;
605 // struct stat status;
608 // char *ptr, *mapPtr;
610 // int *tab = new int[3];
612 // // Read the file state
613 // fstat(fileOpen, &status);
614 // length = status.st_size;
616 // // Mapping the result file into memory
618 // HANDLE fd = CreateFile(theFileName, GENERIC_READ, FILE_SHARE_READ,
619 // NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
620 // HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY,
621 // 0, (DWORD)length, NULL);
622 // ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 );
624 // ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
628 // ptr = readMapIntLine(ptr, tab);
632 // int nbNodes = tab[1];
634 // for (int i=0; i < 4*nbElem; i++)
635 // strtol(ptr, &ptr, 10);
637 // for (int iNode=1; iNode <= nbNodes; iNode++)
638 // for (int iCoor=0; iCoor < 3; iCoor++)
639 // strtod(ptr, &ptr);
642 // // Reading the number of triangles which corresponds to the number of sub-domains
643 // int nbTriangle = strtol(ptr, &ptr, 10);
646 // // The keyword does not exist yet => to update when it is created
647 // // int nbSubdomains = GmfStatKwd(InpMsh, GmfSubdomain);
651 // tabID = new int[nbTriangle];
652 // for (int i=0; i < nbTriangle; i++) {
654 // int nodeId1, nodeId2, nodeId3;
655 // // find the solid corresponding to GHS3D sub-domain following
656 // // the technique proposed in GHS3D manual in chapter
657 // // "B.4 Subdomain (sub-region) assignment"
659 // nodeId1 = strtol(ptr, &ptr, 10);
660 // nodeId2 = strtol(ptr, &ptr, 10);
661 // nodeId3 = strtol(ptr, &ptr, 10);
663 // // // The keyword does not exist yet => to update when it is created
664 // // GmfGetLin(InpMsh, GmfSubdomain, &id_tri[0], &id_tri[1], &id_tri[2]);
665 // // nodeId1 = id_tri[0];
666 // // nodeId2 = id_tri[1];
667 // // nodeId3 = id_tri[2];
669 // if ( nbTriangle > 1 ) {
670 // // get the nodes indices
671 // const SMDS_MeshNode* n1 = theGhs3dIdToNodeMap[ nodeId1 ];
672 // const SMDS_MeshNode* n2 = theGhs3dIdToNodeMap[ nodeId2 ];
673 // const SMDS_MeshNode* n3 = theGhs3dIdToNodeMap[ nodeId3 ];
675 // OCC_CATCH_SIGNALS;
676 // tabID[i] = findShapeID( theMesh, n1, n2, n3, toMeshHoles );
677 // // -- 0020330: Pb with ghs3d as a submesh
678 // // check that found shape is to be meshed
679 // if ( tabID[i] > 0 ) {
680 // const TopoDS_Shape& foundShape = theMeshDS->IndexToShape( tabID[i] );
681 // bool isToBeMeshed = false;
682 // for ( int iS = 0; !isToBeMeshed && iS < nbShape; ++iS )
683 // isToBeMeshed = foundShape.IsSame( tabShape[ iS ]);
684 // if ( !isToBeMeshed )
685 // tabID[i] = HOLE_ID;
687 // // END -- 0020330: Pb with ghs3d as a submesh
689 // std::cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << std::endl;
692 // catch ( Standard_Failure & ex)
695 // std::cout << i+1 << " subdomain: Exception caugt: " << ex.GetMessageString() << std::endl;
700 // std::cout << i+1 << " subdomain: unknown exception caught " << std::endl;
706 // // ===========================
707 // // Fill the tabID array: END
708 // // ===========================
711 // tabRef[GmfVertices] = 3;
712 // tabRef[GmfCorners] = 1;
713 // tabRef[GmfEdges] = 2;
714 // tabRef[GmfRidges] = 1;
715 // tabRef[GmfTriangles] = 3;
716 // // tabRef[GmfQuadrilaterals] = 4;
717 // tabRef[GmfTetrahedra] = 4;
718 // // tabRef[GmfHexahedra] = 8;
720 // SMDS_NodeIteratorPtr itOnGMFInputNode = theMeshDS->nodesIterator();
721 // while ( itOnGMFInputNode->more() )
722 // theMeshDS->RemoveNode( itOnGMFInputNode->next() );
725 // int nbVertices = GmfStatKwd(InpMsh, GmfVertices);
726 // int nbCorners = max(countShape( theMeshDS, TopAbs_VERTEX ) , GmfStatKwd(InpMsh, GmfCorners));
727 // int nbShapeEdge = countShape( theMeshDS, TopAbs_EDGE );
729 // tabCorner = new TopoDS_Shape[ nbCorners ];
730 // tabEdge = new TopoDS_Shape[ nbShapeEdge ];
731 // nodeAssigne = new int[ nbVertices + 1 ];
732 // GMFNodeAssigne = new int[ nbVertices + 1 ];
733 // GMFNode = new SMDS_MeshNode*[ nbVertices + 1 ];
735 // getShape(theMeshDS, TopAbs_VERTEX, tabCorner);
736 // getShape(theMeshDS, TopAbs_EDGE, tabEdge);
738 // std::map <GmfKwdCod,int>::const_iterator it = tabRef.begin();
739 // for ( ; it != tabRef.end() ; ++it)
742 // GmfKwdCod token = it->first;
743 // nbRef = it->second;
745 // nbElem = GmfStatKwd(InpMsh, token);
747 // GmfGotoKwd(InpMsh, token);
748 // std::cout << "Read " << nbElem;
753 // int id[nbElem*tabRef[token]];
754 // int ghs3dShapeID[nbElem];
756 // if (token == GmfVertices) {
757 // std::cout << " vertices" << std::endl;
760 // float VerTab_f[nbElem][3];
761 // double VerTab_d[nbElem][3];
762 // SMDS_MeshNode * aGMFNode;
764 // for ( int iElem = 0; iElem < nbElem; iElem++ ) {
765 // aGMFID = iElem + 1;
766 // if (ver == GmfFloat) {
767 // GmfGetLin(InpMsh, token, &VerTab_f[nbElem][0], &VerTab_f[nbElem][1], &VerTab_f[nbElem][2], &ghs3dShapeID[iElem]);
768 // aGMFNode = theMeshDS->AddNode(VerTab_f[nbElem][0], VerTab_f[nbElem][1], VerTab_f[nbElem][2]);
771 // GmfGetLin(InpMsh, token, &VerTab_d[nbElem][0], &VerTab_d[nbElem][1], &VerTab_d[nbElem][2], &ghs3dShapeID[iElem]);
772 // aGMFNode = theMeshDS->AddNode(VerTab_d[nbElem][0], VerTab_d[nbElem][1], VerTab_d[nbElem][2]);
774 // GMFNode[ aGMFID ] = aGMFNode;
775 // nodeAssigne[ aGMFID ] = 0;
776 // GMFNodeAssigne[ aGMFID ] = 0;
779 // else if (token == GmfCorners && nbElem > 0) {
780 // std::cout << " corners" << std::endl;
781 // for ( int iElem = 0; iElem < nbElem; iElem++ )
782 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
784 // else if (token == GmfRidges && nbElem > 0) {
785 // std::cout << " ridges" << std::endl;
786 // for ( int iElem = 0; iElem < nbElem; iElem++ )
787 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
789 // else if (token == GmfEdges && nbElem > 0) {
790 // std::cout << " edges" << std::endl;
791 // for ( int iElem = 0; iElem < nbElem; iElem++ )
792 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &ghs3dShapeID[iElem]);
794 // else if (token == GmfTriangles && nbElem > 0) {
795 // std::cout << " triangles" << std::endl;
796 // for ( int iElem = 0; iElem < nbElem; iElem++ )
797 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &ghs3dShapeID[iElem]);
799 // // else if (token == GmfQuadrilaterals && nbElem > 0) {
800 // // std::cout << " Quadrilaterals" << std::endl;
801 // // for ( int iElem = 0; iElem < nbElem; iElem++ )
802 // // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &ghs3dShapeID[iElem]);
804 // else if (token == GmfTetrahedra && nbElem > 0) {
805 // std::cout << " Tetrahedra" << std::endl;
806 // for ( int iElem = 0; iElem < nbElem; iElem++ )
807 // GmfGetLin(InpMsh, token,
808 // &id[iElem*tabRef[token]],
809 // &id[iElem*tabRef[token]+1],
810 // &id[iElem*tabRef[token]+2],
811 // &id[iElem*tabRef[token]+3],
812 // &ghs3dShapeID[iElem]);
814 // // else if (token == GmfHexahedra && nbElem > 0) {
815 // // std::cout << " Hexahedra" << std::endl;
816 // // for ( int iElem = 0; iElem < nbElem; iElem++ )
817 // // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3],
818 // // &id[iElem*tabRef[token]+4], &id[iElem*tabRef[token]+5], &id[iElem*tabRef[token]+6], &id[iElem*tabRef[token]+7], &ghs3dShapeID[iElem]);
825 // case GmfTriangles:
826 // // case GmfQuadrilaterals:
827 // case GmfTetrahedra:
828 // // case GmfHexahedra:
830 // int nodeDim, shapeID, *nodeID;
831 // const SMDS_MeshNode** node;
832 // // std::vector< SMDS_MeshNode* > enfNode( nbRef );
833 // SMDS_MeshElement * aGMFElement;
835 // node = new const SMDS_MeshNode*[nbRef];
836 // nodeID = new int[ nbRef ];
838 // for ( int iElem = 0; iElem < nbElem; iElem++ )
840 // for ( int iRef = 0; iRef < nbRef; iRef++ )
842 // aGMFNodeID = id[iElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID
843 // node [ iRef ] = GMFNode[ aGMFNodeID ];
844 // nodeID[ iRef ] = aGMFNodeID;
849 // case GmfCorners: {
851 // gp_Pnt GMFPnt ( node[0]->X(), node[0]->Y(), node[0]->Z() );
852 // for ( int i=0; i<nbElem; i++ ) {
853 // aVertex = TopoDS::Vertex( tabCorner[i] );
854 // gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
855 // if ( aPnt.Distance( GMFPnt ) < epsilon )
862 // aGMFElement = theMeshDS->AddEdge( node[0], node[1] );
864 // if ( GMFNodeAssigne[ nodeID[0] ] == 0 || GMFNodeAssigne[ nodeID[0] ] == 2 )
866 // shapeID = findEdgeID( node[iNode], theMeshDS, nbShapeEdge, tabEdge );
871 // case GmfTriangles: {
873 // aGMFElement = theMeshDS->AddFace( node[0], node[1], node[2]);
877 // // case GmfQuadrilaterals: {
879 // // aGMFElement = theMeshDS->AddFace( node[0], node[1], node[2], node[3] );
883 // case GmfTetrahedra: {
886 // TopoDS_Shape aSolid;
887 // // We always run GHS3D with "to mesh holes"==TRUE but we must not create
888 // // tetras within holes depending on hypo option,
889 // // so we first check if aTet is inside a hole and then create it
890 // if ( nbTriangle > 1 ) {
891 // tetraShapeID = HOLE_ID; // negative tetraShapeID means not to create tetras if !toMeshHoles
892 // int aGhs3dShapeID = ghs3dShapeID[iElem] - IdShapeRef;
893 // if ( tabID[ aGhs3dShapeID ] == 0 ) {
894 // TopAbs_State state;
895 // aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape, &state);
896 // if ( toMeshHoles || state == TopAbs_IN )
897 // tetraShapeID = theMeshDS->ShapeToIndex( aSolid );
898 // tabID[ aGhs3dShapeID ] = tetraShapeID;
901 // tetraShapeID = tabID[ aGhs3dShapeID ];
903 // else if ( nbShape > 1 ) {
904 // // Case where nbTriangle == 1 while nbShape == 2 encountered
905 // // with compound of 2 boxes and "To mesh holes"==False,
906 // // so there are no subdomains specified for each tetrahedron.
907 // // Try to guess a solid by a node already bound to shape
909 // for ( int i=0; i<4 && tetraShapeID==0; i++ ) {
910 // if ( nodeAssigne[ nodeID[i] ] == 1 &&
911 // node[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE &&
912 // node[i]->getshapeId() > 1 )
914 // tetraShapeID = node[i]->getshapeId();
917 // if ( tetraShapeID==0 ) {
918 // aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape);
919 // tetraShapeID = theMeshDS->ShapeToIndex( aSolid );
922 // // set new nodes and tetrahedron onto the shape
923 // for ( int i=0; i<4; i++ ) {
924 // if ( nodeAssigne[ nodeID[i] ] == 0 ) {
925 // if ( tetraShapeID != HOLE_ID )
926 // theMeshDS->SetNodeInVolume( node[i], tetraShapeID );
927 // nodeAssigne[ nodeID[i] ] = tetraShapeID;
930 // if ( toMeshHoles || tetraShapeID != HOLE_ID ) {
931 // aGMFElement = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
932 // theMeshDS->SetMeshElementOnShape( aGMFElement, tetraShapeID );
940 // // case GmfHexahedra: {
942 // // aGMFElement = theMeshDS->AddVolume( node[0], node[3], node[2], node[1],
943 // // node[4], node[7], node[6], node[5] );
946 // default: continue;
948 // if (token != GmfRidges)
950 // for ( int i=0; i<nbRef; i++ ) {
951 // if ( GMFNodeAssigne[ nodeID[i] ] == 0 ) {
952 // if ( token == GmfCorners ) theMeshDS->SetNodeOnVertex( node[0], aVertex );
953 // else if ( token == GmfEdges ) theMeshDS->SetNodeOnEdge( node[i], shapeID );
954 // else if ( token == GmfTriangles ) theMeshDS->SetNodeOnFace( node[i], shapeID );
955 // GMFNodeAssigne[ nodeID[i] ] = nodeDim;
958 // if ( token != "Corners" )
959 // theMeshDS->SetMeshElementOnShape( aGMFElement, shapeID );
963 // if ( !toMeshHoles ) {
964 // map <int,const SMDS_MeshNode*>::iterator itOnNode = theGhs3dIdToNodeMap.find( nbVertices-(nbEnforcedVertices+nbEnforcedNodes) );
965 // for ( ; itOnNode != theGhs3dIdToNodeMap.end(); ++itOnNode) {
966 // if ( nodeAssigne[ itOnNode->first ] == HOLE_ID )
967 // theMeshDS->RemoveFreeNode( itOnNode->second, 0 );
974 // } // case GmfTetrahedra
975 // } // switch(token)
977 // cout << std::endl;
980 // UnmapViewOfFile(mapPtr);
981 // CloseHandle(hMapObject);
984 // munmap(mapPtr, length);
989 // delete [] tabCorner;
990 // delete [] tabEdge;
991 // delete [] nodeAssigne;
992 // delete [] GMFNodeAssigne;
993 // delete [] GMFNode;
999 //=======================================================================
1000 //function : addElemInMeshGroup
1001 //purpose : Update or create groups in mesh
1002 //=======================================================================
1004 static void addElemInMeshGroup(SMESH_Mesh* theMesh,
1005 const SMDS_MeshElement* anElem,
1006 std::string& groupName,
1007 std::set<std::string>& groupsToRemove)
1009 if ( !anElem ) return; // issue 0021776
1011 bool groupDone = false;
1012 SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups();
1013 while (grIt->more()) {
1014 SMESH_Group * group = grIt->next();
1015 if ( !group ) continue;
1016 SMESHDS_GroupBase* groupDS = group->GetGroupDS();
1017 if ( !groupDS ) continue;
1018 if ( groupDS->GetType()==anElem->GetType() &&groupName.compare(group->GetName())==0) {
1019 SMESHDS_Group* aGroupDS = static_cast<SMESHDS_Group*>( groupDS );
1020 aGroupDS->SMDSGroup().Add(anElem);
1022 // MESSAGE("Successfully added enforced element to existing group " << groupName);
1030 SMESH_Group* aGroup = theMesh->AddGroup(anElem->GetType(), groupName.c_str(), groupId);
1031 aGroup->SetName( groupName.c_str() );
1032 SMESHDS_Group* aGroupDS = static_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
1033 aGroupDS->SMDSGroup().Add(anElem);
1034 // MESSAGE("Successfully created enforced vertex group " << groupName);
1038 throw SALOME_Exception(LOCALIZED("A given element was not added to a group"));
1042 //=======================================================================
1043 //function : updateMeshGroups
1044 //purpose : Update or create groups in mesh
1045 //=======================================================================
1047 static void updateMeshGroups(SMESH_Mesh* theMesh, std::set<std::string> groupsToRemove)
1049 SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups();
1050 while (grIt->more()) {
1051 SMESH_Group * group = grIt->next();
1052 if ( !group ) continue;
1053 SMESHDS_GroupBase* groupDS = group->GetGroupDS();
1054 if ( !groupDS ) continue;
1055 std::string currentGroupName = (string)group->GetName();
1056 if (groupDS->IsEmpty() && groupsToRemove.find(currentGroupName) != groupsToRemove.end()) {
1057 // Previous group created by enforced elements
1058 MESSAGE("Delete previous group created by removed enforced elements: " << group->GetName())
1059 theMesh->RemoveGroup(groupDS->GetID());
1064 //=======================================================================
1065 //function : removeEmptyGroupsOfDomains
1066 //purpose : remove empty groups named "Domain_nb" created due to
1067 // "To make groups of domains" option.
1068 //=======================================================================
1070 static void removeEmptyGroupsOfDomains(SMESH_Mesh* mesh,
1071 bool notEmptyAsWell = false)
1073 const char* refName = theDomainGroupNamePrefix;
1074 const size_t refLen = strlen( theDomainGroupNamePrefix );
1076 std::list<int> groupIDs = mesh->GetGroupIds();
1077 std::list<int>::const_iterator id = groupIDs.begin();
1078 for ( ; id != groupIDs.end(); ++id )
1080 SMESH_Group* group = mesh->GetGroup( *id );
1081 if ( !group || ( !group->GetGroupDS()->IsEmpty() && !notEmptyAsWell ))
1083 const char* name = group->GetName();
1086 if ( strncmp( name, refName, refLen ) == 0 && // starts from refName;
1087 isdigit( *( name + refLen )) && // refName is followed by a digit;
1088 strtol( name + refLen, &end, 10) >= 0 && // there are only digits ...
1089 *end == '\0') // ... till a string end.
1091 mesh->RemoveGroup( *id );
1096 //================================================================================
1098 * \brief Create the groups corresponding to domains
1100 //================================================================================
1102 static void makeDomainGroups( std::vector< std::vector< const SMDS_MeshElement* > >& elemsOfDomain,
1103 SMESH_MesherHelper* theHelper)
1105 // int nbDomains = 0;
1106 // for ( size_t i = 0; i < elemsOfDomain.size(); ++i )
1107 // nbDomains += ( elemsOfDomain[i].size() > 0 );
1109 // if ( nbDomains > 1 )
1110 for ( size_t iDomain = 0; iDomain < elemsOfDomain.size(); ++iDomain )
1112 std::vector< const SMDS_MeshElement* > & elems = elemsOfDomain[ iDomain ];
1113 if ( elems.empty() ) continue;
1115 // find existing groups
1116 std::vector< SMESH_Group* > groupOfType( SMDSAbs_NbElementTypes, (SMESH_Group*)NULL );
1117 const std::string domainName = ( SMESH_Comment( theDomainGroupNamePrefix ) << iDomain );
1118 SMESH_Mesh::GroupIteratorPtr groupIt = theHelper->GetMesh()->GetGroups();
1119 while ( groupIt->more() )
1121 SMESH_Group* group = groupIt->next();
1122 if ( domainName == group->GetName() &&
1123 dynamic_cast< SMESHDS_Group* >( group->GetGroupDS()) )
1124 groupOfType[ group->GetGroupDS()->GetType() ] = group;
1126 // create and fill the groups
1131 SMESH_Group* group = groupOfType[ elems[ iElem ]->GetType() ];
1133 group = theHelper->GetMesh()->AddGroup( elems[ iElem ]->GetType(),
1134 domainName.c_str(), groupID );
1135 SMDS_MeshGroup& groupDS =
1136 static_cast< SMESHDS_Group* >( group->GetGroupDS() )->SMDSGroup();
1138 while ( iElem < elems.size() && groupDS.Add( elems[iElem] ))
1141 } while ( iElem < elems.size() );
1145 //=======================================================================
1146 //function : readGMFFile
1147 //purpose : read GMF file w/o geometry associated to mesh
1148 //=======================================================================
1150 static bool readGMFFile(const char* theFile,
1151 GHS3DPlugin_GHS3D* theAlgo,
1152 SMESH_MesherHelper* theHelper,
1153 std::vector <const SMDS_MeshNode*> & theNodeByGhs3dId,
1154 std::vector <const SMDS_MeshElement*> & theFaceByGhs3dId,
1155 map<const SMDS_MeshNode*,int> & theNodeToGhs3dIdMap,
1156 std::vector<std::string> & aNodeGroupByGhs3dId,
1157 std::vector<std::string> & anEdgeGroupByGhs3dId,
1158 std::vector<std::string> & aFaceGroupByGhs3dId,
1159 std::set<std::string> & groupsToRemove,
1160 bool toMakeGroupsOfDomains=false,
1161 bool toMeshHoles=true)
1164 SMESHDS_Mesh* theMeshDS = theHelper->GetMeshDS();
1165 const bool hasGeom = ( theHelper->GetMesh()->HasShapeToMesh() );
1167 int nbInitialNodes = theNodeByGhs3dId.size();
1168 int nbMeshNodes = theMeshDS->NbNodes();
1170 const bool isQuadMesh =
1171 theHelper->GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
1172 theHelper->GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
1173 theHelper->GetMesh()->NbVolumes( ORDER_QUADRATIC );
1176 std::cout << "theNodeByGhs3dId.size(): " << nbInitialNodes << std::endl;
1177 std::cout << "theHelper->GetMesh()->NbNodes(): " << nbMeshNodes << std::endl;
1178 std::cout << "isQuadMesh: " << isQuadMesh << std::endl;
1181 // if ( theHelper->GetSubShapeID() != 0 && hasGeom )
1182 // theHelper->IsQuadraticSubMesh( theHelper->GetSubShape() );
1184 // ---------------------------------
1185 // Read generated elements and nodes
1186 // ---------------------------------
1188 int nbElem = 0, nbRef = 0;
1190 const SMDS_MeshNode** GMFNode;
1192 std::map<int, std::set<int> > subdomainId2tetraId;
1194 std::map <GmfKwdCod,int> tabRef;
1195 const bool force3d = !hasGeom;
1198 tabRef[GmfVertices] = 3; // for new nodes and enforced nodes
1199 tabRef[GmfCorners] = 1;
1200 tabRef[GmfEdges] = 2; // for enforced edges
1201 tabRef[GmfRidges] = 1;
1202 tabRef[GmfTriangles] = 3; // for enforced faces
1203 tabRef[GmfQuadrilaterals] = 4;
1204 tabRef[GmfTetrahedra] = 4; // for new tetras
1205 tabRef[GmfHexahedra] = 8;
1208 MESSAGE("Read " << theFile << " file");
1209 int InpMsh = GmfOpenMesh(theFile, GmfRead, &ver, &dim);
1214 // Read ids of domains
1215 vector< int > solidIDByDomain;
1218 int solid1; // id used in case of 1 domain or some reading failure
1219 if ( theHelper->GetSubShape().ShapeType() == TopAbs_SOLID )
1220 solid1 = theHelper->GetSubShapeID();
1222 solid1 = theMeshDS->ShapeToIndex
1223 ( TopExp_Explorer( theHelper->GetSubShape(), TopAbs_SOLID ).Current() );
1225 int nbDomains = GmfStatKwd( InpMsh, GmfSubDomainFromGeom );
1226 if ( nbDomains > 1 )
1228 solidIDByDomain.resize( nbDomains+1, theHelper->GetSubShapeID() );
1229 int faceNbNodes, faceIndex, orientation, domainNb;
1230 GmfGotoKwd( InpMsh, GmfSubDomainFromGeom );
1231 for ( int i = 0; i < nbDomains; ++i )
1234 GmfGetLin( InpMsh, GmfSubDomainFromGeom,
1235 &faceNbNodes, &faceIndex, &orientation, &domainNb);
1236 solidIDByDomain[ domainNb ] = 1;
1237 if ( 0 < faceIndex && faceIndex-1 < theFaceByGhs3dId.size() )
1239 const SMDS_MeshElement* face = theFaceByGhs3dId[ faceIndex-1 ];
1240 const SMDS_MeshNode* nn[3] = { face->GetNode(0),
1243 if ( orientation < 0 )
1244 std::swap( nn[1], nn[2] );
1245 solidIDByDomain[ domainNb ] =
1246 findShapeID( *theHelper->GetMesh(), nn[0], nn[1], nn[2], toMeshHoles );
1247 if ( solidIDByDomain[ domainNb ] > 0 )
1249 const TopoDS_Shape& foundShape = theMeshDS->IndexToShape( solidIDByDomain[ domainNb ] );
1250 if ( ! theHelper->IsSubShape( foundShape, theHelper->GetSubShape() ))
1251 solidIDByDomain[ domainNb ] = HOLE_ID;
1256 if ( solidIDByDomain.size() < 2 )
1257 solidIDByDomain.resize( 2, solid1 );
1260 // Issue 0020682. Avoid creating nodes and tetras at place where
1261 // volumic elements already exist
1262 SMESH_ElementSearcher* elemSearcher = 0;
1263 std::vector< const SMDS_MeshElement* > foundVolumes;
1264 if ( !hasGeom && theHelper->GetMesh()->NbVolumes() > 0 )
1265 elemSearcher = SMESH_MeshAlgos::GetElementSearcher( *theMeshDS );
1266 auto_ptr< SMESH_ElementSearcher > elemSearcherDeleter( elemSearcher );
1268 // IMP 0022172: [CEA 790] create the groups corresponding to domains
1269 std::vector< std::vector< const SMDS_MeshElement* > > elemsOfDomain;
1271 int nbVertices = GmfStatKwd(InpMsh, GmfVertices) - nbInitialNodes;
1272 GMFNode = new const SMDS_MeshNode*[ nbVertices + 1 ];
1274 std::map <GmfKwdCod,int>::const_iterator it = tabRef.begin();
1275 for ( ; it != tabRef.end() ; ++it)
1277 if(theAlgo->computeCanceled()) {
1278 GmfCloseMesh(InpMsh);
1283 GmfKwdCod token = it->first;
1286 nbElem = GmfStatKwd(InpMsh, token);
1288 GmfGotoKwd(InpMsh, token);
1289 std::cout << "Read " << nbElem;
1294 std::vector<int> id (nbElem*tabRef[token]); // node ids
1295 std::vector<int> domainID( nbElem ); // domain
1297 if (token == GmfVertices) {
1298 (nbElem <= 1) ? tmpStr = " vertex" : tmpStr = " vertices";
1299 // std::cout << nbInitialNodes << " from input mesh " << std::endl;
1301 // Remove orphan nodes from previous enforced mesh which was cleared
1302 // if ( nbElem < nbMeshNodes ) {
1303 // const SMDS_MeshNode* node;
1304 // SMDS_NodeIteratorPtr nodeIt = theMeshDS->nodesIterator();
1305 // while ( nodeIt->more() )
1307 // node = nodeIt->next();
1308 // if (theNodeToGhs3dIdMap.find(node) != theNodeToGhs3dIdMap.end())
1309 // theMeshDS->RemoveNode(node);
1318 const SMDS_MeshNode * aGMFNode;
1320 for ( int iElem = 0; iElem < nbElem; iElem++ ) {
1321 if(theAlgo->computeCanceled()) {
1322 GmfCloseMesh(InpMsh);
1326 if (ver == GmfFloat) {
1327 GmfGetLin(InpMsh, token, &VerTab_f[0], &VerTab_f[1], &VerTab_f[2], &dummy);
1333 GmfGetLin(InpMsh, token, &x, &y, &z, &dummy);
1335 if (iElem >= nbInitialNodes) {
1336 if ( elemSearcher &&
1337 elemSearcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_Volume, foundVolumes))
1340 aGMFNode = theHelper->AddNode(x, y, z);
1342 aGMFID = iElem -nbInitialNodes +1;
1343 GMFNode[ aGMFID ] = aGMFNode;
1344 if (aGMFID-1 < aNodeGroupByGhs3dId.size() && !aNodeGroupByGhs3dId.at(aGMFID-1).empty())
1345 addElemInMeshGroup(theHelper->GetMesh(), aGMFNode, aNodeGroupByGhs3dId.at(aGMFID-1), groupsToRemove);
1349 else if (token == GmfCorners && nbElem > 0) {
1350 (nbElem <= 1) ? tmpStr = " corner" : tmpStr = " corners";
1351 for ( int iElem = 0; iElem < nbElem; iElem++ )
1352 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
1354 else if (token == GmfRidges && nbElem > 0) {
1355 (nbElem <= 1) ? tmpStr = " ridge" : tmpStr = " ridges";
1356 for ( int iElem = 0; iElem < nbElem; iElem++ )
1357 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
1359 else if (token == GmfEdges && nbElem > 0) {
1360 (nbElem <= 1) ? tmpStr = " edge" : tmpStr = " edges";
1361 for ( int iElem = 0; iElem < nbElem; iElem++ )
1362 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &domainID[iElem]);
1364 else if (token == GmfTriangles && nbElem > 0) {
1365 (nbElem <= 1) ? tmpStr = " triangle" : tmpStr = " triangles";
1366 for ( int iElem = 0; iElem < nbElem; iElem++ )
1367 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &domainID[iElem]);
1369 else if (token == GmfQuadrilaterals && nbElem > 0) {
1370 (nbElem <= 1) ? tmpStr = " Quadrilateral" : tmpStr = " Quadrilaterals";
1371 for ( int iElem = 0; iElem < nbElem; iElem++ )
1372 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &domainID[iElem]);
1374 else if (token == GmfTetrahedra && nbElem > 0) {
1375 (nbElem <= 1) ? tmpStr = " Tetrahedron" : tmpStr = " Tetrahedra";
1376 for ( int iElem = 0; iElem < nbElem; iElem++ ) {
1377 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &domainID[iElem]);
1379 subdomainId2tetraId[dummy].insert(iElem+1);
1380 // MESSAGE("subdomainId2tetraId["<<dummy<<"].insert("<<iElem+1<<")");
1384 else if (token == GmfHexahedra && nbElem > 0) {
1385 (nbElem <= 1) ? tmpStr = " Hexahedron" : tmpStr = " Hexahedra";
1386 for ( int iElem = 0; iElem < nbElem; iElem++ )
1387 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3],
1388 &id[iElem*tabRef[token]+4], &id[iElem*tabRef[token]+5], &id[iElem*tabRef[token]+6], &id[iElem*tabRef[token]+7], &domainID[iElem]);
1390 std::cout << tmpStr << std::endl;
1391 std::cout << std::endl;
1398 case GmfQuadrilaterals:
1402 std::vector< const SMDS_MeshNode* > node( nbRef );
1403 std::vector< int > nodeID( nbRef );
1404 std::vector< SMDS_MeshNode* > enfNode( nbRef );
1405 const SMDS_MeshElement* aCreatedElem;
1407 for ( int iElem = 0; iElem < nbElem; iElem++ )
1409 if(theAlgo->computeCanceled()) {
1410 GmfCloseMesh(InpMsh);
1414 // Check if elem is already in input mesh. If yes => skip
1415 bool fullyCreatedElement = false; // if at least one of the nodes was created
1416 for ( int iRef = 0; iRef < nbRef; iRef++ )
1418 aGMFNodeID = id[iElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID
1419 if (aGMFNodeID <= nbInitialNodes) // input nodes
1422 node[ iRef ] = theNodeByGhs3dId[aGMFNodeID];
1426 fullyCreatedElement = true;
1427 aGMFNodeID -= nbInitialNodes;
1428 nodeID[ iRef ] = aGMFNodeID ;
1429 node [ iRef ] = GMFNode[ aGMFNodeID ];
1436 if (fullyCreatedElement) {
1437 aCreatedElem = theHelper->AddEdge( node[0], node[1], noID, force3d );
1438 if (anEdgeGroupByGhs3dId.size() && !anEdgeGroupByGhs3dId[iElem].empty())
1439 addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByGhs3dId[iElem], groupsToRemove);
1443 if (fullyCreatedElement) {
1444 aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], noID, force3d );
1445 if (aFaceGroupByGhs3dId.size() && !aFaceGroupByGhs3dId[iElem].empty())
1446 addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, aFaceGroupByGhs3dId[iElem], groupsToRemove);
1449 case GmfQuadrilaterals:
1450 if (fullyCreatedElement) {
1451 aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], node[3], noID, force3d );
1457 solidID = solidIDByDomain[ domainID[iElem]];
1458 if ( solidID != HOLE_ID )
1460 aCreatedElem = theHelper->AddVolume( node[1], node[0], node[2], node[3],
1462 theMeshDS->SetMeshElementOnShape( aCreatedElem, solidID );
1463 for ( int iN = 0; iN < 4; ++iN )
1464 if ( node[iN]->getshapeId() < 1 )
1465 theMeshDS->SetNodeInVolume( node[iN], solidID );
1470 if ( elemSearcher ) {
1471 // Issue 0020682. Avoid creating nodes and tetras at place where
1472 // volumic elements already exist
1473 if ( !node[1] || !node[0] || !node[2] || !node[3] )
1475 if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) +
1476 SMESH_TNodeXYZ(node[1]) +
1477 SMESH_TNodeXYZ(node[2]) +
1478 SMESH_TNodeXYZ(node[3]) ) / 4.,
1479 SMDSAbs_Volume, foundVolumes ))
1482 aCreatedElem = theHelper->AddVolume( node[1], node[0], node[2], node[3],
1489 solidID = solidIDByDomain[ domainID[iElem]];
1490 if ( solidID != HOLE_ID )
1492 aCreatedElem = theHelper->AddVolume( node[0], node[3], node[2], node[1],
1493 node[4], node[7], node[6], node[5],
1495 theMeshDS->SetMeshElementOnShape( aCreatedElem, solidID );
1496 for ( int iN = 0; iN < 8; ++iN )
1497 if ( node[iN]->getshapeId() < 1 )
1498 theMeshDS->SetNodeInVolume( node[iN], solidID );
1503 if ( elemSearcher ) {
1504 // Issue 0020682. Avoid creating nodes and tetras at place where
1505 // volumic elements already exist
1506 if ( !node[1] || !node[0] || !node[2] || !node[3] || !node[4] || !node[5] || !node[6] || !node[7])
1508 if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) +
1509 SMESH_TNodeXYZ(node[1]) +
1510 SMESH_TNodeXYZ(node[2]) +
1511 SMESH_TNodeXYZ(node[3]) +
1512 SMESH_TNodeXYZ(node[4]) +
1513 SMESH_TNodeXYZ(node[5]) +
1514 SMESH_TNodeXYZ(node[6]) +
1515 SMESH_TNodeXYZ(node[7])) / 8.,
1516 SMDSAbs_Volume, foundVolumes ))
1519 aCreatedElem = theHelper->AddVolume( node[0], node[3], node[2], node[1],
1520 node[4], node[7], node[6], node[5],
1527 if ( aCreatedElem && toMakeGroupsOfDomains )
1529 if ( domainID[iElem] >= (int) elemsOfDomain.size() )
1530 elemsOfDomain.resize( domainID[iElem] + 1 );
1531 elemsOfDomain[ domainID[iElem] ].push_back( aCreatedElem );
1533 } // loop on elements of one type
1539 // remove nodes in holes
1542 for ( int i = 1; i <= nbVertices; ++i )
1543 if ( GMFNode[i]->NbInverseElements() == 0 )
1544 theMeshDS->RemoveFreeNode( GMFNode[i], /*sm=*/0, /*fromGroups=*/false );
1547 GmfCloseMesh(InpMsh);
1550 // 0022172: [CEA 790] create the groups corresponding to domains
1551 if ( toMakeGroupsOfDomains )
1552 makeDomainGroups( elemsOfDomain, theHelper );
1555 MESSAGE("Nb subdomains " << subdomainId2tetraId.size());
1556 std::map<int, std::set<int> >::const_iterator subdomainIt = subdomainId2tetraId.begin();
1557 TCollection_AsciiString aSubdomainFileName = theFile;
1558 aSubdomainFileName = aSubdomainFileName + ".subdomain";
1559 ofstream aSubdomainFile ( aSubdomainFileName.ToCString() , ios::out);
1561 aSubdomainFile << "Nb subdomains " << subdomainId2tetraId.size() << std::endl;
1562 for(;subdomainIt != subdomainId2tetraId.end() ; ++subdomainIt) {
1563 int subdomainId = subdomainIt->first;
1564 std::set<int> tetraIds = subdomainIt->second;
1565 MESSAGE("Subdomain #"<<subdomainId<<": "<<tetraIds.size()<<" tetrahedrons");
1566 std::set<int>::const_iterator tetraIdsIt = tetraIds.begin();
1567 aSubdomainFile << subdomainId << std::endl;
1568 for(;tetraIdsIt != tetraIds.end() ; ++tetraIdsIt) {
1569 aSubdomainFile << (*tetraIdsIt) << " ";
1571 aSubdomainFile << std::endl;
1573 aSubdomainFile.close();
1580 static bool writeGMFFile(const char* theMeshFileName,
1581 const char* theRequiredFileName,
1582 const char* theSolFileName,
1583 const SMESH_ProxyMesh& theProxyMesh,
1584 SMESH_MesherHelper& theHelper,
1585 std::vector <const SMDS_MeshNode*> & theNodeByGhs3dId,
1586 std::vector <const SMDS_MeshElement*> & theFaceByGhs3dId,
1587 std::map<const SMDS_MeshNode*,int> & aNodeToGhs3dIdMap,
1588 std::vector<std::string> & aNodeGroupByGhs3dId,
1589 std::vector<std::string> & anEdgeGroupByGhs3dId,
1590 std::vector<std::string> & aFaceGroupByGhs3dId,
1591 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes,
1592 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
1593 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles,
1594 std::map<std::vector<double>, std::string> & enfVerticesWithGroup,
1595 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices)
1597 MESSAGE("writeGMFFile w/o geometry");
1599 int idx, idxRequired = 0, idxSol = 0;
1600 const int dummyint = 0;
1601 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt;
1602 std::vector<double> enfVertexSizes;
1603 const SMDS_MeshElement* elem;
1604 TIDSortedElemSet anElemSet, theKeptEnforcedEdges, theKeptEnforcedTriangles;
1605 SMDS_ElemIteratorPtr nodeIt;
1606 std::vector <const SMDS_MeshNode*> theEnforcedNodeByGhs3dId;
1607 map<const SMDS_MeshNode*,int> anEnforcedNodeToGhs3dIdMap, anExistingEnforcedNodeToGhs3dIdMap;
1608 std::vector< const SMDS_MeshElement* > foundElems;
1609 map<const SMDS_MeshNode*,TopAbs_State> aNodeToTopAbs_StateMap;
1611 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap::iterator elemIt;
1612 TIDSortedElemSet::iterator elemSetIt;
1614 SMESH_Mesh* theMesh = theHelper.GetMesh();
1615 const bool hasGeom = theMesh->HasShapeToMesh();
1616 auto_ptr< SMESH_ElementSearcher > pntCls
1617 ( SMESH_MeshAlgos::GetElementSearcher(*theMesh->GetMeshDS()));
1619 int nbEnforcedVertices = theEnforcedVertices.size();
1622 int nbFaces = theProxyMesh.NbFaces();
1624 theFaceByGhs3dId.reserve( nbFaces );
1626 // groups management
1627 int usedEnforcedNodes = 0;
1628 std::string gn = "";
1633 idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1637 /* ========================== FACES ========================== */
1638 /* TRIANGLES ========================== */
1639 SMDS_ElemIteratorPtr eIt =
1640 hasGeom ? theProxyMesh.GetFaces( theHelper.GetSubShape()) : theProxyMesh.GetFaces();
1641 while ( eIt->more() )
1644 anElemSet.insert(elem);
1645 nodeIt = elem->nodesIterator();
1646 nbNodes = elem->NbCornerNodes();
1647 while ( nodeIt->more() && nbNodes--)
1650 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1651 int newId = aNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
1652 aNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1656 /* EDGES ========================== */
1658 // Iterate over the enforced edges
1659 for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
1660 elem = elemIt->first;
1662 nodeIt = elem->nodesIterator();
1664 while ( nodeIt->more() && nbNodes-- ) {
1666 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1667 // Test if point is inside shape to mesh
1668 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1669 TopAbs_State result = pntCls->GetPointState( myPoint );
1670 if ( result == TopAbs_OUT ) {
1674 aNodeToTopAbs_StateMap.insert( make_pair( node, result ));
1677 nodeIt = elem->nodesIterator();
1680 while ( nodeIt->more() && nbNodes-- ) {
1682 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1683 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1684 nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1686 std::cout << "Node at "<<node->X()<<", "<<node->Y()<<", "<<node->Z()<<std::endl;
1687 std::cout << "Nb nodes found : "<<nbFoundElems<<std::endl;
1689 if (nbFoundElems ==0) {
1690 if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1691 newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
1692 anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1695 else if (nbFoundElems ==1) {
1696 const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1697 newId = (*aNodeToGhs3dIdMap.find(existingNode)).second;
1698 anExistingEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1703 std::cout << "GHS3D node ID: "<<newId<<std::endl;
1707 theKeptEnforcedEdges.insert(elem);
1711 /* ENFORCED TRIANGLES ========================== */
1713 // Iterate over the enforced triangles
1714 for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
1715 elem = elemIt->first;
1717 nodeIt = elem->nodesIterator();
1719 while ( nodeIt->more() && nbNodes--) {
1721 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1722 // Test if point is inside shape to mesh
1723 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1724 TopAbs_State result = pntCls->GetPointState( myPoint );
1725 if ( result == TopAbs_OUT ) {
1729 aNodeToTopAbs_StateMap.insert( make_pair( node, result ));
1732 nodeIt = elem->nodesIterator();
1735 while ( nodeIt->more() && nbNodes--) {
1737 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1738 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1739 nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1741 std::cout << "Nb nodes found : "<<nbFoundElems<<std::endl;
1743 if (nbFoundElems ==0) {
1744 if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1745 newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
1746 anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1749 else if (nbFoundElems ==1) {
1750 const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1751 newId = (*aNodeToGhs3dIdMap.find(existingNode)).second;
1752 anExistingEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1757 std::cout << "GHS3D node ID: "<<newId<<std::endl;
1761 theKeptEnforcedTriangles.insert(elem);
1765 // put nodes to theNodeByGhs3dId vector
1767 std::cout << "aNodeToGhs3dIdMap.size(): "<<aNodeToGhs3dIdMap.size()<<std::endl;
1769 theNodeByGhs3dId.resize( aNodeToGhs3dIdMap.size() );
1770 map<const SMDS_MeshNode*,int>::const_iterator n2id = aNodeToGhs3dIdMap.begin();
1771 for ( ; n2id != aNodeToGhs3dIdMap.end(); ++ n2id)
1773 // std::cout << "n2id->first: "<<n2id->first<<std::endl;
1774 theNodeByGhs3dId[ n2id->second - 1 ] = n2id->first; // ghs3d ids count from 1
1777 // put nodes to anEnforcedNodeToGhs3dIdMap vector
1779 std::cout << "anEnforcedNodeToGhs3dIdMap.size(): "<<anEnforcedNodeToGhs3dIdMap.size()<<std::endl;
1781 theEnforcedNodeByGhs3dId.resize( anEnforcedNodeToGhs3dIdMap.size());
1782 n2id = anEnforcedNodeToGhs3dIdMap.begin();
1783 for ( ; n2id != anEnforcedNodeToGhs3dIdMap.end(); ++ n2id)
1785 if (n2id->second > aNodeToGhs3dIdMap.size()) {
1786 theEnforcedNodeByGhs3dId[ n2id->second - aNodeToGhs3dIdMap.size() - 1 ] = n2id->first; // ghs3d ids count from 1
1791 /* ========================== NODES ========================== */
1792 vector<const SMDS_MeshNode*> theOrderedNodes, theRequiredNodes;
1793 std::set< std::vector<double> > nodesCoords;
1794 vector<const SMDS_MeshNode*>::const_iterator ghs3dNodeIt = theNodeByGhs3dId.begin();
1795 vector<const SMDS_MeshNode*>::const_iterator after = theNodeByGhs3dId.end();
1797 (theNodeByGhs3dId.size() <= 1) ? tmpStr = " node" : " nodes";
1798 std::cout << theNodeByGhs3dId.size() << tmpStr << " from mesh ..." << std::endl;
1799 for ( ; ghs3dNodeIt != after; ++ghs3dNodeIt )
1801 const SMDS_MeshNode* node = *ghs3dNodeIt;
1802 std::vector<double> coords;
1803 coords.push_back(node->X());
1804 coords.push_back(node->Y());
1805 coords.push_back(node->Z());
1806 nodesCoords.insert(coords);
1807 theOrderedNodes.push_back(node);
1810 // Iterate over the enforced nodes given by enforced elements
1811 ghs3dNodeIt = theEnforcedNodeByGhs3dId.begin();
1812 after = theEnforcedNodeByGhs3dId.end();
1813 (theEnforcedNodeByGhs3dId.size() <= 1) ? tmpStr = " node" : " nodes";
1814 std::cout << theEnforcedNodeByGhs3dId.size() << tmpStr << " from enforced elements ..." << std::endl;
1815 for ( ; ghs3dNodeIt != after; ++ghs3dNodeIt )
1817 const SMDS_MeshNode* node = *ghs3dNodeIt;
1818 std::vector<double> coords;
1819 coords.push_back(node->X());
1820 coords.push_back(node->Y());
1821 coords.push_back(node->Z());
1823 std::cout << "Node at " << node->X()<<", " <<node->Y()<<", " <<node->Z();
1826 if (nodesCoords.find(coords) != nodesCoords.end()) {
1827 // node already exists in original mesh
1829 std::cout << " found" << std::endl;
1834 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) {
1835 // node already exists in enforced vertices
1837 std::cout << " found" << std::endl;
1842 // gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1843 // nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1844 // if (nbFoundElems ==0) {
1845 // std::cout << " not found" << std::endl;
1846 // if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1847 // nodesCoords.insert(coords);
1848 // theOrderedNodes.push_back(node);
1852 // std::cout << " found in initial mesh" << std::endl;
1853 // const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1854 // nodesCoords.insert(coords);
1855 // theOrderedNodes.push_back(existingNode);
1859 std::cout << " not found" << std::endl;
1862 nodesCoords.insert(coords);
1863 theOrderedNodes.push_back(node);
1864 // theRequiredNodes.push_back(node);
1868 // Iterate over the enforced nodes
1869 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt;
1870 (theEnforcedNodes.size() <= 1) ? tmpStr = " node" : " nodes";
1871 std::cout << theEnforcedNodes.size() << tmpStr << " from enforced nodes ..." << std::endl;
1872 for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt)
1874 const SMDS_MeshNode* node = enfNodeIt->first;
1875 std::vector<double> coords;
1876 coords.push_back(node->X());
1877 coords.push_back(node->Y());
1878 coords.push_back(node->Z());
1880 std::cout << "Node at " << node->X()<<", " <<node->Y()<<", " <<node->Z();
1883 // Test if point is inside shape to mesh
1884 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1885 TopAbs_State result = pntCls->GetPointState( myPoint );
1886 if ( result == TopAbs_OUT ) {
1888 std::cout << " out of volume" << std::endl;
1893 if (nodesCoords.find(coords) != nodesCoords.end()) {
1895 std::cout << " found in nodesCoords" << std::endl;
1897 // theRequiredNodes.push_back(node);
1901 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) {
1903 std::cout << " found in theEnforcedVertices" << std::endl;
1908 // nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1909 // if (nbFoundElems ==0) {
1910 // std::cout << " not found" << std::endl;
1911 // if (result == TopAbs_IN) {
1912 // nodesCoords.insert(coords);
1913 // theRequiredNodes.push_back(node);
1917 // std::cout << " found in initial mesh" << std::endl;
1918 // const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1919 // // nodesCoords.insert(coords);
1920 // theRequiredNodes.push_back(existingNode);
1925 // if (pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems) == 0)
1928 // if ( result != TopAbs_IN )
1932 std::cout << " not found" << std::endl;
1934 nodesCoords.insert(coords);
1935 // theOrderedNodes.push_back(node);
1936 theRequiredNodes.push_back(node);
1938 int requiredNodes = theRequiredNodes.size();
1941 std::vector<std::vector<double> > ReqVerTab;
1942 if (nbEnforcedVertices) {
1943 // ReqVerTab.clear();
1944 (nbEnforcedVertices <= 1) ? tmpStr = " node" : " nodes";
1945 std::cout << nbEnforcedVertices << tmpStr << " from enforced vertices ..." << std::endl;
1946 // Iterate over the enforced vertices
1947 for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
1948 double x = vertexIt->first[0];
1949 double y = vertexIt->first[1];
1950 double z = vertexIt->first[2];
1951 // Test if point is inside shape to mesh
1952 gp_Pnt myPoint(x,y,z);
1953 TopAbs_State result = pntCls->GetPointState( myPoint );
1954 if ( result == TopAbs_OUT )
1956 //if (pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems) == 0)
1959 // if ( result != TopAbs_IN )
1961 std::vector<double> coords;
1962 coords.push_back(x);
1963 coords.push_back(y);
1964 coords.push_back(z);
1965 ReqVerTab.push_back(coords);
1966 enfVertexSizes.push_back(vertexIt->second);
1973 std::cout << "Begin writting required nodes in GmfVertices" << std::endl;
1974 std::cout << "Nb vertices: " << theOrderedNodes.size() << std::endl;
1975 GmfSetKwd(idx, GmfVertices, theOrderedNodes.size()/*+solSize*/);
1976 for (ghs3dNodeIt = theOrderedNodes.begin();ghs3dNodeIt != theOrderedNodes.end();++ghs3dNodeIt) {
1977 GmfSetLin(idx, GmfVertices, (*ghs3dNodeIt)->X(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint);
1980 std::cout << "End writting required nodes in GmfVertices" << std::endl;
1982 if (requiredNodes + solSize) {
1983 std::cout << "Begin writting in req and sol file" << std::endl;
1984 aNodeGroupByGhs3dId.resize( requiredNodes + solSize );
1985 idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1990 idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1994 GmfCloseMesh(idxRequired);
1997 int TypTab[] = {GmfSca};
1998 double ValTab[] = {0.0};
1999 GmfSetKwd(idxRequired, GmfVertices, requiredNodes + solSize);
2000 GmfSetKwd(idxSol, GmfSolAtVertices, requiredNodes + solSize, 1, TypTab);
2001 // int usedEnforcedNodes = 0;
2002 // std::string gn = "";
2003 for (ghs3dNodeIt = theRequiredNodes.begin();ghs3dNodeIt != theRequiredNodes.end();++ghs3dNodeIt) {
2004 GmfSetLin(idxRequired, GmfVertices, (*ghs3dNodeIt)->X(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint);
2005 GmfSetLin(idxSol, GmfSolAtVertices, ValTab);
2006 if (theEnforcedNodes.find((*ghs3dNodeIt)) != theEnforcedNodes.end())
2007 gn = theEnforcedNodes.find((*ghs3dNodeIt))->second;
2008 aNodeGroupByGhs3dId[usedEnforcedNodes] = gn;
2009 usedEnforcedNodes++;
2012 for (int i=0;i<solSize;i++) {
2013 std::cout << ReqVerTab[i][0] <<" "<< ReqVerTab[i][1] << " "<< ReqVerTab[i][2] << std::endl;
2015 std::cout << "enfVertexSizes.at("<<i<<"): " << enfVertexSizes.at(i) << std::endl;
2017 double solTab[] = {enfVertexSizes.at(i)};
2018 GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
2019 GmfSetLin(idxSol, GmfSolAtVertices, solTab);
2020 aNodeGroupByGhs3dId[usedEnforcedNodes] = enfVerticesWithGroup.find(ReqVerTab[i])->second;
2022 std::cout << "aNodeGroupByGhs3dId["<<usedEnforcedNodes<<"] = \""<<aNodeGroupByGhs3dId[usedEnforcedNodes]<<"\""<<std::endl;
2024 usedEnforcedNodes++;
2026 std::cout << "End writting in req and sol file" << std::endl;
2029 int nedge[2], ntri[3];
2032 int usedEnforcedEdges = 0;
2033 if (theKeptEnforcedEdges.size()) {
2034 anEdgeGroupByGhs3dId.resize( theKeptEnforcedEdges.size() );
2035 // idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
2036 // if (!idxRequired)
2038 GmfSetKwd(idx, GmfEdges, theKeptEnforcedEdges.size());
2039 // GmfSetKwd(idxRequired, GmfEdges, theKeptEnforcedEdges.size());
2040 for(elemSetIt = theKeptEnforcedEdges.begin() ; elemSetIt != theKeptEnforcedEdges.end() ; ++elemSetIt) {
2041 elem = (*elemSetIt);
2042 nodeIt = elem->nodesIterator();
2044 while ( nodeIt->more() ) {
2046 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
2047 map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node);
2048 if (it == anEnforcedNodeToGhs3dIdMap.end()) {
2049 it = anExistingEnforcedNodeToGhs3dIdMap.find(node);
2050 if (it == anEnforcedNodeToGhs3dIdMap.end())
2051 throw "Node not found";
2053 nedge[index] = it->second;
2056 GmfSetLin(idx, GmfEdges, nedge[0], nedge[1], dummyint);
2057 anEdgeGroupByGhs3dId[usedEnforcedEdges] = theEnforcedEdges.find(elem)->second;
2058 // GmfSetLin(idxRequired, GmfEdges, nedge[0], nedge[1], dummyint);
2059 usedEnforcedEdges++;
2061 // GmfCloseMesh(idxRequired);
2065 if (usedEnforcedEdges) {
2066 GmfSetKwd(idx, GmfRequiredEdges, usedEnforcedEdges);
2067 for (int enfID=1;enfID<=usedEnforcedEdges;enfID++) {
2068 GmfSetLin(idx, GmfRequiredEdges, enfID);
2073 int usedEnforcedTriangles = 0;
2074 if (anElemSet.size()+theKeptEnforcedTriangles.size()) {
2075 aFaceGroupByGhs3dId.resize( anElemSet.size()+theKeptEnforcedTriangles.size() );
2076 GmfSetKwd(idx, GmfTriangles, anElemSet.size()+theKeptEnforcedTriangles.size());
2078 for(elemSetIt = anElemSet.begin() ; elemSetIt != anElemSet.end() ; ++elemSetIt,++k) {
2079 elem = (*elemSetIt);
2080 theFaceByGhs3dId.push_back( elem );
2081 nodeIt = elem->nodesIterator();
2083 for ( int j = 0; j < 3; ++j ) {
2085 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
2086 map< const SMDS_MeshNode*,int >::iterator it = aNodeToGhs3dIdMap.find(node);
2087 if (it == aNodeToGhs3dIdMap.end())
2088 throw "Node not found";
2089 ntri[index] = it->second;
2092 GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint);
2093 aFaceGroupByGhs3dId[k] = "";
2095 if ( !theHelper.GetMesh()->HasShapeToMesh() )
2096 SMESHUtils::FreeVector( theFaceByGhs3dId );
2097 if (theKeptEnforcedTriangles.size()) {
2098 for(elemSetIt = theKeptEnforcedTriangles.begin() ; elemSetIt != theKeptEnforcedTriangles.end() ; ++elemSetIt,++k) {
2099 elem = (*elemSetIt);
2100 nodeIt = elem->nodesIterator();
2102 for ( int j = 0; j < 3; ++j ) {
2104 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
2105 map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node);
2106 if (it == anEnforcedNodeToGhs3dIdMap.end()) {
2107 it = anExistingEnforcedNodeToGhs3dIdMap.find(node);
2108 if (it == anEnforcedNodeToGhs3dIdMap.end())
2109 throw "Node not found";
2111 ntri[index] = it->second;
2114 GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint);
2115 aFaceGroupByGhs3dId[k] = theEnforcedTriangles.find(elem)->second;
2116 usedEnforcedTriangles++;
2122 if (usedEnforcedTriangles) {
2123 GmfSetKwd(idx, GmfRequiredTriangles, usedEnforcedTriangles);
2124 for (int enfID=1;enfID<=usedEnforcedTriangles;enfID++)
2125 GmfSetLin(idx, GmfRequiredTriangles, anElemSet.size()+enfID);
2130 GmfCloseMesh(idxRequired);
2132 GmfCloseMesh(idxSol);
2138 // static bool writeGMFFile(const char* theMeshFileName,
2139 // const char* theRequiredFileName,
2140 // const char* theSolFileName,
2141 // SMESH_MesherHelper& theHelper,
2142 // const SMESH_ProxyMesh& theProxyMesh,
2143 // std::map <int,int> & theNodeId2NodeIndexMap,
2144 // std::map <int,int> & theSmdsToGhs3dIdMap,
2145 // std::map <int,const SMDS_MeshNode*> & theGhs3dIdToNodeMap,
2146 // TIDSortedNodeSet & theEnforcedNodes,
2147 // TIDSortedElemSet & theEnforcedEdges,
2148 // TIDSortedElemSet & theEnforcedTriangles,
2149 // // TIDSortedElemSet & theEnforcedQuadrangles,
2150 // GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices)
2152 // MESSAGE("writeGMFFile with geometry");
2153 // int idx, idxRequired, idxSol;
2154 // int nbv, nbev, nben, aGhs3dID = 0;
2155 // const int dummyint = 0;
2156 // GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt;
2157 // std::vector<double> enfVertexSizes;
2158 // TIDSortedNodeSet::const_iterator enfNodeIt;
2159 // const SMDS_MeshNode* node;
2160 // SMDS_NodeIteratorPtr nodeIt;
2162 // idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
2166 // SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS();
2168 // /* ========================== NODES ========================== */
2170 // nbv = theMeshDS->NbNodes();
2173 // nbev = theEnforcedVertices.size();
2174 // nben = theEnforcedNodes.size();
2176 // // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D
2177 // // The problem is in nodes on degenerated edges, we need to skip nodes which are free
2178 // // and replace not-free nodes on edges by the node on vertex
2179 // TNodeNodeMap n2nDegen; // map a node on degenerated edge to a node on vertex
2180 // TNodeNodeMap::iterator n2nDegenIt;
2181 // if ( theHelper.HasDegeneratedEdges() )
2183 // set<int> checkedSM;
2184 // for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next())
2186 // SMESH_subMesh* sm = theHelper.GetMesh()->GetSubMesh( e.Current() );
2187 // if ( checkedSM.insert( sm->GetId() ).second && theHelper.IsDegenShape(sm->GetId() ))
2189 // if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() )
2191 // TopoDS_Shape vertex = TopoDS_Iterator( e.Current() ).Value();
2192 // const SMDS_MeshNode* vNode = SMESH_Algo::VertexNode( TopoDS::Vertex( vertex ), theMeshDS);
2194 // SMDS_NodeIteratorPtr nIt = smDS->GetNodes();
2195 // while ( nIt->more() )
2196 // n2nDegen.insert( make_pair( nIt->next(), vNode ));
2203 // const bool isQuadMesh =
2204 // theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
2205 // theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
2206 // theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC );
2208 // std::vector<std::vector<double> > VerTab;
2209 // std::set<std::vector<double> > VerMap;
2211 // std::vector<double> aVerTab;
2212 // // Loop from 1 to NB_NODES
2214 // nodeIt = theMeshDS->nodesIterator();
2216 // while ( nodeIt->more() )
2218 // node = nodeIt->next();
2219 // if ( isQuadMesh && theHelper.IsMedium( node )) // Issue 0021238
2221 // if ( n2nDegen.count( node ) ) // Issue 0020674
2224 // std::vector<double> coords;
2225 // coords.push_back(node->X());
2226 // coords.push_back(node->Y());
2227 // coords.push_back(node->Z());
2228 // if (VerMap.find(coords) != VerMap.end()) {
2229 // aGhs3dID = theSmdsToGhs3dIdMap[node->GetID()];
2230 // theGhs3dIdToNodeMap[theSmdsToGhs3dIdMap[node->GetID()]] = node;
2233 // VerTab.push_back(coords);
2234 // VerMap.insert(coords);
2236 // theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID ));
2237 // theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node ));
2241 // /* ENFORCED NODES ========================== */
2243 // std::cout << "Add " << nben << " enforced nodes to input .mesh file" << std::endl;
2244 // for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt) {
2245 // double x = (*enfNodeIt)->X();
2246 // double y = (*enfNodeIt)->Y();
2247 // double z = (*enfNodeIt)->Z();
2248 // // Test if point is inside shape to mesh
2249 // gp_Pnt myPoint(x,y,z);
2250 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2251 // scl.Perform(myPoint, 1e-7);
2252 // TopAbs_State result = scl.State();
2253 // if ( result != TopAbs_IN )
2255 // std::vector<double> coords;
2256 // coords.push_back(x);
2257 // coords.push_back(y);
2258 // coords.push_back(z);
2259 // if (theEnforcedVertices.find(coords) != theEnforcedVertices.end())
2261 // if (VerMap.find(coords) != VerMap.end())
2263 // VerTab.push_back(coords);
2264 // VerMap.insert(coords);
2266 // theNodeId2NodeIndexMap.insert( make_pair( (*enfNodeIt)->GetID(), aGhs3dID ));
2271 // /* ENFORCED VERTICES ========================== */
2273 // std::vector<std::vector<double> > ReqVerTab;
2274 // ReqVerTab.clear();
2276 // std::cout << "Add " << nbev << " enforced vertices to input .mesh file" << std::endl;
2277 // for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
2278 // double x = vertexIt->first[0];
2279 // double y = vertexIt->first[1];
2280 // double z = vertexIt->first[2];
2281 // // Test if point is inside shape to mesh
2282 // gp_Pnt myPoint(x,y,z);
2283 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2284 // scl.Perform(myPoint, 1e-7);
2285 // TopAbs_State result = scl.State();
2286 // if ( result != TopAbs_IN )
2288 // enfVertexSizes.push_back(vertexIt->second);
2289 // std::vector<double> coords;
2290 // coords.push_back(x);
2291 // coords.push_back(y);
2292 // coords.push_back(z);
2293 // if (VerMap.find(coords) != VerMap.end())
2295 // ReqVerTab.push_back(coords);
2296 // VerMap.insert(coords);
2302 // /* ========================== FACES ========================== */
2304 // int nbTriangles = 0/*, nbQuadrangles = 0*/, aSmdsID;
2305 // TopTools_IndexedMapOfShape facesMap, trianglesMap/*, quadranglesMap*/;
2306 // TIDSortedElemSet::const_iterator elemIt;
2307 // const SMESHDS_SubMesh* theSubMesh;
2308 // TopoDS_Shape aShape;
2309 // SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace;
2310 // const SMDS_MeshElement* aFace;
2311 // map<int,int>::const_iterator itOnMap;
2312 // std::vector<std::vector<int> > tt, qt,et;
2316 // std::vector<int> att, aqt, aet;
2318 // TopExp::MapShapes( theMeshDS->ShapeToMesh(), TopAbs_FACE, facesMap );
2320 // for ( int i = 1; i <= facesMap.Extent(); ++i )
2321 // if (( theSubMesh = theProxyMesh.GetSubMesh( facesMap(i))))
2323 // SMDS_ElemIteratorPtr it = theSubMesh->GetElements();
2324 // while (it->more())
2326 // const SMDS_MeshElement *elem = it->next();
2327 // int nbCornerNodes = elem->NbCornerNodes();
2328 // if (nbCornerNodes == 3)
2330 // trianglesMap.Add(facesMap(i));
2333 // // else if (nbCornerNodes == 4)
2335 // // quadranglesMap.Add(facesMap(i));
2336 // // nbQuadrangles ++;
2341 // /* TRIANGLES ========================== */
2342 // if (nbTriangles) {
2343 // for ( int i = 1; i <= trianglesMap.Extent(); i++ )
2345 // aShape = trianglesMap(i);
2346 // theSubMesh = theProxyMesh.GetSubMesh(aShape);
2347 // if ( !theSubMesh ) continue;
2348 // itOnSubMesh = theSubMesh->GetElements();
2349 // while ( itOnSubMesh->more() )
2351 // aFace = itOnSubMesh->next();
2352 // itOnSubFace = aFace->nodesIterator();
2354 // for ( int j = 0; j < 3; ++j ) {
2356 // node = castToNode( itOnSubFace->next() );
2357 // if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() )
2358 // node = n2nDegenIt->second;
2359 // aSmdsID = node->GetID();
2360 // itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
2361 // ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
2362 // att.push_back((*itOnMap).second);
2364 // tt.push_back(att);
2369 // if (theEnforcedTriangles.size()) {
2370 // std::cout << "Add " << theEnforcedTriangles.size() << " enforced triangles to input .mesh file" << std::endl;
2371 // // Iterate over the enforced triangles
2372 // for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
2373 // aFace = (*elemIt);
2374 // itOnSubFace = aFace->nodesIterator();
2375 // bool isOK = true;
2378 // for ( int j = 0; j < 3; ++j ) {
2379 // node = castToNode( itOnSubFace->next() );
2380 // if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() )
2381 // node = n2nDegenIt->second;
2382 // // std::cout << node;
2383 // double x = node->X();
2384 // double y = node->Y();
2385 // double z = node->Z();
2386 // // Test if point is inside shape to mesh
2387 // gp_Pnt myPoint(x,y,z);
2388 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2389 // scl.Perform(myPoint, 1e-7);
2390 // TopAbs_State result = scl.State();
2391 // if ( result != TopAbs_IN ) {
2393 // theEnforcedTriangles.erase(elemIt);
2396 // std::vector<double> coords;
2397 // coords.push_back(x);
2398 // coords.push_back(y);
2399 // coords.push_back(z);
2400 // if (VerMap.find(coords) != VerMap.end()) {
2401 // att.push_back(theNodeId2NodeIndexMap[node->GetID()]);
2404 // VerTab.push_back(coords);
2405 // VerMap.insert(coords);
2407 // theNodeId2NodeIndexMap.insert( make_pair( node->GetID(), aGhs3dID ));
2408 // att.push_back(aGhs3dID);
2411 // tt.push_back(att);
2416 // /* ========================== EDGES ========================== */
2418 // if (theEnforcedEdges.size()) {
2419 // // Iterate over the enforced edges
2420 // std::cout << "Add " << theEnforcedEdges.size() << " enforced edges to input .mesh file" << std::endl;
2421 // for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
2422 // aFace = (*elemIt);
2423 // bool isOK = true;
2424 // itOnSubFace = aFace->nodesIterator();
2426 // for ( int j = 0; j < 2; ++j ) {
2427 // node = castToNode( itOnSubFace->next() );
2428 // if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() )
2429 // node = n2nDegenIt->second;
2430 // double x = node->X();
2431 // double y = node->Y();
2432 // double z = node->Z();
2433 // // Test if point is inside shape to mesh
2434 // gp_Pnt myPoint(x,y,z);
2435 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2436 // scl.Perform(myPoint, 1e-7);
2437 // TopAbs_State result = scl.State();
2438 // if ( result != TopAbs_IN ) {
2440 // theEnforcedEdges.erase(elemIt);
2443 // std::vector<double> coords;
2444 // coords.push_back(x);
2445 // coords.push_back(y);
2446 // coords.push_back(z);
2447 // if (VerMap.find(coords) != VerMap.end()) {
2448 // aet.push_back(theNodeId2NodeIndexMap[node->GetID()]);
2451 // VerTab.push_back(coords);
2452 // VerMap.insert(coords);
2455 // theNodeId2NodeIndexMap.insert( make_pair( node->GetID(), aGhs3dID ));
2456 // aet.push_back(aGhs3dID);
2459 // et.push_back(aet);
2464 // /* Write vertices number */
2465 // MESSAGE("Number of vertices: "<<aGhs3dID);
2466 // MESSAGE("Size of vector: "<<VerTab.size());
2467 // GmfSetKwd(idx, GmfVertices, aGhs3dID/*+solSize*/);
2468 // for (int i=0;i<aGhs3dID;i++)
2469 // GmfSetLin(idx, GmfVertices, VerTab[i][0], VerTab[i][1], VerTab[i][2], dummyint);
2470 // // for (int i=0;i<solSize;i++) {
2471 // // std::cout << ReqVerTab[i][0] <<" "<< ReqVerTab[i][1] << " "<< ReqVerTab[i][2] << std::endl;
2472 // // GmfSetLin(idx, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
2476 // idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
2477 // if (!idxRequired) {
2478 // GmfCloseMesh(idx);
2481 // idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
2483 // GmfCloseMesh(idx);
2485 // GmfCloseMesh(idxRequired);
2489 // int TypTab[] = {GmfSca};
2490 // GmfSetKwd(idxRequired, GmfVertices, solSize);
2491 // GmfSetKwd(idxSol, GmfSolAtVertices, solSize, 1, TypTab);
2493 // for (int i=0;i<solSize;i++) {
2494 // double solTab[] = {enfVertexSizes.at(i)};
2495 // GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
2496 // GmfSetLin(idxSol, GmfSolAtVertices, solTab);
2498 // GmfCloseMesh(idxRequired);
2499 // GmfCloseMesh(idxSol);
2502 // /* Write triangles number */
2504 // GmfSetKwd(idx, GmfTriangles, tt.size());
2505 // for (int i=0;i<tt.size();i++)
2506 // GmfSetLin(idx, GmfTriangles, tt[i][0], tt[i][1], tt[i][2], dummyint);
2509 // /* Write edges number */
2511 // GmfSetKwd(idx, GmfEdges, et.size());
2512 // for (int i=0;i<et.size();i++)
2513 // GmfSetLin(idx, GmfEdges, et[i][0], et[i][1], dummyint);
2516 // /* QUADRANGLES ========================== */
2517 // // TODO: add pyramids ?
2518 // // if (nbQuadrangles) {
2519 // // for ( int i = 1; i <= quadranglesMap.Extent(); i++ )
2521 // // aShape = quadranglesMap(i);
2522 // // theSubMesh = theProxyMesh.GetSubMesh(aShape);
2523 // // if ( !theSubMesh ) continue;
2524 // // itOnSubMesh = theSubMesh->GetElements();
2525 // // for ( int j = 0; j < 4; ++j )
2527 // // aFace = itOnSubMesh->next();
2528 // // itOnSubFace = aFace->nodesIterator();
2530 // // while ( itOnSubFace->more() ) {
2531 // // // find GHS3D ID
2532 // // aSmdsID = itOnSubFace->next()->GetID();
2533 // // itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
2534 // // ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
2535 // // aqt.push_back((*itOnMap).second);
2537 // // qt.push_back(aqt);
2542 // // if (theEnforcedQuadrangles.size()) {
2543 // // // Iterate over the enforced triangles
2544 // // for(elemIt = theEnforcedQuadrangles.begin() ; elemIt != theEnforcedQuadrangles.end() ; ++elemIt) {
2545 // // aFace = (*elemIt);
2546 // // bool isOK = true;
2547 // // itOnSubFace = aFace->nodesIterator();
2549 // // for ( int j = 0; j < 4; ++j ) {
2550 // // int aNodeID = itOnSubFace->next()->GetID();
2551 // // itOnMap = theNodeId2NodeIndexMap.find(aNodeID);
2552 // // if (itOnMap != theNodeId2NodeIndexMap.end())
2553 // // aqt.push_back((*itOnMap).second);
2556 // // theEnforcedQuadrangles.erase(elemIt);
2561 // // qt.push_back(aqt);
2566 // // /* Write quadrilaterals number */
2567 // // if (qt.size()) {
2568 // // GmfSetKwd(idx, GmfQuadrilaterals, qt.size());
2569 // // for (int i=0;i<qt.size();i++)
2570 // // GmfSetLin(idx, GmfQuadrilaterals, qt[i][0], qt[i][1], qt[i][2], qt[i][3], dummyint);
2573 // GmfCloseMesh(idx);
2578 //=======================================================================
2579 //function : writeFaces
2581 //=======================================================================
2583 static bool writeFaces (ofstream & theFile,
2584 const SMESH_ProxyMesh& theMesh,
2585 const TopoDS_Shape& theShape,
2586 const map <int,int> & theSmdsToGhs3dIdMap,
2587 const map <int,int> & theEnforcedNodeIdToGhs3dIdMap,
2588 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
2589 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles)
2591 // record structure:
2593 // NB_ELEMS DUMMY_INT
2594 // Loop from 1 to NB_ELEMS
2595 // NB_NODES NODE_NB_1 NODE_NB_2 ... (NB_NODES + 1) times: DUMMY_INT
2597 TopoDS_Shape aShape;
2598 const SMESHDS_SubMesh* theSubMesh;
2599 const SMDS_MeshElement* aFace;
2600 const char* space = " ";
2601 const int dummyint = 0;
2602 map<int,int>::const_iterator itOnMap;
2603 SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace;
2604 int nbNodes, aSmdsID;
2606 TIDSortedElemSet::const_iterator elemIt;
2607 int nbEnforcedEdges = theEnforcedEdges.size();
2608 int nbEnforcedTriangles = theEnforcedTriangles.size();
2610 // count triangles bound to geometry
2611 int nbTriangles = 0;
2613 TopTools_IndexedMapOfShape facesMap, trianglesMap;
2614 TopExp::MapShapes( theShape, TopAbs_FACE, facesMap );
2616 int nbFaces = facesMap.Extent();
2618 for ( int i = 1; i <= nbFaces; ++i )
2619 if (( theSubMesh = theMesh.GetSubMesh( facesMap(i))))
2620 nbTriangles += theSubMesh->NbElements();
2622 (nbFaces == 0 || nbFaces == 1) ? tmpStr = " shape " : tmpStr = " shapes " ;
2623 std::cout << " " << nbFaces << tmpStr << "of 2D dimension";
2624 int nbEnforcedElements = nbEnforcedEdges+nbEnforcedTriangles;
2625 if (nbEnforcedElements > 0) {
2626 (nbEnforcedElements == 1) ? tmpStr = "shape:" : tmpStr = "shapes:";
2627 std::cout << " and" << std::endl;
2628 std::cout << " " << nbEnforcedElements
2629 << " enforced " << tmpStr << std::endl;
2632 std::cout << std::endl;
2633 if (nbEnforcedEdges) {
2634 (nbEnforcedEdges == 1) ? tmpStr = "edge" : tmpStr = "edges";
2635 std::cout << " " << nbEnforcedEdges << " enforced " << tmpStr << std::endl;
2637 if (nbEnforcedTriangles) {
2638 (nbEnforcedTriangles == 1) ? tmpStr = "triangle" : tmpStr = "triangles";
2639 std::cout << " " << nbEnforcedTriangles << " enforced " << tmpStr << std::endl;
2641 std::cout << std::endl;
2643 // theFile << space << nbTriangles << space << dummyint << std::endl;
2644 std::ostringstream globalStream, localStream, aStream;
2646 for ( int i = 1; i <= facesMap.Extent(); i++ )
2648 aShape = facesMap(i);
2649 theSubMesh = theMesh.GetSubMesh(aShape);
2650 if ( !theSubMesh ) continue;
2651 itOnSubMesh = theSubMesh->GetElements();
2652 while ( itOnSubMesh->more() )
2654 aFace = itOnSubMesh->next();
2655 nbNodes = aFace->NbCornerNodes();
2657 localStream << nbNodes << space;
2659 itOnSubFace = aFace->nodesIterator();
2660 for ( int j = 0; j < 3; ++j ) {
2662 aSmdsID = itOnSubFace->next()->GetID();
2663 itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
2664 // if ( itOnMap == theSmdsToGhs3dIdMap.end() ) {
2665 // cout << "not found node: " << aSmdsID << endl;
2668 ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
2670 localStream << (*itOnMap).second << space ;
2673 // (NB_NODES + 1) times: DUMMY_INT
2674 for ( int j=0; j<=nbNodes; j++)
2675 localStream << dummyint << space ;
2677 localStream << std::endl;
2681 globalStream << localStream.str();
2682 localStream.str("");
2689 // // ENFORCED EDGES : BEGIN
2692 // // Iterate over the enforced edges
2693 // int usedEnforcedEdges = 0;
2695 // for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
2696 // aFace = (*elemIt);
2698 // itOnSubFace = aFace->nodesIterator();
2700 // aStream << "2" << space ;
2701 // for ( int j = 0; j < 2; ++j ) {
2702 // aSmdsID = itOnSubFace->next()->GetID();
2703 // itOnMap = theEnforcedNodeIdToGhs3dIdMap.find(aSmdsID);
2704 // if (itOnMap != theEnforcedNodeIdToGhs3dIdMap.end())
2705 // aStream << (*itOnMap).second << space;
2712 // for ( int j=0; j<=2; j++)
2713 // aStream << dummyint << space ;
2714 // // aStream << dummyint << space << dummyint;
2715 // localStream << aStream.str() << std::endl;
2716 // usedEnforcedEdges++;
2720 // if (usedEnforcedEdges) {
2721 // globalStream << localStream.str();
2722 // localStream.str("");
2726 // // ENFORCED EDGES : END
2731 // // ENFORCED TRIANGLES : BEGIN
2733 // // Iterate over the enforced triangles
2734 // int usedEnforcedTriangles = 0;
2735 // for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
2736 // aFace = (*elemIt);
2737 // nbNodes = aFace->NbCornerNodes();
2739 // itOnSubFace = aFace->nodesIterator();
2741 // aStream << nbNodes << space ;
2742 // for ( int j = 0; j < 3; ++j ) {
2743 // aSmdsID = itOnSubFace->next()->GetID();
2744 // itOnMap = theEnforcedNodeIdToGhs3dIdMap.find(aSmdsID);
2745 // if (itOnMap != theEnforcedNodeIdToGhs3dIdMap.end())
2746 // aStream << (*itOnMap).second << space;
2753 // for ( int j=0; j<=3; j++)
2754 // aStream << dummyint << space ;
2755 // localStream << aStream.str() << std::endl;
2756 // usedEnforcedTriangles++;
2760 // if (usedEnforcedTriangles) {
2761 // globalStream << localStream.str();
2762 // localStream.str("");
2766 // // ENFORCED TRIANGLES : END
2770 << nbTriangles/*+usedEnforcedTriangles+usedEnforcedEdges*/
2771 << " 0" << std::endl
2772 << globalStream.str();
2777 //=======================================================================
2778 //function : writePoints
2780 //=======================================================================
2782 static bool writePoints (ofstream & theFile,
2783 SMESH_MesherHelper& theHelper,
2784 map <int,int> & theSmdsToGhs3dIdMap,
2785 map <int,int> & theEnforcedNodeIdToGhs3dIdMap,
2786 map <int,const SMDS_MeshNode*> & theGhs3dIdToNodeMap,
2787 GHS3DPlugin_Hypothesis::TID2SizeMap & theNodeIDToSizeMap,
2788 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices,
2789 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes,
2790 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
2791 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles)
2793 // record structure:
2796 // Loop from 1 to NB_NODES
2799 SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS();
2800 int nbNodes = theMeshDS->NbNodes();
2804 int nbEnforcedVertices = theEnforcedVertices.size();
2805 int nbEnforcedNodes = theEnforcedNodes.size();
2807 const TopoDS_Shape shapeToMesh = theMeshDS->ShapeToMesh();
2810 SMDS_NodeIteratorPtr nodeIt = theMeshDS->nodesIterator();
2811 const SMDS_MeshNode* node;
2813 // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D
2814 // The problem is in nodes on degenerated edges, we need to skip nodes which are free
2815 // and replace not-free nodes on degenerated edges by the node on vertex
2816 TNodeNodeMap n2nDegen; // map a node on degenerated edge to a node on vertex
2817 TNodeNodeMap::iterator n2nDegenIt;
2818 if ( theHelper.HasDegeneratedEdges() )
2821 for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next())
2823 SMESH_subMesh* sm = theHelper.GetMesh()->GetSubMesh( e.Current() );
2824 if ( checkedSM.insert( sm->GetId() ).second && theHelper.IsDegenShape(sm->GetId() ))
2826 if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() )
2828 TopoDS_Shape vertex = TopoDS_Iterator( e.Current() ).Value();
2829 const SMDS_MeshNode* vNode = SMESH_Algo::VertexNode( TopoDS::Vertex( vertex ), theMeshDS);
2831 SMDS_NodeIteratorPtr nIt = smDS->GetNodes();
2832 while ( nIt->more() )
2833 n2nDegen.insert( make_pair( nIt->next(), vNode ));
2838 nbNodes -= n2nDegen.size();
2841 const bool isQuadMesh =
2842 theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
2843 theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
2844 theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC );
2847 // descrease nbNodes by nb of medium nodes
2848 while ( nodeIt->more() )
2850 node = nodeIt->next();
2851 if ( !theHelper.IsDegenShape( node->getshapeId() ))
2852 nbNodes -= int( theHelper.IsMedium( node ));
2854 nodeIt = theMeshDS->nodesIterator();
2857 const char* space = " ";
2858 const int dummyint = 0;
2861 (nbNodes == 0 || nbNodes == 1) ? tmpStr = " node" : tmpStr = " nodes";
2863 std::cout << std::endl;
2864 std::cout << "The initial 2D mesh contains :" << std::endl;
2865 std::cout << " " << nbNodes << tmpStr << std::endl;
2866 if (nbEnforcedVertices > 0) {
2867 (nbEnforcedVertices == 1) ? tmpStr = "vertex" : tmpStr = "vertices";
2868 std::cout << " " << nbEnforcedVertices << " enforced " << tmpStr << std::endl;
2870 if (nbEnforcedNodes > 0) {
2871 (nbEnforcedNodes == 1) ? tmpStr = "node" : tmpStr = "nodes";
2872 std::cout << " " << nbEnforcedNodes << " enforced " << tmpStr << std::endl;
2874 std::cout << std::endl;
2875 std::cout << "Start writing in 'points' file ..." << std::endl;
2877 theFile << nbNodes << std::endl;
2879 // Loop from 1 to NB_NODES
2881 while ( nodeIt->more() )
2883 node = nodeIt->next();
2884 if ( isQuadMesh && theHelper.IsMedium( node )) // Issue 0021238
2886 if ( n2nDegen.count( node ) ) // Issue 0020674
2889 theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID ));
2890 theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node ));
2895 << node->X() << space
2896 << node->Y() << space
2897 << node->Z() << space
2900 theFile << std::endl;
2904 // Iterate over the enforced nodes
2905 std::map<int,double> enfVertexIndexSizeMap;
2906 if (nbEnforcedNodes) {
2907 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator nodeIt = theEnforcedNodes.begin();
2908 for( ; nodeIt != theEnforcedNodes.end() ; ++nodeIt) {
2909 double x = nodeIt->first->X();
2910 double y = nodeIt->first->Y();
2911 double z = nodeIt->first->Z();
2912 // Test if point is inside shape to mesh
2913 gp_Pnt myPoint(x,y,z);
2914 BRepClass3d_SolidClassifier scl(shapeToMesh);
2915 scl.Perform(myPoint, 1e-7);
2916 TopAbs_State result = scl.State();
2917 if ( result != TopAbs_IN )
2919 std::vector<double> coords;
2920 coords.push_back(x);
2921 coords.push_back(y);
2922 coords.push_back(z);
2923 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end())
2926 // double size = theNodeIDToSizeMap.find(nodeIt->first->GetID())->second;
2927 // theGhs3dIdToNodeMap.insert( make_pair( nbNodes + i, (*nodeIt) ));
2928 // MESSAGE("Adding enforced node (" << x << "," << y <<"," << z << ")");
2929 // X Y Z PHY_SIZE DUMMY_INT
2935 << dummyint << space;
2936 theFile << std::endl;
2937 theEnforcedNodeIdToGhs3dIdMap.insert( make_pair( nodeIt->first->GetID(), aGhs3dID ));
2938 enfVertexIndexSizeMap[aGhs3dID] = -1;
2941 // MESSAGE("Enforced vertex (" << x << "," << y <<"," << z << ") is not inside the geometry: it was not added ");
2945 if (nbEnforcedVertices) {
2946 // Iterate over the enforced vertices
2947 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt = theEnforcedVertices.begin();
2948 for( ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
2949 double x = vertexIt->first[0];
2950 double y = vertexIt->first[1];
2951 double z = vertexIt->first[2];
2952 // Test if point is inside shape to mesh
2953 gp_Pnt myPoint(x,y,z);
2954 BRepClass3d_SolidClassifier scl(shapeToMesh);
2955 scl.Perform(myPoint, 1e-7);
2956 TopAbs_State result = scl.State();
2957 if ( result != TopAbs_IN )
2959 MESSAGE("Adding enforced vertex (" << x << "," << y <<"," << z << ") = " << vertexIt->second);
2960 // X Y Z PHY_SIZE DUMMY_INT
2965 << vertexIt->second << space
2966 << dummyint << space;
2967 theFile << std::endl;
2968 enfVertexIndexSizeMap[aGhs3dID] = vertexIt->second;
2974 std::cout << std::endl;
2975 std::cout << "End writing in 'points' file." << std::endl;
2980 //=======================================================================
2981 //function : readResultFile
2982 //purpose : readResultFile with geometry
2983 //=======================================================================
2985 static bool readResultFile(const int fileOpen,
2987 const char* fileName,
2989 GHS3DPlugin_GHS3D* theAlgo,
2990 SMESH_MesherHelper& theHelper,
2991 TopoDS_Shape tabShape[],
2994 map <int,const SMDS_MeshNode*>& theGhs3dIdToNodeMap,
2995 std::map <int,int> & theNodeId2NodeIndexMap,
2997 int nbEnforcedVertices,
2998 int nbEnforcedNodes,
2999 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
3000 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles,
3001 bool toMakeGroupsOfDomains)
3003 MESSAGE("GHS3DPlugin_GHS3D::readResultFile()");
3004 Kernel_Utils::Localizer loc;
3014 SMESHDS_Mesh* theMeshDS = theHelper.GetMeshDS();
3016 int nbElems, nbNodes, nbInputNodes;
3018 int ID, shapeID, ghs3dShapeID;
3021 nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() );
3023 int *tab, *tabID, *nodeID, *nodeAssigne;
3025 const SMDS_MeshNode **node;
3028 nodeID = new int[4];
3029 coord = new double[3];
3030 node = new const SMDS_MeshNode*[4];
3032 TopoDS_Shape aSolid;
3033 SMDS_MeshNode * aNewNode;
3034 map <int,const SMDS_MeshNode*>::iterator itOnNode;
3035 SMDS_MeshElement* aTet;
3040 // Read the file state
3041 fstat(fileOpen, &status);
3042 length = status.st_size;
3044 // Mapping the result file into memory
3046 HANDLE fd = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ,
3047 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
3048 HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY,
3049 0, (DWORD)length, NULL);
3050 ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 );
3052 ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
3056 ptr = readMapIntLine(ptr, tab);
3061 nbInputNodes = tab[2];
3063 nodeAssigne = new int[ nbNodes+1 ];
3066 aSolid = tabShape[0];
3068 // Reading the nodeId
3069 for (int i=0; i < 4*nbElems; i++)
3070 strtol(ptr, &ptr, 10);
3072 MESSAGE("nbInputNodes: "<<nbInputNodes);
3073 MESSAGE("nbEnforcedVertices: "<<nbEnforcedVertices);
3074 MESSAGE("nbEnforcedNodes: "<<nbEnforcedNodes);
3075 // Reading the nodeCoor and update the nodeMap
3076 for (int iNode=1; iNode <= nbNodes; iNode++) {
3077 if(theAlgo->computeCanceled())
3079 for (int iCoor=0; iCoor < 3; iCoor++)
3080 coord[ iCoor ] = strtod(ptr, &ptr);
3081 nodeAssigne[ iNode ] = 1;
3082 if ( iNode > (nbInputNodes-(nbEnforcedVertices+nbEnforcedNodes)) ) {
3083 // Creating SMESH nodes
3084 // - for enforced vertices
3085 // - for vertices of forced edges
3086 // - for ghs3d nodes
3087 nodeAssigne[ iNode ] = 0;
3088 aNewNode = theMeshDS->AddNode( coord[0],coord[1],coord[2] );
3089 theGhs3dIdToNodeMap.insert(theGhs3dIdToNodeMap.end(), make_pair( iNode, aNewNode ));
3093 // Reading the number of triangles which corresponds to the number of sub-domains
3094 nbTriangle = strtol(ptr, &ptr, 10);
3096 tabID = new int[nbTriangle];
3097 for (int i=0; i < nbTriangle; i++) {
3098 if(theAlgo->computeCanceled())
3101 // find the solid corresponding to GHS3D sub-domain following
3102 // the technique proposed in GHS3D manual in chapter
3103 // "B.4 Subdomain (sub-region) assignment"
3104 int nodeId1 = strtol(ptr, &ptr, 10);
3105 int nodeId2 = strtol(ptr, &ptr, 10);
3106 int nodeId3 = strtol(ptr, &ptr, 10);
3107 if ( nbTriangle > 1 ) {
3108 const SMDS_MeshNode* n1 = theGhs3dIdToNodeMap[ nodeId1 ];
3109 const SMDS_MeshNode* n2 = theGhs3dIdToNodeMap[ nodeId2 ];
3110 const SMDS_MeshNode* n3 = theGhs3dIdToNodeMap[ nodeId3 ];
3111 if (!n1 || !n2 || !n3) {
3117 // tabID[i] = findShapeID( theHelper, n1, n2, n3, toMeshHoles );
3118 tabID[i] = findShapeID( *theHelper.GetMesh(), n1, n2, n3, toMeshHoles );
3119 // -- 0020330: Pb with ghs3d as a submesh
3120 // check that found shape is to be meshed
3121 if ( tabID[i] > 0 ) {
3122 const TopoDS_Shape& foundShape = theMeshDS->IndexToShape( tabID[i] );
3123 bool isToBeMeshed = false;
3124 for ( int iS = 0; !isToBeMeshed && iS < nbShape; ++iS )
3125 isToBeMeshed = foundShape.IsSame( tabShape[ iS ]);
3126 if ( !isToBeMeshed )
3129 // END -- 0020330: Pb with ghs3d as a submesh
3131 std::cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << std::endl;
3134 catch ( Standard_Failure & ex)
3137 std::cout << i+1 << " subdomain: Exception caugt: " << ex.GetMessageString() << std::endl;
3142 std::cout << i+1 << " subdomain: unknown exception caught " << std::endl;
3150 if ( nbTriangle <= nbShape ) // no holes
3151 toMeshHoles = true; // not avoid creating tetras in holes
3153 // IMP 0022172: [CEA 790] create the groups corresponding to domains
3154 std::vector< std::vector< const SMDS_MeshElement* > > elemsOfDomain( Max( nbTriangle, nbShape ));
3156 // Associating the tetrahedrons to the shapes
3157 shapeID = compoundID;
3158 for (int iElem = 0; iElem < nbElems; iElem++) {
3159 if(theAlgo->computeCanceled())
3161 for (int iNode = 0; iNode < 4; iNode++) {
3162 ID = strtol(tetraPtr, &tetraPtr, 10);
3163 itOnNode = theGhs3dIdToNodeMap.find(ID);
3164 node[ iNode ] = itOnNode->second;
3165 nodeID[ iNode ] = ID;
3167 // We always run GHS3D with "to mesh holes"==TRUE but we must not create
3168 // tetras within holes depending on hypo option,
3169 // so we first check if aTet is inside a hole and then create it
3170 //aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
3171 ghs3dShapeID = 0; // domain ID
3172 if ( nbTriangle > 1 ) {
3173 shapeID = HOLE_ID; // negative shapeID means not to create tetras if !toMeshHoles
3174 ghs3dShapeID = strtol(shapePtr, &shapePtr, 10) - IdShapeRef;
3175 if ( tabID[ ghs3dShapeID ] == 0 ) {
3177 aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape, &state);
3178 if ( toMeshHoles || state == TopAbs_IN )
3179 shapeID = theMeshDS->ShapeToIndex( aSolid );
3180 tabID[ ghs3dShapeID ] = shapeID;
3183 shapeID = tabID[ ghs3dShapeID ];
3185 else if ( nbShape > 1 ) {
3186 // Case where nbTriangle == 1 while nbShape == 2 encountered
3187 // with compound of 2 boxes and "To mesh holes"==False,
3188 // so there are no subdomains specified for each tetrahedron.
3189 // Try to guess a solid by a node already bound to shape
3191 for ( int i=0; i<4 && shapeID==0; i++ ) {
3192 if ( nodeAssigne[ nodeID[i] ] == 1 &&
3193 node[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE &&
3194 node[i]->getshapeId() > 1 )
3196 shapeID = node[i]->getshapeId();
3200 aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape);
3201 shapeID = theMeshDS->ShapeToIndex( aSolid );
3204 // set new nodes and tetrahedron onto the shape
3205 for ( int i=0; i<4; i++ ) {
3206 if ( nodeAssigne[ nodeID[i] ] == 0 ) {
3207 if ( shapeID != HOLE_ID )
3208 theMeshDS->SetNodeInVolume( node[i], shapeID );
3209 nodeAssigne[ nodeID[i] ] = shapeID;
3212 if ( toMeshHoles || shapeID != HOLE_ID ) {
3213 aTet = theHelper.AddVolume( node[1], node[0], node[2], node[3],
3214 /*id=*/0, /*force3d=*/false);
3215 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
3216 if ( toMakeGroupsOfDomains )
3218 if ( int( elemsOfDomain.size() ) < ghs3dShapeID+1 )
3219 elemsOfDomain.resize( ghs3dShapeID+1 );
3220 elemsOfDomain[ ghs3dShapeID ].push_back( aTet );
3224 shapeIDs.insert( shapeID );
3227 if ( toMakeGroupsOfDomains )
3228 makeDomainGroups( elemsOfDomain, &theHelper );
3230 // Add enforced elements
3231 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap::const_iterator elemIt;
3232 const SMDS_MeshElement* anElem;
3233 SMDS_ElemIteratorPtr itOnEnfElem;
3234 map<int,int>::const_iterator itOnMap;
3235 shapeID = compoundID;
3237 if (theEnforcedEdges.size()) {
3238 (theEnforcedEdges.size() <= 1) ? tmpStr = " enforced edge" : " enforced edges";
3239 std::cout << "Add " << theEnforcedEdges.size() << tmpStr << std::endl;
3240 std::vector< const SMDS_MeshNode* > node( 2 );
3241 // Iterate over the enforced edges
3242 for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
3243 anElem = elemIt->first;
3244 bool addElem = true;
3245 itOnEnfElem = anElem->nodesIterator();
3246 for ( int j = 0; j < 2; ++j ) {
3247 int aNodeID = itOnEnfElem->next()->GetID();
3248 itOnMap = theNodeId2NodeIndexMap.find(aNodeID);
3249 if (itOnMap != theNodeId2NodeIndexMap.end()) {
3250 itOnNode = theGhs3dIdToNodeMap.find((*itOnMap).second);
3251 if (itOnNode != theGhs3dIdToNodeMap.end()) {
3252 node.push_back((*itOnNode).second);
3253 // shapeID =(*itOnNode).second->getshapeId();
3262 aTet = theHelper.AddEdge( node[0], node[1], 0, false);
3263 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
3268 if (theEnforcedTriangles.size()) {
3269 (theEnforcedTriangles.size() <= 1) ? tmpStr = " enforced triangle" : " enforced triangles";
3270 std::cout << "Add " << theEnforcedTriangles.size() << " enforced triangles" << std::endl;
3271 std::vector< const SMDS_MeshNode* > node( 3 );
3272 // Iterate over the enforced triangles
3273 for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
3274 anElem = elemIt->first;
3275 bool addElem = true;
3276 itOnEnfElem = anElem->nodesIterator();
3277 for ( int j = 0; j < 3; ++j ) {
3278 int aNodeID = itOnEnfElem->next()->GetID();
3279 itOnMap = theNodeId2NodeIndexMap.find(aNodeID);
3280 if (itOnMap != theNodeId2NodeIndexMap.end()) {
3281 itOnNode = theGhs3dIdToNodeMap.find((*itOnMap).second);
3282 if (itOnNode != theGhs3dIdToNodeMap.end()) {
3283 node.push_back((*itOnNode).second);
3284 // shapeID =(*itOnNode).second->getshapeId();
3293 aTet = theHelper.AddFace( node[0], node[1], node[2], 0, false);
3294 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
3299 // Remove nodes of tetras inside holes if !toMeshHoles
3300 if ( !toMeshHoles ) {
3301 itOnNode = theGhs3dIdToNodeMap.find( nbInputNodes );
3302 for ( ; itOnNode != theGhs3dIdToNodeMap.end(); ++itOnNode) {
3303 ID = itOnNode->first;
3304 if ( nodeAssigne[ ID ] == HOLE_ID )
3305 theMeshDS->RemoveFreeNode( itOnNode->second, 0 );
3311 (nbElems <= 1) ? tmpStr = " tetrahedra" : " tetrahedrons";
3312 cout << nbElems << tmpStr << " have been associated to " << nbShape;
3313 (nbShape <= 1) ? tmpStr = " shape" : " shapes";
3314 cout << tmpStr << endl;
3317 UnmapViewOfFile(mapPtr);
3318 CloseHandle(hMapObject);
3321 munmap(mapPtr, length);
3330 delete [] nodeAssigne;
3334 if ( shapeIDs.size() != nbShape ) {
3335 (shapeIDs.size() <= 1) ? tmpStr = " solid" : " solids";
3336 std::cout << "Only " << shapeIDs.size() << tmpStr << " of " << nbShape << " found" << std::endl;
3337 for (int i=0; i<nbShape; i++) {
3338 shapeID = theMeshDS->ShapeToIndex( tabShape[i] );
3339 if ( shapeIDs.find( shapeID ) == shapeIDs.end() )
3340 std::cout << " Solid #" << shapeID << " not found" << std::endl;
3349 //=============================================================================
3351 *Here we are going to use the GHS3D mesher with geometry
3353 //=============================================================================
3355 bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
3356 const TopoDS_Shape& theShape)
3359 //SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
3361 // we count the number of shapes
3362 // _nbShape = countShape( meshDS, TopAbs_SOLID ); -- 0020330: Pb with ghs3d as a submesh
3364 TopExp_Explorer expBox ( theShape, TopAbs_SOLID );
3365 // for ( ; expBox.More(); expBox.Next() )
3368 // create bounding box for every shape inside the compound
3371 // TopoDS_Shape* tabShape;
3373 // tabShape = new TopoDS_Shape[_nbShape];
3374 // tabBox = new double*[_nbShape];
3375 // for (int i=0; i<_nbShape; i++)
3376 // tabBox[i] = new double[6];
3377 // Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
3379 // for (expBox.ReInit(); expBox.More(); expBox.Next()) {
3380 // tabShape[iShape] = expBox.Current();
3381 // Bnd_Box BoundingBox;
3382 // BRepBndLib::Add(expBox.Current(), BoundingBox);
3383 // BoundingBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
3384 // tabBox[iShape][0] = Xmin; tabBox[iShape][1] = Xmax;
3385 // tabBox[iShape][2] = Ymin; tabBox[iShape][3] = Ymax;
3386 // tabBox[iShape][4] = Zmin; tabBox[iShape][5] = Zmax;
3390 // a unique working file name
3391 // to avoid access to the same files by eg different users
3392 _genericName = GHS3DPlugin_Hypothesis::GetFileName(_hyp);
3393 TCollection_AsciiString aGenericName((char*) _genericName.c_str() );
3394 TCollection_AsciiString aGenericNameRequired = aGenericName + "_required";
3396 TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log
3397 TCollection_AsciiString aResultFileName;
3399 TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName;
3401 aGMFFileName = aGenericName + ".mesh"; // GMF mesh file
3402 aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file
3403 aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file
3404 aSolFileName = aGenericNameRequired + ".sol"; // GMF solution file
3406 // aGMFFileName = aGenericName + ".meshb"; // GMF mesh file
3407 // aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file
3408 // aRequiredVerticesFileName = aGenericNameRequired + ".meshb"; // GMF required vertices mesh file
3409 // aSolFileName = aGenericNameRequired + ".solb"; // GMF solution file
3412 std::map <int,int> aNodeId2NodeIndexMap, aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap;
3413 std::map <int,const SMDS_MeshNode*> aGhs3dIdToNodeMap;
3414 std::map <int, int> nodeID2nodeIndexMap;
3415 std::map<std::vector<double>, std::string> enfVerticesWithGroup;
3416 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues coordsSizeMap = GHS3DPlugin_Hypothesis::GetEnforcedVerticesCoordsSize(_hyp);
3417 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = GHS3DPlugin_Hypothesis::GetEnforcedNodes(_hyp);
3418 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp);
3419 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp);
3420 // TIDSortedElemSet enforcedQuadrangles = GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp);
3421 GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp);
3423 int nbEnforcedVertices = coordsSizeMap.size();
3424 int nbEnforcedNodes = enforcedNodes.size();
3427 (nbEnforcedNodes <= 1) ? tmpStr = "node" : "nodes";
3428 std::cout << nbEnforcedNodes << " enforced " << tmpStr << " from hypo" << std::endl;
3429 (nbEnforcedVertices <= 1) ? tmpStr = "vertex" : "vertices";
3430 std::cout << nbEnforcedVertices << " enforced " << tmpStr << " from hypo" << std::endl;
3432 SMESH_MesherHelper helper( theMesh );
3433 helper.SetSubShape( theShape );
3435 std::vector <const SMDS_MeshNode*> aNodeByGhs3dId, anEnforcedNodeByGhs3dId;
3436 std::vector <const SMDS_MeshElement*> aFaceByGhs3dId;
3437 std::map<const SMDS_MeshNode*,int> aNodeToGhs3dIdMap;
3438 std::vector<std::string> aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId;
3440 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
3442 // make prisms on quadrangles
3443 if ( theMesh.NbQuadrangles() > 0 )
3445 vector<SMESH_ProxyMesh::Ptr> components;
3446 for (expBox.ReInit(); expBox.More(); expBox.Next())
3448 if ( _viscousLayersHyp )
3450 proxyMesh = _viscousLayersHyp->Compute( theMesh, expBox.Current() );
3454 StdMeshers_QuadToTriaAdaptor* q2t = new StdMeshers_QuadToTriaAdaptor;
3455 q2t->Compute( theMesh, expBox.Current(), proxyMesh.get() );
3456 components.push_back( SMESH_ProxyMesh::Ptr( q2t ));
3458 proxyMesh.reset( new SMESH_ProxyMesh( components ));
3460 // build viscous layers
3461 else if ( _viscousLayersHyp )
3463 proxyMesh = _viscousLayersHyp->Compute( theMesh, theShape );
3468 // Ok = (writePoints( aPointsFile, helper,
3469 // aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap, aGhs3dIdToNodeMap,
3471 // coordsSizeMap, enforcedNodes, enforcedEdges, enforcedTriangles)
3473 // writeFaces ( aFacesFile, *proxyMesh, theShape,
3474 // aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap,
3475 // enforcedEdges, enforcedTriangles ));
3476 Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(),
3478 aNodeByGhs3dId, aFaceByGhs3dId, aNodeToGhs3dIdMap,
3479 aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId,
3480 enforcedNodes, enforcedEdges, enforcedTriangles, /*enforcedQuadrangles,*/
3481 enfVerticesWithGroup, coordsSizeMap);
3484 // Write aSmdsToGhs3dIdMap to temp file
3485 TCollection_AsciiString aSmdsToGhs3dIdMapFileName;
3486 aSmdsToGhs3dIdMapFileName = aGenericName + ".ids"; // ids relation
3487 ofstream aIdsFile ( aSmdsToGhs3dIdMapFileName.ToCString() , ios::out);
3488 Ok = aIdsFile.rdbuf()->is_open();
3490 INFOS( "Can't write into " << aSmdsToGhs3dIdMapFileName);
3491 return error(SMESH_Comment("Can't write into ") << aSmdsToGhs3dIdMapFileName);
3493 INFOS( "Writing ids relation into " << aSmdsToGhs3dIdMapFileName);
3494 aIdsFile << "Smds Ghs3d" << std::endl;
3495 map <int,int>::const_iterator myit;
3496 for (myit=aSmdsToGhs3dIdMap.begin() ; myit != aSmdsToGhs3dIdMap.end() ; ++myit) {
3497 aIdsFile << myit->first << " " << myit->second << std::endl;
3503 if ( !_keepFiles ) {
3504 removeFile( aGMFFileName );
3505 removeFile( aRequiredVerticesFileName );
3506 removeFile( aSolFileName );
3507 removeFile( aSmdsToGhs3dIdMapFileName );
3509 return error(COMPERR_BAD_INPUT_MESH);
3511 removeFile( aResultFileName ); // needed for boundary recovery module usage
3513 // -----------------
3515 // -----------------
3517 TCollection_AsciiString cmd( (char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp ).c_str() );
3519 cmd += TCollection_AsciiString(" --in ") + aGenericName;
3520 if ( nbEnforcedVertices + nbEnforcedNodes)
3521 cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired;
3522 cmd += TCollection_AsciiString(" --out ") + aResultFileName;
3523 if ( !_logInStandardOutput )
3524 cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
3526 std::cout << std::endl;
3527 std::cout << "Ghs3d execution..." << std::endl;
3528 std::cout << cmd << std::endl;
3530 _compute_canceled = false;
3532 system( cmd.ToCString() ); // run
3534 std::cout << std::endl;
3535 std::cout << "End of Ghs3d execution !" << std::endl;
3541 // Mapping the result file
3544 // fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
3545 // if ( fileOpen < 0 ) {
3546 // std::cout << std::endl;
3547 // std::cout << "Can't open the " << aResultFileName.ToCString() << " GHS3D output file" << std::endl;
3548 // std::cout << "Log: " << aLogFileName << std::endl;
3552 GHS3DPlugin_Hypothesis::TSetStrings groupsToRemove = GHS3DPlugin_Hypothesis::GetGroupsToRemove(_hyp);
3554 _hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles();
3555 const bool toMakeGroupsOfDomains = GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains( _hyp );
3557 helper.IsQuadraticSubMesh( theShape );
3558 helper.SetElementsOnShape( false );
3560 // Ok = readResultFile( fileOpen,
3562 // aResultFileName.ToCString(),
3565 // /*theMesh, */helper, tabShape, tabBox, _nbShape,
3566 // aGhs3dIdToNodeMap, aNodeId2NodeIndexMap,
3568 // nbEnforcedVertices, nbEnforcedNodes,
3569 // enforcedEdges, enforcedTriangles,
3570 // toMakeGroupsOfDomains );
3572 Ok = readGMFFile(aResultFileName.ToCString(),
3574 &helper, aNodeByGhs3dId, aFaceByGhs3dId, aNodeToGhs3dIdMap,
3575 aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId,
3576 groupsToRemove, toMakeGroupsOfDomains, toMeshHoles);
3578 removeEmptyGroupsOfDomains( helper.GetMesh(), /*notEmptyAsWell =*/ !toMakeGroupsOfDomains );
3584 // ---------------------
3585 // remove working files
3586 // ---------------------
3590 if ( _removeLogOnSuccess )
3591 removeFile( aLogFileName );
3593 // if ( _hyp && _hyp->GetToMakeGroupsOfDomains() )
3594 // error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since the mesh is on shape" );
3596 else if ( OSD_File( aLogFileName ).Size() > 0 )
3598 // get problem description from the log file
3599 _Ghs2smdsConvertor conv( aGhs3dIdToNodeMap );
3600 storeErrorDescription( aLogFileName, conv );
3604 // the log file is empty
3605 removeFile( aLogFileName );
3606 INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" );
3607 error(COMPERR_ALGO_FAILED, "ghs3d: command not found" );
3610 if ( !_keepFiles ) {
3611 if (! Ok && _compute_canceled)
3612 removeFile( aLogFileName );
3613 removeFile( aGMFFileName );
3614 removeFile( aRequiredVerticesFileName );
3615 removeFile( aSolFileName );
3616 removeFile( aResultFileName );
3617 removeFile( aSmdsToGhs3dIdMapFileName );
3619 std::cout << "<" << aResultFileName.ToCString() << "> GHS3D output file ";
3621 std::cout << "not ";
3622 std::cout << "treated !" << std::endl;
3623 std::cout << std::endl;
3625 // _nbShape = 0; // re-initializing _nbShape for the next Compute() method call
3626 // delete [] tabShape;
3627 // delete [] tabBox;
3632 //=============================================================================
3634 *Here we are going to use the GHS3D mesher w/o geometry
3636 //=============================================================================
3637 bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
3638 SMESH_MesherHelper* theHelper)
3640 MESSAGE("GHS3DPlugin_GHS3D::Compute()");
3642 //SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
3643 TopoDS_Shape theShape = theHelper->GetSubShape();
3645 // a unique working file name
3646 // to avoid access to the same files by eg different users
3647 _genericName = GHS3DPlugin_Hypothesis::GetFileName(_hyp);
3648 TCollection_AsciiString aGenericName((char*) _genericName.c_str() );
3649 TCollection_AsciiString aGenericNameRequired = aGenericName + "_required";
3651 TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log
3652 TCollection_AsciiString aResultFileName;
3655 TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName;
3657 aGMFFileName = aGenericName + ".mesh"; // GMF mesh file
3658 aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file
3659 aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file
3660 aSolFileName = aGenericNameRequired + ".sol"; // GMF solution file
3662 // aGMFFileName = aGenericName + ".meshb"; // GMF mesh file
3663 // aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file
3664 // aRequiredVerticesFileName = aGenericNameRequired + ".meshb"; // GMF required vertices mesh file
3665 // aSolFileName = aGenericNameRequired + ".solb"; // GMF solution file
3668 std::map <int, int> nodeID2nodeIndexMap;
3669 std::map<std::vector<double>, std::string> enfVerticesWithGroup;
3670 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues coordsSizeMap;
3671 TopoDS_Shape GeomShape;
3672 // TopAbs_ShapeEnum GeomType;
3673 std::vector<double> coords;
3675 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* enfVertex;
3677 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList enfVertices = GHS3DPlugin_Hypothesis::GetEnforcedVertices(_hyp);
3678 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList::const_iterator enfVerIt = enfVertices.begin();
3680 for ( ; enfVerIt != enfVertices.end() ; ++enfVerIt)
3682 enfVertex = (*enfVerIt);
3683 // if (enfVertex->geomEntry.empty() && enfVertex->coords.size()) {
3684 if (enfVertex->coords.size()) {
3685 coordsSizeMap.insert(make_pair(enfVertex->coords,enfVertex->size));
3686 enfVerticesWithGroup.insert(make_pair(enfVertex->coords,enfVertex->groupName));
3687 // MESSAGE("enfVerticesWithGroup.insert(make_pair(("<<enfVertex->coords[0]<<","<<enfVertex->coords[1]<<","<<enfVertex->coords[2]<<"),\""<<enfVertex->groupName<<"\"))");
3690 // if (!enfVertex->geomEntry.empty()) {
3691 GeomShape = entryToShape(enfVertex->geomEntry);
3692 // GeomType = GeomShape.ShapeType();
3694 // if (!enfVertex->isCompound) {
3695 // // if (GeomType == TopAbs_VERTEX) {
3697 // aPnt = BRep_Tool::Pnt(TopoDS::Vertex(GeomShape));
3698 // coords.push_back(aPnt.X());
3699 // coords.push_back(aPnt.Y());
3700 // coords.push_back(aPnt.Z());
3701 // if (coordsSizeMap.find(coords) == coordsSizeMap.end()) {
3702 // coordsSizeMap.insert(make_pair(coords,enfVertex->size));
3703 // enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName));
3707 // // Group Management
3709 // if (GeomType == TopAbs_COMPOUND){
3710 for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){
3712 if (it.Value().ShapeType() == TopAbs_VERTEX){
3713 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(it.Value()));
3714 coords.push_back(aPnt.X());
3715 coords.push_back(aPnt.Y());
3716 coords.push_back(aPnt.Z());
3717 if (coordsSizeMap.find(coords) == coordsSizeMap.end()) {
3718 coordsSizeMap.insert(make_pair(coords,enfVertex->size));
3719 enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName));
3720 // MESSAGE("enfVerticesWithGroup.insert(make_pair(("<<coords[0]<<","<<coords[1]<<","<<coords[2]<<"),\""<<enfVertex->groupName<<"\"))");
3728 // const SMDS_MeshNode* enfNode;
3729 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = GHS3DPlugin_Hypothesis::GetEnforcedNodes(_hyp);
3730 // GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt = enforcedNodes.begin();
3731 // for ( ; enfNodeIt != enforcedNodes.end() ; ++enfNodeIt)
3733 // enfNode = enfNodeIt->first;
3735 // coords.push_back(enfNode->X());
3736 // coords.push_back(enfNode->Y());
3737 // coords.push_back(enfNode->Z());
3738 // if (enfVerticesWithGro
3739 // enfVerticesWithGroup.insert(make_pair(coords,enfNodeIt->second));
3743 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp);
3744 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp);
3745 // TIDSortedElemSet enforcedQuadrangles = GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp);
3746 GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp);
3750 int nbEnforcedVertices = coordsSizeMap.size();
3751 int nbEnforcedNodes = enforcedNodes.size();
3752 (nbEnforcedNodes <= 1) ? tmpStr = "node" : tmpStr = "nodes";
3753 std::cout << nbEnforcedNodes << " enforced " << tmpStr << " from hypo" << std::endl;
3754 (nbEnforcedVertices <= 1) ? tmpStr = "vertex" : tmpStr = "vertices";
3755 std::cout << nbEnforcedVertices << " enforced " << tmpStr << " from hypo" << std::endl;
3757 std::vector <const SMDS_MeshNode*> aNodeByGhs3dId, anEnforcedNodeByGhs3dId;
3758 std::vector <const SMDS_MeshElement*> aFaceByGhs3dId;
3759 std::map<const SMDS_MeshNode*,int> aNodeToGhs3dIdMap;
3760 std::vector<std::string> aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId;
3762 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
3763 if ( theMesh.NbQuadrangles() > 0 )
3765 StdMeshers_QuadToTriaAdaptor* aQuad2Trias = new StdMeshers_QuadToTriaAdaptor;
3766 aQuad2Trias->Compute( theMesh );
3767 proxyMesh.reset( aQuad2Trias );
3770 Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(),
3771 *proxyMesh, *theHelper,
3772 aNodeByGhs3dId, aFaceByGhs3dId, aNodeToGhs3dIdMap,
3773 aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId,
3774 enforcedNodes, enforcedEdges, enforcedTriangles,
3775 enfVerticesWithGroup, coordsSizeMap);
3778 // -----------------
3780 // -----------------
3782 TCollection_AsciiString cmd = TCollection_AsciiString((char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp, false ).c_str());
3784 cmd += TCollection_AsciiString(" --in ") + aGMFFileName;
3785 if ( nbEnforcedVertices + nbEnforcedNodes)
3786 cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired;
3787 cmd += TCollection_AsciiString(" --out ") + aResultFileName;
3788 if ( !_logInStandardOutput )
3789 cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
3791 std::cout << std::endl;
3792 std::cout << "Ghs3d execution..." << std::endl;
3793 std::cout << cmd << std::endl;
3795 _compute_canceled = false;
3797 system( cmd.ToCString() ); // run
3799 std::cout << std::endl;
3800 std::cout << "End of Ghs3d execution !" << std::endl;
3805 GHS3DPlugin_Hypothesis::TSetStrings groupsToRemove = GHS3DPlugin_Hypothesis::GetGroupsToRemove(_hyp);
3806 const bool toMakeGroupsOfDomains = GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains( _hyp );
3808 Ok = readGMFFile(aResultFileName.ToCString(),
3810 theHelper, aNodeByGhs3dId, aFaceByGhs3dId, aNodeToGhs3dIdMap,
3811 aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId,
3812 groupsToRemove, toMakeGroupsOfDomains);
3814 updateMeshGroups(theHelper->GetMesh(), groupsToRemove);
3815 removeEmptyGroupsOfDomains( theHelper->GetMesh(), /*notEmptyAsWell =*/ !toMakeGroupsOfDomains );
3818 GHS3DPlugin_Hypothesis* that = (GHS3DPlugin_Hypothesis*)this->_hyp;
3820 that->ClearGroupsToRemove();
3822 // ---------------------
3823 // remove working files
3824 // ---------------------
3828 if ( _removeLogOnSuccess )
3829 removeFile( aLogFileName );
3831 //if ( !toMakeGroupsOfDomains && _hyp && _hyp->GetToMakeGroupsOfDomains() )
3832 //error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since 'toMeshHoles' is OFF." );
3834 else if ( OSD_File( aLogFileName ).Size() > 0 )
3836 // get problem description from the log file
3837 _Ghs2smdsConvertor conv( aNodeByGhs3dId );
3838 storeErrorDescription( aLogFileName, conv );
3841 // the log file is empty
3842 removeFile( aLogFileName );
3843 INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" );
3844 error(COMPERR_ALGO_FAILED, "ghs3d: command not found" );
3849 if (! Ok && _compute_canceled)
3850 removeFile( aLogFileName );
3851 removeFile( aGMFFileName );
3852 removeFile( aResultFileName );
3853 removeFile( aRequiredVerticesFileName );
3854 removeFile( aSolFileName );
3859 void GHS3DPlugin_GHS3D::CancelCompute()
3861 _compute_canceled = true;
3864 std::string cmd = "ps xo pid,args | grep " + _genericName;
3865 //cmd += " | grep -e \"^ *[0-9]\\+ \\+" + GHS3DPlugin_Hypothesis::GetExeName() + "\"";
3866 cmd += " | awk '{print $1}' | xargs kill -9 > /dev/null 2>&1";
3867 system( cmd.c_str() );
3871 //================================================================================
3873 * \brief Provide human readable text by error code reported by ghs3d
3875 //================================================================================
3877 static const char* translateError(const int errNum)
3881 return "The surface mesh includes a face of type other than edge, "
3882 "triangle or quadrilateral. This face type is not supported.";
3884 return "Not enough memory for the face table.";
3886 return "Not enough memory.";
3888 return "Not enough memory.";
3890 return "Face is ignored.";
3892 return "End of file. Some data are missing in the file.";
3894 return "Read error on the file. There are wrong data in the file.";
3896 return "the metric file is inadequate (dimension other than 3).";
3898 return "the metric file is inadequate (values not per vertices).";
3900 return "the metric file contains more than one field.";
3902 return "the number of values in the \".bb\" (metric file) is incompatible with the expected"
3903 "value of number of mesh vertices in the \".noboite\" file.";
3905 return "Too many sub-domains.";
3907 return "the number of vertices is negative or null.";
3909 return "the number of faces is negative or null.";
3911 return "A face has a null vertex.";
3913 return "incompatible data.";
3915 return "the number of vertices is negative or null.";
3917 return "the number of vertices is negative or null (in the \".mesh\" file).";
3919 return "the number of faces is negative or null.";
3921 return "A face appears more than once in the input surface mesh.";
3923 return "An edge appears more than once in the input surface mesh.";
3925 return "A face has a vertex negative or null.";
3927 return "NOT ENOUGH MEMORY.";
3929 return "Not enough available memory.";
3931 return "Some initial points cannot be inserted. The surface mesh is probably very bad "
3932 "in terms of quality or the input list of points is wrong.";
3934 return "Some vertices are too close to one another or coincident.";
3936 return "Some vertices are too close to one another or coincident.";
3938 return "A vertex cannot be inserted.";
3940 return "There are at least two points considered as coincident.";
3942 return "Some vertices are too close to one another or coincident.";
3944 return "The surface mesh regeneration step has failed.";
3946 return "Constrained edge cannot be enforced.";
3948 return "Constrained face cannot be enforced.";
3950 return "Missing faces.";
3952 return "No guess to start the definition of the connected component(s).";
3954 return "The surface mesh includes at least one hole. The domain is not well defined.";
3956 return "Impossible to define a component.";
3958 return "The surface edge intersects another surface edge.";
3960 return "The surface edge intersects the surface face.";
3962 return "One boundary point lies within a surface face.";
3964 return "One surface edge intersects a surface face.";
3966 return "One boundary point lies within a surface edge.";
3968 return "Insufficient memory ressources detected due to a bad quality surface mesh leading "
3969 "to too many swaps.";
3971 return "Edge is unique (i.e., bounds a hole in the surface).";
3973 return "Presumably, the surface mesh is not compatible with the domain being processed.";
3975 return "Too many components, too many sub-domain.";
3977 return "The surface mesh includes at least one hole. "
3978 "Therefore there is no domain properly defined.";
3980 return "Statistics.";
3982 return "Statistics.";
3984 return "Warning, it is dramatically tedious to enforce the boundary items.";
3986 return "Not enough memory at this time, nevertheless, the program continues. "
3987 "The expected mesh will be correct but not really as large as required.";
3989 return "see above error code, resulting quality may be poor.";
3991 return "Not enough memory at this time, nevertheless, the program continues (warning).";
3993 return "Unknown face type.";
3996 return "End of file. Some data are missing in the file.";
3998 return "A too small volume element is detected.";
4000 return "There exists at least a null or negative volume element.";
4002 return "There exist null or negative volume elements.";
4004 return "A too small volume element is detected. A face is considered being degenerated.";
4006 return "Some element is suspected to be very bad shaped or wrong.";
4008 return "A too bad quality face is detected. This face is considered degenerated.";
4010 return "A too bad quality face is detected. This face is degenerated.";
4012 return "Presumably, the surface mesh is not compatible with the domain being processed.";
4014 return "Abnormal error occured, contact hotline.";
4016 return "Not enough memory for the face table.";
4018 return "The algorithm cannot run further. "
4019 "The surface mesh is probably very bad in terms of quality.";
4021 return "Bad vertex number.";
4023 return "Cannot close mesh file NomFil.";
4025 return "There are wrong data.";
4027 return "The number of faces is negative or null.";
4029 return "The number of vertices is negative or null in the '.sol' file.";
4031 return "The number of tetrahedra is negative or null.";
4033 return "The number of vertices is negative or null.";
4035 return "A face has a vertex negative or null.";
4037 return "The field is not a size in file NomFil.";
4039 return "A count is wrong in the enclosing box in the .boite.mesh input "
4040 "file (option '--read_boite').";
4042 return "A tetrahedron has a vertex with a negative number.";
4044 return "the 'MeshVersionFormatted' is not 1 or 2 in the '.mesh' file or the '.sol'.";
4046 return "The number of values in the '.sol' (metric file) is incompatible with "
4047 "the expected value of number of mesh vertices in the '.mesh' file.";
4049 return "Not enough memory.";
4051 return "Not enough memory for the face table.";
4053 return "Insufficient memory ressources detected due to a bad quality "
4054 "surface mesh leading to too many swaps.";
4056 return "The surface coordinates of a vertex are differing from the "
4057 "volume coordinates, probably due to a precision problem.";
4059 return "Invalid dimension. Dimension 3 expected.";
4061 return "A point has a tag 0. This point is probably outside the domain which has been meshed.";
4063 return "The vertices of an element are too close to one another or coincident.";
4065 return "There are at least two points whose distance is very small, and considered as coincident.";
4067 return "Two vertices are too close to one another or coincident.";
4069 return "A vertex cannot be inserted.";
4071 return "Two vertices are too close to one another or coincident. Note : When "
4072 "this error occurs during the overconstrained processing phase, this is only "
4073 "a warning which means that it is difficult to break some overconstrained facets.";
4075 return "Two surface edges are intersecting.";
4077 return "A surface edge intersects a surface face.";
4079 return "A boundary point lies within a surface face.";
4081 return "A boundary point lies within a surface edge.";
4083 return "A surface mesh appears more than once in the input surface mesh.";
4085 return "An edge appears more than once in the input surface mesh.";
4087 return "Surface with unvalid triangles.";
4089 return "The metric in the '.sol' file contains more than one field.";
4091 return "The surface mesh includes at least one hole. The domain is not well defined.";
4093 return "Presumably, the surface mesh is not compatible with the domain being processed (warning).";
4095 return "Probable faces overlapping somewher.";
4097 return "The quadratic version does not work with prescribed free edges.";
4099 return "The quadratic version does not work with a volume mesh.";
4101 return "The metric in the '.sol' file is inadequate (values not per vertices).";
4103 return "The number of vertices in the '.sol' is different from the one in the "
4104 "'.mesh' file for the required vertices (option '--required_vertices').";
4106 return "More than one type in file NomFil. The type must be equal to 1 in the '.sol'"
4107 "for the required vertices (option '--required_vertices').";
4109 return "Bad vertex number.";
4111 return "No guess to start the definition of the connected component(s).";
4113 return "Some initial points cannot be inserted.";
4115 return "A too bad quality face is detected. This face is considered degenerated.";
4117 return "A too bad quality face is detected. This face is degenerated.";
4119 return "The algorithm cannot run further.";
4121 return "A too small volume element is detected.";
4123 return "A tetrahedra is suspected to be very bad shaped or wrong.";
4125 return "There is at least a null or negative volume element. The resulting mesh"
4126 "may be inappropriate.";
4128 return "There are some null or negative volume element. The resulting mesh may"
4129 "be inappropriate.";
4131 return "An edge is unique (i.e., bounds a hole in the surface).";
4133 return "Abnormal or internal error.";
4135 return "Too many components with respect to too many sub-domain.";
4137 return "An internal error has been encountered or a signal has been received. "
4138 "Current mesh will not be saved.";
4140 return "Impossible to define a component.";
4142 return "There are some overconstrained edges.";
4144 return "There are some overconstrained facets.";
4146 return "Give the number of missing faces (information given when regeneration phase failed).";
4148 return "A constrained face cannot be enforced (information given when regeneration phase failed).";
4150 return "A constrained edge cannot be enforced.";
4152 return "It is dramatically tedious to enforce the boundary items.";
4154 return "The surface mesh regeneration step has failed. A .boite.mesh and .boite.map files are created.";
4156 return "Invalid resulting mesh.";
4158 return "P2 correction not successful.";
4160 return "Program has received an interruption or a termination signal sent by the "
4161 "user or the system administrator. Current mesh will not be saved.";
4166 //================================================================================
4168 * \brief Retrieve from a string given number of integers
4170 //================================================================================
4172 static char* getIds( char* ptr, int nbIds, vector<int>& ids )
4175 ids.reserve( nbIds );
4178 while ( !isdigit( *ptr )) ++ptr;
4179 if ( ptr[-1] == '-' ) --ptr;
4180 ids.push_back( strtol( ptr, &ptr, 10 ));
4186 //================================================================================
4188 * \brief Retrieve problem description form a log file
4189 * \retval bool - always false
4191 //================================================================================
4193 bool GHS3DPlugin_GHS3D::storeErrorDescription(const TCollection_AsciiString& logFile,
4194 const _Ghs2smdsConvertor & toSmdsConvertor )
4196 if(_compute_canceled)
4197 return error(SMESH_Comment("interruption initiated by user"));
4200 int file = ::_open (logFile.ToCString(), _O_RDONLY|_O_BINARY);
4202 int file = ::open (logFile.ToCString(), O_RDONLY);
4205 return error( SMESH_Comment("See ") << logFile << " for problem description");
4208 off_t length = lseek( file, 0, SEEK_END);
4209 lseek( file, 0, SEEK_SET);
4212 vector< char > buf( length );
4213 int nBytesRead = ::read (file, & buf[0], length);
4215 char* ptr = & buf[0];
4216 char* bufEnd = ptr + nBytesRead;
4218 SMESH_Comment errDescription;
4220 enum { NODE = 1, EDGE, TRIA, VOL, SKIP_ID = 1 };
4222 // look for MeshGems version
4223 // Since "MG-TETRA -- MeshGems 1.1-3 (January, 2013)" error codes change.
4224 // To discriminate old codes from new ones we add 1000000 to the new codes.
4225 // This way value of the new codes is same as absolute value of codes printed
4226 // in the log after "MGMESSAGE" string.
4227 int versionAddition = 0;
4230 while ( ++verPtr < bufEnd )
4232 if ( strncmp( verPtr, "MG-TETRA -- MeshGems ", 21 ) != 0 )
4234 if ( strcmp( verPtr, "MG-TETRA -- MeshGems 1.1-3 " ) >= 0 )
4235 versionAddition = 1000000;
4241 // look for errors "ERR #"
4243 set<string> foundErrorStr; // to avoid reporting same error several times
4244 set<int> elemErrorNums; // not to report different types of errors with bad elements
4245 while ( ++ptr < bufEnd )
4247 if ( strncmp( ptr, "ERR ", 4 ) != 0 )
4250 list<const SMDS_MeshElement*> badElems;
4251 vector<int> nodeIds;
4255 int errNum = strtol(ptr, &ptr, 10) + versionAddition;
4256 // we treat errors enumerated in [SALOME platform 0019316] issue
4257 // and all errors from a new (Release 1.1) MeshGems User Manual
4259 case 0015: // The face number (numfac) with vertices (f 1, f 2, f 3) has a null vertex.
4260 case 1005620 : // a too bad quality face is detected. This face is considered degenerated.
4261 ptr = getIds(ptr, SKIP_ID, nodeIds);
4262 ptr = getIds(ptr, TRIA, nodeIds);
4263 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4265 case 1005621 : // a too bad quality face is detected. This face is degenerated.
4266 // hence the is degenerated it is invisible, add its edges in addition
4267 ptr = getIds(ptr, SKIP_ID, nodeIds);
4268 ptr = getIds(ptr, TRIA, nodeIds);
4269 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4271 vector<int> edgeNodes( nodeIds.begin(), --nodeIds.end() ); // 01
4272 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4273 edgeNodes[1] = nodeIds[2]; // 02
4274 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4275 edgeNodes[0] = nodeIds[1]; // 12
4278 case 1000: // Face (f 1, f 2, f 3) appears more than once in the input surface mesh.
4280 case 1002: // Face (f 1, f 2, f 3) has a vertex negative or null
4281 case 3019: // Constrained face (f 1, f 2, f 3) cannot be enforced
4282 case 1002211: // a face has a vertex negative or null.
4283 case 1005200 : // a surface mesh appears more than once in the input surface mesh.
4284 case 1008423 : // a constrained face cannot be enforced (regeneration phase failed).
4285 ptr = getIds(ptr, TRIA, nodeIds);
4286 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4288 case 1001: // Edge (e1, e2) appears more than once in the input surface mesh
4289 case 3009: // Constrained edge (e1, e2) cannot be enforced (warning).
4290 // ERR 3109 : EDGE 5 6 UNIQUE
4291 case 3109: // Edge (e1, e2) is unique (i.e., bounds a hole in the surface)
4292 case 1005210 : // an edge appears more than once in the input surface mesh.
4293 case 1005820 : // an edge is unique (i.e., bounds a hole in the surface).
4294 case 1008441 : // a constrained edge cannot be enforced.
4295 ptr = getIds(ptr, EDGE, nodeIds);
4296 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4298 case 2004: // Vertex v1 and vertex v2 are too close to one another or coincident (warning).
4299 case 2014: // at least two points whose distance is dist, i.e., considered as coincident
4300 case 2103: // Vertex v1 and vertex v2 are too close to one another or coincident (warning).
4301 // ERR 2103 : 16 WITH 3
4302 case 1005105 : // two vertices are too close to one another or coincident.
4303 case 1005107: // Two vertices are too close to one another or coincident.
4304 ptr = getIds(ptr, NODE, nodeIds);
4305 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4306 ptr = getIds(ptr, NODE, nodeIds);
4307 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4309 case 2012: // Vertex v1 cannot be inserted (warning).
4310 case 1005106 : // a vertex cannot be inserted.
4311 ptr = getIds(ptr, NODE, nodeIds);
4312 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4314 case 3103: // The surface edge (e1, e2) intersects another surface edge (e3, e4)
4315 case 1005110 : // two surface edges are intersecting.
4316 // ERR 3103 : 1 2 WITH 7 3
4317 ptr = getIds(ptr, EDGE, nodeIds);
4318 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4319 ptr = getIds(ptr, EDGE, nodeIds);
4320 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4322 case 3104: // The surface edge (e1, e2) intersects the surface face (f 1, f 2, f 3)
4323 // ERR 3104 : 9 10 WITH 1 2 3
4324 case 3106: // One surface edge (say e1, e2) intersects a surface face (f 1, f 2, f 3)
4325 case 1005120 : // a surface edge intersects a surface face.
4326 ptr = getIds(ptr, EDGE, nodeIds);
4327 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4328 ptr = getIds(ptr, TRIA, nodeIds);
4329 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4331 case 3105: // One boundary point (say p1) lies within a surface face (f 1, f 2, f 3)
4332 // ERR 3105 : 8 IN 2 3 5
4333 case 1005150 : // a boundary point lies within a surface face.
4334 ptr = getIds(ptr, NODE, nodeIds);
4335 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4336 ptr = getIds(ptr, TRIA, nodeIds);
4337 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4339 case 3107: // One boundary point (say p1) lies within a surface edge (e1, e2) (stop).
4340 // ERR 3107 : 2 IN 4 1
4341 case 1005160 : // a boundary point lies within a surface edge.
4342 ptr = getIds(ptr, NODE, nodeIds);
4343 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4344 ptr = getIds(ptr, EDGE, nodeIds);
4345 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4347 case 9000: // ERR 9000
4348 // ELEMENT 261 WITH VERTICES : 7 396 -8 242
4349 // VOLUME : -1.11325045E+11 W.R.T. EPSILON 0.
4350 // A too small volume element is detected. Are reported the index of the element,
4351 // its four vertex indices, its volume and the tolerance threshold value
4352 ptr = getIds(ptr, SKIP_ID, nodeIds);
4353 ptr = getIds(ptr, VOL, nodeIds);
4354 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4355 // even if all nodes found, volume it most probably invisible,
4356 // add its faces to demonstrate it anyhow
4358 vector<int> faceNodes( nodeIds.begin(), --nodeIds.end() ); // 012
4359 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4360 faceNodes[2] = nodeIds[3]; // 013
4361 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4362 faceNodes[1] = nodeIds[2]; // 023
4363 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4364 faceNodes[0] = nodeIds[1]; // 123
4365 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4368 case 9001: // ERR 9001
4369 // %% NUMBER OF NEGATIVE VOLUME TETS : 1
4370 // %% THE LARGEST NEGATIVE TET : 1.75376581E+11
4371 // %% NUMBER OF NULL VOLUME TETS : 0
4372 // There exists at least a null or negative volume element
4375 // There exist n null or negative volume elements
4378 // A too small volume element is detected
4381 // A too bad quality face is detected. This face is considered degenerated,
4382 // its index, its three vertex indices together with its quality value are reported
4383 break; // same as next
4384 case 9112: // ERR 9112
4385 // FACE 2 WITH VERTICES : 4 2 5
4386 // SMALL INRADIUS : 0.
4387 // A too bad quality face is detected. This face is degenerated,
4388 // its index, its three vertex indices together with its inradius are reported
4389 ptr = getIds(ptr, SKIP_ID, nodeIds);
4390 ptr = getIds(ptr, TRIA, nodeIds);
4391 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4392 // add triangle edges as it most probably has zero area and hence invisible
4394 vector<int> edgeNodes(2);
4395 edgeNodes[0] = nodeIds[0]; edgeNodes[1] = nodeIds[1]; // 0-1
4396 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4397 edgeNodes[1] = nodeIds[2]; // 0-2
4398 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4399 edgeNodes[0] = nodeIds[1]; // 1-2
4400 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4403 case 1005103 : // the vertices of an element are too close to one another or coincident.
4404 ptr = getIds(ptr, TRIA, nodeIds);
4405 if ( nodeIds.back() == 0 ) // index of the third vertex of the element (0 for an edge)
4406 nodeIds.resize( EDGE );
4407 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4411 bool isNewError = foundErrorStr.insert( string( errBeg, ptr )).second;
4413 continue; // not to report same error several times
4415 // const SMDS_MeshElement* nullElem = 0;
4416 // bool allElemsOk = ( find( badElems.begin(), badElems.end(), nullElem) == badElems.end());
4418 // if ( allElemsOk && !badElems.empty() && !elemErrorNums.empty() ) {
4419 // bool oneMoreErrorType = elemErrorNums.insert( errNum ).second;
4420 // if ( oneMoreErrorType )
4421 // continue; // not to report different types of errors with bad elements
4424 // store bad elements
4425 //if ( allElemsOk ) {
4426 list<const SMDS_MeshElement*>::iterator elem = badElems.begin();
4427 for ( ; elem != badElems.end(); ++elem )
4428 addBadInputElement( *elem );
4432 string text = translateError( errNum );
4433 if ( errDescription.find( text ) == text.npos ) {
4434 if ( !errDescription.empty() )
4435 errDescription << "\n";
4436 errDescription << text;
4441 if ( errDescription.empty() ) { // no errors found
4442 char msgLic1[] = "connection to server failed";
4443 char msgLic2[] = " Dlim ";
4444 if ( search( &buf[0], bufEnd, msgLic1, msgLic1 + strlen(msgLic1)) != bufEnd ||
4445 search( &buf[0], bufEnd, msgLic2, msgLic2 + strlen(msgLic2)) != bufEnd )
4446 errDescription << "Licence problems.";
4449 char msg2[] = "SEGMENTATION FAULT";
4450 if ( search( &buf[0], bufEnd, msg2, msg2 + strlen(msg2)) != bufEnd )
4451 errDescription << "ghs3d: SEGMENTATION FAULT. ";
4455 if ( errDescription.empty() )
4456 errDescription << "See " << logFile << " for problem description";
4458 errDescription << "\nSee " << logFile << " for more information";
4460 return error( errDescription );
4463 //================================================================================
4465 * \brief Creates _Ghs2smdsConvertor
4467 //================================================================================
4469 _Ghs2smdsConvertor::_Ghs2smdsConvertor( const map <int,const SMDS_MeshNode*> & ghs2NodeMap)
4470 :_ghs2NodeMap( & ghs2NodeMap ), _nodeByGhsId( 0 )
4474 //================================================================================
4476 * \brief Creates _Ghs2smdsConvertor
4478 //================================================================================
4480 _Ghs2smdsConvertor::_Ghs2smdsConvertor( const vector <const SMDS_MeshNode*> & nodeByGhsId)
4481 : _ghs2NodeMap( 0 ), _nodeByGhsId( &nodeByGhsId )
4485 //================================================================================
4487 * \brief Return SMDS element by ids of GHS3D nodes
4489 //================================================================================
4491 const SMDS_MeshElement* _Ghs2smdsConvertor::getElement(const vector<int>& ghsNodes) const
4493 size_t nbNodes = ghsNodes.size();
4494 vector<const SMDS_MeshNode*> nodes( nbNodes, 0 );
4495 for ( size_t i = 0; i < nbNodes; ++i ) {
4496 int ghsNode = ghsNodes[ i ];
4497 if ( _ghs2NodeMap ) {
4498 map <int,const SMDS_MeshNode*>::const_iterator in = _ghs2NodeMap->find( ghsNode);
4499 if ( in == _ghs2NodeMap->end() )
4501 nodes[ i ] = in->second;
4504 if ( ghsNode < 1 || ghsNode > _nodeByGhsId->size() )
4506 nodes[ i ] = (*_nodeByGhsId)[ ghsNode-1 ];
4512 if ( nbNodes == 2 ) {
4513 const SMDS_MeshElement* edge= SMDS_Mesh::FindEdge( nodes[0], nodes[1] );
4515 edge = new SMDS_LinearEdge( nodes[0], nodes[1] );
4518 if ( nbNodes == 3 ) {
4519 const SMDS_MeshElement* face = SMDS_Mesh::FindFace( nodes );
4521 face = new SMDS_FaceOfNodes( nodes[0], nodes[1], nodes[2] );
4525 return new SMDS_VolumeOfNodes( nodes[0], nodes[1], nodes[2], nodes[3] );
4531 //=============================================================================
4535 //=============================================================================
4536 bool GHS3DPlugin_GHS3D::Evaluate(SMESH_Mesh& aMesh,
4537 const TopoDS_Shape& aShape,
4538 MapShapeNbElems& aResMap)
4540 int nbtri = 0, nbqua = 0;
4541 double fullArea = 0.0;
4542 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
4543 TopoDS_Face F = TopoDS::Face( exp.Current() );
4544 SMESH_subMesh *sm = aMesh.GetSubMesh(F);
4545 MapShapeNbElemsItr anIt = aResMap.find(sm);
4546 if( anIt==aResMap.end() ) {
4547 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
4548 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,
4549 "Submesh can not be evaluated",this));
4552 std::vector<int> aVec = (*anIt).second;
4553 nbtri += Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
4554 nbqua += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
4556 BRepGProp::SurfaceProperties(F,G);
4557 double anArea = G.Mass();
4561 // collect info from edges
4562 int nb0d_e = 0, nb1d_e = 0;
4563 bool IsQuadratic = false;
4564 bool IsFirst = true;
4565 TopTools_MapOfShape tmpMap;
4566 for (TopExp_Explorer exp(aShape, TopAbs_EDGE); exp.More(); exp.Next()) {
4567 TopoDS_Edge E = TopoDS::Edge(exp.Current());
4568 if( tmpMap.Contains(E) )
4571 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
4572 MapShapeNbElemsItr anIt = aResMap.find(aSubMesh);
4573 std::vector<int> aVec = (*anIt).second;
4574 nb0d_e += aVec[SMDSEntity_Node];
4575 nb1d_e += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
4577 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
4583 double ELen = sqrt(2.* ( fullArea/(nbtri+nbqua*2) ) / sqrt(3.0) );
4586 BRepGProp::VolumeProperties(aShape,G);
4587 double aVolume = G.Mass();
4588 double tetrVol = 0.1179*ELen*ELen*ELen;
4589 double CoeffQuality = 0.9;
4590 int nbVols = int(aVolume/tetrVol/CoeffQuality);
4591 int nb1d_f = (nbtri*3 + nbqua*4 - nb1d_e) / 2;
4592 int nb1d_in = (int) ( nbVols*6 - nb1d_e - nb1d_f ) / 5;
4593 std::vector<int> aVec(SMDSEntity_Last);
4594 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i]=0;
4596 aVec[SMDSEntity_Node] = nb1d_in/6 + 1 + nb1d_in;
4597 aVec[SMDSEntity_Quad_Tetra] = nbVols - nbqua*2;
4598 aVec[SMDSEntity_Quad_Pyramid] = nbqua;
4601 aVec[SMDSEntity_Node] = nb1d_in/6 + 1;
4602 aVec[SMDSEntity_Tetra] = nbVols - nbqua*2;
4603 aVec[SMDSEntity_Pyramid] = nbqua;
4605 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
4606 aResMap.insert(std::make_pair(sm,aVec));
4611 bool GHS3DPlugin_GHS3D::importGMFMesh(const char* theGMFFileName, SMESH_Mesh& theMesh)
4613 SMESH_MesherHelper* helper = new SMESH_MesherHelper(theMesh );
4614 std::vector <const SMDS_MeshNode*> dummyNodeVector;
4615 std::vector <const SMDS_MeshElement*> aFaceByGhs3dId;
4616 std::map<const SMDS_MeshNode*,int> dummyNodeMap;
4617 std::map<std::vector<double>, std::string> dummyEnfVertGroup;
4618 std::vector<std::string> dummyElemGroup;
4619 std::set<std::string> dummyGroupsToRemove;
4621 bool ok = readGMFFile(theGMFFileName,
4623 helper, dummyNodeVector, aFaceByGhs3dId, dummyNodeMap, dummyElemGroup, dummyElemGroup, dummyElemGroup, dummyGroupsToRemove);
4624 theMesh.GetMeshDS()->Modified();
4630 //================================================================================
4632 * \brief Sub-mesh event listener setting enforced elements as soon as an enforced
4635 struct _EnforcedMeshRestorer : public SMESH_subMeshEventListener
4637 _EnforcedMeshRestorer():
4638 SMESH_subMeshEventListener( /*isDeletable = */true, Name() )
4641 //================================================================================
4643 * \brief Returns an ID of listener
4645 static const char* Name() { return "GHS3DPlugin_GHS3D::_EnforcedMeshRestorer"; }
4647 //================================================================================
4649 * \brief Treat events of the subMesh
4651 void ProcessEvent(const int event,
4652 const int eventType,
4653 SMESH_subMesh* subMesh,
4654 SMESH_subMeshEventListenerData* data,
4655 const SMESH_Hypothesis* hyp)
4657 if ( SMESH_subMesh::SUBMESH_LOADED == event &&
4658 SMESH_subMesh::COMPUTE_EVENT == eventType &&
4660 !data->mySubMeshes.empty() )
4662 // An enforced mesh (subMesh->_father) has been loaded from hdf file
4663 if ( GHS3DPlugin_Hypothesis* hyp = GetGHSHypothesis( data->mySubMeshes.front() ))
4664 hyp->RestoreEnfElemsByMeshes();
4667 //================================================================================
4669 * \brief Returns GHS3DPlugin_Hypothesis used to compute a subMesh
4671 static GHS3DPlugin_Hypothesis* GetGHSHypothesis( SMESH_subMesh* subMesh )
4673 SMESH_HypoFilter ghsHypFilter( SMESH_HypoFilter::HasName( "GHS3D_Parameters" ));
4674 return (GHS3DPlugin_Hypothesis* )
4675 subMesh->GetFather()->GetHypothesis( subMesh->GetSubShape(),
4677 /*visitAncestors=*/true);
4681 //================================================================================
4683 * \brief Sub-mesh event listener removing empty groups created due to "To make
4684 * groups of domains".
4686 struct _GroupsOfDomainsRemover : public SMESH_subMeshEventListener
4688 _GroupsOfDomainsRemover():
4689 SMESH_subMeshEventListener( /*isDeletable = */true,
4690 "GHS3DPlugin_GHS3D::_GroupsOfDomainsRemover" ) {}
4692 * \brief Treat events of the subMesh
4694 void ProcessEvent(const int event,
4695 const int eventType,
4696 SMESH_subMesh* subMesh,
4697 SMESH_subMeshEventListenerData* data,
4698 const SMESH_Hypothesis* hyp)
4700 if (SMESH_subMesh::ALGO_EVENT == eventType &&
4701 !subMesh->GetAlgo() )
4703 removeEmptyGroupsOfDomains( subMesh->GetFather(), /*notEmptyAsWell=*/true );
4709 //================================================================================
4711 * \brief Set an event listener to set enforced elements as soon as an enforced
4714 //================================================================================
4716 void GHS3DPlugin_GHS3D::SubmeshRestored(SMESH_subMesh* subMesh)
4718 if ( GHS3DPlugin_Hypothesis* hyp = _EnforcedMeshRestorer::GetGHSHypothesis( subMesh ))
4720 GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList enfMeshes = hyp->_GetEnforcedMeshes();
4721 GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList::iterator it = enfMeshes.begin();
4722 for(;it != enfMeshes.end();++it) {
4723 GHS3DPlugin_Hypothesis::TGHS3DEnforcedMesh* enfMesh = *it;
4724 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
4726 SMESH_subMesh* smToListen = mesh->GetSubMesh( mesh->GetShapeToMesh() );
4727 // a listener set to smToListen will care of hypothesis stored in SMESH_EventListenerData
4728 subMesh->SetEventListener( new _EnforcedMeshRestorer(),
4729 SMESH_subMeshEventListenerData::MakeData( subMesh ),
4736 //================================================================================
4738 * \brief Sets an event listener removing empty groups created due to "To make
4739 * groups of domains".
4740 * \param subMesh - submesh where algo is set
4742 * This method is called when a submesh gets HYP_OK algo_state.
4743 * After being set, event listener is notified on each event of a submesh.
4745 //================================================================================
4747 void GHS3DPlugin_GHS3D::SetEventListener(SMESH_subMesh* subMesh)
4749 subMesh->SetEventListener( new _GroupsOfDomainsRemover(), 0, subMesh );