-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified radiation integrals in wigglers (#188)
* Wiggler field, wiggler integrals * Correct global variable name (#187) * corrected Bwig * Bug fixes * Bug fixes * Bug fixes * Updated atsummary and removed debug info * Analytical I3 * amat, atradon * Fixed missing 'beta' in sync tune and bunch length * Fixed missing 'beta' in sync tune and bunch length * Removed temp files * Fix import of wigglers from matlab * Check overvoltage < 1 * Wiggler radiation in python * Remove useless import, bug fix * Improved docstring * vector ordering in amat * fix coupled tunes * Handle wigglers in atradon and atradoff * Ignore wigglers using DriftPass Co-authored-by: Laurent Farvacque <laurent.farvacque@gmail.com>
- Loading branch information
Showing
13 changed files
with
381 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
function [I1,I2,I3,I4,I5] = WigglerRadiation(ring,lindata) | ||
%WIGGLERRADIATION Compute the radiation integrals in wigglers | ||
% | ||
%[I1,I2,I3,I4,I5] = WIGGLERRADIATION(RING,LINDATA) | ||
% | ||
%RING Lattice structure | ||
%LINDATA Output of atlinopt for all lattice elements | ||
% | ||
%WigglerRadiation computes the radiation integrals for all wigglers with | ||
%the following approximations: | ||
% | ||
%- The self-induced dispersion is neglected in I4 and I5, but is is used as | ||
% a lower limit for the I5 contribution | ||
% | ||
% I1, I2 are integrated analytically | ||
% I3 is integrated analytically for a single harmonic, numerically otherwise | ||
|
||
nstep=60; | ||
e_mass=PhysConstant.electron_mass_energy_equivalent_in_MeV.value*1e6; % eV | ||
cspeed = PhysConstant.speed_of_light_in_vacuum.value; % m/s | ||
|
||
iswiggler=@(elem) strcmp(elem.Class,'Wiggler') && ~strcmp(elem.PassMethod,'DriftPass'); | ||
wigglers=cellfun(iswiggler, ring); | ||
if any(wigglers) | ||
energy=unique(atgetfieldvalues(ring(wigglers),'Energy')); | ||
if length(energy) > 1 | ||
error('AT:NoEnergy','Energy field not equal for all elements'); | ||
end | ||
Brho=sqrt(energy*energy - e_mass*e_mass)/cspeed; | ||
vini=lindata([wigglers;false])'; | ||
[di1,di2,di3,di4,di5]=cellfun(@wigrad,ring(wigglers),num2cell(vini)); | ||
I1=sum(di1); | ||
I2=sum(di2); | ||
I3=sum(di3); | ||
I4=sum(di4); | ||
I5=sum(di5); | ||
else | ||
[I1,I2,I3,I4,I5]=deal(0); | ||
end | ||
|
||
function [di1,di2,di3,di4,di5]=wigrad(elem,dini) | ||
le=elem.Length; | ||
alphax0=dini.alpha(1); | ||
betax0=dini.beta(1); | ||
gammax0=(alphax0.*alphax0+1)./betax0; | ||
eta0 = dini.Dispersion(1); | ||
etap0 = dini.Dispersion(2); | ||
H0=gammax0*eta0*eta0 + 2*alphax0*eta0*etap0 + betax0*etap0*etap0; | ||
avebetax=betax0+alphax0*le+gammax0*le*le/3; | ||
|
||
kw=2*pi/elem.Lw; | ||
rhoinv=elem.Bmax/Brho; | ||
coefh=elem.By(2,:)*rhoinv; | ||
coefv=elem.Bx(2,:)*rhoinv; | ||
coef2=[coefh coefv]; | ||
if length(coef2)==1 % Analytical I3 | ||
di3=coef2^3*4*le/3/pi; | ||
else % Numerical I3 | ||
[bx,bz]=Baxis(elem,linspace(0,elem.Lw,nstep+1)); | ||
B2=bx.*bx+bz.*bz; | ||
rinv=sqrt(B2)/Brho; | ||
di3=trapz(rinv.^3)*le/nstep; | ||
end | ||
di2=elem.Length*(coefh*coefh'+coefv*coefv')/2; | ||
di1=-di2/kw/kw; | ||
di4=0; | ||
if ~isempty(coefh) | ||
d5lim=4*avebetax*le*coefh(1)^5/15/pi/kw/kw; | ||
else | ||
d5lim = 0; | ||
end | ||
di5=max(H0*di3,d5lim); | ||
% fprintf('%s\t%e\t%e\t%e\t%e\t%e\t(%e,%e,%e)\n',elem.FamName,di1,di2,di3,di4,di5,d5lim,H0*di3,dini.Dispersion(1)); | ||
% avebetaz=dini.beta(2)+dini.alpha(2)*le+(1+dini.alpha(2)^2)/dini.beta(2)*le*le/3; | ||
% dnuz=avebetaz*di2/8/pi; | ||
% fprintf('%s\t%e\t%e\n',elem.FamName,dnuz,avebetaz) | ||
end | ||
|
||
function [bx,bz] = Baxis(wig,s) | ||
%Bwig Compute the field on the axis of a generic wiggler | ||
% | ||
%The field of an horizontal wiggler is represented by a sum of harmonics, | ||
%each being described by a 6x1 column in a matrix By such as: | ||
% | ||
% Bz/Bmax = -By2 * cos(By5*kw*s + By6) | ||
% | ||
%The field of an vertical wiggler is represented by a sum of harmonics, | ||
%each being described by a 6x1 column in a matrix Bx such as: | ||
% | ||
% Bx/Bmax = Bx2 * cos(Bx5*kw*s + Bx6) | ||
|
||
kw=2*pi/wig.Lw; | ||
Bmax=wig.Bmax; | ||
kws=kw*s; | ||
[bxh,bzh]=cellfun(@harmh,num2cell(wig.By,1),'UniformOutput',false); | ||
[bxv,bzv]=cellfun(@harmv,num2cell(wig.Bx,1),'UniformOutput',false); | ||
bx=sum(cat(3,bxh{:},bxv{:}),3); | ||
bz=sum(cat(3,bzh{:},bzv{:}),3); | ||
|
||
function [bx,bz]=harm(pb) | ||
bz=-Bmax*pb(2)*cos(pb(5)*kws+pb(6)); | ||
bx=zeros(size(kws)); | ||
end | ||
function [bx,bz]=harmh(pb) | ||
[bx,bz]=harm(pb); | ||
end | ||
function [bx,bz]=harmv(pb) | ||
[bz,fz]=harm(pb); | ||
bx=-fz; | ||
end | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.