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;
187 const list <const SMESHDS_Hypothesis * >& hyps =
188 GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliary=*/false);
189 list <const SMESHDS_Hypothesis* >::const_iterator h = hyps.begin();
190 for ( ; h != hyps.end(); ++h )
193 _hyp = dynamic_cast< const GHS3DPlugin_Hypothesis*> ( *h );
194 if ( !_viscousLayersHyp )
195 _viscousLayersHyp = dynamic_cast< const StdMeshers_ViscousLayers*> ( *h );
198 _keepFiles = _hyp->GetKeepFiles();
204 //=======================================================================
205 //function : entryToShape
207 //=======================================================================
209 TopoDS_Shape GHS3DPlugin_GHS3D::entryToShape(std::string entry)
211 MESSAGE("GHS3DPlugin_GHS3D::entryToShape "<<entry );
212 GEOM::GEOM_Object_var aGeomObj;
213 TopoDS_Shape S = TopoDS_Shape();
214 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
215 if (!aSObj->_is_nil() ) {
216 CORBA::Object_var obj = aSObj->GetObject();
217 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
220 if ( !aGeomObj->_is_nil() )
221 S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
225 //=======================================================================
226 //function : findShape
228 //=======================================================================
230 static TopoDS_Shape findShape(const SMDS_MeshNode *aNode[],
232 const TopoDS_Shape shape[],
235 TopAbs_State * state = 0)
238 int j, iShape, nbNode = 4;
240 for ( j=0; j<nbNode; j++ ) {
241 gp_XYZ p ( aNode[j]->X(), aNode[j]->Y(), aNode[j]->Z() );
242 if ( aNode[j]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE ) {
249 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
250 if (state) *state = SC.State();
251 if ( SC.State() != TopAbs_IN || aShape.IsNull() || aShape.ShapeType() != TopAbs_SOLID) {
252 for (iShape = 0; iShape < nShape; iShape++) {
253 aShape = shape[iShape];
254 if ( !( aPnt.X() < box[iShape][0] || box[iShape][1] < aPnt.X() ||
255 aPnt.Y() < box[iShape][2] || box[iShape][3] < aPnt.Y() ||
256 aPnt.Z() < box[iShape][4] || box[iShape][5] < aPnt.Z()) ) {
257 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
258 if (state) *state = SC.State();
259 if (SC.State() == TopAbs_IN)
267 //=======================================================================
268 //function : readMapIntLine
270 //=======================================================================
272 static char* readMapIntLine(char* ptr, int tab[]) {
274 std::cout << std::endl;
276 for ( int i=0; i<17; i++ ) {
277 intVal = strtol(ptr, &ptr, 10);
284 //================================================================================
286 * \brief returns true if a triangle defined by the nodes is a temporary face on a
287 * side facet of pyramid and defines sub-domian inside the pyramid
289 //================================================================================
291 static bool isTmpFace(const SMDS_MeshNode* node1,
292 const SMDS_MeshNode* node2,
293 const SMDS_MeshNode* node3)
295 // find a pyramid sharing the 3 nodes
296 //const SMDS_MeshElement* pyram = 0;
297 SMDS_ElemIteratorPtr vIt1 = node1->GetInverseElementIterator(SMDSAbs_Volume);
298 while ( vIt1->more() )
300 const SMDS_MeshElement* pyram = vIt1->next();
301 if ( pyram->NbCornerNodes() != 5 ) continue;
303 if ( (i2 = pyram->GetNodeIndex( node2 )) >= 0 &&
304 (i3 = pyram->GetNodeIndex( node3 )) >= 0 )
306 // Triangle defines sub-domian inside the pyramid if it's
307 // normal points out of the pyram
309 // make i2 and i3 hold indices of base nodes of the pyram while
310 // keeping the nodes order in the triangle
313 i2 = i3, i3 = pyram->GetNodeIndex( node1 );
314 else if ( i3 == iApex )
315 i3 = i2, i2 = pyram->GetNodeIndex( node1 );
317 int i3base = (i2+1) % 4; // next index after i2 within the pyramid base
318 return ( i3base != i3 );
324 //=======================================================================
325 //function : findShapeID
326 //purpose : find the solid corresponding to GHS3D sub-domain following
327 // the technique proposed in GHS3D manual (available within
328 // ghs3d installation) in chapter "B.4 Subdomain (sub-region) assignment".
329 // In brief: normal of the triangle defined by the given nodes
330 // points out of the domain it is associated to
331 //=======================================================================
333 static int findShapeID(SMESH_Mesh& mesh,
334 const SMDS_MeshNode* node1,
335 const SMDS_MeshNode* node2,
336 const SMDS_MeshNode* node3,
337 const bool toMeshHoles)
339 const int invalidID = 0;
340 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
342 // face the nodes belong to
343 const SMDS_MeshElement * face = meshDS->FindFace(node1,node2,node3);
345 return isTmpFace(node1, node2, node3) ? HOLE_ID : invalidID;
347 std::cout << "bnd face " << face->GetID() << " - ";
349 // geom face the face assigned to
350 SMESH_MeshEditor editor(&mesh);
351 int geomFaceID = editor.FindShape( face );
353 return isTmpFace(node1, node2, node3) ? HOLE_ID : invalidID;
354 TopoDS_Shape shape = meshDS->IndexToShape( geomFaceID );
355 if ( shape.IsNull() || shape.ShapeType() != TopAbs_FACE )
357 TopoDS_Face geomFace = TopoDS::Face( shape );
359 // solids bounded by geom face
360 TopTools_IndexedMapOfShape solids, shells;
361 TopTools_ListIteratorOfListOfShape ansIt = mesh.GetAncestors(geomFace);
362 for ( ; ansIt.More(); ansIt.Next() ) {
363 switch ( ansIt.Value().ShapeType() ) {
365 solids.Add( ansIt.Value() ); break;
367 shells.Add( ansIt.Value() ); break;
371 // analyse found solids
372 if ( solids.Extent() == 0 || shells.Extent() == 0)
375 const TopoDS_Solid& solid1 = TopoDS::Solid( solids(1) );
376 if ( solids.Extent() == 1 )
379 return meshDS->ShapeToIndex( solid1 );
381 //////////// UNCOMMENT AS SOON AS
382 //////////// http://tracker.dev.opencascade.org/view.php?id=23129
383 //////////// IS SOLVED
384 // - Are we at a hole boundary face?
385 // if ( shells(1).IsSame( BRepTools::OuterShell( solid1 )) )
386 // { // - No, but maybe a hole is bound by two shapes? Does shells(1) touches another shell?
387 // bool touch = false;
388 // TopExp_Explorer eExp( shells(1), TopAbs_EDGE );
389 // // check if any edge of shells(1) belongs to another shell
390 // for ( ; eExp.More() && !touch; eExp.Next() ) {
391 // ansIt = mesh.GetAncestors( eExp.Current() );
392 // for ( ; ansIt.More() && !touch; ansIt.Next() ) {
393 // if ( ansIt.Value().ShapeType() == TopAbs_SHELL )
394 // touch = ( !ansIt.Value().IsSame( shells(1) ));
398 // return meshDS->ShapeToIndex( solid1 );
401 // find orientation of geom face within the first solid
402 TopExp_Explorer fExp( solid1, TopAbs_FACE );
403 for ( ; fExp.More(); fExp.Next() )
404 if ( geomFace.IsSame( fExp.Current() )) {
405 geomFace = TopoDS::Face( fExp.Current() );
409 return invalidID; // face not found
411 // normale to triangle
412 gp_Pnt node1Pnt ( node1->X(), node1->Y(), node1->Z() );
413 gp_Pnt node2Pnt ( node2->X(), node2->Y(), node2->Z() );
414 gp_Pnt node3Pnt ( node3->X(), node3->Y(), node3->Z() );
415 gp_Vec vec12( node1Pnt, node2Pnt );
416 gp_Vec vec13( node1Pnt, node3Pnt );
417 gp_Vec meshNormal = vec12 ^ vec13;
418 if ( meshNormal.SquareMagnitude() < DBL_MIN )
421 // get normale to geomFace at any node
422 bool geomNormalOK = false;
424 const SMDS_MeshNode* nodes[3] = { node1, node2, node3 };
425 SMESH_MesherHelper helper( mesh ); helper.SetSubShape( geomFace );
426 for ( int i = 0; !geomNormalOK && i < 3; ++i )
428 // find UV of i-th node on geomFace
429 const SMDS_MeshNode* nNotOnSeamEdge = 0;
430 if ( helper.IsSeamShape( nodes[i]->getshapeId() )) {
431 if ( helper.IsSeamShape( nodes[(i+1)%3]->getshapeId() ))
432 nNotOnSeamEdge = nodes[(i+2)%3];
434 nNotOnSeamEdge = nodes[(i+1)%3];
437 gp_XY uv = helper.GetNodeUV( geomFace, nodes[i], nNotOnSeamEdge, &uvOK );
438 // check that uv is correct
441 TopoDS_Shape nodeShape = helper.GetSubShapeByNode( nodes[i], meshDS );
442 if ( !nodeShape.IsNull() )
443 switch ( nodeShape.ShapeType() )
445 case TopAbs_FACE: tol = BRep_Tool::Tolerance( TopoDS::Face( nodeShape )); break;
446 case TopAbs_EDGE: tol = BRep_Tool::Tolerance( TopoDS::Edge( nodeShape )); break;
447 case TopAbs_VERTEX: tol = BRep_Tool::Tolerance( TopoDS::Vertex( nodeShape )); break;
450 gp_Pnt nodePnt ( nodes[i]->X(), nodes[i]->Y(), nodes[i]->Z() );
451 BRepAdaptor_Surface surface( geomFace );
452 uvOK = ( nodePnt.Distance( surface.Value( uv.X(), uv.Y() )) < 2 * tol );
454 // normale to geomFace at UV
456 surface.D1( uv.X(), uv.Y(), nodePnt, du, dv );
457 geomNormal = du ^ dv;
458 if ( geomFace.Orientation() == TopAbs_REVERSED )
459 geomNormal.Reverse();
460 geomNormalOK = ( geomNormal.SquareMagnitude() > DBL_MIN * 1e3 );
468 bool isReverse = ( meshNormal * geomNormal ) < 0;
470 return meshDS->ShapeToIndex( solid1 );
472 if ( solids.Extent() == 1 )
473 return HOLE_ID; // we are inside a hole
475 return meshDS->ShapeToIndex( solids(2) );
478 // //=======================================================================
479 // //function : countShape
481 // //=======================================================================
483 // template < class Mesh, class Shape >
484 // static int countShape( Mesh* mesh, Shape shape ) {
485 // TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
486 // TopTools_MapOfShape mapShape;
488 // for ( ; expShape.More(); expShape.Next() ) {
489 // if (mapShape.Add(expShape.Current())) {
496 // //=======================================================================
497 // //function : getShape
499 // //=======================================================================
501 // template < class Mesh, class Shape, class Tab >
502 // void getShape(Mesh* mesh, Shape shape, Tab *t_Shape) {
503 // TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
504 // TopTools_MapOfShape mapShape;
505 // for ( int i=0; expShape.More(); expShape.Next() ) {
506 // if (mapShape.Add(expShape.Current())) {
507 // t_Shape[i] = expShape.Current();
514 // // //=======================================================================
515 // // //function : findEdgeID
517 // // //=======================================================================
519 // static int findEdgeID(const SMDS_MeshNode* aNode,
520 // const SMESHDS_Mesh* theMesh,
522 // const TopoDS_Shape* t_Edge) {
524 // TopoDS_Shape aPntShape, foundEdge;
525 // TopoDS_Vertex aVertex;
526 // gp_Pnt aPnt( aNode->X(), aNode->Y(), aNode->Z() );
528 // int foundInd, ind;
529 // double nearest = RealLast(), *t_Dist;
530 // double epsilon = Precision::Confusion();
532 // t_Dist = new double[ nEdge ];
533 // aPntShape = BRepBuilderAPI_MakeVertex( aPnt ).Shape();
534 // aVertex = TopoDS::Vertex( aPntShape );
536 // for ( ind=0; ind < nEdge; ind++ ) {
537 // BRepExtrema_DistShapeShape aDistance ( aVertex, t_Edge[ind] );
538 // t_Dist[ind] = aDistance.Value();
539 // if ( t_Dist[ind] < nearest ) {
540 // nearest = t_Dist[ind];
541 // foundEdge = t_Edge[ind];
543 // if ( nearest < epsilon )
549 // return theMesh->ShapeToIndex( foundEdge );
553 // // =======================================================================
554 // // function : readGMFFile
555 // // purpose : read GMF file with geometry associated to mesh
556 // // =======================================================================
558 // static bool readGMFFile(const int fileOpen,
559 // const char* theFileName,
560 // SMESH_Mesh& theMesh,
561 // const int nbShape,
562 // const TopoDS_Shape* tabShape,
564 // map <int,const SMDS_MeshNode*>& theGhs3dIdToNodeMap,
566 // int nbEnforcedVertices,
567 // int nbEnforcedNodes)
569 // TopoDS_Shape aShape;
570 // TopoDS_Vertex aVertex;
571 // SMESHDS_Mesh* theMeshDS = theMesh.GetMeshDS();
572 // int nbElem = 0, nbRef = 0, IdShapeRef = 1;
574 // int aGMFNodeID = 0;
576 // nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() );
577 // int tetraShapeID = compoundID;
578 // double epsilon = Precision::Confusion();
579 // int *nodeAssigne, *GMFNodeAssigne;
580 // SMDS_MeshNode** GMFNode;
581 // TopoDS_Shape *tabCorner, *tabEdge;
582 // std::map <GmfKwdCod,int> tabRef;
586 // MESSAGE("Read " << theFileName << " file");
587 // int InpMsh = GmfOpenMesh(theFileName, GmfRead, &ver, &dim);
591 // // ===========================
592 // // Fill the tabID array: BEGIN
593 // // ===========================
596 // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2)
598 // Kernel_Utils::Localizer loc;
599 // struct stat status;
602 // char *ptr, *mapPtr;
604 // int *tab = new int[3];
606 // // Read the file state
607 // fstat(fileOpen, &status);
608 // length = status.st_size;
610 // // Mapping the result file into memory
612 // HANDLE fd = CreateFile(theFileName, GENERIC_READ, FILE_SHARE_READ,
613 // NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
614 // HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY,
615 // 0, (DWORD)length, NULL);
616 // ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 );
618 // ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
622 // ptr = readMapIntLine(ptr, tab);
626 // int nbNodes = tab[1];
628 // for (int i=0; i < 4*nbElem; i++)
629 // strtol(ptr, &ptr, 10);
631 // for (int iNode=1; iNode <= nbNodes; iNode++)
632 // for (int iCoor=0; iCoor < 3; iCoor++)
633 // strtod(ptr, &ptr);
636 // // Reading the number of triangles which corresponds to the number of sub-domains
637 // int nbTriangle = strtol(ptr, &ptr, 10);
640 // // The keyword does not exist yet => to update when it is created
641 // // int nbSubdomains = GmfStatKwd(InpMsh, GmfSubdomain);
645 // tabID = new int[nbTriangle];
646 // for (int i=0; i < nbTriangle; i++) {
648 // int nodeId1, nodeId2, nodeId3;
649 // // find the solid corresponding to GHS3D sub-domain following
650 // // the technique proposed in GHS3D manual in chapter
651 // // "B.4 Subdomain (sub-region) assignment"
653 // nodeId1 = strtol(ptr, &ptr, 10);
654 // nodeId2 = strtol(ptr, &ptr, 10);
655 // nodeId3 = strtol(ptr, &ptr, 10);
657 // // // The keyword does not exist yet => to update when it is created
658 // // GmfGetLin(InpMsh, GmfSubdomain, &id_tri[0], &id_tri[1], &id_tri[2]);
659 // // nodeId1 = id_tri[0];
660 // // nodeId2 = id_tri[1];
661 // // nodeId3 = id_tri[2];
663 // if ( nbTriangle > 1 ) {
664 // // get the nodes indices
665 // const SMDS_MeshNode* n1 = theGhs3dIdToNodeMap[ nodeId1 ];
666 // const SMDS_MeshNode* n2 = theGhs3dIdToNodeMap[ nodeId2 ];
667 // const SMDS_MeshNode* n3 = theGhs3dIdToNodeMap[ nodeId3 ];
669 // OCC_CATCH_SIGNALS;
670 // tabID[i] = findShapeID( theMesh, n1, n2, n3, toMeshHoles );
671 // // -- 0020330: Pb with ghs3d as a submesh
672 // // check that found shape is to be meshed
673 // if ( tabID[i] > 0 ) {
674 // const TopoDS_Shape& foundShape = theMeshDS->IndexToShape( tabID[i] );
675 // bool isToBeMeshed = false;
676 // for ( int iS = 0; !isToBeMeshed && iS < nbShape; ++iS )
677 // isToBeMeshed = foundShape.IsSame( tabShape[ iS ]);
678 // if ( !isToBeMeshed )
679 // tabID[i] = HOLE_ID;
681 // // END -- 0020330: Pb with ghs3d as a submesh
683 // std::cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << std::endl;
686 // catch ( Standard_Failure & ex)
689 // std::cout << i+1 << " subdomain: Exception caugt: " << ex.GetMessageString() << std::endl;
694 // std::cout << i+1 << " subdomain: unknown exception caught " << std::endl;
700 // // ===========================
701 // // Fill the tabID array: END
702 // // ===========================
705 // tabRef[GmfVertices] = 3;
706 // tabRef[GmfCorners] = 1;
707 // tabRef[GmfEdges] = 2;
708 // tabRef[GmfRidges] = 1;
709 // tabRef[GmfTriangles] = 3;
710 // // tabRef[GmfQuadrilaterals] = 4;
711 // tabRef[GmfTetrahedra] = 4;
712 // // tabRef[GmfHexahedra] = 8;
714 // SMDS_NodeIteratorPtr itOnGMFInputNode = theMeshDS->nodesIterator();
715 // while ( itOnGMFInputNode->more() )
716 // theMeshDS->RemoveNode( itOnGMFInputNode->next() );
719 // int nbVertices = GmfStatKwd(InpMsh, GmfVertices);
720 // int nbCorners = max(countShape( theMeshDS, TopAbs_VERTEX ) , GmfStatKwd(InpMsh, GmfCorners));
721 // int nbShapeEdge = countShape( theMeshDS, TopAbs_EDGE );
723 // tabCorner = new TopoDS_Shape[ nbCorners ];
724 // tabEdge = new TopoDS_Shape[ nbShapeEdge ];
725 // nodeAssigne = new int[ nbVertices + 1 ];
726 // GMFNodeAssigne = new int[ nbVertices + 1 ];
727 // GMFNode = new SMDS_MeshNode*[ nbVertices + 1 ];
729 // getShape(theMeshDS, TopAbs_VERTEX, tabCorner);
730 // getShape(theMeshDS, TopAbs_EDGE, tabEdge);
732 // std::map <GmfKwdCod,int>::const_iterator it = tabRef.begin();
733 // for ( ; it != tabRef.end() ; ++it)
736 // GmfKwdCod token = it->first;
737 // nbRef = it->second;
739 // nbElem = GmfStatKwd(InpMsh, token);
741 // GmfGotoKwd(InpMsh, token);
742 // std::cout << "Read " << nbElem;
747 // int id[nbElem*tabRef[token]];
748 // int ghs3dShapeID[nbElem];
750 // if (token == GmfVertices) {
751 // std::cout << " vertices" << std::endl;
754 // float VerTab_f[nbElem][3];
755 // double VerTab_d[nbElem][3];
756 // SMDS_MeshNode * aGMFNode;
758 // for ( int iElem = 0; iElem < nbElem; iElem++ ) {
759 // aGMFID = iElem + 1;
760 // if (ver == GmfFloat) {
761 // GmfGetLin(InpMsh, token, &VerTab_f[nbElem][0], &VerTab_f[nbElem][1], &VerTab_f[nbElem][2], &ghs3dShapeID[iElem]);
762 // aGMFNode = theMeshDS->AddNode(VerTab_f[nbElem][0], VerTab_f[nbElem][1], VerTab_f[nbElem][2]);
765 // GmfGetLin(InpMsh, token, &VerTab_d[nbElem][0], &VerTab_d[nbElem][1], &VerTab_d[nbElem][2], &ghs3dShapeID[iElem]);
766 // aGMFNode = theMeshDS->AddNode(VerTab_d[nbElem][0], VerTab_d[nbElem][1], VerTab_d[nbElem][2]);
768 // GMFNode[ aGMFID ] = aGMFNode;
769 // nodeAssigne[ aGMFID ] = 0;
770 // GMFNodeAssigne[ aGMFID ] = 0;
773 // else if (token == GmfCorners && nbElem > 0) {
774 // std::cout << " corners" << std::endl;
775 // for ( int iElem = 0; iElem < nbElem; iElem++ )
776 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
778 // else if (token == GmfRidges && nbElem > 0) {
779 // std::cout << " ridges" << std::endl;
780 // for ( int iElem = 0; iElem < nbElem; iElem++ )
781 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
783 // else if (token == GmfEdges && nbElem > 0) {
784 // std::cout << " edges" << std::endl;
785 // for ( int iElem = 0; iElem < nbElem; iElem++ )
786 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &ghs3dShapeID[iElem]);
788 // else if (token == GmfTriangles && nbElem > 0) {
789 // std::cout << " triangles" << std::endl;
790 // for ( int iElem = 0; iElem < nbElem; iElem++ )
791 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &ghs3dShapeID[iElem]);
793 // // else if (token == GmfQuadrilaterals && nbElem > 0) {
794 // // std::cout << " Quadrilaterals" << std::endl;
795 // // for ( int iElem = 0; iElem < nbElem; iElem++ )
796 // // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &ghs3dShapeID[iElem]);
798 // else if (token == GmfTetrahedra && nbElem > 0) {
799 // std::cout << " Tetrahedra" << std::endl;
800 // for ( int iElem = 0; iElem < nbElem; iElem++ )
801 // GmfGetLin(InpMsh, token,
802 // &id[iElem*tabRef[token]],
803 // &id[iElem*tabRef[token]+1],
804 // &id[iElem*tabRef[token]+2],
805 // &id[iElem*tabRef[token]+3],
806 // &ghs3dShapeID[iElem]);
808 // // else if (token == GmfHexahedra && nbElem > 0) {
809 // // std::cout << " Hexahedra" << std::endl;
810 // // for ( int iElem = 0; iElem < nbElem; iElem++ )
811 // // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3],
812 // // &id[iElem*tabRef[token]+4], &id[iElem*tabRef[token]+5], &id[iElem*tabRef[token]+6], &id[iElem*tabRef[token]+7], &ghs3dShapeID[iElem]);
819 // case GmfTriangles:
820 // // case GmfQuadrilaterals:
821 // case GmfTetrahedra:
822 // // case GmfHexahedra:
824 // int nodeDim, shapeID, *nodeID;
825 // const SMDS_MeshNode** node;
826 // // std::vector< SMDS_MeshNode* > enfNode( nbRef );
827 // SMDS_MeshElement * aGMFElement;
829 // node = new const SMDS_MeshNode*[nbRef];
830 // nodeID = new int[ nbRef ];
832 // for ( int iElem = 0; iElem < nbElem; iElem++ )
834 // for ( int iRef = 0; iRef < nbRef; iRef++ )
836 // aGMFNodeID = id[iElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID
837 // node [ iRef ] = GMFNode[ aGMFNodeID ];
838 // nodeID[ iRef ] = aGMFNodeID;
843 // case GmfCorners: {
845 // gp_Pnt GMFPnt ( node[0]->X(), node[0]->Y(), node[0]->Z() );
846 // for ( int i=0; i<nbElem; i++ ) {
847 // aVertex = TopoDS::Vertex( tabCorner[i] );
848 // gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
849 // if ( aPnt.Distance( GMFPnt ) < epsilon )
856 // aGMFElement = theMeshDS->AddEdge( node[0], node[1] );
858 // if ( GMFNodeAssigne[ nodeID[0] ] == 0 || GMFNodeAssigne[ nodeID[0] ] == 2 )
860 // shapeID = findEdgeID( node[iNode], theMeshDS, nbShapeEdge, tabEdge );
865 // case GmfTriangles: {
867 // aGMFElement = theMeshDS->AddFace( node[0], node[1], node[2]);
871 // // case GmfQuadrilaterals: {
873 // // aGMFElement = theMeshDS->AddFace( node[0], node[1], node[2], node[3] );
877 // case GmfTetrahedra: {
880 // TopoDS_Shape aSolid;
881 // // We always run GHS3D with "to mesh holes"==TRUE but we must not create
882 // // tetras within holes depending on hypo option,
883 // // so we first check if aTet is inside a hole and then create it
884 // if ( nbTriangle > 1 ) {
885 // tetraShapeID = HOLE_ID; // negative tetraShapeID means not to create tetras if !toMeshHoles
886 // int aGhs3dShapeID = ghs3dShapeID[iElem] - IdShapeRef;
887 // if ( tabID[ aGhs3dShapeID ] == 0 ) {
888 // TopAbs_State state;
889 // aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape, &state);
890 // if ( toMeshHoles || state == TopAbs_IN )
891 // tetraShapeID = theMeshDS->ShapeToIndex( aSolid );
892 // tabID[ aGhs3dShapeID ] = tetraShapeID;
895 // tetraShapeID = tabID[ aGhs3dShapeID ];
897 // else if ( nbShape > 1 ) {
898 // // Case where nbTriangle == 1 while nbShape == 2 encountered
899 // // with compound of 2 boxes and "To mesh holes"==False,
900 // // so there are no subdomains specified for each tetrahedron.
901 // // Try to guess a solid by a node already bound to shape
903 // for ( int i=0; i<4 && tetraShapeID==0; i++ ) {
904 // if ( nodeAssigne[ nodeID[i] ] == 1 &&
905 // node[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE &&
906 // node[i]->getshapeId() > 1 )
908 // tetraShapeID = node[i]->getshapeId();
911 // if ( tetraShapeID==0 ) {
912 // aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape);
913 // tetraShapeID = theMeshDS->ShapeToIndex( aSolid );
916 // // set new nodes and tetrahedron onto the shape
917 // for ( int i=0; i<4; i++ ) {
918 // if ( nodeAssigne[ nodeID[i] ] == 0 ) {
919 // if ( tetraShapeID != HOLE_ID )
920 // theMeshDS->SetNodeInVolume( node[i], tetraShapeID );
921 // nodeAssigne[ nodeID[i] ] = tetraShapeID;
924 // if ( toMeshHoles || tetraShapeID != HOLE_ID ) {
925 // aGMFElement = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
926 // theMeshDS->SetMeshElementOnShape( aGMFElement, tetraShapeID );
934 // // case GmfHexahedra: {
936 // // aGMFElement = theMeshDS->AddVolume( node[0], node[3], node[2], node[1],
937 // // node[4], node[7], node[6], node[5] );
940 // default: continue;
942 // if (token != GmfRidges)
944 // for ( int i=0; i<nbRef; i++ ) {
945 // if ( GMFNodeAssigne[ nodeID[i] ] == 0 ) {
946 // if ( token == GmfCorners ) theMeshDS->SetNodeOnVertex( node[0], aVertex );
947 // else if ( token == GmfEdges ) theMeshDS->SetNodeOnEdge( node[i], shapeID );
948 // else if ( token == GmfTriangles ) theMeshDS->SetNodeOnFace( node[i], shapeID );
949 // GMFNodeAssigne[ nodeID[i] ] = nodeDim;
952 // if ( token != "Corners" )
953 // theMeshDS->SetMeshElementOnShape( aGMFElement, shapeID );
957 // if ( !toMeshHoles ) {
958 // map <int,const SMDS_MeshNode*>::iterator itOnNode = theGhs3dIdToNodeMap.find( nbVertices-(nbEnforcedVertices+nbEnforcedNodes) );
959 // for ( ; itOnNode != theGhs3dIdToNodeMap.end(); ++itOnNode) {
960 // if ( nodeAssigne[ itOnNode->first ] == HOLE_ID )
961 // theMeshDS->RemoveFreeNode( itOnNode->second, 0 );
968 // } // case GmfTetrahedra
969 // } // switch(token)
971 // cout << std::endl;
974 // UnmapViewOfFile(mapPtr);
975 // CloseHandle(hMapObject);
978 // munmap(mapPtr, length);
983 // delete [] tabCorner;
984 // delete [] tabEdge;
985 // delete [] nodeAssigne;
986 // delete [] GMFNodeAssigne;
987 // delete [] GMFNode;
993 //=======================================================================
994 //function : addElemInMeshGroup
995 //purpose : Update or create groups in mesh
996 //=======================================================================
998 static void addElemInMeshGroup(SMESH_Mesh* theMesh,
999 const SMDS_MeshElement* anElem,
1000 std::string& groupName,
1001 std::set<std::string>& groupsToRemove)
1003 if ( !anElem ) return; // issue 0021776
1005 bool groupDone = false;
1006 SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups();
1007 while (grIt->more()) {
1008 SMESH_Group * group = grIt->next();
1009 if ( !group ) continue;
1010 SMESHDS_GroupBase* groupDS = group->GetGroupDS();
1011 if ( !groupDS ) continue;
1012 if ( groupDS->GetType()==anElem->GetType() &&groupName.compare(group->GetName())==0) {
1013 SMESHDS_Group* aGroupDS = static_cast<SMESHDS_Group*>( groupDS );
1014 aGroupDS->SMDSGroup().Add(anElem);
1016 // MESSAGE("Successfully added enforced element to existing group " << groupName);
1024 SMESH_Group* aGroup = theMesh->AddGroup(anElem->GetType(), groupName.c_str(), groupId);
1025 aGroup->SetName( groupName.c_str() );
1026 SMESHDS_Group* aGroupDS = static_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
1027 aGroupDS->SMDSGroup().Add(anElem);
1028 // MESSAGE("Successfully created enforced vertex group " << groupName);
1032 throw SALOME_Exception(LOCALIZED("A given element was not added to a group"));
1036 //=======================================================================
1037 //function : updateMeshGroups
1038 //purpose : Update or create groups in mesh
1039 //=======================================================================
1041 static void updateMeshGroups(SMESH_Mesh* theMesh, std::set<std::string> groupsToRemove)
1043 SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups();
1044 while (grIt->more()) {
1045 SMESH_Group * group = grIt->next();
1046 if ( !group ) continue;
1047 SMESHDS_GroupBase* groupDS = group->GetGroupDS();
1048 if ( !groupDS ) continue;
1049 std::string currentGroupName = (string)group->GetName();
1050 if (groupDS->IsEmpty() && groupsToRemove.find(currentGroupName) != groupsToRemove.end()) {
1051 // Previous group created by enforced elements
1052 MESSAGE("Delete previous group created by removed enforced elements: " << group->GetName())
1053 theMesh->RemoveGroup(groupDS->GetID());
1058 //=======================================================================
1059 //function : removeEmptyGroupsOfDomains
1060 //purpose : remove empty groups named "Domain_nb" created due to
1061 // "To make groups of domains" option.
1062 //=======================================================================
1064 static void removeEmptyGroupsOfDomains(SMESH_Mesh* mesh,
1065 bool notEmptyAsWell = false)
1067 const char* refName = theDomainGroupNamePrefix;
1068 const size_t refLen = strlen( theDomainGroupNamePrefix );
1070 std::list<int> groupIDs = mesh->GetGroupIds();
1071 std::list<int>::const_iterator id = groupIDs.begin();
1072 for ( ; id != groupIDs.end(); ++id )
1074 SMESH_Group* group = mesh->GetGroup( *id );
1075 if ( !group || ( !group->GetGroupDS()->IsEmpty() && !notEmptyAsWell ))
1077 const char* name = group->GetName();
1080 if ( strncmp( name, refName, refLen ) == 0 && // starts from refName;
1081 isdigit( *( name + refLen )) && // refName is followed by a digit;
1082 strtol( name + refLen, &end, 10) && // there are only digits ...
1083 *end == '\0') // ... till a string end.
1085 mesh->RemoveGroup( *id );
1090 //=======================================================================
1091 //function : readGMFFile
1092 //purpose : read GMF file w/o geometry associated to mesh
1093 //=======================================================================
1095 static bool readGMFFile(const char* theFile,
1096 GHS3DPlugin_GHS3D* theAlgo,
1097 SMESH_MesherHelper* theHelper,
1098 TopoDS_Shape theSolid,
1099 vector <const SMDS_MeshNode*> & theNodeByGhs3dId,
1100 map<const SMDS_MeshNode*,int> & theNodeToGhs3dIdMap,
1101 std::vector<std::string> & aNodeGroupByGhs3dId,
1102 std::vector<std::string> & anEdgeGroupByGhs3dId,
1103 std::vector<std::string> & aFaceGroupByGhs3dId,
1104 std::set<std::string> & groupsToRemove,
1105 bool toMakeGroupsOfDomains=false)
1108 SMESHDS_Mesh* theMeshDS = theHelper->GetMeshDS();
1110 int nbInitialNodes = theNodeByGhs3dId.size();
1111 int nbMeshNodes = theMeshDS->NbNodes();
1113 const bool isQuadMesh =
1114 theHelper->GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
1115 theHelper->GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
1116 theHelper->GetMesh()->NbVolumes( ORDER_QUADRATIC );
1119 std::cout << "theNodeByGhs3dId.size(): " << nbInitialNodes << std::endl;
1120 std::cout << "theHelper->GetMesh()->NbNodes(): " << nbMeshNodes << std::endl;
1121 std::cout << "isQuadMesh: " << isQuadMesh << std::endl;
1124 if (theHelper->GetSubShapeID() != 0)
1125 theHelper->IsQuadraticSubMesh( theHelper->GetSubShape() );
1127 // ---------------------------------
1128 // Read generated elements and nodes
1129 // ---------------------------------
1131 int nbElem = 0, nbRef = 0;
1133 const SMDS_MeshNode** GMFNode;
1135 std::map<int, std::set<int> > subdomainId2tetraId;
1137 std::map <GmfKwdCod,int> tabRef;
1138 const bool force3d = true; // since there is no geometry
1141 tabRef[GmfVertices] = 3; // for new nodes and enforced nodes
1142 tabRef[GmfCorners] = 1;
1143 tabRef[GmfEdges] = 2; // for enforced edges
1144 tabRef[GmfRidges] = 1;
1145 tabRef[GmfTriangles] = 3; // for enforced faces
1146 tabRef[GmfQuadrilaterals] = 4;
1147 tabRef[GmfTetrahedra] = 4; // for new tetras
1148 tabRef[GmfHexahedra] = 8;
1151 MESSAGE("Read " << theFile << " file");
1152 int InpMsh = GmfOpenMesh(theFile, GmfRead, &ver, &dim);
1157 // Issue 0020682. Avoid creating nodes and tetras at place where
1158 // volumic elements already exist
1159 SMESH_ElementSearcher* elemSearcher = 0;
1160 std::vector< const SMDS_MeshElement* > foundVolumes;
1161 if ( theHelper->GetMesh()->NbVolumes() > 0 )
1162 elemSearcher = SMESH_MeshAlgos::GetElementSearcher( *theHelper->GetMeshDS() );
1164 // IMP 0022172: [CEA 790] create the groups corresponding to domains
1165 std::vector< std::vector< const SMDS_MeshElement* > > elemsOfDomain;
1167 int nbVertices = GmfStatKwd(InpMsh, GmfVertices) - nbInitialNodes;
1168 GMFNode = new const SMDS_MeshNode*[ nbVertices + 1 ];
1170 std::map <GmfKwdCod,int>::const_iterator it = tabRef.begin();
1171 for ( ; it != tabRef.end() ; ++it)
1173 if(theAlgo->computeCanceled()) {
1174 GmfCloseMesh(InpMsh);
1179 GmfKwdCod token = it->first;
1182 nbElem = GmfStatKwd(InpMsh, token);
1184 GmfGotoKwd(InpMsh, token);
1185 std::cout << "Read " << nbElem;
1190 std::vector<int> id (nbElem*tabRef[token]); // node ids
1191 std::vector<int> domainID( nbElem ); // domain
1193 if (token == GmfVertices) {
1194 (nbElem <= 1) ? tmpStr = " vertex" : tmpStr = " vertices";
1195 // std::cout << nbInitialNodes << " from input mesh " << std::endl;
1197 // Remove orphan nodes from previous enforced mesh which was cleared
1198 // if ( nbElem < nbMeshNodes ) {
1199 // const SMDS_MeshNode* node;
1200 // SMDS_NodeIteratorPtr nodeIt = theMeshDS->nodesIterator();
1201 // while ( nodeIt->more() )
1203 // node = nodeIt->next();
1204 // if (theNodeToGhs3dIdMap.find(node) != theNodeToGhs3dIdMap.end())
1205 // theMeshDS->RemoveNode(node);
1214 const SMDS_MeshNode * aGMFNode;
1216 for ( int iElem = 0; iElem < nbElem; iElem++ ) {
1217 if(theAlgo->computeCanceled()) {
1218 GmfCloseMesh(InpMsh);
1222 if (ver == GmfFloat) {
1223 GmfGetLin(InpMsh, token, &VerTab_f[0], &VerTab_f[1], &VerTab_f[2], &dummy);
1229 GmfGetLin(InpMsh, token, &x, &y, &z, &dummy);
1231 if (iElem >= nbInitialNodes) {
1232 if ( elemSearcher &&
1233 elemSearcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_Volume, foundVolumes))
1236 aGMFNode = theHelper->AddNode(x, y, z);
1238 aGMFID = iElem -nbInitialNodes +1;
1239 GMFNode[ aGMFID ] = aGMFNode;
1240 if (aGMFID-1 < aNodeGroupByGhs3dId.size() && !aNodeGroupByGhs3dId.at(aGMFID-1).empty())
1241 addElemInMeshGroup(theHelper->GetMesh(), aGMFNode, aNodeGroupByGhs3dId.at(aGMFID-1), groupsToRemove);
1245 else if (token == GmfCorners && nbElem > 0) {
1246 (nbElem <= 1) ? tmpStr = " corner" : tmpStr = " corners";
1247 for ( int iElem = 0; iElem < nbElem; iElem++ )
1248 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
1250 else if (token == GmfRidges && nbElem > 0) {
1251 (nbElem <= 1) ? tmpStr = " ridge" : tmpStr = " ridges";
1252 for ( int iElem = 0; iElem < nbElem; iElem++ )
1253 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
1255 else if (token == GmfEdges && nbElem > 0) {
1256 (nbElem <= 1) ? tmpStr = " edge" : tmpStr = " edges";
1257 for ( int iElem = 0; iElem < nbElem; iElem++ )
1258 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &domainID[iElem]);
1260 else if (token == GmfTriangles && nbElem > 0) {
1261 (nbElem <= 1) ? tmpStr = " triangle" : tmpStr = " triangles";
1262 for ( int iElem = 0; iElem < nbElem; iElem++ )
1263 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &domainID[iElem]);
1265 else if (token == GmfQuadrilaterals && nbElem > 0) {
1266 (nbElem <= 1) ? tmpStr = " Quadrilateral" : tmpStr = " Quadrilaterals";
1267 for ( int iElem = 0; iElem < nbElem; iElem++ )
1268 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &domainID[iElem]);
1270 else if (token == GmfTetrahedra && nbElem > 0) {
1271 (nbElem <= 1) ? tmpStr = " Tetrahedron" : tmpStr = " Tetrahedra";
1272 for ( int iElem = 0; iElem < nbElem; iElem++ ) {
1273 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &domainID[iElem]);
1275 subdomainId2tetraId[dummy].insert(iElem+1);
1276 // MESSAGE("subdomainId2tetraId["<<dummy<<"].insert("<<iElem+1<<")");
1280 else if (token == GmfHexahedra && nbElem > 0) {
1281 (nbElem <= 1) ? tmpStr = " Hexahedron" : tmpStr = " Hexahedra";
1282 for ( int iElem = 0; iElem < nbElem; iElem++ )
1283 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3],
1284 &id[iElem*tabRef[token]+4], &id[iElem*tabRef[token]+5], &id[iElem*tabRef[token]+6], &id[iElem*tabRef[token]+7], &domainID[iElem]);
1286 std::cout << tmpStr << std::endl;
1287 std::cout << std::endl;
1294 case GmfQuadrilaterals:
1298 std::vector< const SMDS_MeshNode* > node( nbRef );
1299 std::vector< int > nodeID( nbRef );
1300 std::vector< SMDS_MeshNode* > enfNode( nbRef );
1301 const SMDS_MeshElement* aCreatedElem;
1303 for ( int iElem = 0; iElem < nbElem; iElem++ )
1305 if(theAlgo->computeCanceled()) {
1306 GmfCloseMesh(InpMsh);
1310 // Check if elem is already in input mesh. If yes => skip
1311 bool fullyCreatedElement = false; // if at least one of the nodes was created
1312 for ( int iRef = 0; iRef < nbRef; iRef++ )
1314 aGMFNodeID = id[iElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID
1315 if (aGMFNodeID <= nbInitialNodes) // input nodes
1318 node[ iRef ] = theNodeByGhs3dId[aGMFNodeID];
1322 fullyCreatedElement = true;
1323 aGMFNodeID -= nbInitialNodes;
1324 nodeID[ iRef ] = aGMFNodeID ;
1325 node [ iRef ] = GMFNode[ aGMFNodeID ];
1332 if (fullyCreatedElement) {
1333 aCreatedElem = theHelper->AddEdge( node[0], node[1], noID, force3d );
1334 if (anEdgeGroupByGhs3dId.size() && !anEdgeGroupByGhs3dId[iElem].empty())
1335 addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByGhs3dId[iElem], groupsToRemove);
1339 if (fullyCreatedElement) {
1340 aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], noID, force3d );
1341 if (aFaceGroupByGhs3dId.size() && !aFaceGroupByGhs3dId[iElem].empty())
1342 addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, aFaceGroupByGhs3dId[iElem], groupsToRemove);
1345 case GmfQuadrilaterals:
1346 if (fullyCreatedElement) {
1347 aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], node[3], noID, force3d );
1351 if ( elemSearcher ) {
1352 // Issue 0020682. Avoid creating nodes and tetras at place where
1353 // volumic elements already exist
1354 if ( !node[1] || !node[0] || !node[2] || !node[3] )
1356 if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) +
1357 SMESH_TNodeXYZ(node[1]) +
1358 SMESH_TNodeXYZ(node[2]) +
1359 SMESH_TNodeXYZ(node[3]) ) / 4.,
1360 SMDSAbs_Volume, foundVolumes ))
1363 aCreatedElem = theHelper->AddVolume( node[1], node[0], node[2], node[3], noID, force3d );
1366 if ( elemSearcher ) {
1367 // Issue 0020682. Avoid creating nodes and tetras at place where
1368 // volumic elements already exist
1369 if ( !node[1] || !node[0] || !node[2] || !node[3] || !node[4] || !node[5] || !node[6] || !node[7])
1371 if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) +
1372 SMESH_TNodeXYZ(node[1]) +
1373 SMESH_TNodeXYZ(node[2]) +
1374 SMESH_TNodeXYZ(node[3]) +
1375 SMESH_TNodeXYZ(node[4]) +
1376 SMESH_TNodeXYZ(node[5]) +
1377 SMESH_TNodeXYZ(node[6]) +
1378 SMESH_TNodeXYZ(node[7])) / 8.,
1379 SMDSAbs_Volume, foundVolumes ))
1382 aCreatedElem = theHelper->AddVolume( node[0], node[3], node[2], node[1],
1383 node[4], node[7], node[6], node[5], noID, force3d );
1387 if ( aCreatedElem && toMakeGroupsOfDomains )
1389 if ( domainID[iElem] >= (int) elemsOfDomain.size() )
1390 elemsOfDomain.resize( domainID[iElem] + 1 );
1391 elemsOfDomain[ domainID[iElem] ].push_back( aCreatedElem );
1393 } // loop on elements of one type
1399 GmfCloseMesh(InpMsh);
1402 // 0022172: [CEA 790] create the groups corresponding to domains
1403 if ( toMakeGroupsOfDomains )
1406 for ( size_t i = 0; i < elemsOfDomain.size(); ++i )
1407 nbDomains += ( elemsOfDomain[i].size() > 0 );
1409 if ( nbDomains > 1 )
1410 for ( size_t iDomain = 0; iDomain < elemsOfDomain.size(); ++iDomain )
1412 std::vector< const SMDS_MeshElement* > & elems = elemsOfDomain[ iDomain ];
1413 if ( elems.empty() ) continue;
1415 // find existing groups
1416 std::vector< SMESH_Group* > groupOfType( SMDSAbs_NbElementTypes, (SMESH_Group*)NULL );
1417 const std::string domainName = ( SMESH_Comment( theDomainGroupNamePrefix ) << iDomain );
1418 SMESH_Mesh::GroupIteratorPtr groupIt = theHelper->GetMesh()->GetGroups();
1419 while ( groupIt->more() )
1421 SMESH_Group* group = groupIt->next();
1422 if ( domainName == group->GetName() &&
1423 dynamic_cast< SMESHDS_Group* >( group->GetGroupDS()) )
1424 groupOfType[ group->GetGroupDS()->GetType() ] = group;
1426 // create and fill the groups
1431 SMESH_Group* group = groupOfType[ elems[ iElem ]->GetType() ];
1433 group = theHelper->GetMesh()->AddGroup( elems[ iElem ]->GetType(),
1434 domainName.c_str(), groupID );
1435 SMDS_MeshGroup& groupDS =
1436 static_cast< SMESHDS_Group* >( group->GetGroupDS() )->SMDSGroup();
1438 while ( iElem < elems.size() && groupDS.Add( elems[iElem] ))
1441 } while ( iElem < elems.size() );
1446 MESSAGE("Nb subdomains " << subdomainId2tetraId.size());
1447 std::map<int, std::set<int> >::const_iterator subdomainIt = subdomainId2tetraId.begin();
1448 TCollection_AsciiString aSubdomainFileName = theFile;
1449 aSubdomainFileName = aSubdomainFileName + ".subdomain";
1450 ofstream aSubdomainFile ( aSubdomainFileName.ToCString() , ios::out);
1452 aSubdomainFile << "Nb subdomains " << subdomainId2tetraId.size() << std::endl;
1453 for(;subdomainIt != subdomainId2tetraId.end() ; ++subdomainIt) {
1454 int subdomainId = subdomainIt->first;
1455 std::set<int> tetraIds = subdomainIt->second;
1456 MESSAGE("Subdomain #"<<subdomainId<<": "<<tetraIds.size()<<" tetrahedrons");
1457 std::set<int>::const_iterator tetraIdsIt = tetraIds.begin();
1458 aSubdomainFile << subdomainId << std::endl;
1459 for(;tetraIdsIt != tetraIds.end() ; ++tetraIdsIt) {
1460 aSubdomainFile << (*tetraIdsIt) << " ";
1462 aSubdomainFile << std::endl;
1464 aSubdomainFile.close();
1469 MESSAGE("delete elemSearcher")
1470 delete elemSearcher;
1476 static bool writeGMFFile(const char* theMeshFileName,
1477 const char* theRequiredFileName,
1478 const char* theSolFileName,
1479 const SMESH_ProxyMesh& theProxyMesh,
1480 SMESH_Mesh * theMesh,
1481 std::vector <const SMDS_MeshNode*> & theNodeByGhs3dId,
1482 std::map<const SMDS_MeshNode*,int> & aNodeToGhs3dIdMap,
1483 std::vector<std::string> & aNodeGroupByGhs3dId,
1484 std::vector<std::string> & anEdgeGroupByGhs3dId,
1485 std::vector<std::string> & aFaceGroupByGhs3dId,
1486 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes,
1487 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
1488 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles,
1489 std::map<std::vector<double>, std::string> & enfVerticesWithGroup,
1490 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices)
1492 MESSAGE("writeGMFFile w/o geometry");
1494 int idx, idxRequired = 0, idxSol = 0;
1495 const int dummyint = 0;
1496 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt;
1497 std::vector<double> enfVertexSizes;
1498 const SMDS_MeshElement* elem;
1499 TIDSortedElemSet anElemSet, theKeptEnforcedEdges, theKeptEnforcedTriangles;
1500 SMDS_ElemIteratorPtr nodeIt;
1501 std::vector <const SMDS_MeshNode*> theEnforcedNodeByGhs3dId;
1502 map<const SMDS_MeshNode*,int> anEnforcedNodeToGhs3dIdMap, anExistingEnforcedNodeToGhs3dIdMap;
1503 std::vector< const SMDS_MeshElement* > foundElems;
1504 map<const SMDS_MeshNode*,TopAbs_State> aNodeToTopAbs_StateMap;
1506 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap::iterator elemIt;
1507 TIDSortedElemSet::iterator elemSetIt;
1509 auto_ptr< SMESH_ElementSearcher > pntCls
1510 ( SMESH_MeshAlgos::GetElementSearcher(*theMesh->GetMeshDS()));
1512 int nbEnforcedVertices = theEnforcedVertices.size();
1515 int nbFaces = theProxyMesh.NbFaces();
1518 // groups management
1519 int usedEnforcedNodes = 0;
1520 std::string gn = "";
1525 idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1529 /* ========================== FACES ========================== */
1530 /* TRIANGLES ========================== */
1531 SMDS_ElemIteratorPtr eIt = theProxyMesh.GetFaces();
1532 while ( eIt->more() )
1535 anElemSet.insert(elem);
1536 nodeIt = elem->nodesIterator();
1537 nbNodes = elem->NbCornerNodes();
1538 while ( nodeIt->more() && nbNodes--)
1541 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1542 int newId = aNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
1543 aNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1547 /* EDGES ========================== */
1549 // Iterate over the enforced edges
1550 for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
1551 elem = elemIt->first;
1553 nodeIt = elem->nodesIterator();
1555 while ( nodeIt->more() && nbNodes-- ) {
1557 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1558 // Test if point is inside shape to mesh
1559 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1560 TopAbs_State result = pntCls->GetPointState( myPoint );
1561 if ( result == TopAbs_OUT ) {
1565 aNodeToTopAbs_StateMap.insert( make_pair( node, result ));
1568 nodeIt = elem->nodesIterator();
1571 while ( nodeIt->more() && nbNodes-- ) {
1573 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1574 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1575 nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1577 std::cout << "Node at "<<node->X()<<", "<<node->Y()<<", "<<node->Z()<<std::endl;
1578 std::cout << "Nb nodes found : "<<nbFoundElems<<std::endl;
1580 if (nbFoundElems ==0) {
1581 if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1582 newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
1583 anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1586 else if (nbFoundElems ==1) {
1587 const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1588 newId = (*aNodeToGhs3dIdMap.find(existingNode)).second;
1589 anExistingEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1594 std::cout << "GHS3D node ID: "<<newId<<std::endl;
1598 theKeptEnforcedEdges.insert(elem);
1602 /* ENFORCED TRIANGLES ========================== */
1604 // Iterate over the enforced triangles
1605 for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
1606 elem = elemIt->first;
1608 nodeIt = elem->nodesIterator();
1610 while ( nodeIt->more() && nbNodes--) {
1612 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1613 // Test if point is inside shape to mesh
1614 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1615 TopAbs_State result = pntCls->GetPointState( myPoint );
1616 if ( result == TopAbs_OUT ) {
1620 aNodeToTopAbs_StateMap.insert( make_pair( node, result ));
1623 nodeIt = elem->nodesIterator();
1626 while ( nodeIt->more() && nbNodes--) {
1628 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1629 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1630 nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1632 std::cout << "Nb nodes found : "<<nbFoundElems<<std::endl;
1634 if (nbFoundElems ==0) {
1635 if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1636 newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
1637 anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1640 else if (nbFoundElems ==1) {
1641 const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1642 newId = (*aNodeToGhs3dIdMap.find(existingNode)).second;
1643 anExistingEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1648 std::cout << "GHS3D node ID: "<<newId<<std::endl;
1652 theKeptEnforcedTriangles.insert(elem);
1656 // put nodes to theNodeByGhs3dId vector
1658 std::cout << "aNodeToGhs3dIdMap.size(): "<<aNodeToGhs3dIdMap.size()<<std::endl;
1660 theNodeByGhs3dId.resize( aNodeToGhs3dIdMap.size() );
1661 map<const SMDS_MeshNode*,int>::const_iterator n2id = aNodeToGhs3dIdMap.begin();
1662 for ( ; n2id != aNodeToGhs3dIdMap.end(); ++ n2id)
1664 // std::cout << "n2id->first: "<<n2id->first<<std::endl;
1665 theNodeByGhs3dId[ n2id->second - 1 ] = n2id->first; // ghs3d ids count from 1
1668 // put nodes to anEnforcedNodeToGhs3dIdMap vector
1670 std::cout << "anEnforcedNodeToGhs3dIdMap.size(): "<<anEnforcedNodeToGhs3dIdMap.size()<<std::endl;
1672 theEnforcedNodeByGhs3dId.resize( anEnforcedNodeToGhs3dIdMap.size());
1673 n2id = anEnforcedNodeToGhs3dIdMap.begin();
1674 for ( ; n2id != anEnforcedNodeToGhs3dIdMap.end(); ++ n2id)
1676 if (n2id->second > aNodeToGhs3dIdMap.size()) {
1677 theEnforcedNodeByGhs3dId[ n2id->second - aNodeToGhs3dIdMap.size() - 1 ] = n2id->first; // ghs3d ids count from 1
1682 /* ========================== NODES ========================== */
1683 vector<const SMDS_MeshNode*> theOrderedNodes, theRequiredNodes;
1684 std::set< std::vector<double> > nodesCoords;
1685 vector<const SMDS_MeshNode*>::const_iterator ghs3dNodeIt = theNodeByGhs3dId.begin();
1686 vector<const SMDS_MeshNode*>::const_iterator after = theNodeByGhs3dId.end();
1688 (theNodeByGhs3dId.size() <= 1) ? tmpStr = " node" : " nodes";
1689 std::cout << theNodeByGhs3dId.size() << tmpStr << " from mesh ..." << std::endl;
1690 for ( ; ghs3dNodeIt != after; ++ghs3dNodeIt )
1692 const SMDS_MeshNode* node = *ghs3dNodeIt;
1693 std::vector<double> coords;
1694 coords.push_back(node->X());
1695 coords.push_back(node->Y());
1696 coords.push_back(node->Z());
1697 nodesCoords.insert(coords);
1698 theOrderedNodes.push_back(node);
1701 // Iterate over the enforced nodes given by enforced elements
1702 ghs3dNodeIt = theEnforcedNodeByGhs3dId.begin();
1703 after = theEnforcedNodeByGhs3dId.end();
1704 (theEnforcedNodeByGhs3dId.size() <= 1) ? tmpStr = " node" : " nodes";
1705 std::cout << theEnforcedNodeByGhs3dId.size() << tmpStr << " from enforced elements ..." << std::endl;
1706 for ( ; ghs3dNodeIt != after; ++ghs3dNodeIt )
1708 const SMDS_MeshNode* node = *ghs3dNodeIt;
1709 std::vector<double> coords;
1710 coords.push_back(node->X());
1711 coords.push_back(node->Y());
1712 coords.push_back(node->Z());
1714 std::cout << "Node at " << node->X()<<", " <<node->Y()<<", " <<node->Z();
1717 if (nodesCoords.find(coords) != nodesCoords.end()) {
1718 // node already exists in original mesh
1720 std::cout << " found" << std::endl;
1725 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) {
1726 // node already exists in enforced vertices
1728 std::cout << " found" << std::endl;
1733 // gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1734 // nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1735 // if (nbFoundElems ==0) {
1736 // std::cout << " not found" << std::endl;
1737 // if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1738 // nodesCoords.insert(coords);
1739 // theOrderedNodes.push_back(node);
1743 // std::cout << " found in initial mesh" << std::endl;
1744 // const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1745 // nodesCoords.insert(coords);
1746 // theOrderedNodes.push_back(existingNode);
1750 std::cout << " not found" << std::endl;
1753 nodesCoords.insert(coords);
1754 theOrderedNodes.push_back(node);
1755 // theRequiredNodes.push_back(node);
1759 // Iterate over the enforced nodes
1760 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt;
1761 (theEnforcedNodes.size() <= 1) ? tmpStr = " node" : " nodes";
1762 std::cout << theEnforcedNodes.size() << tmpStr << " from enforced nodes ..." << std::endl;
1763 for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt)
1765 const SMDS_MeshNode* node = enfNodeIt->first;
1766 std::vector<double> coords;
1767 coords.push_back(node->X());
1768 coords.push_back(node->Y());
1769 coords.push_back(node->Z());
1771 std::cout << "Node at " << node->X()<<", " <<node->Y()<<", " <<node->Z();
1774 // Test if point is inside shape to mesh
1775 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1776 TopAbs_State result = pntCls->GetPointState( myPoint );
1777 if ( result == TopAbs_OUT ) {
1779 std::cout << " out of volume" << std::endl;
1784 if (nodesCoords.find(coords) != nodesCoords.end()) {
1786 std::cout << " found in nodesCoords" << std::endl;
1788 // theRequiredNodes.push_back(node);
1792 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) {
1794 std::cout << " found in theEnforcedVertices" << std::endl;
1799 // nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1800 // if (nbFoundElems ==0) {
1801 // std::cout << " not found" << std::endl;
1802 // if (result == TopAbs_IN) {
1803 // nodesCoords.insert(coords);
1804 // theRequiredNodes.push_back(node);
1808 // std::cout << " found in initial mesh" << std::endl;
1809 // const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1810 // // nodesCoords.insert(coords);
1811 // theRequiredNodes.push_back(existingNode);
1816 // if (pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems) == 0)
1819 // if ( result != TopAbs_IN )
1823 std::cout << " not found" << std::endl;
1825 nodesCoords.insert(coords);
1826 // theOrderedNodes.push_back(node);
1827 theRequiredNodes.push_back(node);
1829 int requiredNodes = theRequiredNodes.size();
1832 std::vector<std::vector<double> > ReqVerTab;
1833 if (nbEnforcedVertices) {
1834 // ReqVerTab.clear();
1835 (nbEnforcedVertices <= 1) ? tmpStr = " node" : " nodes";
1836 std::cout << nbEnforcedVertices << tmpStr << " from enforced vertices ..." << std::endl;
1837 // Iterate over the enforced vertices
1838 for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
1839 double x = vertexIt->first[0];
1840 double y = vertexIt->first[1];
1841 double z = vertexIt->first[2];
1842 // Test if point is inside shape to mesh
1843 gp_Pnt myPoint(x,y,z);
1844 TopAbs_State result = pntCls->GetPointState( myPoint );
1845 if ( result == TopAbs_OUT )
1847 //if (pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems) == 0)
1850 // if ( result != TopAbs_IN )
1852 std::vector<double> coords;
1853 coords.push_back(x);
1854 coords.push_back(y);
1855 coords.push_back(z);
1856 ReqVerTab.push_back(coords);
1857 enfVertexSizes.push_back(vertexIt->second);
1864 std::cout << "Begin writting required nodes in GmfVertices" << std::endl;
1865 std::cout << "Nb vertices: " << theOrderedNodes.size() << std::endl;
1866 GmfSetKwd(idx, GmfVertices, theOrderedNodes.size()/*+solSize*/);
1867 for (ghs3dNodeIt = theOrderedNodes.begin();ghs3dNodeIt != theOrderedNodes.end();++ghs3dNodeIt) {
1868 GmfSetLin(idx, GmfVertices, (*ghs3dNodeIt)->X(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint);
1871 std::cout << "End writting required nodes in GmfVertices" << std::endl;
1873 if (requiredNodes + solSize) {
1874 std::cout << "Begin writting in req and sol file" << std::endl;
1875 aNodeGroupByGhs3dId.resize( requiredNodes + solSize );
1876 idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1881 idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1885 GmfCloseMesh(idxRequired);
1888 int TypTab[] = {GmfSca};
1889 double ValTab[] = {0.0};
1890 GmfSetKwd(idxRequired, GmfVertices, requiredNodes + solSize);
1891 GmfSetKwd(idxSol, GmfSolAtVertices, requiredNodes + solSize, 1, TypTab);
1892 // int usedEnforcedNodes = 0;
1893 // std::string gn = "";
1894 for (ghs3dNodeIt = theRequiredNodes.begin();ghs3dNodeIt != theRequiredNodes.end();++ghs3dNodeIt) {
1895 GmfSetLin(idxRequired, GmfVertices, (*ghs3dNodeIt)->X(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint);
1896 GmfSetLin(idxSol, GmfSolAtVertices, ValTab);
1897 if (theEnforcedNodes.find((*ghs3dNodeIt)) != theEnforcedNodes.end())
1898 gn = theEnforcedNodes.find((*ghs3dNodeIt))->second;
1899 aNodeGroupByGhs3dId[usedEnforcedNodes] = gn;
1900 usedEnforcedNodes++;
1903 for (int i=0;i<solSize;i++) {
1904 std::cout << ReqVerTab[i][0] <<" "<< ReqVerTab[i][1] << " "<< ReqVerTab[i][2] << std::endl;
1906 std::cout << "enfVertexSizes.at("<<i<<"): " << enfVertexSizes.at(i) << std::endl;
1908 double solTab[] = {enfVertexSizes.at(i)};
1909 GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
1910 GmfSetLin(idxSol, GmfSolAtVertices, solTab);
1911 aNodeGroupByGhs3dId[usedEnforcedNodes] = enfVerticesWithGroup.find(ReqVerTab[i])->second;
1913 std::cout << "aNodeGroupByGhs3dId["<<usedEnforcedNodes<<"] = \""<<aNodeGroupByGhs3dId[usedEnforcedNodes]<<"\""<<std::endl;
1915 usedEnforcedNodes++;
1917 std::cout << "End writting in req and sol file" << std::endl;
1920 int nedge[2], ntri[3];
1923 int usedEnforcedEdges = 0;
1924 if (theKeptEnforcedEdges.size()) {
1925 anEdgeGroupByGhs3dId.resize( theKeptEnforcedEdges.size() );
1926 // idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1927 // if (!idxRequired)
1929 GmfSetKwd(idx, GmfEdges, theKeptEnforcedEdges.size());
1930 // GmfSetKwd(idxRequired, GmfEdges, theKeptEnforcedEdges.size());
1931 for(elemSetIt = theKeptEnforcedEdges.begin() ; elemSetIt != theKeptEnforcedEdges.end() ; ++elemSetIt) {
1932 elem = (*elemSetIt);
1933 nodeIt = elem->nodesIterator();
1935 while ( nodeIt->more() ) {
1937 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1938 map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node);
1939 if (it == anEnforcedNodeToGhs3dIdMap.end()) {
1940 it = anExistingEnforcedNodeToGhs3dIdMap.find(node);
1941 if (it == anEnforcedNodeToGhs3dIdMap.end())
1942 throw "Node not found";
1944 nedge[index] = it->second;
1947 GmfSetLin(idx, GmfEdges, nedge[0], nedge[1], dummyint);
1948 anEdgeGroupByGhs3dId[usedEnforcedEdges] = theEnforcedEdges.find(elem)->second;
1949 // GmfSetLin(idxRequired, GmfEdges, nedge[0], nedge[1], dummyint);
1950 usedEnforcedEdges++;
1952 // GmfCloseMesh(idxRequired);
1956 if (usedEnforcedEdges) {
1957 GmfSetKwd(idx, GmfRequiredEdges, usedEnforcedEdges);
1958 for (int enfID=1;enfID<=usedEnforcedEdges;enfID++) {
1959 GmfSetLin(idx, GmfRequiredEdges, enfID);
1964 int usedEnforcedTriangles = 0;
1965 if (anElemSet.size()+theKeptEnforcedTriangles.size()) {
1966 aFaceGroupByGhs3dId.resize( anElemSet.size()+theKeptEnforcedTriangles.size() );
1967 GmfSetKwd(idx, GmfTriangles, anElemSet.size()+theKeptEnforcedTriangles.size());
1969 for(elemSetIt = anElemSet.begin() ; elemSetIt != anElemSet.end() ; ++elemSetIt,++k) {
1970 elem = (*elemSetIt);
1971 nodeIt = elem->nodesIterator();
1973 for ( int j = 0; j < 3; ++j ) {
1975 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1976 map< const SMDS_MeshNode*,int >::iterator it = aNodeToGhs3dIdMap.find(node);
1977 if (it == aNodeToGhs3dIdMap.end())
1978 throw "Node not found";
1979 ntri[index] = it->second;
1982 GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint);
1983 aFaceGroupByGhs3dId[k] = "";
1985 if (theKeptEnforcedTriangles.size()) {
1986 for(elemSetIt = theKeptEnforcedTriangles.begin() ; elemSetIt != theKeptEnforcedTriangles.end() ; ++elemSetIt,++k) {
1987 elem = (*elemSetIt);
1988 nodeIt = elem->nodesIterator();
1990 for ( int j = 0; j < 3; ++j ) {
1992 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1993 map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node);
1994 if (it == anEnforcedNodeToGhs3dIdMap.end()) {
1995 it = anExistingEnforcedNodeToGhs3dIdMap.find(node);
1996 if (it == anEnforcedNodeToGhs3dIdMap.end())
1997 throw "Node not found";
1999 ntri[index] = it->second;
2002 GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint);
2003 aFaceGroupByGhs3dId[k] = theEnforcedTriangles.find(elem)->second;
2004 usedEnforcedTriangles++;
2010 if (usedEnforcedTriangles) {
2011 GmfSetKwd(idx, GmfRequiredTriangles, usedEnforcedTriangles);
2012 for (int enfID=1;enfID<=usedEnforcedTriangles;enfID++)
2013 GmfSetLin(idx, GmfRequiredTriangles, anElemSet.size()+enfID);
2018 GmfCloseMesh(idxRequired);
2020 GmfCloseMesh(idxSol);
2026 // static bool writeGMFFile(const char* theMeshFileName,
2027 // const char* theRequiredFileName,
2028 // const char* theSolFileName,
2029 // SMESH_MesherHelper& theHelper,
2030 // const SMESH_ProxyMesh& theProxyMesh,
2031 // std::map <int,int> & theNodeId2NodeIndexMap,
2032 // std::map <int,int> & theSmdsToGhs3dIdMap,
2033 // std::map <int,const SMDS_MeshNode*> & theGhs3dIdToNodeMap,
2034 // TIDSortedNodeSet & theEnforcedNodes,
2035 // TIDSortedElemSet & theEnforcedEdges,
2036 // TIDSortedElemSet & theEnforcedTriangles,
2037 // // TIDSortedElemSet & theEnforcedQuadrangles,
2038 // GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices)
2040 // MESSAGE("writeGMFFile with geometry");
2041 // int idx, idxRequired, idxSol;
2042 // int nbv, nbev, nben, aGhs3dID = 0;
2043 // const int dummyint = 0;
2044 // GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt;
2045 // std::vector<double> enfVertexSizes;
2046 // TIDSortedNodeSet::const_iterator enfNodeIt;
2047 // const SMDS_MeshNode* node;
2048 // SMDS_NodeIteratorPtr nodeIt;
2050 // idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
2054 // SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS();
2056 // /* ========================== NODES ========================== */
2058 // nbv = theMeshDS->NbNodes();
2061 // nbev = theEnforcedVertices.size();
2062 // nben = theEnforcedNodes.size();
2064 // // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D
2065 // // The problem is in nodes on degenerated edges, we need to skip nodes which are free
2066 // // and replace not-free nodes on edges by the node on vertex
2067 // TNodeNodeMap n2nDegen; // map a node on degenerated edge to a node on vertex
2068 // TNodeNodeMap::iterator n2nDegenIt;
2069 // if ( theHelper.HasDegeneratedEdges() )
2071 // set<int> checkedSM;
2072 // for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next())
2074 // SMESH_subMesh* sm = theHelper.GetMesh()->GetSubMesh( e.Current() );
2075 // if ( checkedSM.insert( sm->GetId() ).second && theHelper.IsDegenShape(sm->GetId() ))
2077 // if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() )
2079 // TopoDS_Shape vertex = TopoDS_Iterator( e.Current() ).Value();
2080 // const SMDS_MeshNode* vNode = SMESH_Algo::VertexNode( TopoDS::Vertex( vertex ), theMeshDS);
2082 // SMDS_NodeIteratorPtr nIt = smDS->GetNodes();
2083 // while ( nIt->more() )
2084 // n2nDegen.insert( make_pair( nIt->next(), vNode ));
2091 // const bool isQuadMesh =
2092 // theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
2093 // theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
2094 // theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC );
2096 // std::vector<std::vector<double> > VerTab;
2097 // std::set<std::vector<double> > VerMap;
2099 // std::vector<double> aVerTab;
2100 // // Loop from 1 to NB_NODES
2102 // nodeIt = theMeshDS->nodesIterator();
2104 // while ( nodeIt->more() )
2106 // node = nodeIt->next();
2107 // if ( isQuadMesh && theHelper.IsMedium( node )) // Issue 0021238
2109 // if ( n2nDegen.count( node ) ) // Issue 0020674
2112 // std::vector<double> coords;
2113 // coords.push_back(node->X());
2114 // coords.push_back(node->Y());
2115 // coords.push_back(node->Z());
2116 // if (VerMap.find(coords) != VerMap.end()) {
2117 // aGhs3dID = theSmdsToGhs3dIdMap[node->GetID()];
2118 // theGhs3dIdToNodeMap[theSmdsToGhs3dIdMap[node->GetID()]] = node;
2121 // VerTab.push_back(coords);
2122 // VerMap.insert(coords);
2124 // theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID ));
2125 // theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node ));
2129 // /* ENFORCED NODES ========================== */
2131 // std::cout << "Add " << nben << " enforced nodes to input .mesh file" << std::endl;
2132 // for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt) {
2133 // double x = (*enfNodeIt)->X();
2134 // double y = (*enfNodeIt)->Y();
2135 // double z = (*enfNodeIt)->Z();
2136 // // Test if point is inside shape to mesh
2137 // gp_Pnt myPoint(x,y,z);
2138 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2139 // scl.Perform(myPoint, 1e-7);
2140 // TopAbs_State result = scl.State();
2141 // if ( result != TopAbs_IN )
2143 // std::vector<double> coords;
2144 // coords.push_back(x);
2145 // coords.push_back(y);
2146 // coords.push_back(z);
2147 // if (theEnforcedVertices.find(coords) != theEnforcedVertices.end())
2149 // if (VerMap.find(coords) != VerMap.end())
2151 // VerTab.push_back(coords);
2152 // VerMap.insert(coords);
2154 // theNodeId2NodeIndexMap.insert( make_pair( (*enfNodeIt)->GetID(), aGhs3dID ));
2159 // /* ENFORCED VERTICES ========================== */
2161 // std::vector<std::vector<double> > ReqVerTab;
2162 // ReqVerTab.clear();
2164 // std::cout << "Add " << nbev << " enforced vertices to input .mesh file" << std::endl;
2165 // for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
2166 // double x = vertexIt->first[0];
2167 // double y = vertexIt->first[1];
2168 // double z = vertexIt->first[2];
2169 // // Test if point is inside shape to mesh
2170 // gp_Pnt myPoint(x,y,z);
2171 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2172 // scl.Perform(myPoint, 1e-7);
2173 // TopAbs_State result = scl.State();
2174 // if ( result != TopAbs_IN )
2176 // enfVertexSizes.push_back(vertexIt->second);
2177 // std::vector<double> coords;
2178 // coords.push_back(x);
2179 // coords.push_back(y);
2180 // coords.push_back(z);
2181 // if (VerMap.find(coords) != VerMap.end())
2183 // ReqVerTab.push_back(coords);
2184 // VerMap.insert(coords);
2190 // /* ========================== FACES ========================== */
2192 // int nbTriangles = 0/*, nbQuadrangles = 0*/, aSmdsID;
2193 // TopTools_IndexedMapOfShape facesMap, trianglesMap/*, quadranglesMap*/;
2194 // TIDSortedElemSet::const_iterator elemIt;
2195 // const SMESHDS_SubMesh* theSubMesh;
2196 // TopoDS_Shape aShape;
2197 // SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace;
2198 // const SMDS_MeshElement* aFace;
2199 // map<int,int>::const_iterator itOnMap;
2200 // std::vector<std::vector<int> > tt, qt,et;
2204 // std::vector<int> att, aqt, aet;
2206 // TopExp::MapShapes( theMeshDS->ShapeToMesh(), TopAbs_FACE, facesMap );
2208 // for ( int i = 1; i <= facesMap.Extent(); ++i )
2209 // if (( theSubMesh = theProxyMesh.GetSubMesh( facesMap(i))))
2211 // SMDS_ElemIteratorPtr it = theSubMesh->GetElements();
2212 // while (it->more())
2214 // const SMDS_MeshElement *elem = it->next();
2215 // int nbCornerNodes = elem->NbCornerNodes();
2216 // if (nbCornerNodes == 3)
2218 // trianglesMap.Add(facesMap(i));
2221 // // else if (nbCornerNodes == 4)
2223 // // quadranglesMap.Add(facesMap(i));
2224 // // nbQuadrangles ++;
2229 // /* TRIANGLES ========================== */
2230 // if (nbTriangles) {
2231 // for ( int i = 1; i <= trianglesMap.Extent(); i++ )
2233 // aShape = trianglesMap(i);
2234 // theSubMesh = theProxyMesh.GetSubMesh(aShape);
2235 // if ( !theSubMesh ) continue;
2236 // itOnSubMesh = theSubMesh->GetElements();
2237 // while ( itOnSubMesh->more() )
2239 // aFace = itOnSubMesh->next();
2240 // itOnSubFace = aFace->nodesIterator();
2242 // for ( int j = 0; j < 3; ++j ) {
2244 // node = castToNode( itOnSubFace->next() );
2245 // if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() )
2246 // node = n2nDegenIt->second;
2247 // aSmdsID = node->GetID();
2248 // itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
2249 // ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
2250 // att.push_back((*itOnMap).second);
2252 // tt.push_back(att);
2257 // if (theEnforcedTriangles.size()) {
2258 // std::cout << "Add " << theEnforcedTriangles.size() << " enforced triangles to input .mesh file" << std::endl;
2259 // // Iterate over the enforced triangles
2260 // for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
2261 // aFace = (*elemIt);
2262 // itOnSubFace = aFace->nodesIterator();
2263 // bool isOK = true;
2266 // for ( int j = 0; j < 3; ++j ) {
2267 // node = castToNode( itOnSubFace->next() );
2268 // if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() )
2269 // node = n2nDegenIt->second;
2270 // // std::cout << node;
2271 // double x = node->X();
2272 // double y = node->Y();
2273 // double z = node->Z();
2274 // // Test if point is inside shape to mesh
2275 // gp_Pnt myPoint(x,y,z);
2276 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2277 // scl.Perform(myPoint, 1e-7);
2278 // TopAbs_State result = scl.State();
2279 // if ( result != TopAbs_IN ) {
2281 // theEnforcedTriangles.erase(elemIt);
2284 // std::vector<double> coords;
2285 // coords.push_back(x);
2286 // coords.push_back(y);
2287 // coords.push_back(z);
2288 // if (VerMap.find(coords) != VerMap.end()) {
2289 // att.push_back(theNodeId2NodeIndexMap[node->GetID()]);
2292 // VerTab.push_back(coords);
2293 // VerMap.insert(coords);
2295 // theNodeId2NodeIndexMap.insert( make_pair( node->GetID(), aGhs3dID ));
2296 // att.push_back(aGhs3dID);
2299 // tt.push_back(att);
2304 // /* ========================== EDGES ========================== */
2306 // if (theEnforcedEdges.size()) {
2307 // // Iterate over the enforced edges
2308 // std::cout << "Add " << theEnforcedEdges.size() << " enforced edges to input .mesh file" << std::endl;
2309 // for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
2310 // aFace = (*elemIt);
2311 // bool isOK = true;
2312 // itOnSubFace = aFace->nodesIterator();
2314 // for ( int j = 0; j < 2; ++j ) {
2315 // node = castToNode( itOnSubFace->next() );
2316 // if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() )
2317 // node = n2nDegenIt->second;
2318 // double x = node->X();
2319 // double y = node->Y();
2320 // double z = node->Z();
2321 // // Test if point is inside shape to mesh
2322 // gp_Pnt myPoint(x,y,z);
2323 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2324 // scl.Perform(myPoint, 1e-7);
2325 // TopAbs_State result = scl.State();
2326 // if ( result != TopAbs_IN ) {
2328 // theEnforcedEdges.erase(elemIt);
2331 // std::vector<double> coords;
2332 // coords.push_back(x);
2333 // coords.push_back(y);
2334 // coords.push_back(z);
2335 // if (VerMap.find(coords) != VerMap.end()) {
2336 // aet.push_back(theNodeId2NodeIndexMap[node->GetID()]);
2339 // VerTab.push_back(coords);
2340 // VerMap.insert(coords);
2343 // theNodeId2NodeIndexMap.insert( make_pair( node->GetID(), aGhs3dID ));
2344 // aet.push_back(aGhs3dID);
2347 // et.push_back(aet);
2352 // /* Write vertices number */
2353 // MESSAGE("Number of vertices: "<<aGhs3dID);
2354 // MESSAGE("Size of vector: "<<VerTab.size());
2355 // GmfSetKwd(idx, GmfVertices, aGhs3dID/*+solSize*/);
2356 // for (int i=0;i<aGhs3dID;i++)
2357 // GmfSetLin(idx, GmfVertices, VerTab[i][0], VerTab[i][1], VerTab[i][2], dummyint);
2358 // // for (int i=0;i<solSize;i++) {
2359 // // std::cout << ReqVerTab[i][0] <<" "<< ReqVerTab[i][1] << " "<< ReqVerTab[i][2] << std::endl;
2360 // // GmfSetLin(idx, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
2364 // idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
2365 // if (!idxRequired) {
2366 // GmfCloseMesh(idx);
2369 // idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
2371 // GmfCloseMesh(idx);
2373 // GmfCloseMesh(idxRequired);
2377 // int TypTab[] = {GmfSca};
2378 // GmfSetKwd(idxRequired, GmfVertices, solSize);
2379 // GmfSetKwd(idxSol, GmfSolAtVertices, solSize, 1, TypTab);
2381 // for (int i=0;i<solSize;i++) {
2382 // double solTab[] = {enfVertexSizes.at(i)};
2383 // GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
2384 // GmfSetLin(idxSol, GmfSolAtVertices, solTab);
2386 // GmfCloseMesh(idxRequired);
2387 // GmfCloseMesh(idxSol);
2390 // /* Write triangles number */
2392 // GmfSetKwd(idx, GmfTriangles, tt.size());
2393 // for (int i=0;i<tt.size();i++)
2394 // GmfSetLin(idx, GmfTriangles, tt[i][0], tt[i][1], tt[i][2], dummyint);
2397 // /* Write edges number */
2399 // GmfSetKwd(idx, GmfEdges, et.size());
2400 // for (int i=0;i<et.size();i++)
2401 // GmfSetLin(idx, GmfEdges, et[i][0], et[i][1], dummyint);
2404 // /* QUADRANGLES ========================== */
2405 // // TODO: add pyramids ?
2406 // // if (nbQuadrangles) {
2407 // // for ( int i = 1; i <= quadranglesMap.Extent(); i++ )
2409 // // aShape = quadranglesMap(i);
2410 // // theSubMesh = theProxyMesh.GetSubMesh(aShape);
2411 // // if ( !theSubMesh ) continue;
2412 // // itOnSubMesh = theSubMesh->GetElements();
2413 // // for ( int j = 0; j < 4; ++j )
2415 // // aFace = itOnSubMesh->next();
2416 // // itOnSubFace = aFace->nodesIterator();
2418 // // while ( itOnSubFace->more() ) {
2419 // // // find GHS3D ID
2420 // // aSmdsID = itOnSubFace->next()->GetID();
2421 // // itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
2422 // // ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
2423 // // aqt.push_back((*itOnMap).second);
2425 // // qt.push_back(aqt);
2430 // // if (theEnforcedQuadrangles.size()) {
2431 // // // Iterate over the enforced triangles
2432 // // for(elemIt = theEnforcedQuadrangles.begin() ; elemIt != theEnforcedQuadrangles.end() ; ++elemIt) {
2433 // // aFace = (*elemIt);
2434 // // bool isOK = true;
2435 // // itOnSubFace = aFace->nodesIterator();
2437 // // for ( int j = 0; j < 4; ++j ) {
2438 // // int aNodeID = itOnSubFace->next()->GetID();
2439 // // itOnMap = theNodeId2NodeIndexMap.find(aNodeID);
2440 // // if (itOnMap != theNodeId2NodeIndexMap.end())
2441 // // aqt.push_back((*itOnMap).second);
2444 // // theEnforcedQuadrangles.erase(elemIt);
2449 // // qt.push_back(aqt);
2454 // // /* Write quadrilaterals number */
2455 // // if (qt.size()) {
2456 // // GmfSetKwd(idx, GmfQuadrilaterals, qt.size());
2457 // // for (int i=0;i<qt.size();i++)
2458 // // GmfSetLin(idx, GmfQuadrilaterals, qt[i][0], qt[i][1], qt[i][2], qt[i][3], dummyint);
2461 // GmfCloseMesh(idx);
2466 //=======================================================================
2467 //function : writeFaces
2469 //=======================================================================
2471 static bool writeFaces (ofstream & theFile,
2472 const SMESH_ProxyMesh& theMesh,
2473 const TopoDS_Shape& theShape,
2474 const map <int,int> & theSmdsToGhs3dIdMap,
2475 const map <int,int> & theEnforcedNodeIdToGhs3dIdMap,
2476 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
2477 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles)
2479 // record structure:
2481 // NB_ELEMS DUMMY_INT
2482 // Loop from 1 to NB_ELEMS
2483 // NB_NODES NODE_NB_1 NODE_NB_2 ... (NB_NODES + 1) times: DUMMY_INT
2485 TopoDS_Shape aShape;
2486 const SMESHDS_SubMesh* theSubMesh;
2487 const SMDS_MeshElement* aFace;
2488 const char* space = " ";
2489 const int dummyint = 0;
2490 map<int,int>::const_iterator itOnMap;
2491 SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace;
2492 int nbNodes, aSmdsID;
2494 TIDSortedElemSet::const_iterator elemIt;
2495 int nbEnforcedEdges = theEnforcedEdges.size();
2496 int nbEnforcedTriangles = theEnforcedTriangles.size();
2498 // count triangles bound to geometry
2499 int nbTriangles = 0;
2501 TopTools_IndexedMapOfShape facesMap, trianglesMap;
2502 TopExp::MapShapes( theShape, TopAbs_FACE, facesMap );
2504 int nbFaces = facesMap.Extent();
2506 for ( int i = 1; i <= nbFaces; ++i )
2507 if (( theSubMesh = theMesh.GetSubMesh( facesMap(i))))
2508 nbTriangles += theSubMesh->NbElements();
2510 (nbFaces == 0 || nbFaces == 1) ? tmpStr = " shape " : tmpStr = " shapes " ;
2511 std::cout << " " << nbFaces << tmpStr << "of 2D dimension";
2512 int nbEnforcedElements = nbEnforcedEdges+nbEnforcedTriangles;
2513 if (nbEnforcedElements > 0) {
2514 (nbEnforcedElements == 1) ? tmpStr = "shape:" : tmpStr = "shapes:";
2515 std::cout << " and" << std::endl;
2516 std::cout << " " << nbEnforcedElements
2517 << " enforced " << tmpStr << std::endl;
2520 std::cout << std::endl;
2521 if (nbEnforcedEdges) {
2522 (nbEnforcedEdges == 1) ? tmpStr = "edge" : tmpStr = "edges";
2523 std::cout << " " << nbEnforcedEdges << " enforced " << tmpStr << std::endl;
2525 if (nbEnforcedTriangles) {
2526 (nbEnforcedTriangles == 1) ? tmpStr = "triangle" : tmpStr = "triangles";
2527 std::cout << " " << nbEnforcedTriangles << " enforced " << tmpStr << std::endl;
2529 std::cout << std::endl;
2531 // theFile << space << nbTriangles << space << dummyint << std::endl;
2532 std::ostringstream globalStream, localStream, aStream;
2534 for ( int i = 1; i <= facesMap.Extent(); i++ )
2536 aShape = facesMap(i);
2537 theSubMesh = theMesh.GetSubMesh(aShape);
2538 if ( !theSubMesh ) continue;
2539 itOnSubMesh = theSubMesh->GetElements();
2540 while ( itOnSubMesh->more() )
2542 aFace = itOnSubMesh->next();
2543 nbNodes = aFace->NbCornerNodes();
2545 localStream << nbNodes << space;
2547 itOnSubFace = aFace->nodesIterator();
2548 for ( int j = 0; j < 3; ++j ) {
2550 aSmdsID = itOnSubFace->next()->GetID();
2551 itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
2552 // if ( itOnMap == theSmdsToGhs3dIdMap.end() ) {
2553 // cout << "not found node: " << aSmdsID << endl;
2556 ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
2558 localStream << (*itOnMap).second << space ;
2561 // (NB_NODES + 1) times: DUMMY_INT
2562 for ( int j=0; j<=nbNodes; j++)
2563 localStream << dummyint << space ;
2565 localStream << std::endl;
2569 globalStream << localStream.str();
2570 localStream.str("");
2577 // // ENFORCED EDGES : BEGIN
2580 // // Iterate over the enforced edges
2581 // int usedEnforcedEdges = 0;
2583 // for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
2584 // aFace = (*elemIt);
2586 // itOnSubFace = aFace->nodesIterator();
2588 // aStream << "2" << space ;
2589 // for ( int j = 0; j < 2; ++j ) {
2590 // aSmdsID = itOnSubFace->next()->GetID();
2591 // itOnMap = theEnforcedNodeIdToGhs3dIdMap.find(aSmdsID);
2592 // if (itOnMap != theEnforcedNodeIdToGhs3dIdMap.end())
2593 // aStream << (*itOnMap).second << space;
2600 // for ( int j=0; j<=2; j++)
2601 // aStream << dummyint << space ;
2602 // // aStream << dummyint << space << dummyint;
2603 // localStream << aStream.str() << std::endl;
2604 // usedEnforcedEdges++;
2608 // if (usedEnforcedEdges) {
2609 // globalStream << localStream.str();
2610 // localStream.str("");
2614 // // ENFORCED EDGES : END
2619 // // ENFORCED TRIANGLES : BEGIN
2621 // // Iterate over the enforced triangles
2622 // int usedEnforcedTriangles = 0;
2623 // for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
2624 // aFace = (*elemIt);
2625 // nbNodes = aFace->NbCornerNodes();
2627 // itOnSubFace = aFace->nodesIterator();
2629 // aStream << nbNodes << space ;
2630 // for ( int j = 0; j < 3; ++j ) {
2631 // aSmdsID = itOnSubFace->next()->GetID();
2632 // itOnMap = theEnforcedNodeIdToGhs3dIdMap.find(aSmdsID);
2633 // if (itOnMap != theEnforcedNodeIdToGhs3dIdMap.end())
2634 // aStream << (*itOnMap).second << space;
2641 // for ( int j=0; j<=3; j++)
2642 // aStream << dummyint << space ;
2643 // localStream << aStream.str() << std::endl;
2644 // usedEnforcedTriangles++;
2648 // if (usedEnforcedTriangles) {
2649 // globalStream << localStream.str();
2650 // localStream.str("");
2654 // // ENFORCED TRIANGLES : END
2658 << nbTriangles/*+usedEnforcedTriangles+usedEnforcedEdges*/
2659 << " 0" << std::endl
2660 << globalStream.str();
2665 //=======================================================================
2666 //function : writePoints
2668 //=======================================================================
2670 static bool writePoints (ofstream & theFile,
2671 SMESH_MesherHelper& theHelper,
2672 map <int,int> & theSmdsToGhs3dIdMap,
2673 map <int,int> & theEnforcedNodeIdToGhs3dIdMap,
2674 map <int,const SMDS_MeshNode*> & theGhs3dIdToNodeMap,
2675 GHS3DPlugin_Hypothesis::TID2SizeMap & theNodeIDToSizeMap,
2676 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices,
2677 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes,
2678 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
2679 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles)
2681 // record structure:
2684 // Loop from 1 to NB_NODES
2687 SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS();
2688 int nbNodes = theMeshDS->NbNodes();
2692 int nbEnforcedVertices = theEnforcedVertices.size();
2693 int nbEnforcedNodes = theEnforcedNodes.size();
2695 const TopoDS_Shape shapeToMesh = theMeshDS->ShapeToMesh();
2698 SMDS_NodeIteratorPtr nodeIt = theMeshDS->nodesIterator();
2699 const SMDS_MeshNode* node;
2701 // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D
2702 // The problem is in nodes on degenerated edges, we need to skip nodes which are free
2703 // and replace not-free nodes on degenerated edges by the node on vertex
2704 TNodeNodeMap n2nDegen; // map a node on degenerated edge to a node on vertex
2705 TNodeNodeMap::iterator n2nDegenIt;
2706 if ( theHelper.HasDegeneratedEdges() )
2709 for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next())
2711 SMESH_subMesh* sm = theHelper.GetMesh()->GetSubMesh( e.Current() );
2712 if ( checkedSM.insert( sm->GetId() ).second && theHelper.IsDegenShape(sm->GetId() ))
2714 if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() )
2716 TopoDS_Shape vertex = TopoDS_Iterator( e.Current() ).Value();
2717 const SMDS_MeshNode* vNode = SMESH_Algo::VertexNode( TopoDS::Vertex( vertex ), theMeshDS);
2719 SMDS_NodeIteratorPtr nIt = smDS->GetNodes();
2720 while ( nIt->more() )
2721 n2nDegen.insert( make_pair( nIt->next(), vNode ));
2726 nbNodes -= n2nDegen.size();
2729 const bool isQuadMesh =
2730 theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
2731 theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
2732 theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC );
2735 // descrease nbNodes by nb of medium nodes
2736 while ( nodeIt->more() )
2738 node = nodeIt->next();
2739 if ( !theHelper.IsDegenShape( node->getshapeId() ))
2740 nbNodes -= int( theHelper.IsMedium( node ));
2742 nodeIt = theMeshDS->nodesIterator();
2745 const char* space = " ";
2746 const int dummyint = 0;
2749 (nbNodes == 0 || nbNodes == 1) ? tmpStr = " node" : tmpStr = " nodes";
2751 std::cout << std::endl;
2752 std::cout << "The initial 2D mesh contains :" << std::endl;
2753 std::cout << " " << nbNodes << tmpStr << std::endl;
2754 if (nbEnforcedVertices > 0) {
2755 (nbEnforcedVertices == 1) ? tmpStr = "vertex" : tmpStr = "vertices";
2756 std::cout << " " << nbEnforcedVertices << " enforced " << tmpStr << std::endl;
2758 if (nbEnforcedNodes > 0) {
2759 (nbEnforcedNodes == 1) ? tmpStr = "node" : tmpStr = "nodes";
2760 std::cout << " " << nbEnforcedNodes << " enforced " << tmpStr << std::endl;
2762 std::cout << std::endl;
2763 std::cout << "Start writing in 'points' file ..." << std::endl;
2765 theFile << nbNodes << std::endl;
2767 // Loop from 1 to NB_NODES
2769 while ( nodeIt->more() )
2771 node = nodeIt->next();
2772 if ( isQuadMesh && theHelper.IsMedium( node )) // Issue 0021238
2774 if ( n2nDegen.count( node ) ) // Issue 0020674
2777 theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID ));
2778 theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node ));
2783 << node->X() << space
2784 << node->Y() << space
2785 << node->Z() << space
2788 theFile << std::endl;
2792 // Iterate over the enforced nodes
2793 std::map<int,double> enfVertexIndexSizeMap;
2794 if (nbEnforcedNodes) {
2795 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator nodeIt = theEnforcedNodes.begin();
2796 for( ; nodeIt != theEnforcedNodes.end() ; ++nodeIt) {
2797 double x = nodeIt->first->X();
2798 double y = nodeIt->first->Y();
2799 double z = nodeIt->first->Z();
2800 // Test if point is inside shape to mesh
2801 gp_Pnt myPoint(x,y,z);
2802 BRepClass3d_SolidClassifier scl(shapeToMesh);
2803 scl.Perform(myPoint, 1e-7);
2804 TopAbs_State result = scl.State();
2805 if ( result != TopAbs_IN )
2807 std::vector<double> coords;
2808 coords.push_back(x);
2809 coords.push_back(y);
2810 coords.push_back(z);
2811 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end())
2814 // double size = theNodeIDToSizeMap.find(nodeIt->first->GetID())->second;
2815 // theGhs3dIdToNodeMap.insert( make_pair( nbNodes + i, (*nodeIt) ));
2816 // MESSAGE("Adding enforced node (" << x << "," << y <<"," << z << ")");
2817 // X Y Z PHY_SIZE DUMMY_INT
2823 << dummyint << space;
2824 theFile << std::endl;
2825 theEnforcedNodeIdToGhs3dIdMap.insert( make_pair( nodeIt->first->GetID(), aGhs3dID ));
2826 enfVertexIndexSizeMap[aGhs3dID] = -1;
2829 // MESSAGE("Enforced vertex (" << x << "," << y <<"," << z << ") is not inside the geometry: it was not added ");
2833 if (nbEnforcedVertices) {
2834 // Iterate over the enforced vertices
2835 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt = theEnforcedVertices.begin();
2836 for( ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
2837 double x = vertexIt->first[0];
2838 double y = vertexIt->first[1];
2839 double z = vertexIt->first[2];
2840 // Test if point is inside shape to mesh
2841 gp_Pnt myPoint(x,y,z);
2842 BRepClass3d_SolidClassifier scl(shapeToMesh);
2843 scl.Perform(myPoint, 1e-7);
2844 TopAbs_State result = scl.State();
2845 if ( result != TopAbs_IN )
2847 MESSAGE("Adding enforced vertex (" << x << "," << y <<"," << z << ") = " << vertexIt->second);
2848 // X Y Z PHY_SIZE DUMMY_INT
2853 << vertexIt->second << space
2854 << dummyint << space;
2855 theFile << std::endl;
2856 enfVertexIndexSizeMap[aGhs3dID] = vertexIt->second;
2862 std::cout << std::endl;
2863 std::cout << "End writing in 'points' file." << std::endl;
2868 //=======================================================================
2869 //function : readResultFile
2870 //purpose : readResultFile with geometry
2871 //=======================================================================
2873 static bool readResultFile(const int fileOpen,
2875 const char* fileName,
2877 GHS3DPlugin_GHS3D* theAlgo,
2878 SMESH_MesherHelper& theHelper,
2879 TopoDS_Shape tabShape[],
2882 map <int,const SMDS_MeshNode*>& theGhs3dIdToNodeMap,
2883 std::map <int,int> & theNodeId2NodeIndexMap,
2885 int nbEnforcedVertices,
2886 int nbEnforcedNodes,
2887 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
2888 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles)
2890 MESSAGE("GHS3DPlugin_GHS3D::readResultFile()");
2891 Kernel_Utils::Localizer loc;
2901 SMESHDS_Mesh* theMeshDS = theHelper.GetMeshDS();
2903 int nbElems, nbNodes, nbInputNodes;
2905 int ID, shapeID, ghs3dShapeID;
2908 nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() );
2910 int *tab, *tabID, *nodeID, *nodeAssigne;
2912 const SMDS_MeshNode **node;
2915 nodeID = new int[4];
2916 coord = new double[3];
2917 node = new const SMDS_MeshNode*[4];
2919 TopoDS_Shape aSolid;
2920 SMDS_MeshNode * aNewNode;
2921 map <int,const SMDS_MeshNode*>::iterator itOnNode;
2922 SMDS_MeshElement* aTet;
2927 // Read the file state
2928 fstat(fileOpen, &status);
2929 length = status.st_size;
2931 // Mapping the result file into memory
2933 HANDLE fd = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ,
2934 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2935 HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY,
2936 0, (DWORD)length, NULL);
2937 ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 );
2939 ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
2943 ptr = readMapIntLine(ptr, tab);
2948 nbInputNodes = tab[2];
2950 nodeAssigne = new int[ nbNodes+1 ];
2953 aSolid = tabShape[0];
2955 // Reading the nodeId
2956 for (int i=0; i < 4*nbElems; i++)
2957 strtol(ptr, &ptr, 10);
2959 MESSAGE("nbInputNodes: "<<nbInputNodes);
2960 MESSAGE("nbEnforcedVertices: "<<nbEnforcedVertices);
2961 MESSAGE("nbEnforcedNodes: "<<nbEnforcedNodes);
2962 // Reading the nodeCoor and update the nodeMap
2963 for (int iNode=1; iNode <= nbNodes; iNode++) {
2964 if(theAlgo->computeCanceled())
2966 for (int iCoor=0; iCoor < 3; iCoor++)
2967 coord[ iCoor ] = strtod(ptr, &ptr);
2968 nodeAssigne[ iNode ] = 1;
2969 if ( iNode > (nbInputNodes-(nbEnforcedVertices+nbEnforcedNodes)) ) {
2970 // Creating SMESH nodes
2971 // - for enforced vertices
2972 // - for vertices of forced edges
2973 // - for ghs3d nodes
2974 nodeAssigne[ iNode ] = 0;
2975 aNewNode = theMeshDS->AddNode( coord[0],coord[1],coord[2] );
2976 theGhs3dIdToNodeMap.insert(theGhs3dIdToNodeMap.end(), make_pair( iNode, aNewNode ));
2980 // Reading the number of triangles which corresponds to the number of sub-domains
2981 nbTriangle = strtol(ptr, &ptr, 10);
2983 tabID = new int[nbTriangle];
2984 for (int i=0; i < nbTriangle; i++) {
2985 if(theAlgo->computeCanceled())
2988 // find the solid corresponding to GHS3D sub-domain following
2989 // the technique proposed in GHS3D manual in chapter
2990 // "B.4 Subdomain (sub-region) assignment"
2991 int nodeId1 = strtol(ptr, &ptr, 10);
2992 int nodeId2 = strtol(ptr, &ptr, 10);
2993 int nodeId3 = strtol(ptr, &ptr, 10);
2994 if ( nbTriangle > 1 ) {
2995 const SMDS_MeshNode* n1 = theGhs3dIdToNodeMap[ nodeId1 ];
2996 const SMDS_MeshNode* n2 = theGhs3dIdToNodeMap[ nodeId2 ];
2997 const SMDS_MeshNode* n3 = theGhs3dIdToNodeMap[ nodeId3 ];
2998 if (!n1 || !n2 || !n3) {
3004 // tabID[i] = findShapeID( theHelper, n1, n2, n3, toMeshHoles );
3005 tabID[i] = findShapeID( *theHelper.GetMesh(), n1, n2, n3, toMeshHoles );
3006 // -- 0020330: Pb with ghs3d as a submesh
3007 // check that found shape is to be meshed
3008 if ( tabID[i] > 0 ) {
3009 const TopoDS_Shape& foundShape = theMeshDS->IndexToShape( tabID[i] );
3010 bool isToBeMeshed = false;
3011 for ( int iS = 0; !isToBeMeshed && iS < nbShape; ++iS )
3012 isToBeMeshed = foundShape.IsSame( tabShape[ iS ]);
3013 if ( !isToBeMeshed )
3016 // END -- 0020330: Pb with ghs3d as a submesh
3018 std::cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << std::endl;
3021 catch ( Standard_Failure & ex)
3024 std::cout << i+1 << " subdomain: Exception caugt: " << ex.GetMessageString() << std::endl;
3029 std::cout << i+1 << " subdomain: unknown exception caught " << std::endl;
3037 if ( nbTriangle <= nbShape ) // no holes
3038 toMeshHoles = true; // not avoid creating tetras in holes
3040 // Associating the tetrahedrons to the shapes
3041 shapeID = compoundID;
3042 for (int iElem = 0; iElem < nbElems; iElem++) {
3043 if(theAlgo->computeCanceled())
3045 for (int iNode = 0; iNode < 4; iNode++) {
3046 ID = strtol(tetraPtr, &tetraPtr, 10);
3047 itOnNode = theGhs3dIdToNodeMap.find(ID);
3048 node[ iNode ] = itOnNode->second;
3049 nodeID[ iNode ] = ID;
3051 // We always run GHS3D with "to mesh holes"==TRUE but we must not create
3052 // tetras within holes depending on hypo option,
3053 // so we first check if aTet is inside a hole and then create it
3054 //aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
3055 if ( nbTriangle > 1 ) {
3056 shapeID = HOLE_ID; // negative shapeID means not to create tetras if !toMeshHoles
3057 ghs3dShapeID = strtol(shapePtr, &shapePtr, 10) - IdShapeRef;
3058 if ( tabID[ ghs3dShapeID ] == 0 ) {
3060 aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape, &state);
3061 if ( toMeshHoles || state == TopAbs_IN )
3062 shapeID = theMeshDS->ShapeToIndex( aSolid );
3063 tabID[ ghs3dShapeID ] = shapeID;
3066 shapeID = tabID[ ghs3dShapeID ];
3068 else if ( nbShape > 1 ) {
3069 // Case where nbTriangle == 1 while nbShape == 2 encountered
3070 // with compound of 2 boxes and "To mesh holes"==False,
3071 // so there are no subdomains specified for each tetrahedron.
3072 // Try to guess a solid by a node already bound to shape
3074 for ( int i=0; i<4 && shapeID==0; i++ ) {
3075 if ( nodeAssigne[ nodeID[i] ] == 1 &&
3076 node[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE &&
3077 node[i]->getshapeId() > 1 )
3079 shapeID = node[i]->getshapeId();
3083 aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape);
3084 shapeID = theMeshDS->ShapeToIndex( aSolid );
3087 // set new nodes and tetrahedron onto the shape
3088 for ( int i=0; i<4; i++ ) {
3089 if ( nodeAssigne[ nodeID[i] ] == 0 ) {
3090 if ( shapeID != HOLE_ID )
3091 theMeshDS->SetNodeInVolume( node[i], shapeID );
3092 nodeAssigne[ nodeID[i] ] = shapeID;
3095 if ( toMeshHoles || shapeID != HOLE_ID ) {
3096 aTet = theHelper.AddVolume( node[1], node[0], node[2], node[3],
3097 /*id=*/0, /*force3d=*/false);
3098 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
3101 shapeIDs.insert( shapeID );
3105 // Add enforced elements
3106 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap::const_iterator elemIt;
3107 const SMDS_MeshElement* anElem;
3108 SMDS_ElemIteratorPtr itOnEnfElem;
3109 map<int,int>::const_iterator itOnMap;
3110 shapeID = compoundID;
3112 if (theEnforcedEdges.size()) {
3113 (theEnforcedEdges.size() <= 1) ? tmpStr = " enforced edge" : " enforced edges";
3114 std::cout << "Add " << theEnforcedEdges.size() << tmpStr << std::endl;
3115 std::vector< const SMDS_MeshNode* > node( 2 );
3116 // Iterate over the enforced edges
3117 for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
3118 anElem = elemIt->first;
3119 bool addElem = true;
3120 itOnEnfElem = anElem->nodesIterator();
3121 for ( int j = 0; j < 2; ++j ) {
3122 int aNodeID = itOnEnfElem->next()->GetID();
3123 itOnMap = theNodeId2NodeIndexMap.find(aNodeID);
3124 if (itOnMap != theNodeId2NodeIndexMap.end()) {
3125 itOnNode = theGhs3dIdToNodeMap.find((*itOnMap).second);
3126 if (itOnNode != theGhs3dIdToNodeMap.end()) {
3127 node.push_back((*itOnNode).second);
3128 // shapeID =(*itOnNode).second->getshapeId();
3137 aTet = theHelper.AddEdge( node[0], node[1], 0, false);
3138 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
3143 if (theEnforcedTriangles.size()) {
3144 (theEnforcedTriangles.size() <= 1) ? tmpStr = " enforced triangle" : " enforced triangles";
3145 std::cout << "Add " << theEnforcedTriangles.size() << " enforced triangles" << std::endl;
3146 std::vector< const SMDS_MeshNode* > node( 3 );
3147 // Iterate over the enforced triangles
3148 for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
3149 anElem = elemIt->first;
3150 bool addElem = true;
3151 itOnEnfElem = anElem->nodesIterator();
3152 for ( int j = 0; j < 3; ++j ) {
3153 int aNodeID = itOnEnfElem->next()->GetID();
3154 itOnMap = theNodeId2NodeIndexMap.find(aNodeID);
3155 if (itOnMap != theNodeId2NodeIndexMap.end()) {
3156 itOnNode = theGhs3dIdToNodeMap.find((*itOnMap).second);
3157 if (itOnNode != theGhs3dIdToNodeMap.end()) {
3158 node.push_back((*itOnNode).second);
3159 // shapeID =(*itOnNode).second->getshapeId();
3168 aTet = theHelper.AddFace( node[0], node[1], node[2], 0, false);
3169 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
3174 // Remove nodes of tetras inside holes if !toMeshHoles
3175 if ( !toMeshHoles ) {
3176 itOnNode = theGhs3dIdToNodeMap.find( nbInputNodes );
3177 for ( ; itOnNode != theGhs3dIdToNodeMap.end(); ++itOnNode) {
3178 ID = itOnNode->first;
3179 if ( nodeAssigne[ ID ] == HOLE_ID )
3180 theMeshDS->RemoveFreeNode( itOnNode->second, 0 );
3186 (nbElems <= 1) ? tmpStr = " tetrahedra" : " tetrahedrons";
3187 cout << nbElems << tmpStr << " have been associated to " << nbShape;
3188 (nbShape <= 1) ? tmpStr = " shape" : " shapes";
3189 cout << tmpStr << endl;
3192 UnmapViewOfFile(mapPtr);
3193 CloseHandle(hMapObject);
3196 munmap(mapPtr, length);
3205 delete [] nodeAssigne;
3209 if ( shapeIDs.size() != nbShape ) {
3210 (shapeIDs.size() <= 1) ? tmpStr = " solid" : " solids";
3211 std::cout << "Only " << shapeIDs.size() << tmpStr << " of " << nbShape << " found" << std::endl;
3212 for (int i=0; i<nbShape; i++) {
3213 shapeID = theMeshDS->ShapeToIndex( tabShape[i] );
3214 if ( shapeIDs.find( shapeID ) == shapeIDs.end() )
3215 std::cout << " Solid #" << shapeID << " not found" << std::endl;
3224 //=============================================================================
3226 *Here we are going to use the GHS3D mesher with geometry
3228 //=============================================================================
3230 bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
3231 const TopoDS_Shape& theShape)
3234 //SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
3236 // we count the number of shapes
3237 // _nbShape = countShape( meshDS, TopAbs_SOLID ); -- 0020330: Pb with ghs3d as a submesh
3239 TopExp_Explorer expBox ( theShape, TopAbs_SOLID );
3240 for ( ; expBox.More(); expBox.Next() )
3243 // create bounding box for every shape inside the compound
3246 TopoDS_Shape* tabShape;
3248 tabShape = new TopoDS_Shape[_nbShape];
3249 tabBox = new double*[_nbShape];
3250 for (int i=0; i<_nbShape; i++)
3251 tabBox[i] = new double[6];
3252 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
3254 for (expBox.ReInit(); expBox.More(); expBox.Next()) {
3255 tabShape[iShape] = expBox.Current();
3256 Bnd_Box BoundingBox;
3257 BRepBndLib::Add(expBox.Current(), BoundingBox);
3258 BoundingBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
3259 tabBox[iShape][0] = Xmin; tabBox[iShape][1] = Xmax;
3260 tabBox[iShape][2] = Ymin; tabBox[iShape][3] = Ymax;
3261 tabBox[iShape][4] = Zmin; tabBox[iShape][5] = Zmax;
3265 // a unique working file name
3266 // to avoid access to the same files by eg different users
3267 _genericName = GHS3DPlugin_Hypothesis::GetFileName(_hyp);
3268 TCollection_AsciiString aGenericName((char*) _genericName.c_str() );
3270 TCollection_AsciiString aResultFileName;
3271 TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log
3272 // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2)
3273 // TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName;
3274 // TCollection_AsciiString aGenericNameRequired = aGenericName + "_required";
3276 // aGMFFileName = aGenericName + ".mesh"; // GMF mesh file
3277 // aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file
3278 // aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file
3279 // aSolFileName = aGenericName + "_required.sol"; // GMF solution file
3281 // aGMFFileName = aGenericName + ".meshb"; // GMF mesh file
3282 // aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file
3283 // aRequiredVerticesFileName = aGenericNameRequired + ".meshb"; // GMF required vertices mesh file
3284 // aSolFileName = aGenericName + "_required.solb"; // GMF solution file
3287 TCollection_AsciiString aFacesFileName, aPointsFileName, aBadResFileName, aBbResFileName;
3289 aFacesFileName = aGenericName + ".faces"; // in faces
3290 aPointsFileName = aGenericName + ".points"; // in points
3291 aResultFileName = aGenericName + ".noboite";// out points and volumes
3292 aBadResFileName = aGenericName + ".boite"; // out bad result
3293 aBbResFileName = aGenericName + ".bb"; // out vertex stepsize
3295 // -----------------
3297 // -----------------
3299 ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out);
3300 ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out);
3303 aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open();
3305 INFOS( "Can't write into " << aFacesFileName);
3306 return error(SMESH_Comment("Can't write into ") << aFacesFileName);
3309 std::map <int,int> aNodeId2NodeIndexMap, aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap;
3310 std::map <int,const SMDS_MeshNode*> aGhs3dIdToNodeMap;
3311 std::map <int, int> nodeID2nodeIndexMap;
3312 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues coordsSizeMap = GHS3DPlugin_Hypothesis::GetEnforcedVerticesCoordsSize(_hyp);
3313 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = GHS3DPlugin_Hypothesis::GetEnforcedNodes(_hyp);
3314 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp);
3315 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp);
3316 // TIDSortedElemSet enforcedQuadrangles = GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp);
3317 GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp);
3319 int nbEnforcedVertices = coordsSizeMap.size();
3320 int nbEnforcedNodes = enforcedNodes.size();
3323 (nbEnforcedNodes <= 1) ? tmpStr = "node" : "nodes";
3324 std::cout << nbEnforcedNodes << " enforced " << tmpStr << " from hypo" << std::endl;
3325 (nbEnforcedVertices <= 1) ? tmpStr = "vertex" : "vertices";
3326 std::cout << nbEnforcedVertices << " enforced " << tmpStr << " from hypo" << std::endl;
3328 SMESH_MesherHelper helper( theMesh );
3329 helper.SetSubShape( theShape );
3332 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
3334 // make prisms on quadrangles
3335 if ( theMesh.NbQuadrangles() > 0 )
3337 vector<SMESH_ProxyMesh::Ptr> components;
3338 for (expBox.ReInit(); expBox.More(); expBox.Next())
3340 if ( _viscousLayersHyp )
3342 proxyMesh = _viscousLayersHyp->Compute( theMesh, expBox.Current() );
3346 StdMeshers_QuadToTriaAdaptor* q2t = new StdMeshers_QuadToTriaAdaptor;
3347 q2t->Compute( theMesh, expBox.Current(), proxyMesh.get() );
3348 components.push_back( SMESH_ProxyMesh::Ptr( q2t ));
3350 proxyMesh.reset( new SMESH_ProxyMesh( components ));
3352 // build viscous layers
3353 else if ( _viscousLayersHyp )
3355 proxyMesh = _viscousLayersHyp->Compute( theMesh, theShape );
3360 Ok = (writePoints( aPointsFile, helper,
3361 aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap, aGhs3dIdToNodeMap,
3363 coordsSizeMap, enforcedNodes, enforcedEdges, enforcedTriangles)
3365 writeFaces ( aFacesFile, *proxyMesh, theShape,
3366 aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap,
3367 enforcedEdges, enforcedTriangles ));
3368 // Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(),
3369 // helper, *proxyMesh,
3370 // aNodeId2NodeIndexMap, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap,
3371 // enforcedNodes, enforcedEdges, enforcedTriangles, /*enforcedQuadrangles,*/
3375 // Write aSmdsToGhs3dIdMap to temp file
3376 TCollection_AsciiString aSmdsToGhs3dIdMapFileName;
3377 aSmdsToGhs3dIdMapFileName = aGenericName + ".ids"; // ids relation
3378 ofstream aIdsFile ( aSmdsToGhs3dIdMapFileName.ToCString() , ios::out);
3379 Ok = aIdsFile.rdbuf()->is_open();
3381 INFOS( "Can't write into " << aSmdsToGhs3dIdMapFileName);
3382 return error(SMESH_Comment("Can't write into ") << aSmdsToGhs3dIdMapFileName);
3384 INFOS( "Writing ids relation into " << aSmdsToGhs3dIdMapFileName);
3385 aIdsFile << "Smds Ghs3d" << std::endl;
3386 map <int,int>::const_iterator myit;
3387 for (myit=aSmdsToGhs3dIdMap.begin() ; myit != aSmdsToGhs3dIdMap.end() ; ++myit) {
3388 aIdsFile << myit->first << " " << myit->second << std::endl;
3393 aPointsFile.close();
3396 if ( !_keepFiles ) {
3397 // removeFile( aGMFFileName );
3398 // removeFile( aRequiredVerticesFileName );
3399 // removeFile( aSolFileName );
3400 removeFile( aFacesFileName );
3401 removeFile( aPointsFileName );
3402 removeFile( aSmdsToGhs3dIdMapFileName );
3404 return error(COMPERR_BAD_INPUT_MESH);
3406 removeFile( aResultFileName ); // needed for boundary recovery module usage
3408 // -----------------
3410 // -----------------
3412 TCollection_AsciiString cmd( (char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp ).c_str() );
3413 cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read
3414 cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
3415 // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2)
3416 // cmd += TCollection_AsciiString(" --in ") + aGenericName;
3417 // cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired;
3418 // cmd += TCollection_AsciiString(" --out ") + aResultGMFFileName;
3419 // cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
3421 std::cout << std::endl;
3422 std::cout << "Ghs3d execution..." << std::endl;
3423 std::cout << cmd << std::endl;
3425 _compute_canceled = false;
3427 system( cmd.ToCString() ); // run
3429 std::cout << std::endl;
3430 std::cout << "End of Ghs3d execution !" << std::endl;
3436 // Mapping the result file
3439 fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
3440 if ( fileOpen < 0 ) {
3441 std::cout << std::endl;
3442 std::cout << "Can't open the " << aResultFileName.ToCString() << " GHS3D output file" << std::endl;
3443 std::cout << "Log: " << aLogFileName << std::endl;
3448 _hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles();
3450 helper.IsQuadraticSubMesh( theShape );
3451 helper.SetElementsOnShape( false );
3453 Ok = readResultFile( fileOpen,
3455 aResultFileName.ToCString(),
3458 /*theMesh, */helper, tabShape, tabBox, _nbShape,
3459 aGhs3dIdToNodeMap, aNodeId2NodeIndexMap,
3461 nbEnforcedVertices, nbEnforcedNodes,
3462 enforcedEdges, enforcedTriangles );
3464 // Ok = readGMFFile(
3465 // #ifndef GMF_HAS_SUBDOMAIN_INFO
3468 // aGenericName.ToCString(), theMesh,
3469 // _nbShape, tabShape, tabBox,
3470 // aGhs3dIdToNodeMap, toMeshHoles,
3471 // nbEnforcedVertices, nbEnforcedNodes);
3477 // ---------------------
3478 // remove working files
3479 // ---------------------
3484 removeFile( aLogFileName );
3486 if ( _hyp && _hyp->GetToMakeGroupsOfDomains() )
3487 error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since the mesh is on shape" );
3489 else if ( OSD_File( aLogFileName ).Size() > 0 )
3491 // get problem description from the log file
3492 _Ghs2smdsConvertor conv( aGhs3dIdToNodeMap );
3493 storeErrorDescription( aLogFileName, conv );
3497 // the log file is empty
3498 removeFile( aLogFileName );
3499 INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" );
3500 error(COMPERR_ALGO_FAILED, "ghs3d: command not found" );
3503 if ( !_keepFiles ) {
3505 if(_compute_canceled)
3506 removeFile( aLogFileName );
3507 removeFile( aFacesFileName );
3508 removeFile( aPointsFileName );
3509 removeFile( aResultFileName );
3510 removeFile( aBadResFileName );
3511 removeFile( aBbResFileName );
3512 removeFile( aSmdsToGhs3dIdMapFileName );
3514 std::cout << "<" << aResultFileName.ToCString() << "> GHS3D output file ";
3516 std::cout << "not ";
3517 std::cout << "treated !" << std::endl;
3518 std::cout << std::endl;
3520 _nbShape = 0; // re-initializing _nbShape for the next Compute() method call
3527 //=============================================================================
3529 *Here we are going to use the GHS3D mesher w/o geometry
3531 //=============================================================================
3532 bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
3533 SMESH_MesherHelper* theHelper)
3535 MESSAGE("GHS3DPlugin_GHS3D::Compute()");
3537 //SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
3538 TopoDS_Shape theShape = theHelper->GetSubShape();
3540 // a unique working file name
3541 // to avoid access to the same files by eg different users
3542 _genericName = GHS3DPlugin_Hypothesis::GetFileName(_hyp);
3543 TCollection_AsciiString aGenericName((char*) _genericName.c_str() );
3544 TCollection_AsciiString aGenericNameRequired = aGenericName + "_required";
3546 TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log
3547 TCollection_AsciiString aResultFileName;
3550 TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName;
3552 aGMFFileName = aGenericName + ".mesh"; // GMF mesh file
3553 aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file
3554 aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file
3555 aSolFileName = aGenericNameRequired + ".sol"; // GMF solution file
3557 // aGMFFileName = aGenericName + ".meshb"; // GMF mesh file
3558 // aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file
3559 // aRequiredVerticesFileName = aGenericNameRequired + ".meshb"; // GMF required vertices mesh file
3560 // aSolFileName = aGenericNameRequired + ".solb"; // GMF solution file
3563 std::map <int, int> nodeID2nodeIndexMap;
3564 std::map<std::vector<double>, std::string> enfVerticesWithGroup;
3565 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues coordsSizeMap;
3566 TopoDS_Shape GeomShape;
3567 // TopAbs_ShapeEnum GeomType;
3568 std::vector<double> coords;
3570 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* enfVertex;
3572 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList enfVertices = GHS3DPlugin_Hypothesis::GetEnforcedVertices(_hyp);
3573 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList::const_iterator enfVerIt = enfVertices.begin();
3575 for ( ; enfVerIt != enfVertices.end() ; ++enfVerIt)
3577 enfVertex = (*enfVerIt);
3578 // if (enfVertex->geomEntry.empty() && enfVertex->coords.size()) {
3579 if (enfVertex->coords.size()) {
3580 coordsSizeMap.insert(make_pair(enfVertex->coords,enfVertex->size));
3581 enfVerticesWithGroup.insert(make_pair(enfVertex->coords,enfVertex->groupName));
3582 // MESSAGE("enfVerticesWithGroup.insert(make_pair(("<<enfVertex->coords[0]<<","<<enfVertex->coords[1]<<","<<enfVertex->coords[2]<<"),\""<<enfVertex->groupName<<"\"))");
3585 // if (!enfVertex->geomEntry.empty()) {
3586 GeomShape = entryToShape(enfVertex->geomEntry);
3587 // GeomType = GeomShape.ShapeType();
3589 // if (!enfVertex->isCompound) {
3590 // // if (GeomType == TopAbs_VERTEX) {
3592 // aPnt = BRep_Tool::Pnt(TopoDS::Vertex(GeomShape));
3593 // coords.push_back(aPnt.X());
3594 // coords.push_back(aPnt.Y());
3595 // coords.push_back(aPnt.Z());
3596 // if (coordsSizeMap.find(coords) == coordsSizeMap.end()) {
3597 // coordsSizeMap.insert(make_pair(coords,enfVertex->size));
3598 // enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName));
3602 // // Group Management
3604 // if (GeomType == TopAbs_COMPOUND){
3605 for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){
3607 if (it.Value().ShapeType() == TopAbs_VERTEX){
3608 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(it.Value()));
3609 coords.push_back(aPnt.X());
3610 coords.push_back(aPnt.Y());
3611 coords.push_back(aPnt.Z());
3612 if (coordsSizeMap.find(coords) == coordsSizeMap.end()) {
3613 coordsSizeMap.insert(make_pair(coords,enfVertex->size));
3614 enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName));
3615 // MESSAGE("enfVerticesWithGroup.insert(make_pair(("<<coords[0]<<","<<coords[1]<<","<<coords[2]<<"),\""<<enfVertex->groupName<<"\"))");
3623 // const SMDS_MeshNode* enfNode;
3624 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = GHS3DPlugin_Hypothesis::GetEnforcedNodes(_hyp);
3625 // GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt = enforcedNodes.begin();
3626 // for ( ; enfNodeIt != enforcedNodes.end() ; ++enfNodeIt)
3628 // enfNode = enfNodeIt->first;
3630 // coords.push_back(enfNode->X());
3631 // coords.push_back(enfNode->Y());
3632 // coords.push_back(enfNode->Z());
3633 // if (enfVerticesWithGro
3634 // enfVerticesWithGroup.insert(make_pair(coords,enfNodeIt->second));
3638 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp);
3639 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp);
3640 // TIDSortedElemSet enforcedQuadrangles = GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp);
3641 GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp);
3645 int nbEnforcedVertices = coordsSizeMap.size();
3646 int nbEnforcedNodes = enforcedNodes.size();
3647 (nbEnforcedNodes <= 1) ? tmpStr = "node" : tmpStr = "nodes";
3648 std::cout << nbEnforcedNodes << " enforced " << tmpStr << " from hypo" << std::endl;
3649 (nbEnforcedVertices <= 1) ? tmpStr = "vertex" : tmpStr = "vertices";
3650 std::cout << nbEnforcedVertices << " enforced " << tmpStr << " from hypo" << std::endl;
3652 std::vector <const SMDS_MeshNode*> aNodeByGhs3dId, anEnforcedNodeByGhs3dId;
3653 std::map<const SMDS_MeshNode*,int> aNodeToGhs3dIdMap;
3654 std::vector<std::string> aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId;
3656 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
3657 if ( theMesh.NbQuadrangles() > 0 )
3659 StdMeshers_QuadToTriaAdaptor* aQuad2Trias = new StdMeshers_QuadToTriaAdaptor;
3660 aQuad2Trias->Compute( theMesh );
3661 proxyMesh.reset( aQuad2Trias );
3664 Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(),
3665 *proxyMesh, &theMesh,
3666 aNodeByGhs3dId, aNodeToGhs3dIdMap,
3667 aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId,
3668 enforcedNodes, enforcedEdges, enforcedTriangles,
3669 enfVerticesWithGroup, coordsSizeMap);
3672 // -----------------
3674 // -----------------
3676 TCollection_AsciiString cmd = TCollection_AsciiString((char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp, false ).c_str());
3678 cmd += TCollection_AsciiString(" --in ") + aGenericName;
3679 if ( nbEnforcedVertices + nbEnforcedNodes)
3680 cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired;
3681 cmd += TCollection_AsciiString(" --out ") + aResultFileName;
3682 cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
3684 std::cout << std::endl;
3685 std::cout << "Ghs3d execution..." << std::endl;
3686 std::cout << cmd << std::endl;
3688 _compute_canceled = false;
3690 system( cmd.ToCString() ); // run
3692 std::cout << std::endl;
3693 std::cout << "End of Ghs3d execution !" << std::endl;
3698 GHS3DPlugin_Hypothesis::TSetStrings groupsToRemove = GHS3DPlugin_Hypothesis::GetGroupsToRemove(_hyp);
3699 const bool toMakeGroupsOfDomains = GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains( _hyp );
3701 Ok = readGMFFile(aResultFileName.ToCString(),
3703 theHelper, theShape, aNodeByGhs3dId, aNodeToGhs3dIdMap,
3704 aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId,
3705 groupsToRemove, toMakeGroupsOfDomains);
3707 updateMeshGroups(theHelper->GetMesh(), groupsToRemove);
3708 removeEmptyGroupsOfDomains( theHelper->GetMesh() );
3711 GHS3DPlugin_Hypothesis* that = (GHS3DPlugin_Hypothesis*)this->_hyp;
3713 that->ClearGroupsToRemove();
3715 // ---------------------
3716 // remove working files
3717 // ---------------------
3722 removeFile( aLogFileName );
3724 if ( !toMakeGroupsOfDomains && _hyp && _hyp->GetToMakeGroupsOfDomains() )
3725 error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since 'toMeshHoles' is OFF." );
3727 else if ( OSD_File( aLogFileName ).Size() > 0 )
3729 // get problem description from the log file
3730 _Ghs2smdsConvertor conv( aNodeByGhs3dId );
3731 storeErrorDescription( aLogFileName, conv );
3734 // the log file is empty
3735 removeFile( aLogFileName );
3736 INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" );
3737 error(COMPERR_ALGO_FAILED, "ghs3d: command not found" );
3743 if(_compute_canceled)
3744 removeFile( aLogFileName );
3745 removeFile( aGMFFileName );
3746 removeFile( aResultFileName );
3747 removeFile( aRequiredVerticesFileName );
3748 removeFile( aSolFileName );
3753 void GHS3DPlugin_GHS3D::CancelCompute()
3755 _compute_canceled = true;
3758 std::string cmd = "ps xo pid,args | grep " + _genericName;
3759 //cmd += " | grep -e \"^ *[0-9]\\+ \\+" + GHS3DPlugin_Hypothesis::GetExeName() + "\"";
3760 cmd += " | awk '{print $1}' | xargs kill -9 > /dev/null 2>&1";
3761 system( cmd.c_str() );
3765 //================================================================================
3767 * \brief Provide human readable text by error code reported by ghs3d
3769 //================================================================================
3771 static string translateError(const int errNum)
3775 return "The surface mesh includes a face of type other than edge, "
3776 "triangle or quadrilateral. This face type is not supported.";
3778 return "Not enough memory for the face table.";
3780 return "Not enough memory.";
3782 return "Not enough memory.";
3784 return "Face is ignored.";
3786 return "End of file. Some data are missing in the file.";
3788 return "Read error on the file. There are wrong data in the file.";
3790 return "the metric file is inadequate (dimension other than 3).";
3792 return "the metric file is inadequate (values not per vertices).";
3794 return "the metric file contains more than one field.";
3796 return "the number of values in the \".bb\" (metric file) is incompatible with the expected"
3797 "value of number of mesh vertices in the \".noboite\" file.";
3799 return "Too many sub-domains.";
3801 return "the number of vertices is negative or null.";
3803 return "the number of faces is negative or null.";
3805 return "A face has a null vertex.";
3807 return "incompatible data.";
3809 return "the number of vertices is negative or null.";
3811 return "the number of vertices is negative or null (in the \".mesh\" file).";
3813 return "the number of faces is negative or null.";
3815 return "A face appears more than once in the input surface mesh.";
3817 return "An edge appears more than once in the input surface mesh.";
3819 return "A face has a vertex negative or null.";
3821 return "NOT ENOUGH MEMORY.";
3823 return "Not enough available memory.";
3825 return "Some initial points cannot be inserted. The surface mesh is probably very bad "
3826 "in terms of quality or the input list of points is wrong.";
3828 return "Some vertices are too close to one another or coincident.";
3830 return "Some vertices are too close to one another or coincident.";
3832 return "A vertex cannot be inserted.";
3834 return "There are at least two points considered as coincident.";
3836 return "Some vertices are too close to one another or coincident.";
3838 return "The surface mesh regeneration step has failed.";
3840 return "Constrained edge cannot be enforced.";
3842 return "Constrained face cannot be enforced.";
3844 return "Missing faces.";
3846 return "No guess to start the definition of the connected component(s).";
3848 return "The surface mesh includes at least one hole. The domain is not well defined.";
3850 return "Impossible to define a component.";
3852 return "The surface edge intersects another surface edge.";
3854 return "The surface edge intersects the surface face.";
3856 return "One boundary point lies within a surface face.";
3858 return "One surface edge intersects a surface face.";
3860 return "One boundary point lies within a surface edge.";
3862 return "Insufficient memory ressources detected due to a bad quality surface mesh leading "
3863 "to too many swaps.";
3865 return "Edge is unique (i.e., bounds a hole in the surface).";
3867 return "Presumably, the surface mesh is not compatible with the domain being processed.";
3869 return "Too many components, too many sub-domain.";
3871 return "The surface mesh includes at least one hole. "
3872 "Therefore there is no domain properly defined.";
3874 return "Statistics.";
3876 return "Statistics.";
3878 return "Warning, it is dramatically tedious to enforce the boundary items.";
3880 return "Not enough memory at this time, nevertheless, the program continues. "
3881 "The expected mesh will be correct but not really as large as required.";
3883 return "see above error code, resulting quality may be poor.";
3885 return "Not enough memory at this time, nevertheless, the program continues (warning).";
3887 return "Unknown face type.";
3890 return "End of file. Some data are missing in the file.";
3892 return "A too small volume element is detected.";
3894 return "There exists at least a null or negative volume element.";
3896 return "There exist null or negative volume elements.";
3898 return "A too small volume element is detected. A face is considered being degenerated.";
3900 return "Some element is suspected to be very bad shaped or wrong.";
3902 return "A too bad quality face is detected. This face is considered degenerated.";
3904 return "A too bad quality face is detected. This face is degenerated.";
3906 return "Presumably, the surface mesh is not compatible with the domain being processed.";
3908 return "Abnormal error occured, contact hotline.";
3910 return "Not enough memory for the face table.";
3912 return "The algorithm cannot run further. "
3913 "The surface mesh is probably very bad in terms of quality.";
3915 return "Bad vertex number.";
3920 //================================================================================
3922 * \brief Retrieve from a string given number of integers
3924 //================================================================================
3926 static char* getIds( char* ptr, int nbIds, vector<int>& ids )
3929 ids.reserve( nbIds );
3932 while ( !isdigit( *ptr )) ++ptr;
3933 if ( ptr[-1] == '-' ) --ptr;
3934 ids.push_back( strtol( ptr, &ptr, 10 ));
3940 //================================================================================
3942 * \brief Retrieve problem description form a log file
3943 * \retval bool - always false
3945 //================================================================================
3947 bool GHS3DPlugin_GHS3D::storeErrorDescription(const TCollection_AsciiString& logFile,
3948 const _Ghs2smdsConvertor & toSmdsConvertor )
3950 if(_compute_canceled)
3951 return error(SMESH_Comment("interruption initiated by user"));
3954 int file = ::_open (logFile.ToCString(), _O_RDONLY|_O_BINARY);
3956 int file = ::open (logFile.ToCString(), O_RDONLY);
3959 return error( SMESH_Comment("See ") << logFile << " for problem description");
3962 // struct stat status;
3963 // fstat(file, &status);
3964 // size_t length = status.st_size;
3965 off_t length = lseek( file, 0, SEEK_END);
3966 lseek( file, 0, SEEK_SET);
3969 vector< char > buf( length );
3970 int nBytesRead = ::read (file, & buf[0], length);
3972 char* ptr = & buf[0];
3973 char* bufEnd = ptr + nBytesRead;
3975 SMESH_Comment errDescription;
3977 enum { NODE = 1, EDGE, TRIA, VOL, ID = 1 };
3979 // look for errors "ERR #"
3981 set<string> foundErrorStr; // to avoid reporting same error several times
3982 set<int> elemErrorNums; // not to report different types of errors with bad elements
3983 while ( ++ptr < bufEnd )
3985 if ( strncmp( ptr, "ERR ", 4 ) != 0 )
3988 list<const SMDS_MeshElement*> badElems;
3989 vector<int> nodeIds;
3993 int errNum = strtol(ptr, &ptr, 10);
3994 switch ( errNum ) { // we treat errors enumerated in [SALOME platform 0019316] issue
3996 // The face number (numfac) with vertices (f 1, f 2, f 3) has a null vertex.
3997 ptr = getIds(ptr, NODE, nodeIds);
3998 ptr = getIds(ptr, TRIA, nodeIds);
3999 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4001 case 1000: // ERR 1000 : 1 3 2
4002 // Face (f 1, f 2, f 3) appears more than once in the input surface mesh.
4003 ptr = getIds(ptr, TRIA, nodeIds);
4004 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4007 // Edge (e1, e2) appears more than once in the input surface mesh
4008 ptr = getIds(ptr, EDGE, nodeIds);
4009 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4012 // Face (f 1, f 2, f 3) has a vertex negative or null
4013 ptr = getIds(ptr, TRIA, nodeIds);
4014 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4017 // Vertex v1 and vertex v2 are too close to one another or coincident (warning).
4018 ptr = getIds(ptr, NODE, nodeIds);
4019 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4020 ptr = getIds(ptr, NODE, nodeIds);
4021 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4024 // Vertex v1 cannot be inserted (warning).
4025 ptr = getIds(ptr, NODE, nodeIds);
4026 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4029 // There are at least two points whose distance is dist, i.e., considered as coincident
4030 case 2103: // ERR 2103 : 16 WITH 3
4031 // Vertex v1 and vertex v2 are too close to one another or coincident (warning).
4032 ptr = getIds(ptr, NODE, nodeIds);
4033 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4034 ptr = getIds(ptr, NODE, nodeIds);
4035 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4038 // Constrained edge (e1, e2) cannot be enforced (warning).
4039 ptr = getIds(ptr, EDGE, nodeIds);
4040 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4043 // Constrained face (f 1, f 2, f 3) cannot be enforced
4044 ptr = getIds(ptr, TRIA, nodeIds);
4045 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4047 case 3103: // ERR 3103 : 1 2 WITH 7 3
4048 // The surface edge (e1, e2) intersects another surface edge (e3, e4)
4049 ptr = getIds(ptr, EDGE, nodeIds);
4050 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4051 ptr = getIds(ptr, EDGE, nodeIds);
4052 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4054 case 3104: // ERR 3104 : 9 10 WITH 1 2 3
4055 // The surface edge (e1, e2) intersects the surface face (f 1, f 2, f 3)
4056 ptr = getIds(ptr, EDGE, nodeIds);
4057 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4058 ptr = getIds(ptr, TRIA, nodeIds);
4059 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4061 case 3105: // ERR 3105 : 8 IN 2 3 5
4062 // One boundary point (say p1) lies within a surface face (f 1, f 2, f 3)
4063 ptr = getIds(ptr, NODE, nodeIds);
4064 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4065 ptr = getIds(ptr, TRIA, nodeIds);
4066 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4069 // One surface edge (say e1, e2) intersects a surface face (f 1, f 2, f 3)
4070 ptr = getIds(ptr, EDGE, nodeIds);
4071 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4072 ptr = getIds(ptr, TRIA, nodeIds);
4073 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4075 case 3107: // ERR 3107 : 2 IN 4 1
4076 // One boundary point (say p1) lies within a surface edge (e1, e2) (stop).
4077 ptr = getIds(ptr, NODE, nodeIds);
4078 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4079 ptr = getIds(ptr, EDGE, nodeIds);
4080 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4082 case 3109: // ERR 3109 : EDGE 5 6 UNIQUE
4083 // Edge (e1, e2) is unique (i.e., bounds a hole in the surface)
4084 ptr = getIds(ptr, EDGE, nodeIds);
4085 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4087 case 9000: // ERR 9000
4088 // ELEMENT 261 WITH VERTICES : 7 396 -8 242
4089 // VOLUME : -1.11325045E+11 W.R.T. EPSILON 0.
4090 // A too small volume element is detected. Are reported the index of the element,
4091 // its four vertex indices, its volume and the tolerance threshold value
4092 ptr = getIds(ptr, ID, nodeIds);
4093 ptr = getIds(ptr, VOL, nodeIds);
4094 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4095 // even if all nodes found, volume it most probably invisible,
4096 // add its faces to demenstrate it anyhow
4098 vector<int> faceNodes( nodeIds.begin(), --nodeIds.end() ); // 012
4099 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4100 faceNodes[2] = nodeIds[3]; // 013
4101 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4102 faceNodes[1] = nodeIds[2]; // 023
4103 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4104 faceNodes[0] = nodeIds[1]; // 123
4105 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4108 case 9001: // ERR 9001
4109 // %% NUMBER OF NEGATIVE VOLUME TETS : 1
4110 // %% THE LARGEST NEGATIVE TET : 1.75376581E+11
4111 // %% NUMBER OF NULL VOLUME TETS : 0
4112 // There exists at least a null or negative volume element
4115 // There exist n null or negative volume elements
4118 // A too small volume element is detected
4121 // A too bad quality face is detected. This face is considered degenerated,
4122 // its index, its three vertex indices together with its quality value are reported
4123 break; // same as next
4124 case 9112: // ERR 9112
4125 // FACE 2 WITH VERTICES : 4 2 5
4126 // SMALL INRADIUS : 0.
4127 // A too bad quality face is detected. This face is degenerated,
4128 // its index, its three vertex indices together with its inradius are reported
4129 ptr = getIds(ptr, ID, nodeIds);
4130 ptr = getIds(ptr, TRIA, nodeIds);
4131 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4132 // add triangle edges as it most probably has zero area and hence invisible
4134 vector<int> edgeNodes(2);
4135 edgeNodes[0] = nodeIds[0]; edgeNodes[1] = nodeIds[1]; // 0-1
4136 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4137 edgeNodes[1] = nodeIds[2]; // 0-2
4138 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4139 edgeNodes[0] = nodeIds[1]; // 1-2
4140 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4145 bool isNewError = foundErrorStr.insert( string( errBeg, ptr )).second;
4147 continue; // not to report same error several times
4149 // const SMDS_MeshElement* nullElem = 0;
4150 // bool allElemsOk = ( find( badElems.begin(), badElems.end(), nullElem) == badElems.end());
4152 // if ( allElemsOk && !badElems.empty() && !elemErrorNums.empty() ) {
4153 // bool oneMoreErrorType = elemErrorNums.insert( errNum ).second;
4154 // if ( oneMoreErrorType )
4155 // continue; // not to report different types of errors with bad elements
4158 // store bad elements
4159 //if ( allElemsOk ) {
4160 list<const SMDS_MeshElement*>::iterator elem = badElems.begin();
4161 for ( ; elem != badElems.end(); ++elem )
4162 addBadInputElement( *elem );
4166 string text = translateError( errNum );
4167 if ( errDescription.find( text ) == text.npos ) {
4168 if ( !errDescription.empty() )
4169 errDescription << "\n";
4170 errDescription << text;
4175 if ( errDescription.empty() ) { // no errors found
4176 char msgLic1[] = "connection to server failed";
4177 char msgLic2[] = " Dlim ";
4178 if ( search( &buf[0], bufEnd, msgLic1, msgLic1 + strlen(msgLic1)) != bufEnd ||
4179 search( &buf[0], bufEnd, msgLic2, msgLic2 + strlen(msgLic2)) != bufEnd )
4180 errDescription << "Licence problems.";
4183 char msg2[] = "SEGMENTATION FAULT";
4184 if ( search( &buf[0], bufEnd, msg2, msg2 + strlen(msg2)) != bufEnd )
4185 errDescription << "ghs3d: SEGMENTATION FAULT. ";
4189 if ( errDescription.empty() )
4190 errDescription << "See " << logFile << " for problem description";
4192 errDescription << "\nSee " << logFile << " for more information";
4194 return error( errDescription );
4197 //================================================================================
4199 * \brief Creates _Ghs2smdsConvertor
4201 //================================================================================
4203 _Ghs2smdsConvertor::_Ghs2smdsConvertor( const map <int,const SMDS_MeshNode*> & ghs2NodeMap)
4204 :_ghs2NodeMap( & ghs2NodeMap ), _nodeByGhsId( 0 )
4208 //================================================================================
4210 * \brief Creates _Ghs2smdsConvertor
4212 //================================================================================
4214 _Ghs2smdsConvertor::_Ghs2smdsConvertor( const vector <const SMDS_MeshNode*> & nodeByGhsId)
4215 : _ghs2NodeMap( 0 ), _nodeByGhsId( &nodeByGhsId )
4219 //================================================================================
4221 * \brief Return SMDS element by ids of GHS3D nodes
4223 //================================================================================
4225 const SMDS_MeshElement* _Ghs2smdsConvertor::getElement(const vector<int>& ghsNodes) const
4227 size_t nbNodes = ghsNodes.size();
4228 vector<const SMDS_MeshNode*> nodes( nbNodes, 0 );
4229 for ( size_t i = 0; i < nbNodes; ++i ) {
4230 int ghsNode = ghsNodes[ i ];
4231 if ( _ghs2NodeMap ) {
4232 map <int,const SMDS_MeshNode*>::const_iterator in = _ghs2NodeMap->find( ghsNode);
4233 if ( in == _ghs2NodeMap->end() )
4235 nodes[ i ] = in->second;
4238 if ( ghsNode < 1 || ghsNode > _nodeByGhsId->size() )
4240 nodes[ i ] = (*_nodeByGhsId)[ ghsNode-1 ];
4246 if ( nbNodes == 2 ) {
4247 const SMDS_MeshElement* edge= SMDS_Mesh::FindEdge( nodes[0], nodes[1] );
4249 edge = new SMDS_LinearEdge( nodes[0], nodes[1] );
4252 if ( nbNodes == 3 ) {
4253 const SMDS_MeshElement* face = SMDS_Mesh::FindFace( nodes );
4255 face = new SMDS_FaceOfNodes( nodes[0], nodes[1], nodes[2] );
4259 return new SMDS_VolumeOfNodes( nodes[0], nodes[1], nodes[2], nodes[3] );
4265 //=============================================================================
4269 //=============================================================================
4270 bool GHS3DPlugin_GHS3D::Evaluate(SMESH_Mesh& aMesh,
4271 const TopoDS_Shape& aShape,
4272 MapShapeNbElems& aResMap)
4274 int nbtri = 0, nbqua = 0;
4275 double fullArea = 0.0;
4276 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
4277 TopoDS_Face F = TopoDS::Face( exp.Current() );
4278 SMESH_subMesh *sm = aMesh.GetSubMesh(F);
4279 MapShapeNbElemsItr anIt = aResMap.find(sm);
4280 if( anIt==aResMap.end() ) {
4281 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
4282 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,
4283 "Submesh can not be evaluated",this));
4286 std::vector<int> aVec = (*anIt).second;
4287 nbtri += Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
4288 nbqua += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
4290 BRepGProp::SurfaceProperties(F,G);
4291 double anArea = G.Mass();
4295 // collect info from edges
4296 int nb0d_e = 0, nb1d_e = 0;
4297 bool IsQuadratic = false;
4298 bool IsFirst = true;
4299 TopTools_MapOfShape tmpMap;
4300 for (TopExp_Explorer exp(aShape, TopAbs_EDGE); exp.More(); exp.Next()) {
4301 TopoDS_Edge E = TopoDS::Edge(exp.Current());
4302 if( tmpMap.Contains(E) )
4305 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
4306 MapShapeNbElemsItr anIt = aResMap.find(aSubMesh);
4307 std::vector<int> aVec = (*anIt).second;
4308 nb0d_e += aVec[SMDSEntity_Node];
4309 nb1d_e += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
4311 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
4317 double ELen = sqrt(2.* ( fullArea/(nbtri+nbqua*2) ) / sqrt(3.0) );
4320 BRepGProp::VolumeProperties(aShape,G);
4321 double aVolume = G.Mass();
4322 double tetrVol = 0.1179*ELen*ELen*ELen;
4323 double CoeffQuality = 0.9;
4324 int nbVols = int(aVolume/tetrVol/CoeffQuality);
4325 int nb1d_f = (nbtri*3 + nbqua*4 - nb1d_e) / 2;
4326 int nb1d_in = (int) ( nbVols*6 - nb1d_e - nb1d_f ) / 5;
4327 std::vector<int> aVec(SMDSEntity_Last);
4328 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i]=0;
4330 aVec[SMDSEntity_Node] = nb1d_in/6 + 1 + nb1d_in;
4331 aVec[SMDSEntity_Quad_Tetra] = nbVols - nbqua*2;
4332 aVec[SMDSEntity_Quad_Pyramid] = nbqua;
4335 aVec[SMDSEntity_Node] = nb1d_in/6 + 1;
4336 aVec[SMDSEntity_Tetra] = nbVols - nbqua*2;
4337 aVec[SMDSEntity_Pyramid] = nbqua;
4339 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
4340 aResMap.insert(std::make_pair(sm,aVec));
4345 bool GHS3DPlugin_GHS3D::importGMFMesh(const char* theGMFFileName, SMESH_Mesh& theMesh)
4347 SMESH_MesherHelper* helper = new SMESH_MesherHelper(theMesh );
4348 // TopoDS_Shape theShape = theMesh.GetShapeToMesh();
4349 std::vector <const SMDS_MeshNode*> dummyNodeVector;
4350 std::map<const SMDS_MeshNode*,int> dummyNodeMap;
4351 std::map<std::vector<double>, std::string> dummyEnfVertGroup;
4352 std::vector<std::string> dummyElemGroup;
4353 std::set<std::string> dummyGroupsToRemove;
4355 bool ok = readGMFFile(theGMFFileName,
4357 helper, theMesh.GetShapeToMesh(), dummyNodeVector, dummyNodeMap, dummyElemGroup, dummyElemGroup, dummyElemGroup, dummyGroupsToRemove);
4358 theMesh.GetMeshDS()->Modified();
4364 //================================================================================
4366 * \brief Sub-mesh event listener setting enforced elements as soon as an enforced
4369 struct _EnforcedMeshRestorer : public SMESH_subMeshEventListener
4371 _EnforcedMeshRestorer():
4372 SMESH_subMeshEventListener( /*isDeletable = */true, Name() )
4375 //================================================================================
4377 * \brief Returns an ID of listener
4379 static const char* Name() { return "GHS3DPlugin_GHS3D::_EnforcedMeshRestorer"; }
4381 //================================================================================
4383 * \brief Treat events of the subMesh
4385 void ProcessEvent(const int event,
4386 const int eventType,
4387 SMESH_subMesh* subMesh,
4388 SMESH_subMeshEventListenerData* data,
4389 const SMESH_Hypothesis* hyp)
4391 if ( SMESH_subMesh::SUBMESH_LOADED == event &&
4392 SMESH_subMesh::COMPUTE_EVENT == eventType &&
4394 !data->mySubMeshes.empty() )
4396 // An enforced mesh (subMesh->_father) has been loaded from hdf file
4397 if ( GHS3DPlugin_Hypothesis* hyp = GetGHSHypothesis( data->mySubMeshes.front() ))
4398 hyp->RestoreEnfElemsByMeshes();
4401 //================================================================================
4403 * \brief Returns GHS3DPlugin_Hypothesis used to compute a subMesh
4405 static GHS3DPlugin_Hypothesis* GetGHSHypothesis( SMESH_subMesh* subMesh )
4407 SMESH_HypoFilter ghsHypFilter( SMESH_HypoFilter::HasName( "GHS3D_Parameters" ));
4408 return (GHS3DPlugin_Hypothesis* )
4409 subMesh->GetFather()->GetHypothesis( subMesh->GetSubShape(),
4411 /*visitAncestors=*/true);
4415 //================================================================================
4417 * \brief Sub-mesh event listener removing empty groups created due to "To make
4418 * groups of domains".
4420 struct _GroupsOfDomainsRemover : public SMESH_subMeshEventListener
4422 _GroupsOfDomainsRemover():
4423 SMESH_subMeshEventListener( /*isDeletable = */true,
4424 "GHS3DPlugin_GHS3D::_GroupsOfDomainsRemover" ) {}
4426 * \brief Treat events of the subMesh
4428 void ProcessEvent(const int event,
4429 const int eventType,
4430 SMESH_subMesh* subMesh,
4431 SMESH_subMeshEventListenerData* data,
4432 const SMESH_Hypothesis* hyp)
4434 if (SMESH_subMesh::ALGO_EVENT == eventType &&
4435 !subMesh->GetAlgo() )
4437 removeEmptyGroupsOfDomains( subMesh->GetFather(), /*notEmptyAsWell=*/true );
4443 //================================================================================
4445 * \brief Set an event listener to set enforced elements as soon as an enforced
4448 //================================================================================
4450 void GHS3DPlugin_GHS3D::SubmeshRestored(SMESH_subMesh* subMesh)
4452 if ( GHS3DPlugin_Hypothesis* hyp = _EnforcedMeshRestorer::GetGHSHypothesis( subMesh ))
4454 GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList enfMeshes = hyp->_GetEnforcedMeshes();
4455 GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList::iterator it = enfMeshes.begin();
4456 for(;it != enfMeshes.end();++it) {
4457 GHS3DPlugin_Hypothesis::TGHS3DEnforcedMesh* enfMesh = *it;
4458 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
4460 SMESH_subMesh* smToListen = mesh->GetSubMesh( mesh->GetShapeToMesh() );
4461 // a listener set to smToListen will care of hypothesis stored in SMESH_EventListenerData
4462 subMesh->SetEventListener( new _EnforcedMeshRestorer(),
4463 SMESH_subMeshEventListenerData::MakeData( subMesh ),
4470 //================================================================================
4472 * \brief Sets an event listener removing empty groups created due to "To make
4473 * groups of domains".
4474 * \param subMesh - submesh where algo is set
4476 * This method is called when a submesh gets HYP_OK algo_state.
4477 * After being set, event listener is notified on each event of a submesh.
4479 //================================================================================
4481 void GHS3DPlugin_GHS3D::SetEventListener(SMESH_subMesh* subMesh)
4483 subMesh->SetEventListener( new _GroupsOfDomainsRemover(), 0, subMesh );