1 // Copyright (C) 2004-2013 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.
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 myToMakeGroupsOfDomains(DefaultToMakeGroupsOfDomains()),
48 myOptimizationLevel(DefaultOptimizationLevel()),
49 myCollisionMode(DefaultCollisionMode()),
50 myBoundaryLayersGrowth(DefaultBoundaryLayersGrowth()),
51 myElementGeneration(DefaultElementGeneration()),
52 myAddMultinormals(DefaultAddMultinormals()),
53 mySmoothNormals(DefaultSmoothNormals()),
54 myHeightFirstLayer(DefaultHeightFirstLayer()),
55 myBoundaryLayersProgression(DefaultBoundaryLayersProgression()),
56 myMultinormalsAngle(DefaultMultinormalsAngle()),
57 myNbOfBoundaryLayers(DefaultNbOfBoundaryLayers()),
58 myWorkingDirectory(DefaultWorkingDirectory()),
59 myKeepFiles(DefaultKeepFiles()),
60 myVerboseLevel(DefaultVerboseLevel()),
61 myToCreateNewNodes(DefaultToCreateNewNodes()),
62 myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()),
63 myToUseFemCorrection(DefaultToUseFEMCorrection()),
64 myToRemoveCentralPoint(DefaultToRemoveCentralPoint()),
65 myGradation(DefaultGradation()),
66 myLogInStandardOutput(DefaultStandardOutputLog()),
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 : SetToMeshHoles
86 //=======================================================================
88 void HYBRIDPlugin_Hypothesis::SetToMeshHoles(bool toMesh)
90 if ( myToMeshHoles != toMesh ) {
91 myToMeshHoles = toMesh;
92 NotifySubMeshesHypothesisModification();
96 //=======================================================================
97 //function : GetToMeshHoles
98 //=======================================================================
100 bool HYBRIDPlugin_Hypothesis::GetToMeshHoles(bool checkFreeOption) const
102 if (checkFreeOption && !myTextOption.empty()) {
103 if ( myTextOption.find("-c 0"))
105 if ( myTextOption.find("-c 1"))
108 return myToMeshHoles;
111 //=======================================================================
112 //function : SetToMakeGroupsOfDomains
113 //=======================================================================
115 void HYBRIDPlugin_Hypothesis::SetToMakeGroupsOfDomains(bool toMakeGroups)
117 if ( myToMakeGroupsOfDomains != toMakeGroups ) {
118 myToMakeGroupsOfDomains = toMakeGroups;
119 NotifySubMeshesHypothesisModification();
123 //=======================================================================
124 //function : GetToMakeGroupsOfDomains
125 //=======================================================================
127 bool HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains() const
129 return myToMakeGroupsOfDomains;
132 //=======================================================================
133 //function : GetToMakeGroupsOfDomains
134 //=======================================================================
136 bool HYBRIDPlugin_Hypothesis::GetToMakeGroupsOfDomains(const HYBRIDPlugin_Hypothesis* hyp)
139 if ( hyp ) res = /*hyp->GetToMeshHoles(true) &&*/ hyp->GetToMakeGroupsOfDomains();
140 else res = /*DefaultMeshHoles() &&*/ DefaultToMakeGroupsOfDomains();
144 //=======================================================================
145 //function : SetMaximumMemory
146 //=======================================================================
148 void HYBRIDPlugin_Hypothesis::SetMaximumMemory(double MB)
150 if ( myMaximumMemory != MB ) {
151 myMaximumMemory = MB;
152 NotifySubMeshesHypothesisModification();
156 //=======================================================================
157 //function : GetMaximumMemory
158 // * automatic memory adjustment mode. Default is zero
159 //=======================================================================
161 double HYBRIDPlugin_Hypothesis::GetMaximumMemory() const
163 return myMaximumMemory;
166 //=======================================================================
167 //function : SetInitialMemory
168 //=======================================================================
170 void HYBRIDPlugin_Hypothesis::SetInitialMemory(double MB)
172 if ( myInitialMemory != MB ) {
173 myInitialMemory = MB;
174 NotifySubMeshesHypothesisModification();
178 //=======================================================================
179 //function : GetInitialMemory
180 //=======================================================================
182 double HYBRIDPlugin_Hypothesis::GetInitialMemory() const
184 return myInitialMemory;
187 //=======================================================================
188 //function : SetOptimizationLevel
189 //=======================================================================
191 void HYBRIDPlugin_Hypothesis::SetOptimizationLevel(OptimizationLevel level)
193 if ( myOptimizationLevel != level ) {
194 myOptimizationLevel = level;
195 NotifySubMeshesHypothesisModification();
199 //=======================================================================
200 //function : GetOptimizationLevel
201 //=======================================================================
202 HYBRIDPlugin_Hypothesis::OptimizationLevel HYBRIDPlugin_Hypothesis::GetOptimizationLevel() const
204 return (OptimizationLevel) myOptimizationLevel;
207 //=======================================================================
208 //function : SetCollisionMode
209 //=======================================================================
210 void HYBRIDPlugin_Hypothesis::SetCollisionMode(CollisionMode mode)
212 if ( myCollisionMode != mode ) {
213 myCollisionMode = mode;
214 NotifySubMeshesHypothesisModification();
218 //=======================================================================
219 //function : GetCollisionMode
220 //=======================================================================
221 HYBRIDPlugin_Hypothesis::CollisionMode HYBRIDPlugin_Hypothesis::GetCollisionMode() const
223 return (CollisionMode) myCollisionMode;
226 //=======================================================================
227 //function : SetBoundaryLayersGrowth
228 //=======================================================================
229 void HYBRIDPlugin_Hypothesis::SetBoundaryLayersGrowth(BoundaryLayersGrowth mode)
231 if ( myBoundaryLayersGrowth != mode ) {
232 myBoundaryLayersGrowth = mode;
233 NotifySubMeshesHypothesisModification();
237 //=======================================================================
238 //function : GetBoundaryLayersGrowth
239 //=======================================================================
240 HYBRIDPlugin_Hypothesis::BoundaryLayersGrowth HYBRIDPlugin_Hypothesis::GetBoundaryLayersGrowth() const
242 return (BoundaryLayersGrowth) myBoundaryLayersGrowth;
245 //=======================================================================
246 //function : SetElementGeneration
247 //=======================================================================
248 void HYBRIDPlugin_Hypothesis::SetElementGeneration(ElementGeneration mode)
250 if ( myElementGeneration != mode ) {
251 myElementGeneration = mode;
252 NotifySubMeshesHypothesisModification();
256 //=======================================================================
257 //function : GetElementGeneration
258 //=======================================================================
259 HYBRIDPlugin_Hypothesis::ElementGeneration HYBRIDPlugin_Hypothesis::GetElementGeneration() const
261 return (ElementGeneration) myElementGeneration;
264 //=======================================================================
265 //function : SetAddMultinormals
266 //=======================================================================
267 void HYBRIDPlugin_Hypothesis::SetAddMultinormals(bool toAddMultinormals)
269 if ( myAddMultinormals != toAddMultinormals ) {
270 myAddMultinormals = toAddMultinormals;
271 NotifySubMeshesHypothesisModification();
275 //=======================================================================
276 //function : GetAddMultinormals
277 //=======================================================================
279 bool HYBRIDPlugin_Hypothesis::GetAddMultinormals() const
281 return myAddMultinormals;
284 //=======================================================================
285 //function : SetSmoothNormals
286 //=======================================================================
288 void HYBRIDPlugin_Hypothesis::SetSmoothNormals(bool toSmoothNormals)
290 if ( mySmoothNormals != toSmoothNormals ) {
291 mySmoothNormals = toSmoothNormals;
292 NotifySubMeshesHypothesisModification();
296 //=======================================================================
297 //function : GetSmoothNormals
298 //=======================================================================
300 bool HYBRIDPlugin_Hypothesis::GetSmoothNormals() const
302 return mySmoothNormals;
305 //=======================================================================
306 //function : SetHeightFirstLayer
307 //=======================================================================
309 void HYBRIDPlugin_Hypothesis::SetHeightFirstLayer(double toHeightFirstLayer)
311 if ( myHeightFirstLayer != toHeightFirstLayer ) {
312 myHeightFirstLayer = toHeightFirstLayer;
313 NotifySubMeshesHypothesisModification();
317 //=======================================================================
318 //function : GetHeightFirstLayer
319 //=======================================================================
321 double HYBRIDPlugin_Hypothesis::GetHeightFirstLayer() const
323 return myHeightFirstLayer;
326 //=======================================================================
327 //function : SetBoundaryLayersProgression
328 //=======================================================================
330 void HYBRIDPlugin_Hypothesis::SetBoundaryLayersProgression(double toBoundaryLayersProgression)
332 if ( myBoundaryLayersProgression != toBoundaryLayersProgression ) {
333 myBoundaryLayersProgression = toBoundaryLayersProgression;
334 NotifySubMeshesHypothesisModification();
338 //=======================================================================
339 //function : GetBoundaryLayersProgression
340 //=======================================================================
342 double HYBRIDPlugin_Hypothesis::GetBoundaryLayersProgression() const
344 return myBoundaryLayersProgression;
347 //=======================================================================
348 //function : SetMultinormalsAngle
349 //=======================================================================
351 void HYBRIDPlugin_Hypothesis::SetMultinormalsAngle(double toMultinormalsAngle)
353 if ( myMultinormalsAngle != toMultinormalsAngle ) {
354 myMultinormalsAngle = toMultinormalsAngle;
355 NotifySubMeshesHypothesisModification();
359 //=======================================================================
360 //function : GetMultinormalsAngle
361 //=======================================================================
363 double HYBRIDPlugin_Hypothesis::GetMultinormalsAngle() const
365 return myMultinormalsAngle;
368 //=======================================================================
369 //function : SetNbOfBoundaryLayers
370 //=======================================================================
372 void HYBRIDPlugin_Hypothesis::SetNbOfBoundaryLayers(short toNbOfBoundaryLayers)
374 if ( myNbOfBoundaryLayers != toNbOfBoundaryLayers ) {
375 myNbOfBoundaryLayers = toNbOfBoundaryLayers;
376 NotifySubMeshesHypothesisModification();
380 //=======================================================================
381 //function : GetMultinormalsAngle
382 //=======================================================================
384 short HYBRIDPlugin_Hypothesis::GetNbOfBoundaryLayers() const
386 return myNbOfBoundaryLayers;
390 /////////////////////////////////////////////////////////////////////////
393 //=======================================================================
394 //function : SetWorkingDirectory
395 //=======================================================================
397 void HYBRIDPlugin_Hypothesis::SetWorkingDirectory(const std::string& path)
399 if ( myWorkingDirectory != path ) {
400 myWorkingDirectory = path;
401 NotifySubMeshesHypothesisModification();
405 //=======================================================================
406 //function : GetWorkingDirectory
407 //=======================================================================
409 std::string HYBRIDPlugin_Hypothesis::GetWorkingDirectory() const
411 return myWorkingDirectory;
414 //=======================================================================
415 //function : SetKeepFiles
416 //=======================================================================
418 void HYBRIDPlugin_Hypothesis::SetKeepFiles(bool toKeep)
420 if ( myKeepFiles != toKeep ) {
421 myKeepFiles = toKeep;
422 NotifySubMeshesHypothesisModification();
426 //=======================================================================
427 //function : GetKeepFiles
428 //=======================================================================
430 bool HYBRIDPlugin_Hypothesis::GetKeepFiles() const
435 //=======================================================================
436 //function : SetVerboseLevel
437 //=======================================================================
439 void HYBRIDPlugin_Hypothesis::SetVerboseLevel(short level)
441 if ( myVerboseLevel != level ) {
442 myVerboseLevel = level;
443 NotifySubMeshesHypothesisModification();
447 //=======================================================================
448 //function : GetVerboseLevel
449 //=======================================================================
451 short HYBRIDPlugin_Hypothesis::GetVerboseLevel() const
453 return myVerboseLevel;
456 //=======================================================================
457 //function : SetToCreateNewNodes
458 //=======================================================================
460 void HYBRIDPlugin_Hypothesis::SetToCreateNewNodes(bool toCreate)
462 if ( myToCreateNewNodes != toCreate ) {
463 myToCreateNewNodes = toCreate;
464 NotifySubMeshesHypothesisModification();
468 //=======================================================================
469 //function : GetToCreateNewNodes
470 //=======================================================================
472 bool HYBRIDPlugin_Hypothesis::GetToCreateNewNodes() const
474 return myToCreateNewNodes;
477 //=======================================================================
478 //function : SetToUseBoundaryRecoveryVersion
479 //=======================================================================
481 void HYBRIDPlugin_Hypothesis::SetToUseBoundaryRecoveryVersion(bool toUse)
483 if ( myToUseBoundaryRecoveryVersion != toUse ) {
484 myToUseBoundaryRecoveryVersion = toUse;
485 NotifySubMeshesHypothesisModification();
489 //=======================================================================
490 //function : GetToUseBoundaryRecoveryVersion
491 //=======================================================================
493 bool HYBRIDPlugin_Hypothesis::GetToUseBoundaryRecoveryVersion() const
495 return myToUseBoundaryRecoveryVersion;
498 //=======================================================================
499 //function : SetFEMCorrection
500 //=======================================================================
502 void HYBRIDPlugin_Hypothesis::SetFEMCorrection(bool toUseFem)
504 if ( myToUseFemCorrection != toUseFem ) {
505 myToUseFemCorrection = toUseFem;
506 NotifySubMeshesHypothesisModification();
510 //=======================================================================
511 //function : GetFEMCorrection
512 //=======================================================================
514 bool HYBRIDPlugin_Hypothesis::GetFEMCorrection() const
516 return myToUseFemCorrection;
519 //=======================================================================
520 //function : SetToRemoveCentralPoint
521 //=======================================================================
523 void HYBRIDPlugin_Hypothesis::SetToRemoveCentralPoint(bool toRemove)
525 if ( myToRemoveCentralPoint != toRemove ) {
526 myToRemoveCentralPoint = toRemove;
527 NotifySubMeshesHypothesisModification();
531 //=======================================================================
532 //function : GetToRemoveCentralPoint
533 //=======================================================================
535 bool HYBRIDPlugin_Hypothesis::GetToRemoveCentralPoint() const
537 return myToRemoveCentralPoint;
540 //=======================================================================
541 //function : SetTextOption
542 //=======================================================================
544 void HYBRIDPlugin_Hypothesis::SetTextOption(const std::string& option)
546 if ( myTextOption != option ) {
547 myTextOption = option;
548 NotifySubMeshesHypothesisModification();
552 //=======================================================================
553 //function : GetTextOption
554 //=======================================================================
556 std::string HYBRIDPlugin_Hypothesis::GetTextOption() const
561 //=======================================================================
562 //function : SetGradation
563 //=======================================================================
565 void HYBRIDPlugin_Hypothesis::SetGradation(double gradation)
567 if ( myGradation != gradation ) {
568 myGradation = gradation;
569 NotifySubMeshesHypothesisModification();
573 //=======================================================================
574 //function : GetGradation
575 //=======================================================================
577 double HYBRIDPlugin_Hypothesis::GetGradation() const
582 //=======================================================================
583 //function : SetStandardOutputLog
584 //=======================================================================
586 void HYBRIDPlugin_Hypothesis::SetStandardOutputLog(bool logInStandardOutput)
588 if ( myLogInStandardOutput != logInStandardOutput ) {
589 myLogInStandardOutput = logInStandardOutput;
590 NotifySubMeshesHypothesisModification();
594 //=======================================================================
595 //function : GetStandardOutputLog
596 //=======================================================================
598 bool HYBRIDPlugin_Hypothesis::GetStandardOutputLog() const
600 return myLogInStandardOutput;
603 //=======================================================================
604 //function : SetRemoveLogOnSuccess
605 //=======================================================================
607 void HYBRIDPlugin_Hypothesis::SetRemoveLogOnSuccess(bool removeLogOnSuccess)
609 if ( myRemoveLogOnSuccess != removeLogOnSuccess ) {
610 myRemoveLogOnSuccess = removeLogOnSuccess;
611 NotifySubMeshesHypothesisModification();
615 //=======================================================================
616 //function : GetRemoveLogOnSuccess
617 //=======================================================================
619 bool HYBRIDPlugin_Hypothesis::GetRemoveLogOnSuccess() const
621 return myRemoveLogOnSuccess;
624 //=======================================================================
625 //function : SetEnforcedVertex
626 //=======================================================================
628 bool HYBRIDPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string theEntry, std::string theGroupName,
629 double size, double x, double y, double z, bool isCompound)
631 MESSAGE("HYBRIDPlugin_Hypothesis::SetEnforcedVertex(\""<< theName << "\", \""<< theEntry << "\", \"" << theGroupName << "\", "
632 << size << ", " << x << ", " << y << ", " << z << ", "<< isCompound << ")");
634 bool toNotify = false;
635 bool toCreate = true;
637 THYBRIDEnforcedVertex *oldEnVertex;
638 THYBRIDEnforcedVertex *newEnfVertex = new THYBRIDEnforcedVertex();
639 newEnfVertex->name = theName;
640 newEnfVertex->geomEntry = theEntry;
641 newEnfVertex->coords.clear();
643 newEnfVertex->coords.push_back(x);
644 newEnfVertex->coords.push_back(y);
645 newEnfVertex->coords.push_back(z);
647 newEnfVertex->groupName = theGroupName;
648 newEnfVertex->size = size;
649 newEnfVertex->isCompound = isCompound;
652 // update _enfVertexList
653 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(newEnfVertex);
654 if (it != _enfVertexList.end()) {
657 MESSAGE("Enforced Vertex was found => Update");
658 if (oldEnVertex->name != theName) {
659 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theName << "\"");
660 oldEnVertex->name = theName;
663 if (oldEnVertex->groupName != theGroupName) {
664 MESSAGE("Update group name from \"" << oldEnVertex->groupName << "\" to \"" << theGroupName << "\"");
665 oldEnVertex->groupName = theGroupName;
668 if (oldEnVertex->size != size) {
669 MESSAGE("Update size from \"" << oldEnVertex->size << "\" to \"" << size << "\"");
670 oldEnVertex->size = size;
674 // update map coords / enf vertex if needed
675 if (oldEnVertex->coords.size()) {
676 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
677 _enfVertexCoordsSizeList[oldEnVertex->coords] = size;
680 // update map geom entry / enf vertex if needed
681 if (oldEnVertex->geomEntry != "") {
682 _geomEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
683 _enfVertexEntrySizeList[oldEnVertex->geomEntry] = size;
688 // //////// CREATE ////////////
691 MESSAGE("Creating new enforced vertex");
692 _enfVertexList.insert(newEnfVertex);
693 if (theEntry == "") {
694 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
695 _enfVertexCoordsSizeList[newEnfVertex->coords] = size;
698 _geomEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
699 _enfVertexEntrySizeList[newEnfVertex->geomEntry] = size;
704 NotifySubMeshesHypothesisModification();
706 MESSAGE("HYBRIDPlugin_Hypothesis::SetEnforcedVertex END");
711 //=======================================================================
712 //function : SetEnforcedMesh
713 //=======================================================================
714 bool HYBRIDPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName)
716 TIDSortedElemSet theElemSet;
717 SMDS_ElemIteratorPtr eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType));
718 while ( eIt->more() )
719 theElemSet.insert( eIt->next() );
720 MESSAGE("Add "<<theElemSet.size()<<" types["<<elementType<<"] from source mesh");
721 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
723 THYBRIDEnforcedMesh* newEnfMesh = new THYBRIDEnforcedMesh();
724 newEnfMesh->persistID = theMesh.GetMeshDS()->GetPersistentId();
725 newEnfMesh->name = name;
726 newEnfMesh->entry = entry;
727 newEnfMesh->elementType = elementType;
728 newEnfMesh->groupName = groupName;
730 THYBRIDEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
731 if (it == _enfMeshList.end()) {
732 _entryEnfMeshMap[entry].insert(newEnfMesh);
733 _enfMeshList.insert(newEnfMesh);
742 //=======================================================================
743 //function : SetEnforcedGroup
744 //=======================================================================
745 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)
747 MESSAGE("HYBRIDPlugin_Hypothesis::SetEnforcedGroup");
748 TIDSortedElemSet theElemSet;
749 if ( theIDs->length() == 0 ){MESSAGE("The source group is empty");}
750 for (int i=0; i < theIDs->length(); i++) {
751 CORBA::Long ind = theIDs[i];
752 if (elementType == SMESH::NODE)
754 const SMDS_MeshNode * node = theMeshDS->FindNode(ind);
756 theElemSet.insert( node );
760 const SMDS_MeshElement * elem = theMeshDS->FindElement(ind);
762 theElemSet.insert( elem );
766 // SMDS_ElemIteratorPtr it = theGroup->GetGroupDS()->GetElements();
767 // while ( it->more() )
768 // theElemSet.insert( it->next() );
770 MESSAGE("Add "<<theElemSet.size()<<" types["<<elementType<<"] from source group ");
771 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
773 THYBRIDEnforcedMesh* newEnfMesh = new THYBRIDEnforcedMesh();
774 newEnfMesh->name = name;
775 newEnfMesh->entry = entry;
776 newEnfMesh->elementType = elementType;
777 newEnfMesh->groupName = groupName;
779 THYBRIDEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
780 if (it == _enfMeshList.end()) {
781 _entryEnfMeshMap[entry].insert(newEnfMesh);
782 _enfMeshList.insert(newEnfMesh);
788 //=======================================================================
789 //function : SetEnforcedElements
790 //=======================================================================
791 bool HYBRIDPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName)
793 MESSAGE("HYBRIDPlugin_Hypothesis::SetEnforcedElements");
794 TIDSortedElemSet::const_iterator it = theElemSet.begin();
795 const SMDS_MeshElement* elem;
796 const SMDS_MeshNode* node;
798 pair<TIDSortedNodeGroupMap::iterator,bool> nodeRet;
799 pair<TIDSortedElemGroupMap::iterator,bool> elemRet;
801 for (;it != theElemSet.end();++it)
804 switch (elementType) {
806 node = dynamic_cast<const SMDS_MeshNode*>(elem);
808 nodeRet = _enfNodes.insert(make_pair(node,groupName));
809 added = added && nodeRet.second;
810 string msg = added ? "yes":"no";
811 MESSAGE( "Node (" <<node->X()<<","<<node->Y()<<","<<node->Z()<< ") with ID " << node->GetID() <<" added ? " << msg);
814 SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
815 for (;nodeIt->more();) {
816 node = dynamic_cast<const SMDS_MeshNode*>(nodeIt->next());
817 nodeRet = _enfNodes.insert(make_pair(node,groupName));
818 added = added && nodeRet.second;
824 if (elem->GetType() == SMDSAbs_Edge) {
825 elemRet = _enfEdges.insert(make_pair(elem,groupName));
826 added = added && elemRet.second;
828 else if (elem->GetType() > SMDSAbs_Edge) {
829 SMDS_ElemIteratorPtr it = elem->edgesIterator();
831 const SMDS_MeshElement* anEdge = it->next();
832 elemRet = _enfEdges.insert(make_pair(anEdge,groupName));
833 added = added && elemRet.second;
838 if (elem->GetType() == SMDSAbs_Face)
840 if (elem->NbCornerNodes() == 3) {
841 elemRet = _enfTriangles.insert(make_pair(elem,groupName));
842 added = added && elemRet.second;
845 else if (elem->GetType() > SMDSAbs_Face) { // Group of faces
846 SMDS_ElemIteratorPtr it = elem->facesIterator();
848 const SMDS_MeshElement* aFace = it->next();
849 if (aFace->NbCornerNodes() == 3) {
850 elemRet = _enfTriangles.insert(make_pair(aFace,groupName));
851 added = added && elemRet.second;
861 NotifySubMeshesHypothesisModification();
866 //=======================================================================
867 //function : GetEnforcedVertex
868 //=======================================================================
870 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z)
871 throw (std::invalid_argument)
873 std::vector<double> coord(3);
877 if (_coordsEnfVertexMap.count(coord)>0)
878 return _coordsEnfVertexMap[coord];
879 std::ostringstream msg ;
880 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
881 throw std::invalid_argument(msg.str());
884 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertex* HYBRIDPlugin_Hypothesis::GetEnforcedVertex(const std::string theEntry)
885 throw (std::invalid_argument)
887 if (_geomEntryEnfVertexMap.count(theEntry)>0)
888 return _geomEntryEnfVertexMap[theEntry];
890 std::ostringstream msg ;
891 msg << "No enforced vertex with entry " << theEntry;
892 throw std::invalid_argument(msg.str());
895 //=======================================================================
896 //function : RemoveEnforcedVertex
897 //=======================================================================
899 bool HYBRIDPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, const std::string theEntry)
900 throw (std::invalid_argument)
902 bool toNotify = false;
903 std::ostringstream msg;
904 THYBRIDEnforcedVertex *oldEnfVertex;
905 std::vector<double> coords(3);
910 // check that enf vertex with given enf vertex entry exists
911 TGeomEntryHYBRIDEnforcedVertexMap::iterator it_enfVertexEntry = _geomEntryEnfVertexMap.find(theEntry);
912 if (it_enfVertexEntry != _geomEntryEnfVertexMap.end()) {
914 MESSAGE("Found enforced vertex with geom entry " << theEntry);
915 oldEnfVertex = it_enfVertexEntry->second;
916 _geomEntryEnfVertexMap.erase(it_enfVertexEntry);
919 MESSAGE("Enforced vertex with geom entry " << theEntry << " not found");
920 // check that enf vertex with given coords exists
921 TCoordsHYBRIDEnforcedVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
922 if (it_coords_enf != _coordsEnfVertexMap.end()) {
924 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
925 oldEnfVertex = it_coords_enf->second;
926 _coordsEnfVertexMap.erase(it_coords_enf);
927 _enfVertexCoordsSizeList.erase(_enfVertexCoordsSizeList.find(coords));
930 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
931 throw std::invalid_argument(msg.str());
935 MESSAGE("Remove enf vertex from _enfVertexList");
937 // update _enfVertexList
938 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
939 if (it != _enfVertexList.end()) {
940 if ((*it)->groupName != "")
941 _groupsToRemove.insert((*it)->groupName);
942 _enfVertexList.erase(it);
948 NotifySubMeshesHypothesisModification();
953 //=======================================================================
954 //function : ClearEnforcedVertices
955 //=======================================================================
956 void HYBRIDPlugin_Hypothesis::ClearEnforcedVertices()
958 THYBRIDEnforcedVertexList::const_iterator it = _enfVertexList.begin();
959 for(;it != _enfVertexList.end();++it) {
960 if ((*it)->groupName != "")
961 _groupsToRemove.insert((*it)->groupName);
963 _enfVertexList.clear();
964 _coordsEnfVertexMap.clear();
965 _geomEntryEnfVertexMap.clear();
966 _enfVertexCoordsSizeList.clear();
967 _enfVertexEntrySizeList.clear();
968 NotifySubMeshesHypothesisModification();
971 //=======================================================================
972 //function : ClearEnforcedMeshes
973 //=======================================================================
974 void HYBRIDPlugin_Hypothesis::ClearEnforcedMeshes()
976 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
977 for(;it != _enfMeshList.end();++it) {
978 if ((*it)->groupName != "")
979 _groupsToRemove.insert((*it)->groupName);
983 _enfTriangles.clear();
984 _nodeIDToSizeMap.clear();
985 _enfMeshList.clear();
986 _entryEnfMeshMap.clear();
987 NotifySubMeshesHypothesisModification();
990 //================================================================================
992 * \brief At mesh loading, restore enforced elements by just loaded enforced meshes
994 //================================================================================
996 void HYBRIDPlugin_Hypothesis::RestoreEnfElemsByMeshes()
998 THYBRIDEnforcedMeshList::const_iterator it = _enfMeshList.begin();
999 for(;it != _enfMeshList.end();++it) {
1000 THYBRIDEnforcedMesh* enfMesh = *it;
1001 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
1002 SetEnforcedMesh( *mesh,
1003 enfMesh->elementType,
1006 enfMesh->groupName );
1007 enfMesh->persistID = -1; // not to restore again
1011 //=======================================================================
1012 //function : SetGroupsToRemove
1013 //=======================================================================
1015 void HYBRIDPlugin_Hypothesis::ClearGroupsToRemove()
1017 _groupsToRemove.clear();
1021 //=======================================================================
1022 //function : DefaultMeshHoles
1023 //=======================================================================
1025 bool HYBRIDPlugin_Hypothesis::DefaultMeshHoles()
1027 return false; // PAL19680
1030 //=======================================================================
1031 //function : DefaultToMakeGroupsOfDomains
1032 //=======================================================================
1034 bool HYBRIDPlugin_Hypothesis::DefaultToMakeGroupsOfDomains()
1036 return false; // issue 0022172
1039 //=======================================================================
1040 //function : DefaultMaximumMemory
1041 //=======================================================================
1044 #include <sys/sysinfo.h>
1046 #include <windows.h>
1049 double HYBRIDPlugin_Hypothesis::DefaultMaximumMemory()
1053 int err = sysinfo( &si );
1055 int ramMB = si.totalram * si.mem_unit / 1024 / 1024;
1056 return ( 0.7 * ramMB );
1059 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
1060 MEMORYSTATUSEX statex;
1061 statex.dwLength = sizeof (statex);
1062 int err = GlobalMemoryStatusEx (&statex);
1065 statex.ullTotalPhys / 1024 / 1024 +
1066 statex.ullTotalPageFile / 1024 / 1024 +
1067 statex.ullTotalVirtual / 1024 / 1024;
1068 return ( 0.7 * totMB );
1074 //=======================================================================
1075 //function : DefaultInitialMemory
1076 //=======================================================================
1078 double HYBRIDPlugin_Hypothesis::DefaultInitialMemory()
1080 return DefaultMaximumMemory();
1083 //=======================================================================
1084 //function : DefaultCollisionMode
1085 //=======================================================================
1086 short HYBRIDPlugin_Hypothesis::DefaultCollisionMode()
1091 //=======================================================================
1092 //function : DefaultBoundaryLayersGrowth
1093 //=======================================================================
1094 short HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersGrowth()
1096 return Layer_Growth_Inward;
1099 //=======================================================================
1100 //function : DefaultElementGeneration
1101 //=======================================================================
1102 short HYBRIDPlugin_Hypothesis::DefaultElementGeneration()
1104 return Generation_Tetra_Dominant;
1107 //=======================================================================
1108 //function : DefaultOptimizationLevel
1109 //=======================================================================
1110 short HYBRIDPlugin_Hypothesis::DefaultOptimizationLevel()
1115 //=======================================================================
1116 //function : DefaultWorkingDirectory
1117 //=======================================================================
1119 std::string HYBRIDPlugin_Hypothesis::DefaultWorkingDirectory()
1121 TCollection_AsciiString aTmpDir;
1123 char *Tmp_dir = getenv("SALOME_TMP_DIR");
1124 if(Tmp_dir != NULL) {
1129 aTmpDir = TCollection_AsciiString("C:\\");
1131 aTmpDir = TCollection_AsciiString("/tmp/");
1134 return aTmpDir.ToCString();
1137 //=======================================================================
1138 //function : DefaultKeepFiles
1139 //=======================================================================
1141 bool HYBRIDPlugin_Hypothesis::DefaultKeepFiles()
1146 //=======================================================================
1147 //function : DefaultRemoveLogOnSuccess
1148 //=======================================================================
1150 bool HYBRIDPlugin_Hypothesis::DefaultRemoveLogOnSuccess()
1156 //=======================================================================
1157 //function : DefaultVerboseLevel
1158 //=======================================================================
1160 short HYBRIDPlugin_Hypothesis::DefaultVerboseLevel()
1165 //=======================================================================
1166 //function : DefaultToCreateNewNodes
1167 //=======================================================================
1169 bool HYBRIDPlugin_Hypothesis::DefaultToCreateNewNodes()
1174 //=======================================================================
1175 //function : DefaultToUseBoundaryRecoveryVersion
1176 //=======================================================================
1178 bool HYBRIDPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
1183 //=======================================================================
1184 //function : DefaultToUseFEMCorrection
1185 //=======================================================================
1187 bool HYBRIDPlugin_Hypothesis::DefaultToUseFEMCorrection()
1192 //=======================================================================
1193 //function : DefaultToRemoveCentralPoint
1194 //=======================================================================
1196 bool HYBRIDPlugin_Hypothesis::DefaultToRemoveCentralPoint()
1201 //=======================================================================
1202 //function : DefaultGradation
1203 //=======================================================================
1205 double HYBRIDPlugin_Hypothesis::DefaultGradation()
1210 //=======================================================================
1211 //function : DefaultStandardOutputLog
1212 //=======================================================================
1214 bool HYBRIDPlugin_Hypothesis::DefaultStandardOutputLog()
1219 // //=======================================================================
1220 // //function : DefaultID2SizeMap
1221 // //=======================================================================
1223 // HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::DefaultID2SizeMap()
1225 // return HYBRIDPlugin_Hypothesis::TID2SizeMap();
1228 //=======================================================================
1229 //function : DefaultAddMultinormals
1230 //=======================================================================
1231 bool HYBRIDPlugin_Hypothesis::DefaultAddMultinormals()
1236 //=======================================================================
1237 //function : DefaultSmoothNormals
1238 //=======================================================================
1239 bool HYBRIDPlugin_Hypothesis::DefaultSmoothNormals()
1244 //=======================================================================
1245 //function : DefaultHeightFirstLayer
1246 //=======================================================================
1247 double HYBRIDPlugin_Hypothesis::DefaultHeightFirstLayer()
1249 return 0.0; //or epsilon?
1252 //=======================================================================
1253 //function : DefaultBoundaryLayersProgression
1254 //=======================================================================
1255 double HYBRIDPlugin_Hypothesis::DefaultBoundaryLayersProgression()
1260 //=======================================================================
1261 //function : DefaultMultinormalsAngle
1262 //=======================================================================
1263 double HYBRIDPlugin_Hypothesis::DefaultMultinormalsAngle()
1268 //=======================================================================
1269 //function : DefaultNbOfBoundaryLayers
1270 //=======================================================================
1271 short HYBRIDPlugin_Hypothesis::DefaultNbOfBoundaryLayers()
1276 //=======================================================================
1278 //=======================================================================
1280 std::ostream & HYBRIDPlugin_Hypothesis::SaveTo(std::ostream & save)
1282 save << (int) myBoundaryLayersGrowth << " ";
1283 save << (int) myElementGeneration << " ";
1284 save << (int) myAddMultinormals << " ";
1285 save << (int) mySmoothNormals << " ";
1287 save << myNbOfBoundaryLayers << " ";
1288 save << myHeightFirstLayer << " ";
1289 save << myBoundaryLayersProgression << " ";
1290 save << myMultinormalsAngle << " ";
1292 save << (int) myKeepFiles << " ";
1293 save << myWorkingDirectory << " ";
1294 save << myVerboseLevel << " ";
1295 if (!myTextOption.empty()) {
1296 save << "__OPTIONS_BEGIN__ ";
1297 save << myTextOption << " ";
1298 save << "__OPTIONS_END__ ";
1302 THYBRIDEnforcedVertexList::iterator it = _enfVertexList.begin();
1303 if (it != _enfVertexList.end()) {
1304 save << " " << "__ENFORCED_VERTICES_BEGIN__ ";
1305 for ( ; it != _enfVertexList.end(); ++it ) {
1306 THYBRIDEnforcedVertex *enfVertex = (*it);
1307 save << " " << "__BEGIN_VERTEX__";
1308 if (!enfVertex->name.empty()) {
1309 save << " " << "__BEGIN_NAME__";
1310 save << " " << enfVertex->name;
1311 save << " " << "__END_NAME__";
1313 if (!enfVertex->geomEntry.empty()) {
1314 save << " " << "__BEGIN_ENTRY__";
1315 save << " " << enfVertex->geomEntry;
1316 save << " " << enfVertex->isCompound;
1317 save << " " << "__END_ENTRY__";
1319 if (!enfVertex->groupName.empty()) {
1320 save << " " << "__BEGIN_GROUP__";
1321 save << " " << enfVertex->groupName;
1322 save << " " << "__END_GROUP__";
1324 if (enfVertex->coords.size()) {
1325 save << " " << "__BEGIN_COORDS__";
1326 for (int i=0;i<enfVertex->coords.size();i++)
1327 save << " " << enfVertex->coords[i];
1328 save << " " << "__END_COORDS__";
1330 save << " " << "__BEGIN_SIZE__";
1331 save << " " << enfVertex->size;
1332 save << " " << "__END_SIZE__";
1333 save << " " << "__END_VERTEX__";
1335 save << " " << "__ENFORCED_VERTICES_END__ ";
1338 THYBRIDEnforcedMeshList::iterator it_mesh = _enfMeshList.begin();
1339 if (it_mesh != _enfMeshList.end()) {
1340 save << " " << "__ENFORCED_MESHES_BEGIN__ ";
1341 for ( ; it_mesh != _enfMeshList.end(); ++it_mesh ) {
1342 THYBRIDEnforcedMesh *enfMesh = (*it_mesh);
1343 save << " " << "__BEGIN_ENF_MESH__";
1345 save << " " << "__BEGIN_NAME__";
1346 save << " " << enfMesh->name;
1347 save << " " << "__END_NAME__";
1349 save << " " << "__BEGIN_ENTRY__";
1350 save << " " << enfMesh->entry;
1351 save << " " << "__END_ENTRY__";
1353 save << " " << "__BEGIN_ELEM_TYPE__";
1354 save << " " << (int)enfMesh->elementType;
1355 save << " " << "__END_ELEM_TYPE__";
1357 if (!enfMesh->groupName.empty()) {
1358 save << " " << "__BEGIN_GROUP__";
1359 save << " " << enfMesh->groupName;
1360 save << " " << "__END_GROUP__";
1362 save << " " << "__PERSIST_ID__";
1363 save << " " << enfMesh->persistID;
1364 save << " " << "__END_ENF_MESH__";
1365 std::cout << "Saving of enforced mesh " << enfMesh->name.c_str() << " done" << std::endl;
1367 save << " " << "__ENFORCED_MESHES_END__ ";
1372 //=======================================================================
1373 //function : LoadFrom
1374 //=======================================================================
1376 std::istream & HYBRIDPlugin_Hypothesis::LoadFrom(std::istream & load)
1384 myBoundaryLayersGrowth = (short) i;
1386 load.clear(ios::badbit | load.rdstate());
1390 myElementGeneration = (short) i;
1392 load.clear(ios::badbit | load.rdstate());
1396 myAddMultinormals = (bool) i;
1398 load.clear(ios::badbit | load.rdstate());
1402 mySmoothNormals = (bool) i;
1404 load.clear(ios::badbit | load.rdstate());
1408 myNbOfBoundaryLayers = (short) i;
1410 load.clear(ios::badbit | load.rdstate());
1414 myHeightFirstLayer = d;
1416 load.clear(ios::badbit | load.rdstate());
1420 myBoundaryLayersProgression = d;
1422 load.clear(ios::badbit | load.rdstate());
1426 myMultinormalsAngle = d;
1428 load.clear(ios::badbit | load.rdstate());
1432 myKeepFiles = (bool) i;
1434 load.clear(ios::badbit | load.rdstate());
1436 isOK = (load >> myWorkingDirectory);
1438 if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
1439 myKeepFiles = false;
1440 myWorkingDirectory.clear();
1442 else if ( myWorkingDirectory == "1" ) {
1444 myWorkingDirectory.clear();
1448 load.clear(ios::badbit | load.rdstate());
1450 if ( !myWorkingDirectory.empty() ) {
1455 load.clear(ios::badbit | load.rdstate());
1460 myVerboseLevel = (short) i;
1462 load.clear(ios::badbit | load.rdstate());
1465 std::string separator;
1466 bool hasOptions = false;
1467 bool hasEnforcedVertices = false;
1468 bool hasEnforcedMeshes = false;
1469 isOK = (load >> separator);
1471 if ( isOK && ( separator == "0" || separator == "1" ))
1473 myToMakeGroupsOfDomains = ( separator == "1" );
1474 isOK = (load >> separator);
1478 if (separator == "__OPTIONS_BEGIN__")
1480 else if (separator == "__ENFORCED_VERTICES_BEGIN__")
1481 hasEnforcedVertices = true;
1482 else if (separator == "__ENFORCED_MESHES_BEGIN__")
1483 hasEnforcedMeshes = true;
1489 isOK = (load >> txt);
1491 if (txt == "__OPTIONS_END__") {
1492 if (!myTextOption.empty()) {
1493 // Remove last space
1494 myTextOption.erase(myTextOption.end()-1);
1499 myTextOption += txt;
1500 myTextOption += " ";
1506 isOK = (load >> separator);
1507 if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__")
1508 hasEnforcedVertices = true;
1509 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1510 hasEnforcedMeshes = true;
1513 if (hasEnforcedVertices) {
1514 std::string txt, name, entry, groupName;
1515 double size, coords[3];
1517 bool hasCoords = false;
1518 isOK = (load >> txt); // __BEGIN_VERTEX__
1520 if (txt == "__ENFORCED_VERTICES_END__")
1523 THYBRIDEnforcedVertex *enfVertex = new THYBRIDEnforcedVertex();
1525 isOK = (load >> txt);
1526 if (txt == "__END_VERTEX__") {
1527 enfVertex->name = name;
1528 enfVertex->geomEntry = entry;
1529 enfVertex->isCompound = isCompound;
1530 enfVertex->groupName = groupName;
1531 enfVertex->coords.clear();
1533 enfVertex->coords.assign(coords,coords+3);
1535 _enfVertexList.insert(enfVertex);
1537 if (enfVertex->coords.size())
1538 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1539 if (!enfVertex->geomEntry.empty())
1540 _geomEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1549 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1550 while (isOK && (txt != "__END_NAME__")) {
1551 isOK = (load >> txt);
1552 if (txt != "__END_NAME__") {
1558 MESSAGE("name: " <<name);
1561 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1562 isOK = (load >> entry);
1563 isOK = (load >> isCompound);
1564 isOK = (load >> txt); // __END_ENTRY__
1565 if (txt != "__END_ENTRY__")
1566 throw std::exception();
1567 MESSAGE("entry: " << entry);
1570 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1571 while (isOK && (txt != "__END_GROUP__")) {
1572 isOK = (load >> txt);
1573 if (txt != "__END_GROUP__") {
1574 if (!groupName.empty())
1579 MESSAGE("groupName: " << groupName);
1582 if (txt == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1584 isOK = (load >> coords[0] >> coords[1] >> coords[2]);
1585 isOK = (load >> txt); // __END_COORDS__
1586 if (txt != "__END_COORDS__")
1587 throw std::exception();
1588 MESSAGE("coords: " << coords[0] <<","<< coords[1] <<","<< coords[2]);
1591 if (txt == "__BEGIN_SIZE__") { // __BEGIN_ENTRY__
1592 isOK = (load >> size);
1593 isOK = (load >> txt); // __END_ENTRY__
1594 if (txt != "__END_SIZE__") {
1595 throw std::exception();
1597 MESSAGE("size: " << size);
1600 isOK = (load >> txt); // __BEGIN_VERTEX__
1604 if (hasEnforcedVertices) {
1605 isOK = (load >> separator);
1606 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1607 hasEnforcedMeshes = true;
1610 if (hasEnforcedMeshes) {
1611 std::string txt, name, entry, groupName;
1612 int elementType = -1, persistID = -1;
1613 isOK = (load >> txt); // __BEGIN_ENF_MESH__
1616 if (txt == "__ENFORCED_MESHES_END__")
1619 THYBRIDEnforcedMesh *enfMesh = new THYBRIDEnforcedMesh();
1621 isOK = (load >> txt);
1622 if (txt == "__END_ENF_MESH__") {
1623 enfMesh->name = name;
1624 enfMesh->entry = entry;
1625 enfMesh->elementType = (SMESH::ElementType)elementType;
1626 enfMesh->groupName = groupName;
1627 enfMesh->persistID = persistID;
1629 _enfMeshList.insert(enfMesh);
1630 std::cout << "Restoring of enforced mesh " <<name << " done" << std::endl;
1640 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1641 while (isOK && (txt != "__END_NAME__")) {
1642 isOK = (load >> txt);
1643 if (txt != "__END_NAME__") {
1649 MESSAGE("name: " <<name);
1652 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1653 isOK = (load >> entry);
1654 isOK = (load >> txt); // __END_ENTRY__
1655 if (txt != "__END_ENTRY__")
1656 throw std::exception();
1657 MESSAGE("entry: " << entry);
1660 if (txt == "__BEGIN_ELEM_TYPE__") { // __BEGIN_ELEM_TYPE__
1661 isOK = (load >> elementType);
1662 isOK = (load >> txt); // __END_ELEM_TYPE__
1663 if (txt != "__END_ELEM_TYPE__")
1664 throw std::exception();
1665 MESSAGE("elementType: " << elementType);
1668 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1669 while (isOK && (txt != "__END_GROUP__")) {
1670 isOK = (load >> txt);
1671 if (txt != "__END_GROUP__") {
1672 if (!groupName.empty())
1677 MESSAGE("groupName: " << groupName);
1680 if (txt == "__PERSIST_ID__") {
1681 isOK = (load >> persistID);
1682 MESSAGE("persistID: " << persistID);
1684 std::cout << "isOK: " << isOK << std::endl;
1687 isOK = (load >> txt); // __BEGIN_ENF_MESH__
1694 //=======================================================================
1695 //function : SetParametersByMesh
1696 //=======================================================================
1698 bool HYBRIDPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
1704 //================================================================================
1706 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
1708 //================================================================================
1710 bool HYBRIDPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
1711 const SMESH_Mesh* /*theMesh*/)
1713 myToMakeGroupsOfDomains = ( !dflts._shape || dflts._shape->IsNull() );
1717 //================================================================================
1719 * \brief Return command to run hybrid mesher excluding file prefix (-f)
1721 //================================================================================
1723 std::string HYBRIDPlugin_Hypothesis::CommandToRun(const HYBRIDPlugin_Hypothesis* hyp,
1724 const bool hasShapeToMesh)
1726 TCollection_AsciiString cmd = GetExeName().c_str();
1727 // check if any option is overridden by hyp->myTextOption
1728 bool p_h = ( hyp->myTextOption.find("-h") != std::string::npos );
1729 bool p_v = ( hyp->myTextOption.find("-v ") != std::string::npos );
1730 //bool p_i = ( hyp->myTextOption.find("-i") != std::string::npos );
1731 //bool p_o = ( hyp->myTextOption.find("-o") != std::string::npos );
1732 bool p_mnot = ( hyp->myTextOption.find("--max_number_of_threads ") != std::string::npos );
1733 bool p_blsi = ( hyp->myTextOption.find("--boundary_layers_surface_ids ") != std::string::npos );
1734 bool p_blii = ( hyp->myTextOption.find("--boundary_layers_imprint_ids ") != std::string::npos );
1735 bool p_blsd = ( hyp->myTextOption.find("--boundary_layers_subdomain_direction ") != std::string::npos );
1736 bool p_hotfl = ( hyp->myTextOption.find("--height_of_the_first_layer ") != std::string::npos );
1737 bool p_nobl = ( hyp->myTextOption.find("--number_of_boundary_layers ") != std::string::npos );
1738 bool p_blgp = ( hyp->myTextOption.find("--boundary_layers_geometric_progression ") != std::string::npos );
1739 bool p_eg = ( hyp->myTextOption.find("--element_generation ") != std::string::npos );
1740 bool p_cm = ( hyp->myTextOption.find("--collision_mode ") != std::string::npos );
1741 bool p_am = ( hyp->myTextOption.find("--add_multinormals ") != std::string::npos );
1742 bool p_mat = ( hyp->myTextOption.find("--multinormals_angle_threshold ") != std::string::npos );
1743 bool p_sn = ( hyp->myTextOption.find("--smooth_normals ") != std::string::npos );
1745 bool nolayers = false;
1753 std::cout << "!!!!! CommandToRun help only !!!! " << cmd.ToCString() << std::endl;
1754 return cmd.ToCString();
1757 if ( !p_v && hyp ) {
1758 cmd += " --verbose ";
1759 cmd += hyp->myVerboseLevel;
1762 if ( !p_mnot && hyp ) {
1763 cmd += " --max_number_of_threads ";
1764 cmd += 8; //TODO getenv NB CPU
1767 //if ( !p_blsi && hyp ) {
1768 // cmd += " --boundary_layers_surface_ids ";
1769 // cmd += 0; //TODO hyp->my;
1772 //if ( !p_blii && hyp ) {
1773 // cmd += " --boundary_layers_imprint_ids ";
1774 // cmd += 0; //TODO hyp->my;
1778 if ( !p_nobl && hyp ) {
1779 if ( hyp->myNbOfBoundaryLayers < 1 ) nolayers = true;
1781 if ( !p_hotfl && hyp ) {
1782 if ( hyp->myHeightFirstLayer < 1e-50 ) nolayers = true;
1785 if ( !p_blsd && hyp ) {
1786 if ( hyp->myBoundaryLayersGrowth >= 0 && hyp->myBoundaryLayersGrowth <= 1 ) {
1787 const char* value[] = { "1" , "-1" };
1788 cmd += " --boundary_layers_subdomain_direction ";
1789 cmd += value[ hyp->myBoundaryLayersGrowth ];
1793 if ( !p_hotfl && hyp ) {
1794 cmd += " --height_of_the_first_layer ";
1795 cmd += hyp->myHeightFirstLayer;
1798 if ( !p_nobl && hyp ) {
1799 cmd += " --number_of_boundary_layers ";
1803 cmd += hyp->myNbOfBoundaryLayers;
1806 if ( !p_blgp && hyp ) {
1807 cmd += " --boundary_layers_geometric_progression ";
1808 cmd += hyp->myBoundaryLayersProgression;
1811 //--boundary_layers_surface_ids 5 #for all wrap shell
1812 //--boundary_layers_surface_ids 6 #for all enfMeshList
1813 //TODO if ( !nolayers ) cmd += " --boundary_layers_surface_ids 5,6 "; //as all wrap shell and triangles of enforced mesh
1814 if ( !nolayers ) cmd += " --boundary_layers_surface_ids 6 "; //as triangles of enforced mesh
1816 if ( !p_eg && hyp ) {
1817 if ( hyp->myElementGeneration >= 0 && hyp->myElementGeneration <= 1 ) {
1818 const char* value[] = { "tetra-dominant" , "hexa-dominant" };
1819 cmd += " --element_generation ";
1820 cmd += value[ hyp->myElementGeneration ];
1824 if ( !p_cm && hyp ) {
1825 if ( hyp->myCollisionMode >= 0 && hyp->myCollisionMode <= 1 ) {
1826 const char* value[] = { "decrease" , "stop" };
1827 cmd += " --collision_mode ";
1828 cmd += value[ hyp->myCollisionMode ];
1832 if ( !p_am && hyp ) {
1833 int res = hyp->myAddMultinormals ? 0 : 1 ;
1834 const char* value[] = { "yes" , "no" };
1835 cmd += " --add_multinormals ";
1836 cmd += value[ res ];
1839 if ( !p_mat && hyp ) {
1840 cmd += " --multinormals_angle_threshold ";
1841 cmd += hyp->myMultinormalsAngle;
1844 if ( !p_sn && hyp ) {
1845 int res = hyp->mySmoothNormals ? 0 : 1 ;
1846 const char* value[] = { "yes" , "no" };
1847 cmd += " --smooth_normals ";
1848 cmd += value[ res ];
1854 //std::cout << "!!!!!CommandToRun end " << cmd.ToCString() << std::endl;
1856 return cmd.ToCString();
1859 //================================================================================
1861 * \brief Return a unique file name
1863 //================================================================================
1865 std::string HYBRIDPlugin_Hypothesis::GetFileName(const HYBRIDPlugin_Hypothesis* hyp)
1867 std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
1868 const char lastChar = *aTmpDir.rbegin();
1870 if(lastChar != '\\') aTmpDir+='\\';
1872 if(lastChar != '/') aTmpDir+='/';
1875 TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
1876 aGenericName += "HYBRID_";
1877 aGenericName += getpid();
1878 aGenericName += "_";
1879 aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
1881 return aGenericName.ToCString();
1884 //================================================================================
1886 * Return the name of executable
1888 //================================================================================
1890 std::string HYBRIDPlugin_Hypothesis::GetExeName()
1892 //call mg-hybrid.bash is script which assumes new project version(s) mg-hybrid.exe_Linux_64_avril2014 and special? licence.
1893 return "mg-hybrid.bash";
1896 //================================================================================
1898 * \brief Return the enforced vertices
1900 //================================================================================
1902 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexList HYBRIDPlugin_Hypothesis::GetEnforcedVertices(const HYBRIDPlugin_Hypothesis* hyp)
1904 return hyp ? hyp->_GetEnforcedVertices():DefaultHYBRIDEnforcedVertexList();
1907 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexCoordsValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesCoordsSize (const HYBRIDPlugin_Hypothesis* hyp)
1909 return hyp ? hyp->_GetEnforcedVerticesCoordsSize(): DefaultHYBRIDEnforcedVertexCoordsValues();
1912 HYBRIDPlugin_Hypothesis::THYBRIDEnforcedVertexEntryValues HYBRIDPlugin_Hypothesis::GetEnforcedVerticesEntrySize (const HYBRIDPlugin_Hypothesis* hyp)
1914 return hyp ? hyp->_GetEnforcedVerticesEntrySize(): DefaultHYBRIDEnforcedVertexEntryValues();
1917 HYBRIDPlugin_Hypothesis::TCoordsHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByCoords (const HYBRIDPlugin_Hypothesis* hyp)
1919 return hyp ? hyp->_GetEnforcedVerticesByCoords(): DefaultCoordsHYBRIDEnforcedVertexMap();
1922 HYBRIDPlugin_Hypothesis::TGeomEntryHYBRIDEnforcedVertexMap HYBRIDPlugin_Hypothesis::GetEnforcedVerticesByEntry (const HYBRIDPlugin_Hypothesis* hyp)
1924 return hyp ? hyp->_GetEnforcedVerticesByEntry(): DefaultGeomEntryHYBRIDEnforcedVertexMap();
1927 HYBRIDPlugin_Hypothesis::TIDSortedNodeGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedNodes(const HYBRIDPlugin_Hypothesis* hyp)
1929 return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeGroupMap();
1932 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedEdges(const HYBRIDPlugin_Hypothesis* hyp)
1934 return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemGroupMap();
1937 HYBRIDPlugin_Hypothesis::TIDSortedElemGroupMap HYBRIDPlugin_Hypothesis::GetEnforcedTriangles(const HYBRIDPlugin_Hypothesis* hyp)
1939 return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemGroupMap();
1942 HYBRIDPlugin_Hypothesis::TID2SizeMap HYBRIDPlugin_Hypothesis::GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp)
1944 return hyp ? hyp->_GetNodeIDToSizeMap(): DefaultID2SizeMap();
1947 HYBRIDPlugin_Hypothesis::TSetStrings HYBRIDPlugin_Hypothesis::GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp)
1949 return hyp ? hyp->_GetGroupsToRemove(): DefaultGroupsToRemove();