imake_rundke_jd

PURPOSE ^

SYNOPSIS ^

function imake_rundke_jd(paths,fileids,status,workdir,id_simul_o,opt_gui)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function imake_rundke_jd(paths,fileids,status,workdir,id_simul_o,opt_gui)
0002 %
0003 if nargin < 6,
0004     opt_gui = 1;
0005 end
0006 if nargin < 5,
0007     id_simul_o = '';
0008 end
0009 %
0010 % This function automatically generates a rundke script to run LUKE
0011 %
0012 if ~isfield(fileids,'dkeparam') || ~isfield(fileids,'equil'),
0013     disp('-----> the structures dkeparam and equil must exist in a fileids to run LUKE.');
0014     return
0015 end
0016 %
0017 fileids.dkepath = '';%defined by select_LUKE.m
0018 paths.dkepath = '';%defined by select_LUKE.m
0019 %
0020 id_simul = input(['Please provide an id for the run [',id_simul_o,'] : '],'s');
0021 if isempty(id_simul),
0022     id_simul = id_simul_o;
0023 end
0024 %
0025 filestr = [workdir,'rundke_',id_simul];
0026 filestr(filestr == '.') = 'p';
0027 %
0028 [data_file,data_path] = iputfile_jd(opt_gui,'rundke*.m','Please provide a fileids name for the LUKE run script',[filestr,'.m']);
0029 %
0030 if data_file == 0,
0031     disp('-----> No LUKE run script name specified.');
0032     return
0033 end  
0034 %
0035 filename = [data_path,data_file];
0036 %
0037 % RUN SCRIPT GENERATION
0038 %
0039 s = {};
0040 s = [s,{'% Script for running LUKE'}];
0041 s = [s,{'%'}];
0042 s = [s,{'% This script is automatically generated by irunluke_jd.'}];
0043 s = [s,{'% by J. Decker (joan.decker@cea.fr) and Y. Peysson (yves.peysson@cea.fr)'}];
0044 s = [s,{'%'}];
0045 s = [s,{'clear all'}];
0046 s = [s,{'clear mex'}];
0047 s = [s,{'clear functions'}];
0048 s = [s,{'close all'}];
0049 s = [s,{'warning(''off'',''all'')'}];
0050 s = [s,{'pause(1)'}];
0051 s = [s,{'%'}];
0052 s = [s,{'p_opt = -1;% printing option (-1): none, (0): printer, (1) printer and files, (2) files'}];
0053 s = [s,{'remnum = 0;% batch run index in dkepath.remote; (0) for local run.'}];
0054 s = [s,{'remtimeout = 60;% waiting time in batch run'}];
0055 s = [s,{'%'}];
0056 s = [s,{'% *********************** Specify LUKE structures *****************************'}];
0057 s = [s,{'%'}];
0058 s = [s,{['id_simul = ''',id_simul,''';%Simulation ID']}];
0059 s = [s,{['path_simul = '''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path']}];
0060 %s = [s,{'%'}];
0061 %s = [s,{'psin_S = [];%Normalized poloidal flux grid where calculations are performed (0 < psin_S < 1) (If one value: local calculation only, not used if empty)'}];
0062 %s = [s,{['rho_S = [',num2str(rho_S),'];%Normalized radial flux grid where calculations are performed (0 < rho_S < 1) (If one value: local calculation only, not used if empty)']}];
0063 s = [s,{'%'}];
0064 s = [s,{['id_dkepath = ''',fileids.dkepath,''';%For all paths used by DKE solver']}];
0065 s = [s,{['path_dkepath = ''',paths.dkepath,''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path']}];
0066 s = [s,{'%'}];
0067 s = [s,{['id_equil = ''',fileids.equil,''';%For plasma equilibrium']}];
0068 s = [s,{['path_equil = ''',paths.equil,''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path']}];
0069 s = [s,{'%'}];
0070 s = [s,{['id_dkeparam = ''',fileids.dkeparam,''';%For DKE code parameters']}];
0071 s = [s,{['path_dkeparam = ''',paths.dkeparam,''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path']}];
0072 s = [s,{'%'}];
0073 s = [s,{'id_dkedisplay = ''NO_DISPLAY'';%For output code display'}];
0074 s = [s,{'path_dkedisplay = '''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path'}];
0075 s = [s,{'%'}];
0076 s = [s,{'id_ohm = '''';%For Ohmic electric contribution'}];
0077 s = [s,{'path_ohm = '''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path'}];
0078 %
0079 if status.ohm,
0080     if ~isempty(fileids.ohm),
0081         disp(['----> The run script is generated with the ''ohm'' structure ',fileids.ohm,'.']); 
0082         s{end-1} = ['id_ohm = ''',fileids.ohm,''';%For Ohmic electric contribution'];
0083         s{end} = ['path_ohm = ''',paths.ohm,''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path'];
0084     else
0085         disp('----> The ''ohm'' structure was not saved and is not included in the run script.');
0086     end
0087 else
0088     disp('----> The run script is generated without ''ohm'' structure.');
0089 end
0090 %
0091 s = [s,{'%'}];
0092 %
0093 waves_idstr = '''';
0094 waves_pathstr = '''';
0095 cnt = 0;
0096 if status.waves,
0097     for iw = 1:length(fileids.waves),
0098         if ~isempty(fileids.waves{iw}),
0099             disp(['----> The run script is generated with the ''wave'' structure ',fileids.waves{iw},'.']);
0100             if cnt > 0,
0101                 waves_idstr = [waves_idstr,''',''',fileids.waves{iw}];
0102                 waves_pathstr = [waves_pathstr,''',''',paths.waves{iw}];
0103             else
0104                 waves_idstr = [waves_idstr,fileids.waves{iw}];
0105                 waves_pathstr = [waves_pathstr,paths.waves{iw}];
0106                 cnt = 1;
0107             end
0108         else
0109             disp(['----> The ''wave'' structure #',num2str(iw),'was not saved and is not included in the run script.']);
0110         end
0111     end
0112 else
0113     disp('----> The run script is generated without ''wave'' structures.');
0114 end
0115 waves_idstr = [waves_idstr,''''];
0116 waves_pathstr = [waves_pathstr,''''];
0117 %
0118 s = [s,{['ids_wave = {',waves_idstr,'};%For RF waves contribution (put all the type of waves needed)']}];
0119 s = [s,{['paths_wave = {',waves_pathstr,'};%if nothing is specified, the working directory is first used and then MatLab is looking in all the path']}];
0120 s = [s,{'%'}];
0121 s = [s,{'id_transpfaste = '''';%For fast electron radial transport'}];
0122 s = [s,{'path_transpfaste = '''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path'}];
0123 %
0124 if status.transpfaste,
0125     if ~isempty(fileids.transpfaste),
0126         disp(['----> The run script is generated with the ''transpfaste'' structure ',fileids.transpfaste,'.']); 
0127         s{end-1} = ['id_transpfaste = ''',fileids.transpfaste,''';%For fast electron radial transport'];
0128         s{end} = ['path_transpfaste = ''',paths.transpfaste,''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path'];
0129     else
0130         disp('----> The ''transpfaste'' structure was not saved and is not included in the run script.');
0131     end
0132 else
0133     disp('----> The run script is generated without ''transpfaste'' structure.');
0134 end
0135 %
0136 s = [s,{'%'}];
0137 s = [s,{'id_ripple = '''';%For fast electron magnetic ripple losses'}];
0138 s = [s,{'path_ripple = '''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path'}];
0139 %
0140 if status.ripple,
0141     if ~isempty(fileids.ripple),
0142         disp(['----> The run script is generated with the ''ripple'' structure ',fileids.ripple,'.']); 
0143         s{end-1} = ['id_ripple = ''',fileids.ripple,''';%For fast electron magnetic ripple losses'];
0144         s{end} = ['path_ripple = ''',paths.ripple,''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path'];
0145     else
0146         disp('----> The ''ripple'' structure was not saved and is not included in the run script.');
0147     end
0148 else
0149     disp('----> The run script is generated without ''ripple'' structure.');
0150 end
0151 %
0152 s = [s,{'%'}];
0153 s = [s,{'[dkepath,equil,dkeparam,dkedisplay,ohm,waves,transpfaste,ripple] = load_structures_yp(''dkepath'',id_dkepath,path_dkepath,''equil'',id_equil,path_equil,''dkeparam'',id_dkeparam,path_dkeparam,''dkedisplay'',id_dkedisplay,path_dkedisplay,''ohm'',id_ohm,path_ohm,''waves'',ids_wave,paths_wave,''transpfaste'',id_transpfaste,path_transpfaste,''ripple'',id_ripple,path_ripple);'}];
0154 s = [s,{'%'}];
0155 s = [s,{'%************************************************************************************************************************************'}];
0156 s = [s,{'%'}];
0157 s = [s,{'%'}];
0158 s = [s,{'dkepath.remnum = remnum;'}];
0159 s = [s,{'dkepath.remtimeout = remtimeout;'}];
0160 s = [s,{'%'}];
0161 s = [s,{'lukestructs = struct;'}];
0162 s = [s,{'lukestructs.simul.id_simul = id_simul;'}];
0163 s = [s,{'lukestructs.simul.path = path_simul;;'}];
0164 s = [s,{'lukestructs.dkeparam = dkeparam;'}];
0165 s = [s,{'lukestructs.dkepath = dkepath;'}];
0166 s = [s,{'lukestructs.dkedisplay = dkedisplay;'}];
0167 s = [s,{'lukestructs.equil = equil;'}];
0168 s = [s,{'lukestructs.waves = waves;'}];
0169 s = [s,{'lukestructs.wavestructs = [];'}];
0170 s = [s,{'lukestructs.ohm = ohm;'}];
0171 s = [s,{'lukestructs.transpfaste = transpfaste;'}];
0172 s = [s,{'lukestructs.ripple = ripple;'}];
0173 s = [s,{'lukestructs.Zf0_interp = [];'}];
0174 s = [s,{'%'}];
0175 s = [s,{'lukestructs = run_lukert(lukestructs,dkepath);'}];
0176 s = [s,{'%'}];
0177 s = [s,{'if isfield(lukestructs,''err''),'}];
0178 s = [s,{'    disp(''LUKE run failed for the following reason :'')'}];
0179 s = [s,{'    disperr_jd(lukestructs.err);'}];
0180 s = [s,{'    error(''LUKE run failed'')'}];
0181 s = [s,{'else'}];
0182 s = [s,{'    %'}];
0183 s = [s,{'    Znorm = lukestructs.output.Znorm;'}];
0184 s = [s,{'    Zcurr = lukestructs.output.Zcurr;'}];
0185 s = [s,{'    ZP0 = lukestructs.output.ZP0;'}];
0186 s = [s,{'    dke_out = lukestructs.output.dke_out;'}];
0187 s = [s,{'    radialDKE = lukestructs.output.radialDKE;'}];
0188 s = [s,{'    equilDKE = lukestructs.output.equilDKE;'}];
0189 s = [s,{'    momentumDKE = lukestructs.output.momentumDKE;'}];
0190 s = [s,{'    gridDKE = lukestructs.output.gridDKE;'}];
0191 s = [s,{'    Zmomcoef = lukestructs.output.Zmomcoef;'}];
0192 s = [s,{'    Zbouncecoef = lukestructs.output.Zbouncecoef;'}];
0193 s = [s,{'    Zmripple = lukestructs.output.Zmripple;'}];
0194 s = [s,{'    mksa = lukestructs.output.mksa;'}];
0195 s = [s,{'    XXsinksource = lukestructs.output.XXsinksource;'}];
0196 s = [s,{'    %'}];
0197 s = [s,{'end'}];
0198 s = [s,{'%'}];        
0199 s = [s,{'%************************************************************************************************************************************'}];
0200 s = [s,{'I_tot = sum(Zcurr.x_0_fsav.*equilDKE.xdA_dke*mksa.j_ref);'}];
0201 s = [s,{'figure(''Name'',''Current profile''),'}];
0202 s = [s,{'graph1D_jd(equilDKE.xrho,Zcurr.x_0_fsav*mksa.j_ref,0,0,''\rho'',''J_{tot} (MA/m^2)'',[''I_{tot} = '',num2str(I_tot),'' (MA)''],NaN,NaN,NaN,''-'',''none'',''r'',2,20,gca,0.9,0.7,0.7);drawnow'}];
0203 s = [s,{'print_jd(p_opt,[id_simul,''_Curr'']);'}];
0204 s = [s,{'%'}];
0205 s = [s,{'PRF_tot = sum(ZP0.x_rf_fsav.*equilDKE.xdV_2piRp_dke(:)*mksa.P_ref*2*pi*equilDKE.Rp);'}];
0206 s = [s,{'figure(''Name'',''LH Power''),'}];
0207 s = [s,{'graph1D_jd(equilDKE.xrho,ZP0.x_rf_fsav*mksa.P_ref,0,0,''\rho'',''P_{RF} (MW/m^3)'',[''P_{RF} = '',num2str(PRF_tot),'' (MW)''],NaN,NaN,NaN,''-'',''none'',''r'',2,20,gca,0.9,0.7,0.7);drawnow'}];
0208 s = [s,{'print_jd(p_opt,[id_simul,''_RF_Power'']);'}];
0209 s = [s,{'%'}];
0210 s = [s,{'POHM_tot = sum(ZP0.x_e_fsav.*equilDKE.xdV_2piRp_dke*mksa.P_ref*2*pi*equilDKE.Rp);'}];
0211 s = [s,{'figure(''Name'',''Ohmic Power''),'}];
0212 s = [s,{'graph1D_jd(equilDKE.xrho,ZP0.x_e_fsav*mksa.P_ref,0,0,''\rho'',''P_{OHM} (MW/m^3)'',[''P_{OHM} = '',num2str(POHM_tot),'' (MW)''],NaN,NaN,NaN,''-'',''none'',''r'',2,20,gca,0.9,0.7,0.7);drawnow'}];
0213 s = [s,{'print_jd(p_opt,[id_simul,''_Ohm'']);'}];
0214 s = [s,{'%'}];
0215 s = [s,{'filename = [path_simul,''LUKE_RESULTS_'',id_equil,''_'',id_simul,''.mat''];'}];
0216 s = [s,{'save(filename);'}];
0217 s = [s,{'info_dke_yp(2,[''LUKE Results saved in '',filename]);'}];
0218 s = [s,{'%'}];
0219 %
0220 fid = fopen(filename,'w');
0221 %
0222 for is = 1:length(s),
0223     fprintf(fid,'%s\n',s{is});
0224 end
0225 %
0226 fclose(fid);
0227 disp(['-----> The rundke fileids ',filename,' has been created.']);
0228 %
0229 
0230

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