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 plot results

Pyleecan has generic built-in plot methods which allow to easily plot:

  • simulated or experimental fields (unit conversions supported)

  • slices (normalizations available)

  • Fourier Transforms

but also to compare on the same graph a list of fields.

This flexibility is provided by the SciDataTool module, which has been created to ease the handling of scientific data, and considerately simplify plot commands. It unifies the extraction of relevant data (e.g. slices), whether they are stored in the time/space or in the frequency domain. The call to Fourier Transform functions is transparent, although it still can be parameterized.

This tutorial explains how to use Pyleecan’s plot commands. It is available on GitHub. For more details on the SciDataTool package, please refer to the specific tutorials:

To demonstrate the capabilities and the use of the SciDataTool objects, two simulations are launched with FEMM: with imposed currents and in open-circuit. The simulations use periodicity and parallelization to reduce execution time.

[2]:
# Import Pyleecan modules
from numpy import exp, sqrt, pi
from os.path import join
from pyleecan.Classes.Simu1 import Simu1
from pyleecan.Classes.InputCurrent import InputCurrent
from pyleecan.Classes.MagFEMM import MagFEMM
from pyleecan.Classes.ForceMT import ForceMT
from pyleecan.Classes.Output import Output
from pyleecan.Functions.load import load
from pyleecan.definitions import DATA_DIR

# Load the machine
Toyota_Prius = load(join(DATA_DIR, "Machine", "Toyota_Prius.json"))

# Simulation initialization
simu = Simu1(name="FEMM_periodicity", machine=Toyota_Prius)

# Definition of the enforced output of the electrical module
simu.input = InputCurrent(
    Na_tot=252 * 8,
    Nt_tot=50 * 8,
    N0=1000,
)
# Set Id/Iq according to I0/Phi0
simu.input.set_Id_Iq(I0=250 / sqrt(2), Phi0=140*pi/180)

# Definition of the magnetic simulation: with periodicity
simu.mag = MagFEMM(is_periodicity_a=True, is_periodicity_t=True, nb_worker=4)
simu.force = ForceMT(is_periodicity_a=True, is_periodicity_t=True)

# Definition of the open-circuit simulation
simu2 = simu.copy()
simu2.input.Id_ref = 0
simu2.input.Iq_ref = 0

# Run simulations
out = simu.run()
out2 = simu2.run()
[17:45:33] Starting running simulation FEMM_periodicity (machine=Toyota_Prius)
[17:45:33] Starting Magnetic module
[17:45:34] Solving time step 27 / 50 in FEMM
[17:45:34] Solving time step 14 / 50 in FEMM
[17:45:35] Solving time step 39 / 50 in FEMM
[17:45:35] Solving time step 1 / 50 in FEMM
[17:45:38] Solving time step 28 / 50 in FEMM
[17:45:38] Solving time step 40 / 50 in FEMM
[17:45:38] Solving time step 15 / 50 in FEMM
[17:45:38] Solving time step 2 / 50 in FEMM
[17:45:41] Solving time step 29 / 50 in FEMM
[17:45:42] Solving time step 41 / 50 in FEMM
[17:45:42] Solving time step 3 / 50 in FEMM
[17:45:42] Solving time step 16 / 50 in FEMM
[17:45:47] Solving time step 30 / 50 in FEMM
[17:45:47] Solving time step 42 / 50 in FEMM
[17:45:47] Solving time step 4 / 50 in FEMM
[17:45:47] Solving time step 17 / 50 in FEMM
[17:45:52] Solving time step 43 / 50 in FEMM
[17:45:52] Solving time step 5 / 50 in FEMM
[17:45:52] Solving time step 31 / 50 in FEMM
[17:45:53] Solving time step 18 / 50 in FEMM
[17:45:55] Solving time step 6 / 50 in FEMM
[17:45:55] Solving time step 44 / 50 in FEMM
[17:45:56] Solving time step 32 / 50 in FEMM
[17:45:56] Solving time step 19 / 50 in FEMM
[17:45:59] Solving time step 45 / 50 in FEMM
[17:45:59] Solving time step 7 / 50 in FEMM
[17:46:00] Solving time step 33 / 50 in FEMM
[17:46:00] Solving time step 20 / 50 in FEMM
[17:46:03] Solving time step 8 / 50 in FEMM
[17:46:03] Solving time step 46 / 50 in FEMM
[17:46:03] Solving time step 21 / 50 in FEMM
[17:46:04] Solving time step 34 / 50 in FEMM
[17:46:07] Solving time step 47 / 50 in FEMM
[17:46:07] Solving time step 22 / 50 in FEMM
[17:46:07] Solving time step 9 / 50 in FEMM
[17:46:07] Solving time step 35 / 50 in FEMM
[17:46:10] Solving time step 23 / 50 in FEMM
[17:46:11] Solving time step 48 / 50 in FEMM
[17:46:11] Solving time step 10 / 50 in FEMM
[17:46:11] Solving time step 36 / 50 in FEMM
[17:46:14] Solving time step 24 / 50 in FEMM
[17:46:14] Solving time step 37 / 50 in FEMM
[17:46:15] Solving time step 11 / 50 in FEMM
[17:46:15] Solving time step 49 / 50 in FEMM
[17:46:17] Solving time step 25 / 50 in FEMM
[17:46:18] Solving time step 38 / 50 in FEMM
[17:46:18] Solving time step 12 / 50 in FEMM
[17:46:18] Solving time step 50 / 50 in FEMM
[17:46:21] Solving time step 26 / 50 in FEMM
[17:46:21] Solving time step 13 / 50 in FEMM
[17:46:24] Starting Force module
[17:46:24] End of simulation FEMM_periodicity
[17:46:24] Starting running simulation FEMM_periodicity (machine=Toyota_Prius)
[17:46:24] Starting Magnetic module
[17:46:25] Solving time step 14 / 50 in FEMM
[17:46:25] Solving time step 27 / 50 in FEMM
[17:46:26] Solving time step 39 / 50 in FEMM
[17:46:26] Solving time step 1 / 50 in FEMM
[17:46:29] Solving time step 15 / 50 in FEMM
[17:46:29] Solving time step 2 / 50 in FEMM
[17:46:30] Solving time step 28 / 50 in FEMM
[17:46:30] Solving time step 40 / 50 in FEMM
[17:46:33] Solving time step 3 / 50 in FEMM
[17:46:34] Solving time step 29 / 50 in FEMM
[17:46:34] Solving time step 41 / 50 in FEMM
[17:46:34] Solving time step 16 / 50 in FEMM
[17:46:37] Solving time step 4 / 50 in FEMM
[17:46:38] Solving time step 42 / 50 in FEMM
[17:46:38] Solving time step 17 / 50 in FEMM
[17:46:38] Solving time step 30 / 50 in FEMM
[17:46:41] Solving time step 5 / 50 in FEMM
[17:46:41] Solving time step 43 / 50 in FEMM
[17:46:41] Solving time step 31 / 50 in FEMM
[17:46:41] Solving time step 18 / 50 in FEMM
[17:46:44] Solving time step 44 / 50 in FEMM
[17:46:44] Solving time step 6 / 50 in FEMM
[17:46:44] Solving time step 32 / 50 in FEMM
[17:46:45] Solving time step 19 / 50 in FEMM
[17:46:47] Solving time step 7 / 50 in FEMM
[17:46:49] Solving time step 45 / 50 in FEMM
[17:46:49] Solving time step 20 / 50 in FEMM
[17:46:49] Solving time step 33 / 50 in FEMM
[17:46:52] Solving time step 8 / 50 in FEMM
[17:46:53] Solving time step 46 / 50 in FEMM
[17:46:53] Solving time step 21 / 50 in FEMM
[17:46:54] Solving time step 34 / 50 in FEMM
[17:46:56] Solving time step 9 / 50 in FEMM
[17:46:57] Solving time step 47 / 50 in FEMM
[17:46:57] Solving time step 22 / 50 in FEMM
[17:46:58] Solving time step 35 / 50 in FEMM
[17:47:00] Solving time step 10 / 50 in FEMM
[17:47:00] Solving time step 48 / 50 in FEMM
[17:47:01] Solving time step 23 / 50 in FEMM
[17:47:03] Solving time step 36 / 50 in FEMM
[17:47:03] Solving time step 11 / 50 in FEMM
[17:47:04] Solving time step 49 / 50 in FEMM
[17:47:05] Solving time step 24 / 50 in FEMM
[17:47:06] Solving time step 37 / 50 in FEMM
[17:47:07] Solving time step 12 / 50 in FEMM
[17:47:08] Solving time step 50 / 50 in FEMM
[17:47:08] Solving time step 25 / 50 in FEMM
[17:47:10] Solving time step 38 / 50 in FEMM
[17:47:11] Solving time step 13 / 50 in FEMM
[17:47:12] Solving time step 26 / 50 in FEMM
[17:47:15] Starting Force module
[17:47:15] End of simulation FEMM_periodicity

The following example demonstrates the syntax to quickly plot the torque and airgap flux obtained at the end of the simulation:

[3]:
%matplotlib notebook
#------------------------------------------------------
# Plot the torque as a function of time
out.mag.Tem.plot_2D_Data("time")
out.mag.B.plot_2D_Data("angle")
#------------------------------------------------------

The plot command requires the axis of the field along which to plot (“angle” for instance). Titles and legends are automatically generated. The commands work with any field computed in Pyleecan (and stored in a SciDataTool object).

The syntax for the axes is specific to SciDataTool objects, and will be detailed in this tutorial.

There are two main plot commands in SciDataTool, which can apply to any DataTime, DataFreq or VectorField object from SciDataTool:

  • plot_2D_Data: field as a function of one dimension (time, angle, freqs, wavenumber, phase

  • plot_3D_Data: field as a function of two dimensions

SciDataTool also provides generic plot functions, which can be useful to easily format other plots, or plots of data which is not stored in a SciDataTool object:

  • plot_2D: plot as a function of one dimension (curve, bargraph, barchart, quiver, curve_point, point, barStackResultant)

  • plot_3D: plot as a function of two dimensions (stem, surf, pcolor, scatter)

  • plot_4D: plot as a function of three dimensions (scatter)

To use one of these plot functions, simply import it such as:

[4]:
from SciDataTool.Functions.Plot.plot_2D import plot_2D

We invite you to visit SciDataTool repository on GitHub for more details.

Fonts and colors can be automatically defined from the config_dict, using dict_2D or dict_3D:

[5]:
from pyleecan.Functions.Plot import dict_2D, dict_3D

1. How to plot only one period/antiperiod

To plot only one period or anti-period:

[6]:
#---------------------------------------------------------------
# Plot the torque along the smallest period of time
out.mag.Tem.plot_2D_Data("time[smallestperiod]", **dict_2D)
#---------------------------------------------------------------

2. How to plot VectorField objects

For VectorField objects, such as mag.B or force.AGSF, a plot for each component will be created:

[7]:
#---------------------------------------------------------------
# Plot all components of flux density
out.mag.B.plot_2D_Data("time", **dict_2D)
#---------------------------------------------------------------

To plot only one or several specific components, one can use the component_list parameter:

[8]:
#---------------------------------------------------------------
# Plot only radial flux density
out.mag.B.plot_2D_Data("time", component_list=["radial"], **dict_2D)
#---------------------------------------------------------------

3. How to plot slices

In the previous plots, the flux density was sliced at angle=0 (slice by default), but we could want to slice at another angle:

[9]:
#---------------------------------------------------------------
# Plot for angle = 90°
out.mag.B.plot_2D_Data("time", "angle=90{°}", component_list=["radial"], **dict_2D)
#---------------------------------------------------------------