forked from pabloseleson/hPIC-surrogate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MP_Expected_Theta_E.m
132 lines (97 loc) · 3.34 KB
/
MP_Expected_Theta_E.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The function MP_Expected_Theta_E computes the most probable and expected
% angle and energy
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Input
% -----
% - xNU: x-coordinates of nodes
% - yNU: y-coordinates of nodes
% - xNUpolyarray: x-coordinates of element edges
% - yNUpolyarray: y-coordinates of element edges
% - IEAD_NU: ion energy-angle distribution at the nodes
% - Te: electron temperature
% Output
% ------
% - MP_theta: most probably angle
% - MP_E: most probable energy
% - expected_theta: angle mean
% - expected_E: energy mean
% - std_theta: angle standard deviation
% - std_E: energy standard deviation
% Author: Pablo Seleson
% ------
% Last Modified: February 8, 2022
% -------------
function [MP_theta, MP_E, expected_theta, expected_E, std_theta, std_E] = MP_Expected_Theta_E(xNU,yNU,xNUpolyarray,yNUpolyarray,IEAD_NU,Te)
% -------------------------------------------
% Most probable and expected angle & energy
% -------------------------------------------
% Compute area of polygons: Shoelace formula
%
% Link: https://en.wikipedia.org/wiki/Shoelace_formula
%
% xx = xNUpolyarray(:,n); yy = yNUpolyarray(:,n);
%
% Area = 0.5*(sum(xx.*[yy(2:end); yy(1)]) - sum(yy.*[xx(2:end); xx(1)]));
%
% polyarea(xx,yy);
% Compute most probable (angle, energy)
[~, I] = max(IEAD_NU);
MP_theta = xNU(I);
MP_E = yNU(I)*Te; % Convert value from E/T_e -> E
% Compute expected (angle, energy)
expected_theta = 0;
expected_E = 0;
Ncount = 0;
% Define 1D arrays
xNU_array = xNU(:);
yNU_array = yNU(:);
for n = 1:length(IEAD_NU)
% Omit negative energy values
if yNU_array(n) < 0
else
% Read bin vertices
xx = xNUpolyarray(:,n);
yy = yNUpolyarray(:,n);
% Compute bin area
bin_area = polyarea(xx,yy);
% Bin count
count = IEAD_NU(n)*bin_area;
% Update arrays for expected angle and energy
expected_theta = expected_theta + xNU_array(n)*count;
expected_E = expected_E + yNU_array(n)*count;
% Update total count
Ncount = Ncount + count;
end
end
% Expected angle
expected_theta = expected_theta/Ncount;
% Expected energy
expected_E = (expected_E/Ncount)*Te; % Convert E/T_e -> E
% Compute standard deviation for (angle, energy)
std_theta = 0;
std_E = 0;
Ncount = 0;
for n = 1:length(IEAD_NU)
% Omit negative energy values
if yNU_array(n) < 0
else
% Read bin vertices
xx = xNUpolyarray(:,n);
yy = yNUpolyarray(:,n);
% Compute bin area
bin_area = polyarea(xx,yy);
% Bin count
count = IEAD_NU(n)*bin_area;
% Update arrays for angle and energy standard deviations
std_theta = std_theta + (xNU_array(n) - expected_theta)^2*count;
std_E = std_E + (yNU_array(n) - expected_E/Te)^2*count;
% Update total count
Ncount = Ncount + count;
end
end
% Angle standard deviation
std_theta = sqrt(std_theta/(Ncount));
% Energy standard deviation
std_E = sqrt(std_E/(Ncount))*Te;
end