Salome HOME
Merge changes from 'master' branch.
[plugins/blsurfplugin.git] / tests / quadrangles_gradation.py
1 # -*- coding: utf-8 -*-
2
3 import salome
4
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New()
8
9 import math
10
11 area_tolerance = 0.1
12 nb_faces_tolerance = 20
13
14 ## Return the min and max areas of a mesh
15 def getMinMaxArea(mesh):
16   mini, maxi = mesh.GetMinMax(SMESH.FT_Area)
17   return mini, maxi
18
19 O = geompy.MakeVertex(0, 0, 0)
20 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
21 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
22 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
23
24 Face_1 = geompy.MakeFaceHW(10, 10, 1)
25 geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
26 Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 )
27 vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True)
28 Curve_1 = geompy.MakeInterpol(vertices, True, True)
29
30 p_small = geompy.MakeVertexOnCurve(Curve_1, 0.001)
31 geompy.addToStudy(p_small, "p_small")
32
33 p_small2 = geompy.MakeVertexOnCurve(Curve_1, 0.5)
34 geompy.addToStudy(p_small2, "p_small2")
35
36 p_small3 = geompy.MakeVertexOnCurve(Curve_1, 0.501)
37 geompy.addToStudy(p_small3, "p_small3")
38
39 part = geompy.MakePartition([Face_1], [Curve_1, p_small, p_small2, p_small3], Limit=geompy.ShapeType["FACE"])
40 geompy.addToStudy(part, "part")
41
42 Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
43 Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
44 Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
45
46 p1 = geompy.MakeVertex(-5, -5, 0)
47 p2 = geompy.MakeVertex(5, 5, 0)
48 left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON)
49 left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
50 geompy.UnionList(left, left_edges)
51 geompy.addToStudyInFather(part, left, "left")
52
53 right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON)
54 right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
55 geompy.UnionList(right, right_edges)
56 geompy.addToStudyInFather(part, right, "right")
57
58 bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON)
59 bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
60 geompy.UnionList(bottom, bottom_edges)
61 geompy.addToStudyInFather(part, bottom, "bottom")
62
63 top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON)
64 top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
65 geompy.UnionList(top, top_edges)
66 geompy.addToStudyInFather(part, top, "top")
67
68 faces = geompy.SubShapeAll(part, geompy.ShapeType["FACE"])
69 sub_shapes = []
70 for i, face in enumerate(faces):
71   geompy.addToStudyInFather(part, face, "face_%i"%(i+1))
72   sub_shapes.append(face)
73
74 # Mesh
75 # ====
76
77 import SMESH
78 from salome.smesh import smeshBuilder
79 smesh = smeshBuilder.New()
80
81 # Test gradation with quadrangles
82 Mesh_1 = smesh.Mesh(part, "Mesh")
83
84 algo2d = Mesh_1.Triangle(algo=smeshBuilder.BLSURF)
85 params = algo2d.Parameters()
86 params.SetGeometricMesh( 1 )
87 params.SetAngleMesh( 4 )
88 params.SetPhySize( 8 )
89 algo2d.SetGradation(1.05)
90 params.SetElementType( True )
91
92 ok = Mesh_1.Compute()
93
94 if not ok:
95   raise Exception("Error when computing Mesh_1")
96
97 # Check the areas of Mesh_1
98 mini_1, maxi_1 = getMinMaxArea(Mesh_1)
99 mini_1_ref = 0.00197
100 maxi_1_ref = 0.530
101
102 if abs(mini_1-mini_1_ref) > area_tolerance:
103   raise Exception("Min area of Mesh_1 incorrect")
104
105 if maxi_1 > maxi_1_ref:
106   raise Exception("Max area of Mesh_1 incorrect")
107
108 # Check the number of faces of Mesh_1
109 nb_faces_1 = Mesh_1.NbFaces()
110 nb_faces_1_ref = 1208
111
112 if nb_faces_1 < nb_faces_1_ref:
113   raise Exception("Number of faces of Mesh_1 incorrect")
114
115
116 # Test no gradation with quadrangles and anisotropy
117 # RQ: this kind of mesh is not suitable for simulation
118 # but gives a coarse mesh like a stl geometry
119 Mesh_2 = smesh.Mesh(part, "Mesh")
120
121 algo2d = Mesh_2.Triangle(algo=smeshBuilder.BLSURF)
122 params = algo2d.Parameters()
123 params.SetGeometricMesh( 1 )
124 params.SetAngleMesh( 4 )
125 params.SetPhySize( 8 )
126 algo2d.SetGradation(1.05)
127 params.SetElementType( 1 )
128 params.SetAnisotropic(True)
129
130 ok = Mesh_2.Compute()
131
132 if not ok:
133   raise Exception("Error when computing Mesh_2")
134
135 # Check the areas of Mesh_2
136 mini_2, maxi_2 = getMinMaxArea(Mesh_2)
137 mini_2_ref = 0.000408
138 maxi_2_ref = 10.1982
139
140 if abs(mini_2-mini_2_ref) > area_tolerance:
141   raise Exception("Min area of Mesh_2 incorrect")
142
143 if abs(maxi_2-maxi_2_ref) > area_tolerance:
144   raise Exception("Max area of Mesh_2 incorrect")
145
146 # Check the number of faces of Mesh_2
147 nb_faces_2 = Mesh_2.NbFaces()
148 nb_faces_2_ref = 121
149 if abs(nb_faces_2-nb_faces_2_ref) > nb_faces_tolerance:
150   raise Exception("Number of faces of Mesh_2 incorrect")
151
152 if salome.sg.hasDesktop():
153   salome.sg.updateObjBrowser()
154
155