0001 function [sortie,memoire] = cronos2luke(par,equi,neo,gene,prof,compo,impur,proto,memoire)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 sortie = proto;
0025 sortie.err = 0;
0026
0027
0028
0029
0030
0031 if ~isfield(par,'tok')
0032 tokamak = 'unknown';
0033 else
0034 tokamak = par.tok;
0035 end
0036
0037
0038
0039 if ~isfield(par,'shot')
0040 shotnum = '0';
0041 else
0042 shotnum = num2str(par.shot);
0043 end
0044
0045
0046
0047 if isempty(memoire.data),
0048 shotime = par.temps_cons.tempsini;
0049 else
0050 shotime = par.temps_cons.tempsend;
0051 end
0052
0053 shotimestr = num2str(shotime,'%6.4f');
0054
0055
0056
0057 equil_id = [tokamak,'_',shotnum,'_',shotimestr];
0058
0059
0060
0061 dkeparam = make_dkeparam_cronos(par);
0062
0063
0064
0065 dkepath = load_structures_yp('dkepath','','');
0066
0067
0068
0069 dkedisplay = make_display_cronos;
0070 dkedisplay.rho_display = par.rho_display;
0071 dkedisplay.display_mode = par.display_mode;
0072
0073
0074
0075 equil = make_equil_cronos(equil_id,equi,gene,prof,compo,impur);
0076
0077
0078
0079
0080
0081
0082
0083
0084 nrho_ohm = 101;
0085 ohm.rho = linspace(0,1,nrho_ohm);
0086
0087
0088 if equi.psiRZ(1) == equi.psiRZ(2)
0089 disp('non monotonic psiRZ');
0090 psiRZ = interp1(gene.x*equi.rhomax,equi.psi,double(equi.rhoRZ),'pchip','extrap');
0091 equi.psiRZ = double(psiRZ);
0092 else
0093 psiRZ = double(equi.psiRZ);
0094 end
0095
0096 psipncronoshel = abs(psiRZ-psiRZ(1))/max(abs(psiRZ-psiRZ(1)));
0097 psitncronoshel = equi.rhoRZ/equi.rhomax;
0098 psipn_ohm = rho2psi_jd(equil,ohm.rho);
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 epsicronoshel = -sign(gene.signe.ip)*sign(gene.signe.b0)*interp1(gene.x,prof.epar,psitncronoshel);
0110 ohm.epsi = complex(interp1(psipncronoshel,epsicronoshel,psipn_ohm));
0111
0112
0113
0114 ripple.mode = par.ripple;
0115
0116
0117
0118 if par.Dr0 == 0 && par.Vr0 == 0
0119
0120
0121
0122 transpfaste = '';
0123 else
0124 transpfaste.vparmin = par.vparmin_r;
0125 transpfaste.norm_ref = par.norm_ref;
0126 transpfaste.Dr0 = par.Dr0;
0127 transpfaste.pDr = par.pDr;
0128 transpfaste.Vr0 = par.Vr0;
0129 transpfaste.pVr = par.pVr;
0130 transpfaste.Dr_model = par.Dr_model;
0131 transpfaste.Vr_model = par.Vr_model;
0132 end
0133
0134
0135
0136 if ~isfield(par,'conf')
0137 par.conf = tokamak;
0138 end
0139
0140 cons=par.cons;
0141 if strcmp(par.luke_mode,'lh')
0142 [launchs_lh] = make_wavelaunchs_cronos_lh(gene,par,cons.lh_cons);
0143 launchs_ec = [];
0144 end
0145 if strcmp(par.luke_mode,'ec')
0146 [launchs_ec] = make_wavelaunchs_cronos_ec(equil,par,cons.ecrh_cons);
0147 launchs_lh = [];
0148 end
0149 if strcmp(par.luke_mode,'mixte')
0150 [launchs_lh] = make_wavelaunchs_cronos_lh(gene,par,cons.lh_cons);
0151 [launchs_ec] = make_wavelaunchs_cronos_ec(equil,par,cons.ecrh_cons);
0152 end
0153
0154 launchs = [launchs_lh,launchs_ec];
0155
0156 mask = [];
0157 prf = 0;
0158 for iw = 1:length(launchs),
0159
0160 if strcmp(launchs{iw}.type,'LH')
0161 wprf = sum(launchs{iw}.bPlhtot);
0162 elseif strcmp(launchs{iw}.type,'EC')
0163 wprf = sum(launchs{iw}.yP_L);
0164 end
0165
0166 if ~isfield(par,'prfmin') || wprf >= par.prfmin,
0167 mask = [mask,iw];
0168 prf = prf + wprf;
0169 else
0170 disp(['wave #',int2str(iw),': dismissed as Prf = ',num2str(wprf),' < Prfmin = ',num2str(par.prfmin),'.'])
0171 end
0172 end
0173 launchs = launchs(mask);
0174 nw = length(launchs);
0175
0176 if nw == 0
0177 sortie.j = zeros(size(gene.x));
0178 sortie.el = zeros(size(gene.x));
0179 memoire.data.output.j = sortie.j;
0180 memoire.data.output.el = sortie.el;
0181 memoire.data.output.paddrf = 0;
0182 memoire.data.output.prf = 0;
0183 memoire.data.output.ne = prof.ne;
0184 memoire.data.output.irf = 0;
0185 return
0186 end
0187 wavestructs = cell(1,length(launchs));
0188
0189 dkeparam.w_mask = [];
0190
0191 for iw = 1:nw,
0192 wavestructs{iw} = make_wavert_cronos(launchs{iw},par);
0193
0194 wavestructs{iw}.equil_id = equil.id;
0195
0196 if strcmp(launchs{iw}.type,'EC')
0197
0198 dkeparam.w_mask = [dkeparam.w_mask,iw];
0199 disp(['wave #',int2str(iw),': type :',launchs{iw}.type])
0200
0201 else
0202 disp(['wave #',int2str(iw),': type :',launchs{iw}.type,' n// = ',num2str(wavestructs{iw}.launch.bNpar0,4)])
0203 disp(['wave #',int2str(iw),': type :',launchs{iw}.type,' Plh = ',num2str(wavestructs{iw}.launch.bPlhtot,4)])
0204 end
0205
0206 end
0207 if isempty(dkeparam.w_mask)
0208 dkeparam.w_mask = 1:length(launchs);
0209 end
0210
0211
0212
0213 if nw > 0
0214 acces_lh
0215 end
0216
0217 distrib_RF = [];
0218 distrib_TOT = [];
0219 distrib_OHM = [];
0220
0221 if ~isempty(memoire)
0222 if isfield(memoire,'data')
0223 if isfield(memoire.data,'edistribution')
0224 disp(['-------------using the last distribution function------------'])
0225 tm = memoire.data.edistribution(end).shotime;
0226 if tm == shotime,
0227 memoire.data.edistribution = memoire.data.edistribution(1:end-1);
0228 end
0229
0230 if length(memoire.data.edistribution) >= 1,
0231 distrib_RF = memoire.data.edistribution(end).f0_RF;
0232 distrib_TOT = memoire.data.edistribution(end).f0_TOT;
0233 distrib_OHM = memoire.data.edistribution(end).f0_OHM;
0234 dkeparam.rho_S = memoire.data.edistribution(end).rho_S;
0235 dkeparam.tn = (shotime - memoire.data.edistribution(end).shotime)*distrib_RF.mksa.nhu_ref;
0236 end
0237 end
0238 end
0239 end
0240
0241 if par.save == 2,
0242
0243 try
0244 workdir = fileparts(evalin('base','param.gene.file'));
0245 catch
0246 workdir = [];
0247 end
0248 if isempty(workdir)
0249 disp('you can not save the luke file in batch mode')
0250 else
0251 save([workdir,'/before_luke@',equil_id,'.mat']);
0252 error('Exiting after saving LUKE parameters')
0253 end
0254
0255 end
0256
0257
0258
0259 ik = 1;
0260 warning off
0261 disp(['LUKE is running ....'])
0262
0263 signe_out = -gene.signe.ip;
0264
0265
0266
0267 [Znorm_RF,Zcurr_RF,ZP0_RF,dke_out_RF,radialDKE,equilDKE,momentumDKE,gridDKE,Zmomcoef,Zbouncecoef,Zmripple,mksa] = ...
0268 run_lukert_batchopt('cronos',wavestructs,[],dkepath,equil,dkeparam,dkedisplay,[],transpfaste,ripple,distrib_RF,par);
0269
0270 j_RF_c = signe_out*Zcurr_RF.x_0_vcfsav*mksa.j_ref*1e6;
0271 I_RF_c = sum(signe_out*Zcurr_RF.x_0_fsav.*equilDKE.xdA_dke*mksa.j_ref*1e6);
0272 p_RF_c = ZP0_RF.x_rf_fsav.'*mksa.P_ref*1e6;
0273 P_RF_c = sum(p_RF_c.*equilDKE.xdV_2piRp_dke*2*pi*equilDKE.Rp);
0274 f0_RF = dke_out_RF.Zf0_interp;
0275
0276 waves = dke_out_RF.waves;
0277 dkeparam.rho_S = radialDKE.xrho_S_dke;
0278 dkeparam.rt_mode = 1;
0279
0280 if strcmp(par.syn,'Yes') && sum(abs(ohm.epsi)) ~= 0,
0281
0282
0283
0284 [Znorm_TOT,Zcurr_TOT,ZP0_TOT,dke_out_TOT] = run_lukert_batchopt('cronos',[],waves,dkepath,equil,dkeparam,dkedisplay,ohm,transpfaste,ripple,distrib_TOT,par);
0285
0286 j_TOT_c = signe_out*Zcurr_TOT.x_0_vcfsav*mksa.j_ref*1e6;
0287 I_TOT_c = sum(signe_out*Zcurr_TOT.x_0_fsav.*equilDKE.xdA_dke*mksa.j_ref*1e6);
0288 p_RF_TOT_c = ZP0_TOT.x_rf_fsav.'*mksa.P_ref*1e6;
0289
0290
0291
0292
0293 f0_TOT = dke_out_TOT.Zf0_interp;
0294
0295
0296
0297 [Znorm_OHM,Zcurr_OHM,ZP0_OHM,dke_out_OHM] = run_lukert_batchopt('cronos',[],[],dkepath,equil,dkeparam,dkedisplay,ohm,transpfaste,ripple,distrib_OHM,par);
0298
0299 j_OHM_c = signe_out*Zcurr_OHM.x_0_vcfsav*mksa.j_ref*1e6;
0300 I_OHM_c = sum(signe_out*Zcurr_OHM.x_0_fsav.*equilDKE.xdA_dke*mksa.j_ref*1e6);
0301
0302
0303
0304 f0_OHM = dke_out_OHM.Zf0_interp;
0305
0306 else
0307
0308 j_TOT_c = j_RF_c;
0309 I_TOT_c = I_RF_c;
0310 p_RF_TOT_c = p_RF_c;
0311 j_OHM_c = zeros(1,length(j_RF_c));
0312 I_OHM_c = 0;
0313 f0_TOT = f0_RF;
0314 f0_OHM = [];
0315
0316 end
0317
0318
0319
0320
0321
0322 j_SYN_c = j_TOT_c - j_RF_c - j_OHM_c;
0323 I_SYN_c = I_TOT_c - I_RF_c - I_OHM_c;
0324
0325
0326 warning on
0327
0328 if strcmp(dkedisplay.display_mode,'PARTIAL_VISUAL') || strcmp(dkedisplay.display_mode,'VISUAL'),
0329
0330 visu_luke
0331
0332 end
0333
0334
0335
0336 if isfield(par,'ipfrac'),
0337
0338 I_boot = zintsurf(neo.jboot,gene.x,equi.spr,equi.rhomax);
0339
0340 if (I_RF_c+I_boot)/equi.ip > par.ipfrac,
0341
0342 normip = par.ipfrac*equi.ip/(I_RF_c+I_boot);
0343 disp(['----> to avoid I_L_H + I_b_o_o_t > Ip'])
0344 disp(['normalisation =',num2str(normip,3)])
0345
0346 else
0347
0348 normip = 1;
0349
0350 end
0351 end
0352
0353 sortie.err = normip;
0354
0355
0356
0357
0358
0359
0360 method = 'linear';
0361
0362 xrhoT = [0,equilDKE.xrhoT,1];
0363 j_RF_c = [j_RF_c(1),j_RF_c,0];
0364 j_SYN_c = [j_SYN_c(1),j_SYN_c,0];
0365 p_RF_TOT_c = [p_RF_TOT_c(1),p_RF_c,0];
0366
0367 cj_RF_c = interp1(xrhoT,j_RF_c,gene.x,method);
0368 cj_SYN_c = interp1(xrhoT,j_SYN_c,gene.x,method);
0369 cp_RF_TOT_c = interp1(xrhoT,p_RF_TOT_c,gene.x,method);
0370
0371
0372
0373 irfnew = zintsurf(cj_RF_c,gene.x,equi.spr,equi.rhomax);
0374 isynnew = zintsurf(cj_SYN_c,gene.x,equi.spr,equi.rhomax);
0375 paddrfnew = zintvol(cp_RF_TOT_c,gene.x,equi.vpr,equi.rhomax);
0376
0377 if abs(irfnew - I_RF_c)/abs(I_RF_c) > 0.01,
0378 disp(['WARNING : surface integral on LUKE and CRONOS grids give different results. RF current renormalized by ',num2str(I_RF_c / irfnew)])
0379 end
0380 if abs(isynnew - I_SYN_c)/max([abs(I_SYN_c),eps]) > 0.01,
0381 disp(['WARNING : surface integral on LUKE and CRONOS grids give different results. SYN current renormalized by ',num2str(I_SYN_c / isynnew)])
0382 end
0383 if abs(paddrfnew - P_RF_c)/abs(P_RF_c) > 0.01,
0384 disp(['WARNING : volume integral on LUKE and CRONOS grids give different results. RF power renormalized by ',num2str(P_RF_c / paddrfnew)])
0385 end
0386 cj_RF_c = cj_RF_c * I_RF_c / irfnew * normip;
0387 if isynnew ~= 0,
0388 cj_SYN_c = cj_SYN_c * I_SYN_c / isynnew;
0389 end
0390 if paddrfnew ~= 0,
0391 cp_RF_TOT_c = cp_RF_TOT_c * P_RF_c / paddrfnew;
0392 end
0393
0394
0395
0396 if isfield(par,'smooth') && strcmp(par.smooth,'Yes')
0397 newj = smooth_dke_yp(cj_RF_c.',par.width_smooth,par.method_smooth).';
0398 norm1 = zintsurf(cj_RF_c,gene.x,equi.spr,equi.rhomax);
0399 norm2 = zintsurf(newj,gene.x,equi.spr,equi.rhomax);
0400 cj_RF_c = newj/norm2*norm1;
0401
0402 newjsyn = smooth_dke_yp(cj_SYN_c.',par.width_smooth,par.method_smooth).';
0403 norm1 = zintsurf(cj_SYN_c,gene.x,equi.spr,equi.rhomax);
0404 norm2 = zintsurf(newjsyn,gene.x,equi.spr,equi.rhomax);
0405 if norm1 ~= 0,
0406 cj_SYN_c = newjsyn/norm2*norm1;
0407 end
0408
0409 newel = smooth_dke_yp(cp_RF_TOT_c.',par.width_smooth,par.method_smooth).';
0410 norm1 = zintvol(cp_RF_TOT_c,gene.x,equi.vpr,equi.rhomax);
0411 norm2 = zintvol(newel,gene.x,equi.vpr,equi.rhomax);
0412 if norm1 ~= 0,
0413 cp_RF_TOT_c = newel/norm2*norm1;
0414 end
0415 end
0416
0417
0418
0419 if any(any(ZP0_RF.xy_rf_fsav < 0)),
0420
0421 sortie.err = sortie.err + 1i;
0422
0423 disp('Problem in LUKE, negative absorbed power calculated for some value, use the previous LUKE calculation if possible')
0424
0425 if isfield(memoire.data,'output')
0426
0427
0428
0429 cj_RF_c = memoire.data.output.j*prf/memoire.data.output.prf.*memoire.data.output.ne./prof.ne;
0430 cj_SYN_c = 0;
0431 cp_RF_TOT_c = memoire.data.output.el*prf/memoire.data.output.prf;
0432
0433 end
0434 end
0435
0436
0437
0438
0439
0440 sigmasyn = cj_SYN_c./prof.epar;
0441 sigmasyn(prof.epar == 0) = 0;
0442 sigmasynmax = sigmasyn(find(abs(cj_SYN_c) == max(abs(cj_SYN_c)),1,'first'));
0443 sigmasyn = sign(sigmasyn).*min([abs(sigmasyn);repmat(abs(sigmasynmax),[1,length(sigmasyn)])]);
0444
0445 sortie.j = cj_RF_c;
0446 sortie.sigmasyn = sigmasyn;
0447 sortie.el = cp_RF_TOT_c;
0448
0449 irf = zintsurf(cj_RF_c,gene.x,equi.spr,equi.rhomax);
0450 paddrf = zintvol(cp_RF_TOT_c,gene.x,equi.vpr,equi.rhomax);
0451
0452 disp(['I_L_H = ',num2str(irf/1e3,3),' kA / I_p =',num2str(equi.ip/1e3,4),' kA'])
0453 disp(['P_L_H = ',num2str(paddrf/1e3,3),' kW / P_r_e_f = ',num2str(prf/1e3,3),' kW'])
0454
0455 memoire.data.output.j = cj_RF_c;
0456 memoire.data.output.el = cp_RF_TOT_c;
0457 memoire.data.output.paddrf = paddrf;
0458 memoire.data.output.prf = prf;
0459 memoire.data.output.ne = prof.ne;
0460 memoire.data.output.irf = irf;
0461
0462 for iw = 1:nw,
0463 if isfield(wavestructs{iw}.launch,'aloha') & wavestructs{iw}.launch.aloha.mode ~= 0
0464 if isfield(memoire.data.output,'npar')
0465 if iw <= length(memoire.data.output.npar)
0466 memoire.data.output.npar{iw}(end+1,:) = wavestructs{iw}.launch.bNpar0;
0467 else
0468 memoire.data.output.npar{iw}(1,:) = wavestructs{iw}.launch.bNpar0;
0469 end
0470 else
0471 memoire.data.output.npar{iw}(1,:) = wavestructs{iw}.launch.bNpar0;
0472 end
0473 if isfield(memoire.data.output,'pow')
0474 if iw <= length(memoire.data.output.pow)
0475 memoire.data.output.pow{iw}(end+1,:) = wavestructs{iw}.launch.bPlhtot;
0476 else
0477 memoire.data.output.pow{iw}(1,:) = wavestructs{iw}.launch.bPlhtot;
0478 end
0479 else
0480 memoire.data.output.pow{iw}(1,:) = wavestructs{iw}.launch.bPlhtot;
0481 end
0482 end
0483 end
0484
0485 if isfield(memoire.data,'edistribution')
0486 memoire.data.edistribution(end + 1).shotime = shotime;
0487 else
0488 memoire.data.edistribution.shotime = shotime;
0489 end
0490
0491 memoire.data.edistribution(end).f0_RF = f0_RF;
0492 memoire.data.edistribution(end).f0_TOT = f0_TOT;
0493 memoire.data.edistribution(end).f0_OHM = f0_OHM;
0494 memoire.data.edistribution(end).rho_S = radialDKE.xrho_S_dke;
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510 if par.save == 1,
0511 try
0512 workdir = fileparts(evalin('base','param.gene.file'));
0513 catch
0514 workdir = [];
0515 end
0516 if isempty(workdir)
0517 disp('you can not save the luke file in batch mode')
0518 else
0519 save([workdir,'/last_luke@',equil_id,'.mat']);
0520 end
0521 end
0522 end
0523
0524
0525
0526 function [Znorm,Zcurr,ZP0,dke_out,radialDKE,equilDKE,momentumDKE,gridDKE,Zmomcoef,Zbouncecoef,Zmripple,mksa,XXsinksource,dke_warnings] = ...
0527 run_lukert_batchopt(id_simul,wavestructs,waves,dkepath,equil,dkeparam,dkedisplay,ohm,transpfaste,ripple,distrib,par)
0528
0529 dkepath.remnum = par.remnum;
0530 dkepath.remtimout = par.remtimout;
0531 dkepath.rempause = par.rempause;
0532 dkepath.debugmode = par.debugmode;
0533 dkepath.clean = par.clean;
0534
0535
0536
0537 opt.save = par.saveluke;
0538 if isinf(par.fields),
0539 opt.fields = NaN;
0540 else
0541 opt.fields = par.fields;
0542 end
0543 opt.backup = par.backup;
0544 opt.waves = par.waves;
0545
0546 lukestructs = struct;
0547 lukestructs.simul.id_simul = id_simul;
0548 lukestructs.simul.path = '';
0549 lukestructs.dkeparam = dkeparam;
0550 lukestructs.dkepath = dkepath;
0551 lukestructs.dkedisplay = dkedisplay;
0552 lukestructs.equil = equil;
0553 lukestructs.waves = waves;
0554 lukestructs.wavestructs = wavestructs;
0555 lukestructs.ohm = ohm;
0556 lukestructs.transpfaste = transpfaste;
0557 lukestructs.ripple = ripple;
0558 lukestructs.Zf0_interp = distrib;
0559 lukestructs.opt = opt;
0560
0561 lukestructs = run_lukert(lukestructs,dkepath);
0562
0563 if isfield(lukestructs,'err'),
0564 zverbose('Remote LUKE run failed, aborted.')
0565 else
0566
0567 Znorm = lukestructs.output.Znorm;
0568 Zcurr = lukestructs.output.Zcurr;
0569 ZP0 = lukestructs.output.ZP0;
0570 dke_out = lukestructs.output.dke_out;
0571 radialDKE = lukestructs.output.radialDKE;
0572 equilDKE = lukestructs.output.equilDKE;
0573 momentumDKE = lukestructs.output.momentumDKE;
0574 gridDKE = lukestructs.output.gridDKE;
0575 Zmomcoef = lukestructs.output.Zmomcoef;
0576 Zbouncecoef = lukestructs.output.Zbouncecoef;
0577 Zmripple = lukestructs.output.Zmripple;
0578 mksa = lukestructs.output.mksa;
0579 XXsinksource = lukestructs.output.XXsinksource;
0580
0581 end
0582
0583 clear raytracing_yp alphaphimex_jd trapz_dke_yp dmumpsmex
0584
0585 end
0586
0587
0588
0589
0590
0591
0592
0593 function s=zintsurf(e,x,sp,rhomax)
0594
0595 s = rhomax .* trapz(x,sp .* e,2);
0596 end