13 from salome.shaper import model
16 partSet = model.moduleDocument()
19 Part_1 = model.addPart(partSet)
20 Part_1_doc = Part_1.document()
23 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
26 SketchLine_1 = Sketch_1.addLine(100, 0, 0, 0)
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())
34 SketchLine_2 = Sketch_1.addLine(0, 0, 0, 100)
37 SketchLine_3 = Sketch_1.addLine(0, 100, 100, 100)
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)
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())
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())
68 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 100, 0, "Faces|Wires")
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")
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")
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")
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")
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")
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")
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")
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")
112 ### SHAPERSTUDY component
115 model.publishToShaperStudy()
117 shapes = SHAPERSTUDY.shape(model.featureStringId(Extrusion_1))
119 Extrusion_1_1 = shapes[0]
122 # dict of groups by their name
132 import SMESH, SALOMEDS
133 from salome.smesh import smeshBuilder
135 smesh = smeshBuilder.New()
137 # Create an hexahedral mesh or polyhedral mesh
138 # @param algo: "hexahedra", "polyhedra" or "polygons"
139 def createMesh(algo):
142 Mesh_1 = smesh.Mesh(Extrusion_1_1)
143 mesh_name = "Mesh_%s"%algo
144 Mesh_1.SetName(mesh_name)
146 algo_1d = Mesh_1.Segment()
147 algo_1d.NumberOfSegments(nb_segs)
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)
155 elif algo == "polygons":
159 raise Exception("not expected algo: ", algo)
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
169 gr_sides_1 = Mesh_1.GroupOnGeom(d_groups["sides"],'sides',SMESH.NODE)
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()
176 isDone = Mesh_1.Compute()
178 raise Exception("Error when computing Mesh")
180 nb_nodes = Mesh_1.NbNodes()
181 # Create 2 cracks by two calls of DoubleNodeElemGroups
184 # get affected elements on crack_1
185 [ affectedVolumes_1, affectedFaces_1, affectedEdges_1 ] = Mesh_1.AffectedElemGroupsInRegion( [ d_mesh_groups["crack_1" ] ], [ gr_sides_1 ], None )
186 # affectedVolumes_1 is d_mesh_groups["Solid_1"] => use one or the other
187 # double nodes on crack_1
188 [ 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 )
190 # check new nodes were added
191 new_nb_nodes_1 = Mesh_1.NbNodes()
192 assert new_nb_nodes_1 > nb_nodes
194 # check number of new nodes
195 if algo != "polygons":
196 assert new_nb_nodes_1-nb_nodes == (nb_segs*2-1)*(nb_segs-1)
198 assert new_nb_nodes_1-nb_nodes == nb_segs-1
200 # check new nodes where affected to volume elements
201 affectedVolumes_1_nodes = affectedVolumes_1.GetNodeIDs()
202 for n in range(nb_nodes +1, new_nb_nodes_1):
203 assert n in affectedVolumes_1_nodes, "New node not affected to affectedVolumes_1 in %s"%mesh_name
206 # get affected elements on crack_2
207 [ affectedVolumes_2, affectedFaces_2, affectedEdges_2 ] = Mesh_1.AffectedElemGroupsInRegion( [ d_mesh_groups["crack_2" ] ], [ gr_sides_1 ], None )
208 # double nodes on crack_2
209 # affectedVolumes_2 is d_mesh_groups["Solid_3"] => use one or the other
210 [ 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 )
212 # check new nodes were added
213 new_nb_nodes_2 = Mesh_1.NbNodes()
214 assert new_nb_nodes_2 > new_nb_nodes_1
216 # check number of new nodes
217 if algo != "polygons":
218 assert new_nb_nodes_2-new_nb_nodes_1 == (nb_segs-1)*nb_segs
220 assert new_nb_nodes_2-new_nb_nodes_1 == nb_segs-1
222 # check new nodes where affected to volume elements
223 affectedVolumes_2_nodes = affectedVolumes_2.GetNodeIDs()
224 for n in range(new_nb_nodes_1 +1, new_nb_nodes_2):
225 assert n in affectedVolumes_2_nodes, "New node not affected to affectedVolumes_2 in %s"%mesh_name
227 createMesh("hexahedra")
228 createMesh("polyhedra")
229 createMesh("polygons")
232 if salome.sg.hasDesktop():
233 salome.sg.updateObjBrowser()