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"
27 #include <SMESH_ProxyMesh.hxx>
28 #include <SMESH_Group.hxx>
29 #include <StdMeshers_QuadToTriaAdaptor.hxx>
31 #include <TCollection_AsciiString.hxx>
35 #define getpid _getpid
38 //=======================================================================
39 //function : HYBRIDPlugin_Hypothesis
40 //=======================================================================
42 HYBRIDPlugin_Hypothesis::HYBRIDPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen)
43 : SMESH_Hypothesis(hypId, studyId, gen),
44 myToMeshHoles(DefaultMeshHoles()),
45 myLayersOnAllWrap(DefaultLayersOnAllWrap()),
46 myToMakeGroupsOfDomains(DefaultToMakeGroupsOfDomains()),
49 myOptimizationLevel(DefaultOptimizationLevel()),
50 myCollisionMode(DefaultCollisionMode()),
51 myBoundaryLayersGrowth(DefaultBoundaryLayersGrowth()),
52 myElementGeneration(DefaultElementGeneration()),
53 myKeepFiles(DefaultKeepFiles()),
54 myWorkingDirectory(DefaultWorkingDirectory()),
55 myVerboseLevel(DefaultVerboseLevel()),
56 myToCreateNewNodes(DefaultToCreateNewNodes()),
57 myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()),
58 myToUseFemCorrection(DefaultToUseFEMCorrection()),
59 myToRemoveCentralPoint(DefaultToRemoveCentralPoint()),
60 myLogInStandardOutput(DefaultStandardOutputLog()),
61 myGradation(DefaultGradation()),
62 myAddMultinormals(DefaultAddMultinormals()),
63 mySmoothNormals(DefaultSmoothNormals()),
64 myHeightFirstLayer(DefaultHeightFirstLayer()),
65 myBoundaryLayersProgression(DefaultBoundaryLayersProgression()),
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 : SetToMeshHoles
108 //=======================================================================
110 void HYBRIDPlugin_Hypothesis::SetToMeshHoles(bool toMesh)
112 if ( myToMeshHoles != toMesh ) {
113 myToMeshHoles = toMesh;
114 NotifySubMeshesHypothesisModification();
118 //=======================================================================
119 //function : GetToMeshHoles
120 //=======================================================================
122 bool HYBRIDPlugin_Hypothesis::GetToMeshHoles(bool checkFreeOption) const
124 if (checkFreeOption && !myTextOption.empty()) {
125 if ( myTextOption.find("-c 0"))
127 if ( myTextOption.find("-c 1"))
130 return myToMeshHoles;
133 //=======================================================================
134 //function : SetToMakeGroupsOfDomains
135 //=======================================================================
137 void HYBRIDPlugin_Hypothesis::SetToMakeGroupsOfDomains(bool toMakeGroups)
139 if ( myToMakeGroupsOfDomains != toMakeGroups ) {
140 myToMakeGroupsOfDomains = toMakeGroups;
141 NotifySubMeshesHypothesisModification();
145 //=======================================================================
146 //function : GetToMakeGroupsOfDomains
147 //=======================================================================
149 bool HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains() const
151 return myToMakeGroupsOfDomains;
154 //=======================================================================
155 //function : GetToMakeGroupsOfDomains
156 //=======================================================================
158 bool HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains(const HYBRIDPlugin_Hypothesis* hyp)
161 if ( hyp ) res = /*hyp->GetToMeshHoles(true) &&*/ hyp->GetToMakeGroupsOfDomains();
162 else res = /*DefaultMeshHoles() &&*/ DefaultToMakeGroupsOfDomains();
166 //=======================================================================
167 //function : SetMaximumMemory
168 //=======================================================================
170 void HYBRIDPlugin_Hypothesis::SetMaximumMemory(double MB)
172 if ( myMaximumMemory != MB ) {
173 myMaximumMemory = MB;
174 NotifySubMeshesHypothesisModification();
178 //=======================================================================
179 //function : GetMaximumMemory
180 // * automatic memory adjustment mode. Default is zero
181 //=======================================================================
183 double HYBRIDPlugin_Hypothesis::GetMaximumMemory() const
185 return myMaximumMemory;
188 //=======================================================================
189 //function : SetInitialMemory
190 //=======================================================================
192 void HYBRIDPlugin_Hypothesis::SetInitialMemory(double MB)
194 if ( myInitialMemory != MB ) {
195 myInitialMemory = MB;
196 NotifySubMeshesHypothesisModification();
200 //=======================================================================
201 //function : GetInitialMemory
202 //=======================================================================
204 double HYBRIDPlugin_Hypothesis::GetInitialMemory() const
206 return myInitialMemory;
209 //=======================================================================
210 //function : SetOptimizationLevel
211 //=======================================================================
213 void HYBRIDPlugin_Hypothesis::SetOptimizationLevel(OptimizationLevel level)
215 if ( myOptimizationLevel != level ) {
216 myOptimizationLevel = level;
217 NotifySubMeshesHypothesisModification();
221 //=======================================================================
222 //function : GetOptimizationLevel
223 //=======================================================================
224 HYBRIDPlugin_Hypothesis::OptimizationLevel HYBRIDPlugin_Hypothesis::GetOptimizationLevel() const
226 return (OptimizationLevel) myOptimizationLevel;
229 //=======================================================================
230 //function : SetCollisionMode
231 //=======================================================================
232 void HYBRIDPlugin_Hypothesis::SetCollisionMode(CollisionMode mode)
234 if ( myCollisionMode != mode ) {
235 myCollisionMode = mode;
236 NotifySubMeshesHypothesisModification();
240 //=======================================================================
241 //function : GetCollisionMode
242 //=======================================================================
243 HYBRIDPlugin_Hypothesis::CollisionMode HYBRIDPlugin_Hypothesis::GetCollisionMode() const
245 return (CollisionMode) myCollisionMode;
248 //=======================================================================
249 //function : SetBoundaryLayersGrowth
250 //=======================================================================
251 void HYBRIDPlugin_Hypothesis::SetBoundaryLayersGrowth(BoundaryLayersGrowth mode)
253 if ( myBoundaryLayersGrowth != mode ) {
254 myBoundaryLayersGrowth = mode;
255 NotifySubMeshesHypothesisModification();
259 //=======================================================================
260 //function : GetBoundaryLayersGrowth
261 //=======================================================================
262 HYBRIDPlugin_Hypothesis::BoundaryLayersGrowth HYBRIDPlugin_Hypothesis::GetBoundaryLayersGrowth() const
264 return (BoundaryLayersGrowth) myBoundaryLayersGrowth;
267 //=======================================================================
268 //function : SetElementGeneration
269 //=======================================================================
270 void HYBRIDPlugin_Hypothesis::SetElementGeneration(ElementGeneration mode)
272 if ( myElementGeneration != mode ) {
273 myElementGeneration = mode;
274 NotifySubMeshesHypothesisModification();
278 //=======================================================================
279 //function : GetElementGeneration
280 //=======================================================================
281 HYBRIDPlugin_Hypothesis::ElementGeneration HYBRIDPlugin_Hypothesis::GetElementGeneration() const
283 return (ElementGeneration) myElementGeneration;
286 //=======================================================================
287 //function : SetAddMultinormals
288 //=======================================================================
289 void HYBRIDPlugin_Hypothesis::SetAddMultinormals(bool toAddMultinormals)
291 if ( myAddMultinormals != toAddMultinormals ) {
292 myAddMultinormals = toAddMultinormals;
293 NotifySubMeshesHypothesisModification();
297 //=======================================================================
298 //function : GetAddMultinormals
299 //=======================================================================
301 bool HYBRIDPlugin_Hypothesis::GetAddMultinormals() const
303 return myAddMultinormals;
306 //=======================================================================
307 //function : SetSmoothNormals
308 //=======================================================================
310 void HYBRIDPlugin_Hypothesis::SetSmoothNormals(bool toSmoothNormals)
312 if ( mySmoothNormals != toSmoothNormals ) {
313 mySmoothNormals = toSmoothNormals;
314 NotifySubMeshesHypothesisModification();
318 //=======================================================================
319 //function : GetSmoothNormals
320 //=======================================================================
322 bool HYBRIDPlugin_Hypothesis::GetSmoothNormals() const
324 return mySmoothNormals;
327 //=======================================================================
328 //function : SetHeightFirstLayer
329 //=======================================================================
331 void HYBRIDPlugin_Hypothesis::SetHeightFirstLayer(double toHeightFirstLayer)
333 if ( myHeightFirstLayer != toHeightFirstLayer ) {
334 myHeightFirstLayer = toHeightFirstLayer;
335 NotifySubMeshesHypothesisModification();
339 //=======================================================================
340 //function : GetHeightFirstLayer
341 //=======================================================================
343 double HYBRIDPlugin_Hypothesis::GetHeightFirstLayer() const
345 return myHeightFirstLayer;
348 //=======================================================================
349 //function : SetBoundaryLayersProgression
350 //=======================================================================
352 void HYBRIDPlugin_Hypothesis::SetBoundaryLayersProgression(double toBoundaryLayersProgression)
354 if ( myBoundaryLayersProgression != toBoundaryLayersProgression ) {
355 myBoundaryLayersProgression = toBoundaryLayersProgression;
356 NotifySubMeshesHypothesisModification();
360 //=======================================================================
361 //function : GetBoundaryLayersProgression
362 //=======================================================================
364 double HYBRIDPlugin_Hypothesis::GetBoundaryLayersProgression() const
366 return myBoundaryLayersProgression;
369 //=======================================================================
370 //function : SetMultinormalsAngle
371 //=======================================================================
373 void HYBRIDPlugin_Hypothesis::SetMultinormalsAngle(double toMultinormalsAngle)
375 if ( myMultinormalsAngle != toMultinormalsAngle ) {
376 myMultinormalsAngle = toMultinormalsAngle;
377 NotifySubMeshesHypothesisModification();
381 //=======================================================================
382 //function : GetMultinormalsAngle
383 //=======================================================================
385 double HYBRIDPlugin_Hypothesis::GetMultinormalsAngle() const
387 return myMultinormalsAngle;
390 //=======================================================================
391 //function : SetNbOfBoundaryLayers
392 //=======================================================================
394 void HYBRIDPlugin_Hypothesis::SetNbOfBoundaryLayers(short toNbOfBoundaryLayers)
396 if ( myNbOfBoundaryLayers != toNbOfBoundaryLayers ) {
397 myNbOfBoundaryLayers = toNbOfBoundaryLayers;
398 NotifySubMeshesHypothesisModification();
402 //=======================================================================
403 //function : GetMultinormalsAngle
404 //=======================================================================
406 short HYBRIDPlugin_Hypothesis::GetNbOfBoundaryLayers() const
408 return myNbOfBoundaryLayers;
412 /////////////////////////////////////////////////////////////////////////
415 //=======================================================================
416 //function : SetWorkingDirectory
417 //=======================================================================
419 void HYBRIDPlugin_Hypothesis::SetWorkingDirectory(const std::string& path)
421 if ( myWorkingDirectory != path ) {
422 myWorkingDirectory = path;
423 NotifySubMeshesHypothesisModification();
427 //=======================================================================
428 //function : GetWorkingDirectory
429 //=======================================================================
431 std::string HYBRIDPlugin_Hypothesis::GetWorkingDirectory() const
433 return myWorkingDirectory;
436 //=======================================================================
437 //function : SetKeepFiles
438 //=======================================================================
440 void HYBRIDPlugin_Hypothesis::SetKeepFiles(bool toKeep)
442 if ( myKeepFiles != toKeep ) {
443 myKeepFiles = toKeep;
444 NotifySubMeshesHypothesisModification();
448 //=======================================================================
449 //function : GetKeepFiles
450 //=======================================================================
452 bool HYBRIDPlugin_Hypothesis::GetKeepFiles() const
457 //=======================================================================
458 //function : SetVerboseLevel
459 //=======================================================================
461 void HYBRIDPlugin_Hypothesis::SetVerboseLevel(short level)
463 if ( myVerboseLevel != level ) {
464 myVerboseLevel = level;
465 NotifySubMeshesHypothesisModification();
469 //=======================================================================
470 //function : GetVerboseLevel
471 //=======================================================================
473 short HYBRIDPlugin_Hypothesis::GetVerboseLevel() const
475 return myVerboseLevel;
478 //=======================================================================
479 //function : SetToCreateNewNodes
480 //=======================================================================
482 void HYBRIDPlugin_Hypothesis::SetToCreateNewNodes(bool toCreate)
484 if ( myToCreateNewNodes != toCreate ) {
485 myToCreateNewNodes = toCreate;
486 NotifySubMeshesHypothesisModification();
490 //=======================================================================
491 //function : GetToCreateNewNodes
492 //=======================================================================
494 bool HYBRIDPlugin_Hypothesis::GetToCreateNewNodes() const
496 return myToCreateNewNodes;
499 //=======================================================================
500 //function : SetToUseBoundaryRecoveryVersion
501 //=======================================================================
503 void HYBRIDPlugin_Hypothesis::SetToUseBoundaryRecoveryVersion(bool toUse)
505 if ( myToUseBoundaryRecoveryVersion != toUse ) {
506 myToUseBoundaryRecoveryVersion = toUse;
507 NotifySubMeshesHypothesisModification();
511 //=======================================================================
512 //function : GetToUseBoundaryRecoveryVersion
513 //=======================================================================
515 bool HYBRIDPlugin_Hypothesis::GetToUseBoundaryRecoveryVersion() const
517 return myToUseBoundaryRecoveryVersion;
520 //=======================================================================
521 //function : SetFEMCorrection
522 //=======================================================================
524 void HYBRIDPlugin_Hypothesis::SetFEMCorrection(bool toUseFem)
526 if ( myToUseFemCorrection != toUseFem ) {
527 myToUseFemCorrection = toUseFem;
528 NotifySubMeshesHypothesisModification();
532 //=======================================================================
533 //function : GetFEMCorrection
534 //=======================================================================
536 bool HYBRIDPlugin_Hypothesis::GetFEMCorrection() const
538 return myToUseFemCorrection;
541 //=======================================================================
542 //function : SetToRemoveCentralPoint
543 //=======================================================================
545 void HYBRIDPlugin_Hypothesis::SetToRemoveCentralPoint(bool toRemove)
547 if ( myToRemoveCentralPoint != toRemove ) {
548 myToRemoveCentralPoint = toRemove;
549 NotifySubMeshesHypothesisModification();
553 //=======================================================================
554 //function : GetToRemoveCentralPoint
555 //=======================================================================
557 bool HYBRIDPlugin_Hypothesis::GetToRemoveCentralPoint() const
559 return myToRemoveCentralPoint;
562 //=======================================================================
563 //function : SetTextOption
564 //=======================================================================
566 void HYBRIDPlugin_Hypothesis::SetTextOption(const std::string& option)
568 if ( myTextOption != option ) {
569 myTextOption = option;
570 NotifySubMeshesHypothesisModification();
574 //=======================================================================
575 //function : GetTextOption
576 //=======================================================================
578 std::string HYBRIDPlugin_Hypothesis::GetTextOption() const
583 //=======================================================================
584 //function : SetGradation
585 //=======================================================================
587 void HYBRIDPlugin_Hypothesis::SetGradation(double gradation)
589 if ( myGradation != gradation ) {
590 myGradation = gradation;
591 NotifySubMeshesHypothesisModification();
595 //=======================================================================
596 //function : GetGradation
597 //=======================================================================
599 double HYBRIDPlugin_Hypothesis::GetGradation() const
604 //=======================================================================
605 //function : SetStandardOutputLog
606 //=======================================================================
608 void HYBRIDPlugin_Hypothesis::SetStandardOutputLog(bool logInStandardOutput)
610 if ( myLogInStandardOutput != logInStandardOutput ) {
611 myLogInStandardOutput = logInStandardOutput;
612 NotifySubMeshesHypothesisModification();
616 //=======================================================================
617 //function : GetStandardOutputLog
618 //=======================================================================
620 bool HYBRIDPlugin_Hypothesis::GetStandardOutputLog() const
622 return myLogInStandardOutput;
625 //=======================================================================
626 //function : SetRemoveLogOnSuccess
627 //=======================================================================
629 void HYBRIDPlugin_Hypothesis::SetRemoveLogOnSuccess(bool removeLogOnSuccess)
631 if ( myRemoveLogOnSuccess != removeLogOnSuccess ) {
632 myRemoveLogOnSuccess = removeLogOnSuccess;
633 NotifySubMeshesHypothesisModification();
637 //=======================================================================
638 //function : GetRemoveLogOnSuccess
639 //=======================================================================
641 bool HYBRIDPlugin_Hypothesis::GetRemoveLogOnSuccess() const
643 return myRemoveLogOnSuccess;
646 //=======================================================================
647 //function : SetEnforcedVertex
648 //=======================================================================
650 bool HYBRIDPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string theEntry, std::string theGroupName,
651 double size, double x, double y, double z, bool isCompound)
653 MESSAGE("HYBRIDPlugin_Hypothesis::SetEnforcedVertex(\""<< theName << "\", \""<< theEntry << "\", \"" << theGroupName << "\", "
654 << size << ", " << x << ", " << y << ", " << z << ", "<< isCompound << ")");
656 bool toNotify = false;
657 bool toCreate = true;
659 THYBRIDEnforcedVertex *oldEnVertex;
660 THYBRIDEnforcedVertex *newEnfVertex = new THYBRIDEnforcedVertex();
661 newEnfVertex->name = theName;
662 newEnfVertex->geomEntry = theEntry;
663 newEnfVertex->coords.clear();
665 newEnfVertex->coords.push_back(x);
666 newEnfVertex->coords.push_back(y);
667 newEnfVertex->coords.push_back(z);
669 newEnfVertex->groupName = theGroupName;
670 newEnfVertex->size = size;
671 newEnfVertex->isCompound = isCompound;
674 // update _enfVertexList
675 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(newEnfVertex);
676 if (it != _enfVertexList.end()) {
679 MESSAGE("Enforced Vertex was found => Update");
680 if (oldEnVertex->name != theName) {
681 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theName << "\"");
682 oldEnVertex->name = theName;
685 if (oldEnVertex->groupName != theGroupName) {
686 MESSAGE("Update group name from \"" << oldEnVertex->groupName << "\" to \"" << theGroupName << "\"");
687 oldEnVertex->groupName = theGroupName;
690 if (oldEnVertex->size != size) {
691 MESSAGE("Update size from \"" << oldEnVertex->size << "\" to \"" << size << "\"");
692 oldEnVertex->size = size;
696 // update map coords / enf vertex if needed
697 if (oldEnVertex->coords.size()) {
698 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
699 _enfVertexCoordsSizeList[oldEnVertex->coords] = size;
702 // update map geom entry / enf vertex if needed
703 if (oldEnVertex->geomEntry != "") {
704 _geomEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
705 _enfVertexEntrySizeList[oldEnVertex->geomEntry] = size;
710 // //////// CREATE ////////////
713 MESSAGE("Creating new enforced vertex");
714 _enfVertexList.insert(newEnfVertex);
715 if (theEntry == "") {
716 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
717 _enfVertexCoordsSizeList[newEnfVertex->coords] = size;
720 _geomEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
721 _enfVertexEntrySizeList[newEnfVertex->geomEntry] = size;
726 NotifySubMeshesHypothesisModification();
728 MESSAGE("HYBRIDPlugin_Hypothesis::SetEnforcedVertex END");
733 //=======================================================================
734 //function : SetEnforcedMesh
735 //=======================================================================
736 bool HYBRIDPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName)
738 TIDSortedElemSet theElemSet;
739 SMDS_ElemIteratorPtr eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType));
740 while ( eIt->more() )
741 theElemSet.insert( eIt->next() );
742 MESSAGE("Add "<<theElemSet.size()<<" types["<<elementType<<"] from source mesh");
743 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
745 THYBRIDEnforcedMesh* newEnfMesh = new THYBRIDEnforcedMesh();
746 newEnfMesh->persistID = theMesh.GetMeshDS()->GetPersistentId();
747 newEnfMesh->name = name;
748 newEnfMesh->entry = entry;
749 newEnfMesh->elementType = elementType;
750 newEnfMesh->groupName = groupName;
752 THYBRIDEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
753 if (it == _enfMeshList.end()) {
754 _entryEnfMeshMap[entry].insert(newEnfMesh);
755 _enfMeshList.insert(newEnfMesh);
764 //=======================================================================
765 //function : SetEnforcedGroup
766 //=======================================================================
767 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)
769 MESSAGE("HYBRIDPlugin_Hypothesis::SetEnforcedGroup");
770 TIDSortedElemSet theElemSet;
771 if ( theIDs->length() == 0 ){MESSAGE("The source group is empty");}
772 for ( CORBA::ULong i = 0; i < theIDs->length(); i++) {
773 CORBA::Long ind = theIDs[i];
774 if (elementType == SMESH::NODE)
776 const SMDS_MeshNode * node = theMeshDS->FindNode(ind);
778 theElemSet.insert( node );
782 const SMDS_MeshElement * elem = theMeshDS->FindElement(ind);
784 theElemSet.insert( elem );
788 // SMDS_ElemIteratorPtr it = theGroup->GetGroupDS()->GetElements();
789 // while ( it->more() )
790 // theElemSet.insert( it->next() );
792 MESSAGE("Add "<<theElemSet.size()<<" types["<<elementType<<"] from source group ");
793 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
795 THYBRIDEnforcedMesh* newEnfMesh = new THYBRIDEnforcedMesh();
796 newEnfMesh->name = name;
797 newEnfMesh->entry = entry;
798 newEnfMesh->elementType = elementType;
799 newEnfMesh->groupName = groupName;
801 THYBRIDEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
802 if (it == _enfMeshList.end()) {
803 _entryEnfMeshMap[entry].insert(newEnfMesh);
804 _enfMeshList.insert(newEnfMesh);
810 //=======================================================================
811 //function : SetEnforcedElements
812 //=======================================================================
813 bool HYBRIDPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName)
815 MESSAGE("HYBRIDPlugin_Hypothesis::SetEnforcedElements");
816 TIDSortedElemSet::const_iterator it = theElemSet.begin();
817 const SMDS_MeshElement* elem;
818 const SMDS_MeshNode* node;
820 std::pair<TIDSortedNodeGroupMap::iterator,bool> nodeRet;
821 std::pair<TIDSortedElemGroupMap::iterator,bool> elemRet;
823 for (;it != theElemSet.end();++it)
826 switch (elementType) {
828 node = dynamic_cast<const SMDS_MeshNode*>(elem);
830 nodeRet = _enfNodes.insert(make_pair(node,groupName));
831 added = added && nodeRet.second;
832 std::string msg = added ? "yes":"no";
833 MESSAGE( "Node (" <<node->X()<<","<<node->Y()<<","<<node->Z()<< ") with ID " << node->GetID() <<" added ? " << msg);
836 SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
837 for (;nodeIt->more();) {
838 node = dynamic_cast<const SMDS_MeshNode*>(nodeIt->next());
839 nodeRet = _enfNodes.insert(make_pair(node,groupName));
840 added = added && nodeRet.second;
846 if (elem->GetType() == SMDSAbs_Edge) {
847 elemRet = _enfEdges.insert(make_pair(elem,groupName));
848 added = added && elemRet.second;
850 else if (elem->GetType() > SMDSAbs_Edge) {
851 SMDS_ElemIteratorPtr it = elem->edgesIterator();
853 const SMDS_MeshElement* anEdge = it->next();
854 elemRet = _enfEdges.insert(make_pair(anEdge,groupName));
855 added = added && elemRet.second;
860 if (elem->GetType() == SMDSAbs_Face)
862 if (elem->NbCornerNodes() == 3) {
863 elemRet = _enfTriangles.insert(make_pair(elem,groupName));
864 added = added && elemRet.second;
867 else if (elem->GetType() > SMDSAbs_Face) { // Group of faces
868 SMDS_ElemIteratorPtr it = elem->facesIterator();
870 const SMDS_MeshElement* aFace = it->next();
871 if (aFace->NbCornerNodes() == 3) {
872 elemRet = _enfTriangles.insert(make_pair(aFace,groupName));
873 added = added && elemRet.second;
883 NotifySubMeshesHypothesisModification();
888 //=======================================================================
889 //function : GetEnforcedVertex
890 //=======================================================================
892 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z)
893 throw (std::invalid_argument)
895 std::vector<double> coord(3);
899 if (_coordsEnfVertexMap.count(coord)>0)
900 return _coordsEnfVertexMap[coord];
901 std::ostringstream msg ;
902 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
903 throw std::invalid_argument(msg.str());
906 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(const std::string theEntry)
907 throw (std::invalid_argument)
909 if (_geomEntryEnfVertexMap.count(theEntry)>0)
910 return _geomEntryEnfVertexMap[theEntry];
912 std::ostringstream msg ;
913 msg << "No enforced vertex with entry " << theEntry;
914 throw std::invalid_argument(msg.str());
917 //=======================================================================
918 //function : RemoveEnforcedVertex
919 //=======================================================================
921 bool HYBRIDPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, const std::string theEntry)
922 throw (std::invalid_argument)
924 bool toNotify = false;
925 std::ostringstream msg;
926 THYBRIDEnforcedVertex *oldEnfVertex;
927 std::vector<double> coords(3);
932 // check that enf vertex with given enf vertex entry exists
933 TGeomEntryHYBRIDEnforcedVertexMap::iterator it_enfVertexEntry = _geomEntryEnfVertexMap.find(theEntry);
934 if (it_enfVertexEntry != _geomEntryEnfVertexMap.end()) {
936 MESSAGE("Found enforced vertex with geom entry " << theEntry);
937 oldEnfVertex = it_enfVertexEntry->second;
938 _geomEntryEnfVertexMap.erase(it_enfVertexEntry);
941 MESSAGE("Enforced vertex with geom entry " << theEntry << " not found");
942 // check that enf vertex with given coords exists
943 TCoordsHYBRIDEnforcedVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
944 if (it_coords_enf != _coordsEnfVertexMap.end()) {
946 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
947 oldEnfVertex = it_coords_enf->second;
948 _coordsEnfVertexMap.erase(it_coords_enf);
949 _enfVertexCoordsSizeList.erase(_enfVertexCoordsSizeList.find(coords));
952 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
953 throw std::invalid_argument(msg.str());
957 MESSAGE("Remove enf vertex from _enfVertexList");
959 // update _enfVertexList
960 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
961 if (it != _enfVertexList.end()) {
962 if ((*it)->groupName != "")
963 _groupsToRemove.insert((*it)->groupName);
964 _enfVertexList.erase(it);
970 NotifySubMeshesHypothesisModification();
975 //=======================================================================
976 //function : ClearEnforcedVertices
977 //=======================================================================
978 void HYBRIDPlugin_Hypothesis::ClearEnforcedVertices()
980 THYBRIDEnforcedVertexList::const_iterator it = _enfVertexList.begin();
981 for(;it != _enfVertexList.end();++it) {
982 if ((*it)->groupName != "")
983 _groupsToRemove.insert((*it)->groupName);
985 _enfVertexList.clear();
986 _coordsEnfVertexMap.clear();
987 _geomEntryEnfVertexMap.clear();
988 _enfVertexCoordsSizeList.clear();
989 _enfVertexEntrySizeList.clear();
990 NotifySubMeshesHypothesisModification();
993 //=======================================================================
994 //function : ClearEnforcedMeshes
995 //=======================================================================
996 void HYBRIDPlugin_Hypothesis::ClearEnforcedMeshes()
998 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
999 for(;it != _enfMeshList.end();++it) {
1000 if ((*it)->groupName != "")
1001 _groupsToRemove.insert((*it)->groupName);
1005 _enfTriangles.clear();
1006 _nodeIDToSizeMap.clear();
1007 _enfMeshList.clear();
1008 _entryEnfMeshMap.clear();
1009 NotifySubMeshesHypothesisModification();
1012 //================================================================================
1014 * \brief At mesh loading, restore enforced elements by just loaded enforced meshes
1016 //================================================================================
1018 void HYBRIDPlugin_Hypothesis::RestoreEnfElemsByMeshes()
1020 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
1021 for(;it != _enfMeshList.end();++it) {
1022 THYBRIDEnforcedMesh* enfMesh = *it;
1023 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
1024 SetEnforcedMesh( *mesh,
1025 enfMesh->elementType,
1028 enfMesh->groupName );
1029 enfMesh->persistID = -1; // not to restore again
1033 //=======================================================================
1034 //function : SetGroupsToRemove
1035 //=======================================================================
1037 void HYBRIDPlugin_Hypothesis::ClearGroupsToRemove()
1039 _groupsToRemove.clear();
1043 //=======================================================================
1044 //function : DefaultLayersOnAllWrap
1045 //=======================================================================
1047 bool HYBRIDPlugin_Hypothesis::DefaultLayersOnAllWrap()
1052 //=======================================================================
1053 //function : DefaultMeshHoles
1054 //=======================================================================
1056 bool HYBRIDPlugin_Hypothesis::DefaultMeshHoles()
1058 return false; // PAL19680
1061 //=======================================================================
1062 //function : DefaultToMakeGroupsOfDomains
1063 //=======================================================================
1065 bool HYBRIDPlugin_Hypothesis::DefaultToMakeGroupsOfDomains()
1067 return false; // issue 0022172
1070 //=======================================================================
1071 //function : DefaultMaximumMemory
1072 //=======================================================================
1075 #include <sys/sysinfo.h>
1077 #include <windows.h>
1080 double HYBRIDPlugin_Hypothesis::DefaultMaximumMemory()
1084 int err = sysinfo( &si );
1086 int ramMB = si.totalram * si.mem_unit / 1024 / 1024;
1087 return ( 0.7 * ramMB );
1090 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
1091 MEMORYSTATUSEX statex;
1092 statex.dwLength = sizeof (statex);
1093 int err = GlobalMemoryStatusEx (&statex);
1096 statex.ullTotalPhys / 1024 / 1024 +
1097 statex.ullTotalPageFile / 1024 / 1024 +
1098 statex.ullTotalVirtual / 1024 / 1024;
1099 return ( 0.7 * totMB );
1105 //=======================================================================
1106 //function : DefaultInitialMemory
1107 //=======================================================================
1109 double HYBRIDPlugin_Hypothesis::DefaultInitialMemory()
1111 return DefaultMaximumMemory();
1114 //=======================================================================
1115 //function : DefaultCollisionMode
1116 //=======================================================================
1117 short HYBRIDPlugin_Hypothesis::DefaultCollisionMode()
1122 //=======================================================================
1123 //function : DefaultBoundaryLayersGrowth
1124 //=======================================================================
1125 short HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersGrowth()
1127 return Layer_Growth_Inward;
1130 //=======================================================================
1131 //function : DefaultElementGeneration
1132 //=======================================================================
1133 short HYBRIDPlugin_Hypothesis::DefaultElementGeneration()
1135 return Generation_Tetra_Dominant;
1138 //=======================================================================
1139 //function : DefaultOptimizationLevel
1140 //=======================================================================
1141 short HYBRIDPlugin_Hypothesis::DefaultOptimizationLevel()
1146 //=======================================================================
1147 //function : DefaultWorkingDirectory
1148 //=======================================================================
1150 std::string HYBRIDPlugin_Hypothesis::DefaultWorkingDirectory()
1152 TCollection_AsciiString aTmpDir;
1154 char *Tmp_dir = getenv("SALOME_TMP_DIR");
1155 if(Tmp_dir != NULL) {
1160 aTmpDir = TCollection_AsciiString("C:\\");
1162 aTmpDir = TCollection_AsciiString("/tmp/");
1165 return aTmpDir.ToCString();
1168 //=======================================================================
1169 //function : DefaultKeepFiles
1170 //=======================================================================
1172 bool HYBRIDPlugin_Hypothesis::DefaultKeepFiles()
1177 //=======================================================================
1178 //function : DefaultRemoveLogOnSuccess
1179 //=======================================================================
1181 bool HYBRIDPlugin_Hypothesis::DefaultRemoveLogOnSuccess()
1187 //=======================================================================
1188 //function : DefaultVerboseLevel
1189 //=======================================================================
1191 short HYBRIDPlugin_Hypothesis::DefaultVerboseLevel()
1196 //=======================================================================
1197 //function : DefaultToCreateNewNodes
1198 //=======================================================================
1200 bool HYBRIDPlugin_Hypothesis::DefaultToCreateNewNodes()
1205 //=======================================================================
1206 //function : DefaultToUseBoundaryRecoveryVersion
1207 //=======================================================================
1209 bool HYBRIDPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
1214 //=======================================================================
1215 //function : DefaultToUseFEMCorrection
1216 //=======================================================================
1218 bool HYBRIDPlugin_Hypothesis::DefaultToUseFEMCorrection()
1223 //=======================================================================
1224 //function : DefaultToRemoveCentralPoint
1225 //=======================================================================
1227 bool HYBRIDPlugin_Hypothesis::DefaultToRemoveCentralPoint()
1232 //=======================================================================
1233 //function : DefaultGradation
1234 //=======================================================================
1236 double HYBRIDPlugin_Hypothesis::DefaultGradation()
1241 //=======================================================================
1242 //function : DefaultStandardOutputLog
1243 //=======================================================================
1245 bool HYBRIDPlugin_Hypothesis::DefaultStandardOutputLog()
1250 // //=======================================================================
1251 // //function : DefaultID2SizeMap
1252 // //=======================================================================
1254 // HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::DefaultID2SizeMap()
1256 // return HYBRIDPlugin_Hypothesis::TID2SizeMap();
1259 //=======================================================================
1260 //function : DefaultAddMultinormals
1261 //=======================================================================
1262 bool HYBRIDPlugin_Hypothesis::DefaultAddMultinormals()
1267 //=======================================================================
1268 //function : DefaultSmoothNormals
1269 //=======================================================================
1270 bool HYBRIDPlugin_Hypothesis::DefaultSmoothNormals()
1275 //=======================================================================
1276 //function : DefaultHeightFirstLayer
1277 //=======================================================================
1278 double HYBRIDPlugin_Hypothesis::DefaultHeightFirstLayer()
1280 return 0.0; //or epsilon?
1283 //=======================================================================
1284 //function : DefaultBoundaryLayersProgression
1285 //=======================================================================
1286 double HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersProgression()
1291 //=======================================================================
1292 //function : DefaultMultinormalsAngle
1293 //=======================================================================
1294 double HYBRIDPlugin_Hypothesis::DefaultMultinormalsAngle()
1299 //=======================================================================
1300 //function : DefaultNbOfBoundaryLayers
1301 //=======================================================================
1302 short HYBRIDPlugin_Hypothesis::DefaultNbOfBoundaryLayers()
1307 //=======================================================================
1309 //=======================================================================
1311 std::ostream & HYBRIDPlugin_Hypothesis::SaveTo(std::ostream & save)
1313 save << (int) myBoundaryLayersGrowth << " ";
1314 save << (int) myElementGeneration << " ";
1315 save << (int) myAddMultinormals << " ";
1316 save << (int) mySmoothNormals << " ";
1317 save << (int) myLayersOnAllWrap << " ";
1319 save << myNbOfBoundaryLayers << " ";
1320 save << myHeightFirstLayer << " ";
1321 save << myBoundaryLayersProgression << " ";
1322 save << myMultinormalsAngle << " ";
1324 save << (int) myKeepFiles << " ";
1325 save << myWorkingDirectory << " ";
1326 save << myVerboseLevel << " ";
1327 if (!myTextOption.empty()) {
1328 save << "__OPTIONS_BEGIN__ ";
1329 save << myTextOption << " ";
1330 save << "__OPTIONS_END__ ";
1334 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.begin();
1335 if (it != _enfVertexList.end()) {
1336 save << " " << "__ENFORCED_VERTICES_BEGIN__ ";
1337 for ( ; it != _enfVertexList.end(); ++it ) {
1338 THYBRIDEnforcedVertex *enfVertex = (*it);
1339 save << " " << "__BEGIN_VERTEX__";
1340 if (!enfVertex->name.empty()) {
1341 save << " " << "__BEGIN_NAME__";
1342 save << " " << enfVertex->name;
1343 save << " " << "__END_NAME__";
1345 if (!enfVertex->geomEntry.empty()) {
1346 save << " " << "__BEGIN_ENTRY__";
1347 save << " " << enfVertex->geomEntry;
1348 save << " " << enfVertex->isCompound;
1349 save << " " << "__END_ENTRY__";
1351 if (!enfVertex->groupName.empty()) {
1352 save << " " << "__BEGIN_GROUP__";
1353 save << " " << enfVertex->groupName;
1354 save << " " << "__END_GROUP__";
1356 if (enfVertex->coords.size()) {
1357 save << " " << "__BEGIN_COORDS__";
1358 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1359 save << " " << enfVertex->coords[i];
1360 save << " " << "__END_COORDS__";
1362 save << " " << "__BEGIN_SIZE__";
1363 save << " " << enfVertex->size;
1364 save << " " << "__END_SIZE__";
1365 save << " " << "__END_VERTEX__";
1367 save << " " << "__ENFORCED_VERTICES_END__ ";
1370 THYBRIDEnforcedMeshList::iterator it_mesh = _enfMeshList.begin();
1371 if (it_mesh != _enfMeshList.end()) {
1372 save << " " << "__ENFORCED_MESHES_BEGIN__ ";
1373 for ( ; it_mesh != _enfMeshList.end(); ++it_mesh ) {
1374 THYBRIDEnforcedMesh *enfMesh = (*it_mesh);
1375 save << " " << "__BEGIN_ENF_MESH__";
1377 save << " " << "__BEGIN_NAME__";
1378 save << " " << enfMesh->name;
1379 save << " " << "__END_NAME__";
1381 save << " " << "__BEGIN_ENTRY__";
1382 save << " " << enfMesh->entry;
1383 save << " " << "__END_ENTRY__";
1385 save << " " << "__BEGIN_ELEM_TYPE__";
1386 save << " " << (int)enfMesh->elementType;
1387 save << " " << "__END_ELEM_TYPE__";
1389 if (!enfMesh->groupName.empty()) {
1390 save << " " << "__BEGIN_GROUP__";
1391 save << " " << enfMesh->groupName;
1392 save << " " << "__END_GROUP__";
1394 save << " " << "__PERSIST_ID__";
1395 save << " " << enfMesh->persistID;
1396 save << " " << "__END_ENF_MESH__";
1397 std::cout << "Saving of enforced mesh " << enfMesh->name.c_str() << " done" << std::endl;
1399 save << " " << "__ENFORCED_MESHES_END__ ";
1404 //=======================================================================
1405 //function : LoadFrom
1406 //=======================================================================
1408 std::istream & HYBRIDPlugin_Hypothesis::LoadFrom(std::istream & load)
1414 isOK = static_cast<bool>(load >> i);
1416 myBoundaryLayersGrowth = (short) i;
1418 load.clear(ios::badbit | load.rdstate());
1420 isOK = static_cast<bool>(load >> i);
1422 myElementGeneration = (short) i;
1424 load.clear(ios::badbit | load.rdstate());
1426 isOK = static_cast<bool>(load >> i);
1428 myAddMultinormals = (bool) i;
1430 load.clear(ios::badbit | load.rdstate());
1432 isOK = static_cast<bool>(load >> i);
1434 mySmoothNormals = (bool) i;
1436 load.clear(ios::badbit | load.rdstate());
1438 isOK = static_cast<bool>(load >> i);
1440 myLayersOnAllWrap = (bool) i;
1442 load.clear(ios::badbit | load.rdstate());
1444 isOK = static_cast<bool>(load >> i);
1446 myNbOfBoundaryLayers = (short) i;
1448 load.clear(ios::badbit | load.rdstate());
1450 isOK = static_cast<bool>(load >> d);
1452 myHeightFirstLayer = d;
1454 load.clear(ios::badbit | load.rdstate());
1456 isOK = static_cast<bool>(load >> d);
1458 myBoundaryLayersProgression = d;
1460 load.clear(ios::badbit | load.rdstate());
1462 isOK = static_cast<bool>(load >> d);
1464 myMultinormalsAngle = d;
1466 load.clear(ios::badbit | load.rdstate());
1468 isOK = static_cast<bool>(load >> i);
1470 myKeepFiles = (bool) i;
1472 load.clear(ios::badbit | load.rdstate());
1474 isOK = static_cast<bool>(load >> myWorkingDirectory);
1476 if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
1477 myKeepFiles = false;
1478 myWorkingDirectory.clear();
1480 else if ( myWorkingDirectory == "1" ) {
1482 myWorkingDirectory.clear();
1486 load.clear(ios::badbit | load.rdstate());
1488 if ( !myWorkingDirectory.empty() ) {
1489 isOK = static_cast<bool>(load >> i);
1493 load.clear(ios::badbit | load.rdstate());
1496 isOK = static_cast<bool>(load >> i);
1498 myVerboseLevel = (short) i;
1500 load.clear(ios::badbit | load.rdstate());
1503 std::string separator;
1504 bool hasOptions = false;
1505 bool hasEnforcedVertices = false;
1506 bool hasEnforcedMeshes = false;
1507 isOK = static_cast<bool>(load >> separator);
1509 if ( isOK && ( separator == "0" || separator == "1" ))
1511 myToMakeGroupsOfDomains = ( separator == "1" );
1512 isOK = static_cast<bool>(load >> separator);
1516 if (separator == "__OPTIONS_BEGIN__")
1518 else if (separator == "__ENFORCED_VERTICES_BEGIN__")
1519 hasEnforcedVertices = true;
1520 else if (separator == "__ENFORCED_MESHES_BEGIN__")
1521 hasEnforcedMeshes = true;
1527 isOK = static_cast<bool>(load >> txt);
1529 if (txt == "__OPTIONS_END__") {
1530 if (!myTextOption.empty()) {
1531 // Remove last space
1532 myTextOption.erase(myTextOption.end()-1);
1537 myTextOption += txt;
1538 myTextOption += " ";
1544 isOK = static_cast<bool>(load >> separator);
1545 if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__")
1546 hasEnforcedVertices = true;
1547 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1548 hasEnforcedMeshes = true;
1551 if (hasEnforcedVertices) {
1552 std::string txt, name, entry, groupName;
1553 double size, coords[3];
1555 bool hasCoords = false;
1556 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1558 if (txt == "__ENFORCED_VERTICES_END__")
1561 THYBRIDEnforcedVertex *enfVertex = new THYBRIDEnforcedVertex();
1563 isOK = static_cast<bool>(load >> txt);
1564 if (txt == "__END_VERTEX__") {
1565 enfVertex->name = name;
1566 enfVertex->geomEntry = entry;
1567 enfVertex->isCompound = isCompound;
1568 enfVertex->groupName = groupName;
1569 enfVertex->coords.clear();
1571 enfVertex->coords.assign(coords,coords+3);
1573 _enfVertexList.insert(enfVertex);
1575 if (enfVertex->coords.size())
1576 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1577 if (!enfVertex->geomEntry.empty())
1578 _geomEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1587 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1588 while (isOK && (txt != "__END_NAME__")) {
1589 isOK = static_cast<bool>(load >> txt);
1590 if (txt != "__END_NAME__") {
1596 MESSAGE("name: " <<name);
1599 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1600 isOK = static_cast<bool>(load >> entry);
1601 isOK = static_cast<bool>(load >> isCompound);
1602 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1603 if (txt != "__END_ENTRY__")
1604 throw std::exception();
1605 MESSAGE("entry: " << entry);
1608 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1609 while (isOK && (txt != "__END_GROUP__")) {
1610 isOK = static_cast<bool>(load >> txt);
1611 if (txt != "__END_GROUP__") {
1612 if (!groupName.empty())
1617 MESSAGE("groupName: " << groupName);
1620 if (txt == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1622 isOK = static_cast<bool>(load >> coords[0] >> coords[1] >> coords[2]);
1623 isOK = static_cast<bool>(load >> txt); // __END_COORDS__
1624 if (txt != "__END_COORDS__")
1625 throw std::exception();
1626 MESSAGE("coords: " << coords[0] <<","<< coords[1] <<","<< coords[2]);
1629 if (txt == "__BEGIN_SIZE__") { // __BEGIN_ENTRY__
1630 isOK = static_cast<bool>(load >> size);
1631 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1632 if (txt != "__END_SIZE__") {
1633 throw std::exception();
1635 MESSAGE("size: " << size);
1638 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1642 if (hasEnforcedVertices) {
1643 isOK = static_cast<bool>(load >> separator);
1644 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1645 hasEnforcedMeshes = true;
1648 if (hasEnforcedMeshes) {
1649 std::string txt, name, entry, groupName;
1650 int elementType = -1, persistID = -1;
1651 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1654 if (txt == "__ENFORCED_MESHES_END__")
1657 THYBRIDEnforcedMesh *enfMesh = new THYBRIDEnforcedMesh();
1659 isOK = static_cast<bool>(load >> txt);
1660 if (txt == "__END_ENF_MESH__") {
1661 enfMesh->name = name;
1662 enfMesh->entry = entry;
1663 enfMesh->elementType = (SMESH::ElementType)elementType;
1664 enfMesh->groupName = groupName;
1665 enfMesh->persistID = persistID;
1667 _enfMeshList.insert(enfMesh);
1668 std::cout << "Restoring of enforced mesh " <<name << " done" << std::endl;
1678 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1679 while (isOK && (txt != "__END_NAME__")) {
1680 isOK = static_cast<bool>(load >> txt);
1681 if (txt != "__END_NAME__") {
1687 MESSAGE("name: " <<name);
1690 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1691 isOK = static_cast<bool>(load >> entry);
1692 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1693 if (txt != "__END_ENTRY__")
1694 throw std::exception();
1695 MESSAGE("entry: " << entry);
1698 if (txt == "__BEGIN_ELEM_TYPE__") { // __BEGIN_ELEM_TYPE__
1699 isOK = static_cast<bool>(load >> elementType);
1700 isOK = static_cast<bool>(load >> txt); // __END_ELEM_TYPE__
1701 if (txt != "__END_ELEM_TYPE__")
1702 throw std::exception();
1703 MESSAGE("elementType: " << elementType);
1706 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1707 while (isOK && (txt != "__END_GROUP__")) {
1708 isOK = static_cast<bool>(load >> txt);
1709 if (txt != "__END_GROUP__") {
1710 if (!groupName.empty())
1715 MESSAGE("groupName: " << groupName);
1718 if (txt == "__PERSIST_ID__") {
1719 isOK = static_cast<bool>(load >> persistID);
1720 MESSAGE("persistID: " << persistID);
1722 std::cout << "isOK: " << isOK << std::endl;
1725 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1732 //=======================================================================
1733 //function : SetParametersByMesh
1734 //=======================================================================
1736 bool HYBRIDPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
1742 //================================================================================
1744 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
1746 //================================================================================
1748 bool HYBRIDPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
1749 const SMESH_Mesh* /*theMesh*/)
1751 myToMakeGroupsOfDomains = ( !dflts._shape || dflts._shape->IsNull() );
1755 //================================================================================
1757 * \brief Return command to run hybrid mesher excluding file prefix (-f)
1759 //================================================================================
1761 std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis* hyp,
1762 const bool hasShapeToMesh)
1764 TCollection_AsciiString cmd = GetExeName().c_str();
1765 // check if any option is overridden by hyp->myTextOption
1766 bool p_h = ( hyp && hyp->myTextOption.find("-h") != std::string::npos );
1767 bool p_v = ( hyp && hyp->myTextOption.find("-v ") != std::string::npos );
1768 bool p_i = ( hyp && hyp->myTextOption.find("-i") != std::string::npos );
1769 bool p_o = ( hyp && hyp->myTextOption.find("-o") != std::string::npos );
1770 bool p_mnot = ( hyp && hyp->myTextOption.find("--max_number_of_threads ") != std::string::npos );
1771 bool p_blsi = ( hyp && hyp->myTextOption.find("--boundary_layer_surface_tags ") != std::string::npos );
1772 bool p_blii = ( hyp && hyp->myTextOption.find("--boundary_layer_imprint_tags ") != std::string::npos );
1773 bool p_blsd = ( hyp && hyp->myTextOption.find("--normal_direction ") != std::string::npos );
1774 bool p_hotfl = ( hyp && hyp->myTextOption.find("--boundary_layer_global_initial_height ") != std::string::npos );
1775 bool p_nobl = ( hyp && hyp->myTextOption.find("--number_of_boundary_layers ") != std::string::npos );
1776 bool p_blgp = ( hyp && hyp->myTextOption.find("--boundary_layer_geometric_progression ") != std::string::npos );
1777 bool p_eg = ( hyp && hyp->myTextOption.find("--element_generation ") != std::string::npos );
1778 bool p_cm = ( hyp && hyp->myTextOption.find("--collision_mode ") != std::string::npos );
1779 bool p_am = ( hyp && hyp->myTextOption.find("--add_multinormals ") != std::string::npos );
1780 bool p_mat = ( hyp && hyp->myTextOption.find("--multinormal_angle_threshold ") != std::string::npos );
1781 bool p_sn = ( hyp && hyp->myTextOption.find("--smooth_normals ") != std::string::npos );
1784 //- global_physical_size
1785 //- boundary_layer_size_mode
1786 //- boundary_layer_initial_height_on_surface_tags
1787 //- boundary_layer_max_element_angle
1789 bool nolayers = false;
1790 bool layersOnAllWrap = hyp ? hyp->myLayersOnAllWrap : DefaultLayersOnAllWrap();
1798 std::cout << "!!!!! CommandToRun help only !!!! " << cmd.ToCString() << std::endl;
1799 return cmd.ToCString();
1802 if ( !p_v && hyp ) {
1803 cmd += " --verbose ";
1804 cmd += hyp->myVerboseLevel;
1807 if ( !p_mnot && hyp ) {
1808 cmd += " --max_number_of_threads ";
1809 cmd += 8; //TODO getenv NB CPU
1812 //if ( !p_blsi && hyp ) {
1813 // cmd += " --boundary_layers_surface_ids ";
1814 // cmd += 0; //TODO hyp->my;
1817 //if ( !p_blii && hyp ) {
1818 // cmd += " --boundary_layers_imprint_ids ";
1819 // cmd += 0; //TODO hyp->my;
1823 if ( !p_nobl && hyp ) {
1824 if ( hyp->myNbOfBoundaryLayers < 1 ) nolayers = true;
1826 if ( !p_hotfl && hyp ) {
1827 if ( hyp->myHeightFirstLayer < 1e-50 ) nolayers = true;
1830 if ( !p_blsd && hyp ) {
1831 if ( hyp->myBoundaryLayersGrowth >= 0 && hyp->myBoundaryLayersGrowth <= 1 ) {
1832 const char* value[] = { "1" , "-1" };
1833 cmd += " --normal_direction ";
1834 cmd += value[ hyp->myBoundaryLayersGrowth ];
1838 if ( !p_hotfl && hyp ) {
1839 cmd += " --boundary_layer_global_initial_height ";
1840 cmd += hyp->myHeightFirstLayer;
1843 if ( !p_nobl && hyp ) {
1844 cmd += " --number_of_boundary_layers ";
1848 cmd += hyp->myNbOfBoundaryLayers;
1851 if ( !p_blgp && hyp ) {
1852 cmd += " --boundary_layer_geometric_progression ";
1853 cmd += hyp->myBoundaryLayersProgression;
1856 //--boundary_layers_surface_ids 5 #for all wrap shell
1857 //--boundary_layers_surface_ids 6 #for all enfMeshList
1858 //TODO? if ( !nolayers ) cmd += " --boundary_layers_surface_ids 5,6 "; //as all wrap shell and triangles of enforced mesh
1860 if (layersOnAllWrap)
1861 cmd += " --boundary_layer_surface_tags 5 "; //as triangles of all wrap
1863 cmd += " --boundary_layer_surface_tags 6 "; //as triangles of enforced mesh
1866 if ( !p_eg && hyp ) {
1867 if ( hyp->myElementGeneration >= 0 && hyp->myElementGeneration <= 1 ) {
1868 const char* value[] = { "tetra-dominant" , "hexa-dominant" };
1869 cmd += " --element_generation ";
1870 cmd += value[ hyp->myElementGeneration ];
1874 if ( !p_cm && hyp ) {
1875 if ( hyp->myCollisionMode >= 0 && hyp->myCollisionMode <= 1 ) {
1876 const char* value[] = { "decrease" , "stop" };
1877 cmd += " --collision_mode ";
1878 cmd += value[ hyp->myCollisionMode ];
1882 if ( !p_am && hyp ) {
1883 int res = hyp->myAddMultinormals ? 0 : 1 ;
1884 const char* value[] = { "yes" , "no" };
1885 cmd += " --add_multinormals ";
1886 cmd += value[ res ];
1889 if ( !p_mat && hyp ) {
1890 cmd += " --multinormal_angle_threshold ";
1891 cmd += hyp->myMultinormalsAngle;
1894 if ( !p_sn && hyp ) {
1895 int res = hyp->mySmoothNormals ? 0 : 1 ;
1896 const char* value[] = { "yes" , "no" };
1897 cmd += " --smooth_normals ";
1898 cmd += value[ res ];
1904 //std::cout << "!!!!!CommandToRun end " << cmd.ToCString() << std::endl;
1906 return cmd.ToCString();
1909 //================================================================================
1911 * \brief Return a unique file name
1913 //================================================================================
1915 std::string HYBRIDPlugin_Hypothesis::GetFileName(const HYBRIDPlugin_Hypothesis* hyp)
1917 std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
1918 const char lastChar = *aTmpDir.rbegin();
1920 if(lastChar != '\\') aTmpDir+='\\';
1922 if(lastChar != '/') aTmpDir+='/';
1925 TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
1926 aGenericName += "HYBRID_";
1927 aGenericName += getpid();
1928 aGenericName += "_";
1929 aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
1931 return aGenericName.ToCString();
1934 //================================================================================
1936 * Return the name of executable
1938 //================================================================================
1940 std::string HYBRIDPlugin_Hypothesis::GetExeName()
1942 //call mg-hybrid.bash is script which assumes new project version(s) mg-hybrid.exe in the prerequisite base and special? licence.
1943 return "mg-hybrid.bash";
1946 //================================================================================
1948 * \brief Return the enforced vertices
1950 //================================================================================
1952 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexList HYBRIDPlugin_Hypothesis::GetEnforcedVertices(const HYBRIDPlugin_Hypothesis* hyp)
1954 return hyp ? hyp->_GetEnforcedVertices():DefaultHYBRIDEnforcedVertexList();
1957 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesCoordsSize (const HYBRIDPlugin_Hypothesis* hyp)
1959 return hyp ? hyp->_GetEnforcedVerticesCoordsSize(): DefaultHYBRIDEnforcedVertexCoordsValues();
1962 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexEntryValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesEntrySize (const HYBRIDPlugin_Hypothesis* hyp)
1964 return hyp ? hyp->_GetEnforcedVerticesEntrySize(): DefaultHYBRIDEnforcedVertexEntryValues();
1967 HYBRIDPlugin_Hypothesis::TCoordsHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByCoords (const HYBRIDPlugin_Hypothesis* hyp)
1969 return hyp ? hyp->_GetEnforcedVerticesByCoords(): DefaultCoordsHYBRIDEnforcedVertexMap();
1972 HYBRIDPlugin_Hypothesis::TGeomEntryHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByEntry (const HYBRIDPlugin_Hypothesis* hyp)
1974 return hyp ? hyp->_GetEnforcedVerticesByEntry(): DefaultGeomEntryHYBRIDEnforcedVertexMap();
1977 HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedNodes(const HYBRIDPlugin_Hypothesis* hyp)
1979 return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeGroupMap();
1982 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedEdges(const HYBRIDPlugin_Hypothesis* hyp)
1984 return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemGroupMap();
1987 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(const HYBRIDPlugin_Hypothesis* hyp)
1989 return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemGroupMap();
1992 HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp)
1994 return hyp ? hyp->_GetNodeIDToSizeMap(): DefaultID2SizeMap();
1997 HYBRIDPlugin_Hypothesis::TSetStrings HYBRIDPlugin_Hypothesis::GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp)
1999 return hyp ? hyp->_GetGroupsToRemove(): DefaultGroupsToRemove();