# Version information¶

[1]:

from datetime import date
print("Running date:", date.today().strftime("%B %d, %Y"))
import pyleecan
print("Pyleecan version:" + pyleecan.__version__)
import SciDataTool
print("SciDataTool version:" + SciDataTool.__version__)

Running date: April 29, 2021
Pyleecan version:1.2.1
SciDataTool version:1.3.1


# 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.

[2]:

%matplotlib notebook

from os.path import join
from pyleecan.definitions import DATA_DIR

Toyota_Prius.plot()

c:\python38\lib\site-packages\pyleecan\Methods\Machine\Machine\plot.py:123: MatplotlibDeprecationWarning:
The set_window_title function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use manager.set_window_title or GUI-specific methods instead.
fig.canvas.set_window_title(self.name + " plot machine")


## 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

[3]:

from pyleecan.Classes.Simu1 import Simu1
from pyleecan.Classes.Electrical import Electrical
from pyleecan.Classes.EEC_PMSM import EEC_PMSM
from pyleecan.Classes.IndMagFEMM import IndMagFEMM

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

# Definition of the magnetic simulation (FEMM with symmetry and sliding band)
simu.elec = Electrical(
eec=EEC_PMSM(
indmag=IndMagFEMM(is_periodicity_a=True, Nt_tot=50),
)
)
# 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.

[4]:

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 = 50 # Number of time steps
simu.input.Na_tot = 2048 # Spatial discretization
simu.input.N0 = 2000 # Rotor speed [rpm]

(Id_ref,Iq_ref)

[4]:

(-135.4188051049254, 113.62986941801093)


## Running the simulation and postprocessings¶

[5]:

out = simu.run()

[22:26:42] Starting running simulation tuto_elec (machine=Toyota_Prius)
[22:26:42] Starting Electric module
[22:26:42] INFO: Compute flux linkage with FEMM
[22:28:07] INFO: Compute dq inductances with FEMM
[22:29:21] End of simulation tuto_elec

[6]:

# 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.2378050091584
Uq: -12.666035512466053
Tem: 353.6393920916952

[7]:

from pyleecan.Functions.Plot import dict_2D
# Plot the currents
out.elec.get_Is().plot_2D_Data("time", "phase", **dict_2D)

[8]:

# Plot the voltages
out.elec.Us.plot_2D_Data("time", "phase", **dict_2D)


## Iterating on several Operating Points¶

Reference torque and current angle vector are:

[9]:

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.

[10]:

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

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

print(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]]

[11]:

# Run multisimulation
simu2 = simu.copy()
Xout = simu2.run()

[22:29:22] Starting running simulation tuto_elec (machine=Toyota_Prius)
[22:29:22] Reference Operating point is not in OP_matrix, one extra simulation will be computed
[22:29:22] Computing reference simulation for Variable Load
[22:29:22] Starting Electric module
[22:29:22] Variable Load Reference Results: N0=2000 [rpm], Id=-135.4 [Arms], Iq=113.6 [Arms], I0=176.8 [A], Phi0=2.443 [], Tem_av_ref=353.6 [N.m]
[===                                               ]   7%
[22:29:22] Running simulation 1/13 with N0=2000 [rpm], Id=88.39 [Arms], Iq=153.1 [Arms]
[22:29:22] Starting Electric module
[22:29:22] INFO: Compute dq inductances with FEMM
[22:30:28] Variable Load Results: N0=2000 [rpm], Id=88.39 [Arms], Iq=153.1 [Arms], I0=176.8 [A], Phi0=1.047 [], Tem_av_ref=81.83 [N.m]
[=======                                           ]  14%
[22:30:28] Running simulation 2/13 with N0=2000 [rpm], Id=60.46 [Arms], Iq=166.1 [Arms]
[22:30:28] Starting Electric module
[22:30:28] INFO: Compute dq inductances with FEMM
[22:31:32] Variable Load Results: N0=2000 [rpm], Id=60.46 [Arms], Iq=166.1 [Arms], I0=176.8 [A], Phi0=1.222 [], Tem_av_ref=125.5 [N.m]
[==========                                        ]  21%
[22:31:32] Running simulation 3/13 with N0=2000 [rpm], Id=30.7 [Arms], Iq=174.1 [Arms]
[22:31:32] Starting Electric module
[22:31:32] INFO: Compute dq inductances with FEMM
[22:32:38] Variable Load Results: N0=2000 [rpm], Id=30.7 [Arms], Iq=174.1 [Arms], I0=176.8 [A], Phi0=1.396 [], Tem_av_ref=170.3 [N.m]
[==============                                    ]  28%
[22:32:38] Running simulation 4/13 with N0=2000 [rpm], Id=0 [Arms], Iq=176.8 [Arms]
[22:32:38] Starting Electric module
[22:32:38] INFO: Compute dq inductances with FEMM
[22:33:43] Variable Load Results: N0=2000 [rpm], Id=0 [Arms], Iq=176.8 [Arms], I0=176.8 [A], Phi0=1.571 [], Tem_av_ref=214.3 [N.m]
[=================                                 ]  35%
[22:33:43] Running simulation 5/13 with N0=2000 [rpm], Id=-30.7 [Arms], Iq=174.1 [Arms]
[22:33:43] Starting Electric module
[22:33:43] INFO: Compute dq inductances with FEMM
[22:34:48] Variable Load Results: N0=2000 [rpm], Id=-30.7 [Arms], Iq=174.1 [Arms], I0=176.8 [A], Phi0=1.745 [], Tem_av_ref=255.5 [N.m]
[=====================                             ]  42%
[22:34:48] Running simulation 6/13 with N0=2000 [rpm], Id=-60.46 [Arms], Iq=166.1 [Arms]
[22:34:48] Starting Electric module
[22:34:48] INFO: Compute dq inductances with FEMM
[22:35:53] Variable Load Results: N0=2000 [rpm], Id=-60.46 [Arms], Iq=166.1 [Arms], I0=176.8 [A], Phi0=1.92 [], Tem_av_ref=292.4 [N.m]
[=========================                         ]  50%
[22:35:53] Running simulation 7/13 with N0=2000 [rpm], Id=-88.39 [Arms], Iq=153.1 [Arms]
[22:35:53] Starting Electric module
[22:35:53] INFO: Compute dq inductances with FEMM
[22:37:00] Variable Load Results: N0=2000 [rpm], Id=-88.39 [Arms], Iq=153.1 [Arms], I0=176.8 [A], Phi0=2.094 [], Tem_av_ref=323 [N.m]
[============================                      ]  57%
[22:37:00] Running simulation 8/13 with N0=2000 [rpm], Id=-113.6 [Arms], Iq=135.4 [Arms]
[22:37:00] Starting Electric module
[22:37:00] INFO: Compute dq inductances with FEMM
[22:38:09] Variable Load Results: N0=2000 [rpm], Id=-113.6 [Arms], Iq=135.4 [Arms], I0=176.8 [A], Phi0=2.269 [], Tem_av_ref=344.9 [N.m]
[================================                  ]  64%
[22:38:09] Running simulation 9/13 with N0=2000 [rpm], Id=-135.4 [Arms], Iq=113.6 [Arms]
[22:38:09] Starting Electric module
[22:38:09] Variable Load Results: N0=2000 [rpm], Id=-135.4 [Arms], Iq=113.6 [Arms], I0=176.8 [A], Phi0=2.443 [], Tem_av_ref=353.6 [N.m]
[===================================               ]  71%
[22:38:09] Running simulation 10/13 with N0=2000 [rpm], Id=-153.1 [Arms], Iq=88.39 [Arms]
[22:38:09] Starting Electric module
[22:38:09] INFO: Compute dq inductances with FEMM
[22:39:23] Variable Load Results: N0=2000 [rpm], Id=-153.1 [Arms], Iq=88.39 [Arms], I0=176.8 [A], Phi0=2.618 [], Tem_av_ref=337.9 [N.m]
[=======================================           ]  78%
[22:39:23] Running simulation 11/13 with N0=2000 [rpm], Id=-166.1 [Arms], Iq=60.46 [Arms]
[22:39:23] Starting Electric module
[22:39:23] INFO: Compute dq inductances with FEMM
[22:40:38] Variable Load Results: N0=2000 [rpm], Id=-166.1 [Arms], Iq=60.46 [Arms], I0=176.8 [A], Phi0=2.793 [], Tem_av_ref=273.1 [N.m]
[==========================================        ]  85%
[22:40:38] Running simulation 12/13 with N0=2000 [rpm], Id=-174.1 [Arms], Iq=30.7 [Arms]
[22:40:38] Starting Electric module
[22:40:38] INFO: Compute dq inductances with FEMM
[22:41:55] Variable Load Results: N0=2000 [rpm], Id=-174.1 [Arms], Iq=30.7 [Arms], I0=176.8 [A], Phi0=2.967 [], Tem_av_ref=154.7 [N.m]
[==============================================    ]  92%
[22:41:55] Running simulation 13/13 with N0=2000 [rpm], Id=-176.8 [Arms], Iq=0 [Arms]
[22:41:55] Starting Electric module
[22:41:55] INFO: Compute dq inductances with FEMM
[22:43:20] Variable Load Results: N0=2000 [rpm], Id=-176.8 [Arms], Iq=0 [Arms], I0=176.8 [A], Phi0=3.142 [], Tem_av_ref=-1.72 [N.m]
[==================================================] 100%
[22:43:20] End of simulation tuto_elec


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

[12]:

# Plot torque as a function of Phi0
from SciDataTool.Functions.Plot.plot_2D import plot_2D
from numpy import array

plot_2D(
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",
**dict_2D
)

[ ]: