Ejemplo n.º 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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
def speed(cljob, npart=20000, turns=10, trials=1):
    particles = sim.Particles(nparticles=npart)
    particles.p0c = 7000e9
    particles.px = np.linspace(0, 0.000001, npart)
    cljob.set_particles(particles)
    avg = 0
    for i in range(trials):
        start = time.time()
        cljob.track(turns)
        cljob.collect()
        duration = (time.time() - start)
        avg += duration
    duration = avg / trials
    return duration / turns, duration / (npart * turns)
Ejemplo n.º 4
0
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

def test_monitor():
  assert(cljob.monitor[0].x.reshape(np,nt)[particle][1]==2.49600000e-04)
Ejemplo n.º 5
0
#!/usr/bin/env python3

import time, sys

import numpy as np

import sixtracktools
import simpletrack as sim
import pysixtrack

npart = 1
nturns = 1
x0 = 0.0001

particles = sim.Particles(nparticles=npart)
particles.p0c = 7000e9
particles.x = x0

#lhc = sixtracktools.SixInput('.')
#line, rest, iconv = lhc.expand_struct()
#elements=sim.Elements.fromline(line)

elements = sim.Elements()
lhc = sixtracktools.SixInput('.')
line, rest, iconv = lhc.expand_struct(convert=elements.gen_builder())

cljob = sim.TrackJobCL(particles, elements, device="0.0", dump_element=nturns)
cljob.track()
cljob.collect()
out = cljob.dump_element
Ejemplo n.º 6
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)