Project

General

Profile

run_bad_lattice.py

Eric Stern, 10/23/2015 06:14 AM

 
1
import sys
2
import os
3
import numpy as np
4
import synergia
5
import numpy as np
6
from mpi4py import MPI
7
import beamline
8

    
9

    
10
lattice = synergia.lattice.Mad8_reader().get_lattice("bad_line", "bad_lattice.lat")
11

    
12
for elem in lattice.get_elements():
13
    elem.set_string_attribute("extractor_type", "chef_mixed")
14

    
15
macro_particles = 10
16
real_particles = 1.0e10
17

    
18
commxx = synergia.utils.Commxx()
19
bunch = synergia.bunch.Bunch(lattice.get_reference_particle(),
20
            macro_particles, real_particles, commxx)
21

    
22
bunch_simulator = synergia.simulation.Bunch_simulator(bunch)
23

    
24
bunch_simulator.add_per_step(synergia.bunch.Diagnostics_basic("basic.h5"))
25
bunch_simulator.add_per_step(synergia.bunch.Diagnostics_bulk_track("tracks.h5", macro_particles))
26

    
27
local_particles = bunch.get_local_particles()
28

    
29
stepper = synergia.simulation.Independent_stepper_elements(lattice, 1, 1)
30
chef_beamline = stepper.get_lattice_simulator().get_chef_lattice().get_sliced_beamline()
31
probe = beamline.Proton(lattice.get_reference_particle().get_total_energy())
32
print "chef propagate begin: ", probe.State()
33
#chef_beamline.propagate(probe)
34
for ce in chef_beamline:
35
    ce.propagate(probe)
36
print "chef propagate end: ", probe.State()
37

    
38
propagator = synergia.simulation.Propagator(stepper)
39

    
40
print
41

    
42
print "bunch particle 0 before synergia propagation: "
43
print np.array2string(local_particles[0, 0:6])
44
propagator.propagate(bunch_simulator, 10, 1, 1)
45
print
46
print "bunch particle 0 after synergia propagation: "
47
print np.array2string(local_particles[0, 0:6])
48

    
49
sys.exit(0)
50
print
51
print "beamline"
52
print synergia.lattice.chef_beamline_as_string(chef_beamline)