Skip to content

Commit

Permalink
showning the losses and inductances for a transformer in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
abujazar committed May 2, 2024
1 parent da7e0e5 commit bf0e37b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 29 deletions.
48 changes: 32 additions & 16 deletions femmt/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,33 +1064,49 @@ def visualize_simulation_results(simulation_result_file_path: str, store_figure_
"""Visualize the simulation results by a figure."""
with open(simulation_result_file_path, "r") as fd:
loaded_results_dict = json.loads(fd.read())

inductance = loaded_results_dict["single_sweeps"][0]["winding1"]["flux_over_current"][0]
# core eddy and hysteresis losses
loss_core_eddy_current = loaded_results_dict["total_losses"]["eddy_core"]
loss_core_hysteresis = loaded_results_dict["total_losses"]["hyst_core_fundamental_freq"]
loss_winding_1 = loaded_results_dict["total_losses"]["winding1"]["total"]
# Inductances and winding losses
windings_inductance = []
windings_loss = []
windings_labels = []
# Dynamically for 3 windings
for i in range(1, 3):
winding_key = f"winding{i}"
if winding_key in loaded_results_dict["single_sweeps"][0]:
windings_inductance.append(loaded_results_dict["single_sweeps"][0][winding_key]["flux_over_current"][0])
windings_loss.append(loaded_results_dict["total_losses"][winding_key]["total"])
windings_labels.append(f"Winding {i}")

# Plotting results
fig, ax = plt.subplots()
bar_width = 0.35

print(inductance)
print(loss_core_eddy_current)
print(loss_core_hysteresis)
print(loss_winding_1)
# Plot core losses
ax.bar(0, loss_core_hysteresis, width=bar_width, label='Core Hysteresis Loss')
ax.bar(0, loss_core_eddy_current, bottom=loss_core_hysteresis, width=bar_width, label='Core Eddy Current Loss')

bar_width = 0.35
plt.bar(0, loss_core_hysteresis, width=bar_width)
plt.bar(0, loss_core_eddy_current, bottom=loss_core_hysteresis, width=bar_width)
plt.bar(1, loss_winding_1, width=bar_width)
plt.legend(['Hysteresis loss', 'Eddy current loss', 'Winding loss'])
plt.ylabel('Losses in W')
plt.xticks([0, 1, 2], ['Core', 'Winding 1', 'Winding 2'])
plt.grid()
# Plot winding inductances and losses
for index, (inductance, loss) in enumerate(zip(windings_inductance, windings_loss), start=1):
ax.bar(index, loss, width=bar_width, label=f'{windings_labels[index - 1]} Loss')
print(f"{windings_labels[index - 1]} Inductance: {inductance} H")
print(f"{windings_labels[index - 1]} Loss: {loss} W")

ax.set_ylabel('Losses in W')
ax.set_title('Loss Distribution in Magnetic Components')
ax.set_xticks(list(range(len(windings_labels) + 1)))
ax.set_xticklabels(['Core'] + windings_labels)
ax.legend()

plt.grid(True)
plt.savefig(store_figure_file_path, bbox_inches="tight")

if show_plot:
plt.show()

return loaded_results_dict


def point_is_in_rect(x, y, rect):
"""Check if a given x-y point is inside a rectangular field (e.g. inside a conductor)."""
# x, y of the point
Expand Down
25 changes: 21 additions & 4 deletions gui/femmt_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3195,14 +3195,31 @@ def md_action_run_simulation(self) -> None:
self.md_loss_plot_label.setMask(pixmap.mask())
self.md_loss_plot_label.show()

inductance = loaded_results_dict["single_sweeps"][0]["winding1"]["flux_over_current"][0]
# inductance = loaded_results_dict["single_sweeps"][0]["winding1"]["flux_over_current"][0]
loss_core_eddy_current = loaded_results_dict["total_losses"]["eddy_core"]
loss_core_hysteresis = loaded_results_dict["total_losses"]["hyst_core_fundamental_freq"]
loss_winding_1 = loaded_results_dict["total_losses"]["winding1"]["total"]
# loss_winding_1 = loaded_results_dict["total_losses"]["winding1"]["total"]
self.md_loss_core_hysteresis_label.setText(f"Core Hysteresis loss: {loss_core_hysteresis} W")
self.md_loss_core_eddy_current_label.setText(f"Core Eddy Current loss: {loss_core_eddy_current} W")
self.md_loss_winding1_label.setText(f"Winding 1 loss: {loss_winding_1} W")
self.md_inductance_label.setText(f"Primary Inductance: {inductance} H")
# self.md_loss_winding1_label.setText(f"Winding 1 loss: {loss_winding_1} W")
# self.md_inductance_label.setText(f"Primary Inductance: {inductance} H")
inductances = []
windings_loss = []
for i in range(1, 3): # for 3 windings
winding_key = f"winding{i}"
if winding_key in loaded_results_dict["single_sweeps"][0]:
inductances.append(loaded_results_dict["single_sweeps"][0][winding_key]["flux_over_current"][0])
windings_loss.append(loaded_results_dict["total_losses"][winding_key]["total"])

# show them just for 2 windings in GUI
if self.md_simulation_type_comboBox.currentText() == self.translation_dict['inductor']:
self.md_loss_winding1_label.setText(f"Winding 1 loss: {windings_loss[0]} W")
self.md_inductance1_label.setText(f"Primary Inductance: {inductances[0]} H")
elif self.md_simulation_type_comboBox.currentText() == self.translation_dict['transformer']:
self.md_loss_winding1_label.setText(f"Winding 1 loss: {windings_loss[0]} W")
self.md_loss_winding2_label.setText(f"Winding 2 loss: {windings_loss[1]} W")
self.md_inductance1_label.setText(f"Primary Inductance: {inductances[0]} H")
self.md_inductance2_label.setText(f"Secondary Inductance: {inductances[1]} H")

# log_path = geo.e_m_results_log_path
# simulation_results = str(fmt.read_results_log(log_path))
Expand Down
25 changes: 16 additions & 9 deletions gui/femmt_gui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="md_QWidget_2">
<attribute name="title">
Expand All @@ -46,7 +46,7 @@
</size>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="md_QWidget">
<attribute name="title">
Expand Down Expand Up @@ -1822,15 +1822,15 @@
<string>Simulation Text Output</string>
</property>
<layout class="QGridLayout" name="gridLayout_22">
<item row="0" column="1">
<widget class="QLabel" name="md_loss_core_hysteresis_label">
<item row="3" column="1">
<widget class="QLabel" name="md_loss_winding2_label">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="md_loss_winding2_label">
<item row="0" column="1">
<widget class="QLabel" name="md_loss_core_hysteresis_label">
<property name="text">
<string/>
</property>
Expand All @@ -1843,15 +1843,22 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="md_inductance1_label">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="md_loss_winding1_label">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="md_inductance_label">
<item row="5" column="1">
<widget class="QLabel" name="md_inductance2_label">
<property name="text">
<string/>
</property>
Expand Down Expand Up @@ -9557,7 +9564,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>98</width>
<width>1072</width>
<height>1024</height>
</rect>
</property>
Expand Down

0 comments on commit bf0e37b

Please sign in to comment.