16
Heat Transfer Computer Project Chris McLaughlin Section 1 10-28-12

Computer Project Showcase

Embed Size (px)

Citation preview

Page 1: Computer Project Showcase

Heat Transfer

Computer Project

Chris McLaughlin

Section 1

10-28-12

Page 2: Computer Project Showcase

After analyzing the results of my code, I have a few reasons to believe that my simulation is valid. The first reason I have to believe that my code is valid is the fact that the 3D plot of the temperature distribution across the surface looks like how it should be expected to look. The left side increases in temperature linearly as the Y-coordinate increases, and the bottom edge stay at a roughly constant temperature, close to 40 degrees Celsius, along the X-coordinate. The top right diagonal edge has a very steep temperature drop, which is expected since it is exposed to air and convects heat quite rapidly since the heat generation portion of the geometry is in that region. The insulated edges neither gain nor lose heat rapidly; they flow smoothly from one temperature starting from either the top left or bottom right edge, to the diagonal convection side. Most importantly, near the upper right portion of the geometry, there is a hump indicating much higher temperature values, which is expected due to the heat generation in that region.

The next reason I believe my simulation to be valid is that the heat flow across the edges of the geometry match the heat generated from within the geometry. Most of this heat flow occurs at the top right diagonal edge, which is expected since the heat generation portion is exposed to relatively colder air. The bottom edge has the second highest amount of heat flow since it is exposed to the second lowest temperature. The left side of the geometry has a net heat flow INTO the system. This is expected because although at first it loses heat through the bottom portion of the side, once the temperature gets high enough, the heat starts flowing the other direction, all in all this sums to a net flow INWARD of about 100W. The variable “Edgesumtotal” shows the total heat flow into the system.

The third reason I believe my simulation to be valid, is that whether the mesh size is 10 or any multiple of 10 above that, the numbers for the heat flows and temperature distribution do not change by more than 0.5%.

Finally, the last reason my simulation appears to be valid is the fact that the heat flows, when summed across each individual node, are zero. The matrix “Nodesum”, shows these values

Table of heat transfer values across boundaries

Side Heat transfer Into the system (W)Left 98.52Bottom -754.51Top right diagonal -4444.01

SUM -5100Figure 1 – Table of edge heat flow values

Page 3: Computer Project Showcase

3D Temperature Surface Plots

Figure 2 – Isometric view (Mesh size 100)

Figure 3 – Top view (Mesh size 100)

Page 4: Computer Project Showcase

Figure 4 – Temperature profile across edges (Mesh size of 150)CODE

% FEM Heat transfer Code% Author: Chris McLaughlin%% I DO NOT ADVISE USING A MESH SIZE LARGER THAN 160# ( Recommended values: 10 - 150 )%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clf; clear;%% InputsT1=40; % Temperature along the bottom edgeTinf=10; % T infinity at the convection edgeqgen=30000; % Amount of heat Generationh=500; % Convection Coefficient at the convection edgeN=60; % Mesh Size%% Presetup setupi=N^2;dx=1/N;k=25;qgent=5100; %% Q gen per unit depth, constant%% Set up A and b matricesA=sparse(zeros(i)); %% Coefficient Matrixb=zeros(N);b=b(:); %% Known value matrixfor i=1:(N^2) T2=25*(((floor(i/N))/N)+(1/(2*N)))+40; %% Temperature along left edge %% General A Matrix setup for Interior Nodes A(i,i)=-4;

Page 5: Computer Project Showcase

if mod(i,N)~=0 %% Setup i's Right Node in A A(i,i+1)=1; end if mod(i,N)~=1 %% Setup i's Left Node in A A(i,i-1)=1; end if (i<((N^2)-(N-1))) %% Setup i's Above Node in A A(i,i+N)=1; end if (i>(N)) %% Setup i's Below Node in A A(i,i-N)=1; end %% Special case Modifications %% if (i<=N) %% Far Bottom Nodes b(i)=b(i)-(2*(T1)); A(i,i)=A(i,i)-1; end if mod(i,N)==1 %% Far Left Nodes b(i)=b(i)-(2*(T2)); A(i,i)=A(i,i)-1; end if (i>=((N^2)-(N-1))) || mod(i,N)==0 %% Insulated Nodes A(i,i)=A(i,i)+1; end if i>(.6*N) && ((ceil(i/N)*N)-(ceil(i/N)-(.6*N)-1))==i %% Top Right Convection Nodes b(i)=b(i)-(((h*(sqrt(2)*dx)*Tinf)/k)+((.5*qgen*(dx^2))/k)); A(i,(((ceil(i/N)*N)-((ceil(i/N)-(.6*N)-1))+1)):(ceil(i/N)*N))=0; A(i,i)=-(2+((h*sqrt(2)*dx)/k)); if i<((N^2)-N) A(i,i+N)=0; end end if i>(.5*(N^2)) && (mod(i,N)>(.5*N) || mod(i,N)==0) && ((ceil(i/N)*N)-(ceil(i/N)-(.6*N)-1))~=i %% qgen terms b(i)=b(i)-((qgen*(dx^2))/k); end if (i>(.6*(N^2))) && (((ceil(i/N)*N)-(ceil(i/N)-(.6*N)-1))<i) %% Set all top right Tinf Nodes =0 A(i,:)=0; b(i)=0; endend%% Plot setupx=A\b; %% RAW NODE TEMPERATURE MATRIXz=reshape(x,N,N);v=z';l=flipud(v); %% Matrix of node temperatures sorted correct geometry positionl(l<=.000001)=NaN;%% HT sum across each nodec=(x'*full(A)); %% Multiplies A matrix by node temperaturesNodesum=c'-b; %% Subtracts b from node energy, this should equate to zero%% HT sum across each edgeEDGEsumconv=0;EDGEsumleft=0;EDGEsumbottom=0;A=full(A);pc=zeros(N);pb=zeros(N);pr=zeros(N);pt=zeros(N);pl=zeros(N);for i=1:N^2

Page 6: Computer Project Showcase

if i>(.6*N) && ((ceil(i/N)*N)-(ceil(i/N)-(.6*N)-1))==i %% Top convection diagional edge EDGEsumconv=EDGEsumconv+((10-x(i))*h*(sqrt(2)*dx)); pc(i,1)=x(i); pc(pc == 0) = []; pcl=length(pc); end if mod(i,N)==1 %% Left edge T2=25*(((floor(i/N))/N)+(1/(2*N)))+40; EDGEsumleft=EDGEsumleft+(2*(T2-x(i))*k); pl(i,1)=x(i); pl(pl == 0) = []; pll=length(pl); end if (i<=N) %% Bottom edge EDGEsumbottom=EDGEsumbottom+(2*(T1-x(i))*k); pb(i,1)=x(i); pb(pb == 0) = []; pbl=length(pb); end if (i>=((N^2)-(N-1))) %% Top insulated edge pt(i,1)=x(i); pt(pt == 0) = []; ptl=length(pt); end if mod(i,N)==0 %% Right insulated edge pr(i,1)=x(i); pr(pr == 0) = []; prl=length(pr); endendEdgesumtotal=EDGEsumconv+EDGEsumleft+EDGEsumbottom;%% Edge T-Profile Plotsfigure(1);subplot(2,3,4);plot(1:pcl,pc(:));xlabel('Node Distance');ylabel('Temperature');title('Temperature Profile - Top right convection diagonal');grid onsubplot(2,3,2);plot(1:pll,pl(:));xlabel('Node Distance');ylabel('Temperature');title('Temperature Profile - Left Edge');grid on;subplot(2,3,1);plot(1:pbl,pb(:))xlabel('Node Distance');ylabel('Temperature');title('Temperature Profile - Bottom edge');grid on;subplot(2,3,3);plot(1:ptl,pt(:));xlabel('Node Distance');ylabel('Temperature');title('Temperature Profile - Top insulated edge');grid on;subplot(2,3,5);plot(1:prl,pr(:))xlabel('Node Distance');ylabel('Temperature');title('Temperature Profile - Right insulated edge');grid on;%% 3D Temperature plotfigure(2);plot=surf(flipud(l),'FaceColor','interp');colorbar;axis image;

Page 7: Computer Project Showcase

THE FOLLOWING PAGES OUTLINE THE PROJECT DESCRIPTION AND GUIDELINES

ME 450 Computer ProjectDue Date: Sunday, 10/28/12, Midnight

OverviewYou are to perform a 2D heat transfer simulation of the thermal system shown in the schematic below. All items, including justification, plots, and code must be put WITHIN A SINGLE WORD DOCUMENT, USING THE FILENAME “lastname.firstname.doc”. Your document must be submitted into Safeassign in bblearn (in the computer project folder) by the date/time listed above.

You will have the option of doing either of 2 different geometries for your simulation. The first geometry is easier, but will have a maximum possible score of 85%. The other geometry is more complex and is the only way to get a full 100% on the project. For the more difficult geometry, your code must be able to handle any mesh size that is a multiple of 10 (e.g. 10x10, 20x20, etc). For the easier geometry, your code must be able to handle any mesh size that is an interval of 20, beginning with 10x11 (e.g. 10x11, 30x31, 50x51, etc.). Code that does not allow a variable mesh size will result in a zero grade for the project.

This project may or may not be painful, but I assign it because this is the direction that engineering (not just heat transfer) is going. Additionally, many students have expressed appreciation for the project, although for most of them that was after the fact. I include a couple quotes below from previous students who emailed me after graduating:

“My mentor, who is the Lead Engineer for the testing group at Orbital, was SUPER impressed when I told him about the MATLAB project I did for heat transfer. My tears and extra gray hairs were worth it. Tell that to the new seniors when they whine about the project next year. “

“side note, i learned A LOT. i knew very little about matlab prior to this. thank you”

“I gotta say though, I think the main thing that pushed me into the realm of being qualified for this job is my capability in Matlab. Your HT project you had all of us do was paramount in kicking me into gear.”

DeliverablesYour submitted document must contain all of the following:

A one paragraph justification of how you know that your simulation is valid. Your justification must address EACH of the following tests:

o Heat flows on each individual node should add up to 0 (note: if done correctly, your sums should be something like 10-12)

Page 8: Computer Project Showcase

o Net heat flow summed over the boundaries of your simulation should match the heat generated in the system (again, if correct these sums should match within 10 -12)

o Your temperature profile should match what is physically expected given the prescribed boundary conditions (describe what the boundary conditions should do to the temperature profile, and verify that this is reflected in your temperature map)

o Doubling your mesh density should not affect your solution (i.e. your calculated heat flows) by more than 0.02%

A table listing the quantity of heat transfer per unit depth along each of the 3 non-insulated edges, using a positive value for heat transfer into the solid and negative for heat transfer out of the solid

A 3D projection of the temperature distribution, clearly showing the full temperature distribution

Plots of the temperature profiles along each of the edges. Put these together into a single figure (not a single plot) using the subplot command. Begin with the bottom edge, then work your way clockwise around the geometry.

The code you wrote to complete the project

DeadlinesWhile there are no deliverables associated with the deadlines below other than the final submission, I will not provide assistance to you on the listed subtasks after their associated deadlines, unless it is during my normal office hours AND there is no one else waiting to ask questions. Also make use of the Finite Difference Overview and MATLAB primer, which are posted in Blackboard in the Resources folder.

Deadlines o Deadline 1: 10/5/12. By this time, you should have done the following:

Make sure you understand how FD simulations work, by a) reviewing your lecture notes; b) reading Chapter 4 of your textbook; and c) reviewing the Finite Difference Overview posted in vista

Chosen a numbering scheme for your nodes Identified each of the ‘types’ of nodes present and determined the appropriate

energy balance relation for each of them Determined how to identify the node ‘type’ for an arbitrary node number ‘i’

(based on your numbering scheme and the size of the mesh ‘n’) For a given arbitrary node ‘i’, have a way of identifying the node numbers of all

neighboring nodes using only ‘i’ and ‘n’.o Deadline 2: 10/12/12. By this time, you should have done the following:

Have code that can identify the node numbers for all neighboring nodes for an arbitrary node ‘i’ (this will probably involve a series of ‘if’ statements)

Page 9: Computer Project Showcase

Have code that can identify which energy balance equation should be applied for any arbitrary node ‘i’ (again, this will probably involve a series of ‘if’ statements)

o Deadline 3: 10/19/12. By this time, you should have done the following: Have code that correctly populates the coefficient matrix and ‘b’ vector by:

Iterating through every node Determining which energy balance equation should be applied for each

node Determining the appropriate columns for the coefficients of the energy

balance equation (this comes from knowing the node numbers for all neighboring nodes)

Have code that calculates the temperature distribution from the coefficient matrix and ‘b’ vector

o Deadline 4: 10/28/12. FINAL SUBMISSION. This week should be dedicated to: Creating the required plots Calculating the required heat flows Validating/verifying your simulation

PlagiarismNote that this is an INDIVIDUAL project. While you may collaborate, you may NOT share code. Two people independently writing code will NEVER end up with the same code at the end of the day. Merely changing variable names or comments is not sufficient. I have been continuously impressed at how good the plagiarism checking software is at picking out copied code, both from other students and from internet sources. Plagiarized code will result in a severely reduced score(potentially a zero) and a writeup for academic dishonesty. Moreover, presenting results that were not obtained by your code will result in a zero grade and a writeup for academic dishonesty. Please do not test this – I derive no joy from catching people in plagiarism.

GradingThe grade breakdown will be as follows:

Report: 30 ptso 20 pts: Justification of the validity of your codeo 5 pts: required plots shown in reporto 5 pts: required heat transfer values shown in table

Code: 70 pts (55 pts max if you choose the easier geometry)o 45 pts (35 for easier geometry): coefficient matrix generationo 15 pts: calculation of heat transfer on edgeso 10 pts (5 for easier geometry): temperature matrix and correct surface plot

Subtractions:

Page 10: Computer Project Showcase

o Up to -10 points for grammar and writingo -5 points for incorrect file name and file formato -5 points/day late (no more than 5 days allowed)o Up to 100% deduction for plagiarized codeo 100% deduction for reporting results not generated by your submitted codeo 100% deduction for submitting code that cannot handle a variable mesh size

Skeleton PseudocodeThe code listed below is intended to help you organize your thought process on this project. Feel free to use it or not as you see fit.

******%Choose mesh size (e.g. n=10 for 10x10, 20 for 20x20, etc.) %Calculate number of nodes (probably something related to n2)for i=1:allnodes

if i == xxxxx %use if statements (may need more than one) to determine where node ‘i’ is%e.g. left boundary, bottom right corner, etc. Should be able to determine %using only i and n

%Must be node type 1 (for example)Nodetype(i) = 1

elseif i==xxxxx %use if statements to determine where node ‘i’ is%must be node type 2 (for example)

elseif i ==xxxx %continue for all node typesend

end

for i =1:allnodesif nodetype (i) == 1

%use energy balance equation for node type 1

%put appropriate coefficients into the correct columns of row i for coefficient %matrix and b vector

elseif nodetype(I) ==2%use energy balance equation for node type 2%etc., etc.

endend

%coefficient matrix and b vector should now be populated. Solve for T values%rearrange T values into matrix to make surface plot%verify sum of qin to each node adds to 0%calculate heat flows on edges, verify that it matches generation

Page 11: Computer Project Showcase

%make edge plots

Project Geometries

Easy Geometry (Max Score is 80/100)The overall geometry is 1m x 1m. Note that on convection edges, the center of the node must be on the surface. Thus you will have half-nodes on both the left and right sides. This will result in your number of rows being different than your number of columns (e.g. 10 rows by 11 columns), which you must be aware of and keep track of. While you could write your code to be able to handle any mesh size, I set up the geometry to be easiest if you use intervals of 20, beginning with 10 rows (i.e. 10, 30, 50, etc.).

Page 12: Computer Project Showcase

Harder GeometryThis geometry is designed to work with any geometry that is a multiple of 10x10.