Skip to content

Commit

Permalink
Merge pull request #493 from EOMYS-Public/MatLib
Browse files Browse the repository at this point in the history
Miscellaneous Bug correction
  • Loading branch information
BonneelP authored Jan 26, 2022
2 parents a8e134d + 2f85c10 commit 1b404aa
Show file tree
Hide file tree
Showing 36 changed files with 2,201 additions and 36 deletions.
37 changes: 31 additions & 6 deletions Tests/Functions/test_save_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
from pyleecan.Classes.Simu1 import Simu1
from pyleecan.Classes.SlotM11 import SlotM11
from pyleecan.Classes.SlotW10 import SlotW10
from pyleecan.Classes.SlotUD import SlotUD
from pyleecan.Classes.HoleUD import HoleUD
from pyleecan.Classes.Winding import Winding
from pyleecan.Classes.OPdq import OPdq
from pyleecan.Functions.load import (
LoadSwitchError,
LoadWrongDictClassError,
LoadWrongTypeError,
load,
Expand Down Expand Up @@ -247,6 +248,31 @@ def test_save_load_just_name():
# remove(file_path)


def test_save_load_DXF_flat():
"""Check that you can save/load a machine with dxf slot/hole in flat mode"""
Prius_DXF = load(join(DATA_DIR, "Machine", "Toyota_Prius_DXF.json"))
save_dir = join(save_path, "Toyota_Prius_DXF")
# Check save
assert not isdir(save_dir)
Prius_DXF.save(save_path=save_dir, is_folder=True)
assert isdir(save_dir)
file_list = listdir(save_dir)
assert len(file_list) == 12
assert "hole.json" in file_list
assert "slot.json" in file_list
# Check load
Prius_2 = load(save_dir)
assert isinstance(Prius_2.stator.slot, SlotUD)
assert isinstance(Prius_2.rotor.hole[0], HoleUD)
assert len(Prius_DXF.compare(Prius_2)) == 0
# Remove file and check None
remove(join(save_dir, "hole.json"))
remove(join(save_dir, "slot.json"))
Prius_3 = load(save_dir)
assert Prius_3.stator.slot is None
assert Prius_3.rotor.hole[0] is None


def test_load_error_missing():
"""Test that the load function can detect missing file"""
with pytest.raises(LoadMissingFileError):
Expand Down Expand Up @@ -406,9 +432,8 @@ def test_save_load_simu(type_file):


if __name__ == "__main__":
test_save_load_simu("json")
test_save_load_simu("h5")
test_save_load_simu("pkl")
# test_save_load_folder_path()
# test_save_load_json_compressed()
test_save_load_DXF_flat()
print("Done")
# test_save_load_simu("json")
# test_save_load_simu("h5")
# test_save_load_simu("pkl")
9 changes: 9 additions & 0 deletions pyleecan/Classes/BoreUD.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ def _set_line_list(self, value):
"""setter of line_list"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "line_list"
Expand Down
18 changes: 18 additions & 0 deletions pyleecan/Classes/HoleUD.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ def _set_surf_list(self, value):
"""setter of surf_list"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "surf_list"
Expand Down Expand Up @@ -378,6 +387,15 @@ def _set_magnet_dict(self, value):
"""setter of magnet_dict"""
if type(value) is dict:
for key, obj in value.items():
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[key] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "magnet_dict"
Expand Down
9 changes: 9 additions & 0 deletions pyleecan/Classes/ImportData.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ def _set_axes(self, value):
"""setter of axes"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "axes"
Expand Down
9 changes: 9 additions & 0 deletions pyleecan/Classes/ImportGenMatrixSin.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ def _set_sin_list(self, value):
"""setter of sin_list"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "sin_list"
Expand Down
9 changes: 9 additions & 0 deletions pyleecan/Classes/ImportVectorField.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ def _set_components(self, value):
"""setter of components"""
if type(value) is dict:
for key, obj in value.items():
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[key] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "components"
Expand Down
11 changes: 11 additions & 0 deletions pyleecan/Classes/LUTdq.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,15 @@ def _set_Phi_wind(self, value):
"""setter of Phi_wind"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"SciDataTool.Classes", obj.get("__class__"), "Phi_wind"
Expand Down Expand Up @@ -499,6 +508,8 @@ def _get_Phi_dqh_interp(self):

def _set_Phi_dqh_interp(self, value):
"""setter of Phi_dqh_interp"""
if value == -1:
value = RegularGridInterpolator()
check_var("Phi_dqh_interp", value, "RegularGridInterpolator")
self._Phi_dqh_interp = value

Expand Down
9 changes: 9 additions & 0 deletions pyleecan/Classes/LamHole.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,15 @@ def _set_hole(self, value):
"""setter of hole"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "hole"
Expand Down
9 changes: 9 additions & 0 deletions pyleecan/Classes/LamSlotMulti.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,15 @@ def _set_slot_list(self, value):
"""setter of slot_list"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "slot_list"
Expand Down
9 changes: 9 additions & 0 deletions pyleecan/Classes/LamSquirrelCageMag.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,15 @@ def _set_hole(self, value):
"""setter of hole"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "hole"
Expand Down
27 changes: 27 additions & 0 deletions pyleecan/Classes/Lamination.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,15 @@ def _set_axial_vent(self, value):
"""setter of axial_vent"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "axial_vent"
Expand Down Expand Up @@ -1126,6 +1135,15 @@ def _set_notch(self, value):
"""setter of notch"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "notch"
Expand Down Expand Up @@ -1193,6 +1211,15 @@ def _set_yoke_notch(self, value):
"""setter of yoke_notch"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "yoke_notch"
Expand Down
9 changes: 9 additions & 0 deletions pyleecan/Classes/Loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ def _set_model_list(self, value):
"""setter of model_list"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "model_list"
Expand Down
9 changes: 9 additions & 0 deletions pyleecan/Classes/MachineUD.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ def _set_lam_list(self, value):
"""setter of lam_list"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "lam_list"
Expand Down
9 changes: 9 additions & 0 deletions pyleecan/Classes/MeshMat.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,15 @@ def _set_cell(self, value):
"""setter of cell"""
if type(value) is dict:
for key, obj in value.items():
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[key] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "cell"
Expand Down
18 changes: 18 additions & 0 deletions pyleecan/Classes/MeshSolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,15 @@ def _set_mesh(self, value):
"""setter of mesh"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "mesh"
Expand Down Expand Up @@ -546,6 +555,15 @@ def _set_solution(self, value):
"""setter of solution"""
if type(value) is list:
for ii, obj in enumerate(value):
if isinstance(obj, str): # Load from file
try:
obj = load_init_dict(obj)[1]
except Exception as e:
self.get_logger().error(
"Error while loading " + obj + ", setting None instead"
)
obj = None
value[ii] = None
if type(obj) is dict:
class_obj = import_class(
"pyleecan.Classes", obj.get("__class__"), "solution"
Expand Down
4 changes: 4 additions & 0 deletions pyleecan/Classes/MeshVTK.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ def _get_mesh(self):

def _set_mesh(self, value):
"""setter of mesh"""
if value == -1:
value = vtkPointSet()
check_var("mesh", value, "vtkPointSet")
self._mesh = value

Expand Down Expand Up @@ -491,6 +493,8 @@ def _get_surf(self):

def _set_surf(self, value):
"""setter of surf"""
if value == -1:
value = PolyData()
check_var("surf", value, "PolyData")
self._surf = value

Expand Down
2 changes: 2 additions & 0 deletions pyleecan/Classes/OptiGenAlgNsga2Deap.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ def _get_toolbox(self):

def _set_toolbox(self, value):
"""setter of toolbox"""
if value == -1:
value = Toolbox()
check_var("toolbox", value, "Toolbox")
self._toolbox = value

Expand Down
Loading

0 comments on commit 1b404aa

Please sign in to comment.