RAPTOR tutorial - Variable timegrid

It is possible to use a time-varying grid, typically to have shorter time steps in the early (transient) part of the shot and fewer time points later.

This is illustrated with a simple ITER-like simulation below

Contents

Set up the simulation

close all hidden;
clear; run('../RAPTOR_path.m');

addpath(fullfile(pwd,'..','code'),'-end'); % add RAPTOR path
[config] = RAPTOR_config('ITER'); % load default ITER params

% set NBI parameters
config.nbhcd.params.active = true;
config.nbhcd.params.rdep = [0.25]; %
config.nbhcd.params.wdep = [0.25]; % broad heating
config.nbhcd.params.wdep_out = [0.75]; % broad heating
config.nbhcd.params.cd_eff = [0]; % current drive
config.nbhcd.params.uindices = [2]; % index in input vector

config.echcd = echcd('none');

% switch off alpha power and losses
config.palpha.active = false;
config.pbrem.active = false;
config.prad.active = false;
config.pei.active = false;

% create model, params, init, geometry g, kinetic profiles v.
[model,params,init,g,v,~] = build_RAPTOR_model(config);

Simulation with variable time step

define a monotonic, but not evenly spaced time grid:

tgrid0 = [0:0.1:2.9,3:1:80];
params.tgrid = tgrid0;

% inputs
rampfun = @(t,tmin,ymin,tmax,ymax) ...
    max(ymin,min((ymax-ymin)/(tmax-tmin)*(t-tmin),ymax-ymin)+ymin); % anonymous function for ramps
% Construct actuator inputs on the time grid tgrid0.
U0(1,:) = rampfun(tgrid0,0,4e6,80,12e6); % Ip
U0(2,:) = rampfun(tgrid0,30,0,40,40e6); % NBI power
init.te0  = 0.5e3;
init.jpow = 0;
% Construct kinetic profiles according to the new settings.
v = build_kinetic_profiles(model,init);

% initial condition
init.Ip0 = U0(1,1);
x0 = RAPTOR_initial_conditions(model,init,g(:,1),v(:,1));
simres0 = RAPTOR_predictive(x0,g,v,U0,model,params);
out0 = RAPTOR_out(simres0,model,params);
     it  telaps newt     res   t[ s]  dt[ s]  Ip[MA] Icd[MA] Ibs[MA] Ioh[MA]      qe    qmin      q0   Vl[V] Te0[keV] Ti0[keV] ne0[e19]   f_ss  
      1    0.12    6 1.5e-12       0     0.1       4       0 0.00219       4      15     7.2     7.2 1.0e+00    0.56    0.56    2.00 3.2e+00 
     11    0.59    3 1.5e-12       1     0.1     4.1       0  0.0615    4.04    14.6    6.61    6.61 1.0e+00    0.95    0.95    2.00 3.8e+00 
     21    0.94    2 1.7e-12       2     0.1     4.2       0  0.0695    4.13    14.3    6.09    6.09 9.8e-01    1.05    1.05    2.00 3.8e+00 
     31     1.3    3 1.3e-12       3       1     4.3       0   0.073    4.23    13.9    5.33    5.33 8.9e-01    1.15    1.15    2.00 3.4e+00 
     41     1.6    2 1.2e-11      13       1     5.3       0  0.0987     5.2    11.3    3.02    3.02 9.5e-01    1.71    1.71    2.00 3.6e+00 
     51     1.9    2 2.4e-11      23       1     6.3       0   0.118    6.18    9.51    2.01    2.01 9.5e-01    2.35    2.35    2.00 3.7e+00 
     61     2.3    5 6.9e-12      33       1     7.3       0   0.227    7.07    8.21    1.56    1.56 6.9e-01    5.46    5.46    2.00 3.6e+00 
     71     2.8    2 2.6e-09      43       1     8.3       0   0.517    7.78    7.22    1.47    1.47 4.3e-01   11.09   11.09    2.00 2.5e+00 
     81     3.1    2 1.1e-11      53       1     9.3       0   0.518    8.78    6.44    1.43    1.43 4.4e-01   12.03   12.03    2.00 2.5e+00 
     91     3.4    2 4.1e-11      63       1    10.3       0   0.518    9.78    5.82    1.39    1.39 4.4e-01   12.97   12.97    2.00 2.6e+00 
    101     3.8    2 1.9e-11      73       1    11.3       0   0.517    10.8     5.3    1.36    1.36 4.4e-01   13.92   13.92    2.00 2.6e+00 

Simulation with constant time step

Repeat the same simulation but with a fixed time step.

tgrid1 = [0:0.1:80];
params.tgrid = tgrid1;

% inputs
rampfun = @(t,tmin,ymin,tmax,ymax) max(ymin,min((ymax-ymin)/(tmax-tmin)*(t-tmin),ymax-ymin)+ymin); % anonymous function for ramps
% Construct actuator inputs on the time grid tgrid1.
U1(1,:) = rampfun(tgrid1,0,4e6,80,12e6); % Ip
U1(2,:) = rampfun(tgrid1,30,0,40,40e6); % NBI power

% initial condition
init.Ip0 = U1(1,1);
x0 = RAPTOR_initial_conditions(model,init,g(:,1),v(:,1));
simres1 = RAPTOR_predictive(x0,g,v,U1,model,params);
out1 = RAPTOR_out(simres1,model,params);
     it  telaps newt     res   t[ s]  dt[ s]  Ip[MA] Icd[MA] Ibs[MA] Ioh[MA]      qe    qmin      q0   Vl[V] Te0[keV] Ti0[keV] ne0[e19]   f_ss  
      1     0.1    6 1.5e-12       0     0.1       4       0 0.00219       4      15     7.2     7.2 1.0e+00    0.56    0.56    2.00 3.2e+00 
     11     0.6    3 1.5e-12       1     0.1     4.1       0  0.0615    4.04    14.6    6.61    6.61 1.0e+00    0.95    0.95    2.00 3.8e+00 
     21    0.96    2 1.9e-12       2     0.1     4.2       0  0.0695    4.13    14.3    6.09    6.09 9.8e-01    1.05    1.05    2.00 3.8e+00 
     31     1.3    2 1.8e-12       3     0.1     4.3       0   0.073    4.23    13.9    5.67    5.67 9.7e-01    1.11    1.11    2.00 3.8e+00 
     41     1.6    2 1.5e-12       4     0.1     4.4       0  0.0761    4.32    13.6     5.3     5.3 9.7e-01    1.16    1.16    2.00 3.8e+00 
     51       2    2 1.7e-12       5     0.1     4.5       0   0.079    4.42    13.3    4.97    4.97 9.6e-01    1.21    1.21    2.00 3.7e+00 
     61     2.4    2 2.1e-12       6     0.1     4.6       0  0.0819    4.52      13    4.67    4.67 9.6e-01    1.27    1.27    2.00 3.7e+00 
     71     2.8    2 4.4e-12       7     0.1     4.7       0  0.0847    4.62    12.7    4.39    4.39 9.6e-01    1.32    1.32    2.00 3.7e+00 
     81     3.1    2 5.5e-12       8     0.1     4.8       0  0.0875    4.71    12.5    4.14    4.14 9.6e-01    1.38    1.38    2.00 3.7e+00 
     91     3.5    2 4.5e-12       9     0.1     4.9       0  0.0901    4.81    12.2     3.9     3.9 9.6e-01    1.44    1.44    2.00 3.7e+00 
    101     3.8    2 8.3e-12      10     0.1       5       0  0.0927    4.91      12    3.69    3.69 9.6e-01    1.50    1.50    2.00 3.7e+00 
    111     4.2    2 5.1e-12      11     0.1     5.1       0  0.0952       5    11.7     3.5     3.5 9.6e-01    1.56    1.56    2.00 3.7e+00 
    121     4.5    2 3.6e-12      12     0.1     5.2       0  0.0976     5.1    11.5    3.32    3.32 9.6e-01    1.62    1.62    2.00 3.7e+00 
    131     4.9    2 2.8e-12      13     0.1     5.3       0  0.0999     5.2    11.3    3.16    3.16 9.6e-01    1.68    1.68    2.00 3.7e+00 
    141     5.2    2 8.7e-12      14     0.1     5.4       0   0.102     5.3    11.1       3       3 9.6e-01    1.74    1.74    2.00 3.7e+00 
    151     5.6    2 5.7e-12      15     0.1     5.5       0   0.104     5.4    10.9    2.87    2.87 9.6e-01    1.80    1.80    2.00 3.7e+00 
    161     5.9    2 1.4e-11      16     0.1     5.6       0   0.106    5.49    10.7    2.74    2.74 9.6e-01    1.87    1.87    2.00 3.7e+00 
    171     6.3    2 9.4e-12      17     0.1     5.7       0   0.108    5.59    10.5    2.62    2.62 9.6e-01    1.93    1.93    2.00 3.7e+00 
    181     6.6    2 1.3e-11      18     0.1     5.8       0    0.11    5.69    10.3    2.51    2.51 9.6e-01    1.99    1.99    2.00 3.7e+00 
    191       7    2 1.2e-11      19     0.1     5.9       0   0.112    5.79    10.2    2.41    2.41 9.6e-01    2.06    2.06    2.00 3.7e+00 
     it  telaps newt     res   t[ s]  dt[ s]  Ip[MA] Icd[MA] Ibs[MA] Ioh[MA]      qe    qmin      q0   Vl[V] Te0[keV] Ti0[keV] ne0[e19]   f_ss  
    201     7.3    2 1.0e-11      20     0.1       6       0   0.114    5.89    9.99    2.31    2.31 9.5e-01    2.13    2.13    2.00 3.8e+00 
    211     7.7    2 1.1e-11      21     0.1     6.1       0   0.116    5.98    9.82    2.23    2.23 9.5e-01    2.19    2.19    2.00 3.8e+00 
    221       8    2 1.8e-11      22     0.1     6.2       0   0.118    6.08    9.66    2.14    2.14 9.5e-01    2.26    2.26    2.00 3.8e+00 
    231     8.4    2 1.2e-11      23     0.1     6.3       0   0.119    6.18    9.51    2.07    2.07 9.5e-01    2.33    2.33    2.00 3.8e+00 
    241     8.7    2 1.1e-11      24     0.1     6.4       0   0.121    6.28    9.36    1.99    1.99 9.5e-01    2.39    2.39    2.00 3.8e+00 
    251     9.1    2 1.2e-11      25     0.1     6.5       0   0.122    6.38    9.22    1.93    1.93 9.5e-01    2.46    2.46    2.00 3.8e+00 
    261     9.4    2 1.7e-11      26     0.1     6.6       0   0.124    6.48    9.08    1.86    1.86 9.5e-01    2.53    2.53    2.00 3.8e+00 
    271     9.8    2 9.8e-12      27     0.1     6.7       0   0.125    6.57    8.94    1.81    1.81 9.4e-01    2.60    2.60    2.00 3.8e+00 
    281      10    2 2.6e-11      28     0.1     6.8       0   0.127    6.67    8.81    1.75    1.75 9.4e-01    2.67    2.67    2.00 3.8e+00 
    291      10    2 1.2e-11      29     0.1     6.9       0   0.128    6.77    8.68     1.7     1.7 9.4e-01    2.74    2.74    2.00 3.8e+00 
    301      11    2 1.1e-11      30     0.1       7       0   0.129    6.87    8.56    1.65    1.65 9.4e-01    2.80    2.80    2.00 3.8e+00 
    311      11    2 8.7e-09      31     0.1     7.1       0   0.164    6.94    8.44    1.61    1.61 8.8e-01    3.39    3.39    2.00 4.0e+00 
    321      12    2 4.0e-10      32     0.1     7.2       0    0.22    6.98    8.32    1.59    1.59 7.8e-01    4.41    4.41    2.00 3.9e+00 
    331      12    2 9.7e-11      33     0.1     7.3       0   0.272    7.03    8.21    1.58    1.58 6.9e-01    5.45    5.45    2.00 3.7e+00 
    341      12    2 2.0e-11      34     0.1     7.4       0   0.317    7.08     8.1    1.57    1.57 6.3e-01    6.38    6.38    2.00 3.4e+00 
    351      13    2 3.1e-11      35     0.1     7.5       0   0.356    7.14    7.99    1.55    1.55 5.8e-01    7.22    7.22    2.00 3.2e+00 
    361      13    2 1.8e-11      36     0.1     7.6       0   0.391    7.21    7.88    1.54    1.54 5.4e-01    7.99    7.99    2.00 3.0e+00 
    371      13    2 2.6e-11      37     0.1     7.7       0   0.424    7.28    7.78    1.53    1.53 5.1e-01    8.71    8.71    2.00 2.9e+00 
    381      14    2 1.8e-11      38     0.1     7.8       0   0.454    7.35    7.68    1.52    1.52 4.8e-01    9.39    9.39    2.00 2.8e+00 
    391      14    2 2.7e-11      39     0.1     7.9       0   0.482    7.42    7.58    1.51    1.51 4.6e-01   10.04   10.04    2.00 2.7e+00 
     it  telaps newt     res   t[ s]  dt[ s]  Ip[MA] Icd[MA] Ibs[MA] Ioh[MA]      qe    qmin      q0   Vl[V] Te0[keV] Ti0[keV] ne0[e19]   f_ss  
    401      14    2 2.1e-11      40     0.1       8       0   0.509    7.49    7.49     1.5     1.5 4.4e-01   10.66   10.66    2.00 2.6e+00 
    411      15    2 2.1e-11      41     0.1     8.1       0   0.516    7.58     7.4     1.5     1.5 4.3e-01   10.89   10.89    2.00 2.5e+00 
    421      15    2 2.8e-11      42     0.1     8.2       0   0.517    7.68    7.31    1.49    1.49 4.3e-01   10.99   10.99    2.00 2.5e+00 
    431      15    2 1.9e-11      43     0.1     8.3       0   0.517    7.78    7.22    1.48    1.48 4.3e-01   11.08   11.08    2.00 2.5e+00 
    441      16    2 1.9e-11      44     0.1     8.4       0   0.517    7.88    7.13    1.48    1.48 4.3e-01   11.18   11.18    2.00 2.5e+00 
    451      16    2 4.2e-11      45     0.1     8.5       0   0.517    7.98    7.05    1.47    1.47 4.3e-01   11.27   11.27    2.00 2.5e+00 
    461      16    2 1.9e-11      46     0.1     8.6       0   0.517    8.08    6.97    1.47    1.47 4.3e-01   11.36   11.36    2.00 2.5e+00 
    471      17    2 4.2e-11      47     0.1     8.7       0   0.517    8.18    6.89    1.46    1.46 4.3e-01   11.46   11.46    2.00 2.5e+00 
    481      17    2 2.8e-11      48     0.1     8.8       0   0.517    8.28    6.81    1.46    1.46 4.3e-01   11.55   11.55    2.00 2.5e+00 
    491      17    2 4.1e-11      49     0.1     8.9       0   0.518    8.38    6.73    1.46    1.46 4.3e-01   11.64   11.64    2.00 2.5e+00 
    501      18    2 2.1e-11      50     0.1       9       0   0.518    8.48    6.66    1.45    1.45 4.3e-01   11.74   11.74    2.00 2.5e+00 
    511      18    2 2.9e-11      51     0.1     9.1       0   0.518    8.58    6.58    1.45    1.45 4.3e-01   11.83   11.83    2.00 2.5e+00 
    521      18    1 9.8e-09      52     0.1     9.2       0   0.518    8.68    6.51    1.44    1.44 4.4e-01   11.93   11.93    2.00 2.5e+00 
    531      19    1 8.4e-09      53     0.1     9.3       0   0.518    8.78    6.44    1.44    1.44 4.4e-01   12.02   12.02    2.00 2.5e+00 
    541      19    1 7.1e-09      54     0.1     9.4       0   0.518    8.88    6.37    1.43    1.43 4.4e-01   12.11   12.11    2.00 2.5e+00 
    551      19    1 6.0e-09      55     0.1     9.5       0   0.518    8.98    6.31    1.43    1.43 4.4e-01   12.21   12.21    2.00 2.6e+00 
    561      19    1 4.9e-09      56     0.1     9.6       0   0.518    9.08    6.24    1.43    1.43 4.4e-01   12.30   12.30    2.00 2.6e+00 
    571      19    1 4.0e-09      57     0.1     9.7       0   0.518    9.18    6.18    1.42    1.42 4.4e-01   12.40   12.40    2.00 2.6e+00 
    581      20    1 3.3e-09      58     0.1     9.8       0   0.518    9.28    6.11    1.42    1.42 4.4e-01   12.49   12.49    2.00 2.6e+00 
    591      20    1 2.8e-09      59     0.1     9.9       0   0.518    9.38    6.05    1.41    1.41 4.4e-01   12.59   12.59    2.00 2.6e+00 
     it  telaps newt     res   t[ s]  dt[ s]  Ip[MA] Icd[MA] Ibs[MA] Ioh[MA]      qe    qmin      q0   Vl[V] Te0[keV] Ti0[keV] ne0[e19]   f_ss  
    601      20    1 2.6e-09      60     0.1      10       0   0.518    9.48    5.99    1.41    1.41 4.4e-01   12.68   12.68    2.00 2.6e+00 
    611      20    1 2.6e-09      61     0.1    10.1       0   0.518    9.58    5.93    1.41    1.41 4.4e-01   12.78   12.78    2.00 2.6e+00 
    621      20    1 2.9e-09      62     0.1    10.2       0   0.518    9.68    5.87     1.4     1.4 4.4e-01   12.87   12.87    2.00 2.6e+00 
    631      21    1 3.4e-09      63     0.1    10.3       0   0.518    9.78    5.82     1.4     1.4 4.4e-01   12.97   12.97    2.00 2.6e+00 
    641      21    1 3.9e-09      64     0.1    10.4       0   0.518    9.88    5.76    1.39    1.39 4.4e-01   13.06   13.06    2.00 2.6e+00 
    651      21    1 4.3e-09      65     0.1    10.5       0   0.518    9.98    5.71    1.39    1.39 4.4e-01   13.15   13.15    2.00 2.6e+00 
    661      21    1 4.8e-09      66     0.1    10.6       0   0.518    10.1    5.65    1.39    1.39 4.4e-01   13.25   13.25    2.00 2.6e+00 
    671      21    1 5.3e-09      67     0.1    10.7       0   0.518    10.2     5.6    1.38    1.38 4.4e-01   13.34   13.34    2.00 2.6e+00 
    681      22    1 5.8e-09      68     0.1    10.8       0   0.518    10.3    5.55    1.38    1.38 4.4e-01   13.44   13.44    2.00 2.6e+00 
    691      22    1 6.2e-09      69     0.1    10.9       0   0.518    10.4     5.5    1.38    1.38 4.4e-01   13.53   13.53    2.00 2.6e+00 
    701      22    1 6.6e-09      70     0.1      11       0   0.518    10.5    5.45    1.37    1.37 4.4e-01   13.63   13.63    2.00 2.6e+00 
    711      22    1 7.0e-09      71     0.1    11.1       0   0.518    10.6     5.4    1.37    1.37 4.4e-01   13.72   13.72    2.00 2.6e+00 
    721      22    1 7.3e-09      72     0.1    11.2       0   0.517    10.7    5.35    1.36    1.36 4.4e-01   13.82   13.82    2.00 2.6e+00 
    731      23    1 7.7e-09      73     0.1    11.3       0   0.517    10.8     5.3    1.36    1.36 4.4e-01   13.91   13.91    2.00 2.6e+00 
    741      23    1 8.0e-09      74     0.1    11.4       0   0.517    10.9    5.26    1.36    1.36 4.4e-01   14.00   14.00    2.00 2.6e+00 
    751      23    1 8.3e-09      75     0.1    11.5       0   0.517      11    5.21    1.35    1.35 4.4e-01   14.10   14.10    2.00 2.6e+00 
    761      23    1 8.5e-09      76     0.1    11.6       0   0.517    11.1    5.16    1.35    1.35 4.4e-01   14.19   14.19    2.00 2.6e+00 
    771      23    1 8.8e-09      77     0.1    11.7       0   0.517    11.2    5.12    1.35    1.35 4.4e-01   14.29   14.29    2.00 2.6e+00 
    781      24    1 9.0e-09      78     0.1    11.8       0   0.517    11.3    5.08    1.34    1.34 4.4e-01   14.38   14.38    2.00 2.6e+00 
    791      24    1 9.2e-09      79     0.1    11.9       0   0.517    11.4    5.03    1.34    1.34 4.4e-01   14.47   14.47    2.00 2.6e+00 
     it  telaps newt     res   t[ s]  dt[ s]  Ip[MA] Icd[MA] Ibs[MA] Ioh[MA]      qe    qmin      q0   Vl[V] Te0[keV] Ti0[keV] ne0[e19]   f_ss  
    801      24    1 9.4e-09      80     0.1      12       0   0.517    11.5    4.99    1.34    1.34 4.4e-01   14.57   14.57    2.00 2.6e+00 

Compare

Comparing the two simulations confirms their equivalence

subplot(311)
hh=plot(tgrid1,out1.iota(1:5:end,:),'b.-',tgrid0,out0.iota(1:5:end,:),'ro');
ylabel('iota []'); xlabel('t[s]');
legend(hh([1,end]),'fixed dt','variable dt');

subplot(312)
plot(tgrid1,out1.te(1:5:end,:)/1e3,'b.-',tgrid0,out0.te(1:5:end,:)/1e3,'ro');
ylabel('T_e [keV]'); xlabel('t[s]');

subplot(313)
plot(tgrid1,out1.psi(1:5:end,:),'b.-',tgrid0,out0.psi(1:5:end,:),'ro');
ylabel('\psi [Wb]'); xlabel('t[s]');