Version information

[1]:
%matplotlib notebook
from PySide2.QtWidgets import *
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 27, 2023
Pyleecan version:1.5.0
SciDataTool version:2.5.0

How to compute magnetic forces using Force Module

This tutorial shows the different steps to compute magnetic forces with pyleecan.

The notebook related to this tutorial is available on GitHub.

To compute Forces, pyleecan first needs an OutMag containing airgap flux density. So first a simulation is created to compute the flux in FEMM, with imposed currents, using periodicity and parallelization to reduce execution time. The corresponding objects are introduced in the How to define a simulation to call FEMM tutorial

[3]:
%matplotlib notebook
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.Classes.OPdq import OPdq
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"))
fig, ax = Toyota_Prius.plot()
[4]:
# 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,
    OP=OPdq(N0=1000),
)
# Set Id/Iq according to I0/Phi0
simu.input.OP.set_I0_Phi0(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)

Force Module

All models related to forces inherit the abstract class Force. The ForceMT class inherits from Force class and is dedicated to the computation of air-gap surface force based on the Maxwell stress tensor [source].

Simu1 is an object meant to define simulation that runs sequentially several models by assuming a weak coupling. By setting both simu.mag and simu.force, the simulation will first call the MagFEMM model to compute the flux, the results will be stored in an OutMag that will then be used as an input for the computation of ForceMT which are then stored in an OutForce object.

[5]:
from pyleecan.Classes.ForceMT import ForceMT

# Add the Force model
simu.force = ForceMT(is_periodicity_a=True, is_periodicity_t=True)

# Run simulations both models
out = simu.run()
[16:18:37] Starting running simulation FEMM_periodicity (machine=Toyota_Prius)
[16:18:37] Starting Magnetic module
[16:18:38] Solving time steps: 0%
[16:18:39] Solving time steps: 0%
[16:18:39] Solving time steps: 0%
[16:18:39] Solving time steps: 0%
[16:18:42] Solving time steps: 25%
[16:18:42] Solving time steps: 25%
[16:18:43] Solving time steps: 25%
[16:18:43] Solving time steps: 25%
[16:18:45] Solving time steps: 50%
[16:18:45] Solving time steps: 50%
[16:18:46] Solving time steps: 50%
[16:18:46] Solving time steps: 50%
[16:18:48] Solving time steps: 75%
[16:18:48] Solving time steps: 75%
[16:18:48] Solving time steps: 75%
[16:18:49] Solving time steps: 75%
[16:18:50] Solving time step: 100%
[16:18:50] Solving time step: 100%
[16:18:51] Solving time step: 100%
[16:18:51] Solving time step: 100%
[16:18:51] Starting Force module
[16:18:51] End of simulation FEMM_periodicity
Once the simulation is finished, the results are stored in the force part of the output (i.e. out.force_ ) and we can call different plots. This object contains:
- Time: Time axe - Angle: Angular position axe
- AGSF: Airgap surface force (Radial and Tangential component)

Output object embbed different plot to visualize results easily. You can find a dedicated tutorial here.

Here are some example of useful force related plots.

[6]:
# AGSF as a function of angle in degre (for time=0) both radial and tangential
out.force.AGSF.plot_2D_Data("angle{°}")
[7]:
# FFT of AGSF on angle
out.force.AGSF.plot_2D_Data("wavenumber=[0,78]")
[8]:
from numpy import pi

# Plot the air-gap force as a function of time for a given angle
out.force.AGSF.plot_2D_Data("time","angle[10]", is_auto_ticks=False)
[9]:
# Plot the FFT of time
out.force.AGSF.plot_2D_Data("freqs=[0,4000]", is_auto_ticks=False)

The following plot displays the radial air-gap surface force over time and angle.

[10]:
# Plot the tangential force as a function of time and space
out.force.AGSF.plot_3D_Data("time", "angle{°}", is_2D_view=True)
[ ]: