How to compute currents, voltage and torque using the Electrical Module

This tutorial explains how to use the Electrical Module to compute currents, voltage and torque, using a simple electrical equivalent circuit. The idea is to provide insight on how to implement other methods.

The reference used to validate this tutorial is: Z. Yang, M. Krishnamurthy and I. P. Brown, “Electromagnetic and vibrational characteristic of IPM over full torque-speed range,” 2013 International Electric Machines & Drives Conference, Chicago, IL, 2013, pp. 295-302, doi: 10.1109/IEMDC.2013.6556267.

Machine and Simulation definition

This tutorial use the machine IPMSM_A (Prius 2004) defined in the “How to define a machine” tutorial. The configuration is similar to the one used in the “How to set the Operating Point” tutorial.

%matplotlib notebook

import pyleecan
print("Pyleecan version:" + pyleecan.__version__)
# Load the machine
from os.path import join
from pyleecan.Functions.load import load
from pyleecan.definitions import DATA_DIR

IPMSM_A = load(join(DATA_DIR, "Machine", "IPMSM_A.json"))
Pyleecan version:1.0.4

Electrical Equivalent Circuit (EEC)

The electrical module is defined with the object EEC_PMSM that correspond to the electrical equivalent circuit from “Advanced Electrical Drives, analysis, modeling, control”, Rik de doncker, Duco W.J. Pulle, Andre Veltman, Springer edition, is then used for the computation of Ud/Uq or Id/Iq (see schematics hereafter).

The parameters from the EEC are first computed according to the FluxLinkFEMM and IndMagFEMM objects. They enable to compute the flux linkage and the magnetic inductances using FEMM simulations (with symmetries and number of time steps). For the flux linkage computation, the currents are set to 0A.

Once the parameter of the EEC known, the voltage can be computed. The electrical torque is then computed according to the formula: \(T_{em}=\frac{P-RI^2}{\Omega}\), where \(P\) is the magnetic power \(P=\frac{q_s}{2}\Re(VI^*)\)

             <---                               --->
 -----R-----wsLqIq----              -----R-----wsLdId----
|                     |            |                     |
|                     |            |                    BEMF
|                     |            |                     |
 ---------Id----------              ---------Iq----------

         --->                               --->
          Ud                                 Uq
from pyleecan.Classes.Simu1 import Simu1
from pyleecan.Classes.Electrical import Electrical
from pyleecan.Classes.EEC_PMSM import EEC_PMSM
from pyleecan.Classes.FluxLinkFEMM import FluxLinkFEMM
from pyleecan.Classes.IndMagFEMM import IndMagFEMM

# Initialization of the Simulation
simu = Simu1(name="tuto_elec", machine=IPMSM_A)

# Definition of the magnetic simulation (FEMM with symmetry and sliding band)
simu.elec = Electrical(
        indmag=IndMagFEMM(is_periodicity_a=True, Nt_tot=10),
        fluxlink=FluxLinkFEMM(is_periodicity_a=True, Nt_tot=10),
# Run only Electrical module
simu.mag = None
simu.force = None
simu.struct = None

Defining starting point with InputElec or InputCurrent

The starting point of the simulation is defined with InputElec or InputCurrent. These objects will create an “OutElec” object and initialize it with the provided values for Id/Iq, and/or Ud/Uq with InputElec. InputCurrent enables to define in several ways the starting point (see “How to set the Operating Point”).

Note that Id/Iq are required to accurately compute the magnetic inductances, so that if only Ud/Uq is provided, a current Id=1A and Iq=1A will be used for the computation of Ld and Lq. A more satisfactory method would be to compute a map of Ld and Lq over Id/Iq. Future developments would be welcomed.

from pyleecan.Classes.InputCurrent import InputCurrent
from numpy import sqrt, exp, pi

# Definition of a sinusoidal current
simu.input = InputCurrent()

I0_rms = 250/sqrt(2) # Maximum current [Arms]
Phi0 = 140*pi/180  # Maximum Torque Per Amp

Id_ref = (I0_rms*exp(1j*Phi0)).real
Iq_ref = (I0_rms*exp(1j*Phi0)).imag

simu.input.Id_ref = Id_ref # [Arms]
simu.input.Iq_ref = Iq_ref # [Arms]

simu.input.Nt_tot = 10 # Number of time steps
simu.input.Na_tot = 2048 # Spatial discretization
simu.input.N0 = 2000 # Rotor speed [rpm]

(-135.4188051049254, 113.62986941801093)

Running the simulation and postprocessings

out =
2020-11-16 23:42:23,730-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:42:23,730-INFO-Pyleecan.Simulation: INFO: Compute flux linkage with FEMM
2020-11-16 23:42:39,241-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
# Print voltage and torque
print("Ud: "+str(out.elec.Ud_ref))
print("Uq: "+str(out.elec.Uq_ref))
print("Tem: "+str(out.elec.Tem_av_ref))
Ud: -201.24084060688068
Uq: -12.658880261245603
Tem: 353.6569264233516
# Plot the currents
out.plot_2D_Data("elec.Is", "time", "phase")
# Plot the voltages
out.plot_2D_Data("elec.Us", "time", "phase")

Iterating on several Operating Points

Reference torque and current angle vector are:

from numpy import linspace, array, pi
Tem_av_ref = array([79, 125, 160, 192, 237, 281, 319, 343, 353, 332, 266, 164, 22]) # Yang et al, 2013
Phi0_ref = linspace(60 * pi / 180, 180 * pi / 180, Tem_av_ref.size)
N_simu = Tem_av_ref.size

The multisimulation is similar to the one described in “How to set the Operating Point”, except that we are now computing the electrical torque instead of the magnetic torque.

from pyleecan.Classes.VarLoadCurrent import VarLoadCurrent
from numpy import zeros, ones, linspace, array, sqrt, arange

varload = VarLoadCurrent(is_torque=True, ref_simu_index=0)
varload.type_OP_matrix = 0 # Matrix N0, I0, Phi0

# Creating the Operating point matrix
OP_matrix = zeros((N_simu,4))

# Set N0 = 2000 [rpm] for all simulation
OP_matrix[:,0] = 2000 * ones((N_simu))

# Set I0 = 250 / sqrt(2) [A] (RMS) for all simulation
OP_matrix[:,1] = I0_rms * ones((N_simu))

# Set Phi0 from 60° to 180°
OP_matrix[:,2] = Phi0_ref

# Set reference torque from Yang et al, 2013
OP_matrix[:,3] = Tem_av_ref

varload.OP_matrix = OP_matrix
[[2.00000000e+03 1.76776695e+02 1.04719755e+00 7.90000000e+01]
 [2.00000000e+03 1.76776695e+02 1.22173048e+00 1.25000000e+02]
 [2.00000000e+03 1.76776695e+02 1.39626340e+00 1.60000000e+02]
 [2.00000000e+03 1.76776695e+02 1.57079633e+00 1.92000000e+02]
 [2.00000000e+03 1.76776695e+02 1.74532925e+00 2.37000000e+02]
 [2.00000000e+03 1.76776695e+02 1.91986218e+00 2.81000000e+02]
 [2.00000000e+03 1.76776695e+02 2.09439510e+00 3.19000000e+02]
 [2.00000000e+03 1.76776695e+02 2.26892803e+00 3.43000000e+02]
 [2.00000000e+03 1.76776695e+02 2.44346095e+00 3.53000000e+02]
 [2.00000000e+03 1.76776695e+02 2.61799388e+00 3.32000000e+02]
 [2.00000000e+03 1.76776695e+02 2.79252680e+00 2.66000000e+02]
 [2.00000000e+03 1.76776695e+02 2.96705973e+00 1.64000000e+02]
 [2.00000000e+03 1.76776695e+02 3.14159265e+00 2.20000000e+01]]
# Run multisimulation
simu2 = simu.copy()
simu2.var_simu = varload
Xout =
2020-11-16 23:43:38,322-INFO-Pyleecan.Simulation: Computing reference simulation
2020-11-16 23:43:38,324-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:43:38,325-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
2020-11-16 23:43:51,599-INFO-Pyleecan.Simulation: Results: N0=2000, Id=88.388348, Iq=153.09311, I0=176.7767, Phi0=1.0471976, Tem_av_ref=81.80573
[===                                               ]   7%
2020-11-16 23:43:51,601-INFO-Pyleecan.Simulation: Running simulation 2/13 with Id=60.461191, Iq=166.11576
2020-11-16 23:43:51,604-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:43:51,605-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
2020-11-16 23:44:04,368-INFO-Pyleecan.Simulation: Results: N0=2000, Id=60.461191, Iq=166.11576, I0=176.7767, Phi0=1.2217305, Tem_av_ref=125.49029
[=======                                           ]  15%
2020-11-16 23:44:04,369-INFO-Pyleecan.Simulation: Running simulation 3/13 with Id=30.696951, Iq=174.09106
2020-11-16 23:44:04,371-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:44:04,372-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
2020-11-16 23:44:16,896-INFO-Pyleecan.Simulation: Results: N0=2000, Id=30.696951, Iq=174.09106, I0=176.7767, Phi0=1.3962634, Tem_av_ref=170.3291
[===========                                       ]  23%
2020-11-16 23:44:16,897-INFO-Pyleecan.Simulation: Running simulation 4/13 with Id=0, Iq=176.7767
2020-11-16 23:44:16,899-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:44:16,899-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
2020-11-16 23:44:29,849-INFO-Pyleecan.Simulation: Results: N0=2000, Id=0, Iq=176.7767, I0=176.7767, Phi0=1.5707963, Tem_av_ref=214.25277
[===============                                   ]  30%
2020-11-16 23:44:29,851-INFO-Pyleecan.Simulation: Running simulation 5/13 with Id=-30.696951, Iq=174.09106
2020-11-16 23:44:29,852-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:44:29,853-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
2020-11-16 23:44:42,443-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-30.696951, Iq=174.09106, I0=176.7767, Phi0=1.7453293, Tem_av_ref=255.53258
[===================                               ]  38%
2020-11-16 23:44:42,446-INFO-Pyleecan.Simulation: Running simulation 6/13 with Id=-60.461191, Iq=166.11576
2020-11-16 23:44:42,448-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:44:42,449-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
2020-11-16 23:44:55,994-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-60.461191, Iq=166.11576, I0=176.7767, Phi0=1.9198622, Tem_av_ref=292.4085
[=======================                           ]  46%
2020-11-16 23:44:55,995-INFO-Pyleecan.Simulation: Running simulation 7/13 with Id=-88.388348, Iq=153.09311
2020-11-16 23:44:55,996-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:44:55,997-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
2020-11-16 23:45:10,537-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-88.388348, Iq=153.09311, I0=176.7767, Phi0=2.0943951, Tem_av_ref=323.01584
[==========================                        ]  53%
2020-11-16 23:45:10,541-INFO-Pyleecan.Simulation: Running simulation 8/13 with Id=-113.62987, Iq=135.41881
2020-11-16 23:45:10,544-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:45:10,546-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
2020-11-16 23:45:26,413-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-113.62987, Iq=135.41881, I0=176.7767, Phi0=2.268928, Tem_av_ref=344.91518
[==============================                    ]  61%
2020-11-16 23:45:26,415-INFO-Pyleecan.Simulation: Running simulation 9/13 with Id=-135.41881, Iq=113.62987
2020-11-16 23:45:26,417-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:45:26,437-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-135.41881, Iq=113.62987, I0=176.7767, Phi0=2.443461, Tem_av_ref=353.65693
[==================================                ]  69%
2020-11-16 23:45:26,438-INFO-Pyleecan.Simulation: Running simulation 10/13 with Id=-153.09311, Iq=88.388348
2020-11-16 23:45:26,440-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:45:26,442-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
2020-11-16 23:45:41,649-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-153.09311, Iq=88.388348, I0=176.7767, Phi0=2.6179939, Tem_av_ref=337.88379
[======================================            ]  76%
2020-11-16 23:45:41,651-INFO-Pyleecan.Simulation: Running simulation 11/13 with Id=-166.11576, Iq=60.461191
2020-11-16 23:45:41,652-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:45:41,653-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
2020-11-16 23:45:58,206-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-166.11576, Iq=60.461191, I0=176.7767, Phi0=2.7925268, Tem_av_ref=273.07172
[==========================================        ]  84%
2020-11-16 23:45:58,208-INFO-Pyleecan.Simulation: Running simulation 12/13 with Id=-174.09106, Iq=30.696951
2020-11-16 23:45:58,210-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:45:58,211-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
2020-11-16 23:46:13,655-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-174.09106, Iq=30.696951, I0=176.7767, Phi0=2.9670597, Tem_av_ref=154.62026
[==============================================    ]  92%
2020-11-16 23:46:13,657-INFO-Pyleecan.Simulation: Running simulation 13/13 with Id=-176.7767, Iq=0
2020-11-16 23:46:13,659-INFO-Pyleecan.Simulation: Starting Electric module
2020-11-16 23:46:13,660-INFO-Pyleecan.Simulation: INFO: Compute dq inductances with FEMM
2020-11-16 23:46:29,633-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-176.7767, Iq=0, I0=176.7767, Phi0=3.1415927, Tem_av_ref=-1.6787987
[==================================================] 100%

Once the simulation is done, the torque as a function of Phi0 can be plotted with:

# Plot torque as a function of Phi0
from pyleecan.Functions.Plot.plot_2D import plot_2D
from pyleecan.definitions import config_dict
from numpy import array

curve_colors = config_dict["PLOT"]["COLOR_DICT"]["CURVE_COLORS"]

    array([x*180/pi for x in Xout.xoutput_dict["Phi0"].result]),
    [Xout.xoutput_dict["Tem_av_ref"].result, Tem_av_ref],
    legend_list=["Pyleecan", "Yang et al, 2013"],
    xlabel="Current angle [°]",
    ylabel="Electrical torque [N.m]",
    title="Electrical torque vs current angle"
[ ]: