Skip to content

Commit

Permalink
Remove the dependency of find_orbit6 on the harmonic number (#318)
Browse files Browse the repository at this point in the history
* python: remove the dependence of find_orbit6 on harmonic number

* Matlab: remove the dependence of findorbit6 on harmonic number
  • Loading branch information
lfarv authored Oct 20, 2021
1 parent 6e595a0 commit c4fb929
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
12 changes: 3 additions & 9 deletions atmat/atphysics/Orbit/xorbit_6.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,15 @@
[Ri,varargs]=getargs(varargs,Ri,'check',@(arg) isnumeric(arg) && isequal(size(arg),[6,1])); %#ok<ASGLU>

cavities=RING(atgetcells(RING,'Frequency'));

if isempty(cavities)
error('AT:NoFrequency', 'The lattice has no Cavity element')
end
Frf=min(atgetfieldvalues(cavities,'Frequency'));

L0 = findspos(RING,length(RING)+1); % design length [m]
C0 = PhysConstant.speed_of_light_in_vacuum.value; % speed of light [m/s]

T0 = L0/C0;

Frf = unique(atgetfieldvalues(cavities,'Frequency'));
HarmNumber = unique(atgetfieldvalues(cavities,'HarmNumber'));
if length(Frf) > 1 || length(HarmNumber) > 1
error('AT:NoFrequency','RF cavities are not identical');
end
T0 = L0/C0; % Revolution period [s]
HarmNumber = round(Frf*L0/C0);

if isempty(Ri)
Vcell=sum(atgetfieldvalues(cavities,'Voltage'));
Expand Down
21 changes: 14 additions & 7 deletions pyat/at/physics/orbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,27 @@ def find_sync_orbit(ring, dct=0.0, refpts=None, dp=None, orbit=None,

def _orbit6(ring, cavpts=None, guess=None, keep_lattice=False, **kwargs):
"""Solver for 6D motion"""

def iscavity(elem):
return isinstance(elem, elements.RFCavity) and \
elem.PassMethod.endswith('CavityPass')

convergence = kwargs.pop('convergence', DConstant.OrbConvergence)
max_iterations = kwargs.pop('max_iterations', DConstant.OrbMaxIter)
xy_step = kwargs.pop('XYStep', DConstant.XYStep)
dp_step = kwargs.pop('DPStep', DConstant.DPStep)
method = kwargs.pop('method', ELossMethod.TRACKING)

# Get revolution period
l0 = get_s_pos(ring, len(ring))
cavities = [elm for elm in ring if isinstance(elm, elements.RFCavity)]
if len(cavities) == 0:
l0 = get_s_pos(ring, len(ring))[0]
# Get the main RF frequency (the lowest)
try:
f_rf = min(elm.Frequency for elm in ring if iscavity(elm))
except ValueError:
raise AtError('No cavity found in the lattice.')

f_rf = cavities[0].Frequency
harm_number = cavities[0].HarmNumber
# gamma = self.energy / self.particle.mass
# beta = math.sqrt(1.0 - 1.0 / gamma / gamma)
# h = round(fmin*l0/beta/clight)
harm_number = round(f_rf*l0/clight)

if guess is None:
_, dt = get_timelag_fromU0(ring, method=method, cavpts=cavpts)
Expand Down

0 comments on commit c4fb929

Please sign in to comment.