This repository provides a modular and well-documented implementation for truss topology optimization with respect to peak power, including penalization strategies. The code is organized for clarity and ease of extension, and is inspired by the example at https://gitlab.com/ma.shenyuan/truss_exp/-/blob/main/example/peak_power.ipynb.
run_truss_peak_power_optimization.py: Main script for running all truss optimization and plotting experiments. This is the entry point for most users.peak_power_calculations.py: Contains thePeakPowerCalculatorclass, which implements all peak power calculations (uniform, optimized, penalized, and eta sweep).truss_visualization.py: Contains theTrussPlotterclass for visualizing truss structures and plotting peak power vs penalization parameter.truss_fem_core.py: Core truss and FEM model definitions (containsnodes,elements,truss).
- Install dependencies (see below).
- Run the main script:
This will:
python run_truss_peak_power_optimization.py
- Compute and print peak power for uniform, optimized, and penalized trusses.
- Sweep over multiple penalization parameters (eta) and report the best result.
- Plot the effect of eta on peak power.
- Show a 2x2 comparison of truss structures (uniform, optimized, penalized for eta=1, penalized for best eta).
- All major steps in the main script are clearly commented and sectioned:
- Problem and model settings
- Geometry and FEM assembly
- Load definition
- Peak power calculations (uniform, optimized, penalized)
- Visualization (plots)
- Utility and plotting classes are documented with docstrings and inline comments.
- The code is modular: you can easily swap out or extend optimization and plotting routines.
picos(for optimization)mosek(solver, or another compatible solver)
Install dependencies with:
pip install numpy matplotlib picos
# For mosek, see https://www.mosek.com/products/mosek/ for installation instructions- To add new optimization strategies, extend
PeakPowerCalculatorinpeak_power_calculations.py. - For new visualizations, add methods to
TrussPlotterintruss_visualization.py. - For new truss geometries, modify the node and element definitions in the main script.
- Original reference notebook(which doesnot work as intended): peak_power.ipynb
For questions or contributions, please open an issue or contact me.