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

Fix on atfastring #314

Merged
merged 7 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions atmat/lattice/atfastring.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

xm=0.001;
zm=0.0005;
GLOBVAL.E0=atenergy(ring0);
[GLOBVAL.E0,nper]=atenergy(ring0);
[lindata,tunes,xsi]=atlinopt(ring0,0); %#ok<ASGLU>
gamma=(1+lindata.alpha.*lindata.alpha)./lindata.beta;

Expand All @@ -66,7 +66,7 @@
orbit4=zeros(6,sum(markers));
orbit4(1:5,:)=findsyncorbit(ring,0,markers);
orbit4=num2cell(orbit4,1);
r1=detuning(ring,gamma,xm,zm,orbit4(:,1));
r1=detuning(ring,gamma,xm,zm,orbit4(:,1))/nper;

orbit6=num2cell(findorbit6(ringrad,markers),1);

Expand Down
16 changes: 5 additions & 11 deletions pyat/at/physics/fastring.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
Functions relating to fast_ring
"""
import numpy
import warnings
from at.lattice import RFCavity, Marker, Drift, Lattice, get_refpts
from at.lattice import RFCavity, Marker, Lattice, get_cells, checkname
from at.lattice import get_elements
from at.physics import find_orbit
from at.physics import gen_m66_elem, gen_detuning_elem, gen_quantdiff_elem
import copy

Expand Down Expand Up @@ -41,12 +39,9 @@ def _rearrange(ring, split_inds=[]):

def _fring(ring, split_inds=[], detuning_elem=None):
all_rings, merged_ring = _rearrange(ring, split_inds=split_inds)
ibegs = get_refpts(merged_ring, 'xbeg')
iends = get_refpts(merged_ring, 'xend')
markers = numpy.sort(numpy.concatenate((ibegs, iends)))
with warnings.catch_warnings():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is fine, however we generally use fond_orbit_sync for this kind of calculation without radiation. This is why I had suppressed the warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but in this case, dct=0 is strictly equivalent to dp=0 : it's the on-momentum orbit. And it's the default behaviour.

warnings.simplefilter('ignore')
_, orbit = merged_ring.find_orbit(dct=0.0, refpts=markers)
ibegs = get_cells(merged_ring, checkname('xbeg'))
iends = get_cells(merged_ring, checkname('xend'))
_, orbit = merged_ring.find_orbit(refpts=ibegs | iends)
if detuning_elem is None:
detuning_elem = gen_detuning_elem(merged_ring, orbit[-1])
else:
Expand All @@ -68,8 +63,7 @@ def _fring(ring, split_inds=[], detuning_elem=None):
fastring.append(qd_elem)
except:
pass
fastring = Lattice(fastring, energy=ring.energy)
fastring.radiation
fastring = Lattice(fastring, **vars(ring))
return fastring


Expand Down
3 changes: 1 addition & 2 deletions pyat/at/physics/nonlinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,10 @@ def gen_detuning_elem(ring, orbit=None):
xsi = get_chrom(ring.radiation_off(copy=True))
r0, r1, x, q_dx, y, q_dy = detuning(ring.radiation_off(copy=True),
xm=1.0e-4, ym=1.0e-4, npoints=3)
rp = ring.periodicity
nonlin_elem = Element('NonLinear', PassMethod='DeltaQPass',
Betax=lindata0.beta[0], Betay=lindata0.beta[1],
Alphax=lindata0.alpha[0], Alphay=lindata0.alpha[1],
Qpx=xsi[0], Qpy=xsi[1],
A1=r1[0][0]*rp, A2=r1[0][1]*rp, A3=r1[1][1]*rp,
A1=r1[0][0], A2=r1[0][1], A3=r1[1][1],
T1=-orbit, T2=orbit)
return nonlin_elem
28 changes: 14 additions & 14 deletions pyat/test_matlab/test_cmp_physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_fastring(engine, lattices):
ring_ml, ringrad_ml = engine.pyproxy('atfastring',
ml_lattice, nargout=2)
# Comparison
for r, rml, idq in zip([ring, ringrad], [ring_ml, ringrad_ml], [3, 4]):
for r, rml in zip([ring, ringrad], [ring_ml, ringrad_ml]):
assert_close(r[0].Frequency, rml[1]['Frequency'], rtol=1.0e-20)
assert_close(r[0].Voltage, rml[1]['Voltage'], rtol=1.0e-20)
assert_close(r[1].I2, rml[2]['I2'], rtol=1.0e-20)
Expand All @@ -118,21 +118,21 @@ def test_fastring(engine, lattices):
rtol=1.0e-8, atol=1.0e-11)
assert_close(r[1].T2, numpy.squeeze(rml[2]['T2']),
rtol=1.0e-8, atol=1.0e-11)
assert_close(r[idq-1].A1, rml[idq]['A1'], rtol=0.02)
assert_close(r[idq-1].A2, rml[idq]['A2'], rtol=0.02)
assert_close(r[idq-1].A3, rml[idq]['A3'], rtol=0.02)
assert_close(r[idq-1].Alphax, rml[idq]['Alphax'], rtol=1.0e-5)
assert_close(r[idq-1].Alphay, rml[idq]['Alphay'], rtol=1.0e-6)
assert_close(r[idq-1].Betax, rml[idq]['Betax'], rtol=1.0e-12)
assert_close(r[idq-1].Betay, rml[idq]['Betay'], rtol=1.0e-11)
assert_close(r[idq-1].Qpx, rml[idq]['Qpx'], rtol=1.0e-5)
assert_close(r[idq-1].Qpy, rml[idq]['Qpy'], rtol=1.0e-5)
assert_close(r[idq-1].T1, numpy.squeeze(rml[idq]['T1']),
assert_close(r[2].A1, rml[-1]['A1'], rtol=0.02)
assert_close(r[2].A2, rml[-1]['A2'], rtol=0.02)
assert_close(r[2].A3, rml[-1]['A3'], rtol=0.02)
assert_close(r[2].Alphax, rml[-1]['Alphax'], rtol=1.0e-5)
assert_close(r[2].Alphay, rml[-1]['Alphay'], rtol=1.0e-6)
assert_close(r[2].Betax, rml[-1]['Betax'], rtol=1.0e-10)
assert_close(r[2].Betay, rml[-1]['Betay'], rtol=1.0e-10)
assert_close(r[2].Qpx, rml[-1]['Qpx'], rtol=1.0e-5)
assert_close(r[2].Qpy, rml[-1]['Qpy'], rtol=1.0e-5)
assert_close(r[2].T1, numpy.squeeze(rml[-1]['T1']),
rtol=1.0e-8, atol=1.0e-11)
assert_close(r[idq-1].T2, numpy.squeeze(rml[idq]['T2']),
assert_close(r[2].T2, numpy.squeeze(rml[-1]['T2']),
rtol=1.0e-8, atol=1.0e-11)
if idq == 4:
assert_close(r[2].Lmatp, rml[3]['Lmatp'],
if len(r) >= 4:
assert_close(r[3].Lmatp, rml[-2]['Lmatp'],
rtol=0.02, atol=1.0e-10)


Expand Down