]> SALOME platform Git repositories - plugins/netgenplugin.git/blob - src/NETGENPlugin/NETGENPlugin_DriverParam.cxx
Salome HOME
Now filling param _hypParameters and _stdMaxvolume
[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 "NETGENPlugin_Hypothesis.hxx"
30
31 #include <SMESH_Gen.hxx>
32 #include <StdMeshers_MaxElementVolume.hxx>
33
34 #include <iostream>
35 #include <fstream>
36 #include <string>
37 #include <cassert>
38
39 /**
40  * @brief Print content of a netgen_params
41  *
42  * @param aParams The object to display
43  */
44 void printNetgenParams(netgen_params& aParams){
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, SMESH_Gen *gen){
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   if(aParams.has_netgen_param){
137     aParams._hypParameters = new NETGENPlugin_Hypothesis(0, gen);
138
139     aParams._hypParameters->SetMaxSize(aParams.maxh);
140     aParams._hypParameters->SetMinSize(aParams.minh);
141     aParams._hypParameters->SetNbSegPerEdge(aParams.segmentsperedge);
142     aParams._hypParameters->SetGrowthRate(aParams.grading);
143     aParams._hypParameters->SetNbSegPerRadius(aParams.curvaturesafety);
144     aParams._hypParameters->SetSecondOrder(aParams.secondorder);
145     aParams._hypParameters->SetQuadAllowed(aParams.quad);
146     aParams._hypParameters->SetOptimize(aParams.optimize);
147     aParams._hypParameters->SetFineness((NETGENPlugin_Hypothesis::Fineness)aParams.fineness);
148     aParams._hypParameters->SetSurfaceCurvature(aParams.uselocalh);
149     aParams._hypParameters->SetFuseEdges(aParams.merge_solids);
150     aParams._hypParameters->SetChordalErrorEnabled(aParams.chordalError);
151     if(aParams.optimize){
152       aParams._hypParameters->SetNbSurfOptSteps(aParams.optsteps2d);
153       aParams._hypParameters->SetNbVolOptSteps(aParams.optsteps3d);
154     }
155     aParams._hypParameters->SetElemSizeWeight(aParams.elsizeweight);
156     aParams._hypParameters->SetWorstElemMeasure(aParams.opterrpow);
157     aParams._hypParameters->SetUseDelauney(aParams.delaunay);
158     aParams._hypParameters->SetCheckOverlapping(aParams.checkoverlap);
159     aParams._hypParameters->SetCheckChartBoundary(aParams.checkchartboundary);
160     aParams._hypParameters->SetMeshSizeFile(aParams.meshsizefilename);
161   }
162   if(aParams.has_maxelementvolume_hyp){
163     aParams._hypMaxElementVolume = new StdMeshers_MaxElementVolume(1, gen);
164   }
165   // TODO: Handle viscous layer
166 };
167
168 /**
169  * @brief Writes the content of a netgen_param into a file
170  *
171  * @param param_file the file
172  * @param aParams the object
173  */
174 void exportNetgenParams(const std::string param_file, netgen_params& aParams){
175   std::ofstream myfile(param_file);
176   myfile << aParams.has_netgen_param << std::endl;
177   myfile << aParams.maxh << std::endl;
178   myfile << aParams.minh << std::endl;
179   myfile << aParams.segmentsperedge << std::endl;
180   myfile << aParams.grading << std::endl;
181   myfile << aParams.curvaturesafety << std::endl;
182   myfile << aParams.secondorder << std::endl;
183   myfile << aParams.quad << std::endl;
184   myfile << aParams.optimize << std::endl;
185   myfile << aParams.fineness << std::endl;
186   myfile << aParams.uselocalh << std::endl;
187   myfile << aParams.merge_solids << std::endl;
188   myfile << aParams.chordalError << std::endl;
189   myfile << aParams.optsteps2d << std::endl;
190   myfile << aParams.optsteps3d << std::endl;
191   myfile << aParams.elsizeweight << std::endl;
192   myfile << aParams.opterrpow << std::endl;
193   myfile << aParams.delaunay << std::endl;
194   myfile << aParams.checkoverlap << std::endl;
195   myfile << aParams.checkchartboundary << std::endl;
196   myfile << aParams.closeedgefac << std::endl;
197   myfile << aParams.has_local_size << std::endl;
198   myfile << aParams.meshsizefilename << std::endl;
199   myfile << aParams.has_maxelementvolume_hyp << std::endl;
200   myfile << aParams.maxElementVolume << std::endl;
201   myfile << aParams.has_LengthFromEdges_hyp << std::endl;
202 };