-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGSA_Moments_2D.m
263 lines (191 loc) · 7.65 KB
/
GSA_Moments_2D.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The function GSA_Moments_2D computes the angle and energy moments profiles
% (mean and standard deviation) using the 2D IEAD surrogate model
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Input
% -----
% sglevel: data sparse grid level
% Npoints: number of points per dimension
% Author: Pablo Seleson
% ------
% Last Modified: February 10, 2022
% -------------
function GSA_Moments_2D(sglevel, Npoints)
% Check sglevel input
if sglevel~= 7 && sglevel~= 10 && sglevel~= 13
error('sglevel should be 7, 10, or 13.')
end
% ====================================================================
% Create Evaluation Grid in Physical Parameter Space
% ====================================================================
% Grid limits
min_Log10_Te_Ti = -1.25;
max_Log10_Te_Ti = 1.25;
min_Psi = 0;
max_Psi = 87;
% Generate grid
x_grid = linspace(min_Log10_Te_Ti,max_Log10_Te_Ti,Npoints);
y_grid = linspace(min_Psi,max_Psi,Npoints);
[Xgrid, Ygrid] = meshgrid(x_grid,y_grid);
% Read physical parameter values
Log10_Te_Ti = Xgrid(:);
Psi = Ygrid(:);
% Number of total points
npoints = length(Log10_Te_Ti);
% ====================================================================
% Evaluate IEAD* model
% ====================================================================
% Reload 2D IEAD* fit grid
gridname = ['LS_2D_Grid_IEADstar_level_' num2str(sglevel)];
[lGrid_IEADstar] = tsgReloadGrid(gridname);
% Evaluate IEAD* surrogate model on data points
[IEADstar_all] = tsgEvaluate(lGrid_IEADstar, [Log10_Te_Ti Psi]);
% ====================================================================
% Compute Moments per Case for Transformation
% ====================================================================
% Reload 2D moments grid
gridname = ['LS_2D_Grid_Moments_level_' num2str(sglevel)];
[lGrid_Moments] = tsgReloadGrid(gridname);
% Moment
[Moments] = tsgEvaluate(lGrid_Moments, [Log10_Te_Ti Psi]);
% Assign moments to arrays
thetabar_mean = Moments(:,1);
Ebar_mean = 10.^Moments(:,2);
Theta_mean_11 = 10.^Moments(:,3);
Theta_mean_22 = 10.^Moments(:,4);
Theta_mean_12 = Moments(:,5);
Theta_mean = [Theta_mean_11 Theta_mean_22 Theta_mean_12]; % [Theta(1,1) Theta(2,2) Theta(1,2)];
% ====================================================================
% Read Binning in Transformed Coordinates
% ====================================================================
% Create elements for patch function
[~, ~, ~, ~, xstar, ystar, ~, ~, ~] = gridpolygonsTC;
% ====================================================================
% Compute Moments
% ====================================================================
% Moments
Moments_Theta_E = zeros(npoints,4);
% Ion temperature
Ti = 10;
% Create reference non-uniform grid in the transformed coordinates
[~, ~, ~, ~, xNU_ref, yNU_ref, xNUpolyarray_ref, yNUpolyarray_ref, ~] = gridpolygonsTC;
% Run over samples
for i = 1:npoints
fprintf('Sample %5g of %5g \n',i,npoints)
% Read IEAD* for the ith sample
IEADstar = IEADstar_all(i,:);
% Moments to convert data
thetabar = thetabar_mean(i);
Ebar = Ebar_mean(i);
Theta = [Theta_mean(i,1) Theta_mean(i,3); Theta_mean(i,3) Theta_mean(i,2)];
% Electron temperature
Te = Ti*10^Log10_Te_Ti(i);
% Transform grid in the transformed coordinates to the original coordinates
[xNU, yNU, xNUpolyarray, yNUpolyarray] = transform_gridpolygonsTC(xNU_ref, yNU_ref, xNUpolyarray_ref, yNUpolyarray_ref, thetabar, Ebar, Theta);
% Evaluate IEAD from IEAD*
[IEAD_NU] = evaluate_IEAD_from_IEADstar(xNU(:),yNU(:),thetabar,Ebar,Theta,xstar(:),ystar(:),IEADstar(:));
% Mean and standard devation of angle & energy
[~, ~, expected_theta, expected_E, std_theta, std_E] = MP_Expected_Theta_E(xNU,yNU,xNUpolyarray,yNUpolyarray,IEAD_NU,Te);
Moments_Theta_E(i,:) = [expected_theta expected_E std_theta std_E];
end
% ====================================================================
% Plot Contour Moments
% ====================================================================
% Number of contour lines
Nlines = 35;
% Initialize figure counter
nfig = 0;
% ------------
% theta mean
% ------------
nfig = nfig + 1;
figure(nfig)
% Data
data = Moments_Theta_E(:,1);
moment_plot = reshape(data,Npoints,Npoints);
xmesh_plot = reshape(Log10_Te_Ti,Npoints,Npoints);
ymesh_plot = reshape(Psi,Npoints,Npoints);
% Plot contours
ztext = '$\mu_{\theta}$';
title_text = '';
plot_moment_contour(xmesh_plot,ymesh_plot,moment_plot,ztext,title_text,Nlines)
set(gcf,'Position',[500 800 560 420])
% ------------
% E mean
% ------------
nfig = nfig + 1;
figure(nfig)
% Data
data = Moments_Theta_E(:,2);
moment_plot = reshape(data,Npoints,Npoints);
xmesh_plot = reshape(Log10_Te_Ti,Npoints,Npoints);
ymesh_plot = reshape(Psi,Npoints,Npoints);
% Plot contours
ztext = '$\mu_{E}$';
title_text = '';
plot_moment_contour(xmesh_plot,ymesh_plot,moment_plot,ztext,title_text,Nlines)
set(gcf,'Position',[1200 800 560 420])
% ------------
% theta std.
% ------------
nfig = nfig + 1;
figure(nfig)
% Data
data = Moments_Theta_E(:,3);
moment_plot = reshape(data,Npoints,Npoints);
xmesh_plot = reshape(Log10_Te_Ti,Npoints,Npoints);
ymesh_plot = reshape(Psi,Npoints,Npoints);
% Plot contours
ztext = '$\sigma_{\theta}$';
title_text = '';
plot_moment_contour(xmesh_plot,ymesh_plot,moment_plot,ztext,title_text,Nlines)
set(gcf,'Position',[500 200 560 420])
% ------------
% E std.
% ------------
nfig = nfig + 1;
figure(nfig)
% Data
data = Moments_Theta_E(:,4);
moment_plot = reshape(data,Npoints,Npoints);
xmesh_plot = reshape(Log10_Te_Ti,Npoints,Npoints);
ymesh_plot = reshape(Psi,Npoints,Npoints);
% Plot contours
ztext = '$\sigma_{E}$';
title_text = '';
plot_moment_contour(xmesh_plot,ymesh_plot,moment_plot,ztext,title_text,Nlines)
set(gcf,'Position',[1200 200 560 420])
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The function plot_moment_contour generates a contour plot for given
% moment data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Input
% -----
% - xmesh_fit: x-coordinates of mesh
% - ymesh_fit: y-coordinates of mesh
% - fit: moment data at the mesh points
% - ztext: z-label
% - title_text: plot title
% - Nlines: number of contour lines
% Author: Pablo Seleson
% ------
% Last Modified: February 10, 2022
% -------------
function plot_moment_contour(xmesh_fit,ymesh_fit,fit,ztext,title_text,Nlines)
% Plot contours
contourf(xmesh_fit,ymesh_fit,fit,Nlines)
% Labels
set(gca,'fontsize', 20)
xlabel('$\log_{10}(T_e/T_i)$','Interpreter','latex','Fontsize',24)
ylabel('$\Psi$','Interpreter','latex','Fontsize',24)
zlabel(ztext,'Interpreter','latex','Fontsize',24)
box('on')
title(title_text,'Interpreter','latex','FontSize',26)
% Colorbar
hcb = colorbar;
% Colorbar title
colorTitleHandle = get(hcb,'Title');
titleString = ztext;
set(colorTitleHandle ,'String',titleString,'interpreter','latex','FontSize',24)
end