Computational Physics - Department of Physics

(Axel Boer) #1

10.5 Exercises 333


c) Find the truncation errors of these three schemes and investigate their stability properties.
d) Implement the three algorithms in the same code and perform tests of the solution for
these three approaches for∆x= 1 / 10 ,h= 1 / 100 using∆tas dictated by the stability limit
of the explicit scheme. Study the solutions at two time pointst 1 andt 2 whereu(x,t 1 )is
smooth but still significantly curved andu(x,t 2 )is almost linear, close to the stationary
state. Remember that for solving the tridiagonal equationsyou can use your code from
project 1.
e) Compare the solutions att 1 andt 2 with the closed form result for the continuous problem.
Which of the schemes would you classify as the best?
f) The above problem can be solved using Monte Carlo methods and random walks. We follow
here Farnell and Gibson in Journal of Computational Physics, volume 208 , pages 253-265
(2005). Choose a constant step lengthl 0 =



2 D∆tand equal probability for jumping left
and right. Set up the algorithm for solving the above diffusion problem and write a code to
do it. Compare your results with those from the partial differential equation solution and
comment the results.
g) Change the above stepsize by using a Gaussian distribution with mean value 1 and stan-
dard deviation 0. The step length of the random walker is nowl 0 =



2 D∆tξ, whereξis
random number chosen from the above Gaussian distribution.Implement this stepsize to
the program from f) and compare the results and comment.

10.5.In this exercise the aim is to derive both an explicit and an implicit scheme for the
two-dimensional diffusion equation.
Our differential equation is


∂^2 u(x,y,t)
∂x^2

+∂

(^2) u(x,y,t)
∂y^2
=∂u(x,y,t)
∂t
,t> 0 ,x,y∈[ 0 , 1 ],
where we now have made a model with a square lattice forxandy. Here we will assume that
the initial conditions are
u(x,y, 0 ) = ( 1 −y)exp(x) 0 ≤x,y≤ 1.
The boundary conditions (so-called Dirichlet conditions)are
u( 0 ,y,t) = ( 1 −y)exp(t) t≥ 0 0 ≤y≤ 1 ,
u( 1 ,y,t) = ( 1 −y)exp( 1 +t) t≥ 0 0 ≤y≤ 1 ,
u(x, 0 ,t) =exp(x+t) t≥ 0 0 ≤x≤ 1 ,
and
u(x, 1 ,t) = 0 t≥ 0 0 ≤x≤ 1 ,
This equation has a closed form solution of the typeu(x,y,t) = ( 1 −y)exp(x+t). It is easy to
check this by insertion. In this exercise you are asked to setup an explicit and an implicit
scheme for solving the above equation. You should also discuss convergence criteria and the
numerical stability of the scheme(s) you have chosen. Outline the algorithms for solving the
two-dimensional diffusion equation and implement these schemes as functions of∆x(assum-
ing∆x=∆y). Solve the equations numerically and give a critical discussion of your results.
Compare your results with the closed form answer.

Free download pdf