Skip to content

Commit 41ce9c9

Browse files
committed
Test orbit.sim.linac BunchMonitor
1 parent 93becfe commit 41ce9c9

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import argparse
2+
import math
3+
import os
4+
import pathlib
5+
import random
6+
import sys
7+
8+
from orbit.core.bunch import Bunch
9+
from orbit.core.spacecharge import SpaceChargeCalc3D
10+
from orbit.lattice import AccActionsContainer
11+
from orbit.lattice import AccNode
12+
from orbit.lattice import AccLattice
13+
from orbit.sim.linac import BunchMonitor
14+
from orbit.sim.linac import BunchWriter
15+
from orbit.space_charge.sc3d import setSC3DAccNodes
16+
from orbit.teapot import TEAPOT_Lattice
17+
from orbit.teapot import DriftTEAPOT
18+
from orbit.utils.consts import mass_proton
19+
20+
21+
# Setup
22+
# --------------------------------------------------------------------------------------
23+
24+
path = pathlib.Path(__file__)
25+
output_dir = os.path.join("outputs", path.stem)
26+
os.makedirs(output_dir, exist_ok=True)
27+
28+
29+
# Lattice
30+
# --------------------------------------------------------------------------------------
31+
32+
distance = 5.0
33+
nsteps = 200
34+
delta_s = distance / nsteps
35+
36+
lattice = TEAPOT_Lattice()
37+
node = DriftTEAPOT()
38+
node.setLength(distance)
39+
node.setnParts(nsteps)
40+
lattice.addNode(node)
41+
lattice.initialize()
42+
43+
sc_calc = SpaceChargeCalc3D(64, 64, 64)
44+
sc_nodes = setSC3DAccNodes(lattice, delta_s, sc_calc)
45+
46+
47+
# Bunch
48+
# --------------------------------------------------------------------------------------
49+
50+
bunch = Bunch()
51+
bunch.mass(mass_proton)
52+
bunch.getSyncParticle().kinEnergy(0.0025)
53+
54+
nparts = 128_000
55+
for i in range(nparts):
56+
x = 0.010 * random.gauss()
57+
y = 0.010 * random.gauss()
58+
z = 0.010 * random.gauss()
59+
xp = 0.0
60+
yp = 0.0
61+
dE = 0.0
62+
bunch.addParticle(x, xp, y, yp, z, dE)
63+
64+
intensity = 2.00e+09
65+
size_global = bunch.getSizeGlobal()
66+
macro_size = intensity / size_global
67+
bunch.macroSize(macro_size)
68+
69+
70+
# Simulation
71+
# --------------------------------------------------------------------------------------
72+
73+
bunch_writer = BunchWriter(output_dir=output_dir)
74+
75+
bunch_monitor = BunchMonitor(
76+
output_dir=output_dir,
77+
stride=0.01,
78+
stride_write=2.0,
79+
rf_frequency=402.5e+06,
80+
bunch_writer=bunch_writer,
81+
verbose=True,
82+
)
83+
84+
85+
action_container = AccActionsContainer()
86+
action_container.addAction(bunch_monitor, 0) # entrance
87+
action_container.addAction(bunch_monitor, 2) # exit
88+
89+
lattice.trackBunch(bunch, actionContainer=action_container)

0 commit comments

Comments
 (0)