0001 function imake_makewave_jd(workdir,wave,opt_gui)
0002
0003 if nargin < 3,
0004 opt_gui = 1;
0005 end
0006
0007
0008
0009 equilstr = wave.equil_id;
0010 equilstr(equilstr == '.') = 'p';
0011
0012 [data_file,data_path] = iputfile_jd(opt_gui,'make_wave*.m','Please provide a name for the make_wave script',[workdir,'make_wave_',equilstr,'_',wave.id,'.m']);
0013
0014 if data_file == 0,
0015 disp('-----> No make_wave script name specified.');
0016 return
0017 end
0018
0019 filename = [data_path,data_file];
0020
0021
0022
0023 s = {};
0024 s = [s,{'% Script for generating WAVE structure using C3PO'}];
0025 s = [s,{'%'}];
0026 s = [s,{'% This script is automatically generated by imake_wave_jd.'}];
0027 s = [s,{'% by J. Decker (joan.decker@cea.fr) and Y. Peysson (yves.peysson@cea.fr)'}];
0028 s = [s,{'%'}];
0029 s = [s,{'clear all'}];
0030 s = [s,{'clear mex'}];
0031 s = [s,{'clear functions'}];
0032 s = [s,{'close all'}];
0033 s = [s,{'%'}];
0034 s = [s,{['id_wave = ''',wave.id,''';']}];
0035 s = [s,{'%'}];
0036 s = [s,{'% Path parameters'}];
0037 s = [s,{'%'}];
0038 s = [s,{'id_dkepath = '''';%For all paths used by DKE solver'}];
0039 s = [s,{'path_dkepath = '''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path'}];
0040 s = [s,{'%'}];
0041 s = [s,{'% Equilibrium parameters'}];
0042 s = [s,{'%'}];
0043 s = [s,{['id_equil = ''',wave.equil_id,''';%For plasma equilibrium']}];
0044 s = [s,{'path_equil = '''';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path'}];
0045 s = [s,{'%'}];
0046 s = [s,{'% initial ray conditions'}];
0047 s = [s,{'%'}];
0048
0049 if isfield(wave.rayinit,'launch'),
0050 s = [s,{['ids_launch = {''',wave.rayinit.launch.id,'''};']}];
0051 s = [s,{'paths_launch = {''''};'}];
0052 else
0053 s = [s,{['ids_rayinit = {''',wave.rayinit.id,'''};']}];
0054 s = [s,{'paths_rayinit = {''''};'}];
0055 end
0056
0057 s = [s,{'%'}];
0058 s = [s,{'% C3PO computing parameters'}];
0059 s = [s,{'%'}];
0060 s = [s,{['C3POparam.clustermode.main_C3PO_jd.scheduler.mode = ',num2str(wave.C3POparam.clustermode.main_C3PO_jd.scheduler.mode),';%MatLab distributed computing environment disabled (0), enabled with the dedicated toolbox (1), enabled with a private method (2)for the function main_C3PO_jd.m (MDC toolbox must be installed for option 1)']}];
0061 s = [s,{['C3POparam.clustermode.main_C3PO_jd.scheduler.size = ',num2str(wave.C3POparam.clustermode.main_C3PO_jd.scheduler.memory),';%MatLab distributed computing environment cluster size. Can be Inf is all the processors of the cluster are free for distributed calculations']}];
0062 s = [s,{'%'}];
0063 s = [s,{'% Display parameters'}];
0064 s = [s,{'%'}];
0065 s = [s,{['C3POdisplay.ray = ',num2str(wave.display.ray),';']}];
0066 s = [s,{['C3POdisplay.equilibrium = ',num2str(wave.display.equilibrium),';']}];
0067 s = [s,{['C3POdisplay.p_opt = ',num2str(wave.display.p_opt),';%Printing or saving option of the figures']}];
0068 s = [s,{'%'}];
0069 s = [s,{'% Wave parameters'}];
0070 s = [s,{'%'}];
0071 s = [s,{['waveparam.mmode = ',num2str(wave.waveparam.mmode),';%cold plasma mode [1] : (-1) m (1) p, p is the slow mode when kperp > 0 (ex : LH slow wave)']}];
0072 s = [s,{['waveparam.kmode = ',num2str(wave.waveparam.kmode),';%(0:cold,1:warm,2:hot;3:weak realtivistic,4:full relativistic)']}];
0073 s = [s,{'%'}];
0074 s = [s,{'%Option parameter for FLR effects and cross-comparison between old FP code: '}];
0075 s = [s,{'% - (0): all FLR effects'}];
0076 s = [s,{'% - (1): small FLR effects and 1/vpar dependence'}];
0077 s = [s,{'% - (2): small FLR effects and no 1/vpar dependence and old grid technique for DQL calculations (Karney, Shoucri) (see rfdiff_dke_jd)'}];
0078 s = [s,{'%'}];
0079 s = [s,{['waveparam.opt_rf = ',num2str(wave.waveparam.opt_rf),';']}];
0080 s = [s,{'%'}];
0081 s = [s,{['waveparam.dsmin = ',num2str(wave.waveparam.dsmin),';%minimum size for ray fragments']}];
0082 s = [s,{'%'}];
0083 s = [s,{['waveparam.nd = ',num2str(wave.waveparam.nd),';%Number of transverse distance positions for beamlets']}];
0084 s = [s,{['waveparam.nchi = ',num2str(wave.waveparam.nchi),';%Number of angular positions for beamlets']}];
0085 s = [s,{'%'}];
0086 s = [s,{['waveparam.n_rf_list = [',num2str(wave.waveparam.n_rf_list),'];']}];
0087 s = [s,{'%'}];
0088 s = [s,{'% -------------------------------------------------------------------------'}];
0089 s = [s,{'%'}];
0090 s = [s,{'% Global parameters for the vectorial magnetic equilibrium'}];
0091 s = [s,{'%'}];
0092 s = [s,{'% Equilibrium parameters for the ray-tracing'}];
0093 s = [s,{'%'}];
0094 s = [s,{['fitparam.mode_equil = ',num2str(wave.fitparam.mode_equil),';%Magnetic equilibrium grid type: (1): (psi-theta), (2): (x-y)']}];
0095 s = [s,{['fitparam.method = ''',wave.fitparam.method,''';%nearest,spline,pchip']}];
0096 s = [s,{['fitparam.nharm = ',num2str(wave.fitparam.nharm),';%Number of harmonics in the magnetic equilibrium interpolation (less than ntheta_equil/2)']}];
0097 s = [s,{['fitparam.ngridresample = ',num2str(wave.fitparam.ngridresample),';%Number of grid points for resampling the radial profile of magnetic equilibrium parameters']}];
0098 s = [s,{['fitparam.opt_load = ',num2str(wave.fitparam.opt_load),';%Reload existing vectorial magnetic equilibrium (1) or overwrite it (0).']}];
0099 s = [s,{'%'}];
0100 s = [s,{'% Global parameters for the ray-tracing'}];
0101 s = [s,{'%'}];
0102 s = [s,{['rayparam.testmode = ',num2str(wave.rayparam.testmode),';']}];
0103 s = [s,{['rayparam.tensortype = ',num2str(wave.rayparam.tensortype),';%(0:cold,1:warm,2:hot;3:weak realtivistic,4:full relativistic)']}];
0104 s = [s,{['rayparam.t0 = ',num2str(wave.rayparam.t0),';']}];
0105 s = [s,{['rayparam.tfinal = ',num2str(wave.rayparam.tfinal),';']}];
0106 s = [s,{['rayparam.dt0 = ',num2str(wave.rayparam.dt0),';']}];
0107 s = [s,{['rayparam.dS = ',num2str(wave.rayparam.dS),';']}];
0108 s = [s,{['rayparam.tol = ',num2str(wave.rayparam.tol),';%when tolerance is increased (less accurate calculation of D=0), tfinal must be increased accordingly']}];
0109 s = [s,{['rayparam.kmax = ',num2str(wave.rayparam.kmax),';']}];
0110 s = [s,{['rayparam.ncyclharm = ',num2str(wave.rayparam.ncyclharm),';%number of cyclotron harmonics (just for hot and relativistic dielectric tensors)']}];
0111 s = [s,{['rayparam.reflection = ',num2str(wave.rayparam.reflection),';%1:Enforce wave reflection at plasma boundary, 0: the code calculates itself if the ray must leave of not the plasma']}];
0112 s = [s,{['rayparam.rel_opt = ',num2str(wave.rayparam.rel_opt),';%option for (1) relativistic or (0) non-relativistic calculations']}];
0113 s = [s,{['rayparam.nperp =',num2str(wave.rayparam.nperp),';%number of points in pperp integration for damping calculations']}];
0114 s = [s,{['rayparam.pperpmax = ',num2str(wave.rayparam.pperpmax),';%maximum value of pperp in damping calculations']}];
0115 s = [s,{['rayparam.tau_lim = ',num2str(wave.rayparam.tau_lim),';%value of optical depth beyond which the wave is considered absorbed']}];
0116 s = [s,{['rayparam.kextra = ',num2str(wave.rayparam.kextra),';']}];
0117 s = [s,{'%'}];
0118 s = [s,{'% -------------------------------------------------------------------------'}];
0119 s = [s,{'%'}];
0120 s = [s,{'% Load structures'}];
0121 s = [s,{'%'}];
0122
0123 if isfield(wave.rayinit,'launch'),
0124 s = [s,{'[equil,launchs,dkepath] = load_structures_yp(''equil'',id_equil,path_equil,''launchs'',ids_launch,paths_launch,''dkepath'',id_dkepath,path_dkepath);'}];
0125 s = [s,{'launch = launchs{1};'}];
0126 s = [s,{'%'}];
0127 s = [s,{'rayinit = main_rayinit_launch_jd(equil,launch);'}];
0128 s = [s,{'rayinit.id = [''C3PO_'',launch.id];'}];
0129 s = [s,{'rayinit.type = launch.type;'}];
0130 else
0131 s = [s,{'[equil,rayinits,dkepath] = load_structures_yp(''equil'',id_equil,path_equil,''rayinits'',ids_rayinit,paths_rayinit,''dkepath'',id_dkepath,path_dkepath);'}];
0132 s = [s,{'rayinit = rayinits{1};'}];
0133 end
0134 s = [s,{'%'}];
0135 s = [s,{'% -------------------------------------------------------------------------'}];
0136 s = [s,{'%'}];
0137 s = [s,{'% C3P0 ray tracing'}];
0138 s = [s,{'%'}];
0139 s = [s,{'wave = main_C3PO_jd(dkepath,id_wave,equil,'''',rayinit,waveparam,fitparam,rayparam,C3POdisplay,C3POparam);'}];
0140 s = [s,{'%'}];
0141 s = [s,{'% Wave processing and relativistic linear damping'}];
0142 s = [s,{'%'}];
0143 s = [s,{'wave = wave_process_jd(equil,wave,waveparam.n_rf_list);'}];
0144 s = [s,{'%'}];
0145 s = [s,{'save_str = [''WAVE_'',id_equil,''_'',id_wave,''.mat''];'}];
0146 s = [s,{'eval([''save '',save_str,'' wave'']);'}];
0147 s = [s,{'%'}];
0148 s = [s,{'info_dke_yp(2,''Wave parameters saved'');'}];
0149 s = [s,{'%'}];
0150
0151 fid = fopen(filename,'w');
0152
0153 for is = 1:length(s),
0154 fprintf(fid,'%s\n',s{is});
0155 end
0156
0157 fclose(fid);
0158 disp(['-----> The make_wave script ',filename,' has been created.']);
0159
0160