Finite element formulation for electromagnetic devices supplied by alternating voltages