Skip to content

Commit e7055cc

Browse files
authored
Merge pull request #355 from EOMYS-Public/HoleMag
[NF] getter for ParamExplorer and get_desc for preview
2 parents 365ba66 + 9b92c2f commit e7055cc

File tree

23 files changed

+283
-53
lines changed

23 files changed

+283
-53
lines changed

Tests/Classes/test_classes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,19 @@ def test_class_type_float(class_dict):
317317
prop_list = get_mother_attr(gen_dict, class_dict, "properties")[0]
318318
for prop in prop_list:
319319
value = find_test_value(prop, "float")
320+
msg = "Error for class " + class_dict["name"] + " with " + prop["name"]
320321
# Check the doc to know if it should raise an error or not
321322
if prop["type"] in ["float", "complex", "", None]:
322323
# No error expected
323324
test_obj.__setattr__(prop["name"], value)
324-
assert test_obj.__getattribute__(prop["name"]) == value
325+
326+
assert test_obj.__getattribute__(prop["name"]) == value, msg
325327
else:
326328
# CheckTypeError expected
327-
with pytest.raises(CheckTypeError):
329+
with pytest.raises(
330+
CheckTypeError,
331+
):
332+
# print(msg)
328333
test_obj.__setattr__(prop["name"], value)
329334

330335

Tests/GUI/DMachineSetup/test_SMachineDimension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_init(self, setup):
6868
assert setup["widget"].lf_Lfra.value() == 0.25
6969
assert setup["widget"].g_frame.isChecked() == True
7070
assert setup["widget"].g_shaft.isChecked() == True
71-
assert setup["widget"].out_Drsh.text() == "Drsh = 2*Rotor.Rint = 220.0 mm"
71+
assert setup["widget"].out_Drsh.text() == "Drsh = 2*Rotor.Rint = 0.22 [m]"
7272

7373
def test_init_no_shaft(self, setup):
7474
"""Check that the Widget spinbox initialise to the lamination value"""

Tests/Validation/Simulation/Magnetics/test_meshsolution_plots.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
from pyleecan.Functions.load import load
2-
from pyleecan.definitions import DATA_DIR
3-
4-
from pyleecan.Classes.Simu1 import Simu1
5-
from pyleecan.Classes.InputCurrent import InputCurrent
6-
from pyleecan.Classes.ImportGenVectLin import ImportGenVectLin
7-
from pyleecan.Classes.ImportMatrixVal import ImportMatrixVal
8-
from pyleecan.Classes.MagFEMM import MagFEMM
9-
from pyleecan.Classes.Output import Output
10-
11-
from Tests import save_plot_path
12-
from Tests import save_load_path
1+
import json
2+
from multiprocessing import cpu_count
133
from os.path import join
14-
from numpy import zeros, ones, pi, array
154

165
import matplotlib.pyplot as plt
17-
import json
186
import numpy as np
197
import pytest
8+
from numpy import array, ones, pi, zeros
9+
from pyleecan.Classes.ImportGenVectLin import ImportGenVectLin
10+
from pyleecan.Classes.ImportMatrixVal import ImportMatrixVal
11+
from pyleecan.Classes.InputCurrent import InputCurrent
12+
from pyleecan.Classes.MagFEMM import MagFEMM
13+
from pyleecan.Classes.Output import Output
14+
from pyleecan.Classes.Simu1 import Simu1
15+
from pyleecan.definitions import DATA_DIR
16+
from pyleecan.Functions.load import load
17+
from Tests import save_load_path, save_plot_path
2018

2119

2220
@pytest.mark.long
@@ -81,37 +79,41 @@ def test_SIPMSM_003():
8179
simu_sym.run()
8280

8381
out.mag.meshsolution.plot_mesh(
84-
save_path=join(save_path, simu.name + "_mesh.png"), is_show_fig=False
82+
save_path=join(save_plot_path, simu.name + "_mesh.png"), is_show_fig=False
8583
)
8684

8785
out.mag.meshsolution.plot_mesh(
8886
group_names="stator core",
89-
save_path=join(save_path, simu.name + "_mesh_stator.png"),
87+
save_path=join(save_plot_path, simu.name + "_mesh_stator.png"),
9088
is_show_fig=False,
9189
)
9290

9391
out.mag.meshsolution.plot_mesh(
9492
group_names=["stator core", "/", "airgap", "stator winding"],
95-
save_path=join(save_path, simu.name + "_mesh_stator_interface.png"),
93+
save_path=join(save_plot_path, simu.name + "_mesh_stator_interface.png"),
9694
is_show_fig=False,
9795
)
9896

9997
out.mag.meshsolution.plot_contour(
10098
label="\mu",
101-
save_path=join(save_path, simu.name + "_mu.png"),
99+
save_path=join(save_plot_path, simu.name + "_mu.png"),
102100
is_show_fig=False,
103101
)
104102
out.mag.meshsolution.plot_contour(
105-
label="B", save_path=join(save_path, simu.name + "_B.png"), is_show_fig=False
103+
label="B",
104+
save_path=join(save_plot_path, simu.name + "_B.png"),
105+
is_show_fig=False,
106106
)
107107
out.mag.meshsolution.plot_contour(
108-
label="H", save_path=join(save_path, simu.name + "_H.png"), is_show_fig=False
108+
label="H",
109+
save_path=join(save_plot_path, simu.name + "_H.png"),
110+
is_show_fig=False,
109111
)
110112

111113
out.mag.meshsolution.plot_contour(
112114
label="H",
113115
group_names="stator core",
114-
save_path=join(save_path, simu.name + "_H_stator.png"),
116+
save_path=join(save_plot_path, simu.name + "_H_stator.png"),
115117
is_show_fig=False,
116118
)
117119

Tests/Validation/Simulation/Multisimulation/test_multi_multi.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,16 @@ def test_multi_multi():
196196
symbol="W0s",
197197
unit="m",
198198
setter="simu.machine.stator.slot.W0",
199+
getter="simu.machine.stator.slot.W0",
199200
min_value=0.1 * IPMSM_A.stator.slot.W0,
200201
max_value=IPMSM_A.stator.slot.W0,
201202
N=N1,
202203
)
203204
]
204-
205+
assert (
206+
paramexplorer_list[0].get_desc(simu)
207+
== "W0s: " + str(N1) + " values from 0.000193 to 0.00193 (ref=0.00193) [m]"
208+
)
205209
multisim.paramexplorer_list = paramexplorer_list
206210
multisim.is_keep_all_output = True
207211

pyleecan/Classes/Class_Dict.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,8 @@
787787
"desc": "Class for defining data to keep on a multi-simulation",
788788
"is_internal": false,
789789
"methods": [
790-
"as_dict"
790+
"as_dict",
791+
"_set_result"
791792
],
792793
"mother": "",
793794
"name": "DataKeeper",
@@ -7735,7 +7736,9 @@
77357736
"desc": "Abstract class for the multi-simulation",
77367737
"is_internal": false,
77377738
"methods": [
7738-
"_set_setter"
7739+
"_set_setter",
7740+
"_set_getter",
7741+
"get_desc"
77397742
],
77407743
"mother": "",
77417744
"name": "ParamExplorer",
@@ -7777,6 +7780,15 @@
77777780
"type": "function",
77787781
"unit": "-",
77797782
"value": null
7783+
},
7784+
{
7785+
"desc": "Function to return the reference value (simulation as argument)",
7786+
"max": "",
7787+
"min": "",
7788+
"name": "getter",
7789+
"type": "function",
7790+
"unit": "-",
7791+
"value": null
77807792
}
77817793
]
77827794
},
@@ -7830,7 +7842,7 @@
78307842
},
78317843
{
78327844
"desc": "How to generate the value list. 0: linspace, 1: random (Not available yet)",
7833-
"max": "0",
7845+
"max": "1",
78347846
"min": "0",
78357847
"name": "type_value_gen",
78367848
"type": "int",

pyleecan/Classes/DataKeeper.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
except ImportError as error:
2323
as_dict = error
2424

25+
try:
26+
from ..Methods.Simulation.DataKeeper._set_result import _set_result
27+
except ImportError as error:
28+
_set_result = error
29+
2530

2631
from ntpath import basename
2732
from os.path import isfile
@@ -36,6 +41,7 @@ class DataKeeper(FrozenClass):
3641

3742
VERSION = 1
3843

44+
# Check ImportError to remove unnecessary dependencies in unused method
3945
# cf Methods.Simulation.DataKeeper.as_dict
4046
if isinstance(as_dict, ImportError):
4147
as_dict = property(
@@ -45,6 +51,17 @@ class DataKeeper(FrozenClass):
4551
)
4652
else:
4753
as_dict = as_dict
54+
# cf Methods.Simulation.DataKeeper._set_result
55+
if isinstance(_set_result, ImportError):
56+
_set_result = property(
57+
fget=lambda x: raise_(
58+
ImportError(
59+
"Can't use DataKeeper method _set_result: " + str(_set_result)
60+
)
61+
)
62+
)
63+
else:
64+
_set_result = _set_result
4865
# save and copy methods are available in all object
4966
save = save
5067
copy = copy
@@ -355,13 +372,6 @@ def _get_result(self):
355372
"""getter of result"""
356373
return self._result
357374

358-
def _set_result(self, value):
359-
"""setter of result"""
360-
if type(value) is int and value == -1:
361-
value = list()
362-
check_var("result", value, "list")
363-
self._result = value
364-
365375
result = property(
366376
fget=_get_result,
367377
fset=_set_result,

pyleecan/Classes/OptiDesignVar.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(
4343
symbol="",
4444
unit="",
4545
setter=None,
46+
getter=None,
4647
init_dict=None,
4748
init_str=None,
4849
):
@@ -75,13 +76,15 @@ def __init__(
7576
unit = init_dict["unit"]
7677
if "setter" in list(init_dict.keys()):
7778
setter = init_dict["setter"]
79+
if "getter" in list(init_dict.keys()):
80+
getter = init_dict["getter"]
7881
# Set the properties (value check and convertion are done in setter)
7982
self.type_var = type_var
8083
self.space = space
8184
self.get_value = get_value
8285
# Call ParamExplorer init
8386
super(OptiDesignVar, self).__init__(
84-
name=name, symbol=symbol, unit=unit, setter=setter
87+
name=name, symbol=symbol, unit=unit, setter=setter, getter=getter
8588
)
8689
# The class is frozen (in ParamExplorer init), for now it's impossible to
8790
# add new properties

0 commit comments

Comments
 (0)