Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NF] Symetry for Bore notches in FEMM #460

Merged
merged 15 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Tests/Classes/test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ def test_class_type_float(class_dict):
assert test_obj.__getattribute__(prop["name"]) == value, msg
else:
# CheckTypeError expected
with pytest.raises(CheckTypeError,):
with pytest.raises(
CheckTypeError,
):
# print(msg)
test_obj.__setattr__(prop["name"], value)

Expand Down
38 changes: 32 additions & 6 deletions Tests/Methods/Geometry/test_Arc1_meth.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@
"is_begin": False,
"N_begin": -1j,
"N_end": -1,
"N_radius": 1,
"N_radius": -1,
}
)
split_half_test.append(
Expand Down Expand Up @@ -582,6 +582,19 @@
"N_radius": 2,
}
)
split_half_test.append(
{
"begin": 1 * exp(1j * 5 * pi / 4),
"end": 1 * exp(-1j * pi / 4),
"radius": 1,
"center": 0,
"is_trigo": False,
"is_begin": False,
"N_begin": 1j,
"N_end": 1 * exp(-1j * pi / 4),
"N_radius": -1,
}
)


class Test_Arc1_meth(object):
Expand Down Expand Up @@ -799,11 +812,16 @@ def test_split_half(self, test_dict):
)
assert round(abs(abs(Zc - test_dict["center"]) - 0), 7) == 0, msg
# Check split
arc.split_half(is_begin=test_dict["is_begin"])
assert round(abs(arc.begin - test_dict["N_begin"]), 7) == 0
assert round(abs(arc.end - test_dict["N_end"]), 7) == 0
assert round(abs(arc.radius - test_dict["N_radius"]), 7) == 0
assert round(abs(arc.is_trigo_direction - test_dict["is_trigo"]), 7) == 0
arc_split = arc.copy()
arc_split.split_half(is_begin=test_dict["is_begin"])
assert round(abs(arc_split.begin - test_dict["N_begin"]), 7) == 0
assert round(abs(arc_split.end - test_dict["N_end"]), 7) == 0
assert round(abs(arc_split.radius - test_dict["N_radius"]), 7) == 0
assert round(abs(arc_split.is_trigo_direction - test_dict["is_trigo"]), 7) == 0
# Check center
assert round(abs(arc_split.get_center() - arc.get_center()), 7) == 0
# Check length
assert arc_split.comp_length() == pytest.approx(arc.comp_length() / 2)

def test_plot_schematics(self):
"""Check that the schematics is correct"""
Expand Down Expand Up @@ -865,3 +883,11 @@ def test_translate_error(self):
)
with pytest.raises(PointTranslateArc1Error) as context:
arc.translate("error")


if __name__ == "__main__":
a = Test_Arc1_meth()
for ii, test_dict in enumerate(split_half_test):
print(ii)
a.test_split_half(test_dict)
print("Done")
2 changes: 2 additions & 0 deletions Tests/Methods/Geometry/test_Arc2_meth.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@
comp_length_test = list()
comp_length_test.append({"begin": 1, "center": 0, "angle": pi / 2, "length": pi / 2})
comp_length_test.append({"begin": 2, "center": 0, "angle": pi / 4, "length": pi / 2})
comp_length_test.append({"begin": 1, "center": 0, "angle": -pi / 2, "length": pi / 2})
comp_length_test.append({"begin": 2, "center": 0, "angle": -pi / 4, "length": pi / 2})
# Dictionary to test get_middle
comp_mid_test = list()
comp_mid_test.append(
Expand Down
11 changes: 7 additions & 4 deletions Tests/Methods/Geometry/test_is_inside.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
inside_test.append({"surf": C1, "Z": 0, "result": True}) # inside
inside_test.append({"surf": C1, "Z": 20, "result": False}) # outside
inside_test.append({"surf": C1, "Z": 1, "result": False}) # online not OK
inside_test.append({"surf": C1, "Z": 1, "if_online":True,"result": True}) # online OK
inside_test.append({"surf": C1, "Z": 1, "if_online": True, "result": True}) # online OK

# Test 2 : checking if a point is inside a "C-shape" surface
A0 = 0
Expand All @@ -40,7 +40,9 @@
inside_test.append({"surf": C2, "Z": 0.5 + 2j, "result": True}) # inside
inside_test.append({"surf": C2, "Z": 2 + 2j, "result": False}) # outside
inside_test.append({"surf": C2, "Z": 2.03, "result": False}) # online not OK
inside_test.append({"surf": C2, "Z": 2.03, "if_online":True,"result": True}) # online OK
inside_test.append(
{"surf": C2, "Z": 2.03, "if_online": True, "result": True}
) # online OK


@pytest.mark.parametrize("test_dict", inside_test)
Expand All @@ -52,10 +54,11 @@ def test_is_inside(test_dict):

if "if_online" in test_dict:
if_online = test_dict["if_online"]
assert result == surf.is_inside(Z,if_online)
assert result == surf.is_inside(Z, if_online)
else:
assert result == surf.is_inside(Z)


if __name__ == "__main__":
for test_dict in inside_test:
test_is_inside(test_dict)
test_is_inside(test_dict)
153 changes: 125 additions & 28 deletions Tests/Methods/Machine/test_comp_periodicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,149 @@

from pyleecan.Functions.load import load
from pyleecan.definitions import DATA_DIR
from pyleecan.Classes.VentilationCirc import VentilationCirc

machine_list = [
["Toyota_Prius", (4, True, 4, True)],
["BMW_i3", (6, True, 6, True)],
["Protean_InWheel", (8, False, 32, True)],
["Tesla_S", (2, False, 2, False)],
["Audi_eTron", (2, False, 2, False)],
["Benchmark", (1, True, 5, True)],
["SCIM_001", (1, True, 1, True)],
["SCIM_006", (2, True, 2, True)],
["SPMSM_001", (4, False, 4, True)],
["SPMSM_003", (1, True, 1, True)],
["SPMSM_015", (9, False, 9, True)],
["SIPMSM_001", (1, False, 2, True)],
["SynRM_001", (2, True, 2, True)],
["LSRPM_001", (4, False, 4, True)],
test_per_list = [
{"machine": "Toyota_Prius", "exp": (4, True, 4, True)},
{"machine": "BMW_i3", "exp": (6, True, 6, True)},
{"machine": "Protean_InWheel", "exp": (8, False, 32, True)},
{"machine": "Tesla_S", "exp": (2, False, 2, False)},
{"machine": "Audi_eTron", "exp": (2, False, 2, False)},
{"machine": "Benchmark", "exp": (1, True, 5, True)},
{"machine": "SCIM_001", "exp": (1, True, 1, True)},
{"machine": "SCIM_006", "exp": (2, True, 2, True)},
{"machine": "SPMSM_001", "exp": (4, False, 4, True)},
{"machine": "SPMSM_003", "exp": (1, True, 1, True)},
{"machine": "SPMSM_015", "exp": (9, False, 9, True)},
{"machine": "SIPMSM_001", "exp": (1, False, 2, True)},
{"machine": "SynRM_001", "exp": (2, True, 2, True)},
{"machine": "LSRPM_001", "exp": (4, False, 4, True)},
]

# Machine with ventilation
TP = load(join(DATA_DIR, "Machine", "Toyota_Prius.json"))
# Only Zh matters for periodicity comp
v2 = VentilationCirc(Zh=2)
v4 = VentilationCirc(Zh=4)
v8 = VentilationCirc(Zh=8)
v9 = VentilationCirc(Zh=9)
v16 = VentilationCirc(Zh=16)

# Rotor vent matches sym
TP0 = TP.copy()
TP0.name = TP0.name + "_0"
TP0.rotor.axial_vent = [v8]
test_per_list.append({"machine": TP0, "exp": (4, True, 4, True)})

# Two Rotor vents that match sym
TP1 = TP.copy()
TP1.name = TP1.name + "_1"
TP1.rotor.axial_vent = [v16, v8]
test_per_list.append({"machine": TP1, "exp": (4, True, 4, True)})

# Rotor vents that with 1/2 sym
TP2 = TP.copy()
TP2.name = TP2.name + "_2"
TP2.rotor.axial_vent = [v8, v4]
test_per_list.append({"machine": TP2, "exp": (4, False, 4, False)})

# Rotor vent that removes sym
TP3 = TP.copy()
TP3.name = TP3.name + "_3"
TP3.rotor.axial_vent = [v9]
test_per_list.append({"machine": TP3, "exp": (1, False, 1, False)})

# Stator vent matches sym
TP4 = TP.copy()
TP4.name = TP4.name + "_4"
TP4.stator.axial_vent = [v8]
test_per_list.append({"machine": TP4, "exp": (4, True, 4, True)})

# Two Stator vents that match sym
TP5 = TP.copy()
TP5.name = TP5.name + "_5"
TP5.stator.axial_vent = [v16, v8]
test_per_list.append({"machine": TP5, "exp": (4, True, 4, True)})

# Stator vents that with 1/2 sym
TP6 = TP.copy()
TP6.name = TP6.name + "_6"
TP6.stator.axial_vent = [v8, v4]
test_per_list.append({"machine": TP6, "exp": (4, False, 4, True)})

# Stator vent that removes sym
TP7 = TP.copy()
TP7.name = TP7.name + "_7"
TP7.stator.axial_vent = [v9]
test_per_list.append({"machine": TP7, "exp": (1, False, 4, True)})

# No sym, remove antiper
SC = load(join(DATA_DIR, "Machine", "SCIM_001.json"))
SC0 = SC.copy()
SC0.name = SC0.name + "_0"
SC0.rotor.axial_vent = [v9]
test_per_list.append({"machine": SC0, "exp": (1, False, 1, True)})

# Rotor is 4, True => 1, True
SP = load(join(DATA_DIR, "Machine", "SPMSM_001.json"))
SP0 = SP.copy()
SP0.name = SP0.name + "_0"
SP0.rotor.axial_vent = [v2]
test_per_list.append({"machine": SP0, "exp": (2, False, 1, True)})

# no antiper, remove sym
SP1 = SP.copy()
SP1.name = SP1.name + "_1"
SP1.rotor.axial_vent = [v9]
test_per_list.append({"machine": SP1, "exp": (1, False, 1, True)})


@pytest.mark.periodicity
@pytest.mark.parametrize("machine", machine_list)
def test_comp_periodicity(machine):
@pytest.mark.parametrize("test_dict", test_per_list)
def test_comp_periodicity(test_dict):

machine_obj = load(join(DATA_DIR, "Machine", machine[0] + ".json"))
if isinstance(test_dict["machine"], str):
machine_obj = load(join(DATA_DIR, "Machine", test_dict["machine"] + ".json"))
else:
machine_obj = test_dict["machine"]

# per_a, aper_a = machine_obj.comp_periodicity_spatial()

# per_t, aper_t, _, _ = machine_obj.comp_periodicity_time()

per_a, aper_a, per_t, aper_t = machine_obj.comp_periodicity()

msg = (
"Wrong periodicity calculation for "
# Check angular
msg_a = (
"Wrong Angular periodicity calculation for "
+ machine_obj.name
+ ": "
+ str((per_a, aper_a, per_t, aper_t))
+ ": Returned "
+ str((per_a, aper_a))
+ " Expected "
+ str((test_dict["exp"][0], test_dict["exp"][1]))
)
assert (per_a, aper_a, per_t, aper_t) == machine[1], msg
assert (per_a, aper_a) == (test_dict["exp"][0], test_dict["exp"][1]), msg_a
# Check time
msg_t = (
"Wrong Time periodicity calculation for "
+ machine_obj.name
+ ": Returned "
+ str((per_t, aper_t))
+ " Expected "
+ str((test_dict["exp"][2], test_dict["exp"][3]))
)
assert (per_t, aper_t) == (test_dict["exp"][2], test_dict["exp"][3]), msg_t

return (per_a, aper_a, per_t, aper_t)


# To run it without pytest
if __name__ == "__main__":

per_tuple = test_comp_periodicity(machine_list[-1])

for machine in machine_list:
per_tuple = test_comp_periodicity(machine)
for ii, test_dict in enumerate(test_per_list):
if isinstance(test_dict["machine"], str):
machine_name = test_dict["machine"]
else:
machine_name = test_dict["machine"].name
print(str(ii) + " :" + machine_name)
per_tuple = test_comp_periodicity(test_dict)
print("Done")
14 changes: 14 additions & 0 deletions Tests/Methods/Slot/test_SlotW22_meth.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,17 @@ def test_get_surface_active(self):
result = lam.slot.get_surface_active()
assert result.label == "Wind_Rotor_R0_T0_S0"
assert len(result.get_lines()) == 6


if __name__ == "__main__":
a = Test_SlotW22_meth()
a.test_get_surface_active()

for test_dict in slotW22_test:
a.test_schematics(test_dict)
a.test_build_geometry_active(test_dict)
a.test_comp_angle_active_eq(test_dict)
a.test_comp_angle_opening(test_dict)
a.test_comp_height(test_dict)
a.test_comp_surface(test_dict)
a.test_comp_surface_active(test_dict)
3 changes: 2 additions & 1 deletion Tests/Plot/test_ICEM_2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,4 +842,5 @@ def test_Optimization_problem():


if __name__ == "__main__":
test_WindingUD_layer()
test_FEMM_sym()
# test_WindingUD_layer()
2 changes: 1 addition & 1 deletion Tests/Validation/Electrical/test_EEC_SCIM.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_EEC_SCIM():
"""Validation of the SCIM Electrical Equivalent Circuit with the 3kW SCIM
from 'Berechnung elektrischer Maschinen' (ISBN: 978-3-527-40525-1)
Note: conductor properties have been set to operation point temperature condition,
stator end winding length is adapted to ref. lenght
stator end winding length is adapted to ref. lenght
"""
SCIM = load(join(DATA_DIR, "Machine", "SCIM_010.json"))

Expand Down
Loading