1 // Copyright (C) 2004-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //=============================================================================
21 // File : GHS3DPlugin_GHS3D.cxx
23 // Author : Edward AGAPOV, modified by Lioka RAZAFINDRAZAKA (CEA) 09/02/2007
25 //=============================================================================
27 #include "GHS3DPlugin_GHS3D.hxx"
28 #include "GHS3DPlugin_Hypothesis.hxx"
30 #include <Basics_Utils.hxx>
32 //#include <SMESH_Gen.hxx>
33 #include <SMESH_Client.hxx>
34 #include <SMESH_Mesh.hxx>
35 #include <SMESH_Comment.hxx>
36 #include <SMESH_MesherHelper.hxx>
37 #include <SMESH_MeshEditor.hxx>
38 #include <SMESH_OctreeNode.hxx>
39 #include <SMESH_Group.hxx>
40 #include <SMESH_subMeshEventListener.hxx>
41 #include <SMESH_HypoFilter.hxx>
42 #include <SMESH_MeshAlgos.hxx>
44 #include <SMDS_MeshElement.hxx>
45 #include <SMDS_MeshNode.hxx>
46 #include <SMDS_FaceOfNodes.hxx>
47 #include <SMDS_VolumeOfNodes.hxx>
49 #include <SMESHDS_Group.hxx>
51 #include <StdMeshers_QuadToTriaAdaptor.hxx>
52 #include <StdMeshers_ViscousLayers.hxx>
54 #include <BRepAdaptor_Surface.hxx>
55 #include <BRepBndLib.hxx>
56 #include <BRepBuilderAPI_MakeVertex.hxx>
57 #include <BRepClass3d_SolidClassifier.hxx>
58 #include <BRepExtrema_DistShapeShape.hxx>
59 #include <BRepGProp.hxx>
60 #include <BRepTools.hxx>
61 #include <BRep_Tool.hxx>
62 #include <Bnd_Box.hxx>
63 #include <GProp_GProps.hxx>
64 #include <GeomAPI_ProjectPointOnSurf.hxx>
65 #include <OSD_File.hxx>
66 #include <Precision.hxx>
67 #include <Quantity_Parameter.hxx>
68 #include <Standard_ErrorHandler.hxx>
69 #include <Standard_Failure.hxx>
70 #include <Standard_ProgramError.hxx>
72 #include <TopExp_Explorer.hxx>
73 #include <TopTools_IndexedMapOfShape.hxx>
74 #include <TopTools_ListIteratorOfListOfShape.hxx>
75 #include <TopTools_MapOfShape.hxx>
77 #include <TopoDS_Shape.hxx>
78 #include <TopoDS_Solid.hxx>
80 #include <utilities.h>
85 #include <sys/sysinfo.h>
89 //#include <Standard_Stream.hxx>
92 #define castToNode(n) static_cast<const SMDS_MeshNode *>( n );
105 #include <sys/mman.h>
107 #include <sys/stat.h>
113 typedef const list<const SMDS_MeshFace*> TTriaList;
115 static const char theDomainGroupNamePrefix[] = "Domain_";
117 static void removeFile( const TCollection_AsciiString& fileName )
120 OSD_File( fileName ).Remove();
122 catch ( Standard_ProgramError ) {
123 MESSAGE("Can't remove file: " << fileName.ToCString() << " ; file does not exist or permission denied");
127 //=============================================================================
131 //=============================================================================
133 GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D(int hypId, int studyId, SMESH_Gen* gen)
134 : SMESH_3D_Algo(hypId, studyId, gen)
136 MESSAGE("GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D");
138 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
139 _onlyUnaryInput = false; // Compute() will be called on a compound of solids
142 _compatibleHypothesis.push_back( GHS3DPlugin_Hypothesis::GetHypType());
143 _compatibleHypothesis.push_back( StdMeshers_ViscousLayers::GetHypType() );
144 _requireShape = false; // can work without shape_studyId
146 smeshGen_i = SMESH_Gen_i::GetSMESHGen();
147 CORBA::Object_var anObject = smeshGen_i->GetNS()->Resolve("/myStudyManager");
148 SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject);
150 MESSAGE("studyid = " << _studyId);
153 myStudy = aStudyMgr->GetStudyByID(_studyId);
155 MESSAGE("myStudy->StudyId() = " << myStudy->StudyId());
157 _compute_canceled = false;
160 //=============================================================================
164 //=============================================================================
166 GHS3DPlugin_GHS3D::~GHS3DPlugin_GHS3D()
168 MESSAGE("GHS3DPlugin_GHS3D::~GHS3DPlugin_GHS3D");
171 //=============================================================================
175 //=============================================================================
177 bool GHS3DPlugin_GHS3D::CheckHypothesis ( SMESH_Mesh& aMesh,
178 const TopoDS_Shape& aShape,
179 Hypothesis_Status& aStatus )
181 aStatus = SMESH_Hypothesis::HYP_OK;
184 _viscousLayersHyp = 0;
186 _removeLogOnSuccess = true;
187 _logInStandardOutput = false;
189 const list <const SMESHDS_Hypothesis * >& hyps =
190 GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliary=*/false);
191 list <const SMESHDS_Hypothesis* >::const_iterator h = hyps.begin();
192 for ( ; h != hyps.end(); ++h )
195 _hyp = dynamic_cast< const GHS3DPlugin_Hypothesis*> ( *h );
196 if ( !_viscousLayersHyp )
197 _viscousLayersHyp = dynamic_cast< const StdMeshers_ViscousLayers*> ( *h );
201 _keepFiles = _hyp->GetKeepFiles();
202 _removeLogOnSuccess = _hyp->GetRemoveLogOnSuccess();
203 _logInStandardOutput = _hyp->GetStandardOutputLog();
210 //=======================================================================
211 //function : entryToShape
213 //=======================================================================
215 TopoDS_Shape GHS3DPlugin_GHS3D::entryToShape(std::string entry)
217 MESSAGE("GHS3DPlugin_GHS3D::entryToShape "<<entry );
218 GEOM::GEOM_Object_var aGeomObj;
219 TopoDS_Shape S = TopoDS_Shape();
220 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
221 if (!aSObj->_is_nil() ) {
222 CORBA::Object_var obj = aSObj->GetObject();
223 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
226 if ( !aGeomObj->_is_nil() )
227 S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
231 //=======================================================================
232 //function : findShape
234 //=======================================================================
236 static TopoDS_Shape findShape(const SMDS_MeshNode *aNode[],
238 const TopoDS_Shape shape[],
241 TopAbs_State * state = 0)
244 int j, iShape, nbNode = 4;
246 for ( j=0; j<nbNode; j++ ) {
247 gp_XYZ p ( aNode[j]->X(), aNode[j]->Y(), aNode[j]->Z() );
248 if ( aNode[j]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE ) {
255 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
256 if (state) *state = SC.State();
257 if ( SC.State() != TopAbs_IN || aShape.IsNull() || aShape.ShapeType() != TopAbs_SOLID) {
258 for (iShape = 0; iShape < nShape; iShape++) {
259 aShape = shape[iShape];
260 if ( !( aPnt.X() < box[iShape][0] || box[iShape][1] < aPnt.X() ||
261 aPnt.Y() < box[iShape][2] || box[iShape][3] < aPnt.Y() ||
262 aPnt.Z() < box[iShape][4] || box[iShape][5] < aPnt.Z()) ) {
263 BRepClass3d_SolidClassifier SC (aShape, aPnt, Precision::Confusion());
264 if (state) *state = SC.State();
265 if (SC.State() == TopAbs_IN)
273 //=======================================================================
274 //function : readMapIntLine
276 //=======================================================================
278 static char* readMapIntLine(char* ptr, int tab[]) {
280 std::cout << std::endl;
282 for ( int i=0; i<17; i++ ) {
283 intVal = strtol(ptr, &ptr, 10);
290 //================================================================================
292 * \brief returns true if a triangle defined by the nodes is a temporary face on a
293 * side facet of pyramid and defines sub-domian inside the pyramid
295 //================================================================================
297 static bool isTmpFace(const SMDS_MeshNode* node1,
298 const SMDS_MeshNode* node2,
299 const SMDS_MeshNode* node3)
301 // find a pyramid sharing the 3 nodes
302 //const SMDS_MeshElement* pyram = 0;
303 SMDS_ElemIteratorPtr vIt1 = node1->GetInverseElementIterator(SMDSAbs_Volume);
304 while ( vIt1->more() )
306 const SMDS_MeshElement* pyram = vIt1->next();
307 if ( pyram->NbCornerNodes() != 5 ) continue;
309 if ( (i2 = pyram->GetNodeIndex( node2 )) >= 0 &&
310 (i3 = pyram->GetNodeIndex( node3 )) >= 0 )
312 // Triangle defines sub-domian inside the pyramid if it's
313 // normal points out of the pyram
315 // make i2 and i3 hold indices of base nodes of the pyram while
316 // keeping the nodes order in the triangle
319 i2 = i3, i3 = pyram->GetNodeIndex( node1 );
320 else if ( i3 == iApex )
321 i3 = i2, i2 = pyram->GetNodeIndex( node1 );
323 int i3base = (i2+1) % 4; // next index after i2 within the pyramid base
324 return ( i3base != i3 );
330 //=======================================================================
331 //function : findShapeID
332 //purpose : find the solid corresponding to GHS3D sub-domain following
333 // the technique proposed in GHS3D manual (available within
334 // ghs3d installation) in chapter "B.4 Subdomain (sub-region) assignment".
335 // In brief: normal of the triangle defined by the given nodes
336 // points out of the domain it is associated to
337 //=======================================================================
339 static int findShapeID(SMESH_Mesh& mesh,
340 const SMDS_MeshNode* node1,
341 const SMDS_MeshNode* node2,
342 const SMDS_MeshNode* node3,
343 const bool toMeshHoles)
345 const int invalidID = 0;
346 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
348 // face the nodes belong to
349 const SMDS_MeshElement * face = meshDS->FindFace(node1,node2,node3);
351 return isTmpFace(node1, node2, node3) ? HOLE_ID : invalidID;
353 std::cout << "bnd face " << face->GetID() << " - ";
355 // geom face the face assigned to
356 SMESH_MeshEditor editor(&mesh);
357 int geomFaceID = editor.FindShape( face );
359 return isTmpFace(node1, node2, node3) ? HOLE_ID : invalidID;
360 TopoDS_Shape shape = meshDS->IndexToShape( geomFaceID );
361 if ( shape.IsNull() || shape.ShapeType() != TopAbs_FACE )
363 TopoDS_Face geomFace = TopoDS::Face( shape );
365 // solids bounded by geom face
366 TopTools_IndexedMapOfShape solids, shells;
367 TopTools_ListIteratorOfListOfShape ansIt = mesh.GetAncestors(geomFace);
368 for ( ; ansIt.More(); ansIt.Next() ) {
369 switch ( ansIt.Value().ShapeType() ) {
371 solids.Add( ansIt.Value() ); break;
373 shells.Add( ansIt.Value() ); break;
377 // analyse found solids
378 if ( solids.Extent() == 0 || shells.Extent() == 0)
381 const TopoDS_Solid& solid1 = TopoDS::Solid( solids(1) );
382 if ( solids.Extent() == 1 )
385 return meshDS->ShapeToIndex( solid1 );
387 //////////// UNCOMMENT AS SOON AS
388 //////////// http://tracker.dev.opencascade.org/view.php?id=23129
389 //////////// IS SOLVED
390 // - Are we at a hole boundary face?
391 // if ( shells(1).IsSame( BRepTools::OuterShell( solid1 )) )
392 // { // - No, but maybe a hole is bound by two shapes? Does shells(1) touches another shell?
393 // bool touch = false;
394 // TopExp_Explorer eExp( shells(1), TopAbs_EDGE );
395 // // check if any edge of shells(1) belongs to another shell
396 // for ( ; eExp.More() && !touch; eExp.Next() ) {
397 // ansIt = mesh.GetAncestors( eExp.Current() );
398 // for ( ; ansIt.More() && !touch; ansIt.Next() ) {
399 // if ( ansIt.Value().ShapeType() == TopAbs_SHELL )
400 // touch = ( !ansIt.Value().IsSame( shells(1) ));
404 // return meshDS->ShapeToIndex( solid1 );
407 // find orientation of geom face within the first solid
408 TopExp_Explorer fExp( solid1, TopAbs_FACE );
409 for ( ; fExp.More(); fExp.Next() )
410 if ( geomFace.IsSame( fExp.Current() )) {
411 geomFace = TopoDS::Face( fExp.Current() );
415 return invalidID; // face not found
417 // normale to triangle
418 gp_Pnt node1Pnt ( node1->X(), node1->Y(), node1->Z() );
419 gp_Pnt node2Pnt ( node2->X(), node2->Y(), node2->Z() );
420 gp_Pnt node3Pnt ( node3->X(), node3->Y(), node3->Z() );
421 gp_Vec vec12( node1Pnt, node2Pnt );
422 gp_Vec vec13( node1Pnt, node3Pnt );
423 gp_Vec meshNormal = vec12 ^ vec13;
424 if ( meshNormal.SquareMagnitude() < DBL_MIN )
427 // get normale to geomFace at any node
428 bool geomNormalOK = false;
430 const SMDS_MeshNode* nodes[3] = { node1, node2, node3 };
431 SMESH_MesherHelper helper( mesh ); helper.SetSubShape( geomFace );
432 for ( int i = 0; !geomNormalOK && i < 3; ++i )
434 // find UV of i-th node on geomFace
435 const SMDS_MeshNode* nNotOnSeamEdge = 0;
436 if ( helper.IsSeamShape( nodes[i]->getshapeId() )) {
437 if ( helper.IsSeamShape( nodes[(i+1)%3]->getshapeId() ))
438 nNotOnSeamEdge = nodes[(i+2)%3];
440 nNotOnSeamEdge = nodes[(i+1)%3];
443 gp_XY uv = helper.GetNodeUV( geomFace, nodes[i], nNotOnSeamEdge, &uvOK );
444 // check that uv is correct
447 TopoDS_Shape nodeShape = helper.GetSubShapeByNode( nodes[i], meshDS );
448 if ( !nodeShape.IsNull() )
449 switch ( nodeShape.ShapeType() )
451 case TopAbs_FACE: tol = BRep_Tool::Tolerance( TopoDS::Face( nodeShape )); break;
452 case TopAbs_EDGE: tol = BRep_Tool::Tolerance( TopoDS::Edge( nodeShape )); break;
453 case TopAbs_VERTEX: tol = BRep_Tool::Tolerance( TopoDS::Vertex( nodeShape )); break;
456 gp_Pnt nodePnt ( nodes[i]->X(), nodes[i]->Y(), nodes[i]->Z() );
457 BRepAdaptor_Surface surface( geomFace );
458 uvOK = ( nodePnt.Distance( surface.Value( uv.X(), uv.Y() )) < 2 * tol );
460 // normale to geomFace at UV
462 surface.D1( uv.X(), uv.Y(), nodePnt, du, dv );
463 geomNormal = du ^ dv;
464 if ( geomFace.Orientation() == TopAbs_REVERSED )
465 geomNormal.Reverse();
466 geomNormalOK = ( geomNormal.SquareMagnitude() > DBL_MIN * 1e3 );
474 bool isReverse = ( meshNormal * geomNormal ) < 0;
476 return meshDS->ShapeToIndex( solid1 );
478 if ( solids.Extent() == 1 )
479 return HOLE_ID; // we are inside a hole
481 return meshDS->ShapeToIndex( solids(2) );
484 // //=======================================================================
485 // //function : countShape
487 // //=======================================================================
489 // template < class Mesh, class Shape >
490 // static int countShape( Mesh* mesh, Shape shape ) {
491 // TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
492 // TopTools_MapOfShape mapShape;
494 // for ( ; expShape.More(); expShape.Next() ) {
495 // if (mapShape.Add(expShape.Current())) {
502 // //=======================================================================
503 // //function : getShape
505 // //=======================================================================
507 // template < class Mesh, class Shape, class Tab >
508 // void getShape(Mesh* mesh, Shape shape, Tab *t_Shape) {
509 // TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
510 // TopTools_MapOfShape mapShape;
511 // for ( int i=0; expShape.More(); expShape.Next() ) {
512 // if (mapShape.Add(expShape.Current())) {
513 // t_Shape[i] = expShape.Current();
520 // // //=======================================================================
521 // // //function : findEdgeID
523 // // //=======================================================================
525 // static int findEdgeID(const SMDS_MeshNode* aNode,
526 // const SMESHDS_Mesh* theMesh,
528 // const TopoDS_Shape* t_Edge) {
530 // TopoDS_Shape aPntShape, foundEdge;
531 // TopoDS_Vertex aVertex;
532 // gp_Pnt aPnt( aNode->X(), aNode->Y(), aNode->Z() );
534 // int foundInd, ind;
535 // double nearest = RealLast(), *t_Dist;
536 // double epsilon = Precision::Confusion();
538 // t_Dist = new double[ nEdge ];
539 // aPntShape = BRepBuilderAPI_MakeVertex( aPnt ).Shape();
540 // aVertex = TopoDS::Vertex( aPntShape );
542 // for ( ind=0; ind < nEdge; ind++ ) {
543 // BRepExtrema_DistShapeShape aDistance ( aVertex, t_Edge[ind] );
544 // t_Dist[ind] = aDistance.Value();
545 // if ( t_Dist[ind] < nearest ) {
546 // nearest = t_Dist[ind];
547 // foundEdge = t_Edge[ind];
549 // if ( nearest < epsilon )
555 // return theMesh->ShapeToIndex( foundEdge );
559 // // =======================================================================
560 // // function : readGMFFile
561 // // purpose : read GMF file with geometry associated to mesh
562 // // =======================================================================
564 // static bool readGMFFile(const int fileOpen,
565 // const char* theFileName,
566 // SMESH_Mesh& theMesh,
567 // const int nbShape,
568 // const TopoDS_Shape* tabShape,
570 // map <int,const SMDS_MeshNode*>& theGhs3dIdToNodeMap,
572 // int nbEnforcedVertices,
573 // int nbEnforcedNodes)
575 // TopoDS_Shape aShape;
576 // TopoDS_Vertex aVertex;
577 // SMESHDS_Mesh* theMeshDS = theMesh.GetMeshDS();
578 // int nbElem = 0, nbRef = 0, IdShapeRef = 1;
580 // int aGMFNodeID = 0;
582 // nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() );
583 // int tetraShapeID = compoundID;
584 // double epsilon = Precision::Confusion();
585 // int *nodeAssigne, *GMFNodeAssigne;
586 // SMDS_MeshNode** GMFNode;
587 // TopoDS_Shape *tabCorner, *tabEdge;
588 // std::map <GmfKwdCod,int> tabRef;
592 // MESSAGE("Read " << theFileName << " file");
593 // int InpMsh = GmfOpenMesh(theFileName, GmfRead, &ver, &dim);
597 // // ===========================
598 // // Fill the tabID array: BEGIN
599 // // ===========================
602 // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2)
604 // Kernel_Utils::Localizer loc;
605 // struct stat status;
608 // char *ptr, *mapPtr;
610 // int *tab = new int[3];
612 // // Read the file state
613 // fstat(fileOpen, &status);
614 // length = status.st_size;
616 // // Mapping the result file into memory
618 // HANDLE fd = CreateFile(theFileName, GENERIC_READ, FILE_SHARE_READ,
619 // NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
620 // HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY,
621 // 0, (DWORD)length, NULL);
622 // ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 );
624 // ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
628 // ptr = readMapIntLine(ptr, tab);
632 // int nbNodes = tab[1];
634 // for (int i=0; i < 4*nbElem; i++)
635 // strtol(ptr, &ptr, 10);
637 // for (int iNode=1; iNode <= nbNodes; iNode++)
638 // for (int iCoor=0; iCoor < 3; iCoor++)
639 // strtod(ptr, &ptr);
642 // // Reading the number of triangles which corresponds to the number of sub-domains
643 // int nbTriangle = strtol(ptr, &ptr, 10);
646 // // The keyword does not exist yet => to update when it is created
647 // // int nbSubdomains = GmfStatKwd(InpMsh, GmfSubdomain);
651 // tabID = new int[nbTriangle];
652 // for (int i=0; i < nbTriangle; i++) {
654 // int nodeId1, nodeId2, nodeId3;
655 // // find the solid corresponding to GHS3D sub-domain following
656 // // the technique proposed in GHS3D manual in chapter
657 // // "B.4 Subdomain (sub-region) assignment"
659 // nodeId1 = strtol(ptr, &ptr, 10);
660 // nodeId2 = strtol(ptr, &ptr, 10);
661 // nodeId3 = strtol(ptr, &ptr, 10);
663 // // // The keyword does not exist yet => to update when it is created
664 // // GmfGetLin(InpMsh, GmfSubdomain, &id_tri[0], &id_tri[1], &id_tri[2]);
665 // // nodeId1 = id_tri[0];
666 // // nodeId2 = id_tri[1];
667 // // nodeId3 = id_tri[2];
669 // if ( nbTriangle > 1 ) {
670 // // get the nodes indices
671 // const SMDS_MeshNode* n1 = theGhs3dIdToNodeMap[ nodeId1 ];
672 // const SMDS_MeshNode* n2 = theGhs3dIdToNodeMap[ nodeId2 ];
673 // const SMDS_MeshNode* n3 = theGhs3dIdToNodeMap[ nodeId3 ];
675 // OCC_CATCH_SIGNALS;
676 // tabID[i] = findShapeID( theMesh, n1, n2, n3, toMeshHoles );
677 // // -- 0020330: Pb with ghs3d as a submesh
678 // // check that found shape is to be meshed
679 // if ( tabID[i] > 0 ) {
680 // const TopoDS_Shape& foundShape = theMeshDS->IndexToShape( tabID[i] );
681 // bool isToBeMeshed = false;
682 // for ( int iS = 0; !isToBeMeshed && iS < nbShape; ++iS )
683 // isToBeMeshed = foundShape.IsSame( tabShape[ iS ]);
684 // if ( !isToBeMeshed )
685 // tabID[i] = HOLE_ID;
687 // // END -- 0020330: Pb with ghs3d as a submesh
689 // std::cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << std::endl;
692 // catch ( Standard_Failure & ex)
695 // std::cout << i+1 << " subdomain: Exception caugt: " << ex.GetMessageString() << std::endl;
700 // std::cout << i+1 << " subdomain: unknown exception caught " << std::endl;
706 // // ===========================
707 // // Fill the tabID array: END
708 // // ===========================
711 // tabRef[GmfVertices] = 3;
712 // tabRef[GmfCorners] = 1;
713 // tabRef[GmfEdges] = 2;
714 // tabRef[GmfRidges] = 1;
715 // tabRef[GmfTriangles] = 3;
716 // // tabRef[GmfQuadrilaterals] = 4;
717 // tabRef[GmfTetrahedra] = 4;
718 // // tabRef[GmfHexahedra] = 8;
720 // SMDS_NodeIteratorPtr itOnGMFInputNode = theMeshDS->nodesIterator();
721 // while ( itOnGMFInputNode->more() )
722 // theMeshDS->RemoveNode( itOnGMFInputNode->next() );
725 // int nbVertices = GmfStatKwd(InpMsh, GmfVertices);
726 // int nbCorners = max(countShape( theMeshDS, TopAbs_VERTEX ) , GmfStatKwd(InpMsh, GmfCorners));
727 // int nbShapeEdge = countShape( theMeshDS, TopAbs_EDGE );
729 // tabCorner = new TopoDS_Shape[ nbCorners ];
730 // tabEdge = new TopoDS_Shape[ nbShapeEdge ];
731 // nodeAssigne = new int[ nbVertices + 1 ];
732 // GMFNodeAssigne = new int[ nbVertices + 1 ];
733 // GMFNode = new SMDS_MeshNode*[ nbVertices + 1 ];
735 // getShape(theMeshDS, TopAbs_VERTEX, tabCorner);
736 // getShape(theMeshDS, TopAbs_EDGE, tabEdge);
738 // std::map <GmfKwdCod,int>::const_iterator it = tabRef.begin();
739 // for ( ; it != tabRef.end() ; ++it)
742 // GmfKwdCod token = it->first;
743 // nbRef = it->second;
745 // nbElem = GmfStatKwd(InpMsh, token);
747 // GmfGotoKwd(InpMsh, token);
748 // std::cout << "Read " << nbElem;
753 // int id[nbElem*tabRef[token]];
754 // int ghs3dShapeID[nbElem];
756 // if (token == GmfVertices) {
757 // std::cout << " vertices" << std::endl;
760 // float VerTab_f[nbElem][3];
761 // double VerTab_d[nbElem][3];
762 // SMDS_MeshNode * aGMFNode;
764 // for ( int iElem = 0; iElem < nbElem; iElem++ ) {
765 // aGMFID = iElem + 1;
766 // if (ver == GmfFloat) {
767 // GmfGetLin(InpMsh, token, &VerTab_f[nbElem][0], &VerTab_f[nbElem][1], &VerTab_f[nbElem][2], &ghs3dShapeID[iElem]);
768 // aGMFNode = theMeshDS->AddNode(VerTab_f[nbElem][0], VerTab_f[nbElem][1], VerTab_f[nbElem][2]);
771 // GmfGetLin(InpMsh, token, &VerTab_d[nbElem][0], &VerTab_d[nbElem][1], &VerTab_d[nbElem][2], &ghs3dShapeID[iElem]);
772 // aGMFNode = theMeshDS->AddNode(VerTab_d[nbElem][0], VerTab_d[nbElem][1], VerTab_d[nbElem][2]);
774 // GMFNode[ aGMFID ] = aGMFNode;
775 // nodeAssigne[ aGMFID ] = 0;
776 // GMFNodeAssigne[ aGMFID ] = 0;
779 // else if (token == GmfCorners && nbElem > 0) {
780 // std::cout << " corners" << std::endl;
781 // for ( int iElem = 0; iElem < nbElem; iElem++ )
782 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
784 // else if (token == GmfRidges && nbElem > 0) {
785 // std::cout << " ridges" << std::endl;
786 // for ( int iElem = 0; iElem < nbElem; iElem++ )
787 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
789 // else if (token == GmfEdges && nbElem > 0) {
790 // std::cout << " edges" << std::endl;
791 // for ( int iElem = 0; iElem < nbElem; iElem++ )
792 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &ghs3dShapeID[iElem]);
794 // else if (token == GmfTriangles && nbElem > 0) {
795 // std::cout << " triangles" << std::endl;
796 // for ( int iElem = 0; iElem < nbElem; iElem++ )
797 // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &ghs3dShapeID[iElem]);
799 // // else if (token == GmfQuadrilaterals && nbElem > 0) {
800 // // std::cout << " Quadrilaterals" << std::endl;
801 // // for ( int iElem = 0; iElem < nbElem; iElem++ )
802 // // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &ghs3dShapeID[iElem]);
804 // else if (token == GmfTetrahedra && nbElem > 0) {
805 // std::cout << " Tetrahedra" << std::endl;
806 // for ( int iElem = 0; iElem < nbElem; iElem++ )
807 // GmfGetLin(InpMsh, token,
808 // &id[iElem*tabRef[token]],
809 // &id[iElem*tabRef[token]+1],
810 // &id[iElem*tabRef[token]+2],
811 // &id[iElem*tabRef[token]+3],
812 // &ghs3dShapeID[iElem]);
814 // // else if (token == GmfHexahedra && nbElem > 0) {
815 // // std::cout << " Hexahedra" << std::endl;
816 // // for ( int iElem = 0; iElem < nbElem; iElem++ )
817 // // GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3],
818 // // &id[iElem*tabRef[token]+4], &id[iElem*tabRef[token]+5], &id[iElem*tabRef[token]+6], &id[iElem*tabRef[token]+7], &ghs3dShapeID[iElem]);
825 // case GmfTriangles:
826 // // case GmfQuadrilaterals:
827 // case GmfTetrahedra:
828 // // case GmfHexahedra:
830 // int nodeDim, shapeID, *nodeID;
831 // const SMDS_MeshNode** node;
832 // // std::vector< SMDS_MeshNode* > enfNode( nbRef );
833 // SMDS_MeshElement * aGMFElement;
835 // node = new const SMDS_MeshNode*[nbRef];
836 // nodeID = new int[ nbRef ];
838 // for ( int iElem = 0; iElem < nbElem; iElem++ )
840 // for ( int iRef = 0; iRef < nbRef; iRef++ )
842 // aGMFNodeID = id[iElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID
843 // node [ iRef ] = GMFNode[ aGMFNodeID ];
844 // nodeID[ iRef ] = aGMFNodeID;
849 // case GmfCorners: {
851 // gp_Pnt GMFPnt ( node[0]->X(), node[0]->Y(), node[0]->Z() );
852 // for ( int i=0; i<nbElem; i++ ) {
853 // aVertex = TopoDS::Vertex( tabCorner[i] );
854 // gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
855 // if ( aPnt.Distance( GMFPnt ) < epsilon )
862 // aGMFElement = theMeshDS->AddEdge( node[0], node[1] );
864 // if ( GMFNodeAssigne[ nodeID[0] ] == 0 || GMFNodeAssigne[ nodeID[0] ] == 2 )
866 // shapeID = findEdgeID( node[iNode], theMeshDS, nbShapeEdge, tabEdge );
871 // case GmfTriangles: {
873 // aGMFElement = theMeshDS->AddFace( node[0], node[1], node[2]);
877 // // case GmfQuadrilaterals: {
879 // // aGMFElement = theMeshDS->AddFace( node[0], node[1], node[2], node[3] );
883 // case GmfTetrahedra: {
886 // TopoDS_Shape aSolid;
887 // // We always run GHS3D with "to mesh holes"==TRUE but we must not create
888 // // tetras within holes depending on hypo option,
889 // // so we first check if aTet is inside a hole and then create it
890 // if ( nbTriangle > 1 ) {
891 // tetraShapeID = HOLE_ID; // negative tetraShapeID means not to create tetras if !toMeshHoles
892 // int aGhs3dShapeID = ghs3dShapeID[iElem] - IdShapeRef;
893 // if ( tabID[ aGhs3dShapeID ] == 0 ) {
894 // TopAbs_State state;
895 // aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape, &state);
896 // if ( toMeshHoles || state == TopAbs_IN )
897 // tetraShapeID = theMeshDS->ShapeToIndex( aSolid );
898 // tabID[ aGhs3dShapeID ] = tetraShapeID;
901 // tetraShapeID = tabID[ aGhs3dShapeID ];
903 // else if ( nbShape > 1 ) {
904 // // Case where nbTriangle == 1 while nbShape == 2 encountered
905 // // with compound of 2 boxes and "To mesh holes"==False,
906 // // so there are no subdomains specified for each tetrahedron.
907 // // Try to guess a solid by a node already bound to shape
909 // for ( int i=0; i<4 && tetraShapeID==0; i++ ) {
910 // if ( nodeAssigne[ nodeID[i] ] == 1 &&
911 // node[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE &&
912 // node[i]->getshapeId() > 1 )
914 // tetraShapeID = node[i]->getshapeId();
917 // if ( tetraShapeID==0 ) {
918 // aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape);
919 // tetraShapeID = theMeshDS->ShapeToIndex( aSolid );
922 // // set new nodes and tetrahedron onto the shape
923 // for ( int i=0; i<4; i++ ) {
924 // if ( nodeAssigne[ nodeID[i] ] == 0 ) {
925 // if ( tetraShapeID != HOLE_ID )
926 // theMeshDS->SetNodeInVolume( node[i], tetraShapeID );
927 // nodeAssigne[ nodeID[i] ] = tetraShapeID;
930 // if ( toMeshHoles || tetraShapeID != HOLE_ID ) {
931 // aGMFElement = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
932 // theMeshDS->SetMeshElementOnShape( aGMFElement, tetraShapeID );
940 // // case GmfHexahedra: {
942 // // aGMFElement = theMeshDS->AddVolume( node[0], node[3], node[2], node[1],
943 // // node[4], node[7], node[6], node[5] );
946 // default: continue;
948 // if (token != GmfRidges)
950 // for ( int i=0; i<nbRef; i++ ) {
951 // if ( GMFNodeAssigne[ nodeID[i] ] == 0 ) {
952 // if ( token == GmfCorners ) theMeshDS->SetNodeOnVertex( node[0], aVertex );
953 // else if ( token == GmfEdges ) theMeshDS->SetNodeOnEdge( node[i], shapeID );
954 // else if ( token == GmfTriangles ) theMeshDS->SetNodeOnFace( node[i], shapeID );
955 // GMFNodeAssigne[ nodeID[i] ] = nodeDim;
958 // if ( token != "Corners" )
959 // theMeshDS->SetMeshElementOnShape( aGMFElement, shapeID );
963 // if ( !toMeshHoles ) {
964 // map <int,const SMDS_MeshNode*>::iterator itOnNode = theGhs3dIdToNodeMap.find( nbVertices-(nbEnforcedVertices+nbEnforcedNodes) );
965 // for ( ; itOnNode != theGhs3dIdToNodeMap.end(); ++itOnNode) {
966 // if ( nodeAssigne[ itOnNode->first ] == HOLE_ID )
967 // theMeshDS->RemoveFreeNode( itOnNode->second, 0 );
974 // } // case GmfTetrahedra
975 // } // switch(token)
977 // cout << std::endl;
980 // UnmapViewOfFile(mapPtr);
981 // CloseHandle(hMapObject);
984 // munmap(mapPtr, length);
989 // delete [] tabCorner;
990 // delete [] tabEdge;
991 // delete [] nodeAssigne;
992 // delete [] GMFNodeAssigne;
993 // delete [] GMFNode;
999 //=======================================================================
1000 //function : addElemInMeshGroup
1001 //purpose : Update or create groups in mesh
1002 //=======================================================================
1004 static void addElemInMeshGroup(SMESH_Mesh* theMesh,
1005 const SMDS_MeshElement* anElem,
1006 std::string& groupName,
1007 std::set<std::string>& groupsToRemove)
1009 if ( !anElem ) return; // issue 0021776
1011 bool groupDone = false;
1012 SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups();
1013 while (grIt->more()) {
1014 SMESH_Group * group = grIt->next();
1015 if ( !group ) continue;
1016 SMESHDS_GroupBase* groupDS = group->GetGroupDS();
1017 if ( !groupDS ) continue;
1018 if ( groupDS->GetType()==anElem->GetType() &&groupName.compare(group->GetName())==0) {
1019 SMESHDS_Group* aGroupDS = static_cast<SMESHDS_Group*>( groupDS );
1020 aGroupDS->SMDSGroup().Add(anElem);
1022 // MESSAGE("Successfully added enforced element to existing group " << groupName);
1030 SMESH_Group* aGroup = theMesh->AddGroup(anElem->GetType(), groupName.c_str(), groupId);
1031 aGroup->SetName( groupName.c_str() );
1032 SMESHDS_Group* aGroupDS = static_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
1033 aGroupDS->SMDSGroup().Add(anElem);
1034 // MESSAGE("Successfully created enforced vertex group " << groupName);
1038 throw SALOME_Exception(LOCALIZED("A given element was not added to a group"));
1042 //=======================================================================
1043 //function : updateMeshGroups
1044 //purpose : Update or create groups in mesh
1045 //=======================================================================
1047 static void updateMeshGroups(SMESH_Mesh* theMesh, std::set<std::string> groupsToRemove)
1049 SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups();
1050 while (grIt->more()) {
1051 SMESH_Group * group = grIt->next();
1052 if ( !group ) continue;
1053 SMESHDS_GroupBase* groupDS = group->GetGroupDS();
1054 if ( !groupDS ) continue;
1055 std::string currentGroupName = (string)group->GetName();
1056 if (groupDS->IsEmpty() && groupsToRemove.find(currentGroupName) != groupsToRemove.end()) {
1057 // Previous group created by enforced elements
1058 MESSAGE("Delete previous group created by removed enforced elements: " << group->GetName())
1059 theMesh->RemoveGroup(groupDS->GetID());
1064 //=======================================================================
1065 //function : removeEmptyGroupsOfDomains
1066 //purpose : remove empty groups named "Domain_nb" created due to
1067 // "To make groups of domains" option.
1068 //=======================================================================
1070 static void removeEmptyGroupsOfDomains(SMESH_Mesh* mesh,
1071 bool notEmptyAsWell = false)
1073 const char* refName = theDomainGroupNamePrefix;
1074 const size_t refLen = strlen( theDomainGroupNamePrefix );
1076 std::list<int> groupIDs = mesh->GetGroupIds();
1077 std::list<int>::const_iterator id = groupIDs.begin();
1078 for ( ; id != groupIDs.end(); ++id )
1080 SMESH_Group* group = mesh->GetGroup( *id );
1081 if ( !group || ( !group->GetGroupDS()->IsEmpty() && !notEmptyAsWell ))
1083 const char* name = group->GetName();
1086 if ( strncmp( name, refName, refLen ) == 0 && // starts from refName;
1087 isdigit( *( name + refLen )) && // refName is followed by a digit;
1088 strtol( name + refLen, &end, 10) >= 0 && // there are only digits ...
1089 *end == '\0') // ... till a string end.
1091 mesh->RemoveGroup( *id );
1096 //================================================================================
1098 * \brief Create the groups corresponding to domains
1100 //================================================================================
1102 static void makeDomainGroups( std::vector< std::vector< const SMDS_MeshElement* > >& elemsOfDomain,
1103 SMESH_MesherHelper* theHelper)
1105 // int nbDomains = 0;
1106 // for ( size_t i = 0; i < elemsOfDomain.size(); ++i )
1107 // nbDomains += ( elemsOfDomain[i].size() > 0 );
1109 // if ( nbDomains > 1 )
1110 for ( size_t iDomain = 0; iDomain < elemsOfDomain.size(); ++iDomain )
1112 std::vector< const SMDS_MeshElement* > & elems = elemsOfDomain[ iDomain ];
1113 if ( elems.empty() ) continue;
1115 // find existing groups
1116 std::vector< SMESH_Group* > groupOfType( SMDSAbs_NbElementTypes, (SMESH_Group*)NULL );
1117 const std::string domainName = ( SMESH_Comment( theDomainGroupNamePrefix ) << iDomain );
1118 SMESH_Mesh::GroupIteratorPtr groupIt = theHelper->GetMesh()->GetGroups();
1119 while ( groupIt->more() )
1121 SMESH_Group* group = groupIt->next();
1122 if ( domainName == group->GetName() &&
1123 dynamic_cast< SMESHDS_Group* >( group->GetGroupDS()) )
1124 groupOfType[ group->GetGroupDS()->GetType() ] = group;
1126 // create and fill the groups
1131 SMESH_Group* group = groupOfType[ elems[ iElem ]->GetType() ];
1133 group = theHelper->GetMesh()->AddGroup( elems[ iElem ]->GetType(),
1134 domainName.c_str(), groupID );
1135 SMDS_MeshGroup& groupDS =
1136 static_cast< SMESHDS_Group* >( group->GetGroupDS() )->SMDSGroup();
1138 while ( iElem < elems.size() && groupDS.Add( elems[iElem] ))
1141 } while ( iElem < elems.size() );
1145 //=======================================================================
1146 //function : readGMFFile
1147 //purpose : read GMF file w/o geometry associated to mesh
1148 //=======================================================================
1150 static bool readGMFFile(const char* theFile,
1151 GHS3DPlugin_GHS3D* theAlgo,
1152 SMESH_MesherHelper* theHelper,
1153 TopoDS_Shape theSolid,
1154 vector <const SMDS_MeshNode*> & theNodeByGhs3dId,
1155 map<const SMDS_MeshNode*,int> & theNodeToGhs3dIdMap,
1156 std::vector<std::string> & aNodeGroupByGhs3dId,
1157 std::vector<std::string> & anEdgeGroupByGhs3dId,
1158 std::vector<std::string> & aFaceGroupByGhs3dId,
1159 std::set<std::string> & groupsToRemove,
1160 bool toMakeGroupsOfDomains=false)
1163 SMESHDS_Mesh* theMeshDS = theHelper->GetMeshDS();
1165 int nbInitialNodes = theNodeByGhs3dId.size();
1166 int nbMeshNodes = theMeshDS->NbNodes();
1168 const bool isQuadMesh =
1169 theHelper->GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
1170 theHelper->GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
1171 theHelper->GetMesh()->NbVolumes( ORDER_QUADRATIC );
1174 std::cout << "theNodeByGhs3dId.size(): " << nbInitialNodes << std::endl;
1175 std::cout << "theHelper->GetMesh()->NbNodes(): " << nbMeshNodes << std::endl;
1176 std::cout << "isQuadMesh: " << isQuadMesh << std::endl;
1179 if (theHelper->GetSubShapeID() != 0)
1180 theHelper->IsQuadraticSubMesh( theHelper->GetSubShape() );
1182 // ---------------------------------
1183 // Read generated elements and nodes
1184 // ---------------------------------
1186 int nbElem = 0, nbRef = 0;
1188 const SMDS_MeshNode** GMFNode;
1190 std::map<int, std::set<int> > subdomainId2tetraId;
1192 std::map <GmfKwdCod,int> tabRef;
1193 const bool force3d = true; // since there is no geometry
1196 tabRef[GmfVertices] = 3; // for new nodes and enforced nodes
1197 tabRef[GmfCorners] = 1;
1198 tabRef[GmfEdges] = 2; // for enforced edges
1199 tabRef[GmfRidges] = 1;
1200 tabRef[GmfTriangles] = 3; // for enforced faces
1201 tabRef[GmfQuadrilaterals] = 4;
1202 tabRef[GmfTetrahedra] = 4; // for new tetras
1203 tabRef[GmfHexahedra] = 8;
1206 MESSAGE("Read " << theFile << " file");
1207 int InpMsh = GmfOpenMesh(theFile, GmfRead, &ver, &dim);
1212 // Issue 0020682. Avoid creating nodes and tetras at place where
1213 // volumic elements already exist
1214 SMESH_ElementSearcher* elemSearcher = 0;
1215 std::vector< const SMDS_MeshElement* > foundVolumes;
1216 if ( theHelper->GetMesh()->NbVolumes() > 0 )
1217 elemSearcher = SMESH_MeshAlgos::GetElementSearcher( *theHelper->GetMeshDS() );
1219 // IMP 0022172: [CEA 790] create the groups corresponding to domains
1220 std::vector< std::vector< const SMDS_MeshElement* > > elemsOfDomain;
1222 int nbVertices = GmfStatKwd(InpMsh, GmfVertices) - nbInitialNodes;
1223 GMFNode = new const SMDS_MeshNode*[ nbVertices + 1 ];
1225 std::map <GmfKwdCod,int>::const_iterator it = tabRef.begin();
1226 for ( ; it != tabRef.end() ; ++it)
1228 if(theAlgo->computeCanceled()) {
1229 GmfCloseMesh(InpMsh);
1234 GmfKwdCod token = it->first;
1237 nbElem = GmfStatKwd(InpMsh, token);
1239 GmfGotoKwd(InpMsh, token);
1240 std::cout << "Read " << nbElem;
1245 std::vector<int> id (nbElem*tabRef[token]); // node ids
1246 std::vector<int> domainID( nbElem ); // domain
1248 if (token == GmfVertices) {
1249 (nbElem <= 1) ? tmpStr = " vertex" : tmpStr = " vertices";
1250 // std::cout << nbInitialNodes << " from input mesh " << std::endl;
1252 // Remove orphan nodes from previous enforced mesh which was cleared
1253 // if ( nbElem < nbMeshNodes ) {
1254 // const SMDS_MeshNode* node;
1255 // SMDS_NodeIteratorPtr nodeIt = theMeshDS->nodesIterator();
1256 // while ( nodeIt->more() )
1258 // node = nodeIt->next();
1259 // if (theNodeToGhs3dIdMap.find(node) != theNodeToGhs3dIdMap.end())
1260 // theMeshDS->RemoveNode(node);
1269 const SMDS_MeshNode * aGMFNode;
1271 for ( int iElem = 0; iElem < nbElem; iElem++ ) {
1272 if(theAlgo->computeCanceled()) {
1273 GmfCloseMesh(InpMsh);
1277 if (ver == GmfFloat) {
1278 GmfGetLin(InpMsh, token, &VerTab_f[0], &VerTab_f[1], &VerTab_f[2], &dummy);
1284 GmfGetLin(InpMsh, token, &x, &y, &z, &dummy);
1286 if (iElem >= nbInitialNodes) {
1287 if ( elemSearcher &&
1288 elemSearcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_Volume, foundVolumes))
1291 aGMFNode = theHelper->AddNode(x, y, z);
1293 aGMFID = iElem -nbInitialNodes +1;
1294 GMFNode[ aGMFID ] = aGMFNode;
1295 if (aGMFID-1 < aNodeGroupByGhs3dId.size() && !aNodeGroupByGhs3dId.at(aGMFID-1).empty())
1296 addElemInMeshGroup(theHelper->GetMesh(), aGMFNode, aNodeGroupByGhs3dId.at(aGMFID-1), groupsToRemove);
1300 else if (token == GmfCorners && nbElem > 0) {
1301 (nbElem <= 1) ? tmpStr = " corner" : tmpStr = " corners";
1302 for ( int iElem = 0; iElem < nbElem; iElem++ )
1303 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
1305 else if (token == GmfRidges && nbElem > 0) {
1306 (nbElem <= 1) ? tmpStr = " ridge" : tmpStr = " ridges";
1307 for ( int iElem = 0; iElem < nbElem; iElem++ )
1308 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
1310 else if (token == GmfEdges && nbElem > 0) {
1311 (nbElem <= 1) ? tmpStr = " edge" : tmpStr = " edges";
1312 for ( int iElem = 0; iElem < nbElem; iElem++ )
1313 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &domainID[iElem]);
1315 else if (token == GmfTriangles && nbElem > 0) {
1316 (nbElem <= 1) ? tmpStr = " triangle" : tmpStr = " triangles";
1317 for ( int iElem = 0; iElem < nbElem; iElem++ )
1318 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &domainID[iElem]);
1320 else if (token == GmfQuadrilaterals && nbElem > 0) {
1321 (nbElem <= 1) ? tmpStr = " Quadrilateral" : tmpStr = " Quadrilaterals";
1322 for ( int iElem = 0; iElem < nbElem; iElem++ )
1323 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &domainID[iElem]);
1325 else if (token == GmfTetrahedra && nbElem > 0) {
1326 (nbElem <= 1) ? tmpStr = " Tetrahedron" : tmpStr = " Tetrahedra";
1327 for ( int iElem = 0; iElem < nbElem; iElem++ ) {
1328 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &domainID[iElem]);
1330 subdomainId2tetraId[dummy].insert(iElem+1);
1331 // MESSAGE("subdomainId2tetraId["<<dummy<<"].insert("<<iElem+1<<")");
1335 else if (token == GmfHexahedra && nbElem > 0) {
1336 (nbElem <= 1) ? tmpStr = " Hexahedron" : tmpStr = " Hexahedra";
1337 for ( int iElem = 0; iElem < nbElem; iElem++ )
1338 GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3],
1339 &id[iElem*tabRef[token]+4], &id[iElem*tabRef[token]+5], &id[iElem*tabRef[token]+6], &id[iElem*tabRef[token]+7], &domainID[iElem]);
1341 std::cout << tmpStr << std::endl;
1342 std::cout << std::endl;
1349 case GmfQuadrilaterals:
1353 std::vector< const SMDS_MeshNode* > node( nbRef );
1354 std::vector< int > nodeID( nbRef );
1355 std::vector< SMDS_MeshNode* > enfNode( nbRef );
1356 const SMDS_MeshElement* aCreatedElem;
1358 for ( int iElem = 0; iElem < nbElem; iElem++ )
1360 if(theAlgo->computeCanceled()) {
1361 GmfCloseMesh(InpMsh);
1365 // Check if elem is already in input mesh. If yes => skip
1366 bool fullyCreatedElement = false; // if at least one of the nodes was created
1367 for ( int iRef = 0; iRef < nbRef; iRef++ )
1369 aGMFNodeID = id[iElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID
1370 if (aGMFNodeID <= nbInitialNodes) // input nodes
1373 node[ iRef ] = theNodeByGhs3dId[aGMFNodeID];
1377 fullyCreatedElement = true;
1378 aGMFNodeID -= nbInitialNodes;
1379 nodeID[ iRef ] = aGMFNodeID ;
1380 node [ iRef ] = GMFNode[ aGMFNodeID ];
1387 if (fullyCreatedElement) {
1388 aCreatedElem = theHelper->AddEdge( node[0], node[1], noID, force3d );
1389 if (anEdgeGroupByGhs3dId.size() && !anEdgeGroupByGhs3dId[iElem].empty())
1390 addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByGhs3dId[iElem], groupsToRemove);
1394 if (fullyCreatedElement) {
1395 aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], noID, force3d );
1396 if (aFaceGroupByGhs3dId.size() && !aFaceGroupByGhs3dId[iElem].empty())
1397 addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, aFaceGroupByGhs3dId[iElem], groupsToRemove);
1400 case GmfQuadrilaterals:
1401 if (fullyCreatedElement) {
1402 aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], node[3], noID, force3d );
1406 if ( elemSearcher ) {
1407 // Issue 0020682. Avoid creating nodes and tetras at place where
1408 // volumic elements already exist
1409 if ( !node[1] || !node[0] || !node[2] || !node[3] )
1411 if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) +
1412 SMESH_TNodeXYZ(node[1]) +
1413 SMESH_TNodeXYZ(node[2]) +
1414 SMESH_TNodeXYZ(node[3]) ) / 4.,
1415 SMDSAbs_Volume, foundVolumes ))
1418 aCreatedElem = theHelper->AddVolume( node[1], node[0], node[2], node[3], noID, force3d );
1421 if ( elemSearcher ) {
1422 // Issue 0020682. Avoid creating nodes and tetras at place where
1423 // volumic elements already exist
1424 if ( !node[1] || !node[0] || !node[2] || !node[3] || !node[4] || !node[5] || !node[6] || !node[7])
1426 if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) +
1427 SMESH_TNodeXYZ(node[1]) +
1428 SMESH_TNodeXYZ(node[2]) +
1429 SMESH_TNodeXYZ(node[3]) +
1430 SMESH_TNodeXYZ(node[4]) +
1431 SMESH_TNodeXYZ(node[5]) +
1432 SMESH_TNodeXYZ(node[6]) +
1433 SMESH_TNodeXYZ(node[7])) / 8.,
1434 SMDSAbs_Volume, foundVolumes ))
1437 aCreatedElem = theHelper->AddVolume( node[0], node[3], node[2], node[1],
1438 node[4], node[7], node[6], node[5], noID, force3d );
1442 if ( aCreatedElem && toMakeGroupsOfDomains )
1444 if ( domainID[iElem] >= (int) elemsOfDomain.size() )
1445 elemsOfDomain.resize( domainID[iElem] + 1 );
1446 elemsOfDomain[ domainID[iElem] ].push_back( aCreatedElem );
1448 } // loop on elements of one type
1454 GmfCloseMesh(InpMsh);
1457 // 0022172: [CEA 790] create the groups corresponding to domains
1458 if ( toMakeGroupsOfDomains )
1459 makeDomainGroups( elemsOfDomain, theHelper );
1462 MESSAGE("Nb subdomains " << subdomainId2tetraId.size());
1463 std::map<int, std::set<int> >::const_iterator subdomainIt = subdomainId2tetraId.begin();
1464 TCollection_AsciiString aSubdomainFileName = theFile;
1465 aSubdomainFileName = aSubdomainFileName + ".subdomain";
1466 ofstream aSubdomainFile ( aSubdomainFileName.ToCString() , ios::out);
1468 aSubdomainFile << "Nb subdomains " << subdomainId2tetraId.size() << std::endl;
1469 for(;subdomainIt != subdomainId2tetraId.end() ; ++subdomainIt) {
1470 int subdomainId = subdomainIt->first;
1471 std::set<int> tetraIds = subdomainIt->second;
1472 MESSAGE("Subdomain #"<<subdomainId<<": "<<tetraIds.size()<<" tetrahedrons");
1473 std::set<int>::const_iterator tetraIdsIt = tetraIds.begin();
1474 aSubdomainFile << subdomainId << std::endl;
1475 for(;tetraIdsIt != tetraIds.end() ; ++tetraIdsIt) {
1476 aSubdomainFile << (*tetraIdsIt) << " ";
1478 aSubdomainFile << std::endl;
1480 aSubdomainFile.close();
1485 MESSAGE("delete elemSearcher")
1486 delete elemSearcher;
1492 static bool writeGMFFile(const char* theMeshFileName,
1493 const char* theRequiredFileName,
1494 const char* theSolFileName,
1495 const SMESH_ProxyMesh& theProxyMesh,
1496 SMESH_Mesh * theMesh,
1497 std::vector <const SMDS_MeshNode*> & theNodeByGhs3dId,
1498 std::map<const SMDS_MeshNode*,int> & aNodeToGhs3dIdMap,
1499 std::vector<std::string> & aNodeGroupByGhs3dId,
1500 std::vector<std::string> & anEdgeGroupByGhs3dId,
1501 std::vector<std::string> & aFaceGroupByGhs3dId,
1502 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes,
1503 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
1504 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles,
1505 std::map<std::vector<double>, std::string> & enfVerticesWithGroup,
1506 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices)
1508 MESSAGE("writeGMFFile w/o geometry");
1510 int idx, idxRequired = 0, idxSol = 0;
1511 const int dummyint = 0;
1512 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt;
1513 std::vector<double> enfVertexSizes;
1514 const SMDS_MeshElement* elem;
1515 TIDSortedElemSet anElemSet, theKeptEnforcedEdges, theKeptEnforcedTriangles;
1516 SMDS_ElemIteratorPtr nodeIt;
1517 std::vector <const SMDS_MeshNode*> theEnforcedNodeByGhs3dId;
1518 map<const SMDS_MeshNode*,int> anEnforcedNodeToGhs3dIdMap, anExistingEnforcedNodeToGhs3dIdMap;
1519 std::vector< const SMDS_MeshElement* > foundElems;
1520 map<const SMDS_MeshNode*,TopAbs_State> aNodeToTopAbs_StateMap;
1522 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap::iterator elemIt;
1523 TIDSortedElemSet::iterator elemSetIt;
1525 auto_ptr< SMESH_ElementSearcher > pntCls
1526 ( SMESH_MeshAlgos::GetElementSearcher(*theMesh->GetMeshDS()));
1528 int nbEnforcedVertices = theEnforcedVertices.size();
1531 int nbFaces = theProxyMesh.NbFaces();
1534 // groups management
1535 int usedEnforcedNodes = 0;
1536 std::string gn = "";
1541 idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1545 /* ========================== FACES ========================== */
1546 /* TRIANGLES ========================== */
1547 SMDS_ElemIteratorPtr eIt = theProxyMesh.GetFaces();
1548 while ( eIt->more() )
1551 anElemSet.insert(elem);
1552 nodeIt = elem->nodesIterator();
1553 nbNodes = elem->NbCornerNodes();
1554 while ( nodeIt->more() && nbNodes--)
1557 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1558 int newId = aNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
1559 aNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1563 /* EDGES ========================== */
1565 // Iterate over the enforced edges
1566 for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
1567 elem = elemIt->first;
1569 nodeIt = elem->nodesIterator();
1571 while ( nodeIt->more() && nbNodes-- ) {
1573 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1574 // Test if point is inside shape to mesh
1575 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1576 TopAbs_State result = pntCls->GetPointState( myPoint );
1577 if ( result == TopAbs_OUT ) {
1581 aNodeToTopAbs_StateMap.insert( make_pair( node, result ));
1584 nodeIt = elem->nodesIterator();
1587 while ( nodeIt->more() && nbNodes-- ) {
1589 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1590 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1591 nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1593 std::cout << "Node at "<<node->X()<<", "<<node->Y()<<", "<<node->Z()<<std::endl;
1594 std::cout << "Nb nodes found : "<<nbFoundElems<<std::endl;
1596 if (nbFoundElems ==0) {
1597 if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1598 newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
1599 anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1602 else if (nbFoundElems ==1) {
1603 const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1604 newId = (*aNodeToGhs3dIdMap.find(existingNode)).second;
1605 anExistingEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1610 std::cout << "GHS3D node ID: "<<newId<<std::endl;
1614 theKeptEnforcedEdges.insert(elem);
1618 /* ENFORCED TRIANGLES ========================== */
1620 // Iterate over the enforced triangles
1621 for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
1622 elem = elemIt->first;
1624 nodeIt = elem->nodesIterator();
1626 while ( nodeIt->more() && nbNodes--) {
1628 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1629 // Test if point is inside shape to mesh
1630 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1631 TopAbs_State result = pntCls->GetPointState( myPoint );
1632 if ( result == TopAbs_OUT ) {
1636 aNodeToTopAbs_StateMap.insert( make_pair( node, result ));
1639 nodeIt = elem->nodesIterator();
1642 while ( nodeIt->more() && nbNodes--) {
1644 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1645 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1646 nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1648 std::cout << "Nb nodes found : "<<nbFoundElems<<std::endl;
1650 if (nbFoundElems ==0) {
1651 if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1652 newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1
1653 anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1656 else if (nbFoundElems ==1) {
1657 const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1658 newId = (*aNodeToGhs3dIdMap.find(existingNode)).second;
1659 anExistingEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId ));
1664 std::cout << "GHS3D node ID: "<<newId<<std::endl;
1668 theKeptEnforcedTriangles.insert(elem);
1672 // put nodes to theNodeByGhs3dId vector
1674 std::cout << "aNodeToGhs3dIdMap.size(): "<<aNodeToGhs3dIdMap.size()<<std::endl;
1676 theNodeByGhs3dId.resize( aNodeToGhs3dIdMap.size() );
1677 map<const SMDS_MeshNode*,int>::const_iterator n2id = aNodeToGhs3dIdMap.begin();
1678 for ( ; n2id != aNodeToGhs3dIdMap.end(); ++ n2id)
1680 // std::cout << "n2id->first: "<<n2id->first<<std::endl;
1681 theNodeByGhs3dId[ n2id->second - 1 ] = n2id->first; // ghs3d ids count from 1
1684 // put nodes to anEnforcedNodeToGhs3dIdMap vector
1686 std::cout << "anEnforcedNodeToGhs3dIdMap.size(): "<<anEnforcedNodeToGhs3dIdMap.size()<<std::endl;
1688 theEnforcedNodeByGhs3dId.resize( anEnforcedNodeToGhs3dIdMap.size());
1689 n2id = anEnforcedNodeToGhs3dIdMap.begin();
1690 for ( ; n2id != anEnforcedNodeToGhs3dIdMap.end(); ++ n2id)
1692 if (n2id->second > aNodeToGhs3dIdMap.size()) {
1693 theEnforcedNodeByGhs3dId[ n2id->second - aNodeToGhs3dIdMap.size() - 1 ] = n2id->first; // ghs3d ids count from 1
1698 /* ========================== NODES ========================== */
1699 vector<const SMDS_MeshNode*> theOrderedNodes, theRequiredNodes;
1700 std::set< std::vector<double> > nodesCoords;
1701 vector<const SMDS_MeshNode*>::const_iterator ghs3dNodeIt = theNodeByGhs3dId.begin();
1702 vector<const SMDS_MeshNode*>::const_iterator after = theNodeByGhs3dId.end();
1704 (theNodeByGhs3dId.size() <= 1) ? tmpStr = " node" : " nodes";
1705 std::cout << theNodeByGhs3dId.size() << tmpStr << " from mesh ..." << 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());
1713 nodesCoords.insert(coords);
1714 theOrderedNodes.push_back(node);
1717 // Iterate over the enforced nodes given by enforced elements
1718 ghs3dNodeIt = theEnforcedNodeByGhs3dId.begin();
1719 after = theEnforcedNodeByGhs3dId.end();
1720 (theEnforcedNodeByGhs3dId.size() <= 1) ? tmpStr = " node" : " nodes";
1721 std::cout << theEnforcedNodeByGhs3dId.size() << tmpStr << " from enforced elements ..." << std::endl;
1722 for ( ; ghs3dNodeIt != after; ++ghs3dNodeIt )
1724 const SMDS_MeshNode* node = *ghs3dNodeIt;
1725 std::vector<double> coords;
1726 coords.push_back(node->X());
1727 coords.push_back(node->Y());
1728 coords.push_back(node->Z());
1730 std::cout << "Node at " << node->X()<<", " <<node->Y()<<", " <<node->Z();
1733 if (nodesCoords.find(coords) != nodesCoords.end()) {
1734 // node already exists in original mesh
1736 std::cout << " found" << std::endl;
1741 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) {
1742 // node already exists in enforced vertices
1744 std::cout << " found" << std::endl;
1749 // gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1750 // nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1751 // if (nbFoundElems ==0) {
1752 // std::cout << " not found" << std::endl;
1753 // if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1754 // nodesCoords.insert(coords);
1755 // theOrderedNodes.push_back(node);
1759 // std::cout << " found in initial mesh" << std::endl;
1760 // const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1761 // nodesCoords.insert(coords);
1762 // theOrderedNodes.push_back(existingNode);
1766 std::cout << " not found" << std::endl;
1769 nodesCoords.insert(coords);
1770 theOrderedNodes.push_back(node);
1771 // theRequiredNodes.push_back(node);
1775 // Iterate over the enforced nodes
1776 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt;
1777 (theEnforcedNodes.size() <= 1) ? tmpStr = " node" : " nodes";
1778 std::cout << theEnforcedNodes.size() << tmpStr << " from enforced nodes ..." << std::endl;
1779 for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt)
1781 const SMDS_MeshNode* node = enfNodeIt->first;
1782 std::vector<double> coords;
1783 coords.push_back(node->X());
1784 coords.push_back(node->Y());
1785 coords.push_back(node->Z());
1787 std::cout << "Node at " << node->X()<<", " <<node->Y()<<", " <<node->Z();
1790 // Test if point is inside shape to mesh
1791 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1792 TopAbs_State result = pntCls->GetPointState( myPoint );
1793 if ( result == TopAbs_OUT ) {
1795 std::cout << " out of volume" << std::endl;
1800 if (nodesCoords.find(coords) != nodesCoords.end()) {
1802 std::cout << " found in nodesCoords" << std::endl;
1804 // theRequiredNodes.push_back(node);
1808 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) {
1810 std::cout << " found in theEnforcedVertices" << std::endl;
1815 // nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1816 // if (nbFoundElems ==0) {
1817 // std::cout << " not found" << std::endl;
1818 // if (result == TopAbs_IN) {
1819 // nodesCoords.insert(coords);
1820 // theRequiredNodes.push_back(node);
1824 // std::cout << " found in initial mesh" << std::endl;
1825 // const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1826 // // nodesCoords.insert(coords);
1827 // theRequiredNodes.push_back(existingNode);
1832 // if (pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems) == 0)
1835 // if ( result != TopAbs_IN )
1839 std::cout << " not found" << std::endl;
1841 nodesCoords.insert(coords);
1842 // theOrderedNodes.push_back(node);
1843 theRequiredNodes.push_back(node);
1845 int requiredNodes = theRequiredNodes.size();
1848 std::vector<std::vector<double> > ReqVerTab;
1849 if (nbEnforcedVertices) {
1850 // ReqVerTab.clear();
1851 (nbEnforcedVertices <= 1) ? tmpStr = " node" : " nodes";
1852 std::cout << nbEnforcedVertices << tmpStr << " from enforced vertices ..." << std::endl;
1853 // Iterate over the enforced vertices
1854 for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
1855 double x = vertexIt->first[0];
1856 double y = vertexIt->first[1];
1857 double z = vertexIt->first[2];
1858 // Test if point is inside shape to mesh
1859 gp_Pnt myPoint(x,y,z);
1860 TopAbs_State result = pntCls->GetPointState( myPoint );
1861 if ( result == TopAbs_OUT )
1863 //if (pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems) == 0)
1866 // if ( result != TopAbs_IN )
1868 std::vector<double> coords;
1869 coords.push_back(x);
1870 coords.push_back(y);
1871 coords.push_back(z);
1872 ReqVerTab.push_back(coords);
1873 enfVertexSizes.push_back(vertexIt->second);
1880 std::cout << "Begin writting required nodes in GmfVertices" << std::endl;
1881 std::cout << "Nb vertices: " << theOrderedNodes.size() << std::endl;
1882 GmfSetKwd(idx, GmfVertices, theOrderedNodes.size()/*+solSize*/);
1883 for (ghs3dNodeIt = theOrderedNodes.begin();ghs3dNodeIt != theOrderedNodes.end();++ghs3dNodeIt) {
1884 GmfSetLin(idx, GmfVertices, (*ghs3dNodeIt)->X(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint);
1887 std::cout << "End writting required nodes in GmfVertices" << std::endl;
1889 if (requiredNodes + solSize) {
1890 std::cout << "Begin writting in req and sol file" << std::endl;
1891 aNodeGroupByGhs3dId.resize( requiredNodes + solSize );
1892 idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1897 idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1901 GmfCloseMesh(idxRequired);
1904 int TypTab[] = {GmfSca};
1905 double ValTab[] = {0.0};
1906 GmfSetKwd(idxRequired, GmfVertices, requiredNodes + solSize);
1907 GmfSetKwd(idxSol, GmfSolAtVertices, requiredNodes + solSize, 1, TypTab);
1908 // int usedEnforcedNodes = 0;
1909 // std::string gn = "";
1910 for (ghs3dNodeIt = theRequiredNodes.begin();ghs3dNodeIt != theRequiredNodes.end();++ghs3dNodeIt) {
1911 GmfSetLin(idxRequired, GmfVertices, (*ghs3dNodeIt)->X(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint);
1912 GmfSetLin(idxSol, GmfSolAtVertices, ValTab);
1913 if (theEnforcedNodes.find((*ghs3dNodeIt)) != theEnforcedNodes.end())
1914 gn = theEnforcedNodes.find((*ghs3dNodeIt))->second;
1915 aNodeGroupByGhs3dId[usedEnforcedNodes] = gn;
1916 usedEnforcedNodes++;
1919 for (int i=0;i<solSize;i++) {
1920 std::cout << ReqVerTab[i][0] <<" "<< ReqVerTab[i][1] << " "<< ReqVerTab[i][2] << std::endl;
1922 std::cout << "enfVertexSizes.at("<<i<<"): " << enfVertexSizes.at(i) << std::endl;
1924 double solTab[] = {enfVertexSizes.at(i)};
1925 GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
1926 GmfSetLin(idxSol, GmfSolAtVertices, solTab);
1927 aNodeGroupByGhs3dId[usedEnforcedNodes] = enfVerticesWithGroup.find(ReqVerTab[i])->second;
1929 std::cout << "aNodeGroupByGhs3dId["<<usedEnforcedNodes<<"] = \""<<aNodeGroupByGhs3dId[usedEnforcedNodes]<<"\""<<std::endl;
1931 usedEnforcedNodes++;
1933 std::cout << "End writting in req and sol file" << std::endl;
1936 int nedge[2], ntri[3];
1939 int usedEnforcedEdges = 0;
1940 if (theKeptEnforcedEdges.size()) {
1941 anEdgeGroupByGhs3dId.resize( theKeptEnforcedEdges.size() );
1942 // idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1943 // if (!idxRequired)
1945 GmfSetKwd(idx, GmfEdges, theKeptEnforcedEdges.size());
1946 // GmfSetKwd(idxRequired, GmfEdges, theKeptEnforcedEdges.size());
1947 for(elemSetIt = theKeptEnforcedEdges.begin() ; elemSetIt != theKeptEnforcedEdges.end() ; ++elemSetIt) {
1948 elem = (*elemSetIt);
1949 nodeIt = elem->nodesIterator();
1951 while ( nodeIt->more() ) {
1953 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1954 map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node);
1955 if (it == anEnforcedNodeToGhs3dIdMap.end()) {
1956 it = anExistingEnforcedNodeToGhs3dIdMap.find(node);
1957 if (it == anEnforcedNodeToGhs3dIdMap.end())
1958 throw "Node not found";
1960 nedge[index] = it->second;
1963 GmfSetLin(idx, GmfEdges, nedge[0], nedge[1], dummyint);
1964 anEdgeGroupByGhs3dId[usedEnforcedEdges] = theEnforcedEdges.find(elem)->second;
1965 // GmfSetLin(idxRequired, GmfEdges, nedge[0], nedge[1], dummyint);
1966 usedEnforcedEdges++;
1968 // GmfCloseMesh(idxRequired);
1972 if (usedEnforcedEdges) {
1973 GmfSetKwd(idx, GmfRequiredEdges, usedEnforcedEdges);
1974 for (int enfID=1;enfID<=usedEnforcedEdges;enfID++) {
1975 GmfSetLin(idx, GmfRequiredEdges, enfID);
1980 int usedEnforcedTriangles = 0;
1981 if (anElemSet.size()+theKeptEnforcedTriangles.size()) {
1982 aFaceGroupByGhs3dId.resize( anElemSet.size()+theKeptEnforcedTriangles.size() );
1983 GmfSetKwd(idx, GmfTriangles, anElemSet.size()+theKeptEnforcedTriangles.size());
1985 for(elemSetIt = anElemSet.begin() ; elemSetIt != anElemSet.end() ; ++elemSetIt,++k) {
1986 elem = (*elemSetIt);
1987 nodeIt = elem->nodesIterator();
1989 for ( int j = 0; j < 3; ++j ) {
1991 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1992 map< const SMDS_MeshNode*,int >::iterator it = aNodeToGhs3dIdMap.find(node);
1993 if (it == aNodeToGhs3dIdMap.end())
1994 throw "Node not found";
1995 ntri[index] = it->second;
1998 GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint);
1999 aFaceGroupByGhs3dId[k] = "";
2001 if (theKeptEnforcedTriangles.size()) {
2002 for(elemSetIt = theKeptEnforcedTriangles.begin() ; elemSetIt != theKeptEnforcedTriangles.end() ; ++elemSetIt,++k) {
2003 elem = (*elemSetIt);
2004 nodeIt = elem->nodesIterator();
2006 for ( int j = 0; j < 3; ++j ) {
2008 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
2009 map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node);
2010 if (it == anEnforcedNodeToGhs3dIdMap.end()) {
2011 it = anExistingEnforcedNodeToGhs3dIdMap.find(node);
2012 if (it == anEnforcedNodeToGhs3dIdMap.end())
2013 throw "Node not found";
2015 ntri[index] = it->second;
2018 GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint);
2019 aFaceGroupByGhs3dId[k] = theEnforcedTriangles.find(elem)->second;
2020 usedEnforcedTriangles++;
2026 if (usedEnforcedTriangles) {
2027 GmfSetKwd(idx, GmfRequiredTriangles, usedEnforcedTriangles);
2028 for (int enfID=1;enfID<=usedEnforcedTriangles;enfID++)
2029 GmfSetLin(idx, GmfRequiredTriangles, anElemSet.size()+enfID);
2034 GmfCloseMesh(idxRequired);
2036 GmfCloseMesh(idxSol);
2042 // static bool writeGMFFile(const char* theMeshFileName,
2043 // const char* theRequiredFileName,
2044 // const char* theSolFileName,
2045 // SMESH_MesherHelper& theHelper,
2046 // const SMESH_ProxyMesh& theProxyMesh,
2047 // std::map <int,int> & theNodeId2NodeIndexMap,
2048 // std::map <int,int> & theSmdsToGhs3dIdMap,
2049 // std::map <int,const SMDS_MeshNode*> & theGhs3dIdToNodeMap,
2050 // TIDSortedNodeSet & theEnforcedNodes,
2051 // TIDSortedElemSet & theEnforcedEdges,
2052 // TIDSortedElemSet & theEnforcedTriangles,
2053 // // TIDSortedElemSet & theEnforcedQuadrangles,
2054 // GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices)
2056 // MESSAGE("writeGMFFile with geometry");
2057 // int idx, idxRequired, idxSol;
2058 // int nbv, nbev, nben, aGhs3dID = 0;
2059 // const int dummyint = 0;
2060 // GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt;
2061 // std::vector<double> enfVertexSizes;
2062 // TIDSortedNodeSet::const_iterator enfNodeIt;
2063 // const SMDS_MeshNode* node;
2064 // SMDS_NodeIteratorPtr nodeIt;
2066 // idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
2070 // SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS();
2072 // /* ========================== NODES ========================== */
2074 // nbv = theMeshDS->NbNodes();
2077 // nbev = theEnforcedVertices.size();
2078 // nben = theEnforcedNodes.size();
2080 // // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D
2081 // // The problem is in nodes on degenerated edges, we need to skip nodes which are free
2082 // // and replace not-free nodes on edges by the node on vertex
2083 // TNodeNodeMap n2nDegen; // map a node on degenerated edge to a node on vertex
2084 // TNodeNodeMap::iterator n2nDegenIt;
2085 // if ( theHelper.HasDegeneratedEdges() )
2087 // set<int> checkedSM;
2088 // for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next())
2090 // SMESH_subMesh* sm = theHelper.GetMesh()->GetSubMesh( e.Current() );
2091 // if ( checkedSM.insert( sm->GetId() ).second && theHelper.IsDegenShape(sm->GetId() ))
2093 // if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() )
2095 // TopoDS_Shape vertex = TopoDS_Iterator( e.Current() ).Value();
2096 // const SMDS_MeshNode* vNode = SMESH_Algo::VertexNode( TopoDS::Vertex( vertex ), theMeshDS);
2098 // SMDS_NodeIteratorPtr nIt = smDS->GetNodes();
2099 // while ( nIt->more() )
2100 // n2nDegen.insert( make_pair( nIt->next(), vNode ));
2107 // const bool isQuadMesh =
2108 // theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
2109 // theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
2110 // theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC );
2112 // std::vector<std::vector<double> > VerTab;
2113 // std::set<std::vector<double> > VerMap;
2115 // std::vector<double> aVerTab;
2116 // // Loop from 1 to NB_NODES
2118 // nodeIt = theMeshDS->nodesIterator();
2120 // while ( nodeIt->more() )
2122 // node = nodeIt->next();
2123 // if ( isQuadMesh && theHelper.IsMedium( node )) // Issue 0021238
2125 // if ( n2nDegen.count( node ) ) // Issue 0020674
2128 // std::vector<double> coords;
2129 // coords.push_back(node->X());
2130 // coords.push_back(node->Y());
2131 // coords.push_back(node->Z());
2132 // if (VerMap.find(coords) != VerMap.end()) {
2133 // aGhs3dID = theSmdsToGhs3dIdMap[node->GetID()];
2134 // theGhs3dIdToNodeMap[theSmdsToGhs3dIdMap[node->GetID()]] = node;
2137 // VerTab.push_back(coords);
2138 // VerMap.insert(coords);
2140 // theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID ));
2141 // theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node ));
2145 // /* ENFORCED NODES ========================== */
2147 // std::cout << "Add " << nben << " enforced nodes to input .mesh file" << std::endl;
2148 // for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt) {
2149 // double x = (*enfNodeIt)->X();
2150 // double y = (*enfNodeIt)->Y();
2151 // double z = (*enfNodeIt)->Z();
2152 // // Test if point is inside shape to mesh
2153 // gp_Pnt myPoint(x,y,z);
2154 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2155 // scl.Perform(myPoint, 1e-7);
2156 // TopAbs_State result = scl.State();
2157 // if ( result != TopAbs_IN )
2159 // std::vector<double> coords;
2160 // coords.push_back(x);
2161 // coords.push_back(y);
2162 // coords.push_back(z);
2163 // if (theEnforcedVertices.find(coords) != theEnforcedVertices.end())
2165 // if (VerMap.find(coords) != VerMap.end())
2167 // VerTab.push_back(coords);
2168 // VerMap.insert(coords);
2170 // theNodeId2NodeIndexMap.insert( make_pair( (*enfNodeIt)->GetID(), aGhs3dID ));
2175 // /* ENFORCED VERTICES ========================== */
2177 // std::vector<std::vector<double> > ReqVerTab;
2178 // ReqVerTab.clear();
2180 // std::cout << "Add " << nbev << " enforced vertices to input .mesh file" << std::endl;
2181 // for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
2182 // double x = vertexIt->first[0];
2183 // double y = vertexIt->first[1];
2184 // double z = vertexIt->first[2];
2185 // // Test if point is inside shape to mesh
2186 // gp_Pnt myPoint(x,y,z);
2187 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2188 // scl.Perform(myPoint, 1e-7);
2189 // TopAbs_State result = scl.State();
2190 // if ( result != TopAbs_IN )
2192 // enfVertexSizes.push_back(vertexIt->second);
2193 // std::vector<double> coords;
2194 // coords.push_back(x);
2195 // coords.push_back(y);
2196 // coords.push_back(z);
2197 // if (VerMap.find(coords) != VerMap.end())
2199 // ReqVerTab.push_back(coords);
2200 // VerMap.insert(coords);
2206 // /* ========================== FACES ========================== */
2208 // int nbTriangles = 0/*, nbQuadrangles = 0*/, aSmdsID;
2209 // TopTools_IndexedMapOfShape facesMap, trianglesMap/*, quadranglesMap*/;
2210 // TIDSortedElemSet::const_iterator elemIt;
2211 // const SMESHDS_SubMesh* theSubMesh;
2212 // TopoDS_Shape aShape;
2213 // SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace;
2214 // const SMDS_MeshElement* aFace;
2215 // map<int,int>::const_iterator itOnMap;
2216 // std::vector<std::vector<int> > tt, qt,et;
2220 // std::vector<int> att, aqt, aet;
2222 // TopExp::MapShapes( theMeshDS->ShapeToMesh(), TopAbs_FACE, facesMap );
2224 // for ( int i = 1; i <= facesMap.Extent(); ++i )
2225 // if (( theSubMesh = theProxyMesh.GetSubMesh( facesMap(i))))
2227 // SMDS_ElemIteratorPtr it = theSubMesh->GetElements();
2228 // while (it->more())
2230 // const SMDS_MeshElement *elem = it->next();
2231 // int nbCornerNodes = elem->NbCornerNodes();
2232 // if (nbCornerNodes == 3)
2234 // trianglesMap.Add(facesMap(i));
2237 // // else if (nbCornerNodes == 4)
2239 // // quadranglesMap.Add(facesMap(i));
2240 // // nbQuadrangles ++;
2245 // /* TRIANGLES ========================== */
2246 // if (nbTriangles) {
2247 // for ( int i = 1; i <= trianglesMap.Extent(); i++ )
2249 // aShape = trianglesMap(i);
2250 // theSubMesh = theProxyMesh.GetSubMesh(aShape);
2251 // if ( !theSubMesh ) continue;
2252 // itOnSubMesh = theSubMesh->GetElements();
2253 // while ( itOnSubMesh->more() )
2255 // aFace = itOnSubMesh->next();
2256 // itOnSubFace = aFace->nodesIterator();
2258 // for ( int j = 0; j < 3; ++j ) {
2260 // node = castToNode( itOnSubFace->next() );
2261 // if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() )
2262 // node = n2nDegenIt->second;
2263 // aSmdsID = node->GetID();
2264 // itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
2265 // ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
2266 // att.push_back((*itOnMap).second);
2268 // tt.push_back(att);
2273 // if (theEnforcedTriangles.size()) {
2274 // std::cout << "Add " << theEnforcedTriangles.size() << " enforced triangles to input .mesh file" << std::endl;
2275 // // Iterate over the enforced triangles
2276 // for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
2277 // aFace = (*elemIt);
2278 // itOnSubFace = aFace->nodesIterator();
2279 // bool isOK = true;
2282 // for ( int j = 0; j < 3; ++j ) {
2283 // node = castToNode( itOnSubFace->next() );
2284 // if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() )
2285 // node = n2nDegenIt->second;
2286 // // std::cout << node;
2287 // double x = node->X();
2288 // double y = node->Y();
2289 // double z = node->Z();
2290 // // Test if point is inside shape to mesh
2291 // gp_Pnt myPoint(x,y,z);
2292 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2293 // scl.Perform(myPoint, 1e-7);
2294 // TopAbs_State result = scl.State();
2295 // if ( result != TopAbs_IN ) {
2297 // theEnforcedTriangles.erase(elemIt);
2300 // std::vector<double> coords;
2301 // coords.push_back(x);
2302 // coords.push_back(y);
2303 // coords.push_back(z);
2304 // if (VerMap.find(coords) != VerMap.end()) {
2305 // att.push_back(theNodeId2NodeIndexMap[node->GetID()]);
2308 // VerTab.push_back(coords);
2309 // VerMap.insert(coords);
2311 // theNodeId2NodeIndexMap.insert( make_pair( node->GetID(), aGhs3dID ));
2312 // att.push_back(aGhs3dID);
2315 // tt.push_back(att);
2320 // /* ========================== EDGES ========================== */
2322 // if (theEnforcedEdges.size()) {
2323 // // Iterate over the enforced edges
2324 // std::cout << "Add " << theEnforcedEdges.size() << " enforced edges to input .mesh file" << std::endl;
2325 // for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
2326 // aFace = (*elemIt);
2327 // bool isOK = true;
2328 // itOnSubFace = aFace->nodesIterator();
2330 // for ( int j = 0; j < 2; ++j ) {
2331 // node = castToNode( itOnSubFace->next() );
2332 // if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() )
2333 // node = n2nDegenIt->second;
2334 // double x = node->X();
2335 // double y = node->Y();
2336 // double z = node->Z();
2337 // // Test if point is inside shape to mesh
2338 // gp_Pnt myPoint(x,y,z);
2339 // BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh());
2340 // scl.Perform(myPoint, 1e-7);
2341 // TopAbs_State result = scl.State();
2342 // if ( result != TopAbs_IN ) {
2344 // theEnforcedEdges.erase(elemIt);
2347 // std::vector<double> coords;
2348 // coords.push_back(x);
2349 // coords.push_back(y);
2350 // coords.push_back(z);
2351 // if (VerMap.find(coords) != VerMap.end()) {
2352 // aet.push_back(theNodeId2NodeIndexMap[node->GetID()]);
2355 // VerTab.push_back(coords);
2356 // VerMap.insert(coords);
2359 // theNodeId2NodeIndexMap.insert( make_pair( node->GetID(), aGhs3dID ));
2360 // aet.push_back(aGhs3dID);
2363 // et.push_back(aet);
2368 // /* Write vertices number */
2369 // MESSAGE("Number of vertices: "<<aGhs3dID);
2370 // MESSAGE("Size of vector: "<<VerTab.size());
2371 // GmfSetKwd(idx, GmfVertices, aGhs3dID/*+solSize*/);
2372 // for (int i=0;i<aGhs3dID;i++)
2373 // GmfSetLin(idx, GmfVertices, VerTab[i][0], VerTab[i][1], VerTab[i][2], dummyint);
2374 // // for (int i=0;i<solSize;i++) {
2375 // // std::cout << ReqVerTab[i][0] <<" "<< ReqVerTab[i][1] << " "<< ReqVerTab[i][2] << std::endl;
2376 // // GmfSetLin(idx, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
2380 // idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
2381 // if (!idxRequired) {
2382 // GmfCloseMesh(idx);
2385 // idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
2387 // GmfCloseMesh(idx);
2389 // GmfCloseMesh(idxRequired);
2393 // int TypTab[] = {GmfSca};
2394 // GmfSetKwd(idxRequired, GmfVertices, solSize);
2395 // GmfSetKwd(idxSol, GmfSolAtVertices, solSize, 1, TypTab);
2397 // for (int i=0;i<solSize;i++) {
2398 // double solTab[] = {enfVertexSizes.at(i)};
2399 // GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint);
2400 // GmfSetLin(idxSol, GmfSolAtVertices, solTab);
2402 // GmfCloseMesh(idxRequired);
2403 // GmfCloseMesh(idxSol);
2406 // /* Write triangles number */
2408 // GmfSetKwd(idx, GmfTriangles, tt.size());
2409 // for (int i=0;i<tt.size();i++)
2410 // GmfSetLin(idx, GmfTriangles, tt[i][0], tt[i][1], tt[i][2], dummyint);
2413 // /* Write edges number */
2415 // GmfSetKwd(idx, GmfEdges, et.size());
2416 // for (int i=0;i<et.size();i++)
2417 // GmfSetLin(idx, GmfEdges, et[i][0], et[i][1], dummyint);
2420 // /* QUADRANGLES ========================== */
2421 // // TODO: add pyramids ?
2422 // // if (nbQuadrangles) {
2423 // // for ( int i = 1; i <= quadranglesMap.Extent(); i++ )
2425 // // aShape = quadranglesMap(i);
2426 // // theSubMesh = theProxyMesh.GetSubMesh(aShape);
2427 // // if ( !theSubMesh ) continue;
2428 // // itOnSubMesh = theSubMesh->GetElements();
2429 // // for ( int j = 0; j < 4; ++j )
2431 // // aFace = itOnSubMesh->next();
2432 // // itOnSubFace = aFace->nodesIterator();
2434 // // while ( itOnSubFace->more() ) {
2435 // // // find GHS3D ID
2436 // // aSmdsID = itOnSubFace->next()->GetID();
2437 // // itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
2438 // // ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
2439 // // aqt.push_back((*itOnMap).second);
2441 // // qt.push_back(aqt);
2446 // // if (theEnforcedQuadrangles.size()) {
2447 // // // Iterate over the enforced triangles
2448 // // for(elemIt = theEnforcedQuadrangles.begin() ; elemIt != theEnforcedQuadrangles.end() ; ++elemIt) {
2449 // // aFace = (*elemIt);
2450 // // bool isOK = true;
2451 // // itOnSubFace = aFace->nodesIterator();
2453 // // for ( int j = 0; j < 4; ++j ) {
2454 // // int aNodeID = itOnSubFace->next()->GetID();
2455 // // itOnMap = theNodeId2NodeIndexMap.find(aNodeID);
2456 // // if (itOnMap != theNodeId2NodeIndexMap.end())
2457 // // aqt.push_back((*itOnMap).second);
2460 // // theEnforcedQuadrangles.erase(elemIt);
2465 // // qt.push_back(aqt);
2470 // // /* Write quadrilaterals number */
2471 // // if (qt.size()) {
2472 // // GmfSetKwd(idx, GmfQuadrilaterals, qt.size());
2473 // // for (int i=0;i<qt.size();i++)
2474 // // GmfSetLin(idx, GmfQuadrilaterals, qt[i][0], qt[i][1], qt[i][2], qt[i][3], dummyint);
2477 // GmfCloseMesh(idx);
2482 //=======================================================================
2483 //function : writeFaces
2485 //=======================================================================
2487 static bool writeFaces (ofstream & theFile,
2488 const SMESH_ProxyMesh& theMesh,
2489 const TopoDS_Shape& theShape,
2490 const map <int,int> & theSmdsToGhs3dIdMap,
2491 const map <int,int> & theEnforcedNodeIdToGhs3dIdMap,
2492 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
2493 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles)
2495 // record structure:
2497 // NB_ELEMS DUMMY_INT
2498 // Loop from 1 to NB_ELEMS
2499 // NB_NODES NODE_NB_1 NODE_NB_2 ... (NB_NODES + 1) times: DUMMY_INT
2501 TopoDS_Shape aShape;
2502 const SMESHDS_SubMesh* theSubMesh;
2503 const SMDS_MeshElement* aFace;
2504 const char* space = " ";
2505 const int dummyint = 0;
2506 map<int,int>::const_iterator itOnMap;
2507 SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace;
2508 int nbNodes, aSmdsID;
2510 TIDSortedElemSet::const_iterator elemIt;
2511 int nbEnforcedEdges = theEnforcedEdges.size();
2512 int nbEnforcedTriangles = theEnforcedTriangles.size();
2514 // count triangles bound to geometry
2515 int nbTriangles = 0;
2517 TopTools_IndexedMapOfShape facesMap, trianglesMap;
2518 TopExp::MapShapes( theShape, TopAbs_FACE, facesMap );
2520 int nbFaces = facesMap.Extent();
2522 for ( int i = 1; i <= nbFaces; ++i )
2523 if (( theSubMesh = theMesh.GetSubMesh( facesMap(i))))
2524 nbTriangles += theSubMesh->NbElements();
2526 (nbFaces == 0 || nbFaces == 1) ? tmpStr = " shape " : tmpStr = " shapes " ;
2527 std::cout << " " << nbFaces << tmpStr << "of 2D dimension";
2528 int nbEnforcedElements = nbEnforcedEdges+nbEnforcedTriangles;
2529 if (nbEnforcedElements > 0) {
2530 (nbEnforcedElements == 1) ? tmpStr = "shape:" : tmpStr = "shapes:";
2531 std::cout << " and" << std::endl;
2532 std::cout << " " << nbEnforcedElements
2533 << " enforced " << tmpStr << std::endl;
2536 std::cout << std::endl;
2537 if (nbEnforcedEdges) {
2538 (nbEnforcedEdges == 1) ? tmpStr = "edge" : tmpStr = "edges";
2539 std::cout << " " << nbEnforcedEdges << " enforced " << tmpStr << std::endl;
2541 if (nbEnforcedTriangles) {
2542 (nbEnforcedTriangles == 1) ? tmpStr = "triangle" : tmpStr = "triangles";
2543 std::cout << " " << nbEnforcedTriangles << " enforced " << tmpStr << std::endl;
2545 std::cout << std::endl;
2547 // theFile << space << nbTriangles << space << dummyint << std::endl;
2548 std::ostringstream globalStream, localStream, aStream;
2550 for ( int i = 1; i <= facesMap.Extent(); i++ )
2552 aShape = facesMap(i);
2553 theSubMesh = theMesh.GetSubMesh(aShape);
2554 if ( !theSubMesh ) continue;
2555 itOnSubMesh = theSubMesh->GetElements();
2556 while ( itOnSubMesh->more() )
2558 aFace = itOnSubMesh->next();
2559 nbNodes = aFace->NbCornerNodes();
2561 localStream << nbNodes << space;
2563 itOnSubFace = aFace->nodesIterator();
2564 for ( int j = 0; j < 3; ++j ) {
2566 aSmdsID = itOnSubFace->next()->GetID();
2567 itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID );
2568 // if ( itOnMap == theSmdsToGhs3dIdMap.end() ) {
2569 // cout << "not found node: " << aSmdsID << endl;
2572 ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() );
2574 localStream << (*itOnMap).second << space ;
2577 // (NB_NODES + 1) times: DUMMY_INT
2578 for ( int j=0; j<=nbNodes; j++)
2579 localStream << dummyint << space ;
2581 localStream << std::endl;
2585 globalStream << localStream.str();
2586 localStream.str("");
2593 // // ENFORCED EDGES : BEGIN
2596 // // Iterate over the enforced edges
2597 // int usedEnforcedEdges = 0;
2599 // for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
2600 // aFace = (*elemIt);
2602 // itOnSubFace = aFace->nodesIterator();
2604 // aStream << "2" << space ;
2605 // for ( int j = 0; j < 2; ++j ) {
2606 // aSmdsID = itOnSubFace->next()->GetID();
2607 // itOnMap = theEnforcedNodeIdToGhs3dIdMap.find(aSmdsID);
2608 // if (itOnMap != theEnforcedNodeIdToGhs3dIdMap.end())
2609 // aStream << (*itOnMap).second << space;
2616 // for ( int j=0; j<=2; j++)
2617 // aStream << dummyint << space ;
2618 // // aStream << dummyint << space << dummyint;
2619 // localStream << aStream.str() << std::endl;
2620 // usedEnforcedEdges++;
2624 // if (usedEnforcedEdges) {
2625 // globalStream << localStream.str();
2626 // localStream.str("");
2630 // // ENFORCED EDGES : END
2635 // // ENFORCED TRIANGLES : BEGIN
2637 // // Iterate over the enforced triangles
2638 // int usedEnforcedTriangles = 0;
2639 // for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
2640 // aFace = (*elemIt);
2641 // nbNodes = aFace->NbCornerNodes();
2643 // itOnSubFace = aFace->nodesIterator();
2645 // aStream << nbNodes << space ;
2646 // for ( int j = 0; j < 3; ++j ) {
2647 // aSmdsID = itOnSubFace->next()->GetID();
2648 // itOnMap = theEnforcedNodeIdToGhs3dIdMap.find(aSmdsID);
2649 // if (itOnMap != theEnforcedNodeIdToGhs3dIdMap.end())
2650 // aStream << (*itOnMap).second << space;
2657 // for ( int j=0; j<=3; j++)
2658 // aStream << dummyint << space ;
2659 // localStream << aStream.str() << std::endl;
2660 // usedEnforcedTriangles++;
2664 // if (usedEnforcedTriangles) {
2665 // globalStream << localStream.str();
2666 // localStream.str("");
2670 // // ENFORCED TRIANGLES : END
2674 << nbTriangles/*+usedEnforcedTriangles+usedEnforcedEdges*/
2675 << " 0" << std::endl
2676 << globalStream.str();
2681 //=======================================================================
2682 //function : writePoints
2684 //=======================================================================
2686 static bool writePoints (ofstream & theFile,
2687 SMESH_MesherHelper& theHelper,
2688 map <int,int> & theSmdsToGhs3dIdMap,
2689 map <int,int> & theEnforcedNodeIdToGhs3dIdMap,
2690 map <int,const SMDS_MeshNode*> & theGhs3dIdToNodeMap,
2691 GHS3DPlugin_Hypothesis::TID2SizeMap & theNodeIDToSizeMap,
2692 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices,
2693 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes,
2694 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
2695 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles)
2697 // record structure:
2700 // Loop from 1 to NB_NODES
2703 SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS();
2704 int nbNodes = theMeshDS->NbNodes();
2708 int nbEnforcedVertices = theEnforcedVertices.size();
2709 int nbEnforcedNodes = theEnforcedNodes.size();
2711 const TopoDS_Shape shapeToMesh = theMeshDS->ShapeToMesh();
2714 SMDS_NodeIteratorPtr nodeIt = theMeshDS->nodesIterator();
2715 const SMDS_MeshNode* node;
2717 // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D
2718 // The problem is in nodes on degenerated edges, we need to skip nodes which are free
2719 // and replace not-free nodes on degenerated edges by the node on vertex
2720 TNodeNodeMap n2nDegen; // map a node on degenerated edge to a node on vertex
2721 TNodeNodeMap::iterator n2nDegenIt;
2722 if ( theHelper.HasDegeneratedEdges() )
2725 for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next())
2727 SMESH_subMesh* sm = theHelper.GetMesh()->GetSubMesh( e.Current() );
2728 if ( checkedSM.insert( sm->GetId() ).second && theHelper.IsDegenShape(sm->GetId() ))
2730 if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() )
2732 TopoDS_Shape vertex = TopoDS_Iterator( e.Current() ).Value();
2733 const SMDS_MeshNode* vNode = SMESH_Algo::VertexNode( TopoDS::Vertex( vertex ), theMeshDS);
2735 SMDS_NodeIteratorPtr nIt = smDS->GetNodes();
2736 while ( nIt->more() )
2737 n2nDegen.insert( make_pair( nIt->next(), vNode ));
2742 nbNodes -= n2nDegen.size();
2745 const bool isQuadMesh =
2746 theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
2747 theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
2748 theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC );
2751 // descrease nbNodes by nb of medium nodes
2752 while ( nodeIt->more() )
2754 node = nodeIt->next();
2755 if ( !theHelper.IsDegenShape( node->getshapeId() ))
2756 nbNodes -= int( theHelper.IsMedium( node ));
2758 nodeIt = theMeshDS->nodesIterator();
2761 const char* space = " ";
2762 const int dummyint = 0;
2765 (nbNodes == 0 || nbNodes == 1) ? tmpStr = " node" : tmpStr = " nodes";
2767 std::cout << std::endl;
2768 std::cout << "The initial 2D mesh contains :" << std::endl;
2769 std::cout << " " << nbNodes << tmpStr << std::endl;
2770 if (nbEnforcedVertices > 0) {
2771 (nbEnforcedVertices == 1) ? tmpStr = "vertex" : tmpStr = "vertices";
2772 std::cout << " " << nbEnforcedVertices << " enforced " << tmpStr << std::endl;
2774 if (nbEnforcedNodes > 0) {
2775 (nbEnforcedNodes == 1) ? tmpStr = "node" : tmpStr = "nodes";
2776 std::cout << " " << nbEnforcedNodes << " enforced " << tmpStr << std::endl;
2778 std::cout << std::endl;
2779 std::cout << "Start writing in 'points' file ..." << std::endl;
2781 theFile << nbNodes << std::endl;
2783 // Loop from 1 to NB_NODES
2785 while ( nodeIt->more() )
2787 node = nodeIt->next();
2788 if ( isQuadMesh && theHelper.IsMedium( node )) // Issue 0021238
2790 if ( n2nDegen.count( node ) ) // Issue 0020674
2793 theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID ));
2794 theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node ));
2799 << node->X() << space
2800 << node->Y() << space
2801 << node->Z() << space
2804 theFile << std::endl;
2808 // Iterate over the enforced nodes
2809 std::map<int,double> enfVertexIndexSizeMap;
2810 if (nbEnforcedNodes) {
2811 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator nodeIt = theEnforcedNodes.begin();
2812 for( ; nodeIt != theEnforcedNodes.end() ; ++nodeIt) {
2813 double x = nodeIt->first->X();
2814 double y = nodeIt->first->Y();
2815 double z = nodeIt->first->Z();
2816 // Test if point is inside shape to mesh
2817 gp_Pnt myPoint(x,y,z);
2818 BRepClass3d_SolidClassifier scl(shapeToMesh);
2819 scl.Perform(myPoint, 1e-7);
2820 TopAbs_State result = scl.State();
2821 if ( result != TopAbs_IN )
2823 std::vector<double> coords;
2824 coords.push_back(x);
2825 coords.push_back(y);
2826 coords.push_back(z);
2827 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end())
2830 // double size = theNodeIDToSizeMap.find(nodeIt->first->GetID())->second;
2831 // theGhs3dIdToNodeMap.insert( make_pair( nbNodes + i, (*nodeIt) ));
2832 // MESSAGE("Adding enforced node (" << x << "," << y <<"," << z << ")");
2833 // X Y Z PHY_SIZE DUMMY_INT
2839 << dummyint << space;
2840 theFile << std::endl;
2841 theEnforcedNodeIdToGhs3dIdMap.insert( make_pair( nodeIt->first->GetID(), aGhs3dID ));
2842 enfVertexIndexSizeMap[aGhs3dID] = -1;
2845 // MESSAGE("Enforced vertex (" << x << "," << y <<"," << z << ") is not inside the geometry: it was not added ");
2849 if (nbEnforcedVertices) {
2850 // Iterate over the enforced vertices
2851 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt = theEnforcedVertices.begin();
2852 for( ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
2853 double x = vertexIt->first[0];
2854 double y = vertexIt->first[1];
2855 double z = vertexIt->first[2];
2856 // Test if point is inside shape to mesh
2857 gp_Pnt myPoint(x,y,z);
2858 BRepClass3d_SolidClassifier scl(shapeToMesh);
2859 scl.Perform(myPoint, 1e-7);
2860 TopAbs_State result = scl.State();
2861 if ( result != TopAbs_IN )
2863 MESSAGE("Adding enforced vertex (" << x << "," << y <<"," << z << ") = " << vertexIt->second);
2864 // X Y Z PHY_SIZE DUMMY_INT
2869 << vertexIt->second << space
2870 << dummyint << space;
2871 theFile << std::endl;
2872 enfVertexIndexSizeMap[aGhs3dID] = vertexIt->second;
2878 std::cout << std::endl;
2879 std::cout << "End writing in 'points' file." << std::endl;
2884 //=======================================================================
2885 //function : readResultFile
2886 //purpose : readResultFile with geometry
2887 //=======================================================================
2889 static bool readResultFile(const int fileOpen,
2891 const char* fileName,
2893 GHS3DPlugin_GHS3D* theAlgo,
2894 SMESH_MesherHelper& theHelper,
2895 TopoDS_Shape tabShape[],
2898 map <int,const SMDS_MeshNode*>& theGhs3dIdToNodeMap,
2899 std::map <int,int> & theNodeId2NodeIndexMap,
2901 int nbEnforcedVertices,
2902 int nbEnforcedNodes,
2903 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
2904 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles,
2905 bool toMakeGroupsOfDomains)
2907 MESSAGE("GHS3DPlugin_GHS3D::readResultFile()");
2908 Kernel_Utils::Localizer loc;
2918 SMESHDS_Mesh* theMeshDS = theHelper.GetMeshDS();
2920 int nbElems, nbNodes, nbInputNodes;
2922 int ID, shapeID, ghs3dShapeID;
2925 nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() );
2927 int *tab, *tabID, *nodeID, *nodeAssigne;
2929 const SMDS_MeshNode **node;
2932 nodeID = new int[4];
2933 coord = new double[3];
2934 node = new const SMDS_MeshNode*[4];
2936 TopoDS_Shape aSolid;
2937 SMDS_MeshNode * aNewNode;
2938 map <int,const SMDS_MeshNode*>::iterator itOnNode;
2939 SMDS_MeshElement* aTet;
2944 // Read the file state
2945 fstat(fileOpen, &status);
2946 length = status.st_size;
2948 // Mapping the result file into memory
2950 HANDLE fd = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ,
2951 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2952 HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY,
2953 0, (DWORD)length, NULL);
2954 ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 );
2956 ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
2960 ptr = readMapIntLine(ptr, tab);
2965 nbInputNodes = tab[2];
2967 nodeAssigne = new int[ nbNodes+1 ];
2970 aSolid = tabShape[0];
2972 // Reading the nodeId
2973 for (int i=0; i < 4*nbElems; i++)
2974 strtol(ptr, &ptr, 10);
2976 MESSAGE("nbInputNodes: "<<nbInputNodes);
2977 MESSAGE("nbEnforcedVertices: "<<nbEnforcedVertices);
2978 MESSAGE("nbEnforcedNodes: "<<nbEnforcedNodes);
2979 // Reading the nodeCoor and update the nodeMap
2980 for (int iNode=1; iNode <= nbNodes; iNode++) {
2981 if(theAlgo->computeCanceled())
2983 for (int iCoor=0; iCoor < 3; iCoor++)
2984 coord[ iCoor ] = strtod(ptr, &ptr);
2985 nodeAssigne[ iNode ] = 1;
2986 if ( iNode > (nbInputNodes-(nbEnforcedVertices+nbEnforcedNodes)) ) {
2987 // Creating SMESH nodes
2988 // - for enforced vertices
2989 // - for vertices of forced edges
2990 // - for ghs3d nodes
2991 nodeAssigne[ iNode ] = 0;
2992 aNewNode = theMeshDS->AddNode( coord[0],coord[1],coord[2] );
2993 theGhs3dIdToNodeMap.insert(theGhs3dIdToNodeMap.end(), make_pair( iNode, aNewNode ));
2997 // Reading the number of triangles which corresponds to the number of sub-domains
2998 nbTriangle = strtol(ptr, &ptr, 10);
3000 tabID = new int[nbTriangle];
3001 for (int i=0; i < nbTriangle; i++) {
3002 if(theAlgo->computeCanceled())
3005 // find the solid corresponding to GHS3D sub-domain following
3006 // the technique proposed in GHS3D manual in chapter
3007 // "B.4 Subdomain (sub-region) assignment"
3008 int nodeId1 = strtol(ptr, &ptr, 10);
3009 int nodeId2 = strtol(ptr, &ptr, 10);
3010 int nodeId3 = strtol(ptr, &ptr, 10);
3011 if ( nbTriangle > 1 ) {
3012 const SMDS_MeshNode* n1 = theGhs3dIdToNodeMap[ nodeId1 ];
3013 const SMDS_MeshNode* n2 = theGhs3dIdToNodeMap[ nodeId2 ];
3014 const SMDS_MeshNode* n3 = theGhs3dIdToNodeMap[ nodeId3 ];
3015 if (!n1 || !n2 || !n3) {
3021 // tabID[i] = findShapeID( theHelper, n1, n2, n3, toMeshHoles );
3022 tabID[i] = findShapeID( *theHelper.GetMesh(), n1, n2, n3, toMeshHoles );
3023 // -- 0020330: Pb with ghs3d as a submesh
3024 // check that found shape is to be meshed
3025 if ( tabID[i] > 0 ) {
3026 const TopoDS_Shape& foundShape = theMeshDS->IndexToShape( tabID[i] );
3027 bool isToBeMeshed = false;
3028 for ( int iS = 0; !isToBeMeshed && iS < nbShape; ++iS )
3029 isToBeMeshed = foundShape.IsSame( tabShape[ iS ]);
3030 if ( !isToBeMeshed )
3033 // END -- 0020330: Pb with ghs3d as a submesh
3035 std::cout << i+1 << " subdomain: findShapeID() returns " << tabID[i] << std::endl;
3038 catch ( Standard_Failure & ex)
3041 std::cout << i+1 << " subdomain: Exception caugt: " << ex.GetMessageString() << std::endl;
3046 std::cout << i+1 << " subdomain: unknown exception caught " << std::endl;
3054 if ( nbTriangle <= nbShape ) // no holes
3055 toMeshHoles = true; // not avoid creating tetras in holes
3057 // IMP 0022172: [CEA 790] create the groups corresponding to domains
3058 std::vector< std::vector< const SMDS_MeshElement* > > elemsOfDomain( Max( nbTriangle, nbShape ));
3060 // Associating the tetrahedrons to the shapes
3061 shapeID = compoundID;
3062 for (int iElem = 0; iElem < nbElems; iElem++) {
3063 if(theAlgo->computeCanceled())
3065 for (int iNode = 0; iNode < 4; iNode++) {
3066 ID = strtol(tetraPtr, &tetraPtr, 10);
3067 itOnNode = theGhs3dIdToNodeMap.find(ID);
3068 node[ iNode ] = itOnNode->second;
3069 nodeID[ iNode ] = ID;
3071 // We always run GHS3D with "to mesh holes"==TRUE but we must not create
3072 // tetras within holes depending on hypo option,
3073 // so we first check if aTet is inside a hole and then create it
3074 //aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
3075 ghs3dShapeID = 0; // domain ID
3076 if ( nbTriangle > 1 ) {
3077 shapeID = HOLE_ID; // negative shapeID means not to create tetras if !toMeshHoles
3078 ghs3dShapeID = strtol(shapePtr, &shapePtr, 10) - IdShapeRef;
3079 if ( tabID[ ghs3dShapeID ] == 0 ) {
3081 aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape, &state);
3082 if ( toMeshHoles || state == TopAbs_IN )
3083 shapeID = theMeshDS->ShapeToIndex( aSolid );
3084 tabID[ ghs3dShapeID ] = shapeID;
3087 shapeID = tabID[ ghs3dShapeID ];
3089 else if ( nbShape > 1 ) {
3090 // Case where nbTriangle == 1 while nbShape == 2 encountered
3091 // with compound of 2 boxes and "To mesh holes"==False,
3092 // so there are no subdomains specified for each tetrahedron.
3093 // Try to guess a solid by a node already bound to shape
3095 for ( int i=0; i<4 && shapeID==0; i++ ) {
3096 if ( nodeAssigne[ nodeID[i] ] == 1 &&
3097 node[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_3DSPACE &&
3098 node[i]->getshapeId() > 1 )
3100 shapeID = node[i]->getshapeId();
3104 aSolid = findShape(node, aSolid, tabShape, tabBox, nbShape);
3105 shapeID = theMeshDS->ShapeToIndex( aSolid );
3108 // set new nodes and tetrahedron onto the shape
3109 for ( int i=0; i<4; i++ ) {
3110 if ( nodeAssigne[ nodeID[i] ] == 0 ) {
3111 if ( shapeID != HOLE_ID )
3112 theMeshDS->SetNodeInVolume( node[i], shapeID );
3113 nodeAssigne[ nodeID[i] ] = shapeID;
3116 if ( toMeshHoles || shapeID != HOLE_ID ) {
3117 aTet = theHelper.AddVolume( node[1], node[0], node[2], node[3],
3118 /*id=*/0, /*force3d=*/false);
3119 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
3120 if ( toMakeGroupsOfDomains )
3122 if ( int( elemsOfDomain.size() ) < ghs3dShapeID+1 )
3123 elemsOfDomain.resize( ghs3dShapeID+1 );
3124 elemsOfDomain[ ghs3dShapeID ].push_back( aTet );
3128 shapeIDs.insert( shapeID );
3131 if ( toMakeGroupsOfDomains )
3132 makeDomainGroups( elemsOfDomain, &theHelper );
3134 // Add enforced elements
3135 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap::const_iterator elemIt;
3136 const SMDS_MeshElement* anElem;
3137 SMDS_ElemIteratorPtr itOnEnfElem;
3138 map<int,int>::const_iterator itOnMap;
3139 shapeID = compoundID;
3141 if (theEnforcedEdges.size()) {
3142 (theEnforcedEdges.size() <= 1) ? tmpStr = " enforced edge" : " enforced edges";
3143 std::cout << "Add " << theEnforcedEdges.size() << tmpStr << std::endl;
3144 std::vector< const SMDS_MeshNode* > node( 2 );
3145 // Iterate over the enforced edges
3146 for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
3147 anElem = elemIt->first;
3148 bool addElem = true;
3149 itOnEnfElem = anElem->nodesIterator();
3150 for ( int j = 0; j < 2; ++j ) {
3151 int aNodeID = itOnEnfElem->next()->GetID();
3152 itOnMap = theNodeId2NodeIndexMap.find(aNodeID);
3153 if (itOnMap != theNodeId2NodeIndexMap.end()) {
3154 itOnNode = theGhs3dIdToNodeMap.find((*itOnMap).second);
3155 if (itOnNode != theGhs3dIdToNodeMap.end()) {
3156 node.push_back((*itOnNode).second);
3157 // shapeID =(*itOnNode).second->getshapeId();
3166 aTet = theHelper.AddEdge( node[0], node[1], 0, false);
3167 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
3172 if (theEnforcedTriangles.size()) {
3173 (theEnforcedTriangles.size() <= 1) ? tmpStr = " enforced triangle" : " enforced triangles";
3174 std::cout << "Add " << theEnforcedTriangles.size() << " enforced triangles" << std::endl;
3175 std::vector< const SMDS_MeshNode* > node( 3 );
3176 // Iterate over the enforced triangles
3177 for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
3178 anElem = elemIt->first;
3179 bool addElem = true;
3180 itOnEnfElem = anElem->nodesIterator();
3181 for ( int j = 0; j < 3; ++j ) {
3182 int aNodeID = itOnEnfElem->next()->GetID();
3183 itOnMap = theNodeId2NodeIndexMap.find(aNodeID);
3184 if (itOnMap != theNodeId2NodeIndexMap.end()) {
3185 itOnNode = theGhs3dIdToNodeMap.find((*itOnMap).second);
3186 if (itOnNode != theGhs3dIdToNodeMap.end()) {
3187 node.push_back((*itOnNode).second);
3188 // shapeID =(*itOnNode).second->getshapeId();
3197 aTet = theHelper.AddFace( node[0], node[1], node[2], 0, false);
3198 theMeshDS->SetMeshElementOnShape( aTet, shapeID );
3203 // Remove nodes of tetras inside holes if !toMeshHoles
3204 if ( !toMeshHoles ) {
3205 itOnNode = theGhs3dIdToNodeMap.find( nbInputNodes );
3206 for ( ; itOnNode != theGhs3dIdToNodeMap.end(); ++itOnNode) {
3207 ID = itOnNode->first;
3208 if ( nodeAssigne[ ID ] == HOLE_ID )
3209 theMeshDS->RemoveFreeNode( itOnNode->second, 0 );
3215 (nbElems <= 1) ? tmpStr = " tetrahedra" : " tetrahedrons";
3216 cout << nbElems << tmpStr << " have been associated to " << nbShape;
3217 (nbShape <= 1) ? tmpStr = " shape" : " shapes";
3218 cout << tmpStr << endl;
3221 UnmapViewOfFile(mapPtr);
3222 CloseHandle(hMapObject);
3225 munmap(mapPtr, length);
3234 delete [] nodeAssigne;
3238 if ( shapeIDs.size() != nbShape ) {
3239 (shapeIDs.size() <= 1) ? tmpStr = " solid" : " solids";
3240 std::cout << "Only " << shapeIDs.size() << tmpStr << " of " << nbShape << " found" << std::endl;
3241 for (int i=0; i<nbShape; i++) {
3242 shapeID = theMeshDS->ShapeToIndex( tabShape[i] );
3243 if ( shapeIDs.find( shapeID ) == shapeIDs.end() )
3244 std::cout << " Solid #" << shapeID << " not found" << std::endl;
3253 //=============================================================================
3255 *Here we are going to use the GHS3D mesher with geometry
3257 //=============================================================================
3259 bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
3260 const TopoDS_Shape& theShape)
3263 //SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
3265 // we count the number of shapes
3266 // _nbShape = countShape( meshDS, TopAbs_SOLID ); -- 0020330: Pb with ghs3d as a submesh
3268 TopExp_Explorer expBox ( theShape, TopAbs_SOLID );
3269 for ( ; expBox.More(); expBox.Next() )
3272 // create bounding box for every shape inside the compound
3275 TopoDS_Shape* tabShape;
3277 tabShape = new TopoDS_Shape[_nbShape];
3278 tabBox = new double*[_nbShape];
3279 for (int i=0; i<_nbShape; i++)
3280 tabBox[i] = new double[6];
3281 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
3283 for (expBox.ReInit(); expBox.More(); expBox.Next()) {
3284 tabShape[iShape] = expBox.Current();
3285 Bnd_Box BoundingBox;
3286 BRepBndLib::Add(expBox.Current(), BoundingBox);
3287 BoundingBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
3288 tabBox[iShape][0] = Xmin; tabBox[iShape][1] = Xmax;
3289 tabBox[iShape][2] = Ymin; tabBox[iShape][3] = Ymax;
3290 tabBox[iShape][4] = Zmin; tabBox[iShape][5] = Zmax;
3294 // a unique working file name
3295 // to avoid access to the same files by eg different users
3296 _genericName = GHS3DPlugin_Hypothesis::GetFileName(_hyp);
3297 TCollection_AsciiString aGenericName((char*) _genericName.c_str() );
3299 TCollection_AsciiString aResultFileName;
3300 TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log
3301 // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2)
3302 // TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName;
3303 // TCollection_AsciiString aGenericNameRequired = aGenericName + "_required";
3305 // aGMFFileName = aGenericName + ".mesh"; // GMF mesh file
3306 // aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file
3307 // aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file
3308 // aSolFileName = aGenericName + "_required.sol"; // GMF solution file
3310 // aGMFFileName = aGenericName + ".meshb"; // GMF mesh file
3311 // aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file
3312 // aRequiredVerticesFileName = aGenericNameRequired + ".meshb"; // GMF required vertices mesh file
3313 // aSolFileName = aGenericName + "_required.solb"; // GMF solution file
3316 TCollection_AsciiString aFacesFileName, aPointsFileName, aBadResFileName, aBbResFileName;
3318 aFacesFileName = aGenericName + ".faces"; // in faces
3319 aPointsFileName = aGenericName + ".points"; // in points
3320 aResultFileName = aGenericName + ".noboite";// out points and volumes
3321 aBadResFileName = aGenericName + ".boite"; // out bad result
3322 aBbResFileName = aGenericName + ".bb"; // out vertex stepsize
3324 // -----------------
3326 // -----------------
3328 ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out);
3329 ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out);
3332 aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open();
3334 INFOS( "Can't write into " << aFacesFileName);
3335 return error(SMESH_Comment("Can't write into ") << aFacesFileName);
3338 std::map <int,int> aNodeId2NodeIndexMap, aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap;
3339 std::map <int,const SMDS_MeshNode*> aGhs3dIdToNodeMap;
3340 std::map <int, int> nodeID2nodeIndexMap;
3341 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues coordsSizeMap = GHS3DPlugin_Hypothesis::GetEnforcedVerticesCoordsSize(_hyp);
3342 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = GHS3DPlugin_Hypothesis::GetEnforcedNodes(_hyp);
3343 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp);
3344 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp);
3345 // TIDSortedElemSet enforcedQuadrangles = GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp);
3346 GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp);
3348 int nbEnforcedVertices = coordsSizeMap.size();
3349 int nbEnforcedNodes = enforcedNodes.size();
3352 (nbEnforcedNodes <= 1) ? tmpStr = "node" : "nodes";
3353 std::cout << nbEnforcedNodes << " enforced " << tmpStr << " from hypo" << std::endl;
3354 (nbEnforcedVertices <= 1) ? tmpStr = "vertex" : "vertices";
3355 std::cout << nbEnforcedVertices << " enforced " << tmpStr << " from hypo" << std::endl;
3357 SMESH_MesherHelper helper( theMesh );
3358 helper.SetSubShape( theShape );
3361 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
3363 // make prisms on quadrangles
3364 if ( theMesh.NbQuadrangles() > 0 )
3366 vector<SMESH_ProxyMesh::Ptr> components;
3367 for (expBox.ReInit(); expBox.More(); expBox.Next())
3369 if ( _viscousLayersHyp )
3371 proxyMesh = _viscousLayersHyp->Compute( theMesh, expBox.Current() );
3375 StdMeshers_QuadToTriaAdaptor* q2t = new StdMeshers_QuadToTriaAdaptor;
3376 q2t->Compute( theMesh, expBox.Current(), proxyMesh.get() );
3377 components.push_back( SMESH_ProxyMesh::Ptr( q2t ));
3379 proxyMesh.reset( new SMESH_ProxyMesh( components ));
3381 // build viscous layers
3382 else if ( _viscousLayersHyp )
3384 proxyMesh = _viscousLayersHyp->Compute( theMesh, theShape );
3389 Ok = (writePoints( aPointsFile, helper,
3390 aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap, aGhs3dIdToNodeMap,
3392 coordsSizeMap, enforcedNodes, enforcedEdges, enforcedTriangles)
3394 writeFaces ( aFacesFile, *proxyMesh, theShape,
3395 aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap,
3396 enforcedEdges, enforcedTriangles ));
3397 // Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(),
3398 // helper, *proxyMesh,
3399 // aNodeId2NodeIndexMap, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap,
3400 // enforcedNodes, enforcedEdges, enforcedTriangles, /*enforcedQuadrangles,*/
3404 // Write aSmdsToGhs3dIdMap to temp file
3405 TCollection_AsciiString aSmdsToGhs3dIdMapFileName;
3406 aSmdsToGhs3dIdMapFileName = aGenericName + ".ids"; // ids relation
3407 ofstream aIdsFile ( aSmdsToGhs3dIdMapFileName.ToCString() , ios::out);
3408 Ok = aIdsFile.rdbuf()->is_open();
3410 INFOS( "Can't write into " << aSmdsToGhs3dIdMapFileName);
3411 return error(SMESH_Comment("Can't write into ") << aSmdsToGhs3dIdMapFileName);
3413 INFOS( "Writing ids relation into " << aSmdsToGhs3dIdMapFileName);
3414 aIdsFile << "Smds Ghs3d" << std::endl;
3415 map <int,int>::const_iterator myit;
3416 for (myit=aSmdsToGhs3dIdMap.begin() ; myit != aSmdsToGhs3dIdMap.end() ; ++myit) {
3417 aIdsFile << myit->first << " " << myit->second << std::endl;
3422 aPointsFile.close();
3425 if ( !_keepFiles ) {
3426 // removeFile( aGMFFileName );
3427 // removeFile( aRequiredVerticesFileName );
3428 // removeFile( aSolFileName );
3429 removeFile( aFacesFileName );
3430 removeFile( aPointsFileName );
3431 removeFile( aSmdsToGhs3dIdMapFileName );
3433 return error(COMPERR_BAD_INPUT_MESH);
3435 removeFile( aResultFileName ); // needed for boundary recovery module usage
3437 // -----------------
3439 // -----------------
3441 TCollection_AsciiString cmd( (char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp ).c_str() );
3442 cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read
3444 if ( !_logInStandardOutput )
3445 cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
3446 // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2)
3447 // cmd += TCollection_AsciiString(" --in ") + aGenericName;
3448 // cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired;
3449 // cmd += TCollection_AsciiString(" --out ") + aResultGMFFileName;
3450 // cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
3452 std::cout << std::endl;
3453 std::cout << "Ghs3d execution..." << std::endl;
3454 std::cout << cmd << std::endl;
3456 _compute_canceled = false;
3458 system( cmd.ToCString() ); // run
3460 std::cout << std::endl;
3461 std::cout << "End of Ghs3d execution !" << std::endl;
3467 // Mapping the result file
3470 fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
3471 if ( fileOpen < 0 ) {
3472 std::cout << std::endl;
3473 std::cout << "Can't open the " << aResultFileName.ToCString() << " GHS3D output file" << std::endl;
3474 std::cout << "Log: " << aLogFileName << std::endl;
3479 _hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles();
3480 const bool toMakeGroupsOfDomains = GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains( _hyp );
3482 helper.IsQuadraticSubMesh( theShape );
3483 helper.SetElementsOnShape( false );
3485 Ok = readResultFile( fileOpen,
3487 aResultFileName.ToCString(),
3490 /*theMesh, */helper, tabShape, tabBox, _nbShape,
3491 aGhs3dIdToNodeMap, aNodeId2NodeIndexMap,
3493 nbEnforcedVertices, nbEnforcedNodes,
3494 enforcedEdges, enforcedTriangles,
3495 toMakeGroupsOfDomains );
3497 // Ok = readGMFFile(
3498 // #ifndef GMF_HAS_SUBDOMAIN_INFO
3501 // aGenericName.ToCString(), theMesh,
3502 // _nbShape, tabShape, tabBox,
3503 // aGhs3dIdToNodeMap, toMeshHoles,
3504 // nbEnforcedVertices, nbEnforcedNodes);
3506 removeEmptyGroupsOfDomains( helper.GetMesh(), /*notEmptyAsWell =*/ !toMakeGroupsOfDomains );
3512 // ---------------------
3513 // remove working files
3514 // ---------------------
3518 if ( _removeLogOnSuccess )
3519 removeFile( aLogFileName );
3521 // if ( _hyp && _hyp->GetToMakeGroupsOfDomains() )
3522 // error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since the mesh is on shape" );
3524 else if ( OSD_File( aLogFileName ).Size() > 0 )
3526 // get problem description from the log file
3527 _Ghs2smdsConvertor conv( aGhs3dIdToNodeMap );
3528 storeErrorDescription( aLogFileName, conv );
3532 // the log file is empty
3533 removeFile( aLogFileName );
3534 INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" );
3535 error(COMPERR_ALGO_FAILED, "ghs3d: command not found" );
3538 if ( !_keepFiles ) {
3539 if (! Ok && _compute_canceled)
3540 removeFile( aLogFileName );
3541 removeFile( aFacesFileName );
3542 removeFile( aPointsFileName );
3543 removeFile( aResultFileName );
3544 removeFile( aBadResFileName );
3545 removeFile( aBbResFileName );
3546 removeFile( aSmdsToGhs3dIdMapFileName );
3548 std::cout << "<" << aResultFileName.ToCString() << "> GHS3D output file ";
3550 std::cout << "not ";
3551 std::cout << "treated !" << std::endl;
3552 std::cout << std::endl;
3554 _nbShape = 0; // re-initializing _nbShape for the next Compute() method call
3561 //=============================================================================
3563 *Here we are going to use the GHS3D mesher w/o geometry
3565 //=============================================================================
3566 bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
3567 SMESH_MesherHelper* theHelper)
3569 MESSAGE("GHS3DPlugin_GHS3D::Compute()");
3571 //SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
3572 TopoDS_Shape theShape = theHelper->GetSubShape();
3574 // a unique working file name
3575 // to avoid access to the same files by eg different users
3576 _genericName = GHS3DPlugin_Hypothesis::GetFileName(_hyp);
3577 TCollection_AsciiString aGenericName((char*) _genericName.c_str() );
3578 TCollection_AsciiString aGenericNameRequired = aGenericName + "_required";
3580 TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log
3581 TCollection_AsciiString aResultFileName;
3584 TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName;
3586 aGMFFileName = aGenericName + ".mesh"; // GMF mesh file
3587 aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file
3588 aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file
3589 aSolFileName = aGenericNameRequired + ".sol"; // GMF solution file
3591 // aGMFFileName = aGenericName + ".meshb"; // GMF mesh file
3592 // aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file
3593 // aRequiredVerticesFileName = aGenericNameRequired + ".meshb"; // GMF required vertices mesh file
3594 // aSolFileName = aGenericNameRequired + ".solb"; // GMF solution file
3597 std::map <int, int> nodeID2nodeIndexMap;
3598 std::map<std::vector<double>, std::string> enfVerticesWithGroup;
3599 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues coordsSizeMap;
3600 TopoDS_Shape GeomShape;
3601 // TopAbs_ShapeEnum GeomType;
3602 std::vector<double> coords;
3604 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* enfVertex;
3606 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList enfVertices = GHS3DPlugin_Hypothesis::GetEnforcedVertices(_hyp);
3607 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList::const_iterator enfVerIt = enfVertices.begin();
3609 for ( ; enfVerIt != enfVertices.end() ; ++enfVerIt)
3611 enfVertex = (*enfVerIt);
3612 // if (enfVertex->geomEntry.empty() && enfVertex->coords.size()) {
3613 if (enfVertex->coords.size()) {
3614 coordsSizeMap.insert(make_pair(enfVertex->coords,enfVertex->size));
3615 enfVerticesWithGroup.insert(make_pair(enfVertex->coords,enfVertex->groupName));
3616 // MESSAGE("enfVerticesWithGroup.insert(make_pair(("<<enfVertex->coords[0]<<","<<enfVertex->coords[1]<<","<<enfVertex->coords[2]<<"),\""<<enfVertex->groupName<<"\"))");
3619 // if (!enfVertex->geomEntry.empty()) {
3620 GeomShape = entryToShape(enfVertex->geomEntry);
3621 // GeomType = GeomShape.ShapeType();
3623 // if (!enfVertex->isCompound) {
3624 // // if (GeomType == TopAbs_VERTEX) {
3626 // aPnt = BRep_Tool::Pnt(TopoDS::Vertex(GeomShape));
3627 // coords.push_back(aPnt.X());
3628 // coords.push_back(aPnt.Y());
3629 // coords.push_back(aPnt.Z());
3630 // if (coordsSizeMap.find(coords) == coordsSizeMap.end()) {
3631 // coordsSizeMap.insert(make_pair(coords,enfVertex->size));
3632 // enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName));
3636 // // Group Management
3638 // if (GeomType == TopAbs_COMPOUND){
3639 for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){
3641 if (it.Value().ShapeType() == TopAbs_VERTEX){
3642 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(it.Value()));
3643 coords.push_back(aPnt.X());
3644 coords.push_back(aPnt.Y());
3645 coords.push_back(aPnt.Z());
3646 if (coordsSizeMap.find(coords) == coordsSizeMap.end()) {
3647 coordsSizeMap.insert(make_pair(coords,enfVertex->size));
3648 enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName));
3649 // MESSAGE("enfVerticesWithGroup.insert(make_pair(("<<coords[0]<<","<<coords[1]<<","<<coords[2]<<"),\""<<enfVertex->groupName<<"\"))");
3657 // const SMDS_MeshNode* enfNode;
3658 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = GHS3DPlugin_Hypothesis::GetEnforcedNodes(_hyp);
3659 // GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt = enforcedNodes.begin();
3660 // for ( ; enfNodeIt != enforcedNodes.end() ; ++enfNodeIt)
3662 // enfNode = enfNodeIt->first;
3664 // coords.push_back(enfNode->X());
3665 // coords.push_back(enfNode->Y());
3666 // coords.push_back(enfNode->Z());
3667 // if (enfVerticesWithGro
3668 // enfVerticesWithGroup.insert(make_pair(coords,enfNodeIt->second));
3672 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp);
3673 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp);
3674 // TIDSortedElemSet enforcedQuadrangles = GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp);
3675 GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp);
3679 int nbEnforcedVertices = coordsSizeMap.size();
3680 int nbEnforcedNodes = enforcedNodes.size();
3681 (nbEnforcedNodes <= 1) ? tmpStr = "node" : tmpStr = "nodes";
3682 std::cout << nbEnforcedNodes << " enforced " << tmpStr << " from hypo" << std::endl;
3683 (nbEnforcedVertices <= 1) ? tmpStr = "vertex" : tmpStr = "vertices";
3684 std::cout << nbEnforcedVertices << " enforced " << tmpStr << " from hypo" << std::endl;
3686 std::vector <const SMDS_MeshNode*> aNodeByGhs3dId, anEnforcedNodeByGhs3dId;
3687 std::map<const SMDS_MeshNode*,int> aNodeToGhs3dIdMap;
3688 std::vector<std::string> aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId;
3690 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
3691 if ( theMesh.NbQuadrangles() > 0 )
3693 StdMeshers_QuadToTriaAdaptor* aQuad2Trias = new StdMeshers_QuadToTriaAdaptor;
3694 aQuad2Trias->Compute( theMesh );
3695 proxyMesh.reset( aQuad2Trias );
3698 Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(),
3699 *proxyMesh, &theMesh,
3700 aNodeByGhs3dId, aNodeToGhs3dIdMap,
3701 aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId,
3702 enforcedNodes, enforcedEdges, enforcedTriangles,
3703 enfVerticesWithGroup, coordsSizeMap);
3706 // -----------------
3708 // -----------------
3710 TCollection_AsciiString cmd = TCollection_AsciiString((char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp, false ).c_str());
3712 cmd += TCollection_AsciiString(" --in ") + aGenericName;
3713 if ( nbEnforcedVertices + nbEnforcedNodes)
3714 cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired;
3715 cmd += TCollection_AsciiString(" --out ") + aResultFileName;
3716 if ( !_logInStandardOutput )
3717 cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
3719 std::cout << std::endl;
3720 std::cout << "Ghs3d execution..." << std::endl;
3721 std::cout << cmd << std::endl;
3723 _compute_canceled = false;
3725 system( cmd.ToCString() ); // run
3727 std::cout << std::endl;
3728 std::cout << "End of Ghs3d execution !" << std::endl;
3733 GHS3DPlugin_Hypothesis::TSetStrings groupsToRemove = GHS3DPlugin_Hypothesis::GetGroupsToRemove(_hyp);
3734 const bool toMakeGroupsOfDomains = GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains( _hyp );
3736 Ok = readGMFFile(aResultFileName.ToCString(),
3738 theHelper, theShape, aNodeByGhs3dId, aNodeToGhs3dIdMap,
3739 aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId,
3740 groupsToRemove, toMakeGroupsOfDomains);
3742 updateMeshGroups(theHelper->GetMesh(), groupsToRemove);
3743 removeEmptyGroupsOfDomains( theHelper->GetMesh(), /*notEmptyAsWell =*/ !toMakeGroupsOfDomains );
3746 GHS3DPlugin_Hypothesis* that = (GHS3DPlugin_Hypothesis*)this->_hyp;
3748 that->ClearGroupsToRemove();
3750 // ---------------------
3751 // remove working files
3752 // ---------------------
3756 if ( _removeLogOnSuccess )
3757 removeFile( aLogFileName );
3759 //if ( !toMakeGroupsOfDomains && _hyp && _hyp->GetToMakeGroupsOfDomains() )
3760 //error( COMPERR_WARNING, "'toMakeGroupsOfDomains' is ignored since 'toMeshHoles' is OFF." );
3762 else if ( OSD_File( aLogFileName ).Size() > 0 )
3764 // get problem description from the log file
3765 _Ghs2smdsConvertor conv( aNodeByGhs3dId );
3766 storeErrorDescription( aLogFileName, conv );
3769 // the log file is empty
3770 removeFile( aLogFileName );
3771 INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" );
3772 error(COMPERR_ALGO_FAILED, "ghs3d: command not found" );
3777 if (! Ok && _compute_canceled)
3778 removeFile( aLogFileName );
3779 removeFile( aGMFFileName );
3780 removeFile( aResultFileName );
3781 removeFile( aRequiredVerticesFileName );
3782 removeFile( aSolFileName );
3787 void GHS3DPlugin_GHS3D::CancelCompute()
3789 _compute_canceled = true;
3792 std::string cmd = "ps xo pid,args | grep " + _genericName;
3793 //cmd += " | grep -e \"^ *[0-9]\\+ \\+" + GHS3DPlugin_Hypothesis::GetExeName() + "\"";
3794 cmd += " | awk '{print $1}' | xargs kill -9 > /dev/null 2>&1";
3795 system( cmd.c_str() );
3799 //================================================================================
3801 * \brief Provide human readable text by error code reported by ghs3d
3803 //================================================================================
3805 static string translateError(const int errNum)
3809 return "The surface mesh includes a face of type other than edge, "
3810 "triangle or quadrilateral. This face type is not supported.";
3812 return "Not enough memory for the face table.";
3814 return "Not enough memory.";
3816 return "Not enough memory.";
3818 return "Face is ignored.";
3820 return "End of file. Some data are missing in the file.";
3822 return "Read error on the file. There are wrong data in the file.";
3824 return "the metric file is inadequate (dimension other than 3).";
3826 return "the metric file is inadequate (values not per vertices).";
3828 return "the metric file contains more than one field.";
3830 return "the number of values in the \".bb\" (metric file) is incompatible with the expected"
3831 "value of number of mesh vertices in the \".noboite\" file.";
3833 return "Too many sub-domains.";
3835 return "the number of vertices is negative or null.";
3837 return "the number of faces is negative or null.";
3839 return "A face has a null vertex.";
3841 return "incompatible data.";
3843 return "the number of vertices is negative or null.";
3845 return "the number of vertices is negative or null (in the \".mesh\" file).";
3847 return "the number of faces is negative or null.";
3849 return "A face appears more than once in the input surface mesh.";
3851 return "An edge appears more than once in the input surface mesh.";
3853 return "A face has a vertex negative or null.";
3855 return "NOT ENOUGH MEMORY.";
3857 return "Not enough available memory.";
3859 return "Some initial points cannot be inserted. The surface mesh is probably very bad "
3860 "in terms of quality or the input list of points is wrong.";
3862 return "Some vertices are too close to one another or coincident.";
3864 return "Some vertices are too close to one another or coincident.";
3866 return "A vertex cannot be inserted.";
3868 return "There are at least two points considered as coincident.";
3870 return "Some vertices are too close to one another or coincident.";
3872 return "The surface mesh regeneration step has failed.";
3874 return "Constrained edge cannot be enforced.";
3876 return "Constrained face cannot be enforced.";
3878 return "Missing faces.";
3880 return "No guess to start the definition of the connected component(s).";
3882 return "The surface mesh includes at least one hole. The domain is not well defined.";
3884 return "Impossible to define a component.";
3886 return "The surface edge intersects another surface edge.";
3888 return "The surface edge intersects the surface face.";
3890 return "One boundary point lies within a surface face.";
3892 return "One surface edge intersects a surface face.";
3894 return "One boundary point lies within a surface edge.";
3896 return "Insufficient memory ressources detected due to a bad quality surface mesh leading "
3897 "to too many swaps.";
3899 return "Edge is unique (i.e., bounds a hole in the surface).";
3901 return "Presumably, the surface mesh is not compatible with the domain being processed.";
3903 return "Too many components, too many sub-domain.";
3905 return "The surface mesh includes at least one hole. "
3906 "Therefore there is no domain properly defined.";
3908 return "Statistics.";
3910 return "Statistics.";
3912 return "Warning, it is dramatically tedious to enforce the boundary items.";
3914 return "Not enough memory at this time, nevertheless, the program continues. "
3915 "The expected mesh will be correct but not really as large as required.";
3917 return "see above error code, resulting quality may be poor.";
3919 return "Not enough memory at this time, nevertheless, the program continues (warning).";
3921 return "Unknown face type.";
3924 return "End of file. Some data are missing in the file.";
3926 return "A too small volume element is detected.";
3928 return "There exists at least a null or negative volume element.";
3930 return "There exist null or negative volume elements.";
3932 return "A too small volume element is detected. A face is considered being degenerated.";
3934 return "Some element is suspected to be very bad shaped or wrong.";
3936 return "A too bad quality face is detected. This face is considered degenerated.";
3938 return "A too bad quality face is detected. This face is degenerated.";
3940 return "Presumably, the surface mesh is not compatible with the domain being processed.";
3942 return "Abnormal error occured, contact hotline.";
3944 return "Not enough memory for the face table.";
3946 return "The algorithm cannot run further. "
3947 "The surface mesh is probably very bad in terms of quality.";
3949 return "Bad vertex number.";
3954 //================================================================================
3956 * \brief Retrieve from a string given number of integers
3958 //================================================================================
3960 static char* getIds( char* ptr, int nbIds, vector<int>& ids )
3963 ids.reserve( nbIds );
3966 while ( !isdigit( *ptr )) ++ptr;
3967 if ( ptr[-1] == '-' ) --ptr;
3968 ids.push_back( strtol( ptr, &ptr, 10 ));
3974 //================================================================================
3976 * \brief Retrieve problem description form a log file
3977 * \retval bool - always false
3979 //================================================================================
3981 bool GHS3DPlugin_GHS3D::storeErrorDescription(const TCollection_AsciiString& logFile,
3982 const _Ghs2smdsConvertor & toSmdsConvertor )
3984 if(_compute_canceled)
3985 return error(SMESH_Comment("interruption initiated by user"));
3988 int file = ::_open (logFile.ToCString(), _O_RDONLY|_O_BINARY);
3990 int file = ::open (logFile.ToCString(), O_RDONLY);
3993 return error( SMESH_Comment("See ") << logFile << " for problem description");
3996 // struct stat status;
3997 // fstat(file, &status);
3998 // size_t length = status.st_size;
3999 off_t length = lseek( file, 0, SEEK_END);
4000 lseek( file, 0, SEEK_SET);
4003 vector< char > buf( length );
4004 int nBytesRead = ::read (file, & buf[0], length);
4006 char* ptr = & buf[0];
4007 char* bufEnd = ptr + nBytesRead;
4009 SMESH_Comment errDescription;
4011 enum { NODE = 1, EDGE, TRIA, VOL, ID = 1 };
4013 // look for errors "ERR #"
4015 set<string> foundErrorStr; // to avoid reporting same error several times
4016 set<int> elemErrorNums; // not to report different types of errors with bad elements
4017 while ( ++ptr < bufEnd )
4019 if ( strncmp( ptr, "ERR ", 4 ) != 0 )
4022 list<const SMDS_MeshElement*> badElems;
4023 vector<int> nodeIds;
4027 int errNum = strtol(ptr, &ptr, 10);
4028 switch ( errNum ) { // we treat errors enumerated in [SALOME platform 0019316] issue
4030 // The face number (numfac) with vertices (f 1, f 2, f 3) has a null vertex.
4031 ptr = getIds(ptr, NODE, nodeIds);
4032 ptr = getIds(ptr, TRIA, nodeIds);
4033 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4035 case 1000: // ERR 1000 : 1 3 2
4036 // Face (f 1, f 2, f 3) appears more than once in the input surface mesh.
4037 ptr = getIds(ptr, TRIA, nodeIds);
4038 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4041 // Edge (e1, e2) appears more than once in the input surface mesh
4042 ptr = getIds(ptr, EDGE, nodeIds);
4043 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4046 // Face (f 1, f 2, f 3) has a vertex negative or null
4047 ptr = getIds(ptr, TRIA, nodeIds);
4048 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4051 // Vertex v1 and vertex v2 are too close to one another or coincident (warning).
4052 ptr = getIds(ptr, NODE, nodeIds);
4053 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4054 ptr = getIds(ptr, NODE, nodeIds);
4055 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4058 // Vertex v1 cannot be inserted (warning).
4059 ptr = getIds(ptr, NODE, nodeIds);
4060 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4063 // There are at least two points whose distance is dist, i.e., considered as coincident
4064 case 2103: // ERR 2103 : 16 WITH 3
4065 // Vertex v1 and vertex v2 are too close to one another or coincident (warning).
4066 ptr = getIds(ptr, NODE, nodeIds);
4067 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4068 ptr = getIds(ptr, NODE, nodeIds);
4069 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4072 // Constrained edge (e1, e2) cannot be enforced (warning).
4073 ptr = getIds(ptr, EDGE, nodeIds);
4074 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4077 // Constrained face (f 1, f 2, f 3) cannot be enforced
4078 ptr = getIds(ptr, TRIA, nodeIds);
4079 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4081 case 3103: // ERR 3103 : 1 2 WITH 7 3
4082 // The surface edge (e1, e2) intersects another surface edge (e3, e4)
4083 ptr = getIds(ptr, EDGE, nodeIds);
4084 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4085 ptr = getIds(ptr, EDGE, nodeIds);
4086 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4088 case 3104: // ERR 3104 : 9 10 WITH 1 2 3
4089 // The surface edge (e1, e2) intersects the surface face (f 1, f 2, f 3)
4090 ptr = getIds(ptr, EDGE, nodeIds);
4091 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4092 ptr = getIds(ptr, TRIA, nodeIds);
4093 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4095 case 3105: // ERR 3105 : 8 IN 2 3 5
4096 // One boundary point (say p1) lies within a surface face (f 1, f 2, f 3)
4097 ptr = getIds(ptr, NODE, nodeIds);
4098 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4099 ptr = getIds(ptr, TRIA, nodeIds);
4100 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4103 // One surface edge (say e1, e2) intersects a surface face (f 1, f 2, f 3)
4104 ptr = getIds(ptr, EDGE, nodeIds);
4105 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4106 ptr = getIds(ptr, TRIA, nodeIds);
4107 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4109 case 3107: // ERR 3107 : 2 IN 4 1
4110 // One boundary point (say p1) lies within a surface edge (e1, e2) (stop).
4111 ptr = getIds(ptr, NODE, nodeIds);
4112 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4113 ptr = getIds(ptr, EDGE, nodeIds);
4114 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4116 case 3109: // ERR 3109 : EDGE 5 6 UNIQUE
4117 // Edge (e1, e2) is unique (i.e., bounds a hole in the surface)
4118 ptr = getIds(ptr, EDGE, nodeIds);
4119 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4121 case 9000: // ERR 9000
4122 // ELEMENT 261 WITH VERTICES : 7 396 -8 242
4123 // VOLUME : -1.11325045E+11 W.R.T. EPSILON 0.
4124 // A too small volume element is detected. Are reported the index of the element,
4125 // its four vertex indices, its volume and the tolerance threshold value
4126 ptr = getIds(ptr, ID, nodeIds);
4127 ptr = getIds(ptr, VOL, nodeIds);
4128 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4129 // even if all nodes found, volume it most probably invisible,
4130 // add its faces to demenstrate it anyhow
4132 vector<int> faceNodes( nodeIds.begin(), --nodeIds.end() ); // 012
4133 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4134 faceNodes[2] = nodeIds[3]; // 013
4135 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4136 faceNodes[1] = nodeIds[2]; // 023
4137 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4138 faceNodes[0] = nodeIds[1]; // 123
4139 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
4142 case 9001: // ERR 9001
4143 // %% NUMBER OF NEGATIVE VOLUME TETS : 1
4144 // %% THE LARGEST NEGATIVE TET : 1.75376581E+11
4145 // %% NUMBER OF NULL VOLUME TETS : 0
4146 // There exists at least a null or negative volume element
4149 // There exist n null or negative volume elements
4152 // A too small volume element is detected
4155 // A too bad quality face is detected. This face is considered degenerated,
4156 // its index, its three vertex indices together with its quality value are reported
4157 break; // same as next
4158 case 9112: // ERR 9112
4159 // FACE 2 WITH VERTICES : 4 2 5
4160 // SMALL INRADIUS : 0.
4161 // A too bad quality face is detected. This face is degenerated,
4162 // its index, its three vertex indices together with its inradius are reported
4163 ptr = getIds(ptr, ID, nodeIds);
4164 ptr = getIds(ptr, TRIA, nodeIds);
4165 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
4166 // add triangle edges as it most probably has zero area and hence invisible
4168 vector<int> edgeNodes(2);
4169 edgeNodes[0] = nodeIds[0]; edgeNodes[1] = nodeIds[1]; // 0-1
4170 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4171 edgeNodes[1] = nodeIds[2]; // 0-2
4172 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4173 edgeNodes[0] = nodeIds[1]; // 1-2
4174 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
4179 bool isNewError = foundErrorStr.insert( string( errBeg, ptr )).second;
4181 continue; // not to report same error several times
4183 // const SMDS_MeshElement* nullElem = 0;
4184 // bool allElemsOk = ( find( badElems.begin(), badElems.end(), nullElem) == badElems.end());
4186 // if ( allElemsOk && !badElems.empty() && !elemErrorNums.empty() ) {
4187 // bool oneMoreErrorType = elemErrorNums.insert( errNum ).second;
4188 // if ( oneMoreErrorType )
4189 // continue; // not to report different types of errors with bad elements
4192 // store bad elements
4193 //if ( allElemsOk ) {
4194 list<const SMDS_MeshElement*>::iterator elem = badElems.begin();
4195 for ( ; elem != badElems.end(); ++elem )
4196 addBadInputElement( *elem );
4200 string text = translateError( errNum );
4201 if ( errDescription.find( text ) == text.npos ) {
4202 if ( !errDescription.empty() )
4203 errDescription << "\n";
4204 errDescription << text;
4209 if ( errDescription.empty() ) { // no errors found
4210 char msgLic1[] = "connection to server failed";
4211 char msgLic2[] = " Dlim ";
4212 if ( search( &buf[0], bufEnd, msgLic1, msgLic1 + strlen(msgLic1)) != bufEnd ||
4213 search( &buf[0], bufEnd, msgLic2, msgLic2 + strlen(msgLic2)) != bufEnd )
4214 errDescription << "Licence problems.";
4217 char msg2[] = "SEGMENTATION FAULT";
4218 if ( search( &buf[0], bufEnd, msg2, msg2 + strlen(msg2)) != bufEnd )
4219 errDescription << "ghs3d: SEGMENTATION FAULT. ";
4223 if ( errDescription.empty() )
4224 errDescription << "See " << logFile << " for problem description";
4226 errDescription << "\nSee " << logFile << " for more information";
4228 return error( errDescription );
4231 //================================================================================
4233 * \brief Creates _Ghs2smdsConvertor
4235 //================================================================================
4237 _Ghs2smdsConvertor::_Ghs2smdsConvertor( const map <int,const SMDS_MeshNode*> & ghs2NodeMap)
4238 :_ghs2NodeMap( & ghs2NodeMap ), _nodeByGhsId( 0 )
4242 //================================================================================
4244 * \brief Creates _Ghs2smdsConvertor
4246 //================================================================================
4248 _Ghs2smdsConvertor::_Ghs2smdsConvertor( const vector <const SMDS_MeshNode*> & nodeByGhsId)
4249 : _ghs2NodeMap( 0 ), _nodeByGhsId( &nodeByGhsId )
4253 //================================================================================
4255 * \brief Return SMDS element by ids of GHS3D nodes
4257 //================================================================================
4259 const SMDS_MeshElement* _Ghs2smdsConvertor::getElement(const vector<int>& ghsNodes) const
4261 size_t nbNodes = ghsNodes.size();
4262 vector<const SMDS_MeshNode*> nodes( nbNodes, 0 );
4263 for ( size_t i = 0; i < nbNodes; ++i ) {
4264 int ghsNode = ghsNodes[ i ];
4265 if ( _ghs2NodeMap ) {
4266 map <int,const SMDS_MeshNode*>::const_iterator in = _ghs2NodeMap->find( ghsNode);
4267 if ( in == _ghs2NodeMap->end() )
4269 nodes[ i ] = in->second;
4272 if ( ghsNode < 1 || ghsNode > _nodeByGhsId->size() )
4274 nodes[ i ] = (*_nodeByGhsId)[ ghsNode-1 ];
4280 if ( nbNodes == 2 ) {
4281 const SMDS_MeshElement* edge= SMDS_Mesh::FindEdge( nodes[0], nodes[1] );
4283 edge = new SMDS_LinearEdge( nodes[0], nodes[1] );
4286 if ( nbNodes == 3 ) {
4287 const SMDS_MeshElement* face = SMDS_Mesh::FindFace( nodes );
4289 face = new SMDS_FaceOfNodes( nodes[0], nodes[1], nodes[2] );
4293 return new SMDS_VolumeOfNodes( nodes[0], nodes[1], nodes[2], nodes[3] );
4299 //=============================================================================
4303 //=============================================================================
4304 bool GHS3DPlugin_GHS3D::Evaluate(SMESH_Mesh& aMesh,
4305 const TopoDS_Shape& aShape,
4306 MapShapeNbElems& aResMap)
4308 int nbtri = 0, nbqua = 0;
4309 double fullArea = 0.0;
4310 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
4311 TopoDS_Face F = TopoDS::Face( exp.Current() );
4312 SMESH_subMesh *sm = aMesh.GetSubMesh(F);
4313 MapShapeNbElemsItr anIt = aResMap.find(sm);
4314 if( anIt==aResMap.end() ) {
4315 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
4316 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,
4317 "Submesh can not be evaluated",this));
4320 std::vector<int> aVec = (*anIt).second;
4321 nbtri += Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
4322 nbqua += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
4324 BRepGProp::SurfaceProperties(F,G);
4325 double anArea = G.Mass();
4329 // collect info from edges
4330 int nb0d_e = 0, nb1d_e = 0;
4331 bool IsQuadratic = false;
4332 bool IsFirst = true;
4333 TopTools_MapOfShape tmpMap;
4334 for (TopExp_Explorer exp(aShape, TopAbs_EDGE); exp.More(); exp.Next()) {
4335 TopoDS_Edge E = TopoDS::Edge(exp.Current());
4336 if( tmpMap.Contains(E) )
4339 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
4340 MapShapeNbElemsItr anIt = aResMap.find(aSubMesh);
4341 std::vector<int> aVec = (*anIt).second;
4342 nb0d_e += aVec[SMDSEntity_Node];
4343 nb1d_e += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
4345 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
4351 double ELen = sqrt(2.* ( fullArea/(nbtri+nbqua*2) ) / sqrt(3.0) );
4354 BRepGProp::VolumeProperties(aShape,G);
4355 double aVolume = G.Mass();
4356 double tetrVol = 0.1179*ELen*ELen*ELen;
4357 double CoeffQuality = 0.9;
4358 int nbVols = int(aVolume/tetrVol/CoeffQuality);
4359 int nb1d_f = (nbtri*3 + nbqua*4 - nb1d_e) / 2;
4360 int nb1d_in = (int) ( nbVols*6 - nb1d_e - nb1d_f ) / 5;
4361 std::vector<int> aVec(SMDSEntity_Last);
4362 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i]=0;
4364 aVec[SMDSEntity_Node] = nb1d_in/6 + 1 + nb1d_in;
4365 aVec[SMDSEntity_Quad_Tetra] = nbVols - nbqua*2;
4366 aVec[SMDSEntity_Quad_Pyramid] = nbqua;
4369 aVec[SMDSEntity_Node] = nb1d_in/6 + 1;
4370 aVec[SMDSEntity_Tetra] = nbVols - nbqua*2;
4371 aVec[SMDSEntity_Pyramid] = nbqua;
4373 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
4374 aResMap.insert(std::make_pair(sm,aVec));
4379 bool GHS3DPlugin_GHS3D::importGMFMesh(const char* theGMFFileName, SMESH_Mesh& theMesh)
4381 SMESH_MesherHelper* helper = new SMESH_MesherHelper(theMesh );
4382 // TopoDS_Shape theShape = theMesh.GetShapeToMesh();
4383 std::vector <const SMDS_MeshNode*> dummyNodeVector;
4384 std::map<const SMDS_MeshNode*,int> dummyNodeMap;
4385 std::map<std::vector<double>, std::string> dummyEnfVertGroup;
4386 std::vector<std::string> dummyElemGroup;
4387 std::set<std::string> dummyGroupsToRemove;
4389 bool ok = readGMFFile(theGMFFileName,
4391 helper, theMesh.GetShapeToMesh(), dummyNodeVector, dummyNodeMap, dummyElemGroup, dummyElemGroup, dummyElemGroup, dummyGroupsToRemove);
4392 theMesh.GetMeshDS()->Modified();
4398 //================================================================================
4400 * \brief Sub-mesh event listener setting enforced elements as soon as an enforced
4403 struct _EnforcedMeshRestorer : public SMESH_subMeshEventListener
4405 _EnforcedMeshRestorer():
4406 SMESH_subMeshEventListener( /*isDeletable = */true, Name() )
4409 //================================================================================
4411 * \brief Returns an ID of listener
4413 static const char* Name() { return "GHS3DPlugin_GHS3D::_EnforcedMeshRestorer"; }
4415 //================================================================================
4417 * \brief Treat events of the subMesh
4419 void ProcessEvent(const int event,
4420 const int eventType,
4421 SMESH_subMesh* subMesh,
4422 SMESH_subMeshEventListenerData* data,
4423 const SMESH_Hypothesis* hyp)
4425 if ( SMESH_subMesh::SUBMESH_LOADED == event &&
4426 SMESH_subMesh::COMPUTE_EVENT == eventType &&
4428 !data->mySubMeshes.empty() )
4430 // An enforced mesh (subMesh->_father) has been loaded from hdf file
4431 if ( GHS3DPlugin_Hypothesis* hyp = GetGHSHypothesis( data->mySubMeshes.front() ))
4432 hyp->RestoreEnfElemsByMeshes();
4435 //================================================================================
4437 * \brief Returns GHS3DPlugin_Hypothesis used to compute a subMesh
4439 static GHS3DPlugin_Hypothesis* GetGHSHypothesis( SMESH_subMesh* subMesh )
4441 SMESH_HypoFilter ghsHypFilter( SMESH_HypoFilter::HasName( "GHS3D_Parameters" ));
4442 return (GHS3DPlugin_Hypothesis* )
4443 subMesh->GetFather()->GetHypothesis( subMesh->GetSubShape(),
4445 /*visitAncestors=*/true);
4449 //================================================================================
4451 * \brief Sub-mesh event listener removing empty groups created due to "To make
4452 * groups of domains".
4454 struct _GroupsOfDomainsRemover : public SMESH_subMeshEventListener
4456 _GroupsOfDomainsRemover():
4457 SMESH_subMeshEventListener( /*isDeletable = */true,
4458 "GHS3DPlugin_GHS3D::_GroupsOfDomainsRemover" ) {}
4460 * \brief Treat events of the subMesh
4462 void ProcessEvent(const int event,
4463 const int eventType,
4464 SMESH_subMesh* subMesh,
4465 SMESH_subMeshEventListenerData* data,
4466 const SMESH_Hypothesis* hyp)
4468 if (SMESH_subMesh::ALGO_EVENT == eventType &&
4469 !subMesh->GetAlgo() )
4471 removeEmptyGroupsOfDomains( subMesh->GetFather(), /*notEmptyAsWell=*/true );
4477 //================================================================================
4479 * \brief Set an event listener to set enforced elements as soon as an enforced
4482 //================================================================================
4484 void GHS3DPlugin_GHS3D::SubmeshRestored(SMESH_subMesh* subMesh)
4486 if ( GHS3DPlugin_Hypothesis* hyp = _EnforcedMeshRestorer::GetGHSHypothesis( subMesh ))
4488 GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList enfMeshes = hyp->_GetEnforcedMeshes();
4489 GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList::iterator it = enfMeshes.begin();
4490 for(;it != enfMeshes.end();++it) {
4491 GHS3DPlugin_Hypothesis::TGHS3DEnforcedMesh* enfMesh = *it;
4492 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
4494 SMESH_subMesh* smToListen = mesh->GetSubMesh( mesh->GetShapeToMesh() );
4495 // a listener set to smToListen will care of hypothesis stored in SMESH_EventListenerData
4496 subMesh->SetEventListener( new _EnforcedMeshRestorer(),
4497 SMESH_subMeshEventListenerData::MakeData( subMesh ),
4504 //================================================================================
4506 * \brief Sets an event listener removing empty groups created due to "To make
4507 * groups of domains".
4508 * \param subMesh - submesh where algo is set
4510 * This method is called when a submesh gets HYP_OK algo_state.
4511 * After being set, event listener is notified on each event of a submesh.
4513 //================================================================================
4515 void GHS3DPlugin_GHS3D::SetEventListener(SMESH_subMesh* subMesh)
4517 subMesh->SetEventListener( new _GroupsOfDomainsRemover(), 0, subMesh );