Fixed-Magnetization Spin Models and Their Application to Programmable Matter