Skip to content

Commit 28e8f07

Browse files
committed
Initial commit of raycon.
1 parent 71d2765 commit 28e8f07

19 files changed

+4787
-0
lines changed

adjust_disp_m.m

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
function y_ant = adjust_disp_m(y,m)
2+
global plasma %cnst
3+
4+
% ----- Adjusted position & wave vector in cylindrical coordinates -----------
5+
r=y(1); z=y(2);
6+
kr=y(3); kz=y(4); % starting wave vector
7+
rho=sqrt((r-plasma.r0).^2+z.^2);
8+
theta=atan2(plasma.r0-r,-z)+pi/2;
9+
10+
krho_old=-sqrt(kr^2 + kz^2 -(m/rho)^2); % assume wave starts out going in
11+
%krho=+sqrt(kr^2 + kz^2 -(m/rho)^2);
12+
13+
% Want to adjust kr and kz so that, for given m, k_phi, the initial
14+
% condtions are on the dispersion surface.
15+
% m = function argument = rho*k_theta
16+
17+
%kf = plasma.kant(2);
18+
19+
%y0=[r,z,kr,(kr*sin(theta)+(m/rho))/cos(theta)];
20+
21+
% kz = (kr*sin(theta)+(m/rho))/cos(theta)
22+
% f = @(krho) dispersion([r,z,...
23+
% krho*cos(theta)-(m/rho)*sin(theta),...
24+
% -(krho*sin(theta)+(m/rho)*cos(theta))],'Dsp');
25+
% krho = fzero(f,krho);
26+
27+
f = @(krho) disp_eig([r,z,...
28+
krho*cos(theta)-(m/rho)*sin(theta),...
29+
-(krho*sin(theta)+(m/rho)*cos(theta)), reshape(eye(4),1,16)].','Dsp');
30+
% f = @(krho) disp_eig([r,z,...
31+
% krho*cos(theta)-(m/rho)*sin(theta),...
32+
% -(krho*sin(theta)+(m/rho)*cos(theta)), zeros(1,16)].','Dsp');
33+
krho_new = fzero(f,krho_old);
34+
35+
%kz = (kr*sin(theta)+(m/rho))/cos(theta);
36+
37+
y_ant = [r,z,krho_new*cos(theta)-(m/rho)*sin(theta),...
38+
-(krho_new*sin(theta)+(m/rho)*cos(theta))].';
39+
40+
% ----- Wave vector and refraction index -------------------------------------
41+
% kn=kr.*ener +kf.*enef +kz.*enez;
42+
% kb=kr.*eber +kf.*ebef +kz.*ebez;
43+
% kp=kr.*eper +kf.*epef +kz.*epez;
44+
% T =[ener enef enez;...
45+
% eber ebef ebez;...
46+
% eper epef epez];
47+
% k_cart = T^(-1) * [kn;kb;kp];
48+
end
49+

calcFlux.m

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function plasma = calcFlux(plasma)
2+
3+
%% Calculate the flux surface coordinates ('mesh' and 'boundary')
4+
s=0.0001:(.999/(plasma.NS-1)):1.; % radial mesh
5+
theta=0:2*pi/plasma.NT:2*pi; % poloidal mesh
6+
plasma.r = zeros(plasma.NS,plasma.NT+1);
7+
plasma.z = zeros(plasma.NS,plasma.NT+1);
8+
for kk=1:plasma.NS
9+
si=s(kk).*ones(size(theta)); % flux surfaces
10+
[rho,plasma.r(kk,:),plasma.z(kk,:)]=mapFlux(si,theta); % coordinates
11+
end;
12+
13+
plasma.Rho = sqrt((plasma.r-plasma.r0).^2 +plasma.z.^2);
14+
plasma.Theta = atan2(-plasma.z,(plasma.r-plasma.r0));
15+
16+

cgamma.m

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
function out = cgamma(z)
2+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3+
% Complex gamma function for -10<Re(z)<10, 10<Im(z)<10
4+
%
5+
% Tested 12 digits accuracy for
6+
% cgamma([0 .5+.5i -.5+.5i -.5-.5i .5-.5i 1 1+i i -1+i -1 -1-i -i 1-i]')
7+
%
8+
% A. JAUN, Numerical Analysis, KTH, 100 44 Stockholm, Sweden
9+
% A.N. KAUFMAN, Lawrence Berkeley Laboratory, Berkeley, CA 94720, USA
10+
% E.R. TRACY, College of William & Mary, Williamsburg, VA 23187-8795, USA
11+
%
12+
% Documented under "http://www.nada.kth.se/~jaun"
13+
%
14+
% (C) Version 7.0, 14-Aug-2006. All Rights Reserved.
15+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16+
%
17+
x=real(z); y=imag(z); n=prod(size(x));
18+
%
19+
% ----- Map to domain of asymptotic expansion
20+
%
21+
for k=1:n
22+
if (y(k)<0)
23+
z(k)=conj(z(k));
24+
end
25+
end
26+
%
27+
lnCgamma=zeros(size(x));
28+
for k=1:n
29+
for m=1:floor(9-x)
30+
lnCgamma(k)=lnCgamma(k)-log(z(k)); z(k)=z(k)+1;
31+
end
32+
end
33+
%
34+
% ----- First compute log(cgamma) from expansion for 9<Re(z)<10, 0<Im(z)<10
35+
%
36+
zm =1./z; zm1 =zm; zm2=zm1.*zm1; % Avoid power function
37+
zm=zm.*zm2; zm3 =zm;
38+
zm=zm.*zm2; zm5 =zm;
39+
zm=zm.*zm2; zm7 =zm;
40+
zm=zm.*zm2; zm9 =zm;
41+
zm=zm.*zm2; zm11=zm;
42+
zm=zm.*zm2; zm13=zm;
43+
zm=zm.*zm2; zm15=zm;
44+
%
45+
lnCgamma=lnCgamma -zm15*(3617./122400); % Add series in reverse order
46+
lnCgamma=lnCgamma +zm13/156;
47+
lnCgamma=lnCgamma -zm11*(691./360360);
48+
lnCgamma=lnCgamma +zm9 /1188;
49+
lnCgamma=lnCgamma -zm7 /1680;
50+
lnCgamma=lnCgamma +zm5 /1260;
51+
lnCgamma=lnCgamma -zm3 /360;
52+
lnCgamma=lnCgamma +zm1 /12 +(z-0.5).*log(z) -z +0.5*log(2*pi);
53+
%
54+
for k=1:n
55+
% if (y(k)>0) % Don't understand why not <0
56+
if (y(k)<0) % modified by Steve Richardson
57+
lnCgamma(k)=conj(lnCgamma(k));
58+
end
59+
end
60+
%
61+
% ----- Take exponential
62+
%
63+
out = exp(lnCgamma);

0 commit comments

Comments
 (0)