11 import GEOM, SMESH, SALOMEDS
13 from salome.geom import geomBuilder
14 from salome.smesh import smeshBuilder
18 smesh = smeshBuilder.New()
19 geompy = geomBuilder.New()
21 import medcoupling as mc
23 def create_simple2d_param_file_1D(param_file,segments,segLenght,maxArea):
24 """ Create a parameter file for runner """
29 0""".format(segments,segLenght,maxArea)
30 with open(param_file, "w") as ffile:
33 def create_simple2d3d_param_file_1D(param_file,segments,segLenght,maxArea,maxVolume):
34 """ Create a parameter file for runner """
40 0""".format(segments,segLenght,maxArea,maxVolume)
42 with open(param_file, "w") as ffile:
45 def CommonFunction(netgen,case,segments,segLenght,maxArea,maxVolume):
47 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
49 # Create 1D regular elements
50 mesh_1d = smesh.Mesh(box, 'Maillage_1')
51 mesh_1d.Segment().NumberOfSegments(1)
52 isDone = mesh_1d.Compute()
55 raise Exception("Error when computing Mesh")
57 smesh.SetName(mesh_1d, 'Maillage_1')
62 with tempfile.TemporaryDirectory() as tmp_dir:
63 mesh_file = path.join(tmp_dir, "mesh.med")
64 shape_file = path.join(tmp_dir, "shape.brep")
66 param_file = path.join(tmp_dir, "param_simple2D.txt")
68 param_file = path.join(tmp_dir, "param_simple3D.txt")
70 output_mesh = path.join(tmp_dir, "meshout.med")
72 print("Running in folder: ", tmp_dir)
75 create_simple2d_param_file_1D(param_file, segments, segLenght, maxArea )
77 create_simple2d3d_param_file_1D(param_file, segments, segLenght, maxArea, maxVolume )
79 mesh_1d.ExportMED(mesh_file, 0, 41, 1, mesh_1d, 1, [], '', -1, 1)
80 geompy.ExportBREP( box, shape_file )
82 runner = path.join("${NETGENPLUGIN_ROOT_DIR}",
85 "NETGENPlugin_Runner")
87 if sys.platform == 'win32':
90 cmd = "{runner} {NETGEN} {mesh_file} {shape_file} "\
91 "{param_file} NONE NONE {output_mesh}"\
92 .format(runner=runner,
95 shape_file=shape_file,
96 param_file=param_file,
97 output_mesh=output_mesh)
99 subprocess.check_call(cmd, shell=True)
100 mesh_read = mc.ReadUMeshFromFile(output_mesh, "MESH", 0)
101 nb_points = mesh_read.getNumberOfNodes()
103 nb_segments = mesh_read.getNumberOfCellsWithType(mc.NORM_SEG2)
105 nb_triangles = mesh_read.getNumberOfCellsWithType(mc.NORM_TRI3)
106 mesh_read = mc.ReadUMeshFromFile(output_mesh, "MESH", -1)
107 nb_segments = mesh_read.getNumberOfCellsWithType(mc.NORM_SEG2)
109 nb_tetras = mesh_read.getNumberOfCellsWithType(mc.NORM_TETRA4)
110 mesh_read = mc.ReadUMeshFromFile(output_mesh, "MESH", -1)
111 nb_triangles = mesh_read.getNumberOfCellsWithType(mc.NORM_TRI3)
112 mesh_read = mc.ReadUMeshFromFile(output_mesh, "MESH", -2)
113 nb_segments = mesh_read.getNumberOfCellsWithType(mc.NORM_SEG2)
115 return [nb_points,nb_segments,nb_triangles,nb_tetras]
118 [nb_points,nb_segments,nb_triangles,nb_tetras] = CommonFunction( "NETGEN1D", 1, 1, 200, 0.0, 0.0 )
120 print("Nb Points:", nb_points)
121 print("Nb Segments:", nb_segments)
123 assert nb_segments > 0
126 def test_netgen1d2d():
127 """ Test netgen1d2d mesher """
128 [nb_points,nb_segments,nb_triangles,nb_tetras] = CommonFunction( "NETGEN1D2D", 2, 1, 200, 0.0, 0.0 )
130 print("Nb Triangles:", nb_triangles)
131 print("Nb Segments:", nb_segments)
132 print("Nb Points:", nb_points)
134 assert nb_triangles == 12
136 assert nb_segments > 0
138 def test_netgen1d2dMaxArea():
139 """ Test netgen1d2d mesher """
140 [nb_points,nb_segments,nb_triangles, nb_tetras] = CommonFunction( "NETGEN1D2D", 2, 5, 200, 50.0, 0.0 )
142 print("Nb Triangles:", nb_triangles)
143 print("Nb Segments:", nb_segments)
144 print("Nb Points:", nb_points)
146 assert nb_triangles > 12
148 assert nb_segments > 0
151 def test_netgen1d2d3d():
152 """ Test netgen1d2d mesher """
153 [nb_points,nb_segments,nb_triangles,nb_tetras] = CommonFunction( "NETGEN1D2D3D", 3, 1, 200, 0.0, 0.0 )
155 print("Nb Tetras:", nb_tetras)
156 print("Nb Triangles:", nb_triangles)
157 print("Nb Segments:", nb_segments)
158 print("Nb Points:", nb_points)
160 assert nb_triangles == 12
161 assert nb_tetras == 5
163 assert nb_segments > 0
165 def test_netgen1d2dMaxVolume():
166 """ Test netgen1d2d mesher """
167 [nb_points,nb_segments,nb_triangles,nb_tetras] = CommonFunction( "NETGEN1D2D3D", 3, 1, 200, 500.0, 500.0 )
169 print("Nb Tetras:", nb_tetras)
170 print("Nb Triangles:", nb_triangles)
171 print("Nb Segments:", nb_segments)
172 print("Nb Points:", nb_points)
174 assert nb_triangles > 12
177 assert nb_segments > 0
179 if __name__ == "__main__":
180 if sys.platform == "win32":
181 print("Disabled on windows")
186 test_netgen1d2dMaxArea()
187 test_netgen1d2dMaxVolume()