A computational code for analyzing permanent magnet motors