There are several ways to run FEMAG with femagtools: either using an existing FSL script or
optionally in combination with one of the 7 FE simulation functions: cogg_calc, pm_rel_sim_fast, pm_sym_loss, mult_cal_fast, torq_calc, ld_lq_fast, psd_psq_fast.
In [1]:
import femagtools
Create the FSL command by referencing a model name:
In [2]:
femagtools.create_fsl('PM_270_L8')
Out[2]:
This produces a list of FSL commands which can be written to a file:
In [3]:
with open('femag.fsl', 'w') as f:
f.write('\n'.join(femagtools.create_fsl('PM_270_L8')))
Note: The explicit creation of an FSL file is often not necessary.
The FSL commands to build a FEMAG model can be generated from parameterized stator and magnet models. This is done by setting up a dict variable that contains a general set of parameters together with the stator, magnet and winding dicts:
In [4]:
machine = {
"name": "PM 270 L8",
"desc": "PM Motor 270mm 8 poles VMAGN",
"poles": 8,
"outer_diam": 0.26924,
"bore_diam": 0.16192,
"inner_diam": 0.11064,
"airgap": 0.00075,
"lfe": 0.08356,
"stator": {
"num_slots": 48,
"mcvkey_yoke": 'M270-35A',
"statorRotor3": {
"slot_height": 0.0335,
"slot_h1": 0.001,
"slot_h2": 0.0,
"slot_width": 0.00193,
"slot_r1": 0.0001,
"slot_r2": 0.00282,
"wedge_width1": 0.00295,
"wedge_width2": 0.0,
"middle_line": 0.0,
"tooth_width": 0.0,
"slot_top_sh": 0.0}
},
"magnet": {
"mcvkey_yoke": 'M270-35A',
"nodedist": 4,
"magnetIronV": {
"magn_angle": 145.0,
"magn_height": 0.00648,
"magn_width": 0.018,
"condshaft_r": 0.05532,
"magn_num": 1.0,
"air_triangle": 1,
"iron_hs": 0.0,
"gap_ma_iron": 0.0002,
"iron_height": 0.00261,
"magn_rem": 1.2,
"iron_shape": 0.0802
}
},
"windings": {
"num_phases": 3,
"num_layers": 1,
"num_wires": 9,
"coil_span": 6.0,
"cufilfact": 0.4,
"culength": 1.4,
"slot_indul": 0.5e-3
}
}
Using this model description it is possible to create the FSL file by a set of pre-defined templates. To do so we first chose a working directory and set the directory of the MC/MCV files using the parameter 'magnetizingCurves':
In [5]:
import os
workdir = os.path.join(os.path.expanduser('~'), 'femag')
fslfile = 'femag.fsl'
with open(os.path.join(workdir, fslfile), 'w') as f:
f.write('\n'.join(femagtools.create_fsl(machine)))
femag = femagtools.femag.Femag(workdir, magnetizingCurves='.')
femag.run(fslfile, options=['-g'])
To invoke a FE calculation an additional dict must be setup:
In [6]:
simulation = {
"angl_i_up": -30.0,
"calculationMode": "pm_sym_fast",
"num_move_steps": 0,
"wind_temp": 60.0,
"magn_temp": 60.0,
"current": 150.0,
"speed": 50.0,
"airgap_induc": True
}
If we want to receive some feedback a logger would be useful:
In [7]:
import logging
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(message)s')
Now we can invoke FEMAG without creating an FSL file. The Femag object knows how to handle this:
In [8]:
r = femag(machine,
simulation, options=['-g'])
After a calculation has finished we can examine all the BCH values which are included in the result 'r'. For example the torque:
In [9]:
r.machine['torque']
Out[9]:
If we had set the parameter 'airgap_induc' to True we can read the produced airgap values:
In [10]:
airgap = femag.read_airgap_induction()
and create a nice plot including the base harmonic:
In [11]:
import matplotlib.pylab as plt
import femagtools.plot
femagtools.plot.airgap(airgap)
plt.show()
We can even create a graphical report of the results:
In [12]:
femagtools.plot.pmrelsim(r)
plt.show()
In [13]:
machine['magnet'] = dict(
mcvkey_yoke='M270-35A',
spokefml=dict(
magn_height=0.008,
shaft_diam=0.01,
slot_width=0.004,
magn_width=0.022
)
)
The FSL fragment should make use of the globally defined variables as described in the femagtools documentation.
In [14]:
fslfile = 'femag.fsl'
with open(os.path.join(workdir, fslfile), 'w') as f:
f.write('\n'.join(femagtools.create_fsl(machine)))
femag.run(fslfile, options=['-g'])
The resulting geometry can be plotted:
In [15]:
isa = femag.read_isa()
femagtools.plot.spel(isa)
plt.show()