Skip to content

Commit 6c40295

Browse files
committed
[BC] plot mmf
1 parent 8296226 commit 6c40295

File tree

3 files changed

+40
-60
lines changed

3 files changed

+40
-60
lines changed

pyleecan/GUI/Dialog/DMachineSetup/SPreview/WMachineTable/WMachineTable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def plot_mmf(self):
101101
"""Plot the unit mmf of the stator"""
102102
try:
103103
if self.machine is not None:
104-
self.machine.stator.plot_mmf_unit(is_create_appli=False)
104+
self.machine.stator.plot_mmf_unit()
105105
set_plot_gui_icon()
106106
except Exception as e:
107107
err_msg = "Error while plotting Stator mmf unit:\n" + str(e)

pyleecan/GUI/Dialog/DMachineSetup/SWinding/SWinding.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ def __init__(self, machine, material_dict, is_stator=False):
8080
# Enforce star of slot
8181
self.c_wind_type.setEnabled(False)
8282
self.c_wind_type.setCurrentIndex(0)
83+
# No plot_mmf
84+
self.b_plot_mmf.hide()
8385

8486
# Pattern Group setup
8587
if self.obj.winding is None:
@@ -561,7 +563,7 @@ def s_plot_mmf(self):
561563
"""Plot the unit mmf of the stator"""
562564
if self.machine is not None:
563565
try:
564-
self.plot_widget = self.obj.plot_mmf_unit(is_create_appli=False)
566+
self.obj.plot_mmf_unit()
565567
except Exception as e:
566568
if self.obj.is_stator: # Adapt the text to the current lamination
567569
err_msg = "Error while plotting Stator mmf unit:\n" + str(e)
Lines changed: 36 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
import matplotlib.pyplot as plt
2-
from numpy import min as np_min, max as np_max
32

4-
from PySide2.QtCore import *
5-
from PySide2.QtGui import *
6-
from PySide2.QtWidgets import *
7-
8-
from ....Functions.Plot.set_plot_gui_icon import set_plot_gui_icon
93
from ....Functions.Plot import dict_2D
104
from ....definitions import config_dict
115

126

13-
def plot_mmf_unit(self, is_create_appli=True, save_path=None):
7+
def plot_mmf_unit(self, r_max=100, fig=None, is_show_fig=True):
148
"""Plot the winding unit mmf as a function of space
159
Parameters
1610
----------
17-
1811
self : LamSlotWind
1912
an LamSlotWind object
20-
is_create_appli : bool
21-
True to create an QApplication (required if not already created by another GUI)
13+
Na : int
14+
Space discretization
15+
fig : Matplotlib.figure.Figure
16+
existing figure to use if None create a new one
17+
is_show_fig : bool
18+
To call show at the end of the method
2219
"""
2320

2421
name = ""
@@ -30,55 +27,36 @@ def plot_mmf_unit(self, is_create_appli=True, save_path=None):
3027
name += "Rotor "
3128

3229
# Compute the winding function and mmf
33-
wf = self.comp_wind_function(per_a=1)
3430
qs = self.winding.qs
35-
MMF_U, WF = self.comp_mmf_unit(Nt=1, Na=wf.shape[1])
31+
p = self.get_pole_pair_number()
32+
MMF_U, WF = self.comp_mmf_unit(Nt=1, Na=400 * p)
3633

3734
color_list = config_dict["PLOT"]["COLOR_DICT"]["COLOR_LIST"][:qs]
3835

39-
plot_arg_dict = dict_2D.copy()
40-
plot_arg_dict["color_list"] = color_list + ["k"]
41-
plot_arg_dict["data_list"] = [MMF_U]
42-
43-
if save_path is not None:
44-
WF.plot_2D_Data(
45-
"angle{°}",
46-
"phase[]",
47-
unit="A",
48-
y_min=np_min(MMF_U.values) * 1.1,
49-
y_max=np_max(MMF_U.values) * 1.1,
50-
is_show_fig=False,
51-
save_path=save_path,
52-
**plot_arg_dict,
53-
)
54-
55-
elif is_create_appli:
56-
WF.plot(
57-
"angle{°}",
58-
"phase[]",
59-
unit="A",
60-
z_min=np_min(MMF_U.values) * 1.1,
61-
z_max=np_max(MMF_U.values) * 1.1,
62-
plot_arg_dict=plot_arg_dict,
63-
is_create_appli=is_create_appli,
64-
frozen_type=2,
65-
)
66-
else:
67-
wid = WF.plot(
68-
"angle{°}",
69-
"phase[]",
70-
unit="A",
71-
z_min=np_min(MMF_U.values) * 1.1,
72-
z_max=np_max(MMF_U.values) * 1.1,
73-
plot_arg_dict=plot_arg_dict,
74-
is_create_appli=is_create_appli,
75-
frozen_type=2,
76-
)
77-
78-
wid.setWindowTitle(name + "Phase MMF plot")
79-
set_plot_gui_icon()
80-
# Change default file name
81-
wid.canvas.get_default_filename = (
82-
lambda: wid.windowTitle().replace(" ", "_").replace(":", "") + ".png"
83-
)
84-
return wid
36+
fig, axs = plt.subplots(2, 1, tight_layout=True, figsize=(8, 8))
37+
38+
dict_2D_0 = dict_2D.copy()
39+
dict_2D_0["color_list"] = color_list + ["k"]
40+
41+
WF.plot_2D_Data(
42+
"angle{°}",
43+
"phase[]",
44+
data_list=[MMF_U],
45+
fig=fig,
46+
ax=axs[0],
47+
is_show_fig=is_show_fig,
48+
win_title=name + "phase MMF",
49+
**dict_2D_0,
50+
)
51+
52+
dict_2D_0["color_list"] = [color_list[0], "k"]
53+
54+
WF.plot_2D_Data(
55+
"wavenumber=[0," + str(r_max) + "]",
56+
data_list=[MMF_U],
57+
fig=fig,
58+
ax=axs[1],
59+
is_show_fig=is_show_fig,
60+
win_title=name + "phase MMF FFT",
61+
**dict_2D_0,
62+
)

0 commit comments

Comments
 (0)