Code for simulating dipoles