1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : HYBRIDPlugin_HYBRID.cxx
22 // Author : Christian VAN WAMBEKE (CEA) (from GHS3D plugin V730)
25 #include "HYBRIDPlugin_HYBRID.hxx"
26 #include "HYBRIDPlugin_Hypothesis.hxx"
27 #include "MG_HYBRID_API.hxx"
29 #include <SMDS_FaceOfNodes.hxx>
30 #include <SMDS_LinearEdge.hxx>
31 #include <SMDS_VolumeOfNodes.hxx>
32 #include <SMESHDS_Group.hxx>
33 #include <SMESHDS_Mesh.hxx>
34 #include <SMESH_Comment.hxx>
35 #include <SMESH_File.hxx>
36 #include <SMESH_Group.hxx>
37 #include <SMESH_HypoFilter.hxx>
38 #include <SMESH_Mesh.hxx>
39 #include <SMESH_MeshAlgos.hxx>
40 #include <SMESH_MeshEditor.hxx>
41 #include <SMESH_MesherHelper.hxx>
42 #include <SMESH_ProxyMesh.hxx>
43 #include <SMESH_subMeshEventListener.hxx>
45 #include <BRepAdaptor_Surface.hxx>
46 #include <BRepBndLib.hxx>
47 #include <BRepBuilderAPI_MakeVertex.hxx>
48 #include <BRepClass3d.hxx>
49 #include <BRepClass3d_SolidClassifier.hxx>
50 #include <BRepExtrema_DistShapeShape.hxx>
51 #include <BRepGProp.hxx>
52 #include <BRepTools.hxx>
53 #include <BRep_Tool.hxx>
54 #include <Bnd_Box.hxx>
55 #include <GProp_GProps.hxx>
56 #include <GeomAPI_ProjectPointOnSurf.hxx>
57 #include <Precision.hxx>
58 #include <Standard_ErrorHandler.hxx>
59 #include <Standard_Failure.hxx>
60 #include <Standard_ProgramError.hxx>
62 #include <TopExp_Explorer.hxx>
63 #include <TopTools_IndexedMapOfShape.hxx>
64 #include <TopTools_ListIteratorOfListOfShape.hxx>
65 #include <TopTools_MapOfShape.hxx>
67 #include <TopoDS_Shell.hxx>
68 #include <TopoDS_Solid.hxx>
70 #include <Basics_Utils.hxx>
71 #include <utilities.h>
75 #define castToNode(n) static_cast<const SMDS_MeshNode *>( n );
78 #define GMFVERSION GmfDouble
80 #define GMFDIMENSION 3
84 typedef const std::list<const SMDS_MeshFace*> TTriaList;
86 static const char theDomainGroupNamePrefix[] = "Domain_";
88 static void removeFile( const std::string& fileName )
91 SMESH_File( fileName ).remove();
94 MESSAGE("Can't remove file: " << fileName << " ; file does not exist or permission denied");
98 //=============================================================================
102 //=============================================================================
104 HYBRIDPlugin_HYBRID::HYBRIDPlugin_HYBRID(int hypId, SMESH_Gen* gen)
105 : SMESH_3D_Algo(hypId, gen)
108 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
109 _onlyUnaryInput = true; // Compute() will be called on each solid
112 _compatibleHypothesis.push_back( HYBRIDPlugin_Hypothesis::GetHypType());
113 _requireShape = false; // can work without shape
114 _computeCanceled = false;
117 //=============================================================================
121 //=============================================================================
123 HYBRIDPlugin_HYBRID::~HYBRIDPlugin_HYBRID()
127 //=============================================================================
131 //=============================================================================
133 bool HYBRIDPlugin_HYBRID::CheckHypothesis ( SMESH_Mesh& aMesh,
134 const TopoDS_Shape& aShape,
135 Hypothesis_Status& aStatus )
137 aStatus = SMESH_Hypothesis::HYP_OK;
141 _removeLogOnSuccess = true;
142 _logInStandardOutput = false;
144 const std::list <const SMESHDS_Hypothesis * >& hyps =
145 GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliary=*/false);
146 std::list <const SMESHDS_Hypothesis* >::const_iterator h = hyps.begin();
147 for ( ; h != hyps.end(); ++h )
150 _hyp = dynamic_cast< const HYBRIDPlugin_Hypothesis*> ( *h );
154 _keepFiles = _hyp->GetKeepFiles();
155 _removeLogOnSuccess = _hyp->GetRemoveLogOnSuccess();
156 _logInStandardOutput = _hyp->GetStandardOutputLog();
163 //=======================================================================
164 //function : entryToShape
166 //=======================================================================
168 TopoDS_Shape HYBRIDPlugin_HYBRID::entryToShape(std::string entry)
170 if ( SMESH_Gen_i::getStudyServant()->_is_nil() )
171 throw SALOME_Exception("MG-HYBRID plugin can't work w/o publishing in the study");
172 GEOM::GEOM_Object_var aGeomObj;
173 TopoDS_Shape S = TopoDS_Shape();
174 SALOMEDS::SObject_var aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( entry.c_str() );
175 if (!aSObj->_is_nil() ) {
176 CORBA::Object_var obj = aSObj->GetObject();
177 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
180 if ( !aGeomObj->_is_nil() )
181 S = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aGeomObj.in() );
185 //=======================================================================
186 //function : addElemInMeshGroup
187 //purpose : Update or create groups in mesh
188 //=======================================================================
190 static void addElemInMeshGroup(SMESH_Mesh* theMesh,
191 const SMDS_MeshElement* anElem,
192 std::string& groupName,
193 std::set<std::string>& groupsToRemove)
195 if ( !anElem ) return; // issue 0021776
197 bool groupDone = false;
198 SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups();
199 while (grIt->more()) {
200 SMESH_Group * group = grIt->next();
201 if ( !group ) continue;
202 SMESHDS_GroupBase* groupDS = group->GetGroupDS();
203 if ( !groupDS ) continue;
204 if ( groupDS->GetType()==anElem->GetType() &&groupName.compare(group->GetName())==0) {
205 SMESHDS_Group* aGroupDS = static_cast<SMESHDS_Group*>( groupDS );
206 aGroupDS->SMDSGroup().Add(anElem);
215 SMESH_Group* aGroup = theMesh->AddGroup(anElem->GetType(), groupName.c_str(), groupId);
216 aGroup->SetName( groupName.c_str() );
217 SMESHDS_Group* aGroupDS = static_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
218 aGroupDS->SMDSGroup().Add(anElem);
222 throw SALOME_Exception(LOCALIZED("A given element was not added to a group"));
226 //=======================================================================
227 //function : updateMeshGroups
228 //purpose : Update or create groups in mesh
229 //=======================================================================
231 static void updateMeshGroups(SMESH_Mesh* theMesh, std::set<std::string> groupsToRemove)
233 SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups();
234 while (grIt->more()) {
235 SMESH_Group * group = grIt->next();
236 if ( !group ) continue;
237 SMESHDS_GroupBase* groupDS = group->GetGroupDS();
238 if ( !groupDS ) continue;
239 std::string currentGroupName = (std::string)group->GetName();
240 if (groupDS->IsEmpty() && groupsToRemove.find(currentGroupName) != groupsToRemove.end()) {
241 // Previous group created by enforced elements
242 theMesh->RemoveGroup(groupDS->GetID());
247 //=======================================================================
248 //function : removeEmptyGroupsOfDomains
249 //purpose : remove empty groups named "Domain_nb" created due to
250 // "To make groups of domains" option.
251 //=======================================================================
253 static void removeEmptyGroupsOfDomains(SMESH_Mesh* mesh,
254 bool notEmptyAsWell = false)
256 const char* refName = theDomainGroupNamePrefix;
257 const size_t refLen = strlen( theDomainGroupNamePrefix );
259 std::list<int> groupIDs = mesh->GetGroupIds();
260 std::list<int>::const_iterator id = groupIDs.begin();
261 for ( ; id != groupIDs.end(); ++id )
263 SMESH_Group* group = mesh->GetGroup( *id );
264 if ( !group || ( !group->GetGroupDS()->IsEmpty() && !notEmptyAsWell ))
266 const char* name = group->GetName();
269 if ( strncmp( name, refName, refLen ) == 0 && // starts from refName;
270 isdigit( *( name + refLen )) && // refName is followed by a digit;
271 strtol( name + refLen, &end, 10) >= 0 && // there are only digits ...
272 *end == '\0') // ... till a string end.
274 mesh->RemoveGroup( *id );
279 //================================================================================
281 * \brief Create the groups corresponding to domains
283 //================================================================================
285 static void makeDomainGroups( std::vector< std::vector< const SMDS_MeshElement* > >& elemsOfDomain,
286 SMESH_MesherHelper* theHelper)
288 for ( size_t iDomain = 0; iDomain < elemsOfDomain.size(); ++iDomain )
290 std::vector< const SMDS_MeshElement* > & elems = elemsOfDomain[ iDomain ];
291 if ( elems.empty() ) continue;
293 // find existing groups
294 std::vector< SMESH_Group* > groupOfType( SMDSAbs_NbElementTypes, (SMESH_Group*)NULL );
295 const std::string domainName = ( SMESH_Comment( theDomainGroupNamePrefix ) << iDomain );
296 SMESH_Mesh::GroupIteratorPtr groupIt = theHelper->GetMesh()->GetGroups();
297 while ( groupIt->more() )
299 SMESH_Group* group = groupIt->next();
300 if ( domainName == group->GetName() &&
301 dynamic_cast< SMESHDS_Group* >( group->GetGroupDS()) )
302 groupOfType[ group->GetGroupDS()->GetType() ] = group;
304 // create and fill the groups
309 SMESH_Group* group = groupOfType[ elems[ iElem ]->GetType() ];
311 group = theHelper->GetMesh()->AddGroup( elems[ iElem ]->GetType(),
312 domainName.c_str(), groupID );
313 SMDS_MeshGroup& groupDS =
314 static_cast< SMESHDS_Group* >( group->GetGroupDS() )->SMDSGroup();
316 while ( iElem < elems.size() && groupDS.Add( elems[iElem] ))
319 } while ( iElem < elems.size() );
323 //=======================================================================
324 //function : readGMFFile
325 //purpose : read GMF file w/o geometry associated to mesh
326 //=======================================================================
328 static bool readGMFFile(MG_HYBRID_API* MGOutput,
330 HYBRIDPlugin_HYBRID* theAlgo,
331 SMESH_MesherHelper* theHelper,
332 std::vector <const SMDS_MeshNode*> & theNodeByHybridId,
333 std::vector <const SMDS_MeshElement*> & theFaceByHybridId,
334 std::map<const SMDS_MeshNode*,int> & theNodeToHybridIdMap,
335 std::vector<std::string> & aNodeGroupByHybridId,
336 std::vector<std::string> & anEdgeGroupByHybridId,
337 std::vector<std::string> & aFaceGroupByHybridId,
338 std::set<std::string> & groupsToRemove,
339 bool toMakeGroupsOfDomains=false,
340 bool toMeshHoles=true)
343 SMESHDS_Mesh* theMeshDS = theHelper->GetMeshDS();
344 const bool hasGeom = ( theHelper->GetMesh()->HasShapeToMesh() );
346 // if imprinting, the original mesh faces are modified
347 // => we clear all the faces to retrieve them from Hybrid output mesh.
348 std::vector<int> facesWithImprinting;
349 if (theAlgo->getHyp())
350 facesWithImprinting = theAlgo->getHyp()->GetFacesWithImprinting();
352 if ( ! facesWithImprinting.empty() ) {
354 std::cout << "Imprinting => Clear original mesh" << std::endl;
356 SMDS_ElemIteratorPtr eIt = theMeshDS->elementsIterator();
358 theMeshDS->RemoveFreeElement( eIt->next(), /*sm=*/0 );
359 SMDS_NodeIteratorPtr nIt = theMeshDS->nodesIterator();
360 while ( nIt->more() )
361 theMeshDS->RemoveFreeNode( nIt->next(), /*sm=*/0 );
363 theNodeByHybridId.clear();
364 theFaceByHybridId.clear();
367 int nbMeshNodes = theMeshDS->NbNodes();
368 int nbInitialNodes = theNodeByHybridId.size();
370 const bool isQuadMesh =
371 theHelper->GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
372 theHelper->GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
373 theHelper->GetMesh()->NbVolumes( ORDER_QUADRATIC );
376 std::cout << "theNodeByHybridId.size(): " << nbInitialNodes << std::endl;
377 std::cout << "theHelper->GetMesh()->NbNodes(): " << nbMeshNodes << std::endl;
378 std::cout << "isQuadMesh: " << isQuadMesh << std::endl;
381 // ---------------------------------
382 // Read generated elements and nodes
383 // ---------------------------------
385 int nbElem = 0, nbRef = 0;
387 std::vector< const SMDS_MeshNode* > GMFNode;
389 std::map<int, std::set<int> > subdomainId2tetraId;
391 std::map <GmfKwdCod,int> tabRef;
392 const bool force3d = !hasGeom;
395 tabRef[GmfVertices] = 3; // for new nodes and enforced nodes
396 tabRef[GmfCorners] = 1;
397 tabRef[GmfEdges] = 2; // for enforced edges
398 tabRef[GmfRidges] = 1;
399 tabRef[GmfTriangles] = 3; // for enforced faces
400 tabRef[GmfQuadrilaterals] = 4;
401 tabRef[GmfTetrahedra] = 4; // for new tetras
402 tabRef[GmfPyramids] = 5; // for new pyramids
403 tabRef[GmfPrisms] = 6; // for new prisms
404 tabRef[GmfHexahedra] = 8;
407 int InpMsh = MGOutput->GmfOpenMesh(theFile, GmfRead, &ver, &dim);
411 // Hybrid is not multi-domain => We can't (and don't need to) read ids of domains in ouput file like in GHS3DPlugin
412 // We just need to get the id of the one and only solid
416 if ( theHelper->GetSubShape().ShapeType() == TopAbs_SOLID )
417 solidID = theHelper->GetSubShapeID();
419 solidID = theMeshDS->ShapeToIndex
420 ( TopExp_Explorer( theHelper->GetSubShape(), TopAbs_SOLID ).Current() );
423 // Issue 0020682. Avoid creating nodes and tetras at place where
424 // volumic elements already exist
425 SMESH_ElementSearcher* elemSearcher = 0;
426 std::vector< const SMDS_MeshElement* > foundVolumes;
427 if ( !hasGeom && theHelper->GetMesh()->NbVolumes() > 0 )
428 elemSearcher = SMESH_MeshAlgos::GetElementSearcher( *theMeshDS );
429 SMESHUtils::Deleter< SMESH_ElementSearcher > elemSearcherDeleter( elemSearcher );
431 // IMP 0022172: [CEA 790] create the groups corresponding to domains
432 std::vector< std::vector< const SMDS_MeshElement* > > elemsOfDomain;
434 int nbVertices = MGOutput->GmfStatKwd(InpMsh, GmfVertices) - nbInitialNodes;
435 if ( nbVertices < 0 )
437 GMFNode.resize( nbVertices + 1 );
439 std::map <GmfKwdCod,int>::const_iterator it = tabRef.begin();
440 for ( ; it != tabRef.end() ; ++it)
442 if(theAlgo->computeCanceled()) {
443 MGOutput->GmfCloseMesh(InpMsh);
447 GmfKwdCod token = it->first;
450 nbElem = MGOutput->GmfStatKwd(InpMsh, token);
452 MGOutput->GmfGotoKwd(InpMsh, token);
453 std::cout << "Read " << nbElem;
458 std::vector<int> id (nbElem*tabRef[token]); // node ids
459 std::vector<int> domainID( nbElem ); // domain
461 if (token == GmfVertices) {
462 (nbElem <= 1) ? tmpStr = " vertex" : tmpStr = " vertices";
467 const SMDS_MeshNode * aGMFNode;
469 for ( int iElem = 0; iElem < nbElem; iElem++ ) {
470 if(theAlgo->computeCanceled()) {
471 MGOutput->GmfCloseMesh(InpMsh);
474 if (ver == GmfFloat) {
475 MGOutput->GmfGetLin(InpMsh, token, &VerTab_f[0], &VerTab_f[1], &VerTab_f[2], &dummy);
481 MGOutput->GmfGetLin(InpMsh, token, &x, &y, &z, &dummy);
483 if (iElem >= nbInitialNodes) {
485 elemSearcher->FindElementsByPoint( gp_Pnt(x,y,z), SMDSAbs_Volume, foundVolumes))
488 aGMFNode = theHelper->AddNode(x, y, z);
490 aGMFID = iElem -nbInitialNodes +1;
491 GMFNode[ aGMFID ] = aGMFNode;
492 if (aGMFID-1 < (int)aNodeGroupByHybridId.size() && !aNodeGroupByHybridId.at(aGMFID-1).empty())
493 addElemInMeshGroup(theHelper->GetMesh(), aGMFNode, aNodeGroupByHybridId.at(aGMFID-1), groupsToRemove);
497 else if (token == GmfCorners && nbElem > 0) {
498 (nbElem <= 1) ? tmpStr = " corner" : tmpStr = " corners";
499 for ( int iElem = 0; iElem < nbElem; iElem++ )
500 MGOutput->GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
502 else if (token == GmfRidges && nbElem > 0) {
503 (nbElem <= 1) ? tmpStr = " ridge" : tmpStr = " ridges";
504 for ( int iElem = 0; iElem < nbElem; iElem++ )
505 MGOutput->GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]]);
507 else if (token == GmfEdges && nbElem > 0) {
508 (nbElem <= 1) ? tmpStr = " edge" : tmpStr = " edges";
509 for ( int iElem = 0; iElem < nbElem; iElem++ )
510 MGOutput->GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &domainID[iElem]);
512 else if (token == GmfTriangles && nbElem > 0) {
513 (nbElem <= 1) ? tmpStr = " triangle" : tmpStr = " triangles";
514 for ( int iElem = 0; iElem < nbElem; iElem++ )
515 MGOutput->GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &domainID[iElem]);
517 else if (token == GmfQuadrilaterals && nbElem > 0) {
518 (nbElem <= 1) ? tmpStr = " Quadrilateral" : tmpStr = " Quadrilaterals";
519 for ( int iElem = 0; iElem < nbElem; iElem++ )
520 MGOutput->GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &domainID[iElem]);
522 else if (token == GmfTetrahedra && nbElem > 0) {
523 (nbElem <= 1) ? tmpStr = " Tetrahedron" : tmpStr = " Tetrahedra";
524 for ( int iElem = 0; iElem < nbElem; iElem++ ) {
525 MGOutput->GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &domainID[iElem]);
527 subdomainId2tetraId[dummy].insert(iElem+1);
531 else if (token == GmfPyramids && nbElem > 0) {
532 (nbElem <= 1) ? tmpStr = " Pyramid" : tmpStr = " Pyramids";
533 for ( int iElem = 0; iElem < nbElem; iElem++ )
534 MGOutput->GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3],
535 &id[iElem*tabRef[token]+4], &domainID[iElem]);
537 else if (token == GmfPrisms && nbElem > 0) {
538 (nbElem <= 1) ? tmpStr = " Prism" : tmpStr = " Prisms";
539 for ( int iElem = 0; iElem < nbElem; iElem++ )
540 MGOutput->GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3],
541 &id[iElem*tabRef[token]+4], &id[iElem*tabRef[token]+5], &domainID[iElem]);
543 else if (token == GmfHexahedra && nbElem > 0) {
544 (nbElem <= 1) ? tmpStr = " Hexahedron" : tmpStr = " Hexahedra";
545 for ( int iElem = 0; iElem < nbElem; iElem++ )
546 MGOutput->GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3],
547 &id[iElem*tabRef[token]+4], &id[iElem*tabRef[token]+5], &id[iElem*tabRef[token]+6], &id[iElem*tabRef[token]+7], &domainID[iElem]);
549 std::cout << tmpStr << std::endl;
550 //std::cout << std::endl;
557 case GmfQuadrilaterals:
563 std::vector< const SMDS_MeshNode* > node( nbRef );
564 std::vector< int > nodeID( nbRef );
565 std::vector< SMDS_MeshNode* > enfNode( nbRef );
566 const SMDS_MeshElement* aCreatedElem;
568 for ( int iElem = 0; iElem < nbElem; iElem++ )
570 if(theAlgo->computeCanceled()) {
571 MGOutput->GmfCloseMesh(InpMsh);
574 // Check if elem is already in input mesh. If yes => skip
575 bool fullyCreatedElement = false; // if at least one of the nodes was created
576 for ( int iRef = 0; iRef < nbRef; iRef++ )
578 aGMFNodeID = id[iElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID
579 if (aGMFNodeID <= nbInitialNodes) // input nodes
582 node[ iRef ] = theNodeByHybridId[aGMFNodeID];
586 fullyCreatedElement = true;
587 aGMFNodeID -= nbInitialNodes;
588 nodeID[ iRef ] = aGMFNodeID ;
589 node [ iRef ] = GMFNode[ aGMFNodeID ];
596 if (fullyCreatedElement) {
597 aCreatedElem = theHelper->AddEdge( node[0], node[1], noID, force3d );
598 if ( !anEdgeGroupByHybridId.empty() && !anEdgeGroupByHybridId[iElem].empty())
599 addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByHybridId[iElem], groupsToRemove);
603 if (fullyCreatedElement) {
604 aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], noID, force3d );
605 // add iElem < aFaceGroupByHybridId.size() to avoid crash if imprinting with hexa core with MeshGems <= 2.4-5
606 if ( iElem < (int)aFaceGroupByHybridId.size() && !aFaceGroupByHybridId[iElem].empty() ) {
607 addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, aFaceGroupByHybridId[iElem], groupsToRemove);
609 // add element in shape for groups on geom to work
610 if ( domainID[iElem] > 0 )
612 theMeshDS->SetMeshElementOnShape( aCreatedElem, domainID[iElem] );
613 for ( int iN = 0; iN < 3; ++iN )
614 if ( node[iN]->getshapeId() < 1 )
615 theMeshDS->SetNodeOnFace( node[iN], domainID[iElem] );
619 case GmfQuadrilaterals:
620 if (fullyCreatedElement) {
621 aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], node[3], noID, force3d );
622 // add element in shape for groups on geom to work
623 if ( domainID[iElem] > 0 )
625 theMeshDS->SetMeshElementOnShape( aCreatedElem, domainID[iElem] );
626 for ( int iN = 0; iN < 3; ++iN )
627 if ( node[iN]->getshapeId() < 1 )
628 theMeshDS->SetNodeOnFace( node[iN], domainID[iElem] );
635 if ( solidID != HOLE_ID )
637 aCreatedElem = theHelper->AddVolume( node[1], node[0], node[2], node[3],
639 theMeshDS->SetMeshElementOnShape( aCreatedElem, solidID );
640 for ( int iN = 0; iN < 4; ++iN )
641 if ( node[iN]->getshapeId() < 1 )
642 theMeshDS->SetNodeInVolume( node[iN], solidID );
647 if ( elemSearcher ) {
648 // Issue 0020682. Avoid creating nodes and tetras at place where
649 // volumic elements already exist
650 if ( !node[1] || !node[0] || !node[2] || !node[3] )
652 if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) +
653 SMESH_TNodeXYZ(node[1]) +
654 SMESH_TNodeXYZ(node[2]) +
655 SMESH_TNodeXYZ(node[3]) ) / 4.,
656 SMDSAbs_Volume, foundVolumes ))
659 aCreatedElem = theHelper->AddVolume( node[1], node[0], node[2], node[3],
666 if ( solidID != HOLE_ID )
668 aCreatedElem = theHelper->AddVolume( node[3], node[2], node[1],
671 theMeshDS->SetMeshElementOnShape( aCreatedElem, solidID );
672 for ( int iN = 0; iN < 5; ++iN )
673 if ( node[iN]->getshapeId() < 1 )
674 theMeshDS->SetNodeInVolume( node[iN], solidID );
679 if ( elemSearcher ) {
680 // Issue 0020682. Avoid creating nodes and tetras at place where
681 // volumic elements already exist
682 if ( !node[1] || !node[0] || !node[2] || !node[3] || !node[4] || !node[5] )
684 if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) +
685 SMESH_TNodeXYZ(node[1]) +
686 SMESH_TNodeXYZ(node[2]) +
687 SMESH_TNodeXYZ(node[3]) +
688 SMESH_TNodeXYZ(node[4])) / 5.,
689 SMDSAbs_Volume, foundVolumes ))
692 aCreatedElem = theHelper->AddVolume( node[3], node[2], node[1],
700 if ( solidID != HOLE_ID )
702 aCreatedElem = theHelper->AddVolume( node[0], node[2], node[1],
703 node[3], node[5], node[4],
705 theMeshDS->SetMeshElementOnShape( aCreatedElem, solidID );
706 for ( int iN = 0; iN < 6; ++iN )
707 if ( node[iN]->getshapeId() < 1 )
708 theMeshDS->SetNodeInVolume( node[iN], solidID );
713 if ( elemSearcher ) {
714 // Issue 0020682. Avoid creating nodes and tetras at place where
715 // volumic elements already exist
716 if ( !node[1] || !node[0] || !node[2] || !node[3] || !node[4] || !node[5] )
718 if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) +
719 SMESH_TNodeXYZ(node[1]) +
720 SMESH_TNodeXYZ(node[2]) +
721 SMESH_TNodeXYZ(node[3]) +
722 SMESH_TNodeXYZ(node[4]) +
723 SMESH_TNodeXYZ(node[5])) / 6.,
724 SMDSAbs_Volume, foundVolumes ))
727 aCreatedElem = theHelper->AddVolume( node[0], node[2], node[1],
728 node[3], node[5], node[4],
735 if ( solidID != HOLE_ID )
737 aCreatedElem = theHelper->AddVolume( node[0], node[3], node[2], node[1],
738 node[4], node[7], node[6], node[5],
740 theMeshDS->SetMeshElementOnShape( aCreatedElem, solidID );
741 for ( int iN = 0; iN < 8; ++iN )
742 if ( node[iN]->getshapeId() < 1 )
743 theMeshDS->SetNodeInVolume( node[iN], solidID );
748 if ( elemSearcher ) {
749 // Issue 0020682. Avoid creating nodes and tetras at place where
750 // volumic elements already exist
751 if ( !node[1] || !node[0] || !node[2] || !node[3] || !node[4] || !node[5] || !node[6] || !node[7])
753 if ( elemSearcher->FindElementsByPoint((SMESH_TNodeXYZ(node[0]) +
754 SMESH_TNodeXYZ(node[1]) +
755 SMESH_TNodeXYZ(node[2]) +
756 SMESH_TNodeXYZ(node[3]) +
757 SMESH_TNodeXYZ(node[4]) +
758 SMESH_TNodeXYZ(node[5]) +
759 SMESH_TNodeXYZ(node[6]) +
760 SMESH_TNodeXYZ(node[7])) / 8.,
761 SMDSAbs_Volume, foundVolumes ))
764 aCreatedElem = theHelper->AddVolume( node[0], node[3], node[2], node[1],
765 node[4], node[7], node[6], node[5],
772 if ( aCreatedElem && toMakeGroupsOfDomains )
774 if ( domainID[iElem] >= (int) elemsOfDomain.size() )
775 elemsOfDomain.resize( domainID[iElem] + 1 );
776 elemsOfDomain[ domainID[iElem] ].push_back( aCreatedElem );
778 } // loop on elements of one type
786 // remove nodes in holes
789 for ( int i = 1; i <= nbVertices; ++i )
790 if ( GMFNode[i]->NbInverseElements() == 0 )
791 theMeshDS->RemoveFreeNode( GMFNode[i], /*sm=*/0, /*fromGroups=*/false );
794 MGOutput->GmfCloseMesh(InpMsh);
796 // 0022172: [CEA 790] create the groups corresponding to domains
797 if ( toMakeGroupsOfDomains )
798 makeDomainGroups( elemsOfDomain, theHelper );
801 std::map<int, std::set<int> >::const_iterator subdomainIt = subdomainId2tetraId.begin();
802 std::string aSubdomainFileName = theFile;
803 aSubdomainFileName = aSubdomainFileName + ".subdomain";
804 ofstream aSubdomainFile ( aSubdomainFileName , ios::out);
806 aSubdomainFile << "Nb subdomains " << subdomainId2tetraId.size() << std::endl;
807 for(;subdomainIt != subdomainId2tetraId.end() ; ++subdomainIt) {
808 int subdomainId = subdomainIt->first;
809 std::set<int> tetraIds = subdomainIt->second;
810 std::set<int>::const_iterator tetraIdsIt = tetraIds.begin();
811 aSubdomainFile << subdomainId << std::endl;
812 for(;tetraIdsIt != tetraIds.end() ; ++tetraIdsIt) {
813 aSubdomainFile << (*tetraIdsIt) << " ";
815 aSubdomainFile << std::endl;
817 aSubdomainFile.close();
824 static bool writeGMFFile(MG_HYBRID_API* MGInput,
825 const char* theMeshFileName,
826 const char* theRequiredFileName,
827 const char* theSolFileName,
828 const SMESH_ProxyMesh& theProxyMesh,
829 SMESH_MesherHelper& theHelper,
830 std::vector <const SMDS_MeshNode*> & theNodeByHybridId,
831 std::vector <const SMDS_MeshElement*> & theFaceByHybridId,
832 std::map<const SMDS_MeshNode*,int> & aNodeToHybridIdMap,
833 std::vector<std::string> & aNodeGroupByHybridId,
834 std::vector<std::string> & anEdgeGroupByHybridId,
835 std::vector<std::string> & aFaceGroupByHybridId,
836 HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes,
837 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges,
838 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles,
839 std::map<std::vector<double>, std::string> & enfVerticesWithGroup,
840 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues & theEnforcedVertices)
843 int idx, idxRequired = 0, idxSol = 0;
845 //const int dummyint = 0;
846 const int dummyint1 = 1;
847 const int dummyint2 = 2;
848 const int dummyint3 = 3;
849 const int dummyint4 = 4;
850 const int enforcedTag = HYBRIDPlugin_Hypothesis::EnforcedTag();
851 //const int dummyint6 = 6; //are interesting for layers
852 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues::const_iterator vertexIt;
853 std::vector<double> enfVertexSizes;
854 const SMDS_MeshElement* elem;
855 TIDSortedElemSet anElemSetTri, anElemSetQuad, theKeptEnforcedEdges, theKeptEnforcedTriangles;
856 SMDS_ElemIteratorPtr nodeIt;
857 std::vector <const SMDS_MeshNode*> theEnforcedNodeByHybridId;
858 std::map<const SMDS_MeshNode*,int> anEnforcedNodeToHybridIdMap, anExistingEnforcedNodeToHybridIdMap;
859 std::vector< const SMDS_MeshElement* > foundElems;
860 std::map<const SMDS_MeshNode*,TopAbs_State> aNodeToTopAbs_StateMap;
862 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap::iterator elemIt;
863 TIDSortedElemSet::iterator elemSetIt;
865 SMESH_Mesh* theMesh = theHelper.GetMesh();
866 const bool hasGeom = theMesh->HasShapeToMesh();
867 SMESHUtils::Deleter< SMESH_ElementSearcher > pntCls
868 ( SMESH_MeshAlgos::GetElementSearcher(*theMesh->GetMeshDS()));
870 int nbEnforcedVertices = theEnforcedVertices.size();
873 int nbFaces = theProxyMesh.NbFaces();
875 theFaceByHybridId.reserve( nbFaces );
878 int usedEnforcedNodes = 0;
884 idx = MGInput->GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
888 // ========================== FACES ==========================
889 // TRIANGLES ==========================
890 SMDS_ElemIteratorPtr eIt =
891 hasGeom ? theProxyMesh.GetFaces( theHelper.GetSubShape()) : theProxyMesh.GetFaces();
892 while ( eIt->more() )
895 nodeIt = elem->nodesIterator();
896 nbNodes = elem->NbCornerNodes();
898 anElemSetTri.insert(elem);
899 else if (nbNodes == 4)
900 anElemSetQuad.insert(elem);
903 std::cout << "Unexpected number of nodes: " << nbNodes << std::endl;
904 throw ("Unexpected number of nodes" );
906 while ( nodeIt->more() && nbNodes--)
909 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
910 int newId = aNodeToHybridIdMap.size() + 1; // hybrid ids count from 1
911 aNodeToHybridIdMap.insert( std::make_pair( node, newId ));
915 //EDGES ==========================
917 // Iterate over the enforced edges
918 for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) {
919 elem = elemIt->first;
921 nodeIt = elem->nodesIterator();
923 while ( nodeIt->more() && nbNodes-- ) {
925 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
926 // Test if point is inside shape to mesh
927 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
928 TopAbs_State result = pntCls->GetPointState( myPoint );
929 if ( result == TopAbs_OUT ) {
933 aNodeToTopAbs_StateMap.insert( std::make_pair( node, result ));
936 nodeIt = elem->nodesIterator();
939 while ( nodeIt->more() && nbNodes-- ) {
941 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
942 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
943 nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
945 std::cout << "Node at "<<node->X()<<", "<<node->Y()<<", "<<node->Z()<<std::endl;
946 std::cout << "Nb nodes found : "<<nbFoundElems<<std::endl;
948 if (nbFoundElems ==0) {
949 if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
950 newId = aNodeToHybridIdMap.size() + anEnforcedNodeToHybridIdMap.size() + 1; // hybrid ids count from 1
951 anEnforcedNodeToHybridIdMap.insert( std::make_pair( node, newId ));
954 else if (nbFoundElems ==1) {
955 const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
956 newId = (*aNodeToHybridIdMap.find(existingNode)).second;
957 anExistingEnforcedNodeToHybridIdMap.insert( std::make_pair( node, newId ));
962 std::cout << "HYBRID node ID: "<<newId<<std::endl;
966 theKeptEnforcedEdges.insert(elem);
970 //ENFORCED TRIANGLES ==========================
972 // Iterate over the enforced triangles
973 for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) {
974 elem = elemIt->first;
976 nodeIt = elem->nodesIterator();
978 while ( nodeIt->more() && nbNodes--) {
980 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
981 // Test if point is inside shape to mesh
982 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
983 TopAbs_State result = pntCls->GetPointState( myPoint );
984 if ( result == TopAbs_OUT ) {
988 aNodeToTopAbs_StateMap.insert( std::make_pair( node, result ));
991 nodeIt = elem->nodesIterator();
994 while ( nodeIt->more() && nbNodes--) {
996 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
997 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
998 nbFoundElems = pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems);
1000 std::cout << "Nb nodes found : "<<nbFoundElems<<std::endl;
1002 if (nbFoundElems ==0) {
1003 if ((*aNodeToTopAbs_StateMap.find(node)).second == TopAbs_IN) {
1004 newId = aNodeToHybridIdMap.size() + anEnforcedNodeToHybridIdMap.size() + 1; // hybrid ids count from 1
1005 anEnforcedNodeToHybridIdMap.insert( std::make_pair( node, newId ));
1008 else if (nbFoundElems ==1) {
1009 const SMDS_MeshNode* existingNode = (SMDS_MeshNode*) foundElems.at(0);
1010 newId = (*aNodeToHybridIdMap.find(existingNode)).second;
1011 anExistingEnforcedNodeToHybridIdMap.insert( std::make_pair( node, newId ));
1016 std::cout << "HYBRID node ID: "<<newId<<std::endl;
1020 theKeptEnforcedTriangles.insert(elem);
1024 // put nodes to theNodeByHybridId vector
1026 std::cout << "aNodeToHybridIdMap.size(): "<<aNodeToHybridIdMap.size()<<std::endl;
1028 theNodeByHybridId.resize( aNodeToHybridIdMap.size() );
1029 std::map<const SMDS_MeshNode*,int>::const_iterator n2id = aNodeToHybridIdMap.begin();
1030 for ( ; n2id != aNodeToHybridIdMap.end(); ++ n2id)
1032 // std::cout << "n2id->first: "<<n2id->first<<std::endl;
1033 theNodeByHybridId[ n2id->second - 1 ] = n2id->first; // hybrid ids count from 1
1036 // put nodes to anEnforcedNodeToHybridIdMap vector
1038 std::cout << "anEnforcedNodeToHybridIdMap.size(): "<<anEnforcedNodeToHybridIdMap.size()<<std::endl;
1040 theEnforcedNodeByHybridId.resize( anEnforcedNodeToHybridIdMap.size());
1041 n2id = anEnforcedNodeToHybridIdMap.begin();
1042 for ( ; n2id != anEnforcedNodeToHybridIdMap.end(); ++ n2id)
1044 if (n2id->second > (int)aNodeToHybridIdMap.size()) {
1045 theEnforcedNodeByHybridId[ n2id->second - aNodeToHybridIdMap.size() - 1 ] = n2id->first; // hybrid ids count from 1
1050 //========================== NODES ==========================
1051 std::vector<const SMDS_MeshNode*> theOrderedNodes, theRequiredNodes;
1052 std::set< std::vector<double> > nodesCoords;
1053 std::vector<const SMDS_MeshNode*>::const_iterator hybridNodeIt = theNodeByHybridId.begin();
1054 std::vector<const SMDS_MeshNode*>::const_iterator after = theNodeByHybridId.end();
1056 (theNodeByHybridId.size() <= 1) ? tmpStr = " node" : " nodes";
1057 std::cout << theNodeByHybridId.size() << tmpStr << " from mesh ..." << std::endl;
1058 for ( ; hybridNodeIt != after; ++hybridNodeIt )
1060 const SMDS_MeshNode* node = *hybridNodeIt;
1061 std::vector<double> coords;
1062 coords.push_back(node->X());
1063 coords.push_back(node->Y());
1064 coords.push_back(node->Z());
1065 nodesCoords.insert(coords);
1066 theOrderedNodes.push_back(node);
1069 // Iterate over the enforced nodes given by enforced elements
1070 hybridNodeIt = theEnforcedNodeByHybridId.begin();
1071 after = theEnforcedNodeByHybridId.end();
1072 (theEnforcedNodeByHybridId.size() <= 1) ? tmpStr = " node" : " nodes";
1073 std::cout << theEnforcedNodeByHybridId.size() << tmpStr << " from enforced elements ..." << std::endl;
1074 for ( ; hybridNodeIt != after; ++hybridNodeIt )
1076 const SMDS_MeshNode* node = *hybridNodeIt;
1077 std::vector<double> coords;
1078 coords.push_back(node->X());
1079 coords.push_back(node->Y());
1080 coords.push_back(node->Z());
1082 std::cout << "Node at " << node->X()<<", " <<node->Y()<<", " <<node->Z();
1085 if (nodesCoords.find(coords) != nodesCoords.end()) {
1086 // node already exists in original mesh
1088 std::cout << " found" << std::endl;
1093 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) {
1094 // node already exists in enforced vertices
1096 std::cout << " found" << std::endl;
1102 std::cout << " not found" << std::endl;
1105 nodesCoords.insert(coords);
1106 theOrderedNodes.push_back(node);
1107 // theRequiredNodes.push_back(node);
1111 // Iterate over the enforced nodes
1112 HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt;
1113 (theEnforcedNodes.size() <= 1) ? tmpStr = " node" : " nodes";
1114 std::cout << theEnforcedNodes.size() << tmpStr << " from enforced nodes ..." << std::endl;
1115 for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt)
1117 const SMDS_MeshNode* node = enfNodeIt->first;
1118 std::vector<double> coords;
1119 coords.push_back(node->X());
1120 coords.push_back(node->Y());
1121 coords.push_back(node->Z());
1123 std::cout << "Node at " << node->X()<<", " <<node->Y()<<", " <<node->Z();
1126 // Test if point is inside shape to mesh
1127 gp_Pnt myPoint(node->X(),node->Y(),node->Z());
1128 TopAbs_State result = pntCls->GetPointState( myPoint );
1129 if ( result == TopAbs_OUT ) {
1131 std::cout << " out of volume" << std::endl;
1136 if (nodesCoords.find(coords) != nodesCoords.end()) {
1138 std::cout << " found in nodesCoords" << std::endl;
1140 // theRequiredNodes.push_back(node);
1144 if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) {
1146 std::cout << " found in theEnforcedVertices" << std::endl;
1152 std::cout << " not found" << std::endl;
1154 nodesCoords.insert(coords);
1155 // theOrderedNodes.push_back(node);
1156 theRequiredNodes.push_back(node);
1158 int requiredNodes = theRequiredNodes.size();
1161 std::vector<std::vector<double> > ReqVerTab;
1162 if (nbEnforcedVertices) {
1163 (nbEnforcedVertices <= 1) ? tmpStr = " node" : " nodes";
1164 std::cout << nbEnforcedVertices << tmpStr << " from enforced vertices ..." << std::endl;
1165 // Iterate over the enforced vertices
1166 for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) {
1167 double x = vertexIt->first[0];
1168 double y = vertexIt->first[1];
1169 double z = vertexIt->first[2];
1170 // Test if point is inside shape to mesh
1171 gp_Pnt myPoint(x,y,z);
1172 TopAbs_State result = pntCls->GetPointState( myPoint );
1173 if ( result == TopAbs_OUT )
1175 std::vector<double> coords;
1176 coords.push_back(x);
1177 coords.push_back(y);
1178 coords.push_back(z);
1179 ReqVerTab.push_back(coords);
1180 enfVertexSizes.push_back(vertexIt->second);
1187 std::cout << "Begin writing required nodes in GmfVertices" << std::endl;
1188 std::cout << "Nb vertices: " << theOrderedNodes.size() << std::endl;
1189 MGInput->GmfSetKwd(idx, GmfVertices, theOrderedNodes.size());
1190 for (hybridNodeIt = theOrderedNodes.begin();hybridNodeIt != theOrderedNodes.end();++hybridNodeIt) {
1191 MGInput->GmfSetLin(idx, GmfVertices, (*hybridNodeIt)->X(), (*hybridNodeIt)->Y(), (*hybridNodeIt)->Z(), dummyint1);
1194 std::cout << "End writing required nodes in GmfVertices" << std::endl;
1196 if (requiredNodes + solSize) {
1197 std::cout << "Begin writing in req and sol file" << std::endl;
1198 aNodeGroupByHybridId.resize( requiredNodes + solSize );
1199 idxRequired = MGInput->GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1201 MGInput->GmfCloseMesh(idx);
1204 idxSol = MGInput->GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION);
1206 MGInput->GmfCloseMesh(idx);
1208 MGInput->GmfCloseMesh(idxRequired);
1211 int TypTab[] = {GmfSca};
1212 double ValTab[] = {0.0};
1213 MGInput->GmfSetKwd(idxRequired, GmfVertices, requiredNodes + solSize);
1214 MGInput->GmfSetKwd(idxSol, GmfSolAtVertices, requiredNodes + solSize, 1, TypTab);
1215 for (hybridNodeIt = theRequiredNodes.begin();hybridNodeIt != theRequiredNodes.end();++hybridNodeIt) {
1216 MGInput->GmfSetLin(idxRequired, GmfVertices, (*hybridNodeIt)->X(), (*hybridNodeIt)->Y(), (*hybridNodeIt)->Z(), dummyint2);
1217 MGInput->GmfSetLin(idxSol, GmfSolAtVertices, ValTab);
1218 if (theEnforcedNodes.find((*hybridNodeIt)) != theEnforcedNodes.end())
1219 gn = theEnforcedNodes.find((*hybridNodeIt))->second;
1220 aNodeGroupByHybridId[usedEnforcedNodes] = gn;
1221 usedEnforcedNodes++;
1224 for (int i=0;i<solSize;i++) {
1225 std::cout << ReqVerTab[i][0] <<" "<< ReqVerTab[i][1] << " "<< ReqVerTab[i][2] << std::endl;
1227 std::cout << "enfVertexSizes.at("<<i<<"): " << enfVertexSizes.at(i) << std::endl;
1229 double solTab[] = {enfVertexSizes.at(i)};
1230 MGInput->GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint3);
1231 MGInput->GmfSetLin(idxSol, GmfSolAtVertices, solTab);
1232 aNodeGroupByHybridId[usedEnforcedNodes] = enfVerticesWithGroup.find(ReqVerTab[i])->second;
1234 std::cout << "aNodeGroupByHybridId["<<usedEnforcedNodes<<"] = \""<<aNodeGroupByHybridId[usedEnforcedNodes]<<"\""<<std::endl;
1236 usedEnforcedNodes++;
1238 std::cout << "End writing in req and sol file" << std::endl;
1241 int nedge[2], ntri[3], nquad[4];
1244 int usedEnforcedEdges = 0;
1245 if (theKeptEnforcedEdges.size()) {
1246 anEdgeGroupByHybridId.resize( theKeptEnforcedEdges.size() );
1247 MGInput->GmfSetKwd(idx, GmfEdges, theKeptEnforcedEdges.size());
1248 for(elemSetIt = theKeptEnforcedEdges.begin() ; elemSetIt != theKeptEnforcedEdges.end() ; ++elemSetIt) {
1249 elem = (*elemSetIt);
1250 nodeIt = elem->nodesIterator();
1252 while ( nodeIt->more() ) {
1254 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1255 std::map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToHybridIdMap.find(node);
1256 if (it == anEnforcedNodeToHybridIdMap.end()) {
1257 it = anExistingEnforcedNodeToHybridIdMap.find(node);
1258 if (it == anEnforcedNodeToHybridIdMap.end())
1259 throw "Node not found";
1261 nedge[index] = it->second;
1264 MGInput->GmfSetLin(idx, GmfEdges, nedge[0], nedge[1], dummyint4);
1265 anEdgeGroupByHybridId[usedEnforcedEdges] = theEnforcedEdges.find(elem)->second;
1266 usedEnforcedEdges++;
1271 if (usedEnforcedEdges) {
1272 MGInput->GmfSetKwd(idx, GmfRequiredEdges, usedEnforcedEdges);
1273 for (int enfID=1;enfID<=usedEnforcedEdges;enfID++) {
1274 MGInput->GmfSetLin(idx, GmfRequiredEdges, enfID);
1279 int usedEnforcedTriangles = 0;
1280 if (anElemSetTri.size()+theKeptEnforcedTriangles.size())
1282 aFaceGroupByHybridId.resize( anElemSetTri.size()+theKeptEnforcedTriangles.size() );
1283 MGInput->GmfSetKwd(idx, GmfTriangles, anElemSetTri.size()+theKeptEnforcedTriangles.size());
1285 for(elemSetIt = anElemSetTri.begin() ; elemSetIt != anElemSetTri.end() ; ++elemSetIt,++k)
1287 elem = (*elemSetIt);
1288 theFaceByHybridId.push_back( elem );
1289 nodeIt = elem->nodesIterator();
1291 for ( int j = 0; j < 3; ++j )
1294 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1295 std::map< const SMDS_MeshNode*,int >::iterator it = aNodeToHybridIdMap.find(node);
1296 if (it == aNodeToHybridIdMap.end())
1297 throw "Node not found";
1298 ntri[index] = it->second;
1301 MGInput->GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], /*tag=*/elem->getshapeId() );
1302 aFaceGroupByHybridId[k] = "";
1305 if ( !theHelper.GetMesh()->HasShapeToMesh() ) SMESHUtils::FreeVector( theFaceByHybridId );
1306 std::cout << "Enforced triangles size " << theKeptEnforcedTriangles.size() << std::endl;
1307 if (theKeptEnforcedTriangles.size())
1309 for(elemSetIt = theKeptEnforcedTriangles.begin() ; elemSetIt != theKeptEnforcedTriangles.end() ; ++elemSetIt,++k)
1311 elem = (*elemSetIt);
1312 nodeIt = elem->nodesIterator();
1314 for ( int j = 0; j < 3; ++j )
1317 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1318 std::map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToHybridIdMap.find(node);
1319 if (it == anEnforcedNodeToHybridIdMap.end())
1321 it = anExistingEnforcedNodeToHybridIdMap.find(node);
1322 if (it == anEnforcedNodeToHybridIdMap.end())
1323 throw "Node not found";
1325 ntri[index] = it->second;
1328 MGInput->GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], enforcedTag);
1329 aFaceGroupByHybridId[k] = theEnforcedTriangles.find(elem)->second;
1330 usedEnforcedTriangles++;
1336 if (usedEnforcedTriangles)
1338 MGInput->GmfSetKwd(idx, GmfRequiredTriangles, usedEnforcedTriangles);
1339 for (int enfID=1;enfID<=usedEnforcedTriangles;enfID++)
1340 MGInput->GmfSetLin(idx, GmfRequiredTriangles, anElemSetTri.size()+enfID);
1343 if (anElemSetQuad.size())
1345 MGInput->GmfSetKwd(idx, GmfQuadrilaterals, anElemSetQuad.size());
1347 for(elemSetIt = anElemSetQuad.begin() ; elemSetIt != anElemSetQuad.end() ; ++elemSetIt,++k)
1349 elem = (*elemSetIt);
1350 theFaceByHybridId.push_back( elem );
1351 nodeIt = elem->nodesIterator();
1353 for ( int j = 0; j < 4; ++j )
1356 const SMDS_MeshNode* node = castToNode( nodeIt->next() );
1357 std::map< const SMDS_MeshNode*,int >::iterator it = aNodeToHybridIdMap.find(node);
1358 if (it == aNodeToHybridIdMap.end())
1359 throw "Node not found";
1360 nquad[index] = it->second;
1363 MGInput->GmfSetLin(idx, GmfQuadrilaterals, nquad[0], nquad[1], nquad[2], nquad[3],
1364 /*tag=*/elem->getshapeId() );
1365 // _CEA_cbo what is it for???
1366 //aFaceGroupByHybridId[k] = "";
1370 MGInput->GmfCloseMesh(idx);
1372 MGInput->GmfCloseMesh(idxRequired);
1374 MGInput->GmfCloseMesh(idxSol);
1380 //=============================================================================
1382 *Here we are going to use the HYBRID mesher with geometry
1384 //=============================================================================
1386 bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh,
1387 const TopoDS_Shape& theShape)
1391 // a unique working file name
1392 // to avoid access to the same files by eg different users
1393 _genericName = HYBRIDPlugin_Hypothesis::GetFileName(_hyp);
1394 std::string aGenericName = _genericName;
1395 std::string aGenericNameRequired = aGenericName + "_required";
1397 std::string aLogFileName = aGenericName + ".log"; // log
1398 std::string aResultFileName;
1400 std::string aGMFFileName, aRequiredVerticesFileName, aSolFileName, aResSolFileName;
1401 aGMFFileName = aGenericName + ".mesh"; // GMF mesh file
1402 aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file
1403 aResSolFileName = aGenericName + "Vol.sol"; // GMF mesh file
1404 aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file
1405 aSolFileName = aGenericNameRequired + ".sol"; // GMF solution file
1407 std::map <int,int> aNodeId2NodeIndexMap, aSmdsToHybridIdMap, anEnforcedNodeIdToHybridIdMap;
1408 std::map <int, int> nodeID2nodeIndexMap;
1409 std::map<std::vector<double>, std::string> enfVerticesWithGroup;
1410 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues coordsSizeMap = HYBRIDPlugin_Hypothesis::GetEnforcedVerticesCoordsSize(_hyp);
1411 HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = HYBRIDPlugin_Hypothesis::GetEnforcedNodes(_hyp);
1412 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = HYBRIDPlugin_Hypothesis::GetEnforcedEdges(_hyp);
1413 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(_hyp);
1414 HYBRIDPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = HYBRIDPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp);
1416 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexList enfVertices = HYBRIDPlugin_Hypothesis::GetEnforcedVertices(_hyp);
1417 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexList::const_iterator enfVerIt = enfVertices.begin();
1418 std::vector<double> coords;
1420 for ( ; enfVerIt != enfVertices.end() ; ++enfVerIt)
1422 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* enfVertex = (*enfVerIt);
1423 if (enfVertex->coords.size()) {
1424 coordsSizeMap.insert(std::make_pair(enfVertex->coords,enfVertex->size));
1425 enfVerticesWithGroup.insert(std::make_pair(enfVertex->coords,enfVertex->groupName));
1428 TopoDS_Shape GeomShape = entryToShape(enfVertex->geomEntry);
1429 for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){
1431 if (it.Value().ShapeType() == TopAbs_VERTEX){
1432 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(it.Value()));
1433 coords.push_back(aPnt.X());
1434 coords.push_back(aPnt.Y());
1435 coords.push_back(aPnt.Z());
1436 if (coordsSizeMap.find(coords) == coordsSizeMap.end()) {
1437 coordsSizeMap.insert(std::make_pair(coords,enfVertex->size));
1438 enfVerticesWithGroup.insert(std::make_pair(coords,enfVertex->groupName));
1444 int nbEnforcedVertices = coordsSizeMap.size();
1445 int nbEnforcedNodes = enforcedNodes.size();
1448 (nbEnforcedNodes <= 1) ? tmpStr = "node" : "nodes";
1449 std::cout << nbEnforcedNodes << " enforced " << tmpStr << " from hypo" << std::endl;
1450 (nbEnforcedVertices <= 1) ? tmpStr = "vertex" : "vertices";
1451 std::cout << nbEnforcedVertices << " enforced " << tmpStr << " from hypo" << std::endl;
1453 SMESH_MesherHelper helper( theMesh );
1454 helper.SetSubShape( theShape );
1456 std::vector <const SMDS_MeshNode*> aNodeByHybridId, anEnforcedNodeByHybridId;
1457 std::vector <const SMDS_MeshElement*> aFaceByHybridId;
1458 std::map<const SMDS_MeshNode*,int> aNodeToHybridIdMap;
1459 std::vector<std::string> aNodeGroupByHybridId, anEdgeGroupByHybridId, aFaceGroupByHybridId;
1461 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
1463 MG_HYBRID_API mgHybrid( _computeCanceled, _progress );
1465 Ok = writeGMFFile(&mgHybrid,
1466 aGMFFileName.c_str(),
1467 aRequiredVerticesFileName.c_str(),
1468 aSolFileName.c_str(),
1470 aNodeByHybridId, aFaceByHybridId, aNodeToHybridIdMap,
1471 aNodeGroupByHybridId, anEdgeGroupByHybridId, aFaceGroupByHybridId,
1472 enforcedNodes, enforcedEdges, enforcedTriangles, /*enforcedQuadrangles,*/
1473 enfVerticesWithGroup, coordsSizeMap);
1475 // Write aSmdsToHybridIdMap to temp file
1476 std::string aSmdsToHybridIdMapFileName;
1477 aSmdsToHybridIdMapFileName = aGenericName + ".ids"; // ids relation
1478 ofstream aIdsFile ( aSmdsToHybridIdMapFileName , ios::out);
1479 Ok = aIdsFile.rdbuf()->is_open();
1481 INFOS( "Can't write into " << aSmdsToHybridIdMapFileName);
1482 return error(SMESH_Comment("Can't write into ") << aSmdsToHybridIdMapFileName);
1484 INFOS( "Writing ids relation into " << aSmdsToHybridIdMapFileName);
1485 aIdsFile << "Smds Hybrid" << std::endl;
1486 std::map <int,int>::const_iterator myit;
1487 for (myit=aSmdsToHybridIdMap.begin() ; myit != aSmdsToHybridIdMap.end() ; ++myit) {
1488 aIdsFile << myit->first << " " << myit->second << std::endl;
1494 if ( !_keepFiles ) {
1495 removeFile( aGMFFileName );
1496 removeFile( aRequiredVerticesFileName );
1497 removeFile( aSolFileName );
1498 removeFile( aSmdsToHybridIdMapFileName );
1500 return error(COMPERR_BAD_INPUT_MESH);
1502 removeFile( aResultFileName ); // needed for boundary recovery module usage
1504 // -----------------
1505 // run hybrid mesher
1506 // -----------------
1508 std::string cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp, theMesh );
1510 if ( mgHybrid.IsExecutable() )
1512 cmd += " --in " + aGMFFileName;
1513 cmd += " --out " + aResultFileName;
1515 std::cout << std::endl;
1516 std::cout << "Hybrid execution with geometry..." << std::endl;
1518 if ( !_logInStandardOutput )
1520 mgHybrid.SetLogFile( aLogFileName );
1521 if ( mgHybrid.IsExecutable() )
1522 cmd += " 1>" + aLogFileName; // dump into file
1523 std::cout << " 1> " << aLogFileName;
1525 std::cout << std::endl;
1527 _computeCanceled = false;
1530 Ok = mgHybrid.Compute( cmd, errStr ); // run
1532 if ( _logInStandardOutput && mgHybrid.IsLibrary() )
1533 std::cout << std::endl << mgHybrid.GetLog() << std::endl;
1535 std::cout << "End of Hybrid execution !" << std::endl;
1541 // Mapping the result file
1543 HYBRIDPlugin_Hypothesis::TSetStrings groupsToRemove = HYBRIDPlugin_Hypothesis::GetGroupsToRemove(_hyp);
1545 _hyp ? _hyp->GetToMeshHoles(true) : HYBRIDPlugin_Hypothesis::DefaultMeshHoles();
1546 const bool toMakeGroupsOfDomains = HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains( _hyp );
1548 helper.IsQuadraticSubMesh( theShape );
1549 helper.SetElementsOnShape( false );
1551 Ok = readGMFFile(&mgHybrid, aResultFileName.c_str(),
1553 &helper, aNodeByHybridId, aFaceByHybridId, aNodeToHybridIdMap,
1554 aNodeGroupByHybridId, anEdgeGroupByHybridId, aFaceGroupByHybridId,
1555 groupsToRemove, toMakeGroupsOfDomains, toMeshHoles);
1557 removeEmptyGroupsOfDomains( helper.GetMesh(), !toMakeGroupsOfDomains );
1561 // ---------------------
1562 // remove working files
1563 // ---------------------
1567 if ( _removeLogOnSuccess )
1568 removeFile( aLogFileName );
1570 else if ( mgHybrid.HasLog() )
1572 // get problem description from the log file
1573 _Ghs2smdsConvertor conv( aNodeByHybridId );
1574 storeErrorDescription( _logInStandardOutput ? 0 : aLogFileName.c_str(),
1575 mgHybrid.GetLog(), conv );
1577 else if ( !errStr.empty() )
1579 // the log file is empty
1580 removeFile( aLogFileName );
1581 INFOS( "HYBRID Error, " << errStr );
1582 error(COMPERR_ALGO_FAILED, errStr );
1585 if ( !_keepFiles ) {
1586 if (! Ok && _computeCanceled)
1587 removeFile( aLogFileName );
1588 removeFile( aGMFFileName );
1589 removeFile( aRequiredVerticesFileName );
1590 removeFile( aSolFileName );
1591 removeFile( aResSolFileName );
1592 removeFile( aResultFileName );
1593 removeFile( aSmdsToHybridIdMapFileName );
1595 if ( mgHybrid.IsExecutable() )
1597 std::cout << "<" << aResultFileName << "> HYBRID output file ";
1599 std::cout << "not ";
1600 std::cout << "treated !" << std::endl;
1601 std::cout << std::endl;
1605 std::cout << "MG-HYBRID " << ( Ok ? "succeeded" : "failed") << std::endl;
1611 //=============================================================================
1613 *Here we are going to use the HYBRID mesher w/o geometry
1615 //=============================================================================
1616 bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh,
1617 SMESH_MesherHelper* theHelper)
1619 theHelper->IsQuadraticSubMesh( theHelper->GetSubShape() );
1621 // a unique working file name
1622 // to avoid access to the same files by eg different users
1623 _genericName = HYBRIDPlugin_Hypothesis::GetFileName(_hyp);
1624 std::string aGenericName((char*) _genericName.c_str() );
1625 std::string aGenericNameRequired = aGenericName + "_required";
1627 std::string aLogFileName = aGenericName + ".log"; // log
1628 std::string aResultFileName;
1631 std::string aGMFFileName, aRequiredVerticesFileName, aSolFileName, aResSolFileName;
1632 aGMFFileName = aGenericName + ".mesh"; // GMF mesh file
1633 aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file
1634 aResSolFileName = aGenericName + "Vol.sol"; // GMF mesh file
1635 aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file
1636 aSolFileName = aGenericNameRequired + ".sol"; // GMF solution file
1638 std::map <int, int> nodeID2nodeIndexMap;
1639 std::map<std::vector<double>, std::string> enfVerticesWithGroup;
1640 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues coordsSizeMap;
1641 TopoDS_Shape GeomShape;
1642 std::vector<double> coords;
1644 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* enfVertex;
1646 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexList enfVertices = HYBRIDPlugin_Hypothesis::GetEnforcedVertices(_hyp);
1647 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexList::const_iterator enfVerIt = enfVertices.begin();
1649 for ( ; enfVerIt != enfVertices.end() ; ++enfVerIt)
1651 enfVertex = (*enfVerIt);
1652 if (enfVertex->coords.size()) {
1653 coordsSizeMap.insert(std::make_pair(enfVertex->coords,enfVertex->size));
1654 enfVerticesWithGroup.insert(std::make_pair(enfVertex->coords,enfVertex->groupName));
1657 GeomShape = entryToShape(enfVertex->geomEntry);
1658 for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){
1660 if (it.Value().ShapeType() == TopAbs_VERTEX){
1661 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(it.Value()));
1662 coords.push_back(aPnt.X());
1663 coords.push_back(aPnt.Y());
1664 coords.push_back(aPnt.Z());
1665 if (coordsSizeMap.find(coords) == coordsSizeMap.end()) {
1666 coordsSizeMap.insert(std::make_pair(coords,enfVertex->size));
1667 enfVerticesWithGroup.insert(std::make_pair(coords,enfVertex->groupName));
1674 HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = HYBRIDPlugin_Hypothesis::GetEnforcedNodes(_hyp);
1675 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = HYBRIDPlugin_Hypothesis::GetEnforcedEdges(_hyp);
1676 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(_hyp);
1677 HYBRIDPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = HYBRIDPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp);
1681 int nbEnforcedVertices = coordsSizeMap.size();
1682 int nbEnforcedNodes = enforcedNodes.size();
1683 (nbEnforcedNodes <= 1) ? tmpStr = "node" : tmpStr = "nodes";
1684 std::cout << nbEnforcedNodes << " enforced " << tmpStr << " from hypo" << std::endl;
1685 (nbEnforcedVertices <= 1) ? tmpStr = "vertex" : tmpStr = "vertices";
1686 std::cout << nbEnforcedVertices << " enforced " << tmpStr << " from hypo" << std::endl;
1688 std::vector <const SMDS_MeshNode*> aNodeByHybridId, anEnforcedNodeByHybridId;
1689 std::vector <const SMDS_MeshElement*> aFaceByHybridId;
1690 std::map<const SMDS_MeshNode*,int> aNodeToHybridIdMap;
1691 std::vector<std::string> aNodeGroupByHybridId, anEdgeGroupByHybridId, aFaceGroupByHybridId;
1693 SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
1695 MG_HYBRID_API mgHybrid( _computeCanceled, _progress );
1697 Ok = writeGMFFile(&mgHybrid,
1698 aGMFFileName.c_str(),
1699 aRequiredVerticesFileName.c_str(), aSolFileName.c_str(),
1700 *proxyMesh, *theHelper,
1701 aNodeByHybridId, aFaceByHybridId, aNodeToHybridIdMap,
1702 aNodeGroupByHybridId, anEdgeGroupByHybridId, aFaceGroupByHybridId,
1703 enforcedNodes, enforcedEdges, enforcedTriangles,
1704 enfVerticesWithGroup, coordsSizeMap);
1706 // -----------------
1707 // run hybrid mesher
1708 // -----------------
1710 std::string cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp, theMesh );
1712 if ( mgHybrid.IsExecutable() )
1714 cmd += " --in " + aGMFFileName;
1715 cmd += " --out " + aResultFileName;
1717 if ( !_logInStandardOutput )
1719 cmd += " 1> " + aLogFileName; // dump into file
1720 mgHybrid.SetLogFile( aLogFileName );
1722 std::cout << std::endl;
1723 std::cout << "Hybrid execution w/o geometry..." << std::endl;
1724 std::cout << cmd << std::endl;
1726 _computeCanceled = false;
1729 Ok = mgHybrid.Compute( cmd, errStr ); // run
1731 if ( _logInStandardOutput && mgHybrid.IsLibrary() )
1732 std::cout << std::endl << mgHybrid.GetLog() << std::endl;
1734 std::cout << "End of Hybrid execution !" << std::endl;
1739 HYBRIDPlugin_Hypothesis::TSetStrings groupsToRemove = HYBRIDPlugin_Hypothesis::GetGroupsToRemove(_hyp);
1740 const bool toMakeGroupsOfDomains = HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains( _hyp );
1742 Ok = Ok && readGMFFile(&mgHybrid,
1743 aResultFileName.c_str(),
1745 theHelper, aNodeByHybridId, aFaceByHybridId, aNodeToHybridIdMap,
1746 aNodeGroupByHybridId, anEdgeGroupByHybridId, aFaceGroupByHybridId,
1747 groupsToRemove, toMakeGroupsOfDomains);
1749 updateMeshGroups(theHelper->GetMesh(), groupsToRemove);
1750 removeEmptyGroupsOfDomains( theHelper->GetMesh(), !toMakeGroupsOfDomains );
1753 HYBRIDPlugin_Hypothesis* that = (HYBRIDPlugin_Hypothesis*)this->_hyp;
1755 that->ClearGroupsToRemove();
1757 // ---------------------
1758 // remove working files
1759 // ---------------------
1763 if ( _removeLogOnSuccess )
1764 removeFile( aLogFileName );
1766 else if ( mgHybrid.HasLog() )
1768 // get problem description from the log file
1769 _Ghs2smdsConvertor conv( aNodeByHybridId );
1770 storeErrorDescription( _logInStandardOutput ? 0 : aLogFileName.c_str(),
1771 mgHybrid.GetLog(), conv );
1774 // the log file is empty
1775 removeFile( aLogFileName );
1776 INFOS( "HYBRID Error, command '" << cmd << "' failed" );
1777 error(COMPERR_ALGO_FAILED, "hybrid: command not found" );
1782 if (! Ok && _computeCanceled)
1783 removeFile( aLogFileName );
1784 removeFile( aGMFFileName );
1785 removeFile( aResultFileName );
1786 removeFile( aRequiredVerticesFileName );
1787 removeFile( aSolFileName );
1788 removeFile( aResSolFileName );
1793 void HYBRIDPlugin_HYBRID::CancelCompute()
1795 _computeCanceled = true;
1796 #if !defined(WIN32) && !defined(__APPLE__)
1797 std::string cmd = "ps xo pid,args | grep " + _genericName;
1798 //cmd += " | grep -e \"^ *[0-9]\\+ \\+" + HYBRIDPlugin_Hypothesis::GetExeName() + "\"";
1799 cmd += " | awk '{print $1}' | xargs kill -9 > /dev/null 2>&1";
1800 system( cmd.c_str() );
1804 //================================================================================
1806 * \brief Provide human readable text by error code reported by hybrid
1808 //================================================================================
1810 static const char* translateError(const int errNum)
1814 return "error distene 0";
1816 return "error distene 1";
1818 return "unknown distene error";
1821 //================================================================================
1823 * \brief Retrieve from a string given number of integers
1825 //================================================================================
1827 static char* getIds( char* ptr, int nbIds, std::vector<int>& ids )
1830 ids.reserve( nbIds );
1833 while ( !isdigit( *ptr )) ++ptr;
1834 if ( ptr[-1] == '-' ) --ptr;
1835 ids.push_back( strtol( ptr, &ptr, 10 ));
1841 //================================================================================
1843 * \brief Retrieve problem description form a log file
1844 * \retval bool - always false
1846 //================================================================================
1848 bool HYBRIDPlugin_HYBRID::storeErrorDescription(const char* logFile,
1849 const std::string& log,
1850 const _Ghs2smdsConvertor & toSmdsConvertor )
1852 if(_computeCanceled)
1853 return error(SMESH_Comment("interruption initiated by user"));
1855 char* ptr = const_cast<char*>( log.c_str() );
1856 char* buf = ptr, * bufEnd = ptr + log.size();
1858 SMESH_Comment errDescription;
1860 enum { NODE = 1, EDGE, TRIA, VOL, SKIP_ID = 1 };
1862 // look for MeshGems version
1863 // Since "MG-TETRA -- MeshGems 1.1-3 (January, 2013)" error codes change.
1864 // To discriminate old codes from new ones we add 1000000 to the new codes.
1865 // This way value of the new codes is same as absolute value of codes printed
1866 // in the log after "MGMESSAGE" string.
1867 int versionAddition = 0;
1870 while ( ++verPtr < bufEnd )
1872 if ( strncmp( verPtr, "MG-TETRA -- MeshGems ", 21 ) != 0 )
1874 if ( strcmp( verPtr, "MG-TETRA -- MeshGems 1.1-3 " ) >= 0 )
1875 versionAddition = 1000000;
1881 // look for errors "ERR #"
1883 std::set<std::string> foundErrorStr; // to avoid reporting same error several times
1884 std::set<int> elemErrorNums; // not to report different types of errors with bad elements
1885 while ( ++ptr < bufEnd )
1887 if ( strncmp( ptr, "ERR ", 4 ) != 0 )
1890 std::list<const SMDS_MeshElement*> badElems;
1891 std::vector<int> nodeIds;
1895 int errNum = strtol(ptr, &ptr, 10) + versionAddition;
1896 // we treat errors enumerated in [SALOME platform 0019316] issue
1897 // and all errors from a new (Release 1.1) MeshGems User Manual
1899 case 0015: // The face number (numfac) with vertices (f 1, f 2, f 3) has a null vertex.
1900 case 1005620 : // a too bad quality face is detected. This face is considered degenerated.
1901 ptr = getIds(ptr, SKIP_ID, nodeIds);
1902 ptr = getIds(ptr, TRIA, nodeIds);
1903 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1905 case 1005621 : // a too bad quality face is detected. This face is degenerated.
1906 // hence the is degenerated it is invisible, add its edges in addition
1907 ptr = getIds(ptr, SKIP_ID, nodeIds);
1908 ptr = getIds(ptr, TRIA, nodeIds);
1909 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1911 std::vector<int> edgeNodes( nodeIds.begin(), --nodeIds.end() ); // 01
1912 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
1913 edgeNodes[1] = nodeIds[2]; // 02
1914 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
1915 edgeNodes[0] = nodeIds[1]; // 12
1918 case 1000: // Face (f 1, f 2, f 3) appears more than once in the input surface mesh.
1920 case 1002: // Face (f 1, f 2, f 3) has a vertex negative or null
1921 case 3019: // Constrained face (f 1, f 2, f 3) cannot be enforced
1922 case 1002211: // a face has a vertex negative or null.
1923 case 1005200 : // a surface mesh appears more than once in the input surface mesh.
1924 case 1008423 : // a constrained face cannot be enforced (regeneration phase failed).
1925 ptr = getIds(ptr, TRIA, nodeIds);
1926 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1928 case 1001: // Edge (e1, e2) appears more than once in the input surface mesh
1929 case 3009: // Constrained edge (e1, e2) cannot be enforced (warning).
1930 // ERR 3109 : EDGE 5 6 UNIQUE
1931 case 3109: // Edge (e1, e2) is unique (i.e., bounds a hole in the surface)
1932 case 1005210 : // an edge appears more than once in the input surface mesh.
1933 case 1005820 : // an edge is unique (i.e., bounds a hole in the surface).
1934 case 1008441 : // a constrained edge cannot be enforced.
1935 ptr = getIds(ptr, EDGE, nodeIds);
1936 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1938 case 2004: // Vertex v1 and vertex v2 are too close to one another or coincident (warning).
1939 case 2014: // at least two points whose distance is dist, i.e., considered as coincident
1940 case 2103: // Vertex v1 and vertex v2 are too close to one another or coincident (warning).
1941 // ERR 2103 : 16 WITH 3
1942 case 1005105 : // two vertices are too close to one another or coincident.
1943 case 1005107: // Two vertices are too close to one another or coincident.
1944 ptr = getIds(ptr, NODE, nodeIds);
1945 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1946 ptr = getIds(ptr, NODE, nodeIds);
1947 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1949 case 2012: // Vertex v1 cannot be inserted (warning).
1950 case 1005106 : // a vertex cannot be inserted.
1951 ptr = getIds(ptr, NODE, nodeIds);
1952 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1954 case 3103: // The surface edge (e1, e2) intersects another surface edge (e3, e4)
1955 case 1005110 : // two surface edges are intersecting.
1956 // ERR 3103 : 1 2 WITH 7 3
1957 ptr = getIds(ptr, EDGE, nodeIds);
1958 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1959 ptr = getIds(ptr, EDGE, nodeIds);
1960 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1962 case 3104: // The surface edge (e1, e2) intersects the surface face (f 1, f 2, f 3)
1963 // ERR 3104 : 9 10 WITH 1 2 3
1964 case 3106: // One surface edge (say e1, e2) intersects a surface face (f 1, f 2, f 3)
1965 case 1005120 : // a surface edge intersects a surface face.
1966 ptr = getIds(ptr, EDGE, nodeIds);
1967 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1968 ptr = getIds(ptr, TRIA, nodeIds);
1969 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1971 case 3105: // One boundary point (say p1) lies within a surface face (f 1, f 2, f 3)
1972 // ERR 3105 : 8 IN 2 3 5
1973 case 1005150 : // a boundary point lies within a surface face.
1974 ptr = getIds(ptr, NODE, nodeIds);
1975 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1976 ptr = getIds(ptr, TRIA, nodeIds);
1977 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1979 case 3107: // One boundary point (say p1) lies within a surface edge (e1, e2) (stop).
1980 // ERR 3107 : 2 IN 4 1
1981 case 1005160 : // a boundary point lies within a surface edge.
1982 ptr = getIds(ptr, NODE, nodeIds);
1983 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1984 ptr = getIds(ptr, EDGE, nodeIds);
1985 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1987 case 9000: // ERR 9000
1988 // ELEMENT 261 WITH VERTICES : 7 396 -8 242
1989 // VOLUME : -1.11325045E+11 W.R.T. EPSILON 0.
1990 // A too small volume element is detected. Are reported the index of the element,
1991 // its four vertex indices, its volume and the tolerance threshold value
1992 ptr = getIds(ptr, SKIP_ID, nodeIds);
1993 ptr = getIds(ptr, VOL, nodeIds);
1994 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
1995 // even if all nodes found, volume it most probably invisible,
1996 // add its faces to demonstrate it anyhow
1998 std::vector<int> faceNodes( nodeIds.begin(), --nodeIds.end() ); // 012
1999 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
2000 faceNodes[2] = nodeIds[3]; // 013
2001 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
2002 faceNodes[1] = nodeIds[2]; // 023
2003 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
2004 faceNodes[0] = nodeIds[1]; // 123
2005 badElems.push_back( toSmdsConvertor.getElement(faceNodes));
2008 case 9001: // ERR 9001
2009 // %% NUMBER OF NEGATIVE VOLUME TETS : 1
2010 // %% THE LARGEST NEGATIVE TET : 1.75376581E+11
2011 // %% NUMBER OF NULL VOLUME TETS : 0
2012 // There exists at least a null or negative volume element
2015 // There exist n null or negative volume elements
2018 // A too small volume element is detected
2021 // A too bad quality face is detected. This face is considered degenerated,
2022 // its index, its three vertex indices together with its quality value are reported
2023 break; // same as next
2024 case 9112: // ERR 9112
2025 // FACE 2 WITH VERTICES : 4 2 5
2026 // SMALL INRADIUS : 0.
2027 // A too bad quality face is detected. This face is degenerated,
2028 // its index, its three vertex indices together with its inradius are reported
2029 ptr = getIds(ptr, SKIP_ID, nodeIds);
2030 ptr = getIds(ptr, TRIA, nodeIds);
2031 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
2032 // add triangle edges as it most probably has zero area and hence invisible
2034 std::vector<int> edgeNodes(2);
2035 edgeNodes[0] = nodeIds[0]; edgeNodes[1] = nodeIds[1]; // 0-1
2036 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
2037 edgeNodes[1] = nodeIds[2]; // 0-2
2038 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
2039 edgeNodes[0] = nodeIds[1]; // 1-2
2040 badElems.push_back( toSmdsConvertor.getElement(edgeNodes));
2043 case 1005103 : // the vertices of an element are too close to one another or coincident.
2044 ptr = getIds(ptr, TRIA, nodeIds);
2045 if ( nodeIds.back() == 0 ) // index of the third vertex of the element (0 for an edge)
2046 nodeIds.resize( EDGE );
2047 badElems.push_back( toSmdsConvertor.getElement(nodeIds));
2051 bool isNewError = foundErrorStr.insert( std::string( errBeg, ptr )).second;
2053 continue; // not to report same error several times
2055 // const SMDS_MeshElement* nullElem = 0;
2056 // bool allElemsOk = ( find( badElems.begin(), badElems.end(), nullElem) == badElems.end());
2058 // if ( allElemsOk && !badElems.empty() && !elemErrorNums.empty() ) {
2059 // bool oneMoreErrorType = elemErrorNums.insert( errNum ).second;
2060 // if ( oneMoreErrorType )
2061 // continue; // not to report different types of errors with bad elements
2064 // store bad elements
2065 //if ( allElemsOk ) {
2066 std::list<const SMDS_MeshElement*>::iterator elem = badElems.begin();
2067 for ( ; elem != badElems.end(); ++elem )
2068 addBadInputElement( *elem );
2072 std::string text = translateError( errNum );
2073 if ( errDescription.find( text ) == text.npos ) {
2074 if ( !errDescription.empty() )
2075 errDescription << "\n";
2076 errDescription << text;
2081 if ( errDescription.empty() ) { // no errors found
2082 char msgLic1[] = "connection to server failed";
2083 char msgLic2[] = " Dlim ";
2084 if ( std::search( &buf[0], bufEnd, msgLic1, msgLic1 + strlen(msgLic1)) != bufEnd ||
2085 std::search( &buf[0], bufEnd, msgLic2, msgLic2 + strlen(msgLic2)) != bufEnd )
2086 errDescription << "Licence problems.";
2089 char msg2[] = "SEGMENTATION FAULT";
2090 if ( std::search( &buf[0], bufEnd, msg2, msg2 + strlen(msg2)) != bufEnd )
2091 errDescription << "hybrid: SEGMENTATION FAULT. ";
2095 if ( logFile && logFile[0] )
2097 if ( errDescription.empty() )
2098 errDescription << "See " << logFile << " for problem description";
2100 errDescription << "\nSee " << logFile << " for more information";
2102 return error( errDescription );
2105 //================================================================================
2107 * \brief Creates _Ghs2smdsConvertor
2109 //================================================================================
2111 _Ghs2smdsConvertor::_Ghs2smdsConvertor( const std::map <int,const SMDS_MeshNode*> & ghs2NodeMap)
2112 :_ghs2NodeMap( & ghs2NodeMap ), _nodeByGhsId( 0 )
2116 //================================================================================
2118 * \brief Creates _Ghs2smdsConvertor
2120 //================================================================================
2122 _Ghs2smdsConvertor::_Ghs2smdsConvertor( const std::vector <const SMDS_MeshNode*> & nodeByGhsId)
2123 : _ghs2NodeMap( 0 ), _nodeByGhsId( &nodeByGhsId )
2127 //================================================================================
2129 * \brief Return SMDS element by ids of HYBRID nodes
2131 //================================================================================
2133 const SMDS_MeshElement* _Ghs2smdsConvertor::getElement(const std::vector<int>& ghsNodes) const
2135 size_t nbNodes = ghsNodes.size();
2136 std::vector<const SMDS_MeshNode*> nodes( nbNodes, 0 );
2137 for ( size_t i = 0; i < nbNodes; ++i ) {
2138 int ghsNode = ghsNodes[ i ];
2139 if ( _ghs2NodeMap ) {
2140 std::map <int,const SMDS_MeshNode*>::const_iterator in = _ghs2NodeMap->find( ghsNode);
2141 if ( in == _ghs2NodeMap->end() )
2143 nodes[ i ] = in->second;
2146 if ( ghsNode < 1 || ghsNode > (int)_nodeByGhsId->size() )
2148 nodes[ i ] = (*_nodeByGhsId)[ ghsNode-1 ];
2154 if ( nbNodes == 2 ) {
2155 const SMDS_MeshElement* edge= SMDS_Mesh::FindEdge( nodes[0], nodes[1] );
2157 edge = new SMDS_LinearEdge( nodes[0], nodes[1] );
2160 if ( nbNodes == 3 ) {
2161 const SMDS_MeshElement* face = SMDS_Mesh::FindFace( nodes );
2163 face = new SMDS_FaceOfNodes( nodes[0], nodes[1], nodes[2] );
2167 return new SMDS_VolumeOfNodes( nodes[0], nodes[1], nodes[2], nodes[3] );
2173 //=============================================================================
2177 //=============================================================================
2178 bool HYBRIDPlugin_HYBRID::Evaluate(SMESH_Mesh& aMesh,
2179 const TopoDS_Shape& aShape,
2180 MapShapeNbElems& aResMap)
2182 int nbtri = 0, nbqua = 0;
2183 double fullArea = 0.0;
2184 for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
2185 TopoDS_Face F = TopoDS::Face( exp.Current() );
2186 SMESH_subMesh *sm = aMesh.GetSubMesh(F);
2187 MapShapeNbElemsItr anIt = aResMap.find(sm);
2188 if( anIt==aResMap.end() ) {
2189 SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
2190 smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,
2191 "Submesh can not be evaluated",this));
2194 std::vector<int> aVec = (*anIt).second;
2195 nbtri += Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
2196 nbqua += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
2198 BRepGProp::SurfaceProperties(F,G);
2199 double anArea = G.Mass();
2203 // collect info from edges
2204 int nb0d_e = 0, nb1d_e = 0;
2205 bool IsQuadratic = false;
2206 bool IsFirst = true;
2207 TopTools_MapOfShape tmpMap;
2208 for (TopExp_Explorer exp(aShape, TopAbs_EDGE); exp.More(); exp.Next()) {
2209 TopoDS_Edge E = TopoDS::Edge(exp.Current());
2210 if( tmpMap.Contains(E) )
2213 SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
2214 MapShapeNbElemsItr anIt = aResMap.find(aSubMesh);
2215 std::vector<int> aVec = (*anIt).second;
2216 nb0d_e += aVec[SMDSEntity_Node];
2217 nb1d_e += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
2219 IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
2225 double ELen = sqrt(2.* ( fullArea/(nbtri+nbqua*2) ) / sqrt(3.0) );
2228 BRepGProp::VolumeProperties(aShape,G);
2229 double aVolume = G.Mass();
2230 double tetrVol = 0.1179*ELen*ELen*ELen;
2231 double CoeffQuality = 0.9;
2232 int nbVols = int(aVolume/tetrVol/CoeffQuality);
2233 int nb1d_f = (nbtri*3 + nbqua*4 - nb1d_e) / 2;
2234 int nb1d_in = (int) ( nbVols*6 - nb1d_e - nb1d_f ) / 5;
2235 std::vector<int> aVec(SMDSEntity_Last);
2236 for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i]=0;
2238 aVec[SMDSEntity_Node] = nb1d_in/6 + 1 + nb1d_in;
2239 aVec[SMDSEntity_Quad_Tetra] = nbVols - nbqua*2;
2240 aVec[SMDSEntity_Quad_Pyramid] = nbqua;
2243 aVec[SMDSEntity_Node] = nb1d_in/6 + 1;
2244 aVec[SMDSEntity_Tetra] = nbVols - nbqua*2;
2245 aVec[SMDSEntity_Pyramid] = nbqua;
2247 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
2248 aResMap.insert(std::make_pair(sm,aVec));
2253 bool HYBRIDPlugin_HYBRID::importGMFMesh(const char* theGMFFileName, SMESH_Mesh& theMesh)
2255 SMESH_ComputeErrorPtr err = theMesh.GMFToMesh( theGMFFileName, /*makeRequiredGroups =*/ true );
2257 theMesh.GetMeshDS()->Modified();
2259 return ( !err || err->IsOK());
2264 //================================================================================
2266 * \brief Sub-mesh event listener setting enforced elements as soon as an enforced
2269 struct _EnforcedMeshRestorer : public SMESH_subMeshEventListener
2271 _EnforcedMeshRestorer():
2272 SMESH_subMeshEventListener( /*isDeletable = */true, Name() )
2275 //================================================================================
2277 * \brief Returns an ID of listener
2279 static const char* Name() { return "HYBRIDPlugin_HYBRID::_EnforcedMeshRestorer"; }
2281 //================================================================================
2283 * \brief Treat events of the subMesh
2285 void ProcessEvent(const int event,
2286 const int eventType,
2287 SMESH_subMesh* subMesh,
2288 SMESH_subMeshEventListenerData* data,
2289 const SMESH_Hypothesis* hyp)
2291 if ( SMESH_subMesh::SUBMESH_LOADED == event &&
2292 SMESH_subMesh::COMPUTE_EVENT == eventType &&
2294 !data->mySubMeshes.empty() )
2296 // An enforced mesh (subMesh->_father) has been loaded from hdf file
2297 if ( HYBRIDPlugin_Hypothesis* hyp = GetGHSHypothesis( data->mySubMeshes.front() ))
2298 hyp->RestoreEnfElemsByMeshes();
2301 //================================================================================
2303 * \brief Returns HYBRIDPlugin_Hypothesis used to compute a subMesh
2305 static HYBRIDPlugin_Hypothesis* GetGHSHypothesis( SMESH_subMesh* subMesh )
2307 SMESH_HypoFilter ghsHypFilter( SMESH_HypoFilter::HasName( "HYBRID_Parameters" ));
2308 return (HYBRIDPlugin_Hypothesis* )
2309 subMesh->GetFather()->GetHypothesis( subMesh->GetSubShape(),
2311 /*visitAncestors=*/true);
2315 //================================================================================
2317 * \brief Sub-mesh event listener removing empty groups created due to "To make
2318 * groups of domains".
2320 struct _GroupsOfDomainsRemover : public SMESH_subMeshEventListener
2322 _GroupsOfDomainsRemover():
2323 SMESH_subMeshEventListener( /*isDeletable = */true,
2324 "HYBRIDPlugin_HYBRID::_GroupsOfDomainsRemover" ) {}
2326 * \brief Treat events of the subMesh
2328 void ProcessEvent(const int event,
2329 const int eventType,
2330 SMESH_subMesh* subMesh,
2331 SMESH_subMeshEventListenerData* data,
2332 const SMESH_Hypothesis* hyp)
2334 if (SMESH_subMesh::ALGO_EVENT == eventType &&
2335 !subMesh->GetAlgo() )
2337 removeEmptyGroupsOfDomains( subMesh->GetFather(), /*notEmptyAsWell=*/true );
2343 //================================================================================
2345 * \brief Set an event listener to set enforced elements as soon as an enforced
2348 //================================================================================
2350 void HYBRIDPlugin_HYBRID::SubmeshRestored(SMESH_subMesh* subMesh)
2352 if ( HYBRIDPlugin_Hypothesis* hyp = _EnforcedMeshRestorer::GetGHSHypothesis( subMesh ))
2354 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedMeshList enfMeshes = hyp->_GetEnforcedMeshes();
2355 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedMeshList::iterator it = enfMeshes.begin();
2356 for(;it != enfMeshes.end();++it) {
2357 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedMesh* enfMesh = *it;
2358 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
2360 SMESH_subMesh* smToListen = mesh->GetSubMesh( mesh->GetShapeToMesh() );
2361 // a listener set to smToListen will care of hypothesis stored in SMESH_EventListenerData
2362 subMesh->SetEventListener( new _EnforcedMeshRestorer(),
2363 SMESH_subMeshEventListenerData::MakeData( subMesh ),
2370 //================================================================================
2372 * \brief Sets an event listener removing empty groups created due to "To make
2373 * groups of domains".
2374 * \param subMesh - submesh where algo is set
2376 * This method is called when a submesh gets HYP_OK algo_state.
2377 * After being set, event listener is notified on each event of a submesh.
2379 //================================================================================
2381 void HYBRIDPlugin_HYBRID::SetEventListener(SMESH_subMesh* subMesh)
2383 subMesh->SetEventListener( new _GroupsOfDomainsRemover(), 0, subMesh );