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 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;
909 else if (elem->GetType() > SMDSAbs_Edge) {
910 SMDS_ElemIteratorPtr it = elem->edgesIterator();
912 const SMDS_MeshElement* anEdge = it->next();
913 elemRet = _enfEdges.insert(make_pair(anEdge,groupName));
914 added = added && elemRet.second;
919 if (elem->GetType() == SMDSAbs_Face)
921 if (elem->NbCornerNodes() == 3) {
922 elemRet = _enfTriangles.insert(make_pair(elem,groupName));
923 added = added && elemRet.second;
926 else if (elem->GetType() > SMDSAbs_Face) { // Group of faces
927 SMDS_ElemIteratorPtr it = elem->facesIterator();
929 const SMDS_MeshElement* aFace = it->next();
930 if (aFace->NbCornerNodes() == 3) {
931 elemRet = _enfTriangles.insert(make_pair(aFace,groupName));
932 added = added && elemRet.second;
942 NotifySubMeshesHypothesisModification();
947 //=======================================================================
948 //function : GetEnforcedVertex
949 //=======================================================================
951 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z)
952 throw (std::invalid_argument)
954 std::vector<double> coord(3);
958 if (_coordsEnfVertexMap.count(coord)>0)
959 return _coordsEnfVertexMap[coord];
960 std::ostringstream msg ;
961 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
962 throw std::invalid_argument(msg.str());
965 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(const std::string theEntry)
966 throw (std::invalid_argument)
968 if (_geomEntryEnfVertexMap.count(theEntry)>0)
969 return _geomEntryEnfVertexMap[theEntry];
971 std::ostringstream msg ;
972 msg << "No enforced vertex with entry " << theEntry;
973 throw std::invalid_argument(msg.str());
976 //=======================================================================
977 //function : RemoveEnforcedVertex
978 //=======================================================================
980 bool HYBRIDPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, const std::string theEntry)
981 throw (std::invalid_argument)
983 bool toNotify = false;
984 std::ostringstream msg;
985 THYBRIDEnforcedVertex *oldEnfVertex;
986 std::vector<double> coords(3);
991 // check that enf vertex with given enf vertex entry exists
992 TGeomEntryHYBRIDEnforcedVertexMap::iterator it_enfVertexEntry = _geomEntryEnfVertexMap.find(theEntry);
993 if (it_enfVertexEntry != _geomEntryEnfVertexMap.end()) {
995 oldEnfVertex = it_enfVertexEntry->second;
996 _geomEntryEnfVertexMap.erase(it_enfVertexEntry);
999 // check that enf vertex with given coords exists
1000 TCoordsHYBRIDEnforcedVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1001 if (it_coords_enf != _coordsEnfVertexMap.end()) {
1003 oldEnfVertex = it_coords_enf->second;
1004 _coordsEnfVertexMap.erase(it_coords_enf);
1005 _enfVertexCoordsSizeList.erase(_enfVertexCoordsSizeList.find(coords));
1008 throw std::invalid_argument(msg.str());
1013 // update _enfVertexList
1014 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1015 if (it != _enfVertexList.end()) {
1016 if ((*it)->groupName != "")
1017 _groupsToRemove.insert((*it)->groupName);
1018 _enfVertexList.erase(it);
1023 NotifySubMeshesHypothesisModification();
1028 //=======================================================================
1029 //function : ClearEnforcedVertices
1030 //=======================================================================
1031 void HYBRIDPlugin_Hypothesis::ClearEnforcedVertices()
1033 THYBRIDEnforcedVertexList::const_iterator it = _enfVertexList.begin();
1034 for(;it != _enfVertexList.end();++it) {
1035 if ((*it)->groupName != "")
1036 _groupsToRemove.insert((*it)->groupName);
1038 _enfVertexList.clear();
1039 _coordsEnfVertexMap.clear();
1040 _geomEntryEnfVertexMap.clear();
1041 _enfVertexCoordsSizeList.clear();
1042 _enfVertexEntrySizeList.clear();
1043 NotifySubMeshesHypothesisModification();
1046 //=======================================================================
1047 //function : ClearEnforcedMeshes
1048 //=======================================================================
1049 void HYBRIDPlugin_Hypothesis::ClearEnforcedMeshes()
1051 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
1052 for(;it != _enfMeshList.end();++it) {
1053 if ((*it)->groupName != "")
1054 _groupsToRemove.insert((*it)->groupName);
1058 _enfTriangles.clear();
1059 _nodeIDToSizeMap.clear();
1060 _enfMeshList.clear();
1061 _entryEnfMeshMap.clear();
1062 NotifySubMeshesHypothesisModification();
1065 //================================================================================
1067 * \brief At mesh loading, restore enforced elements by just loaded enforced meshes
1069 //================================================================================
1071 void HYBRIDPlugin_Hypothesis::RestoreEnfElemsByMeshes()
1073 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
1074 for(;it != _enfMeshList.end();++it) {
1075 THYBRIDEnforcedMesh* enfMesh = *it;
1076 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
1077 SetEnforcedMesh( *mesh,
1078 enfMesh->elementType,
1081 enfMesh->groupName );
1082 enfMesh->persistID = -1; // not to restore again
1086 //=======================================================================
1087 //function : SetGroupsToRemove
1088 //=======================================================================
1090 void HYBRIDPlugin_Hypothesis::ClearGroupsToRemove()
1092 _groupsToRemove.clear();
1096 //=======================================================================
1097 //function : DefaultLayersOnAllWrap
1098 //=======================================================================
1100 bool HYBRIDPlugin_Hypothesis::DefaultLayersOnAllWrap()
1105 //=======================================================================
1106 //function : DefaultMeshHoles
1107 //=======================================================================
1109 bool HYBRIDPlugin_Hypothesis::DefaultMeshHoles()
1111 return false; // PAL19680
1114 //=======================================================================
1115 //function : DefaultToMakeGroupsOfDomains
1116 //=======================================================================
1118 bool HYBRIDPlugin_Hypothesis::DefaultToMakeGroupsOfDomains()
1120 return false; // issue 0022172
1123 //=======================================================================
1124 //function : DefaultMaximumMemory
1125 //=======================================================================
1128 #include <windows.h>
1129 #elif !defined(__APPLE__)
1130 #include <sys/sysinfo.h>
1133 double HYBRIDPlugin_Hypothesis::DefaultMaximumMemory()
1136 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
1137 MEMORYSTATUSEX statex;
1138 statex.dwLength = sizeof (statex);
1139 int err = GlobalMemoryStatusEx (&statex);
1142 statex.ullTotalPhys / 1024 / 1024 +
1143 statex.ullTotalPageFile / 1024 / 1024 +
1144 statex.ullTotalVirtual / 1024 / 1024;
1145 return ( 0.7 * totMB );
1147 #elif !defined(__APPLE__)
1149 int err = sysinfo( &si );
1151 int ramMB = si.totalram * si.mem_unit / 1024 / 1024;
1152 return ( 0.7 * ramMB );
1158 //=======================================================================
1159 //function : DefaultInitialMemory
1160 //=======================================================================
1162 double HYBRIDPlugin_Hypothesis::DefaultInitialMemory()
1164 return DefaultMaximumMemory();
1167 //=======================================================================
1168 //function : DefaultCollisionMode
1169 //=======================================================================
1170 short HYBRIDPlugin_Hypothesis::DefaultCollisionMode()
1175 //=======================================================================
1176 //function : DefaultBoundaryLayersGrowth
1177 //=======================================================================
1178 short HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersGrowth()
1180 return Layer_Growth_Inward;
1183 //=======================================================================
1184 //function : DefaultElementGeneration
1185 //=======================================================================
1186 short HYBRIDPlugin_Hypothesis::DefaultElementGeneration()
1188 return Generation_Tetra_Dominant;
1191 //=======================================================================
1192 //function : DefaultOptimizationLevel
1193 //=======================================================================
1194 short HYBRIDPlugin_Hypothesis::DefaultOptimizationLevel()
1199 //=======================================================================
1200 //function : DefaultWorkingDirectory
1201 //=======================================================================
1203 std::string HYBRIDPlugin_Hypothesis::DefaultWorkingDirectory()
1205 std::string aTmpDir;
1207 char *Tmp_dir = getenv("SALOME_TMP_DIR");
1208 if(Tmp_dir != NULL) {
1221 //=======================================================================
1222 //function : DefaultKeepFiles
1223 //=======================================================================
1225 bool HYBRIDPlugin_Hypothesis::DefaultKeepFiles()
1230 //=======================================================================
1231 //function : DefaultRemoveLogOnSuccess
1232 //=======================================================================
1234 bool HYBRIDPlugin_Hypothesis::DefaultRemoveLogOnSuccess()
1240 //=======================================================================
1241 //function : DefaultVerboseLevel
1242 //=======================================================================
1244 short HYBRIDPlugin_Hypothesis::DefaultVerboseLevel()
1249 //=======================================================================
1250 //function : DefaultToCreateNewNodes
1251 //=======================================================================
1253 bool HYBRIDPlugin_Hypothesis::DefaultToCreateNewNodes()
1258 //=======================================================================
1259 //function : DefaultToUseBoundaryRecoveryVersion
1260 //=======================================================================
1262 bool HYBRIDPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
1267 //=======================================================================
1268 //function : DefaultToUseFEMCorrection
1269 //=======================================================================
1271 bool HYBRIDPlugin_Hypothesis::DefaultToUseFEMCorrection()
1276 //=======================================================================
1277 //function : DefaultToRemoveCentralPoint
1278 //=======================================================================
1280 bool HYBRIDPlugin_Hypothesis::DefaultToRemoveCentralPoint()
1285 //=======================================================================
1286 //function : DefaultGradation
1287 //=======================================================================
1289 double HYBRIDPlugin_Hypothesis::DefaultGradation()
1294 //=======================================================================
1295 //function : DefaultStandardOutputLog
1296 //=======================================================================
1298 bool HYBRIDPlugin_Hypothesis::DefaultStandardOutputLog()
1303 // //=======================================================================
1304 // //function : DefaultID2SizeMap
1305 // //=======================================================================
1307 // HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::DefaultID2SizeMap()
1309 // return HYBRIDPlugin_Hypothesis::TID2SizeMap();
1312 //=======================================================================
1313 //function : DefaultAddMultinormals
1314 //=======================================================================
1315 bool HYBRIDPlugin_Hypothesis::DefaultAddMultinormals()
1320 //=======================================================================
1321 //function : DefaultSmoothNormals
1322 //=======================================================================
1323 bool HYBRIDPlugin_Hypothesis::DefaultSmoothNormals()
1328 //=======================================================================
1329 //function : DefaultHeightFirstLayer
1330 //=======================================================================
1331 double HYBRIDPlugin_Hypothesis::DefaultHeightFirstLayer()
1333 return 0.0; //or epsilon?
1336 //=======================================================================
1337 //function : DefaultBoundaryLayersProgression
1338 //=======================================================================
1339 double HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersProgression()
1344 //=======================================================================
1345 //function : DefaultCoreSize
1346 //=======================================================================
1347 double HYBRIDPlugin_Hypothesis::DefaultCoreSize()
1352 //=======================================================================
1353 //function : DefaultMultinormalsAngle
1354 //=======================================================================
1355 double HYBRIDPlugin_Hypothesis::DefaultMultinormalsAngle()
1360 //=======================================================================
1361 //function : DefaultNbOfBoundaryLayers
1362 //=======================================================================
1363 short HYBRIDPlugin_Hypothesis::DefaultNbOfBoundaryLayers()
1368 //=======================================================================
1370 //=======================================================================
1372 std::ostream & HYBRIDPlugin_Hypothesis::SaveTo(std::ostream & save)
1374 save << (int) myBoundaryLayersGrowth << " ";
1375 save << (int) myElementGeneration << " ";
1376 save << (int) myAddMultinormals << " ";
1377 save << (int) mySmoothNormals << " ";
1378 save << (int) myLayersOnAllWrap << " ";
1380 save << myNbOfBoundaryLayers << " ";
1381 save << myHeightFirstLayer << " ";
1382 save << myBoundaryLayersProgression << " ";
1383 save << myMultinormalsAngle << " ";
1385 save << (int) myKeepFiles << " ";
1386 save << myWorkingDirectory << " ";
1387 save << myVerboseLevel << " ";
1388 save << myCoreSize << " ";
1390 if (!myTextOption.empty()) {
1391 save << "__OPTIONS_BEGIN__ ";
1392 save << myTextOption << " ";
1393 save << "__OPTIONS_END__ ";
1397 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.begin();
1398 if (it != _enfVertexList.end()) {
1399 save << " " << "__ENFORCED_VERTICES_BEGIN__ ";
1400 for ( ; it != _enfVertexList.end(); ++it ) {
1401 THYBRIDEnforcedVertex *enfVertex = (*it);
1402 save << " " << "__BEGIN_VERTEX__";
1403 if (!enfVertex->name.empty()) {
1404 save << " " << "__BEGIN_NAME__";
1405 save << " " << enfVertex->name;
1406 save << " " << "__END_NAME__";
1408 if (!enfVertex->geomEntry.empty()) {
1409 save << " " << "__BEGIN_ENTRY__";
1410 save << " " << enfVertex->geomEntry;
1411 save << " " << enfVertex->isCompound;
1412 save << " " << "__END_ENTRY__";
1414 if (!enfVertex->groupName.empty()) {
1415 save << " " << "__BEGIN_GROUP__";
1416 save << " " << enfVertex->groupName;
1417 save << " " << "__END_GROUP__";
1419 if (enfVertex->coords.size()) {
1420 save << " " << "__BEGIN_COORDS__";
1421 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1422 save << " " << enfVertex->coords[i];
1423 save << " " << "__END_COORDS__";
1425 save << " " << "__BEGIN_SIZE__";
1426 save << " " << enfVertex->size;
1427 save << " " << "__END_SIZE__";
1428 save << " " << "__END_VERTEX__";
1430 save << " " << "__ENFORCED_VERTICES_END__ ";
1433 THYBRIDEnforcedMeshList::iterator it_mesh = _enfMeshList.begin();
1434 if (it_mesh != _enfMeshList.end()) {
1435 save << " " << "__ENFORCED_MESHES_BEGIN__ ";
1436 for ( ; it_mesh != _enfMeshList.end(); ++it_mesh ) {
1437 THYBRIDEnforcedMesh *enfMesh = (*it_mesh);
1438 save << " " << "__BEGIN_ENF_MESH__";
1440 save << " " << "__BEGIN_NAME__";
1441 save << " " << enfMesh->name;
1442 save << " " << "__END_NAME__";
1444 save << " " << "__BEGIN_ENTRY__";
1445 save << " " << enfMesh->entry;
1446 save << " " << "__END_ENTRY__";
1448 save << " " << "__BEGIN_ELEM_TYPE__";
1449 save << " " << (int)enfMesh->elementType;
1450 save << " " << "__END_ELEM_TYPE__";
1452 if (!enfMesh->groupName.empty()) {
1453 save << " " << "__BEGIN_GROUP__";
1454 save << " " << enfMesh->groupName;
1455 save << " " << "__END_GROUP__";
1457 save << " " << "__PERSIST_ID__";
1458 save << " " << enfMesh->persistID;
1459 save << " " << "__END_ENF_MESH__";
1460 std::cout << "Saving of enforced mesh " << enfMesh->name.c_str() << " done" << std::endl;
1462 save << " " << "__ENFORCED_MESHES_END__ ";
1465 save << " " << myFacesWithLayers.size();
1466 for ( size_t i = 0; i < myFacesWithLayers.size(); ++i )
1467 save << " " << myFacesWithLayers[i];
1469 save << " " << myFacesWithImprinting.size();
1470 for ( size_t i = 0; i < myFacesWithImprinting.size(); ++i )
1471 save << " " << myFacesWithImprinting[i];
1476 //=======================================================================
1477 //function : LoadFrom
1478 //=======================================================================
1480 std::istream & HYBRIDPlugin_Hypothesis::LoadFrom(std::istream & load)
1486 isOK = static_cast<bool>(load >> i);
1488 myBoundaryLayersGrowth = (short) i;
1490 load.clear(ios::badbit | load.rdstate());
1492 isOK = static_cast<bool>(load >> i);
1494 myElementGeneration = (short) i;
1496 load.clear(ios::badbit | load.rdstate());
1498 isOK = static_cast<bool>(load >> i);
1500 myAddMultinormals = (bool) i;
1502 load.clear(ios::badbit | load.rdstate());
1504 isOK = static_cast<bool>(load >> i);
1506 mySmoothNormals = (bool) i;
1508 load.clear(ios::badbit | load.rdstate());
1510 isOK = static_cast<bool>(load >> i);
1512 myLayersOnAllWrap = (bool) i;
1514 load.clear(ios::badbit | load.rdstate());
1516 isOK = static_cast<bool>(load >> i);
1518 myNbOfBoundaryLayers = (short) i;
1520 load.clear(ios::badbit | load.rdstate());
1522 isOK = static_cast<bool>(load >> d);
1524 myHeightFirstLayer = d;
1526 load.clear(ios::badbit | load.rdstate());
1528 isOK = static_cast<bool>(load >> d);
1530 myBoundaryLayersProgression = d;
1532 load.clear(ios::badbit | load.rdstate());
1534 isOK = static_cast<bool>(load >> d);
1536 myMultinormalsAngle = d;
1538 load.clear(ios::badbit | load.rdstate());
1540 isOK = static_cast<bool>(load >> i);
1542 myKeepFiles = (bool) i;
1544 load.clear(ios::badbit | load.rdstate());
1546 isOK = static_cast<bool>(load >> myWorkingDirectory);
1548 if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
1549 myKeepFiles = false;
1550 myWorkingDirectory.clear();
1552 else if ( myWorkingDirectory == "1" ) {
1554 myWorkingDirectory.clear();
1558 load.clear(ios::badbit | load.rdstate());
1560 isOK = static_cast<bool>(load >> i);
1562 myVerboseLevel = (short) i;
1564 load.clear(ios::badbit | load.rdstate());
1566 isOK = static_cast<bool>(load >> d);
1570 load.clear(ios::badbit | load.rdstate());
1572 std::string separator;
1573 bool hasOptions = false;
1574 bool hasEnforcedVertices = false;
1575 bool hasEnforcedMeshes = false;
1576 isOK = static_cast<bool>(load >> separator);
1578 if ( isOK && ( separator == "0" || separator == "1" ))
1580 myToMakeGroupsOfDomains = ( separator == "1" );
1581 isOK = static_cast<bool>(load >> separator);
1585 if (separator == "__OPTIONS_BEGIN__")
1587 else if (separator == "__ENFORCED_VERTICES_BEGIN__")
1588 hasEnforcedVertices = true;
1589 else if (separator == "__ENFORCED_MESHES_BEGIN__")
1590 hasEnforcedMeshes = true;
1596 isOK = static_cast<bool>(load >> txt);
1598 if (txt == "__OPTIONS_END__") {
1599 if (!myTextOption.empty()) {
1600 // Remove last space
1601 myTextOption.erase(myTextOption.end()-1);
1606 myTextOption += txt;
1607 myTextOption += " ";
1613 isOK = static_cast<bool>(load >> separator);
1614 if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__")
1615 hasEnforcedVertices = true;
1616 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1617 hasEnforcedMeshes = true;
1620 if (hasEnforcedVertices) {
1621 std::string txt, name, entry, groupName;
1622 double size, coords[3];
1624 bool hasCoords = false;
1625 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1627 if (txt == "__ENFORCED_VERTICES_END__")
1630 THYBRIDEnforcedVertex *enfVertex = new THYBRIDEnforcedVertex();
1632 isOK = static_cast<bool>(load >> txt);
1633 if (txt == "__END_VERTEX__") {
1634 enfVertex->name = name;
1635 enfVertex->geomEntry = entry;
1636 enfVertex->isCompound = isCompound;
1637 enfVertex->groupName = groupName;
1638 enfVertex->coords.clear();
1640 enfVertex->coords.assign(coords,coords+3);
1642 _enfVertexList.insert(enfVertex);
1644 if (enfVertex->coords.size())
1645 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1646 if (!enfVertex->geomEntry.empty())
1647 _geomEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1656 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1657 while (isOK && (txt != "__END_NAME__")) {
1658 isOK = static_cast<bool>(load >> txt);
1659 if (txt != "__END_NAME__") {
1667 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1668 isOK = static_cast<bool>(load >> entry);
1669 isOK = static_cast<bool>(load >> isCompound);
1670 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1671 if (txt != "__END_ENTRY__")
1672 throw std::exception();
1675 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1676 while (isOK && (txt != "__END_GROUP__")) {
1677 isOK = static_cast<bool>(load >> txt);
1678 if (txt != "__END_GROUP__") {
1679 if (!groupName.empty())
1686 if (txt == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1688 isOK = static_cast<bool>(load >> coords[0] >> coords[1] >> coords[2]);
1689 isOK = static_cast<bool>(load >> txt); // __END_COORDS__
1690 if (txt != "__END_COORDS__")
1691 throw std::exception();
1694 if (txt == "__BEGIN_SIZE__") { // __BEGIN_ENTRY__
1695 isOK = static_cast<bool>(load >> size);
1696 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1697 if (txt != "__END_SIZE__") {
1698 throw std::exception();
1702 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1706 if (hasEnforcedVertices) {
1707 isOK = static_cast<bool>(load >> separator);
1708 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1709 hasEnforcedMeshes = true;
1712 if (hasEnforcedMeshes) {
1713 std::string txt, name, entry, groupName;
1714 int elementType = -1, persistID = -1;
1715 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1718 if (txt == "__ENFORCED_MESHES_END__")
1721 THYBRIDEnforcedMesh *enfMesh = new THYBRIDEnforcedMesh();
1723 isOK = static_cast<bool>(load >> txt);
1724 if (txt == "__END_ENF_MESH__") {
1725 enfMesh->name = name;
1726 enfMesh->entry = entry;
1727 enfMesh->elementType = (SMESH::ElementType)elementType;
1728 enfMesh->groupName = groupName;
1729 enfMesh->persistID = persistID;
1731 _enfMeshList.insert(enfMesh);
1732 std::cout << "Restoring of enforced mesh " <<name << " done" << std::endl;
1742 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1743 while (isOK && (txt != "__END_NAME__")) {
1744 isOK = static_cast<bool>(load >> txt);
1745 if (txt != "__END_NAME__") {
1753 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1754 isOK = static_cast<bool>(load >> entry);
1755 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1756 if (txt != "__END_ENTRY__")
1757 throw std::exception();
1760 if (txt == "__BEGIN_ELEM_TYPE__") { // __BEGIN_ELEM_TYPE__
1761 isOK = static_cast<bool>(load >> elementType);
1762 isOK = static_cast<bool>(load >> txt); // __END_ELEM_TYPE__
1763 if (txt != "__END_ELEM_TYPE__")
1764 throw std::exception();
1767 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1768 while (isOK && (txt != "__END_GROUP__")) {
1769 isOK = static_cast<bool>(load >> txt);
1770 if (txt != "__END_GROUP__") {
1771 if (!groupName.empty())
1778 if (txt == "__PERSIST_ID__") {
1779 isOK = static_cast<bool>(load >> persistID);
1781 std::cout << "isOK: " << isOK << std::endl;
1784 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1788 if ( hasEnforcedMeshes )
1789 isOK = static_cast<bool>(load >> separator);
1793 i = atoi( separator.c_str() );
1797 myFacesWithLayers.reserve( i );
1798 while (( myFacesWithLayers.size() < myFacesWithLayers.capacity() ) &&
1799 ( isOK = static_cast<bool>(load >> i)) )
1800 myFacesWithLayers.push_back( i );
1806 i = atoi( separator.c_str() );
1810 myFacesWithImprinting.reserve( i );
1811 while (( myFacesWithImprinting.size() < myFacesWithImprinting.capacity() ) &&
1812 ( isOK = static_cast<bool>(load >> i)) )
1813 myFacesWithImprinting.push_back( i );
1820 //=======================================================================
1821 //function : SetParametersByMesh
1822 //=======================================================================
1824 bool HYBRIDPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
1830 //================================================================================
1832 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
1834 //================================================================================
1836 bool HYBRIDPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
1837 const SMESH_Mesh* /*theMesh*/)
1839 myToMakeGroupsOfDomains = ( !dflts._shape || dflts._shape->IsNull() );
1843 //================================================================================
1845 * \brief Return command to run hybrid mesher excluding file prefix (-f)
1847 //================================================================================
1849 std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis* hyp,
1852 SMESH_Comment cmd = GetExeName();
1853 // check if any option is overridden by hyp->myTextOption
1854 bool p_h = ( hyp && hyp->myTextOption.find("-h") != std::string::npos );
1855 bool p_v = ( hyp && hyp->myTextOption.find("-v") != std::string::npos );
1856 bool p_i = ( hyp && hyp->myTextOption.find("-i") != std::string::npos );
1857 bool p_o = ( hyp && hyp->myTextOption.find("-o") != std::string::npos );
1858 bool p_mnot = ( hyp && hyp->myTextOption.find("--max_number_of_threads ") != std::string::npos );
1859 bool p_blsi = ( hyp && hyp->myTextOption.find("--boundary_layer_surface_tags ") != std::string::npos );
1860 bool p_blii = ( hyp && hyp->myTextOption.find("--boundary_layer_imprint_tags ") != std::string::npos );
1861 bool p_blsd = ( hyp && hyp->myTextOption.find("--normal_direction ") != std::string::npos );
1862 bool p_hotfl = ( hyp && hyp->myTextOption.find("--boundary_layer_global_initial_height ") != std::string::npos );
1863 bool p_nobl = ( hyp && hyp->myTextOption.find("--number_of_boundary_layers ") != std::string::npos );
1864 bool p_blgp = ( hyp && hyp->myTextOption.find("--boundary_layer_geometric_progression ") != std::string::npos );
1865 bool p_eg = ( hyp && hyp->myTextOption.find("--element_generation ") != std::string::npos );
1866 bool p_cm = ( hyp && hyp->myTextOption.find("--collision_mode ") != std::string::npos );
1867 bool p_am = ( hyp && hyp->myTextOption.find("--add_multinormals ") != std::string::npos );
1868 bool p_cs = ( hyp && hyp->myTextOption.find("--global_physical_size ") != std::string::npos );
1869 bool p_mat = ( hyp && hyp->myTextOption.find("--multinormal_angle_threshold ") != std::string::npos );
1870 bool p_sn = ( hyp && hyp->myTextOption.find("--smooth_normals ") != std::string::npos );
1873 //- boundary_layer_max_element_angle
1875 bool nolayers = false;
1876 bool layersOnAllWrap = hyp ? hyp->myLayersOnAllWrap : DefaultLayersOnAllWrap();
1884 std::cout << "!!!!! CommandToRun help only !!!! " << cmd << std::endl;
1889 cmd << " --verbose " << hyp->myVerboseLevel;
1891 if ( !p_mnot && hyp )
1892 cmd << " --max_number_of_threads " << 8; //TODO getenv NB CPU
1895 if ( !p_nobl && hyp ) {
1896 if ( hyp->myNbOfBoundaryLayers < 1 ) nolayers = true;
1898 if ( !p_hotfl && hyp ) {
1899 if ( hyp->myHeightFirstLayer < 1e-50 ) nolayers = true;
1902 if ( !p_blsd && hyp ) {
1903 if ( hyp->myBoundaryLayersGrowth >= 0 && hyp->myBoundaryLayersGrowth <= 1 ) {
1904 const char* value[] = { "-1" , "1" }; // -1 == inside
1905 cmd << " --normal_direction " << value[ hyp->myBoundaryLayersGrowth ];
1909 if ( !p_hotfl && hyp ) {
1910 cmd << " --boundary_layer_global_initial_height " << hyp->myHeightFirstLayer;
1913 if ( !p_nobl && hyp ) {
1914 cmd << " --number_of_boundary_layers " << ( nolayers ? 0 : hyp->myNbOfBoundaryLayers );
1917 if ( !p_blgp && hyp ) {
1918 cmd << " --boundary_layer_geometric_progression " << hyp->myBoundaryLayersProgression;
1921 if ( !nolayers && hyp )
1923 cmd << " --boundary_layer_size_mode " << ( layersOnAllWrap ? "global" : "local" );
1925 if ( !layersOnAllWrap )
1927 // faces with layers
1928 const std::vector<int>& faceLayersIDs = hyp->GetFacesWithLayers();
1929 if ( !faceLayersIDs.empty() )
1930 cmd << " --boundary_layer_surface_tags ";
1931 for ( size_t i = 0; i < faceLayersIDs.size(); ++i )
1932 cmd << faceLayersIDs[i] << ",";
1933 if ( !faceLayersIDs.empty() )
1934 cmd << " --boundary_layer_initial_height_on_surface_tags ";
1935 for ( size_t i = 0; i < faceLayersIDs.size(); ++i )
1936 cmd << hyp->myHeightFirstLayer << ",";
1938 // faces with imprinting
1939 const std::vector<int>& faceImprintingIDs = hyp->GetFacesWithImprinting();
1940 if ( !faceImprintingIDs.empty() )
1941 cmd << " --boundary_layer_imprinting yes --boundary_layer_imprinting_tags ";
1942 for ( size_t i = 0; i < faceImprintingIDs.size(); ++i )
1943 cmd << faceImprintingIDs[i] << ",";
1947 if ( !p_eg && hyp ) {
1948 if ( hyp->myElementGeneration >= 0 && hyp->myElementGeneration <= 2 ) {
1949 const char* value[] = { "tetra-dominant" , "hexa-dominant", "cartesian_core" };
1950 cmd << " --element_generation " << value[ hyp->myElementGeneration ];
1954 if ( !p_cs && hyp ) {
1955 if ( hyp->myCoreSize >= 0 ) {
1956 cmd << " --global_physical_size " << hyp->myCoreSize;
1960 if ( !p_cm && hyp ) {
1961 if ( hyp->myCollisionMode >= 0 && hyp->myCollisionMode <= 1 ) {
1962 const char* value[] = { "decrease" , "stop" };
1963 cmd << " --collision_mode " << value[ hyp->myCollisionMode ];
1967 if ( !p_am && hyp ) {
1968 int res = hyp->myAddMultinormals ? 0 : 1 ;
1969 const char* value[] = { "yes" , "no" };
1970 cmd << " --add_multinormals " << value[ res ];
1973 if ( !p_mat && hyp ) {
1974 cmd << " --multinormal_angle_threshold " << hyp->myMultinormalsAngle;
1977 if ( !p_sn && hyp ) {
1978 int res = hyp->mySmoothNormals ? 0 : 1 ;
1979 const char* value[] = { "yes" , "no" };
1980 cmd << " --smooth_normals " << value[ res ];
1984 if ( hyp && !hyp->myTextOption.empty() ) {
1985 cmd += " " + hyp->myTextOption;
1990 //std::cout << "!!!!!CommandToRun end " << cmd << std::endl;
1995 //================================================================================
1997 * \brief Return a unique file name
1999 //================================================================================
2001 std::string HYBRIDPlugin_Hypothesis::GetFileName(const HYBRIDPlugin_Hypothesis* hyp)
2003 std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
2004 const char lastChar = *aTmpDir.rbegin();
2006 if(lastChar != '\\') aTmpDir+='\\';
2008 if(lastChar != '/') aTmpDir+='/';
2011 SMESH_Comment aGenericName = aTmpDir;
2012 aGenericName << "HYBRID_";
2013 aGenericName << getpid();
2014 aGenericName << "_";
2015 aGenericName << Abs((Standard_Integer)(long) aGenericName.c_str());
2017 return aGenericName;
2020 //================================================================================
2022 * Return the name of executable
2024 //================================================================================
2026 std::string HYBRIDPlugin_Hypothesis::GetExeName()
2028 //call mg-hybrid.bash is script which assumes new project version(s) mg-hybrid.exe in the prerequisite base and special? licence.
2030 return "mg-hybrid.exe";
2032 return "mg-hybrid.bash";
2036 //================================================================================
2038 * \brief Return the enforced vertices
2040 //================================================================================
2042 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexList HYBRIDPlugin_Hypothesis::GetEnforcedVertices(const HYBRIDPlugin_Hypothesis* hyp)
2044 return hyp ? hyp->_GetEnforcedVertices():DefaultHYBRIDEnforcedVertexList();
2047 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesCoordsSize (const HYBRIDPlugin_Hypothesis* hyp)
2049 return hyp ? hyp->_GetEnforcedVerticesCoordsSize(): DefaultHYBRIDEnforcedVertexCoordsValues();
2052 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexEntryValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesEntrySize (const HYBRIDPlugin_Hypothesis* hyp)
2054 return hyp ? hyp->_GetEnforcedVerticesEntrySize(): DefaultHYBRIDEnforcedVertexEntryValues();
2057 HYBRIDPlugin_Hypothesis::TCoordsHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByCoords (const HYBRIDPlugin_Hypothesis* hyp)
2059 return hyp ? hyp->_GetEnforcedVerticesByCoords(): DefaultCoordsHYBRIDEnforcedVertexMap();
2062 HYBRIDPlugin_Hypothesis::TGeomEntryHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByEntry (const HYBRIDPlugin_Hypothesis* hyp)
2064 return hyp ? hyp->_GetEnforcedVerticesByEntry(): DefaultGeomEntryHYBRIDEnforcedVertexMap();
2067 HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedNodes(const HYBRIDPlugin_Hypothesis* hyp)
2069 return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeGroupMap();
2072 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedEdges(const HYBRIDPlugin_Hypothesis* hyp)
2074 return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemGroupMap();
2077 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(const HYBRIDPlugin_Hypothesis* hyp)
2079 return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemGroupMap();
2082 HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp)
2084 return hyp ? hyp->_GetNodeIDToSizeMap(): DefaultID2SizeMap();
2087 HYBRIDPlugin_Hypothesis::TSetStrings HYBRIDPlugin_Hypothesis::GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp)
2089 return hyp ? hyp->_GetGroupsToRemove(): DefaultGroupsToRemove();