]> SALOME platform Git repositories - plugins/netgenplugin.git/blob - src/NETGENPlugin/NETGENPlugin_DriverParam.cxx
Salome HOME
Merge branch 'V9_13_BR'
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_DriverParam.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  File   : NETGENPlugin_DriverParam.hxx
24 //  Author : Yoann AUDOUIN, EDF
25 //  Module : NETGEN
26 //
27 #include "NETGENPlugin_DriverParam.hxx"
28
29
30 #include <iostream>
31 #include <fstream>
32 #include <string>
33 #include <cassert>
34
35 /**
36  * @brief Print content of a netgen_params
37  *
38  * @param aParams The object to display
39  */
40 void printNetgenParams(netgen_params& aParams){
41   if ( aParams.myType == Hypo )
42   {
43     std::cout << "has_netgen_param: " << aParams.has_netgen_param << std::endl;
44     std::cout << "maxh: " << aParams.maxh << std::endl;
45     std::cout << "minh: " << aParams.minh << std::endl;
46     std::cout << "segmentsperedge: " << aParams.segmentsperedge << std::endl;
47     std::cout << "grading: " << aParams.grading << std::endl;
48     std::cout << "curvaturesafety: " << aParams.curvaturesafety << std::endl;
49     std::cout << "secondorder: " << aParams.secondorder << std::endl;
50     std::cout << "quad: " << aParams.quad << std::endl;
51     std::cout << "optimize: " << aParams.optimize << std::endl;
52     std::cout << "fineness: " << aParams.fineness << std::endl;
53     std::cout << "uselocalh: " << aParams.uselocalh << std::endl;
54     std::cout << "merge_solids: " << aParams.merge_solids << std::endl;
55     std::cout << "chordalError: " << aParams.chordalError << std::endl;
56     std::cout << "optsteps2d: " << aParams.optsteps2d << std::endl;
57     std::cout << "optsteps3d: " << aParams.optsteps3d << std::endl;
58     std::cout << "elsizeweight: " << aParams.elsizeweight << std::endl;
59     std::cout << "opterrpow: " << aParams.opterrpow << std::endl;
60     std::cout << "delaunay: " << aParams.delaunay << std::endl;
61     std::cout << "checkoverlap: " << aParams.checkoverlap << std::endl;
62     std::cout << "checkchartboundary: " << aParams.checkchartboundary << std::endl;
63     std::cout << "closeedgefac: " << aParams.closeedgefac << std::endl;
64     std::cout << "nbThreadMesher: " << aParams.nbThreads << std::endl;
65     std::cout << "has_local_size: " << aParams.has_local_size << std::endl;
66     std::cout << "meshsizefilename: " << aParams.meshsizefilename << std::endl;
67     std::cout << "has_maxelementvolume_hyp: " << aParams.has_maxelementvolume_hyp << std::endl;
68     std::cout << "maxElementVolume: " << aParams.maxElementVolume << std::endl;
69     std::cout << "has_LengthFromEdges_hyp: " << aParams.has_LengthFromEdges_hyp << std::endl;
70   }
71 }
72
73 void importDefaultNetgenParams(const std::string param_file, netgen_params& aParams)
74 {
75   std::ifstream myfile(param_file);
76   std::string line;
77   // set the default type!
78   aParams.myType = Hypo;
79
80   std::getline(myfile, line);
81   aParams.has_netgen_param = std::stoi(line);
82   std::getline(myfile, line);
83   aParams.maxh = std::stod(line);
84   std::getline(myfile, line);
85   aParams.minh = std::stod(line);
86   std::getline(myfile, line);
87   aParams.segmentsperedge = std::stod(line);
88   std::getline(myfile, line);
89   aParams.grading = std::stod(line);
90   std::getline(myfile, line);
91   aParams.curvaturesafety = std::stod(line);
92   std::getline(myfile, line);
93   aParams.secondorder = std::stoi(line);
94   std::getline(myfile, line);
95   aParams.quad = std::stoi(line);
96   std::getline(myfile, line);
97   aParams.optimize = std::stoi(line);
98   std::getline(myfile, line);
99   aParams.fineness = std::stoi(line);
100   std::getline(myfile, line);
101   aParams.uselocalh = std::stoi(line);
102   std::getline(myfile, line);
103   aParams.merge_solids = std::stoi(line);
104   std::getline(myfile, line);
105   aParams.chordalError = std::stod(line);
106   std::getline(myfile, line);
107   aParams.optsteps2d = std::stoi(line);
108   std::getline(myfile, line);
109   aParams.optsteps3d = std::stoi(line);
110   std::getline(myfile, line);
111   aParams.elsizeweight = std::stod(line);
112   std::getline(myfile, line);
113   aParams.opterrpow = std::stoi(line);
114   std::getline(myfile, line);
115   aParams.delaunay = std::stoi(line);
116   std::getline(myfile, line);
117   aParams.checkoverlap = std::stoi(line);
118   std::getline(myfile, line);
119   aParams.checkchartboundary = std::stoi(line);
120   std::getline(myfile, line);
121   aParams.closeedgefac = std::stoi(line);
122   std::getline(myfile, line);
123   aParams.nbThreads = std::stoi(line);
124   std::getline(myfile, line);
125   aParams.has_local_size = std::stoi(line);
126   std::getline(myfile, line);
127   aParams.meshsizefilename = line;
128   std::getline(myfile, line);
129   aParams.has_maxelementvolume_hyp = std::stoi(line);
130   std::getline(myfile, line);
131   aParams.maxElementVolume = std::stod(line);
132   std::getline(myfile, line);
133   aParams.maxElementVolume = std::stoi(line);
134   myfile.close();
135 }
136
137 void importSimple2D3DNetgenParams(const std::string param_file, netgen_params& aParams, bool is3D )
138 {
139   std::ifstream myfile(param_file);
140   std::string line;
141
142   aParams.myType = !is3D ? Simple2D : Simple3D;
143   std::getline(myfile, line);
144   aParams.has_netgen_param = std::stoi(line); // 1
145   std::getline(myfile, line);
146   aParams.numberOfSegments = std::stoi(line); // segments      (int)
147   std::getline(myfile, line);
148   aParams.localLength = std::stod(line);      // localLenght  (double)
149   std::getline(myfile, line);
150   aParams.maxElementArea = std::stod(line);   // max area     (double)
151   if ( is3D )
152   {
153     std::getline(myfile, line);
154     aParams.maxElementVol = std::stod(line); // max volume    (double)
155   }    
156   std::getline(myfile, line);
157   aParams.allowQuadrangles = std::stoi(line); // int
158
159   myfile.close();
160 };
161
162 /**
163  * @brief Import a param_file into a netgen_params structure
164  *
165  * @param param_file Name of the file
166  * @param aParams Structure to fill
167  */
168 void importNetgenParams(const std::string param_file, netgen_params& aParams){
169   
170   if ( param_file.find("simple2D") != std::string::npos || param_file.find("simple3D") != std::string::npos /*support simple 2D && 3D*/ )
171   {
172     importSimple2D3DNetgenParams( param_file, aParams, bool(param_file.find("simple3D") != std::string::npos) );
173   }
174   else if ( param_file.find("maxarea") == std::string::npos && param_file.find("lenghtfromedge") == std::string::npos /*hypo file for 2D SA*/)
175   {
176     importDefaultNetgenParams( param_file, aParams );
177   }
178   else
179   {
180     aParams.has_netgen_param = false;
181   }
182 };
183
184 /**
185  * @brief Writes the content of a netgen_param into a file
186  *
187  * @param param_file the file
188  * @param aParams the object
189  */
190 void exportNetgenParams(const std::string param_file, netgen_params& aParams){
191   if ( aParams.myType == Hypo ){
192     std::ofstream myfile(param_file);
193     myfile << aParams.has_netgen_param << std::endl;
194     myfile << aParams.maxh << std::endl;
195     myfile << aParams.minh << std::endl;
196     myfile << aParams.segmentsperedge << std::endl;
197     myfile << aParams.grading << std::endl;
198     myfile << aParams.curvaturesafety << std::endl;
199     myfile << aParams.secondorder << std::endl;
200     myfile << aParams.quad << std::endl;
201     myfile << aParams.optimize << std::endl;
202     myfile << aParams.fineness << std::endl;
203     myfile << aParams.uselocalh << std::endl;
204     myfile << aParams.merge_solids << std::endl;
205     myfile << aParams.chordalError << std::endl;
206     myfile << aParams.optsteps2d << std::endl;
207     myfile << aParams.optsteps3d << std::endl;
208     myfile << aParams.elsizeweight << std::endl;
209     myfile << aParams.opterrpow << std::endl;
210     myfile << aParams.delaunay << std::endl;
211     myfile << aParams.checkoverlap << std::endl;
212     myfile << aParams.checkchartboundary << std::endl;
213     myfile << aParams.closeedgefac << std::endl;
214     myfile << aParams.nbThreads << std::endl;
215     myfile << aParams.has_local_size << std::endl;
216     myfile << aParams.meshsizefilename << std::endl;
217     myfile << aParams.has_maxelementvolume_hyp << std::endl;
218     myfile << aParams.maxElementVolume << std::endl;
219     myfile << aParams.has_LengthFromEdges_hyp << std::endl;
220   }
221   else if ( aParams.myType == Simple2D )
222   {
223     // TODO: Export the 2D && 3D simple versions
224   }
225 };