Skip to content

Releases: nathan-carmichael/lw-feaopt-py

ShepherdLab LW FEA-OPT v1.0 (Python)

Choose a tag to compare

@nathan-carmichael nathan-carmichael released this 11 Mar 14:20

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:

optimized beam python optimized beam python spline

Example of a truss optimization:
optimized truss python
optimized truss python spline


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 einsum operations, 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.py

What'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_matrix in 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