# 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 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 demonstrate the capabilities and the use of the SciDataTool objects, a simulation is launched with FEMM, with imposed currents, using periodicity and parallelization to reduce execution time.

[2]:

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.definitions import DATA_DIR

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

# Run simulations
out = simu.run()

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


## Force Module¶

The Force abstract class will make it possible to define different ways of calculating forces.

The ForceMT class inherits from Force class. ForceMT is dedicated to the computation of air-gap surface force based on the Maxwell stress tensor [source].

Here, we get the results from a magnetic simulation without any force calculation. The Force module is initialized and run alone.

[3]:

from pyleecan.Classes.Simu1 import Simu1
from pyleecan.Classes.ForceMT import ForceMT

# Create the Simulation
mySimu = Simu1(name="Tuto_Force")
mySimu.parent = out
mySimu.force = ForceMT()

# Run only the force module
mySimu.force.run()

[17:50:42] Starting Force module

Once the simulation is finished, the results are stored in the force part of the output (i.e. myResults.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 plots.

[4]:

%matplotlib notebook
from pyleecan.Functions.Plot import dict_2D, dict_3D
out.force.AGSF.plot_2D_Data("angle{°}", **dict_2D)
out.force.AGSF.plot_2D_Data("wavenumber=[0,78]", **dict_2D)

[5]:

from numpy import pi

#------------------------------------------------------
# Plot the air-gap force as a function of time with the time fft
out.force.AGSF.plot_2D_Data("time","angle[10]", is_auto_ticks=False, **dict_2D)
out.force.AGSF.plot_2D_Data("freqs=[0,4000]", is_auto_ticks=False, **dict_2D)
#------------------------------------------------------


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

[6]:

#------------------------------------------------------
# Plot the tangential force as a function of time and space
out.force.AGSF.plot_3D_Data("time", "angle{°}", is_2D_view=True, **dict_3D)
#------------------------------------------------------