예제 #1
0
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
예제 #2
0
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

def test_monitor():
  assert(cljob.monitor[0].x.reshape(np,nt)[particle][1]==2.49600000e-04)

예제 #3
0
import numpy as np

import simpletrack as sim


def speed(cljob, npart=20000, turns=10):
    particles = sim.Particles(nparticles=npart)
    particles.p0c = 7000e9
    particles.px = np.linspace(0, 0.000001, npart)
    cljob.set_particles(particles)
    start = time.time()
    cljob.track(turns)
    cljob.collect()
    duration = (time.time() - start)
    return duration


elements = sim.Elements.fromfile("line.bin")
particles = sim.Particles(nparticles=1)

device = "0.0"
npart = 16
nturn = 15

for device in sim.TrackJobCL.get_available_devices():
    cljob = sim.TrackJobCL(particles, elements, device=device, dump_element=0)
    duration = speed(cljob, npart, nturn)
    print(f"{(npart*nturn)/duration:9.0f} particles*turns/seconds, "
          f"{npart} particles, {nturn} turns, "
          f"device '{device}', {cljob.ctx.devices[0].name}")
예제 #4
0
import numpy as np

import simpletrack as sim

elements = sim.Elements()

elements.Multipole(knl=[0.1570796327], hxl=0.1570796327, length=1)
elements.Drift(length=5)
elements.Multipole(knl=[0, 0.1657145946])
elements.Drift(length=5)
elements.Multipole(knl=[0.1570796327], hxl=0.1570796327, length=1)
elements.Drift(length=5)
elements.Multipole(knl=[0, -0.1685973315])
elements.Drift(length=5)
elements.Cavity(voltage=5000000.0, frequency=239833966.4, lag=180)
elements.Monitor(turns=10)

particles = sim.Particles(nparticles=5)
particles.p0c = 450e9
particles.x = np.linspace(0, 1e-8, 5)

job = sim.TrackJobCL(particles, elements)
job.track(10)
job.collect()

job.monitor[0].x.reshape(5, -1)
예제 #5
0
# 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
job = sim.TrackJob(line, particles)