pyleecan
pyleecan copied to clipboard
How can I create a Slot object to test some methods ?
I would like to know how can I create a slot object to test some methods like _comp_point_coordinate ,build_geometry and
plot_schematics
This is the code for the test ( calling two methods )
from numpy import angle, arcsin, arctan, cos, exp, pi, sin, sqrt
from pyleecan.Methods.Slot.SlotW15 import S15InnerError
from pyleecan.Classes.SlotW15 import SlotW15
from pyleecan.Classes.Slot import Slot
import matplotlib.pyplot as plt
from pyleecan.Classes.Arc1 import Arc1
from pyleecan.Classes.Segment import Segment
import _frozen
def _comp_point_coordinate(self):
"""Compute the point coordinates needed to plot the Slot.
Parameters
----------
self : SlotW15
A SlotW15 object
Returns
-------
point_dict: dict
A dict of the slot point coordinates
"""
Rbo = self.get_Rbo()
# alpha is the angle to rotate Z0 so ||Z1,Z13|| = W0
alpha = arcsin(self.W0 / (2 * Rbo))
hsp = pi / self.Zs # Half slot pitch
Z0 = Rbo * exp(1j * 0)
Z13 = Z0 * exp(1j * alpha)
if self.is_outwards():
Z12 = Z0 + self.H0 + 1j * Z13.imag
Z7 = Z0 + self.H0 + self.H1 + self.H2
# Zc3, Z8 and (0,0) are align (tangent) => abs(Zc3)=Rbo+H0+H1+H2-R2
# In tooth ref: Im(Zc3') = -W3/2 - R2
A = Rbo + self.H0 + self.H1 + self.H2 - self.R2
B = -self.W3 / 2 - self.R2
xc2 = B * sin(-hsp) + sqrt(-(B ** 2) + A ** 2) * cos(-hsp)
yc2 = B * cos(-hsp) - sqrt(-(B ** 2) + A ** 2) * sin(-hsp)
Zc3 = xc2 + 1j * yc2
Z9 = (Zc3 * exp(1j * -hsp) + self.R2 * 1j) * exp(1j * hsp)
# Zc3, Z8 and (0,0) are align, |Zc3, Z8| = R2
Z8 = (Zc3 * exp(1j * -angle(Zc3)) + self.R2) * exp(1j * angle(Zc3))
# Real(Zc4) = Rbo+H0+H1
# In tooth ref: Im(Zc4') = -W3/2 - R1
xc1 = Rbo + self.H0 + self.H1
yc1 = (-self.W3 / 2 - self.R1 - xc1 * sin(-hsp)) / cos(-hsp)
Zc4 = xc1 + 1j * yc1
Z10 = (Zc4 * exp(1j * -hsp) + self.R1 * 1j) * exp(1j * hsp)
# Ref center at Zc4, (Z11,Z12) and (Z11,Zc4) are orthogonal
# Z11 = R1*exp(1i*theta)
# (R1*cos(theta)-x2)*R1*cos(theta)+(R1*sin(theta)-y2)*R1*sin(theta) = 0
R1 = self.R1
y2 = (Z12 - Zc4).imag
x2 = (Z12 - Zc4).real
theta = 2 * arctan((y2 - sqrt(-(R1 ** 2) + x2 ** 2 + y2 ** 2)) / (R1 + x2))
Z11 = R1 * exp(1j * theta) + Zc4
else:
raise S15InnerError("Slot Type 15 can't be used on inner lamination")
point_dict = dict()
# symetry
point_dict["Z13"] = Z13
point_dict["Z12"] = Z12
point_dict["Z11"] = Z11
point_dict["Z10"] = Z10
point_dict["Z9"] = Z9
point_dict["Z8"] = Z8
point_dict["Z7"] = Z7
point_dict["Z6"] = Z8.conjugate()
point_dict["Z5"] = Z9.conjugate()
point_dict["Z4"] = Z10.conjugate()
point_dict["Z3"] = Z11.conjugate()
point_dict["Z2"] = Z12.conjugate()
point_dict["Z1"] = Z13.conjugate()
point_dict["Zc4"] = Zc4
point_dict["Zc3"] = Zc3
point_dict["Zc2"] = Zc3.conjugate()
point_dict["Zc1"] = Zc4.conjugate()
return point_dict
def build_geometry(self):
"""Compute the curve (Line) needed to plot the Slot.
The ending point of a curve is the starting point of the next curve in
the list
Parameters
----------
self : SlotW15
A SlotW15 object
Returns
-------
curve_list: list
A list of 6 Segment and 5 Arc
"""
point_dict = self._comp_point_coordinate()
Z1 = point_dict["Z1"]
Z2 = point_dict["Z2"]
Z3 = point_dict["Z3"]
Z4 = point_dict["Z4"]
Z5 = point_dict["Z5"]
Z6 = point_dict["Z6"]
Z7 = point_dict["Z7"]
Z8 = point_dict["Z8"]
Z9 = point_dict["Z9"]
Z10 = point_dict["Z10"]
Z11 = point_dict["Z11"]
Z12 = point_dict["Z12"]
Z13 = point_dict["Z13"]
# Creation of curve
curve_list = list()
curve_list.append(Segment(Z1, Z2))
curve_list.append(Segment(Z2, Z3))
curve_list.append(Arc1(Z3, Z4, self.R1))
curve_list.append(Segment(Z4, Z5))
curve_list.append(Arc1(Z5, Z6, self.R2))
curve_list.append(Arc1(Z6, Z8, abs(Z7)))
curve_list.append(Arc1(Z8, Z9, self.R2))
curve_list.append(Segment(Z9, Z10))
curve_list.append(Arc1(Z10, Z11, self.R1))
curve_list.append(Segment(Z11, Z12))
curve_list.append(Segment(Z12, Z13))
return curve_list
frozen = _frozen.FrozenClass()
slot = Slot()
slot15 = SlotW15()
dict = _comp_point_coordinate(slot15) # not working
print(dict)
I got this error :
pyleecan.Methods.ParentMissingError: Error: The slot is not inside a Lamination
Hello abdou31,
Welcome to pyleecan :)
You can find here the tutorial to add a new slot shape in pyleecan: https://www.pyleecan.org/tuto.add.slot.html. Briefly, the new slot class should be implemented using the class generator and then its methods should be placed in the Methods folder.
Another possibility is to use dxf import to create your new slot topology.
Best regards, Emile
Hello,
To complete Emile's answer, we also have a dedicated webinar on how to add a Slot: https://pyleecan.org/webinar_3.html
Regarding your error message, in _comp_point_coordinate you call "Rbo = self.get_Rbo()" which try to access lamination.Rint (or Rext depending if the slot is inwards or outwards). In your test you haven't defined any lamination so pyleecan can't find Rbo and the method can't work. You can try something like:
from pyleecan.Classes.LamSlotWind import LamSlotWind
lam = LamSlotWind(Rint=0.1,Rext=0.2,is_stator=True, is_internal=False)
slot = SlotW15(Zs=12, H0=....)
lam.slot = slot
You can also take inspiration from our test on the slot methods that are gathered here : https://github.com/Eomys/pyleecan/tree/master/Tests/Methods/Slot
Best regards, Pierre
Hello,
Do you need further help on the topic or can we close this issue ?
Best regards, Pierre