Advertisement
Guest User

sample

a guest
Apr 17th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. clc;
  2. clear;
  3.  
  4. %% Plate Dimensions
  5. Ly = 3.5; %Height (in)
  6. Lx = 0.3125; %Width (in)
  7.  
  8. %% Spatial Discretization of Elements
  9. dx = 0.0521; %(in)
  10. dy = 0.140; %(in)
  11. dt = 0.08; %(s)
  12. n_i = 26; %Number of nodes along the i-axis
  13. n_j = 7; %Number of nodes along the j-axis
  14.  
  15. %% Material Properties and Constants
  16. K = 1.9907e-4; %Conductivity of Steel (Btu/hr-in-R)
  17. rho = .2853; %Density (lbm/in^3)
  18. c_p = 0.114; %Specific Heat (Btu/lbm-R)
  19. h = 3.858e-5; %Heat Transfer Coefficient (Btu/hr-in^2-F)
  20. a = 6.12e-3; %Thermal Diffusivity (in^2/s)
  21.  
  22. %% Inital Conditions
  23. T_inf = 60; %Air temperature (F)
  24. Ts = T_inf; %Surface temperature (F)
  25. q_dot = 0.020; %Heat Flux (Btu/s-in^2)
  26. T(1:n_i,1:n_j,1)= Ts; %All nodes along the right wall are at Ts
  27. t = 0; %Initial time (s)
  28. t_f = 8; %Final stopping time (s)
  29.  
  30. %% Temperature Profile Generation
  31.  
  32. k = 1; %Beginning iteration at the first time step
  33.  
  34. while t < t_f
  35. for i = 1:n_i
  36. for j = 1:n_j
  37.  
  38. % General Recursive Formula for Interior Nodes
  39. if (i>1 && i<n_i) && (j>1 && j<n_j)
  40. T(i,j,k+1)= T(i,j,k)*(1 - (a*dt)/(dx^2) -(a*dt)/(dx^2) - (a*dt)/(dy^2) - (a*dt)/(dy^2)) + T(i,j-1,k)*(a*dt)/(dx^2) + T(i,j+1,k)*(a*dt)/(dx^2) + T(i+1,j,k)*(a*dt)/(dy^2)+ T(i-1,j,k)*(a*dt)/(dy^2);
  41.  
  42. % Top nodes (52,78,104,130,156)
  43. elseif i == n_i && (j>1 && j<n_j)
  44. T(i,j,k+1)= T(i,j,k)*(1 - (2*h*dt)/(rho*c_p*dy) -(a*dt)/(dx^2) - (a*dt)/(dx^2) - (2*a*dt)/(dy^2)) + T_inf*(2*h*dt)/(rho*c_p*dy) + T(i,j-1,k)*(a*dt)/(dx^2) + T(i,j+1,k)*(a*dt)/(dx^2) + T(i-1,j,k)*(2*a*dt)/(dy^2);
  45.  
  46. % Bottom nodes (27,53,79,105,131)
  47. elseif i == 1 && (j>1 && j<n_j)
  48. T(i,j,k+1)= T(i,j,k)*(1 - (a*dt)/(dx^2) -(a*dt)/(dx^2) - (2*a*dt)/(dy^2)) + T(i,j-1,k)*(a*dt)/(dx^2) + T(i,j+1,k)*(a*dt)/(dx^2) + T(i+1,j,k)*(2*a*dt)/(dy^2);
  49.  
  50. % Right nodes (158,159,160, ... 181)
  51. elseif j == n_j && (i>1 && i<n_i)
  52. T(i,j,k+1)= T(i,j,k)*(1 - (2*a*dt)/(dx^2) -(2*h*dt)/(rho*c_p*dx) - (a*dt)/(dy^2) - (a*dt)/(dy^2)) + T_inf*(2*h*dt)/(rho*c_p*dx) + T(i,j-1,k)*(2*a*dt)/(dx^2) + T(i+1,j,k)*(a*dt)/(dy^2) + T(i-1,j,k)*(a*dt)/(dy^2) +((2*q_dot*dt)/(rho*c_p*dx));
  53.  
  54. % Left nodes (2,3,4, ... 25)
  55. elseif j == 1 && (i>1 && i<n_i)
  56. T(i,j,k+1)= T(i,j,k)*(1 - (2*h*dt)/(rho*c_p*dx) -(2*a*dt)/(dx^2) - (a*dt)/(dy^2) - (a*dt)/(dy^2)) + T_inf*(2*h*dt)/(rho*c_p*dx) + T(i,j+1,k)*(2*a*dt)/(dx^2) + T(i+1,j,k)*(a*dt)/(dy^2) + T(i-1,j,k)*(a*dt)/(dy^2);
  57.  
  58. % Upper Left Node (1)
  59. elseif i==1 && j==1
  60. T(i,j,k+1)= T(i,j,k)*(1 - (2*h*dt)/(rho*c_p*dx) - (2*a*dt)/(dx^2) - (2*a*dt)/(dy^2)) + T_inf*((2*h*dt)/(rho*c_p*dx)) + T(i,j+1,k)*(2*a*dt)/(dx^2) + T(i+1,j,k)*(2*a*dt)/(dy^2);
  61.  
  62. % Lower Left Node (26)
  63. elseif j==1 && i==n_i
  64. T(i,j,k+1)= T(i,j,k)*(1 - (2*h*dt)/(rho*c_p*dx) -(2*h*dt)/(rho*c_p*dy) - (2*a*dt)/(dx^2) - (2*a*dt)/(dy^2)) + T_inf*((2*h*dt)/(rho*c_p*dx)+(2*h*dt)/(rho*c_p*dy)) + T(i-1,j,k)*(2*a*dt)/(dy^2) + T(i,j+1,k)*(2*a*dt)/(dx^2);
  65.  
  66. % Upper Right Node (157)
  67. elseif j==n_j && i==1
  68. T(i,j,k+1)= T(i,j,k)*(1 - (2*h*dt)/(rho*c_p*dx) - (2*a*dt)/(dx^2) - (2*a*dt)/(dy^2)) + T_inf*((2*h*dt)/(rho*c_p*dx)) + T(i+1,j,k)*(2*a*dt)/(dy^2) + T(i,j-1,k)*(2*a*dt)/(dx^2) + ((2*q_dot*dt)/(rho*c_p*dx));
  69.  
  70. % Lower Right Node (182)
  71. elseif j==n_j && i==n_i
  72. T(i,j,k+1)= T(i,j,k)*(1 - (2*h*dt)/(rho*c_p*dx) -(2*h*dt)/(rho*c_p*dy) - (2*a*dt)/(dx^2) - (2*a*dt)/(dy^2)) + T_inf*((2*h*dt)/(rho*c_p*dx)+(2*h*dt)/(rho*c_p*dy)) + T(i,j-1,k)*(2*a*dt)/(dx^2) + T(i-1,j,k)*(2*a*dt)/(dy^2) + ((2*q_dot*dt)/(rho*c_p*dx));
  73.  
  74. end
  75. end
  76. end
  77.  
  78. t = t+dt; %Sets the current time ahead 0.08 seconds until reaching 8 seconds
  79. k = k+1; %Tells the program to reiterate with the next time step
  80.  
  81. end
  82.  
  83. M = T(1:n_i,1:n_j,1:k); %Builds the 101 matrices for the temperature profile
  84. [T_max, Indx] = max(M(:)); %Returns the maximum value throughout all matrices
  85. [Indx1, Indx2, Indx3] = ind2sub(size(M), Indx); %Returns the location of T_max
  86. disp('Maximum Temperature:');
  87. disp(max(M(:)));
  88. disp('Location of Maximum Temperature:')
  89. disp([Indx1, Indx2, Indx3]);
  90. FX = gradient(M);
  91. [FXmax, Indx] = max(FX(:));
  92. [Indx1, Indx2, Indx3] = ind2sub(size(FX), Indx);
  93. disp('Maximum Temperature Gradient:');
  94. disp(max(FX(:)));
  95. disp('Location of Maximum Temperature Gradient in x direction:')
  96. disp([Indx1, Indx2, Indx3]);
  97.  
  98. t = (k-1)*dt;
  99.  
  100. %% Plots
  101.  
  102. for i = 1:n_i
  103. y(i) = dy*(i-1) ;
  104. end
  105.  
  106. for j = 1:n_j
  107. x(j) = dx*(j-1) ;
  108. end
  109.  
  110. set(gcf, 'units', 'normalized');
  111. set(gcf, 'Position', [0, 0.1, 1, 0.9]);
  112.  
  113.  
  114. subplot(2,2,4)
  115. pcolor(x,y,T(1:n_i,1:n_j,k))
  116. title('2D Temperature Profile')
  117. xlabel('Width (in)')
  118. ylabel('Height (in)')
  119. zlabel('Temperature (F)')
  120. set(gca,'XMinorTick','on')
  121. set(gca,'YMinorTick','on')
  122. shading interp
  123.  
  124. subplot(2,2,1)
  125. surf(x,y,T(1:n_i,1:n_j,k));
  126. title('3D Temperature Profile')
  127. xlabel('Width (in)')
  128. ylabel('Height (in)')
  129. zlabel('Temperature (F)')
  130. set(gca,'XMinorTick','on')
  131. set(gca,'YMinorTick','on')
  132. set(gca,'ZMinorTick','on')
  133. colorbar
  134. shading interp
  135.  
  136. subplot(2,2,3)
  137. [c,T] = contour(x,y,T(1:n_i,1:n_j,k));
  138. title('Temperature Contour')
  139. xlabel('Width (in)')
  140. ylabel('Height (in)')
  141. set(gca,'XMinorTick','on')
  142. set(gca,'YMinorTick','on')
  143. clabel(c,T);
  144.  
  145. subplot(2,2,2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement