1 // Copyright (C) 2004-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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,
29 :GHS3DPlugin_Hypothesis( hypId, studyId, gen ),
30 myOptimization( YES ),
31 mySplitOverConstrained( NO ),
32 mySmoothOffSlivers( false ),
33 myMaximalNumberOfThreads( 4 ),
34 myPThreadsMode( NONE )
40 void GHS3DPlugin_OptimizerHypothesis::SetOptimization( Mode mode )
42 if ( myOptimization != mode )
44 myOptimization = mode;
45 NotifySubMeshesHypothesisModification();
49 GHS3DPlugin_OptimizerHypothesis::Mode GHS3DPlugin_OptimizerHypothesis::GetOptimization() const
51 return myOptimization;
54 void GHS3DPlugin_OptimizerHypothesis::SetSplitOverConstrained( Mode mode )
56 if ( mode != mySplitOverConstrained )
58 mySplitOverConstrained = mode;
59 NotifySubMeshesHypothesisModification();
63 GHS3DPlugin_OptimizerHypothesis::Mode GHS3DPlugin_OptimizerHypothesis::GetSplitOverConstrained() const
65 return mySplitOverConstrained;
68 void GHS3DPlugin_OptimizerHypothesis::SetSmoothOffSlivers( bool toSmooth )
70 if ( mySmoothOffSlivers != toSmooth )
72 mySmoothOffSlivers = toSmooth;
73 NotifySubMeshesHypothesisModification();
77 bool GHS3DPlugin_OptimizerHypothesis::GetSmoothOffSlivers() const
79 return mySmoothOffSlivers;
82 void GHS3DPlugin_OptimizerHypothesis::SetPThreadsMode( PThreadsMode mode )
84 if ( myPThreadsMode != mode )
86 myPThreadsMode = mode;
87 NotifySubMeshesHypothesisModification();
91 GHS3DPlugin_OptimizerHypothesis::PThreadsMode GHS3DPlugin_OptimizerHypothesis::GetPThreadsMode() const
93 return myPThreadsMode;
96 void GHS3DPlugin_OptimizerHypothesis::SetMaximalNumberOfThreads( int nb )
98 if ( myMaximalNumberOfThreads != nb )
100 myMaximalNumberOfThreads = nb;
101 NotifySubMeshesHypothesisModification();
105 int GHS3DPlugin_OptimizerHypothesis::GetMaximalNumberOfThreads() const
107 return myMaximalNumberOfThreads;
111 std::ostream & GHS3DPlugin_OptimizerHypothesis::SaveTo(std::ostream & save)
113 save << " " << (int)myOptimization
114 << " " << (int)mySplitOverConstrained
115 << " " << (int)mySmoothOffSlivers
116 << " " << (int)myMaximalNumberOfThreads
117 << " " << (int)myPThreadsMode << " ";
119 GHS3DPlugin_Hypothesis::SaveTo( save );
124 std::istream & GHS3DPlugin_OptimizerHypothesis::LoadFrom(std::istream & load)
129 myOptimization = (Mode) i;
131 mySplitOverConstrained = (Mode) i;
133 mySmoothOffSlivers = (bool) i;
135 myMaximalNumberOfThreads = i;
137 myPThreadsMode = (PThreadsMode) i;
139 GHS3DPlugin_Hypothesis::LoadFrom( load );
143 bool GHS3DPlugin_OptimizerHypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
144 const TopoDS_Shape& theShape)
149 bool GHS3DPlugin_OptimizerHypothesis::SetParametersByDefaults(const TDefaults& theDflts,
150 const SMESH_Mesh* theMesh)
155 std::string GHS3DPlugin_OptimizerHypothesis::CommandToRun(const GHS3DPlugin_OptimizerHypothesis* hyp)
157 SMESH_Comment cmd( GetExeName() );
161 const char* mode[3] = { "no", "yes", "only" };
163 if ( hyp->GetOptimization() >= 0 && hyp->GetOptimization() < 3 )
164 cmd << " --optimisation " << mode[ hyp->GetOptimization() ];
166 if ( hyp->myOptimizationLevel >= 0 && hyp->myOptimizationLevel < 5 ) {
167 const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
168 cmd << " --optimisation_level " << level[ hyp->myOptimizationLevel ];
171 if ( hyp->GetSplitOverConstrained() >= 0 && hyp->GetSplitOverConstrained() < 3 )
172 cmd << " --split_overconstrained_elements " << mode[ hyp->GetSplitOverConstrained() ];
174 if ( hyp->GetSmoothOffSlivers() )
175 cmd << " --smooth_off_slivers yes";
177 switch ( hyp->GetPThreadsMode() ) {
178 case GHS3DPlugin_OptimizerHypothesis::SAFE:
179 cmd << " --pthreads_mode safe"; break;
180 case GHS3DPlugin_OptimizerHypothesis::AGGRESSIVE:
181 cmd << " --pthreads_mode aggressive"; break;
185 if ( hyp->GetMaximalNumberOfThreads() > 0 )
186 cmd << " --max_number_of_threads " << hyp->GetMaximalNumberOfThreads();
188 if ( !hyp->myToCreateNewNodes )
189 cmd << " --no_internal_points";
191 if ( hyp->myMaximumMemory > 0 )
192 cmd << " --max_memory " << hyp->myMaximumMemory;
194 if ( hyp->myInitialMemory > 0 )
195 cmd << " --automatic_memory " << hyp->myInitialMemory;
197 cmd << " --verbose " << hyp->myVerboseLevel;
199 cmd << " " << hyp->myTextOption;