1 // Copyright (C) 2007-2019 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 : SetFacesWithSnapping
160 //purpose : Set IDs of faces that already have surface layers
161 //=======================================================================
163 bool HYBRIDPlugin_Hypothesis::SetFacesWithSnapping(const std::vector<int>& theVal)
165 if ( myFacesWithSnapping != theVal )
167 myFacesWithSnapping = theVal;
168 NotifySubMeshesHypothesisModification();
174 //=======================================================================
175 //function : GetFacesWithSnapping
176 //purpose : Return IDs of faces that already have surface layers
177 //=======================================================================
179 const std::vector<int>& HYBRIDPlugin_Hypothesis::GetFacesWithSnapping() const
181 return myFacesWithSnapping;
184 //=======================================================================
185 //function : SetToMeshHoles
186 //=======================================================================
188 void HYBRIDPlugin_Hypothesis::SetToMeshHoles(bool toMesh)
190 if ( myToMeshHoles != toMesh ) {
191 myToMeshHoles = toMesh;
192 NotifySubMeshesHypothesisModification();
196 //=======================================================================
197 //function : GetToMeshHoles
198 //=======================================================================
200 bool HYBRIDPlugin_Hypothesis::GetToMeshHoles(bool checkFreeOption) const
202 if (checkFreeOption && !myTextOption.empty()) {
203 if ( myTextOption.find("-c 0"))
205 if ( myTextOption.find("-c 1"))
208 return myToMeshHoles;
211 //=======================================================================
212 //function : SetToMakeGroupsOfDomains
213 //=======================================================================
215 void HYBRIDPlugin_Hypothesis::SetToMakeGroupsOfDomains(bool toMakeGroups)
217 if ( myToMakeGroupsOfDomains != toMakeGroups ) {
218 myToMakeGroupsOfDomains = toMakeGroups;
219 NotifySubMeshesHypothesisModification();
223 //=======================================================================
224 //function : GetToMakeGroupsOfDomains
225 //=======================================================================
227 bool HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains() const
229 return myToMakeGroupsOfDomains;
232 //=======================================================================
233 //function : GetToMakeGroupsOfDomains
234 //=======================================================================
236 bool HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains(const HYBRIDPlugin_Hypothesis* hyp)
239 if ( hyp ) res = /*hyp->GetToMeshHoles(true) &&*/ hyp->GetToMakeGroupsOfDomains();
240 else res = /*DefaultMeshHoles() &&*/ DefaultToMakeGroupsOfDomains();
244 //=======================================================================
245 //function : SetMaximumMemory
246 //=======================================================================
248 void HYBRIDPlugin_Hypothesis::SetMaximumMemory(double MB)
250 if ( myMaximumMemory != MB ) {
251 myMaximumMemory = MB;
252 NotifySubMeshesHypothesisModification();
256 //=======================================================================
257 //function : GetMaximumMemory
258 // * automatic memory adjustment mode. Default is zero
259 //=======================================================================
261 double HYBRIDPlugin_Hypothesis::GetMaximumMemory() const
263 return myMaximumMemory;
266 //=======================================================================
267 //function : SetInitialMemory
268 //=======================================================================
270 void HYBRIDPlugin_Hypothesis::SetInitialMemory(double MB)
272 if ( myInitialMemory != MB ) {
273 myInitialMemory = MB;
274 NotifySubMeshesHypothesisModification();
278 //=======================================================================
279 //function : GetInitialMemory
280 //=======================================================================
282 double HYBRIDPlugin_Hypothesis::GetInitialMemory() const
284 return myInitialMemory;
287 //=======================================================================
288 //function : SetOptimizationLevel
289 //=======================================================================
291 void HYBRIDPlugin_Hypothesis::SetOptimizationLevel(OptimizationLevel level)
293 if ( myOptimizationLevel != level ) {
294 myOptimizationLevel = level;
295 NotifySubMeshesHypothesisModification();
299 //=======================================================================
300 //function : GetOptimizationLevel
301 //=======================================================================
302 HYBRIDPlugin_Hypothesis::OptimizationLevel HYBRIDPlugin_Hypothesis::GetOptimizationLevel() const
304 return (OptimizationLevel) myOptimizationLevel;
307 //=======================================================================
308 //function : SetCollisionMode
309 //=======================================================================
310 void HYBRIDPlugin_Hypothesis::SetCollisionMode(CollisionMode mode)
312 if ( myCollisionMode != mode ) {
313 myCollisionMode = mode;
314 NotifySubMeshesHypothesisModification();
318 //=======================================================================
319 //function : GetCollisionMode
320 //=======================================================================
321 HYBRIDPlugin_Hypothesis::CollisionMode HYBRIDPlugin_Hypothesis::GetCollisionMode() const
323 return (CollisionMode) myCollisionMode;
326 //=======================================================================
327 //function : SetBoundaryLayersGrowth
328 //=======================================================================
329 void HYBRIDPlugin_Hypothesis::SetBoundaryLayersGrowth(BoundaryLayersGrowth mode)
331 if ( myBoundaryLayersGrowth != mode ) {
332 myBoundaryLayersGrowth = mode;
333 NotifySubMeshesHypothesisModification();
337 //=======================================================================
338 //function : GetBoundaryLayersGrowth
339 //=======================================================================
340 HYBRIDPlugin_Hypothesis::BoundaryLayersGrowth HYBRIDPlugin_Hypothesis::GetBoundaryLayersGrowth() const
342 return (BoundaryLayersGrowth) myBoundaryLayersGrowth;
345 //=======================================================================
346 //function : SetElementGeneration
347 //=======================================================================
348 void HYBRIDPlugin_Hypothesis::SetElementGeneration(ElementGeneration mode)
350 if ( myElementGeneration != mode ) {
351 myElementGeneration = mode;
352 NotifySubMeshesHypothesisModification();
356 //=======================================================================
357 //function : GetElementGeneration
358 //=======================================================================
359 HYBRIDPlugin_Hypothesis::ElementGeneration HYBRIDPlugin_Hypothesis::GetElementGeneration() const
361 return (ElementGeneration) myElementGeneration;
364 //=======================================================================
365 //function : SetAddMultinormals
366 //=======================================================================
367 void HYBRIDPlugin_Hypothesis::SetAddMultinormals(bool toAddMultinormals)
369 if ( myAddMultinormals != toAddMultinormals ) {
370 myAddMultinormals = toAddMultinormals;
371 NotifySubMeshesHypothesisModification();
375 //=======================================================================
376 //function : GetAddMultinormals
377 //=======================================================================
379 bool HYBRIDPlugin_Hypothesis::GetAddMultinormals() const
381 return myAddMultinormals;
384 //=======================================================================
385 //function : SetSmoothNormals
386 //=======================================================================
388 void HYBRIDPlugin_Hypothesis::SetSmoothNormals(bool toSmoothNormals)
390 if ( mySmoothNormals != toSmoothNormals ) {
391 mySmoothNormals = toSmoothNormals;
392 NotifySubMeshesHypothesisModification();
396 //=======================================================================
397 //function : GetSmoothNormals
398 //=======================================================================
400 bool HYBRIDPlugin_Hypothesis::GetSmoothNormals() const
402 return mySmoothNormals;
405 //=======================================================================
406 //function : SetHeightFirstLayer
407 //=======================================================================
409 void HYBRIDPlugin_Hypothesis::SetHeightFirstLayer(double toHeightFirstLayer)
411 if ( myHeightFirstLayer != toHeightFirstLayer ) {
412 myHeightFirstLayer = toHeightFirstLayer;
413 NotifySubMeshesHypothesisModification();
417 //=======================================================================
418 //function : GetHeightFirstLayer
419 //=======================================================================
421 double HYBRIDPlugin_Hypothesis::GetHeightFirstLayer() const
423 return myHeightFirstLayer;
426 //=======================================================================
427 //function : SetBoundaryLayersProgression
428 //=======================================================================
430 void HYBRIDPlugin_Hypothesis::SetBoundaryLayersProgression(double toBoundaryLayersProgression)
432 if ( myBoundaryLayersProgression != toBoundaryLayersProgression ) {
433 myBoundaryLayersProgression = toBoundaryLayersProgression;
434 NotifySubMeshesHypothesisModification();
438 //=======================================================================
439 //function : GetBoundaryLayersProgression
440 //=======================================================================
442 double HYBRIDPlugin_Hypothesis::GetBoundaryLayersProgression() const
444 return myBoundaryLayersProgression;
447 //=======================================================================
448 //function : SetCoreSize
449 //=======================================================================
451 void HYBRIDPlugin_Hypothesis::SetCoreSize(double toCoreSize)
453 if ( myCoreSize != toCoreSize ) {
454 myCoreSize = toCoreSize;
455 NotifySubMeshesHypothesisModification();
459 //=======================================================================
460 //function : GetCoreSize
461 //=======================================================================
463 double HYBRIDPlugin_Hypothesis::GetCoreSize() const
468 //=======================================================================
469 //function : SetMultinormalsAngle
470 //=======================================================================
472 void HYBRIDPlugin_Hypothesis::SetMultinormalsAngle(double toMultinormalsAngle)
474 if ( myMultinormalsAngle != toMultinormalsAngle ) {
475 myMultinormalsAngle = toMultinormalsAngle;
476 NotifySubMeshesHypothesisModification();
480 //=======================================================================
481 //function : GetMultinormalsAngle
482 //=======================================================================
484 double HYBRIDPlugin_Hypothesis::GetMultinormalsAngle() const
486 return myMultinormalsAngle;
489 //=======================================================================
490 //function : SetNbOfBoundaryLayers
491 //=======================================================================
493 void HYBRIDPlugin_Hypothesis::SetNbOfBoundaryLayers(short toNbOfBoundaryLayers)
495 if ( myNbOfBoundaryLayers != toNbOfBoundaryLayers ) {
496 myNbOfBoundaryLayers = toNbOfBoundaryLayers;
497 NotifySubMeshesHypothesisModification();
501 //=======================================================================
502 //function : GetCoreSize
503 //=======================================================================
505 short HYBRIDPlugin_Hypothesis::GetNbOfBoundaryLayers() const
507 return myNbOfBoundaryLayers;
511 /////////////////////////////////////////////////////////////////////////
514 //=======================================================================
515 //function : SetWorkingDirectory
516 //=======================================================================
518 void HYBRIDPlugin_Hypothesis::SetWorkingDirectory(const std::string& path)
520 if ( myWorkingDirectory != path ) {
521 myWorkingDirectory = path;
522 NotifySubMeshesHypothesisModification();
526 //=======================================================================
527 //function : GetWorkingDirectory
528 //=======================================================================
530 std::string HYBRIDPlugin_Hypothesis::GetWorkingDirectory() const
532 return myWorkingDirectory;
535 //=======================================================================
536 //function : SetKeepFiles
537 //=======================================================================
539 void HYBRIDPlugin_Hypothesis::SetKeepFiles(bool toKeep)
541 if ( myKeepFiles != toKeep ) {
542 myKeepFiles = toKeep;
543 NotifySubMeshesHypothesisModification();
547 //=======================================================================
548 //function : GetKeepFiles
549 //=======================================================================
551 bool HYBRIDPlugin_Hypothesis::GetKeepFiles() const
556 //=======================================================================
557 //function : SetVerboseLevel
558 //=======================================================================
560 void HYBRIDPlugin_Hypothesis::SetVerboseLevel(short level)
562 if ( myVerboseLevel != level ) {
563 myVerboseLevel = level;
564 NotifySubMeshesHypothesisModification();
568 //=======================================================================
569 //function : GetVerboseLevel
570 //=======================================================================
572 short HYBRIDPlugin_Hypothesis::GetVerboseLevel() const
574 return myVerboseLevel;
577 //=======================================================================
578 //function : SetToCreateNewNodes
579 //=======================================================================
581 void HYBRIDPlugin_Hypothesis::SetToCreateNewNodes(bool toCreate)
583 if ( myToCreateNewNodes != toCreate ) {
584 myToCreateNewNodes = toCreate;
585 NotifySubMeshesHypothesisModification();
589 //=======================================================================
590 //function : GetToCreateNewNodes
591 //=======================================================================
593 bool HYBRIDPlugin_Hypothesis::GetToCreateNewNodes() const
595 return myToCreateNewNodes;
598 //=======================================================================
599 //function : SetToUseBoundaryRecoveryVersion
600 //=======================================================================
602 void HYBRIDPlugin_Hypothesis::SetToUseBoundaryRecoveryVersion(bool toUse)
604 if ( myToUseBoundaryRecoveryVersion != toUse ) {
605 myToUseBoundaryRecoveryVersion = toUse;
606 NotifySubMeshesHypothesisModification();
610 //=======================================================================
611 //function : GetToUseBoundaryRecoveryVersion
612 //=======================================================================
614 bool HYBRIDPlugin_Hypothesis::GetToUseBoundaryRecoveryVersion() const
616 return myToUseBoundaryRecoveryVersion;
619 //=======================================================================
620 //function : SetFEMCorrection
621 //=======================================================================
623 void HYBRIDPlugin_Hypothesis::SetFEMCorrection(bool toUseFem)
625 if ( myToUseFemCorrection != toUseFem ) {
626 myToUseFemCorrection = toUseFem;
627 NotifySubMeshesHypothesisModification();
631 //=======================================================================
632 //function : GetFEMCorrection
633 //=======================================================================
635 bool HYBRIDPlugin_Hypothesis::GetFEMCorrection() const
637 return myToUseFemCorrection;
640 //=======================================================================
641 //function : SetToRemoveCentralPoint
642 //=======================================================================
644 void HYBRIDPlugin_Hypothesis::SetToRemoveCentralPoint(bool toRemove)
646 if ( myToRemoveCentralPoint != toRemove ) {
647 myToRemoveCentralPoint = toRemove;
648 NotifySubMeshesHypothesisModification();
652 //=======================================================================
653 //function : GetToRemoveCentralPoint
654 //=======================================================================
656 bool HYBRIDPlugin_Hypothesis::GetToRemoveCentralPoint() const
658 return myToRemoveCentralPoint;
661 //=======================================================================
662 //function : SetAdvancedOption
663 //=======================================================================
665 void HYBRIDPlugin_Hypothesis::SetAdvancedOption(const std::string& option)
667 if ( myTextOption != option ) {
668 myTextOption = option;
669 NotifySubMeshesHypothesisModification();
673 //=======================================================================
674 //function : GetAdvancedOption
675 //=======================================================================
677 std::string HYBRIDPlugin_Hypothesis::GetAdvancedOption() const
682 //=======================================================================
683 //function : SetGradation
684 //=======================================================================
686 void HYBRIDPlugin_Hypothesis::SetGradation(double gradation)
688 if ( myGradation != gradation ) {
689 myGradation = gradation;
690 NotifySubMeshesHypothesisModification();
694 //=======================================================================
695 //function : GetGradation
696 //=======================================================================
698 double HYBRIDPlugin_Hypothesis::GetGradation() const
703 //=======================================================================
704 //function : SetStandardOutputLog
705 //=======================================================================
707 void HYBRIDPlugin_Hypothesis::SetStandardOutputLog(bool logInStandardOutput)
709 if ( myLogInStandardOutput != logInStandardOutput ) {
710 myLogInStandardOutput = logInStandardOutput;
711 NotifySubMeshesHypothesisModification();
715 //=======================================================================
716 //function : GetStandardOutputLog
717 //=======================================================================
719 bool HYBRIDPlugin_Hypothesis::GetStandardOutputLog() const
721 return myLogInStandardOutput;
724 //=======================================================================
725 //function : SetRemoveLogOnSuccess
726 //=======================================================================
728 void HYBRIDPlugin_Hypothesis::SetRemoveLogOnSuccess(bool removeLogOnSuccess)
730 if ( myRemoveLogOnSuccess != removeLogOnSuccess ) {
731 myRemoveLogOnSuccess = removeLogOnSuccess;
732 NotifySubMeshesHypothesisModification();
736 //=======================================================================
737 //function : GetRemoveLogOnSuccess
738 //=======================================================================
740 bool HYBRIDPlugin_Hypothesis::GetRemoveLogOnSuccess() const
742 return myRemoveLogOnSuccess;
745 //=======================================================================
746 //function : SetEnforcedVertex
747 //=======================================================================
749 bool HYBRIDPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string theEntry, std::string theGroupName,
750 double size, double x, double y, double z, bool isCompound)
752 bool toNotify = false;
753 bool toCreate = true;
755 THYBRIDEnforcedVertex *oldEnVertex;
756 THYBRIDEnforcedVertex *newEnfVertex = new THYBRIDEnforcedVertex();
757 newEnfVertex->name = theName;
758 newEnfVertex->geomEntry = theEntry;
759 newEnfVertex->coords.clear();
761 newEnfVertex->coords.push_back(x);
762 newEnfVertex->coords.push_back(y);
763 newEnfVertex->coords.push_back(z);
765 newEnfVertex->groupName = theGroupName;
766 newEnfVertex->size = size;
767 newEnfVertex->isCompound = isCompound;
770 // update _enfVertexList
771 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(newEnfVertex);
772 if (it != _enfVertexList.end()) {
775 if (oldEnVertex->name != theName) {
776 oldEnVertex->name = theName;
779 if (oldEnVertex->groupName != theGroupName) {
780 oldEnVertex->groupName = theGroupName;
783 if (oldEnVertex->size != size) {
784 oldEnVertex->size = size;
788 // update map coords / enf vertex if needed
789 if (oldEnVertex->coords.size()) {
790 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
791 _enfVertexCoordsSizeList[oldEnVertex->coords] = size;
794 // update map geom entry / enf vertex if needed
795 if (oldEnVertex->geomEntry != "") {
796 _geomEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
797 _enfVertexEntrySizeList[oldEnVertex->geomEntry] = size;
802 // //////// CREATE ////////////
805 _enfVertexList.insert(newEnfVertex);
806 if (theEntry == "") {
807 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
808 _enfVertexCoordsSizeList[newEnfVertex->coords] = size;
811 _geomEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
812 _enfVertexEntrySizeList[newEnfVertex->geomEntry] = size;
817 NotifySubMeshesHypothesisModification();
823 //=======================================================================
824 //function : SetEnforcedMesh
825 //=======================================================================
826 bool HYBRIDPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName)
828 TIDSortedElemSet theElemSet;
829 SMDS_ElemIteratorPtr eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType));
830 while ( eIt->more() )
831 theElemSet.insert( eIt->next() );
832 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
834 THYBRIDEnforcedMesh* newEnfMesh = new THYBRIDEnforcedMesh();
835 newEnfMesh->persistID = theMesh.GetMeshDS()->GetPersistentId();
836 newEnfMesh->name = name;
837 newEnfMesh->entry = entry;
838 newEnfMesh->elementType = elementType;
839 newEnfMesh->groupName = groupName;
841 THYBRIDEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
842 if (it == _enfMeshList.end()) {
843 _entryEnfMeshMap[entry].insert(newEnfMesh);
844 _enfMeshList.insert(newEnfMesh);
853 //=======================================================================
854 //function : SetEnforcedGroup
855 //=======================================================================
856 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)
858 TIDSortedElemSet theElemSet;
859 if ( theIDs->length() == 0 ){MESSAGE("The source group is empty");}
860 for ( CORBA::ULong i = 0; i < theIDs->length(); i++) {
861 CORBA::Long ind = theIDs[i];
862 if (elementType == SMESH::NODE)
864 const SMDS_MeshNode * node = theMeshDS->FindNode(ind);
866 theElemSet.insert( node );
870 const SMDS_MeshElement * elem = theMeshDS->FindElement(ind);
872 theElemSet.insert( elem );
876 // SMDS_ElemIteratorPtr it = theGroup->GetGroupDS()->GetElements();
877 // while ( it->more() )
878 // theElemSet.insert( it->next() );
880 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
882 THYBRIDEnforcedMesh* newEnfMesh = new THYBRIDEnforcedMesh();
883 newEnfMesh->name = name;
884 newEnfMesh->entry = entry;
885 newEnfMesh->elementType = elementType;
886 newEnfMesh->groupName = groupName;
888 THYBRIDEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
889 if (it == _enfMeshList.end()) {
890 _entryEnfMeshMap[entry].insert(newEnfMesh);
891 _enfMeshList.insert(newEnfMesh);
897 //=======================================================================
898 //function : SetEnforcedElements
899 //=======================================================================
900 bool HYBRIDPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName)
902 TIDSortedElemSet::const_iterator it = theElemSet.begin();
903 const SMDS_MeshElement* elem;
904 const SMDS_MeshNode* node;
906 std::pair<TIDSortedNodeGroupMap::iterator,bool> nodeRet;
907 std::pair<TIDSortedElemGroupMap::iterator,bool> elemRet;
909 for (;it != theElemSet.end();++it)
912 switch (elementType) {
914 node = dynamic_cast<const SMDS_MeshNode*>(elem);
916 nodeRet = _enfNodes.insert(make_pair(node,groupName));
917 added = added && nodeRet.second;
918 std::string msg = added ? "yes":"no";
921 SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
922 for (;nodeIt->more();) {
923 node = dynamic_cast<const SMDS_MeshNode*>(nodeIt->next());
924 nodeRet = _enfNodes.insert(make_pair(node,groupName));
925 added = added && nodeRet.second;
931 if (elem->GetType() == SMDSAbs_Edge) {
932 elemRet = _enfEdges.insert(make_pair(elem,groupName));
933 added = added && elemRet.second;
937 if (elem->GetType() == SMDSAbs_Face)
939 if (elem->NbCornerNodes() == 3) {
940 elemRet = _enfTriangles.insert(make_pair(elem,groupName));
941 added = added && elemRet.second;
950 NotifySubMeshesHypothesisModification();
955 //=======================================================================
956 //function : GetEnforcedVertex
957 //=======================================================================
959 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z)
960 throw (std::invalid_argument)
962 std::vector<double> coord(3);
966 if (_coordsEnfVertexMap.count(coord)>0)
967 return _coordsEnfVertexMap[coord];
968 std::ostringstream msg ;
969 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
970 throw std::invalid_argument(msg.str());
973 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(const std::string theEntry)
974 throw (std::invalid_argument)
976 if (_geomEntryEnfVertexMap.count(theEntry)>0)
977 return _geomEntryEnfVertexMap[theEntry];
979 std::ostringstream msg ;
980 msg << "No enforced vertex with entry " << theEntry;
981 throw std::invalid_argument(msg.str());
984 //=======================================================================
985 //function : RemoveEnforcedVertex
986 //=======================================================================
988 bool HYBRIDPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, const std::string theEntry)
989 throw (std::invalid_argument)
991 bool toNotify = false;
992 std::ostringstream msg;
993 THYBRIDEnforcedVertex *oldEnfVertex;
994 std::vector<double> coords(3);
999 // check that enf vertex with given enf vertex entry exists
1000 TGeomEntryHYBRIDEnforcedVertexMap::iterator it_enfVertexEntry = _geomEntryEnfVertexMap.find(theEntry);
1001 if (it_enfVertexEntry != _geomEntryEnfVertexMap.end()) {
1003 oldEnfVertex = it_enfVertexEntry->second;
1004 _geomEntryEnfVertexMap.erase(it_enfVertexEntry);
1007 // check that enf vertex with given coords exists
1008 TCoordsHYBRIDEnforcedVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1009 if (it_coords_enf != _coordsEnfVertexMap.end()) {
1011 oldEnfVertex = it_coords_enf->second;
1012 _coordsEnfVertexMap.erase(it_coords_enf);
1013 _enfVertexCoordsSizeList.erase(_enfVertexCoordsSizeList.find(coords));
1016 throw std::invalid_argument(msg.str());
1021 // update _enfVertexList
1022 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1023 if (it != _enfVertexList.end()) {
1024 if ((*it)->groupName != "")
1025 _groupsToRemove.insert((*it)->groupName);
1026 _enfVertexList.erase(it);
1031 NotifySubMeshesHypothesisModification();
1036 //=======================================================================
1037 //function : ClearEnforcedVertices
1038 //=======================================================================
1039 void HYBRIDPlugin_Hypothesis::ClearEnforcedVertices()
1041 THYBRIDEnforcedVertexList::const_iterator it = _enfVertexList.begin();
1042 for(;it != _enfVertexList.end();++it) {
1043 if ((*it)->groupName != "")
1044 _groupsToRemove.insert((*it)->groupName);
1046 _enfVertexList.clear();
1047 _coordsEnfVertexMap.clear();
1048 _geomEntryEnfVertexMap.clear();
1049 _enfVertexCoordsSizeList.clear();
1050 _enfVertexEntrySizeList.clear();
1051 NotifySubMeshesHypothesisModification();
1054 //=======================================================================
1055 //function : ClearEnforcedMeshes
1056 //=======================================================================
1057 void HYBRIDPlugin_Hypothesis::ClearEnforcedMeshes()
1059 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
1060 for(;it != _enfMeshList.end();++it) {
1061 if ((*it)->groupName != "")
1062 _groupsToRemove.insert((*it)->groupName);
1066 _enfTriangles.clear();
1067 _nodeIDToSizeMap.clear();
1068 _enfMeshList.clear();
1069 _entryEnfMeshMap.clear();
1070 NotifySubMeshesHypothesisModification();
1073 //================================================================================
1075 * \brief At mesh loading, restore enforced elements by just loaded enforced meshes
1077 //================================================================================
1079 void HYBRIDPlugin_Hypothesis::RestoreEnfElemsByMeshes()
1081 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
1082 for(;it != _enfMeshList.end();++it) {
1083 THYBRIDEnforcedMesh* enfMesh = *it;
1084 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
1085 SetEnforcedMesh( *mesh,
1086 enfMesh->elementType,
1089 enfMesh->groupName );
1090 enfMesh->persistID = -1; // not to restore again
1094 //=======================================================================
1095 //function : SetGroupsToRemove
1096 //=======================================================================
1098 void HYBRIDPlugin_Hypothesis::ClearGroupsToRemove()
1100 _groupsToRemove.clear();
1104 //=======================================================================
1105 //function : DefaultLayersOnAllWrap
1106 //=======================================================================
1108 bool HYBRIDPlugin_Hypothesis::DefaultLayersOnAllWrap()
1113 //=======================================================================
1114 //function : DefaultMeshHoles
1115 //=======================================================================
1117 bool HYBRIDPlugin_Hypothesis::DefaultMeshHoles()
1119 return false; // PAL19680
1122 //=======================================================================
1123 //function : DefaultToMakeGroupsOfDomains
1124 //=======================================================================
1126 bool HYBRIDPlugin_Hypothesis::DefaultToMakeGroupsOfDomains()
1128 return false; // issue 0022172
1131 //=======================================================================
1132 //function : DefaultMaximumMemory
1133 //=======================================================================
1136 #include <windows.h>
1137 #elif !defined(__APPLE__)
1138 #include <sys/sysinfo.h>
1141 double HYBRIDPlugin_Hypothesis::DefaultMaximumMemory()
1144 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
1145 MEMORYSTATUSEX statex;
1146 statex.dwLength = sizeof (statex);
1147 int err = GlobalMemoryStatusEx (&statex);
1150 statex.ullTotalPhys / 1024 / 1024 +
1151 statex.ullTotalPageFile / 1024 / 1024 +
1152 statex.ullTotalVirtual / 1024 / 1024;
1153 return ( 0.7 * totMB );
1155 #elif !defined(__APPLE__)
1157 int err = sysinfo( &si );
1159 int ramMB = si.totalram * si.mem_unit / 1024 / 1024;
1160 return ( 0.7 * ramMB );
1166 //=======================================================================
1167 //function : DefaultInitialMemory
1168 //=======================================================================
1170 double HYBRIDPlugin_Hypothesis::DefaultInitialMemory()
1172 return DefaultMaximumMemory();
1175 //=======================================================================
1176 //function : DefaultCollisionMode
1177 //=======================================================================
1178 short HYBRIDPlugin_Hypothesis::DefaultCollisionMode()
1183 //=======================================================================
1184 //function : DefaultBoundaryLayersGrowth
1185 //=======================================================================
1186 short HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersGrowth()
1188 return Layer_Growth_Inward;
1191 //=======================================================================
1192 //function : DefaultElementGeneration
1193 //=======================================================================
1194 short HYBRIDPlugin_Hypothesis::DefaultElementGeneration()
1196 return Generation_Tetra_Dominant;
1199 //=======================================================================
1200 //function : DefaultOptimizationLevel
1201 //=======================================================================
1202 short HYBRIDPlugin_Hypothesis::DefaultOptimizationLevel()
1207 //=======================================================================
1208 //function : DefaultWorkingDirectory
1209 //=======================================================================
1211 std::string HYBRIDPlugin_Hypothesis::DefaultWorkingDirectory()
1213 std::string aTmpDir;
1215 char *Tmp_dir = getenv("SALOME_TMP_DIR");
1216 if(Tmp_dir != NULL) {
1229 //=======================================================================
1230 //function : DefaultKeepFiles
1231 //=======================================================================
1233 bool HYBRIDPlugin_Hypothesis::DefaultKeepFiles()
1238 //=======================================================================
1239 //function : DefaultRemoveLogOnSuccess
1240 //=======================================================================
1242 bool HYBRIDPlugin_Hypothesis::DefaultRemoveLogOnSuccess()
1248 //=======================================================================
1249 //function : DefaultVerboseLevel
1250 //=======================================================================
1252 short HYBRIDPlugin_Hypothesis::DefaultVerboseLevel()
1257 //=======================================================================
1258 //function : DefaultToCreateNewNodes
1259 //=======================================================================
1261 bool HYBRIDPlugin_Hypothesis::DefaultToCreateNewNodes()
1266 //=======================================================================
1267 //function : DefaultToUseBoundaryRecoveryVersion
1268 //=======================================================================
1270 bool HYBRIDPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
1275 //=======================================================================
1276 //function : DefaultToUseFEMCorrection
1277 //=======================================================================
1279 bool HYBRIDPlugin_Hypothesis::DefaultToUseFEMCorrection()
1284 //=======================================================================
1285 //function : DefaultToRemoveCentralPoint
1286 //=======================================================================
1288 bool HYBRIDPlugin_Hypothesis::DefaultToRemoveCentralPoint()
1293 //=======================================================================
1294 //function : DefaultGradation
1295 //=======================================================================
1297 double HYBRIDPlugin_Hypothesis::DefaultGradation()
1302 //=======================================================================
1303 //function : DefaultStandardOutputLog
1304 //=======================================================================
1306 bool HYBRIDPlugin_Hypothesis::DefaultStandardOutputLog()
1311 // //=======================================================================
1312 // //function : DefaultID2SizeMap
1313 // //=======================================================================
1315 // HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::DefaultID2SizeMap()
1317 // return HYBRIDPlugin_Hypothesis::TID2SizeMap();
1320 //=======================================================================
1321 //function : DefaultAddMultinormals
1322 //=======================================================================
1323 bool HYBRIDPlugin_Hypothesis::DefaultAddMultinormals()
1328 //=======================================================================
1329 //function : DefaultSmoothNormals
1330 //=======================================================================
1331 bool HYBRIDPlugin_Hypothesis::DefaultSmoothNormals()
1336 //=======================================================================
1337 //function : DefaultHeightFirstLayer
1338 //=======================================================================
1339 double HYBRIDPlugin_Hypothesis::DefaultHeightFirstLayer()
1341 return 0.0; //or epsilon?
1344 //=======================================================================
1345 //function : DefaultBoundaryLayersProgression
1346 //=======================================================================
1347 double HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersProgression()
1352 //=======================================================================
1353 //function : DefaultCoreSize
1354 //=======================================================================
1355 double HYBRIDPlugin_Hypothesis::DefaultCoreSize()
1360 //=======================================================================
1361 //function : DefaultMultinormalsAngle
1362 //=======================================================================
1363 double HYBRIDPlugin_Hypothesis::DefaultMultinormalsAngle()
1368 //=======================================================================
1369 //function : DefaultNbOfBoundaryLayers
1370 //=======================================================================
1371 short HYBRIDPlugin_Hypothesis::DefaultNbOfBoundaryLayers()
1376 //=======================================================================
1378 //=======================================================================
1380 std::ostream & HYBRIDPlugin_Hypothesis::SaveTo(std::ostream & save)
1382 save << (int) myBoundaryLayersGrowth << " ";
1383 save << (int) myElementGeneration << " ";
1384 save << (int) myAddMultinormals << " ";
1385 save << (int) mySmoothNormals << " ";
1386 save << (int) myLayersOnAllWrap << " ";
1388 save << myNbOfBoundaryLayers << " ";
1389 save << myHeightFirstLayer << " ";
1390 save << myBoundaryLayersProgression << " ";
1391 save << myMultinormalsAngle << " ";
1393 save << (int) myKeepFiles << " ";
1394 save << myWorkingDirectory << " ";
1395 save << myVerboseLevel << " ";
1396 save << myCoreSize << " ";
1398 if (!myTextOption.empty()) {
1399 save << "__OPTIONS_BEGIN__ ";
1400 save << myTextOption << " ";
1401 save << "__OPTIONS_END__ ";
1405 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.begin();
1406 if (it != _enfVertexList.end()) {
1407 save << " " << "__ENFORCED_VERTICES_BEGIN__ ";
1408 for ( ; it != _enfVertexList.end(); ++it ) {
1409 THYBRIDEnforcedVertex *enfVertex = (*it);
1410 save << " " << "__BEGIN_VERTEX__";
1411 if (!enfVertex->name.empty()) {
1412 save << " " << "__BEGIN_NAME__";
1413 save << " " << enfVertex->name;
1414 save << " " << "__END_NAME__";
1416 if (!enfVertex->geomEntry.empty()) {
1417 save << " " << "__BEGIN_ENTRY__";
1418 save << " " << enfVertex->geomEntry;
1419 save << " " << enfVertex->isCompound;
1420 save << " " << "__END_ENTRY__";
1422 if (!enfVertex->groupName.empty()) {
1423 save << " " << "__BEGIN_GROUP__";
1424 save << " " << enfVertex->groupName;
1425 save << " " << "__END_GROUP__";
1427 if (enfVertex->coords.size()) {
1428 save << " " << "__BEGIN_COORDS__";
1429 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1430 save << " " << enfVertex->coords[i];
1431 save << " " << "__END_COORDS__";
1433 save << " " << "__BEGIN_SIZE__";
1434 save << " " << enfVertex->size;
1435 save << " " << "__END_SIZE__";
1436 save << " " << "__END_VERTEX__";
1438 save << " " << "__ENFORCED_VERTICES_END__ ";
1441 THYBRIDEnforcedMeshList::iterator it_mesh = _enfMeshList.begin();
1442 if (it_mesh != _enfMeshList.end()) {
1443 save << " " << "__ENFORCED_MESHES_BEGIN__ ";
1444 for ( ; it_mesh != _enfMeshList.end(); ++it_mesh ) {
1445 THYBRIDEnforcedMesh *enfMesh = (*it_mesh);
1446 save << " " << "__BEGIN_ENF_MESH__";
1448 save << " " << "__BEGIN_NAME__";
1449 save << " " << enfMesh->name;
1450 save << " " << "__END_NAME__";
1452 save << " " << "__BEGIN_ENTRY__";
1453 save << " " << enfMesh->entry;
1454 save << " " << "__END_ENTRY__";
1456 save << " " << "__BEGIN_ELEM_TYPE__";
1457 save << " " << (int)enfMesh->elementType;
1458 save << " " << "__END_ELEM_TYPE__";
1460 if (!enfMesh->groupName.empty()) {
1461 save << " " << "__BEGIN_GROUP__";
1462 save << " " << enfMesh->groupName;
1463 save << " " << "__END_GROUP__";
1465 save << " " << "__PERSIST_ID__";
1466 save << " " << enfMesh->persistID;
1467 save << " " << "__END_ENF_MESH__";
1468 std::cout << "Saving of enforced mesh " << enfMesh->name.c_str() << " done" << std::endl;
1470 save << " " << "__ENFORCED_MESHES_END__ ";
1473 save << " " << myFacesWithLayers.size();
1474 for ( size_t i = 0; i < myFacesWithLayers.size(); ++i )
1475 save << " " << myFacesWithLayers[i];
1477 save << " " << myFacesWithImprinting.size();
1478 for ( size_t i = 0; i < myFacesWithImprinting.size(); ++i )
1479 save << " " << myFacesWithImprinting[i];
1481 save << " " << myFacesWithSnapping.size();
1482 for ( size_t i = 0; i < myFacesWithSnapping.size(); ++i )
1483 save << " " << myFacesWithSnapping[i];
1488 //=======================================================================
1489 //function : LoadFrom
1490 //=======================================================================
1492 std::istream & HYBRIDPlugin_Hypothesis::LoadFrom(std::istream & load)
1498 isOK = static_cast<bool>(load >> i);
1500 myBoundaryLayersGrowth = (short) i;
1502 load.clear(ios::badbit | load.rdstate());
1504 isOK = static_cast<bool>(load >> i);
1506 myElementGeneration = (short) i;
1508 load.clear(ios::badbit | load.rdstate());
1510 isOK = static_cast<bool>(load >> i);
1512 myAddMultinormals = (bool) i;
1514 load.clear(ios::badbit | load.rdstate());
1516 isOK = static_cast<bool>(load >> i);
1518 mySmoothNormals = (bool) i;
1520 load.clear(ios::badbit | load.rdstate());
1522 isOK = static_cast<bool>(load >> i);
1524 myLayersOnAllWrap = (bool) i;
1526 load.clear(ios::badbit | load.rdstate());
1528 isOK = static_cast<bool>(load >> i);
1530 myNbOfBoundaryLayers = (short) i;
1532 load.clear(ios::badbit | load.rdstate());
1534 isOK = static_cast<bool>(load >> d);
1536 myHeightFirstLayer = d;
1538 load.clear(ios::badbit | load.rdstate());
1540 isOK = static_cast<bool>(load >> d);
1542 myBoundaryLayersProgression = d;
1544 load.clear(ios::badbit | load.rdstate());
1546 isOK = static_cast<bool>(load >> d);
1548 myMultinormalsAngle = d;
1550 load.clear(ios::badbit | load.rdstate());
1552 isOK = static_cast<bool>(load >> i);
1554 myKeepFiles = (bool) i;
1556 load.clear(ios::badbit | load.rdstate());
1558 isOK = static_cast<bool>(load >> myWorkingDirectory);
1560 if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
1561 myKeepFiles = false;
1562 myWorkingDirectory.clear();
1564 else if ( myWorkingDirectory == "1" ) {
1566 myWorkingDirectory.clear();
1570 load.clear(ios::badbit | load.rdstate());
1572 isOK = static_cast<bool>(load >> i);
1574 myVerboseLevel = (short) i;
1576 load.clear(ios::badbit | load.rdstate());
1578 isOK = static_cast<bool>(load >> d);
1582 load.clear(ios::badbit | load.rdstate());
1584 std::string separator;
1585 bool hasOptions = false;
1586 bool hasEnforcedVertices = false;
1587 bool hasEnforcedMeshes = false;
1588 isOK = static_cast<bool>(load >> separator);
1590 if ( isOK && ( separator == "0" || separator == "1" ))
1592 myToMakeGroupsOfDomains = ( separator == "1" );
1593 isOK = static_cast<bool>(load >> separator);
1597 if (separator == "__OPTIONS_BEGIN__")
1599 else if (separator == "__ENFORCED_VERTICES_BEGIN__")
1600 hasEnforcedVertices = true;
1601 else if (separator == "__ENFORCED_MESHES_BEGIN__")
1602 hasEnforcedMeshes = true;
1608 isOK = static_cast<bool>(load >> txt);
1610 if (txt == "__OPTIONS_END__") {
1611 if (!myTextOption.empty()) {
1612 // Remove last space
1613 myTextOption.erase(myTextOption.end()-1);
1618 myTextOption += txt;
1619 myTextOption += " ";
1625 isOK = static_cast<bool>(load >> separator);
1626 if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__")
1627 hasEnforcedVertices = true;
1628 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1629 hasEnforcedMeshes = true;
1632 if (hasEnforcedVertices) {
1633 std::string txt, name, entry, groupName;
1634 double size, coords[3];
1636 bool hasCoords = false;
1637 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1639 if (txt == "__ENFORCED_VERTICES_END__")
1642 THYBRIDEnforcedVertex *enfVertex = new THYBRIDEnforcedVertex();
1644 isOK = static_cast<bool>(load >> txt);
1645 if (txt == "__END_VERTEX__") {
1646 enfVertex->name = name;
1647 enfVertex->geomEntry = entry;
1648 enfVertex->isCompound = isCompound;
1649 enfVertex->groupName = groupName;
1650 enfVertex->coords.clear();
1652 enfVertex->coords.assign(coords,coords+3);
1654 _enfVertexList.insert(enfVertex);
1656 if (enfVertex->coords.size())
1657 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1658 if (!enfVertex->geomEntry.empty())
1659 _geomEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1668 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1669 while (isOK && (txt != "__END_NAME__")) {
1670 isOK = static_cast<bool>(load >> txt);
1671 if (txt != "__END_NAME__") {
1679 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1680 isOK = static_cast<bool>(load >> entry);
1681 isOK = static_cast<bool>(load >> isCompound);
1682 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1683 if (txt != "__END_ENTRY__")
1684 throw std::exception();
1687 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1688 while (isOK && (txt != "__END_GROUP__")) {
1689 isOK = static_cast<bool>(load >> txt);
1690 if (txt != "__END_GROUP__") {
1691 if (!groupName.empty())
1698 if (txt == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1700 isOK = static_cast<bool>(load >> coords[0] >> coords[1] >> coords[2]);
1701 isOK = static_cast<bool>(load >> txt); // __END_COORDS__
1702 if (txt != "__END_COORDS__")
1703 throw std::exception();
1706 if (txt == "__BEGIN_SIZE__") { // __BEGIN_ENTRY__
1707 isOK = static_cast<bool>(load >> size);
1708 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1709 if (txt != "__END_SIZE__") {
1710 throw std::exception();
1714 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1718 if (hasEnforcedVertices) {
1719 isOK = static_cast<bool>(load >> separator);
1720 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1721 hasEnforcedMeshes = true;
1724 if (hasEnforcedMeshes) {
1725 std::string txt, name, entry, groupName;
1726 int elementType = -1, persistID = -1;
1727 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1730 if (txt == "__ENFORCED_MESHES_END__")
1733 THYBRIDEnforcedMesh *enfMesh = new THYBRIDEnforcedMesh();
1735 isOK = static_cast<bool>(load >> txt);
1736 if (txt == "__END_ENF_MESH__") {
1737 enfMesh->name = name;
1738 enfMesh->entry = entry;
1739 enfMesh->elementType = (SMESH::ElementType)elementType;
1740 enfMesh->groupName = groupName;
1741 enfMesh->persistID = persistID;
1743 _enfMeshList.insert(enfMesh);
1744 std::cout << "Restoring of enforced mesh " <<name << " done" << std::endl;
1754 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1755 while (isOK && (txt != "__END_NAME__")) {
1756 isOK = static_cast<bool>(load >> txt);
1757 if (txt != "__END_NAME__") {
1765 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1766 isOK = static_cast<bool>(load >> entry);
1767 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1768 if (txt != "__END_ENTRY__")
1769 throw std::exception();
1772 if (txt == "__BEGIN_ELEM_TYPE__") { // __BEGIN_ELEM_TYPE__
1773 isOK = static_cast<bool>(load >> elementType);
1774 isOK = static_cast<bool>(load >> txt); // __END_ELEM_TYPE__
1775 if (txt != "__END_ELEM_TYPE__")
1776 throw std::exception();
1779 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1780 while (isOK && (txt != "__END_GROUP__")) {
1781 isOK = static_cast<bool>(load >> txt);
1782 if (txt != "__END_GROUP__") {
1783 if (!groupName.empty())
1790 if (txt == "__PERSIST_ID__") {
1791 isOK = static_cast<bool>(load >> persistID);
1793 std::cout << "isOK: " << isOK << std::endl;
1796 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1800 if ( hasEnforcedMeshes )
1801 isOK = static_cast<bool>(load >> separator);
1805 i = atoi( separator.c_str() );
1809 myFacesWithLayers.reserve( i );
1810 while (( myFacesWithLayers.size() < myFacesWithLayers.capacity() ) &&
1811 ( isOK = static_cast<bool>(load >> i)) )
1812 myFacesWithLayers.push_back( i );
1816 isOK = static_cast<bool>(load >> separator);
1819 i = atoi( separator.c_str() );
1823 myFacesWithImprinting.reserve( i );
1824 while (( myFacesWithImprinting.size() < myFacesWithImprinting.capacity() ) &&
1825 ( isOK = static_cast<bool>(load >> i)) )
1826 myFacesWithImprinting.push_back( i );
1830 isOK = static_cast<bool>(load >> separator);
1833 i = atoi( separator.c_str() );
1837 myFacesWithSnapping.reserve( i );
1838 while (( myFacesWithSnapping.size() < myFacesWithSnapping.capacity() ) &&
1839 ( isOK = static_cast<bool>(load >> i)) )
1840 myFacesWithSnapping.push_back( i );
1847 //=======================================================================
1848 //function : SetParametersByMesh
1849 //=======================================================================
1851 bool HYBRIDPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
1857 //================================================================================
1859 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
1861 //================================================================================
1863 bool HYBRIDPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
1864 const SMESH_Mesh* /*theMesh*/)
1866 myToMakeGroupsOfDomains = ( !dflts._shape || dflts._shape->IsNull() );
1870 //================================================================================
1872 * \brief Return command to run hybrid mesher excluding file prefix (-f)
1874 //================================================================================
1876 std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis* hyp,
1879 SMESH_Comment cmd = GetExeName();
1880 // check if any option is overridden by hyp->myTextOption
1881 bool p_h = ( hyp && hyp->myTextOption.find("-h") != std::string::npos );
1882 bool p_v = ( hyp && hyp->myTextOption.find("-v") != std::string::npos );
1883 bool p_i = ( hyp && hyp->myTextOption.find("-i") != std::string::npos );
1884 bool p_o = ( hyp && hyp->myTextOption.find("-o") != std::string::npos );
1885 bool p_mnot = ( hyp && hyp->myTextOption.find("--max_number_of_threads ") != std::string::npos );
1886 bool p_blsi = ( hyp && hyp->myTextOption.find("--boundary_layer_surface_tags ") != std::string::npos );
1887 bool p_blii = ( hyp && hyp->myTextOption.find("--boundary_layer_imprint_tags ") != std::string::npos );
1888 bool p_blsd = ( hyp && hyp->myTextOption.find("--normal_direction ") != std::string::npos );
1889 bool p_hotfl = ( hyp && hyp->myTextOption.find("--boundary_layer_global_initial_height ") != std::string::npos );
1890 bool p_nobl = ( hyp && hyp->myTextOption.find("--number_of_boundary_layers ") != std::string::npos );
1891 bool p_blgp = ( hyp && hyp->myTextOption.find("--boundary_layer_geometric_progression ") != std::string::npos );
1892 bool p_eg = ( hyp && hyp->myTextOption.find("--element_generation ") != std::string::npos );
1893 bool p_cm = ( hyp && hyp->myTextOption.find("--collision_mode ") != std::string::npos );
1894 bool p_am = ( hyp && hyp->myTextOption.find("--add_multinormals ") != std::string::npos );
1895 bool p_cs = ( hyp && hyp->myTextOption.find("--global_physical_size ") != std::string::npos );
1896 bool p_mat = ( hyp && hyp->myTextOption.find("--multinormal_angle_threshold ") != std::string::npos );
1897 bool p_sn = ( hyp && hyp->myTextOption.find("--smooth_normals ") != std::string::npos );
1900 //- boundary_layer_max_element_angle
1902 bool nolayers = false;
1903 bool layersOnAllWrap = hyp ? hyp->myLayersOnAllWrap : DefaultLayersOnAllWrap();
1911 std::cout << "!!!!! CommandToRun help only !!!! " << cmd << std::endl;
1916 cmd << " --verbose " << hyp->myVerboseLevel;
1918 if ( !p_mnot && hyp )
1919 cmd << " --max_number_of_threads " << 8; //TODO getenv NB CPU
1922 if ( !p_nobl && hyp ) {
1923 if ( hyp->myNbOfBoundaryLayers < 1 ) nolayers = true;
1925 if ( !p_hotfl && hyp ) {
1926 if ( hyp->myHeightFirstLayer < 1e-50 ) nolayers = true;
1929 if ( !p_blsd && hyp ) {
1930 if ( hyp->myBoundaryLayersGrowth >= 0 && hyp->myBoundaryLayersGrowth <= 1 ) {
1931 const char* value[] = { "-1" , "1" }; // -1 == inside
1932 cmd << " --normal_direction " << value[ hyp->myBoundaryLayersGrowth ];
1936 if ( !p_hotfl && hyp ) {
1937 cmd << " --boundary_layer_global_initial_height " << hyp->myHeightFirstLayer;
1940 if ( !p_nobl && hyp ) {
1941 cmd << " --number_of_boundary_layers " << ( nolayers ? 0 : hyp->myNbOfBoundaryLayers );
1944 if ( !p_blgp && hyp ) {
1945 cmd << " --boundary_layer_geometric_progression " << hyp->myBoundaryLayersProgression;
1948 if ( !nolayers && hyp )
1950 cmd << " --boundary_layer_size_mode " << ( layersOnAllWrap ? "global" : "local" );
1952 if ( !layersOnAllWrap )
1954 // faces with layers
1955 const std::vector<int>& faceLayersIDs = hyp->GetFacesWithLayers();
1956 if ( !faceLayersIDs.empty() )
1957 cmd << " --boundary_layer_surface_tags ";
1958 for ( size_t i = 0; i < faceLayersIDs.size(); ++i )
1959 cmd << faceLayersIDs[i] << ",";
1960 if ( !faceLayersIDs.empty() )
1961 cmd << " --boundary_layer_initial_height_on_surface_tags ";
1962 for ( size_t i = 0; i < faceLayersIDs.size(); ++i )
1963 cmd << hyp->myHeightFirstLayer << ",";
1965 // faces with imprinting
1966 const std::vector<int>& faceImprintingIDs = hyp->GetFacesWithImprinting();
1967 if ( !faceImprintingIDs.empty() )
1968 cmd << " --boundary_layer_imprinting yes --boundary_layer_imprinting_tags ";
1969 for ( size_t i = 0; i < faceImprintingIDs.size(); ++i )
1970 cmd << faceImprintingIDs[i] << ",";
1972 // faces with snapping
1973 const std::vector<int>& faceSnappingIDs = hyp->GetFacesWithSnapping();
1974 if ( !faceSnappingIDs.empty() )
1975 cmd << " --boundary_layer_snapping yes --boundary_layer_snapping_tags ";
1976 for ( size_t i = 0; i < faceSnappingIDs.size(); ++i )
1977 cmd << faceSnappingIDs[i] << ",";
1981 if ( !p_eg && hyp ) {
1982 if ( hyp->myElementGeneration >= 0 && hyp->myElementGeneration <= 2 ) {
1983 const char* value[] = { "tetra-dominant" , "hexa-dominant", "cartesian_core" };
1984 cmd << " --element_generation " << value[ hyp->myElementGeneration ];
1988 if ( !p_cs && hyp ) {
1989 if ( hyp->myCoreSize >= 0 ) {
1990 cmd << " --global_physical_size " << hyp->myCoreSize;
1994 if ( !p_cm && hyp ) {
1995 if ( hyp->myCollisionMode >= 0 && hyp->myCollisionMode <= 1 ) {
1996 const char* value[] = { "decrease" , "stop" };
1997 cmd << " --collision_mode " << value[ hyp->myCollisionMode ];
2001 if ( !p_am && hyp ) {
2002 int res = hyp->myAddMultinormals ? 0 : 1 ;
2003 const char* value[] = { "yes" , "no" };
2004 cmd << " --add_multinormals " << value[ res ];
2007 if ( !p_mat && hyp ) {
2008 cmd << " --multinormal_angle_threshold " << hyp->myMultinormalsAngle;
2011 if ( !p_sn && hyp ) {
2012 int res = hyp->mySmoothNormals ? 0 : 1 ;
2013 const char* value[] = { "yes" , "no" };
2014 cmd << " --smooth_normals " << value[ res ];
2018 if ( hyp && !hyp->myTextOption.empty() ) {
2019 cmd += " " + hyp->myTextOption;
2024 //std::cout << "!!!!!CommandToRun end " << cmd << std::endl;
2029 //================================================================================
2031 * \brief Return a unique file name
2033 //================================================================================
2035 std::string HYBRIDPlugin_Hypothesis::GetFileName(const HYBRIDPlugin_Hypothesis* hyp)
2037 std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
2038 const char lastChar = *aTmpDir.rbegin();
2040 if(lastChar != '\\') aTmpDir+='\\';
2042 if(lastChar != '/') aTmpDir+='/';
2045 SMESH_Comment aGenericName = aTmpDir;
2046 aGenericName << "HYBRID_";
2047 aGenericName << getpid();
2048 aGenericName << "_";
2049 aGenericName << Abs((Standard_Integer)(long) aGenericName.c_str());
2051 return aGenericName;
2054 //================================================================================
2056 * Return the name of executable
2058 //================================================================================
2060 std::string HYBRIDPlugin_Hypothesis::GetExeName()
2062 //call mg-hybrid.bash is script which assumes new project version(s) mg-hybrid.exe in the prerequisite base and special? licence.
2064 return "mg-hybrid.exe";
2066 return "mg-hybrid.bash";
2070 //================================================================================
2072 * \brief Return the enforced vertices
2074 //================================================================================
2076 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexList HYBRIDPlugin_Hypothesis::GetEnforcedVertices(const HYBRIDPlugin_Hypothesis* hyp)
2078 return hyp ? hyp->_GetEnforcedVertices():DefaultHYBRIDEnforcedVertexList();
2081 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesCoordsSize (const HYBRIDPlugin_Hypothesis* hyp)
2083 return hyp ? hyp->_GetEnforcedVerticesCoordsSize(): DefaultHYBRIDEnforcedVertexCoordsValues();
2086 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexEntryValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesEntrySize (const HYBRIDPlugin_Hypothesis* hyp)
2088 return hyp ? hyp->_GetEnforcedVerticesEntrySize(): DefaultHYBRIDEnforcedVertexEntryValues();
2091 HYBRIDPlugin_Hypothesis::TCoordsHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByCoords (const HYBRIDPlugin_Hypothesis* hyp)
2093 return hyp ? hyp->_GetEnforcedVerticesByCoords(): DefaultCoordsHYBRIDEnforcedVertexMap();
2096 HYBRIDPlugin_Hypothesis::TGeomEntryHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByEntry (const HYBRIDPlugin_Hypothesis* hyp)
2098 return hyp ? hyp->_GetEnforcedVerticesByEntry(): DefaultGeomEntryHYBRIDEnforcedVertexMap();
2101 HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedNodes(const HYBRIDPlugin_Hypothesis* hyp)
2103 return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeGroupMap();
2106 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedEdges(const HYBRIDPlugin_Hypothesis* hyp)
2108 return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemGroupMap();
2111 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(const HYBRIDPlugin_Hypothesis* hyp)
2113 return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemGroupMap();
2116 HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp)
2118 return hyp ? hyp->_GetNodeIDToSizeMap(): DefaultID2SizeMap();
2121 HYBRIDPlugin_Hypothesis::TSetStrings HYBRIDPlugin_Hypothesis::GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp)
2123 return hyp ? hyp->_GetGroupsToRemove(): DefaultGroupsToRemove();