]> SALOME platform Git repositories - plugins/netgenplugin.git/blob - src/NETGENPlugin/NETGENPlugin_DriverParam.cxx
Salome HOME
2ddf398a43e627c0e38b0a29db13c35a90b49f77
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_DriverParam.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, 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 #include <iostream>
30 #include <fstream>
31 #include <string>
32 #include <cassert>
33
34
35 // TODO: Error handling of read/write
36
37 /**
38  * @brief Print content of a netgen_params
39  *
40  * @param aParams The object to display
41  */
42 void printNetgenParams(netgen_params& aParams){
43   // TODO: prettier print
44   // TODO: Add call to print in log
45   std::cout << "has_netgen_param: " << aParams.has_netgen_param << std::endl;
46   std::cout << "maxh: " << aParams.maxh << std::endl;
47   std::cout << "minh: " << aParams.minh << std::endl;
48   std::cout << "segmentsperedge: " << aParams.segmentsperedge << std::endl;
49   std::cout << "grading: " << aParams.grading << std::endl;
50   std::cout << "curvaturesafety: " << aParams.curvaturesafety << std::endl;
51   std::cout << "secondorder: " << aParams.secondorder << std::endl;
52   std::cout << "quad: " << aParams.quad << std::endl;
53   std::cout << "optimize: " << aParams.optimize << std::endl;
54   std::cout << "fineness: " << aParams.fineness << std::endl;
55   std::cout << "uselocalh: " << aParams.uselocalh << std::endl;
56   std::cout << "merge_solids: " << aParams.merge_solids << std::endl;
57   std::cout << "chordalError: " << aParams.chordalError << std::endl;
58   std::cout << "optsteps2d: " << aParams.optsteps2d << std::endl;
59   std::cout << "optsteps3d: " << aParams.optsteps3d << std::endl;
60   std::cout << "elsizeweight: " << aParams.elsizeweight << std::endl;
61   std::cout << "opterrpow: " << aParams.opterrpow << std::endl;
62   std::cout << "delaunay: " << aParams.delaunay << std::endl;
63   std::cout << "checkoverlap: " << aParams.checkoverlap << std::endl;
64   std::cout << "checkchartboundary: " << aParams.checkchartboundary << std::endl;
65   std::cout << "closeedgefac: " << aParams.closeedgefac << std::endl;
66   std::cout << "has_local_size: " << aParams.has_local_size << std::endl;
67   std::cout << "meshsizefilename: " << aParams.meshsizefilename << std::endl;
68   std::cout << "has_maxelementvolume_hyp: " << aParams.has_maxelementvolume_hyp << std::endl;
69   std::cout << "maxElementVolume: " << aParams.maxElementVolume << std::endl;
70   std::cout << "has_LengthFromEdges_hyp: " << aParams.has_LengthFromEdges_hyp << std::endl;
71 }
72
73 /**
74  * @brief Import a param_file into a netgen_params structure
75  *
76  * @param param_file Name of the file
77  * @param aParams Structure to fill
78  */
79 void importNetgenParams(const std::string param_file, netgen_params& aParams){
80   std::ifstream myfile(param_file);
81   std::string line;
82
83   std::getline(myfile, line);
84   aParams.has_netgen_param = std::stoi(line);
85   std::getline(myfile, line);
86   aParams.maxh = std::stod(line);
87   std::getline(myfile, line);
88   aParams.minh = std::stod(line);
89   std::getline(myfile, line);
90   aParams.segmentsperedge = std::stod(line);
91   std::getline(myfile, line);
92   aParams.grading = std::stod(line);
93   std::getline(myfile, line);
94   aParams.curvaturesafety = std::stod(line);
95   std::getline(myfile, line);
96   aParams.secondorder = std::stoi(line);
97   std::getline(myfile, line);
98   aParams.quad = std::stoi(line);
99   std::getline(myfile, line);
100   aParams.optimize = std::stoi(line);
101   std::getline(myfile, line);
102   aParams.fineness = std::stoi(line);
103   std::getline(myfile, line);
104   aParams.uselocalh = std::stoi(line);
105   std::getline(myfile, line);
106   aParams.merge_solids = std::stoi(line);
107   std::getline(myfile, line);
108   aParams.chordalError = std::stod(line);
109   std::getline(myfile, line);
110   aParams.optsteps2d = std::stoi(line);
111   std::getline(myfile, line);
112   aParams.optsteps3d = std::stoi(line);
113   std::getline(myfile, line);
114   aParams.elsizeweight = std::stod(line);
115   std::getline(myfile, line);
116   aParams.opterrpow = std::stoi(line);
117   std::getline(myfile, line);
118   aParams.delaunay = std::stoi(line);
119   std::getline(myfile, line);
120   aParams.checkoverlap = std::stoi(line);
121   std::getline(myfile, line);
122   aParams.checkchartboundary = std::stoi(line);
123   std::getline(myfile, line);
124   aParams.closeedgefac = std::stoi(line);
125   std::getline(myfile, line);
126   aParams.has_local_size = std::stoi(line);
127   std::getline(myfile, line);
128   aParams.meshsizefilename = line;
129   std::getline(myfile, line);
130   aParams.has_maxelementvolume_hyp = std::stoi(line);
131   std::getline(myfile, line);
132   aParams.maxElementVolume = std::stod(line);
133   std::getline(myfile, line);
134   aParams.maxElementVolume = std::stoi(line);
135
136   myfile.close();
137 };
138
139 /**
140  * @brief Writes the content of a netgen_param into a file
141  *
142  * @param param_file the file
143  * @param aParams the object
144  */
145 void exportNetgenParams(const std::string param_file, netgen_params& aParams){
146   std::ofstream myfile(param_file);
147   myfile << aParams.has_netgen_param << std::endl;
148   myfile << aParams.maxh << std::endl;
149   myfile << aParams.minh << std::endl;
150   myfile << aParams.segmentsperedge << std::endl;
151   myfile << aParams.grading << std::endl;
152   myfile << aParams.curvaturesafety << std::endl;
153   myfile << aParams.secondorder << std::endl;
154   myfile << aParams.quad << std::endl;
155   myfile << aParams.optimize << std::endl;
156   myfile << aParams.fineness << std::endl;
157   myfile << aParams.uselocalh << std::endl;
158   myfile << aParams.merge_solids << std::endl;
159   myfile << aParams.chordalError << std::endl;
160   myfile << aParams.optsteps2d << std::endl;
161   myfile << aParams.optsteps3d << std::endl;
162   myfile << aParams.elsizeweight << std::endl;
163   myfile << aParams.opterrpow << std::endl;
164   myfile << aParams.delaunay << std::endl;
165   myfile << aParams.checkoverlap << std::endl;
166   myfile << aParams.checkchartboundary << std::endl;
167   myfile << aParams.closeedgefac << std::endl;
168   myfile << aParams.has_local_size << std::endl;
169   myfile << aParams.meshsizefilename << std::endl;
170   myfile << aParams.has_maxelementvolume_hyp << std::endl;
171   myfile << aParams.maxElementVolume << std::endl;
172   myfile << aParams.has_LengthFromEdges_hyp << std::endl;
173
174   myfile.close();
175 };
176
177 /**
178  * @brief Compares two netgen_parms object
179  *
180  * @param params1 Object 1
181  * @param params2 Object 2
182
183  * @return true if the two object are identical
184  */
185 bool diffNetgenParams(netgen_params params1, netgen_params params2){
186   bool ret = true;
187   ret &= params1.maxh == params2.maxh;
188   ret &= params1.minh == params2.minh;
189   ret &= params1.segmentsperedge == params2.segmentsperedge;
190   ret &= params1.grading == params2.grading;
191   ret &= params1.curvaturesafety == params2.curvaturesafety;
192   ret &= params1.secondorder == params2.secondorder;
193   ret &= params1.quad == params2.quad;
194   ret &= params1.optimize == params2.optimize;
195   ret &= params1.fineness == params2.fineness;
196   ret &= params1.uselocalh == params2.uselocalh;
197   ret &= params1.merge_solids == params2.merge_solids;
198   ret &= params1.chordalError == params2.chordalError;
199   ret &= params1.optsteps2d == params2.optsteps2d;
200   ret &= params1.optsteps3d == params2.optsteps3d;
201   ret &= params1.elsizeweight == params2.elsizeweight;
202   ret &= params1.opterrpow == params2.opterrpow;
203   ret &= params1.delaunay == params2.delaunay;
204   ret &= params1.checkoverlap == params2.checkoverlap;
205   ret &= params1.checkchartboundary == params2.checkchartboundary;
206   ret &= params1.closeedgefac == params2.closeedgefac;
207   ret &= params1.has_local_size == params2.has_local_size;
208   ret &= params1.meshsizefilename == params2.meshsizefilename;
209   ret &= params1.has_maxelementvolume_hyp == params2.has_maxelementvolume_hyp;
210   ret &= params1.maxElementVolume == params2.maxElementVolume;
211   ret &= params1.has_LengthFromEdges_hyp == params2.has_LengthFromEdges_hyp;
212
213   return ret;
214 }