From c3e007f0cb5be7dff16d59efd625639d9ab94f8e Mon Sep 17 00:00:00 2001
From: Antoine Hoffmann <antoine.hoffmann@epfl.ch>
Date: Wed, 20 Sep 2023 09:56:18 +0200
Subject: [PATCH] can show Ni00 mode evolution

---
 matlab/compute/mode_growth_meter.m | 25 ++++++++++++++++---------
 wk/fast_analysis.m                 | 26 ++++++++++++++++----------
 2 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/matlab/compute/mode_growth_meter.m b/matlab/compute/mode_growth_meter.m
index b9aa6fe0..0f04834b 100644
--- a/matlab/compute/mode_growth_meter.m
+++ b/matlab/compute/mode_growth_meter.m
@@ -3,17 +3,24 @@ function [FIGURE, kykx, wkykx, ekykx] = mode_growth_meter(DATA,OPTIONS)
 NORMALIZED = OPTIONS.NORMALIZED;
 Nma   = OPTIONS.NMA; %Number moving average
 d     = OPTIONS.fftz.flag;  % To add spectral evolution of z (useful for 3d zpinch)
-
-if numel(size(DATA.PHI)) == 3
-        field = squeeze(DATA.PHI);
+switch OPTIONS.FIELD
+    case 'Ni00'
+        FIELD = DATA.Ni00;
+        fname = 'N^{00}';
+    case 'phi'
+        FIELD = DATA.PHI;
+        fname = '\phi';
+end
+if numel(size(FIELD)) == 3
+        field = squeeze(FIELD);
         zstrcomp = 'z=0';
 else
     switch OPTIONS.iz
         case 'avg'
-            field = reshape(mean(DATA.PHI,3),DATA.grids.Nky,DATA.grids.Nkx,numel(DATA.Ts3D));
+            field = reshape(mean(FIELD,3),DATA.grids.Nky,DATA.grids.Nkx,numel(DATA.Ts3D));
             zstrcomp = 'z-avg';
         otherwise
-            field = reshape(DATA.PHI(:,:,OPTIONS.iz,:),DATA.grids.Nky,DATA.grids.Nkx,numel(DATA.Ts3D));
+            field = reshape(FIELD(:,:,OPTIONS.iz,:),DATA.grids.Nky,DATA.grids.Nkx,numel(DATA.Ts3D));
             zstrcomp = ['z=',num2str(DATA.grids.z(OPTIONS.iz))];
     end
 end
@@ -31,7 +38,7 @@ TW = [OPTIONS.KY_TW; OPTIONS.KX_TW];
 [~,ikzf] = max(mean(squeeze(abs(field(1,:,FRAMES))),2));
 
 % Amplitude ratio method to measure growth rates and freq.
-[wkykx, ekykx] = compute_growth_rates(DATA.PHI(:,:,:,FRAMES),DATA.Ts3D(FRAMES));
+[wkykx, ekykx] = compute_growth_rates(FIELD(:,:,:,FRAMES),DATA.Ts3D(FRAMES));
 kykx = meshgrid(DATA.grids.ky,DATA.grids.kx)';
 
 FIGURE.fig = figure; %set(gcf, 'Position',  [100 100 1200 700])
@@ -131,7 +138,7 @@ for i = 1:2
         plot(t(it1)*[1 1],[1e-10 1],'--k')
         plot(t(it2)*[1 1],[1e-10 1],'--k')
         xlim([t(1) t(end)]); %ylim([1e-5 1])
-        xlabel('$t c_s /R_0$'); ylabel(['$|\phi_{',kstr,'}|$']);
+        xlabel('$t c_s /R_0$'); ylabel(['$|',fname,'_{',kstr,'}|$']);
         title('Measure time window')
 
 %     subplot(2+d,3,3+3*(i-1))
@@ -174,10 +181,10 @@ end
 if d
     [~,ikx] = min(abs(DATA.grids.kx-OPTIONS.fftz.kx));
     [~,iky] = min(abs(DATA.grids.ky-OPTIONS.fftz.ky));
-    sz_=size(DATA.PHI);nkz = sz_(3)/2;
+    sz_=size(FIELD);nkz = sz_(3)/2;
     k = [(0:nkz/2), (-nkz/2+1):-1]/DATA.grids.Npol;
     % Spectral treatment of z-dimension
-    Y = fft(DATA.PHI(iky,ikx,:,:),[],3);
+    Y = fft(FIELD(iky,ikx,:,:),[],3);
     phi = squeeze(Y(1,1,2:2:end,:)); 
     
     gamma = zeros(nkz);
diff --git a/wk/fast_analysis.m b/wk/fast_analysis.m
index 1e5957cc..125223c7 100644
--- a/wk/fast_analysis.m
+++ b/wk/fast_analysis.m
@@ -7,7 +7,7 @@ default_plots_options
 % Partition of the computer where the data have to be searched
 % PARTITION='/Users/ahoffmann/gyacomo/results/paper_3/';
 % PARTITION='/misc/gyacomo23_outputs/paper_3/';
-PARITION = '';
+PARTITION = '';
 %% Paper 3
 % resdir = 'DTT_rho85/3x2x192x48x32';
 % resdir = 'DTT_rho85/3x2x192x48x32_NT';
@@ -15,7 +15,8 @@ PARITION = '';
 % resdir = 'DTT_rho98/3x2x192x48x32_0.25grad';
 % resdir = 'LM_DIIID_rho95/5x3x512x92x32';
 % resdir = 'LM_DIIID_rho95/3x2x512x92x32';
-resdir = '../results/dev/ExB_SF';
+% resdir = '../testcases/cyclone_example';
+% resdir = '../testcases/CBC_ExBshear';
  %%
 J0 = 00; J1 = 02;
 
@@ -39,10 +40,10 @@ options.RESOLUTION = 256;
 plot_radial_transport_and_spacetime(data,options);
 end
 
-if 1
+if 0
 %% MOVIES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % Options
-% [data.PHI, data.Ts3D] = compile_results_3D(DATADIR,J0,J1,'phi');
+[data.PHI, data.Ts3D] = compile_results_3D(DATADIR,J0,J1,'phi');
 [data.Na00, data.Ts3D] = compile_results_3Da(DATADIR,J0,J1,'Na00');
 data.Ni00 = reshape(data.Na00(1,:,:,:,:),data.grids.Nky,data.grids.Nkx,data.grids.Nz,numel(data.Ts3D));
 options.INTERP    = 1;
@@ -58,7 +59,7 @@ options.NAME     = 'N_i^{00}';
 % options.NAME      = 'Q_x';
 % options.NAME      = 'n_i';
 % options.NAME      = 'n_i-n_e';
-options.PLAN      = 'xy';
+options.PLAN      = 'kxky';
 % options.NAME      = 'f_i';
 % options.PLAN      = 'sx';
 options.COMP      = 1;
@@ -112,19 +113,24 @@ options.TAVG_2D_CTR= 0; %make it contour plot
 fig = show_moments_spectrum(data,options);
 end
 
-if 0
+if 1
 %% Mode evolution
 [data.PHI, data.Ts3D] = compile_results_3D(DATADIR,J0,J1,'phi');
+[data.Na00, data.Ts3D] = compile_results_3Da(DATADIR,J0,J1,'Na00');
+data.Ni00 = reshape(data.Na00(1,:,:,:,:),data.grids.Nky,data.grids.Nkx,data.grids.Nz,numel(data.Ts3D));
 
 options.NORMALIZED = 0;
-options.TIME   = [000:9000];
-options.KX_TW  = [30 40]; %kx Growth rate time window
-options.KY_TW  = [10 20];  %ky Growth rate time window
+options.TIME   = data.Ts3D;
+options.KX_TW  = [ 0 2]; %kx Growth rate time window
+options.KY_TW  = [ 0 2];  %ky Growth rate time window
 options.NMA    = 1;
 options.NMODES = 800;
 options.iz     = 'avg'; % avg or index
-options.ik     = 1; % sum, max or index
+options.ik     = 'sum'; % sum, max or index
 options.fftz.flag = 0;
+options.FIELD  = 'Ni00';
+% options.FIELD  = 'phi';
+options.GOK2   = 0;
 fig = mode_growth_meter(data,options);
 % save_figure(data,fig,'.png')
 end
-- 
GitLab