Design of Magnets and Electromagnets