# Example: Python script for a connecting rod¶

Connecting rod

## Model creation¶

```import math

import geompy
import hexablock

# ------------------------------------- Build 2 cylindrical grids

angle_px   = math.pi / 3

grille_p = doc.makeCylindrical(centre_pb, vecteur_px, vecteur_z,  1, 360, 1,  1, 3, 1,  False)
grille_g = doc.makeCylindrical(centre_gb, vecteur_gx, vecteur_z,  1, 360, 1,  1, 3, 1,  False)

# ------------------------------------- Join the grids

point_p1 = grille_p.getVertexIJK(1, 0, 0)
point_p2 = grille_p.getVertexIJK(1, 2, 0)

point_g1 = grille_g.getVertexIJK(1, 1, 0)
point_g2 = grille_g.getVertexIJK(1, 2, 0)

point_p2, point_g2,  3)
```

Go back to Steps

## Recovering edges and faces from geometry before the association¶

```bielle = geompy.ImportSTEP("bielle.stp")

sommets = geompy.SubShapeAllSortedCentres(bielle, geompy.ShapeType["VERTEX"])

sommets_petit = [  6,  8,  7,  9 ]
sommets_grand = [ 10, 12, 11, 13 ]

aretes = geompy.SubShapeAllSortedCentres(bielle, geompy.ShapeType["EDGE"])

aretes_petit = [  7,  9,  8, 10 ]
aretes_grand = [ 19, 21, 20, 22 ]

ga_pbcd = aretes[ 0]
ga_pbe  = aretes[ 2]

ga_phcd = aretes[ 1]
ga_phe  = aretes[ 3]

ga_gbcd = aretes[27]
ga_gbe  = aretes[25]

ga_ghcd = aretes[28]
ga_ghe  = aretes[26]
```

Go back to Steps

## Association of the model to the geometry¶

```doc.setShape(bielle)

# ---------------------------- Clean implicit associations of the model

doc.clearAssociation()

# -------------------------- Procedure who associates external circles
def cercle(grille, k, ge, p):
ms  = grille.getVertexIJK(0, 0, k)

ma1 = grille.getEdgeJ(0, 2, k)
ma2 = grille.getEdgeJ(0, 1, k)
ma3 = grille.getEdgeJ(0, 0, k)

doc.associateClosedLine(ms, ma1, [ ma2, ma3 ], ge, p, False, [])

cercle(grille_p, 0, ga_pbe, 5.0/6)
cercle(grille_p, 1, ga_phe, 5.0/6)

cercle(grille_g, 0, ga_gbe, 0)
cercle(grille_g, 1, ga_ghe, 0)

# ------------------- Procedure who associates external decentered lines
def arc(grille, i1, i2, k, ge):
ma1 = grille.getEdgeJ(1, i1, k)
ma2 = grille.getEdgeJ(1, i2, k)

doc.associateOpenedLine(ma1, [ ma2 ], ge, 0, [], 1)

arc(grille_p, 1, 0, 0, ga_pbcd)
arc(grille_p, 1, 0, 1, ga_phcd)

arc(grille_g, 0, 2, 0, ga_gbcd)
arc(grille_g, 0, 2, 1, ga_ghcd)

# ---------------------- Associate archs vertices with connection circles

hm = prisme.getHexa(1)
for i in xrange(0, 4):
vm = hm.getVertex(i)
ga = sommets[ sommets_petit[i] ]
vm.setAssociation(ga)

hm = prisme.getHexa(2)
for i in xrange(0, 4):
vm = hm.getVertex(i)
ga = sommets[ sommets_grand[i] ]
vm.setAssociation(ga)

# ---------------------- Associate connection circles

hm = prisme.getHexa(0)
for i in xrange(0, 4):
em = hm.getEdge(i+8)
ga = aretes[ aretes_petit[i] ]

hm = prisme.getHexa(2)
for i in xrange(0, 4):
em = hm.getEdge(i+8)
ga = aretes[ aretes_grand[i] ]

# --------------------- Round implicit cylindrical associations

for h, i, ech in [ [0, 0, 0.95], [0, 1, 0.95],  [2, 2, 0.85], [2, 3, 0.85] ]:
hm = prisme.getHexa(h)
em = hm.getEdge(i)
va = em.getVertex(0).getAssociation()
vb = em.getVertex(1).getAssociation()
vax, vay, vaz = geompy.PointCoordinates(va)
vbx, vby, vbz = geompy.PointCoordinates(vb)
vmx = ( vax + vbx ) / 2.0 * ech
vmy = ( vay + vby ) / 2.0
vmz = ( vaz + vbz ) / 2.0
vm = geompy.MakeVertex(vmx, vmy, vmz)
eg = geompy.MakeArc(va, vm, vb)
em.clearAssociation()
```

Go back to Steps

## Definition of elements groups for the mesh¶

```# -------------------------- # Define 5 faces groups

# -------------------------- Define little and big cylinder groups

for i in xrange(3):

# -------------------------- Define bottum and up groups

for i in xrange(3):

for i in xrange(3):
h = prisme.getHexa(i)

# -------------------------- Define border group

for i in xrange(2):

for i in [0, 2]:

for i in xrange(3):
h = prisme.getHexa(i)

# -------------------------- Define 3 groups of volumes

for i in xrange(3):

for i in xrange(3):
```

Go back to Steps

## Definition of a law discretization laws :¶

```hexablock.addLaws(doc, 0.003, True)
```

Go back to Steps

## Mesh generation¶

```blocs = hexablock.mesh(doc)
##  .. and show statistics
muv, mue, muq, muh = hexablock.dump(doc, blocs)
```