in pyt_rfq_designer.create_vanes
the actual vane construction method reach the limit of the python recursion limit very fast
to fix it I propose the function
with this it will keeps the union tree to depth log2(N) instead of N. With this, it will be possible to achieve higher resolutions in the vanes
def union_balanced(self, objs):
objs = [o for o in objs if o is not None]
if not objs:
return None
if len(objs) == 1:
return objs[0]
mid = len(objs) // 2
return self.union_balanced(objs[:mid]) + self.union_balanced(objs[mid:])
and later in the function create_vanes
vane1_parts = []
for i in range(len(vane1_pts) - 1):
zc = 0.5 * (vane1_pts[i, 0] + vane1_pts[i + 1, 0])
yc = 0.5 * (vane1_pts[i, 1] + vane1_pts[i + 1, 1]) + radius
zl = vane1_pts[i + 1, 0] - vane1_pts[i, 0]
if zl <= 0:
continue
box_h = box_top - yc
vane1_parts.append(ZCylinder(radius, length=zl, voltage=voltage, zcent=zc, ycent=yc))
vane1_parts.append(Box(xsize=2 * radius, ysize=box_h, zsize=zl, voltage=voltage,
zcent=zc, ycent=yc + 0.5 * box_h))
vane1_cond = self.union_balanced(vane1_parts)
# ---------------- VANE 2 ----------------
vane2_parts = []
for i in range(len(vane2_pts) - 1):
zc = 0.5 * (vane2_pts[i, 0] + vane2_pts[i + 1, 0])
xc = 0.5 * (vane2_pts[i, 1] + vane2_pts[i + 1, 1]) + radius
zl = vane2_pts[i + 1, 0] - vane2_pts[i, 0]
if zl <= 0:
continue
box_h = box_top - xc
vane2_parts.append(ZCylinder(radius, length=zl, voltage=-voltage, zcent=zc, xcent=xc))
vane2_parts.append(Box(xsize=box_h, ysize=2 * radius, zsize=zl, voltage=-voltage,
zcent=zc, xcent=xc + 0.5 * box_h))
vane2_cond = self.union_balanced(vane2_parts)
in pyt_rfq_designer.create_vanes
the actual vane construction method reach the limit of the python recursion limit very fast
to fix it I propose the function
with this it will keeps the union tree to depth log2(N) instead of N. With this, it will be possible to achieve higher resolutions in the vanes
and later in the function create_vanes
vane1_parts = []
for i in range(len(vane1_pts) - 1):
zc = 0.5 * (vane1_pts[i, 0] + vane1_pts[i + 1, 0])
yc = 0.5 * (vane1_pts[i, 1] + vane1_pts[i + 1, 1]) + radius
zl = vane1_pts[i + 1, 0] - vane1_pts[i, 0]
if zl <= 0:
continue