0001 function [equil_magnetic,prho,pspsin,pspsinT,pp,li,jout,qpsi,ppsi] = build_helmex_equil_yp(nit,ppsi_in,ptot_in,pj_in,Rp_in,Zp_in,Bt_in,Ip_in,ap_in,R_in,Z_in,ntheta,display_opt)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 init = [0,1e-3,1e-7];
0040
0041 ppsi_init = abs(ppsi_in)/max(abs(ppsi_in));
0042 pj_init = pj_in;
0043 ptot_init = ptot_in;
0044
0045 if exist(['helmex77.',mexext]) == 3,
0046 [C2,C3,rho2m,Rout,Zout,rho,Vp,drhoor,qpsi,ppsi,ftra,Fdia,psiT,B2,invB2,Sp, ...
0047 rav,oor,drhoav,xshift,xrad,xell,xtriapos,xtrianeg,jout,ipout,pout, ...
0048 r2,oor2,r2tau2,drho2ob2,r3otau3,r3otau,BR,BZ,b,df2,dpr,kkbig,li, ...
0049 dimerc,drmerc,balcrit,frmode,ifail,nchi,cpsurf,radius,gem11,gem12,gem33,rspot,zspot,brspot,bzspot]= ...
0050 helmex77(ppsi_init,ptot_init,pj_init,Rp_in,abs(Bt_in),abs(Ip_in),2,ap_in,0,0,0,R_in,Z_in-Zp_in,init,0,0*ppsi_in,[],2);
0051
0052 if nit > 1,
0053
0054 disp('Start iteration for numerical consistency.')
0055
0056 pj_in = jout;
0057
0058
0059
0060 figure('name','HELENA convergence');
0061
0062 for it = 1:nit,
0063
0064 [C2,C3,rho2m,Rout,Zout,rho,Vp,drhoor,qpsi,ppsi,ftra,Fdia,psiT,B2,invB2,Sp, ...
0065 rav,oor,drhoav,xshift,xrad,xell,xtriapos,xtrianeg,jout,ipout,pout, ...
0066 r2,oor2,r2tau2,drho2ob2,r3otau3,r3otau,BR,BZ,b,df2,dpr,kkbig,li, ...
0067 dimerc,drmerc,balcrit,frmode,ifail,nchi,cpsurf,radius,gem11,gem12,gem33,rspot,zspot,brspot,bzspot]= ...
0068 helmex77(ppsi_init,ptot_init,pj_in,Rp_in,abs(Bt_in),abs(Ip_in),2,ap_in,0,0,0,R_in,Z_in-Zp_in,init,0,0*ppsi_in,[],2);
0069
0070 delta(it) = sum(abs(jout - pj_in))/max(abs(jout));
0071
0072 graph1D_jd([1:it],delta,0,1,'Iteration','Current convergence','HELENA',NaN,'','','-','none','b',2);hold on
0073
0074 pj_in = 0.7*jout + 0.3*pj_in;
0075 ppsi_in = ppsi;
0076 end
0077 else
0078 disp('WARNING: no numerical consistency performed.')
0079 end
0080
0081 [qe,me,mp,mn,e0,mu0] = pc_dke_yp;
0082 Ip_helmex = ipout.* max(xrad).*abs(Bt_in)/mu0*sign(Ip_in);
0083
0084 BPHI = (Fdia*ones(1,ntheta))./Rout*sign(Bt_in);
0085 BR(1,:) = 0;
0086 BZ(1,:) = 0;
0087 BR = BR*sign(Ip_in);
0088 BZ = BZ*sign(Ip_in);
0089 ppsi = ppsi*sign(Ip_in);
0090
0091 BP = sqrt(BR.*BR+BZ.*BZ);
0092
0093 if display_opt >= 1,
0094 disp('------------------------------------------------------');
0095 disp(['Magnetic field on axis guess (T) : ',num2str(Bt_in),', from HELMEX77 : ',num2str(BPHI(1,1))])
0096 disp(['Plasma current guess (MA) : ',num2str(Ip_in/1e6),', from HELMEX77 : ',num2str(Ip_helmex/1e6)])
0097 disp('------------------------------------------------------');
0098 end
0099
0100 ppsi = ppsi/2/pi;
0101 ppsin = ppsi'/ppsi(end);
0102 theta = linspace(0,2*pi,ntheta);
0103
0104
0105
0106 if display_opt >= 2,
0107
0108 figure('name','Separatrices'),
0109 [ax] = graph1D_jd(R_in - Rp_in,Z_in - Zp_in,0,0,'R - R_{p} (m)','Z - Z_{p} (m)','HELENA separatrix',NaN,'','','-','none','b',2);
0110 [ax] = graph1D_jd(Rout(end,:) - Rp_in,Zout(end,:) - Zp_in,0,0,'R - R_{p} (m)','Z - Z_{p} (m)','HELENA separatrix',NaN,'','','--','none','r',2);
0111 legend('Guess','HELENA');
0112 [ax] = graph1D_jd(R_in(1,1) - Rp_in,Z_in(1,1) - Zp_in,0,0,'R - R_{p} (m)','Z - Z_{p} (m)','HELENA separatrix',NaN,'','','none','+','b',2);
0113 [ax] = graph1D_jd(Rout(end,1) - Rp_in,Zout(end,1) - Zp_in,0,0,'R - R_{p} (m)','Z - Z_{p} (m)','HELENA separatrix',NaN,'','','none','*','r',2);
0114 [ax] = graph1D_jd(Rout(1,1) - Rp_in,Zout(1,1) - Zp_in,0,0,'R - R_{p} (m)','Z - Z_{p} (m)','HELENA separatrix',NaN,'','','none','+','r',2);
0115 axis('equal')
0116
0117 figure('name','HELENA separatrix')
0118 [ax] = graph1D_jd(Rout(end,:),Zout(end,:) + Zp_in,0,0,'R (m)','Z (m)','HELENA separatrix',NaN,'','','--','none','r',2);
0119 [ax] = graph1D_jd(Rout(end,1),Zout(end,1) + Zp_in,0,0,'R (m)','Z (m)','HELENA separatrix',NaN,'','','none','*','r',2);
0120 [ax] = graph1D_jd(Rout(1,1),Zout(end,1) + Zp_in,0,0,'R (m)','Z (m)','HELENA separatrix',NaN,'','','none','+','r',2);
0121 axis('equal')
0122 end
0123
0124 equil_magnetic.psi_apRp = ppsi*(Rout(end,1) - Rp_in)/Rout(1,1);
0125 equil_magnetic.theta = theta;
0126 equil_magnetic.ptx = Rout - Rout(1,1);
0127 equil_magnetic.pty = Zout - Zp_in;
0128 equil_magnetic.ptBx = BR;
0129 equil_magnetic.ptBy = BZ;
0130 equil_magnetic.ptBPHI = BPHI;
0131 equil_magnetic.Rp = Rout(1,1);
0132 equil_magnetic.Zp = Zp_in;
0133 equil_magnetic.ap = Rout(end,1) - Rout(1,1);
0134
0135 equil_magnetic.helmex.qpsi = qpsi;
0136 equil_magnetic.helmex.ppsi = ppsi;
0137 equil_magnetic.helmex.jout = jout;
0138 equil_magnetic.helmex.li = li;
0139
0140
0141
0142 prho = equil_magnetic.ptx(:,1).'/equil_magnetic.ptx(end,1);
0143
0144 pq_h = (qpsi(1:end-1) + qpsi(2:end))/2;
0145 pdpsin = diff(ppsin);
0146 ppsiT = [0,cumsum(pq_h'.*pdpsin)];
0147 pspsinT = sqrt(ppsiT/ppsiT(end));
0148
0149 pspsin = sqrt(ppsin);
0150
0151 pp = pout;
0152 else
0153 equil_magnetic = [];
0154 prho = [];
0155 pspsin = [];
0156 pspsinT = [];
0157 pp = [];
0158 li = [];
0159 disp([' ---> WARNING: The mexfile helmex77.',mexext,' does not exists ! Compile it for the computer you are using...']);
0160 end