Modelling and optimization of a permanent magnet machine in a flywheel door