Salome HOME
774c62dd269a0c3428320f78fb24fef75dd385d5
[plugins/ghs3dplugin.git] / src / GHS3DPlugin / GHS3DPlugin_OptimizerHypothesis.cxx
1 // Copyright (C) 2004-2021  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File      : GHS3DPlugin_OptimizerHypothesis.cxx
20 // Created   : Tue Nov  1 17:18:38 2016
21
22 #include "GHS3DPlugin_OptimizerHypothesis.hxx"
23
24 #include <SMESH_Gen.hxx>
25
26 GHS3DPlugin_OptimizerHypothesis::GHS3DPlugin_OptimizerHypothesis(int         hypId,
27                                                                  SMESH_Gen * gen)
28   :GHS3DPlugin_Hypothesis( hypId, gen ),
29    myOptimization( YES ),
30    mySplitOverConstrained( NO ),
31    mySmoothOffSlivers( false ),
32    myMaximalNumberOfThreads( 4 ),
33    myPThreadsMode( NONE )
34 {
35   _name = GetHypType();
36   _param_algo_dim = 3;
37 }
38
39 void GHS3DPlugin_OptimizerHypothesis::SetOptimization( Mode mode )
40 {
41   if ( myOptimization != mode )
42   {
43     myOptimization = mode;
44     NotifySubMeshesHypothesisModification();
45   }
46 }
47
48 GHS3DPlugin_OptimizerHypothesis::Mode GHS3DPlugin_OptimizerHypothesis::GetOptimization() const
49 {
50   return myOptimization;
51 }
52
53 void GHS3DPlugin_OptimizerHypothesis::SetSplitOverConstrained( Mode mode )
54 {
55   if ( mode != mySplitOverConstrained )
56   {
57     mySplitOverConstrained = mode;
58     NotifySubMeshesHypothesisModification();
59   }
60 }
61
62 GHS3DPlugin_OptimizerHypothesis::Mode GHS3DPlugin_OptimizerHypothesis::GetSplitOverConstrained() const
63 {
64   return mySplitOverConstrained;
65 }
66
67 void GHS3DPlugin_OptimizerHypothesis::SetSmoothOffSlivers( bool toSmooth )
68 {
69   if ( mySmoothOffSlivers != toSmooth )
70   {
71     mySmoothOffSlivers = toSmooth;
72     NotifySubMeshesHypothesisModification();
73   }
74 }
75
76 bool GHS3DPlugin_OptimizerHypothesis::GetSmoothOffSlivers() const
77 {
78   return mySmoothOffSlivers;
79 }
80
81 void GHS3DPlugin_OptimizerHypothesis::SetPThreadsMode( PThreadsMode mode )
82 {
83   if ( myPThreadsMode != mode )
84   {
85     myPThreadsMode = mode;
86     NotifySubMeshesHypothesisModification();
87   }
88 }
89
90 GHS3DPlugin_OptimizerHypothesis::PThreadsMode GHS3DPlugin_OptimizerHypothesis::GetPThreadsMode() const
91 {
92   return myPThreadsMode;
93 }
94
95 void GHS3DPlugin_OptimizerHypothesis::SetMaximalNumberOfThreads( int nb )
96 {
97   if ( myMaximalNumberOfThreads != nb )
98   {
99     myMaximalNumberOfThreads = nb;
100     NotifySubMeshesHypothesisModification();
101   }
102 }
103
104 int GHS3DPlugin_OptimizerHypothesis::GetMaximalNumberOfThreads() const
105 {
106   return myMaximalNumberOfThreads;
107 }
108
109
110 std::ostream & GHS3DPlugin_OptimizerHypothesis::SaveTo(std::ostream & save)
111 {
112   save << " " << (int)myOptimization
113        << " " << (int)mySplitOverConstrained
114        << " " << (int)mySmoothOffSlivers
115        << " " << (int)myMaximalNumberOfThreads
116        << " " << (int)myPThreadsMode << " ";
117
118   GHS3DPlugin_Hypothesis::SaveTo( save );
119
120   return save;
121 }
122
123 std::istream & GHS3DPlugin_OptimizerHypothesis::LoadFrom(std::istream & load)
124 {
125   int i;
126
127   if ( load >> i )
128     myOptimization = (Mode) i;
129   if ( load >> i )
130     mySplitOverConstrained = (Mode) i;
131   if ( load >> i )
132     mySmoothOffSlivers = (bool) i;
133   if ( load >> i )
134     myMaximalNumberOfThreads = i;
135   if ( load >> i )
136     myPThreadsMode = (PThreadsMode) i;
137
138   GHS3DPlugin_Hypothesis::LoadFrom( load );
139   return load;
140 }
141
142 bool GHS3DPlugin_OptimizerHypothesis::SetParametersByMesh(const SMESH_Mesh*   /*theMesh*/,
143                                                           const TopoDS_Shape& /*theShape*/)
144 {
145   return false;
146 }
147
148 bool GHS3DPlugin_OptimizerHypothesis::SetParametersByDefaults(const TDefaults&  /*theDflts*/,
149                                                               const SMESH_Mesh* /*theMesh*/)
150 {
151   return false;
152 }
153
154 std::string GHS3DPlugin_OptimizerHypothesis::CommandToRun(const GHS3DPlugin_OptimizerHypothesis* hyp)
155 {
156   SMESH_Comment cmd( GetExeName() );
157
158   cmd << " --max_memory "
159       << (( hyp && hyp->myMaximumMemory > 0 ) ? hyp->myMaximumMemory : DefaultMaximumMemory());
160
161   cmd << " --automatic_memory "
162       << (( hyp && hyp->myInitialMemory > 0 ) ? hyp->myInitialMemory : 100.0 );
163
164   if ( hyp )
165   {
166     const char* mode[3] = { "no", "yes", "only" };
167
168     if ( hyp->GetOptimization() >= 0 && hyp->GetOptimization() < 3 )
169       cmd << " --optimisation " << mode[ hyp->GetOptimization() ];
170
171     if ( hyp->myOptimizationLevel >= 0 && hyp->myOptimizationLevel < 5 ) {
172       const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
173       cmd << " --optimisation_level " << level[ hyp->myOptimizationLevel ];
174     }
175
176     if ( hyp->GetSplitOverConstrained() >= 0 && hyp->GetSplitOverConstrained() < 3 )
177       cmd << " --split_overconstrained_elements " << mode[ hyp->GetSplitOverConstrained() ];
178
179     if ( hyp->GetSmoothOffSlivers() )
180       cmd << " --smooth_off_slivers yes";
181
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;
187     default:;
188     }
189
190     if ( hyp->GetMaximalNumberOfThreads() > 0 )
191       cmd << " --max_number_of_threads " << hyp->GetMaximalNumberOfThreads();
192
193     if ( !hyp->myToCreateNewNodes )
194       cmd << " --no_internal_points";
195
196     cmd << " --verbose " << hyp->myVerboseLevel;
197     
198     //cmd << " " << hyp->myTextOption;
199   }
200
201   return cmd;
202 }