test_itm_starwars

PURPOSE ^

LUKE - Test program for the itm_starwars MatLab function used in KEPLER actor (C3PO/LUKE for ITM simulator)

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

LUKE - Test program for the itm_starwars MatLab function used in KEPLER actor (C3PO/LUKE for ITM simulator)

Test program for the itm_starwars MatLab function used in KEPLER actor (C3PO/LUKE for ITM simulator)
Part of this script may be used readily in the KEPLER actor
 
 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 %LUKE - Test program for the itm_starwars MatLab function used in KEPLER actor (C3PO/LUKE for ITM simulator)
0002 %
0003 %Test program for the itm_starwars MatLab function used in KEPLER actor (C3PO/LUKE for ITM simulator)
0004 %Part of this script may be used readily in the KEPLER actor
0005 %
0006 % by Yves Peysson (CEA/DSM/IRFM, yves.peysson@cea.fr) and Joan Decker (CEA/DSM/IRFM, joan.decker@cea.fr)
0007 %
0008 clear all
0009 close all
0010 clc
0011 %
0012 % Computing parameters
0013 %
0014 remdebugmode = 0;% debug mode (0) off (1) on
0015 remclean = 2;% clean job files/folders : both on remote and local (2), only on remote (1) or not at all (0)
0016 luke_memory = 12000;% job memory in mb
0017 luke_walltime = 1;%job walltime in hours
0018 enforce = 0;% exit if remote calculation failed
0019 %
0020 opt_struct = 0;%(0) light version, compatible with fluctuations, proc_luke and runhxr, (1) : heavy version, all fields are kept except XYD_rf and gridindex_rf (rarely used, except for looking for bug), (2) : full version,all fields are kept.
0021 %
0022 opt.save = 1;% (1): save LUKE_RESULTS or return error in localdatadir (0): return results or error
0023 opt.localdatadir = 'results';% local directory where LUKE_RESULTS is saved
0024 opt.fields = {'Znorm','Zcurr','ZP0','zS','dke_out','radialDKE','equilDKE','equil','momentumDKE','gridDKE','Zmomcoef','Zbouncecoef','Zmripple','mksa','XXsinksource'};% select fields to be returned from lukestructs. Use NaN to return all fields.
0025 opt.proc = struct;%postprocessing done remotely
0026 opt.backup = 0;% (1) save fluctuation time steps (0) do not save
0027 opt.waves = 0;%(-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
0028 opt.saveinputs = 0;% (1) save input structures in .mat files before starting (0) do not save
0029 %
0030 svnremoteupdate = 0;%(1) svn remote update on the ITM gateway (0) : no svn remote update on the ITM gateway
0031 %
0032 rho_S = 51;
0033 %
0034 euitm.loadlocalfile = 1;%(1): load euitm data in local file if it exists (otherwise read data in MDS+ database), (0) do not load locally (in MDS+ database only)
0035 euitm.savelocalfile = 1;%(2): save euitm data in local file and in MDS+ database (1): save euitm data in local file but not in MDS+ database, (0) do not save locally (in MDS+ database only)
0036 %
0037 % remote profile for loading data from EUITM MDS+ database only
0038 %
0039 remoteprofile = 'EFDA_ITM';
0040 scheduler = 'direct';
0041 profilename = 'yvesp';
0042 duplicate = 'true';%if true, don't use the remote LUKE_ITM toolbox
0043 %
0044 % Display and printing options
0045 %
0046 ray_display = 0;%for display ray propagation (0,1,2)
0047 display_mode = 0;%display results 'equilibrium, Fokker-Planck (0,1,2)
0048 ir_display = -1;%proc_luke_jd display option (-1,0,1,2)
0049 p_opt = -1;%Printing options
0050 %
0051 % Simulation parameters (EC17 paper parameters)
0052 %
0053 %  slice   t(s)    P_EL25(W)    P_EL40(W)    P_UL(W)
0054 %---------------------------------------------
0055 %   1       0       1e6         0           0
0056 %   2       1       0           1e6         0
0057 %   3       2       0           0           1e6
0058 %   4       3       1           0           0
0059 %   5       4       0           1           0
0060 %   6       5       0           0           1
0061 %   7       6       1e6         1e6         0
0062 %
0063 % The first three slices and the last one match the original data used for the benchmark
0064 % (still saved as shot 2, run 551). The three additional slices are a copy of the first three,
0065 % with 1W instead of 1MW at the antenna.
0066 %
0067 mds_ver = '4.10a';%'4.09a';%File format version in EUITM MDS+ database
0068 %
0069 machine = 'test';
0070 shot = 2;
0071 run= 601;
0072 run_out= 602;
0073 timeslice = NaN;%NaN;%[1,2,3,4,5,6,7];%NaN;
0074 iter = 1;
0075 occurrence_out = 0;
0076 %
0077 time_interp = 1;
0078 %
0079 CPOs = {'equilibrium','coreprof','antennas'};
0080 %
0081 occurrence_eq = 0;%equilibrium CPO occurence
0082 occurrence_cp = 0;%coreprof CPO occurence
0083 occurrence_an = 0;%antenna CPO occurence
0084 %
0085 %----------------------------------------------------------------------------------------------
0086 %
0087 CPO_occurrences = [occurrence_eq,occurrence_cp,occurrence_an];
0088 %
0089 dataname = dataname_ITM(machine,shot,run,timeslice,time_interp);
0090 filename = [pwd,'/LUKE_RESULTS_',dataname,'.mat'];
0091 %
0092 if exist(filename,'file'),
0093     cleansim = input_dke_yp(['Do you to clean the existing simulation: ',dataname,' (y/n)'],'n',{'y','n'});
0094     disp(' ')
0095     if cleansim == 'y',% clean simulation
0096         delete(filename)
0097     end
0098 end
0099 %
0100 if ~exist(filename,'file'),% load existing simulation if it exists
0101     %
0102     dkepath = setpath_luke_jd('');
0103     %
0104     if ~isempty(dkepath.remote),
0105         remopt = input_dke_yp(['Do you want to transfer the distributed calculation to a remote host (y/n)'],'n',{'y','n'});
0106         disp(' ')
0107     else
0108         remopt = 'n';
0109     end
0110     %
0111     if remopt == 'y',% use of mdce_remote
0112         remnum = iselect_jd(dkepath.profilestr,'Please select the host for the distributed calculation ?',0,struct,1);
0113         disp(' ')
0114         dist_mode = NaN;
0115         mdce_mode = input_dke_yp(['Please select a mode for the distribution on host ',dkepath.profilestr{remnum},':\n(0) sequential \n(1) jobcomputing \n(2) parcomputing \n(3) remcomputing \n'],0,0:3);
0116         disp(' ')
0117         %
0118         remtimout = input_dke_yp(['Timeout for remote calculations, in minutes. Use (0) to return later and check results by running this script again'],0,0:1000);
0119         disp(' ')
0120         %
0121         if remtimout > 0,
0122             rempause = input_dke_yp(['Pause between job checks (in minutes)'],1,1:10);
0123         else
0124             rempause = 1;
0125         end
0126         %
0127     else% direct distribution from localhost
0128         remnum = 0;
0129         remtimout = input_dke_yp(['Timeout for remote calculations, in minutes.'],100,10:1000);
0130         disp(' ')
0131         %
0132         rempause = input_dke_yp(['Pause between job checks (in minutes)'],1,1:10);
0133         disp(' ')
0134         %
0135         dist_mode = iselect_jd(dkepath.distprofiles,'Please select a mode for the distribution from the local host ?',0,struct,1);
0136         disp(' ')
0137         if dist_mode > 3,
0138             mdce_mode = 3 - dist_mode;
0139         else
0140             mdce_mode = dist_mode - 1;
0141         end
0142     end 
0143     %
0144     remstart = 0;% (1) start new simulation; (0) check older simulation (only for remtimout = 0)
0145     %
0146     opts.remnum = remnum;%3;% remote profile number. Use 0 for local sequential calculations (for LUKE only from ITM gateway). (> 0 transfer before distribution, <0 distribution before transfer)
0147     opts.remmdce = mdce_mode;%distribution mode of LUKE on the remote machine (0) sequential, (1) jobcomputing, (2) parcomputing, (3) remcomputing
0148     opts.remtimout = remtimout;% timeout for remote calculations, in minutes. Use (0) to return later and check results by running this script again
0149     opts.rempause = rempause;% pause between job checks (in minutes) (only for remtimout > 0)
0150     opts.remstart = remstart;% (1) start new simulation; (0) check older simulation (only for remtimout = 0)
0151     opts.remdebugmode = remdebugmode;% debug mode (0) off (1) on
0152     opts.remclean = remclean;% clean job files/folders : both on remote and local (2), only on remote (1) or not at all (0)
0153     opts.luke_memory = luke_memory;% job memory in mb
0154     opts.luke_walltime = luke_walltime;%job walltime in hours
0155     opts.enforce = enforce;% exit if remote calculation failed
0156     %
0157     opts.opt_struct = opt_struct;%(0) light version, compatible with fluctuations, proc_luke and runhxr, (1) : heavy version, all fields are kept except XYD_rf and gridindex_rf (rarely used, except for looking for bug), (2) : full version,all fields are kept.
0158     %
0159     opts.opt.save = opt.save;% (1): save LUKE_RESULTS or return error in localdatadir (0): return results or error
0160     opts.opt.localdatadir = opt.localdatadir;% local directory where LUKE_RESULTS is saved
0161     opts.opt.fields = opt.fields;% select fields to be returned from lukestructs. Use NaN to return all fields.
0162     opts.opt.proc = opt.proc;%postprocessing done remotely
0163     opts.opt.backup = opt.backup;% (1) save fluctuation time steps (0) do not save
0164     opts.opt.waves = 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
0165     opts.opt.saveinputs = opt.saveinputs;% (1) save input structures in .mat files before starting (0) do not save
0166     %
0167     opts.svnremoteupdate = svnremoteupdate;%(1) svn remote update on the ITM gateway (0) : no svn remote update on the ITM gateway
0168     %
0169     opts.rho_S = rho_S;
0170     %
0171     opts.euitm.loadlocalfile = euitm.loadlocalfile;%(1): load euitm data in local file if it exists (otherwise read data in MDS+ database), (0) do not load locally (in MDS+ database only)
0172     opts.euitm.savelocalfile = euitm.savelocalfile;%(2): save euitm data in local file and in MDS+ database (1): save euitm data in local file but not in MDS+ database, (0) do not save locally (in MDS+ database only)
0173     %
0174     opts.opt.ray_display = ray_display;%for display ray propagation (0,1,2)
0175     opts.opt.display_mode = display_mode;%display results 'equilibrium, Fokker-Planck (0,1,2)
0176     opts.opt.ir_display = ir_display;%proc_luke_jd display option (-1,0,1,2)
0177     opts.opt.p_opt = p_opt;%Printing options
0178     %
0179     disp('*************************************')
0180     disp([' ---> remunm = ',int2str(remnum)])
0181     disp([' ---> mdce_mode = ',int2str(mdce_mode)])
0182     disp('*************************************')
0183     %
0184 else
0185     temp_luke_results = load(['LUKE_RESULTS_',dataname,'.mat']);
0186     %
0187     opts = temp_luke_results.opts;
0188     dkepath = temp_luke_results.dkepath;
0189     %
0190     if isfield(temp_luke_results,'data_proc')
0191         disp(['WARNING: the file LUKE_RESULTS_',dataname,'.mat must be deleted or renamed first to start a new simulation.']);
0192         clear('temp_luke_results');
0193     end
0194     %
0195 end
0196 %
0197 disp('---------------------------------------------')
0198 if opts.remnum > 0
0199     disp(['Computer used for calculations --> ',dkepath.profilestr{opts.remnum}]);
0200 else
0201     disp('Local computer used for calculations');
0202 end
0203 disp(['Distributed computing mode     --> ',int2str(opts.remmdce)]);
0204 disp('---------------------------------------------')
0205 %
0206 cd([dkepath.luke_root,'Project_DKE/Modules/ITM'])
0207 %
0208 [s_host,w_host] = unix('hostname -f');%identify the local machine
0209 %
0210 % check if current jobs exists to load possible existing jobs
0211 %
0212 if ~length(strfind(w_host,'itm')),%remote calculations
0213     [remote,profilestr] = load_remoteprofiles_jd(remoteprofile,false,false,scheduler,profilename,duplicate);
0214     job = matstandardjob_jd('runmat');
0215     if exist('opts') && isfield(opts,'remdebugmode') && opts.remdebugmode,
0216         remote.debugmode = 1;
0217     end 
0218 else
0219     remote = [];
0220     job = [];
0221 end
0222 %
0223 if isfield(opts,'svnremoteupdate') && opts.svnremoteupdate,
0224     %
0225     [err_svn,~,c_svn,s_svn,w_svn] = matremote_jd('itmsvnupdate',{},remote,job);%svn remote or local update
0226     %
0227     if ~isempty(err_svn),
0228         disp('WARNING: SVN update of the ITM tools for LUKE calculations failed') 
0229     else
0230         disp(['Successful SVN update of the ITM tools for LUKE calculations: ',w_svn{1},w_svn{2}]),
0231     end
0232 end
0233 %
0234 if ~isfield(opts,'euitm') || ~isfield(opts.euitm,'savelocalfile') || opts.euitm.savelocalfile ~= 1,%LUKE results are saved in MDS+ database
0235     %
0236     if ~exist('machine_mds','var') || ~exist('username_mds','var') || ~exist('ver_mds','var'),
0237         [err_mds,~,machine_mds,username_mds,ver_mds] = matremote_jd('which_MDSdatabase',{},remote,job);%remote or local test of the MDS database
0238         %
0239         if  ~isempty(err_mds),
0240             error(['ERROR: ITM database not recognized -> machine: ',machine_mds,', user: ',username_mds,', datastructure version: ',ver_mds]);
0241         else
0242             disp(['ITM database well recognized -> machine: ',machine_mds,', user: ',username_mds,', datastructure version: ',ver_mds]);
0243         end
0244     end
0245     %
0246     if ~strcmp(machine,machine_mds),disp('WARNING: inconsistent machine name between script and MDS+ database.');end
0247     %
0248     [err_database,~,flag_database] = matremote_jd('database_recreate_ITM',{'shot','run_out'},remote,job);%remote or local database creation output (for the test only)
0249     %
0250     if ~isempty(err_database),
0251         disp('WARNING: output MDS database creation failed. Data saved locally') 
0252         opts.euitm.savelocalfile = 1;%LUKE results not saved in the MDS database
0253     else
0254         disp('Output MDS database creation successfuly created.') 
0255     end
0256 end
0257 %
0258 [err_waves,waves] = itm_starwars(mds_ver,machine,shot,run,timeslice,time_interp,CPOs,CPO_occurrences,run_out,iter,occurrence_out,opts);
0259 %
0260 if isstruct(waves),    
0261     %
0262     if ~exist('opts') || ~isfield(opts,'euitm') || ~isfield(opts.euitm,'savelocalfile') || opts.euitm.savelocalfile ~= 1,%LUKE results are saved in MDS+ database
0263         [err_waves,~,waves_euitm] = matremote_jd('check_write_waves_ITM',{length(remote),shot,run_out},remote,job);%write LUKE ouput in ITM database
0264     else
0265         waves_euitm = '';
0266     end
0267     %
0268     load(['LUKE_RESULTS_',dataname,'.mat'],'data_proc');
0269     %
0270     for it = 1:length(waves),
0271         figure;
0272         graph1D_jd(waves(it).coherentwave(1).grid_1d.psi,waves(it).coherentwave(1).profiles_1d.powd_tot,0,0,'','','',NaN,NaN,NaN,'-','none','r',2);hold on
0273         %
0274         if isstruct(waves_euitm), 
0275             graph1D_jd(waves_euitm(it).coherentwave(1).grid_1d.psi,waves_euitm(it).coherentwave(1).profiles_1d.powd_tot,0,0,'','','',NaN,NaN,NaN,'-','none','b',2);hold on
0276         end
0277         %
0278         disp('--------------')
0279         disp(['Line-averaged electron density (it = ',int2str(it),') -> ',num2str(data_proc{it}.scalar.jne/1e20),' (10+20 m-3)']);
0280         disp(['Major radius (it = ',int2str(it),') -> ',num2str(data_proc{it}.scalar.Rp),' (m)']);
0281         %
0282         disp(['RF absorbed power (it = ',int2str(it),') -> ',num2str(data_proc{it}.scalar.p0_rf_2piRp*2*pi*data_proc{1}.scalar.Rp),' (MW)']);
0283         disp(['RF current (it = ',int2str(it),') -> ',num2str(data_proc{it}.scalar.I_tot),' (MA)']);
0284         disp(['RF current drive efficiency (it = ',int2str(it),') -> ',num2str(data_proc{it}.scalar.EtaRFRp),' (10+19 A.m.W-1)']);
0285         %
0286     end
0287     %
0288     if ~exist('opts') || ~isfield(opts,'euitm') || ~isfield(opts.euitm,'savelocalfile') || opts.euitm.savelocalfile == 0,%LUKE results are saved in MDS+ database
0289         if exist(['MDSDATA_euitm_',dataname,'.mat'],'file'),
0290             delete(['MDSDATA_euitm_',dataname,'.mat'],'file'),
0291         end
0292     end
0293     %
0294 else
0295     disp(err_waves);%in case of error
0296 end

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