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