Python implementation of a planar truss solver for strength-of-materials coursework. The code reads node/element/material data from CSV files, assembles the global stiffness matrix, solves for nodal displacements and support reactions, and reports axial forces, stresses, and material phase for each member.
- Linear-elastic 2D truss analysis using the matrix stiffness method (NumPy)
- CSV-driven inputs for nodes, elements, and materials; easy to edit for new cases
- Computes nodal displacements, support reactions, axial forces, stresses, and state (tension/compression)
- Flags plastic/fracture phases based on yield/ultimate stress limits
- Text tables generated via
tabulateand saved toio/result.txt - Modular layout (
io/,model/,solver/) for simple extension or replacement of components
main.py— orchestrates reading inputs, assembling, solving, and writing resultsio/reader.py— loads CSV data fromio/io/writer.py— formats and writes result tables toio/result.txtmodel/— core classes:Node,Element,Materialsolver/— assembly (assembly.py), boundary conditions (boundary.py), and linear solution (solve.py)io/*.csv— sample datasets for nodes, elements, and material properties
io/nodes_input.csv- Columns:
ID, x, y, F_x, F_y, constrained_x, constrained_y constrained_*:1for fixed DOF,0for free. Use consistent units for forces and lengths.
- Columns:
io/elements_input.csv- Columns:
ID, node_1, node_2, cross_sectional_area, material materialmust match a name inmaterial.csv; area in square meters.
- Columns:
io/material.csv- Columns:
name, E, S_y, S_u Ein GPa;S_yandS_uin MPa. Values are converted to Pascals internally.
- Columns:
- Python 3.9+
- Packages:
numpy,tabulate(seerequirements.txt)
From the directory that contains the mom_project folder:
python -m venv .venv
.venv\Scripts\activate
pip install -r mom_project/requirements.txt
python -m mom_project.mainAfter execution, open mom_project/io/result.txt to view:
- Nodal displacements (Ux, Uy)
- Support reactions (Rx, Ry) at constrained DOFs
- Element axial forces, stresses, tension/compression state, and phase (Elastic/Plastic/Fracture)
Nodal Displacements (Ux, Uy):
| Node | Ux | Uy |
| 3 | -2.35357e-05 | -3.09817e-05 |
...
Element Axial Forces and Stresses:
| Element | N | Sigma | State | Phase |
| 6 | -2.82843e+04 | 2.35702e+06 | Tension | Elastic |
- Pin-jointed, small-displacement, linear-elastic truss; no geometric or material nonlinearity.
- Node IDs and element connectivity must be consistent across CSV files.
- Units must be compatible across forces, lengths, and material properties.
- To analyze a new case, edit the three CSV files in
io/and rerunpython -m mom_project.main.