Example #1
0
def make6DEllipticalBeam(lattice_file,lattice_name):
    
    '''Constructs a coasting elliptic beam with Gaussian longitduinal distribution and stores it in a Synergia bunch.
    
    A lattice file is required, as Synergia constructs the bunch relative to the reference particle as specified in mad-x.
    
    Arguments:
        lattice_file - A .madx file which stores the lattice
        lattice_name - The sequence name within the madx file

     '''
    
    #import lattice and construct options object
    #load lattice
    lattice = synergia.lattice.MadX_reader().get_lattice(lattice_name,lattice_file)
    length = lattice.get_length()
    ref = lattice.get_reference_particle() #reference particle
    ds = 0.01
    #nsteps = int(length/ds) +1 #calculate # of steps to take per turn
    #nsteps_per_element = nsteps/len(lattice.get_elements()) #not this isn't using future division, so returns int
    nsteps_per_element = 10 #hardcoded for IOTA nl elements
    nsteps = len(lattice.get_elements())*nsteps_per_element


    name = 'lattice_1IO_NL_Center'
    order = 1
    outputdir = 'order_'+str(order)+'_'+name

    opts = workflow.make_opts(name, order, outputdir, nsteps, nsteps_per_element)
    opts.macro_particles=1000
    opts.emitx = 7.0e-6
    workflow.make_path(outputdir)

    #make lattice chef propagating
    latticework.make_chef(lattice)

    stepper = synergia.simulation.Independent_stepper_elements(lattice, opts.map_order, opts.steps_per_element)
    lattice_simulator = stepper.get_lattice_simulator()
    #lattice_simulator = synergia.simulation.Lattice_simulator(lattice,opts.map_order)


    #construct bunch array and write it to a textfile
    EllipticalBeam6D(opts)

    #read in the file and construct a synergia bunch
    particles_file = 'myBunch.txt'
    comm = synergia.utils.Commxx(True)
    bucket_length = lattice_simulator.get_bucket_length()
    bucket_length = 0.05 #potential workaround
    myBunch = read_bunch.read_bunch(particles_file, ref, opts.real_particles, bucket_length, comm, verbose=False)
    
    return opts, lattice, lattice_simulator, stepper, myBunch
    
n_ppc = 100 #n_ppc particles per transverse cell
n_macro = n_ppc*opts.gridx*opts.gridy 
dpop = 0.00
emittances = [9.74e-6]
tval = 0.4
cval = 0.01
name = 't3_1IO_NLL'
outputdir = "{}_turns_order{}_{}_{}PPC-14mA".format(turns,order,name,n_ppc)

nsteps = len(lattice.get_elements())*nsteps_per_element
opts.output_dir = outputdir
opts.relpath = opts.output_dir
opts.macro_particles = n_macro
opts.steps = nsteps
opts.steps_per_element = nsteps_per_element
workflow.make_path(outputdir)

print >>logger, "output directory:", opts.output_dir


requested_stepper = opts.stepper
print >>logger, "requested_stepper: ",  requested_stepper


if requested_stepper == "splitoperator":

    print >>logger, "Using split-operator stepper with ", opts.steps, " steps/turn"

    stepper = synergia.simulation.Split_operator_stepper(
        lattice, opts.map_order, coll_operator, opts.steps)