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>
40 * @brief Test of shape Import/Export
46 std::cout << "Testing Shape Import/Export" << std::endl;
47 std::string shape_file = "box.step";
51 // Test 1 import -> export cmp files
52 std::string shape_file2 = "/tmp/shape.step";
54 import_shape(shape_file, myShape);
55 export_shape(shape_file2, myShape);
57 assert(diff_step_file(shape_file, shape_file2));
59 // Test 2 import->export->import cmp TopoDS_Shape
60 std::string shape_file3 = "/tmp/shape2.step";
61 TopoDS_Shape myShape1, myShape2;
63 import_shape(shape_file, myShape1);
65 export_shape(shape_file3, myShape1);
67 import_shape(shape_file3, myShape2);
69 // TODO: See why this does not work
70 // TShape seems to be different
71 //assert(myShape1.IsSame(myShape2));
76 * @brief test of mesh import/export
82 std::cout << "Testing Mesh Import/Export" << std::endl;
83 std::string mesh_file = "box.med";
86 SMESH_Mesh *myMesh = gen.CreateMesh(false);
87 std::string mesh_name = "Maillage_1";
89 // Test 1 import -> export cmp files
90 std::string mesh_file2 = "/tmp/mesh.med";
92 import_mesh(mesh_file, *myMesh, mesh_name);
93 export_mesh(mesh_file2, *myMesh, mesh_name);
95 assert(diff_med_file(mesh_file, mesh_file2, mesh_name));
97 // TODO: Compare the two med files via dump ?
99 // Test 2 import->export->import cmp TopoDS_Shape
100 std::string mesh_file3 = "/tmp/mesh2.med";
101 SMESH_Mesh *myMesh1 = gen.CreateMesh(false);
102 SMESH_Mesh *myMesh2 = gen.CreateMesh(false);
104 import_mesh(mesh_file, *myMesh1, mesh_name);
106 export_mesh(mesh_file3, *myMesh1, mesh_name);
108 import_mesh(mesh_file3, *myMesh2, mesh_name);
110 // TODO: Compare SMESH_Mesh
111 //assert(myMesh1==myMesh2);
115 * @brief Test of import/export of netgen param
118 void test_netgen_params(){
120 std::string param_file = "/tmp/netgen_param.txt";
121 netgen_params myParams, myParams2;
122 myParams.has_netgen_param = true;
123 myParams.maxh = 34.64;
124 myParams.minh = 0.14;
125 myParams.segmentsperedge = 15;
126 myParams.grading = 0.2;
127 myParams.curvaturesafety = 1.5;
128 myParams.secondorder = false;
129 myParams.quad = false;
130 myParams.optimize = true;
131 myParams.fineness = 5;
132 myParams.uselocalh = true;
133 myParams.merge_solids = true;
134 myParams.chordalError = -1;
135 myParams.optsteps2d = 3;
136 myParams.optsteps3d = 3;
137 myParams.elsizeweight = 0.2;
138 myParams.opterrpow = 2;
139 myParams.delaunay = true;
140 myParams.checkoverlap = true;
141 myParams.checkchartboundary = false;
142 myParams.closeedgefac = 2;
143 myParams.has_local_size = false;
144 myParams.meshsizefilename = "";
145 myParams.has_maxelementvolume_hyp = false;
146 myParams.maxElementVolume = 0.0;
148 export_netgen_params(param_file, myParams);
149 import_netgen_params(param_file, myParams2);
151 assert(diff_netgen_params(myParams, myParams2));
155 void test_netgen3d(){
157 std::cout << "Testing NETGEN 3D mesher" << std::endl;
158 netgen3d("box_partial2D1D-2.med",
161 "element_orient.dat",
166 // TODO: Check result
170 * @brief Main function
172 * @param argc Number of arguments
173 * @param argv Arguments
177 int main(int argc, char *argv[]){
179 if(argc!=9||(argc==2 && (argv[1] == "-h" || argv[1]=="--help"))){
180 std::cout << "Error in number of argument"<<std::endl;
181 std::cout << "Syntax:"<<std::endl;
182 std::cout << "run_mesher MESHER INPUT_MESH_FILE SHAPE_FILE HYPO_FILE" << std::endl;
183 std::cout << " ELEM_ORIENT_FILE NEW_ELEMENT_FILE OUTPUT_MESH_FILE" << std::endl;
184 std::cout << std::endl;
185 std::cout << "Args:" << std::endl;
186 std::cout << " MESHER: mesher to use from (NETGEN3D)" << std::endl;
187 std::cout << " INPUT_MESH_FILE: MED File containing lower-dimension-elements already meshed" << std::endl;
188 std::cout << " SHAPE_FILE: STEP file containing the shape to mesh" << std::endl;
189 std::cout << " HYPO_FILE: Ascii file containint the list of parameters" << std::endl;
190 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;
191 std::cout << " NEW_ELEMENT_FILE: (out) contains elements and nodes added by the meshing" << std::endl;
192 std::cout << " OUTPUT_MESH: If !=0 will export mesh into OUTPUT_MESH_FILE " << std::endl;
193 std::cout << " OUTPUT_MESH_FILE: MED File containing the mesh after the run of the mesher" << std::endl;
196 std::string mesher=argv[1];
197 std::string input_mesh_file=argv[2];
198 std::string shape_file=argv[3];
199 std::string hypo_file=argv[4];
200 std::string element_orientation_file=argv[5];
201 std::string new_element_file=argv[6];
202 bool output_mesh = std::stoi(argv[7]) != 0;
203 std::string output_mesh_file=argv[8];
206 std::cout << "Running tests" << std::endl;
209 test_netgen_params();
211 } else if (mesher=="NETGEN3D"){
212 netgen3d(input_mesh_file,
215 element_orientation_file,
220 std::cerr << "Unknown mesher:" << mesher << std::endl;