1 // Copyright (C) 2004-2023 CEA, EDF
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
19 // File : GHS3DPlugin_OptimizerHypothesis.cxx
20 // Created : Tue Nov 1 17:18:38 2016
22 #include "GHS3DPlugin_OptimizerHypothesis.hxx"
24 #include <SMESH_Gen.hxx>
26 GHS3DPlugin_OptimizerHypothesis::GHS3DPlugin_OptimizerHypothesis(int hypId,
28 :GHS3DPlugin_Hypothesis( hypId, gen ),
29 myOptimization( YES ),
30 mySplitOverConstrained( NO ),
31 mySmoothOffSlivers( false ),
32 myMaximalNumberOfThreads( 4 ),
33 myPThreadsMode( NONE )
39 void GHS3DPlugin_OptimizerHypothesis::SetOptimization( Mode mode )
41 if ( myOptimization != mode )
43 myOptimization = mode;
44 NotifySubMeshesHypothesisModification();
48 GHS3DPlugin_OptimizerHypothesis::Mode GHS3DPlugin_OptimizerHypothesis::GetOptimization() const
50 return myOptimization;
53 void GHS3DPlugin_OptimizerHypothesis::SetSplitOverConstrained( Mode mode )
55 if ( mode != mySplitOverConstrained )
57 mySplitOverConstrained = mode;
58 NotifySubMeshesHypothesisModification();
62 GHS3DPlugin_OptimizerHypothesis::Mode GHS3DPlugin_OptimizerHypothesis::GetSplitOverConstrained() const
64 return mySplitOverConstrained;
67 void GHS3DPlugin_OptimizerHypothesis::SetSmoothOffSlivers( bool toSmooth )
69 if ( mySmoothOffSlivers != toSmooth )
71 mySmoothOffSlivers = toSmooth;
72 NotifySubMeshesHypothesisModification();
76 bool GHS3DPlugin_OptimizerHypothesis::GetSmoothOffSlivers() const
78 return mySmoothOffSlivers;
81 void GHS3DPlugin_OptimizerHypothesis::SetPThreadsMode( PThreadsMode mode )
83 if ( myPThreadsMode != mode )
85 myPThreadsMode = mode;
86 NotifySubMeshesHypothesisModification();
90 GHS3DPlugin_OptimizerHypothesis::PThreadsMode GHS3DPlugin_OptimizerHypothesis::GetPThreadsMode() const
92 return myPThreadsMode;
95 void GHS3DPlugin_OptimizerHypothesis::SetMaximalNumberOfThreads( int nb )
97 if ( myMaximalNumberOfThreads != nb )
99 myMaximalNumberOfThreads = nb;
100 NotifySubMeshesHypothesisModification();
104 int GHS3DPlugin_OptimizerHypothesis::GetMaximalNumberOfThreads() const
106 return myMaximalNumberOfThreads;
110 std::ostream & GHS3DPlugin_OptimizerHypothesis::SaveTo(std::ostream & save)
112 save << " " << (int)myOptimization
113 << " " << (int)mySplitOverConstrained
114 << " " << (int)mySmoothOffSlivers
115 << " " << (int)myMaximalNumberOfThreads
116 << " " << (int)myPThreadsMode << " ";
118 GHS3DPlugin_Hypothesis::SaveTo( save );
123 std::istream & GHS3DPlugin_OptimizerHypothesis::LoadFrom(std::istream & load)
128 myOptimization = (Mode) i;
130 mySplitOverConstrained = (Mode) i;
132 mySmoothOffSlivers = (bool) i;
134 myMaximalNumberOfThreads = i;
136 myPThreadsMode = (PThreadsMode) i;
138 GHS3DPlugin_Hypothesis::LoadFrom( load );
142 bool GHS3DPlugin_OptimizerHypothesis::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
143 const TopoDS_Shape& /*theShape*/)
148 bool GHS3DPlugin_OptimizerHypothesis::SetParametersByDefaults(const TDefaults& /*theDflts*/,
149 const SMESH_Mesh* /*theMesh*/)
154 std::string GHS3DPlugin_OptimizerHypothesis::CommandToRun(const GHS3DPlugin_OptimizerHypothesis* hyp)
156 SMESH_Comment cmd( GetExeName( (ImplementedAlgorithms) 1 ) );
158 cmd << " --max_memory "
159 << (( hyp && hyp->myMaximumMemory > 0 ) ? hyp->myMaximumMemory : DefaultMaximumMemory());
161 cmd << " --automatic_memory "
162 << (( hyp && hyp->myInitialMemory > 0 ) ? hyp->myInitialMemory : 100.0 );
166 const char* mode[3] = { "no", "yes", "only" };
168 if ( hyp->GetOptimization() >= 0 && hyp->GetOptimization() < 3 )
169 cmd << " --optimisation " << mode[ hyp->GetOptimization() ];
171 if ( hyp->myOptimizationLevel >= 0 && hyp->myOptimizationLevel < 5 ) {
172 const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
173 cmd << " --optimisation_level " << level[ hyp->myOptimizationLevel ];
176 if ( hyp->GetSplitOverConstrained() >= 0 && hyp->GetSplitOverConstrained() < 3 )
177 cmd << " --split_overconstrained_elements " << mode[ hyp->GetSplitOverConstrained() ];
179 if ( hyp->GetSmoothOffSlivers() )
180 cmd << " --smooth_off_slivers yes";
182 switch ( hyp->GetPThreadsMode() ) {
183 case GHS3DPlugin_OptimizerHypothesis::SAFE:
184 cmd << " --pthreads_mode safe"; break;
185 case GHS3DPlugin_OptimizerHypothesis::AGGRESSIVE:
186 cmd << " --pthreads_mode aggressive"; break;
190 if ( hyp->GetMaximalNumberOfThreads() > 0 )
191 cmd << " --max_number_of_threads " << hyp->GetMaximalNumberOfThreads();
193 if ( !hyp->myToCreateNewNodes )
194 cmd << " --no_internal_points";
196 cmd << " --verbose " << hyp->myVerboseLevel;
198 //cmd << " " << hyp->myTextOption;