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

The first step consists in getting simulation data. In order to demonstrate the capabilities of the plot commands, a simulation over 2048 time steps has been performed in the simulation tutorial, and the resulting Output object has been stored on Pyleecan’s website. First, these results need to be downloaded:

[ ]:

# Import Pyleecan modules
from pyleecan.definitions import USER_DIR
from os.path import join, isfile
import urllib.request

data_path = join(USER_DIR, 'tuto_Simu_FEMM_results.json')

if not isfile(data_path):
url = 'https://www.pyleecan.org/Data/tuto_Simu_FEMM_results.json'
urllib.request.urlretrieve(url, data_path)
print("Done")

# Load Output object from json file
print("Done")


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

[ ]:

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

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 vector without symmetry
- angle: Position vector without symmetry
- Nt_tot: Length of the time vector - Na_tot: Length of the angle vector - Prad: Radial airgap surface force
- Ptan: Tangential airgap surface force

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

Here are some example of useful plots.

[ ]:

%matplotlib notebook
out.plot_2D_Data("force.P", "angle")
out.plot_2D_Data("force.P", "wavenumber=[0,78]")

[ ]:

from numpy import pi

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


You can also define your own plot. The following plot requires plotly to display the radial air-gap surface force over time and angle.

[ ]:

#------------------------------------------------------
# Plot the tangential force as a function of time and space
out.plot_A_time_space("force.P", freq_max=freq_max, r_max=r_max)
#------------------------------------------------------