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
rp_perlength = current/(beta*scipy.constants.c*scipy.constants.e) real_particles = rp_perlength*bunch_length #real_particles = np.round(current*bunch_length/(beta*scipy.constants.c*scipy.constants.e)) #current = (14./400)*1.e-3 #mA of current #blt = bunch_length/(beta*scipy.constants.c) #temporal length of bunch #real_particles = np.round((current*blt)/scipy.constants.e) opts.real_particles = real_particles print "Approximating a current of {}A using {} particles".format(current,opts.real_particles) #totalQ = opts.real_particles*scipy.constants.e bucket_length = beta*lattice.get_length()/4 #RF harmonic number is 4 particles_file = 'myBunch.txt' myBunch = read_bunch.read_bunch(particles_file, reference_particle, opts.real_particles, bucket_length, comm) #============================ Finished acquiring a bunch ===================== #================== set up the output diagnostics by creating the bunch_simulator ============= bunch_simulator = synergia.simulation.Bunch_simulator(myBunch) #basic diagnostics - PER STEP basicdiag = synergia.bunch.Diagnostics_basic("basic.h5", opts.output_dir) bunch_simulator.add_per_step(basicdiag) print >>logger, "saving basic diagnostics each step" #include full diagnostics
#import lattice and construct options object #load lattice lattice = synergia.lattice.MadX_reader().get_lattice("iota", "/Users/ncook/Synergia_Tests/lattices/Iota6-6/lattice_2IO_nll.madx") 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 name = 'lattice_2IO_NL' order = 1 outputdir = 'order_'+str(order)+'_'+name opts = workflow.make_opts(name, order, outputdir, nsteps, nsteps_per_element) opts.macro_particles=1000 opts.emitx = 1.0e-5 #workflow.make_path(outputdir) lattice_simulator = synergia.simulation.Lattice_simulator(lattice,opts.map_order) #construct bunch array and write it to a textfile EllipticBeam6D.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() myBunch = read_bunch.read_bunch(particles_file, ref, opts.real_particles, bucket_length, comm, verbose=False)