Skip to content

Commit 0ed938f

Browse files
committed
New tests
1 parent 5eb8991 commit 0ed938f

14 files changed

+447
-14
lines changed

test_link/test_align_vertices.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pyMagix3D as Mgx3D
2+
3+
def test_align_vertices(capfd):
4+
ctx = Mgx3D.getStdContext()
5+
ctx.clearSession() # Clean the session after the previous test
6+
tm = ctx.getTopoManager()
7+
8+
# Création d'une boite avec une topologie
9+
tm.newBoxWithTopo (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), 10, 10, 10)
10+
# Découpage de l'arête Ar0000
11+
tm.splitEdge("Ar0000", .5)
12+
assertPoint(tm, 0, 0, 0.5)
13+
# Translation de la topologie seule Som0008
14+
tm.translate (["Som0008"], Mgx3D.Vector(0, .2, 0), False)
15+
assertPoint(tm, 0, 0.2, 0.5)
16+
# Aligne des sommets topologiques sur une droite définie par 2 points
17+
tm.alignVertices(Mgx3D.Point(0, 0, 1), Mgx3D.Point(0, 0, 0), ["Som0008"])
18+
assertPoint(tm, 0, 0, 0.5)
19+
20+
def assertPoint(tm, x, y, z):
21+
p = tm.getCoord("Som0008")
22+
assert p.getX() == x
23+
assert p.getY() == y
24+
assert p.getZ() == z

test_link/test_boxes.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import pyMagix3D as Mgx3D
2+
3+
def test_one_hollow_box(capfd):
4+
ctx = Mgx3D.getStdContext()
5+
ctx.clearSession() # Clean the session after the previous test
6+
gm = ctx.getGeomManager()
7+
tm = ctx.getTopoManager()
8+
mm = ctx.getMeshManager()
9+
10+
# Création de la boite Vol0000
11+
gm.newBox (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), "B")
12+
# Création du cylindre Vol0001
13+
gm.newCylinder (Mgx3D.Point(.5, .5, 0), .2, Mgx3D.Vector(0, 0, 1), 3.600000e+02, "C")
14+
# Différences entre géométries avec plusieurs entités à couper
15+
gm.cut (["Vol0000"], ["Vol0001"])
16+
# Création d'un bloc topologique structuré sans projection (Vol0002)
17+
tm.newFreeTopoOnGeometry ("Vol0002")
18+
# Découpage en O-grid des blocs structurés Bl0000
19+
tm.splitBlocksWithOgridV2 (["Bl0000"], ["Fa0004","Fa0005"], .5, 5)
20+
# Destruction des entités topologiques Bl0005
21+
tm.destroy (["Bl0005"], True)
22+
# Affectation d'une projection vers Surf0006 pour les entités topologiques Fa0021 Fa0019 Fa0020 Fa0018
23+
tm.setGeomAssociation (["Fa0021","Fa0019","Fa0020","Fa0018"], "Surf0006", True)
24+
# Création du maillage pour tous les blocs
25+
mm.newAllBlocksMesh()
26+
27+
out, err = capfd.readouterr()
28+
assert len(err) == 0
29+
30+
def test_two_hollow_box(capfd):
31+
ctx = Mgx3D.getStdContext()
32+
ctx.clearSession() # Clean the session after the previous test
33+
gm = ctx.getGeomManager()
34+
tm = ctx.getTopoManager()
35+
mm = ctx.getMeshManager()
36+
37+
# Création de la boite Vol0000
38+
gm.newBox (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), "A")
39+
# Création d'une boite avec une topologie
40+
tm.newBoxWithTopo (Mgx3D.Point(1, 0, 0), Mgx3D.Point(2, 1, 1), 10, 10, 10, "B")
41+
# Collage entre géométries avec topologies
42+
gm.glue (["Vol0000","Vol0001"])
43+
# Création du cylindre Vol0002
44+
gm.newCylinder (Mgx3D.Point(.5, .5, 0), .2, Mgx3D.Vector(0, 0, 1), 3.600000e+02, "C")
45+
# Différences entre géométries avec plusieurs entités à couper
46+
gm.cut (["Vol0000"], ["Vol0002"])
47+
# Création d'un bloc topologique non structuré sur une géométrie (Vol0003)
48+
tm.newUnstructuredTopoOnGeometry ("Vol0003")
49+
# Création d'un cylindre avec une topologie
50+
tm.newCylinderWithTopo (Mgx3D.Point(1.5, .5, 0), .3, Mgx3D.Vector(0, 0, 1), 360, False, 1, 10, 10, 10, "I")
51+
# Création du maillage pour tous les blocs
52+
mm.newAllBlocksMesh()
53+
54+
out, err = capfd.readouterr()
55+
assert len(err) == 0
56+
57+
def test_split_blocks_with_ogrid(capfd):
58+
ctx = Mgx3D.getStdContext()
59+
ctx.clearSession() # Clean the session after the previous test
60+
gm = ctx.getGeomManager()
61+
tm = ctx.getTopoManager()
62+
mm = ctx.getMeshManager()
63+
64+
# Création d'une boite avec une topologie
65+
tm.newBoxWithTopo (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), 10, 10, 10)
66+
# Création d'une boite avec une topologie
67+
tm.newBoxWithTopo (Mgx3D.Point(1, 0, 0), Mgx3D.Point(2, 1, 1), 10, 10, 10)
68+
# Création d'une boite avec une topologie
69+
tm.newBoxWithTopo (Mgx3D.Point(2, 0, 0), Mgx3D.Point(3, 1, 1), 10, 10, 10)
70+
# Collage entre géométries avec topologies
71+
gm.glue (["Vol0000","Vol0001","Vol0002"])
72+
# Découpage en O-grid des blocs structurés Bl0000
73+
tm.splitBlocksWithOgridV2 (["Bl0000"], ["Fa0001","Fa0005","Fa0004"], .5, 10)
74+
# Création du maillage pour tous les blocs
75+
mm.newAllBlocksMesh()
76+
assert mm.getNbRegions() == 10000
77+
78+
out, err = capfd.readouterr()
79+
assert len(err) == 0

test_link/test_export_vtk.py

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,55 @@
11
import os
22
import pyMagix3D as Mgx3D
33

4-
vtkfilename = "box.vtk"
54

6-
def test_export_box():
5+
def test_export_box(capfd):
76
ctx = Mgx3D.getStdContext()
87
ctx.clearSession() # Clean the session after the previous test
9-
# Création de la boite Vol0000
8+
9+
vtkfilename = "box.vtk"
1010
ctx.getGeomManager().newBox (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1))
11-
# Création d'un bloc topologique non structuré sur une géométrie (Vol0000)
12-
ctx.getTopoManager().newUnstructuredTopoOnGeometry ("Vol0000")
13-
# Création du maillage pour toutes les faces
11+
ctx.getTopoManager().newUnstructuredTopoOnGeometry("Vol0000")
1412
ctx.getMeshManager().newAllFacesMesh()
1513
ctx.getGeomManager().exportVTK(vtkfilename)
14+
15+
assert os.path.exists(vtkfilename)
16+
assert os.path.getsize(vtkfilename) > 0
17+
out, err = capfd.readouterr()
18+
assert len(err) == 0
19+
20+
def test_export_cylinder(capfd):
21+
ctx = Mgx3D.getStdContext()
22+
ctx.clearSession() # Clean the session after the previous test
23+
24+
vtkfilename = "cylinder.vtk"
25+
ctx.getGeomManager().newCylinder(Mgx3D.Point(0.3, 0.5, 0.5), 0.4, Mgx3D.Vector(0.4, 0, 0), 360)
26+
ctx.getTopoManager().newUnstructuredTopoOnGeometry("Vol0000")
27+
ctx.getMeshManager().newAllFacesMesh()
28+
ctx.getGeomManager().exportVTK(vtkfilename)
29+
30+
assert os.path.exists(vtkfilename)
31+
assert os.path.getsize(vtkfilename) > 0
32+
out, err = capfd.readouterr()
33+
assert len(err) == 0
34+
35+
def test_export_imported_step(capfd):
36+
ctx = Mgx3D.getStdContext()
37+
ctx.clearSession() # Clean the session after the previous test
38+
39+
test_folder = os.path.dirname(__file__)
40+
step_file_path = os.path.join(test_folder, 'B0.step')
41+
# Import STEP
42+
# Changement d'unité de longueur
43+
ctx.setLengthUnit(Mgx3D.Unit.meter)
44+
# Import STEP
45+
ctx.getGeomManager().importSTEP(step_file_path)
46+
47+
vtkfilename = "B0.vtk"
48+
ctx.getTopoManager().newUnstructuredTopoOnGeometry("Vol0000")
49+
ctx.getMeshManager().newAllFacesMesh()
50+
ctx.getGeomManager().exportVTK(vtkfilename)
51+
1652
assert os.path.exists(vtkfilename)
1753
assert os.path.getsize(vtkfilename) > 0
54+
out, err = capfd.readouterr()
55+
assert len(err) == 0

test_link/test_get_entity_at.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,35 @@ def test_getVertexAt():
55
ctx = Mgx3D.getStdContext()
66
ctx.clearSession() # Clean the session after the previous test
77
gm = ctx.getGeomManager ()
8-
ctx.getGeomManager().newVertex (Mgx3D.Point(0, 0, 0))
8+
9+
gm.newVertex(Mgx3D.Point(0, 0, 0))
910
pt0 = gm.getVertexAt(Mgx3D.Point(0, 0, 0))
1011
assert pt0 == "Pt0000"
1112
pt1 = gm.getVertexAt(Mgx3D.Point(1e-14, 0, 0))
1213
assert pt1 == "Pt0000"
1314
with pytest.raises(RuntimeError) as excinfo:
1415
pt2 = gm.getVertexAt(Mgx3D.Point(1e-12, 0, 0))
1516
assert "getVertexAt impossible, on trouve 0 sommets" in str(excinfo.value)
17+
18+
def test_newVertex():
19+
ctx = Mgx3D.getStdContext()
20+
ctx.clearSession() # Clean the session after the previous test
21+
gm = ctx.getGeomManager ()
22+
23+
gm.newVertex(Mgx3D.Point(1, 2, 3)/100)
24+
c = gm.getCoord("Pt0000")
25+
assert c.getX() == 0.01
26+
assert c.getY() == 0.02
27+
assert c.getZ() == 0.03
28+
29+
def test_translate_vertex():
30+
ctx = Mgx3D.getStdContext()
31+
ctx.clearSession() # Clean the session after the previous test
32+
gm = ctx.getGeomManager ()
33+
34+
gm.newVertex(Mgx3D.Point(1, 0, 0))
35+
gm.translate(["Pt0000"], Mgx3D.Vector(0, 1, 0))
36+
c = gm.getCoord("Pt0000")
37+
assert c.getX() == 1
38+
assert c.getY() == 1
39+
assert c.getZ() == 0

test_link/test_ijk_boxes.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pyMagix3D as Mgx3D
2+
3+
def test_ij_boxes(capfd):
4+
ctx = Mgx3D.getStdContext()
5+
ctx.clearSession() # Clean the session after the previous test
6+
tm = ctx.getTopoManager()
7+
mm = ctx.getMeshManager()
8+
9+
tm.setDefaultNbMeshingEdges(100)
10+
tm.newIJBoxesWithTopo(5, 2, False)
11+
emp = Mgx3D.EdgeMeshingPropertyUniform(10)
12+
tm.setParallelMeshingProperty(emp, "Ar0000")
13+
mm.newAllBlocksMesh()
14+
assert mm.getNbRegions() == 1000000
15+
16+
out, err = capfd.readouterr()
17+
assert len(err) == 0
18+
19+
def test_ijk_boxes(capfd):
20+
ctx = Mgx3D.getStdContext()
21+
ctx.clearSession() # Clean the session after the previous test
22+
tm = ctx.getTopoManager()
23+
mm = ctx.getMeshManager()
24+
25+
tm.setDefaultNbMeshingEdges(100)
26+
tm.newIJKBoxesWithTopo(5, 5, 5, False)
27+
mm.newAllBlocksMesh()
28+
assert mm.getNbRegions() == 125000
29+
30+
out, err = capfd.readouterr()
31+
assert len(err) == 0

test_link/test_issue55.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pyMagix3D as Mgx3D
22

3-
def test_issue55():
3+
def test_issue55(capfd):
44
ctx = Mgx3D.getStdContext()
55
ctx.clearSession() # Clean the session after the previous test
66
tm = ctx.getTopoManager ()
@@ -11,5 +11,6 @@ def test_issue55():
1111
tm.splitEdge("Ar0033",.3)
1212
tm.splitEdge("Ar0035",.5)
1313
tm.splitBlocksWithOgridV2(["Bl0001","Bl0002"],[],.5,10)
14-
# Erreur de la commande Découpage en O-grid des blocs structurés Bl0001 Bl0002 avec le message :
15-
# Erreur interne dans CommandSplitBlocksWithOgrid::createEdge, pas d'arêtes interne face à 2 sommets (Som0016,Som0017)
14+
15+
out, err = capfd.readouterr()
16+
assert len(err) == 0

test_link/test_needle.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pyMagix3D as Mgx3D
2+
import pytest
3+
4+
def test_needle(capfd):
5+
ctx = Mgx3D.getStdContext()
6+
ctx.clearSession() # Clean the session after the previous test
7+
gm = ctx.getGeomManager()
8+
tm = ctx.getTopoManager()
9+
mm = ctx.getMeshManager()
10+
11+
angle = 5
12+
r1 = 0.5
13+
r2 = 0.6
14+
r3 = 0.7
15+
r4 = 0.8
16+
17+
# Création d'une aiguille pleine avec une topologie
18+
tm.newSpherePartWithTopo(r1, angle, angle, 5, 1, 1)
19+
# Création d'une aiguille creuse avec une topologie
20+
tm.newHollowSpherePartWithTopo(r1, r2, 5, 5, 1, 2, 2)
21+
# Création d'une aiguille creuse avec une topologie
22+
tm.newHollowSpherePartWithTopo(r2, r3, 5, 5, 1, 4, 4)
23+
# Création d'une aiguille creuse avec une topologie
24+
tm.newHollowSpherePartWithTopo(r3, r4, 5, 5, 1, 8, 8)
25+
# Collage
26+
gm.glue(gm.getVolumes())
27+
# Maillage
28+
mm.newAllBlocksMesh()
29+
assert mm.getNbRegions() == 89
30+
31+
out, err = capfd.readouterr()
32+
assert len(err) == 0
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pyMagix3D as Mgx3D
2+
3+
def test_new_subvolume_between_sheets(capfd):
4+
ctx = Mgx3D.getStdContext()
5+
ctx.clearSession() # Clean the session after the previous test
6+
tm = ctx.getTopoManager()
7+
mm = ctx.getMeshManager()
8+
9+
# Création d'un cylindre avec une topologie
10+
tm.newCylinderWithTopo (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Vector(10, 0, 0), 360, True, .5, 10, 10, 10, "CYL")
11+
# Création du maillage pour tous les blocs
12+
mm.newAllBlocksMesh()
13+
# Création volume entre 2 feuillets
14+
mm.newSubVolumeBetweenSheets ( ["Bl0000", "Bl0001", "Bl0002", "Bl0003", "Bl0004"], "Ar0010", 3, 5, "INT")
15+
16+
assert mm.getNbVolumes() == 2
17+
out, err = capfd.readouterr()
18+
assert len(err) == 0

test_link/test_ns_mesh.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pyMagix3D as Mgx3D
22

3-
def test_ns_mesh(capfd):
3+
def test_ns_mesh_1(capfd):
44
ctx = Mgx3D.getStdContext()
55
ctx.clearSession() # Clean the session after the previous test
66
gm = ctx.getGeomManager()
@@ -54,3 +54,39 @@ def test_ns_mesh(capfd):
5454
assert mm.getNbFaces() == 5828
5555
out, err = capfd.readouterr()
5656
assert len(err) == 0
57+
58+
def test_ns_mesh_2(capfd):
59+
ctx = Mgx3D.getStdContext()
60+
ctx.clearSession() # Clean the session after the previous test
61+
gm = ctx.getGeomManager()
62+
tm = ctx.getTopoManager()
63+
mm = ctx.getMeshManager()
64+
65+
gm.newBox(Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), "B")
66+
gm.newCylinder(Mgx3D.Point(0.4, 0, 0.4), .1, Mgx3D.Vector(0, 1, 0), 3.600000e+02, "C")
67+
gm.glue(["Vol0000", "Vol0001"])
68+
tm.newUnstructuredTopoOnGeometry("Vol0002")
69+
tm.newUnstructuredTopoOnGeometry("Vol0001")
70+
mm.newAllBlocksMesh()
71+
72+
assert gm.getNbVolumes() == 2
73+
out, err = capfd.readouterr()
74+
assert len(err) == 0
75+
76+
def test_block_on_box_union(capfd):
77+
ctx = Mgx3D.getStdContext()
78+
ctx.clearSession() # Clean the session after the previous test
79+
gm = ctx.getGeomManager()
80+
tm = ctx.getTopoManager()
81+
mm = ctx.getMeshManager()
82+
83+
gm.newBox(Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1))
84+
gm.newBox(Mgx3D.Point(1, 0, 0), Mgx3D.Point(2, 1, 1))
85+
gm.translate(["Vol0001"], Mgx3D.Vector(0, 0.5, 0.5))
86+
gm.fuse(["Vol0000", "Vol0001"])
87+
tm.newUnstructuredTopoOnGeometry("Vol0002")
88+
mm.newAllBlocksMesh()
89+
90+
assert gm.getNbVolumes() == 1
91+
out, err = capfd.readouterr()
92+
assert len(err) == 0

test_link/test_perturbation.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pyMagix3D as Mgx3D
2-
import pytest
2+
from math import *
3+
import os
34

45
def test_perturbation1(capfd):
56
ctx = Mgx3D.getStdContext()
@@ -50,11 +51,34 @@ def pert(x, y, z):
5051
ctx.getTopoManager().newBoxWithTopo (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), 10, 10, 10)
5152
# Modifie le groupe ZMAX
5253
ctx.getGeomManager().addToGroup (["Surf0005"], 2, "ZMAX")
53-
#ctx.getGroupManager().addCartesianPerturbation("ZMAX", pert)
54+
ctx.getGroupManager().addCartesianPerturbation("ZMAX", pert)
5455
# Création du maillage pour des faces
5556
ctx.getMeshManager().newFacesMesh ( ["Fa0005"] )
5657
# Sauvegarde du maillage (mli)
57-
ctx.getMeshManager().writeMli("perturbation3.mli2")
58+
mli_file_name = "perturbation3.mli2"
59+
ctx.getMeshManager().writeMli(mli_file_name)
60+
assert os.path.exists(mli_file_name)
61+
assert os.path.getsize(mli_file_name) > 0
5862

5963
out, err = capfd.readouterr()
6064
assert len(err) == 0
65+
66+
def test_perturbation4(capfd):
67+
ctx = Mgx3D.getStdContext()
68+
ctx.clearSession() # Clean the session after the previous test
69+
70+
def pert(r, t, p):
71+
return [ r*(1+cos(t*7)/20*cos(p*5)), t, p ]
72+
73+
ctx.getTopoManager().newSphereWithTopo(Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.QUART, True, .5, 10, 10)
74+
ctx.getGeomManager().addToGroup(["Surf0000"], 2, "EXT")
75+
ctx.getGroupManager().addPolarPerturbation("EXT", pert)
76+
ctx.getMeshManager().newFacesMesh(["Fa0010", "Fa0016", "Fa0022", "Fa0028"])
77+
mli_file_name = "perturbation4.mli2"
78+
ctx.getMeshManager().writeMli(mli_file_name)
79+
assert os.path.exists(mli_file_name)
80+
assert os.path.getsize(mli_file_name) > 0
81+
82+
out, err = capfd.readouterr()
83+
assert len(err) == 0
84+

0 commit comments

Comments
 (0)