An advanced electromagnetic code for the analysis and design of electromechanical apparatuses