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_param_file(param_file):
24 """ Create a parameter file for runner """
50 with open(param_file, "w") as ffile:
55 """ Test netgen3d mesher """
57 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
59 geompy.ExtractShapes(box, geompy.ShapeType["FACE"], True)
60 Groupe_1 = geompy.CreateGroup(box, geompy.ShapeType["FACE"])
61 geompy.UnionIDs(Groupe_1, [3, 13, 23, 27, 31, 33])
64 [_, _, _, _, _, _, Groupe_1] = geompy.GetExistingSubObjects(box, False)
67 NETGEN_2D_Parameters_1 = smesh.CreateHypothesisByAverageLength(
68 'NETGEN_Parameters_2D', 'NETGENEngine', 34.641, 0)
69 Mesh2D = smesh.Mesh(Groupe_1, 'Maillage_1')
70 status = Mesh2D.AddHypothesis(Groupe_1, NETGEN_2D_Parameters_1)
71 NETGEN_1D_2D = Mesh2D.Triangle(algo=smeshBuilder.NETGEN_1D2D)
72 isDone = Mesh2D.Compute()
73 smesh.SetName(Mesh2D, 'Maillage_1')
75 # tmp_dir = tempfile.mkdtemp()
76 with tempfile.TemporaryDirectory() as tmp_dir:
77 mesh_file = path.join(tmp_dir, "mesh.med")
78 shape_file = path.join(tmp_dir, "shape.step")
79 param_file = path.join(tmp_dir, "param.txt")
80 output_mesh = path.join(tmp_dir, "mesh3D.med")
82 print("Running in folder: ", tmp_dir)
83 create_param_file(param_file)
85 Mesh2D.ExportMED(mesh_file, 0, 41, 1, Mesh2D, 1, [], '', -1, 1)
86 geompy.ExportSTEP(box, shape_file, GEOM.LU_METER)
88 runner = path.join("${NETGENPLUGIN_ROOT_DIR}",
91 "NETGENPlugin_Runner")
93 cmd = "{runner} NETGEN3D {mesh_file} {shape_file} "\
94 "{param_file} NONE 2 NONE {output_mesh}"\
95 .format(runner=runner,
97 shape_file=shape_file,
98 param_file=param_file,
99 output_mesh=output_mesh)
101 subprocess.check_call(cmd, shell=True)
103 meshRead = mc.ReadUMeshFromFile (output_mesh, "MESH", 0)
105 nbTetras = meshRead.getNumberOfCellsWithType(mc.NORM_TETRA4)
106 nbPoints = meshRead.getNumberOfNodes()
108 meshRead = mc.ReadUMeshFromFile (output_mesh, "MESH", -1)
109 nbTriangles = meshRead.getNumberOfCellsWithType(mc.NORM_TRI3)
111 meshRead = mc.ReadUMeshFromFile (output_mesh, "MESH", -2)
112 nbSegments = meshRead.getNumberOfCellsWithType(mc.NORM_SEG2)
114 print("Nb Tetras:", nbTetras)
115 print("Nb Triangles:", nbTriangles)
116 print("Nb Segments:", nbSegments)
117 print("Nb Points:", nbPoints)
120 assert(nbSegments > 0)
121 assert(nbTriangles > 0)
124 if __name__ == "__main__":