def mktest(pdata, tol, rtol, elem, **elemdata): pref = six.Particles(**pdata) p = sim.Particles(nparticles=1) for k, v in pdata.items(): setattr(p, k, v) getattr(six, elem)(**elemdata).track(pref) elements = sim.Elements() getattr(elements, elem)(**elemdata) cljob = sim.TrackJobCL(p, elements, device="0.0", debug=False) cljob.track(1) cljob.collect() tdiff = 0 trdiff = 0 print(elem, elemdata) for coord in 'x px y py zeta delta rvv rpp beta0'.split(): diff, rdiff = check_diff(coord, p, pref, tol, rtol) tdiff += diff**2 trdiff += rdiff**2 tdiff = np.sqrt(tdiff) trdiff = np.sqrt(trdiff) if tdiff > tol or trdiff > rtol: print(f"Sum : {tdiff:17.12g} {trdiff:17.12g}") return False else: return True
import sys import numpy as np import simpletrack as sim elements = sim.Elements() elements.Monitor(turns=5) elements.Drift(length=1.2) elements.Multipole(knl=[0,0.8]) elements.Monitor(turns=5) elements.Drift(length=1.2) m=elements.Multipole(knl=[0,-0.7]) elements.tofile('fodo.buf') elements = sim.Elements.fromfile('fodo.buf') particles = sim.Particles(nparticles=11) particles.px=np.linspace(0,0.001,particles.nparticles) cljob = sim.TrackJobCL(particles, elements, device="0.0",dump_element=5) cljob.track(5) cljob.collect() np=11 nt=5 particle=2 turn=3
import simpletrack as sim # alternate API elem = sim.Elements() elem.Drift(length=1.0) elem.Drift(length=2.0) elem.Drift(length=3.0) #line=sim.Line(elements) # create particles npart=1 part = sim.Particles(nparticles=npart) part.px=0.001 # OpenCL workflow sim.TrackJobCL.print_devices() cljob = sim.TrackJobCL(part, elem, device="0.0",dump_element=5) cljob.track(turns=10) cljob.collect() cljob.dump_element.x ## to do cljob.track(turns=10) cljob.track(turns=20) cljob.track(turns=30) trackout = clctx.collect() # tracking