Professional Documents
Culture Documents
Tansu Sevine
1679950, Dept. of Aerospace Eng.
April 22, 2018
1 Objective
Objective of this project is to write a MATLAB code to calculate heat diffusion of a body of 2D using
finite difference methods. Then, calculate POD basis and reconstruct temperature fields based on POD
modes.
2 Method
4 Conclusion
In this study, a MATLAB code is written to calculate ice thickness at which the glaze ice starts to
build up, Bg ; ice thickness, B; freezing fraction, F F and water layer thickness, h at given ambient and
substrate temperatures, Ta and Ts is successfully. The results are compared with [Myers, 2001] paper.
Re-illustration of the Figure 2 (Ice and water growth for Ts = Ta = 263.15K and 270K), Figure 3 (Bg vsTa
with Ts = 263.15K Ta = 270K and Ts = Ta = 270K), Figure 5 (Variation of freezing fraction with time
for Ta = Ts = 263.15K), Figure 6 (Variation of freezing fraction with time for Ta = Ts = 270K) are done.
It is seen that results are near perfectly matching.
1
Main MATLAB code for calculations and plots
1 clc;clear all; close all; format compact; format shortg
2 nx = 101;
3 ny = 101;
4 dt = 0.1; % time step
5 casenumber = 2; % use 1 or 2 only for case1 (c =0.01), case2(c=0.05)
6 prompt = ’Enter method name "IE", "CN", "RS" >> ’;
7 method = input(prompt,’s’)
8
9 if(casenumber == 1)
10 disp(’1st case selected’)
11 ka = 0.01; % thermal diffisuvity
12 else
13 disp(’2nd case selected’)
14 ka = 0.1;
15 end
16
17 %% Defaults for figures
18 width = 8; % Width in inches
19 height = 10; % Height in inches
20 alw = 0.2; % AxesLineWidth
21 fsz = 14; % Fontsize
22 lw = 1.5; % LineWidth
23 msz = 8; % MarkerSize
24 % The properties we’ve been using in the figures
25 set(0,’defaultLineLineWidth’,lw); % set the default line width to lw
26 set(0,’defaultLineMarkerSize’,msz); % set the default line marker size to msz
27 set(0,’defaultLineLineWidth’,lw); % set the default line width to lw
28 set(0,’defaultLineMarkerSize’,msz); % set the default line marker size to msz
29
30 % Set the default Size for display
31 defpos = get(0,’defaultFigurePosition’);
32 set(0,’defaultFigurePosition’, [100 -50 width*100, height*100]);
33
34 % Set the defaults for saving/printing to a file
35 set(0,’defaultFigureInvertHardcopy’,’on’); % This is the default anyway
36 set(0,’defaultFigurePaperUnits’,’inches’); % This is the default anyway
37 defsize = get(gcf, ’PaperSize’);
38 left = (defsize(1)- width)/2;
39 bottom = (defsize(2)- height)/2;
40 defsize = [left, bottom, width, height];
41 set(0, ’defaultFigurePaperPosition’, defsize);
42
43 %% Preperation Section
44 [A,dx,dy,x,y,Number] = preparation(nx,ny);
45 [X,Y] = meshgrid(x,y);
46 % T0 = ones(nx*ny ,1)*10;
47 for j=1:ny
48 for i=1:nx
49 if(casenumber == 1)
50 T01(i,j) = sin(2*pi*x(i))*sin(pi*y(i)); % case 1
51 else
52 if(x(i) > 0.249 && x(i)< 0.751 && y(j) > 0.249 && y(j)< 0.751) % case 2
53 T01(i,j) = 1;
54 else
55 T01(i,j) = 0;
56 end
57 end
58 T0(Number(i,j),1) = T01(i,j);
59 end
60 end
61 figure
62 pcolor(X,Y,T01), shading interp, colorbar, colormap(’jet’);
63 title(’Initial temperature distribution’)
64 [T0] = add_boundary(T0,nx,ny,Number);
65
66 %% Solution Section
67 % [sln_E,time_E] = solve_heat_fdm(ka,A,nx,ny,Number,dx,dy,dt,T0,’IE’);
68 % [sln_CN,time_CN] = solve_heat_fdm(ka,A,nx,ny,Number,dx,dy,dt,T0,’CN’);
69 % [sln_RS,time_RS] = solve_heat_fdm(ka,A,nx,ny,Number,dx,dy,dt,T0,’RS’);
70 [sln,time] = solve_heat_fdm(ka,A,nx,ny,Number,dx,dy,dt,T0,method);
71
72 num =1;
73 for j=1:ny
74 for i=1:nx
75 slnij(i,j) = sln(num,end);
76 % euler_sln(i,j) = sln_E(num,end);
77 % CN_sln(i,j) = sln_CN(num,end);
78 % RS_sln(i,j) = sln_RS(num,end);
79 num = num+1;
80 end
81 end
82 % %% Plot Section
83 % figure
84 % subplot(3,1,1)
85 % pcolor(Y,X,euler_sln); shading interp, colorbar, colormap(’jet’);
86 % title([’EULER, final time= ’ num2str(time_E), ’, # of tstep= 100 ’])
87 % subplot(3,1,2)
88 % pcolor(Y,X,CN_sln); shading interp, colorbar, colormap(’jet’);
89 % title([’CN, final time= ’ num2str(time_CN), ’, # of tstep= 100 ’])
90 % subplot(3,1,3)
91 % pcolor(Y,X,RS_sln); shading interp, colorbar, colormap(’jet’);
92 % title([’RS, final time= ’ num2str(time_RS), ’, # of tstep= 100 ’])
93 %% POD calculation
94 % sent snapshot matrix to this function, returns POD basis and Singular values
95 [U,SS,coef] = podhesap(sln);
96 %% weight matrix
97 W_e = weight_matrix(SS,’E’); % for Euclidian norm
98 W_l2 = weight_matrix(SS,’L2’); % for L2 norm
99 %% reconstruction section
100 rank = 10 ; % rank number for reduced order model
101 red_coef = coef(1:rank,:);
102 rA = U(:,1:rank)*red_coef ;
103 error = rms(rms(rA-sln))
104 tcontrol = 40;
105 num = 1;
106 for j=1:ny
107 for i=1:nx
108 sln_control(i,j) = sln(num,tcontrol);
109 r_control(i,j) = rA(num,tcontrol);
110 num = num+1;
111 end
112 end
113
114
115
116 close all
117
118 figure
119 subplot(3,1,1)
120 pcolor(Y,X,sln_control); shading interp, colorbar, colormap(’jet’);
121 title([’Real solution at time= ’ num2str(tcontrol) ])
122 subplot(3,1,2)
123 pcolor(Y,X,r_control); shading interp, colorbar, colormap(’jet’);
124 title([’Approximated solution with reduced order model’ ])
125 subplot(3,1,3)
126 pcolor(Y,X,abs(sln_control - r_control)); shading interp, colorbar, colormap(’jet’);
127 title([’Abs. error distribution, | Real - Reduced order model |’])
128 suptitle([’Method : ’ method, ’, Rank: ’ num2str(rank), ’, Kappa= ’ num2str(ka)])
129
130 filename = [ ’figs/’ method ’_t’ num2str(tcontrol) ’_r’ num2str(rank) ’_c’ num2str(ka*100) ’.png’ ];
131 print(figure(1),filename,’-dpng’)