# paste this code at the end of VectorFieldPlot 1.1
doc = FieldplotDocument('VFPt_quadrupole_coils_1',
width=600, height=600, unit=100, commons=True)
R = 1.2
rs = 0.5
ls = 0.4
field = Field({'coils':[
[-R, R, -pi/4, rs, ls, -1.0], [R, R, pi/4, rs, ls, -1.0],
[R, -R, -pi/4, rs, ls, 1.0], [-R, -R, pi/4, rs, ls, 1.0]]})
r0 = op.brentq(lambda r: field.F([0, r])[0], 0.1 * R, 2.0 * R)
Fs = ig.quad(lambda r: field.F([0, r])[0], 0.0, r0)[0]
n = 4
for i in range(n):
a = (i + 0.5) / n
r = op.brentq(lambda r: ig.quad(
lambda r1: field.F([0, r1])[0], 0.0, r)[0] - a * Fs, 0.0, r0)
for phi in range(4):
line = FieldLine(field, rot([r, 0], phi * pi / 2.0), directions='both')
doc.draw_line(line, arrows_style={'dist':1.3, 'offsets':[0.0, 0.5, 0.5, 1.0]})
for phi in range(4):
xy = rot([R, R], phi * pi / 2.0)
for d in (-1, 1):
xy1 = xy + d * rot([0.427, 0], (phi-0.5) * pi / 2.0)
line = FieldLine(field, xy1, directions='both')
doc.draw_line(line, arrows_style={'dist':1.3})
# draw coils
windings = 9
b = ls / (windings - 1.0)
coil_defs = doc.draw_object('defs', {})
grad_back = doc.draw_object('linearGradient', {'id':'grad_back',
'x1':'0', 'x2':'0', 'y1':str(-rs-b), 'y2':str(rs+b),
'gradientUnits':'userSpaceOnUse'}, group=coil_defs)
for of, col in ((0.00, '#ac7d6b'), (0.15, '#220e0b'), (0.35, '#8a634f'),
(0.60, '#ffffff'), (0.80, '#8a634f'), (0.90, '#371f18'), (1.00, '#a37e6b')):
doc.draw_object('stop', {'offset':str(of), 'stop-color':col}, group=grad_back)
grad_front = doc.draw_object('linearGradient', {'id':'grad_front',
'x1':str(-b), 'x2':str(b), 'y1':'0', 'y2':'0',
'gradientUnits':'userSpaceOnUse'}, group=coil_defs)
for of, col, opa in ((0.00, '#ad7d63', 0.90), (0.48, '#ad8169', 0.31),
(0.65, '#8f6050', 0.14), (0.83, '#844038', 0.42), (1.00, '#2d1412', 1.00)):
doc.draw_object('stop', {'offset':str(of), 'stop-color':col, 'stop-opacity':str(opa)}, group=grad_front)
wire = doc.draw_object('g', {'id':'wire'}, group=coil_defs)
wire_string = 'M -{0},{1} L -{0},-{1} A {0},{0} 0 1 1 {0},-{1} L {0},{1} A {0},{0} 0 1 1 -{0},{1} Z'.format(b, rs)
wire_back = doc.draw_object('path', {'d':wire_string, 'stroke':'none',
'fill':'url(#grad_back)'}, group=wire)
wire_front = doc.draw_object('path', {'d':wire_string, 'stroke':'#000000',
'stroke-width':'0.01', 'fill':'url(#grad_front)'}, group=wire)
coil = doc.draw_object('g', {'id':'coil'}, group=coil_defs)
for i in range(windings):
doc.draw_object('use', {'{http://www.w3.org/1999/xlink}href':'#wire',
'x':str(b * (2 * i + 1 - windings))}, group=coil)
doc.draw_object('use', {'{http://www.w3.org/1999/xlink}href':'#coil',
'transform':'translate(-{0},{0}) scale(-1,1) rotate(45)'.format(R)})
doc.draw_object('use', {'{http://www.w3.org/1999/xlink}href':'#coil',
'transform':'translate({0},{0}) rotate(45)'.format(R)})
doc.draw_object('use', {'{http://www.w3.org/1999/xlink}href':'#coil',
'transform':'translate({0},-{0}) scale(-1,1) rotate(45)'.format(R)})
doc.draw_object('use', {'{http://www.w3.org/1999/xlink}href':'#coil',
'transform':'translate(-{0},-{0}) rotate(45)'.format(R)})
doc.write()