1 // Copyright (C) 2004-2021 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)
822 std::vector<double> coord(3);
826 if (_coordsEnfVertexMap.count(coord)>0)
827 return _coordsEnfVertexMap[coord];
828 std::ostringstream msg ;
829 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
830 throw std::invalid_argument(msg.str());
833 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* GHS3DPlugin_Hypothesis::GetEnforcedVertex(const std::string theEntry)
835 if (_geomEntryEnfVertexMap.count(theEntry)>0)
836 return _geomEntryEnfVertexMap[theEntry];
838 std::ostringstream msg ;
839 msg << "No enforced vertex with entry " << theEntry;
840 throw std::invalid_argument(msg.str());
843 //=======================================================================
844 //function : RemoveEnforcedVertex
845 //=======================================================================
847 bool GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, const std::string theEntry)
849 bool toNotify = false;
850 std::ostringstream msg;
851 TGHS3DEnforcedVertex *oldEnfVertex;
852 std::vector<double> coords(3);
857 // check that enf vertex with given enf vertex entry exists
858 TGeomEntryGHS3DEnforcedVertexMap::iterator it_enfVertexEntry = _geomEntryEnfVertexMap.find(theEntry);
859 if (it_enfVertexEntry != _geomEntryEnfVertexMap.end()) {
861 MESSAGE("Found enforced vertex with geom entry " << theEntry);
862 oldEnfVertex = it_enfVertexEntry->second;
863 _geomEntryEnfVertexMap.erase(it_enfVertexEntry);
866 MESSAGE("Enforced vertex with geom entry " << theEntry << " not found");
867 // check that enf vertex with given coords exists
868 TCoordsGHS3DEnforcedVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
869 if (it_coords_enf != _coordsEnfVertexMap.end()) {
871 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
872 oldEnfVertex = it_coords_enf->second;
873 _coordsEnfVertexMap.erase(it_coords_enf);
874 _enfVertexCoordsSizeList.erase(_enfVertexCoordsSizeList.find(coords));
877 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
878 throw std::invalid_argument(msg.str());
882 MESSAGE("Remove enf vertex from _enfVertexList");
884 // update _enfVertexList
885 TGHS3DEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
886 if (it != _enfVertexList.end()) {
887 if ((*it)->groupName != "")
888 _groupsToRemove.insert((*it)->groupName);
889 _enfVertexList.erase(it);
895 NotifySubMeshesHypothesisModification();
900 //=======================================================================
901 //function : ClearEnforcedVertices
902 //=======================================================================
903 void GHS3DPlugin_Hypothesis::ClearEnforcedVertices()
905 TGHS3DEnforcedVertexList::const_iterator it = _enfVertexList.begin();
906 for(;it != _enfVertexList.end();++it) {
907 if ((*it)->groupName != "")
908 _groupsToRemove.insert((*it)->groupName);
910 _enfVertexList.clear();
911 _coordsEnfVertexMap.clear();
912 _geomEntryEnfVertexMap.clear();
913 _enfVertexCoordsSizeList.clear();
914 _enfVertexEntrySizeList.clear();
915 NotifySubMeshesHypothesisModification();
918 //=======================================================================
919 //function : ClearEnforcedMeshes
920 //=======================================================================
921 void GHS3DPlugin_Hypothesis::ClearEnforcedMeshes()
923 TGHS3DEnforcedMeshList::const_iterator it = _enfMeshList.begin();
924 for(;it != _enfMeshList.end();++it) {
925 if ((*it)->groupName != "")
926 _groupsToRemove.insert((*it)->groupName);
930 _enfTriangles.clear();
931 _nodeIDToSizeMap.clear();
932 _enfMeshList.clear();
933 _entryEnfMeshMap.clear();
934 NotifySubMeshesHypothesisModification();
937 //================================================================================
939 * \brief At mesh loading, restore enforced elements by just loaded enforced meshes
941 //================================================================================
943 void GHS3DPlugin_Hypothesis::RestoreEnfElemsByMeshes()
945 TGHS3DEnforcedMeshList::const_iterator it = _enfMeshList.begin();
946 for(;it != _enfMeshList.end();++it) {
947 TGHS3DEnforcedMesh* enfMesh = *it;
948 if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
949 SetEnforcedMesh( *mesh,
950 enfMesh->elementType,
953 enfMesh->groupName );
954 enfMesh->persistID = -1; // not to restore again
958 //=======================================================================
959 //function : SetGroupsToRemove
960 //=======================================================================
962 void GHS3DPlugin_Hypothesis::ClearGroupsToRemove()
964 _groupsToRemove.clear();
968 //=======================================================================
969 //function : DefaultMeshHoles
970 //=======================================================================
972 bool GHS3DPlugin_Hypothesis::DefaultMeshHoles()
974 return false; // PAL19680
977 //=======================================================================
978 //function : DefaultToMakeGroupsOfDomains
979 //=======================================================================
981 bool GHS3DPlugin_Hypothesis::DefaultToMakeGroupsOfDomains()
983 return false; // issue 0022172
986 //=======================================================================
987 //function : DefaultMaximumMemory
988 //=======================================================================
992 #elif !defined(__APPLE__)
993 #include <sys/sysinfo.h>
996 float GHS3DPlugin_Hypothesis::DefaultMaximumMemory()
999 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
1000 MEMORYSTATUSEX statex;
1001 statex.dwLength = sizeof (statex);
1002 long err = GlobalMemoryStatusEx (&statex);
1004 double totMB = (double)statex.ullAvailPhys / 1024. / 1024.;
1005 return (float)( 0.7 * totMB );
1007 #elif !defined(__APPLE__)
1009 long err = sysinfo( &si );
1011 long ramMB = si.totalram * si.mem_unit / 1024 / 1024;
1012 return ( 0.7 * ramMB );
1018 //=======================================================================
1019 //function : DefaultInitialMemory
1020 //=======================================================================
1022 float GHS3DPlugin_Hypothesis::DefaultInitialMemory()
1024 return DefaultMaximumMemory();
1027 //=======================================================================
1028 //function : DefaultOptimizationLevel
1029 //=======================================================================
1031 short GHS3DPlugin_Hypothesis::DefaultOptimizationLevel()
1036 //=======================================================================
1037 //function : DefaultWorkingDirectory
1038 //=======================================================================
1040 std::string GHS3DPlugin_Hypothesis::DefaultWorkingDirectory()
1042 TCollection_AsciiString aTmpDir;
1044 char *Tmp_dir = getenv("SALOME_TMP_DIR");
1045 if(Tmp_dir != NULL) {
1050 aTmpDir = TCollection_AsciiString("C:\\");
1052 aTmpDir = TCollection_AsciiString("/tmp/");
1055 return aTmpDir.ToCString();
1058 //=======================================================================
1059 //function : DefaultKeepFiles
1060 //=======================================================================
1062 bool GHS3DPlugin_Hypothesis::DefaultKeepFiles()
1067 //=======================================================================
1068 //function : DefaultRemoveLogOnSuccess
1069 //=======================================================================
1071 bool GHS3DPlugin_Hypothesis::DefaultRemoveLogOnSuccess()
1077 //=======================================================================
1078 //function : DefaultVerboseLevel
1079 //=======================================================================
1081 short GHS3DPlugin_Hypothesis::DefaultVerboseLevel()
1086 //=======================================================================
1087 //function : DefaultToCreateNewNodes
1088 //=======================================================================
1090 bool GHS3DPlugin_Hypothesis::DefaultToCreateNewNodes()
1095 //=======================================================================
1096 //function : DefaultToUseBoundaryRecoveryVersion
1097 //=======================================================================
1099 bool GHS3DPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
1104 //=======================================================================
1105 //function : DefaultToUseFEMCorrection
1106 //=======================================================================
1108 bool GHS3DPlugin_Hypothesis::DefaultToUseFEMCorrection()
1113 //=======================================================================
1114 //function : DefaultToRemoveCentralPoint
1115 //=======================================================================
1117 bool GHS3DPlugin_Hypothesis::DefaultToRemoveCentralPoint()
1122 //=======================================================================
1123 //function : DefaultStandardOutputLog
1124 //=======================================================================
1126 bool GHS3DPlugin_Hypothesis::DefaultStandardOutputLog()
1131 // //=======================================================================
1132 // //function : DefaultID2SizeMap
1133 // //=======================================================================
1135 // GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::DefaultID2SizeMap()
1137 // return GHS3DPlugin_Hypothesis::TID2SizeMap();
1141 //=======================================================================
1143 //=======================================================================
1145 std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save)
1147 save << (int) myToMeshHoles << " ";
1148 save << myMaximumMemory << " ";
1149 save << myInitialMemory << " ";
1150 save << myOptimizationLevel << " ";
1151 save << myWorkingDirectory << " ";
1152 save << (int)myKeepFiles << " ";
1153 save << myVerboseLevel << " ";
1154 save << (int)myToCreateNewNodes << " ";
1155 save << (int)myToUseBoundaryRecoveryVersion << " ";
1156 save << (int)myToUseFemCorrection << " ";
1157 save << (int)myToRemoveCentralPoint << " ";
1158 save << myGradation << " ";
1159 save << myToMakeGroupsOfDomains << " ";
1160 // if (!myTextOption.empty()) {
1161 // save << "__OPTIONS_BEGIN__ ";
1162 // save << myTextOption << " ";
1163 // save << "__OPTIONS_END__ ";
1167 TGHS3DEnforcedVertexList::iterator it = _enfVertexList.begin();
1168 if (it != _enfVertexList.end()) {
1169 save << " " << "__ENFORCED_VERTICES_BEGIN__ ";
1170 for ( ; it != _enfVertexList.end(); ++it ) {
1171 TGHS3DEnforcedVertex *enfVertex = (*it);
1172 save << " " << "__BEGIN_VERTEX__";
1173 if (!enfVertex->name.empty()) {
1174 save << " " << "__BEGIN_NAME__";
1175 save << " " << enfVertex->name;
1176 save << " " << "__END_NAME__";
1178 if (!enfVertex->geomEntry.empty()) {
1179 save << " " << "__BEGIN_ENTRY__";
1180 save << " " << enfVertex->geomEntry;
1181 save << " " << enfVertex->isCompound;
1182 save << " " << "__END_ENTRY__";
1184 if (!enfVertex->groupName.empty()) {
1185 save << " " << "__BEGIN_GROUP__";
1186 save << " " << enfVertex->groupName;
1187 save << " " << "__END_GROUP__";
1189 if (enfVertex->coords.size()) {
1190 save << " " << "__BEGIN_COORDS__";
1191 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1192 save << " " << enfVertex->coords[i];
1193 save << " " << "__END_COORDS__";
1195 save << " " << "__BEGIN_SIZE__";
1196 save << " " << enfVertex->size;
1197 save << " " << "__END_SIZE__";
1198 save << " " << "__END_VERTEX__";
1200 save << " " << "__ENFORCED_VERTICES_END__ ";
1203 TGHS3DEnforcedMeshList::iterator it_mesh = _enfMeshList.begin();
1204 if (it_mesh != _enfMeshList.end()) {
1205 save << " " << "__ENFORCED_MESHES_BEGIN__ ";
1206 for ( ; it_mesh != _enfMeshList.end(); ++it_mesh ) {
1207 TGHS3DEnforcedMesh *enfMesh = (*it_mesh);
1208 save << " " << "__BEGIN_ENF_MESH__";
1210 save << " " << "__BEGIN_NAME__";
1211 save << " " << enfMesh->name;
1212 save << " " << "__END_NAME__";
1214 save << " " << "__BEGIN_ENTRY__";
1215 save << " " << enfMesh->entry;
1216 save << " " << "__END_ENTRY__";
1218 save << " " << "__BEGIN_ELEM_TYPE__";
1219 save << " " << (int)enfMesh->elementType;
1220 save << " " << "__END_ELEM_TYPE__";
1222 if (!enfMesh->groupName.empty()) {
1223 save << " " << "__BEGIN_GROUP__";
1224 save << " " << enfMesh->groupName;
1225 save << " " << "__END_GROUP__";
1227 save << " " << "__PERSIST_ID__";
1228 save << " " << enfMesh->persistID;
1229 save << " " << "__END_ENF_MESH__";
1230 std::cout << "Saving of enforced mesh " << enfMesh->name.c_str() << " done" << std::endl;
1232 save << " " << "__ENFORCED_MESHES_END__ ";
1235 // New options in 2.9.6 (issue #17784)
1237 save << " " << myUseVolumeProximity;
1238 save << " " << myNbVolumeProximityLayers;
1239 save << " " << myMinSize;
1240 save << " " << myMaxSize;
1241 save << " " << myMinSizeDefault;
1242 save << " " << myMaxSizeDefault;
1244 save << " " << _option2value.size();
1245 TOptionValues::iterator o2v = _option2value.begin();
1246 for ( ; o2v != _option2value.end(); ++o2v )
1247 save << " -" << o2v->first << " -" << o2v->second;
1249 save << " " << _customOption2value.size();
1250 for ( o2v = _customOption2value.begin(); o2v != _customOption2value.end(); ++o2v )
1251 save << " -" << o2v->first << " -" << o2v->second;
1256 //=======================================================================
1257 //function : LoadFrom
1258 //=======================================================================
1260 std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
1266 isOK = static_cast<bool>(load >> i);
1270 load.clear(ios::badbit | load.rdstate());
1272 isOK = static_cast<bool>(load >> d);
1274 myMaximumMemory = d;
1276 load.clear(ios::badbit | load.rdstate());
1278 isOK = static_cast<bool>(load >> d);
1280 myInitialMemory = d;
1282 load.clear(ios::badbit | load.rdstate());
1284 isOK = static_cast<bool>(load >> i);
1286 myOptimizationLevel = i;
1288 load.clear(ios::badbit | load.rdstate());
1290 isOK = static_cast<bool>(load >> myWorkingDirectory);
1292 if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
1293 myKeepFiles = false;
1294 myWorkingDirectory.clear();
1296 else if ( myWorkingDirectory == "1" ) {
1298 myWorkingDirectory.clear();
1302 load.clear(ios::badbit | load.rdstate());
1304 if ( !myWorkingDirectory.empty() ) {
1305 isOK = static_cast<bool>(load >> i);
1309 load.clear(ios::badbit | load.rdstate());
1312 isOK = static_cast<bool>(load >> i);
1314 myVerboseLevel = (short) i;
1316 load.clear(ios::badbit | load.rdstate());
1318 isOK = static_cast<bool>(load >> i);
1320 myToCreateNewNodes = (bool) i;
1322 load.clear(ios::badbit | load.rdstate());
1324 isOK = static_cast<bool>(load >> i);
1326 myToUseBoundaryRecoveryVersion = (bool) i;
1328 load.clear(ios::badbit | load.rdstate());
1330 isOK = static_cast<bool>(load >> i);
1332 myToUseFemCorrection = (bool) i;
1334 load.clear(ios::badbit | load.rdstate());
1336 isOK = static_cast<bool>(load >> i);
1338 myToRemoveCentralPoint = (bool) i;
1340 load.clear(ios::badbit | load.rdstate());
1342 isOK = static_cast<bool>(load >> d);
1346 load.clear(ios::badbit | load.rdstate());
1348 std::string separator;
1349 bool hasOptions = false;
1350 bool hasEnforcedVertices = false;
1351 bool hasEnforcedMeshes = false;
1352 isOK = static_cast<bool>(load >> separator);
1354 if ( isOK && ( separator == "0" || separator == "1" ))
1356 myToMakeGroupsOfDomains = ( separator == "1" );
1357 isOK = static_cast<bool>(load >> separator);
1361 if (separator == "__OPTIONS_BEGIN__")
1363 else if (separator == "__ENFORCED_VERTICES_BEGIN__")
1364 hasEnforcedVertices = true;
1365 else if (separator == "__ENFORCED_MESHES_BEGIN__")
1366 hasEnforcedMeshes = true;
1372 isOK = static_cast<bool>(load >> txt);
1374 if (txt == "__OPTIONS_END__") {
1375 // if (!myTextOption.empty()) {
1376 // // Remove last space
1377 // myTextOption.erase(myTextOption.end()-1);
1382 // myTextOption += txt;
1383 // myTextOption += " ";
1389 isOK = static_cast<bool>(load >> separator);
1390 if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__")
1391 hasEnforcedVertices = true;
1392 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1393 hasEnforcedMeshes = true;
1396 if (hasEnforcedVertices) {
1397 std::string txt, name, entry, groupName;
1398 double size, coords[3];
1400 bool hasCoords = false;
1401 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1403 if (txt == "__ENFORCED_VERTICES_END__") {
1408 TGHS3DEnforcedVertex *enfVertex = new TGHS3DEnforcedVertex();
1410 isOK = static_cast<bool>(load >> txt);
1411 if (txt == "__END_VERTEX__") {
1412 enfVertex->name = name;
1413 enfVertex->geomEntry = entry;
1414 enfVertex->isCompound = isCompound;
1415 enfVertex->groupName = groupName;
1416 enfVertex->coords.clear();
1418 enfVertex->coords.assign(coords,coords+3);
1420 _enfVertexList.insert(enfVertex);
1422 if (enfVertex->coords.size())
1423 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1424 if (!enfVertex->geomEntry.empty())
1425 _geomEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1434 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1435 while (isOK && (txt != "__END_NAME__")) {
1436 isOK = static_cast<bool>(load >> txt);
1437 if (txt != "__END_NAME__") {
1443 MESSAGE("name: " <<name);
1446 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1447 isOK = static_cast<bool>(load >> entry);
1448 isOK = static_cast<bool>(load >> isCompound);
1449 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1450 if (txt != "__END_ENTRY__")
1451 throw std::exception();
1452 MESSAGE("entry: " << entry);
1455 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1456 while (isOK && (txt != "__END_GROUP__")) {
1457 isOK = static_cast<bool>(load >> txt);
1458 if (txt != "__END_GROUP__") {
1459 if (!groupName.empty())
1464 MESSAGE("groupName: " << groupName);
1467 if (txt == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1469 isOK = static_cast<bool>(load >> coords[0] >> coords[1] >> coords[2]);
1470 isOK = static_cast<bool>(load >> txt); // __END_COORDS__
1471 if (txt != "__END_COORDS__")
1472 throw std::exception();
1473 MESSAGE("coords: " << coords[0] <<","<< coords[1] <<","<< coords[2]);
1476 if (txt == "__BEGIN_SIZE__") { // __BEGIN_ENTRY__
1477 isOK = static_cast<bool>(load >> size);
1478 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1479 if (txt != "__END_SIZE__") {
1480 throw std::exception();
1482 MESSAGE("size: " << size);
1485 isOK = static_cast<bool>(load >> txt); // __BEGIN_VERTEX__
1489 if (hasEnforcedVertices) {
1490 isOK = static_cast<bool>(load >> separator);
1491 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1492 hasEnforcedMeshes = true;
1495 if (hasEnforcedMeshes) {
1496 std::string txt, name, entry, groupName;
1497 int elementType = -1, persistID = -1;
1498 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1501 if (txt == "__ENFORCED_MESHES_END__")
1504 TGHS3DEnforcedMesh *enfMesh = new TGHS3DEnforcedMesh();
1506 isOK = static_cast<bool>(load >> txt);
1507 if (txt == "__END_ENF_MESH__") {
1508 enfMesh->name = name;
1509 enfMesh->entry = entry;
1510 enfMesh->elementType = (SMESH::ElementType)elementType;
1511 enfMesh->groupName = groupName;
1512 enfMesh->persistID = persistID;
1514 _enfMeshList.insert(enfMesh);
1515 //std::cout << "Restoring of enforced mesh " <<name << " done" << std::endl;
1525 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1526 while (isOK && (txt != "__END_NAME__")) {
1527 isOK = static_cast<bool>(load >> txt);
1528 if (txt != "__END_NAME__") {
1534 MESSAGE("name: " <<name);
1537 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1538 isOK = static_cast<bool>(load >> entry);
1539 isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
1540 if (txt != "__END_ENTRY__")
1541 throw std::exception();
1542 MESSAGE("entry: " << entry);
1545 if (txt == "__BEGIN_ELEM_TYPE__") { // __BEGIN_ELEM_TYPE__
1546 isOK = static_cast<bool>(load >> elementType);
1547 isOK = static_cast<bool>(load >> txt); // __END_ELEM_TYPE__
1548 if (txt != "__END_ELEM_TYPE__")
1549 throw std::exception();
1550 MESSAGE("elementType: " << elementType);
1553 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1554 while (isOK && (txt != "__END_GROUP__")) {
1555 isOK = static_cast<bool>(load >> txt);
1556 if (txt != "__END_GROUP__") {
1557 if (!groupName.empty())
1562 MESSAGE("groupName: " << groupName);
1565 if (txt == "__PERSIST_ID__") {
1566 isOK = static_cast<bool>(load >> persistID);
1567 MESSAGE("persistID: " << persistID);
1569 //std::cout << "isOK: " << isOK << std::endl;
1572 isOK = static_cast<bool>(load >> txt); // __BEGIN_ENF_MESH__
1576 // New options in 2.9.6 (issue #17784)
1578 if ( ! hasOptions && ! hasEnforcedVertices && ! hasEnforcedMeshes )
1579 myUseVolumeProximity = ( separator == "1" );
1580 else if ( static_cast<bool>( load >> i ))
1581 myUseVolumeProximity = (bool) i;
1583 if ( static_cast<bool>( load >> myNbVolumeProximityLayers ))
1587 load >> myMinSizeDefault;
1588 load >> myMaxSizeDefault;
1590 std::string option, value;
1591 if ( static_cast<bool>( load >> i ) && i >= 0 )
1593 for ( int nbRead = 0; nbRead < i; ++nbRead )
1595 load >> option >> value;
1596 _option2value[ std::string( option, 1 )] = std::string( value, 1 );
1599 if ( static_cast<bool>( load >> i ) && i >= 0 )
1601 for ( int nbRead = 0; nbRead < i; ++nbRead )
1603 load >> option >> value;
1604 _customOption2value[ std::string( option, 1 )] = std::string( value, 1 );
1612 //=======================================================================
1613 //function : SetParametersByMesh
1614 //=======================================================================
1616 bool GHS3DPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
1622 //================================================================================
1624 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
1626 //================================================================================
1628 bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
1629 const SMESH_Mesh* /*theMesh*/)
1631 myToMakeGroupsOfDomains = ( !dflts._shape || dflts._shape->IsNull() );
1633 double diagonal = dflts._elemLength * _gen->GetBoundaryBoxSegmentation();
1634 myMinSizeDefault = 1e-3 * diagonal;
1635 myMaxSizeDefault = diagonal / 5.;
1640 //================================================================================
1642 * \brief Return command to run MG-Tetra mesher excluding file prefix (-f)
1644 //================================================================================
1646 std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
1647 const bool hasShapeToMesh,
1648 const bool forExecutable)
1650 std::string cmd = GetExeName();
1651 // check if any option is overridden by hyp->myTextOption
1652 bool max_memory = hyp ? !hyp->HasOptionDefined("max_memory") : true;
1653 bool auto_memory = hyp ? !hyp->HasOptionDefined("automatic_memory") : true;
1654 bool comp = hyp ? !hyp->HasOptionDefined("components") : true;
1655 bool optim_level = hyp ? !hyp->HasOptionDefined("optimisation_level") : true;
1656 bool no_int_points = hyp ? !hyp->HasOptionDefined("no_internal_points") : true;
1657 bool C = hyp ? !hyp->HasOptionDefined("-C") : true;
1658 bool verbose = hyp ? !hyp->HasOptionDefined("verbose") : true;
1659 bool gra = hyp ? !hyp->HasOptionDefined("-Dcpropa") : true;
1660 bool rem = hyp ? !hyp->HasOptionDefined("no_initial_central_point") : true;
1661 //bool fem = hyp ? !hyp->HasOptionDefined("-FEM") : true;
1663 // if use boundary recovery version, few options are allowed
1664 bool useBndRecovery = !C;
1665 if ( !useBndRecovery && hyp )
1666 useBndRecovery = hyp->myToUseBoundaryRecoveryVersion;
1668 // MG-Tetra needs to know amount of memory it may use (MB).
1669 // Default memory is defined at MG-Tetra installation but it may be not enough,
1670 // so allow to use about all available memory
1672 float aMaximumMemory = hyp ? hyp->myMaximumMemory : -1;
1673 cmd += " --max_memory ";
1674 if ( aMaximumMemory < 0 ) cmd += SMESH_Comment( int( DefaultMaximumMemory() ));
1675 else cmd += SMESH_Comment( int( aMaximumMemory ));
1677 if ( auto_memory && !useBndRecovery ) {
1678 float aInitialMemory = hyp ? hyp->myInitialMemory : -1;
1679 cmd += " --automatic_memory ";
1680 if ( aInitialMemory > 0 ) cmd += SMESH_Comment( int( aInitialMemory ));
1683 // component to mesh
1684 if ( comp && !useBndRecovery ) {
1685 // We always run MG-Tetra with "to mesh holes'==TRUE (see PAL19680)
1686 if ( hasShapeToMesh )
1687 cmd += " --components all";
1689 bool aToMeshHoles = hyp ? hyp->myToMeshHoles : DefaultMeshHoles();
1690 if ( aToMeshHoles ) cmd += " --components all";
1691 else cmd += " --components outside_components";
1694 const bool toCreateNewNodes = ( no_int_points && ( !hyp || hyp->myToCreateNewNodes ));
1696 // optimization level
1697 if ( !toCreateNewNodes ) {
1698 cmd += " --optimisation_level none"; // issue 22608
1700 else if ( optim_level && hyp && !useBndRecovery ) {
1701 if ( hyp->myOptimizationLevel >= 0 && hyp->myOptimizationLevel < 5 ) {
1702 const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
1703 cmd += " --optimisation_level ";
1704 cmd += level[ hyp->myOptimizationLevel ];
1708 // to create internal nodes
1709 if ( no_int_points && !toCreateNewNodes ) {
1710 if ( forExecutable )
1711 cmd += " --no_internal_points";
1713 cmd += " --internalpoints no";
1717 if ( verbose && hyp ) {
1718 cmd += " --verbose " + SMESH_Comment( hyp->myVerboseLevel );
1721 // boundary recovery version
1722 // if ( useBndRecovery ) {
1726 // to use FEM correction
1727 // if ( fem && hyp && hyp->myToUseFemCorrection) {
1731 // to remove initial central point.
1732 if ( rem && hyp && hyp->myToRemoveCentralPoint ) {
1733 if ( forExecutable )
1734 cmd += " --no_initial_central_point";
1736 cmd += " --centralpoint no";
1740 // if ( hyp && !hyp->myTextOption.empty() ) {
1741 // cmd += " " + hyp->myTextOption;
1747 if ( hyp->GetMinSize() > 0 )
1748 cmd += " --min_size " + SMESH_Comment( hyp->GetMinSize() );
1749 if ( hyp->GetMaxSize() > 0 )
1750 cmd += " --max_size " + SMESH_Comment( hyp->GetMaxSize() );
1753 // to define volumic gradation.
1756 cmd += " --gradation " + SMESH_Comment( hyp->myGradation );
1762 if ( hyp->GetUseVolumeProximity() )
1764 cmd += " --volume_proximity_layers " + SMESH_Comment( hyp->GetNbVolumeProximityLayers() );
1767 std::string option, value;
1769 const TOptionValues* options[] = { & hyp->_option2value, & hyp->_customOption2value };
1770 for ( int iOp = 0; iOp < 2; ++iOp )
1772 TOptionValues::const_iterator o2v = options[iOp]->begin();
1773 for ( ; o2v != options[iOp]->end(); ++o2v )
1775 option = o2v->first;
1776 value = hyp->GetOptionValue( option, &isDefault );
1780 if ( value.empty() )//value == NoValue() )
1782 if ( hyp->_defaultOptionValues.count( option ))
1783 continue; // non-custom option with no value
1786 if ( strncmp( "no", option.c_str(), 2 ) == 0 ) // options w/o values: --no_*
1788 if ( !value.empty() && ToBool( value ) == false )
1792 if ( option[0] != '-' )
1796 cmd += option + " " + value;
1808 //================================================================================
1810 * \brief Return a unique file name
1812 //================================================================================
1814 std::string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hyp)
1816 std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
1817 const char lastChar = *aTmpDir.rbegin();
1819 if(lastChar != '\\') aTmpDir+='\\';
1821 if(lastChar != '/') aTmpDir+='/';
1824 TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
1825 aGenericName += "GHS3D_";
1826 aGenericName += getpid();
1827 aGenericName += "_";
1828 aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
1830 return aGenericName.ToCString();
1833 //================================================================================
1835 * Return the name of executable
1837 //================================================================================
1839 std::string GHS3DPlugin_Hypothesis::GetExeName()
1841 return "mg-tetra.exe";
1844 //================================================================================
1846 * \brief Return the enforced vertices
1848 //================================================================================
1850 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList GHS3DPlugin_Hypothesis::GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp)
1852 return hyp ? hyp->_GetEnforcedVertices(): TGHS3DEnforcedVertexList();
1855 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues GHS3DPlugin_Hypothesis::GetEnforcedVerticesCoordsSize (const GHS3DPlugin_Hypothesis* hyp)
1857 return hyp ? hyp->_GetEnforcedVerticesCoordsSize(): TGHS3DEnforcedVertexCoordsValues();
1860 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexEntryValues GHS3DPlugin_Hypothesis::GetEnforcedVerticesEntrySize (const GHS3DPlugin_Hypothesis* hyp)
1862 return hyp ? hyp->_GetEnforcedVerticesEntrySize(): TGHS3DEnforcedVertexEntryValues();
1865 GHS3DPlugin_Hypothesis::TCoordsGHS3DEnforcedVertexMap GHS3DPlugin_Hypothesis::GetEnforcedVerticesByCoords (const GHS3DPlugin_Hypothesis* hyp)
1867 return hyp ? hyp->_GetEnforcedVerticesByCoords(): TCoordsGHS3DEnforcedVertexMap();
1870 GHS3DPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap GHS3DPlugin_Hypothesis::GetEnforcedVerticesByEntry (const GHS3DPlugin_Hypothesis* hyp)
1872 return hyp ? hyp->_GetEnforcedVerticesByEntry(): TGeomEntryGHS3DEnforcedVertexMap();
1875 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap GHS3DPlugin_Hypothesis::GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp)
1877 return hyp ? hyp->_GetEnforcedNodes():TIDSortedNodeGroupMap();
1880 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap GHS3DPlugin_Hypothesis::GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp)
1882 return hyp ? hyp->_GetEnforcedEdges():TIDSortedElemGroupMap();
1885 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap GHS3DPlugin_Hypothesis::GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp)
1887 return hyp ? hyp->_GetEnforcedTriangles():TIDSortedElemGroupMap();
1890 GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp)
1892 return hyp ? hyp->_GetNodeIDToSizeMap(): TID2SizeMap();
1895 GHS3DPlugin_Hypothesis::TSetStrings GHS3DPlugin_Hypothesis::GetGroupsToRemove(const GHS3DPlugin_Hypothesis* hyp)
1897 return hyp ? hyp->_GetGroupsToRemove(): TSetStrings();
1901 //=============================================================================
1902 void GHS3DPlugin_Hypothesis::SetOptionValue(const std::string& optionName,
1903 const std::string& optionValue)
1905 TOptionValues::iterator op_val = _option2value.find(optionName);
1906 if (op_val == _option2value.end())
1908 op_val = _customOption2value.find( optionName );
1909 if ( op_val != _customOption2value.end() && op_val->second != optionValue )
1910 NotifySubMeshesHypothesisModification();
1911 _customOption2value[ optionName ] = optionValue;
1915 if (op_val->second != optionValue)
1917 const char* ptr = optionValue.c_str();
1918 // strip white spaces
1919 while (ptr[0] == ' ')
1921 int i = strlen(ptr);
1922 while (i != 0 && ptr[i - 1] == ' ')
1926 std::string typeName;
1929 } else if (_charOptions.count(optionName)) {
1930 // do not check strings
1931 } else if (_doubleOptions.count(optionName)) {
1932 // check if value is double
1933 ToDbl(ptr, &typeOk);
1935 } else if (_boolOptions.count(optionName)) {
1936 // check if value is bool
1937 ToBool(ptr, &typeOk);
1940 // check if value is int
1941 ToInt(ptr, &typeOk);
1942 typeName = "integer";
1944 if ( typeOk ) // check some specific values ?
1949 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
1950 throw std::invalid_argument(msg);
1952 std::string value( ptr, i );
1953 if ( _defaultOptionValues[ optionName ] == value )
1956 op_val->second = value;
1958 NotifySubMeshesHypothesisModification();
1962 //=============================================================================
1963 //! Return option value. If isDefault provided, it can be a default value,
1964 // then *isDefault == true. If isDefault is not provided, the value will be
1965 // empty if it equals a default one.
1966 std::string GHS3DPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
1967 bool* isDefault) const
1969 TOptionValues::const_iterator op_val = _option2value.find(optionName);
1970 if (op_val == _option2value.end())
1972 op_val = _customOption2value.find(optionName);
1973 if (op_val == _customOption2value.end())
1975 std::string msg = "Unknown MG-Tetra option: <" + optionName + ">";
1976 throw std::invalid_argument(msg);
1979 std::string val = op_val->second;
1980 if ( isDefault ) *isDefault = ( val.empty() );
1982 if ( val.empty() && isDefault )
1984 op_val = _defaultOptionValues.find( optionName );
1985 if (op_val != _defaultOptionValues.end())
1986 val = op_val->second;
1992 //=============================================================================
1993 bool GHS3DPlugin_Hypothesis::HasOptionDefined( const std::string& optionName ) const
1995 bool isDefault = false;
1998 GetOptionValue( optionName, &isDefault );
2000 catch ( std::invalid_argument& )
2007 //=============================================================================
2008 void GHS3DPlugin_Hypothesis::ClearOption(const std::string& optionName)
2010 TOptionValues::iterator op_val = _customOption2value.find(optionName);
2011 if (op_val != _customOption2value.end())
2012 _customOption2value.erase(op_val);
2014 op_val = _option2value.find(optionName);
2015 if (op_val != _option2value.end())
2016 op_val->second.clear();
2020 //=============================================================================
2021 GHS3DPlugin_Hypothesis::TOptionValues GHS3DPlugin_Hypothesis::GetOptionValues() const
2024 TOptionValues::const_iterator op_val = _option2value.begin();
2025 for ( ; op_val != _option2value.end(); ++op_val )
2026 vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
2031 //================================================================================
2033 * \brief Converts a string to a bool
2035 //================================================================================
2037 bool GHS3DPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
2039 std::string s = str;
2040 if ( isOk ) *isOk = true;
2042 for ( size_t i = 0; i <= s.size(); ++i )
2043 s[i] = tolower( s[i] );
2045 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
2048 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
2054 std::string msg = "Not a Boolean value:'" + str + "'";
2055 throw std::invalid_argument(msg);
2060 //================================================================================
2062 * \brief Converts a string to a real value
2064 //================================================================================
2066 double GHS3DPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
2068 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
2071 double val = strtod(&str[0], &endPtr);
2072 bool ok = (&str[0] != endPtr);
2074 if ( isOk ) *isOk = ok;
2078 std::string msg = "Not a real value:'" + str + "'";
2079 throw std::invalid_argument(msg);
2084 //================================================================================
2086 * \brief Converts a string to a integer value
2088 //================================================================================
2090 int GHS3DPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
2092 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
2095 int val = (int)strtol( &str[0], &endPtr, 10);
2096 bool ok = (&str[0] != endPtr);
2098 if ( isOk ) *isOk = ok;
2102 std::string msg = "Not an integer value:'" + str + "'";
2103 throw std::invalid_argument(msg);