Vous êtes sur la page 1sur 10

Finite Difference Methods in Heat Transfer

V.Vuorinen
Aalto University School of Engineering
Heat and Mass Transfer Course, Autumn 2016

November 2nd 2016, Otaniemi


ville.vuorinen@aalto.fi
Overview
• Numerical methods have been mathematically developed in order to solve analytical,
mathematical equations using numerical approximation.
• Examples: Taylor series, Newton's method, Solution of Ax = b, Iteration schemes
• The problem: analytical solution by pen and paper of various equation types can be very
difficult and has of severe limitations.
• It is vary convenient to understand the very basics of numerical solution of heat equations
in 1d and 2d.
• Numerical software like Matlab and Python could be used for short implementation of
numerical solvers which give e.g. temperature as a function of space and time.
• In particular, for complex geometries and combined heat/fluid flow, various CFD
(computational fluid dynamics) software like OpenFOAM, ELMER, Fluent etc can be used.
• Using the Matlab programs (supplementary course material) you learn that basics of heat
transfer can be simulated with very short code of only a couple of lines.
• Learn basic ideas behind numerical solution on the course → extend your opportunities
for future work life!
Discretization by Finite Difference
Method 2
∂T ∂ T
=α 2
∂t ∂x
Recall Taylor series and basic discretization formulae for derivatives

Time derivative in cell i at timestep n Second space derivative in cell i


at timestep n
n n+1 n n n n n
T i −T i 2
T
∂T
( )
∂t i

Δt ( )
∂ T
2
∂x i
≈ i +1 −2T +T
Δx
i
2
i−1

n
Known from previous timestep n: T i
n+1
Unknown on the n+1 timestep: Ti
Discretization by Finite Difference
Method
Continuous version of Discrete version of
heat equation heat equation

∂T ∂ T
2
T ni +1−T ni T ni+ 1−2 T in +T in−1
=α 2 =α
∂t ∂x Δt Δ x2
αΔ t
CFL=
Δ x2
Courant-
Friedrichs- n n n
Lewy number T i +1−2 T i +T i−1
(CFL<0.5 for
stability).
T n+1
i =T n
i +Δ t α 2
Δx
Now we have an explicit update scheme for T in each discrete grid
point i. This is the explicit Euler scheme (most simple timestepping).
Schematic Representation of the
Scheme
i=1 i=2 i=3 i=N+1 i=N+2
t=t T1 T2 T3 TN+1 TN+2
n+2

t=t T1 T2 T3 TN+1 TN+2


n+1

t=t T1 T2 T3 TN+1 TN+2


n

n n n
t n=n Δ t ,n=0,1,2,... T i +1−2 T i +T i−1
T n+1
n
i =T i +Δ t α
Δ x2
Boundary Condition Types
• The problem: some numerical value needs to be assigned to the ”ghost cells”
• Otherwise: we can not calculate second derivative of T in cells i=2 and i=N+1
• Case 1: Given temperature value (Dirichlet or “fixed value”) → heat flux through boundary
• Case 2: Isolated (Neumann or “zero-gradient”) → no heat flux through boundary
• Case 3: Given heat flux → heat flux through boundary

Ghost i=2 i=3 i=N+1 Ghost


cell T2 T3 TN+1 cell
i=1 i=N+2

x=0 x=L
Case 1: n n n n
(T +T )/2=T min
1 2 (T N +1 +T )/2=T max
N+2
n n n n
Case 2: T 1=T 2 You get the ghost cell value T =T
N +1
N +2
n n
Case 3: (T 1−T 2 )/Δ x =q L n n
(T 1−T 2 )/Δ x =q R
Summary of the Numerical Solution
Scheme for 1d Heat Equation
1) Set boundary conditions to cells 1 and N+2 T ni (Known)
using T from step n.

n+1 n T ni +1−2 T ni +T ni−1


T =T +Δ t α
2) Update new temperature at timestep n+1 in the i i
Δ x2
internal cells 2...N+1
T n+1
i

3) Update time according to t = t + dt t n+1 =t n +Δ t

4) Go back to 1)
This Scheme is Extremely Short to
Program in Matlab
Program: /Example1d/HeatDiffusion.m
Execution: >> HeatDiffusion
What it does: Solves 1d heat equation in equispaced grid, fixed Tleft and Tright.
Main for-loop:
for(t=1:K)
    % set boundary conditions 
    T(1)  = 2*Tleft ­ T(2); T(N+2) = 2*Tright ­ T(N+1);                     
      
    % update temperature in inner points                                    
    T(in) = T(in) + (dt*kappa/dx^2)*(T(in+1)­2*T(in)+T(in­1)); 
end

Note: I use constantly the “trick” which makes Matlab-programs often very fast.
% define a table which refers to the 'inner points' Example for N+1 = 5
in = 2:(N+1);
 
The Following Folders and Files for
Matlab Programs Provided (Week 1)
/Example0d/ Execute by
cool0d.m >> cool0d
/Examples1d/ Execute by e.g.
HeatDiffusion.m >> HeatDiffusion
ConvectionDiffusion.m
/HowToPlot/ Demos on plotting Figures.
DrawingSurface.m   Execute by e.g.:
PlottingFigure.m   >> DrawingSurface
SurfaceAnimation.m
/Examples2d/
CaseDefinition.m  computedT.m  GradX.m  2d heat transfer code.
GradY.m HeatDiffusion2d.m     project.m   Execute by:
solveTemperature.m >> HeatDiffusion2d
circle.m DivDiv.m GradXskew.m  
GradYskew.m  Laplacian.m  setTBCs.m  
visualizeResults.m
Thank you for your attention!

Vous aimerez peut-être aussi