Salome HOME
Update of CheckDone
[modules/smesh.git] / test / doublenodes_polyhedra.py
1 #!/usr/bin/env python
2
3 import sys
4 import salome
5
6 salome.standalone()
7 salome.salome_init()
8
9 ###
10 ### SHAPER component
11 ###
12
13 from salome.shaper import model
14
15 model.begin()
16 partSet = model.moduleDocument()
17
18 ### Create Part
19 Part_1 = model.addPart(partSet)
20 Part_1_doc = Part_1.document()
21
22 ### Create Sketch
23 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
24
25 ### Create SketchLine
26 SketchLine_1 = Sketch_1.addLine(100, 0, 0, 0)
27
28 ### Create SketchProjection
29 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
30 SketchPoint_1 = SketchProjection_1.createdFeature()
31 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchPoint_1.result())
32
33 ### Create SketchLine
34 SketchLine_2 = Sketch_1.addLine(0, 0, 0, 100)
35
36 ### Create SketchLine
37 SketchLine_3 = Sketch_1.addLine(0, 100, 100, 100)
38
39 ### Create SketchLine
40 SketchLine_4 = Sketch_1.addLine(100, 100, 100, 0)
41 Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
42 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
43 Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
44 Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
45 Sketch_1.setHorizontal(SketchLine_1.result())
46 Sketch_1.setVertical(SketchLine_2.result())
47 Sketch_1.setHorizontal(SketchLine_3.result())
48 Sketch_1.setVertical(SketchLine_4.result())
49 Sketch_1.setEqual(SketchLine_3.result(), SketchLine_4.result())
50 Sketch_1.setLength(SketchLine_1.result(), 100)
51
52 ### Create SketchLine
53 SketchLine_5 = Sketch_1.addLine(0, 50, 100, 50)
54 Sketch_1.setCoincident(SketchLine_5.startPoint(), SketchLine_2.result())
55 Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_4.result())
56 Sketch_1.setHorizontal(SketchLine_5.result())
57
58 ### Create SketchLine
59 SketchLine_6 = Sketch_1.addLine(50, 50.00000000000001, 50, 0)
60 Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_1.result())
61 Sketch_1.setVertical(SketchLine_6.result())
62 Sketch_1.setCoincident(SketchLine_6.startPoint(), SketchLine_5.result())
63 Sketch_1.setMiddlePoint(SketchLine_6.startPoint(), SketchLine_5.result())
64 Sketch_1.setMiddlePoint(SketchLine_5.startPoint(), SketchLine_2.result())
65 model.do()
66
67 ### Create Extrusion
68 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 100, 0, "Faces|Wires")
69
70 ### Create Group
71 Group_1 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Extrusion_1_1_1/Generated_Face&Sketch_1/SketchLine_5"), model.selection("FACE", "(Extrusion_1_1_3/Generated_Face&Sketch_1/SketchLine_4)(Extrusion_1_1_3/From_Face)(Extrusion_1_1_3/To_Face)(Extrusion_1_1_3/Generated_Face&Sketch_1/SketchLine_3)2(Extrusion_1_1_3/Generated_Face&Sketch_1/SketchLine_2)2")])
72 Group_1.setName("crack_1")
73 Group_1.result().setName("crack_1")
74
75 ### Create Group
76 Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Extrusion_1_1_1/Generated_Face&Sketch_1/SketchLine_6")])
77 Group_2.setName("crack_2")
78 Group_2.result().setName("crack_2")
79
80 ### Create Group
81 Group_3 = model.addGroup(Part_1_doc, "Faces", [model.selection("COMPSOLID", "Extrusion_1_1")])
82 Group_3.setName("all_faces")
83 Group_3.result().setName("all_faces")
84
85 ### Create GroupSubstraction
86 GroupSubstraction_1 = model.addGroupSubstraction(Part_1_doc, [model.selection("COMPOUND", "all_faces")], [model.selection("COMPOUND", "crack_1"), model.selection("COMPOUND", "crack_2")])
87 GroupSubstraction_1.result().setName("sides")
88
89 ### Create Group
90 Group_4 = model.addGroup(Part_1_doc, "Edges", [model.selection("EDGE", "[Extrusion_1_1_3/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1_3/To_Face]")])
91 Group_4.setName("top_edge")
92 Group_4.result().setName("top_edge")
93
94 ### Create Group
95 Group_5 = model.addGroup(Part_1_doc, "Solids", [model.selection("SOLID", "Extrusion_1_1_3")])
96 Group_5.setName("Solid_1")
97 Group_5.result().setName("Solid_1")
98
99 ### Create Group
100 Group_6 = model.addGroup(Part_1_doc, "Solids", [model.selection("SOLID", "Extrusion_1_1_1")])
101 Group_6.setName("Solid_2")
102 Group_6.result().setName("Solid_2")
103
104 ### Create Group
105 Group_7 = model.addGroup(Part_1_doc, "Solids", [model.selection("SOLID", "Extrusion_1_1_2")])
106 Group_7.setName("Solid_3")
107 Group_7.result().setName("Solid_3")
108
109 model.end()
110
111 ###
112 ### SHAPERSTUDY component
113 ###
114
115 model.publishToShaperStudy()
116 import SHAPERSTUDY
117 shapes = SHAPERSTUDY.shape(model.featureStringId(Extrusion_1))
118
119 Extrusion_1_1 = shapes[0]
120 groups = shapes[1:]
121
122 # dict of groups by their name
123 d_groups = {}
124 for gr in groups:
125   name = gr.GetName()
126   d_groups[name] = gr
127
128 ###
129 ### SMESH component
130 ###
131
132 import  SMESH, SALOMEDS
133 from salome.smesh import smeshBuilder
134
135 smesh = smeshBuilder.New()
136
137 # Create an hexahedral mesh or polyhedral mesh
138 # @param algo: "hexahedra", "polyhedra" or "polygons"
139 def createMesh(algo):
140   
141   nb_segs = 5
142   Mesh_1 = smesh.Mesh(Extrusion_1_1)
143   mesh_name = "Mesh_%s"%algo
144   Mesh_1.SetName(mesh_name)
145
146   algo_1d = Mesh_1.Segment()
147   algo_1d.NumberOfSegments(nb_segs)
148
149   if algo == "hexahedra":
150     Mesh_1.Quadrangle(algo=smeshBuilder.QUADRANGLE)
151     Mesh_1.Hexahedron(algo=smeshBuilder.Hexa)
152   elif algo == "polyhedra":
153     Mesh_1.Quadrangle(algo=smeshBuilder.QUADRANGLE)
154     Mesh_1.Polyhedron()
155   elif algo == "polygons":
156     Mesh_1.Polygon()
157     Mesh_1.Polyhedron()
158   else:
159     raise Exception("not expected algo: ", algo)
160
161   d_mesh_groups = {}
162   # Create group of faces
163   for name, gr in d_groups.items():
164     if name.startswith("crack") or name.startswith("Solid_"):
165       gr_mesh = Mesh_1.Group(gr)
166       d_mesh_groups[name] = gr_mesh
167
168   # Group on nodes
169   gr_sides_1 = Mesh_1.GroupOnGeom(d_groups["sides"],'sides',SMESH.NODE)
170
171   # sub-mesh on top edge
172   algo_1d_sub = Mesh_1.Segment(geom=d_groups["top_edge"])
173   algo_1d_sub.NumberOfSegments(2*nb_segs)
174   algo_1d_sub.Propagation()
175
176   isDone = Mesh_1.Compute()
177
178   nb_nodes = Mesh_1.NbNodes()
179   # Create 2 cracks by two calls of DoubleNodeElemGroups
180
181   # FIRST CRACK
182   # get affected elements on crack_1
183   [ affectedVolumes_1, affectedFaces_1, affectedEdges_1 ] = Mesh_1.AffectedElemGroupsInRegion( [ d_mesh_groups["crack_1" ] ], [ gr_sides_1 ], None )
184   # affectedVolumes_1 is d_mesh_groups["Solid_1"] => use one or the other
185   # double nodes on crack_1
186   [ crack_1_double_faces, crack_1_double_nodes ] = Mesh_1.DoubleNodeElemGroups( [ d_mesh_groups["crack_1" ] ], [ gr_sides_1 ], [ affectedVolumes_1, affectedFaces_1, affectedEdges_1 ], 1, 1 )
187
188   # check new nodes were added
189   new_nb_nodes_1 = Mesh_1.NbNodes()
190   assert new_nb_nodes_1 > nb_nodes
191   
192   # check number of new nodes
193   if algo != "polygons":
194     assert new_nb_nodes_1-nb_nodes == (nb_segs*2-1)*(nb_segs-1)
195   else:
196     assert new_nb_nodes_1-nb_nodes == nb_segs-1
197
198   # check new nodes where affected to volume elements
199   affectedVolumes_1_nodes = affectedVolumes_1.GetNodeIDs()
200   for n in range(nb_nodes +1, new_nb_nodes_1):
201     assert n in affectedVolumes_1_nodes, "New node not affected to affectedVolumes_1 in %s"%mesh_name
202
203   # SECOND CRACK
204   # get affected elements on crack_2
205   [ affectedVolumes_2, affectedFaces_2, affectedEdges_2 ] = Mesh_1.AffectedElemGroupsInRegion( [ d_mesh_groups["crack_2" ] ], [ gr_sides_1 ], None )
206   # double nodes on crack_2
207   # affectedVolumes_2 is d_mesh_groups["Solid_3"] => use one or the other
208   [ crack_2_double_faces, crack_2_double_nodes ] = Mesh_1.DoubleNodeElemGroups( [ d_mesh_groups["crack_2" ] ], [ gr_sides_1 ], [ affectedVolumes_2, affectedFaces_2, affectedEdges_2 ], 1, 1 )
209
210   # check new nodes were added
211   new_nb_nodes_2 = Mesh_1.NbNodes()
212   assert new_nb_nodes_2 > new_nb_nodes_1
213   
214   # check number of new nodes
215   if algo != "polygons":
216     assert new_nb_nodes_2-new_nb_nodes_1 == (nb_segs-1)*nb_segs
217   else:
218     assert new_nb_nodes_2-new_nb_nodes_1 == nb_segs-1
219
220   # check new nodes where affected to volume elements
221   affectedVolumes_2_nodes = affectedVolumes_2.GetNodeIDs()
222   for n in range(new_nb_nodes_1 +1, new_nb_nodes_2):
223     assert n in affectedVolumes_2_nodes, "New node not affected to affectedVolumes_2 in %s"%mesh_name
224
225 createMesh("hexahedra")
226 createMesh("polyhedra")
227 createMesh("polygons")
228
229
230 if salome.sg.hasDesktop():
231   salome.sg.updateObjBrowser()