Lightweight 2-D Frame Topology Optimisation for Python
A pure-Python port of the MATLAB toolkit for finite element analysis and stress-ratio thickness optimisation of 2-D frame and truss structures. Import geometry, analyse, optimise, and export CAD-ready profiles — all in one workflow.
Example of a beam optimization:
Example of a truss optimization:


Highlights
- Linear & nonlinear FEA — Euler–Bernoulli frame elements with Newton–Raphson large-deflection solver
- Stress-ratio thickness optimisation — iteratively redistributes material for uniform stress, producing organic variable-thickness shapes
- Truss subdivision — refine coarse trusses into fine meshes for topology-like optimisation where load paths emerge naturally
- Image-processing profile export — rasterise optimised structures, extract boundary loops, fit splines, and export SolidWorks-ready point files
- Geometry import — CSV and IGES/IGS files (e.g. SolidWorks sketch exports)
- Vectorised internals — NumPy broadcasting, batched
einsumoperations, and SciPy sparse solvers for performance
Included Demos
| Demo | Description |
|---|---|
demo_beam.py |
Import an S-curve from IGS, run nonlinear FEA, optimise thickness, and export the organic profile |
demo_truss.py |
4-bay cantilever truss with tip force + moment, subdivided into 850 elements, optimised to show load path emergence with before/after plots |
Requirements
- Python 3.9+
- NumPy and SciPy
- matplotlib (for visualisation)
- scikit-image (for profile export)
Quick Start
pip install numpy scipy matplotlib scikit-image
python examples/demo_beam.pyWhat's New (vs MATLAB v1.0)
This is a complete Python port of the MATLAB original with the same mathematical formulations and default parameters. Key differences:
- 0-based indexing throughout (nodes, elements, DOFs, constraints)
- Vectorised element operations — stiffness matrices, transformations, and internal forces are computed for all elements simultaneously as
(M, 6, 6)array operations, replacing per-element loops - Sparse assembly — global stiffness matrix built as
scipy.sparse.csr_matrixin a single call - scikit-image replaces MATLAB's Image Processing Toolbox for profile export
- Performance fix — morphological closing disk radius is capped to prevent excessive runtimes on large images
- Dict-based API — results, options, and imported data returned as Python dicts
License
MIT