0001 function [ppsin,ppsi_apRp,theta,x,y,Bx,By,BPHI,pBpp,pq_Rpap,pj,pmag,Ip_test,prho,pspsin,pspsinT,ppsiT] = idealequilcyl_yp(ap,Rp,Zp,Bt,Ip,qmin_Rpap,eq,qopt,npsi,ntheta,lambda)
0002
0003
0004
0005
0006
0007 if nargin < 11,
0008 lambda = NaN;
0009 end
0010
0011 if nargin < 10,
0012 ntheta = 65;
0013 end
0014
0015 if nargin < 9,
0016 npsi = 101;
0017 end
0018
0019 if nargin < 8,
0020 qopt = 0;
0021 end
0022
0023 [qe,me,mp,mn,e0,mu0] = pc_dke_yp;
0024
0025 Bpa = mu0*Ip*1e6/(2*pi*ap);
0026 qmax_Rpap = abs(Bt/Bpa);
0027
0028 prho = linspace(0,1,npsi);
0029 theta = linspace(0,2*pi,ntheta);
0030
0031 Xrho = repmat(prho',[1,ntheta]);
0032 Xtheta = repmat(theta,[npsi,1]);
0033
0034 x = ap*Xrho.*cos(Xtheta);
0035 y = ap*Xrho.*sin(Xtheta);
0036
0037 if isempty(lambda) || isnan(lambda),
0038 if qopt == 2,
0039 if eq >= 1,
0040 pq_Rpap = qmax_Rpap*prho.^2./(1.0 - (1.0 - prho.^2).^(1.0 + eq));
0041 pq_Rpap(1) = qmax_Rpap/(1.0 + eq);
0042 pdq_Rpap = 2*pq_Rpap.*(1.0 - pq_Rpap*(eq + 1.0).*(1.0 - prho.^2)/qmax_Rpap)./prho;
0043 pdq_Rpap(1) = 0;
0044 else
0045 error('Error: eq >= 1.0 for qopt = 2 !');
0046 end
0047 elseif qopt == 1,
0048 pq_Rpap = (qmax_Rpap - qmin_Rpap)*prho.^eq + qmin_Rpap;
0049 pdq_Rpap = eq*(qmax_Rpap - qmin_Rpap)*prho.^(eq-1);
0050 elseif qopt == 0,
0051 pq_Rpap = qmax_Rpap*ones(1,npsi);
0052 pdq_Rpap = zeros(1,npsi);
0053 else
0054 error('This safety factor model is not recognized.')
0055 end
0056
0057 pBphi = Bt*ones(size(prho));
0058 pBpp = sign(Bpa)*prho*abs(Bt)./pq_Rpap;
0059 else
0060 pq_Rpap = prho.*besselj(0,lambda*prho)./besselj(1,lambda*prho);
0061 pdq_Rpap = besselj(0,lambda*prho)./besselj(1,lambda*prho)...
0062 - lambda*prho - besselj(0,lambda*prho)./besselj(1,lambda*prho).^2.*(besselj(0,lambda*prho) - lambda*prho.*besselj(2,lambda*prho));
0063
0064 pBphi = Bt*besselj(0,lambda*prho);
0065 pBpp = Bt*besselj(1,lambda*prho);
0066
0067 ppsi_apRp_theoric = ap*ap*Bt*(1.0 - besselj(0,lambda*prho))/lambda;
0068 end
0069
0070
0071
0072 XBpp = repmat(pBpp',[1,ntheta]);
0073
0074 spBpp = triu(repmat((pBpp(1:npsi-1) + pBpp(2:npsi))'/2,[1,npsi-1]));
0075 pdprho = diff(prho);
0076 ppsi_apRp = [0,ap^2*integral_dke_jd(pdprho,spBpp,1)'];
0077 ppsin = ppsi_apRp/max(ppsi_apRp);
0078
0079 pspsin = sqrt(ppsin);
0080
0081 ppsiT = pi*Bt*ap^2*prho.^2;
0082 ppsinT = ppsiT/ppsiT(end);
0083 pspsinT = sqrt(ppsinT);
0084
0085 Upsilon = 1 + x/Rp;
0086
0087 Bx = -XBpp.*sin(Xtheta)./Upsilon;
0088 By = XBpp.*cos(Xtheta)./Upsilon;
0089 BPHI = repmat(pBphi',[1,ntheta])./Upsilon;
0090
0091 pj = (Bt/ap/mu0).*(2./pq_Rpap - pdq_Rpap.*prho./pq_Rpap.^2);
0092
0093 for ii = 1:length(prho),
0094 pIp(ii) = 2*pi*trapz_dke_yp([prho(1:ii)',prho(1:ii)'.*pj(1:ii)'])*ap*ap;
0095 pmag(ii) = -trapz_dke_yp([prho(1:ii)',pBpp(1:ii)'.*pj(1:ii)'])*ap;
0096 end
0097 pIp(2) = pIp(1);
0098 pmag(2) = pmag(1);
0099 Ip_test = pIp(end)/1e6;
0100 pmag = (pmag - pmag(end))/qe/1000;
0101