Download presentation
Presentation is loading. Please wait.
Published byFerdinand Barker Modified over 9 years ago
1
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011 by Douglas Wilhelm Harder. All rights reserved. Advanced Calculus 2 for Electrical Engineering Advanced Calculus 2 for Nanotechnology Engineering Heat-conduction/Diffusion Equation
2
2 Outline This topic discusses numerical solutions to the heat-conduction/ diffusion equation: –Discuss the physical problem and properties –Examine the equation –Approximate solutions using a finite-difference equation Consider numerical stability Examples
3
Heat-conduction/Diffusion Equation 3 Outcomes Based Learning Objectives By the end of this laboratory, you will: –Understand the heat-conduction/diffusion equation –Understand how to approximate partial differential equations using finite-difference equations –Set up solutions in one spatial dimension –Understand the implementation of insulated boundaries
4
Heat-conduction/Diffusion Equation 4 Motivating Example Suppose you have a metal bar in contact with a body at 100 °C –If the bar is insulated, over time, the entire length of the bar will be at 100 °C 100 °C 0 °C
5
Heat-conduction/Diffusion Equation 5 Motivating Example At time t = 0, one end of the bar is brought in contact with a heat sink at 0 °C 100 °C 0 °C
6
Heat-conduction/Diffusion Equation 6 Motivating Example At the end closest to the heat sink, the bar will cool rapidly; however, the cooling is not uniform 100 °C 0 °C
7
Heat-conduction/Diffusion Equation 7 Motivating Example Over time, however, the temperature will drop linearly from 100 °C to 0 °C across the bar 100 °C 0 °C
8
Heat-conduction/Diffusion Equation 8 The Heat-conduction/Diffusion Equation The equation that describes the change in temperature over time is given by the partial differential equation where u(x, t) is a real-valued function of space and time and > 0 is the thermal diffusivity coefficient heat conduction diffusivity coefficient diffusion
9
Heat-conduction/Diffusion Equation 9 The Laplacian Equation The heat-conduction/diffusion equation is a time-independent version of Laplace’s equation where u(x) is a real-valued function of space
10
Heat-conduction/Diffusion Equation 10 The Laplacian Operator The Laplacian operator depends on the dimensions of space argument –In one dimension, and therefore –In two dimensions, and therefore –In three dimensions, and therefore
11
Heat-conduction/Diffusion Equation 11 The Laplacian Equation In Laboratory 1, we saw that the only solution to Laplace’s equation in one dimension with boundary values is a straight line The solution of is
12
Heat-conduction/Diffusion Equation 12 The Laplacian Operator Notice if that u(x, t) already satisfies Laplace’s equation, then or That is, if a solution already satisfies Laplace’s equation, it will not vary over time –In one dimension, if the bar is already linearly varying from 0 to 100, placing a heat source and sink at each end will not change the temperature
13
Heat-conduction/Diffusion Equation 13 Applications Applications of the heat-conduction/diffusion equation include: –Heat equation –Fick’s laws of diffusion –Thermal diffusivity in polymers Steven Byrnes Oleg Alexandrov
14
Heat-conduction/Diffusion Equation 14 Rate of Change Proportional to Concavity In one dimension, what does this equation mean? –Recall we assumed that > 0 –If the function u is concave up at (x, t), the rate of change of u over time will be positive That is, it will become less concave up –If the function u is concave down at (x, t), the rate of change of u over time will be negative That is, it will become less concave up
15
Heat-conduction/Diffusion Equation 15 Rate of Change Proportional to Concavity We can see this visually: –If the function u is concave up at (x, t), the rate of change of u over time will be positive
16
Heat-conduction/Diffusion Equation 16 Rate of Change Proportional to Concavity We can see this visually: –If the function u is concave down at (x, t), the rate of change of u over time will be negative
17
Heat-conduction/Diffusion Equation 17 Rate of Change Proportional to Concavity We can see this visually: –Of course, a function may be concave up and down in different regions Ultimately, the concavity tends to disappear—that is, as time goes to infinity, u(x, t) becomes a straight line…
18
Heat-conduction/Diffusion Equation 18 Examples Consider heat conduction problem: –A bar initially at 5 °C with one end touching a heat sink also at 5 °C –At time t = 0, the other end is placed in contact with a heat source at 80 °C
19
Heat-conduction/Diffusion Equation 19 Examples As time passes, the bar warms up
20
Heat-conduction/Diffusion Equation 20 Examples A plot of the temperature over time across the bar is given by this solution: –The end placed in contact with the 80 °C heats up faster than points closer to the heat sink –As the concavity becomes smaller, the rate of change also gets smaller
21
Heat-conduction/Diffusion Equation 21 Examples A plot of the temperature over time across the bar is given by this solution: –The end placed in contact with the 80 °C heats up faster than points closer to the heat sink –As the concavity becomes smaller, the rate of change also gets smaller
22
Heat-conduction/Diffusion Equation 22 Examples Consider another example: –A bar initially at 100 °C is placed at time t = 0 in contact with a heat source of 80 °C at one end and a heat sink at 5 °C
23
Heat-conduction/Diffusion Equation 23 Examples The ultimate temperature will be no different: –A uniform change from 80 °C down to 5 °C
24
Heat-conduction/Diffusion Equation 24 Example A plot of the temperature over time across the bar is given by this solution: –Both ends drop from 100 °C however, the centre cools slower than does the bar at either end point
25
Heat-conduction/Diffusion Equation 25 Example A plot of the temperature over time across the bar is given by this solution: –Both ends drop from 100 °C however, the centre cools slower than does the bar at either end point
26
Heat-conduction/Diffusion Equation 26 Rate of Change Proportional to Concavity Ultimately, the concavity tends to disappear—that is, as time goes to infinity, u(x, t) becomes a straight line… Important note: –This statement is only true in one spacial dimension –In higher spacial dimensions, u(x, t) will approach a solution to Laplace’s equation in the given region
27
Heat-conduction/Diffusion Equation 27 Approximating the Derivative Questions: –How do we approximate partial derivatives? –What are the required conditions?
28
Heat-conduction/Diffusion Equation 28 Approximating Partial Derivatives Recall our approximations of the derivatives: In this case, however, we are dealing with partial derivatives
29
Heat-conduction/Diffusion Equation 29 Approximating Partial Derivatives If you recall the definition of the partial derivative, we focus on one variable and leave the other variables constant To ensure clarity: – h is used to indicate small steps in space – t is used to indicate a small step in time
30
Heat-conduction/Diffusion Equation 30 Approximating Partial Derivatives The obvious extension is to define
31
Heat-conduction/Diffusion Equation 31 Approximating Partial Derivatives If we substitute the second into the heat-conduction/diffusion equation, we or
32
Heat-conduction/Diffusion Equation 32 Similarity with IVPs If this looks familiar to you, it should: Recall Euler’s method: if y (1) (t) = f (t, y(t)) and y(t 1 ) = y 1, it follows that The slope at (t 1, y 1 )
33
Heat-conduction/Diffusion Equation 33 Approximating the Second Partial Derivative The next step is to approximate the concavity We will use our 2 nd -order formula: to get
34
Heat-conduction/Diffusion Equation 34 Approximating the Second Partial Derivative There is only one small interesting issue: –What happens if the coefficient is very large? –It should be obvious; however, we will be approximating these at discrete points:
35
Heat-conduction/Diffusion Equation 35 Approximating the Second Partial Derivative There is only one small interesting issue: –Consider the total sum: –If, the contribution from the boundary conditions will always increase; thus, for stability, we require
36
Heat-conduction/Diffusion Equation 36 Initial and Boundary Conditions For a 1 st -order ODE, we require a single initial condition
37
Heat-conduction/Diffusion Equation 37 Initial and Boundary Conditions For a 2 nd -order ODE, we require either two initial conditions or a boundary condition: Time variables are usually associated with initial conditions Space variables are usually associated with boundary conditions
38
Heat-conduction/Diffusion Equation 38 Initial and Boundary Conditions For the heat-conduction/diffusion equation, we have: –A first-order partial derivative with respect to time –A second-order partial derivative with respect to space
39
Heat-conduction/Diffusion Equation 39 Initial and Boundary Conditions For the heat-conduction/diffusion equation, we require: –For each space coordinate, we require an initial condition for the time –For each time coordinate, we require a boundary conditions for the space
40
Heat-conduction/Diffusion Equation 40 Initial and Boundary Conditions In this case, we will require an initial value for each space coordinate –Keeping in the spirit of one dimension: If we were monitoring the progress of the temperature of a bar, we would know the initial temperature at each point of the bar at time t = t 1 If we were monitoring the diffusion of a gas, we would have to know the initial concentration of the gas
41
Heat-conduction/Diffusion Equation 41 Initial and Boundary Conditions Is a one-dimensional system restricted to bars and thin tubes? –Insulated wires, impermeable tubes, etc. No, many systems where two spacial dimensions are significant larger than one may be approximated by a one-dimensional system away the boundaries –Consider the effect of a thin insulator between two materials that have approximately uniform temperature –Consider the diffusion of particles across a membrane separating liquids with different concentrations In all such cases, it may be able to approximate the system as a one-dimensional system
42
Heat-conduction/Diffusion Equation 42 Approximating the Solution Just as we did with BVPs, we will divide the spacial interval [a, b] into n x points or n x – 1 sub-intervals
43
Heat-conduction/Diffusion Equation 43 Approximating the Solution Just as we did with BVPs, we will divide the spacial interval [a, b] into n x points or n x – 1 sub-intervals –The initial state at time t = t 1 would be defined by a function u init (x) where u init :[a, b] → R
44
Heat-conduction/Diffusion Equation 44 Approximating the Solution As with Euler’s method, we will attempt to approximate the solution u(x, t) at discrete times in the future –Given the state at time t = t 1, approximate the solution at time t = t 2
45
Heat-conduction/Diffusion Equation 45 Approximating the Solution Never-the-less, we must still determine the 2 nd -order component –This requires two boundary values at a and b
46
Heat-conduction/Diffusion Equation 46 Approximating the Solution Indeed, at each subsequent point, we will require the boundary values –Over time, the boundary values could change
47
Heat-conduction/Diffusion Equation 47 Approximating the Solution Therefore, we will need two functions a bndry (t) and b bndry (t) –At each step, we would evaluate and determine two the boundary conditions
48
Heat-conduction/Diffusion Equation 48 Approximating the Solution Therefore, we will need two functions a bndry (t) and b bndry (t) –We would continue from our initial time t initial and continue to a final time t final
49
Heat-conduction/Diffusion Equation 49 Approximating the Solution Like the spatial dimension, we would break the time interval into n t discrete points where
50
Heat-conduction/Diffusion Equation 50 Approximating the Solution Therefore, we will need two functions a bndry (t) and b bndry (t) –We would continue from our initial time t initial and continue to a final time t final
51
Heat-conduction/Diffusion Equation 51 Approximating the Solution Now that we have functions that define both the initial conditions and the boundary conditions, we must solve how the heat conducts or the material diffuses
52
Heat-conduction/Diffusion Equation 52 Approximating the Solution Given the state at time t = t 1, we approximate the state at time t = t 2
53
Heat-conduction/Diffusion Equation 53 Approximating the Solution Given the state at time t = t 2, we approximate the state at time t = t 3
54
Heat-conduction/Diffusion Equation 54 Approximating the Solution Given the state at time t = t 3, we approximate the state at time t = t 4
55
Heat-conduction/Diffusion Equation 55 Approximating the Solution We continue this process until we have approximated the solution at each of the desired times
56
Heat-conduction/Diffusion Equation 56 Approximating the Solution This last image suggests strongly that our solution will be a matrix Given the heat-conduction/diffusion equation we will approximate the solution u(x, t) where a < x < b and t initial < t < t final by calculating an n x × n t matrix U where U(k, ℓ) approximate the solution at time (x k, t ℓ ) with x k = a + (k – 1)h t ℓ = t initial + (ℓ – 1) t
57
Heat-conduction/Diffusion Equation 57 Step 1: Error Checking Once the parameters are validated, the next step is to ensure If this condition is not met, we should exit and provide a useful error message to the user: –For example, The ratio kappa*dt/h^2 = ??? > 0.5, consider using nt = ??? where The first ??? is replaced by the calculated ratio, and The second ??? is found by calculating the smallest integer for n t that would be acceptable to bring this ratio under 0.5 –You may wish to read up on the floor and ceil commands
58
Heat-conduction/Diffusion Equation 58 Step 2: Initialization We will begin by creating the n x × n t matrix –The zeros command is as good as any
59
Heat-conduction/Diffusion Equation 59 Step 2: Initialization Next, we assign the initial values nxnx
60
Heat-conduction/Diffusion Equation 60 Step 2: Initialization Next, calculate the boundary values nxnx ntnt
61
Heat-conduction/Diffusion Equation 61 Step 3: Solving In order to calculate both the initial and boundary values, we will require two vectors: –A column vector of x values, and –A row vector of t values Both of these can be constructed using linspace –Both of these will be returned to the user
62
Heat-conduction/Diffusion Equation 62 Step 3: Solving We still have to calculate the interior values nxnx ntnt
63
Heat-conduction/Diffusion Equation 63 Step 3: Solving For this, we go back to our finite difference equation:
64
Heat-conduction/Diffusion Equation 64 Step 3: Solving For this, we go back to our finite difference equation: Replace the x with x k and t with t ℓ :
65
Heat-conduction/Diffusion Equation 65 Step 3: Solving For this, we go back to our finite difference equation: Replace the x with x k and t with t ℓ : Recall that x k + h = x k + 1 and t ℓ + t = t ℓ + 1
66
Heat-conduction/Diffusion Equation 66 Step 3: Solving Finally, given the equation recall that we are approximating the solution at u(x k, t ℓ ) by u k,ℓ :
67
Heat-conduction/Diffusion Equation 67 Step 3: Solving Using this formula we can first calculate u 2,2 through u n – 1,2 x
68
Heat-conduction/Diffusion Equation 68 Step 3: Solving Using this formula and then u 2,3 through u n – 1,3 and so on x
69
Heat-conduction/Diffusion Equation 69 Useful Matlab Commands Recall that you can both access and assign to sub-matrices of a given matrix: >> U = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15; 16 17 18 19 20] U = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 >> U(:,1) = [0 0 0 0]'; >> U(1,2:end) = [42 42 42 42]; >> U(2:end - 1,3) = [91 91]' U = 0 42 42 42 42 0 7 91 9 10 0 12 91 14 15 0 17 18 19 20
70
Heat-conduction/Diffusion Equation 70 Useful Matlab Commands Matlab actually gives you a lot of power when it comes to assigning entries by row or by column: >> U = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15; 16 17 18 19 20] U = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 >> U([1, 3],2:end) = [42 42 42 42; 91 91 91 91] U = 1 42 42 42 42 6 7 8 9 10 11 91 91 91 91 16 17 18 19 20
71
Heat-conduction/Diffusion Equation 71 Useful Matlab Commands The throw command in Matlab allows the user to format its message in a manner similar to the sprintf command in Matlab (and C) function [] = error_example( a, b ) throw( MException( 'MATLAB:invalid_argument',... 'the argument %f (%d) and %f (%d) were passed', a, a, b, b ) ); end When run, the output is: >> error_example( 3, pi ) ??? Error using ==> ff at 2 the argument 3.000000 (3 ) and 3.141593 (3.141593e+000) were passed
72
Heat-conduction/Diffusion Equation 72 Useful Matlab Commands You can, of course, modify this: function [] = error_example( a, b ) throw( MException( 'MATLAB:invalid_argument',... 'the ratio of %d and %d is %f', a, b, a/b ) ); end When run, the output is: >> error_example( 3, 5 ) ??? Error using ==> error_example at 2 the ratio of 3 and 5 is 0.600000 See >> help sprintf
73
Heat-conduction/Diffusion Equation 73 Useful Matlab Commands A very useful command is the diff command: >> v = [1 3 6 7 5 4 2 0] v = 1 3 6 7 5 4 2 0 >> diff( v ) ans = 2 3 1 -2 -1 -2 -2 >> v(2:end) - v(1:end - 1) ans = 2 3 1 -2 -1 -2 -2 >> diff( v, 2 ) ans = 1 -2 -3 1 -1 0 >> v(3:end) - 2*v(2:end - 1) + v(1:end - 2) ans = 1 -2 -3 1 -1 0
74
Heat-conduction/Diffusion Equation 74 Useful Matlab Commands Why use diff instead of a for loop? –We could simply use two nested for loops: >> for it = 2:nt for ix = 2:(nx - 1) % calculate U(ix, it) end however, it would be better to use: >> for it = 2:nt % calculate U(2:nx - 1, it) using diff end In Matlab –Most commands call compiled C code –For loops and while loops are interpreted
75
Heat-conduction/Diffusion Equation 75 Useful Matlab Commands How slow is interpreted code? –This function implements matrix-matrix-multiplication function [ M12 ] = multiplication( M1, M2 ) [m, n1] = size( M1 ); [n2, p] = size( M2 ); if n1 ~= n; error( 'dimensions must agree' ); end; M12 = zeros( m, p ); for i=1:m for j=1:n1 for k = 1:p M12( i, k ) = M12( i, k ) + M1(i,j)*M2(j,k); end
76
Heat-conduction/Diffusion Equation 76 Useful Matlab Commands Now, consider: >> M = rand( 1300, 1000 ); >> N = rand( 1000, 1007 ); >> tic; M*N; toc Elapsed time is 0.196247 seconds. >> tic; multiplication( M, N ); toc Elapsed time is 35.530549 seconds. >> 35.530549/0.196247 ans = 181.0502 What’s two orders of magnitude between you and your employer?
77
Heat-conduction/Diffusion Equation 77 Useful Matlab Commands Suppose we want to implement a function which is only turned on for, say, one period In Matlab, you could use the following: function y = f( x ) y = -cos(x).* ((x >= 0.5*pi) & (x <= 2.5*pi )); end
78
Heat-conduction/Diffusion Equation 78 Useful Matlab Commands The output of >> x = linspace( 0, 10, 101 ); >> plot( x, f( x ), 'ro' ) In order to understand the output, consider >> >> x = linspace( 0, 10, 11 );| >> x >= 0.5*pi ans = 0 0 1 1 1 1 1 1 1 1 1 >> x <= 2.5*pi ans = 1 1 1 1 1 1 1 1 0 0 0 >> (x >= 0.5*pi) & (x <= 2.5*pi) ans = 0 0 1 1 1 1 1 1 0 0 0
79
Heat-conduction/Diffusion Equation 79 Example 1 As a first example: >> [x1, t1, U1] = diffusion1d( 0.1, [0,1], 6, [1, 3], 12, @u_init1, @u_bndry1 ); >> size(x1) ans = 6 1 >> size(t1) ans = 1 12 >> size(U1) ans = 6 12 >> mesh( t1, x1, U1 ) x t b = 1 a = 0 t initial = 1 t final = 3 u init (x) = 0.9 b bndry (t) = 4.1 a bndry (t) = 1.7 n t = 12 n x = 6 = 0.1
80
Heat-conduction/Diffusion Equation 80 Example 1 As a first example: >> [x1, t1, U1] = diffusion1d( 0.1, [0,1], 6, [1, 3], 12, @u_init1, @u_bndry1 ); The two functions are: function u = u_init1( x ) u = x*0 + 0.9; end fucntion u_bndry1( t ) u = [t*0 + 1.7; t*0 + 4.1]; end x t b = 1 a = 0 t initial = 1 t final = 3 u init (x) = 0.9 b bndry (t) = 4.1 a bndry (t) = 1.7 n t = 12 n x = 6 = 0.1
81
Heat-conduction/Diffusion Equation 81 Example 1 Because the large size of both h and t, there is still some numeric fluctuations x t
82
Heat-conduction/Diffusion Equation 82 Example 2 Decreasing h and t produces a better result >> [x2, t2, U2] = diffusion1d( 0.1, [0,1], 100, [1, 3], 4000, @u_init1, @u_bndry1 ); >> size(x2) ans = 100 1 >> size(t2) ans = 1 4000 >> size(U2) ans = 100 4000 >> mesh( t2, x2, U2 ) x t h = 0.01 t = 0.0005
83
Heat-conduction/Diffusion Equation 83 Example 3 If we exceed 0.5, the approximation begins to fail >> [x2, t2, U2] = diffusion1d( 0.1, [0,1], 100, [1, 3], 3916, @u_init1, @u_bndry1 ); >> mesh( t2, x2, U2 ) x t Stable when n t = 4000
84
Heat-conduction/Diffusion Equation 84 Example 4 As the ratio exceeds 0.5, it quickly breaks down: >> [x2, t2, U2] = diffusion1d( 0.1, [0,1], 100, [1, 3], 3900, @u_init1, @u_bndry1 ); >> mesh( t2, x2, U2 ) x t Stable when n t = 4000 2 × 10 14
85
Heat-conduction/Diffusion Equation 85 Summary We have looked at the heat-conduction/diffusion equation –Considered the physical problem –Considered the effects in one dimension –Found a divided-difference equation approximating the PDE Saw that Examples –In the laboratory, you will consider insulated boundaries
86
Heat-conduction/Diffusion Equation 86 References [1]Glyn James, Modern Engineering Mathematics, 4 th Ed., Prentice Hall, 2007, p.778. [2]Glyn James, Advanced Modern Engineering Mathematics, 4 th Ed., Prentice Hall, 2011, p.164.
87
Heat-conduction/Diffusion Equation 87 Usage Notes These slides are made publicly available on the web for anyone to use If you choose to use them, or a part thereof, for a course at another institution, I ask only three things: –that you inform me that you are using the slides, –that you acknowledge my work, and –that you alert me of any mistakes which I made or changes which you make, and allow me the option of incorporating such changes (with an acknowledgment) in my set of slides Sincerely, Douglas Wilhelm Harder, MMath dwharder@alumni.uwaterloo.ca
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.