rundke_metis

PURPOSE ^

SYNOPSIS ^

function rundke_metis(path_sources,locid_simul,basestr,shotnum,shotimes,opt,dkepath,wavestructs,equil,dkeparam,dkedisplay,ohm,transpfaste,ripple,metisevol,scheduler_run_lukert)

DESCRIPTION ^

 function running LUKE using METIS output and possibly user-defined
 parameters

 INPUTS :

   - path_sources                    : Source files path (leave empty for current path)
   - locid_simul                     : Simulation local id (leave empty for standard id)
   - c_opt                           : Option for distributed batch jobs (0) : sequential, (1, 2, ...) remote profile number 
   - basestr                         : tokamak name (ex: TS, ITER, ...)
   - shotnum                         : shot number (string)
   - shotimes              (optional): shot times to consider (cell array of strings *.****). Leave empty to include all relevant METIS data files in directory (default)
   - opt                   (optional): options for saving LUKE results remotely, backup, wave, etc...
   - dkepath               (optional): path structure for LUKE simulations (Leave empty for LOCAL path)
   - wavestructs           (optional): user-defined wavestruct parameters (cell array of structure array, of size 1 or shotimes)
   - equil                 (optional): user-defined equil parameters (structure array of size 1 or shotimes)
   - dkeparam              (optional): user-defined dkeparam parameters (structure array of size 1 or shotimes)
   - dkedisplay            (optional): user-defined dkedisplay parameters (structure array of size 1 or shotimes)
   - ohm                   (optional): user-defined ohm parameters (structure array of size 1 or shotimes)
   - transpfaste           (optional): user-defined transpfaste parameters (structure array of size 1 or shotimes)
   - ripple                (optional): user-defined ripple parameters (structure array of size 1 or shotimes)
   - metisevol             (optional): time evolution (1) or indepedent times (0)
   - scheduler_run_lukert  (optional): distributed calculation options for run_lukert

 NOTE: the optional structures wavestructs ... ripple do not need to contain all fields. They are concatenated with METIS parameters.

 by J. Decker (joan.decker@cea.fr), E. Nilsson (emelie.nilsson@cea.fr) and Y. Peysson (yves.peysson@cea.fr)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function rundke_metis(path_sources,locid_simul,basestr,shotnum,shotimes,opt,dkepath,wavestructs,equil,dkeparam,dkedisplay,ohm,transpfaste,ripple,metisevol,scheduler_run_lukert)
0002 %
0003 % function running LUKE using METIS output and possibly user-defined
0004 % parameters
0005 %
0006 % INPUTS :
0007 %
0008 %   - path_sources                    : Source files path (leave empty for current path)
0009 %   - locid_simul                     : Simulation local id (leave empty for standard id)
0010 %   - c_opt                           : Option for distributed batch jobs (0) : sequential, (1, 2, ...) remote profile number
0011 %   - basestr                         : tokamak name (ex: TS, ITER, ...)
0012 %   - shotnum                         : shot number (string)
0013 %   - shotimes              (optional): shot times to consider (cell array of strings *.****). Leave empty to include all relevant METIS data files in directory (default)
0014 %   - opt                   (optional): options for saving LUKE results remotely, backup, wave, etc...
0015 %   - dkepath               (optional): path structure for LUKE simulations (Leave empty for LOCAL path)
0016 %   - wavestructs           (optional): user-defined wavestruct parameters (cell array of structure array, of size 1 or shotimes)
0017 %   - equil                 (optional): user-defined equil parameters (structure array of size 1 or shotimes)
0018 %   - dkeparam              (optional): user-defined dkeparam parameters (structure array of size 1 or shotimes)
0019 %   - dkedisplay            (optional): user-defined dkedisplay parameters (structure array of size 1 or shotimes)
0020 %   - ohm                   (optional): user-defined ohm parameters (structure array of size 1 or shotimes)
0021 %   - transpfaste           (optional): user-defined transpfaste parameters (structure array of size 1 or shotimes)
0022 %   - ripple                (optional): user-defined ripple parameters (structure array of size 1 or shotimes)
0023 %   - metisevol             (optional): time evolution (1) or indepedent times (0)
0024 %   - scheduler_run_lukert  (optional): distributed calculation options for run_lukert
0025 %
0026 % NOTE: the optional structures wavestructs ... ripple do not need to contain all fields. They are concatenated with METIS parameters.
0027 %
0028 % by J. Decker (joan.decker@cea.fr), E. Nilsson (emelie.nilsson@cea.fr) and Y. Peysson (yves.peysson@cea.fr)
0029 %
0030 maxnargin = 16;
0031 %
0032 if nargin < maxnargin,
0033     scheduler_run_lukert = struct;
0034 end
0035 if nargin < maxnargin-1,
0036     metisevol = 0;
0037 end
0038 if nargin < maxnargin-2 || (~isstruct(ripple) && any(isnan(ripple))),
0039     ripple = struct;
0040 end
0041 if nargin < maxnargin-3 || (~isstruct(transpfaste) && any(isnan(transpfaste))),
0042     transpfaste = struct;
0043 end
0044 if nargin < maxnargin-4 || (~isstruct(ohm) && any(isnan(ohm))),
0045     ohm = struct;
0046     %ohm='';
0047 end
0048 if nargin < maxnargin-5 || (~isstruct(dkedisplay) && any(isnan(dkedisplay))),
0049     dkedisplay = struct;
0050 end
0051 if nargin < maxnargin-6 || (~isstruct(dkeparam) && any(isnan(dkeparam))),
0052     dkeparam = struct;
0053 end
0054 if nargin < maxnargin-7 || (~isstruct(equil) && any(isnan(equil))),
0055     equil = struct;
0056 end
0057 if nargin < maxnargin-8 || (~iscell(wavestructs) && ~isstruct(wavestructs) && any(isnan(wavestructs))),
0058     wavestructs = struct;
0059 end
0060 if nargin < maxnargin-9 || (~isstruct(dkepath) && any(isnan(dkepath))),
0061     dkepath = load_structures_yp('dkepath','','');
0062 end
0063 if nargin < maxnargin-10 || (~isstruct(opt) && any(isnan(opt))),
0064     opt = struct;
0065 end
0066 if nargin < maxnargin-11,
0067     shotimes = {};% all shot times
0068 end
0069 if nargin < maxnargin-12,
0070     error('shot number must be specified');
0071 end
0072 %
0073 dkepath.clustermode.run_lukert.scheduler = scheduler_run_lukert;
0074 %
0075 if metisevol == 0,
0076     dkepath.clustermode.run_lukert.scheduler.remtimout = 0;% do not return results, as it could be too heavy in terms of memory
0077 else    
0078     dkepath.clustermode.run_lukert.scheduler.remtimout = Inf;% return result needed for next step
0079     opt.save = 1;% save each time step for later processing
0080     opt.fields = NaN;% selected fields in returned lukestructs. Use NaN for all fields
0081     dkeparam.tn_mode = 1;% time given in seconds
0082 end
0083 %
0084 % select source files associated with the current shot
0085 %
0086 if isempty(path_sources),
0087     path_sources = './';
0088 end
0089 %
0090 [shotimes,isel] = select_shotimes_jd(['before_luke@',basestr,'_',shotnum,'_'],'.mat',path_sources,shotimes);
0091 %
0092 % select shot times
0093 %
0094 if ~isnan(isel),% indices in structure arrays
0095     %
0096     % case of structure arrays
0097     %
0098     if length(dkeparam) > 1,
0099         dkeparam = dkeparam(isel);
0100     end
0101     if length(dkedisplay) > 1,
0102         dkedisplay = dkedisplay(isel);
0103     end
0104     if length(equil) > 1,
0105         equil = equil(isel);
0106     end
0107     for iw = 1:length(wavestructs),
0108         if iscell(wavestructs) && length(wavestructs{iw}) > 1,
0109             wavestructs{iw} = wavestructs{iw}(isel);
0110         elseif ~iscell(wavestructs) && length(wavestructs) > 1,
0111             wavestructs = wavestructs(isel);
0112         end
0113     end
0114     if length(ohm) > 1,
0115         ohm = ohm(isel);
0116     end
0117     if length(transpfaste) > 1,
0118         transpfaste = transpfaste(isel);
0119     end
0120     if length(ripple) > 1,
0121         ripple = ripple(isel);
0122     end
0123 end
0124 %
0125 nshots = length(shotimes);
0126 %
0127 % LUKE calculation for selected shotimes
0128 %
0129 lukestructs = cell(1,nshots);
0130 %
0131 for ishot = 1:nshots
0132     %
0133     metis_data = load([path_sources,filesep,'before_luke@',basestr,'_',shotnum,'_',shotimes{ishot},'.mat']);
0134     %
0135     lukestruct = struct;
0136     %
0137     % replace structure content with user prescription
0138     %
0139     if length(dkeparam) > 1,
0140         lukestruct.dkeparam = conc_struct_jd(metis_data.dkeparam,dkeparam(ishot));
0141     else
0142         lukestruct.dkeparam = conc_struct_jd(metis_data.dkeparam,dkeparam);
0143     end 
0144     %
0145     if length(dkedisplay) > 1,
0146         lukestruct.dkedisplay = conc_struct_jd(metis_data.dkedisplay,dkedisplay(ishot));
0147     else
0148         lukestruct.dkedisplay = conc_struct_jd(metis_data.dkedisplay,dkedisplay);
0149     end        
0150     %
0151     if length(equil) > 1,
0152         lukestruct.equil = conc_struct_jd(metis_data.equil,equil(ishot));
0153     else
0154         lukestruct.equil = conc_struct_jd(metis_data.equil,equil);
0155     end        
0156     %
0157     if length(metis_data.wavestructs) == 1 && iscell(wavestructs) && length(wavestructs) > 1,
0158         metis_data.wavestructs = repmat(metis_data.wavestructs,[1,length(wavestructs)]);
0159     end
0160     if isempty(metis_data.wavestructs) && iscell(wavestructs) && length(wavestructs) >= 1,
0161         metis_data.wavestructs = repmat({struct},[1,length(wavestructs)]);
0162     end
0163     %
0164     lukestruct.wavestructs = {};
0165     for iw = 1:length(metis_data.wavestructs),
0166         if iscell(wavestructs),% wavestruct specified for each wave
0167             if length(wavestructs{iw}) > 1,
0168                 lukestruct.wavestructs{iw} = conc_struct_jd(metis_data.wavestructs{iw},wavestructs{iw}(ishot));
0169             else
0170                 lukestruct.wavestructs{iw} = conc_struct_jd(metis_data.wavestructs{iw},wavestructs{iw});
0171             end
0172         else% wavestruct specified for all wave
0173             if length(wavestructs) > 1,
0174                 lukestruct.wavestructs{iw} = conc_struct_jd(metis_data.wavestructs{iw},wavestructs(ishot));
0175             else
0176                 lukestruct.wavestructs{iw} = conc_struct_jd(metis_data.wavestructs{iw},wavestructs);
0177             end
0178         end
0179     end
0180     %
0181     if length(ohm) > 1,
0182         lukestruct.ohm = conc_struct_jd(metis_data.ohm,ohm(ishot));
0183     else
0184         lukestruct.ohm = conc_struct_jd(metis_data.ohm,ohm);
0185     end        
0186     if length(transpfaste) > 1,
0187         lukestruct.transpfaste = conc_struct_jd(metis_data.transpfaste,transpfaste(ishot));
0188     else
0189         lukestruct.transpfaste = conc_struct_jd(metis_data.transpfaste,transpfaste);
0190     end        
0191     if length(ripple) > 1,
0192         lukestruct.ripple = conc_struct_jd(metis_data.ripple,ripple(ishot));
0193     else
0194         lukestruct.ripple = conc_struct_jd(metis_data.ripple,ripple);
0195     end 
0196     %
0197     lukestruct.opt = opt;
0198     %
0199     % Simulation ID
0200     %
0201     lukestruct.simul.id = ['METIS_',make_luke_simulid_jd(lukestruct.equil,lukestruct.ohm,lukestruct.transpfaste,lukestruct.ripple,...
0202         '',lukestruct.wavestructs,locid_simul)];
0203     %
0204     if (~isfield(dkepath,'remnum') || dkepath.remnum == 0 || isempty(dkepath.remote(dkepath.remnum).host)) && ...
0205        (~isfield(scheduler_run_lukert,'mode') || scheduler_run_lukert.mode >= 0),
0206         lukestruct.simul.path = path_sources;
0207     end
0208     %
0209     lukestructs{ishot} = lukestruct;
0210     %
0211     if isfield(opt,'saveinputs') && opt.saveinputs == 1,
0212         %
0213         saveinputs_jd(lukestruct);
0214         %
0215     end
0216     %
0217 end
0218 %
0219 % Run LUKE
0220 %
0221 if metisevol == 0,
0222     %
0223     lukestructs = run_lukert(lukestructs,dkepath);
0224     %
0225 else
0226     %
0227     if metisevol == 1,% start from t = -inf
0228         lukestructs{1}.dkeparam.tn = NaN;% asymptotic first time calculation
0229     else % start from t = 0
0230         lukestructs{1}.dkeparam.tn = str2double(shotimes{1});% asymptotic first time calculation
0231     end
0232     %
0233     lukestruct = run_lukert(lukestructs{1},dkepath);
0234     %
0235     if ~isfield(lukestruct.dkeparam,'Te_ref') || ~isfield(lukestruct.dkeparam,'ne_ref'),% reference from first time
0236         lukestruct.dkeparam.Te_ref = lukestruct.output.mksa.Te_ref;
0237         lukestruct.dkeparam.ne_ref = lukestruct.output.mksa.ne_ref;
0238     end
0239     %
0240     for ishot = 2:nshots,
0241         lukestructs{ishot}.XXf0 = lukestruct.output.dke_out.Zf0_interp(end);% start from previous distribution
0242         lukestructs{ishot}.dkeparam.rho_S = lukestruct.output.radialDKE.xrho_S_dke;% use same radial grid
0243         lukestructs{ishot}.dkeparam.tn = str2double(shotimes{ishot}) - str2double(shotimes{ishot-1});% time in seconds
0244         %
0245         lukestruct = run_lukert(lukestructs{ishot},dkepath);
0246     end
0247 end
0248 %
0249 % Save results if needed
0250 %
0251 if ~isfield(opt,'save') || opt.save == 0,
0252     %
0253     savestr = [basestr,'_',shotnum];
0254     %
0255     if ~isempty(locid_simul),
0256         savestr = [savestr,'_',locid_simul];
0257     end
0258     %
0259     save_batch_jd(lukestructs,dkepath,savestr)
0260     %
0261 end
0262 %

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