5 ===========================================
6 Example: Python script for a connecting rod
7 ===========================================
9 .. image:: _static/cad_bielle.png
19 - :ref:`modelcreation`
39 doc = hexablock.addDocument("bielle")
41 # ------------------------------------- Build 2 cylindrical grids
43 centre_pb = doc.addVertex(0, 0, 0)
44 centre_gb = doc.addVertex(7, 0, 0)
46 angle_px = math.pi / 3
47 vecteur_px = doc.addVector(math.cos(angle_px), math.sin(angle_px), 0)
48 vecteur_gx = doc.addVector(1, 0, 0)
50 vecteur_z = doc.addVector(0, 0, 1)
52 grille_p = doc.makeCylindrical(centre_pb, vecteur_px, vecteur_z, 1, 360, 1, 1, 3, 1, False)
53 grille_g = doc.makeCylindrical(centre_gb, vecteur_gx, vecteur_z, 1, 360, 1, 1, 3, 1, False)
55 # ------------------------------------- Join the grids
57 quad_p = grille_p.getQuadJK(1, 2, 0)
58 quad_g = grille_g.getQuadJK(1, 1, 0)
60 point_p1 = grille_p.getVertexIJK(1, 0, 0)
61 point_p2 = grille_p.getVertexIJK(1, 2, 0)
63 point_g1 = grille_g.getVertexIJK(1, 1, 0)
64 point_g2 = grille_g.getVertexIJK(1, 2, 0)
66 prisme = doc.joinQuad(quad_p, quad_g, point_p1, point_g1,
67 point_p2, point_g2, 3)
70 Go back to :ref:`menu`
74 Recovering edges and faces from geometry before the association
75 ===============================================================
79 bielle = geompy.ImportSTEP("bielle.stp")
82 sommets = geompy.SubShapeAllSortedCentres(bielle, geompy.ShapeType["VERTEX"])
84 sommets_petit = [ 6, 8, 7, 9 ]
85 sommets_grand = [ 10, 12, 11, 13 ]
87 aretes = geompy.SubShapeAllSortedCentres(bielle, geompy.ShapeType["EDGE"])
89 aretes_petit = [ 7, 9, 8, 10 ]
90 aretes_grand = [ 19, 21, 20, 22 ]
105 Go back to :ref:`menu`
109 Association of the model to the geometry
110 ========================================
116 # ---------------------------- Clean implicit associations of the model
118 doc.clearAssociation()
120 # -------------------------- Procedure who associates external circles
121 def cercle(grille, k, ge, p):
122 ms = grille.getVertexIJK(0, 0, k)
124 ma1 = grille.getEdgeJ(0, 2, k)
125 ma2 = grille.getEdgeJ(0, 1, k)
126 ma3 = grille.getEdgeJ(0, 0, k)
128 doc.associateClosedLine(ms, ma1, [ ma2, ma3 ], ge, p, False, [])
130 cercle(grille_p, 0, ga_pbe, 5.0/6)
131 cercle(grille_p, 1, ga_phe, 5.0/6)
133 cercle(grille_g, 0, ga_gbe, 0)
134 cercle(grille_g, 1, ga_ghe, 0)
136 # ------------------- Procedure who associates external decentered lines
137 def arc(grille, i1, i2, k, ge):
138 ma1 = grille.getEdgeJ(1, i1, k)
139 ma2 = grille.getEdgeJ(1, i2, k)
141 doc.associateOpenedLine(ma1, [ ma2 ], ge, 0, [], 1)
143 arc(grille_p, 1, 0, 0, ga_pbcd)
144 arc(grille_p, 1, 0, 1, ga_phcd)
146 arc(grille_g, 0, 2, 0, ga_gbcd)
147 arc(grille_g, 0, 2, 1, ga_ghcd)
150 # ---------------------- Associate archs vertices with connection circles
152 hm = prisme.getHexa(1)
153 for i in xrange(0, 4):
155 ga = sommets[ sommets_petit[i] ]
156 vm.setAssociation(ga)
158 hm = prisme.getHexa(2)
159 for i in xrange(0, 4):
161 ga = sommets[ sommets_grand[i] ]
162 vm.setAssociation(ga)
164 # ---------------------- Associate connection circles
166 hm = prisme.getHexa(0)
167 for i in xrange(0, 4):
169 ga = aretes[ aretes_petit[i] ]
170 em.addAssociation(ga, 0, 1)
172 hm = prisme.getHexa(2)
173 for i in xrange(0, 4):
175 ga = aretes[ aretes_grand[i] ]
176 em.addAssociation(ga, 0, 1)
178 # --------------------- Round implicit cylindrical associations
180 for h, i, ech in [ [0, 0, 0.95], [0, 1, 0.95], [2, 2, 0.85], [2, 3, 0.85] ]:
181 hm = prisme.getHexa(h)
183 va = em.getVertex(0).getAssociation()
184 vb = em.getVertex(1).getAssociation()
185 vax, vay, vaz = geompy.PointCoordinates(va)
186 vbx, vby, vbz = geompy.PointCoordinates(vb)
187 vmx = ( vax + vbx ) / 2.0 * ech
188 vmy = ( vay + vby ) / 2.0
189 vmz = ( vaz + vbz ) / 2.0
190 vm = geompy.MakeVertex(vmx, vmy, vmz)
191 eg = geompy.MakeArc(va, vm, vb)
192 em.clearAssociation()
193 em.addAssociation(eg, 0, 1)
195 Go back to :ref:`menu`
199 Definition of elements groups for the mesh
200 ==========================================
204 # -------------------------- # Define 5 faces groups
206 groupe_petit = doc.addQuadGroup("Petit")
207 groupe_grand = doc.addQuadGroup("Grand")
208 groupe_bas = doc.addQuadGroup("Bas")
209 groupe_haut = doc.addQuadGroup("Haut")
210 groupe_contour = doc.addQuadGroup("Contour")
212 # -------------------------- Define little and big cylinder groups
215 groupe_petit.addElement( grille_p.getQuadJK(0, i, 0) )
216 groupe_grand.addElement( grille_g.getQuadJK(0, i, 0) )
218 # -------------------------- Define bottum and up groups
221 groupe_bas.addElement( grille_p.getQuadIJ(0, i, 0) )
222 groupe_bas.addElement( grille_g.getQuadIJ(0, i, 0) )
224 groupe_haut.addElement( grille_p.getQuadIJ(0, i, 1) )
225 groupe_haut.addElement( grille_g.getQuadIJ(0, i, 1) )
228 h = prisme.getHexa(i)
230 groupe_bas.addElement( h.getQuad(2) )
231 groupe_haut.addElement( h.getQuad(3) )
233 # -------------------------- Define border group
236 groupe_contour.addElement( grille_p.getQuadJK(1, i, 0) )
239 groupe_contour.addElement( grille_g.getQuadJK(1, i, 0) )
242 h = prisme.getHexa(i)
244 groupe_contour.addElement( h.getQuad(4) )
245 groupe_contour.addElement( h.getQuad(5) )
247 # -------------------------- Define 3 groups of volumes
249 groupe_petit = doc.addHexaGroup("Petit")
250 groupe_grand = doc.addHexaGroup("Grand")
251 groupe_prisme = doc.addHexaGroup("Prisme")
254 groupe_petit.addElement( grille_p.getHexa(i) )
255 groupe_grand.addElement( grille_g.getHexa(i) )
258 groupe_prisme.addElement( prisme.getHexa(i) )
261 Go back to :ref:`menu`
265 Definition of a law discretization laws :
266 ========================================
270 hexablock.addLaws(doc, 0.003, True)
273 Go back to :ref:`menu`
283 blocs = hexablock.mesh(doc)
284 ## .. and show statistics
285 muv, mue, muq, muh = hexablock.dump(doc, blocs)