-
Notifications
You must be signed in to change notification settings - Fork 0
/
transient05.m
223 lines (194 loc) · 7.18 KB
/
transient05.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
%% Solves: Unsteady, compressible convection-diffusion problems.
% Description:
% This program solves unsteady convection-diffusion problems
% using the transient simple algorithm described in ch. 8.7.1 in "Computational
% Fluid Dynamics" by H.K. Versteeg and W. Malalasekera. Symbols and
% variables follow exactly the notations in this reference, and all
% equations cited are from this reference unless mentioned otherwise.
% Converted from C to Matlab by YTANG
% References: 1. Computational Fluid Dynamics, H.K. Versteeg and W. Malalasekera, Longman Group Ltd, 1995
clear
close all
clc
%% declare all variables and contants
% variables
global x x_u y y_v u v pc T rho mu Gamma b SMAX SAVG aP aE aW aN aS eps k...
u_old v_old pc_old T_old Dt eps_old k_old uplus yplus yplus1 yplus2 P_ATM F_u F_v ratio_u ratio_v m_
% constants
global NPI NPJ XMAX YMAX LARGE U_IN SMALL Cmu sigmak sigmaeps C1eps C2eps kappa ERough Ti p Y_truck X_truck X_distance
Y_truck = 2.70/2; % 2.70height of a truck [m]
X_truck = 15/2; % 15 length of a truck [m]
X_distance = 5; % 2 distance between trucks [m]
NPI = 100; % number of grid cells in x-direction [-]
NPJ = 50; % number of grid cells in y-direction [-]
XMAX = 3* X_truck + 2* X_distance + 5; % width of the domain [m]
YMAX = 20; % height of the domain [m]
MAX_ITER = 1000; % maximum number of outer iterations [-]
U_ITER = 1; % number of Newton iterations for u equation [-]
V_ITER = 1; % number of Newton iterations for v equation [-]
PC_ITER = 30; % number of Newton iterations for pc equation [-]
T_ITER = 1; % number of Newton iterations for T equation [-]
EPS_ITER = 1; % number of Newton iterations for Eps equation [-]
K_ITER = 1; % number of Newton iterations for K equation [-]
SMAXneeded = 1E-8; % maximum accepted error in mass balance [kg/s]
SAVGneeded = 1E-9; % maximum accepted average error in mass balance [kg/s]
LARGE = 1E30; % arbitrary very large value [-]
SMALL = 1E-30; % arbitrary very small value [-]
P_ATM = 101000.; % athmospheric pressure [Pa]
U_IN = 80/3.6; % in flow velocity [m/s]
Cmu = 0.09;
sigmak = 1.;
sigmaeps = 1.3;
C1eps = 1.44;
C2eps = 1.92;
kappa = 0.4187;
ERough = 9.793;
Ti = 0.04;
Dt = XMAX/NPI/U_IN;
TOTAL_TIME = 1.;
%% start main function here
init(); % initialization
bound(); % apply boundary conditions
for time = Dt:Dt:TOTAL_TIME
iter = 0;
% outer iteration loop
while iter < MAX_ITER && SMAX > SMAXneeded && SAVG > SAVGneeded
derivatives();
ucoeff();
for iter_u = 1:U_ITER
u = solve(u, b, aE, aW, aN, aS, aP);
end
vcoeff();
for iter_v = 1:V_ITER
v = solve(v, b, aE, aW, aN, aS, aP);
end
bound();
pccoeff();
for iter_pc = 1:PC_ITER
pc = solve(pc, b, aE, aW, aN, aS, aP);
end
velcorr(); % Correct pressure and velocity
kcoeff();
for iter_k = 1:K_ITER
k = solve(k, b, aE, aW, aN, aS, aP);
end
epscoeff();
for iter_eps = 1:EPS_ITER
eps = solve(eps, b, aE, aW, aN, aS, aP);
end
Tcoeff();
for iter_T = 1:T_ITER
T = solve(T, b, aE, aW, aN, aS, aP);
end
viscosity();
bound();
% begin:storeresults()=============================================
% Store data at current time level in arrays for "old" data
% To newly calculated variables are stored in the arrays ...
% for old variables, which can be used in the next timestep
u_old(3:NPI+1,2:NPJ+1) = u(3:NPI+1,2:NPJ+1);
v_old(2:NPI+1,3:NPJ+1) = v(2:NPI+1,3:NPJ+1);
pc_old(2:NPI+1,2:NPJ+1) = pc(2:NPI+1,2:NPJ+1);
T_old(2:NPI+1,2:NPJ+1) = T(2:NPI+1,2:NPJ+1);
eps_old(2:NPI+1,2:NPJ+1) = eps(2:NPI+1,2:NPJ+1);
k_old(2:NPI+1,2:NPJ+1) = k(2:NPI+1,2:NPJ+1);
% end: storeresults()==============================================
% increase iteration number
iter = iter +1;
end % end of while loop (outer interation)
% begin: printConv(time,iter)=========================================
% print convergence to the screen
if time == Dt
fprintf ('Iter\t Time\t u\t v\t T\t SMAX\t SAVG\n');
end
fprintf ("%4d %10.3e\t%10.2e\t%10.2e\t%10.2e\t%10.2e\t%10.2e\n",iter,...
time,u(ceil(3*(NPI+1)/10),ceil(2*(NPJ+1)/5)),v(ceil(3*(NPI+1)/10),ceil(2*(NPJ+1)/5)),...
T(ceil(3*(NPI+1)/10),ceil(2*(NPJ+1)/5)), SMAX, SAVG);
% end: printConv(time, iter)===========================================
% reset SMAX and SAVG
SMAX = LARGE;
SAVG = LARGE;
end % end of calculation
% %% begin: output()
% % Print all results in output.txt
% fp = fopen('output.txt','w');
% for I = 1:NPI+1
% i = I;
% for J = 2:NPJ+1
% j = J;
% ugrid = 0.5*(u(i,J)+u(i+1,J)); % interpolated horizontal velocity
% vgrid = 0.5*(v(I,j)+v(I,j+1)); % interpolated vertical velocity
% fprintf(fp,'%11.5e\t%11.5e\t%11.5e\t%11.5e\t%11.5e\t%11.5e\t%11.5e\t%11.5e\t%11.5e\t%11.5e\t%11.5e\t%11.5e\t%11.5e\t%11.5e\t%11.5e\n',...
% x(I), y(J), ugrid, vgrid, pc(I,J), T(I,J), rho(I,J), mu(I,J), Gamma(I,J), ...
% k(I,J), eps(I,J), uplus(I,J), yplus(I,J), yplus1(I,J), yplus2(I,J));
% end
% fprintf(fp, '\n');
% end
% fclose(fp);
%
% % Plot vorticity in vort.txt
% vort = fopen('vort.txt','w');
% for I = 2:NPI+1
% i = I;
% for J = 2:NPJ+1
% j = J;
% vorticity = (u(i,J) - u(i,J-1)) / (y(J) - y(J-1)) - (v(I,j) - v(I-1,j)) / (x(I) - x(I-1));
% fprintf(vort, '%11.5e\t%11.5e\t%11.5e\n',x(I), y(J), vorticity);
% end
% fprintf(vort,'\n');
% end
% fclose(vort);
%
% % Plot streamlines in str.txt
% str = fopen('str.txt', 'w');
% for I = 1:NPI+1
% i = I;
% for J = 1:NPJ+1
% j = J;
% stream = -0.5*(v(I+1,j)+v(I,j))*(x(I+1)-x(I))+0.5*(u(i,J+1)+u(i,J))*(y(J+1)-y(J));
% fprintf(str, '%11.5e\t%11.5e\t%11.5e\n',x(I), y(J), stream);
% end
% fprintf(str,'\n');
% end
% fclose(str);
%
% % Plot horizontal velocity components in velu.txt
% velu = fopen('velu.txt','w');
% for I = 2:NPI+2
% i = I;
% for J = 1:NPJ+2
% fprintf(velu, '%11.5e\t%11.5e\t%11.5e\n',x_u(i), y(J), u(i,J));
% end
% fprintf(velu, '\n');
% end
% fclose(velu);
%
% % Plot vertical velocity components in velv.txt
% velv = fopen('velv.txt','w');
% for I = 1:NPI+2
% for J = 2:NPJ+2
% j = J;
% fprintf(velv, '%11.5e\t%11.5e\t%11.5e\n',x(I), y_v(j), v(I,j));
% end
% fprintf(velv,'\n');
% end
% fclose(velv);
% % end output()
%% plot vector map
[X,Y]=meshgrid(y_v, x_u);
figure(1)
quiver(Y,X,u,v,3);
axis equal;
figure(2)
surf(X,Y,u);
figure(3)
surf(X,Y,p);
figure(4)
plot(Y(2:NPI,6),p(2:NPI,6));
hold on
plot(Y(2:NPI,NPJ-1),p(2:NPI,NPJ-1));
hold off
figure(5)
plot(Y(2:NPI,6),u(2:NPI,6));
hold on
plot(Y(2:NPI,NPJ-1),u(2:NPI,NPJ-1));