Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
21 views

Assignment - Final Code

This document contains code to analyze a structural element undergoing axial loading. It discretizes the element into multiple elements, calculates the element stiffness matrices, assembles the global stiffness matrix, applies boundary conditions, and calculates displacements, strains and stresses. It takes the element length, applied force, elastic modulus, varying width dimensions, and number of elements as inputs. Key steps include discretization, assembly of the global stiffness matrix, solving for displacements using the applied loads and boundary conditions, and determining strains and stresses from displacements.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Assignment - Final Code

This document contains code to analyze a structural element undergoing axial loading. It discretizes the element into multiple elements, calculates the element stiffness matrices, assembles the global stiffness matrix, applies boundary conditions, and calculates displacements, strains and stresses. It takes the element length, applied force, elastic modulus, varying width dimensions, and number of elements as inputs. Key steps include discretization, assembly of the global stiffness matrix, solving for displacements using the applied loads and boundary conditions, and determining strains and stresses from displacements.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#import HW1functionsExample as HW1f

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

# Asking for number of elements to user


n = input("Please enter a non zero integer value for number of elemnts:\n")
Nelem = int(n)
print(f'Number of elements = {Nelem} and number of nodes = {Nelem + 1}')

# Declaration of arrays considering number of elements


Le = np.zeros(Nelem) # Single Element Length
A = np.zeros(Nelem) # Area at node point
m = np.zeros(Nelem) # Part of Area equation, considered for simplification
n = np.log(w1) # Part of Area equation, considered for simplification
p = np.zeros(Nelem) # Part of Area equation, considered for simplification
K_el = np.zeros(Nelem) # Stiffness of each element
K_e = np.array([[1,-1],[-1,1]]) # Multiplier of Global stiffness matrix
K_g = np.zeros((Nelem+1,Nelem+1)) # Global stiffness matrix
R = np. zeros(Nelem+1).T # Reaction Force
u = np.zeros(Nelem) # Displacement
u_d =np.zeros(Nelem)
Stress = np.zeros(Nelem)
Strain = np.zeros(Nelem)
u1 = np.ones(Nelem+1) # Displacement
F1 = np.zeros(Nelem+1) # Axial Force
U = np.zeros(Nelem) # Global Displacement

#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

# To cancel out first row and first coloumn (Not used)


for dof in BC:
for i in [0,1]:
K_g_1 = np.delete(K_g_1, dof, axis=i)

# Global Stiffness Matrix


print('',end='\n' )
print('',end='\n' )
print('Global Stiffness Matrix =',end='\n' )
print('',end='\n' )
print( K_g)

# Global Stiffness Matrix after elemination


print('',end='\n' )
print('Global Stiffness Matrix (afetr elemination of 1st row and 1st coloumn =',end='\n' )
print('',end='\n' )
print( K_g_1)

# 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)

You might also like