How to set the Operating Point

This tutorial explains how to use the object InputCurrent and VarLoadCurrent to run a magnetic simulation on several operating points by setting Id/Iq or I0/Phi0.

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 magnetic module is the same as the symmetrical one from the tutorial “How to define a simulation to call FEMM”.

[1]:
%matplotlib notebook

# Load the machine
from pyleecan.Functions.load import load
from pyleecan.definitions import DATA_DIR
from os.path import join

IPMSM_A = load(join(DATA_DIR, "Machine", "IPMSM_A.json"))
IPMSM_A.plot()
[2]:
from pyleecan.Classes.Simu1 import Simu1
from pyleecan.Classes.MagFEMM import MagFEMM
# Initialization of the Simulation
simu_op = Simu1(name="tuto_Id_Iq", machine=IPMSM_A)

# Definition of the magnetic simulation (FEMM with symmetry and sliding band)
simu_op.mag = MagFEMM(
    type_BH_stator=0,
    type_BH_rotor=0,
    is_periodicity_a=True,
    is_periodicity_t=True,
    nb_worker=4,
    Kgeo_fineness=1,
)
# Run only Magnetic module
simu_op.elec = None
simu_op.force = None
simu_op.struct = None

Defining an Operating point with Id/Iq

The InputCurrent object enable to create an “OutElec” object that corresponds to the output of the Electrical module and the input of the Magnetic module. In this example, InputCurrent is used to define the starting point with a sinusoidal current defined with Id_ref and Iq_ref:

The tutorial “How to define a simulation to call FEMM” uses the same InputCurrent object to enforce any current by directly setting Is

[3]:
from pyleecan.Classes.InputCurrent import InputCurrent
from numpy import sqrt, exp,pi

# Definition of a sinusoidal current
simu_op.input = InputCurrent()
# I0, Phi0 to set
I0_rms = 250/sqrt(2) # Maximum current [Arms]
Phi0 = 140*pi/180  # Maximum Torque Per Amp
# Compute corresponding Id/Iq
Id_ref = (I0_rms*exp(1j*Phi0)).real
Iq_ref = (I0_rms*exp(1j*Phi0)).imag
# Setting the values
simu_op.input.Id_ref = Id_ref # [Arms]
simu_op.input.Iq_ref = Iq_ref # [Arms]

(Id_ref,Iq_ref)
[3]:
(-135.4188051049254, 113.62986941801093)

The discretization of the current and for the magnetic computation can be set with time and angle (as in “How to define a simulation to call FEMM” tutorial) or by setting the following parameters:

[4]:
simu_op.input.Nt_tot = 128 # Number of time step
simu_op.input.Na_tot = 2048 # Spatial discretization
simu_op.input.N0 = 2000 # Rotor speed [rpm]

When Nt_tot is defined, the time vector is automatically set to:

linspace(0, 60 / N0 * Nrev, Nt_tot)

With Nrev the number of revolution of the rotor (1 by default)

When Na_tot is defined, the angle vector is automatically set to:

linspace(0, 2*pi, Na_tot)

The input is now fully defined, the simulation can now be run:

[5]:
out_op = simu_op.run()
# Plot the flux
out_op.plot_2D_Data("mag.B", "angle")
# Plot the torque
out_op.plot_2D_Data("mag.Tem", "time")
# Plot the current
out_op.plot_2D_Data("elec.Is", "time", "phase")
2020-11-16 23:31:57,838-INFO-Pyleecan.Simulation: Starting Magnetic module

The Operating Point can also be defined directly with I0 / Phi0 with:

[6]:
from numpy import pi

simu_op.input.set_Id_Iq(I0=I0_rms, Phi0=Phi0)
print("Id: "+str(simu_op.input.Id_ref))
print("Iq: "+str(simu_op.input.Iq_ref))
Id: -135.4188051049254
Iq: 113.62986941801093

Iterating on several Operating Point

Each pyleecan simulation is assumed to be quasi-static and run on a single operating point (fixed speed). To run a simulation on several operating points two steps are needed: First define a simulation that run correctly on a single operating point (like the one defined above), then define a VarLoadCurrent object.

The VarLoadCurrent object is defined with a matrix with each line corresponding to an operating point and the column are: - (N0, I0, Phi0) if type_OP_matrix==0 - (N0, Id, Iq) if type_OP_matrix==1

The following VarLoadCurrent object will run the previous simulation N_simu times by changing the value of Phi0.

A fourth column can be added by setting is_torque=True. It enables to define the reference torque for the Operating Point. The reference is stored in output.elec.Tem_av_ref, the real computed torque is stored in output.mag.Tem_av.

Reference torque and current angle vector are:

[7]:
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
[8]:
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
print(OP_matrix)

# All the simulation use the same machine
# No need to draw the machine for all OP
varload.is_reuse_femm_file=True
[[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]]

The original simulation will be duplicated N_simu times with the value of InputCurrent updated according to the matrix.

[9]:
simu_vop = simu_op.copy()
simu_vop.var_simu = varload
# simu2.input.Nt_tot = 64
Xout = simu_vop.run()
2020-11-16 23:33:05,620-INFO-Pyleecan.Simulation: Computing reference simulation
2020-11-16 23:33:05,622-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:33:16,805-INFO-Pyleecan.Simulation: Results: N0=2000, Id=88.388348, Iq=153.09311, I0=176.7767, Phi0=1.0471976, Tem_av_ref=79, Tem_av=81.568451, Tem_rip_pp=29.303401, Tem_rip_norm=0.35924921
[===                                               ]   7%
2020-11-16 23:33:16,807-INFO-Pyleecan.Simulation: VarSimu: Using same FEMM file for all simulation (C:\Anaconda3\Lib\site-packages\pyleecan\Results\tuto_Id_Iq\Femm\IPMSM_A_model.fem)
2020-11-16 23:33:16,808-INFO-Pyleecan.Simulation: VarSimu: Using same FEMM file for all simulation (C:\Anaconda3\Lib\site-packages\pyleecan\Results\tuto_Id_Iq\Femm\IPMSM_A_model.fem)
2020-11-16 23:33:16,808-INFO-Pyleecan.Simulation: VarSimu: Using same FEMM file for all simulation (C:\Anaconda3\Lib\site-packages\pyleecan\Results\tuto_Id_Iq\Femm\IPMSM_A_model.fem)
2020-11-16 23:33:16,809-INFO-Pyleecan.Simulation: VarSimu: Using same FEMM file for all simulation (C:\Anaconda3\Lib\site-packages\pyleecan\Results\tuto_Id_Iq\Femm\IPMSM_A_model.fem)
2020-11-16 23:33:16,810-INFO-Pyleecan.Simulation: VarSimu: Using same FEMM file for all simulation (C:\Anaconda3\Lib\site-packages\pyleecan\Results\tuto_Id_Iq\Femm\IPMSM_A_model.fem)
2020-11-16 23:33:16,810-INFO-Pyleecan.Simulation: VarSimu: Using same FEMM file for all simulation (C:\Anaconda3\Lib\site-packages\pyleecan\Results\tuto_Id_Iq\Femm\IPMSM_A_model.fem)
2020-11-16 23:33:16,811-INFO-Pyleecan.Simulation: VarSimu: Using same FEMM file for all simulation (C:\Anaconda3\Lib\site-packages\pyleecan\Results\tuto_Id_Iq\Femm\IPMSM_A_model.fem)
2020-11-16 23:33:16,812-INFO-Pyleecan.Simulation: VarSimu: Using same FEMM file for all simulation (C:\Anaconda3\Lib\site-packages\pyleecan\Results\tuto_Id_Iq\Femm\IPMSM_A_model.fem)
2020-11-16 23:33:16,813-INFO-Pyleecan.Simulation: VarSimu: Using same FEMM file for all simulation (C:\Anaconda3\Lib\site-packages\pyleecan\Results\tuto_Id_Iq\Femm\IPMSM_A_model.fem)
2020-11-16 23:33:16,813-INFO-Pyleecan.Simulation: VarSimu: Using same FEMM file for all simulation (C:\Anaconda3\Lib\site-packages\pyleecan\Results\tuto_Id_Iq\Femm\IPMSM_A_model.fem)
2020-11-16 23:33:16,815-INFO-Pyleecan.Simulation: VarSimu: Using same FEMM file for all simulation (C:\Anaconda3\Lib\site-packages\pyleecan\Results\tuto_Id_Iq\Femm\IPMSM_A_model.fem)
2020-11-16 23:33:16,815-INFO-Pyleecan.Simulation: VarSimu: Using same FEMM file for all simulation (C:\Anaconda3\Lib\site-packages\pyleecan\Results\tuto_Id_Iq\Femm\IPMSM_A_model.fem)
2020-11-16 23:33:16,816-INFO-Pyleecan.Simulation: Running simulation 2/13 with Id=60.461191, Iq=166.11576
2020-11-16 23:33:16,818-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:33:27,665-INFO-Pyleecan.Simulation: Results: N0=2000, Id=60.461191, Iq=166.11576, I0=176.7767, Phi0=1.2217305, Tem_av_ref=125, Tem_av=125.37986, Tem_rip_pp=43.79845, Tem_rip_norm=0.34932603
[=======                                           ]  15%
2020-11-16 23:33:27,666-INFO-Pyleecan.Simulation: Running simulation 3/13 with Id=30.696951, Iq=174.09106
2020-11-16 23:33:27,668-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:33:40,128-INFO-Pyleecan.Simulation: Results: N0=2000, Id=30.696951, Iq=174.09106, I0=176.7767, Phi0=1.3962634, Tem_av_ref=160, Tem_av=170.28325, Tem_rip_pp=53.201114, Tem_rip_norm=0.31242717
[===========                                       ]  23%
2020-11-16 23:33:40,131-INFO-Pyleecan.Simulation: Running simulation 4/13 with Id=0, Iq=176.7767
2020-11-16 23:33:40,133-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:33:53,723-INFO-Pyleecan.Simulation: Results: N0=2000, Id=0, Iq=176.7767, I0=176.7767, Phi0=1.5707963, Tem_av_ref=192, Tem_av=214.26534, Tem_rip_pp=51.042877, Tem_rip_norm=0.23822274
[===============                                   ]  30%
2020-11-16 23:33:53,725-INFO-Pyleecan.Simulation: Running simulation 5/13 with Id=-30.696951, Iq=174.09106
2020-11-16 23:33:53,728-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:34:06,213-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-30.696951, Iq=174.09106, I0=176.7767, Phi0=1.7453293, Tem_av_ref=237, Tem_av=255.53244, Tem_rip_pp=55.327972, Tem_rip_norm=0.21652034
[===================                               ]  38%
2020-11-16 23:34:06,214-INFO-Pyleecan.Simulation: Running simulation 6/13 with Id=-60.461191, Iq=166.11576
2020-11-16 23:34:06,216-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:34:18,921-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-60.461191, Iq=166.11576, I0=176.7767, Phi0=1.9198622, Tem_av_ref=281, Tem_av=292.43895, Tem_rip_pp=70.078304, Tem_rip_norm=0.23963396
[=======================                           ]  46%
2020-11-16 23:34:18,923-INFO-Pyleecan.Simulation: Running simulation 7/13 with Id=-88.388348, Iq=153.09311
2020-11-16 23:34:18,926-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:34:33,067-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-88.388348, Iq=153.09311, I0=176.7767, Phi0=2.0943951, Tem_av_ref=319, Tem_av=323.08086, Tem_rip_pp=79.834004, Tem_rip_norm=0.24710224
[==========================                        ]  53%
2020-11-16 23:34:33,069-INFO-Pyleecan.Simulation: Running simulation 8/13 with Id=-113.62987, Iq=135.41881
2020-11-16 23:34:33,070-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:34:49,067-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-113.62987, Iq=135.41881, I0=176.7767, Phi0=2.268928, Tem_av_ref=343, Tem_av=344.98634, Tem_rip_pp=83.682266, Tem_rip_norm=0.2425669
[==============================                    ]  61%
2020-11-16 23:34:49,069-INFO-Pyleecan.Simulation: Running simulation 9/13 with Id=-135.41881, Iq=113.62987
2020-11-16 23:34:49,070-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:35:04,923-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-135.41881, Iq=113.62987, I0=176.7767, Phi0=2.443461, Tem_av_ref=353, Tem_av=353.68661, Tem_rip_pp=82.812753, Tem_rip_norm=0.23414162
[==================================                ]  69%
2020-11-16 23:35:04,924-INFO-Pyleecan.Simulation: Running simulation 10/13 with Id=-153.09311, Iq=88.388348
2020-11-16 23:35:04,927-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:35:21,185-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-153.09311, Iq=88.388348, I0=176.7767, Phi0=2.6179939, Tem_av_ref=332, Tem_av=337.89315, Tem_rip_pp=66.027728, Tem_rip_norm=0.19541008
[======================================            ]  76%
2020-11-16 23:35:21,188-INFO-Pyleecan.Simulation: Running simulation 11/13 with Id=-166.11576, Iq=60.461191
2020-11-16 23:35:21,189-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:35:37,852-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-166.11576, Iq=60.461191, I0=176.7767, Phi0=2.7925268, Tem_av_ref=266, Tem_av=272.93652, Tem_rip_pp=38.569957, Tem_rip_norm=0.14131475
[==========================================        ]  84%
2020-11-16 23:35:37,854-INFO-Pyleecan.Simulation: Running simulation 12/13 with Id=-174.09106, Iq=30.696951
2020-11-16 23:35:37,856-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:35:55,215-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-174.09106, Iq=30.696951, I0=176.7767, Phi0=2.9670597, Tem_av_ref=164, Tem_av=154.64829, Tem_rip_pp=45.689859, Tem_rip_norm=0.29544367
[==============================================    ]  92%
2020-11-16 23:35:55,216-INFO-Pyleecan.Simulation: Running simulation 13/13 with Id=-176.7767, Iq=0
2020-11-16 23:35:55,218-INFO-Pyleecan.Simulation: Starting Magnetic module
2020-11-16 23:36:14,471-INFO-Pyleecan.Simulation: Results: N0=2000, Id=-176.7767, Iq=0, I0=176.7767, Phi0=3.1415927, Tem_av_ref=22, Tem_av=-1.096865, Tem_rip_pp=39.483295, Tem_rip_norm=-35.996495
[==================================================] 100%

Pyleecan will automatically extract some values from each simulation. These values are all gathered in the xoutput_dict:

[10]:
print("Values available in XOutput:")
print(Xout.xoutput_dict.keys())

print("\nI0 for each simulation:")
print(Xout["I0"].result)
print("\nPhi0 for each simulation:")
print(Xout["Phi0"].result)
Values available in XOutput:
dict_keys(['N0', 'Id', 'Iq', 'I0', 'Phi0', 'Tem_av_ref', 'Tem_av', 'Tem_rip_pp', 'Tem_rip_norm'])

I0 for each simulation:
[176.77669529663686, 176.77669529663686, 176.77669529663683, 176.77669529663686, 176.77669529663683, 176.77669529663686, 176.77669529663686, 176.77669529663686, 176.77669529663686, 176.77669529663686, 176.77669529663683, 176.77669529663683, 176.77669529663686]

Phi0 for each simulation:
[1.0471975511965976, 1.2217304763960306, 1.3962634015954636, 1.5707963267948966, 1.7453292519943295, 1.9198621771937625, 2.0943951023931957, 2.2689280275926285, 2.443460952792061, 2.6179938779914944, 2.7925268031909276, 2.9670597283903604, 3.141592653589793]

Any parameter in the XOutput can be plot as a function of any other

[11]:
fig = Xout.plot_multi("Phi0", "Tem_av")
fig = Xout.plot_multi("Id", "Iq")

Finally, the computed average torque can be compared to the one in the publication from Yang et al (data has been extracted from their graph using Engauge Digitizer. Note that the generic plot function plot_2D has been used here.

[12]:
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"]

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