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

Energy loss tracking #393

Merged
merged 4 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 11 additions & 4 deletions pyat/at/physics/energy_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,16 @@ def tracking(ring):
sextupole_pass=None,
octupole_pass=None,
copy=True)
o0 = numpy.zeros(6)
o6 = numpy.squeeze(lattice_pass(ringtmp, o0, refpts=len(ringtmp)))
return -o6[4] * ring.energy

o6 = numpy.squeeze(lattice_pass(ringtmp, numpy.zeros(6), refpts=len(ringtmp)))
if numpy.isnan(o6[0]):
dp = 0
for e in ringtmp:
ot = numpy.squeeze(lattice_pass([e], numpy.zeros(6)))
dp += -ot[4] * ring.energy
return dp
else:
return -o6[4] * ring.energy

if isinstance(method, str):
method = ELossMethod[method.upper()]
Expand Down Expand Up @@ -150,7 +157,7 @@ def deq(x):
return timelag, ts


def set_cavity_phase(ring, method=ELossMethod.INTEGRAL,
def set_cavity_phase(ring, method=ELossMethod.TRACKING,
refpts=None, cavpts=None, copy=False):
"""
Adjust the TimeLag attribute of RF cavities based on frequency,
Expand Down
8 changes: 6 additions & 2 deletions pyat/at/physics/radiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from at.tracking import lattice_pass
from at.physics import find_orbit6, find_m66, find_elem_m66
from at.physics import find_mpole_raddiff_matrix, get_tunes_damp
from at.physics import ELossMethod

__all__ = ['ohmi_envelope', 'get_radiation_integrals', 'quantdiffmat',
'gen_quantdiff_elem', 'tapering']
Expand Down Expand Up @@ -397,21 +398,24 @@ def tapering(ring, multipoles=True, niter=1, **kwargs):

KEYWORDS
multipoles=True scale all multipoles
method Method for energy loss computation
(see get_energy_loss)
niter=1 number of iteration
XYStep=1.0e-8 transverse step for numerical computation
DPStep=1.0E-6 momentum deviation used for computation of orbit6
"""

xy_step = kwargs.pop('XYStep', DConstant.XYStep)
dp_step = kwargs.pop('DPStep', DConstant.DPStep)
method = kwargs.pop('method', ELossMethod.TRACKING)
dipoles = get_refpts(ring, Dipole)
b0 = get_value_refpts(ring, dipoles, 'BendingAngle')
k0 = get_value_refpts(ring, dipoles, 'PolynomB', index=0)
ld = get_value_refpts(ring, dipoles, 'Length')

for i in range(niter):
_, o6 = find_orbit6(ring, refpts=range(len(ring)+1),
XYStep=xy_step, DPStep=dp_step)
XYStep=xy_step, DPStep=dp_step, method=method)
dpps = (o6[dipoles, 4] + o6[dipoles+1, 4]) / 2
set_value_refpts(ring, dipoles, 'PolynomB', b0/ld*dpps+k0*(1+dpps),
index=0)
Expand All @@ -420,7 +424,7 @@ def tapering(ring, multipoles=True, niter=1, **kwargs):
mults = get_refpts(ring, Multipole)
k0 = get_value_refpts(ring, dipoles, 'PolynomB', index=0)
_, o6 = find_orbit6(ring, refpts=range(len(ring)+1),
XYStep=xy_step, DPStep=dp_step)
XYStep=xy_step, DPStep=dp_step, method=method)
dpps = (o6[mults, 4] + o6[mults+1, 4]) / 2
for dpp, el in zip(dpps, ring[mults]):
el.PolynomB *= 1+dpp
Expand Down