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, SMESH_Gen * gen)
42 : SMESH_Hypothesis(hypId, 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 myCoreSize(DefaultCoreSize()),
66 myMultinormalsAngle(DefaultMultinormalsAngle()),
67 myNbOfBoundaryLayers(DefaultNbOfBoundaryLayers()),
68 _enfVertexList(DefaultHYBRIDEnforcedVertexList()),
69 _enfVertexCoordsSizeList(DefaultHYBRIDEnforcedVertexCoordsValues()),
70 _enfVertexEntrySizeList(DefaultHYBRIDEnforcedVertexEntryValues()),
71 _coordsEnfVertexMap(DefaultCoordsHYBRIDEnforcedVertexMap()),
72 _geomEntryEnfVertexMap(DefaultGeomEntryHYBRIDEnforcedVertexMap()),
73 _enfMeshList(DefaultHYBRIDEnforcedMeshList()),
74 _entryEnfMeshMap(DefaultEntryHYBRIDEnforcedMeshListMap()),
75 _enfNodes(TIDSortedNodeGroupMap()),
76 _enfEdges(TIDSortedElemGroupMap()),
77 _enfTriangles(TIDSortedElemGroupMap()),
78 _nodeIDToSizeMap(DefaultID2SizeMap()),
79 _groupsToRemove(DefaultGroupsToRemove())
81 _name = "HYBRID_Parameters";
85 //=======================================================================
86 //function : SetLayersOnAllWrap
87 //=======================================================================
89 void HYBRIDPlugin_Hypothesis::SetLayersOnAllWrap(bool toMesh)
91 if ( myLayersOnAllWrap != toMesh ) {
92 myLayersOnAllWrap = toMesh;
93 NotifySubMeshesHypothesisModification();
97 //=======================================================================
98 //function : GetLayersOnAllWrap
99 //=======================================================================
101 bool HYBRIDPlugin_Hypothesis::GetLayersOnAllWrap(bool checkFreeOption) const
103 return myLayersOnAllWrap;
106 //=======================================================================
107 //function : SetFacesWithLayers
108 //purpose : Set IDs of faces to grow the layers on
109 //=======================================================================
111 bool HYBRIDPlugin_Hypothesis::SetFacesWithLayers(const std::vector<int>& theVal)
113 if ( myFacesWithLayers != theVal )
115 myFacesWithLayers = theVal;
116 NotifySubMeshesHypothesisModification();
122 //=======================================================================
123 //function : GetFacesWithLayers
124 //purpose : Return IDs of faces to grow the layers on
125 //=======================================================================
127 const std::vector<int>& HYBRIDPlugin_Hypothesis::GetFacesWithLayers() const
129 return myFacesWithLayers;
132 //=======================================================================
133 //function : SetFacesWithImprinting
134 //purpose : Set IDs of faces to grow the layers on
135 //=======================================================================
137 bool HYBRIDPlugin_Hypothesis::SetFacesWithImprinting(const std::vector<int>& theVal)
139 if ( myFacesWithImprinting != theVal )
141 myFacesWithImprinting = theVal;
142 NotifySubMeshesHypothesisModification();
148 //=======================================================================
149 //function : GetFacesWithImprinting
150 //purpose : Return IDs of faces to grow the layers on
151 //=======================================================================
153 const std::vector<int>& HYBRIDPlugin_Hypothesis::GetFacesWithImprinting() const
155 return myFacesWithImprinting;
158 //=======================================================================
159 //function : SetToMeshHoles
160 //=======================================================================
162 void HYBRIDPlugin_Hypothesis::SetToMeshHoles(bool toMesh)
164 if ( myToMeshHoles != toMesh ) {
165 myToMeshHoles = toMesh;
166 NotifySubMeshesHypothesisModification();
170 //=======================================================================
171 //function : GetToMeshHoles
172 //=======================================================================
174 bool HYBRIDPlugin_Hypothesis::GetToMeshHoles(bool checkFreeOption) const
176 if (checkFreeOption && !myTextOption.empty()) {
177 if ( myTextOption.find("-c 0"))
179 if ( myTextOption.find("-c 1"))
182 return myToMeshHoles;
185 //=======================================================================
186 //function : SetToMakeGroupsOfDomains
187 //=======================================================================
189 void HYBRIDPlugin_Hypothesis::SetToMakeGroupsOfDomains(bool toMakeGroups)
191 if ( myToMakeGroupsOfDomains != toMakeGroups ) {
192 myToMakeGroupsOfDomains = toMakeGroups;
193 NotifySubMeshesHypothesisModification();
197 //=======================================================================
198 //function : GetToMakeGroupsOfDomains
199 //=======================================================================
201 bool HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains() const
203 return myToMakeGroupsOfDomains;
206 //=======================================================================
207 //function : GetToMakeGroupsOfDomains
208 //=======================================================================
210 bool HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains(const HYBRIDPlugin_Hypothesis* hyp)
213 if ( hyp ) res = /*hyp->GetToMeshHoles(true) &&*/ hyp->GetToMakeGroupsOfDomains();
214 else res = /*DefaultMeshHoles() &&*/ DefaultToMakeGroupsOfDomains();
218 //=======================================================================
219 //function : SetMaximumMemory
220 //=======================================================================
222 void HYBRIDPlugin_Hypothesis::SetMaximumMemory(double MB)
224 if ( myMaximumMemory != MB ) {
225 myMaximumMemory = MB;
226 NotifySubMeshesHypothesisModification();
230 //=======================================================================
231 //function : GetMaximumMemory
232 // * automatic memory adjustment mode. Default is zero
233 //=======================================================================
235 double HYBRIDPlugin_Hypothesis::GetMaximumMemory() const
237 return myMaximumMemory;
240 //=======================================================================
241 //function : SetInitialMemory
242 //=======================================================================
244 void HYBRIDPlugin_Hypothesis::SetInitialMemory(double MB)
246 if ( myInitialMemory != MB ) {
247 myInitialMemory = MB;
248 NotifySubMeshesHypothesisModification();
252 //=======================================================================
253 //function : GetInitialMemory
254 //=======================================================================
256 double HYBRIDPlugin_Hypothesis::GetInitialMemory() const
258 return myInitialMemory;
261 //=======================================================================
262 //function : SetOptimizationLevel
263 //=======================================================================
265 void HYBRIDPlugin_Hypothesis::SetOptimizationLevel(OptimizationLevel level)
267 if ( myOptimizationLevel != level ) {
268 myOptimizationLevel = level;
269 NotifySubMeshesHypothesisModification();
273 //=======================================================================
274 //function : GetOptimizationLevel
275 //=======================================================================
276 HYBRIDPlugin_Hypothesis::OptimizationLevel HYBRIDPlugin_Hypothesis::GetOptimizationLevel() const
278 return (OptimizationLevel) myOptimizationLevel;
281 //=======================================================================
282 //function : SetCollisionMode
283 //=======================================================================
284 void HYBRIDPlugin_Hypothesis::SetCollisionMode(CollisionMode mode)
286 if ( myCollisionMode != mode ) {
287 myCollisionMode = mode;
288 NotifySubMeshesHypothesisModification();
292 //=======================================================================
293 //function : GetCollisionMode
294 //=======================================================================
295 HYBRIDPlugin_Hypothesis::CollisionMode HYBRIDPlugin_Hypothesis::GetCollisionMode() const
297 return (CollisionMode) myCollisionMode;
300 //=======================================================================
301 //function : SetBoundaryLayersGrowth
302 //=======================================================================
303 void HYBRIDPlugin_Hypothesis::SetBoundaryLayersGrowth(BoundaryLayersGrowth mode)
305 if ( myBoundaryLayersGrowth != mode ) {
306 myBoundaryLayersGrowth = mode;
307 NotifySubMeshesHypothesisModification();
311 //=======================================================================
312 //function : GetBoundaryLayersGrowth
313 //=======================================================================
314 HYBRIDPlugin_Hypothesis::BoundaryLayersGrowth HYBRIDPlugin_Hypothesis::GetBoundaryLayersGrowth() const
316 return (BoundaryLayersGrowth) myBoundaryLayersGrowth;
319 //=======================================================================
320 //function : SetElementGeneration
321 //=======================================================================
322 void HYBRIDPlugin_Hypothesis::SetElementGeneration(ElementGeneration mode)
324 if ( myElementGeneration != mode ) {
325 myElementGeneration = mode;
326 NotifySubMeshesHypothesisModification();
330 //=======================================================================
331 //function : GetElementGeneration
332 //=======================================================================
333 HYBRIDPlugin_Hypothesis::ElementGeneration HYBRIDPlugin_Hypothesis::GetElementGeneration() const
335 return (ElementGeneration) myElementGeneration;
338 //=======================================================================
339 //function : SetAddMultinormals
340 //=======================================================================
341 void HYBRIDPlugin_Hypothesis::SetAddMultinormals(bool toAddMultinormals)
343 if ( myAddMultinormals != toAddMultinormals ) {
344 myAddMultinormals = toAddMultinormals;
345 NotifySubMeshesHypothesisModification();
349 //=======================================================================
350 //function : GetAddMultinormals
351 //=======================================================================
353 bool HYBRIDPlugin_Hypothesis::GetAddMultinormals() const
355 return myAddMultinormals;
358 //=======================================================================
359 //function : SetSmoothNormals
360 //=======================================================================
362 void HYBRIDPlugin_Hypothesis::SetSmoothNormals(bool toSmoothNormals)
364 if ( mySmoothNormals != toSmoothNormals ) {
365 mySmoothNormals = toSmoothNormals;
366 NotifySubMeshesHypothesisModification();
370 //=======================================================================
371 //function : GetSmoothNormals
372 //=======================================================================
374 bool HYBRIDPlugin_Hypothesis::GetSmoothNormals() const
376 return mySmoothNormals;
379 //=======================================================================
380 //function : SetHeightFirstLayer
381 //=======================================================================
383 void HYBRIDPlugin_Hypothesis::SetHeightFirstLayer(double toHeightFirstLayer)
385 if ( myHeightFirstLayer != toHeightFirstLayer ) {
386 myHeightFirstLayer = toHeightFirstLayer;
387 NotifySubMeshesHypothesisModification();
391 //=======================================================================
392 //function : GetHeightFirstLayer
393 //=======================================================================
395 double HYBRIDPlugin_Hypothesis::GetHeightFirstLayer() const
397 return myHeightFirstLayer;
400 //=======================================================================
401 //function : SetBoundaryLayersProgression
402 //=======================================================================
404 void HYBRIDPlugin_Hypothesis::SetBoundaryLayersProgression(double toBoundaryLayersProgression)
406 if ( myBoundaryLayersProgression != toBoundaryLayersProgression ) {
407 myBoundaryLayersProgression = toBoundaryLayersProgression;
408 NotifySubMeshesHypothesisModification();
412 //=======================================================================
413 //function : GetBoundaryLayersProgression
414 //=======================================================================
416 double HYBRIDPlugin_Hypothesis::GetBoundaryLayersProgression() const
418 return myBoundaryLayersProgression;
421 //=======================================================================
422 //function : SetCoreSize
423 //=======================================================================
425 void HYBRIDPlugin_Hypothesis::SetCoreSize(double toCoreSize)
427 if ( myCoreSize != toCoreSize ) {
428 myCoreSize = toCoreSize;
429 NotifySubMeshesHypothesisModification();
433 //=======================================================================
434 //function : GetCoreSize
435 //=======================================================================
437 double HYBRIDPlugin_Hypothesis::GetCoreSize() const
442 //=======================================================================
443 //function : SetMultinormalsAngle
444 //=======================================================================
446 void HYBRIDPlugin_Hypothesis::SetMultinormalsAngle(double toMultinormalsAngle)
448 if ( myMultinormalsAngle != toMultinormalsAngle ) {
449 myMultinormalsAngle = toMultinormalsAngle;
450 NotifySubMeshesHypothesisModification();
454 //=======================================================================
455 //function : GetMultinormalsAngle
456 //=======================================================================
458 double HYBRIDPlugin_Hypothesis::GetMultinormalsAngle() const
460 return myMultinormalsAngle;
463 //=======================================================================
464 //function : SetNbOfBoundaryLayers
465 //=======================================================================
467 void HYBRIDPlugin_Hypothesis::SetNbOfBoundaryLayers(short toNbOfBoundaryLayers)
469 if ( myNbOfBoundaryLayers != toNbOfBoundaryLayers ) {
470 myNbOfBoundaryLayers = toNbOfBoundaryLayers;
471 NotifySubMeshesHypothesisModification();
475 //=======================================================================
476 //function : GetCoreSize
477 //=======================================================================
479 short HYBRIDPlugin_Hypothesis::GetNbOfBoundaryLayers() const
481 return myNbOfBoundaryLayers;
485 /////////////////////////////////////////////////////////////////////////
488 //=======================================================================
489 //function : SetWorkingDirectory
490 //=======================================================================
492 void HYBRIDPlugin_Hypothesis::SetWorkingDirectory(const std::string& path)
494 if ( myWorkingDirectory != path ) {
495 myWorkingDirectory = path;
496 NotifySubMeshesHypothesisModification();
500 //=======================================================================
501 //function : GetWorkingDirectory
502 //=======================================================================
504 std::string HYBRIDPlugin_Hypothesis::GetWorkingDirectory() const
506 return myWorkingDirectory;
509 //=======================================================================
510 //function : SetKeepFiles
511 //=======================================================================
513 void HYBRIDPlugin_Hypothesis::SetKeepFiles(bool toKeep)
515 if ( myKeepFiles != toKeep ) {
516 myKeepFiles = toKeep;
517 NotifySubMeshesHypothesisModification();
521 //=======================================================================
522 //function : GetKeepFiles
523 //=======================================================================
525 bool HYBRIDPlugin_Hypothesis::GetKeepFiles() const
530 //=======================================================================
531 //function : SetVerboseLevel
532 //=======================================================================
534 void HYBRIDPlugin_Hypothesis::SetVerboseLevel(short level)
536 if ( myVerboseLevel != level ) {
537 myVerboseLevel = level;
538 NotifySubMeshesHypothesisModification();
542 //=======================================================================
543 //function : GetVerboseLevel
544 //=======================================================================
546 short HYBRIDPlugin_Hypothesis::GetVerboseLevel() const
548 return myVerboseLevel;
551 //=======================================================================
552 //function : SetToCreateNewNodes
553 //=======================================================================
555 void HYBRIDPlugin_Hypothesis::SetToCreateNewNodes(bool toCreate)
557 if ( myToCreateNewNodes != toCreate ) {
558 myToCreateNewNodes = toCreate;
559 NotifySubMeshesHypothesisModification();
563 //=======================================================================
564 //function : GetToCreateNewNodes
565 //=======================================================================
567 bool HYBRIDPlugin_Hypothesis::GetToCreateNewNodes() const
569 return myToCreateNewNodes;
572 //=======================================================================
573 //function : SetToUseBoundaryRecoveryVersion
574 //=======================================================================
576 void HYBRIDPlugin_Hypothesis::SetToUseBoundaryRecoveryVersion(bool toUse)
578 if ( myToUseBoundaryRecoveryVersion != toUse ) {
579 myToUseBoundaryRecoveryVersion = toUse;
580 NotifySubMeshesHypothesisModification();
584 //=======================================================================
585 //function : GetToUseBoundaryRecoveryVersion
586 //=======================================================================
588 bool HYBRIDPlugin_Hypothesis::GetToUseBoundaryRecoveryVersion() const
590 return myToUseBoundaryRecoveryVersion;
593 //=======================================================================
594 //function : SetFEMCorrection
595 //=======================================================================
597 void HYBRIDPlugin_Hypothesis::SetFEMCorrection(bool toUseFem)
599 if ( myToUseFemCorrection != toUseFem ) {
600 myToUseFemCorrection = toUseFem;
601 NotifySubMeshesHypothesisModification();
605 //=======================================================================
606 //function : GetFEMCorrection
607 //=======================================================================
609 bool HYBRIDPlugin_Hypothesis::GetFEMCorrection() const
611 return myToUseFemCorrection;
614 //=======================================================================
615 //function : SetToRemoveCentralPoint
616 //=======================================================================
618 void HYBRIDPlugin_Hypothesis::SetToRemoveCentralPoint(bool toRemove)
620 if ( myToRemoveCentralPoint != toRemove ) {
621 myToRemoveCentralPoint = toRemove;
622 NotifySubMeshesHypothesisModification();
626 //=======================================================================
627 //function : GetToRemoveCentralPoint
628 //=======================================================================
630 bool HYBRIDPlugin_Hypothesis::GetToRemoveCentralPoint() const
632 return myToRemoveCentralPoint;
635 //=======================================================================
636 //function : SetAdvancedOption
637 //=======================================================================
639 void HYBRIDPlugin_Hypothesis::SetAdvancedOption(const std::string& option)
641 if ( myTextOption != option ) {
642 myTextOption = option;
643 NotifySubMeshesHypothesisModification();
647 //=======================================================================
648 //function : GetAdvancedOption
649 //=======================================================================
651 std::string HYBRIDPlugin_Hypothesis::GetAdvancedOption() const
656 //=======================================================================
657 //function : SetGradation
658 //=======================================================================
660 void HYBRIDPlugin_Hypothesis::SetGradation(double gradation)
662 if ( myGradation != gradation ) {
663 myGradation = gradation;
664 NotifySubMeshesHypothesisModification();
668 //=======================================================================
669 //function : GetGradation
670 //=======================================================================
672 double HYBRIDPlugin_Hypothesis::GetGradation() const
677 //=======================================================================
678 //function : SetStandardOutputLog
679 //=======================================================================
681 void HYBRIDPlugin_Hypothesis::SetStandardOutputLog(bool logInStandardOutput)
683 if ( myLogInStandardOutput != logInStandardOutput ) {
684 myLogInStandardOutput = logInStandardOutput;
685 NotifySubMeshesHypothesisModification();
689 //=======================================================================
690 //function : GetStandardOutputLog
691 //=======================================================================
693 bool HYBRIDPlugin_Hypothesis::GetStandardOutputLog() const
695 return myLogInStandardOutput;
698 //=======================================================================
699 //function : SetRemoveLogOnSuccess
700 //=======================================================================
702 void HYBRIDPlugin_Hypothesis::SetRemoveLogOnSuccess(bool removeLogOnSuccess)
704 if ( myRemoveLogOnSuccess != removeLogOnSuccess ) {
705 myRemoveLogOnSuccess = removeLogOnSuccess;
706 NotifySubMeshesHypothesisModification();
710 //=======================================================================
711 //function : GetRemoveLogOnSuccess
712 //=======================================================================
714 bool HYBRIDPlugin_Hypothesis::GetRemoveLogOnSuccess() const
716 return myRemoveLogOnSuccess;
719 //=======================================================================
720 //function : SetEnforcedVertex
721 //=======================================================================
723 bool HYBRIDPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string theEntry, std::string theGroupName,
724 double size, double x, double y, double z, bool isCompound)
726 bool toNotify = false;
727 bool toCreate = true;
729 THYBRIDEnforcedVertex *oldEnVertex;
730 THYBRIDEnforcedVertex *newEnfVertex = new THYBRIDEnforcedVertex();
731 newEnfVertex->name = theName;
732 newEnfVertex->geomEntry = theEntry;
733 newEnfVertex->coords.clear();
735 newEnfVertex->coords.push_back(x);
736 newEnfVertex->coords.push_back(y);
737 newEnfVertex->coords.push_back(z);
739 newEnfVertex->groupName = theGroupName;
740 newEnfVertex->size = size;
741 newEnfVertex->isCompound = isCompound;
744 // update _enfVertexList
745 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(newEnfVertex);
746 if (it != _enfVertexList.end()) {
749 if (oldEnVertex->name != theName) {
750 oldEnVertex->name = theName;
753 if (oldEnVertex->groupName != theGroupName) {
754 oldEnVertex->groupName = theGroupName;
757 if (oldEnVertex->size != size) {
758 oldEnVertex->size = size;
762 // update map coords / enf vertex if needed
763 if (oldEnVertex->coords.size()) {
764 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
765 _enfVertexCoordsSizeList[oldEnVertex->coords] = size;
768 // update map geom entry / enf vertex if needed
769 if (oldEnVertex->geomEntry != "") {
770 _geomEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
771 _enfVertexEntrySizeList[oldEnVertex->geomEntry] = size;
776 // //////// CREATE ////////////
779 _enfVertexList.insert(newEnfVertex);
780 if (theEntry == "") {
781 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
782 _enfVertexCoordsSizeList[newEnfVertex->coords] = size;
785 _geomEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
786 _enfVertexEntrySizeList[newEnfVertex->geomEntry] = size;
791 NotifySubMeshesHypothesisModification();
797 //=======================================================================
798 //function : SetEnforcedMesh
799 //=======================================================================
800 bool HYBRIDPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName)
802 TIDSortedElemSet theElemSet;
803 SMDS_ElemIteratorPtr eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType));
804 while ( eIt->more() )
805 theElemSet.insert( eIt->next() );
806 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
808 THYBRIDEnforcedMesh* newEnfMesh = new THYBRIDEnforcedMesh();
809 newEnfMesh->persistID = theMesh.GetMeshDS()->GetPersistentId();
810 newEnfMesh->name = name;
811 newEnfMesh->entry = entry;
812 newEnfMesh->elementType = elementType;
813 newEnfMesh->groupName = groupName;
815 THYBRIDEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
816 if (it == _enfMeshList.end()) {
817 _entryEnfMeshMap[entry].insert(newEnfMesh);
818 _enfMeshList.insert(newEnfMesh);
827 //=======================================================================
828 //function : SetEnforcedGroup
829 //=======================================================================
830 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)
832 TIDSortedElemSet theElemSet;
833 if ( theIDs->length() == 0 ){MESSAGE("The source group is empty");}
834 for ( CORBA::ULong i = 0; i < theIDs->length(); i++) {
835 CORBA::Long ind = theIDs[i];
836 if (elementType == SMESH::NODE)
838 const SMDS_MeshNode * node = theMeshDS->FindNode(ind);
840 theElemSet.insert( node );
844 const SMDS_MeshElement * elem = theMeshDS->FindElement(ind);
846 theElemSet.insert( elem );
850 // SMDS_ElemIteratorPtr it = theGroup->GetGroupDS()->GetElements();
851 // while ( it->more() )
852 // theElemSet.insert( it->next() );
854 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
856 THYBRIDEnforcedMesh* newEnfMesh = new THYBRIDEnforcedMesh();
857 newEnfMesh->name = name;
858 newEnfMesh->entry = entry;
859 newEnfMesh->elementType = elementType;
860 newEnfMesh->groupName = groupName;
862 THYBRIDEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
863 if (it == _enfMeshList.end()) {
864 _entryEnfMeshMap[entry].insert(newEnfMesh);
865 _enfMeshList.insert(newEnfMesh);
871 //=======================================================================
872 //function : SetEnforcedElements
873 //=======================================================================
874 bool HYBRIDPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName)
876 TIDSortedElemSet::const_iterator it = theElemSet.begin();
877 const SMDS_MeshElement* elem;
878 const SMDS_MeshNode* node;
880 std::pair<TIDSortedNodeGroupMap::iterator,bool> nodeRet;
881 std::pair<TIDSortedElemGroupMap::iterator,bool> elemRet;
883 for (;it != theElemSet.end();++it)
886 switch (elementType) {
888 node = dynamic_cast<const SMDS_MeshNode*>(elem);
890 nodeRet = _enfNodes.insert(make_pair(node,groupName));
891 added = added && nodeRet.second;
892 std::string msg = added ? "yes":"no";
895 SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
896 for (;nodeIt->more();) {
897 node = dynamic_cast<const SMDS_MeshNode*>(nodeIt->next());
898 nodeRet = _enfNodes.insert(make_pair(node,groupName));
899 added = added && nodeRet.second;
905 if (elem->GetType() == SMDSAbs_Edge) {
906 elemRet = _enfEdges.insert(make_pair(elem,groupName));
907 added = added && elemRet.second;
911 if (elem->GetType() == SMDSAbs_Face)
913 if (elem->NbCornerNodes() == 3) {
914 elemRet = _enfTriangles.insert(make_pair(elem,groupName));
915 added = added && elemRet.second;
924 NotifySubMeshesHypothesisModification();
929 //=======================================================================
930 //function : GetEnforcedVertex
931 //=======================================================================
933 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z)
934 throw (std::invalid_argument)
936 std::vector<double> coord(3);
940 if (_coordsEnfVertexMap.count(coord)>0)
941 return _coordsEnfVertexMap[coord];
942 std::ostringstream msg ;
943 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
944 throw std::invalid_argument(msg.str());
947 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(const std::string theEntry)
948 throw (std::invalid_argument)
950 if (_geomEntryEnfVertexMap.count(theEntry)>0)
951 return _geomEntryEnfVertexMap[theEntry];
953 std::ostringstream msg ;
954 msg << "No enforced vertex with entry " << theEntry;
955 throw std::invalid_argument(msg.str());
958 //=======================================================================
959 //function : RemoveEnforcedVertex
960 //=======================================================================
962 bool HYBRIDPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, const std::string theEntry)
963 throw (std::invalid_argument)
965 bool toNotify = false;
966 std::ostringstream msg;
967 THYBRIDEnforcedVertex *oldEnfVertex;
968 std::vector<double> coords(3);
973 // check that enf vertex with given enf vertex entry exists
974 TGeomEntryHYBRIDEnforcedVertexMap::iterator it_enfVertexEntry = _geomEntryEnfVertexMap.find(theEntry);
975 if (it_enfVertexEntry != _geomEntryEnfVertexMap.end()) {
977 oldEnfVertex = it_enfVertexEntry->second;
978 _geomEntryEnfVertexMap.erase(it_enfVertexEntry);
981 // check that enf vertex with given coords exists
982 TCoordsHYBRIDEnforcedVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
983 if (it_coords_enf != _coordsEnfVertexMap.end()) {
985 oldEnfVertex = it_coords_enf->second;
986 _coordsEnfVertexMap.erase(it_coords_enf);
987 _enfVertexCoordsSizeList.erase(_enfVertexCoordsSizeList.find(coords));
990 throw std::invalid_argument(msg.str());
995 // update _enfVertexList
996 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
997 if (it != _enfVertexList.end()) {
998 if ((*it)->groupName != "")
999 _groupsToRemove.insert((*it)->groupName);
1000 _enfVertexList.erase(it);
1005 NotifySubMeshesHypothesisModification();
1010 //=======================================================================
1011 //function : ClearEnforcedVertices
1012 //=======================================================================
1013 void HYBRIDPlugin_Hypothesis::ClearEnforcedVertices()
1015 THYBRIDEnforcedVertexList::const_iterator it = _enfVertexList.begin();
1016 for(;it != _enfVertexList.end();++it) {
1017 if ((*it)->groupName != "")
1018 _groupsToRemove.insert((*it)->groupName);
1020 _enfVertexList.clear();
1021 _coordsEnfVertexMap.clear();
1022 _geomEntryEnfVertexMap.clear();
1023 _enfVertexCoordsSizeList.clear();
1024 _enfVertexEntrySizeList.clear();
1025 NotifySubMeshesHypothesisModification();
1028 //=======================================================================
1029 //function : ClearEnforcedMeshes
1030 //=======================================================================
1031 void HYBRIDPlugin_Hypothesis::ClearEnforcedMeshes()
1033 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
1034 for(;it != _enfMeshList.end();++it) {
1035 if ((*it)->groupName != "")
1036 _groupsToRemove.insert((*it)->groupName);
1040 _enfTriangles.clear();
1041 _nodeIDToSizeMap.clear();
1042 _enfMeshList.clear();
1043 _entryEnfMeshMap.clear();
1044 NotifySubMeshesHypothesisModification();
1047 //================================================================================
1049 * \brief At mesh loading, restore enforced elements by just loaded enforced meshes
1051 //================================================================================
1053 void HYBRIDPlugin_Hypothesis::RestoreEnfElemsByMeshes()
1055 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
1056 for(;it != _enfMeshList.end();++it) {
1057 THYBRIDEnforcedMesh* enfMesh = *it;
1058 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
1059 SetEnforcedMesh( *mesh,
1060 enfMesh->elementType,
1063 enfMesh->groupName );
1064 enfMesh->persistID = -1; // not to restore again
1068 //=======================================================================
1069 //function : SetGroupsToRemove
1070 //=======================================================================
1072 void HYBRIDPlugin_Hypothesis::ClearGroupsToRemove()
1074 _groupsToRemove.clear();
1078 //=======================================================================
1079 //function : DefaultLayersOnAllWrap
1080 //=======================================================================
1082 bool HYBRIDPlugin_Hypothesis::DefaultLayersOnAllWrap()
1087 //=======================================================================
1088 //function : DefaultMeshHoles
1089 //=======================================================================
1091 bool HYBRIDPlugin_Hypothesis::DefaultMeshHoles()
1093 return false; // PAL19680
1096 //=======================================================================
1097 //function : DefaultToMakeGroupsOfDomains
1098 //=======================================================================
1100 bool HYBRIDPlugin_Hypothesis::DefaultToMakeGroupsOfDomains()
1102 return false; // issue 0022172
1105 //=======================================================================
1106 //function : DefaultMaximumMemory
1107 //=======================================================================
1110 #include <windows.h>
1111 #elif !defined(__APPLE__)
1112 #include <sys/sysinfo.h>
1115 double HYBRIDPlugin_Hypothesis::DefaultMaximumMemory()
1118 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
1119 MEMORYSTATUSEX statex;
1120 statex.dwLength = sizeof (statex);
1121 int err = GlobalMemoryStatusEx (&statex);
1124 statex.ullTotalPhys / 1024 / 1024 +
1125 statex.ullTotalPageFile / 1024 / 1024 +
1126 statex.ullTotalVirtual / 1024 / 1024;
1127 return ( 0.7 * totMB );
1129 #elif !defined(__APPLE__)
1131 int err = sysinfo( &si );
1133 int ramMB = si.totalram * si.mem_unit / 1024 / 1024;
1134 return ( 0.7 * ramMB );
1140 //=======================================================================
1141 //function : DefaultInitialMemory
1142 //=======================================================================
1144 double HYBRIDPlugin_Hypothesis::DefaultInitialMemory()
1146 return DefaultMaximumMemory();
1149 //=======================================================================
1150 //function : DefaultCollisionMode
1151 //=======================================================================
1152 short HYBRIDPlugin_Hypothesis::DefaultCollisionMode()
1157 //=======================================================================
1158 //function : DefaultBoundaryLayersGrowth
1159 //=======================================================================
1160 short HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersGrowth()
1162 return Layer_Growth_Inward;
1165 //=======================================================================
1166 //function : DefaultElementGeneration
1167 //=======================================================================
1168 short HYBRIDPlugin_Hypothesis::DefaultElementGeneration()
1170 return Generation_Tetra_Dominant;
1173 //=======================================================================
1174 //function : DefaultOptimizationLevel
1175 //=======================================================================
1176 short HYBRIDPlugin_Hypothesis::DefaultOptimizationLevel()
1181 //=======================================================================
1182 //function : DefaultWorkingDirectory
1183 //=======================================================================
1185 std::string HYBRIDPlugin_Hypothesis::DefaultWorkingDirectory()
1187 std::string aTmpDir;
1189 char *Tmp_dir = getenv("SALOME_TMP_DIR");
1190 if(Tmp_dir != NULL) {
1203 //=======================================================================
1204 //function : DefaultKeepFiles
1205 //=======================================================================
1207 bool HYBRIDPlugin_Hypothesis::DefaultKeepFiles()
1212 //=======================================================================
1213 //function : DefaultRemoveLogOnSuccess
1214 //=======================================================================
1216 bool HYBRIDPlugin_Hypothesis::DefaultRemoveLogOnSuccess()
1222 //=======================================================================
1223 //function : DefaultVerboseLevel
1224 //=======================================================================
1226 short HYBRIDPlugin_Hypothesis::DefaultVerboseLevel()
1231 //=======================================================================
1232 //function : DefaultToCreateNewNodes
1233 //=======================================================================
1235 bool HYBRIDPlugin_Hypothesis::DefaultToCreateNewNodes()
1240 //=======================================================================
1241 //function : DefaultToUseBoundaryRecoveryVersion
1242 //=======================================================================
1244 bool HYBRIDPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
1249 //=======================================================================
1250 //function : DefaultToUseFEMCorrection
1251 //=======================================================================
1253 bool HYBRIDPlugin_Hypothesis::DefaultToUseFEMCorrection()
1258 //=======================================================================
1259 //function : DefaultToRemoveCentralPoint
1260 //=======================================================================
1262 bool HYBRIDPlugin_Hypothesis::DefaultToRemoveCentralPoint()
1267 //=======================================================================
1268 //function : DefaultGradation
1269 //=======================================================================
1271 double HYBRIDPlugin_Hypothesis::DefaultGradation()
1276 //=======================================================================
1277 //function : DefaultStandardOutputLog
1278 //=======================================================================
1280 bool HYBRIDPlugin_Hypothesis::DefaultStandardOutputLog()
1285 // //=======================================================================
1286 // //function : DefaultID2SizeMap
1287 // //=======================================================================
1289 // HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::DefaultID2SizeMap()
1291 // return HYBRIDPlugin_Hypothesis::TID2SizeMap();
1294 //=======================================================================
1295 //function : DefaultAddMultinormals
1296 //=======================================================================
1297 bool HYBRIDPlugin_Hypothesis::DefaultAddMultinormals()
1302 //=======================================================================
1303 //function : DefaultSmoothNormals
1304 //=======================================================================
1305 bool HYBRIDPlugin_Hypothesis::DefaultSmoothNormals()
1310 //=======================================================================
1311 //function : DefaultHeightFirstLayer
1312 //=======================================================================
1313 double HYBRIDPlugin_Hypothesis::DefaultHeightFirstLayer()
1315 return 0.0; //or epsilon?
1318 //=======================================================================
1319 //function : DefaultBoundaryLayersProgression
1320 //=======================================================================
1321 double HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersProgression()
1326 //=======================================================================
1327 //function : DefaultCoreSize
1328 //=======================================================================
1329 double HYBRIDPlugin_Hypothesis::DefaultCoreSize()
1334 //=======================================================================
1335 //function : DefaultMultinormalsAngle
1336 //=======================================================================
1337 double HYBRIDPlugin_Hypothesis::DefaultMultinormalsAngle()
1342 //=======================================================================
1343 //function : DefaultNbOfBoundaryLayers
1344 //=======================================================================
1345 short HYBRIDPlugin_Hypothesis::DefaultNbOfBoundaryLayers()
1350 //=======================================================================
1352 //=======================================================================
1354 std::ostream & HYBRIDPlugin_Hypothesis::SaveTo(std::ostream & save)
1356 save << (int) myBoundaryLayersGrowth << " ";
1357 save << (int) myElementGeneration << " ";
1358 save << (int) myAddMultinormals << " ";
1359 save << (int) mySmoothNormals << " ";
1360 save << (int) myLayersOnAllWrap << " ";
1362 save << myNbOfBoundaryLayers << " ";
1363 save << myHeightFirstLayer << " ";
1364 save << myBoundaryLayersProgression << " ";
1365 save << myMultinormalsAngle << " ";
1367 save << (int) myKeepFiles << " ";
1368 save << myWorkingDirectory << " ";
1369 save << myVerboseLevel << " ";
1370 save << myCoreSize << " ";
1372 if (!myTextOption.empty()) {
1373 save << "__OPTIONS_BEGIN__ ";
1374 save << myTextOption << " ";
1375 save << "__OPTIONS_END__ ";
1379 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.begin();
1380 if (it != _enfVertexList.end()) {
1381 save << " " << "__ENFORCED_VERTICES_BEGIN__ ";
1382 for ( ; it != _enfVertexList.end(); ++it ) {
1383 THYBRIDEnforcedVertex *enfVertex = (*it);
1384 save << " " << "__BEGIN_VERTEX__";
1385 if (!enfVertex->name.empty()) {
1386 save << " " << "__BEGIN_NAME__";
1387 save << " " << enfVertex->name;
1388 save << " " << "__END_NAME__";
1390 if (!enfVertex->geomEntry.empty()) {
1391 save << " " << "__BEGIN_ENTRY__";
1392 save << " " << enfVertex->geomEntry;
1393 save << " " << enfVertex->isCompound;
1394 save << " " << "__END_ENTRY__";
1396 if (!enfVertex->groupName.empty()) {
1397 save << " " << "__BEGIN_GROUP__";
1398 save << " " << enfVertex->groupName;
1399 save << " " << "__END_GROUP__";
1401 if (enfVertex->coords.size()) {
1402 save << " " << "__BEGIN_COORDS__";
1403 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1404 save << " " << enfVertex->coords[i];
1405 save << " " << "__END_COORDS__";
1407 save << " " << "__BEGIN_SIZE__";
1408 save << " " << enfVertex->size;
1409 save << " " << "__END_SIZE__";
1410 save << " " << "__END_VERTEX__";
1412 save << " " << "__ENFORCED_VERTICES_END__ ";
1415 THYBRIDEnforcedMeshList::iterator it_mesh = _enfMeshList.begin();
1416 if (it_mesh != _enfMeshList.end()) {
1417 save << " " << "__ENFORCED_MESHES_BEGIN__ ";
1418 for ( ; it_mesh != _enfMeshList.end(); ++it_mesh ) {
1419 THYBRIDEnforcedMesh *enfMesh = (*it_mesh);
1420 save << " " << "__BEGIN_ENF_MESH__";
1422 save << " " << "__BEGIN_NAME__";
1423 save << " " << enfMesh->name;
1424 save << " " << "__END_NAME__";
1426 save << " " << "__BEGIN_ENTRY__";
1427 save << " " << enfMesh->entry;
1428 save << " " << "__END_ENTRY__";
1430 save << " " << "__BEGIN_ELEM_TYPE__";
1431 save << " " << (int)enfMesh->elementType;
1432 save << " " << "__END_ELEM_TYPE__";
1434 if (!enfMesh->groupName.empty()) {
1435 save << " " << "__BEGIN_GROUP__";
1436 save << " " << enfMesh->groupName;
1437 save << " " << "__END_GROUP__";
1439 save << " " << "__PERSIST_ID__";
1440 save << " " << enfMesh->persistID;
1441 save << " " << "__END_ENF_MESH__";
1442 std::cout << "Saving of enforced mesh " << enfMesh->name.c_str() << " done" << std::endl;
1444 save << " " << "__ENFORCED_MESHES_END__ ";
1447 save << " " << myFacesWithLayers.size();
1448 for ( size_t i = 0; i < myFacesWithLayers.size(); ++i )
1449 save << " " << myFacesWithLayers[i];
1451 save << " " << myFacesWithImprinting.size();
1452 for ( size_t i = 0; i < myFacesWithImprinting.size(); ++i )
1453 save << " " << myFacesWithImprinting[i];
1458 //=======================================================================
1459 //function : LoadFrom
1460 //=======================================================================
1462 std::istream & HYBRIDPlugin_Hypothesis::LoadFrom(std::istream & load)
1468 isOK = static_cast<bool>(load >> i);
1470 myBoundaryLayersGrowth = (short) i;
1472 load.clear(ios::badbit | load.rdstate());
1474 isOK = static_cast<bool>(load >> i);
1476 myElementGeneration = (short) i;
1478 load.clear(ios::badbit | load.rdstate());
1480 isOK = static_cast<bool>(load >> i);
1482 myAddMultinormals = (bool) i;
1484 load.clear(ios::badbit | load.rdstate());
1486 isOK = static_cast<bool>(load >> i);
1488 mySmoothNormals = (bool) i;
1490 load.clear(ios::badbit | load.rdstate());
1492 isOK = static_cast<bool>(load >> i);
1494 myLayersOnAllWrap = (bool) i;
1496 load.clear(ios::badbit | load.rdstate());
1498 isOK = static_cast<bool>(load >> i);
1500 myNbOfBoundaryLayers = (short) i;
1502 load.clear(ios::badbit | load.rdstate());
1504 isOK = static_cast<bool>(load >> d);
1506 myHeightFirstLayer = d;
1508 load.clear(ios::badbit | load.rdstate());
1510 isOK = static_cast<bool>(load >> d);
1512 myBoundaryLayersProgression = d;
1514 load.clear(ios::badbit | load.rdstate());
1516 isOK = static_cast<bool>(load >> d);
1518 myMultinormalsAngle = d;
1520 load.clear(ios::badbit | load.rdstate());
1522 isOK = static_cast<bool>(load >> i);
1524 myKeepFiles = (bool) i;
1526 load.clear(ios::badbit | load.rdstate());
1528 isOK = static_cast<bool>(load >> myWorkingDirectory);
1530 if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
1531 myKeepFiles = false;
1532 myWorkingDirectory.clear();
1534 else if ( myWorkingDirectory == "1" ) {
1536 myWorkingDirectory.clear();
1540 load.clear(ios::badbit | load.rdstate());
1542 isOK = static_cast<bool>(load >> i);
1544 myVerboseLevel = (short) i;
1546 load.clear(ios::badbit | load.rdstate());
1548 isOK = static_cast<bool>(load >> d);
1552 load.clear(ios::badbit | load.rdstate());
1554 std::string separator;
1555 bool hasOptions = false;
1556 bool hasEnforcedVertices = false;
1557 bool hasEnforcedMeshes = false;
1558 isOK = static_cast<bool>(load >> separator);
1560 if ( isOK && ( separator == "0" || separator == "1" ))
1562 myToMakeGroupsOfDomains = ( separator == "1" );
1563 isOK = static_cast<bool>(load >> separator);
1567 if (separator == "__OPTIONS_BEGIN__")
1569 else if (separator == "__ENFORCED_VERTICES_BEGIN__")
1570 hasEnforcedVertices = true;
1571 else if (separator == "__ENFORCED_MESHES_BEGIN__")
1572 hasEnforcedMeshes = true;
1578 isOK = static_cast<bool>(load >> txt);
1580 if (txt == "__OPTIONS_END__") {
1581 if (!myTextOption.empty()) {
1582 // Remove last space
1583 myTextOption.erase(myTextOption.end()-1);
1588 myTextOption += txt;
1589 myTextOption += " ";
1595 isOK = static_cast<bool>(load >> separator);
1596 if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__")
1597 hasEnforcedVertices = true;
1598 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1599 hasEnforcedMeshes = true;
1602 if (hasEnforcedVertices) {
1603 std::string txt, name, entry, groupName;
1604 double size, coords[3];
1606 bool hasCoords = false;
1607 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1609 if (txt == "__ENFORCED_VERTICES_END__")
1612 THYBRIDEnforcedVertex *enfVertex = new THYBRIDEnforcedVertex();
1614 isOK = static_cast<bool>(load >> txt);
1615 if (txt == "__END_VERTEX__") {
1616 enfVertex->name = name;
1617 enfVertex->geomEntry = entry;
1618 enfVertex->isCompound = isCompound;
1619 enfVertex->groupName = groupName;
1620 enfVertex->coords.clear();
1622 enfVertex->coords.assign(coords,coords+3);
1624 _enfVertexList.insert(enfVertex);
1626 if (enfVertex->coords.size())
1627 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1628 if (!enfVertex->geomEntry.empty())
1629 _geomEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1638 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1639 while (isOK && (txt != "__END_NAME__")) {
1640 isOK = static_cast<bool>(load >> txt);
1641 if (txt != "__END_NAME__") {
1649 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1650 isOK = static_cast<bool>(load >> entry);
1651 isOK = static_cast<bool>(load >> isCompound);
1652 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1653 if (txt != "__END_ENTRY__")
1654 throw std::exception();
1657 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1658 while (isOK && (txt != "__END_GROUP__")) {
1659 isOK = static_cast<bool>(load >> txt);
1660 if (txt != "__END_GROUP__") {
1661 if (!groupName.empty())
1668 if (txt == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1670 isOK = static_cast<bool>(load >> coords[0] >> coords[1] >> coords[2]);
1671 isOK = static_cast<bool>(load >> txt); // __END_COORDS__
1672 if (txt != "__END_COORDS__")
1673 throw std::exception();
1676 if (txt == "__BEGIN_SIZE__") { // __BEGIN_ENTRY__
1677 isOK = static_cast<bool>(load >> size);
1678 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1679 if (txt != "__END_SIZE__") {
1680 throw std::exception();
1684 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1688 if (hasEnforcedVertices) {
1689 isOK = static_cast<bool>(load >> separator);
1690 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1691 hasEnforcedMeshes = true;
1694 if (hasEnforcedMeshes) {
1695 std::string txt, name, entry, groupName;
1696 int elementType = -1, persistID = -1;
1697 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1700 if (txt == "__ENFORCED_MESHES_END__")
1703 THYBRIDEnforcedMesh *enfMesh = new THYBRIDEnforcedMesh();
1705 isOK = static_cast<bool>(load >> txt);
1706 if (txt == "__END_ENF_MESH__") {
1707 enfMesh->name = name;
1708 enfMesh->entry = entry;
1709 enfMesh->elementType = (SMESH::ElementType)elementType;
1710 enfMesh->groupName = groupName;
1711 enfMesh->persistID = persistID;
1713 _enfMeshList.insert(enfMesh);
1714 std::cout << "Restoring of enforced mesh " <<name << " done" << std::endl;
1724 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1725 while (isOK && (txt != "__END_NAME__")) {
1726 isOK = static_cast<bool>(load >> txt);
1727 if (txt != "__END_NAME__") {
1735 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1736 isOK = static_cast<bool>(load >> entry);
1737 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1738 if (txt != "__END_ENTRY__")
1739 throw std::exception();
1742 if (txt == "__BEGIN_ELEM_TYPE__") { // __BEGIN_ELEM_TYPE__
1743 isOK = static_cast<bool>(load >> elementType);
1744 isOK = static_cast<bool>(load >> txt); // __END_ELEM_TYPE__
1745 if (txt != "__END_ELEM_TYPE__")
1746 throw std::exception();
1749 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1750 while (isOK && (txt != "__END_GROUP__")) {
1751 isOK = static_cast<bool>(load >> txt);
1752 if (txt != "__END_GROUP__") {
1753 if (!groupName.empty())
1760 if (txt == "__PERSIST_ID__") {
1761 isOK = static_cast<bool>(load >> persistID);
1763 std::cout << "isOK: " << isOK << std::endl;
1766 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1770 if ( hasEnforcedMeshes )
1771 isOK = static_cast<bool>(load >> separator);
1775 i = atoi( separator.c_str() );
1779 myFacesWithLayers.reserve( i );
1780 while (( myFacesWithLayers.size() < myFacesWithLayers.capacity() ) &&
1781 ( isOK = static_cast<bool>(load >> i)) )
1782 myFacesWithLayers.push_back( i );
1786 isOK = static_cast<bool>(load >> separator);
1789 i = atoi( separator.c_str() );
1793 myFacesWithImprinting.reserve( i );
1794 while (( myFacesWithImprinting.size() < myFacesWithImprinting.capacity() ) &&
1795 ( isOK = static_cast<bool>(load >> i)) )
1796 myFacesWithImprinting.push_back( i );
1803 //=======================================================================
1804 //function : SetParametersByMesh
1805 //=======================================================================
1807 bool HYBRIDPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
1813 //================================================================================
1815 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
1817 //================================================================================
1819 bool HYBRIDPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
1820 const SMESH_Mesh* /*theMesh*/)
1822 myToMakeGroupsOfDomains = ( !dflts._shape || dflts._shape->IsNull() );
1826 //================================================================================
1828 * \brief Return command to run hybrid mesher excluding file prefix (-f)
1830 //================================================================================
1832 std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis* hyp,
1835 SMESH_Comment cmd = GetExeName();
1836 // check if any option is overridden by hyp->myTextOption
1837 bool p_h = ( hyp && hyp->myTextOption.find("-h") != std::string::npos );
1838 bool p_v = ( hyp && hyp->myTextOption.find("-v") != std::string::npos );
1839 bool p_i = ( hyp && hyp->myTextOption.find("-i") != std::string::npos );
1840 bool p_o = ( hyp && hyp->myTextOption.find("-o") != std::string::npos );
1841 bool p_mnot = ( hyp && hyp->myTextOption.find("--max_number_of_threads ") != std::string::npos );
1842 bool p_blsi = ( hyp && hyp->myTextOption.find("--boundary_layer_surface_tags ") != std::string::npos );
1843 bool p_blii = ( hyp && hyp->myTextOption.find("--boundary_layer_imprint_tags ") != std::string::npos );
1844 bool p_blsd = ( hyp && hyp->myTextOption.find("--normal_direction ") != std::string::npos );
1845 bool p_hotfl = ( hyp && hyp->myTextOption.find("--boundary_layer_global_initial_height ") != std::string::npos );
1846 bool p_nobl = ( hyp && hyp->myTextOption.find("--number_of_boundary_layers ") != std::string::npos );
1847 bool p_blgp = ( hyp && hyp->myTextOption.find("--boundary_layer_geometric_progression ") != std::string::npos );
1848 bool p_eg = ( hyp && hyp->myTextOption.find("--element_generation ") != std::string::npos );
1849 bool p_cm = ( hyp && hyp->myTextOption.find("--collision_mode ") != std::string::npos );
1850 bool p_am = ( hyp && hyp->myTextOption.find("--add_multinormals ") != std::string::npos );
1851 bool p_cs = ( hyp && hyp->myTextOption.find("--global_physical_size ") != std::string::npos );
1852 bool p_mat = ( hyp && hyp->myTextOption.find("--multinormal_angle_threshold ") != std::string::npos );
1853 bool p_sn = ( hyp && hyp->myTextOption.find("--smooth_normals ") != std::string::npos );
1856 //- boundary_layer_max_element_angle
1858 bool nolayers = false;
1859 bool layersOnAllWrap = hyp ? hyp->myLayersOnAllWrap : DefaultLayersOnAllWrap();
1867 std::cout << "!!!!! CommandToRun help only !!!! " << cmd << std::endl;
1872 cmd << " --verbose " << hyp->myVerboseLevel;
1874 if ( !p_mnot && hyp )
1875 cmd << " --max_number_of_threads " << 8; //TODO getenv NB CPU
1878 if ( !p_nobl && hyp ) {
1879 if ( hyp->myNbOfBoundaryLayers < 1 ) nolayers = true;
1881 if ( !p_hotfl && hyp ) {
1882 if ( hyp->myHeightFirstLayer < 1e-50 ) nolayers = true;
1885 if ( !p_blsd && hyp ) {
1886 if ( hyp->myBoundaryLayersGrowth >= 0 && hyp->myBoundaryLayersGrowth <= 1 ) {
1887 const char* value[] = { "-1" , "1" }; // -1 == inside
1888 cmd << " --normal_direction " << value[ hyp->myBoundaryLayersGrowth ];
1892 if ( !p_hotfl && hyp ) {
1893 cmd << " --boundary_layer_global_initial_height " << hyp->myHeightFirstLayer;
1896 if ( !p_nobl && hyp ) {
1897 cmd << " --number_of_boundary_layers " << ( nolayers ? 0 : hyp->myNbOfBoundaryLayers );
1900 if ( !p_blgp && hyp ) {
1901 cmd << " --boundary_layer_geometric_progression " << hyp->myBoundaryLayersProgression;
1904 if ( !nolayers && hyp )
1906 cmd << " --boundary_layer_size_mode " << ( layersOnAllWrap ? "global" : "local" );
1908 if ( !layersOnAllWrap )
1910 // faces with layers
1911 const std::vector<int>& faceLayersIDs = hyp->GetFacesWithLayers();
1912 if ( !faceLayersIDs.empty() )
1913 cmd << " --boundary_layer_surface_tags ";
1914 for ( size_t i = 0; i < faceLayersIDs.size(); ++i )
1915 cmd << faceLayersIDs[i] << ",";
1916 if ( !faceLayersIDs.empty() )
1917 cmd << " --boundary_layer_initial_height_on_surface_tags ";
1918 for ( size_t i = 0; i < faceLayersIDs.size(); ++i )
1919 cmd << hyp->myHeightFirstLayer << ",";
1921 // faces with imprinting
1922 const std::vector<int>& faceImprintingIDs = hyp->GetFacesWithImprinting();
1923 if ( !faceImprintingIDs.empty() )
1924 cmd << " --boundary_layer_imprinting yes --boundary_layer_imprinting_tags ";
1925 for ( size_t i = 0; i < faceImprintingIDs.size(); ++i )
1926 cmd << faceImprintingIDs[i] << ",";
1930 if ( !p_eg && hyp ) {
1931 if ( hyp->myElementGeneration >= 0 && hyp->myElementGeneration <= 2 ) {
1932 const char* value[] = { "tetra-dominant" , "hexa-dominant", "cartesian_core" };
1933 cmd << " --element_generation " << value[ hyp->myElementGeneration ];
1937 if ( !p_cs && hyp ) {
1938 if ( hyp->myCoreSize >= 0 ) {
1939 cmd << " --global_physical_size " << hyp->myCoreSize;
1943 if ( !p_cm && hyp ) {
1944 if ( hyp->myCollisionMode >= 0 && hyp->myCollisionMode <= 1 ) {
1945 const char* value[] = { "decrease" , "stop" };
1946 cmd << " --collision_mode " << value[ hyp->myCollisionMode ];
1950 if ( !p_am && hyp ) {
1951 int res = hyp->myAddMultinormals ? 0 : 1 ;
1952 const char* value[] = { "yes" , "no" };
1953 cmd << " --add_multinormals " << value[ res ];
1956 if ( !p_mat && hyp ) {
1957 cmd << " --multinormal_angle_threshold " << hyp->myMultinormalsAngle;
1960 if ( !p_sn && hyp ) {
1961 int res = hyp->mySmoothNormals ? 0 : 1 ;
1962 const char* value[] = { "yes" , "no" };
1963 cmd << " --smooth_normals " << value[ res ];
1967 if ( hyp && !hyp->myTextOption.empty() ) {
1968 cmd += " " + hyp->myTextOption;
1973 //std::cout << "!!!!!CommandToRun end " << cmd << std::endl;
1978 //================================================================================
1980 * \brief Return a unique file name
1982 //================================================================================
1984 std::string HYBRIDPlugin_Hypothesis::GetFileName(const HYBRIDPlugin_Hypothesis* hyp)
1986 std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
1987 const char lastChar = *aTmpDir.rbegin();
1989 if(lastChar != '\\') aTmpDir+='\\';
1991 if(lastChar != '/') aTmpDir+='/';
1994 SMESH_Comment aGenericName = aTmpDir;
1995 aGenericName << "HYBRID_";
1996 aGenericName << getpid();
1997 aGenericName << "_";
1998 aGenericName << Abs((Standard_Integer)(long) aGenericName.c_str());
2000 return aGenericName;
2003 //================================================================================
2005 * Return the name of executable
2007 //================================================================================
2009 std::string HYBRIDPlugin_Hypothesis::GetExeName()
2011 //call mg-hybrid.bash is script which assumes new project version(s) mg-hybrid.exe in the prerequisite base and special? licence.
2013 return "mg-hybrid.exe";
2015 return "mg-hybrid.bash";
2019 //================================================================================
2021 * \brief Return the enforced vertices
2023 //================================================================================
2025 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexList HYBRIDPlugin_Hypothesis::GetEnforcedVertices(const HYBRIDPlugin_Hypothesis* hyp)
2027 return hyp ? hyp->_GetEnforcedVertices():DefaultHYBRIDEnforcedVertexList();
2030 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesCoordsSize (const HYBRIDPlugin_Hypothesis* hyp)
2032 return hyp ? hyp->_GetEnforcedVerticesCoordsSize(): DefaultHYBRIDEnforcedVertexCoordsValues();
2035 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexEntryValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesEntrySize (const HYBRIDPlugin_Hypothesis* hyp)
2037 return hyp ? hyp->_GetEnforcedVerticesEntrySize(): DefaultHYBRIDEnforcedVertexEntryValues();
2040 HYBRIDPlugin_Hypothesis::TCoordsHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByCoords (const HYBRIDPlugin_Hypothesis* hyp)
2042 return hyp ? hyp->_GetEnforcedVerticesByCoords(): DefaultCoordsHYBRIDEnforcedVertexMap();
2045 HYBRIDPlugin_Hypothesis::TGeomEntryHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByEntry (const HYBRIDPlugin_Hypothesis* hyp)
2047 return hyp ? hyp->_GetEnforcedVerticesByEntry(): DefaultGeomEntryHYBRIDEnforcedVertexMap();
2050 HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedNodes(const HYBRIDPlugin_Hypothesis* hyp)
2052 return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeGroupMap();
2055 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedEdges(const HYBRIDPlugin_Hypothesis* hyp)
2057 return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemGroupMap();
2060 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(const HYBRIDPlugin_Hypothesis* hyp)
2062 return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemGroupMap();
2065 HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp)
2067 return hyp ? hyp->_GetNodeIDToSizeMap(): DefaultID2SizeMap();
2070 HYBRIDPlugin_Hypothesis::TSetStrings HYBRIDPlugin_Hypothesis::GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp)
2072 return hyp ? hyp->_GetGroupsToRemove(): DefaultGroupsToRemove();