Skip to content

Commit

Permalink
Merge pull request #107 from xsuite/release/v0.5.4
Browse files Browse the repository at this point in the history
Release 0.5.4
  • Loading branch information
freddieknets authored Oct 9, 2024
2 parents 99d7076 + a75e8eb commit a237888
Show file tree
Hide file tree
Showing 139 changed files with 1,134 additions and 513 deletions.
9 changes: 7 additions & 2 deletions examples/adt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# copyright ############################### #
# This file is part of the Xcoll Package. #
# This file is part of the Xcoll package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

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


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

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

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

Expand All @@ -150,6 +153,7 @@
ax.set_ylabel(r"normalised amplitude $[mm]$")
ax.set_xlabel("Turn number")
ax.legend()
plt.tight_layout()
ax.set_title("Average amplitude growth by ADT blow-up in the LHC")
plt.savefig("adt_vertical_amplitude.png", dpi=300)
plt.show()
Expand All @@ -162,5 +166,6 @@
ax.set_xlabel("Turn number")
ax.legend()
ax.set_title("Longitudinal emittance growth by ADT blow-up in the LHC")
plt.tight_layout()
plt.savefig("adt_longitudinal_emittance.png", dpi=300)
plt.show()
9 changes: 7 additions & 2 deletions examples/adt_simplified.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# copyright ############################### #
# This file is part of the Xcoll Package. #
# This file is part of the Xcoll package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

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


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

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

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

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

Expand All @@ -152,5 +156,6 @@
ax.set_xlabel("Turn number")
ax.legend()
ax.set_title("Longitudinal emittance growth by ADT blow-up in the LHC")
plt.tight_layout()
plt.savefig("adt_simplified_longitudinal_emittance.png", dpi=300)
plt.show()
2 changes: 1 addition & 1 deletion examples/everest_block.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# copyright ############################### #
# This file is part of the Xcoll Package. #
# This file is part of the Xcoll package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

Expand Down
2 changes: 1 addition & 1 deletion examples/everest_collimator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# copyright ############################### #
# This file is part of the Xcoll Package. #
# This file is part of the Xcoll package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

Expand Down
2 changes: 1 addition & 1 deletion examples/everest_crystal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# copyright ############################### #
# This file is part of the Xcoll Package. #
# This file is part of the Xcoll package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

Expand Down
71 changes: 71 additions & 0 deletions examples/impact_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# copyright ############################### #
# This file is part of the Xcoll package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

import xobjects as xo
import xtrack as xt
import xpart as xp
import xcoll as xc

# ============================================
# With collimators
# ============================================

# Get line and collimators
line = xt.Line.from_json(xc._pkg_root / '..' / 'examples' / 'machines' / 'lhc_run3_b1.json')

colldb = xc.CollimatorDatabase.from_yaml(xc._pkg_root / '..' / 'examples' / 'colldb' / 'lhc_run3.yaml', beam=1)
colldb.install_everest_collimators(verbose=True, line=line)
df_with_coll = line.check_aperture()
assert not np.any(df_with_coll.has_aperture_problem)

# Start interaction record
impacts = xc.InteractionRecord.start(line=line)

# Build tracker, assign optics and generate particles
line.build_tracker()
xc.assign_optics_to_collimators(line=line)
part = xc.generate_pencil_on_collimator(line, 'tcp.d6l7.b1', 50000)

# This is not needed, but is done here so that we can track with 12 treads.
line.discard_tracker()
line.build_tracker(_context=xo.ContextCpu(omp_num_threads=12))

# Track
xc.enable_scattering(line)
line.track(part, num_turns=20, time=True, with_progress=1)
xc.disable_scattering(line)
line.discard_tracker()

df = impacts.to_pandas()
df[df.interaction_type == 'Enter Jaw L']
df.to_csv('impacts.csv', index=False)

# ============================================
# With crystal
# ============================================
coll = xc.EverestCrystal(length=0.002, material=xc.materials.SiliconCrystal, bending_angle=149e-6,
width=0.002, height=0.05, side='+', lattice='strip', jaw=0.001)

num_part = int(50000)
x_init = np.random.normal(loc=1.5e-3, scale=75.e-6, size=num_part)
px_init = np.random.uniform(low=-50.e-6, high=250.e-6, size=num_part)
y_init = np.random.normal(loc=0., scale=1e-3, size=num_part)
py_init = np.random.normal(loc=0., scale=5.e-6, size=num_part)
part = xp.Particles(x=x_init, px=px_init, y=y_init, py=py_init, delta=0, p0c=4e11)

io_buffer = xt.new_io_buffer(capacity=int(2e7)) # 4-5 GB of memory
coll.record_scatterings = True
impacts_crystal = xt.start_internal_logging(elements=[coll], io_buffer=io_buffer, capacity=io_buffer.capacity)

coll.track(part)
part.sort(interleave_lost_particles=True)

impacts_crystal.to_pandas()
df_crystal = impacts_crystal.interactions_per_collimator()
df_crystal.to_csv('interactions_per_crystal.csv', index=False)
2 changes: 1 addition & 1 deletion examples/lhc_run3_lossmap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# copyright ############################### #
# This file is part of the Xcoll Package. #
# This file is part of the Xcoll package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

Expand Down
4 changes: 2 additions & 2 deletions examples/lhc_run3_lossmap_with_blowup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# copyright ############################### #
# This file is part of the Xcoll Package. #
# This file is part of the Xcoll package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

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


Expand Down
2 changes: 1 addition & 1 deletion examples/lhc_run3_lossmap_with_crystals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# copyright ############################### #
# This file is part of the Xcoll Package. #
# This file is part of the Xcoll package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

Expand Down
2 changes: 1 addition & 1 deletion examples/lhc_run3_offmomentum_lossmap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# copyright ############################### #
# This file is part of the Xcoll Package. #
# This file is part of the Xcoll package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

Expand Down
2 changes: 1 addition & 1 deletion examples/rf_sweep.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# copyright ############################### #
# This file is part of the Xcoll Package. #
# This file is part of the Xcoll package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

Expand Down
2 changes: 1 addition & 1 deletion examples/transfer_line_with_air.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# copyright ############################### #
# This file is part of the Xcoll Package. #
# This file is part of the Xcoll package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

Expand Down
Loading

0 comments on commit a237888

Please sign in to comment.