Skip to content

Commit a237888

Browse files
authored
Merge pull request #107 from xsuite/release/v0.5.4
Release 0.5.4
2 parents 99d7076 + a75e8eb commit a237888

File tree

139 files changed

+1134
-513
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+1134
-513
lines changed

examples/adt.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# copyright ############################### #
2-
# This file is part of the Xcoll Package. #
2+
# This file is part of the Xcoll package. #
33
# Copyright (c) CERN, 2024. #
44
# ######################################### #
55

@@ -47,7 +47,7 @@
4747
tank_start = f'adtk{plane.lower()}.{pos}.a.b{beam}'
4848
tank_end = f'adtk{plane.lower()}.{pos}.d.b{beam}'
4949
adt_pos = 0.5*line.get_s_position(tank_start) + 0.5*line.get_s_position(tank_end)
50-
adt = xc.BlowUp.install(line, name=name, at_s=adt_pos, need_apertures=False, plane=plane,
50+
adt = xc.BlowUp.install(line, name=f'{name}_blowup', at_s=adt_pos, need_apertures=False, plane=plane,
5151
stop_at_turn=adt_turns)
5252

5353

@@ -117,6 +117,7 @@
117117
ax.legend()
118118
ax.set_title("Horizontal emittance growth by ADT blow-up in the LHC")
119119
print(f"Total calculation time {time.time()-start_time}s")
120+
plt.tight_layout()
120121
plt.savefig("adt_horizontal_emittance.png", dpi=300)
121122
plt.show()
122123

@@ -128,6 +129,7 @@
128129
ax.set_xlabel("Turn number")
129130
ax.legend()
130131
ax.set_title("Average amplitude growth by ADT blow-up in the LHC")
132+
plt.tight_layout()
131133
plt.savefig("adt_horizontal_amplitude.png", dpi=300)
132134
plt.show()
133135

@@ -140,6 +142,7 @@
140142
ax.set_xlabel("Turn number")
141143
ax.legend()
142144
ax.set_title("Vertical emittance growth by ADT blow-up in the LHC")
145+
plt.tight_layout()
143146
plt.savefig("adt_vertical_emittance.png", dpi=300)
144147
plt.show()
145148

@@ -150,6 +153,7 @@
150153
ax.set_ylabel(r"normalised amplitude $[mm]$")
151154
ax.set_xlabel("Turn number")
152155
ax.legend()
156+
plt.tight_layout()
153157
ax.set_title("Average amplitude growth by ADT blow-up in the LHC")
154158
plt.savefig("adt_vertical_amplitude.png", dpi=300)
155159
plt.show()
@@ -162,5 +166,6 @@
162166
ax.set_xlabel("Turn number")
163167
ax.legend()
164168
ax.set_title("Longitudinal emittance growth by ADT blow-up in the LHC")
169+
plt.tight_layout()
165170
plt.savefig("adt_longitudinal_emittance.png", dpi=300)
166171
plt.show()

examples/adt_simplified.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# copyright ############################### #
2-
# This file is part of the Xcoll Package. #
2+
# This file is part of the Xcoll package. #
33
# Copyright (c) CERN, 2024. #
44
# ######################################### #
55

@@ -37,7 +37,7 @@
3737
tank_start = f'adtk{plane.lower()}.{pos}.a.b{beam}'
3838
tank_end = f'adtk{plane.lower()}.{pos}.d.b{beam}'
3939
adt_pos = 0.5*line.get_s_position(tank_start) + 0.5*line.get_s_position(tank_end)
40-
adt = xc.BlowUp.install(line, name=name, at_s=adt_pos, need_apertures=False, plane=plane,
40+
adt = xc.BlowUp.install(line, name=f'{name}_blowup', at_s=adt_pos, need_apertures=False, plane=plane,
4141
stop_at_turn=adt_turns, use_individual_kicks=True)
4242

4343

@@ -107,6 +107,7 @@
107107
ax.legend()
108108
ax.set_title("Horizontal emittance growth by ADT blow-up in the LHC")
109109
print(f"Total calculation time {time.time()-start_time}s")
110+
plt.tight_layout()
110111
plt.savefig("adt_simplified_horizontal_emittance.png", dpi=300)
111112
plt.show()
112113

@@ -118,6 +119,7 @@
118119
ax.set_xlabel("Turn number")
119120
ax.legend()
120121
ax.set_title("Average amplitude growth by ADT blow-up in the LHC")
122+
plt.tight_layout()
121123
plt.savefig("adt_simplified_horizontal_amplitude.png", dpi=300)
122124
plt.show()
123125

@@ -130,6 +132,7 @@
130132
ax.set_xlabel("Turn number")
131133
ax.legend()
132134
ax.set_title("Vertical emittance growth by ADT blow-up in the LHC")
135+
plt.tight_layout()
133136
plt.savefig("adt_simplified_vertical_emittance.png", dpi=300)
134137
plt.show()
135138

@@ -141,6 +144,7 @@
141144
ax.set_xlabel("Turn number")
142145
ax.legend()
143146
ax.set_title("Average amplitude growth by ADT blow-up in the LHC")
147+
plt.tight_layout()
144148
plt.savefig("adt_simplified_vertical_amplitude.png", dpi=300)
145149
plt.show()
146150

@@ -152,5 +156,6 @@
152156
ax.set_xlabel("Turn number")
153157
ax.legend()
154158
ax.set_title("Longitudinal emittance growth by ADT blow-up in the LHC")
159+
plt.tight_layout()
155160
plt.savefig("adt_simplified_longitudinal_emittance.png", dpi=300)
156161
plt.show()

examples/everest_block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# copyright ############################### #
2-
# This file is part of the Xcoll Package. #
2+
# This file is part of the Xcoll package. #
33
# Copyright (c) CERN, 2024. #
44
# ######################################### #
55

examples/everest_collimator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# copyright ############################### #
2-
# This file is part of the Xcoll Package. #
2+
# This file is part of the Xcoll package. #
33
# Copyright (c) CERN, 2024. #
44
# ######################################### #
55

examples/everest_crystal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# copyright ############################### #
2-
# This file is part of the Xcoll Package. #
2+
# This file is part of the Xcoll package. #
33
# Copyright (c) CERN, 2024. #
44
# ######################################### #
55

examples/impact_table.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# copyright ############################### #
2+
# This file is part of the Xcoll package. #
3+
# Copyright (c) CERN, 2024. #
4+
# ######################################### #
5+
6+
import numpy as np
7+
import matplotlib as mpl
8+
import matplotlib.pyplot as plt
9+
10+
import xobjects as xo
11+
import xtrack as xt
12+
import xpart as xp
13+
import xcoll as xc
14+
15+
# ============================================
16+
# With collimators
17+
# ============================================
18+
19+
# Get line and collimators
20+
line = xt.Line.from_json(xc._pkg_root / '..' / 'examples' / 'machines' / 'lhc_run3_b1.json')
21+
22+
colldb = xc.CollimatorDatabase.from_yaml(xc._pkg_root / '..' / 'examples' / 'colldb' / 'lhc_run3.yaml', beam=1)
23+
colldb.install_everest_collimators(verbose=True, line=line)
24+
df_with_coll = line.check_aperture()
25+
assert not np.any(df_with_coll.has_aperture_problem)
26+
27+
# Start interaction record
28+
impacts = xc.InteractionRecord.start(line=line)
29+
30+
# Build tracker, assign optics and generate particles
31+
line.build_tracker()
32+
xc.assign_optics_to_collimators(line=line)
33+
part = xc.generate_pencil_on_collimator(line, 'tcp.d6l7.b1', 50000)
34+
35+
# This is not needed, but is done here so that we can track with 12 treads.
36+
line.discard_tracker()
37+
line.build_tracker(_context=xo.ContextCpu(omp_num_threads=12))
38+
39+
# Track
40+
xc.enable_scattering(line)
41+
line.track(part, num_turns=20, time=True, with_progress=1)
42+
xc.disable_scattering(line)
43+
line.discard_tracker()
44+
45+
df = impacts.to_pandas()
46+
df[df.interaction_type == 'Enter Jaw L']
47+
df.to_csv('impacts.csv', index=False)
48+
49+
# ============================================
50+
# With crystal
51+
# ============================================
52+
coll = xc.EverestCrystal(length=0.002, material=xc.materials.SiliconCrystal, bending_angle=149e-6,
53+
width=0.002, height=0.05, side='+', lattice='strip', jaw=0.001)
54+
55+
num_part = int(50000)
56+
x_init = np.random.normal(loc=1.5e-3, scale=75.e-6, size=num_part)
57+
px_init = np.random.uniform(low=-50.e-6, high=250.e-6, size=num_part)
58+
y_init = np.random.normal(loc=0., scale=1e-3, size=num_part)
59+
py_init = np.random.normal(loc=0., scale=5.e-6, size=num_part)
60+
part = xp.Particles(x=x_init, px=px_init, y=y_init, py=py_init, delta=0, p0c=4e11)
61+
62+
io_buffer = xt.new_io_buffer(capacity=int(2e7)) # 4-5 GB of memory
63+
coll.record_scatterings = True
64+
impacts_crystal = xt.start_internal_logging(elements=[coll], io_buffer=io_buffer, capacity=io_buffer.capacity)
65+
66+
coll.track(part)
67+
part.sort(interleave_lost_particles=True)
68+
69+
impacts_crystal.to_pandas()
70+
df_crystal = impacts_crystal.interactions_per_collimator()
71+
df_crystal.to_csv('interactions_per_crystal.csv', index=False)

examples/lhc_run3_lossmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# copyright ############################### #
2-
# This file is part of the Xcoll Package. #
2+
# This file is part of the Xcoll package. #
33
# Copyright (c) CERN, 2024. #
44
# ######################################### #
55

examples/lhc_run3_lossmap_with_blowup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# copyright ############################### #
2-
# This file is part of the Xcoll Package. #
2+
# This file is part of the Xcoll package. #
33
# Copyright (c) CERN, 2024. #
44
# ######################################### #
55

@@ -51,7 +51,7 @@
5151
tank_start = f'adtk{plane.lower()}.{pos}.a.b{beam}'
5252
tank_end = f'adtk{plane.lower()}.{pos}.d.b{beam}'
5353
adt_pos = 0.5*line.get_s_position(tank_start) + 0.5*line.get_s_position(tank_end)
54-
adt = xc.BlowUp.install(line, name=name, at_s=adt_pos, plane=plane, stop_at_turn=num_turns,
54+
adt = xc.BlowUp.install(line, name=f'{name}_blowup', at_s=adt_pos, plane=plane, stop_at_turn=num_turns,
5555
amplitude=0.75, use_individual_kicks=True)
5656

5757

examples/lhc_run3_lossmap_with_crystals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# copyright ############################### #
2-
# This file is part of the Xcoll Package. #
2+
# This file is part of the Xcoll package. #
33
# Copyright (c) CERN, 2024. #
44
# ######################################### #
55

examples/lhc_run3_offmomentum_lossmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# copyright ############################### #
2-
# This file is part of the Xcoll Package. #
2+
# This file is part of the Xcoll package. #
33
# Copyright (c) CERN, 2024. #
44
# ######################################### #
55

0 commit comments

Comments
 (0)