ACCESS THE COMPLETE LIBRARY OF COURSES & TUTORIALS ➡️
40. Building the primary stiffness matrix
Optimising for Larger Structures in Python
📂 Please log in or enroll to access resources

Summary

In this lecture, we'll cover:

  • Setting up a new truss analysis in a Jupyter Notebook environment
  • Defining material properties, degrees of freedom, restraints and the global force vector
  • Reusing and adapting a function to compute the element stiffness matrix
  • Writing a new function to automatically assemble the primary (global) stiffness matrix
  • Programmatically adding each element’s stiffness contribution to the correct location in the global matrix

In this lecture, we work through a second truss example in a more efficient and structured way than before. We begin by setting up the problem in Python, importing the required libraries, defining Young’s modulus and cross-sectional area (temporarily set to unity for consistency with earlier calculations), and explicitly specifying the total degrees of freedom, restrained degrees of freedom and the global force vector. We then reuse a previously developed function to compute each element stiffness matrix, adapting it slightly so that element orientation is provided in degrees rather than radians.

The key focus of the lecture is the automated assembly of the primary (global) stiffness matrix. Instead of manually inserting each element stiffness matrix into the correct position, we write a dedicated function that determines the correct matrix indices from the element’s node numbers. By mapping node numbers to their associated global degree-of-freedom indices, we systematically place each of the four stiffness submatrices into the correct block of the global matrix, adding contributions rather than overwriting existing terms. This approach significantly improves efficiency, clarity and scalability, allowing us to assemble the full 12 ×\times 12 primary stiffness matrix simply by calling the function once for each element.

Next up:

In the next lecture, we extract the structure stiffness matrix from the primary stiffness matrix by programmatically removing restrained rows and columns.

Tags

global stiffness matrix assemblyPython implementationdegree of freedom indexing

Please log in or enroll to continue

If you've already enrolled, please log in to continue.

The Direct Stiffness Method for Truss Analysis with Python

Build your own finite element truss analysis software using Python and tackle large scale structures.

After completing this course...

  • You’ll understand how to use the Direct Stiffness Method to build complete structural models that can be solved using Python.
  • You’ll have your own analysis programme to identify displacements, reactions and internal member forces for any truss.
  • You’ll understand how common models of elastic behaviour such as plane stress and plane strain apply to real-world structures.
Next Lesson
41. Extracting the structure stiffness matrix