optimizing permanent magnet generators