1 // Copyright (C) 2004-2020 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 : GHS3DPlugin_Hypothesis.cxx
22 // Created : Wed Apr 2 12:36:29 2008
23 // Author : Edward AGAPOV (eap)
24 //=============================================================================
26 #include "GHS3DPlugin_Hypothesis.hxx"
28 #include <SMESHDS_Mesh.hxx>
30 #include <TCollection_AsciiString.hxx>
34 #define getpid _getpid
41 struct GET_DEFAULT // struct used to get default value from GetOptionValue()
44 operator bool* () { return &isDefault; }
48 //=======================================================================
49 //function : GHS3DPlugin_Hypothesis
50 //=======================================================================
52 GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, SMESH_Gen * gen)
53 : SMESH_Hypothesis(hypId, gen),
54 myToMeshHoles(DefaultMeshHoles()),
55 myToMakeGroupsOfDomains(DefaultToMakeGroupsOfDomains()),
58 myOptimizationLevel(DefaultOptimizationLevel()),
59 myKeepFiles(DefaultKeepFiles()),
60 myWorkingDirectory(DefaultWorkingDirectory()),
61 myVerboseLevel(DefaultVerboseLevel()),
62 myToCreateNewNodes(DefaultToCreateNewNodes()),
63 myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()),
64 myToUseFemCorrection(DefaultToUseFEMCorrection()),
65 myToRemoveCentralPoint(DefaultToRemoveCentralPoint()),
66 myLogInStandardOutput(DefaultStandardOutputLog()),
67 myRemoveLogOnSuccess( DefaultRemoveLogOnSuccess() ),
68 myGradation(DefaultGradation()),
69 myUseVolumeProximity(DefaultUseVolumeProximity()),
70 myNbVolumeProximityLayers(DefaultNbVolumeProximityLayers()),
79 const char* boolOptionNames[] = { "no_initial_central_point", // no
80 "force_max_size", // no
81 "apply_gradation_on_skin_vertex_sizes", // yes
82 "optimise_worst_elements", // no
83 "force_output_quadratic_mesh", // no
84 "rectify_jacobian", // yes
85 "jacobian_rectification_respect_input_surface_mesh", // yes
88 const char* intOptionNames[] = { "max_number_of_errors_printed", // 1
89 "max_number_of_threads", // 4
92 const char* doubleOptionNames[] = { "target_quality", // 0
96 const char* charOptionNames[] = { "pthreads_mode", // ""
97 "boundary_regeneration", // standard
98 "split_overconstrained_tetrahedra", // no
103 while (boolOptionNames[i][0])
105 _boolOptions.insert( boolOptionNames[i] );
106 _option2value[boolOptionNames[i++]].clear();
109 while (intOptionNames[i][0])
110 _option2value[intOptionNames[i++]].clear();
113 while (doubleOptionNames[i][0]) {
114 _doubleOptions.insert(doubleOptionNames[i]);
115 _option2value[doubleOptionNames[i++]].clear();
118 while (charOptionNames[i][0]) {
119 _charOptions.insert(charOptionNames[i]);
120 _option2value[charOptionNames[i++]].clear();
123 // default values to be used while MG meshing
125 _defaultOptionValues["no_initial_central_point" ] = "no";
126 _defaultOptionValues["force_max_size" ] = "no";
127 _defaultOptionValues["apply_gradation_on_skin_vertex_sizes" ] = "yes";
128 _defaultOptionValues["optimise_worst_elements" ] = "no";
129 _defaultOptionValues["force_output_quadratic_mesh" ] = "no";
130 _defaultOptionValues["rectify_jacobian" ] = "yes";
131 _defaultOptionValues["jacobian_rectification_respect_input_surface_mesh"] = "yes";
132 _defaultOptionValues["max_number_of_errors_printed" ] = "1";
133 _defaultOptionValues["max_number_of_threads" ] = "4";
134 _defaultOptionValues["target_quality" ] = "";//NoValue();
135 _defaultOptionValues["sliver_angle" ] = "5";
136 _defaultOptionValues["pthreads_mode" ] = "";//NoValue();
137 _defaultOptionValues["boundary_regeneration" ] = "standard";
138 _defaultOptionValues["split_overconstrained_tetrahedra" ] = "no";
141 // check validity of option names of _defaultOptionValues
142 TOptionValues::iterator n2v = _defaultOptionValues.begin();
143 for ( ; n2v != _defaultOptionValues.end(); ++n2v )
144 ASSERT( _option2value.count( n2v->first ));
145 ASSERT( _option2value.size() == _defaultOptionValues.size() );
149 //=======================================================================
150 //function : SetToMeshHoles
151 //=======================================================================
153 void GHS3DPlugin_Hypothesis::SetToMeshHoles(bool toMesh)
155 if ( myToMeshHoles != toMesh ) {
156 myToMeshHoles = toMesh;
157 NotifySubMeshesHypothesisModification();
161 //=======================================================================
162 //function : GetToMeshHoles
163 //=======================================================================
165 bool GHS3DPlugin_Hypothesis::GetToMeshHoles(bool checkFreeOption) const
167 if ( checkFreeOption )
169 std::string optionName = "components";
170 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
171 if ( op_val != _customOption2value.end())
173 if ( op_val->second.find("all"))
175 if ( op_val->second.find("outside_components"))
179 return myToMeshHoles;
182 //=======================================================================
183 //function : SetToMakeGroupsOfDomains
184 //=======================================================================
186 void GHS3DPlugin_Hypothesis::SetToMakeGroupsOfDomains(bool toMakeGroups)
188 if ( myToMakeGroupsOfDomains != toMakeGroups ) {
189 myToMakeGroupsOfDomains = toMakeGroups;
190 NotifySubMeshesHypothesisModification();
194 //=======================================================================
195 //function : GetToMakeGroupsOfDomains
196 //=======================================================================
198 bool GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains() const
200 return myToMakeGroupsOfDomains;
203 //=======================================================================
204 //function : GetToMakeGroupsOfDomains
205 //=======================================================================
207 bool GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains(const GHS3DPlugin_Hypothesis* hyp)
210 if ( hyp ) res = /*hyp->GetToMeshHoles(true) &&*/ hyp->GetToMakeGroupsOfDomains();
211 else res = /*DefaultMeshHoles() &&*/ DefaultToMakeGroupsOfDomains();
215 //=======================================================================
216 //function : SetMaximumMemory
217 //=======================================================================
219 void GHS3DPlugin_Hypothesis::SetMaximumMemory(float MB)
221 if ( myMaximumMemory != MB ) {
222 myMaximumMemory = MB;
223 NotifySubMeshesHypothesisModification();
227 //=======================================================================
228 //function : GetMaximumMemory
229 // * automatic memory adjustment mode. Default is zero
230 //=======================================================================
232 float GHS3DPlugin_Hypothesis::GetMaximumMemory() const
234 return myMaximumMemory;
237 //=======================================================================
238 //function : SetInitialMemory
239 //=======================================================================
241 void GHS3DPlugin_Hypothesis::SetInitialMemory(float MB)
243 if ( myInitialMemory != MB ) {
244 myInitialMemory = MB;
245 NotifySubMeshesHypothesisModification();
249 //=======================================================================
250 //function : GetInitialMemory
251 //=======================================================================
253 float GHS3DPlugin_Hypothesis::GetInitialMemory() const
255 return myInitialMemory;
258 //=======================================================================
259 //function : SetOptimizationLevel
260 //=======================================================================
262 void GHS3DPlugin_Hypothesis::SetOptimizationLevel(OptimizationLevel level)
264 if ( myOptimizationLevel != level ) {
265 myOptimizationLevel = level;
266 NotifySubMeshesHypothesisModification();
270 //=======================================================================
271 //function : GetOptimizationLevel
272 //=======================================================================
274 GHS3DPlugin_Hypothesis::OptimizationLevel GHS3DPlugin_Hypothesis::GetOptimizationLevel() const
276 return (OptimizationLevel) myOptimizationLevel;
279 //=======================================================================
280 //function : SetWorkingDirectory
281 //=======================================================================
283 void GHS3DPlugin_Hypothesis::SetWorkingDirectory(const std::string& path)
285 if ( myWorkingDirectory != path ) {
286 myWorkingDirectory = path;
287 NotifySubMeshesHypothesisModification();
291 //=======================================================================
292 //function : GetWorkingDirectory
293 //=======================================================================
295 std::string GHS3DPlugin_Hypothesis::GetWorkingDirectory() const
297 return myWorkingDirectory;
300 //=======================================================================
301 //function : SetKeepFiles
302 //=======================================================================
304 void GHS3DPlugin_Hypothesis::SetKeepFiles(bool toKeep)
306 if ( myKeepFiles != toKeep ) {
307 myKeepFiles = toKeep;
308 NotifySubMeshesHypothesisModification();
312 //=======================================================================
313 //function : GetKeepFiles
314 //=======================================================================
316 bool GHS3DPlugin_Hypothesis::GetKeepFiles() const
321 //=======================================================================
322 //function : SetVerboseLevel
323 //=======================================================================
325 void GHS3DPlugin_Hypothesis::SetVerboseLevel(short level)
327 if ( myVerboseLevel != level ) {
328 myVerboseLevel = level;
329 NotifySubMeshesHypothesisModification();
333 //=======================================================================
334 //function : GetVerboseLevel
335 //=======================================================================
337 short GHS3DPlugin_Hypothesis::GetVerboseLevel() const
339 return myVerboseLevel;
342 //=======================================================================
343 //function : SetToCreateNewNodes
344 //=======================================================================
346 void GHS3DPlugin_Hypothesis::SetToCreateNewNodes(bool toCreate)
348 if ( myToCreateNewNodes != toCreate ) {
349 myToCreateNewNodes = toCreate;
350 NotifySubMeshesHypothesisModification();
354 //=======================================================================
355 //function : GetToCreateNewNodes
356 //=======================================================================
358 bool GHS3DPlugin_Hypothesis::GetToCreateNewNodes() const
360 return myToCreateNewNodes;
363 //=======================================================================
364 //function : SetToUseBoundaryRecoveryVersion
365 //=======================================================================
367 void GHS3DPlugin_Hypothesis::SetToUseBoundaryRecoveryVersion(bool toUse)
369 if ( myToUseBoundaryRecoveryVersion != toUse ) {
370 myToUseBoundaryRecoveryVersion = toUse;
371 NotifySubMeshesHypothesisModification();
375 //=======================================================================
376 //function : GetToUseBoundaryRecoveryVersion
377 //=======================================================================
379 bool GHS3DPlugin_Hypothesis::GetToUseBoundaryRecoveryVersion() const
381 return myToUseBoundaryRecoveryVersion;
384 //=======================================================================
385 //function : SetFEMCorrection
386 //=======================================================================
388 void GHS3DPlugin_Hypothesis::SetFEMCorrection(bool toUseFem)
390 if ( myToUseFemCorrection != toUseFem ) {
391 myToUseFemCorrection = toUseFem;
392 NotifySubMeshesHypothesisModification();
396 //=======================================================================
397 //function : GetFEMCorrection
398 //=======================================================================
400 bool GHS3DPlugin_Hypothesis::GetFEMCorrection() const
402 return myToUseFemCorrection;
405 //=======================================================================
406 //function : SetToRemoveCentralPoint
407 //=======================================================================
409 void GHS3DPlugin_Hypothesis::SetToRemoveCentralPoint(bool toRemove)
411 SetOptionValue( "no_initial_central_point", toRemove ? "yes" : "no" );
412 myToRemoveCentralPoint = toRemove;
415 //=======================================================================
416 //function : GetToRemoveCentralPoint
417 //=======================================================================
419 bool GHS3DPlugin_Hypothesis::GetToRemoveCentralPoint() const
421 return myToRemoveCentralPoint;
424 //=======================================================================
425 //function : SetAdvancedOption
426 //=======================================================================
428 void GHS3DPlugin_Hypothesis::SetAdvancedOption(const std::string& option)
430 size_t wsPos = option.find(' ');
431 if ( wsPos == string::npos )
433 SetOptionValue( option, "" );
437 std::string opt( option, 0, wsPos );
438 std::string val( option, wsPos + 1 );
439 SetOptionValue( opt, val );
443 //=======================================================================
444 //function : GetAdvancedOption
445 //=======================================================================
447 std::string GHS3DPlugin_Hypothesis::GetAdvancedOption() const
451 TOptionValues::const_iterator o2v = _option2value.begin();
452 for ( ; o2v != _option2value.end(); ++o2v )
453 if ( !o2v->second.empty() )
457 txt << o2v->first << " " << o2v->second;
459 for ( o2v = _customOption2value.begin(); o2v != _customOption2value.end(); ++o2v )
463 txt << o2v->first << " " << o2v->second;
468 //=======================================================================
469 //function : SetGradation
470 //=======================================================================
472 void GHS3DPlugin_Hypothesis::SetGradation(double gradation)
474 if ( myGradation != gradation ) {
475 myGradation = gradation;
476 NotifySubMeshesHypothesisModification();
480 //=======================================================================
481 //function : GetGradation
482 //=======================================================================
484 double GHS3DPlugin_Hypothesis::GetGradation() const
489 //=============================================================================
490 void GHS3DPlugin_Hypothesis::SetMinSize(double theMinSize)
492 if ( theMinSize != myMinSize )
494 myMinSize = theMinSize;
495 NotifySubMeshesHypothesisModification();
499 //=============================================================================
500 void GHS3DPlugin_Hypothesis::SetMaxSize(double theMaxSize)
502 if ( theMaxSize != myMaxSize )
504 myMaxSize = theMaxSize;
505 NotifySubMeshesHypothesisModification();
509 //=============================================================================
510 void GHS3DPlugin_Hypothesis::SetUseVolumeProximity( bool toUse )
512 if ( myUseVolumeProximity != toUse )
514 myUseVolumeProximity = toUse;
515 NotifySubMeshesHypothesisModification();
519 //=============================================================================
520 void GHS3DPlugin_Hypothesis::SetNbVolumeProximityLayers( int nbLayers )
522 if ( myNbVolumeProximityLayers != nbLayers )
524 myNbVolumeProximityLayers = nbLayers;
525 NotifySubMeshesHypothesisModification();
529 //=======================================================================
530 //function : SetStandardOutputLog
531 //=======================================================================
533 void GHS3DPlugin_Hypothesis::SetStandardOutputLog(bool logInStandardOutput)
535 if ( myLogInStandardOutput != logInStandardOutput ) {
536 myLogInStandardOutput = logInStandardOutput;
537 NotifySubMeshesHypothesisModification();
541 //=======================================================================
542 //function : GetStandardOutputLog
543 //=======================================================================
545 bool GHS3DPlugin_Hypothesis::GetStandardOutputLog() const
547 return myLogInStandardOutput;
550 //=======================================================================
551 //function : SetRemoveLogOnSuccess
552 //=======================================================================
554 void GHS3DPlugin_Hypothesis::SetRemoveLogOnSuccess(bool removeLogOnSuccess)
556 if ( myRemoveLogOnSuccess != removeLogOnSuccess ) {
557 myRemoveLogOnSuccess = removeLogOnSuccess;
558 NotifySubMeshesHypothesisModification();
562 //=======================================================================
563 //function : GetRemoveLogOnSuccess
564 //=======================================================================
566 bool GHS3DPlugin_Hypothesis::GetRemoveLogOnSuccess() const
568 return myRemoveLogOnSuccess;
571 //=======================================================================
572 //function : SetEnforcedVertex
573 //=======================================================================
575 bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName,
576 std::string theEntry,
577 std::string theGroupName,
579 double x, double y, double z,
582 MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedVertex(\""<< theName << "\", \""<< theEntry << "\", \"" << theGroupName << "\", "
583 << size << ", " << x << ", " << y << ", " << z << ", "<< isCompound << ")");
585 bool toNotify = false;
586 bool toCreate = true;
588 TGHS3DEnforcedVertex *oldEnVertex;
589 TGHS3DEnforcedVertex *newEnfVertex = new TGHS3DEnforcedVertex();
590 newEnfVertex->name = theName;
591 newEnfVertex->geomEntry = theEntry;
592 newEnfVertex->coords.clear();
594 newEnfVertex->coords.push_back(x);
595 newEnfVertex->coords.push_back(y);
596 newEnfVertex->coords.push_back(z);
598 newEnfVertex->groupName = theGroupName;
599 newEnfVertex->size = size;
600 newEnfVertex->isCompound = isCompound;
603 // update _enfVertexList
604 TGHS3DEnforcedVertexList::iterator it = _enfVertexList.find(newEnfVertex);
605 if (it != _enfVertexList.end()) {
608 MESSAGE("Enforced Vertex was found => Update");
609 if (oldEnVertex->name != theName) {
610 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theName << "\"");
611 oldEnVertex->name = theName;
614 if (oldEnVertex->groupName != theGroupName) {
615 MESSAGE("Update group name from \"" << oldEnVertex->groupName << "\" to \"" << theGroupName << "\"");
616 oldEnVertex->groupName = theGroupName;
619 if (oldEnVertex->size != size) {
620 MESSAGE("Update size from \"" << oldEnVertex->size << "\" to \"" << size << "\"");
621 oldEnVertex->size = size;
625 // update map coords / enf vertex if needed
626 if (oldEnVertex->coords.size()) {
627 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
628 _enfVertexCoordsSizeList[oldEnVertex->coords] = size;
631 // update map geom entry / enf vertex if needed
632 if (oldEnVertex->geomEntry != "") {
633 _geomEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
634 _enfVertexEntrySizeList[oldEnVertex->geomEntry] = size;
639 // //////// CREATE ////////////
642 MESSAGE("Creating new enforced vertex");
643 _enfVertexList.insert(newEnfVertex);
644 if (theEntry == "") {
645 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
646 _enfVertexCoordsSizeList[newEnfVertex->coords] = size;
649 _geomEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
650 _enfVertexEntrySizeList[newEnfVertex->geomEntry] = size;
655 NotifySubMeshesHypothesisModification();
657 MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedVertex END");
662 //=======================================================================
663 //function : SetEnforcedMesh
664 //=======================================================================
665 bool GHS3DPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName)
667 TIDSortedElemSet theElemSet;
668 SMDS_ElemIteratorPtr eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType));
669 while ( eIt->more() )
670 theElemSet.insert( eIt->next() );
671 MESSAGE("Add "<<theElemSet.size()<<" types["<<elementType<<"] from source mesh");
672 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
674 TGHS3DEnforcedMesh* newEnfMesh = new TGHS3DEnforcedMesh();
675 newEnfMesh->persistID = theMesh.GetMeshDS()->GetPersistentId();
676 newEnfMesh->name = name;
677 newEnfMesh->entry = entry;
678 newEnfMesh->elementType = elementType;
679 newEnfMesh->groupName = groupName;
681 TGHS3DEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
682 if (it == _enfMeshList.end()) {
683 _entryEnfMeshMap[entry].insert(newEnfMesh);
684 _enfMeshList.insert(newEnfMesh);
693 //=======================================================================
694 //function : SetEnforcedGroup
695 //=======================================================================
696 bool GHS3DPlugin_Hypothesis::SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName)
698 MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedGroup");
699 TIDSortedElemSet theElemSet;
700 if ( theIDs->length() == 0 ){MESSAGE("The source group is empty");}
701 for ( CORBA::ULong i=0; i < theIDs->length(); i++) {
702 CORBA::Long ind = theIDs[i];
703 if (elementType == SMESH::NODE)
705 const SMDS_MeshNode * node = theMeshDS->FindNode(ind);
707 theElemSet.insert( node );
711 const SMDS_MeshElement * elem = theMeshDS->FindElement(ind);
713 theElemSet.insert( elem );
717 // SMDS_ElemIteratorPtr it = theGroup->GetGroupDS()->GetElements();
718 // while ( it->more() )
719 // theElemSet.insert( it->next() );
721 MESSAGE("Add "<<theElemSet.size()<<" types["<<elementType<<"] from source group ");
722 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
724 TGHS3DEnforcedMesh* newEnfMesh = new TGHS3DEnforcedMesh();
725 newEnfMesh->name = name;
726 newEnfMesh->entry = entry;
727 newEnfMesh->elementType = elementType;
728 newEnfMesh->groupName = groupName;
730 TGHS3DEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
731 if (it == _enfMeshList.end()) {
732 _entryEnfMeshMap[entry].insert(newEnfMesh);
733 _enfMeshList.insert(newEnfMesh);
739 //=======================================================================
740 //function : SetEnforcedElements
741 //=======================================================================
742 bool GHS3DPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName)
744 MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedElements");
745 TIDSortedElemSet::const_iterator it = theElemSet.begin();
746 const SMDS_MeshElement* elem;
747 const SMDS_MeshNode* node;
749 pair<TIDSortedNodeGroupMap::iterator,bool> nodeRet;
750 pair<TIDSortedElemGroupMap::iterator,bool> elemRet;
752 for (;it != theElemSet.end();++it)
755 switch (elementType) {
757 node = dynamic_cast<const SMDS_MeshNode*>(elem);
759 nodeRet = _enfNodes.insert(make_pair(node,groupName));
760 added = added && nodeRet.second;
761 string msg = added ? "yes":"no";
762 MESSAGE( "Node (" <<node->X()<<","<<node->Y()<<","<<node->Z()<< ") with ID " << node->GetID() <<" added ? " << msg);
765 SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
766 for (;nodeIt->more();) {
767 node = dynamic_cast<const SMDS_MeshNode*>(nodeIt->next());
768 nodeRet = _enfNodes.insert(make_pair(node,groupName));
769 added = added && nodeRet.second;
774 if (elem->GetType() == SMDSAbs_Edge) {
775 elemRet = _enfEdges.insert(make_pair(elem,groupName));
776 added = added && elemRet.second;
778 else if (elem->GetType() > SMDSAbs_Edge) {
779 // SMDS_ElemIteratorPtr it = elem->edgesIterator();
780 // for (;it->more();) {
781 // const SMDS_MeshElement* anEdge = it->next();
782 // elemRet = _enfEdges.insert(make_pair(anEdge,groupName));
783 // added = added && elemRet.second;
788 if (elem->GetType() == SMDSAbs_Face)
790 if (elem->NbCornerNodes() == 3) {
791 elemRet = _enfTriangles.insert(make_pair(elem,groupName));
792 added = added && elemRet.second;
795 else if (elem->GetType() > SMDSAbs_Face) { // Group of faces
796 // SMDS_ElemIteratorPtr it = elem->facesIterator();
797 // for (;it->more();) {
798 // const SMDS_MeshElement* aFace = it->next();
799 // if (aFace->NbCornerNodes() == 3) {
800 // elemRet = _enfTriangles.insert(make_pair(aFace,groupName));
801 // added = added && elemRet.second;
811 NotifySubMeshesHypothesisModification();
816 //=======================================================================
817 //function : GetEnforcedVertex
818 //=======================================================================
820 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* GHS3DPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z)
821 throw (std::invalid_argument)
823 std::vector<double> coord(3);
827 if (_coordsEnfVertexMap.count(coord)>0)
828 return _coordsEnfVertexMap[coord];
829 std::ostringstream msg ;
830 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
831 throw std::invalid_argument(msg.str());
834 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* GHS3DPlugin_Hypothesis::GetEnforcedVertex(const std::string theEntry)
835 throw (std::invalid_argument)
837 if (_geomEntryEnfVertexMap.count(theEntry)>0)
838 return _geomEntryEnfVertexMap[theEntry];
840 std::ostringstream msg ;
841 msg << "No enforced vertex with entry " << theEntry;
842 throw std::invalid_argument(msg.str());
845 //=======================================================================
846 //function : RemoveEnforcedVertex
847 //=======================================================================
849 bool GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, const std::string theEntry)
850 throw (std::invalid_argument)
852 bool toNotify = false;
853 std::ostringstream msg;
854 TGHS3DEnforcedVertex *oldEnfVertex;
855 std::vector<double> coords(3);
860 // check that enf vertex with given enf vertex entry exists
861 TGeomEntryGHS3DEnforcedVertexMap::iterator it_enfVertexEntry = _geomEntryEnfVertexMap.find(theEntry);
862 if (it_enfVertexEntry != _geomEntryEnfVertexMap.end()) {
864 MESSAGE("Found enforced vertex with geom entry " << theEntry);
865 oldEnfVertex = it_enfVertexEntry->second;
866 _geomEntryEnfVertexMap.erase(it_enfVertexEntry);
869 MESSAGE("Enforced vertex with geom entry " << theEntry << " not found");
870 // check that enf vertex with given coords exists
871 TCoordsGHS3DEnforcedVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
872 if (it_coords_enf != _coordsEnfVertexMap.end()) {
874 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
875 oldEnfVertex = it_coords_enf->second;
876 _coordsEnfVertexMap.erase(it_coords_enf);
877 _enfVertexCoordsSizeList.erase(_enfVertexCoordsSizeList.find(coords));
880 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
881 throw std::invalid_argument(msg.str());
885 MESSAGE("Remove enf vertex from _enfVertexList");
887 // update _enfVertexList
888 TGHS3DEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
889 if (it != _enfVertexList.end()) {
890 if ((*it)->groupName != "")
891 _groupsToRemove.insert((*it)->groupName);
892 _enfVertexList.erase(it);
898 NotifySubMeshesHypothesisModification();
903 //=======================================================================
904 //function : ClearEnforcedVertices
905 //=======================================================================
906 void GHS3DPlugin_Hypothesis::ClearEnforcedVertices()
908 TGHS3DEnforcedVertexList::const_iterator it = _enfVertexList.begin();
909 for(;it != _enfVertexList.end();++it) {
910 if ((*it)->groupName != "")
911 _groupsToRemove.insert((*it)->groupName);
913 _enfVertexList.clear();
914 _coordsEnfVertexMap.clear();
915 _geomEntryEnfVertexMap.clear();
916 _enfVertexCoordsSizeList.clear();
917 _enfVertexEntrySizeList.clear();
918 NotifySubMeshesHypothesisModification();
921 //=======================================================================
922 //function : ClearEnforcedMeshes
923 //=======================================================================
924 void GHS3DPlugin_Hypothesis::ClearEnforcedMeshes()
926 TGHS3DEnforcedMeshList::const_iterator it = _enfMeshList.begin();
927 for(;it != _enfMeshList.end();++it) {
928 if ((*it)->groupName != "")
929 _groupsToRemove.insert((*it)->groupName);
933 _enfTriangles.clear();
934 _nodeIDToSizeMap.clear();
935 _enfMeshList.clear();
936 _entryEnfMeshMap.clear();
937 NotifySubMeshesHypothesisModification();
940 //================================================================================
942 * \brief At mesh loading, restore enforced elements by just loaded enforced meshes
944 //================================================================================
946 void GHS3DPlugin_Hypothesis::RestoreEnfElemsByMeshes()
948 TGHS3DEnforcedMeshList::const_iterator it = _enfMeshList.begin();
949 for(;it != _enfMeshList.end();++it) {
950 TGHS3DEnforcedMesh* enfMesh = *it;
951 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
952 SetEnforcedMesh( *mesh,
953 enfMesh->elementType,
956 enfMesh->groupName );
957 enfMesh->persistID = -1; // not to restore again
961 //=======================================================================
962 //function : SetGroupsToRemove
963 //=======================================================================
965 void GHS3DPlugin_Hypothesis::ClearGroupsToRemove()
967 _groupsToRemove.clear();
971 //=======================================================================
972 //function : DefaultMeshHoles
973 //=======================================================================
975 bool GHS3DPlugin_Hypothesis::DefaultMeshHoles()
977 return false; // PAL19680
980 //=======================================================================
981 //function : DefaultToMakeGroupsOfDomains
982 //=======================================================================
984 bool GHS3DPlugin_Hypothesis::DefaultToMakeGroupsOfDomains()
986 return false; // issue 0022172
989 //=======================================================================
990 //function : DefaultMaximumMemory
991 //=======================================================================
995 #elif !defined(__APPLE__)
996 #include <sys/sysinfo.h>
999 float GHS3DPlugin_Hypothesis::DefaultMaximumMemory()
1002 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
1003 MEMORYSTATUSEX statex;
1004 statex.dwLength = sizeof (statex);
1005 long err = GlobalMemoryStatusEx (&statex);
1007 double totMB = (double)statex.ullAvailPhys / 1024. / 1024.;
1008 return (float)( 0.7 * totMB );
1010 #elif !defined(__APPLE__)
1012 long err = sysinfo( &si );
1014 long ramMB = si.totalram * si.mem_unit / 1024 / 1024;
1015 return ( 0.7 * ramMB );
1021 //=======================================================================
1022 //function : DefaultInitialMemory
1023 //=======================================================================
1025 float GHS3DPlugin_Hypothesis::DefaultInitialMemory()
1027 return DefaultMaximumMemory();
1030 //=======================================================================
1031 //function : DefaultOptimizationLevel
1032 //=======================================================================
1034 short GHS3DPlugin_Hypothesis::DefaultOptimizationLevel()
1039 //=======================================================================
1040 //function : DefaultWorkingDirectory
1041 //=======================================================================
1043 std::string GHS3DPlugin_Hypothesis::DefaultWorkingDirectory()
1045 TCollection_AsciiString aTmpDir;
1047 char *Tmp_dir = getenv("SALOME_TMP_DIR");
1048 if(Tmp_dir != NULL) {
1053 aTmpDir = TCollection_AsciiString("C:\\");
1055 aTmpDir = TCollection_AsciiString("/tmp/");
1058 return aTmpDir.ToCString();
1061 //=======================================================================
1062 //function : DefaultKeepFiles
1063 //=======================================================================
1065 bool GHS3DPlugin_Hypothesis::DefaultKeepFiles()
1070 //=======================================================================
1071 //function : DefaultRemoveLogOnSuccess
1072 //=======================================================================
1074 bool GHS3DPlugin_Hypothesis::DefaultRemoveLogOnSuccess()
1080 //=======================================================================
1081 //function : DefaultVerboseLevel
1082 //=======================================================================
1084 short GHS3DPlugin_Hypothesis::DefaultVerboseLevel()
1089 //=======================================================================
1090 //function : DefaultToCreateNewNodes
1091 //=======================================================================
1093 bool GHS3DPlugin_Hypothesis::DefaultToCreateNewNodes()
1098 //=======================================================================
1099 //function : DefaultToUseBoundaryRecoveryVersion
1100 //=======================================================================
1102 bool GHS3DPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
1107 //=======================================================================
1108 //function : DefaultToUseFEMCorrection
1109 //=======================================================================
1111 bool GHS3DPlugin_Hypothesis::DefaultToUseFEMCorrection()
1116 //=======================================================================
1117 //function : DefaultToRemoveCentralPoint
1118 //=======================================================================
1120 bool GHS3DPlugin_Hypothesis::DefaultToRemoveCentralPoint()
1125 //=======================================================================
1126 //function : DefaultStandardOutputLog
1127 //=======================================================================
1129 bool GHS3DPlugin_Hypothesis::DefaultStandardOutputLog()
1134 // //=======================================================================
1135 // //function : DefaultID2SizeMap
1136 // //=======================================================================
1138 // GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::DefaultID2SizeMap()
1140 // return GHS3DPlugin_Hypothesis::TID2SizeMap();
1144 //=======================================================================
1146 //=======================================================================
1148 std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save)
1150 save << (int) myToMeshHoles << " ";
1151 save << myMaximumMemory << " ";
1152 save << myInitialMemory << " ";
1153 save << myOptimizationLevel << " ";
1154 save << myWorkingDirectory << " ";
1155 save << (int)myKeepFiles << " ";
1156 save << myVerboseLevel << " ";
1157 save << (int)myToCreateNewNodes << " ";
1158 save << (int)myToUseBoundaryRecoveryVersion << " ";
1159 save << (int)myToUseFemCorrection << " ";
1160 save << (int)myToRemoveCentralPoint << " ";
1161 save << myGradation << " ";
1162 save << myToMakeGroupsOfDomains << " ";
1163 // if (!myTextOption.empty()) {
1164 // save << "__OPTIONS_BEGIN__ ";
1165 // save << myTextOption << " ";
1166 // save << "__OPTIONS_END__ ";
1170 TGHS3DEnforcedVertexList::iterator it = _enfVertexList.begin();
1171 if (it != _enfVertexList.end()) {
1172 save << " " << "__ENFORCED_VERTICES_BEGIN__ ";
1173 for ( ; it != _enfVertexList.end(); ++it ) {
1174 TGHS3DEnforcedVertex *enfVertex = (*it);
1175 save << " " << "__BEGIN_VERTEX__";
1176 if (!enfVertex->name.empty()) {
1177 save << " " << "__BEGIN_NAME__";
1178 save << " " << enfVertex->name;
1179 save << " " << "__END_NAME__";
1181 if (!enfVertex->geomEntry.empty()) {
1182 save << " " << "__BEGIN_ENTRY__";
1183 save << " " << enfVertex->geomEntry;
1184 save << " " << enfVertex->isCompound;
1185 save << " " << "__END_ENTRY__";
1187 if (!enfVertex->groupName.empty()) {
1188 save << " " << "__BEGIN_GROUP__";
1189 save << " " << enfVertex->groupName;
1190 save << " " << "__END_GROUP__";
1192 if (enfVertex->coords.size()) {
1193 save << " " << "__BEGIN_COORDS__";
1194 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1195 save << " " << enfVertex->coords[i];
1196 save << " " << "__END_COORDS__";
1198 save << " " << "__BEGIN_SIZE__";
1199 save << " " << enfVertex->size;
1200 save << " " << "__END_SIZE__";
1201 save << " " << "__END_VERTEX__";
1203 save << " " << "__ENFORCED_VERTICES_END__ ";
1206 TGHS3DEnforcedMeshList::iterator it_mesh = _enfMeshList.begin();
1207 if (it_mesh != _enfMeshList.end()) {
1208 save << " " << "__ENFORCED_MESHES_BEGIN__ ";
1209 for ( ; it_mesh != _enfMeshList.end(); ++it_mesh ) {
1210 TGHS3DEnforcedMesh *enfMesh = (*it_mesh);
1211 save << " " << "__BEGIN_ENF_MESH__";
1213 save << " " << "__BEGIN_NAME__";
1214 save << " " << enfMesh->name;
1215 save << " " << "__END_NAME__";
1217 save << " " << "__BEGIN_ENTRY__";
1218 save << " " << enfMesh->entry;
1219 save << " " << "__END_ENTRY__";
1221 save << " " << "__BEGIN_ELEM_TYPE__";
1222 save << " " << (int)enfMesh->elementType;
1223 save << " " << "__END_ELEM_TYPE__";
1225 if (!enfMesh->groupName.empty()) {
1226 save << " " << "__BEGIN_GROUP__";
1227 save << " " << enfMesh->groupName;
1228 save << " " << "__END_GROUP__";
1230 save << " " << "__PERSIST_ID__";
1231 save << " " << enfMesh->persistID;
1232 save << " " << "__END_ENF_MESH__";
1233 std::cout << "Saving of enforced mesh " << enfMesh->name.c_str() << " done" << std::endl;
1235 save << " " << "__ENFORCED_MESHES_END__ ";
1238 // New options in 2.9.6 (issue #17784)
1240 save << " " << myUseVolumeProximity;
1241 save << " " << myNbVolumeProximityLayers;
1242 save << " " << myMinSize;
1243 save << " " << myMaxSize;
1244 save << " " << myMinSizeDefault;
1245 save << " " << myMaxSizeDefault;
1247 save << " " << _option2value.size();
1248 TOptionValues::iterator o2v = _option2value.begin();
1249 for ( ; o2v != _option2value.end(); ++o2v )
1250 save << " -" << o2v->first << " -" << o2v->second;
1252 save << " " << _customOption2value.size();
1253 for ( o2v = _customOption2value.begin(); o2v != _customOption2value.end(); ++o2v )
1254 save << " -" << o2v->first << " -" << o2v->second;
1259 //=======================================================================
1260 //function : LoadFrom
1261 //=======================================================================
1263 std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
1269 isOK = static_cast<bool>(load >> i);
1273 load.clear(ios::badbit | load.rdstate());
1275 isOK = static_cast<bool>(load >> d);
1277 myMaximumMemory = d;
1279 load.clear(ios::badbit | load.rdstate());
1281 isOK = static_cast<bool>(load >> d);
1283 myInitialMemory = d;
1285 load.clear(ios::badbit | load.rdstate());
1287 isOK = static_cast<bool>(load >> i);
1289 myOptimizationLevel = i;
1291 load.clear(ios::badbit | load.rdstate());
1293 isOK = static_cast<bool>(load >> myWorkingDirectory);
1295 if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
1296 myKeepFiles = false;
1297 myWorkingDirectory.clear();
1299 else if ( myWorkingDirectory == "1" ) {
1301 myWorkingDirectory.clear();
1305 load.clear(ios::badbit | load.rdstate());
1307 if ( !myWorkingDirectory.empty() ) {
1308 isOK = static_cast<bool>(load >> i);
1312 load.clear(ios::badbit | load.rdstate());
1315 isOK = static_cast<bool>(load >> i);
1317 myVerboseLevel = (short) i;
1319 load.clear(ios::badbit | load.rdstate());
1321 isOK = static_cast<bool>(load >> i);
1323 myToCreateNewNodes = (bool) i;
1325 load.clear(ios::badbit | load.rdstate());
1327 isOK = static_cast<bool>(load >> i);
1329 myToUseBoundaryRecoveryVersion = (bool) i;
1331 load.clear(ios::badbit | load.rdstate());
1333 isOK = static_cast<bool>(load >> i);
1335 myToUseFemCorrection = (bool) i;
1337 load.clear(ios::badbit | load.rdstate());
1339 isOK = static_cast<bool>(load >> i);
1341 myToRemoveCentralPoint = (bool) i;
1343 load.clear(ios::badbit | load.rdstate());
1345 isOK = static_cast<bool>(load >> d);
1349 load.clear(ios::badbit | load.rdstate());
1351 std::string separator;
1352 bool hasOptions = false;
1353 bool hasEnforcedVertices = false;
1354 bool hasEnforcedMeshes = false;
1355 isOK = static_cast<bool>(load >> separator);
1357 if ( isOK && ( separator == "0" || separator == "1" ))
1359 myToMakeGroupsOfDomains = ( separator == "1" );
1360 isOK = static_cast<bool>(load >> separator);
1364 if (separator == "__OPTIONS_BEGIN__")
1366 else if (separator == "__ENFORCED_VERTICES_BEGIN__")
1367 hasEnforcedVertices = true;
1368 else if (separator == "__ENFORCED_MESHES_BEGIN__")
1369 hasEnforcedMeshes = true;
1375 isOK = static_cast<bool>(load >> txt);
1377 if (txt == "__OPTIONS_END__") {
1378 // if (!myTextOption.empty()) {
1379 // // Remove last space
1380 // myTextOption.erase(myTextOption.end()-1);
1385 // myTextOption += txt;
1386 // myTextOption += " ";
1392 isOK = static_cast<bool>(load >> separator);
1393 if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__")
1394 hasEnforcedVertices = true;
1395 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1396 hasEnforcedMeshes = true;
1399 if (hasEnforcedVertices) {
1400 std::string txt, name, entry, groupName;
1401 double size, coords[3];
1403 bool hasCoords = false;
1404 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1406 if (txt == "__ENFORCED_VERTICES_END__") {
1411 TGHS3DEnforcedVertex *enfVertex = new TGHS3DEnforcedVertex();
1413 isOK = static_cast<bool>(load >> txt);
1414 if (txt == "__END_VERTEX__") {
1415 enfVertex->name = name;
1416 enfVertex->geomEntry = entry;
1417 enfVertex->isCompound = isCompound;
1418 enfVertex->groupName = groupName;
1419 enfVertex->coords.clear();
1421 enfVertex->coords.assign(coords,coords+3);
1423 _enfVertexList.insert(enfVertex);
1425 if (enfVertex->coords.size())
1426 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1427 if (!enfVertex->geomEntry.empty())
1428 _geomEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1437 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1438 while (isOK && (txt != "__END_NAME__")) {
1439 isOK = static_cast<bool>(load >> txt);
1440 if (txt != "__END_NAME__") {
1446 MESSAGE("name: " <<name);
1449 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1450 isOK = static_cast<bool>(load >> entry);
1451 isOK = static_cast<bool>(load >> isCompound);
1452 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1453 if (txt != "__END_ENTRY__")
1454 throw std::exception();
1455 MESSAGE("entry: " << entry);
1458 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1459 while (isOK && (txt != "__END_GROUP__")) {
1460 isOK = static_cast<bool>(load >> txt);
1461 if (txt != "__END_GROUP__") {
1462 if (!groupName.empty())
1467 MESSAGE("groupName: " << groupName);
1470 if (txt == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1472 isOK = static_cast<bool>(load >> coords[0] >> coords[1] >> coords[2]);
1473 isOK = static_cast<bool>(load >> txt); // __END_COORDS__
1474 if (txt != "__END_COORDS__")
1475 throw std::exception();
1476 MESSAGE("coords: " << coords[0] <<","<< coords[1] <<","<< coords[2]);
1479 if (txt == "__BEGIN_SIZE__") { // __BEGIN_ENTRY__
1480 isOK = static_cast<bool>(load >> size);
1481 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1482 if (txt != "__END_SIZE__") {
1483 throw std::exception();
1485 MESSAGE("size: " << size);
1488 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1492 if (hasEnforcedVertices) {
1493 isOK = static_cast<bool>(load >> separator);
1494 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1495 hasEnforcedMeshes = true;
1498 if (hasEnforcedMeshes) {
1499 std::string txt, name, entry, groupName;
1500 int elementType = -1, persistID = -1;
1501 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1504 if (txt == "__ENFORCED_MESHES_END__")
1507 TGHS3DEnforcedMesh *enfMesh = new TGHS3DEnforcedMesh();
1509 isOK = static_cast<bool>(load >> txt);
1510 if (txt == "__END_ENF_MESH__") {
1511 enfMesh->name = name;
1512 enfMesh->entry = entry;
1513 enfMesh->elementType = (SMESH::ElementType)elementType;
1514 enfMesh->groupName = groupName;
1515 enfMesh->persistID = persistID;
1517 _enfMeshList.insert(enfMesh);
1518 //std::cout << "Restoring of enforced mesh " <<name << " done" << std::endl;
1528 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1529 while (isOK && (txt != "__END_NAME__")) {
1530 isOK = static_cast<bool>(load >> txt);
1531 if (txt != "__END_NAME__") {
1537 MESSAGE("name: " <<name);
1540 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1541 isOK = static_cast<bool>(load >> entry);
1542 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1543 if (txt != "__END_ENTRY__")
1544 throw std::exception();
1545 MESSAGE("entry: " << entry);
1548 if (txt == "__BEGIN_ELEM_TYPE__") { // __BEGIN_ELEM_TYPE__
1549 isOK = static_cast<bool>(load >> elementType);
1550 isOK = static_cast<bool>(load >> txt); // __END_ELEM_TYPE__
1551 if (txt != "__END_ELEM_TYPE__")
1552 throw std::exception();
1553 MESSAGE("elementType: " << elementType);
1556 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1557 while (isOK && (txt != "__END_GROUP__")) {
1558 isOK = static_cast<bool>(load >> txt);
1559 if (txt != "__END_GROUP__") {
1560 if (!groupName.empty())
1565 MESSAGE("groupName: " << groupName);
1568 if (txt == "__PERSIST_ID__") {
1569 isOK = static_cast<bool>(load >> persistID);
1570 MESSAGE("persistID: " << persistID);
1572 //std::cout << "isOK: " << isOK << std::endl;
1575 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1579 // New options in 2.9.6 (issue #17784)
1581 if ( ! hasOptions && ! hasEnforcedVertices && ! hasEnforcedMeshes )
1582 myUseVolumeProximity = ( separator == "1" );
1583 else if ( static_cast<bool>( load >> i ))
1584 myUseVolumeProximity = (bool) i;
1586 if ( static_cast<bool>( load >> myNbVolumeProximityLayers ))
1590 load >> myMinSizeDefault;
1591 load >> myMaxSizeDefault;
1593 std::string option, value;
1594 if ( static_cast<bool>( load >> i ) && i >= 0 )
1596 for ( int nbRead = 0; nbRead < i; ++nbRead )
1598 load >> option >> value;
1599 _option2value[ std::string( option, 1 )] = std::string( value, 1 );
1602 if ( static_cast<bool>( load >> i ) && i >= 0 )
1604 for ( int nbRead = 0; nbRead < i; ++nbRead )
1606 load >> option >> value;
1607 _customOption2value[ std::string( option, 1 )] = std::string( value, 1 );
1615 //=======================================================================
1616 //function : SetParametersByMesh
1617 //=======================================================================
1619 bool GHS3DPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
1625 //================================================================================
1627 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
1629 //================================================================================
1631 bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
1632 const SMESH_Mesh* /*theMesh*/)
1634 myToMakeGroupsOfDomains = ( !dflts._shape || dflts._shape->IsNull() );
1636 double diagonal = dflts._elemLength * _gen->GetBoundaryBoxSegmentation();
1637 myMinSizeDefault = 1e-3 * diagonal;
1638 myMaxSizeDefault = diagonal / 5.;
1643 //================================================================================
1645 * \brief Return command to run MG-Tetra mesher excluding file prefix (-f)
1647 //================================================================================
1649 std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
1650 const bool hasShapeToMesh,
1651 const bool forExecutable)
1653 std::string cmd = GetExeName();
1654 // check if any option is overridden by hyp->myTextOption
1655 bool max_memory = hyp ? !hyp->HasOptionDefined("max_memory") : true;
1656 bool auto_memory = hyp ? !hyp->HasOptionDefined("automatic_memory") : true;
1657 bool comp = hyp ? !hyp->HasOptionDefined("components") : true;
1658 bool optim_level = hyp ? !hyp->HasOptionDefined("optimisation_level") : true;
1659 bool no_int_points = hyp ? !hyp->HasOptionDefined("no_internal_points") : true;
1660 bool C = hyp ? !hyp->HasOptionDefined("-C") : true;
1661 bool verbose = hyp ? !hyp->HasOptionDefined("verbose") : true;
1662 bool gra = hyp ? !hyp->HasOptionDefined("-Dcpropa") : true;
1663 bool rem = hyp ? !hyp->HasOptionDefined("no_initial_central_point") : true;
1664 //bool fem = hyp ? !hyp->HasOptionDefined("-FEM") : true;
1666 // if use boundary recovery version, few options are allowed
1667 bool useBndRecovery = !C;
1668 if ( !useBndRecovery && hyp )
1669 useBndRecovery = hyp->myToUseBoundaryRecoveryVersion;
1671 // MG-Tetra needs to know amount of memory it may use (MB).
1672 // Default memory is defined at MG-Tetra installation but it may be not enough,
1673 // so allow to use about all available memory
1675 float aMaximumMemory = hyp ? hyp->myMaximumMemory : -1;
1676 cmd += " --max_memory ";
1677 if ( aMaximumMemory < 0 ) cmd += SMESH_Comment( int( DefaultMaximumMemory() ));
1678 else cmd += SMESH_Comment( int( aMaximumMemory ));
1680 if ( auto_memory && !useBndRecovery ) {
1681 float aInitialMemory = hyp ? hyp->myInitialMemory : -1;
1682 cmd += " --automatic_memory ";
1683 if ( aInitialMemory > 0 ) cmd += SMESH_Comment( int( aInitialMemory ));
1686 // component to mesh
1687 if ( comp && !useBndRecovery ) {
1688 // We always run MG-Tetra with "to mesh holes'==TRUE (see PAL19680)
1689 if ( hasShapeToMesh )
1690 cmd += " --components all";
1692 bool aToMeshHoles = hyp ? hyp->myToMeshHoles : DefaultMeshHoles();
1693 if ( aToMeshHoles ) cmd += " --components all";
1694 else cmd += " --components outside_components";
1697 const bool toCreateNewNodes = ( no_int_points && ( !hyp || hyp->myToCreateNewNodes ));
1699 // optimization level
1700 if ( !toCreateNewNodes ) {
1701 cmd += " --optimisation_level none"; // issue 22608
1703 else if ( optim_level && hyp && !useBndRecovery ) {
1704 if ( hyp->myOptimizationLevel >= 0 && hyp->myOptimizationLevel < 5 ) {
1705 const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
1706 cmd += " --optimisation_level ";
1707 cmd += level[ hyp->myOptimizationLevel ];
1711 // to create internal nodes
1712 if ( no_int_points && !toCreateNewNodes ) {
1713 if ( forExecutable )
1714 cmd += " --no_internal_points";
1716 cmd += " --internalpoints no";
1720 if ( verbose && hyp ) {
1721 cmd += " --verbose " + SMESH_Comment( hyp->myVerboseLevel );
1724 // boundary recovery version
1725 // if ( useBndRecovery ) {
1729 // to use FEM correction
1730 // if ( fem && hyp && hyp->myToUseFemCorrection) {
1734 // to remove initial central point.
1735 if ( rem && hyp && hyp->myToRemoveCentralPoint ) {
1736 if ( forExecutable )
1737 cmd += " --no_initial_central_point";
1739 cmd += " --centralpoint no";
1743 // if ( hyp && !hyp->myTextOption.empty() ) {
1744 // cmd += " " + hyp->myTextOption;
1750 if ( hyp->GetMinSize() > 0 )
1751 cmd += " --min_size " + SMESH_Comment( hyp->GetMinSize() );
1752 if ( hyp->GetMaxSize() > 0 )
1753 cmd += " --max_size " + SMESH_Comment( hyp->GetMaxSize() );
1756 // to define volumic gradation.
1759 cmd += " --gradation " + SMESH_Comment( hyp->myGradation );
1765 if ( hyp->GetUseVolumeProximity() )
1767 cmd += " --volume_proximity_layers " + SMESH_Comment( hyp->GetNbVolumeProximityLayers() );
1770 std::string option, value;
1772 const TOptionValues* options[] = { & hyp->_option2value, & hyp->_customOption2value };
1773 for ( int iOp = 0; iOp < 2; ++iOp )
1775 TOptionValues::const_iterator o2v = options[iOp]->begin();
1776 for ( ; o2v != options[iOp]->end(); ++o2v )
1778 option = o2v->first;
1779 value = hyp->GetOptionValue( option, &isDefault );
1783 if ( value.empty() )//value == NoValue() )
1785 if ( hyp->_defaultOptionValues.count( option ))
1786 continue; // non-custom option with no value
1789 if ( strncmp( "no", option.c_str(), 2 ) == 0 ) // options w/o values: --no_*
1791 if ( !value.empty() && ToBool( value ) == false )
1795 if ( option[0] != '-' )
1799 cmd += option + " " + value;
1811 //================================================================================
1813 * \brief Return a unique file name
1815 //================================================================================
1817 std::string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hyp)
1819 std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
1820 const char lastChar = *aTmpDir.rbegin();
1822 if(lastChar != '\\') aTmpDir+='\\';
1824 if(lastChar != '/') aTmpDir+='/';
1827 TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
1828 aGenericName += "GHS3D_";
1829 aGenericName += getpid();
1830 aGenericName += "_";
1831 aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
1833 return aGenericName.ToCString();
1836 //================================================================================
1838 * Return the name of executable
1840 //================================================================================
1842 std::string GHS3DPlugin_Hypothesis::GetExeName()
1844 return "mg-tetra.exe";
1847 //================================================================================
1849 * \brief Return the enforced vertices
1851 //================================================================================
1853 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList GHS3DPlugin_Hypothesis::GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp)
1855 return hyp ? hyp->_GetEnforcedVertices(): TGHS3DEnforcedVertexList();
1858 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues GHS3DPlugin_Hypothesis::GetEnforcedVerticesCoordsSize (const GHS3DPlugin_Hypothesis* hyp)
1860 return hyp ? hyp->_GetEnforcedVerticesCoordsSize(): TGHS3DEnforcedVertexCoordsValues();
1863 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexEntryValues GHS3DPlugin_Hypothesis::GetEnforcedVerticesEntrySize (const GHS3DPlugin_Hypothesis* hyp)
1865 return hyp ? hyp->_GetEnforcedVerticesEntrySize(): TGHS3DEnforcedVertexEntryValues();
1868 GHS3DPlugin_Hypothesis::TCoordsGHS3DEnforcedVertexMap GHS3DPlugin_Hypothesis::GetEnforcedVerticesByCoords (const GHS3DPlugin_Hypothesis* hyp)
1870 return hyp ? hyp->_GetEnforcedVerticesByCoords(): TCoordsGHS3DEnforcedVertexMap();
1873 GHS3DPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap GHS3DPlugin_Hypothesis::GetEnforcedVerticesByEntry (const GHS3DPlugin_Hypothesis* hyp)
1875 return hyp ? hyp->_GetEnforcedVerticesByEntry(): TGeomEntryGHS3DEnforcedVertexMap();
1878 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap GHS3DPlugin_Hypothesis::GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp)
1880 return hyp ? hyp->_GetEnforcedNodes():TIDSortedNodeGroupMap();
1883 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap GHS3DPlugin_Hypothesis::GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp)
1885 return hyp ? hyp->_GetEnforcedEdges():TIDSortedElemGroupMap();
1888 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap GHS3DPlugin_Hypothesis::GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp)
1890 return hyp ? hyp->_GetEnforcedTriangles():TIDSortedElemGroupMap();
1893 GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp)
1895 return hyp ? hyp->_GetNodeIDToSizeMap(): TID2SizeMap();
1898 GHS3DPlugin_Hypothesis::TSetStrings GHS3DPlugin_Hypothesis::GetGroupsToRemove(const GHS3DPlugin_Hypothesis* hyp)
1900 return hyp ? hyp->_GetGroupsToRemove(): TSetStrings();
1904 //=============================================================================
1905 void GHS3DPlugin_Hypothesis::SetOptionValue(const std::string& optionName,
1906 const std::string& optionValue)
1907 throw (std::invalid_argument)
1909 TOptionValues::iterator op_val = _option2value.find(optionName);
1910 if (op_val == _option2value.end())
1912 op_val = _customOption2value.find( optionName );
1913 if ( op_val != _customOption2value.end() && op_val->second != optionValue )
1914 NotifySubMeshesHypothesisModification();
1915 _customOption2value[ optionName ] = optionValue;
1919 if (op_val->second != optionValue)
1921 const char* ptr = optionValue.c_str();
1922 // strip white spaces
1923 while (ptr[0] == ' ')
1925 int i = strlen(ptr);
1926 while (i != 0 && ptr[i - 1] == ' ')
1930 std::string typeName;
1933 } else if (_charOptions.count(optionName)) {
1934 // do not check strings
1935 } else if (_doubleOptions.count(optionName)) {
1936 // check if value is double
1937 ToDbl(ptr, &typeOk);
1939 } else if (_boolOptions.count(optionName)) {
1940 // check if value is bool
1941 ToBool(ptr, &typeOk);
1944 // check if value is int
1945 ToInt(ptr, &typeOk);
1946 typeName = "integer";
1948 if ( typeOk ) // check some specific values ?
1953 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
1954 throw std::invalid_argument(msg);
1956 std::string value( ptr, i );
1957 if ( _defaultOptionValues[ optionName ] == value )
1960 op_val->second = value;
1962 NotifySubMeshesHypothesisModification();
1966 //=============================================================================
1967 //! Return option value. If isDefault provided, it can be a default value,
1968 // then *isDefault == true. If isDefault is not provided, the value will be
1969 // empty if it equals a default one.
1970 std::string GHS3DPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
1971 bool* isDefault) const
1972 throw (std::invalid_argument)
1974 TOptionValues::const_iterator op_val = _option2value.find(optionName);
1975 if (op_val == _option2value.end())
1977 op_val = _customOption2value.find(optionName);
1978 if (op_val == _customOption2value.end())
1980 std::string msg = "Unknown MG-Tetra option: <" + optionName + ">";
1981 throw std::invalid_argument(msg);
1984 std::string val = op_val->second;
1985 if ( isDefault ) *isDefault = ( val.empty() );
1987 if ( val.empty() && isDefault )
1989 op_val = _defaultOptionValues.find( optionName );
1990 if (op_val != _defaultOptionValues.end())
1991 val = op_val->second;
1997 //=============================================================================
1998 bool GHS3DPlugin_Hypothesis::HasOptionDefined( const std::string& optionName ) const
2000 bool isDefault = false;
2003 GetOptionValue( optionName, &isDefault );
2005 catch ( std::invalid_argument )
2012 //=============================================================================
2013 void GHS3DPlugin_Hypothesis::ClearOption(const std::string& optionName)
2015 TOptionValues::iterator op_val = _customOption2value.find(optionName);
2016 if (op_val != _customOption2value.end())
2017 _customOption2value.erase(op_val);
2019 op_val = _option2value.find(optionName);
2020 if (op_val != _option2value.end())
2021 op_val->second.clear();
2025 //=============================================================================
2026 GHS3DPlugin_Hypothesis::TOptionValues GHS3DPlugin_Hypothesis::GetOptionValues() const
2029 TOptionValues::const_iterator op_val = _option2value.begin();
2030 for ( ; op_val != _option2value.end(); ++op_val )
2031 vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
2036 //================================================================================
2038 * \brief Converts a string to a bool
2040 //================================================================================
2042 bool GHS3DPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
2043 throw (std::invalid_argument)
2045 std::string s = str;
2046 if ( isOk ) *isOk = true;
2048 for ( size_t i = 0; i <= s.size(); ++i )
2049 s[i] = tolower( s[i] );
2051 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
2054 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
2060 std::string msg = "Not a Boolean value:'" + str + "'";
2061 throw std::invalid_argument(msg);
2066 //================================================================================
2068 * \brief Converts a string to a real value
2070 //================================================================================
2072 double GHS3DPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
2073 throw (std::invalid_argument)
2075 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
2078 double val = strtod(&str[0], &endPtr);
2079 bool ok = (&str[0] != endPtr);
2081 if ( isOk ) *isOk = ok;
2085 std::string msg = "Not a real value:'" + str + "'";
2086 throw std::invalid_argument(msg);
2091 //================================================================================
2093 * \brief Converts a string to a integer value
2095 //================================================================================
2097 int GHS3DPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
2098 throw (std::invalid_argument)
2100 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
2103 int val = (int)strtol( &str[0], &endPtr, 10);
2104 bool ok = (&str[0] != endPtr);
2106 if ( isOk ) *isOk = ok;
2110 std::string msg = "Not an integer value:'" + str + "'";
2111 throw std::invalid_argument(msg);