# Tutorial for time-varying geometry simulation

Simulation with time-varying geometry is demonstrated in case of plasma elongation increase from 1.1 to 1.7. An increase in the edge safety factor q95 is expected. Two CHEASE data files are used to get equilibrium data for low and high plasma elongation.

## Contents

- Model construction and initialization
- Run RAPTOR simulation
- Plot results

## Model construction and initialization

    close all hidden;
    run(fullfile(pwd,'..','RAPTOR_path.m'));
    % Load default parameters
    config = RAPTOR_config;
    % Specify input data file(s)
    % One can specify several input data file(s) corresponding to plasma
    % equilibrium at different time steps. In case of several data
    % files config.equi.filenames contains a cell array.
    config.equi.filenames = [{'/equils/chease/tutorial_freegeom_t0.1_cheasedata.mat'},...
               {'/equils/chease/tutorial_freegeom_t0.4_cheasedata.mat'}];
    % Specify time grid for input data
    config.equi.times = [0.1 0.4];
    % Define geometry type
    config.equi.mode = 'free';
    % Define time grid: time interval from 0.0 to 450.0 ms
    config.grid.tgrid = [0:0.005:0.45];

    % Build model and get params, init structures, geometry g, kinetic profiles
    % v, actuator inputs U
    [model,params,init,g,v,U] = build_RAPTOR_model(config);

    % Define initial conditions for plasma state
    x0 = RAPTOR_initial_conditions(model,init,g(:,1),v(:,1));

## Run RAPTOR simulation

    simres = RAPTOR_predictive(x0,g,v,U,model,params);
    out = RAPTOR_out(simres,model,params);

         it  telaps newt     res   t[ms]  dt[ms]  Ip[kA] Icd[kA] Ibs[kA] Ioh[kA]      qe    qmin      q0   Vl[V] Te0[keV] Ti0[keV] ne0[e19]   f_ss
          1    0.28    5 1.8e-13       0       5      80       0    1.13    78.9    8.46    3.05    3.05 3.3e+00    0.31    0.31    1.00 7.3e+00
         11    0.49    2 3.1e-12      50       5      80       0    3.34    76.7    8.46    1.26    1.26 2.2e+00    0.51    0.51    1.00 5.1e-01
         21    0.68    2 9.6e-15     100       5      80       0    3.38    76.6    8.46    1.19    1.19 2.1e+00    0.53    0.53    1.00 4.9e-02
         31    0.88    2 2.6e-14     150       5      80       0    3.35    76.7     9.2    1.25    1.25 2.1e+00    0.51    0.51    1.00 5.3e-02
         41       1    1 6.5e-09     200       5      80       0    3.22    76.8    10.1    1.35    1.35 2.1e+00    0.48    0.48    1.00 7.7e-02
         51     1.2    2 4.8e-14     250       5      80       0    3.07    76.9    11.1    1.49    1.49 2.1e+00    0.44    0.44    1.00 1.9e-01
         61     1.4    2 5.1e-14     300       5      80       0    2.89    77.1    12.4    1.67    1.67 2.1e+00    0.41    0.41    1.00 3.0e-01
         71     1.6    2 1.2e-13     350       5      80       0    2.68    77.3    14.1     1.9     1.9 2.2e+00    0.37    0.37    1.00 4.1e-01
         81     1.8    2 2.3e-13     400       5      80       0    2.43    77.6    16.2    2.22    2.22 2.3e+00    0.33    0.33    1.00 5.3e-01
         91       2    2 7.0e-14     450       5      80       0    2.31    77.7    16.2    2.42    2.42 2.4e+00    0.31    0.31    1.00 6.0e-02

## Plot results

    subplot(211)
    plot(out.time,[out.q95;out.q(end,:);out.Ip(end,:)/1e4]);
    xlabel('time, sec'); legend({'q_{95}','q_{edge}','Ip [10kA]'},'location','northwest');
    subplot(212)
    plot(out.time,[out.te(1,:);out.Wth]);
    xlabel('time, sec'); legend({'Te0','W_{e}'},'location','northwest');