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
20 //=============================================================================
21 // File : HYBRIDPlugin_Hypothesis.cxx
22 // Created : Wed Apr 2 12:36:29 2008
23 // Author : Edward AGAPOV (eap)
24 //=============================================================================
26 #include "HYBRIDPlugin_Hypothesis.hxx"
28 #include <SMESHDS_Mesh.hxx>
30 #include <TopExp_Explorer.hxx>
34 #define getpid _getpid
37 //=======================================================================
38 //function : HYBRIDPlugin_Hypothesis
39 //=======================================================================
41 HYBRIDPlugin_Hypothesis::HYBRIDPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen)
42 : SMESH_Hypothesis(hypId, studyId, gen),
43 myToMeshHoles(DefaultMeshHoles()),
44 myLayersOnAllWrap(DefaultLayersOnAllWrap()),
45 myToMakeGroupsOfDomains(DefaultToMakeGroupsOfDomains()),
48 myOptimizationLevel(DefaultOptimizationLevel()),
49 myCollisionMode(DefaultCollisionMode()),
50 myBoundaryLayersGrowth(DefaultBoundaryLayersGrowth()),
51 myElementGeneration(DefaultElementGeneration()),
52 myKeepFiles(DefaultKeepFiles()),
53 myWorkingDirectory(DefaultWorkingDirectory()),
54 myVerboseLevel(DefaultVerboseLevel()),
55 myToCreateNewNodes(DefaultToCreateNewNodes()),
56 myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()),
57 myToUseFemCorrection(DefaultToUseFEMCorrection()),
58 myToRemoveCentralPoint(DefaultToRemoveCentralPoint()),
59 myLogInStandardOutput(DefaultStandardOutputLog()),
60 myGradation(DefaultGradation()),
61 myAddMultinormals(DefaultAddMultinormals()),
62 mySmoothNormals(DefaultSmoothNormals()),
63 myHeightFirstLayer(DefaultHeightFirstLayer()),
64 myBoundaryLayersProgression(DefaultBoundaryLayersProgression()),
65 myMultinormalsAngle(DefaultMultinormalsAngle()),
66 myNbOfBoundaryLayers(DefaultNbOfBoundaryLayers()),
67 _enfVertexList(DefaultHYBRIDEnforcedVertexList()),
68 _enfVertexCoordsSizeList(DefaultHYBRIDEnforcedVertexCoordsValues()),
69 _enfVertexEntrySizeList(DefaultHYBRIDEnforcedVertexEntryValues()),
70 _coordsEnfVertexMap(DefaultCoordsHYBRIDEnforcedVertexMap()),
71 _geomEntryEnfVertexMap(DefaultGeomEntryHYBRIDEnforcedVertexMap()),
72 _enfMeshList(DefaultHYBRIDEnforcedMeshList()),
73 _entryEnfMeshMap(DefaultEntryHYBRIDEnforcedMeshListMap()),
74 _enfNodes(TIDSortedNodeGroupMap()),
75 _enfEdges(TIDSortedElemGroupMap()),
76 _enfTriangles(TIDSortedElemGroupMap()),
77 _nodeIDToSizeMap(DefaultID2SizeMap()),
78 _groupsToRemove(DefaultGroupsToRemove())
80 _name = "HYBRID_Parameters";
84 //=======================================================================
85 //function : SetLayersOnAllWrap
86 //=======================================================================
88 void HYBRIDPlugin_Hypothesis::SetLayersOnAllWrap(bool toMesh)
90 if ( myLayersOnAllWrap != toMesh ) {
91 myLayersOnAllWrap = toMesh;
92 NotifySubMeshesHypothesisModification();
96 //=======================================================================
97 //function : GetLayersOnAllWrap
98 //=======================================================================
100 bool HYBRIDPlugin_Hypothesis::GetLayersOnAllWrap(bool checkFreeOption) const
102 return myLayersOnAllWrap;
105 //=======================================================================
106 //function : SetFacesWithLayers
107 //purpose : Set IDs of faces to grow the layers on
108 //=======================================================================
110 bool HYBRIDPlugin_Hypothesis::SetFacesWithLayers(const std::vector<int>& theVal)
112 if ( myFacesWithLayers != theVal )
114 myFacesWithLayers = theVal;
115 NotifySubMeshesHypothesisModification();
121 //=======================================================================
122 //function : GetFacesWithLayers
123 //purpose : Return IDs of faces to grow the layers on
124 //=======================================================================
126 const std::vector<int>& HYBRIDPlugin_Hypothesis::GetFacesWithLayers() const
128 return myFacesWithLayers;
131 //=======================================================================
132 //function : SetToMeshHoles
133 //=======================================================================
135 void HYBRIDPlugin_Hypothesis::SetToMeshHoles(bool toMesh)
137 if ( myToMeshHoles != toMesh ) {
138 myToMeshHoles = toMesh;
139 NotifySubMeshesHypothesisModification();
143 //=======================================================================
144 //function : GetToMeshHoles
145 //=======================================================================
147 bool HYBRIDPlugin_Hypothesis::GetToMeshHoles(bool checkFreeOption) const
149 if (checkFreeOption && !myTextOption.empty()) {
150 if ( myTextOption.find("-c 0"))
152 if ( myTextOption.find("-c 1"))
155 return myToMeshHoles;
158 //=======================================================================
159 //function : SetToMakeGroupsOfDomains
160 //=======================================================================
162 void HYBRIDPlugin_Hypothesis::SetToMakeGroupsOfDomains(bool toMakeGroups)
164 if ( myToMakeGroupsOfDomains != toMakeGroups ) {
165 myToMakeGroupsOfDomains = toMakeGroups;
166 NotifySubMeshesHypothesisModification();
170 //=======================================================================
171 //function : GetToMakeGroupsOfDomains
172 //=======================================================================
174 bool HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains() const
176 return myToMakeGroupsOfDomains;
179 //=======================================================================
180 //function : GetToMakeGroupsOfDomains
181 //=======================================================================
183 bool HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains(const HYBRIDPlugin_Hypothesis* hyp)
186 if ( hyp ) res = /*hyp->GetToMeshHoles(true) &&*/ hyp->GetToMakeGroupsOfDomains();
187 else res = /*DefaultMeshHoles() &&*/ DefaultToMakeGroupsOfDomains();
191 //=======================================================================
192 //function : SetMaximumMemory
193 //=======================================================================
195 void HYBRIDPlugin_Hypothesis::SetMaximumMemory(double MB)
197 if ( myMaximumMemory != MB ) {
198 myMaximumMemory = MB;
199 NotifySubMeshesHypothesisModification();
203 //=======================================================================
204 //function : GetMaximumMemory
205 // * automatic memory adjustment mode. Default is zero
206 //=======================================================================
208 double HYBRIDPlugin_Hypothesis::GetMaximumMemory() const
210 return myMaximumMemory;
213 //=======================================================================
214 //function : SetInitialMemory
215 //=======================================================================
217 void HYBRIDPlugin_Hypothesis::SetInitialMemory(double MB)
219 if ( myInitialMemory != MB ) {
220 myInitialMemory = MB;
221 NotifySubMeshesHypothesisModification();
225 //=======================================================================
226 //function : GetInitialMemory
227 //=======================================================================
229 double HYBRIDPlugin_Hypothesis::GetInitialMemory() const
231 return myInitialMemory;
234 //=======================================================================
235 //function : SetOptimizationLevel
236 //=======================================================================
238 void HYBRIDPlugin_Hypothesis::SetOptimizationLevel(OptimizationLevel level)
240 if ( myOptimizationLevel != level ) {
241 myOptimizationLevel = level;
242 NotifySubMeshesHypothesisModification();
246 //=======================================================================
247 //function : GetOptimizationLevel
248 //=======================================================================
249 HYBRIDPlugin_Hypothesis::OptimizationLevel HYBRIDPlugin_Hypothesis::GetOptimizationLevel() const
251 return (OptimizationLevel) myOptimizationLevel;
254 //=======================================================================
255 //function : SetCollisionMode
256 //=======================================================================
257 void HYBRIDPlugin_Hypothesis::SetCollisionMode(CollisionMode mode)
259 if ( myCollisionMode != mode ) {
260 myCollisionMode = mode;
261 NotifySubMeshesHypothesisModification();
265 //=======================================================================
266 //function : GetCollisionMode
267 //=======================================================================
268 HYBRIDPlugin_Hypothesis::CollisionMode HYBRIDPlugin_Hypothesis::GetCollisionMode() const
270 return (CollisionMode) myCollisionMode;
273 //=======================================================================
274 //function : SetBoundaryLayersGrowth
275 //=======================================================================
276 void HYBRIDPlugin_Hypothesis::SetBoundaryLayersGrowth(BoundaryLayersGrowth mode)
278 if ( myBoundaryLayersGrowth != mode ) {
279 myBoundaryLayersGrowth = mode;
280 NotifySubMeshesHypothesisModification();
284 //=======================================================================
285 //function : GetBoundaryLayersGrowth
286 //=======================================================================
287 HYBRIDPlugin_Hypothesis::BoundaryLayersGrowth HYBRIDPlugin_Hypothesis::GetBoundaryLayersGrowth() const
289 return (BoundaryLayersGrowth) myBoundaryLayersGrowth;
292 //=======================================================================
293 //function : SetElementGeneration
294 //=======================================================================
295 void HYBRIDPlugin_Hypothesis::SetElementGeneration(ElementGeneration mode)
297 if ( myElementGeneration != mode ) {
298 myElementGeneration = mode;
299 NotifySubMeshesHypothesisModification();
303 //=======================================================================
304 //function : GetElementGeneration
305 //=======================================================================
306 HYBRIDPlugin_Hypothesis::ElementGeneration HYBRIDPlugin_Hypothesis::GetElementGeneration() const
308 return (ElementGeneration) myElementGeneration;
311 //=======================================================================
312 //function : SetAddMultinormals
313 //=======================================================================
314 void HYBRIDPlugin_Hypothesis::SetAddMultinormals(bool toAddMultinormals)
316 if ( myAddMultinormals != toAddMultinormals ) {
317 myAddMultinormals = toAddMultinormals;
318 NotifySubMeshesHypothesisModification();
322 //=======================================================================
323 //function : GetAddMultinormals
324 //=======================================================================
326 bool HYBRIDPlugin_Hypothesis::GetAddMultinormals() const
328 return myAddMultinormals;
331 //=======================================================================
332 //function : SetSmoothNormals
333 //=======================================================================
335 void HYBRIDPlugin_Hypothesis::SetSmoothNormals(bool toSmoothNormals)
337 if ( mySmoothNormals != toSmoothNormals ) {
338 mySmoothNormals = toSmoothNormals;
339 NotifySubMeshesHypothesisModification();
343 //=======================================================================
344 //function : GetSmoothNormals
345 //=======================================================================
347 bool HYBRIDPlugin_Hypothesis::GetSmoothNormals() const
349 return mySmoothNormals;
352 //=======================================================================
353 //function : SetHeightFirstLayer
354 //=======================================================================
356 void HYBRIDPlugin_Hypothesis::SetHeightFirstLayer(double toHeightFirstLayer)
358 if ( myHeightFirstLayer != toHeightFirstLayer ) {
359 myHeightFirstLayer = toHeightFirstLayer;
360 NotifySubMeshesHypothesisModification();
364 //=======================================================================
365 //function : GetHeightFirstLayer
366 //=======================================================================
368 double HYBRIDPlugin_Hypothesis::GetHeightFirstLayer() const
370 return myHeightFirstLayer;
373 //=======================================================================
374 //function : SetBoundaryLayersProgression
375 //=======================================================================
377 void HYBRIDPlugin_Hypothesis::SetBoundaryLayersProgression(double toBoundaryLayersProgression)
379 if ( myBoundaryLayersProgression != toBoundaryLayersProgression ) {
380 myBoundaryLayersProgression = toBoundaryLayersProgression;
381 NotifySubMeshesHypothesisModification();
385 //=======================================================================
386 //function : GetBoundaryLayersProgression
387 //=======================================================================
389 double HYBRIDPlugin_Hypothesis::GetBoundaryLayersProgression() const
391 return myBoundaryLayersProgression;
394 //=======================================================================
395 //function : SetMultinormalsAngle
396 //=======================================================================
398 void HYBRIDPlugin_Hypothesis::SetMultinormalsAngle(double toMultinormalsAngle)
400 if ( myMultinormalsAngle != toMultinormalsAngle ) {
401 myMultinormalsAngle = toMultinormalsAngle;
402 NotifySubMeshesHypothesisModification();
406 //=======================================================================
407 //function : GetMultinormalsAngle
408 //=======================================================================
410 double HYBRIDPlugin_Hypothesis::GetMultinormalsAngle() const
412 return myMultinormalsAngle;
415 //=======================================================================
416 //function : SetNbOfBoundaryLayers
417 //=======================================================================
419 void HYBRIDPlugin_Hypothesis::SetNbOfBoundaryLayers(short toNbOfBoundaryLayers)
421 if ( myNbOfBoundaryLayers != toNbOfBoundaryLayers ) {
422 myNbOfBoundaryLayers = toNbOfBoundaryLayers;
423 NotifySubMeshesHypothesisModification();
427 //=======================================================================
428 //function : GetMultinormalsAngle
429 //=======================================================================
431 short HYBRIDPlugin_Hypothesis::GetNbOfBoundaryLayers() const
433 return myNbOfBoundaryLayers;
437 /////////////////////////////////////////////////////////////////////////
440 //=======================================================================
441 //function : SetWorkingDirectory
442 //=======================================================================
444 void HYBRIDPlugin_Hypothesis::SetWorkingDirectory(const std::string& path)
446 if ( myWorkingDirectory != path ) {
447 myWorkingDirectory = path;
448 NotifySubMeshesHypothesisModification();
452 //=======================================================================
453 //function : GetWorkingDirectory
454 //=======================================================================
456 std::string HYBRIDPlugin_Hypothesis::GetWorkingDirectory() const
458 return myWorkingDirectory;
461 //=======================================================================
462 //function : SetKeepFiles
463 //=======================================================================
465 void HYBRIDPlugin_Hypothesis::SetKeepFiles(bool toKeep)
467 if ( myKeepFiles != toKeep ) {
468 myKeepFiles = toKeep;
469 NotifySubMeshesHypothesisModification();
473 //=======================================================================
474 //function : GetKeepFiles
475 //=======================================================================
477 bool HYBRIDPlugin_Hypothesis::GetKeepFiles() const
482 //=======================================================================
483 //function : SetVerboseLevel
484 //=======================================================================
486 void HYBRIDPlugin_Hypothesis::SetVerboseLevel(short level)
488 if ( myVerboseLevel != level ) {
489 myVerboseLevel = level;
490 NotifySubMeshesHypothesisModification();
494 //=======================================================================
495 //function : GetVerboseLevel
496 //=======================================================================
498 short HYBRIDPlugin_Hypothesis::GetVerboseLevel() const
500 return myVerboseLevel;
503 //=======================================================================
504 //function : SetToCreateNewNodes
505 //=======================================================================
507 void HYBRIDPlugin_Hypothesis::SetToCreateNewNodes(bool toCreate)
509 if ( myToCreateNewNodes != toCreate ) {
510 myToCreateNewNodes = toCreate;
511 NotifySubMeshesHypothesisModification();
515 //=======================================================================
516 //function : GetToCreateNewNodes
517 //=======================================================================
519 bool HYBRIDPlugin_Hypothesis::GetToCreateNewNodes() const
521 return myToCreateNewNodes;
524 //=======================================================================
525 //function : SetToUseBoundaryRecoveryVersion
526 //=======================================================================
528 void HYBRIDPlugin_Hypothesis::SetToUseBoundaryRecoveryVersion(bool toUse)
530 if ( myToUseBoundaryRecoveryVersion != toUse ) {
531 myToUseBoundaryRecoveryVersion = toUse;
532 NotifySubMeshesHypothesisModification();
536 //=======================================================================
537 //function : GetToUseBoundaryRecoveryVersion
538 //=======================================================================
540 bool HYBRIDPlugin_Hypothesis::GetToUseBoundaryRecoveryVersion() const
542 return myToUseBoundaryRecoveryVersion;
545 //=======================================================================
546 //function : SetFEMCorrection
547 //=======================================================================
549 void HYBRIDPlugin_Hypothesis::SetFEMCorrection(bool toUseFem)
551 if ( myToUseFemCorrection != toUseFem ) {
552 myToUseFemCorrection = toUseFem;
553 NotifySubMeshesHypothesisModification();
557 //=======================================================================
558 //function : GetFEMCorrection
559 //=======================================================================
561 bool HYBRIDPlugin_Hypothesis::GetFEMCorrection() const
563 return myToUseFemCorrection;
566 //=======================================================================
567 //function : SetToRemoveCentralPoint
568 //=======================================================================
570 void HYBRIDPlugin_Hypothesis::SetToRemoveCentralPoint(bool toRemove)
572 if ( myToRemoveCentralPoint != toRemove ) {
573 myToRemoveCentralPoint = toRemove;
574 NotifySubMeshesHypothesisModification();
578 //=======================================================================
579 //function : GetToRemoveCentralPoint
580 //=======================================================================
582 bool HYBRIDPlugin_Hypothesis::GetToRemoveCentralPoint() const
584 return myToRemoveCentralPoint;
587 //=======================================================================
588 //function : SetAdvancedOption
589 //=======================================================================
591 void HYBRIDPlugin_Hypothesis::SetAdvancedOption(const std::string& option)
593 if ( myTextOption != option ) {
594 myTextOption = option;
595 NotifySubMeshesHypothesisModification();
599 //=======================================================================
600 //function : GetAdvancedOption
601 //=======================================================================
603 std::string HYBRIDPlugin_Hypothesis::GetAdvancedOption() const
608 //=======================================================================
609 //function : SetGradation
610 //=======================================================================
612 void HYBRIDPlugin_Hypothesis::SetGradation(double gradation)
614 if ( myGradation != gradation ) {
615 myGradation = gradation;
616 NotifySubMeshesHypothesisModification();
620 //=======================================================================
621 //function : GetGradation
622 //=======================================================================
624 double HYBRIDPlugin_Hypothesis::GetGradation() const
629 //=======================================================================
630 //function : SetStandardOutputLog
631 //=======================================================================
633 void HYBRIDPlugin_Hypothesis::SetStandardOutputLog(bool logInStandardOutput)
635 if ( myLogInStandardOutput != logInStandardOutput ) {
636 myLogInStandardOutput = logInStandardOutput;
637 NotifySubMeshesHypothesisModification();
641 //=======================================================================
642 //function : GetStandardOutputLog
643 //=======================================================================
645 bool HYBRIDPlugin_Hypothesis::GetStandardOutputLog() const
647 return myLogInStandardOutput;
650 //=======================================================================
651 //function : SetRemoveLogOnSuccess
652 //=======================================================================
654 void HYBRIDPlugin_Hypothesis::SetRemoveLogOnSuccess(bool removeLogOnSuccess)
656 if ( myRemoveLogOnSuccess != removeLogOnSuccess ) {
657 myRemoveLogOnSuccess = removeLogOnSuccess;
658 NotifySubMeshesHypothesisModification();
662 //=======================================================================
663 //function : GetRemoveLogOnSuccess
664 //=======================================================================
666 bool HYBRIDPlugin_Hypothesis::GetRemoveLogOnSuccess() const
668 return myRemoveLogOnSuccess;
671 //=======================================================================
672 //function : SetEnforcedVertex
673 //=======================================================================
675 bool HYBRIDPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string theEntry, std::string theGroupName,
676 double size, double x, double y, double z, bool isCompound)
678 bool toNotify = false;
679 bool toCreate = true;
681 THYBRIDEnforcedVertex *oldEnVertex;
682 THYBRIDEnforcedVertex *newEnfVertex = new THYBRIDEnforcedVertex();
683 newEnfVertex->name = theName;
684 newEnfVertex->geomEntry = theEntry;
685 newEnfVertex->coords.clear();
687 newEnfVertex->coords.push_back(x);
688 newEnfVertex->coords.push_back(y);
689 newEnfVertex->coords.push_back(z);
691 newEnfVertex->groupName = theGroupName;
692 newEnfVertex->size = size;
693 newEnfVertex->isCompound = isCompound;
696 // update _enfVertexList
697 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(newEnfVertex);
698 if (it != _enfVertexList.end()) {
701 if (oldEnVertex->name != theName) {
702 oldEnVertex->name = theName;
705 if (oldEnVertex->groupName != theGroupName) {
706 oldEnVertex->groupName = theGroupName;
709 if (oldEnVertex->size != size) {
710 oldEnVertex->size = size;
714 // update map coords / enf vertex if needed
715 if (oldEnVertex->coords.size()) {
716 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
717 _enfVertexCoordsSizeList[oldEnVertex->coords] = size;
720 // update map geom entry / enf vertex if needed
721 if (oldEnVertex->geomEntry != "") {
722 _geomEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
723 _enfVertexEntrySizeList[oldEnVertex->geomEntry] = size;
728 // //////// CREATE ////////////
731 _enfVertexList.insert(newEnfVertex);
732 if (theEntry == "") {
733 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
734 _enfVertexCoordsSizeList[newEnfVertex->coords] = size;
737 _geomEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
738 _enfVertexEntrySizeList[newEnfVertex->geomEntry] = size;
743 NotifySubMeshesHypothesisModification();
749 //=======================================================================
750 //function : SetEnforcedMesh
751 //=======================================================================
752 bool HYBRIDPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName)
754 TIDSortedElemSet theElemSet;
755 SMDS_ElemIteratorPtr eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType));
756 while ( eIt->more() )
757 theElemSet.insert( eIt->next() );
758 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
760 THYBRIDEnforcedMesh* newEnfMesh = new THYBRIDEnforcedMesh();
761 newEnfMesh->persistID = theMesh.GetMeshDS()->GetPersistentId();
762 newEnfMesh->name = name;
763 newEnfMesh->entry = entry;
764 newEnfMesh->elementType = elementType;
765 newEnfMesh->groupName = groupName;
767 THYBRIDEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
768 if (it == _enfMeshList.end()) {
769 _entryEnfMeshMap[entry].insert(newEnfMesh);
770 _enfMeshList.insert(newEnfMesh);
779 //=======================================================================
780 //function : SetEnforcedGroup
781 //=======================================================================
782 bool HYBRIDPlugin_Hypothesis::SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName)
784 TIDSortedElemSet theElemSet;
785 if ( theIDs->length() == 0 ){MESSAGE("The source group is empty");}
786 for ( CORBA::ULong i = 0; i < theIDs->length(); i++) {
787 CORBA::Long ind = theIDs[i];
788 if (elementType == SMESH::NODE)
790 const SMDS_MeshNode * node = theMeshDS->FindNode(ind);
792 theElemSet.insert( node );
796 const SMDS_MeshElement * elem = theMeshDS->FindElement(ind);
798 theElemSet.insert( elem );
802 // SMDS_ElemIteratorPtr it = theGroup->GetGroupDS()->GetElements();
803 // while ( it->more() )
804 // theElemSet.insert( it->next() );
806 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
808 THYBRIDEnforcedMesh* newEnfMesh = new THYBRIDEnforcedMesh();
809 newEnfMesh->name = name;
810 newEnfMesh->entry = entry;
811 newEnfMesh->elementType = elementType;
812 newEnfMesh->groupName = groupName;
814 THYBRIDEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
815 if (it == _enfMeshList.end()) {
816 _entryEnfMeshMap[entry].insert(newEnfMesh);
817 _enfMeshList.insert(newEnfMesh);
823 //=======================================================================
824 //function : SetEnforcedElements
825 //=======================================================================
826 bool HYBRIDPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName)
828 TIDSortedElemSet::const_iterator it = theElemSet.begin();
829 const SMDS_MeshElement* elem;
830 const SMDS_MeshNode* node;
832 std::pair<TIDSortedNodeGroupMap::iterator,bool> nodeRet;
833 std::pair<TIDSortedElemGroupMap::iterator,bool> elemRet;
835 for (;it != theElemSet.end();++it)
838 switch (elementType) {
840 node = dynamic_cast<const SMDS_MeshNode*>(elem);
842 nodeRet = _enfNodes.insert(make_pair(node,groupName));
843 added = added && nodeRet.second;
844 std::string msg = added ? "yes":"no";
847 SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
848 for (;nodeIt->more();) {
849 node = dynamic_cast<const SMDS_MeshNode*>(nodeIt->next());
850 nodeRet = _enfNodes.insert(make_pair(node,groupName));
851 added = added && nodeRet.second;
857 if (elem->GetType() == SMDSAbs_Edge) {
858 elemRet = _enfEdges.insert(make_pair(elem,groupName));
859 added = added && elemRet.second;
861 else if (elem->GetType() > SMDSAbs_Edge) {
862 SMDS_ElemIteratorPtr it = elem->edgesIterator();
864 const SMDS_MeshElement* anEdge = it->next();
865 elemRet = _enfEdges.insert(make_pair(anEdge,groupName));
866 added = added && elemRet.second;
871 if (elem->GetType() == SMDSAbs_Face)
873 if (elem->NbCornerNodes() == 3) {
874 elemRet = _enfTriangles.insert(make_pair(elem,groupName));
875 added = added && elemRet.second;
878 else if (elem->GetType() > SMDSAbs_Face) { // Group of faces
879 SMDS_ElemIteratorPtr it = elem->facesIterator();
881 const SMDS_MeshElement* aFace = it->next();
882 if (aFace->NbCornerNodes() == 3) {
883 elemRet = _enfTriangles.insert(make_pair(aFace,groupName));
884 added = added && elemRet.second;
894 NotifySubMeshesHypothesisModification();
899 //=======================================================================
900 //function : GetEnforcedVertex
901 //=======================================================================
903 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z)
904 throw (std::invalid_argument)
906 std::vector<double> coord(3);
910 if (_coordsEnfVertexMap.count(coord)>0)
911 return _coordsEnfVertexMap[coord];
912 std::ostringstream msg ;
913 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
914 throw std::invalid_argument(msg.str());
917 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(const std::string theEntry)
918 throw (std::invalid_argument)
920 if (_geomEntryEnfVertexMap.count(theEntry)>0)
921 return _geomEntryEnfVertexMap[theEntry];
923 std::ostringstream msg ;
924 msg << "No enforced vertex with entry " << theEntry;
925 throw std::invalid_argument(msg.str());
928 //=======================================================================
929 //function : RemoveEnforcedVertex
930 //=======================================================================
932 bool HYBRIDPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, const std::string theEntry)
933 throw (std::invalid_argument)
935 bool toNotify = false;
936 std::ostringstream msg;
937 THYBRIDEnforcedVertex *oldEnfVertex;
938 std::vector<double> coords(3);
943 // check that enf vertex with given enf vertex entry exists
944 TGeomEntryHYBRIDEnforcedVertexMap::iterator it_enfVertexEntry = _geomEntryEnfVertexMap.find(theEntry);
945 if (it_enfVertexEntry != _geomEntryEnfVertexMap.end()) {
947 oldEnfVertex = it_enfVertexEntry->second;
948 _geomEntryEnfVertexMap.erase(it_enfVertexEntry);
951 // check that enf vertex with given coords exists
952 TCoordsHYBRIDEnforcedVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
953 if (it_coords_enf != _coordsEnfVertexMap.end()) {
955 oldEnfVertex = it_coords_enf->second;
956 _coordsEnfVertexMap.erase(it_coords_enf);
957 _enfVertexCoordsSizeList.erase(_enfVertexCoordsSizeList.find(coords));
960 throw std::invalid_argument(msg.str());
965 // update _enfVertexList
966 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
967 if (it != _enfVertexList.end()) {
968 if ((*it)->groupName != "")
969 _groupsToRemove.insert((*it)->groupName);
970 _enfVertexList.erase(it);
975 NotifySubMeshesHypothesisModification();
980 //=======================================================================
981 //function : ClearEnforcedVertices
982 //=======================================================================
983 void HYBRIDPlugin_Hypothesis::ClearEnforcedVertices()
985 THYBRIDEnforcedVertexList::const_iterator it = _enfVertexList.begin();
986 for(;it != _enfVertexList.end();++it) {
987 if ((*it)->groupName != "")
988 _groupsToRemove.insert((*it)->groupName);
990 _enfVertexList.clear();
991 _coordsEnfVertexMap.clear();
992 _geomEntryEnfVertexMap.clear();
993 _enfVertexCoordsSizeList.clear();
994 _enfVertexEntrySizeList.clear();
995 NotifySubMeshesHypothesisModification();
998 //=======================================================================
999 //function : ClearEnforcedMeshes
1000 //=======================================================================
1001 void HYBRIDPlugin_Hypothesis::ClearEnforcedMeshes()
1003 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
1004 for(;it != _enfMeshList.end();++it) {
1005 if ((*it)->groupName != "")
1006 _groupsToRemove.insert((*it)->groupName);
1010 _enfTriangles.clear();
1011 _nodeIDToSizeMap.clear();
1012 _enfMeshList.clear();
1013 _entryEnfMeshMap.clear();
1014 NotifySubMeshesHypothesisModification();
1017 //================================================================================
1019 * \brief At mesh loading, restore enforced elements by just loaded enforced meshes
1021 //================================================================================
1023 void HYBRIDPlugin_Hypothesis::RestoreEnfElemsByMeshes()
1025 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
1026 for(;it != _enfMeshList.end();++it) {
1027 THYBRIDEnforcedMesh* enfMesh = *it;
1028 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
1029 SetEnforcedMesh( *mesh,
1030 enfMesh->elementType,
1033 enfMesh->groupName );
1034 enfMesh->persistID = -1; // not to restore again
1038 //=======================================================================
1039 //function : SetGroupsToRemove
1040 //=======================================================================
1042 void HYBRIDPlugin_Hypothesis::ClearGroupsToRemove()
1044 _groupsToRemove.clear();
1048 //=======================================================================
1049 //function : DefaultLayersOnAllWrap
1050 //=======================================================================
1052 bool HYBRIDPlugin_Hypothesis::DefaultLayersOnAllWrap()
1057 //=======================================================================
1058 //function : DefaultMeshHoles
1059 //=======================================================================
1061 bool HYBRIDPlugin_Hypothesis::DefaultMeshHoles()
1063 return false; // PAL19680
1066 //=======================================================================
1067 //function : DefaultToMakeGroupsOfDomains
1068 //=======================================================================
1070 bool HYBRIDPlugin_Hypothesis::DefaultToMakeGroupsOfDomains()
1072 return false; // issue 0022172
1075 //=======================================================================
1076 //function : DefaultMaximumMemory
1077 //=======================================================================
1080 #include <windows.h>
1081 #elif !defined(__APPLE__)
1082 #include <sys/sysinfo.h>
1085 double HYBRIDPlugin_Hypothesis::DefaultMaximumMemory()
1088 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
1089 MEMORYSTATUSEX statex;
1090 statex.dwLength = sizeof (statex);
1091 int err = GlobalMemoryStatusEx (&statex);
1094 statex.ullTotalPhys / 1024 / 1024 +
1095 statex.ullTotalPageFile / 1024 / 1024 +
1096 statex.ullTotalVirtual / 1024 / 1024;
1097 return ( 0.7 * totMB );
1099 #elif !defined(__APPLE__)
1101 int err = sysinfo( &si );
1103 int ramMB = si.totalram * si.mem_unit / 1024 / 1024;
1104 return ( 0.7 * ramMB );
1110 //=======================================================================
1111 //function : DefaultInitialMemory
1112 //=======================================================================
1114 double HYBRIDPlugin_Hypothesis::DefaultInitialMemory()
1116 return DefaultMaximumMemory();
1119 //=======================================================================
1120 //function : DefaultCollisionMode
1121 //=======================================================================
1122 short HYBRIDPlugin_Hypothesis::DefaultCollisionMode()
1127 //=======================================================================
1128 //function : DefaultBoundaryLayersGrowth
1129 //=======================================================================
1130 short HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersGrowth()
1132 return Layer_Growth_Inward;
1135 //=======================================================================
1136 //function : DefaultElementGeneration
1137 //=======================================================================
1138 short HYBRIDPlugin_Hypothesis::DefaultElementGeneration()
1140 return Generation_Tetra_Dominant;
1143 //=======================================================================
1144 //function : DefaultOptimizationLevel
1145 //=======================================================================
1146 short HYBRIDPlugin_Hypothesis::DefaultOptimizationLevel()
1151 //=======================================================================
1152 //function : DefaultWorkingDirectory
1153 //=======================================================================
1155 std::string HYBRIDPlugin_Hypothesis::DefaultWorkingDirectory()
1157 std::string aTmpDir;
1159 char *Tmp_dir = getenv("SALOME_TMP_DIR");
1160 if(Tmp_dir != NULL) {
1173 //=======================================================================
1174 //function : DefaultKeepFiles
1175 //=======================================================================
1177 bool HYBRIDPlugin_Hypothesis::DefaultKeepFiles()
1182 //=======================================================================
1183 //function : DefaultRemoveLogOnSuccess
1184 //=======================================================================
1186 bool HYBRIDPlugin_Hypothesis::DefaultRemoveLogOnSuccess()
1192 //=======================================================================
1193 //function : DefaultVerboseLevel
1194 //=======================================================================
1196 short HYBRIDPlugin_Hypothesis::DefaultVerboseLevel()
1201 //=======================================================================
1202 //function : DefaultToCreateNewNodes
1203 //=======================================================================
1205 bool HYBRIDPlugin_Hypothesis::DefaultToCreateNewNodes()
1210 //=======================================================================
1211 //function : DefaultToUseBoundaryRecoveryVersion
1212 //=======================================================================
1214 bool HYBRIDPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
1219 //=======================================================================
1220 //function : DefaultToUseFEMCorrection
1221 //=======================================================================
1223 bool HYBRIDPlugin_Hypothesis::DefaultToUseFEMCorrection()
1228 //=======================================================================
1229 //function : DefaultToRemoveCentralPoint
1230 //=======================================================================
1232 bool HYBRIDPlugin_Hypothesis::DefaultToRemoveCentralPoint()
1237 //=======================================================================
1238 //function : DefaultGradation
1239 //=======================================================================
1241 double HYBRIDPlugin_Hypothesis::DefaultGradation()
1246 //=======================================================================
1247 //function : DefaultStandardOutputLog
1248 //=======================================================================
1250 bool HYBRIDPlugin_Hypothesis::DefaultStandardOutputLog()
1255 // //=======================================================================
1256 // //function : DefaultID2SizeMap
1257 // //=======================================================================
1259 // HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::DefaultID2SizeMap()
1261 // return HYBRIDPlugin_Hypothesis::TID2SizeMap();
1264 //=======================================================================
1265 //function : DefaultAddMultinormals
1266 //=======================================================================
1267 bool HYBRIDPlugin_Hypothesis::DefaultAddMultinormals()
1272 //=======================================================================
1273 //function : DefaultSmoothNormals
1274 //=======================================================================
1275 bool HYBRIDPlugin_Hypothesis::DefaultSmoothNormals()
1280 //=======================================================================
1281 //function : DefaultHeightFirstLayer
1282 //=======================================================================
1283 double HYBRIDPlugin_Hypothesis::DefaultHeightFirstLayer()
1285 return 0.0; //or epsilon?
1288 //=======================================================================
1289 //function : DefaultBoundaryLayersProgression
1290 //=======================================================================
1291 double HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersProgression()
1296 //=======================================================================
1297 //function : DefaultMultinormalsAngle
1298 //=======================================================================
1299 double HYBRIDPlugin_Hypothesis::DefaultMultinormalsAngle()
1304 //=======================================================================
1305 //function : DefaultNbOfBoundaryLayers
1306 //=======================================================================
1307 short HYBRIDPlugin_Hypothesis::DefaultNbOfBoundaryLayers()
1312 //=======================================================================
1314 //=======================================================================
1316 std::ostream & HYBRIDPlugin_Hypothesis::SaveTo(std::ostream & save)
1318 save << (int) myBoundaryLayersGrowth << " ";
1319 save << (int) myElementGeneration << " ";
1320 save << (int) myAddMultinormals << " ";
1321 save << (int) mySmoothNormals << " ";
1322 save << (int) myLayersOnAllWrap << " ";
1324 save << myNbOfBoundaryLayers << " ";
1325 save << myHeightFirstLayer << " ";
1326 save << myBoundaryLayersProgression << " ";
1327 save << myMultinormalsAngle << " ";
1329 save << (int) myKeepFiles << " ";
1330 save << myWorkingDirectory << " ";
1331 save << myVerboseLevel << " ";
1332 if (!myTextOption.empty()) {
1333 save << "__OPTIONS_BEGIN__ ";
1334 save << myTextOption << " ";
1335 save << "__OPTIONS_END__ ";
1339 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.begin();
1340 if (it != _enfVertexList.end()) {
1341 save << " " << "__ENFORCED_VERTICES_BEGIN__ ";
1342 for ( ; it != _enfVertexList.end(); ++it ) {
1343 THYBRIDEnforcedVertex *enfVertex = (*it);
1344 save << " " << "__BEGIN_VERTEX__";
1345 if (!enfVertex->name.empty()) {
1346 save << " " << "__BEGIN_NAME__";
1347 save << " " << enfVertex->name;
1348 save << " " << "__END_NAME__";
1350 if (!enfVertex->geomEntry.empty()) {
1351 save << " " << "__BEGIN_ENTRY__";
1352 save << " " << enfVertex->geomEntry;
1353 save << " " << enfVertex->isCompound;
1354 save << " " << "__END_ENTRY__";
1356 if (!enfVertex->groupName.empty()) {
1357 save << " " << "__BEGIN_GROUP__";
1358 save << " " << enfVertex->groupName;
1359 save << " " << "__END_GROUP__";
1361 if (enfVertex->coords.size()) {
1362 save << " " << "__BEGIN_COORDS__";
1363 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1364 save << " " << enfVertex->coords[i];
1365 save << " " << "__END_COORDS__";
1367 save << " " << "__BEGIN_SIZE__";
1368 save << " " << enfVertex->size;
1369 save << " " << "__END_SIZE__";
1370 save << " " << "__END_VERTEX__";
1372 save << " " << "__ENFORCED_VERTICES_END__ ";
1375 THYBRIDEnforcedMeshList::iterator it_mesh = _enfMeshList.begin();
1376 if (it_mesh != _enfMeshList.end()) {
1377 save << " " << "__ENFORCED_MESHES_BEGIN__ ";
1378 for ( ; it_mesh != _enfMeshList.end(); ++it_mesh ) {
1379 THYBRIDEnforcedMesh *enfMesh = (*it_mesh);
1380 save << " " << "__BEGIN_ENF_MESH__";
1382 save << " " << "__BEGIN_NAME__";
1383 save << " " << enfMesh->name;
1384 save << " " << "__END_NAME__";
1386 save << " " << "__BEGIN_ENTRY__";
1387 save << " " << enfMesh->entry;
1388 save << " " << "__END_ENTRY__";
1390 save << " " << "__BEGIN_ELEM_TYPE__";
1391 save << " " << (int)enfMesh->elementType;
1392 save << " " << "__END_ELEM_TYPE__";
1394 if (!enfMesh->groupName.empty()) {
1395 save << " " << "__BEGIN_GROUP__";
1396 save << " " << enfMesh->groupName;
1397 save << " " << "__END_GROUP__";
1399 save << " " << "__PERSIST_ID__";
1400 save << " " << enfMesh->persistID;
1401 save << " " << "__END_ENF_MESH__";
1402 std::cout << "Saving of enforced mesh " << enfMesh->name.c_str() << " done" << std::endl;
1404 save << " " << "__ENFORCED_MESHES_END__ ";
1407 save << " " << myFacesWithLayers.size();
1408 for ( size_t i = 0; i < myFacesWithLayers.size(); ++i )
1409 save << " " << myFacesWithLayers[i];
1414 //=======================================================================
1415 //function : LoadFrom
1416 //=======================================================================
1418 std::istream & HYBRIDPlugin_Hypothesis::LoadFrom(std::istream & load)
1424 isOK = static_cast<bool>(load >> i);
1426 myBoundaryLayersGrowth = (short) i;
1428 load.clear(ios::badbit | load.rdstate());
1430 isOK = static_cast<bool>(load >> i);
1432 myElementGeneration = (short) i;
1434 load.clear(ios::badbit | load.rdstate());
1436 isOK = static_cast<bool>(load >> i);
1438 myAddMultinormals = (bool) i;
1440 load.clear(ios::badbit | load.rdstate());
1442 isOK = static_cast<bool>(load >> i);
1444 mySmoothNormals = (bool) i;
1446 load.clear(ios::badbit | load.rdstate());
1448 isOK = static_cast<bool>(load >> i);
1450 myLayersOnAllWrap = (bool) i;
1452 load.clear(ios::badbit | load.rdstate());
1454 isOK = static_cast<bool>(load >> i);
1456 myNbOfBoundaryLayers = (short) i;
1458 load.clear(ios::badbit | load.rdstate());
1460 isOK = static_cast<bool>(load >> d);
1462 myHeightFirstLayer = d;
1464 load.clear(ios::badbit | load.rdstate());
1466 isOK = static_cast<bool>(load >> d);
1468 myBoundaryLayersProgression = d;
1470 load.clear(ios::badbit | load.rdstate());
1472 isOK = static_cast<bool>(load >> d);
1474 myMultinormalsAngle = d;
1476 load.clear(ios::badbit | load.rdstate());
1478 isOK = static_cast<bool>(load >> i);
1480 myKeepFiles = (bool) i;
1482 load.clear(ios::badbit | load.rdstate());
1484 isOK = static_cast<bool>(load >> myWorkingDirectory);
1486 if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
1487 myKeepFiles = false;
1488 myWorkingDirectory.clear();
1490 else if ( myWorkingDirectory == "1" ) {
1492 myWorkingDirectory.clear();
1496 load.clear(ios::badbit | load.rdstate());
1498 isOK = static_cast<bool>(load >> i);
1500 myVerboseLevel = (short) i;
1502 load.clear(ios::badbit | load.rdstate());
1505 std::string separator;
1506 bool hasOptions = false;
1507 bool hasEnforcedVertices = false;
1508 bool hasEnforcedMeshes = false;
1509 isOK = static_cast<bool>(load >> separator);
1511 if ( isOK && ( separator == "0" || separator == "1" ))
1513 myToMakeGroupsOfDomains = ( separator == "1" );
1514 isOK = static_cast<bool>(load >> separator);
1518 if (separator == "__OPTIONS_BEGIN__")
1520 else if (separator == "__ENFORCED_VERTICES_BEGIN__")
1521 hasEnforcedVertices = true;
1522 else if (separator == "__ENFORCED_MESHES_BEGIN__")
1523 hasEnforcedMeshes = true;
1529 isOK = static_cast<bool>(load >> txt);
1531 if (txt == "__OPTIONS_END__") {
1532 if (!myTextOption.empty()) {
1533 // Remove last space
1534 myTextOption.erase(myTextOption.end()-1);
1539 myTextOption += txt;
1540 myTextOption += " ";
1546 isOK = static_cast<bool>(load >> separator);
1547 if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__")
1548 hasEnforcedVertices = true;
1549 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1550 hasEnforcedMeshes = true;
1553 if (hasEnforcedVertices) {
1554 std::string txt, name, entry, groupName;
1555 double size, coords[3];
1557 bool hasCoords = false;
1558 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1560 if (txt == "__ENFORCED_VERTICES_END__")
1563 THYBRIDEnforcedVertex *enfVertex = new THYBRIDEnforcedVertex();
1565 isOK = static_cast<bool>(load >> txt);
1566 if (txt == "__END_VERTEX__") {
1567 enfVertex->name = name;
1568 enfVertex->geomEntry = entry;
1569 enfVertex->isCompound = isCompound;
1570 enfVertex->groupName = groupName;
1571 enfVertex->coords.clear();
1573 enfVertex->coords.assign(coords,coords+3);
1575 _enfVertexList.insert(enfVertex);
1577 if (enfVertex->coords.size())
1578 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1579 if (!enfVertex->geomEntry.empty())
1580 _geomEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1589 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1590 while (isOK && (txt != "__END_NAME__")) {
1591 isOK = static_cast<bool>(load >> txt);
1592 if (txt != "__END_NAME__") {
1600 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1601 isOK = static_cast<bool>(load >> entry);
1602 isOK = static_cast<bool>(load >> isCompound);
1603 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1604 if (txt != "__END_ENTRY__")
1605 throw std::exception();
1608 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1609 while (isOK && (txt != "__END_GROUP__")) {
1610 isOK = static_cast<bool>(load >> txt);
1611 if (txt != "__END_GROUP__") {
1612 if (!groupName.empty())
1619 if (txt == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1621 isOK = static_cast<bool>(load >> coords[0] >> coords[1] >> coords[2]);
1622 isOK = static_cast<bool>(load >> txt); // __END_COORDS__
1623 if (txt != "__END_COORDS__")
1624 throw std::exception();
1627 if (txt == "__BEGIN_SIZE__") { // __BEGIN_ENTRY__
1628 isOK = static_cast<bool>(load >> size);
1629 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1630 if (txt != "__END_SIZE__") {
1631 throw std::exception();
1635 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1639 if (hasEnforcedVertices) {
1640 isOK = static_cast<bool>(load >> separator);
1641 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1642 hasEnforcedMeshes = true;
1645 if (hasEnforcedMeshes) {
1646 std::string txt, name, entry, groupName;
1647 int elementType = -1, persistID = -1;
1648 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1651 if (txt == "__ENFORCED_MESHES_END__")
1654 THYBRIDEnforcedMesh *enfMesh = new THYBRIDEnforcedMesh();
1656 isOK = static_cast<bool>(load >> txt);
1657 if (txt == "__END_ENF_MESH__") {
1658 enfMesh->name = name;
1659 enfMesh->entry = entry;
1660 enfMesh->elementType = (SMESH::ElementType)elementType;
1661 enfMesh->groupName = groupName;
1662 enfMesh->persistID = persistID;
1664 _enfMeshList.insert(enfMesh);
1665 std::cout << "Restoring of enforced mesh " <<name << " done" << std::endl;
1675 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1676 while (isOK && (txt != "__END_NAME__")) {
1677 isOK = static_cast<bool>(load >> txt);
1678 if (txt != "__END_NAME__") {
1686 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1687 isOK = static_cast<bool>(load >> entry);
1688 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1689 if (txt != "__END_ENTRY__")
1690 throw std::exception();
1693 if (txt == "__BEGIN_ELEM_TYPE__") { // __BEGIN_ELEM_TYPE__
1694 isOK = static_cast<bool>(load >> elementType);
1695 isOK = static_cast<bool>(load >> txt); // __END_ELEM_TYPE__
1696 if (txt != "__END_ELEM_TYPE__")
1697 throw std::exception();
1700 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1701 while (isOK && (txt != "__END_GROUP__")) {
1702 isOK = static_cast<bool>(load >> txt);
1703 if (txt != "__END_GROUP__") {
1704 if (!groupName.empty())
1711 if (txt == "__PERSIST_ID__") {
1712 isOK = static_cast<bool>(load >> persistID);
1714 std::cout << "isOK: " << isOK << std::endl;
1717 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1721 if ( hasEnforcedMeshes )
1722 isOK = static_cast<bool>(load >> separator);
1726 i = atoi( separator.c_str() );
1730 myFacesWithLayers.reserve( i );
1731 while (( myFacesWithLayers.size() < myFacesWithLayers.capacity() ) &&
1732 ( isOK = static_cast<bool>(load >> i)) )
1733 myFacesWithLayers.push_back( i );
1739 //=======================================================================
1740 //function : SetParametersByMesh
1741 //=======================================================================
1743 bool HYBRIDPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
1749 //================================================================================
1751 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
1753 //================================================================================
1755 bool HYBRIDPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
1756 const SMESH_Mesh* /*theMesh*/)
1758 myToMakeGroupsOfDomains = ( !dflts._shape || dflts._shape->IsNull() );
1762 //================================================================================
1764 * \brief Return command to run hybrid mesher excluding file prefix (-f)
1766 //================================================================================
1768 std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis* hyp,
1771 SMESH_Comment cmd = GetExeName();
1772 // check if any option is overridden by hyp->myTextOption
1773 bool p_h = ( hyp && hyp->myTextOption.find("-h") != std::string::npos );
1774 bool p_v = ( hyp && hyp->myTextOption.find("-v") != std::string::npos );
1775 bool p_i = ( hyp && hyp->myTextOption.find("-i") != std::string::npos );
1776 bool p_o = ( hyp && hyp->myTextOption.find("-o") != std::string::npos );
1777 bool p_mnot = ( hyp && hyp->myTextOption.find("--max_number_of_threads ") != std::string::npos );
1778 bool p_blsi = ( hyp && hyp->myTextOption.find("--boundary_layer_surface_tags ") != std::string::npos );
1779 bool p_blii = ( hyp && hyp->myTextOption.find("--boundary_layer_imprint_tags ") != std::string::npos );
1780 bool p_blsd = ( hyp && hyp->myTextOption.find("--normal_direction ") != std::string::npos );
1781 bool p_hotfl = ( hyp && hyp->myTextOption.find("--boundary_layer_global_initial_height ") != std::string::npos );
1782 bool p_nobl = ( hyp && hyp->myTextOption.find("--number_of_boundary_layers ") != std::string::npos );
1783 bool p_blgp = ( hyp && hyp->myTextOption.find("--boundary_layer_geometric_progression ") != std::string::npos );
1784 bool p_eg = ( hyp && hyp->myTextOption.find("--element_generation ") != std::string::npos );
1785 bool p_cm = ( hyp && hyp->myTextOption.find("--collision_mode ") != std::string::npos );
1786 bool p_am = ( hyp && hyp->myTextOption.find("--add_multinormals ") != std::string::npos );
1787 bool p_mat = ( hyp && hyp->myTextOption.find("--multinormal_angle_threshold ") != std::string::npos );
1788 bool p_sn = ( hyp && hyp->myTextOption.find("--smooth_normals ") != std::string::npos );
1791 //- global_physical_size
1792 //- boundary_layer_size_mode
1793 //- boundary_layer_initial_height_on_surface_tags
1794 //- boundary_layer_max_element_angle
1796 bool nolayers = false;
1797 bool layersOnAllWrap = hyp ? hyp->myLayersOnAllWrap : DefaultLayersOnAllWrap();
1805 std::cout << "!!!!! CommandToRun help only !!!! " << cmd << std::endl;
1810 cmd << " --verbose " << hyp->myVerboseLevel;
1812 if ( !p_mnot && hyp )
1813 cmd << " --max_number_of_threads " << 8; //TODO getenv NB CPU
1816 if ( !p_nobl && hyp ) {
1817 if ( hyp->myNbOfBoundaryLayers < 1 ) nolayers = true;
1819 if ( !p_hotfl && hyp ) {
1820 if ( hyp->myHeightFirstLayer < 1e-50 ) nolayers = true;
1823 if ( !p_blsd && hyp ) {
1824 if ( hyp->myBoundaryLayersGrowth >= 0 && hyp->myBoundaryLayersGrowth <= 1 ) {
1825 const char* value[] = { "-1" , "1" }; // -1 == inside
1826 cmd << " --normal_direction " << value[ hyp->myBoundaryLayersGrowth ];
1830 if ( !p_hotfl && hyp ) {
1831 cmd << " --boundary_layer_global_initial_height " << hyp->myHeightFirstLayer;
1834 if ( !p_nobl && hyp ) {
1835 cmd << " --number_of_boundary_layers " << ( nolayers ? 0 : hyp->myNbOfBoundaryLayers );
1838 if ( !p_blgp && hyp ) {
1839 cmd << " --boundary_layer_geometric_progression " << hyp->myBoundaryLayersProgression;
1842 if ( !nolayers && hyp )
1844 cmd << " --boundary_layer_size_mode " << ( layersOnAllWrap ? "global" : "local" );
1845 cmd << " --boundary_layer_surface_tags ";
1846 if ( layersOnAllWrap )
1852 const std::vector<int>& faceIDs = hyp->GetFacesWithLayers();
1853 const bool hasEnforcedTria = !HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(hyp).empty();
1854 for ( size_t i = 0; i < faceIDs.size(); ++i )
1855 cmd << faceIDs[i] << ",";
1856 if ( hasEnforcedTria )
1857 cmd << EnforcedTag();
1858 cmd << " --boundary_layer_initial_height_on_surface_tags ";
1859 for ( size_t i = 0; i < faceIDs.size() + hasEnforcedTria; ++i )
1860 cmd << hyp->myHeightFirstLayer << ",";
1864 if ( !p_eg && hyp ) {
1865 if ( hyp->myElementGeneration >= 0 && hyp->myElementGeneration <= 1 ) {
1866 const char* value[] = { "tetra-dominant" , "hexa-dominant" };
1867 cmd << " --element_generation " << value[ hyp->myElementGeneration ];
1871 if ( !p_cm && hyp ) {
1872 if ( hyp->myCollisionMode >= 0 && hyp->myCollisionMode <= 1 ) {
1873 const char* value[] = { "decrease" , "stop" };
1874 cmd << " --collision_mode " << value[ hyp->myCollisionMode ];
1878 if ( !p_am && hyp ) {
1879 int res = hyp->myAddMultinormals ? 0 : 1 ;
1880 const char* value[] = { "yes" , "no" };
1881 cmd << " --add_multinormals " << value[ res ];
1884 if ( !p_mat && hyp ) {
1885 cmd << " --multinormal_angle_threshold " << hyp->myMultinormalsAngle;
1888 if ( !p_sn && hyp ) {
1889 int res = hyp->mySmoothNormals ? 0 : 1 ;
1890 const char* value[] = { "yes" , "no" };
1891 cmd << " --smooth_normals " << value[ res ];
1897 //std::cout << "!!!!!CommandToRun end " << cmd << std::endl;
1902 //================================================================================
1904 * \brief Return a unique file name
1906 //================================================================================
1908 std::string HYBRIDPlugin_Hypothesis::GetFileName(const HYBRIDPlugin_Hypothesis* hyp)
1910 std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
1911 const char lastChar = *aTmpDir.rbegin();
1913 if(lastChar != '\\') aTmpDir+='\\';
1915 if(lastChar != '/') aTmpDir+='/';
1918 SMESH_Comment aGenericName = aTmpDir;
1919 aGenericName << "HYBRID_";
1920 aGenericName << getpid();
1921 aGenericName << "_";
1922 aGenericName << Abs((Standard_Integer)(long) aGenericName.c_str());
1924 return aGenericName;
1927 //================================================================================
1929 * Return the name of executable
1931 //================================================================================
1933 std::string HYBRIDPlugin_Hypothesis::GetExeName()
1935 //call mg-hybrid.bash is script which assumes new project version(s) mg-hybrid.exe in the prerequisite base and special? licence.
1937 return "mg-hybrid.exe";
1939 return "mg-hybrid.bash";
1943 //================================================================================
1945 * \brief Return the enforced vertices
1947 //================================================================================
1949 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexList HYBRIDPlugin_Hypothesis::GetEnforcedVertices(const HYBRIDPlugin_Hypothesis* hyp)
1951 return hyp ? hyp->_GetEnforcedVertices():DefaultHYBRIDEnforcedVertexList();
1954 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesCoordsSize (const HYBRIDPlugin_Hypothesis* hyp)
1956 return hyp ? hyp->_GetEnforcedVerticesCoordsSize(): DefaultHYBRIDEnforcedVertexCoordsValues();
1959 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexEntryValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesEntrySize (const HYBRIDPlugin_Hypothesis* hyp)
1961 return hyp ? hyp->_GetEnforcedVerticesEntrySize(): DefaultHYBRIDEnforcedVertexEntryValues();
1964 HYBRIDPlugin_Hypothesis::TCoordsHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByCoords (const HYBRIDPlugin_Hypothesis* hyp)
1966 return hyp ? hyp->_GetEnforcedVerticesByCoords(): DefaultCoordsHYBRIDEnforcedVertexMap();
1969 HYBRIDPlugin_Hypothesis::TGeomEntryHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByEntry (const HYBRIDPlugin_Hypothesis* hyp)
1971 return hyp ? hyp->_GetEnforcedVerticesByEntry(): DefaultGeomEntryHYBRIDEnforcedVertexMap();
1974 HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedNodes(const HYBRIDPlugin_Hypothesis* hyp)
1976 return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeGroupMap();
1979 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedEdges(const HYBRIDPlugin_Hypothesis* hyp)
1981 return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemGroupMap();
1984 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(const HYBRIDPlugin_Hypothesis* hyp)
1986 return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemGroupMap();
1989 HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp)
1991 return hyp ? hyp->_GetNodeIDToSizeMap(): DefaultID2SizeMap();
1994 HYBRIDPlugin_Hypothesis::TSetStrings HYBRIDPlugin_Hypothesis::GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp)
1996 return hyp ? hyp->_GetGroupsToRemove(): DefaultGroupsToRemove();