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.
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 ratings0% found this document useful (0 votes)
6 views1 page
GRASP Python (18)
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.
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 self.supports.items(): 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 = np.zeros(2*num_nodes) for node_id, force in self.forces.items(): 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 = np.linalg.solve(K_reduced, F_reduced) except np.linalg.LinAlgError: print("Error: Structure is unstable or matrix is singular") return
# Create full displacement vector
U = np.zeros(2*num_nodes) U[free_dofs] = displacements