def getElementCentroid(element,nodes):
    etype = element[0]
    if etype == 'hex8':
        N = 0.125
        centroid = [0.,0.,0.]
        for i in xrange(8):
            centroid[0] += nodes[element[i+2]-1][1]*N
            centroid[1] += nodes[element[i+2]-1][2]*N
            centroid[2] += nodes[element[i+2]-1][3]*N
            
    elif etype == 'tet4':
        dmy = 1./3.
        N [dmy, dmy, dmy] # first shape function is zero at centroid so no need to include
        centroid = [0.,0.,0.]
        for i in xrange(3):
            centroid[0] += nodes[element[i+3]-1][1]*N[i]
            centroid[1] += nodes[element[i+3]-1][2]*N[i]
            centroid[2] += nodes[element[i+3]-1][3]*N[i]
    elif etype == 'penta6':
        N = 1/6.
        centroid = [0.,0.,0.]
        for i in xrange(6):
            centroid[0] += nodes[element[i+2]-1][1]*N
            centroid[1] += nodes[element[i+2]-1][2]*N
            centroid[2] += nodes[element[i+2]-1][3]*N
    else:
        print 'Unknown element '+etype+' passed to getElementCentroid. Exiting...'
        raise SystemExit

    return centroid

