0% found this document useful (0 votes)
100 views17 pages

Paul Summers Final Write Up

The document describes modeling 2D heat transfer using the Crank-Nicolson method. It discusses: 1) The heat equation and properties of heat transfer systems. 2) How the Crank-Nicolson method can model the heat equation in 1D and 2D, representing the equations as matrices that can be solved. 3) Testing the model, showing it accurately conserves energy and is unconditionally stable, as the Crank-Nicolson method predicts.

Uploaded by

cartamenes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views17 pages

Paul Summers Final Write Up

The document describes modeling 2D heat transfer using the Crank-Nicolson method. It discusses: 1) The heat equation and properties of heat transfer systems. 2) How the Crank-Nicolson method can model the heat equation in 1D and 2D, representing the equations as matrices that can be solved. 3) Testing the model, showing it accurately conserves energy and is unconditionally stable, as the Crank-Nicolson method predicts.

Uploaded by

cartamenes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

2D Heat Equation Modeled by Crank-Nicolson

Method
Paul Summers
December 5, 2012

The Heat Equation

U
2U
2 =0
t
x

U
2 x = 0
t

The system I chose to study was that of a hot object in a cold medium,
and document the time progression of various cases. This system is fairly
straight forward to relate to as it a situation we frequently encounter in daily
life. Heat transfer follows a few classical rules:
-Heat flows from hot to cold (Hight T to low T)
-Heat flows at rate proportional to the spacial 2nd derivative. This rate
is
-A change in heat results in a change in T
T = mCv Q
-Total heat energy must be conserved.
Such systems in general are equilibrium seeking, non-oscillatory systems
which approach the equilibrium state (constant T) asymptotically as time
progresses.
In my system we consider a grid of 100x100 particles with m = Cv = 1 and
constant across the whole grid. While this system is rather simplistic, it
still allows us to model and solve many complex and interesting distributions
of heat features.

In addition, this model can easily be extended to other non-heat related


systems. Namely:
-Diffusion of a particle density function P
t P = D 2 P
-Schrdinger equation of a free particle
t =

i
h 2

2m

The Crank-Nicolson Method


un+1
uni
1
u 2 u
u 2 u
i
= [Fin+1 (u, x, t, , 2 ) + Fin (u, x, t, , 2 )]
t
2
x x
x x
Where:

u
t

= F (u, x, t, u
, u)
x x2

The Crank-Nicolson Method ( CNM ) can be thought of as a combination


of the forward and backward Euler methods, but it should not be mistaken
as a simple average of the two as the method is implicitly dependent on its
solution. (Much like backwards Euler, but differing from forward Euler).
This method is a good choice for solving the heat equation as it is unconditionally stable for both 1D and 2D applications. This trait makes it ideal
for any system involving a conservation law.

2.1

1D Crank-Nicolson

In one dimension, the CNM for the heat equation comes to:
(n is the time step, i is the position):
a
un+1
uni
i
n
n
n
=
[(un+1 2un+1
+ un+1
i
i1 ) + (ui+1 2ui + ui1 )]
t
2(x)2 i+1
which allowing r =

at
2(x)2

simplifies to:

n+1
n
n
n
run+1
) run+1
i+1 + (1 + 2rui
i1 = rui+1 + (1 2rui ) + rui1

2.2 2D Crank-Nicolson
which can be solved for un+1
rather simply from the equation:
i
Au
n+1 = B u
n
where A and B are tridiagonal matrices and u
n is the vector representation
of the 1D grid at time n.

2.2

2D Crank-Nicolson

In two dimensions, the CNM for the heat equation comes to:
un+1
uni
a
i
=
[(un+1 +un+1 +un+1 +un+1 4un+1
)+(uni+1,j +uni1,j +uni,j+1 +uni,j1 4uni )]
i
t
2(x)2 i+1,j i1,j i,j+1 i,j1
assuming x = y and letting =

at
(x)2

gives us:

n+1
n
n+1
n
n+1
n
n+1
n
n
(1+2)un+1
i,j (ui+1,j +ui1,j +ui,j+1 +ui,j1 ) = (12)ui,j + (ui+1,j +ui1,j +ui,j+1 +ui,j1 )
2
2
or if we allow the use of the operators x2 and y2 where:
x2 fi,j = fi+1,j 2fi,j + fi1,j

y2 f = fi,j+1 2fi,j + fi,j1

the equation can be written as


(1

2 2 n+1
x y )ui,j = (1 + x2 + y2 )uni,j
2
2
2
2

which is very nice and pretty, but not too much fun solve. So we go in search
of a different equation to solve. Let us consider:
(1

x )(1 y2 )un+1
x )(1 + y2 )uni,j
i,j = (1 +
2
2
2
2

which can be shown to be a fair approximation of the original equation if


you consider quadratic terms negligible.
(1

0
*0
*
2 2 2 
2 2 2 
2 n

x y + 
yx2 )un+1
=
(1
+

)u
i,j

2
2
2 2
2 x 2 y 
2 y 2 x i,j

2.2 2D Crank-Nicolson

The advantage of this new form is that it allow us to solve in two steps
with the help of an intermediate value u
(1

2
x )ui,j = (1 + y2 )uni,j
2
2

2 n+1
y )ui,j = (1 + x2 )ui,j
2
2
which is confirmed to be a valid method by multiplying the upper by
(1 + 2 x2 ) and the lower by (1 2 x2 ) which yields:
(1

(1

x )(1 y2 )un+1
x )(1 x2 )ui,j = (1 + x2 )(1 + y2 )uni,j
i,j = (1 +
2
2
2
2
2
2

2
x )(1 y2 )un+1
x )(1 + y2 )uni,j
i,j = (1 +
2
2
2
2
which is exactly what we were going for. This 2 step process allows us to
handle 1 dimension at a time which allows the use of matrix notation just like
before, almost. By naively solving the 1D case twice, we would be tempted
to solve for

(1 x2 )ui,j = (1 + x2 )uni,j
2
2
2 n+1

(1 y )ui,j = (1 + y2 )ui,j
2
2
which looks close, but is not correct. The issue lies in that previously, we
were always taking derivatives in the same dimension we were evaluating, i.e.
taking x derivatives along the x axis of a vector or matrix. But now we have
to compare the x2 and y2 operators. Naturally we chose to evaluate a whole
row/column of the grid at once, and so the operator in the same direction is
easy (matrix-vector multiplication like in 1D) but the other operator gives us
some trouble. The issue with the off-axis operator is that unlike the on-axis
operator the j+1 and j-1 terms are not on the row/column you are currently
evaluating, and so could not simply be solved using traditional vector/matrix
multiplication since as those j+1 and j-1 values would not be in the vector.
A solution becomes clear when we take a step back, and realize we dont
need to try and find some matrix-like solution, rather all we needed is the
vector result of the operator, and so we can simply apply the off-axis operator
via the roll function. Once we have the off-axis operator figured, the rest of
the program falls into place and we are ready to test.
(1

3
3.1

Testing
Numeric Accuracy

To test our system we can compare it to the analytical solution of a delta


function:
2
er
u(r, t) = To
4t
where r is the distance from the origin centered at the delta function. In our
model a delta function is approximated as one hot square in a bath of T=0.
The weight of the delta function (To ) is equal to Tg (x)2 where Tg is the
temperature of the hot grid point. This is to ensure that the integral over all
the grid (Total Energy) is the same for both cases. The results after 256 steps
with t = .25 yielded an error of 1.44 104 of and a variance of 2.293 108 .
It can be seen from the heat map that the results are rotationally symmetric
about the delta function, as predicted.

3.1 Numeric Accuracy

After testing for a few differing values of x and we become satisfied with
the accuracy of the simulation given t = .25, which will be the default
unless otherwise noted.

3.2 Energy Conservation

3.2

Energy Conservation

We then can go on to test the energy conservation of our system. For a test
run of 1024 steps with a complex initial heat map we find the average energy
of the system to stay constant!

3.2 Energy Conservation

In addition we can simulate 1024 steps of a zero average system, which


though not very realistic, still can be simulated by the CNM. This shows
the error in more detail, but stays restrained to well under 1010 , which is
very good considering the system normally runs with average energies on the
order of 100, so a signal to noise ratio of 1 : 1012 is more than sufficient.

3.3 Unconditional Stability

3.3

Unconditional Stability

The CNM is supposedly unconditionally stable, which should allow for t


of any size while maintaining stability, and hopefully energy conservation as
well. To test we can run a 1024 step run with t = 10

Though we can see significant lack of accuracy from the cross section and
heat map at t = 20, the system does stay stable, conservers energy, and even
happens upon the correct equilibrium solution!

3.4 Visualization of Boundary Conditions

3.4

Visualization of Boundary Conditions

To help us visualize these boundary effects, let us consider a system of 4


paraboloids

We will discuss the evolution of a paraboloid later, but for now we can use
it as a helpful example of the periodic boundary conditions of our system.
As you can see, rotational symmetry is broken due to the non-symmetric
distribution of neighbors, resulting in an angled checker-board pattern. It
should be noted that effect is not a computational error, but rather an artifact
of the boundary conditions.

3.5

Testing Conclusion

By this point we have not only mathematically shown our method to be


to the CNM, we have also shown that our implementation of it correctly
satisfies 3 conditions of the CNM: Numeric accuracy, energy conservation,
and unconditional stability. We will now work under the assumption that
our method is sound and begin to characterize the time evolution of a few
interesting initial conditions.

10

4
4.1

Case Studies
Small Ring

We have already covered the case of a delta function in our error analysis, so
let us move on to a similar but more exciting case, a small hot ring.

The ring begins to cool much like we would have expected, keeping its circular
shape, but then after 128 steps when t 30, we see an interesting shift. The
twin peaks we can the cross section begin to move towards each other,
before merging and resembling the gaussian shape we would expect from a
delta function. This makes sense because to a large enough approximation
(x r) a hot circle does resemble a delta function, so its not surprising to
find that they have similar solutions after a reasonable amount of time has
passed.

11

4.2 U-Shaped Disturbance

4.2

U-Shaped Disturbance

Out next case is that of a hot, collection of 3 rods in the shape of a U.

We can first see the hard edges round out on the U, giving it a more truly
round U shape. We then begin to see bay left at the center of the U begin
to heat much faster than the surroundings, similar to the heating of the inside
of the circle. But eventually, like always the heat profile begins to resemble
that of a gaussian, though this time it appears less symmetric, not doubt an
artifact of its asymmetric initial condition.

12

4.3 Rods

4.3

Rods

Now for a simple rod.

We again see the sharp edges very quickly cool and round out. This can
be explained by the high 2nd derivative at these sharp edges resulting in
a rapid cooling. The opposite effect can be noted on the interior, which is
relatively flat and does not cool much until it begins to have a significant
curve to it. This is a nice visual example of how the magnitude of the spacial
2nd derivative determines the rate of cooling, as indicated was indicated by
the original heat equation.

13

4.4 Cone

4.4

Cone

To further prove this point, we can consider the case of a cone, where initial
the 2nd derivative is 0 everywhere except at the tip and edges.

As expected, we find the cone to actually be a rather stable shape, even


though it is not isothermal. We see that the edges and tip are quick to
change, while the sides of the cone stay rather stable. We can see from both
the cross section and heat maps that the tip rapidly cools and the midsections
remain relatively constant temperature for early t. This of course only last
for a short while until the sides too eventually cool and the whole system
moves towards the equilibrium state of equal temperature everywhere.

14

4.5 Paraboloid

4.5

Paraboloid

Now to consider an example with constant 2nd derivative, the paraboloid.

As we would expect, the system as a whole seems to cool a constant rate,


with no one spot cooling significantly faster or slower. Note that the diamond
shaped heat map on the final plot is due to the periodic boundary conditions
of the system, not due to quantization error.

15

Conclusion

As a final visual treat, here is a full run of 1024 steps on a complex heat
map. See if you can spot any heat features we may have discussed earlier!
I hope you have found this short introduction and explanation of the 2D
Heat Equation modeled by the Crank-Nicolson method as interesting as I
found the topic. If you have any questions, please feel free to ask away!

16

References

Many thanks to the following sources:


Wikipedia Articles:
-Heat Equation
http://en.wikipedia.org/wiki/Heat equation
-Crank-Nicolson Method
http://en.wikipedia.org/wiki/Crank-Nicolson
T. Lakoba of the University of Vermont:
http://www.cems.uvm.edu/ tlakoba/math337/notes 15.pdf
Tristen Ursell of Cal Tech:
http://www.rpgroup.caltech.edu/courses/aph162/2006/Protocols/diffusion.pdf

17

You might also like