Skip to content

Commit

Permalink
Merge pull request #536 from EOMYS-Public/MatLib
Browse files Browse the repository at this point in the history
[CC] Rework plot_multi arguments cf #527
  • Loading branch information
BonneelP authored May 2, 2022
2 parents 1344951 + b579249 commit 8dfc180
Show file tree
Hide file tree
Showing 149 changed files with 1,718 additions and 910 deletions.
8 changes: 4 additions & 4 deletions Tests/GUI/DMachineSetup/PWSlot/test_PWSlot25.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,17 @@ def test_check(self):
self.test_obj.slot = SlotW25(Zs=4, H2=0.11, H1=0, W4=0.1, W3=0.16)
assert (
self.widget.check(self.test_obj)
== "You must have H1>0 (use Slot 24 for H1=0)"
== "You must have H1>0 (use Slot 25 for H1=0)"
)
self.test_obj.slot = SlotW25(Zs=4, H2=0, H1=0.11, W4=0.1, W3=0.16)
assert (
self.widget.check(self.test_obj)
== "You must have H2>0 (use Slot 24 for H2=0)"
== "You must have H2>0 (use Slot 25 for H2=0)"
)
self.test_obj.slot = SlotW25(Zs=4, H2=0.12, H1=0.11, W4=0.1, W3=0.1)
assert (
self.widget.check(self.test_obj)
== "You must have W4 != W3 (use Slot 24 for W4=W3)"
== "You must have W4 != W3 (use Slot 25 for W4=W3)"
)

def test_set_wedge(self):
Expand Down Expand Up @@ -182,6 +182,6 @@ def test_set_wedge(self):
a = TestPWSlot25()
a.setup_class()
a.setup_method()
a.test_init()
a.test_check()
a.teardown_class()
print("Done")
35 changes: 34 additions & 1 deletion Tests/GUI/DMatLib/test_Workflow_Matlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,38 @@ def test_new_machine_material(self):
# Close the dialog
dialog.close()

def test_copy_machine_material(self):
"""Copy a material for the machine and check changes in the GUI"""
# Check initial state
assert self.widget.machine.rotor.hole[0].magnet_0.mat_type.struct.rho == 7500
assert not isfile(join(WS_path, "MagnetPrius_old.json"))
# Open DMatlib
self.widget.nav_step.setCurrentRow(6) # Hole material
assert isinstance(self.widget.w_step, SMHoleMag)
w_mat = self.widget.w_step.tab_hole.widget(0).w_hole.w_mat_1
assert w_mat.current_dialog is None
w_mat.b_matlib.clicked.emit()
assert isinstance(w_mat.current_dialog, DMatLib)
dialog = w_mat.current_dialog
assert dialog.is_lib_mat is False
assert dialog.nav_mat_mach.currentRow() == 1
assert dialog.nav_mat.count() == 4
assert dialog.nav_mat_mach.count() == 2
assert dialog.w_setup.le_name.text() == "MagnetPrius_old"

# Copy MagnetPrius_old material once
dialog.b_copy.clicked.emit()
assert dialog.w_setup.le_name.text() == "MagnetPrius_old_copy"
dialog.w_setup.b_save.clicked.emit()

# Copy MagnetPrius_old material twice
dialog.b_copy.clicked.emit()
assert dialog.w_setup.le_name.text() == "MagnetPrius_old_copy_2"
dialog.w_setup.b_save.clicked.emit()

# Close the dialog
dialog.close()

def test_rename_matlib(self):
"""rename a material in the Library and check changes in machine"""
# Check initial state
Expand Down Expand Up @@ -622,9 +654,10 @@ def test_edit_machine_to_library(self):
# a.test_rename_machine_material()
# a.test_rename_matlib()
# a.test_new_machine_material()
a.test_copy_machine_material()
# a.test_new_matlib()
# a.test_edit_machine_to_library()
a.test_edit_matlib_to_machine()
# a.test_edit_matlib_to_machine()
# a.test_edit_machine_material_several()
# a.test_edit_machine_material()
# a.test_edit_matlib()
Expand Down
4 changes: 2 additions & 2 deletions Tests/Methods/Machine/test_desc_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
@pytest.mark.SCIM
def test_desc_SCIM():
"""Check that the description of a SCIM is correct"""
SCIM_001 = load(join(DATA_DIR, "Machine", "Railway_Traction.json"))
desc_dict = SCIM_001.comp_desc_dict()
Railway_Traction = load(join(DATA_DIR, "Machine", "Railway_Traction.json"))
desc_dict = Railway_Traction.comp_desc_dict()
assert len(desc_dict) == 9
assert desc_dict[0]["name"] == "Type"
assert desc_dict[0]["value"] == "SCIM"
Expand Down
38 changes: 17 additions & 21 deletions Tests/Plot/Schematics/test_hole_convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@

def test_plot_radius():
"""Plot the min/max radius of the Hole"""
plt.close("all")
BMW = load(join(DATA_DIR, "Machine", "BMW_i3.json"))

# Modification for better visualization
BMW.rotor.hole[0].Zh = 6
for surf in BMW.rotor.hole[0].surf_list:
surf.translate(-5e-3)

BMW.rotor.plot(is_show_fig=False)
fig = plt.gcf()
ax = plt.gca()

fig, ax = BMW.rotor.plot(is_show_fig=False, edgecolor="k")
# Top and Bottom arc
(Rint, Rext) = BMW.rotor.hole[0].comp_radius()
line = Arc1(
Expand Down Expand Up @@ -59,16 +57,16 @@ def test_plot_radius():
)
# Adding Label
Zref = Rext * exp(1j * pi / 2)
plt.plot(Zref.real, Zref.imag, "xr")
plt.text(
ax.plot(Zref.real, Zref.imag, "xr")
ax.text(
Zref.real,
Zref.imag + 1e-3,
"Rext",
weight="bold",
)
Zref = Rint * exp(1j * pi / 2)
plt.plot(Zref.real, Zref.imag, "xr")
plt.text(
ax.plot(Zref.real, Zref.imag, "xr")
ax.text(
Zref.real,
Zref.imag + 1e-3,
"Rint",
Expand All @@ -85,6 +83,7 @@ def test_plot_radius():

fig.savefig(join(save_path, "Schematics", "Hole_radius.png"))
# plt.show()
plt.close(fig=fig)


def test_plot_magnet_id():
Expand Down Expand Up @@ -114,21 +113,20 @@ def test_plot_magnet_id():
)
)

rotor.plot(is_show_fig=False)
fig, ax = rotor.plot(is_show_fig=False, edgecolor="k")

# Adding label
surf_list = rotor.hole[0].build_geometry()
for surf in surf_list:
label_dict = decode_label(surf.label)
if HOLEM_LAB in label_dict["surf_type"]:
Zref = surf.point_ref * exp(1j * pi / 2)
plt.text(
ax.text(
Zref.real - 5e-3,
Zref.imag,
"magnet_" + str(label_dict["T_id"]),
weight="bold",
)
ax = plt.gca()
ax.set_xlim(-30e-3, 30e-3)
ax.set_ylim(50e-3, 90e-3)

Expand All @@ -138,8 +136,8 @@ def test_plot_magnet_id():
ax.get_legend().remove()
ax.set_title("")

fig = plt.gcf()
fig.savefig(join(save_path, "Schematics", "Hole_magnet_id.png"))
plt.close(fig=fig)


def test_plot_hole_RTS():
Expand Down Expand Up @@ -188,24 +186,21 @@ def test_plot_hole_RTS():
)
)

rotor.plot(
is_show_fig=False
) # , save_path=join(save_path, "Shematics", "Hole_RTS.png"))
fig, ax = rotor.plot(is_show_fig=False, edgecolor="k")

# Adding label
surf_list = rotor.hole[0].build_geometry()
surf_list.extend(rotor.hole[1].build_geometry())
for surf in surf_list:
Zref = surf.point_ref * exp(1j * pi / 2)
plt.plot(Zref.real, Zref.imag, "xr")
ax.plot(Zref.real, Zref.imag, "xr")
label_dict = decode_label(surf.label)
plt.text(
ax.text(
Zref.real,
Zref.imag,
label_dict["surf_type"][4:] + "_" + label_dict["index"],
weight="bold",
)
ax = plt.gca()
ax.set_xlim(-30e-3, 30e-3)
ax.set_ylim(50e-3, 90e-3)
# Set figure to full screen for readibility
Expand All @@ -216,11 +211,12 @@ def test_plot_hole_RTS():
ax.set_axis_off()
ax.get_legend().remove()
ax.set_title("")
fig = plt.gcf()
fig.savefig(join(save_path, "Schematics", "Hole_RTS.png"))
plt.close(fig=fig)


if __name__ == "__main__":
test_plot_radius()
# test_plot_magnet_id()
# test_plot_hole_RTS()
test_plot_magnet_id()
test_plot_hole_RTS()
print("Done")
4 changes: 2 additions & 2 deletions Tests/Simulation/test_StructElmer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from os.path import join
from numpy import pi
import pytest
from Tests import save_path, TEST_DATA_DIR
from Tests import save_validation_path as save_path, TEST_DATA_DIR
from pyleecan.Classes.OPdq import OPdq
from pyleecan.definitions import DATA_DIR

Expand All @@ -17,7 +17,7 @@

# get the machine
machine_1 = load(join(DATA_DIR, "Machine", "Toyota_Prius.json"))

save_path = join(save_path, "StructElmer")
# mesh settings, original line label names have to be used (not the translated)
n1 = 3
n2 = 20
Expand Down
2 changes: 1 addition & 1 deletion Tests/Simulation/test_post_var_simu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from copy import copy

from numpy import sqrt

import numpy as np
from pyleecan.Classes.HoleM51 import HoleM51
from pyleecan.Classes.HoleM52 import HoleM52
from pyleecan.Classes.HoleM53 import HoleM53
Expand Down
5 changes: 2 additions & 3 deletions Tests/Validation/Optimization/test_Binh_and_Korn_Bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@
@pytest.mark.periodicity
@pytest.mark.SingleOP
def test_Binh_and_Korn():
SCIM_001 = load(join(DATA_DIR, "Machine", "SCIM_001.json"))
# Defining reference Output
# Definition of the enforced output of the electrical module
SCIM_001 = load(join(DATA_DIR, "Machine", "SCIM_001.json"))
Railway_Traction = load(join(DATA_DIR, "Machine", "Railway_Traction.json"))
Nt = 2
N0 = 3000
Is = ImportMatrixVal(
Expand All @@ -60,7 +59,7 @@ def test_Binh_and_Korn():
Na_tot = 64

# Definition of the simulation
simu = Simu1(name="test_Binh_and_Korn_Bayes", machine=SCIM_001)
simu = Simu1(name="test_Binh_and_Korn_Bayes", machine=Railway_Traction)

simu.input = InputCurrent(
Is=Is,
Expand Down
4 changes: 2 additions & 2 deletions Tests/Validation/Optimization/test_opti_datakeeper_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
def test_opti_datakeeper_list():
# Defining reference Output
# Definition of the enforced output of the electrical module
SCIM_001 = load(join(DATA_DIR, "Machine", "Railway_Traction.json"))
Railway_Traction = load(join(DATA_DIR, "Machine", "Railway_Traction.json"))

# Definition of the simulation
simu = Simu1(name="test_opti_datakeeper_list", machine=SCIM_001)
simu = Simu1(name="test_opti_datakeeper_list", machine=Railway_Traction)

# Design variable
my_vars = [
Expand Down
4 changes: 2 additions & 2 deletions Tests/Validation/Optimization/test_zdt3_Bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@pytest.mark.SingleOP
def test_zdt3_Bayes():
# ### Defining reference Output
SCIM_001 = load(join(DATA_DIR, "Machine", "SCIM_001.json"))
Railway_Traction = load(join(DATA_DIR, "Machine", "Railway_Traction.json"))

# Definition of the enforced output of the electrical module
Nt = 2
Expand All @@ -55,7 +55,7 @@ def test_zdt3_Bayes():
Na_tot = 64

# Definition of the simulation
simu = Simu1(name="test_zdt3", machine=SCIM_001)
simu = Simu1(name="test_zdt3", machine=Railway_Traction)

simu.input = InputCurrent(
Is=Is,
Expand Down
1 change: 1 addition & 0 deletions pyleecan/Functions/Optimization/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from os import stat, remove
from datetime import datetime
from numpy import nan
import numpy as np


def evaluate(solver, indiv):
Expand Down
2 changes: 1 addition & 1 deletion pyleecan/Functions/Simulation/VarSimu/run_multisim_step.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from numpy import ndarray, min as np_min, max as np_max

import numpy as np
from SciDataTool import VectorField, Data
from ....Functions.Load.import_class import import_class
from ....Functions.Simulation.VarSimu.log_datakeeper_step_result import (
Expand Down
16 changes: 12 additions & 4 deletions pyleecan/GUI/Dialog/DMatLib/DMatLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,19 @@ def new_material(self, is_copy=True):
# Adapt name to be unique
name_list = [mat.name for mat in self.material_dict[LIB_KEY]]
name_list.extend([mat.name for mat in self.material_dict[MACH_KEY]])

# Renaming the material so that we have "_copy","_copy_2","_copy_3"...
if new_mat.name in name_list:
index = 1
while new_mat.name + "_" + str(index) in name_list:
index += 1
new_mat.name = new_mat.name + "_" + str(index)
# Adding number after copy
if new_mat.name[-4:] == "copy":
new_mat.name = new_mat.name + "_2"
# Setting the index after the current one
else:
index = 1
while int(new_mat.name[-1]) >= index:
index += 1
new_mat.name = new_mat.name[:-1]
new_mat.name = new_mat.name + str(index)
new_mat.path = join(dirname(new_mat.path), new_mat.name + ".json")

# Save if in MatLib
Expand Down
8 changes: 4 additions & 4 deletions pyleecan/GUI/Tools/WTableData/DTableData.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,15 @@ def s_plot(self):
# Data in line
fig, axes = plt.subplots()
axes.plot(data[0, :], data[1, :])
plt.ylabel(self.col_header[1])
plt.xlabel(self.col_header[0])
axes.set_xlabel(self.col_header[0])
axes.set_ylabel(self.col_header[1])
fig.show()
elif len(data.shape) == 2 and data.shape[1] == 2:
# Data in column
fig, axes = plt.subplots()
axes.plot(data[:, 0], data[:, 1])
plt.ylabel(self.col_header[1])
plt.xlabel(self.col_header[0])
axes.set_xlabel(self.col_header[0])
axes.set_ylabel(self.col_header[1])
fig.show()
if self.col_header is not None:
fig.canvas.manager.set_window_title(self.col_header[0] + " plot")
Expand Down
Loading

0 comments on commit 8dfc180

Please sign in to comment.