imake_wave_jd

PURPOSE ^

SYNOPSIS ^

function wave = imake_wave_jd(dkepath,basestr,equil,external,workdir,opt_gui,select)

DESCRIPTION ^

 This function interactively builds the wave structure

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function wave = imake_wave_jd(dkepath,basestr,equil,external,workdir,opt_gui,select)
0002 %
0003 % This function interactively builds the wave structure
0004 %
0005 if nargin < 7,
0006     select = struct;
0007 end
0008 %
0009 if nargin < 6,
0010     opt_gui = true;
0011 end
0012 %
0013 if nargin < 5,
0014     workdir = pwd;
0015 end
0016 %
0017 if nargin < 4,
0018     external = '';
0019 end
0020 %
0021 if ~isfield(select,'style'),
0022     select.style = struct;
0023 end
0024 %
0025 if isfield(external,'bNpar0') & isfield(external,'antenna')
0026     if isfield(external.antenna,'aloha')
0027         flag_aloha = 1;%ALOHA was running remotely outside imake_wave_jd.m
0028         launch = external;
0029         i_opt = 0;
0030         wavestruct = struct;
0031     end
0032 else
0033     wave = '';
0034     wavestruct = struct;
0035     type = '';
0036     flag_aloha = 0;
0037 end
0038 %
0039 if ~flag_aloha,
0040     if ~isempty(external) && ~isfield(external,'wavestructs'),% wave data from external database
0041         %
0042         titletext = 'For the wave structure :';      
0043         s = {'Use data loaded from the external database',...
0044              'Use data from an existing file',...
0045              'Build the wave data locally'};
0046         %
0047         i_opt = iselect_jd(s,titletext,opt_gui,select.style,1) - 1;
0048         %
0049     elseif ~isempty(external) && isfield(external,'wavestructs'),% wave data from wavestructs
0050         %
0051         titletext = 'For the wave structure :';      
0052         s = {'Use data from an existing file',...
0053              'Build the wave data locally',...
0054              'Use data from wavestructs'};
0055         %
0056         i_opt = iselect_jd(s,titletext,opt_gui,select.style,1);
0057         %
0058     else
0059         %
0060         titletext = 'For the wave structure :';      
0061         s = {'Use data from an existing file',...
0062              'Build the wave data locally'};
0063         %
0064         i_opt = iselect_jd(s,titletext,opt_gui,select.style,1);
0065         %
0066     end
0067 end
0068 %
0069 if i_opt == 0,% use data from external database
0070     %
0071     d_opt = 0;% rayinit built from launching conditions
0072     %
0073     if ~flag_aloha,
0074         %
0075         launchs = imake_launch_jd(dkepath,basestr,equil,external,workdir,opt_gui,select);
0076         %
0077         nlaun = length(launchs);
0078         %
0079         if nlaun == 0,
0080             return
0081         elseif nlaun == 1,
0082             launch = launchs{1};
0083         else
0084             titletext = 'Please select a launch structure from external data :';      
0085             s = cell(1,nlaun);
0086             for ilaun = 1:nlaun,
0087                 s{ilaun} = launchs{ilaun}.id;
0088             end
0089             %
0090             launch = launchs{iselect_jd(s,titletext,opt_gui,select.style,1)};
0091         end
0092         %
0093         if isfield(launch,'job'),
0094             wave.launchs = launchs;
0095             wave.id = wave.launchs{1}.id;
0096             return
0097         end
0098         %
0099         launch = imod_struct_jd(launch,'launch',1,opt_gui);
0100         %
0101     end
0102     %
0103     type = launch.type;
0104     %
0105     if ~isfield(launch,'job')
0106         if isfield(launch,'tail') && strcmp(type,'LH'),
0107             if launch.tail.bn_tail > 0 && (launch.tail.bP_tail > 0 || isnan(launch.tail.bP_tail)),
0108                 launch.id = [launch.id,'_TAIL_',make_tail_simulid_jd(launch.tail)];
0109             end
0110         else
0111             if input_dke_yp(['','Do you want to activate the tail LH model (y/n)'],'n',{'y','n'}) == 'y',
0112                 launch = imake_tail_yp(launch);
0113             end        
0114         end
0115     end
0116     %
0117 elseif i_opt == 1,% use data from an existing file
0118     %
0119     w_opt = input_dke_yp('Code used to generate data : 1 (TORAY), 2 (ART), 3 (AMR), 4 (EVE)',1,1:4,'',[1,1]);
0120     %
0121     launch = [];
0122     %
0123 elseif i_opt == 2,% build the wave data locally
0124     %
0125     d_opt = input_dke_yp(['Initial conditions :',...
0126         '\n0 (user-specified conditions)',...
0127         '\n1 (from an existing LAUNCH file)',...
0128         '\n2 (from an existing RAYINIT file)',...
0129         '\n3 (from an existing spectrum file)',...
0130         '\n4 (from TORAY data)',...
0131         '\n5 (from ART data)',...
0132         '\n6 (from AMR data)'],0,0:4,'',[1,1]);
0133     %
0134     %
0135     if d_opt == 0,% user-specified initial conditions
0136         %
0137         launchs = imake_launch_jd(dkepath,basestr,equil,'',workdir,opt_gui,select);
0138         %
0139         launch = imod_struct_jd(launchs{1},'launch',1,opt_gui);
0140         %
0141         type = launch.type;
0142         %
0143         if isfield(launch,'tail') && strcmp(type,'LH'),
0144             if launch.tail.bn_tail > 0 && (launch.tail.bP_tail > 0 || isnan(launch.tail.bP_tail)),
0145                 launch.id = [launch.id,'_TAIL_',make_tail_simulid_jd(launch.tail)];
0146             end
0147         else
0148             if input_dke_yp(['','Do you want to activate the tail LH model (y/n)'],'n',{'y','n'}) == 'y',
0149                 launch = imake_tail_yp(launch);
0150             end
0151         end
0152         %
0153     elseif d_opt == 1,%initial conditions from an existing LAUNCH file
0154         %
0155         launch = iload_struct_jd('launch','LAUNCH',workdir,opt_gui);
0156         %
0157         launch = imod_struct_jd(launch,'launch',1,opt_gui);
0158         %
0159         type = launch.type;
0160         %
0161         if isfield(launch,'tail') && strcmp(type,'LH'),
0162             if launch.tail.bn_tail > 0 && (launch.tail.bP_tail > 0 || isnan(launch.tail.bP_tail)),
0163                 launch.id = [launch.id,'_TAIL_',make_tail_simulid_jd(launch.tail)];
0164             end
0165         else
0166             if input_dke_yp(['','Do you want to activate the tail LH model (y/n)'],'n',{'y','n'}) == 'y',
0167                 launch = imake_tail_yp(launch);
0168                 launch = imod_struct_jd(launch,'launch',1,opt_gui);
0169             end
0170         end
0171         %
0172     elseif d_opt == 2,%initial conditions from an existing RAYINIT file
0173         %
0174         rayinit = iload_struct_jd('rayinit','RAYINIT',workdir,opt_gui);
0175         rayinit = imod_struct_jd(rayinit,'rayinit',1,opt_gui);
0176         %
0177         type = rayinit.type;
0178         %
0179     elseif d_opt == 3,%initial conditions from an existing ALOHA file
0180         %
0181         [alohafile,alohapath] = igetfile_jd(opt_gui,'*.*','Please select the ALOHA output file',workdir,0);
0182         %
0183         if ischar(alohafile),
0184             %
0185             aloha = load([alohapath,alohafile]);
0186             launchs = imake_launch_jd(dkepath,basestr,equil,aloha,workdir,opt_gui,select);
0187             %
0188             launch = imod_struct_jd(launchs{1},'launch',1,opt_gui);
0189             %
0190             if isfield(launch,'tail')
0191                 if launch.tail.bn_tail > 0 && (launch.tail.bP_tail > 0 || isnan(launch.tail.bP_tail)),
0192                     launch.id = [launch.id,'_TAIL_',make_tail_simulid_jd(launch.tail)];
0193                 end
0194             else
0195                 if input_dke_yp(['','Do you want to activate the tail LH model (y/n)'],'n',{'y','n'}) == 'y',
0196                     launch = imake_tail_yp(launch);
0197                     launch = imod_struct_jd(launch,'launch',1,opt_gui);
0198                 end
0199             end
0200         else
0201             disp('No file selected, aborted.')
0202             return
0203         end
0204         %
0205         type = launch.type;
0206         %
0207     elseif d_opt == 4,%initial conditions from TORAY
0208         %
0209         disp('-----> initial conditions from TORAY not implemented yet');
0210         return
0211         %
0212     elseif d_opt == 5,% wave from ART calculations
0213         %
0214         disp('-----> initial conditions from ART not implemented yet');
0215         return
0216         %
0217     elseif d_opt == 6,% wave from AMR calculations
0218         %
0219         disp('-----> initial conditions from AMR not implemented yet');
0220         return
0221         %
0222     end
0223     %
0224 elseif i_opt == 3,% use data from wavestructs
0225     %
0226     d_opt = 0;% rayinit built from launching conditions
0227     %
0228     wavestructs = external.wavestructs;
0229     %
0230     nwavestr = length(wavestructs);
0231     %
0232     if nwavestr == 0,
0233         return
0234     elseif nwavestr == 1,
0235         wavestruct = wavestructs{1};
0236     else
0237         titletext = 'Please select a wavestruct structure :';      
0238         s = cell(1,nwavestr);
0239         for iwavestr = 1:nwavestr,
0240             s{iwavestr} = wavestructs{iwavestr}.id;
0241         end
0242         %
0243         wavestruct = wavestructs{iselect_jd(s,titletext,opt_gui,select.style,1)};
0244     end
0245     %
0246     % WAVE TYPE
0247     %
0248     launch = wavestruct.launch;
0249     type = launch.type;
0250     %
0251 end
0252 %
0253 % Select the ray tracing code to be launched from LUKE
0254 %
0255 if any(i_opt == [0,2,3]),
0256     %
0257     titletext = 'Which ray-tracing code do you want to run :';      
0258     s = {'C3PO',...
0259          'TORAY',...
0260          'ART',...
0261          'AMR'};
0262     %
0263     w_opt = iselect_jd(s,titletext,opt_gui,select.style,1) - 1;
0264     %
0265     if w_opt == 1,% Run TORAY from LUKE interface
0266         %
0267         disp('-----> TORAY run from LUKE not implemented yet');
0268         return
0269         %
0270     elseif w_opt == 2,% Run ART from LUKE interface
0271         %
0272         disp('-----> ART run from LUKE not implemented yet');
0273         return
0274         %
0275     end
0276 end
0277 %
0278 % C3PO CALCULATIONS
0279 %
0280 if w_opt == 0; % C3PO Calculation
0281     %
0282     % WAVE TYPE AND DEFAULT WAVE PARAMETERS
0283     %
0284     if strcmp(type,'LH') || strcmp(type,'IC') || strcmp(type,'FW'),
0285         %
0286         ftype = 'LF';
0287         rtparam = load_structures_yp('rtparam','LH','');
0288         %
0289     elseif strcmp(type,'EC') || strcmp(type,'EB'),
0290         %
0291         ftype = 'HF';
0292         rtparam = load_structures_yp('rtparam','EC','');
0293         %
0294     else
0295         %
0296         disp('-----> wave type not yet implemented');
0297         return                
0298         %
0299     end
0300     %
0301     wavestruct = conc_struct_jd(rtparam,wavestruct);
0302     %
0303     wavestruct = imod_struct_jd(wavestruct,'wavestruct',1,opt_gui,struct,select.style);
0304     %
0305     % BUILDING RAYINIT
0306     %
0307     if d_opt <= 1,% rayinit built from launching conditions
0308         %
0309         if strcmp(ftype,'HF') && ~isfield(launch,'dNpar0'),
0310             %
0311             dNpar0 = 0.06;
0312             %
0313             % SPECTRAL WIDTH
0314             %
0315             titletext = 'Spectral width :';      
0316             if isfield(launch,'w0'),
0317                 s = {'Calculated from waist and focal point',...
0318                      'Fixed value',...
0319                      'Minimum width within numerical constraints'};
0320                 %
0321                 dNpar0_opt = iselect_jd(s,titletext,opt_gui,select.style,1) - 1;
0322                 %
0323             else
0324                 s = {'Specify fixed value',...
0325                      'Minimum width within numerical constraints'};
0326                 %
0327                 dNpar0_opt = iselect_jd(s,titletext,opt_gui,select.style,1);
0328                 %
0329             end
0330             %
0331             if dNpar0_opt == 0,
0332                 launch.dNpar0 = NaN;
0333             elseif dNpar0_opt == 2,
0334                 launch.dNpar0 = 0;
0335             else
0336                 launch.dNpar0 = input_dke_yp(['Specify fixed dNpar0 value'],dNpar0,[0;Inf],'',[1,1]);
0337             end
0338             %
0339         end
0340         %
0341         launch.type = type;
0342         %
0343         launch.ns = 1000;
0344         launch.method = 'cubic';
0345     end
0346     %
0347     % BUILDING RAYINIT
0348     %
0349     rayinit = main_rayinit_launch_jd(equil,launch);
0350     %
0351     rayinit.id = ['C3PO_',launch.id];
0352     rayinit.type = launch.type;
0353     %
0354     r_opt = iselect_jd({'No','Yes'},'Do you want to save the rayinit structure ?',opt_gui,select.style,1) - 1;
0355     %
0356     if r_opt == 1,
0357         sd = pwd;
0358         cd(workdir);
0359         [rayinit_file,rayinit_path] = iputfile_jd(opt_gui,['RAYINIT_',equil.id,'*.mat'],'Please provide the RAYINIT file name',['RAYINIT_',equil.id,'_',rayinit.id,'.mat']);
0360         %
0361         if rayinit_file == 0,
0362             disp('-----> No file name specified, rayinit structure not saved.')
0363         else
0364             save([rayinit_path,rayinit_file],'rayinit');
0365             disp('-----> The rayinit structure is saved')
0366         end
0367         cd(sd);
0368     end        
0369     %
0370     %
0371     % C3PO ray tracing
0372     %
0373     sd = pwd;
0374     cd(workdir);
0375     %
0376     if length(rayinit.yrho0) < 2,      
0377         disp(['-----> There are ',int2str(length(rayinit.yrho0)),' rays to calculate.']);
0378         wavestruct.C3POparam.clustermode.main_C3PO_jd.scheduler.remnum = iselect_jd(dkepath.remprofiles,'Remote calculation mode (mdce_remote): ',opt_gui,select.style,1) - 1;
0379         %
0380         if wavestruct.C3POparam.clustermode.main_C3PO_jd.scheduler.remnum == 0,%local distribution
0381             flag_mdce = 1:length(dkepath.distprofiles);% all mdce modes
0382         else
0383             flag_mdce = 1:3;% remcomputing within mdce_remote disabled
0384         end        
0385         %
0386         wavestruct.C3POparam.clustermode.main_C3PO_jd.scheduler.mode = iselect_jd(dkepath.distprofiles(flag_mdce),'Distributed computing mode : ',opt_gui,select.style,1) - 1;
0387         %
0388         if wavestruct.C3POparam.clustermode.main_C3PO_jd.scheduler.mode > 2,
0389             wavestruct.C3POparam.clustermode.main_C3PO_jd.scheduler.mode = 2 - wavestruct.C3POparam.clustermode.main_C3PO_jd.scheduler.mode;
0390         end
0391         %
0392         tstart = tic;
0393         wave = main_C3PO_jd(dkepath,rayinit.id,equil,[],rayinit,wavestruct.waveparam,wavestruct.fitparam,wavestruct.rayparam,wavestruct.C3POdisplay,wavestruct.C3POparam);
0394         telapsed = toc(tstart); 
0395         %
0396         disp(' ');
0397         disp(['The calculation of ',int2str(length(rayinit.yrho0)),' rays has been done in ',num2str(telapsed),' (s).']);
0398         disp(' ');
0399         %
0400     else
0401         %
0402         flag_mdce = 1:3;% remcomputing within mdce_remote disabled
0403         %
0404         wavestruct.C3POparam.clustermode.main_C3PO_jd.scheduler.remnum = 0;%always local for the ray-tracing
0405         %
0406         wavestruct.C3POparam.clustermode.main_C3PO_jd.scheduler.mode = iselect_jd(dkepath.distprofiles(flag_mdce),'Distributed computing mode : ',opt_gui,select.style,1) - 1;
0407         %
0408         selected_remprofile = iselect_jd(dkepath.remprofiles,'Remote calculation mode : ',opt_gui,select.style,1) - 1;
0409         %
0410         if selected_remprofile > 0,
0411             %
0412             remote = dkepath.remote(selected_remprofile);
0413             remote.timeout = 0;
0414             %
0415             job = matstandardjob_jd('runmat');
0416             job.remtimout = 0;
0417             %
0418             [err,job,wave] = matremote_jd('main_C3PO_jd',{dkepath,rayinit.id,equil,[],rayinit,wavestruct.waveparam,wavestruct.fitparam,wavestruct.rayparam,wavestruct.C3POdisplay,wavestruct.C3POparam},remote,job);
0419             %
0420             if isempty(err) 
0421                 if isempty(job.remote.host)
0422                      disp(['The ray-tracing C3PO has been launched on the local host'])
0423                 else
0424                     disp(['The ray-tracing C3PO has been launched on host : ',job.remote.host])
0425                 end
0426                 %
0427                 wave.job = job;
0428                 wave.id = rayinit.id;
0429                 %
0430                 cd(sd);
0431                 %
0432                 wave.info.type = 'RT';
0433                 wave.info.RT = 'C3PO';
0434                 wave.info.ftype = ftype;
0435                 %
0436                 s_opt = iselect_jd({'No','Yes'},'Do you want to generate an equivalent make_wave script ?',opt_gui,select.style,1) - 1;
0437                 %
0438                 if s_opt == 1,
0439                     %
0440                     imake_makewave_jd(workdir,wave,opt_gui);
0441                     %
0442                 end
0443                 %
0444                 wave.n_rf_list = wavestruct.waveparam.n_rf_list;
0445                 return
0446             else
0447                 return
0448             end
0449         else
0450             disp(['-----> There are ',int2str(length(rayinit.yrho0)),' rays to calculate.']);
0451             %
0452             if wavestruct.C3POparam.clustermode.main_C3PO_jd.scheduler.remnum == 0,%local distribution
0453                 flag_mdce = 1:length(dkepath.distprofiles);% all mdce modes
0454             else
0455                 flag_mdce = 1:3;% remcomputing within mdce_remote disabled
0456             end        
0457             %
0458             tstart = tic;
0459             wave = main_C3PO_jd(dkepath,rayinit.id,equil,[],rayinit,wavestruct.waveparam,wavestruct.fitparam,wavestruct.rayparam,wavestruct.C3POdisplay,wavestruct.C3POparam);
0460             telapsed = toc(tstart); 
0461             %
0462             disp(' ');
0463             disp(['The calculation of ',int2str(length(rayinit.yrho0)),' rays has been done in ',num2str(telapsed),' (s).']);
0464             disp(' ');
0465         end
0466     end
0467     %
0468     cd(sd);
0469     %
0470     wave.info.type = 'RT';
0471     wave.info.RT = 'C3PO';
0472     wave.info.ftype = ftype;
0473     %
0474     s_opt = iselect_jd({'No','Yes'},'Do you want to generate an equivalent make_wave script ?',opt_gui,select.style,1) - 1;
0475     %
0476     if s_opt == 'y',
0477         %
0478         imake_makewave_jd(workdir,wave,opt_gui);
0479         %
0480     end
0481     %
0482     n_rf_list = wavestruct.waveparam.n_rf_list;
0483     %
0484 elseif w_opt == 1,% TORAY calculations
0485     %
0486     wave = imake_wave_TORAY_jd(equil);
0487     %
0488     n_rf_list = NaN;
0489     %
0490 elseif w_opt == 2,% ART calculations
0491     %
0492     wave = imake_wave_ART_jd(workdir,equil,opt_gui);
0493     %
0494     n_rf_list = NaN;
0495     %
0496 elseif w_opt == 3, % AMR calculations
0497     %
0498     wave = imake_wave_AMR_jd(basestr,equil,launch,workdir,opt_gui);
0499     %
0500     n_rf_list = 1:3;
0501     %
0502 elseif w_opt == 4, % EVE calculations
0503     %
0504     wave = imake_wave_EVE_jd(basestr,equil,workdir,opt_gui);
0505     %
0506     n_rf_list = 0;
0507     %
0508 end
0509 %
0510 if isempty(wave),
0511     return
0512 end
0513 %
0514 % Wave processing and relativistic linear damping
0515 %
0516 wave = wave_process_jd(equil,wave,n_rf_list);
0517 %

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