Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equilibrium emittance in presence of SR and IBS #157

Draft
wants to merge 60 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
9d60d14
Add function to compute the equilibrium emittance in presence of SR a…
Jan 3, 2025
3d49542
Fix small bug with 'excitation' constraint.
Jan 3, 2025
5aed27d
Add tests.
Jan 3, 2025
e76d4a2
Additional fixes and simplifications.
Jan 9, 2025
60584cc
Proper initialization of the emittances when forcing an emittance cou…
Jan 10, 2025
a104d83
Remove 'natural_emittances' from 'ibs_rates' to avoid potential confu…
Jan 13, 2025
2e706f0
Remove last 'natural_emittances' traces
Jan 13, 2025
9a5d910
imports shuffle, xo class for derivatives to simplify passing data ar…
fsoubelet Jan 13, 2025
98eed04
rename function to explicit name and make private
fsoubelet Jan 13, 2025
e6468ce
return as classes and beware of order in call line
fsoubelet Jan 13, 2025
717f6ac
unpack as tuple, specify comment
fsoubelet Jan 13, 2025
896060d
rename to emittance_derivatives
fsoubelet Jan 13, 2025
87caa65
commented out code to return a Table for the user's enjoyment
fsoubelet Jan 13, 2025
e1fd86a
do not export private function
fsoubelet Jan 13, 2025
4b3deaf
rename params that are not used in private function anymore - emittan…
fsoubelet Jan 13, 2025
25b2c64
explicitely name attributions
fsoubelet Jan 13, 2025
6b4357d
docstring rework and TODOs
fsoubelet Jan 13, 2025
59c9a00
input_sigma_zeta and input_sigma_delta are not in this function, remo…
fsoubelet Jan 13, 2025
53d3511
replace call of intermediate badly named natural_emittance_[xyz] to d…
fsoubelet Jan 13, 2025
692b664
also remove attribution to vars, could add later a check for presence…
fsoubelet Jan 13, 2025
57270e4
remove damping rates from parameters and take it directly from the Tw…
fsoubelet Jan 13, 2025
2e46884
and rework the return statement in docstring
fsoubelet Jan 13, 2025
8c20bfc
commented out potential check for presence of expected attributes in …
fsoubelet Jan 13, 2025
7363448
asserts and checks as high as possible
fsoubelet Jan 13, 2025
25f5b99
comments to walk through the function, pretty clean already
fsoubelet Jan 13, 2025
eb8c687
one last todo
fsoubelet Jan 13, 2025
d858ab0
Merge pull request #1 from SebastienJoly/cosmetics
SebastienJoly Jan 14, 2025
da11a19
bunch_intensity -> total_beam_intensity to mimic the rest of the APIs
fsoubelet Jan 14, 2025
02124e5
pass kwargs to IBS growth rates method, document in docstring
fsoubelet Jan 14, 2025
4d66bb8
remove bunched=True as it is default, and with kwargs passing the use…
fsoubelet Jan 14, 2025
ff81624
no default for formalism, place it as second arg to mimic API pf IBS …
fsoubelet Jan 14, 2025
d94f1a9
add formalism to main function as the user NEEDS to be able to choose…
fsoubelet Jan 14, 2025
f4fa9db
some walkthrough
fsoubelet Jan 14, 2025
447a104
reworking of the docstring, part1
fsoubelet Jan 14, 2025
3e44bf5
reworking of the docstring, part2
fsoubelet Jan 14, 2025
6f89e98
natural emittances is not a param anymore, remove from docstring
fsoubelet Jan 14, 2025
7a48a4c
clarify rtol
fsoubelet Jan 14, 2025
369f660
clear up call to _ibs_rates_and_emittance_derivatives which was using…
fsoubelet Jan 14, 2025
d5b3650
propagate kwargs to inner function
fsoubelet Jan 14, 2025
f514a23
rework the whole emittance constraint thing in docstring, should be c…
fsoubelet Jan 14, 2025
7dcbfe6
commented out code for Table return, and global quantities included
fsoubelet Jan 14, 2025
d73c041
commented out docstring for when we return a table
fsoubelet Jan 14, 2025
6effcb5
use new parameter names in warning
fsoubelet Jan 14, 2025
69c577a
some harmless renaming
fsoubelet Jan 14, 2025
e8f6948
some todo
fsoubelet Jan 14, 2025
b876bb1
put back this piece of docstring
fsoubelet Jan 14, 2025
cbde1b3
fix my mess of overriding names
fsoubelet Jan 14, 2025
7234e33
small correction to emittance_coupling_factor
fsoubelet Jan 14, 2025
6ae0a8f
typos
fsoubelet Jan 14, 2025
42a1b94
verbose flag and xobjects print
fsoubelet Jan 15, 2025
2619c33
todo for emittance constraint checks
fsoubelet Jan 15, 2025
b7d9270
review changes for emittance constraint
fsoubelet Jan 15, 2025
34f953c
only transverse constraints enforced in loop
fsoubelet Jan 15, 2025
77f4008
correct info on default value
fsoubelet Jan 15, 2025
51749da
typo
fsoubelet Jan 15, 2025
39f9504
add todo for api changes
fsoubelet Jan 15, 2025
5d77c42
should be elif
fsoubelet Jan 15, 2025
079e5f7
Merge pull request #2 from SebastienJoly/api_changes
SebastienJoly Jan 15, 2025
db29a81
file rename
fsoubelet Jan 15, 2025
3754409
Merge pull request #3 from SebastienJoly/rename
fsoubelet Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions tests/test_ibs_equilibrium_emittances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import pytest
import xfields as xf
import xobjects as xo
import xtrack as xt
from ibs_conftest import XTRACK_TEST_DATA
from numpy.testing import assert_allclose

bunch_intensity = 6.2e9 # 1C bunch intensity

bessy3_dir = XTRACK_TEST_DATA / "bessy3"
line = xt.Line.from_json(str(bessy3_dir / "line.json"))
line.build_tracker(_context=xo.ContextCpu())
line.matrix_stability_tol = 1e-2
line.configure_radiation(model='mean')
line.compensate_radiation_energy_loss()

twiss = line.twiss(eneloss_and_damping=True)

@pytest.mark.parametrize('emittance_constraint', ['coupling', 'excitation'])
def test_ibs_emittance_constraints(emittance_constraint):

#######################################
# Equilibrium emittances calculations #
#######################################

emittance_coupling_factor = 0.02

time, emittances_x_list, emittances_y_list, emittances_z_list, T_x, T_y, T_z = xf.ibs.compute_emittance_evolution(
twiss, bunch_intensity,
emittance_coupling_factor=emittance_coupling_factor,
emittance_constraint=emittance_constraint,
)

if emittance_constraint == 'coupling':
# Check equilibrium emittance
assert_allclose(
emittances_x_list[-1],
twiss.eq_gemitt_x / (1 + emittance_coupling_factor) / (1 - T_x[-1] / 2 / twiss.damping_constants_s[0]),
rtol=5e-2
)
# Check equilibrium emittance
assert_allclose(
emittances_z_list[-1],
twiss.eq_gemitt_zeta / (1 - T_z[-1] / 2 / twiss.damping_constants_s[2]),
rtol=2e-2
)
# Check emittance coupling constraint
assert_allclose(
emittances_y_list[-1] / emittances_x_list[-1],
emittance_coupling_factor,
rtol=2e-2
)

else:
# Check equilibrium emittance
assert_allclose(
emittances_x_list[-1],
twiss.eq_gemitt_x / (1 - T_x[-1] / 2 / twiss.damping_constants_s[0]),
rtol=5e-2
)
# Check equilibrium emittance
assert_allclose(
emittances_z_list[-1],
twiss.eq_gemitt_zeta / (1 - T_z[-1] / 2 / twiss.damping_constants_s[2]),
rtol=2e-2
)
# Check emittance coupling constraint
assert_allclose(
emittances_y_list[-1] / emittances_x_list[-1],
emittance_coupling_factor,
)

@pytest.mark.parametrize('emittance_coupling_factor', [0.02, 0.1, 0.2])
def test_ibs_emittance_coupling_factor(emittance_coupling_factor):
"""
As the emittance coupling factor increases, the equilibrium emittance
cannot be compared anymore to the solution of the differential equation
describing the emittance evolution in presence of IBS and SR if a
constraint on the emittance is enforced.
"""
#######################################
# Equilibrium emittances calculations #
#######################################

time, emittances_x_list, emittances_y_list, emittances_z_list, T_x, T_y, T_z = xf.ibs.compute_emittance_evolution(
twiss, bunch_intensity,
emittance_coupling_factor=emittance_coupling_factor,
)

# Check equilibrium emittance
assert_allclose(
emittances_x_list[-1],
twiss.eq_gemitt_x / (1 + emittance_coupling_factor) / (1 - T_x[-1] / 2 / twiss.damping_constants_s[0]),
rtol=1e-1
)
# Check equilibrium emittance
assert_allclose(
emittances_z_list[-1],
twiss.eq_gemitt_zeta / (1 - T_z[-1] / 2 / twiss.damping_constants_s[2]),
rtol=2e-2
)
# Check emittance coupling constraint
assert_allclose(
emittances_y_list[-1] / emittances_x_list[-1],
emittance_coupling_factor,
)

@pytest.mark.parametrize('emittance_coupling_factor', [0.02, 0.1, 1.])
def test_ibs_emittance_no_constraint(emittance_coupling_factor):
"""
Without any emittance constraint, the equilibrium emittance becomes
almost identical to the solution of the differential equation describing
the emittance evolution in presence of IBS and SR.
"""
initial_emittances=(
twiss.eq_gemitt_x, emittance_coupling_factor*twiss.eq_gemitt_x,
twiss.eq_gemitt_zeta
)
emittance_constraint=""
natural_emittances=(
twiss.eq_gemitt_x, emittance_coupling_factor*twiss.eq_gemitt_x,
twiss.eq_gemitt_zeta
)

#######################################
# Equilibrium emittances calculations #
#######################################

time, emittances_x_list, emittances_y_list, emittances_z_list, T_x, T_y, T_z = xf.ibs.compute_emittance_evolution(
twiss, bunch_intensity,
initial_emittances=initial_emittances,
emittance_coupling_factor=emittance_coupling_factor,
emittance_constraint=emittance_constraint,
natural_emittances=natural_emittances,
)

# Check equilibrium emittance
assert_allclose(
emittances_x_list[-1],
twiss.eq_gemitt_x / (1 - T_x[-1] / 2 / twiss.damping_constants_s[0]),
rtol=2e-2
)
# Check equilibrium emittance
assert_allclose(
emittances_y_list[-1],
emittance_coupling_factor*twiss.eq_gemitt_x / (1 - T_y[-1] / 2 / twiss.damping_constants_s[1]),
rtol=2e-2
)
# Check equilibrium emittance
assert_allclose(
emittances_z_list[-1],
twiss.eq_gemitt_zeta / (1 - T_z[-1] / 2 / twiss.damping_constants_s[2]),
rtol=2e-2
)
2 changes: 2 additions & 0 deletions xfields/ibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
from ._analytical import BjorkenMtingwaIBS, IBSGrowthRates, NagaitsevIBS
from ._api import configure_intrabeam_scattering, get_intrabeam_scattering_growth_rates
from ._kicks import IBSAnalyticalKick, IBSKineticKick
from ._equilibrium import compute_emittance_evolution

__all__ = [
"BjorkenMtingwaIBS",
"configure_intrabeam_scattering",
"get_intrabeam_scattering_growth_rates",
"compute_emittance_evolution",
"IBSGrowthRates",
"IBSAnalyticalKick",
"IBSKineticKick",
Expand Down
Loading