Skip to content

Commit 47e6b31

Browse files
committed
New test and fix on BlockMeshingPropertyDelaunayTetgen
1 parent 33e6e2b commit 47e6b31

File tree

10 files changed

+303
-42
lines changed

10 files changed

+303
-42
lines changed

src/Core/protected/Topo/BlockMeshingPropertyDelaunayTetgen.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class BlockMeshingPropertyDelaunayTetgen : public BlockMeshingProperty {
3636
/// Constructeur pour la méthode de maillage d'un bloc avec le Delaunay de Tetgen
3737
BlockMeshingPropertyDelaunayTetgen(const DelaunayLaw delLaw = QC,
3838
const double val=2.0, const double val2 = 2.0, double ratio_pyramid_size=1.0)
39-
: m_law(delLaw), m_verbose(false), m_is_default(true), m_ratio_pyramid_size(ratio_pyramid_size)
39+
: m_law(delLaw), m_verbose(false), m_is_default(delLaw == QC && val==2.0 && val2==2.0 && ratio_pyramid_size==1.0), m_ratio_pyramid_size(ratio_pyramid_size)
4040
{
4141
if(m_law==QC){
4242
m_radius_edge_ratio=val;
@@ -63,7 +63,7 @@ class BlockMeshingPropertyDelaunayTetgen : public BlockMeshingProperty {
6363
m_radius_edge_ratio(radius_edge_ratio),
6464
m_max_volume(max_volume),
6565
m_verbose(false),
66-
m_is_default(true),
66+
m_is_default(m_radius_edge_ratio==2.0 && m_max_volume==2.0 && m_ratio_pyramid_size==1.0),
6767
m_ratio_pyramid_size(ratio_pyramid_size)
6868
{}
6969

@@ -176,7 +176,6 @@ class BlockMeshingPropertyDelaunayTetgen : public BlockMeshingProperty {
176176
#endif
177177

178178
private:
179-
180179
DelaunayLaw m_law;
181180

182181
// indique de passer en mode verbose pour remonter des informations de

test_link/test_command_edit_geom.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import math
12
import pyMagix3D as Mgx3D
23

3-
def test_command_join_entities(capfd):
4+
def test_command_join_entities():
45
ctx = Mgx3D.getStdContext()
56
ctx.clearSession() # Clean the session after the previous test
67
gm = ctx.getGeomManager ()
@@ -56,7 +57,7 @@ def test_command_join_entities(capfd):
5657
ctx.redo()
5758
assert gm.getNbCurves()==25
5859

59-
def test_command_scaling(capfd):
60+
def test_command_scaling():
6061
ctx = Mgx3D.getStdContext()
6162
ctx.clearSession() # Clean the session after the previous test
6263
gm = ctx.getGeomManager ()
@@ -93,7 +94,7 @@ def test_command_scaling(capfd):
9394
ctx.redo()
9495
assertPoint(gm, "Pt0001", 1, 1, 1)
9596

96-
def test_command_scaling_2(capfd):
97+
def test_command_scaling_2():
9798
ctx = Mgx3D.getStdContext()
9899
ctx.clearSession() # Clean the session after the previous test
99100
gm = ctx.getGeomManager ()
@@ -109,7 +110,7 @@ def test_command_scaling_2(capfd):
109110
gm.scale (["Vol0000"], 3.000000e+00)
110111
assertPoint(tm, "Som0006", 3, 3, 3)
111112

112-
def test_command_remove(capfd):
113+
def test_command_remove():
113114
ctx = Mgx3D.getStdContext()
114115
ctx.clearSession() # Clean the session after the previous test
115116
gm = ctx.getGeomManager ()
@@ -146,7 +147,17 @@ def test_command_remove(capfd):
146147
assert gm.getNbSurfaces()==3
147148
assert gm.getNbCurves()==10
148149

149-
def test_command_mirroring(capfd):
150+
def test_command_mirror():
151+
ctx = Mgx3D.getStdContext()
152+
ctx.clearSession() # Clean the session after the previous test
153+
gm = ctx.getGeomManager ()
154+
tm = ctx.getTopoManager()
155+
tm.newSphereWithTopo (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.HUITIEME, True, 0.5, 10, 10, "A")
156+
assertClosePoint(gm, "Pt0000", 0, 0, 1)
157+
gm.mirror(["Vol0000"], Mgx3D.Plane(Mgx3D.Point(0, 0, 0), Mgx3D.Vector(0, 0, 1)))
158+
assertClosePoint(gm, "Pt0000", 0, 0, -1)
159+
160+
def test_command_copy_mirror():
150161
#Ce test prend aussi en charge l'appel à CommandGeomCopy
151162
ctx = Mgx3D.getStdContext()
152163
ctx.clearSession() # Clean the session after the previous test
@@ -176,7 +187,7 @@ def test_command_mirroring(capfd):
176187
assert gm.getNbSurfaces()==17
177188
assert gm.getNbCurves()==32
178189

179-
def test_command_common(capfd):
190+
def test_command_common():
180191
ctx = Mgx3D.getStdContext()
181192
ctx.clearSession() # Clean the session after the previous test
182193
gm = ctx.getGeomManager ()
@@ -206,7 +217,7 @@ def test_command_common(capfd):
206217
assert gm.getNbSurfaces()==11
207218
assert gm.getNbCurves()==20
208219

209-
def test_command_common2d(capfd):
220+
def test_command_common2d():
210221
ctx = Mgx3D.getStdContext()
211222
ctx.clearSession() # Clean the session after the previous test
212223
gm = ctx.getGeomManager ()
@@ -240,4 +251,10 @@ def assertPoint(m, point, x, y, z):
240251
p = m.getCoord(point)
241252
assert p.getX() == x
242253
assert p.getY() == y
243-
assert p.getZ() == z
254+
assert p.getZ() == z
255+
256+
def assertClosePoint(m, point, x, y, z):
257+
p = m.getCoord(point)
258+
assert math.isclose(p.getX(), x, abs_tol=1e-15)
259+
assert math.isclose(p.getY(), y, abs_tol=1e-15)
260+
assert math.isclose(p.getZ(), z, abs_tol=1e-15)

test_link/test_groups.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22
import pyMagix3D as Mgx3D
33
import pytest
44

5+
def test_undo_hg():
6+
ctx = Mgx3D.getStdContext()
7+
ctx.clearSession() # Clean the session after the previous test
8+
9+
ctx.getGeomManager().newBox (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), "GGG")
10+
with pytest.raises(RuntimeError) as excinfo:
11+
ctx.getGroupManager().getInfos("Hors_Groupe_3D", 3)
12+
ctx.getGroupManager().clearGroup(3, "GGG")
13+
ctx.undo()
14+
#with pytest.raises(RuntimeError) as excinfo:
15+
# ctx.getGroupManager().getInfos("Hors_Groupe_3D", 3)
16+
17+
def test_set_topo_group():
18+
ctx = Mgx3D.getStdContext()
19+
ctx.clearSession() # Clean the session after the previous test
20+
ctx.getTopoManager().newBoxWithTopo (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), 10, 10, 10)
21+
with pytest.raises(RuntimeError) as excinfo:
22+
ctx.getTopoManager().setGroup(["Bl0000"], 3, "AAA")
23+
assert "Le groupe Hors_Groupe_3D ne contient pas Bl0000" in str(excinfo.value)
24+
525
def test_group_box():
626
ctx = Mgx3D.getStdContext()
727
ctx.clearSession() # Clean the session after the previous test
@@ -13,37 +33,45 @@ def test_group_box():
1333
coque = "Coque"
1434
ctx.getTopoManager().newBoxWithTopo (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), 10, 10, 10, acier)
1535
assert_all(ctx, "Bl0000", [acier])
16-
36+
37+
# Création d'une box avec topo sans groupe
1738
ctx.getTopoManager().newBoxWithTopo (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), 10, 10, 10)
1839
assert_all(ctx, "Bl0001", [hors_group])
40+
41+
# On ajoute le volume geom dans le groupe plastique
42+
# => le bloc topo est aussi dans le groupe plastique
1943
ctx.getGeomManager().addToGroup(["Vol0001"], 3, plastique)
2044
assert_all(ctx, "Bl0001", [plastique])
2145
ctx.undo()
2246
assert_all(ctx, "Bl0001", [hors_group])
2347
ctx.redo()
2448
assert_all(ctx, "Bl0001", [plastique])
2549

50+
# On affecte le volume geom dans le groupe coque
51+
# => le bloc topo est aussi et seulement dans le groupe coque
2652
ctx.getGeomManager().setGroup(["Vol0001"], 3, coque)
2753
assert_all(ctx, "Bl0001", [coque])
2854
ctx.undo()
2955
assert_all(ctx, "Bl0001", [plastique])
3056
ctx.redo()
3157
assert_all(ctx, "Bl0001", [coque])
32-
58+
59+
# On retire le volume geom du groupe coque
60+
# => le bloc topo est dans le groupe Hors_Groupe_3D
3361
ctx.getGeomManager().removeFromGroup(["Vol0001"], 3, coque)
3462
assert_all(ctx, "Bl0001", [hors_group])
3563
ctx.undo()
3664
assert_all(ctx, "Bl0001", [coque])
37-
65+
66+
# On détruit le groupe coque
67+
# => le bloc topo est dans le groupe Hors_Groupe_3D
3868
ctx.getGroupManager().clearGroup(3, coque)
3969
assert_all(ctx, "Bl0001", [hors_group])
4070
ctx.undo()
41-
#TODO Créer une issue
42-
#assert_all(ctx, "Bl0001", [coque])
71+
assert_all(ctx, "Bl0001", [coque])
4372

4473
ctx.getGeomManager().addToGroup(["Vol0001"], 3, plastique)
45-
#TODO Cf issue précédente
46-
#assert_all(ctx, "Bl0001", [plastique, coque])
74+
assert_all(ctx, "Bl0001", [plastique, coque])
4775

4876

4977
def assert_all(ctx, block, group_names):

test_link/test_ns_mesh.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ def test_ns_mesh_2(capfd):
7070
mm.newAllBlocksMesh()
7171

7272
assert gm.getNbVolumes() == 2
73-
assert mm.getNbFaces() < 1900
73+
assert mm.getNbFaces() < 1950
7474
assert mm.getNbFaces() > 1850
7575
out, err = capfd.readouterr()
7676
assert len(err) == 0
7777

78-
def test_ns_mesh_2(capfd):
78+
def test_ns_mesh_3(capfd):
7979
ctx = Mgx3D.getStdContext()
8080
ctx.clearSession() # Clean the session after the previous test
8181
gm = ctx.getGeomManager()
@@ -109,3 +109,21 @@ def test_block_on_box_union(capfd):
109109
assert gm.getNbVolumes() == 1
110110
out, err = capfd.readouterr()
111111
assert len(err) == 0
112+
113+
def test_block_on_cut_surface(capfd):
114+
ctx = Mgx3D.getStdContext()
115+
ctx.clearSession() # Clean the session after the previous test
116+
gm = ctx.getGeomManager()
117+
tm = ctx.getTopoManager()
118+
mm = ctx.getMeshManager()
119+
120+
gm.newBox(Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1))
121+
gm.newCylinder(Mgx3D.Point(0, 0, 0), 0.2, Mgx3D.Vector(1, 0, 0), 360)
122+
gm.translate(["Vol0001"], Mgx3D.Vector(0, 0.5, 0.5))
123+
gm.cut(["Vol0000"], ["Vol0001"])
124+
tm.newUnstructuredTopoOnGeometry("Vol0002")
125+
mm.newAllBlocksMesh()
126+
127+
assert gm.getNbVolumes() == 1
128+
out, err = capfd.readouterr()
129+
assert len(err) == 0

test_link/test_nsbox_cylinder.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import pyMagix3D as Mgx3D
2+
3+
# Maillage structuré du cylindre et non structuré du cube
4+
def test_nsbox_cylinder(capfd):
5+
ctx = Mgx3D.getStdContext()
6+
gm = ctx.getGeomManager()
7+
tm = ctx.getTopoManager()
8+
ctx.clearSession() # Clean the session after the previous test
9+
10+
# Création d'un cylindre avec une topologie
11+
tm.newCylinderWithTopo(Mgx3D.Point(0, 0, 0), .2, Mgx3D.Vector(1, 0, 0), 90, True, .5, 10, 10, 10, "A")
12+
# Création d'une boite
13+
gm.newBox(Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), "B")
14+
# Rotation d'une géométrie
15+
gm.rotate(["Vol0000"], Mgx3D.RotX(270))
16+
# Collage entre géométries
17+
gm.glue(["Vol0001", "Vol0000"])
18+
# Création d'un bloc topologique non structuré sur une géométrie
19+
tm.newUnstructuredTopoOnGeometry("Vol0002")
20+
# Création du maillage pour tous les blocs
21+
ctx.getMeshManager().newAllBlocksMesh()
22+
23+
out, err = capfd.readouterr()
24+
assert len(err) == 0
25+
26+
# Maillage non structuré du cylindre et du cube
27+
def test_nsbox_nscylinder(capfd):
28+
ctx = Mgx3D.getStdContext()
29+
gm = ctx.getGeomManager()
30+
tm = ctx.getTopoManager()
31+
ctx.clearSession() # Clean the session after the previous test
32+
33+
# Création d'une boite
34+
gm.newBox(Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1))
35+
# Création d'un cylindre
36+
gm.newCylinder(Mgx3D.Point(0, 0, 0), .2, Mgx3D.Vector(1, 0, 0), 360)
37+
# Rotation d'une géométrie
38+
gm.translate(["Vol0001"], Mgx3D.Vector(0.5, 0.5, 0.5))
39+
# Fusion booléennes entre géométries
40+
gm.fuse(["Vol0000", "Vol0001"])
41+
# Création d'un bloc topologique non structuré sur une géométrie
42+
tm.newUnstructuredTopoOnGeometry("Vol0002")
43+
# Création du maillage pour tous les blocs
44+
ctx.getMeshManager().newAllBlocksMesh()
45+
46+
out, err = capfd.readouterr()
47+
assert len(err) == 0

test_link/test_nsbox_scylinder.py

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import pyMagix3D as Mgx3D
2+
import pytest
3+
4+
def test_set_block_meshing_property(capfd):
5+
ctx = Mgx3D.getStdContext()
6+
ctx.clearSession() # Clean the session after the previous test
7+
gm = ctx.getGeomManager()
8+
tm = ctx.getTopoManager()
9+
10+
gm.newBox (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1))
11+
gm.newBox (Mgx3D.Point(1, 0, 0), Mgx3D.Point(2, 1, 1))
12+
gm.newBox (Mgx3D.Point(2, 0, 0), Mgx3D.Point(3, 1, 1))
13+
gm.newBox (Mgx3D.Point(3, 0, 0), Mgx3D.Point(4, 1, 1))
14+
15+
tm.newUnstructuredTopoOnGeometry("Vol0000")
16+
tm.newUnstructuredTopoOnGeometry("Vol0001")
17+
tm.newUnstructuredTopoOnGeometry("Vol0002")
18+
tm.newUnstructuredTopoOnGeometry("Vol0003")
19+
20+
tm.setMeshingProperty (Mgx3D.BlockMeshingPropertyDelaunayTetgen(Mgx3D.BlockMeshingPropertyDelaunayTetgen.Min), ["Bl0000"])
21+
tm.setMeshingProperty (Mgx3D.BlockMeshingPropertyDelaunayTetgen(Mgx3D.BlockMeshingPropertyDelaunayTetgen.QC, 0.8, 0.1), ["Bl0001"])
22+
tm.setMeshingProperty (Mgx3D.BlockMeshingPropertyDelaunayTetgen(Mgx3D.BlockMeshingPropertyDelaunayTetgen.QCRadius, 0.5), ["Bl0002"])
23+
tm.setMeshingProperty (Mgx3D.BlockMeshingPropertyDelaunayTetgen(Mgx3D.BlockMeshingPropertyDelaunayTetgen.QCMaxVol, 0.001), ["Bl0003"])
24+
25+
ctx.getMeshManager().newBlocksMesh(["Bl0000", "Bl0001", "Bl0002", "Bl0003"])
26+
27+
out, err = capfd.readouterr()
28+
assert len(err) == 0
29+
30+
def test_set_edge_meshing_property():
31+
ctx = Mgx3D.getStdContext()
32+
ctx.clearSession() # Clean the session after the previous test
33+
tm = ctx.getTopoManager()
34+
35+
tm.newBoxWithTopo (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1))
36+
emp = Mgx3D.EdgeMeshingPropertyUniform(12)
37+
tm.setMeshingProperty (emp, ["Ar0000"])
38+
39+
with pytest.raises(RuntimeError) as excinfo:
40+
ctx.getMeshManager().newAllBlocksMesh()
41+
assert "2 arêtes n'ont pas la même discrétisation" in str(excinfo.value)
42+
43+
def test_set_face_meshing_property(capfd):
44+
ctx = Mgx3D.getStdContext()
45+
ctx.clearSession() # Clean the session after the previous test
46+
gm = ctx.getGeomManager()
47+
tm = ctx.getTopoManager()
48+
49+
gm.newBox (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1))
50+
tm.newUnstructuredTopoOnGeometry("Vol0000")
51+
tm.setMeshingProperty (Mgx3D.FaceMeshingPropertyDelaunayGMSH(0.03, 0.07), ["Fa0005"])
52+
ctx.getMeshManager().newAllBlocksMesh()
53+
54+
out, err = capfd.readouterr()
55+
assert len(err) == 0

test_link/test_snap_vertices.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pyMagix3D as Mgx3D
2+
import pytest
3+
4+
def test_snap_vertices_1():
5+
ctx = Mgx3D.getStdContext()
6+
ctx.clearSession() # Clean the session after the previous test
7+
tm = ctx.getTopoManager()
8+
9+
tm.newBoxWithTopo (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), 10, 10, 10)
10+
tm.splitFace ("Fa0000", "Ar0001", .5, True)
11+
tm.splitBlocksWithOgridV2 (["Bl0000"], ["Fa0007","Fa0006","Fa0005","Fa0004"], .5, 10)
12+
with pytest.raises(RuntimeError) as excinfo:
13+
tm.snapVertices ("Fa0022", "Fa0021", True)
14+
assert "il n'est pas prévu pour le moment le cas avec plusieurs arêtes communes entre les sommets fusionnés" in str(excinfo.value)
15+
16+
def test_snap_vertices_2(capfd):
17+
ctx = Mgx3D.getStdContext()
18+
ctx.clearSession() # Clean the session after the previous test
19+
tm = ctx.getTopoManager()
20+
21+
tm.newIJBoxesWithTopo(1, 2, False)
22+
tm.snapVertices ("Ar0001", "Ar0003", True)
23+
tm.snapVertices ("Ar0013", "Ar0015", True)
24+
25+
out, err = capfd.readouterr()
26+
assert len(err) == 0

0 commit comments

Comments
 (0)