-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinal_Trajectory_Generation.m
96 lines (81 loc) · 3.77 KB
/
Final_Trajectory_Generation.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
%function Primary_Trajectory_Generation
clc
clear all
%-------------------------------------------------------------------------%
% INITIALIZATION
%-------------------------------------------------------------------------%
% E = Total electric field matrix using Poisson's equation
% V = Potential matrix
% Nx = Number of grid points in X- direction
% Ny = Number of grid points in Y-Direction
%-------------------------------------------------------------------------%
%-------------------------------------------------------------------------%
% LOADING THE INPUT FILES
%-------------------------------------------------------------------------%
load('Test') %Variable number for the test iteration'
Test = Test -2;
date_yes = char(datetime(2020,9,10));
folder_name = ['Test_Data\' date_yes];
%-------------------------------------------------------------------------%
qi = 100;
e_charge = 1.602e-19;
eps = 8.854*(10^-12);
m_Xe = 2.1801714e-25; %kg
f_bohm = 1;
v_bohm = f_bohm * sqrt(100* 1.60217662 * (10^-19) *3/(100 * 2.18017 * 10^-25));
V = csvread([folder_name '\Test' num2str(Test) '_VtgDistMat.csv']);
size1 = 6*10e-3/size(V, 1); % this variable is needed for interpolation, it is the grid size (e.g. 0.1 m)
Ex_cd = csvread([folder_name '\Test' num2str(Test) '_Ex_ion.csv']);
Ey_cd = csvread([folder_name '\Test' num2str(Test) '_Ex_ion.csv']);
Nx = size(V,1);
Ny = size(V,2);
Ex = zeros(Nx,Ny);
Ey = zeros(Nx,Ny);
for i = 3:Nx-2
for j = 3:Ny-2
Ex(i,j) = -(-V(i, j+2) + 8*V(i,j+1) - 8*V(i,j-1) + V(i,j-2))/12;
Ey(i,j) = -(-V(i+2, j) + 8*V(i+1,j) - 8*V(i-1,j) + V(i-2,j))/12;
end
end
% Electric field Magnitude
Ex = Ex + Ex_cd;
Ey = Ey + Ey_cd;
E = sqrt(Ex.^2+Ey.^2);
x = (1:Ny);
y = (1:Nx);
Nj = 100000;
%-------------------------------------------------------------------------%
% Positon Simulation
%-------------------------------------------------------------------------%
NPos_x = zeros(253,Nj); % X position matrix to multiple trajectories
NPos_y = zeros(253,Nj); % Y position matrix to multiple trajectories
time_step = zeros(253,Nj);
Vx_in= v_bohm;
Vy_in = 0;
Vx_new = zeros(253,Nj);
Vy_new = zeros(253,Nj);
xn = 132; % Initial X position
yn = 126:378; % Initial Y position
for itr = 1:253
[NPos_x(itr,:), NPos_y(itr,:), Vx_new(itr, :), Vy_new(itr, :), time_step(itr,:)] = Path_Calculation(xn, yn(1,itr), Ex, Ey, Vx_in, Vy_in);
end
p_dim = size(NPos_x, 1);
pos_cellX = {};
pos_cellY = {};
for s = 1:p_dim
[pos_cellX{s}, pos_cellY{s}] = Post_process(NPos_x(s,:), NPos_y(s,:));
end
%-------------------------------------------------------------------------%
% SAVING THE TRAJECTORIES
%-------------------------------------------------------------------------%
if isfolder(folder_name)
writematrix(NPos_x, [folder_name '\Test' num2str(Test) '_NPos_x_Final.csv']) % writes the generated Trajectory matrix to a given name
writematrix(NPos_y, [folder_name '\Test' num2str(Test) '_NPos_y_Final.csv']) % writes the generated Trajectory matrix to a given name
writematrix(time_step, [folder_name '\Test' num2str(Test) '_TimeStep_Final.csv']) % writes the generated Time Step matrix to a given name
writematrix(Vx_new, [folder_name '\Test' num2str(Test) '_Vx_Final.csv']) % Writes the generated Velocity matrix to a given name
else
mkdir(fullfile('Test_Data\', date))
writematrix(NPos_x, [folder_name '\Test' num2str(Test) '_NPos_x_Final.csv']) % writes the generated Trajectory matrix to a given name
writematrix(NPos_y, [folder_name '\Test' num2str(Test) '_NPos_y_Final.csv']) % writes the generated Trajectory matrix to a given name
writematrix(time_step, [folder_name '\Test' num2str(Test) '_TimeStep_Final.csv']) % writes the generated Time Step matrix to a given name
end