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