Skip to content

Commit a5acab2

Browse files
authored
Merge pull request #401 from EOMYS-Public/BH_curve
[NF] Multi-simulation of Multi-simulation tutorial
2 parents 3a57e97 + 005be8f commit a5acab2

File tree

7 files changed

+844
-20
lines changed

7 files changed

+844
-20
lines changed

Tests/GUI/DMatLib/test_DMatLib.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
# -*- coding: utf-8 -*-
22

33
import sys
4-
5-
from PySide2 import QtWidgets
6-
7-
from pyleecan.Classes.MatMagnetics import MatMagnetics
8-
from pyleecan.Classes.Material import Material
9-
from pyleecan.Functions.load import load_matlib
10-
from pyleecan.GUI.Dialog.DMatLib.DMatLib import DMatLib
11-
from Tests import save_gui_path
12-
134
from os import makedirs
145
from os.path import isdir, join
156
from shutil import rmtree
167

178
import pytest
9+
from numpy import array
10+
from pyleecan.Classes.ImportMatrixVal import ImportMatrixVal
11+
from pyleecan.Classes.Material import Material
12+
from pyleecan.Classes.MatMagnetics import MatMagnetics
13+
from pyleecan.Functions.load import load_matlib
14+
from pyleecan.GUI.Dialog.DMatLib.DMatLib import DMatLib
15+
from PySide2 import QtWidgets
16+
from Tests import save_gui_path
1817

1918
# To save the tmp Matlib
2019
tmp_folder = join(save_gui_path, "DMatLib", "tmp_matlib")
@@ -38,6 +37,9 @@ def setup(self):
3837
mat_lib[0].is_isotropic = True
3938
mat_lib[0].elec.rho = 0.11
4039
mat_lib[0].mag = MatMagnetics(mur_lin=0.12, Wlam=0.13)
40+
mat_lib[0].mag.BH_curve = ImportMatrixVal(
41+
value=array([[0, 1], [2, 100], [3, 300], [4, 450]])
42+
)
4143
mat_lib[0].struct.rho = 0.14
4244
mat_lib[0].struct.Ex = 0.15
4345
mat_lib[0].struct.Ey = 0.152
@@ -92,6 +94,7 @@ def test_init(self, setup):
9294
assert setup["widget"].out_nu.text() == "nu = 0.16"
9395
assert setup["widget"].out_mur_lin.text() == "mur_lin = 0.12"
9496
assert setup["widget"].out_wlam.text() == "wlam = 0.13 [m]"
97+
assert setup["widget"].out_BH.text() == "Matrix (4, 2)"
9598

9699
# Check list
97100
assert setup["widget"].nav_mat.count() == 7

Tests/GUI/DMatLib/test_DMatSetup.py

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
import sys
44
from os import mkdir
5-
from os.path import join, isdir
5+
from os.path import join, isdir, isfile
6+
import mock
67
from shutil import rmtree, copyfile
78
from random import uniform
8-
9+
from numpy import array
910
from PySide2 import QtWidgets
1011
from PySide2.QtCore import Qt
1112
from PySide2.QtTest import QTest
1213

1314
from pyleecan.Classes.MatMagnetics import MatMagnetics
1415
from pyleecan.Classes.Material import Material
16+
from pyleecan.Classes.ImportMatrixVal import ImportMatrixVal
1517
from pyleecan.GUI.Dialog.DMatLib.DMatSetup.DMatSetup import DMatSetup
1618
from Tests import save_load_path as save_path, TEST_DATA_DIR
1719

@@ -46,6 +48,9 @@ def setup(self):
4648
test_obj.is_isotropic = True
4749
test_obj.elec.rho = 0.11
4850
test_obj.mag = MatMagnetics(mur_lin=0.12, Wlam=0.13)
51+
test_obj.mag.BH_curve = ImportMatrixVal(
52+
value=array([[0, 1], [2, 100], [3, 300], [4, 450]])
53+
)
4954
test_obj.struct.rho = 0.14
5055
test_obj.struct.Ex = 0.15
5156
test_obj.struct.Ey = 0.152
@@ -87,6 +92,9 @@ def test_init(self, setup):
8792
assert setup["widget"].lf_Cp.value() == 0.19
8893
assert setup["widget"].lf_alpha.value() == 0.2
8994
assert setup["widget"].lf_cost_unit.value() == 0.21
95+
assert setup["widget"].w_BH_import.w_import.in_matrix.text() == (
96+
"Matrix size: (4, 2)"
97+
)
9098

9199
# Test Raw Material
92100
setup["test_obj"].mag = None
@@ -429,3 +437,65 @@ def test_set_lambda_x_y_z(self, setup):
429437
setup["widget"].lf_Lz.editingFinished.emit()
430438

431439
assert setup["widget"].mat.HT.lambda_z == value
440+
441+
def test_BH_setup(self, setup):
442+
"""Check that the BH curve behave have expected"""
443+
w_imp = setup["widget"].w_BH_import.w_import
444+
assert setup["widget"].w_BH_import.c_type_import.currentIndex() == 1
445+
setup["widget"].w_BH_import.w_import.in_matrix.text()
446+
# Open table to check BH values
447+
assert w_imp.tab_window is None
448+
w_imp.b_tab.clicked.emit()
449+
w_imp.tab_window.si_row.value() == 4
450+
w_imp.tab_window.si_col.value() == 2
451+
w_imp.tab_window.w_tab.cellWidget(0, 0).value() == 0
452+
w_imp.tab_window.w_tab.cellWidget(0, 1).value() == 1
453+
w_imp.tab_window.w_tab.cellWidget(1, 0).value() == 2
454+
w_imp.tab_window.w_tab.cellWidget(1, 1).value() == 100
455+
w_imp.tab_window.w_tab.cellWidget(2, 0).value() == 3
456+
w_imp.tab_window.w_tab.cellWidget(2, 1).value() == 300
457+
w_imp.tab_window.w_tab.cellWidget(3, 0).value() == 4
458+
w_imp.tab_window.w_tab.cellWidget(3, 1).value() == 450
459+
# Edit table
460+
w_imp.tab_window.w_tab.cellWidget(3, 0).setValue(5)
461+
w_imp.tab_window.w_tab.cellWidget(3, 1).setValue(800)
462+
w_imp.tab_window.b_close.accepted.emit()
463+
w_imp.tab_window.close()
464+
setup["widget"].mat.mag.BH_curve.value[3, 0] == 5
465+
setup["widget"].mat.mag.BH_curve.value[3, 0] == 800
466+
# Export to excel
467+
excel_path = join(save_path, "DMatSetup_excel_export.xls").replace("\\", "/")
468+
assert not isfile(excel_path)
469+
with mock.patch(
470+
"PySide2.QtWidgets.QFileDialog.getSaveFileName",
471+
return_value=(excel_path, "Excel file (*.xls .*xlsx)"),
472+
):
473+
w_imp.b_convert.clicked.emit()
474+
assert isfile(excel_path)
475+
# Convert to excel import
476+
setup["widget"].w_BH_import.c_type_import.setCurrentIndex(0)
477+
assert (
478+
setup["widget"].w_BH_import.c_type_import.currentText()
479+
== "Import from Excel"
480+
)
481+
w_imp = setup["widget"].w_BH_import.w_import
482+
# Import the excel file
483+
with mock.patch(
484+
"PySide2.QtWidgets.QFileDialog.getOpenFileName",
485+
return_value=(excel_path, "Excel file (*.xls .*xlsx)"),
486+
):
487+
w_imp.w_file_path.b_path.clicked.emit()
488+
assert w_imp.w_file_path.le_path.text() == excel_path
489+
# Check table
490+
assert w_imp.tab_window is None
491+
w_imp.b_tab.clicked.emit()
492+
w_imp.tab_window.si_row.value() == 4
493+
w_imp.tab_window.si_col.value() == 2
494+
w_imp.tab_window.w_tab.cellWidget(0, 0).value() == 0
495+
w_imp.tab_window.w_tab.cellWidget(0, 1).value() == 1
496+
w_imp.tab_window.w_tab.cellWidget(1, 0).value() == 2
497+
w_imp.tab_window.w_tab.cellWidget(1, 1).value() == 100
498+
w_imp.tab_window.w_tab.cellWidget(2, 0).value() == 3
499+
w_imp.tab_window.w_tab.cellWidget(2, 1).value() == 300
500+
w_imp.tab_window.w_tab.cellWidget(3, 0).value() == 5
501+
w_imp.tab_window.w_tab.cellWidget(3, 1).value() == 800

0 commit comments

Comments
 (0)