1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : run_mesher.cxx
24 // Author : Yoann AUDOUIN, EDF
28 #include "DriverStep.hxx"
29 #include "DriverMesh.hxx"
30 #include "netgen_param.hxx"
31 #include "netgen_mesher.hxx"
33 #include <SMESH_Mesh.hxx>
34 #include <SMESH_Gen.hxx>
36 #include <TopoDS_Shape.hxx>
42 * @brief Test of shape Import/Export
48 std::cout << "Testing Shape Import/Export" << std::endl;
49 std::string shape_file = "box.step";
53 // Test 1 import -> export cmp files
54 std::string shape_file2 = "/tmp/shape.step";
56 import_shape(shape_file, myShape);
57 export_shape(shape_file2, myShape);
59 assert(diff_step_file(shape_file, shape_file2));
61 // Test 2 import->export->import cmp TopoDS_Shape
62 std::string shape_file3 = "/tmp/shape2.step";
63 TopoDS_Shape myShape1, myShape2;
65 import_shape(shape_file, myShape1);
67 export_shape(shape_file3, myShape1);
69 import_shape(shape_file3, myShape2);
71 // TODO: See why this does not work
72 // TShape seems to be different
73 //assert(myShape1.IsSame(myShape2));
78 * @brief test of mesh import/export
84 std::cout << "Testing Mesh Import/Export" << std::endl;
85 std::string mesh_file = "box.med";
88 SMESH_Mesh *myMesh = gen.CreateMesh(false);
89 std::string mesh_name = "Maillage_1";
91 // Test 1 import -> export cmp files
92 std::string mesh_file2 = "/tmp/mesh.med";
94 import_mesh(mesh_file, *myMesh, mesh_name);
95 export_mesh(mesh_file2, *myMesh, mesh_name);
97 assert(diff_med_file(mesh_file, mesh_file2, mesh_name));
99 // TODO: Compare the two med files via dump ?
101 // Test 2 import->export->import cmp TopoDS_Shape
102 std::string mesh_file3 = "/tmp/mesh2.med";
103 SMESH_Mesh *myMesh1 = gen.CreateMesh(false);
104 SMESH_Mesh *myMesh2 = gen.CreateMesh(false);
106 import_mesh(mesh_file, *myMesh1, mesh_name);
108 export_mesh(mesh_file3, *myMesh1, mesh_name);
110 import_mesh(mesh_file3, *myMesh2, mesh_name);
112 // TODO: Compare SMESH_Mesh
113 //assert(myMesh1==myMesh2);
117 * @brief Test of import/export of netgen param
120 void test_netgen_params(){
122 std::string param_file = "/tmp/netgen_param.txt";
123 netgen_params myParams, myParams2;
124 myParams.has_netgen_param = true;
125 myParams.maxh = 34.64;
126 myParams.minh = 0.14;
127 myParams.segmentsperedge = 15;
128 myParams.grading = 0.2;
129 myParams.curvaturesafety = 1.5;
130 myParams.secondorder = false;
131 myParams.quad = false;
132 myParams.optimize = true;
133 myParams.fineness = 5;
134 myParams.uselocalh = true;
135 myParams.merge_solids = true;
136 myParams.chordalError = -1;
137 myParams.optsteps2d = 3;
138 myParams.optsteps3d = 3;
139 myParams.elsizeweight = 0.2;
140 myParams.opterrpow = 2;
141 myParams.delaunay = true;
142 myParams.checkoverlap = true;
143 myParams.checkchartboundary = false;
144 myParams.closeedgefac = 2;
145 myParams.has_local_size = false;
146 myParams.meshsizefilename = "";
147 myParams.has_maxelementvolume_hyp = false;
148 myParams.maxElementVolume = 0.0;
150 export_netgen_params(param_file, myParams);
151 import_netgen_params(param_file, myParams2);
153 assert(diff_netgen_params(myParams, myParams2));
157 void test_netgen3d(){
159 std::cout << "Testing NETGEN 3D mesher" << std::endl;
160 netgen3d("box_partial2D1D-2.med",
163 "element_orient.dat",
169 // TODO: Check result
173 * @brief Main function
175 * @param argc Number of arguments
176 * @param argv Arguments
180 int main(int argc, char *argv[]){
182 if(argc!=10||(argc==2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help")==0))){
183 std::cout << "Error in number of argument"<<std::endl;
184 std::cout << "Syntax:"<<std::endl;
185 std::cout << "run_mesher MESHER INPUT_MESH_FILE SHAPE_FILE HYPO_FILE" << std::endl;
186 std::cout << " ELEM_ORIENT_FILE NB_THREADS" << std::endl;
187 std::cout << " NEW_ELEMENT_FILE OUTPUT_MESH_FILE" << std::endl;
188 std::cout << std::endl;
189 std::cout << "Args:" << std::endl;
190 std::cout << " MESHER: mesher to use from (NETGEN3D, NETGEN2D)" << std::endl;
191 std::cout << " INPUT_MESH_FILE: MED File containing lower-dimension-elements already meshed" << std::endl;
192 std::cout << " SHAPE_FILE: STEP file containing the shape to mesh" << std::endl;
193 std::cout << " HYPO_FILE: Ascii file containint the list of parameters" << std::endl;
194 std::cout << " ELEM_ORIENT_FILE: binary file containing the list of element from INPUT_MESH_FILE associated to the shape and their orientation" << std::endl;
195 std::cout << " NB_THREADS: Number of thread to use for the mesher" << std::endl;
196 std::cout << " NEW_ELEMENT_FILE: (out) contains elements and nodes added by the meshing" << std::endl;
197 std::cout << " OUTPUT_MESH: If !=0 will export mesh into OUTPUT_MESH_FILE " << std::endl;
198 std::cout << " OUTPUT_MESH_FILE: MED File containing the mesh after the run of the mesher" << std::endl;
201 std::string mesher=argv[1];
202 std::string input_mesh_file=argv[2];
203 std::string shape_file=argv[3];
204 std::string hypo_file=argv[4];
205 std::string element_orientation_file=argv[5];
206 int nbThreads=std::stoi(argv[6]);
207 std::string new_element_file=argv[7];
208 bool output_mesh = std::stoi(argv[8]) != 0;
209 std::string output_mesh_file=argv[9];
212 std::cout << "Running tests" << std::endl;
215 test_netgen_params();
217 } else if (mesher=="NETGEN3D"){
218 auto begin = std::chrono::high_resolution_clock::now();
219 netgen3d(input_mesh_file,
222 element_orientation_file,
227 auto end = std::chrono::high_resolution_clock::now();
228 auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
229 std::cout << "Time elapsed: " << elapsed.count()*1e-9 << std::endl;
230 } else if (mesher=="NETGEN2D"){
231 netgen2d(input_mesh_file,
234 element_orientation_file,
239 std::cerr << "Unknown mesher:" << mesher << std::endl;