Assignment - Final Code
Assignment - Final Code
import sys
sys.stdout = open('Result_Final.txt', 'w')
import numpy as np
# input
L = 250 # total length of the bar in mm
F = 1000 # applied force on the final nodes (scalar value) in N
E = 70e3 # elastic modulus Mpa
w1 = 50 # Width of the bar in mm at x = 0
w2 = 25 # Width of the bar in mm at x = L
t = 3.125 # Width of the bar in mm at x = 0
#Boundary conditions
BC = np.array([0,]) #form: [node numbers], [applied displacements]
u1[0] = 0 # at x =0, u1 =0
F1[Nelem] = F # at x =L, F1 =F (axial load applied at last node )
# functions here
#u, strain, stress = HW1f.calcDisp(L, Nelem, F, E, BC)
# output
for el in range(Nelem):
a = L / Nelem *(el+1)
Le[el] = a
m[el] = (w1 + (w2-w1) / L * Le[el])
A[el] = (m[el]) * t
1
K_el[el] = E * A[el] / (L/Nelem)
K_int = np.zeros((Nelem+1,Nelem+1))
K_int[el:el+2,el:el+2] = K_e *K_el [el]
K_g += K_int
K_g_1 = K_g # Define another array to distinguish beofore and after Elemination
# Displacement Matrix
F1 = np.delete(F1,1)
F1=np.transpose(F1)
print('',end='\n' )
print('Boundary Conditions =',end='\n' )
print('',end='\n' )
print('Applied force =',end='\n' )
print(F1)
print('Fixed Displacement at x=0, u0 =0')
print('Displacement array = [[0] ,[u1],[u2],[u3]]')
U = F1 * np.linalg.inv(K_g_1)
print('',end='\n' )
print('Global Displcament =',end='\n' )
print('',end='\n' )
print( U)
#Reaction Force
#R = K_g_1 * U - F1
#print('',end='\n' )
#print('Reaction force R = ', end='\n')
#print(R)
# Strain
for i in range(Nelem):
for j in range(Nelem-1):
U =np.delete(U,i)
U =np.transpose(U,)
Strain[0]=U[0]/(L/Nelem)
for i in range(Nelem-1):
2
Strain[i+1] = (U[i+1]-U[i])/(L/Nelem)
print('',end='\n' )
print('Strain =',end='\n' )
print('',end='\n' )
print(Strain)
# Stress
Stress = E * Strain
print('',end='\n' )
print('Stress =',end='\n' )
print('',end='\n' )
print(Stress)