0% found this document useful (0 votes)
17 views15 pages

Structural dynamics

Structural dynamics

Uploaded by

SUMIT KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views15 pages

Structural dynamics

Structural dynamics

Uploaded by

SUMIT KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Homework 6

FRAME ANALYSIS

# Dependencies
import copy # Allows us to create copies of objects in memory
import math # Math functionality
import numpy as np # Numpy for working with arrays
import matplotlib.pyplot as plt # Plotting functionality

# Constants
E=29000 #(kilopounds per square inch)
Ar=[16,12] #(in^2)
In=[800,400] #(in^4)

xFac = 50 #Scale factor for plotted displacements

# #Nodal coordinates [x, y] (in ascending node order)


nodes = np.array([[0,0],
[30,0],
[45,-20]])

# #Members [node_i, node_j]


members = np.array([[1,2],
[2,3]])

# #Supports
restrainedDOF=[1, 2, 3, 7, 8, 9] #The degrees of freedom restrained by supports

# #Loading
forceVector=np.array([[0,-30,0,0,-30,2700,0,0,0]]).T

fig = plt.figure()
axes = fig.add_axes([0.1,0.1,2,2])
fig.gca().set_aspect('equal', adjustable='box')

#Plot members
for mbr in members:
node_i = mbr[0] #Node number for node i of this member
node_j = mbr[1] #Node number for node j of this member

ix = nodes[node_i-1,0] #x-coord of node i of this member


iy = nodes[node_i-1,1] #y-coord of node i of this member
jx = nodes[node_j-1,0] #x-coord of node j of this member
jy = nodes[node_j-1,1] #y-coord of node j of this member

axes.plot([ix,jx],[iy,jy],'b') #Member

#Plot nodes
for node in nodes:
axes.plot([node[0]],[node[1]],'bo')

axes.set_xlabel('Distance (m)')
axes.set_ylabel('Distance (m)')
axes.set_title('Structure to analyse')
axes.grid()
plt.show()
Calculate member orientation and length

#Define a function to calculate member orientation and length


def memberOrientation(memberNo):
memberIndex = memberNo-1 #Index identifying member in array of members
node_i = members[memberIndex][0] #Node number for node i of this member
node_j = members[memberIndex][1] #Node number for node j of this member

xi = nodes[node_i-1][0] #x-coord for node i


yi = nodes[node_i-1][1] #y-coord for node i
xj = nodes[node_j-1][0] #x-coord for node j
yj = nodes[node_j-1][1] #y-coord for node j

#Angle of member with respect to horizontal axis

dx = xj-xi #x-component of vector along member


dy = yj-yi #y-component of vector along member
mag = math.sqrt(dx**2 + dy**2) #Magnitude of vector (length of member)
memberVector = np.array([dx,dy])#Member represented as a vector

#Need to capture quadrant first then appropriate reference axis and offset angle
if(dx>0 and dy==0):
theta = 0
elif(dx==0 and dy>0):
theta = math.pi/2
elif(dx<0 and dy==0):
theta = math.pi
elif(dx==0 and dy<0):
theta = 3*math.pi/2
elif(dx>0 and dy>0):
# 0<theta<90
refVector = np.array([1,0]) # Vector describing the positive x-axis
theta = math.acos(refVector.dot(memberVector)/(mag))#Standard formula for the angle between two vectors
elif(dx<0 and dy>0):
# 90<theta<180
refVector = np.array([0,1]) # Vector describing the positive y-axis
theta = (math.pi/2) + math.acos(refVector.dot(memberVector)/(mag))#Standard formula for the angle between two
elif(dx<0 and dy<0):
# 180<theta<270
refVector = np.array([-1,0]) # Vector describing the negative x-axis
theta = math.pi + math.acos(refVector.dot(memberVector)/(mag))#Standard formula for the angle between two vec
else:
# 270<theta<360
refVector = np.array([0,-1]) # Vector describing the negative y-axis
theta = (3*math.pi/2) + math.acos(refVector.dot(memberVector)/(mag))#Standard formula for the angle between t

return [theta, mag]

#Calculate orientation and length for each member and store


orientations = np.array([])#Initialise an array to hold orientations
lengths = np.array([]) #Initialise an array to hold lengths
for n, mbr in enumerate(members):
[angle, length] = memberOrientation(n+1)
orientations = np.append(orientations,angle)
lengths = np.append(lengths,length)
Define a function to calculate member global stiffness
matrix
#Define a function to calculate the global stiffness matrix for a beam element
def calculateKg(memberNo):

theta = orientations[memberNo-1]
L = lengths[memberNo-1]*12
A=Ar[memberNo-1]
I=In[memberNo-1]

c = math.cos(theta)
s = math.sin(theta)

#Define the transformation matrix


TM = np.array([[c,s,0,0,0,0],
[-s,c,0,0,0,0],
[0,0,1,0,0,0],
[0,0,0,c,s,0],
[0,0,0,-s,c,0],
[0,0,0,0,0,1]])

#For clarity, define individual elements of local stiffness matrix


#Row 1
k11 = E*A/L
k12 = 0
k13 = 0
k14 = -E*A/L
k15 = 0
k16 = 0
#Row 2
k21 = 0
k22 = 12*E*I/L**3
k23 = 6*E*I/L**2
k24 = 0
k25 = -12*E*I/L**3
k26 = 6*E*I/L**2
#Row 3
k31 = 0
k32 = 6*E*I/L**2
k33 = 4*E*I/L
k34 = 0
k35 = -6*E*I/L**2
k36 = 2*E*I/L
#Row 4
k41 = -E*A/L
k42 = 0
k43 = 0
k44 = E*A/L
k45 = 0
k46 = 0
#Row 5
k51 = 0
k52 = -12*E*I/L**3
k53 = -6*E*I/L**2
k54 = 0
k55 = 12*E*I/L**3
k56 = -6*E*I/L**2
#Row 6
k61 = 0
k62 = 6*E*I/L**2
k63 = 2*E*I/L
k64 = 0
k65 = -6*E*I/L**2
k66 = 4*E*I/L

#Build the quadrants of the local stiffness matrix


K11 = np.array([[k11,k12,k13],[k21,k22,k23],[k31,k32,k33]]) #Top left quadrant of local stiffness matrix
K12 = np.array([[k14,k15,k16],[k24,k25,k26],[k34,k35,k36]]) #Top right quadrant of local stiffness matrix
K21 = np.array([[k41,k42,k43],[k51,k52,k53],[k61,k62,k63]]) #Bottom left quadrant of local stiffness matrix
K22 = np.array([[k44,k45,k46],[k54,k55,k56],[k64,k65,k66]]) #Bottom right quadrant of local stiffness matrix

#Build complete local element stiffness matrix


top = np.concatenate((K11,K12),axis=1) #Top 3 rows
btm = np.concatenate((K21,K22),axis=1) #Bottom 3 rows
Kl = np.concatenate((top,btm), axis=0) #Full local stiffness matrix

#Calculate the element global stiffness matrix


Kg = TM.T.dot(Kl).dot(TM)
#Kg = np.round(TM.T@Kl@TM,1) #Matrix multiply symbol as pf Python 3.5

#Divide global element stiffness matrix quadrants for return


K11g = Kg[0:3,0:3]
K12g = Kg[0:3,3:6]
K21g = Kg[3:6,0:3]
K22g = Kg[3:6,3:6]

return [K11g, K12g, K21g, K22g]

nDoF = np.amax(members)*3 #Total number of degrees of freedom in the problem


Kp = np.zeros([nDoF,nDoF]) #Initialise the primary stiffness matrix

for n, mbr in enumerate(members):


#note that enumerate adds a counter to an iterable (n)

#Calculate the quadrants of the global stiffness matrix for the member
[K11, K12, K21,K22] = calculateKg(n+1)

node_i = mbr[0] #Node number for node i of this member


node_j = mbr[1] #Node number for node j of this member

#Primary stiffness matrix indices associated with each node


#i.e. node 1 occupies indices 0, 1 and 2 (accessed in Python with [0:3])
ia = 3*node_i-3 #index 0 (e.g. node 1)
ib = 3*node_i-1 #index 2 (e.g. node 1)
ja = 3*node_j-3 #index 3 (e.g. node 2)
jb = 3*node_j-1 #index 5 (e.g. node 2)
Kp[ia:ib+1,ia:ib+1] = Kp[ia:ib+1,ia:ib+1] + K11
Kp[ia:ib+1,ja:jb+1] = Kp[ia:ib+1,ja:jb+1] + K12
Kp[ja:jb+1,ia:ib+1] = Kp[ja:jb+1,ia:ib+1] + K21
Kp[ja:jb+1,ja:jb+1] = Kp[ja:jb+1,ja:jb+1] + K22

Extract structure stiffness matrix, Ks


restrainedIndex = [x - 1 for x in restrainedDOF] #Index for each restrained DoF (list comprehension)

#Reduce to structure stiffness matrix by deleting rows and columns for restrained DoF
Ks = np.delete(Kp,restrainedIndex,0) #Delete rows
Ks = np.delete(Ks,restrainedIndex,1) #Delete columns
Ks = np.matrix(Ks) # Convert Ks from numpy.ndarray to numpy.matrix to use build in inverter function
print("structure sti¤ness matrix:")
print(Ks)

structure sti¤ness matrix:


[[ 1709.78844444 -554.32533333 618.66666667]
[ -554.32533333 750.22307819 -610.07407407]
[ 618.66666667 -610.07407407 412444.44444444]]

Solve for displacements


forceVectorRed = copy.copy(forceVector)# Make a copy of forceVector so the copy can be edited, leaving the original u
forceVectorRed = np.delete(forceVectorRed,restrainedIndex,0) #Delete rows corresponding to restrained DoF
U = Ks.I*forceVectorRed
print('Displacements:')
print(U)

Displacements:
[[-0.017888 ]
[-0.0479176 ]
[ 0.00650229]]

Solve for reactions


#Construct the global displacement vector
UG = np.zeros(nDoF) #Initialise an array to hold the global displacement vector
c=0 #Initialise a counter to track how many restraints have been imposed
for i in np.arange(nDoF):
if i in restrainedIndex:
#Impose zero displacement
UG[i] = 0
else:
#Assign actual displacement
UG[i] = U[c]
c=c+1
UG = np.array([UG]).T
FG = np.matmul(Kp,UG)
forceVector=np.array([[0,30,1800,0,30,-1800,0,0,0]]).T
FG=FG+forceVector
C:\Users\sxk2012\AppData\Local\Temp\ipykernel_24368\3585855237.py:10: DeprecationWarning: Conversion of an array
with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your
array before performing this operation. (Deprecated NumPy 1.25.)
UG[i] = U[c]

Solve for member actions (Axial Force, BM, Shear)


mbrForces = np.array([]) #Initialise an array to hold member axial forces
mbrShears = np.zeros(members.shape) #Initialise an array to hold member shear forces
mbrMoments = np.zeros(members.shape) #Initialise an array to hold member moments

for n, mbr in enumerate(members):


theta = orientations[n]
L = lengths[n]
A=Ar[n]
I=In[n]

node_i = mbr[0] #Node number for node i of this member


node_j = mbr[1] #Node number for node j of this member
#Primary stiffness matrix indices associated with each node
ia = 3*node_i-3 #index 0 (e.g. node 1)
ib = 3*node_i-1 #index 2 (e.g. node 1)
ja = 3*node_j-3 #index 3 (e.g. node 2)
jb = 3*node_j-1 #index 5 (e.g. node 2)

#Transformation matrix
c = math.cos(theta)
s = math.sin(theta)

#Define the transformation matrix


T = np.array([[c,s,0,0,0,0],
[-s,c,0,0,0,0],
[0,0,1,0,0,0],
[0,0,0,c,s,0],
[0,0,0,-s,c,0],
[0,0,0,0,0,1]])

disp = np.array([ [UG[ia,0],UG[ia+1,0],UG[ib,0],UG[ja,0],UG[ja+1,0],UG[jb,0]]]).T


disp_local = np.matmul(T,disp)

F_axial = (A*E/L)*(disp_local[3]-disp_local[0])[0]

#Calculate the quadrants of the global stiffness matrix for the member
[K11, K12, K21,K22] = calculateKg(n+1)

#Build complete global element stiffness matrix


top = np.concatenate((K11,K12),axis=1) #Top 3 rows
btm = np.concatenate((K21,K22),axis=1) #Bottom 3 rows
Kg = np.concatenate((top,btm), axis=0) #Full global stiffness matrix

#Convert back to local stiffness matrix


Kl = T.dot(Kg).dot(T.T)

#Compute moments at each end of the member


Mi = Kl[2,:].dot(disp_local)[0]
Mj = Kl[5,:].dot(disp_local)[0]

#Compute shear forces at each end of the member


Fy_i = Kl[1,:].dot(disp_local)[0]
Fy_j = Kl[4,:].dot(disp_local)[0]

#Store member actions


mbrForces = np.append(mbrForces,F_axial) #Store axial loads

mbrShears[n,0] = Fy_i
mbrShears[n,1] = Fy_j

mbrMoments[n,0] = Mi
mbrMoments[n,1] = Mj

fig = plt.figure()
axes = fig.add_axes([0.1,0.1,2,2])
fig.gca().set_aspect('equal', adjustable='box')

#Plot members
for mbr in members:
node_i = mbr[0] #Node number for node i of this member
node_j = mbr[1] #Node number for node j of this member

ix = nodes[node_i-1,0] #x-coord of node i of this member


iy = nodes[node_i-1,1] #y-coord of node i of this member
jx = nodes[node_j-1,0] #x-coord of node j of this member
jy = nodes[node_j-1,1] #y-coord of node j of this member

ia = 3*node_i-3 #index 0 (e.g. node 1)


ib = 3*node_i-1 #index 2 (e.g. node 1)
ja = 3*node_j-3 #index 3 (e.g. node 2)
jb = 3*node_j-1 #index 5 (e.g. node 2)

axes.plot([ix,jx],[iy,jy],'b') #Member
axes.plot([ix + UG[ia,0]*xFac, jx + UG[ja,0]*xFac], [iy + UG[ia+1,0]*xFac, jy + UG[ja+1,0]*xFac],'--r') #Deformed

#Plot nodes
for node in nodes:
axes.plot([node[0]],[node[1]],'bo')

axes.set_xlabel('Distance (m)')
axes.set_ylabel('Distance (m)')
axes.set_title('Deflected shape')
axes.grid()
plt.show()

Result Summary

#Generate output statements


print("REACTIONS")
for i in np.arange(0,len(restrainedIndex)):
index = restrainedIndex[i]
if index in [0,1,6,7]:
print("- Reaction at DoF {one}: {two} k".format(one = index+1, two = round(FG[index].item(),2)))
else:
print("- Reaction at DoF {one}: {two} k-in".format(one = index+1, two = round(FG[index].item(),2)))

print("")
print("MEMBER AXIAL FORCES")
for n, mbr in enumerate(members):
print("- Force in member {one} (nodes {two} to {three}) is {four} k".format(one = n+1, two=mbr[0], three=mbr[1],

print("")
print("MEMBER SHEAR FORCES")
for n, mbr in enumerate(members):
print("- Shear force in member {one} (nodes {two}/{three}) is {four}/{five} k".format(one = n+1, two=mbr[0], thre

print("")
print("MEMBER BENDING MOMENTS")
for n, mbr in enumerate(members):
print("- Bending moment in member {one} (nodes {two}/{three}) is {four}/{five} kin".format(one = n+1, two=mbr[0

print("")
print("NODAL DISPLACEMENTS")
for n, node in enumerate(nodes):
ix = 3*(n+1)-3 #horizontal DoF for this node
iy = ix+1 #vertical DoF for this node
iz = ix+2 #rotational DoF for this node

ux = round(UG[ix,0],5) #Horizontal nodal displacement


uy = round(UG[iy,0],5) #Vertical nodal displacement
theta = round(UG[iz,0],5) #Nodal rotation
print("- Node {one}: Ux = {two} in, Uy = {three} in, theta = {four} radians".format(one=n+1, two=ux, three=uy,

REACTIONS
- Reaction at DoF 1: 23.06 k
- Reaction at DoF 2: 37.27 k
- Reaction at DoF 3: 2689.54 k-in
- Reaction at DoF 7: -23.06 k
- Reaction at DoF 8: 22.73 k
- Reaction at DoF 9: 469.54 k-in

MEMBER AXIAL FORCES


- Force in member 1 (nodes 1 to 2) is -276.67 k
- Force in member 2 (nodes 2 to 3) is -384.21 k

MEMBER SHEAR FORCES


- Shear force in member 1 (nodes 1/2) is 7.27/-7.27 k
- Shear force in member 2 (nodes 2/3) is 4.81/-4.81 k

MEMBER BENDING MOMENTS


- Bending moment in member 1 (nodes 1/2) is 889.54/1727.61 kin
- Bending moment in member 2 (nodes 2/3) is 972.39/469.54 kin

NODAL DISPLACEMENTS
- Node 1: Ux = 0.0 in, Uy = 0.0 in, theta = 0.0 radians
- Node 2: Ux = -0.01789 in, Uy = -0.04792 in, theta = 0.0065 radians
- Node 3: Ux = 0.0 in, Uy = 0.0 in, theta = 0.0 radians
Loading [MathJax]/extensions/Safe.js
Beam Analysis

# Dependencies
import copy # Allows us to create copies of objects in memory
import math # Math functionality
import numpy as np # Numpy for working with arrays
import matplotlib.pyplot as plt # Plotting functionality

# Constants
E=1 #()
Ar=[1,1,1] #(in^2)
In=[1,1,1] #(in^4)

xFac = 50 #Scale factor for plotted displacements

# #Nodal coordinates [x, y] (in ascending node order)


nodes = np.array([[0,0],
[10,0],
[20,0],
[25,0]])

# #Members [node_i, node_j]


members = np.array([[1,2],
[2,3],
[3,4]])

# #Supports
restrainedDOF=[1, 2, 3,4,5, 7, 8, 10,11,12] #The degrees of freedom restrained by supports

# #Loading
forceVector=np.array([[0,28.16,76.8,0,171.84,-84.8,0,120,200,0,0,0]]).T

fig = plt.figure()
axes = fig.add_axes([0.1,0.1,2,2])
fig.gca().set_aspect('equal', adjustable='box')

#Plot members
for mbr in members:
node_i = mbr[0] #Node number for node i of this member
node_j = mbr[1] #Node number for node j of this member

ix = nodes[node_i-1,0] #x-coord of node i of this member


iy = nodes[node_i-1,1] #y-coord of node i of this member
jx = nodes[node_j-1,0] #x-coord of node j of this member
jy = nodes[node_j-1,1] #y-coord of node j of this member

axes.plot([ix,jx],[iy,jy],'b') #Member

#Plot nodes
for node in nodes:
axes.plot([node[0]],[node[1]-1],'bo')

axes.set_xlabel('Distance (m)')
axes.set_ylabel('Distance (m)')
axes.set_title('Structure to analyse')
axes.grid()
plt.show()

#Define a function to calculate member orientation and length


def memberOrientation(memberNo):
memberIndex = memberNo-1 #Index identifying member in array of members
node_i = members[memberIndex][0] #Node number for node i of this member
node_j = members[memberIndex][1] #Node number for node j of this member

xi = nodes[node_i-1][0] #x-coord for node i


yi = nodes[node_i-1][1] #y-coord for node i
xj = nodes[node_j-1][0] #x-coord for node j
yj = nodes[node_j-1][1] #y-coord for node j

#Angle of member with respect to horizontal axis

dx = xj-xi #x-component of vector along member


dy = yj-yi #y-component of vector along member
mag = math.sqrt(dx**2 + dy**2) #Magnitude of vector (length of member)
memberVector = np.array([dx,dy])#Member represented as a vector

#Need to capture quadrant first then appropriate reference axis and offset angle
if(dx>0 and dy==0):
theta = 0
elif(dx==0 and dy>0):
theta = math.pi/2
elif(dx<0 and dy==0):
theta = math.pi
elif(dx==0 and dy<0):
theta = 3*math.pi/2
elif(dx>0 and dy>0):
# 0<theta<90
refVector = np.array([1,0]) # Vector describing the positive x-axis
theta = math.acos(refVector.dot(memberVector)/(mag))#Standard formula for the angle between two vectors
elif(dx<0 and dy>0):
# 90<theta<180
refVector = np.array([0,1]) # Vector describing the positive y-axis
theta = (math.pi/2) + math.acos(refVector.dot(memberVector)/(mag))#Standard formula for the angle between two
elif(dx<0 and dy<0):
# 180<theta<270
refVector = np.array([-1,0]) # Vector describing the negative x-axis
theta = math.pi + math.acos(refVector.dot(memberVector)/(mag))#Standard formula for the angle between two vec
else:
# 270<theta<360
refVector = np.array([0,-1]) # Vector describing the negative y-axis
theta = (3*math.pi/2) + math.acos(refVector.dot(memberVector)/(mag))#Standard formula for the angle between t

return [theta, mag]

#Calculate orientation and length for each member and store


orientations = np.array([])#Initialise an array to hold orientations
lengths = np.array([]) #Initialise an array to hold lengths
for n, mbr in enumerate(members):
[angle, length] = memberOrientation(n+1)
orientations = np.append(orientations,angle)
lengths = np.append(lengths,length)

#Define a function to calculate the global stiffness matrix for a beam element
def calculateKg(memberNo):

theta = orientations[memberNo-1]
L = lengths[memberNo-1]
A=Ar[memberNo-1]
I=In[memberNo-1]

c = math.cos(theta)
s = math.sin(theta)

#Define the transformation matrix


TM = np.array([[c,s,0,0,0,0],
[-s,c,0,0,0,0],
[0,0,1,0,0,0],
[0,0,0,c,s,0],
[0,0,0,-s,c,0],
[0,0,0,0,0,1]])

#For clarity, define individual elements of local stiffness matrix


#Row 1
k11 = E*A/L
k12 = 0
k13 = 0
k14 = -E*A/L
k15 = 0
k16 = 0
#Row 2
k21 = 0
k22 = 12*E*I/L**3
k23 = 6*E*I/L**2
k24 = 0
k25 = -12*E*I/L**3
k26 = 6*E*I/L**2
#Row 3
k31 = 0
k32 = 6*E*I/L**2
k33 = 4*E*I/L
k34 = 0
k35 = -6*E*I/L**2
k36 = 2*E*I/L
#Row 4
k41 = -E*A/L
k42 = 0
k43 = 0
k44 = E*A/L
k45 = 0
k46 = 0
#Row 5
k51 = 0
k52 = -12*E*I/L**3
k53 = -6*E*I/L**2
k54 = 0
k55 = 12*E*I/L**3
k56 = -6*E*I/L**2
#Row 6
k61 = 0
k62 = 6*E*I/L**2
k63 = 2*E*I/L
k64 = 0
k65 = -6*E*I/L**2
k66 = 4*E*I/L

#Build the quadrants of the local stiffness matrix


K11 = np.array([[k11,k12,k13],[k21,k22,k23],[k31,k32,k33]]) #Top left quadrant of local stiffness matrix
K12 = np.array([[k14,k15,k16],[k24,k25,k26],[k34,k35,k36]]) #Top right quadrant of local stiffness matrix
K21 = np.array([[k41,k42,k43],[k51,k52,k53],[k61,k62,k63]]) #Bottom left quadrant of local stiffness matrix
K22 = np.array([[k44,k45,k46],[k54,k55,k56],[k64,k65,k66]]) #Bottom right quadrant of local stiffness matrix

#Build complete local element stiffness matrix


top = np.concatenate((K11,K12),axis=1) #Top 3 rows
btm = np.concatenate((K21,K22),axis=1) #Bottom 3 rows
Kl = np.concatenate((top,btm), axis=0) #Full local stiffness matrix

#Calculate the element global stiffness matrix


Kg = TM.T.dot(Kl).dot(TM)
#Kg = np.round(TM.T@Kl@TM,1) #Matrix multiply symbol as pf Python 3.5

#Divide global element stiffness matrix quadrants for return


K11g = Kg[0:3,0:3]
K12g = Kg[0:3,3:6]
K21g = Kg[3:6,0:3]
K22g = Kg[3:6,3:6]

return [K11g, K12g, K21g, K22g]

nDoF = np.amax(members)*3 #Total number of degrees of freedom in the problem


Kp = np.zeros([nDoF,nDoF]) #Initialise the primary stiffness matrix

for n, mbr in enumerate(members):


#note that enumerate adds a counter to an iterable (n)

#Calculate the quadrants of the global stiffness matrix for the member
[K11, K12, K21,K22] = calculateKg(n+1)

node_i = mbr[0] #Node number for node i of this member


node_j = mbr[1] #Node number for node j of this member

#Primary stiffness matrix indices associated with each node


#i.e. node 1 occupies indices 0, 1 and 2 (accessed in Python with [0:3])
ia = 3*node_i-3 #index 0 (e.g. node 1)
ib = 3*node_i-1 #index 2 (e.g. node 1)
ja = 3*node_j-3 #index 3 (e.g. node 2)
jb = 3*node_j-1 #index 5 (e.g. node 2)
Kp[ia:ib+1,ia:ib+1] = Kp[ia:ib+1,ia:ib+1] + K11
Kp[ia:ib+1,ja:jb+1] = Kp[ia:ib+1,ja:jb+1] + K12
Kp[ja:jb+1,ia:ib+1] = Kp[ja:jb+1,ia:ib+1] + K21
Kp[ja:jb+1,ja:jb+1] = Kp[ja:jb+1,ja:jb+1] + K22

restrainedIndex = [x - 1 for x in restrainedDOF] #Index for each restrained DoF (list comprehension)

#Reduce to structure stiffness matrix by deleting rows and columns for restrained DoF
Ks = np.delete(Kp,restrainedIndex,0) #Delete rows
Ks = np.delete(Ks,restrainedIndex,1) #Delete columns
Ks = np.matrix(Ks) # Convert Ks from numpy.ndarray to numpy.matrix to use build in inverter function
print("structure sti¤ness matrix:")
print(Ks)

structure sti¤ness matrix:


[[0.8 0.2]
[0.2 1.2]]

forceVectorRed = copy.copy(forceVector)# Make a copy of forceVector so the copy can be edited, leaving the original u
forceVectorRed = np.delete(forceVectorRed,restrainedIndex,0) #Delete rows corresponding to restrained DoF
U = Ks.I*forceVectorRed
print('Displacements:')
print(U)
Displacements:
[[-154.08695652]
[ 192.34782609]]

#Construct the global displacement vector


UG = np.zeros(nDoF) #Initialise an array to hold the global displacement vector
c=0 #Initialise a counter to track how many restraints have been imposed
for i in np.arange(nDoF):
if i in restrainedIndex:
#Impose zero displacement
UG[i] = 0
else:
#Assign actual displacement
UG[i] = U[c]
c=c+1
UG = np.array([UG]).T

FG = np.matmul(Kp,UG)
forceVector=np.array([[0,28.16,76.8,0,171.84,-84.8,0,120,200,0,0,0]]).T
FG=FG+forceVector

C:\Users\sxk2012\AppData\Local\Temp\ipykernel_25376\2610428321.py:10: DeprecationWarning: Conversion of an array


with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your
array before performing this operation. (Deprecated NumPy 1.25.)
UG[i] = U[c]

mbrForces = np.array([]) #Initialise an array to hold member axial forces


mbrShears = np.zeros(members.shape) #Initialise an array to hold member shear forces
mbrMoments = np.zeros(members.shape) #Initialise an array to hold member moments

for n, mbr in enumerate(members):


theta = orientations[n]
L = lengths[n]
A=Ar[n]
I=In[n]

node_i = mbr[0] #Node number for node i of this member


node_j = mbr[1] #Node number for node j of this member
#Primary stiffness matrix indices associated with each node
ia = 3*node_i-3 #index 0 (e.g. node 1)
ib = 3*node_i-1 #index 2 (e.g. node 1)
ja = 3*node_j-3 #index 3 (e.g. node 2)
jb = 3*node_j-1 #index 5 (e.g. node 2)

#Transformation matrix
c = math.cos(theta)
s = math.sin(theta)

#Define the transformation matrix


T = np.array([[c,s,0,0,0,0],
[-s,c,0,0,0,0],
[0,0,1,0,0,0],
[0,0,0,c,s,0],
[0,0,0,-s,c,0],
[0,0,0,0,0,1]])

disp = np.array([ [UG[ia,0],UG[ia+1,0],UG[ib,0],UG[ja,0],UG[ja+1,0],UG[jb,0]]]).T


disp_local = np.matmul(T,disp)

F_axial = (A*E/L)*(disp_local[3]-disp_local[0])[0]

#Calculate the quadrants of the global stiffness matrix for the member
[K11, K12, K21,K22] = calculateKg(n+1)

#Build complete global element stiffness matrix


top = np.concatenate((K11,K12),axis=1) #Top 3 rows
btm = np.concatenate((K21,K22),axis=1) #Bottom 3 rows
Kg = np.concatenate((top,btm), axis=0) #Full global stiffness matrix

#Convert back to local stiffness matrix


Kl = T.dot(Kg).dot(T.T)

#Compute moments at each end of the member


Mi = Kl[2,:].dot(disp_local)[0]
Mj = Kl[5,:].dot(disp_local)[0]

#Compute shear forces at each end of the member


Fy_i = Kl[1,:].dot(disp_local)[0]
Fy_j = Kl[4,:].dot(disp_local)[0]

#Store member actions


mbrForces = np.append(mbrForces,F_axial) #Store axial loads

mbrShears[n,0] = Fy_i
mbrShears[n,1] = Fy_j

mbrMoments[n,0] = Mi
mbrMoments[n,1] = Mj

fig = plt.figure()
axes = fig.add_axes([0.1,0.1,2,2])
fig.gca().set_aspect('equal', adjustable='box')

#Plot members
for mbr in members:
node_i = mbr[0] #Node number for node i of this member
node_j = mbr[1] #Node number for node j of this member

ix = nodes[node_i-1,0] #x-coord of node i of this member


iy = nodes[node_i-1,1] #y-coord of node i of this member
jx = nodes[node_j-1,0] #x-coord of node j of this member
jy = nodes[node_j-1,1] #y-coord of node j of this member

ia = 3*node_i-3 #index 0 (e.g. node 1)


ib = 3*node_i-1 #index 2 (e.g. node 1)
ja = 3*node_j-3 #index 3 (e.g. node 2)
jb = 3*node_j-1 #index 5 (e.g. node 2)

axes.plot([ix,jx],[iy,jy],'b') #Member
axes.plot([ix + UG[ia,0]*xFac, jx + UG[ja,0]*xFac], [iy + UG[ia+1,0]*xFac, jy + UG[ja+1,0]*xFac],'--r') #Deformed

#Plot nodes
for node in nodes:
axes.plot([node[0]],[node[1]-1],'bo')

axes.set_xlabel('Distance (m)')
axes.set_ylabel('Distance (m)')
axes.set_title('Deflected shape')
axes.grid()
plt.show()

#Generate output statements


print("REACTIONS")
for i in np.arange(0,len(restrainedIndex)):
index = restrainedIndex[i]
if index in [0,1,3,4,6,7,9,10]:
print("- Reaction at DoF {one}: {two} KN".format(one = index+1, two = round(FG[index].item(),2)))
else:
print("- Reaction at DoF {one}: {two} KN-m".format(one = index+1, two = round(FG[index].item(),2)))

print("")
print("MEMBER AXIAL FORCES")
for n, mbr in enumerate(members):
print("- Force in member {one} (nodes {two} to {three}) is {four} KN".format(one = n+1, two=mbr[0], three=mbr[1

print("")
print("MEMBER SHEAR FORCES")
for n, mbr in enumerate(members):
print("- Shear force in member {one} (nodes {two}/{three}) is {four}/{five} KN".format(one = n+1, two=mbr[0], thr

print("")
print("MEMBER BENDING MOMENTS")
for n, mbr in enumerate(members):
print("- Bending moment in member {one} (nodes {two}/{three}) is {four}/{five} KN-m".format(one = n+1, two=mbr[

print("")
print("NODAL DISPLACEMENTS")
for n, node in enumerate(nodes):
ix = 3*(n+1)-3 #horizontal DoF for this node
iy = ix+1 #vertical DoF for this node
iz = ix+2 #rotational DoF for this node

ux = round(UG[ix,0],5) #Horizontal nodal displacement


uy = round(UG[iy,0],5) #Vertical nodal displacement
theta = round(UG[iz,0],5) #Nodal rotation
print("- Node {one}: Ux = {two} in, Uy = {three} in, theta = {four} radians".format(one=n+1, two=ux, three=uy,
REACTIONS
- Reaction at DoF 1: 0.0 KN
- Reaction at DoF 2: 18.91 KN
- Reaction at DoF 3: 45.98 KN-m
- Reaction at DoF 4: 0.0 KN
- Reaction at DoF 5: 183.38 KN
- Reaction at DoF 7: 0.0 KN
- Reaction at DoF 8: 163.87 KN
- Reaction at DoF 10: 0.0 KN
- Reaction at DoF 11: -46.16 KN
- Reaction at DoF 12: 76.94 KN-m

MEMBER AXIAL FORCES


- Force in member 1 (nodes 1 to 2) is 0.0 KN
- Force in member 2 (nodes 2 to 3) is 0.0 KN
- Force in member 3 (nodes 3 to 4) is 0.0 KN

MEMBER SHEAR FORCES


- Shear force in member 1 (nodes 1/2) is -9.25/9.25 KN
- Shear force in member 2 (nodes 2/3) is 2.3/-2.3 KN
- Shear force in member 3 (nodes 3/4) is 46.16/-46.16 KN

MEMBER BENDING MOMENTS


- Bending moment in member 1 (nodes 1/2) is -30.82/-61.63 KN-m
- Bending moment in member 2 (nodes 2/3) is -23.17/46.12 KN-m
- Bending moment in member 3 (nodes 3/4) is 153.88/76.94 KN-m

NODAL DISPLACEMENTS
- Node 1: Ux = 0.0 in, Uy = 0.0 in, theta = 0.0 radians
- Node 2: Ux = 0.0 in, Uy = 0.0 in, theta = -154.08696 radians
- Node 3: Ux = 0.0 in, Uy = 0.0 in, theta = 192.34783 radians
- Node 4: Ux = 0.0 in, Uy = 0.0 in, theta = 0.0 radians
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js

You might also like