0% found this document useful (0 votes)
28 views1 page

GRASP Python

The document outlines the process of calculating the element stiffness matrix in local and global coordinates for a structural analysis. It includes steps for applying boundary conditions, removing fixed degrees of freedom, creating a force vector, and solving for displacements. The final output is a full displacement vector that incorporates the calculated displacements for free degrees of freedom.

Uploaded by

Le Fondateur
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)
28 views1 page

GRASP Python

The document outlines the process of calculating the element stiffness matrix in local and global coordinates for a structural analysis. It includes steps for applying boundary conditions, removing fixed degrees of freedom, creating a force vector, and solving for displacements. The final output is a full displacement vector that incorporates the calculated displacements for free degrees of freedom.

Uploaded by

Le Fondateur
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

# Element stiffness matrix in local coordinates

k_local = (E*A/L) * [Link]([


[1, -1],
[-1, 1]
])

# Transformation matrix
T = [Link]([
[c, s, 0, 0],
[0, 0, c, s]
])

# Element stiffness matrix in global coordinates


k_global = T.T @ k_local @ T

# Get global DOF indices


dof_indices = [
2*(node1-1), 2*(node1-1)+1,
2*(node2-1), 2*(node2-1)+1
]

# Add to global stiffness matrix


for i in range(4):
for j in range(4):
K_global[dof_indices[i], dof_indices[j]] += k_global[i,
j]

# Apply boundary conditions


fixed_dofs = []
for node_id, support in [Link]():
if support == 'fixed':
fixed_dofs.extend([2*(node_id-1), 2*(node_id-1)+1])
elif support == 'pinned' or support == 'roller':
fixed_dofs.append(2*(node_id-1)+1) # Fixed in y-direction

# Remove fixed DOFs from the system


free_dofs = [i for i in range(2*num_nodes) if i not in fixed_dofs]
K_reduced = K_global[np.ix_(free_dofs, free_dofs)]

# Create force vector


F = [Link](2*num_nodes)
for node_id, force in [Link]():
F[2*(node_id-1)] = force['fx']
F[2*(node_id-1)+1] = force['fy']
F_reduced = F[free_dofs]

# Solve for displacements


try:
displacements = [Link](K_reduced, F_reduced)
except [Link]:
print("Error: Structure is unstable or matrix is singular")
return

# Create full displacement vector


U = [Link](2*num_nodes)
U[free_dofs] = displacements

P a g e 4 | 62

You might also like