1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //=============================================================================
21 // File : HYBRIDPlugin_Hypothesis.cxx
22 // Created : Wed Apr 2 12:36:29 2008
23 // Author : Edward AGAPOV (eap)
24 //=============================================================================
26 #include "HYBRIDPlugin_Hypothesis.hxx"
28 #include <SMESHDS_Mesh.hxx>
30 #include <TCollection_AsciiString.hxx>
34 #define getpid _getpid
37 //=======================================================================
38 //function : HYBRIDPlugin_Hypothesis
39 //=======================================================================
41 HYBRIDPlugin_Hypothesis::HYBRIDPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen)
42 : SMESH_Hypothesis(hypId, studyId, gen),
43 myToMeshHoles(DefaultMeshHoles()),
44 myLayersOnAllWrap(DefaultLayersOnAllWrap()),
45 myToMakeGroupsOfDomains(DefaultToMakeGroupsOfDomains()),
48 myOptimizationLevel(DefaultOptimizationLevel()),
49 myCollisionMode(DefaultCollisionMode()),
50 myBoundaryLayersGrowth(DefaultBoundaryLayersGrowth()),
51 myElementGeneration(DefaultElementGeneration()),
52 myKeepFiles(DefaultKeepFiles()),
53 myWorkingDirectory(DefaultWorkingDirectory()),
54 myVerboseLevel(DefaultVerboseLevel()),
55 myToCreateNewNodes(DefaultToCreateNewNodes()),
56 myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()),
57 myToUseFemCorrection(DefaultToUseFEMCorrection()),
58 myToRemoveCentralPoint(DefaultToRemoveCentralPoint()),
59 myLogInStandardOutput(DefaultStandardOutputLog()),
60 myGradation(DefaultGradation()),
61 myAddMultinormals(DefaultAddMultinormals()),
62 mySmoothNormals(DefaultSmoothNormals()),
63 myHeightFirstLayer(DefaultHeightFirstLayer()),
64 myBoundaryLayersProgression(DefaultBoundaryLayersProgression()),
65 myMultinormalsAngle(DefaultMultinormalsAngle()),
66 myNbOfBoundaryLayers(DefaultNbOfBoundaryLayers()),
67 _enfVertexList(DefaultHYBRIDEnforcedVertexList()),
68 _enfVertexCoordsSizeList(DefaultHYBRIDEnforcedVertexCoordsValues()),
69 _enfVertexEntrySizeList(DefaultHYBRIDEnforcedVertexEntryValues()),
70 _coordsEnfVertexMap(DefaultCoordsHYBRIDEnforcedVertexMap()),
71 _geomEntryEnfVertexMap(DefaultGeomEntryHYBRIDEnforcedVertexMap()),
72 _enfMeshList(DefaultHYBRIDEnforcedMeshList()),
73 _entryEnfMeshMap(DefaultEntryHYBRIDEnforcedMeshListMap()),
74 _enfNodes(TIDSortedNodeGroupMap()),
75 _enfEdges(TIDSortedElemGroupMap()),
76 _enfTriangles(TIDSortedElemGroupMap()),
77 _nodeIDToSizeMap(DefaultID2SizeMap()),
78 _groupsToRemove(DefaultGroupsToRemove())
80 _name = "HYBRID_Parameters";
84 //=======================================================================
85 //function : SetLayersOnAllWrap
86 //=======================================================================
88 void HYBRIDPlugin_Hypothesis::SetLayersOnAllWrap(bool toMesh)
90 if ( myLayersOnAllWrap != toMesh ) {
91 myLayersOnAllWrap = toMesh;
92 NotifySubMeshesHypothesisModification();
96 //=======================================================================
97 //function : GetLayersOnAllWrap
98 //=======================================================================
100 bool HYBRIDPlugin_Hypothesis::GetLayersOnAllWrap(bool checkFreeOption) const
102 return myLayersOnAllWrap;
105 //=======================================================================
106 //function : SetToMeshHoles
107 //=======================================================================
109 void HYBRIDPlugin_Hypothesis::SetToMeshHoles(bool toMesh)
111 if ( myToMeshHoles != toMesh ) {
112 myToMeshHoles = toMesh;
113 NotifySubMeshesHypothesisModification();
117 //=======================================================================
118 //function : GetToMeshHoles
119 //=======================================================================
121 bool HYBRIDPlugin_Hypothesis::GetToMeshHoles(bool checkFreeOption) const
123 if (checkFreeOption && !myTextOption.empty()) {
124 if ( myTextOption.find("-c 0"))
126 if ( myTextOption.find("-c 1"))
129 return myToMeshHoles;
132 //=======================================================================
133 //function : SetToMakeGroupsOfDomains
134 //=======================================================================
136 void HYBRIDPlugin_Hypothesis::SetToMakeGroupsOfDomains(bool toMakeGroups)
138 if ( myToMakeGroupsOfDomains != toMakeGroups ) {
139 myToMakeGroupsOfDomains = toMakeGroups;
140 NotifySubMeshesHypothesisModification();
144 //=======================================================================
145 //function : GetToMakeGroupsOfDomains
146 //=======================================================================
148 bool HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains() const
150 return myToMakeGroupsOfDomains;
153 //=======================================================================
154 //function : GetToMakeGroupsOfDomains
155 //=======================================================================
157 bool HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains(const HYBRIDPlugin_Hypothesis* hyp)
160 if ( hyp ) res = /*hyp->GetToMeshHoles(true) &&*/ hyp->GetToMakeGroupsOfDomains();
161 else res = /*DefaultMeshHoles() &&*/ DefaultToMakeGroupsOfDomains();
165 //=======================================================================
166 //function : SetMaximumMemory
167 //=======================================================================
169 void HYBRIDPlugin_Hypothesis::SetMaximumMemory(double MB)
171 if ( myMaximumMemory != MB ) {
172 myMaximumMemory = MB;
173 NotifySubMeshesHypothesisModification();
177 //=======================================================================
178 //function : GetMaximumMemory
179 // * automatic memory adjustment mode. Default is zero
180 //=======================================================================
182 double HYBRIDPlugin_Hypothesis::GetMaximumMemory() const
184 return myMaximumMemory;
187 //=======================================================================
188 //function : SetInitialMemory
189 //=======================================================================
191 void HYBRIDPlugin_Hypothesis::SetInitialMemory(double MB)
193 if ( myInitialMemory != MB ) {
194 myInitialMemory = MB;
195 NotifySubMeshesHypothesisModification();
199 //=======================================================================
200 //function : GetInitialMemory
201 //=======================================================================
203 double HYBRIDPlugin_Hypothesis::GetInitialMemory() const
205 return myInitialMemory;
208 //=======================================================================
209 //function : SetOptimizationLevel
210 //=======================================================================
212 void HYBRIDPlugin_Hypothesis::SetOptimizationLevel(OptimizationLevel level)
214 if ( myOptimizationLevel != level ) {
215 myOptimizationLevel = level;
216 NotifySubMeshesHypothesisModification();
220 //=======================================================================
221 //function : GetOptimizationLevel
222 //=======================================================================
223 HYBRIDPlugin_Hypothesis::OptimizationLevel HYBRIDPlugin_Hypothesis::GetOptimizationLevel() const
225 return (OptimizationLevel) myOptimizationLevel;
228 //=======================================================================
229 //function : SetCollisionMode
230 //=======================================================================
231 void HYBRIDPlugin_Hypothesis::SetCollisionMode(CollisionMode mode)
233 if ( myCollisionMode != mode ) {
234 myCollisionMode = mode;
235 NotifySubMeshesHypothesisModification();
239 //=======================================================================
240 //function : GetCollisionMode
241 //=======================================================================
242 HYBRIDPlugin_Hypothesis::CollisionMode HYBRIDPlugin_Hypothesis::GetCollisionMode() const
244 return (CollisionMode) myCollisionMode;
247 //=======================================================================
248 //function : SetBoundaryLayersGrowth
249 //=======================================================================
250 void HYBRIDPlugin_Hypothesis::SetBoundaryLayersGrowth(BoundaryLayersGrowth mode)
252 if ( myBoundaryLayersGrowth != mode ) {
253 myBoundaryLayersGrowth = mode;
254 NotifySubMeshesHypothesisModification();
258 //=======================================================================
259 //function : GetBoundaryLayersGrowth
260 //=======================================================================
261 HYBRIDPlugin_Hypothesis::BoundaryLayersGrowth HYBRIDPlugin_Hypothesis::GetBoundaryLayersGrowth() const
263 return (BoundaryLayersGrowth) myBoundaryLayersGrowth;
266 //=======================================================================
267 //function : SetElementGeneration
268 //=======================================================================
269 void HYBRIDPlugin_Hypothesis::SetElementGeneration(ElementGeneration mode)
271 if ( myElementGeneration != mode ) {
272 myElementGeneration = mode;
273 NotifySubMeshesHypothesisModification();
277 //=======================================================================
278 //function : GetElementGeneration
279 //=======================================================================
280 HYBRIDPlugin_Hypothesis::ElementGeneration HYBRIDPlugin_Hypothesis::GetElementGeneration() const
282 return (ElementGeneration) myElementGeneration;
285 //=======================================================================
286 //function : SetAddMultinormals
287 //=======================================================================
288 void HYBRIDPlugin_Hypothesis::SetAddMultinormals(bool toAddMultinormals)
290 if ( myAddMultinormals != toAddMultinormals ) {
291 myAddMultinormals = toAddMultinormals;
292 NotifySubMeshesHypothesisModification();
296 //=======================================================================
297 //function : GetAddMultinormals
298 //=======================================================================
300 bool HYBRIDPlugin_Hypothesis::GetAddMultinormals() const
302 return myAddMultinormals;
305 //=======================================================================
306 //function : SetSmoothNormals
307 //=======================================================================
309 void HYBRIDPlugin_Hypothesis::SetSmoothNormals(bool toSmoothNormals)
311 if ( mySmoothNormals != toSmoothNormals ) {
312 mySmoothNormals = toSmoothNormals;
313 NotifySubMeshesHypothesisModification();
317 //=======================================================================
318 //function : GetSmoothNormals
319 //=======================================================================
321 bool HYBRIDPlugin_Hypothesis::GetSmoothNormals() const
323 return mySmoothNormals;
326 //=======================================================================
327 //function : SetHeightFirstLayer
328 //=======================================================================
330 void HYBRIDPlugin_Hypothesis::SetHeightFirstLayer(double toHeightFirstLayer)
332 if ( myHeightFirstLayer != toHeightFirstLayer ) {
333 myHeightFirstLayer = toHeightFirstLayer;
334 NotifySubMeshesHypothesisModification();
338 //=======================================================================
339 //function : GetHeightFirstLayer
340 //=======================================================================
342 double HYBRIDPlugin_Hypothesis::GetHeightFirstLayer() const
344 return myHeightFirstLayer;
347 //=======================================================================
348 //function : SetBoundaryLayersProgression
349 //=======================================================================
351 void HYBRIDPlugin_Hypothesis::SetBoundaryLayersProgression(double toBoundaryLayersProgression)
353 if ( myBoundaryLayersProgression != toBoundaryLayersProgression ) {
354 myBoundaryLayersProgression = toBoundaryLayersProgression;
355 NotifySubMeshesHypothesisModification();
359 //=======================================================================
360 //function : GetBoundaryLayersProgression
361 //=======================================================================
363 double HYBRIDPlugin_Hypothesis::GetBoundaryLayersProgression() const
365 return myBoundaryLayersProgression;
368 //=======================================================================
369 //function : SetMultinormalsAngle
370 //=======================================================================
372 void HYBRIDPlugin_Hypothesis::SetMultinormalsAngle(double toMultinormalsAngle)
374 if ( myMultinormalsAngle != toMultinormalsAngle ) {
375 myMultinormalsAngle = toMultinormalsAngle;
376 NotifySubMeshesHypothesisModification();
380 //=======================================================================
381 //function : GetMultinormalsAngle
382 //=======================================================================
384 double HYBRIDPlugin_Hypothesis::GetMultinormalsAngle() const
386 return myMultinormalsAngle;
389 //=======================================================================
390 //function : SetNbOfBoundaryLayers
391 //=======================================================================
393 void HYBRIDPlugin_Hypothesis::SetNbOfBoundaryLayers(short toNbOfBoundaryLayers)
395 if ( myNbOfBoundaryLayers != toNbOfBoundaryLayers ) {
396 myNbOfBoundaryLayers = toNbOfBoundaryLayers;
397 NotifySubMeshesHypothesisModification();
401 //=======================================================================
402 //function : GetMultinormalsAngle
403 //=======================================================================
405 short HYBRIDPlugin_Hypothesis::GetNbOfBoundaryLayers() const
407 return myNbOfBoundaryLayers;
411 /////////////////////////////////////////////////////////////////////////
414 //=======================================================================
415 //function : SetWorkingDirectory
416 //=======================================================================
418 void HYBRIDPlugin_Hypothesis::SetWorkingDirectory(const std::string& path)
420 if ( myWorkingDirectory != path ) {
421 myWorkingDirectory = path;
422 NotifySubMeshesHypothesisModification();
426 //=======================================================================
427 //function : GetWorkingDirectory
428 //=======================================================================
430 std::string HYBRIDPlugin_Hypothesis::GetWorkingDirectory() const
432 return myWorkingDirectory;
435 //=======================================================================
436 //function : SetKeepFiles
437 //=======================================================================
439 void HYBRIDPlugin_Hypothesis::SetKeepFiles(bool toKeep)
441 if ( myKeepFiles != toKeep ) {
442 myKeepFiles = toKeep;
443 NotifySubMeshesHypothesisModification();
447 //=======================================================================
448 //function : GetKeepFiles
449 //=======================================================================
451 bool HYBRIDPlugin_Hypothesis::GetKeepFiles() const
456 //=======================================================================
457 //function : SetVerboseLevel
458 //=======================================================================
460 void HYBRIDPlugin_Hypothesis::SetVerboseLevel(short level)
462 if ( myVerboseLevel != level ) {
463 myVerboseLevel = level;
464 NotifySubMeshesHypothesisModification();
468 //=======================================================================
469 //function : GetVerboseLevel
470 //=======================================================================
472 short HYBRIDPlugin_Hypothesis::GetVerboseLevel() const
474 return myVerboseLevel;
477 //=======================================================================
478 //function : SetToCreateNewNodes
479 //=======================================================================
481 void HYBRIDPlugin_Hypothesis::SetToCreateNewNodes(bool toCreate)
483 if ( myToCreateNewNodes != toCreate ) {
484 myToCreateNewNodes = toCreate;
485 NotifySubMeshesHypothesisModification();
489 //=======================================================================
490 //function : GetToCreateNewNodes
491 //=======================================================================
493 bool HYBRIDPlugin_Hypothesis::GetToCreateNewNodes() const
495 return myToCreateNewNodes;
498 //=======================================================================
499 //function : SetToUseBoundaryRecoveryVersion
500 //=======================================================================
502 void HYBRIDPlugin_Hypothesis::SetToUseBoundaryRecoveryVersion(bool toUse)
504 if ( myToUseBoundaryRecoveryVersion != toUse ) {
505 myToUseBoundaryRecoveryVersion = toUse;
506 NotifySubMeshesHypothesisModification();
510 //=======================================================================
511 //function : GetToUseBoundaryRecoveryVersion
512 //=======================================================================
514 bool HYBRIDPlugin_Hypothesis::GetToUseBoundaryRecoveryVersion() const
516 return myToUseBoundaryRecoveryVersion;
519 //=======================================================================
520 //function : SetFEMCorrection
521 //=======================================================================
523 void HYBRIDPlugin_Hypothesis::SetFEMCorrection(bool toUseFem)
525 if ( myToUseFemCorrection != toUseFem ) {
526 myToUseFemCorrection = toUseFem;
527 NotifySubMeshesHypothesisModification();
531 //=======================================================================
532 //function : GetFEMCorrection
533 //=======================================================================
535 bool HYBRIDPlugin_Hypothesis::GetFEMCorrection() const
537 return myToUseFemCorrection;
540 //=======================================================================
541 //function : SetToRemoveCentralPoint
542 //=======================================================================
544 void HYBRIDPlugin_Hypothesis::SetToRemoveCentralPoint(bool toRemove)
546 if ( myToRemoveCentralPoint != toRemove ) {
547 myToRemoveCentralPoint = toRemove;
548 NotifySubMeshesHypothesisModification();
552 //=======================================================================
553 //function : GetToRemoveCentralPoint
554 //=======================================================================
556 bool HYBRIDPlugin_Hypothesis::GetToRemoveCentralPoint() const
558 return myToRemoveCentralPoint;
561 //=======================================================================
562 //function : SetAdvancedOption
563 //=======================================================================
565 void HYBRIDPlugin_Hypothesis::SetAdvancedOption(const std::string& option)
567 if ( myTextOption != option ) {
568 myTextOption = option;
569 NotifySubMeshesHypothesisModification();
573 //=======================================================================
574 //function : GetAdvancedOption
575 //=======================================================================
577 std::string HYBRIDPlugin_Hypothesis::GetAdvancedOption() const
582 //=======================================================================
583 //function : SetGradation
584 //=======================================================================
586 void HYBRIDPlugin_Hypothesis::SetGradation(double gradation)
588 if ( myGradation != gradation ) {
589 myGradation = gradation;
590 NotifySubMeshesHypothesisModification();
594 //=======================================================================
595 //function : GetGradation
596 //=======================================================================
598 double HYBRIDPlugin_Hypothesis::GetGradation() const
603 //=======================================================================
604 //function : SetStandardOutputLog
605 //=======================================================================
607 void HYBRIDPlugin_Hypothesis::SetStandardOutputLog(bool logInStandardOutput)
609 if ( myLogInStandardOutput != logInStandardOutput ) {
610 myLogInStandardOutput = logInStandardOutput;
611 NotifySubMeshesHypothesisModification();
615 //=======================================================================
616 //function : GetStandardOutputLog
617 //=======================================================================
619 bool HYBRIDPlugin_Hypothesis::GetStandardOutputLog() const
621 return myLogInStandardOutput;
624 //=======================================================================
625 //function : SetRemoveLogOnSuccess
626 //=======================================================================
628 void HYBRIDPlugin_Hypothesis::SetRemoveLogOnSuccess(bool removeLogOnSuccess)
630 if ( myRemoveLogOnSuccess != removeLogOnSuccess ) {
631 myRemoveLogOnSuccess = removeLogOnSuccess;
632 NotifySubMeshesHypothesisModification();
636 //=======================================================================
637 //function : GetRemoveLogOnSuccess
638 //=======================================================================
640 bool HYBRIDPlugin_Hypothesis::GetRemoveLogOnSuccess() const
642 return myRemoveLogOnSuccess;
645 //=======================================================================
646 //function : SetEnforcedVertex
647 //=======================================================================
649 bool HYBRIDPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string theEntry, std::string theGroupName,
650 double size, double x, double y, double z, bool isCompound)
652 MESSAGE("HYBRIDPlugin_Hypothesis::SetEnforcedVertex(\""<< theName << "\", \""<< theEntry << "\", \"" << theGroupName << "\", "
653 << size << ", " << x << ", " << y << ", " << z << ", "<< isCompound << ")");
655 bool toNotify = false;
656 bool toCreate = true;
658 THYBRIDEnforcedVertex *oldEnVertex;
659 THYBRIDEnforcedVertex *newEnfVertex = new THYBRIDEnforcedVertex();
660 newEnfVertex->name = theName;
661 newEnfVertex->geomEntry = theEntry;
662 newEnfVertex->coords.clear();
664 newEnfVertex->coords.push_back(x);
665 newEnfVertex->coords.push_back(y);
666 newEnfVertex->coords.push_back(z);
668 newEnfVertex->groupName = theGroupName;
669 newEnfVertex->size = size;
670 newEnfVertex->isCompound = isCompound;
673 // update _enfVertexList
674 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(newEnfVertex);
675 if (it != _enfVertexList.end()) {
678 MESSAGE("Enforced Vertex was found => Update");
679 if (oldEnVertex->name != theName) {
680 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theName << "\"");
681 oldEnVertex->name = theName;
684 if (oldEnVertex->groupName != theGroupName) {
685 MESSAGE("Update group name from \"" << oldEnVertex->groupName << "\" to \"" << theGroupName << "\"");
686 oldEnVertex->groupName = theGroupName;
689 if (oldEnVertex->size != size) {
690 MESSAGE("Update size from \"" << oldEnVertex->size << "\" to \"" << size << "\"");
691 oldEnVertex->size = size;
695 // update map coords / enf vertex if needed
696 if (oldEnVertex->coords.size()) {
697 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
698 _enfVertexCoordsSizeList[oldEnVertex->coords] = size;
701 // update map geom entry / enf vertex if needed
702 if (oldEnVertex->geomEntry != "") {
703 _geomEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
704 _enfVertexEntrySizeList[oldEnVertex->geomEntry] = size;
709 // //////// CREATE ////////////
712 MESSAGE("Creating new enforced vertex");
713 _enfVertexList.insert(newEnfVertex);
714 if (theEntry == "") {
715 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
716 _enfVertexCoordsSizeList[newEnfVertex->coords] = size;
719 _geomEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
720 _enfVertexEntrySizeList[newEnfVertex->geomEntry] = size;
725 NotifySubMeshesHypothesisModification();
727 MESSAGE("HYBRIDPlugin_Hypothesis::SetEnforcedVertex END");
732 //=======================================================================
733 //function : SetEnforcedMesh
734 //=======================================================================
735 bool HYBRIDPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName)
737 TIDSortedElemSet theElemSet;
738 SMDS_ElemIteratorPtr eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType));
739 while ( eIt->more() )
740 theElemSet.insert( eIt->next() );
741 MESSAGE("Add "<<theElemSet.size()<<" types["<<elementType<<"] from source mesh");
742 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
744 THYBRIDEnforcedMesh* newEnfMesh = new THYBRIDEnforcedMesh();
745 newEnfMesh->persistID = theMesh.GetMeshDS()->GetPersistentId();
746 newEnfMesh->name = name;
747 newEnfMesh->entry = entry;
748 newEnfMesh->elementType = elementType;
749 newEnfMesh->groupName = groupName;
751 THYBRIDEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
752 if (it == _enfMeshList.end()) {
753 _entryEnfMeshMap[entry].insert(newEnfMesh);
754 _enfMeshList.insert(newEnfMesh);
763 //=======================================================================
764 //function : SetEnforcedGroup
765 //=======================================================================
766 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)
768 MESSAGE("HYBRIDPlugin_Hypothesis::SetEnforcedGroup");
769 TIDSortedElemSet theElemSet;
770 if ( theIDs->length() == 0 ){MESSAGE("The source group is empty");}
771 for ( CORBA::ULong i = 0; i < theIDs->length(); i++) {
772 CORBA::Long ind = theIDs[i];
773 if (elementType == SMESH::NODE)
775 const SMDS_MeshNode * node = theMeshDS->FindNode(ind);
777 theElemSet.insert( node );
781 const SMDS_MeshElement * elem = theMeshDS->FindElement(ind);
783 theElemSet.insert( elem );
787 // SMDS_ElemIteratorPtr it = theGroup->GetGroupDS()->GetElements();
788 // while ( it->more() )
789 // theElemSet.insert( it->next() );
791 MESSAGE("Add "<<theElemSet.size()<<" types["<<elementType<<"] from source group ");
792 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
794 THYBRIDEnforcedMesh* newEnfMesh = new THYBRIDEnforcedMesh();
795 newEnfMesh->name = name;
796 newEnfMesh->entry = entry;
797 newEnfMesh->elementType = elementType;
798 newEnfMesh->groupName = groupName;
800 THYBRIDEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
801 if (it == _enfMeshList.end()) {
802 _entryEnfMeshMap[entry].insert(newEnfMesh);
803 _enfMeshList.insert(newEnfMesh);
809 //=======================================================================
810 //function : SetEnforcedElements
811 //=======================================================================
812 bool HYBRIDPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName)
814 MESSAGE("HYBRIDPlugin_Hypothesis::SetEnforcedElements");
815 TIDSortedElemSet::const_iterator it = theElemSet.begin();
816 const SMDS_MeshElement* elem;
817 const SMDS_MeshNode* node;
819 std::pair<TIDSortedNodeGroupMap::iterator,bool> nodeRet;
820 std::pair<TIDSortedElemGroupMap::iterator,bool> elemRet;
822 for (;it != theElemSet.end();++it)
825 switch (elementType) {
827 node = dynamic_cast<const SMDS_MeshNode*>(elem);
829 nodeRet = _enfNodes.insert(make_pair(node,groupName));
830 added = added && nodeRet.second;
831 std::string msg = added ? "yes":"no";
832 MESSAGE( "Node (" <<node->X()<<","<<node->Y()<<","<<node->Z()<< ") with ID " << node->GetID() <<" added ? " << msg);
835 SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
836 for (;nodeIt->more();) {
837 node = dynamic_cast<const SMDS_MeshNode*>(nodeIt->next());
838 nodeRet = _enfNodes.insert(make_pair(node,groupName));
839 added = added && nodeRet.second;
845 if (elem->GetType() == SMDSAbs_Edge) {
846 elemRet = _enfEdges.insert(make_pair(elem,groupName));
847 added = added && elemRet.second;
849 else if (elem->GetType() > SMDSAbs_Edge) {
850 SMDS_ElemIteratorPtr it = elem->edgesIterator();
852 const SMDS_MeshElement* anEdge = it->next();
853 elemRet = _enfEdges.insert(make_pair(anEdge,groupName));
854 added = added && elemRet.second;
859 if (elem->GetType() == SMDSAbs_Face)
861 if (elem->NbCornerNodes() == 3) {
862 elemRet = _enfTriangles.insert(make_pair(elem,groupName));
863 added = added && elemRet.second;
866 else if (elem->GetType() > SMDSAbs_Face) { // Group of faces
867 SMDS_ElemIteratorPtr it = elem->facesIterator();
869 const SMDS_MeshElement* aFace = it->next();
870 if (aFace->NbCornerNodes() == 3) {
871 elemRet = _enfTriangles.insert(make_pair(aFace,groupName));
872 added = added && elemRet.second;
882 NotifySubMeshesHypothesisModification();
887 //=======================================================================
888 //function : GetEnforcedVertex
889 //=======================================================================
891 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z)
892 throw (std::invalid_argument)
894 std::vector<double> coord(3);
898 if (_coordsEnfVertexMap.count(coord)>0)
899 return _coordsEnfVertexMap[coord];
900 std::ostringstream msg ;
901 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
902 throw std::invalid_argument(msg.str());
905 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(const std::string theEntry)
906 throw (std::invalid_argument)
908 if (_geomEntryEnfVertexMap.count(theEntry)>0)
909 return _geomEntryEnfVertexMap[theEntry];
911 std::ostringstream msg ;
912 msg << "No enforced vertex with entry " << theEntry;
913 throw std::invalid_argument(msg.str());
916 //=======================================================================
917 //function : RemoveEnforcedVertex
918 //=======================================================================
920 bool HYBRIDPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, const std::string theEntry)
921 throw (std::invalid_argument)
923 bool toNotify = false;
924 std::ostringstream msg;
925 THYBRIDEnforcedVertex *oldEnfVertex;
926 std::vector<double> coords(3);
931 // check that enf vertex with given enf vertex entry exists
932 TGeomEntryHYBRIDEnforcedVertexMap::iterator it_enfVertexEntry = _geomEntryEnfVertexMap.find(theEntry);
933 if (it_enfVertexEntry != _geomEntryEnfVertexMap.end()) {
935 MESSAGE("Found enforced vertex with geom entry " << theEntry);
936 oldEnfVertex = it_enfVertexEntry->second;
937 _geomEntryEnfVertexMap.erase(it_enfVertexEntry);
940 MESSAGE("Enforced vertex with geom entry " << theEntry << " not found");
941 // check that enf vertex with given coords exists
942 TCoordsHYBRIDEnforcedVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
943 if (it_coords_enf != _coordsEnfVertexMap.end()) {
945 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
946 oldEnfVertex = it_coords_enf->second;
947 _coordsEnfVertexMap.erase(it_coords_enf);
948 _enfVertexCoordsSizeList.erase(_enfVertexCoordsSizeList.find(coords));
951 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
952 throw std::invalid_argument(msg.str());
956 MESSAGE("Remove enf vertex from _enfVertexList");
958 // update _enfVertexList
959 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
960 if (it != _enfVertexList.end()) {
961 if ((*it)->groupName != "")
962 _groupsToRemove.insert((*it)->groupName);
963 _enfVertexList.erase(it);
969 NotifySubMeshesHypothesisModification();
974 //=======================================================================
975 //function : ClearEnforcedVertices
976 //=======================================================================
977 void HYBRIDPlugin_Hypothesis::ClearEnforcedVertices()
979 THYBRIDEnforcedVertexList::const_iterator it = _enfVertexList.begin();
980 for(;it != _enfVertexList.end();++it) {
981 if ((*it)->groupName != "")
982 _groupsToRemove.insert((*it)->groupName);
984 _enfVertexList.clear();
985 _coordsEnfVertexMap.clear();
986 _geomEntryEnfVertexMap.clear();
987 _enfVertexCoordsSizeList.clear();
988 _enfVertexEntrySizeList.clear();
989 NotifySubMeshesHypothesisModification();
992 //=======================================================================
993 //function : ClearEnforcedMeshes
994 //=======================================================================
995 void HYBRIDPlugin_Hypothesis::ClearEnforcedMeshes()
997 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
998 for(;it != _enfMeshList.end();++it) {
999 if ((*it)->groupName != "")
1000 _groupsToRemove.insert((*it)->groupName);
1004 _enfTriangles.clear();
1005 _nodeIDToSizeMap.clear();
1006 _enfMeshList.clear();
1007 _entryEnfMeshMap.clear();
1008 NotifySubMeshesHypothesisModification();
1011 //================================================================================
1013 * \brief At mesh loading, restore enforced elements by just loaded enforced meshes
1015 //================================================================================
1017 void HYBRIDPlugin_Hypothesis::RestoreEnfElemsByMeshes()
1019 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
1020 for(;it != _enfMeshList.end();++it) {
1021 THYBRIDEnforcedMesh* enfMesh = *it;
1022 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
1023 SetEnforcedMesh( *mesh,
1024 enfMesh->elementType,
1027 enfMesh->groupName );
1028 enfMesh->persistID = -1; // not to restore again
1032 //=======================================================================
1033 //function : SetGroupsToRemove
1034 //=======================================================================
1036 void HYBRIDPlugin_Hypothesis::ClearGroupsToRemove()
1038 _groupsToRemove.clear();
1042 //=======================================================================
1043 //function : DefaultLayersOnAllWrap
1044 //=======================================================================
1046 bool HYBRIDPlugin_Hypothesis::DefaultLayersOnAllWrap()
1051 //=======================================================================
1052 //function : DefaultMeshHoles
1053 //=======================================================================
1055 bool HYBRIDPlugin_Hypothesis::DefaultMeshHoles()
1057 return false; // PAL19680
1060 //=======================================================================
1061 //function : DefaultToMakeGroupsOfDomains
1062 //=======================================================================
1064 bool HYBRIDPlugin_Hypothesis::DefaultToMakeGroupsOfDomains()
1066 return false; // issue 0022172
1069 //=======================================================================
1070 //function : DefaultMaximumMemory
1071 //=======================================================================
1074 #include <sys/sysinfo.h>
1076 #include <windows.h>
1079 double HYBRIDPlugin_Hypothesis::DefaultMaximumMemory()
1083 int err = sysinfo( &si );
1085 int ramMB = si.totalram * si.mem_unit / 1024 / 1024;
1086 return ( 0.7 * ramMB );
1089 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
1090 MEMORYSTATUSEX statex;
1091 statex.dwLength = sizeof (statex);
1092 int err = GlobalMemoryStatusEx (&statex);
1095 statex.ullTotalPhys / 1024 / 1024 +
1096 statex.ullTotalPageFile / 1024 / 1024 +
1097 statex.ullTotalVirtual / 1024 / 1024;
1098 return ( 0.7 * totMB );
1104 //=======================================================================
1105 //function : DefaultInitialMemory
1106 //=======================================================================
1108 double HYBRIDPlugin_Hypothesis::DefaultInitialMemory()
1110 return DefaultMaximumMemory();
1113 //=======================================================================
1114 //function : DefaultCollisionMode
1115 //=======================================================================
1116 short HYBRIDPlugin_Hypothesis::DefaultCollisionMode()
1121 //=======================================================================
1122 //function : DefaultBoundaryLayersGrowth
1123 //=======================================================================
1124 short HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersGrowth()
1126 return Layer_Growth_Inward;
1129 //=======================================================================
1130 //function : DefaultElementGeneration
1131 //=======================================================================
1132 short HYBRIDPlugin_Hypothesis::DefaultElementGeneration()
1134 return Generation_Tetra_Dominant;
1137 //=======================================================================
1138 //function : DefaultOptimizationLevel
1139 //=======================================================================
1140 short HYBRIDPlugin_Hypothesis::DefaultOptimizationLevel()
1145 //=======================================================================
1146 //function : DefaultWorkingDirectory
1147 //=======================================================================
1149 std::string HYBRIDPlugin_Hypothesis::DefaultWorkingDirectory()
1151 TCollection_AsciiString aTmpDir;
1153 char *Tmp_dir = getenv("SALOME_TMP_DIR");
1154 if(Tmp_dir != NULL) {
1159 aTmpDir = TCollection_AsciiString("C:\\");
1161 aTmpDir = TCollection_AsciiString("/tmp/");
1164 return aTmpDir.ToCString();
1167 //=======================================================================
1168 //function : DefaultKeepFiles
1169 //=======================================================================
1171 bool HYBRIDPlugin_Hypothesis::DefaultKeepFiles()
1176 //=======================================================================
1177 //function : DefaultRemoveLogOnSuccess
1178 //=======================================================================
1180 bool HYBRIDPlugin_Hypothesis::DefaultRemoveLogOnSuccess()
1186 //=======================================================================
1187 //function : DefaultVerboseLevel
1188 //=======================================================================
1190 short HYBRIDPlugin_Hypothesis::DefaultVerboseLevel()
1195 //=======================================================================
1196 //function : DefaultToCreateNewNodes
1197 //=======================================================================
1199 bool HYBRIDPlugin_Hypothesis::DefaultToCreateNewNodes()
1204 //=======================================================================
1205 //function : DefaultToUseBoundaryRecoveryVersion
1206 //=======================================================================
1208 bool HYBRIDPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
1213 //=======================================================================
1214 //function : DefaultToUseFEMCorrection
1215 //=======================================================================
1217 bool HYBRIDPlugin_Hypothesis::DefaultToUseFEMCorrection()
1222 //=======================================================================
1223 //function : DefaultToRemoveCentralPoint
1224 //=======================================================================
1226 bool HYBRIDPlugin_Hypothesis::DefaultToRemoveCentralPoint()
1231 //=======================================================================
1232 //function : DefaultGradation
1233 //=======================================================================
1235 double HYBRIDPlugin_Hypothesis::DefaultGradation()
1240 //=======================================================================
1241 //function : DefaultStandardOutputLog
1242 //=======================================================================
1244 bool HYBRIDPlugin_Hypothesis::DefaultStandardOutputLog()
1249 // //=======================================================================
1250 // //function : DefaultID2SizeMap
1251 // //=======================================================================
1253 // HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::DefaultID2SizeMap()
1255 // return HYBRIDPlugin_Hypothesis::TID2SizeMap();
1258 //=======================================================================
1259 //function : DefaultAddMultinormals
1260 //=======================================================================
1261 bool HYBRIDPlugin_Hypothesis::DefaultAddMultinormals()
1266 //=======================================================================
1267 //function : DefaultSmoothNormals
1268 //=======================================================================
1269 bool HYBRIDPlugin_Hypothesis::DefaultSmoothNormals()
1274 //=======================================================================
1275 //function : DefaultHeightFirstLayer
1276 //=======================================================================
1277 double HYBRIDPlugin_Hypothesis::DefaultHeightFirstLayer()
1279 return 0.0; //or epsilon?
1282 //=======================================================================
1283 //function : DefaultBoundaryLayersProgression
1284 //=======================================================================
1285 double HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersProgression()
1290 //=======================================================================
1291 //function : DefaultMultinormalsAngle
1292 //=======================================================================
1293 double HYBRIDPlugin_Hypothesis::DefaultMultinormalsAngle()
1298 //=======================================================================
1299 //function : DefaultNbOfBoundaryLayers
1300 //=======================================================================
1301 short HYBRIDPlugin_Hypothesis::DefaultNbOfBoundaryLayers()
1306 //=======================================================================
1308 //=======================================================================
1310 std::ostream & HYBRIDPlugin_Hypothesis::SaveTo(std::ostream & save)
1312 save << (int) myBoundaryLayersGrowth << " ";
1313 save << (int) myElementGeneration << " ";
1314 save << (int) myAddMultinormals << " ";
1315 save << (int) mySmoothNormals << " ";
1316 save << (int) myLayersOnAllWrap << " ";
1318 save << myNbOfBoundaryLayers << " ";
1319 save << myHeightFirstLayer << " ";
1320 save << myBoundaryLayersProgression << " ";
1321 save << myMultinormalsAngle << " ";
1323 save << (int) myKeepFiles << " ";
1324 save << myWorkingDirectory << " ";
1325 save << myVerboseLevel << " ";
1326 if (!myTextOption.empty()) {
1327 save << "__OPTIONS_BEGIN__ ";
1328 save << myTextOption << " ";
1329 save << "__OPTIONS_END__ ";
1333 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.begin();
1334 if (it != _enfVertexList.end()) {
1335 save << " " << "__ENFORCED_VERTICES_BEGIN__ ";
1336 for ( ; it != _enfVertexList.end(); ++it ) {
1337 THYBRIDEnforcedVertex *enfVertex = (*it);
1338 save << " " << "__BEGIN_VERTEX__";
1339 if (!enfVertex->name.empty()) {
1340 save << " " << "__BEGIN_NAME__";
1341 save << " " << enfVertex->name;
1342 save << " " << "__END_NAME__";
1344 if (!enfVertex->geomEntry.empty()) {
1345 save << " " << "__BEGIN_ENTRY__";
1346 save << " " << enfVertex->geomEntry;
1347 save << " " << enfVertex->isCompound;
1348 save << " " << "__END_ENTRY__";
1350 if (!enfVertex->groupName.empty()) {
1351 save << " " << "__BEGIN_GROUP__";
1352 save << " " << enfVertex->groupName;
1353 save << " " << "__END_GROUP__";
1355 if (enfVertex->coords.size()) {
1356 save << " " << "__BEGIN_COORDS__";
1357 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1358 save << " " << enfVertex->coords[i];
1359 save << " " << "__END_COORDS__";
1361 save << " " << "__BEGIN_SIZE__";
1362 save << " " << enfVertex->size;
1363 save << " " << "__END_SIZE__";
1364 save << " " << "__END_VERTEX__";
1366 save << " " << "__ENFORCED_VERTICES_END__ ";
1369 THYBRIDEnforcedMeshList::iterator it_mesh = _enfMeshList.begin();
1370 if (it_mesh != _enfMeshList.end()) {
1371 save << " " << "__ENFORCED_MESHES_BEGIN__ ";
1372 for ( ; it_mesh != _enfMeshList.end(); ++it_mesh ) {
1373 THYBRIDEnforcedMesh *enfMesh = (*it_mesh);
1374 save << " " << "__BEGIN_ENF_MESH__";
1376 save << " " << "__BEGIN_NAME__";
1377 save << " " << enfMesh->name;
1378 save << " " << "__END_NAME__";
1380 save << " " << "__BEGIN_ENTRY__";
1381 save << " " << enfMesh->entry;
1382 save << " " << "__END_ENTRY__";
1384 save << " " << "__BEGIN_ELEM_TYPE__";
1385 save << " " << (int)enfMesh->elementType;
1386 save << " " << "__END_ELEM_TYPE__";
1388 if (!enfMesh->groupName.empty()) {
1389 save << " " << "__BEGIN_GROUP__";
1390 save << " " << enfMesh->groupName;
1391 save << " " << "__END_GROUP__";
1393 save << " " << "__PERSIST_ID__";
1394 save << " " << enfMesh->persistID;
1395 save << " " << "__END_ENF_MESH__";
1396 std::cout << "Saving of enforced mesh " << enfMesh->name.c_str() << " done" << std::endl;
1398 save << " " << "__ENFORCED_MESHES_END__ ";
1403 //=======================================================================
1404 //function : LoadFrom
1405 //=======================================================================
1407 std::istream & HYBRIDPlugin_Hypothesis::LoadFrom(std::istream & load)
1413 isOK = static_cast<bool>(load >> i);
1415 myBoundaryLayersGrowth = (short) i;
1417 load.clear(ios::badbit | load.rdstate());
1419 isOK = static_cast<bool>(load >> i);
1421 myElementGeneration = (short) i;
1423 load.clear(ios::badbit | load.rdstate());
1425 isOK = static_cast<bool>(load >> i);
1427 myAddMultinormals = (bool) i;
1429 load.clear(ios::badbit | load.rdstate());
1431 isOK = static_cast<bool>(load >> i);
1433 mySmoothNormals = (bool) i;
1435 load.clear(ios::badbit | load.rdstate());
1437 isOK = static_cast<bool>(load >> i);
1439 myLayersOnAllWrap = (bool) i;
1441 load.clear(ios::badbit | load.rdstate());
1443 isOK = static_cast<bool>(load >> i);
1445 myNbOfBoundaryLayers = (short) i;
1447 load.clear(ios::badbit | load.rdstate());
1449 isOK = static_cast<bool>(load >> d);
1451 myHeightFirstLayer = d;
1453 load.clear(ios::badbit | load.rdstate());
1455 isOK = static_cast<bool>(load >> d);
1457 myBoundaryLayersProgression = d;
1459 load.clear(ios::badbit | load.rdstate());
1461 isOK = static_cast<bool>(load >> d);
1463 myMultinormalsAngle = d;
1465 load.clear(ios::badbit | load.rdstate());
1467 isOK = static_cast<bool>(load >> i);
1469 myKeepFiles = (bool) i;
1471 load.clear(ios::badbit | load.rdstate());
1473 isOK = static_cast<bool>(load >> myWorkingDirectory);
1475 if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
1476 myKeepFiles = false;
1477 myWorkingDirectory.clear();
1479 else if ( myWorkingDirectory == "1" ) {
1481 myWorkingDirectory.clear();
1485 load.clear(ios::badbit | load.rdstate());
1487 isOK = static_cast<bool>(load >> i);
1489 myVerboseLevel = (short) i;
1491 load.clear(ios::badbit | load.rdstate());
1494 std::string separator;
1495 bool hasOptions = false;
1496 bool hasEnforcedVertices = false;
1497 bool hasEnforcedMeshes = false;
1498 isOK = static_cast<bool>(load >> separator);
1500 if ( isOK && ( separator == "0" || separator == "1" ))
1502 myToMakeGroupsOfDomains = ( separator == "1" );
1503 isOK = static_cast<bool>(load >> separator);
1507 if (separator == "__OPTIONS_BEGIN__")
1509 else if (separator == "__ENFORCED_VERTICES_BEGIN__")
1510 hasEnforcedVertices = true;
1511 else if (separator == "__ENFORCED_MESHES_BEGIN__")
1512 hasEnforcedMeshes = true;
1518 isOK = static_cast<bool>(load >> txt);
1520 if (txt == "__OPTIONS_END__") {
1521 if (!myTextOption.empty()) {
1522 // Remove last space
1523 myTextOption.erase(myTextOption.end()-1);
1528 myTextOption += txt;
1529 myTextOption += " ";
1535 isOK = static_cast<bool>(load >> separator);
1536 if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__")
1537 hasEnforcedVertices = true;
1538 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1539 hasEnforcedMeshes = true;
1542 if (hasEnforcedVertices) {
1543 std::string txt, name, entry, groupName;
1544 double size, coords[3];
1546 bool hasCoords = false;
1547 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1549 if (txt == "__ENFORCED_VERTICES_END__")
1552 THYBRIDEnforcedVertex *enfVertex = new THYBRIDEnforcedVertex();
1554 isOK = static_cast<bool>(load >> txt);
1555 if (txt == "__END_VERTEX__") {
1556 enfVertex->name = name;
1557 enfVertex->geomEntry = entry;
1558 enfVertex->isCompound = isCompound;
1559 enfVertex->groupName = groupName;
1560 enfVertex->coords.clear();
1562 enfVertex->coords.assign(coords,coords+3);
1564 _enfVertexList.insert(enfVertex);
1566 if (enfVertex->coords.size())
1567 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1568 if (!enfVertex->geomEntry.empty())
1569 _geomEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1578 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1579 while (isOK && (txt != "__END_NAME__")) {
1580 isOK = static_cast<bool>(load >> txt);
1581 if (txt != "__END_NAME__") {
1587 MESSAGE("name: " <<name);
1590 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1591 isOK = static_cast<bool>(load >> entry);
1592 isOK = static_cast<bool>(load >> isCompound);
1593 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1594 if (txt != "__END_ENTRY__")
1595 throw std::exception();
1596 MESSAGE("entry: " << entry);
1599 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1600 while (isOK && (txt != "__END_GROUP__")) {
1601 isOK = static_cast<bool>(load >> txt);
1602 if (txt != "__END_GROUP__") {
1603 if (!groupName.empty())
1608 MESSAGE("groupName: " << groupName);
1611 if (txt == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1613 isOK = static_cast<bool>(load >> coords[0] >> coords[1] >> coords[2]);
1614 isOK = static_cast<bool>(load >> txt); // __END_COORDS__
1615 if (txt != "__END_COORDS__")
1616 throw std::exception();
1617 MESSAGE("coords: " << coords[0] <<","<< coords[1] <<","<< coords[2]);
1620 if (txt == "__BEGIN_SIZE__") { // __BEGIN_ENTRY__
1621 isOK = static_cast<bool>(load >> size);
1622 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1623 if (txt != "__END_SIZE__") {
1624 throw std::exception();
1626 MESSAGE("size: " << size);
1629 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1633 if (hasEnforcedVertices) {
1634 isOK = static_cast<bool>(load >> separator);
1635 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1636 hasEnforcedMeshes = true;
1639 if (hasEnforcedMeshes) {
1640 std::string txt, name, entry, groupName;
1641 int elementType = -1, persistID = -1;
1642 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1645 if (txt == "__ENFORCED_MESHES_END__")
1648 THYBRIDEnforcedMesh *enfMesh = new THYBRIDEnforcedMesh();
1650 isOK = static_cast<bool>(load >> txt);
1651 if (txt == "__END_ENF_MESH__") {
1652 enfMesh->name = name;
1653 enfMesh->entry = entry;
1654 enfMesh->elementType = (SMESH::ElementType)elementType;
1655 enfMesh->groupName = groupName;
1656 enfMesh->persistID = persistID;
1658 _enfMeshList.insert(enfMesh);
1659 std::cout << "Restoring of enforced mesh " <<name << " done" << std::endl;
1669 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1670 while (isOK && (txt != "__END_NAME__")) {
1671 isOK = static_cast<bool>(load >> txt);
1672 if (txt != "__END_NAME__") {
1678 MESSAGE("name: " <<name);
1681 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1682 isOK = static_cast<bool>(load >> entry);
1683 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1684 if (txt != "__END_ENTRY__")
1685 throw std::exception();
1686 MESSAGE("entry: " << entry);
1689 if (txt == "__BEGIN_ELEM_TYPE__") { // __BEGIN_ELEM_TYPE__
1690 isOK = static_cast<bool>(load >> elementType);
1691 isOK = static_cast<bool>(load >> txt); // __END_ELEM_TYPE__
1692 if (txt != "__END_ELEM_TYPE__")
1693 throw std::exception();
1694 MESSAGE("elementType: " << elementType);
1697 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1698 while (isOK && (txt != "__END_GROUP__")) {
1699 isOK = static_cast<bool>(load >> txt);
1700 if (txt != "__END_GROUP__") {
1701 if (!groupName.empty())
1706 MESSAGE("groupName: " << groupName);
1709 if (txt == "__PERSIST_ID__") {
1710 isOK = static_cast<bool>(load >> persistID);
1711 MESSAGE("persistID: " << persistID);
1713 std::cout << "isOK: " << isOK << std::endl;
1716 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1723 //=======================================================================
1724 //function : SetParametersByMesh
1725 //=======================================================================
1727 bool HYBRIDPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
1733 //================================================================================
1735 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
1737 //================================================================================
1739 bool HYBRIDPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
1740 const SMESH_Mesh* /*theMesh*/)
1742 myToMakeGroupsOfDomains = ( !dflts._shape || dflts._shape->IsNull() );
1746 //================================================================================
1748 * \brief Return command to run hybrid mesher excluding file prefix (-f)
1750 //================================================================================
1752 std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis* hyp,
1753 const bool hasShapeToMesh)
1755 TCollection_AsciiString cmd = GetExeName().c_str();
1756 // check if any option is overridden by hyp->myTextOption
1757 bool p_h = ( hyp && hyp->myTextOption.find("-h") != std::string::npos );
1758 bool p_v = ( hyp && hyp->myTextOption.find("-v ") != std::string::npos );
1759 bool p_i = ( hyp && hyp->myTextOption.find("-i") != std::string::npos );
1760 bool p_o = ( hyp && hyp->myTextOption.find("-o") != std::string::npos );
1761 bool p_mnot = ( hyp && hyp->myTextOption.find("--max_number_of_threads ") != std::string::npos );
1762 bool p_blsi = ( hyp && hyp->myTextOption.find("--boundary_layer_surface_tags ") != std::string::npos );
1763 bool p_blii = ( hyp && hyp->myTextOption.find("--boundary_layer_imprint_tags ") != std::string::npos );
1764 bool p_blsd = ( hyp && hyp->myTextOption.find("--normal_direction ") != std::string::npos );
1765 bool p_hotfl = ( hyp && hyp->myTextOption.find("--boundary_layer_global_initial_height ") != std::string::npos );
1766 bool p_nobl = ( hyp && hyp->myTextOption.find("--number_of_boundary_layers ") != std::string::npos );
1767 bool p_blgp = ( hyp && hyp->myTextOption.find("--boundary_layer_geometric_progression ") != std::string::npos );
1768 bool p_eg = ( hyp && hyp->myTextOption.find("--element_generation ") != std::string::npos );
1769 bool p_cm = ( hyp && hyp->myTextOption.find("--collision_mode ") != std::string::npos );
1770 bool p_am = ( hyp && hyp->myTextOption.find("--add_multinormals ") != std::string::npos );
1771 bool p_mat = ( hyp && hyp->myTextOption.find("--multinormal_angle_threshold ") != std::string::npos );
1772 bool p_sn = ( hyp && hyp->myTextOption.find("--smooth_normals ") != std::string::npos );
1775 //- global_physical_size
1776 //- boundary_layer_size_mode
1777 //- boundary_layer_initial_height_on_surface_tags
1778 //- boundary_layer_max_element_angle
1780 bool nolayers = false;
1781 bool layersOnAllWrap = hyp ? hyp->myLayersOnAllWrap : DefaultLayersOnAllWrap();
1789 std::cout << "!!!!! CommandToRun help only !!!! " << cmd.ToCString() << std::endl;
1790 return cmd.ToCString();
1793 if ( !p_v && hyp ) {
1794 cmd += " --verbose ";
1795 cmd += hyp->myVerboseLevel;
1798 if ( !p_mnot && hyp ) {
1799 cmd += " --max_number_of_threads ";
1800 cmd += 8; //TODO getenv NB CPU
1803 //if ( !p_blsi && hyp ) {
1804 // cmd += " --boundary_layers_surface_ids ";
1805 // cmd += 0; //TODO hyp->my;
1808 //if ( !p_blii && hyp ) {
1809 // cmd += " --boundary_layers_imprint_ids ";
1810 // cmd += 0; //TODO hyp->my;
1814 if ( !p_nobl && hyp ) {
1815 if ( hyp->myNbOfBoundaryLayers < 1 ) nolayers = true;
1817 if ( !p_hotfl && hyp ) {
1818 if ( hyp->myHeightFirstLayer < 1e-50 ) nolayers = true;
1821 if ( !p_blsd && hyp ) {
1822 if ( hyp->myBoundaryLayersGrowth >= 0 && hyp->myBoundaryLayersGrowth <= 1 ) {
1823 const char* value[] = { "1" , "-1" };
1824 cmd += " --normal_direction ";
1825 cmd += value[ hyp->myBoundaryLayersGrowth ];
1829 if ( !p_hotfl && hyp ) {
1830 cmd += " --boundary_layer_global_initial_height ";
1831 cmd += hyp->myHeightFirstLayer;
1834 if ( !p_nobl && hyp ) {
1835 cmd += " --number_of_boundary_layers ";
1839 cmd += hyp->myNbOfBoundaryLayers;
1842 if ( !p_blgp && hyp ) {
1843 cmd += " --boundary_layer_geometric_progression ";
1844 cmd += hyp->myBoundaryLayersProgression;
1847 //--boundary_layers_surface_ids 5 #for all wrap shell
1848 //--boundary_layers_surface_ids 6 #for all enfMeshList
1849 //TODO? if ( !nolayers ) cmd += " --boundary_layers_surface_ids 5,6 "; //as all wrap shell and triangles of enforced mesh
1851 if (layersOnAllWrap)
1852 cmd += " --boundary_layer_surface_tags 5 "; //as triangles of all wrap
1854 cmd += " --boundary_layer_surface_tags 6 "; //as triangles of enforced mesh
1857 if ( !p_eg && hyp ) {
1858 if ( hyp->myElementGeneration >= 0 && hyp->myElementGeneration <= 1 ) {
1859 const char* value[] = { "tetra-dominant" , "hexa-dominant" };
1860 cmd += " --element_generation ";
1861 cmd += value[ hyp->myElementGeneration ];
1865 if ( !p_cm && hyp ) {
1866 if ( hyp->myCollisionMode >= 0 && hyp->myCollisionMode <= 1 ) {
1867 const char* value[] = { "decrease" , "stop" };
1868 cmd += " --collision_mode ";
1869 cmd += value[ hyp->myCollisionMode ];
1873 if ( !p_am && hyp ) {
1874 int res = hyp->myAddMultinormals ? 0 : 1 ;
1875 const char* value[] = { "yes" , "no" };
1876 cmd += " --add_multinormals ";
1877 cmd += value[ res ];
1880 if ( !p_mat && hyp ) {
1881 cmd += " --multinormal_angle_threshold ";
1882 cmd += hyp->myMultinormalsAngle;
1885 if ( !p_sn && hyp ) {
1886 int res = hyp->mySmoothNormals ? 0 : 1 ;
1887 const char* value[] = { "yes" , "no" };
1888 cmd += " --smooth_normals ";
1889 cmd += value[ res ];
1895 //std::cout << "!!!!!CommandToRun end " << cmd.ToCString() << std::endl;
1897 return cmd.ToCString();
1900 //================================================================================
1902 * \brief Return a unique file name
1904 //================================================================================
1906 std::string HYBRIDPlugin_Hypothesis::GetFileName(const HYBRIDPlugin_Hypothesis* hyp)
1908 std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
1909 const char lastChar = *aTmpDir.rbegin();
1911 if(lastChar != '\\') aTmpDir+='\\';
1913 if(lastChar != '/') aTmpDir+='/';
1916 TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
1917 aGenericName += "HYBRID_";
1918 aGenericName += getpid();
1919 aGenericName += "_";
1920 aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
1922 return aGenericName.ToCString();
1925 //================================================================================
1927 * Return the name of executable
1929 //================================================================================
1931 std::string HYBRIDPlugin_Hypothesis::GetExeName()
1933 //call mg-hybrid.bash is script which assumes new project version(s) mg-hybrid.exe in the prerequisite base and special? licence.
1935 return "mg-hybrid.exe";
1937 return "mg-hybrid.bash";
1941 //================================================================================
1943 * \brief Return the enforced vertices
1945 //================================================================================
1947 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexList HYBRIDPlugin_Hypothesis::GetEnforcedVertices(const HYBRIDPlugin_Hypothesis* hyp)
1949 return hyp ? hyp->_GetEnforcedVertices():DefaultHYBRIDEnforcedVertexList();
1952 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesCoordsSize (const HYBRIDPlugin_Hypothesis* hyp)
1954 return hyp ? hyp->_GetEnforcedVerticesCoordsSize(): DefaultHYBRIDEnforcedVertexCoordsValues();
1957 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexEntryValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesEntrySize (const HYBRIDPlugin_Hypothesis* hyp)
1959 return hyp ? hyp->_GetEnforcedVerticesEntrySize(): DefaultHYBRIDEnforcedVertexEntryValues();
1962 HYBRIDPlugin_Hypothesis::TCoordsHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByCoords (const HYBRIDPlugin_Hypothesis* hyp)
1964 return hyp ? hyp->_GetEnforcedVerticesByCoords(): DefaultCoordsHYBRIDEnforcedVertexMap();
1967 HYBRIDPlugin_Hypothesis::TGeomEntryHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByEntry (const HYBRIDPlugin_Hypothesis* hyp)
1969 return hyp ? hyp->_GetEnforcedVerticesByEntry(): DefaultGeomEntryHYBRIDEnforcedVertexMap();
1972 HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedNodes(const HYBRIDPlugin_Hypothesis* hyp)
1974 return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeGroupMap();
1977 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedEdges(const HYBRIDPlugin_Hypothesis* hyp)
1979 return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemGroupMap();
1982 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(const HYBRIDPlugin_Hypothesis* hyp)
1984 return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemGroupMap();
1987 HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp)
1989 return hyp ? hyp->_GetNodeIDToSizeMap(): DefaultID2SizeMap();
1992 HYBRIDPlugin_Hypothesis::TSetStrings HYBRIDPlugin_Hypothesis::GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp)
1994 return hyp ? hyp->_GetGroupsToRemove(): DefaultGroupsToRemove();