This repo is a starter kit for a Numerical Methods programming assignment on quasi-Newton optimization (BFGS).
Students will minimize the energy of a closed, charged elastic filament in 3D, discretized as N points.
The energy combines:
- Bending (curvature penalty),
- Stretching (near-inextensibility),
- Screened Coulomb repulsion (Debye–Hückel).
The core energy + gradient kernel is implemented in C++ for speed and exposed to Python via ctypes. You will implement BFGS (and a line search) in Python and use it to find low-energy configurations.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e .Linux/macOS (clang/gcc):
bash csrc/build.shThis produces csrc/librod.so (Linux) or csrc/librod.dylib (macOS).
pytest -qpython scripts/run_opt.py --N 120 --steps 200src/elastic_rod/bfgs.py: BFGS update + line search (Wolfe or backtracking).csrc/rod_energy.cpp: The code described in the TODO: comment.- (Optional) better initialization and plotting in
scripts/run_opt.py.
csrc/: C++ energy + gradient, builds a shared librarysrc/elastic_rod/: Python wrapper + optimization codedocs/background.tex: short LaTeX background note (assignment handout)tests/: finite-difference gradient checks
kb: bending stiffnessks: stretching stiffnessl0: rest segment lengthq: charge magnitude per nodekappa: screening parameter (0 gives unscreened Coulomb)
See src/elastic_rod/model.py.
MIT (for the starter code). Add your course policy as needed.
Staff: see gradescope/README_GRADESCOPE.md for an autograder skeleton.
Students: see docs/AUTOGRADING.md and run python scripts/autograde_local.py --mode accuracy.