itm2luke

PURPOSE ^

LUKE - Interface for running C3PO/LUKE using euitm data

SYNOPSIS ^

function [waves_euitm] = itm2luke(euitmshot,equil_euitm,coreprof_euitm,antennas_euitm,ver_mds,opts)

DESCRIPTION ^

LUKE -  Interface for running C3PO/LUKE using euitm data
 
 by Yves Peysson (CEA/DSM/IRFM, yves.peysson@cea.fr) and Joan Decker (CEA/DSM/IRFM, joan.decker@cea.fr)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [waves_euitm] = itm2luke(euitmshot,equil_euitm,coreprof_euitm,antennas_euitm,ver_mds,opts)
0002 %LUKE -  Interface for running C3PO/LUKE using euitm data
0003 %
0004 % by Yves Peysson (CEA/DSM/IRFM, yves.peysson@cea.fr) and Joan Decker (CEA/DSM/IRFM, joan.decker@cea.fr)
0005 %
0006 if nargin < 6, error('Not enough input arguments in itm2luke.m');end
0007 %
0008 % LUKE post-processing options
0009 %
0010 opt.rho = 'g';
0011 opt.nr_dep = 0;
0012 opt.peakmode = 0;
0013 opt.peak = 'n';
0014 opt.wave = 'n';
0015 opt.blist = '';
0016 opt.diaryname = '';
0017 opt.spec = 0;
0018 %
0019 % User specific C3PO/LUKEparameters
0020 %
0021 dataname = dataname_ITM(euitmshot.machine,euitmshot.numshot,euitmshot.numrun_in,euitmshot.timeslice,euitmshot.time_interp);   
0022 filename = [pwd,'/LUKE_RESULTS_',dataname,'.mat'];
0023 %
0024 if ~exist(filename,'file'),
0025     %
0026     [dkepath,dkedisplay] = load_structures_yp('dkepath','','','dkedisplay','NO_DISPLAY','');
0027     %
0028     profilestr = dkepath.profilestr;
0029     %
0030     disp('WARNING: dkeparam for EC wave only. LH case not yet implemented');
0031     dkeparam = load_structures_yp('dkeparam','EC_RT','');%yet EC wave only
0032     %
0033     if isfield(opts,'opt_struct'),
0034         dkeparam.opt_struct = opts.opt_struct;
0035     end
0036     %
0037     if isfield(opts,'rho_S'),dkeparam.rho_S = opts.rho_S;end
0038     %
0039     %TODO: implement dkeparam for LH or mixed EC+LH
0040     %
0041     disp('----------------------------------------------------------');
0042     disp('Simulation status');
0043     disp('----------------------------------------------------------');
0044     %
0045     if exist(['LUKE_RESULTS_',dataname,'.mat'],'file'),
0046         load(['LUKE_RESULTS_',dataname,'.mat'])
0047     else
0048         if nargin == 6,
0049             %
0050             dkepath.clustermode.run_lukert.scheduler.remnum = opts.remnum;% remote profile number. Use 0 for local sequential calculations
0051             dkepath.clustermode.run_lukert.scheduler.mode = opts.remmdce;%distribution mode of LUKE on the remote machine
0052             dkepath.clustermode.run_lukert.scheduler.remtimout = opts.remtimout;% timeout for remote calculations, in minutes. Use (0) to return later and check results by running this script again
0053             dkepath.clustermode.run_lukert.scheduler.rempause = opts.rempause;% pause between job checks (in minutes) (only for remtimout > 0)
0054             dkepath.clustermode.run_lukert.scheduler.debugmode = opts.remdebugmode;% debug mode (0) off (1) on
0055             dkepath.clustermode.run_lukert.scheduler.clean = opts.remclean;% clean job files/folders : both on remote and local (2), only on remote (1) or not at all (0)
0056             dkepath.clustermode.run_lukert.scheduler.memory = opts.luke_memory;% job memory in mb
0057             dkepath.clustermode.run_lukert.scheduler.walltime = opts.luke_walltime;%job walltime in hours
0058             dkepath.clustermode.run_lukert.scheduler.enforce = opts.enforce;% exit if remote calculation failed
0059             %
0060             optluke.save = opts.opt.save;% (1): save LUKE_RESULTS or return error in localdatadir (0): return results or error
0061             optluke.localdatadir = opts.opt.localdatadir;% local directory where LUKE_RESULTS is saved
0062             %
0063             if optluke.save,% (1): save LUKE_RESULTS or return error (0): return results or error
0064                 dkepath.clustermode.run_lukert.scheduler.localdatadir = optluke.localdatadir;
0065                 if exist(optluke.localdatadir,'dir') && length(dir(optluke.localdatadir)) > 2,
0066                     initdir = pwd;
0067                     cd(optluke.localdatadir);
0068                     delete('LUKE_RESULTS_*');
0069                     cd(initdir);
0070                 end
0071             end
0072             %
0073             optluke.proc = opts.opt.proc;%do postprocessing remotely
0074             optluke.fields = opts.opt.fields;% selected fields in returned lukestructs. Use NaN for all fields
0075             optluke.backup = opts.opt.backup;% (1) save fluctuation time steps (0) do not save
0076             optluke.waves = opts.opt.waves;%(-1) waves are not saved in "wave_results/" and not stored in dke_out. In this case, C3PO must be rerun to see the rays (0) waves are stored in dke_out and saved in LUKE_RESULTS, (1) waves are saved in "wave_results/" but not stored in dke_out
0077             optluke.saveinputs = opts.opt.saveinputs;% (1) save input structures in .mat files before starting (0) do not save
0078             %
0079             ray_display = opts.opt.ray_display;%for display ray propagation (0,1,2)
0080             display_mode = opts.opt.display_mode;%display results 'equilibrium, Fokker-Planck (0,1,2)
0081             ir_display = opts.opt.ir_display;%proc_luke_jd display option (-1,0,1,2)
0082             p_opt = opts.opt.p_opt;%Printing options
0083             %
0084         end
0085         %
0086         waves = '';
0087         ohm = '';
0088         transpfaste = '';
0089         ripple = '';
0090         distrib = '';
0091         %
0092         for it = 1:length(equil_euitm),%the number if equils is the number of timeslice
0093             %
0094             if it == 1,
0095                 equil = process_euitm_dataequil(ver_mds,equil_euitm{it},coreprof_euitm{it},display_mode);%Data conversion between CPO and LUKE format
0096             else
0097                 equil_euitm1 = rmfield(equil_euitm{it-1},'time');
0098                 equil_euitm2 = rmfield(equil_euitm{it},'time');
0099                 %
0100                 if comp_struct_jd(equil_euitm1,equil_euitm2,0) == 0,
0101                     equil = process_euitm_dataequil(ver_mds,equil_euitm{it},coreprof_euitm{it},display_mode);%Data conversion between CPO and LUKE format
0102                 end
0103             end
0104             %
0105             launchs = CPO2LUKEstruct_yp(ver_mds,'antennas',antennas_euitm{it});%Data conversion between CPO and LUKE format
0106             %
0107             iw = 1;
0108             %
0109             for jw = 1:length(launchs),
0110                 %
0111                 % Conversion to the generalized axial coordinate system
0112                 %
0113                 launchs{jw}.yx_L = launchs{jw}.yR_L - equil.Rp;
0114                 launchs{jw}.yy_L = launchs{jw}.yZ_L - equil.Zp;
0115                 launchs{jw}.yz_L = launchs{jw}.yphi_L*equil.Rp;    
0116                 %
0117                 if ray_display,%launching direction
0118                     [sysh,sysy,syx,syy,syz,syalpha,sybeta,sygx,sygy,sygz] = raypath_prop_jd(equil.Rp,launchs{jw}.yx_L,launchs{jw}.yy_L,launchs{jw}.yz_L,launchs{jw}.yalpha_L,launchs{jw}.ybeta_L,linspace(0,10,1000));
0119                     %
0120                     %equilibrium_jd(equil,'',3);
0121                     figure(1)
0122                     hold on
0123                     graph1D_jd(syx,syy,0,0,'','','',NaN,'','','-','non','k',2);%plot ray trajectory
0124                 end
0125                 %
0126                 if launchs{jw}.yP_L > 0,%calculation done only for rays carrying EC power
0127                     %
0128                     if strcmp(launchs{jw}.type,'EC'),
0129                         data = load([dkepath.luke_root,'Project_DKE/Database/WAVE_files/C3POPARAM_EC.mat']);%Generic parameters for EC wave calculations
0130                     elseif strcmp(launchs{jw}.type,'LH'),
0131                         data = load([dkepath.luke_root,'Project_DKE/Database/WAVE_files/C3POPARAM_LH.mat']);%Generic parameters for LH wave calculations
0132                     end
0133                     %
0134                     wavestructs{iw}.id = launchs{jw}.id;
0135                     wavestructs{iw}.launch = launchs{jw};
0136                     wavestructs{iw}.waveparam = conc_struct_jd(wavestructs{iw},data.waveparam);
0137                     wavestructs{iw}.fitequilparam = conc_struct_jd(wavestructs{iw},data.fitparam);
0138                     wavestructs{iw}.rayparam = conc_struct_jd(wavestructs{iw},data.rayparam);
0139                     wavestructs{iw}.C3POparam = conc_struct_jd(wavestructs{iw},data.C3POparam);
0140                     wavestructs{iw}.wavesolver = 'C3PO';
0141                     wavestructs{iw}.equil_id = equil.id;       
0142                     %
0143                     % Specific parameters for EC wave calculations
0144                     %
0145                     wavestructs{iw}.raydisplay.ray = ray_display;%for display ray propagation
0146                     wavestructs{iw}.raydisplay.equilibrium = 0;
0147                     wavestructs{iw}.raydisplay.p_opt = -1;%Printing or saving option of the figures
0148                     %
0149                     wavestructs{iw} = make_wavert_cronos(launchs{jw},0);
0150                     %
0151                     wavestructs{iw}.waveparam.dsmin = 0;
0152                     %
0153                     wavestructs{iw}.fitequilparam.method = 'spline';
0154                     %
0155                     if wavestructs{iw}.launch.yP_L == 0, 
0156                         wavestructs{iw}.launch.yP_L = eps;%to avoid interpolation problems
0157                     end
0158                     %
0159                     info_dke_yp(4,['time slice: ',int2str(it),' - wave : ',int2str(jw),' type : ',launchs{jw}.type,' used. Power = ',num2str(launchs{jw}.yP_L),' (W)'])
0160                     %
0161                     iw = iw + 1;
0162                 else
0163                     info_dke_yp(4,['time slice: ',int2str(it),' - wave : ',int2str(jw),' type : ',launchs{jw}.type,' removed. No power'])
0164                 end     
0165             end
0166             %
0167             lukestructs{it} = struct;
0168             %
0169             lukestructs{it}.simul.id_simul = equil.id;
0170             lukestructs{it}.simul.path = '';
0171             lukestructs{it}.dkeparam = dkeparam;
0172             lukestructs{it}.dkepath = dkepath;
0173             lukestructs{it}.dkedisplay = dkedisplay;
0174             lukestructs{it}.equil = equil;
0175             lukestructs{it}.waves = waves;
0176             lukestructs{it}.wavestructs = wavestructs;
0177             lukestructs{it}.ohm = ohm;
0178             lukestructs{it}.transpfaste = transpfaste;
0179             lukestructs{it}.ripple = ripple;
0180             lukestructs{it}.Zf0_interp = distrib;
0181             %
0182             if nargin == 6,
0183                 lukestructs{it}.opt = optluke;
0184             end
0185             %
0186             if exist('wavestructs'),clear wavestructs;end
0187             %
0188         end
0189     end
0190 else
0191     load(filename,'lukestructs','dkepath','profilestr');
0192 end
0193 %
0194 %--------------------------- Run C3PO/LUKE ---------------------------
0195 %
0196 disp('---------------------------------------------')
0197 if opts.remnum > 0,
0198     disp(['--> ',profilestr{opts.remnum}]);
0199 else
0200     disp('--> Local calculations');
0201 end
0202 %
0203 disp('---------------------------------------------')
0204 %
0205 lukestructs = run_lukert(lukestructs,dkepath);
0206 %
0207 for it = 1:length(lukestructs),
0208     if isfield(lukestructs{it},'job'),
0209         flag_running(it) = true;
0210     else
0211         if ~isempty(lukestructs{it}),
0212             flag_running(it) = false;
0213         end
0214     end
0215 end
0216 %
0217 waves_euitm = [];
0218 %
0219 save(['LUKE_RESULTS_',dataname,'.mat'],'lukestructs','dkepath','profilestr','ver_mds','opts');
0220 %
0221 if sum(flag_running) > 0,
0222     return
0223 else
0224     %
0225     dataname_out = dataname_ITM(euitmshot.machine,euitmshot.numshot,euitmshot.numrun_in,euitmshot.timeslice,euitmshot.time_interp,euitmshot.numrun_out,euitmshot.occurrence_out);   
0226     data_proc = '';
0227     %
0228     for it = 1:length(lukestructs),
0229         %
0230         if isfield(lukestructs{it},'output'), 
0231             if isfield(lukestructs{it}.output,'Znorm'),
0232                 rawdata.Znorm = lukestructs{it}.output.Znorm;
0233             else
0234                 disp(['WARNING: ''Znorm'' structure is missing in the lukestructs{',int2str(it),'}.output structure.']);
0235                 rawdata.Znorm = '';
0236             end
0237             %
0238             if isfield(lukestructs{it}.output,'Zcurr'),
0239                 rawdata.Zcurr = lukestructs{it}.output.Zcurr;
0240             else
0241                 disp(['WARNING: ''Zcurr'' structure is missing in the lukestructs{',int2str(it),'}.output structure.']);
0242                 rawdata.Zcurr = '';
0243             end
0244             %
0245             if isfield(lukestructs{it}.output,'ZP0'),
0246                 rawdata.ZP0 = lukestructs{it}.output.ZP0;
0247             else
0248                 disp(['WARNING: ''ZP0'' structure is missing in the lukestructs{',int2str(it),'}.output structure.']);
0249                 rawdata.ZP0 = '';
0250             end
0251             %
0252             if isfield(lukestructs{it}.output,'dke_out'),
0253                 rawdata.dke_out = lukestructs{it}.output.dke_out;  
0254                 %
0255                 if isfield(lukestructs{it}.output,'waves'),
0256                     for iray = 1:length(rawdata.dke_out.waves{1}.rays),
0257                         if ~isfield(rawdata.dke_out.waves{1}.rays{iray},'mask_p') || ~isfield(rawdata.dke_out.waves{1}.rays{iray},'mask_m');
0258                             rawdata.dke_out.waves{1}.rays{iray}.mask_p = zeros(size(rawdata.dke_out.waves{1}.rays{iray}.ss));
0259                             rawdata.dke_out.waves{1}.rays{iray}.mask_m = ones(size(rawdata.dke_out.waves{1}.rays{iray}.ss));
0260                         end        
0261                     end
0262                 end 
0263                 %
0264             else
0265                 disp(['WARNING: ''dke_out'' structure is missing in the lukestructs{',int2str(it),'}.output structure.']);
0266                 rawdata.dke_out = '';
0267             end
0268             %
0269             if isfield(lukestructs{it}.output,'radialDKE'),
0270                 rawdata.radialDKE = lukestructs{it}.output.radialDKE;
0271             else
0272                 disp(['WARNING: ''radialDKE'' structure is missing in the lukestructs{',int2str(it),'}.output structure.']);
0273                 rawdata.radialDKE = '';
0274             end
0275             %
0276             if isfield(lukestructs{it}.output,'equilDKE'),
0277                 rawdata.equilDKE = lukestructs{it}.output.equilDKE;
0278             else
0279                 disp(['WARNING: ''equilDKE'' structure is missing in the lukestructs{',int2str(it),'}.output structure.']);
0280                 rawdata.equilDKE = '';
0281             end
0282             %
0283             if isfield(lukestructs{it},'equil'),
0284                 rawdata.equil = lukestructs{it}.equil;
0285             else
0286                 disp(['WARNING: ''equil'' structure is missing in the lukestructs{',int2str(it),'} structure.']);
0287                 rawdata.equil = '';
0288             end
0289             %
0290             if isfield(lukestructs{it}.output,'momentumDKE'),
0291                 rawdata.momentumDKE = lukestructs{it}.output.momentumDKE;
0292             else
0293                 disp(['WARNING: ''momentumDKE'' structure is missing in the lukestructs{',int2str(it),'}.output structure.']);
0294                 rawdata.momentumDKE = '';
0295             end
0296             %
0297             if isfield(lukestructs{it}.output,'gridDKE'),
0298                 rawdata.gridDKE = lukestructs{it}.output.gridDKE;
0299             else
0300                 disp(['WARNING: ''gridDKE'' structure is missing in the lukestructs{',int2str(it),'}.output structure.']);
0301                 rawdata.gridDKE = '';
0302             end
0303             %
0304             if isfield(lukestructs{it}.output,'Zmomcoef'),
0305                 rawdata.Zmomcoef = lukestructs{it}.output.Zmomcoef;
0306             else
0307                 disp(['WARNING: ''Zmomcoef'' structure is missing in the lukestructs{',int2str(it),'}.output structure.']);
0308                 rawdata.Zmomcoef = '';
0309             end
0310             %
0311             if isfield(lukestructs{it}.output,'Zbouncecoef'),
0312                 rawdata.Zbouncecoef = lukestructs{it}.output.Zbouncecoef;
0313             else
0314                 disp(['WARNING: ''Zbouncecoef'' structure is missing in the lukestructs{',int2str(it),'}.output structure.']);
0315                 rawdata.Zbouncecoef = '';
0316             end
0317             %
0318             if isfield(lukestructs{it}.output,'Zmripple'),
0319                 rawdata.Zmripple = lukestructs{it}.output.Zmripple;
0320             else
0321                 disp(['WARNING: ''Zmripple'' structure is missing in the lukestructs{',int2str(it),'}.output structure.']);
0322                 rawdata.Zmripple = '';
0323             end
0324             %
0325             if isfield(lukestructs{it}.output,'mksa'),
0326                 rawdata.mksa = lukestructs{it}.output.mksa;
0327             else
0328                 disp(['WARNING: ''mksa'' structure is missing in the lukestructs{',int2str(it),'}.output structure.']);
0329                 rawdata.mksa = '';
0330             end
0331             %
0332             if isfield(lukestructs{it}.output,'XXsinksource'),
0333                 rawdata.XXsinksource = lukestructs{it}.output.XXsinksource;
0334             else
0335                 disp(['WARNING: ''XXsinksource'' array is missing in the lukestructs{',int2str(it),'}.output structure.']);
0336                 rawdata.XXsinksource = '';
0337             end
0338             %
0339             rawdata.dkepath = dkepath;
0340             %
0341             if ~isfield(lukestructs{it}.output,'data_proc'),%local postprocessing
0342                 data_proc{it} = proc_luke_jd(rawdata,ir_display,p_opt,0.1,NaN,'',opt);
0343             else
0344                 data_proc{it} = lukestructs{it}.output.data_proc;
0345             end
0346             %
0347             waves_euitm = LUKEstruct2CPO(ver_mds,euitmshot.machine,euitmshot.numshot,euitmshot.numrun_out,euitmshot.timeslice,'waves',rawdata,data_proc{it},waves_euitm);%convert date from LUKE format to EUITM MDS+ format
0348             %
0349         elseif isfield(lukestructs{it},'err'),
0350             disp('*************************')
0351             if iscell(lukestructs{it}.err)
0352                 for ierr = 1:length(lukestructs{it}.err)
0353                     disp(lukestructs{it}.err{ierr});
0354                 end
0355             else
0356                 disp(lukestructs{it}.err);
0357             end
0358             disp('*************************')
0359         end
0360     end
0361     %
0362     save(['LUKE_RESULTS_',dataname,'.mat'],'data_proc','-append');
0363     %
0364 end
0365

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.