General Formulation of the Magnetostatic Field and Temperature Distribution in Electrical Machines Using Spectral Element Analysis