0001 function [xTe,Efield,J,pfM,pf0,pfbM,savedata,trbetath] = frundke_quench(id_simul,j0,betath0,betathf,wpr,Zi,opt,varargin)
0002
0003 [dkepath,equil0,dkeparam,dkedisplay,waves] = fprep_runaway(wpr,Zi,opt,varargin{:});
0004
0005 [~,~,~,~,~,~,~,mc2] = pc_dke_yp;
0006
0007
0008
0009
0010
0011 equil0.pTe = betath0^2*mc2*ones(size(equil0.pTe));
0012
0013 dkeparam0 = dkeparam;
0014
0015 dkeparam0.tn = NaN;
0016 dkeparam0.dtn = NaN;
0017 dkeparam0.opt_struct = 2;
0018
0019 if isempty(waves),
0020
0021 dkeparam0.Jtot_ohm = j0;
0022
0023 dkeparam0.nit_ohm = opt.maxiconv;
0024 dkeparam0.tol_ohm = opt.tol;
0025 dkeparam0.efield_ohm = opt.efield0;
0026
0027 [Znorm0,Zcurr0,ZP00,dke_out0,radialDKE0,equilDKE0,momentumDKE0,gridDKE0,Zmomcoef0,Zbouncecoef0,Zmripple0,mksa0,XXsinksource0] = main_dke_yp(id_simul,dkepath,equil0,dkeparam0,dkedisplay,'','','','',[],[]);
0028
0029 else
0030
0031 for it_wave = 1:opt.maxiconv,
0032
0033 [Znorm0,Zcurr0,ZP00,dke_out0,radialDKE0,equilDKE0,momentumDKE0,gridDKE0,Zmomcoef0,Zbouncecoef0,Zmripple0,mksa0,XXsinksource0] = main_dke_yp(id_simul,dkepath,equil0,dkeparam0,dkedisplay,'',waves,'','',[],[]);
0034
0035 Jtot_rf = Zcurr0.x_0_fsav*mksa0.j_ref;
0036
0037 if abs(Jtot_rf - j0)/j0 <= opt.tol,
0038 disp(['convergence obtained for RF current after ',num2str(it_wave),' iterations']);
0039 break
0040 elseif it_wave == opt.maxiconv,
0041 disp(['WARNING : convergence not obtained for RF current after ',num2str(it_wave),' iterations']);
0042 else
0043 waves{1}.rays{1}.P0_2piRp = waves{1}.rays{1}.P0_2piRp*j0/Jtot_rf;
0044 end
0045
0046 end
0047
0048 end
0049
0050 dkeparam.Jtot_ohm = j0;
0051
0052 dkeparam.nit_ohm = opt.maxiconv;
0053 dkeparam.tol_ohm = opt.tol;
0054 dkeparam.efield_ohm = opt.efield0;
0055
0056 dkeparam.opt_struct = 0;
0057
0058 dmhu = momentumDKE0.dmhu;
0059 mhu = momentumDKE0.mhu;
0060 dpn = momentumDKE0.dpn;
0061 pn = momentumDKE0.pn;
0062 pn2 = gridDKE0.pn2;
0063 gamma = Zmomcoef0.gamma;
0064
0065 if opt.loadstructs,
0066 loadstructs.radialgrid_dke_jd.radialDKE = radialDKE0;
0067
0068
0069
0070 loadstructs.momentumgrid_dke_jd.momentumDKE = momentumDKE0;
0071 loadstructs.matrix3Dgridbuilder_dke_yp.gridDKE = gridDKE0;
0072 loadstructs.momentumcoefbuilder_dke_yp.Zmomcoef = Zmomcoef0;
0073 loadstructs.bouncecoefbuilder_dke_yp.Zbouncecoef = Zbouncecoef0;
0074 loadstructs.mripplecoefbuilder_dke_yp.Zmripple = Zmripple0;
0075 loadstructs.mksacoefbuilder_dke_yp.mksa = mksa0;
0076 loadstructs.sinksourcecoeffbuilder_dke_yp.XXsinksource = XXsinksource0;
0077
0078 loadstructs.rad_dke_yp.ZXXD_a = dke_out0.ZXXD_a;
0079 loadstructs.rad_dke_yp.ZXXF_a = dke_out0.ZXXF_a;
0080
0081
0082
0083
0084
0085
0086
0087
0088 loadstructs.efield_dke_jd.ZXXD_e = dke_out0.ZXXD_e;
0089 loadstructs.efield_dke_jd.ZXXF_e = dke_out0.ZXXF_e;
0090 loadstructs.efield_dke_jd.ZXXD_e_tp = NaN;
0091 loadstructs.efield_dke_jd.ZXXF_e_tp = NaN;
0092 loadstructs.efield_dke_jd.xepsi_init = dke_out0.xepsi_init;
0093 loadstructs.efield_dke_jd.xEfield_validity = dke_out0.xEfield_validity;
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110 else
0111
0112 loadstructs = [];
0113
0114 dkeparam.Te_ref = mksa0.Te_ref;
0115 dkeparam.ne_ref = mksa0.ne_ref;
0116
0117 end
0118
0119 I_tot = Zcurr0.I_tot;
0120
0121 XXfinit = dke_out0.XXf0;
0122
0123 ohm = struct;
0124 ohm.id = 'evolution';
0125 ohm.rho = gridDKE0.xrho;
0126 ohm.epsi = dke_out0.xepsi{end}*mksa0.Edreicer_ref;
0127 ohm.xnrem_init = dke_out0.xnorm_rem{end};
0128 ohm.xnrep_init = dke_out0.xnorm_rep{end};
0129
0130
0131
0132
0133
0134
0135
0136 nit = opt.nit;
0137
0138 if isnan(opt.tnmax),
0139 if opt.T == 0,
0140 opt.tnmax = opt.tnq;
0141 elseif opt.T == 1,
0142 opt.tnmax = opt.tnq*(1 - (betathf/betath0)^3);
0143 elseif opt.T == 2,
0144 opt.tnmax = 2*opt.tnq;
0145 elseif opt.T == 3,
0146 opt.tnmax = opt.tnq;
0147 elseif opt.T == 4,
0148 opt.tnmax = 2*opt.tnq;
0149 end
0150 end
0151
0152
0153
0154
0155
0156
0157
0158
0159 dkeparam.tn = NaN;
0160 dkeparam.dtn = opt.tnmax/nit;
0161 tn = linspace(dkeparam.dtn,opt.tnmax,nit);
0162
0163 if opt.T == 0,
0164 tbetath = repmat(betath0,[1,nit]);
0165 elseif opt.T == 1,
0166 tbetath = betath0*(1-tn/opt.tnq).^(1/3);
0167 elseif opt.T == 2,
0168 tbetath = sqrt(betathf^2 + (betath0^2-betathf^2)*exp(-tn/opt.tnq));
0169 elseif opt.T == 3,
0170 tbetath = repmat(betathf,[1,nit]);
0171 elseif opt.T == 4,
0172 tbetath = sqrt(betathf^2 + (betath0^2-betathf^2)*exp(-(tn/opt.tnq).^2));
0173 end
0174
0175 trbetath = [1,tbetath/betath0];
0176
0177 tequil = repmat(equil0,[1,nit]);
0178
0179 for it = 1:nit,
0180 tequil(it).pTe = tbetath(it)^2*mc2*ones(size(tequil(it).pTe));
0181 end
0182
0183 for it = 1:nit,
0184 [Znorm(it),Zcurr(it),ZP0(it),dke_out(it)] = main_dke_yp(id_simul,dkepath,tequil(it),dkeparam,dkedisplay,ohm,'','','',XXfinit{it},[],loadstructs);
0185 XXfinit{it+1} = dke_out(it).XXf0{1};
0186
0187 ohm.epsi = dke_out(it).xepsi{end}*mksa0.Edreicer_ref;
0188 ohm.xnrem_init = dke_out(it).xnorm_rem{end};
0189 ohm.xnrep_init = dke_out(it).xnorm_rep{end};
0190
0191 disp(['Time step ',num2str(it),'/',num2str(nit),' calculated.'])
0192 end
0193
0194
0195
0196 dkeparam.avalanche_mode = 0;
0197 dkeparam.dtn = NaN;
0198 dkeparam.nit_ohm = 1;
0199
0200
0201 ohm = struct;
0202 ohm.id = 'linear';
0203 ohm.rho = gridDKE0.xrho;
0204 ohm.epsi = 1e-6;
0205
0206 if opt.loadstructs,
0207 loadstructs = rmfield(loadstructs,'efield_dke_jd');
0208 end
0209
0210 [~,Zcurr_lin0] = main_dke_yp(id_simul,dkepath,equil0,dkeparam,dkedisplay,ohm,'','','',[],[],loadstructs);
0211 for it = 1:nit,
0212 [~,Zcurr_lin(it),~,~,~,~,~,~,~,~,~,mksa_lin(it)] = main_dke_yp(id_simul,dkepath,tequil(it),dkeparam,dkedisplay,ohm,'','','',[],[],loadstructs);
0213 disp(['Time step ',num2str(it),'/',num2str(nit),' calculated.'])
0214 end
0215
0216 pfM = cell(1,nit+1);
0217 pf0 = cell(1,nit+1);
0218
0219 xTe.normM = NaN(1,nit+1);
0220 xTe.norm0 = NaN(1,nit+1);
0221
0222 pfbM = cell(1,nit+1);
0223 xTe.normb = NaN(1,nit+1);
0224 xTe.norms = NaN(1,nit+1);
0225 xTe.delta = NaN(1,nit+1);
0226 err = NaN(1,nit+1);
0227
0228 pfM{1} = (1/2)*integral_dke_jd(dmhu,dke_out0.XXfM,2);
0229 pf0{1} = (1/2)*integral_dke_jd(dmhu,dke_out0.XXf0{1},2);
0230
0231 for it = 1:nit,
0232 pfM{it+1} = (1/2)*integral_dke_jd(dmhu,dke_out(it).XXfM,2);
0233 pf0{it+1} = (1/2)*integral_dke_jd(dmhu,dke_out(it).XXf0{1},2);
0234 end
0235
0236 for it = 1:nit+1,
0237
0238 xTe.normM(it) = 4*pi*integral_dke_jd(dpn.',pn2.'.*pn2.'.*pfM{it}./gamma.',1)/3;
0239 xTe.norm0(it) = 4*pi*integral_dke_jd(dpn.',pn2.'.*pn2.'.*pf0{it}./gamma.',1)/3;
0240
0241 [xTe.normb(it),xTe.norms(it),xTe.delta(it),pfbM{it},err(it)] = bimaxfit_jd(dpn.',pn.',gamma.',pf0{it},1,3,xTe.normM(it),1);
0242 end
0243
0244 J.tot = NaN(1,nit+1);
0245 J.lin = NaN(1,nit+1);
0246 J.rei = NaN(1,nit+1);
0247 J.ree = NaN(1,nit+1);
0248
0249 Efield = NaN(1,nit+1);
0250
0251 Efield(1) = dke_out0.xepsi{end}/mksa0.betath_ref^2;
0252
0253 J.tot(1) = dke_out0.xcurr{end};
0254 J.lin(1) = Zcurr_lin0.x_0_fsav*(dke_out0.xepsi{end}.*mksa0.Edreicer_ref)/ohm.epsi;
0255 J.rei(1) = Zcurr0.x_Rfrac_0_fsav;
0256 J.ree(1) = dke_out0.xcurr_rem{end} + dke_out0.xcurr_rep{end};
0257
0258 for it = 1:nit,
0259 Efield(it+1) = dke_out(it).xepsi{1}/mksa0.betath_ref^2;
0260
0261 J.tot(it+1) = dke_out(it).xcurr{end};
0262
0263
0264 J.lin(it+1) = Zcurr_lin(it).x_0_fsav*(mksa_lin(it).j_ref/mksa0.j_ref)*(dke_out(it).xepsi{end}*mksa0.Edreicer_ref)/ohm.epsi;
0265 J.rei(it+1) = Zcurr(it).x_Rfrac_0_fsav;
0266 J.ree(it+1) = dke_out(it).xcurr_rem{end} + dke_out(it).xcurr_rep{end};
0267 end
0268
0269 J.hot = J.tot - J.lin - J.rei - J.ree;
0270
0271 J.j0 = j0/mksa0.j_ref;
0272
0273 [np,nmhu] = size(dke_out0.XXf0{1});
0274
0275 savedata = struct;
0276
0277 savedata.t = [0,tn];
0278 savedata.betath0 = betath0;
0279 savedata.pn = pn;
0280 savedata.dpn = dpn;
0281 savedata.xi = mhu;
0282 savedata.dxi = dmhu;
0283
0284 savedata.rbetath = [betath0,tbetath]/betath0;
0285 savedata.f = NaN(np,nmhu,nit+1);
0286 savedata.fM = NaN(np,nmhu,nit+1);
0287 savedata.f(:,:,1) = dke_out0.XXf0{1}/Znorm0.x_0_fsav;
0288 savedata.fM = dke_out0.XXfM;
0289 for it = 1:nit,
0290 savedata.f(:,:,it+1) = dke_out(it).XXf0{1}/Znorm(it).x_0_fsav;
0291 savedata.fM(:,:,it+1) = dke_out(it).XXfM;
0292 end
0293
0294 savedata.info.t = 'time grid, normalized to electron thermal collision time 4*pi*e0^2*m^2*vT0^3/(ne*e^4)';
0295 savedata.info.betath0 = 'ratio of the reference thermal velocity VT0=sqrt(T0/m) to the speed of light c. Also equal to sqrt(T0/mc2)';
0296 savedata.info.pn = 'momentum grid, normalized to the reference thermal momentum pT0 = m*vT0';
0297 savedata.info.dpn = 'momentum grid steps';
0298 savedata.info.xi = 'pitch angle grid, xi = p||/p';
0299 savedata.info.dxi = 'pitch angle grid steps';
0300 savedata.info.rbetath = 'temperature evolution prescribed through field particles in the collision operator: rbetath = vT/vT0';
0301 savedata.info.f = 'electron distribution function as a function of (pn,xi,t), normalized to the electron density';
0302 savedata.info.fM = 'Maxwellian distribution function as a function of (pn,xi,t), normalized to the electron density';
0303