From: Yoann Audouin Date: Wed, 14 Sep 2022 14:36:10 +0000 (+0200) Subject: Adding tests for netgen_runner and parallel compute X-Git-Tag: V9_10_0b1~9^2~18 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3a97cee0d22316af9d2c8e25902b12292cb923ec;p=modules%2Fsmesh.git Adding tests for netgen_runner and parallel compute --- diff --git a/test/netgen_runner.py b/test/netgen_runner.py new file mode 100644 index 000000000..9740b2676 --- /dev/null +++ b/test/netgen_runner.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +import sys +import salome + +salome.salome_init() + +from os import path +import tempfile +import subprocess + +import GEOM, SMESH, SALOMEDS + +from salome.geom import geomBuilder +from salome.smesh import smeshBuilder + +import math + +smesh = smeshBuilder.New() +geompy = geomBuilder.New() + +import medcoupling as mc + +def create_param_file(param_file): + """ Create a parameter file for runner """ + param="""1 +34.64 +0.14 +16 +0.15 +1.5 +0 +0 +1 +5 +1 +1 +-1 +3 +3 +0.2 +2 +1 +0 +0 +2 +0 + +0 +0""" + with open(param_file, "w") as ffile: + ffile.write(param) + + +def test_netgen3d(): + """ Test netgen3d mesher """ + # Building geometry + box = geompy.MakeBoxDXDYDZ(200, 200, 200) + + geompy.ExtractShapes(box, geompy.ShapeType["FACE"], True) + Groupe_1 = geompy.CreateGroup(box, geompy.ShapeType["FACE"]) + geompy.UnionIDs(Groupe_1, [3, 13, 23, 27, 31, 33]) + + # TODO: useful ? + [_, _, _, _, _, _, Groupe_1] = geompy.GetExistingSubObjects(box, False) + + # Creating 2D mesh + NETGEN_2D_Parameters_1 = smesh.CreateHypothesisByAverageLength( + 'NETGEN_Parameters_2D', 'NETGENEngine', 34.641, 0) + Mesh2D = smesh.Mesh(Groupe_1, 'Maillage_1') + status = Mesh2D.AddHypothesis(Groupe_1, NETGEN_2D_Parameters_1) + NETGEN_1D_2D = Mesh2D.Triangle(algo=smeshBuilder.NETGEN_1D2D) + isDone = Mesh2D.Compute() + smesh.SetName(Mesh2D, 'Maillage_1') + + # tmp_dir = tempfile.mkdtemp() + with tempfile.TemporaryDirectory() as tmp_dir: + mesh_file = path.join(tmp_dir, "mesh.med") + shape_file = path.join(tmp_dir, "shape.step") + param_file = path.join(tmp_dir, "param.txt") + output_mesh = path.join(tmp_dir, "mesh3D.med") + + print("Running in folder: ", tmp_dir) + create_param_file(param_file) + + Mesh2D.ExportMED(mesh_file, 0, 41, 1, Mesh2D, 1, [], '', -1, 1) + geompy.ExportSTEP(box, shape_file, GEOM.LU_METER) + + runner = path.join("${NETGENPLUGIN_ROOT_DIR}", + "bin", + "salome", + "NETGENPlugin_Runner") + + cmd = "{runner} NETGEN3D {mesh_file} {shape_file} "\ + "{param_file} NONE 2 NONE {output_mesh}"\ + .format(runner=runner, + mesh_file=mesh_file, + shape_file=shape_file, + param_file=param_file, + output_mesh=output_mesh) + print(cmd) + subprocess.check_call(cmd, shell=True) + + meshRead = mc.ReadUMeshFromFile (output_mesh, "Maillage_1", 0) + + nbTetras = meshRead.getNumberOfCellsWithType(mc.NORM_TETRA4) + nbPoints = meshRead.getNumberOfNodes() + + meshRead = mc.ReadUMeshFromFile (output_mesh, "Maillage_1", -1) + nbTriangles = meshRead.getNumberOfCellsWithType(mc.NORM_TRI3) + + meshRead = mc.ReadUMeshFromFile (output_mesh, "Maillage_1", -2) + nbSegments = meshRead.getNumberOfCellsWithType(mc.NORM_SEG2) + + print("Nb Tetras:", nbTetras) + print("Nb Triangles:", nbTriangles) + print("Nb Segments:", nbSegments) + print("Nb Points:", nbPoints) + + assert(nbPoints > 0) + assert(nbSegments > 0) + assert(nbTriangles > 0) + assert(nbTetras > 0) + +if __name__ == "__main__": + test_netgen3d() diff --git a/test/tests.set b/test/tests.set index fddb00249..4664c6a51 100644 --- a/test/tests.set +++ b/test/tests.set @@ -63,6 +63,7 @@ SET(BAD_TESTS SMESH_test2.py SMESH_test4.py SMESH_create_dual_mesh_adapt.py + netgen_runner.py ) IF(NOT WIN32) LIST(APPEND BAD_TESTS