2-D FEM shape functions

Compute the shape functions at try the interpolation at different “integration” pints within the element.

[31]:
import numpy as np
[32]:
#def shapes():
#
#    N1 = ?
#    N2 = ?
#    N3 = ?
#    N4 = ?

#    N = np.array([N1, N2, N3, N4])

#    return N
[33]:
#hide

def shapes():

    #shape functions

    N1 = 0.25*(1-xi)*(1-eta)
    N2 = 0.25*(1+xi)*(1-eta)
    N3 = 0.25*(1+xi)*(1+eta)
    N4 = 0.25*(1-xi)*(1+eta)

    N = np.array([N1, N2, N3, N4])

    # and their derivatives
    dNds = np.zeros((2,4))

    dNds[0,0]   =  0.25*(-1  + eta) #derivative with xi
    dNds[1,0]   =  0.25*(xi  -  1) #derivative with eta

    #derivatives of second shape function with local coordinates
    dNds[0,1]   =  0.25*(1   - eta)
    dNds[1,1]   =  0.25*(-xi -  1)

    #derivatives of third shape function with local coordinates
    dNds[0,2]   =  0.25*(eta  +  1)
    dNds[1,2]   =  0.25*(xi  +  1)

    #derivatives of fourth shape function with local coordinates
    dNds[0,3]   =  0.25*(-eta -  1)
    dNds[1,3]   =  0.25*(1   - xi)

    return N, dNds
[38]:
# pseudo gcoord
GCOORD = np.array([[-1, 1, 1, -1],[-1, -1, 1, 1]])
print(GCOORD)
# pseudo nodal temperatures
T = np.array([0, 0, 1, 1])
print(T)
# interpolatin point
xi = 0
eta = 0

# shape functions at integration point
N, dNds = shapes()

#interpolation
print(sum(N*T))
print(sum(dNds[1,:]*T))
[[-1  1  1 -1]
 [-1 -1  1  1]]
[0 0 1 1]
0.5
0.5
[ ]: