CompPhysScript 2017 PDF
CompPhysScript 2017 PDF
CompPhysScript 2017 PDF
Script by
Dr. H. M. Singer, Lorenz Müller and Marco - Andrea Buchmann
• http://www.comphys.ethz.ch/index.php/lectures
• http://www.ifb.ethz.ch/education/IntroductionComPhys
Pdf-files of both the slides and the exercises are also provided on these two pages.
1
2
hjherrmann@ethz.ch
His office is located in the Institute of Building materials (IfB), HIF E12, ETH
Hönggerberg, Zürich.
The personal web page is located at www.icp.uni-stuttgart.de/~hans and at
www.comphys.ethz.ch
In 2009/2010, Lorenz Müller and Marco - Andrea Buchmann continued the script
and filled in the gaps, expanded said chapters and added chapters on Monte Carlo
methods, fractal dimensions and the Ising model.
marcobuchmann@student.ethz.ch
Thank you!
In the second part of the class we shall look into numerical ways of solving equa-
tions (e.g. ordinary differential equations). We shall get to know a variety of ways
to solve these and learn about their advantages as well as their disadvantages.
3
• You should ideally have some knowledge about a higher level programming
language such as Fortran, C/C++, Java, ... . In particular you should also
be able to write, compile and debug programs yourself.
• It is beneficial to know how to make scientific plots. There are many tools,
which can help you with that. For example Matlab, Maple, Mathematica,
R, SPlus, gnuplot, etc.
• Requirements in mathematics:
• Requirements in physics
I Stochastic Processes 8
1 Random Numbers 9
1.1 Definition of Random Numbers . . . . . . . . . . . . . . . . . . . 9
1.2 Congruential RNG (Multiplicative) . . . . . . . . . . . . . . . . . 10
1.3 Lagged Fibonacci RNG (Additive) . . . . . . . . . . . . . . . . . 13
1.4 How Good is a RNG? . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.5 Non-Uniform Distributions . . . . . . . . . . . . . . . . . . . . . . 16
2 Percolation 22
2.1 The Sol-Gel Transition . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2 The Percolation Model . . . . . . . . . . . . . . . . . . . . . . . . 23
3 Fractals 36
3.1 Self-Similarity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.2 Fractal Dimension: Mathematical Definition . . . . . . . . . . . . 37
3.3 The Box Counting Method . . . . . . . . . . . . . . . . . . . . . . 39
3.4 The Sandbox Method . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.5 The Correlation-Function Method . . . . . . . . . . . . . . . . . . 41
3.6 Correlation Length ξ . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.7 Finite Size Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.8 Fractal Dimension in Percolation . . . . . . . . . . . . . . . . . . 46
3.9 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
3.10 Cellular Automata . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4
CONTENTS 5
The evaluation and visualization of large data sets, which can come from nu-
merical simulations or experimental data (for example maps in geophysics) is also
part of computational physics.
Another area in which computers are used in physics is the control of experi-
ments. However, this area is not treated in the lecture.
Suggested Literature
Books:
• H. Gould, J. Tobochnik and Wolfgang Christian: „Introduction to Computer
Simulation Methods“ 3rd edition (Addison Wesley, Reading MA, 2006).
• D. P. Landau and K. Binder: „A Guide to Monte Carlo Simulations in
Statistical Physics“ (Cambridge University Press, Cambridge, 2000).
• D. Stauffer, F. W. Hehl, V. Winkelmann and J. G. Zabolitzky: „Computer
Simulation and Computer Algebra“ 3rd edition (Springer, Berlin, 1993).
• K. Binder and D. W. Heermann: „Monte Carlo Simulation in Statistical
Physics“ 4th edition (Springer, Berlin, 2002).
• N. J. Giordano: „Computational Physics“ (Addison Wesley, Reading MA,
1996).
• J. M. Thijssen: “Computational Physics”, (Cambridge University Press,
Cambridge, 1999).
Book Series:
• „Monte Carlo Method in Condensed Matter Physics“, ed. K. Binder (Springer
Series).
• „Annual Reviews of Computational Physics“, ed. D. Stauffer (World Scien-
tific).
• „Granada Lectures in Computational Physics“, ed. J. Marro (Springer Se-
ries).
• „Computer Simulations Studies in Condensed Matter Physics“, ed. D. Lan-
dau (Springer Series).
Journals:
• Journal of Computational Physics (Elsevier).
• Computer Physics Communications (Elsevier).
• International Journal of Modern Physics C (World Scientific).
Conferences:
• Annual Conference on Computational Physics (CCP): In 2007, the CCP
was held in Brussels (Sept. 5th-8th 2007), in 2008 it was in Brazil.
Part I
Stochastic Processes
8
Chapter 1
Random Numbers
Special literature about random numbers is given at the end of this chapter.
The algorithmic creation of random numbers is a bit problematic, since the com-
puter is completely deterministic but the sequence should be non-deterministic.
One therefore considers the creation of pseudo-random numbers, which are cal-
culated with a deterministic algorithm, but in such a way that the numbers are
9
CHAPTER 1. RANDOM NUMBERS 10
a = nq + r (1.1)
with 0 ≤ r < |n|, where r is the the remainder. The mod-operator is useful be-
cause one obtains both big and small numbers when starting with a big number.
The pseudo-random number generators (RNG) can be divided into two classes:
the multiplicative and the additive generators.
• The multiplicative ones are simpler and faster to program and execute, but
do not produce very good sequences.
• The additive ones are more difficult to implement and take longer to run,
but produce much better random sequences.
Since all integers are smaller than p the sequence must repeat after at least (p − 1)
iterations. Thus, the maximal period of this RNG is (p − 1). If we pick the seed
value x0 = 0, the sequence sits on a fixed point 0 (therefore, x0 = 0 cannot be
used).
In 1988, Park and Miller presented the following numbers, which produce a rela-
tively long sequence of pseudo-random numbers, here in pseudo-C code:
Lagged Fibonacci generators often use integer values, but in the following we
shall focus on binary values.
with J ⊂ [1, .., b]. In other words, the sum includes only a subset of all the other
bits, so the new bit could for instance simply be based on the first and third bit,
xb+1 = (x1 + x3 )mod 2 (or of course any other subset!).
Let us try to illustrate some points with a two element lagged Fibonacci gen-
erator. Consider two natural numbers c, d ∈ N with d ≤ c, and we define our
sequence recursively as
Much as in the case of congruential generators, there are conditions for the choice
of the numbers c and d. In this case, c and d must satisfy the Zierler-Trinomial
condition which states that
1.3.1 Implementation
There are two methods to convert the obtained binary sequences to natural num-
bers (e.g. 32 bit unsigned variables):
• One runs 32 Fibonacci generators in parallel (this can be done very ef-
ficiently). The problem with this method is the initialization, as the 32
initial sequences do not only need to be uncorrelated each one by itself but
also among each other. The quality of the initial sequences has a major
impact on the quality of the produced random numbers.
• One extracts a 32 bit long part from the sequence. This method is relatively
slow, as for each random number one needs to generate 32 new elements in
the binary sequence. Furthermore, it has been shown that random numbers
produced in this way show strong correlations.
1. Square test: the plot of two consecutive numbers (si , si+1 ) ∀i should be
distributed homogeneously. Any sign of lines or clustering shows the non-
randomness and correlation of the sequence {si }.
2. Cube test: this test is similar to the square test, but this time the plot is
three-dimensional with the tuples (si , si+1 , si+2 ). Again the tuples should be
distributed homogeneously.
3. Average value: the arithmetic mean of all the numbers in the sequence {si }
should correspond to the analytical mean value. Let us assume here that
the numbers si are rescaled to be in the interval si ∈ [0, 1[. The arithmetic
mean should then be
N
1 X 1
s̄ = lim si = (1.8)
N →∞ N 2
i=1
CHAPTER 1. RANDOM NUMBERS 15
1
So the more numbers are averaged, the better 2
will be approximated.
4. Fluctuation of the mean value (χ2 -test): the distribution around the mean
value should behave like a Gaussian distribution.
5. Spectral analysis (Fourier analysis): If we assume that the {si } are values
of a function, it is possible to perform a Fourier transform by means of the
Fast Fourier Transform (FFT). If the frequency distribution corresponds to
white noise (uniform distribution), the randomness is good, otherwise peaks
will show up (resonances).
for different d.
Of course this list is not complete. There are many other tests that can be used
to check the randomness of pseudo-random sequences.
Very famous are Marsaglia’s “Diehard” tests for random numbers. These Diehard
tests are a battery of statistical tests for measuring the quality of a set of random
numbers. They were developed over many years and published for the first time
by Marsaglia on a CD-ROM with random numbers in 1995. These tests are 3 :
• Monkey test: Sequences of some number of bits are taken as words and the
number of overlapping words in a stream is counted. The number of words
not appearing should follow a known distribution. The name is based on
the infinite monkey theorem5 .
• Parking lot test: Randomly place unit circles in a 100 x 100 square. If the
circle overlaps an existing one, try again. After 12,000 tries, the number of
successfully "parked" circles should follow a certain normal distribution.
• Random spheres test: put 4000 randomly chosen points in a cube of edge
1000. Now a sphere is placed on every point with a radius corresponding
to the minimum distance to another point. The smallest sphere’s volume
should then be exponentially distributed.
• Craps test: 200,000 games of craps6 are played. The number of wins and
the number of throws per game should follow a certain distribution.
Let us now consider the distribution P (y). If we compare the areas of intergration,
we find ˆ y ˆ z
0 0
z= P (y )dy = Pu (z 0 )dz 0 (1.11)
0 0
where z is a uniformly distributed random variable and y a random variable
distributed according to the desired distribution. Let us rewrite the integral of
P (y) as IP (y) then we find z = IP (y) and therefore
This shows that a transformation between the two distributions can be found only
if
´y
1. the integral IP (y) = 0 P (y 0 )dy 0 can be solved analytically in a closed form
We are now going to demonstrate this method for the two most commonly used
distributions: the Poisson distribution and the Gaussian distribution. We are
already going to see in the case of the Gaussian distribution that quite a bit of
work is required to create such a transformation.
thus
0
z = −e−y k |y0 = 1 − e−yk . (1.15)
Solving for y yields
1
y = − ln(1 − z). (1.16)
k
This integral can now be solved by transforming the variables y10 and y20 into polar
coordinates:
Thus, using two uniformly distributed random numbers z1 and z2 , one obtains
(through the Box-Muller transform) two normally distributed random numbers
y1 and y2 .
CHAPTER 1. RANDOM NUMBERS 20
Let P (y) be the distribution of which we would like to obtain random numbers. A
necessary condition for the rejection method to work is that P (y) is well-behaved,
in this case “well-behaved” means that P (y) is finite over the domain of interest
P (y) < A for y ∈ [0, B], with A, B ∈ R and A, B < ∞. We then define an upper
bound to be the box with edge length B and A. (see Fig. 1.2)
The method works in principle quite well, however certain issues have to be taken
into consideration when using it.
• It is desirable to have a good guess for the upper bound. Obviously, the
better the guess, the less points are rejected. In the above description of
the algorithm we have assumed a rectangular box. This is however not a
necessary conditions. The bound can be any distribution for which random
numbers are easily generated.
• While the method is sound, in practice it is often faster to invert P (y)
numerically as mentioned already in subsection 1.5.1.
• There is a method to make the rejection method faster (but also more com-
plicated): We use N boxes to cover P (y) and define the individual box with
CHAPTER 1. RANDOM NUMBERS 21
Literature
• Numerical Recipes
• J.E. Gentle, "Random number generation and Monte Carlo Methods", (Springer,
Berlin, 2003).
Chapter 2
Percolation
A very simple and basic model of such a process was first introduced by Broadbent
and Hammersley (Proc. Cambridge Phil. Soc. Vol. 53, p.629 (1957)).
While the original idea was to model the fluid motion through a porous mate-
rial (e.g. a container filled with glass beads), it was found that the model had
many other applications. Furthermore, it was observed that the model had some
interesting universal features of so called critical phenomena2 .
Applications include
• General porous media: for example used in the oil industry and as a model
for the pollution of soils
• Sol-Gel transitions
• “Mixtures” of conductors and insulators: find the point at which a conduct-
ing material becomes insulating
• Spreading of fires for example in forest
• Spreading of epidemics or computer virii
• Crash of stock markets (D. Sornette, Professor at ETH)
• Landslide election victories (S. Galam)
• Recognition of antigens by T-cells (Perelson)
1
ita: percolare: 1 Passare attraverso. ~ filtrare. 2 Far filtrare. ( 1 pass through ~ filter, 2
make sth filter).
2
Critical phenomena is the collective name associated with the physics of critical points.
22
CHAPTER 2. PERCOLATION 23
Figure 2.1: Sol-Gel transition: a) Monomers are dispersed in the liquid (sol).
b) When the liquid is cooled down, the monomers start polymerizing and grow.
c) Once a huge macromolecule (which spans through the whole container) has
formed the Gel transition occurs. [2]
with probability p, that is, for each cell we create a random number z ∈ [0, 1[
and compare it to p. If z < p, the cell will be marked as occupied otherwise the
cell remains empty. This can be done for different values of p, leading to different
results (see Fig 2.3). One immediately notices that for small values of p, most
cells are empty, whereas for big values of p, most cells are occupied. There exists
a critical probability p = pc = 0.592... when for the first time a fully connected
cluster of cells spans two opposite sides of the box (this is also called a percolating
cluster). While pc is defined for infinite clusters, we can also find it for finite sizes;
in that case, pc is the average probability at which a percolating cluster first occurs.
The critical probability is sometimes referred to as the percolation threshold.
Figure 2.3: Percolation on a square lattice with L=40 for different values of p. As
the occupation probability p increases, more cells are filled. [20]
The burning method provides us with exactly this information; it does not only
provide us with a boolean feedback (yes/no) but even calculates the minimal
path length (the minimal distance between opposite sides, following only occu-
pied sites). The name of the method stems from its implementation; let us assume
that we have a grid with occupied and unoccupied sites. An occupied site repre-
sents a tree while an unoccupied site stands for empty space. If we start a fire
at the very top of our grid, all trees in the first row will start to light up as they
are in the immediate vicinity of the fire. Obviously, not only the first row of trees
will fall victim to this forest fire, as the neighbors of the trees in the first row will
soon catch on fire as well. The second iteration step is thus that all trees that are
neighbors of already burning trees are being torched.
CHAPTER 2. PERCOLATION 25
Clearly, the iterative method only comes to an end when the fire finds no new
victims (i.e. unburnt occupied sites neighboring a burning site) to devour and
consequently dies out or if the fire has reached the bottom. If the inferno has
reached the bottom, we can read off the length of the shortest path from the it-
eration counter since the number of iterations defines the minimum shortest path
of the percolating cluster.
1. Label all occupied cells in the top line with the marker t=2.
(a) Go through all the cells and find the cells which have label t.
(b) For each of the found t-label cells do
i. Check if any direct neighbor (North, East, South, West) is occupied
and not burning (label is 1).
ii. Set the found neighbors to label t+1.
3. Repeat step 2 (with t=t+1) until either there are no neighbors to burn
anymore or the bottom line has been reached - in the latter case the latest
label minus 1 defines the shortest path.
Figure 2.4: The burning method: a fire is started in the first line. At every
iteration, the fire from a burning tree lights up occupied neighboring cells. The
algorithm ends if all (neighboring) trees are burnt or if the burning method has
reached the bottom line. [20]
CHAPTER 2. PERCOLATION 26
The fact that for small lattices the transition is smeared out stems from the nature
of the process which is based on randomness. When we carry out a sequence of
simulations with increasing lattice sizes, we can determine the percolation thresh-
old to be approximately pc = 0.59274... .
Percolation can be performed not only on lattice sites, but also on the corre-
sponding bonds. Considering bonds changes the number of neighbors in a given
lattice and therefore also the percolation threshold.
CHAPTER 2. PERCOLATION 27
Figure 2.6: Percolation threshold for different lattices for site percolation and
bond percolation. Numbers with a star (*) can be calculated analytically. [10]
By looking at the values for different lattices in Fig. 2.6, it becomes clear that
different geometries (e.g. those in Fig. 2.7) have significantly different thresholds.
For example, the honeycomb lattice (Fig. 2.7e) has the highest 2D threshold.
Furthermore, some lattices (such as the triangular lattice seen in Fig. 2.7b) can
be calculated analytically (denoted by a *). Intuitively, it is clear that the thresh-
old needs to depend on the geometry as, when we think of the burning algorithm,
the speed at which the “fire” will spread depends on the geometry of the lattice.
Please note that if not otherwise stated we will only use “sites” for the perco-
lation. This implies in general also the behavior for “bonds”.
(a) Square (b) Triangu- (c) Martini (d) (4,6,12) (e) Hon-
lattice lar lattice lattice lattice eycomb
lattice
Let us write the lattice as a matrix Nij , which can have values of 0 (site is unoccu-
pied) and 1 (site is occupied) and let k be the running variable (we use k to label
the clusters in Nij ). Additionally, an array Mk is introduced, the mass of cluster
k, which counts the number of sites belonging to a given cluster k. We start the
algorithm by setting k = 2 (since 0 and 1 are already taken) and searching for the
first occupied site in Nij . We then add this site to the array Mk=2 = 1 and set
the entry in Nij to k (so it is branded as pertaining to the cluster k).
We then start looping over all lattice sites Nij and try to detect whether an oc-
cupied site belongs to an already known cluster or a new one. We comb through
the lattice from top-left to bottom-right; the criterion is rather simple:
• If a site is occupied and the top and left neighbors are empty, we have found
a new cluster and we set k to k + 1, Nij = k and Mk = 1. We continue the
loop.
• If one of the sites (top or left) has the value k0 (i.e. has already been
absorbed into a cluster), we increase the value of the corresponding array
Mk0 by one (setting Mk0 to Mk0 + 1). We name the new site accordingly,
i.e. Nij = k0 .
The last point is crucial, as we usually deal with a number of sites that are marked
in such a way that we have to first recursively detect which cluster they pertain
to before carrying out any further part of the algorithm. The recursive detection
stops as soon as we have found a k0 with Mk0 ≥ 0 (i.e. a “true” cluster number).
CHAPTER 2. PERCOLATION 30
Once all the sites Nij have been visited, the algorithm ends up with a num-
ber l of clusters (where l < kmax ). The only thing left to do is to construct a
histogram of the different cluster sizes. This is done by looping through all the
clusters k ← 2..kmax while skipping negative Mk .
1. k ← 2, Mk ← 1
(a) if top and left are empty (or non-existent) k ← k +1, Nij ← k, Mk ← 1
(b) if one is occupied with k0 then Nij ← k0 , Mk0 ← Mk0 + 1
(c) if both are occupied with k1 and k2 (and k1 6= k2 ) then choose one, e.g.
k1 and Nij ← k1 , Mk1 ← Mk1 + Mk2 + 1, Mk2 ← −k1
(d) If both are occupied with k1 , Nij ← k1 , Mk1 ← Mk1 + 1
(e) if any of the k’s considered has a negative mass Mk , find the original
cluster they reference and use its cluster number and weight instead
3. for k ← 2..kmax do
Once we have run the algorithm for a given lattice (or collection of lattices and
taken the average) we can evaluate the results. We find different behaviors of
the relative cluster size ns (where s denotes the size of the clusters) depending
on the occupation probability p. These results are illustrated in Fig. 2.10, where
the first graph (Fig. 2.10a) represents the behavior for subcritical occupation
probabilities (p < pc ), the second graph (Fig. 2.10b) shows the behavior for the
critical occupation probability(p = pc ) and the third graph (Fig. 2.10c) depicts
the behavior for overcritical occupation probabilities(p > pc ).The corresponding
distributions are also noted.
(a) np<pc (s) ∝ s−θ eas (b) npc (s) = s−τ 1−1/d
(c) np>pc (s) ∝ e−bs
Figure 2.10: Cluster size distribution for p < pc (left), p = pc (center) and p > pc
(right). [10]
One finds that in the subcritical regime (p < pc ), np (s) obeys a power law multi-
plied with an exponential function, whereas in the overcritical region (p > pc ), we
observe a distribution that resembles an exponential decay but with an argument
that is stretched with a power s1−1/d .
We are thus able to describe the subcritical and overcritical behavior of the cluster
size distribution - the only remaining question is how we can go from one to the
other, or, in other words, what the cluster size distribution at the critical occupa-
tion probability pc is. As one can see from Fig. 2.10b, the function appears as a
straight line in the logarithmic plot, implying a power law behavior npc (s) = s−τ .
Of course we would still like to know the exponent τ ; this exponent depends on
the dimension of the problem but can be calculated (in 2D it is 187 91
while in 3D
we find 2.18). One can also calculate the bounds for τ : 2 ≤ τ ≤ 5/2.
We can summarize the behavior of the cluster size distribution ns in the three
different regions: −θ as
s e p < pc
−τ
np (s) ∝ s p = pc (2.1)
−bs1−1/d
e p > pc
CHAPTER 2. PERCOLATION 32
Figure 2.11: Scaling behavior of the percolation cluster size distribution [10]
In a next step, we can compare the non-critical distributions to the cluster size
distribution for pc ; We plot a rescaled distribution
which is defined on all three regions from (2.1). We may feel adventurous and
want to plot ñp (s) against (p − pc )sσ as in Fig. 2.11. We immediately notice that
we obtain a global curve which can be described by
with the scaling functions3 <± , where the subscript ± stands for p > pc (+) and
p < pc (-), respectively.
When we calculate the second moment4 of the distribution we find a power law:
X
χ =< ’ s2 n(s) > (2.3)
s
3
Scaling function: A function f (x, y) of two variables that can be expressed as a function of
one variable f (x0 ).
4
The n-th moment of a distribution P (x) is defined as
ˆ
µn = xn P (x)dx
therefore´ the 0-th moment of a normalized distribution is simply µ0 = 1 and the first moment
is µ1 = xP (x)dx = E(x) (the expectation value). Accordingly, µ2 is the standard deviation
of the distribution around the expectation value. As we are dealing with a discretely valued
argument s, the integral becomes a sum.
CHAPTER 2. PERCOLATION 33
The apostrophe (’) indicates the exclusion of the largest cluster in the sum (as
the largest cluster would make χ infinite at p > pc ). One finds
χ ∝ C± |p − pc |−γ (2.4)
with γ = 43/18 ≈ 2.39 in 2D and γ = 1.8 in 3D. The second moment is a very
strong indicator of pc as we can see a very clear divergence around pc . Of course
we see a connection to the Ising model (which is explained further later on), where
the magnetic susceptibility diverges near the critical temperature.
It can be shown that the scaling exponents we have seen so far are related by
3−τ
γ=
σ
These exponents can be found for different lattice types (such as those in Fig. 2.7)
and in different dimensions. The table shown in Fig. 2.12 gives an overview of the
different exponents measured for a regular (square) lattice up to 6 dimensions.
Of course it is possible to determine dmin for site percolation and bond perco-
lation as well as for different lattice types. As an example, Fig. 2.14 shows the
site and bond percolation for a 4-dimensional system (square lattice), which was
calculated by Ziff in 2001.
CHAPTER 2. PERCOLATION 35
Literature
• D. Stauffer: „Introduction to Percolation Theory“ (Taylor and Francis,
1985).
Fractals
3.1 Self-Similarity
The fractal dimension is a concept which has been introduced in the field of fractal
geometry. The underlying idea is to find a measure to describe how well a given
(fractal) object fills a certain space.
The Sierpinski-Triangle
1
Invented by the Polish mathematician Wacław Franciszek Sierpiński (1882-1969)
36
CHAPTER 3. FRACTALS 37
This obviously produces an object that is built up of elements that are almost
the same as the complete object, which can be referred to as ‘approximate’ self-
similarity. It is only in the limit of infinite iterations that the object becomes
exactly self-similar: In this case the building blocks of the object are exactly the
scaled object. One also says that the object becomes a fractal in the limit of
infinite iterations.
Self-Similarity in Nature
Naturally occurring self-similar objects are usu-
ally only approximately self-similar. As an il-
lustration of this point, consider a tree; a
tree has different branches, and the whole
tree looks similar to a branch connected to
the tree trunk. The branch itself resem-
bles a smaller branch attached to it and so
on. Evidently, this breaks down after a few
iterations, when the leaves of the tree are
reached.
Figure 3.2: Barnsley fern[1]
Another example are gold colloids, which were
shown to arrange in fractals of fractal dimen-
sion 1.70 (the meaning of this will soon be
explained) by David Weitz in 1984. Col-
loidal gold is a suspension of sub-micrometer-
sized gold particles in a fluid (for example wa-
ter). These gold colloids arrange in frac-
tals.
where d is the dimension of the spheres (i.e. the dimension of the space into which
the object is embedded).
We define V∗ as the volume of the covering that uses as few spheres as possi-
ble and has minimal volume
∗
V = min min (V (c))
V (c) N (c)
As a simple example consider the Sierpinski triangle as seen in Fig. 3.4. Stretching
its sides by a factor of 2 evidently increases its volume by a factor of 3 (‘volume’
in two dimensions is usually referred to as ‘area’). By inserting these values
into equation (3.1) we find that the Sierpinski triangle has the fractal dimension
log(3)/ log(2) ≈ 1.585.
CHAPTER 3. FRACTALS 39
In the box counting method, we start with a picture of the fractal and super-
impose a lattice with lattice constant . We define the number of boxes in the
lattice that are not empty (contain a part of the fractal) as N (). We do this for
a large range of and plot N () vs. in a log-log plot. A typical result can be
seen in Fig. 3.5.
Interlude: Multifractality
By slightly adapting the box counting method, another subtlety of the fractal
dimension can be understood, the so-called ‘multifractality’. Instead of only con-
sidering whether a box is completely empty or not, one also counts how many
filled dots or pixels there are in a certain box i; we will denote this number by Ni .
Additionally, we introduce the fraction pi = Ni /N , where N is the total number
of occupied points. Thus pi is the fraction of dots contained in the box i.
So far we have not done anything new and original. Let us define the ‘q-mass’ Mq
of an object as X q
Mq = pi
i
Mq ∝ Ldq
log((Mq /N )(1/q) )
1
dq = lim lim
1 − q →0 N →∞ log ()
For some objects dq is the same for all q and the same as the fractal dimension.
For other objects, called ‘strange attractors’, one obtains different fractal dimen-
sions for different values of q. This topic is of marginal interest in this course;
the interested reader may find additional information by searching the keywords
‘multifractality’ and ‘Renyi dimensions’.
of the picture and count the number of occupied sites (or pixels) in the box N (R).
We then successively increase the box size R in small steps until we cover the
whole picture with our box, always storing N (R). We finally plot N (R) vs. R in
a log-log plot where the fractal dimension is the slope (see e.g. Fig. 3.7).
The angled brackets denote a suitable averaging (for instance over all points at a
distance r from randomly chosen origins). By measuring the correlation function
c(r) one can obtain the fractal dimension of the object,
c(r) ∝ rdf −d
We see that in a double-logarithmic plot of c(r) vs. r the slope of the (visually)
linear part is the fractal dimension minus the dimension of the space the object
is embedded into).
CHAPTER 3. FRACTALS 42
on the dimension. With this background we can move on to the most important
part of the chapter, the finite size effects.
We can draw a first conclusion at this point: if we let L → ∞, the critical region
will vanish. This is obviously impossible with a finite computer. Thus L is finite
and close to pc we observe an approximation instead of the real values,
1
peff (L) = pc (1 − aL− ν )
The best we can do at this point is using the data acquired at finite sizes to guess
the values for an infinite system; this process is called extrapolation which can be
done for instance to find the critical occupation probability pc .
CHAPTER 3. FRACTALS 44
Out of sheer curiosity, one might have a glimpse at the peak and try to find
an expression for the size of the peak, depending only on the system size. Fur-
thermore, one might introduce new parameters that are combinations of the pre-
vious ones and find that the plots start to look very much alike once the right
expression is chosen. One possible combination of parameters is illustrated in
Fig. 3.13 where we note that points that originally were far apart (as in Fig.
3.12) now come to lie on top of each other - we have found data collapse! Let
us try to comprehend what this data collapse means. We have a function χ that
was originally a function of two parameters (the occupation probability p and the
system size L) and that now behaves as though it was a one-parameter function.
Figure 3.12: Illustration of the system size dependence of χ. Shown here: Mag-
netic susceptibility vs. temperature which shows a similar behavior. Note that
the peak size increases with the system size. Sizes used: L=20 (blue), L=40 (red),
L=50 (yellow), L=60 (green)[20][12]
CHAPTER 3. FRACTALS 45
which could be verified by plotting the maxima of Figure 3.13: Finite size
Fig. 3.12). These expressions are reminiscient of scaling of χ; one observes
those previously introduced in the context of perco- data collapse when plotting
lation and the idea is the same (e.g. compare (3.7.1) χL−γ/ν against |p−p pc
c|
L1/ν .
to (2.2) ). We recall from chapter two that a scal- The straight lines have a
ing function is a function of two variables (in this slope of −γ (as the criti-
context p, L) that can be expressed in terms of only cal behavior of χ for infinite
one variable. systems, (2.4)) . [11]
P Ld = s∞ ∝ Ldf
where
91
= 48 in 2 dimensions;
df
≈ 2.51 in 3 dimensions.
and
β
df = d −
ν
In section 2.2.5, we simply introduced df without a word about its origins. When
we consider fractal dimensions however, df will come out of the equations!
CHAPTER 3. FRACTALS 46
P ∝ (p − pc )β
Moreover, at pc , we find that not only the order parameter is system size depen-
dent,
β
P ∝ L− ν
but that the number of sites is also system size dependent
M ∝ Ldf
3.9 Examples
3.9.1 Volatile Fractals
In a volatile fractal, the cluster is “redefined” at each
scale, e.g. the path that spans L1 < L2 is not nec-
essarily part of the path spanning L2 as can be seen
in Fig. 3.14.
Figure 3.14: Example of a
volatile fractal[2]
3.9.2 Bootstrap Percolation
The canonical bootstrap model is one where sites are initially occupied randomly
(with a given probability p) as in the percolation model. Then, any sites that do
not have at least m neighbors are removed. In the case of m = 1, all isolated sites
are removed, in the case of m = 2 all “dangling” sites are removed. This does
CHAPTER 3. FRACTALS 47
however not affect pc . If we choose m ≥ 3, pc and the nature of the transition are
strongly dependent on the lattice; for sufficiently large m a first order transition
is observed.
The bootstrap percolation method has many applications, including some sys-
tems in solid state physics, fluid flow in porous media and others.
Figure 3.15: freshly occupied lattice (left) and the same lattice (right) after re-
moving all sites with less than m neighbors (“culling”) [18]
• The sites are discrete (we are considering a lattice, not a continuous volume)
• We use finite time steps, and compute the next step t + 1 based on the last
time step t.
The binary variable σi at a given site i at the next time step t + 1 is determined
by
σi (t + 1) = fi (σ1 (t), ..., σk (t)) (3.2)
k
where k is the number of inputs. We see that there are thus 22 possible rules!
CHAPTER 3. FRACTALS 48
c = 0 · 27 + 1 · 26 + 1 · 25 + 0 · 24 + 0 · 23 + 1 · 22 + 0 · 21 + 1 · 20 = 64 + 32 + 4 + 1 = 101
We can thus identify a rule by its c number. Let us consider a couple of rules to
see how this works (rule 4,8,20,28 and 90):
• Class 1: Almost all initial patterns evolve quickly into a stable, homogeneous
state, any randomness in the initial pattern disappears.
• Class 2: Almost all initial patterns evolve quickly into stable or oscillating
structures. Some of the randomness in the initial pattern may be filtered
out, but some remains. Local changes to the initial pattern tend to remain
local.
CHAPTER 3. FRACTALS 49
Figure 3.16: Comparison of the evolution for two completely different rules
• Class 4: Nearly all initial patterns evolve into structures that interact in
complex and interesting ways. Eventually a class 4 may become a class 2
but the time necessary to reach that point is very large.
• if n<2 : 0
• if n=3 : 1
• if n>3 : 0
Figure 3.18: Steps 0 and 16 (in a period of 30 time steps) of the Game of Life [1]
Chapter 4
• Physics: They are used in many areas in physics, some applications include
statistical physics (e.g. Monte Carlo molecular modeling) or in Quantum
Chromodynamics. In the much talked about Large Hadron Collider (LHC)
at CERN, Monte Carlo methods were used to simulate signals of Higgs
particles, and they are used for designing detectors (and to help understand
as well as predict their behavior)
• Design: Monte Carlo methods have also penetrated areas that might - at
first sight - seem surprising. They help in solving coupled integro-differential
51
CHAPTER 4. MONTE CARLO METHODS 52
• Economics: Monte Carlo models have also found their place in economics
where they have been used e.g. for financial derivatives.
4.2.1 Computation of π
A good illustration of this method of repeated ran-
dom sampling and averaging is the computation of
the number π.
Another way to compute π though (and learn something about Monte Carlo at
the same time) goes as follows: We consider N random points in the unit square
that are characterized by their x and y coordinates xi , yi . Then, the number of
points Nc lying within the quarter circle (i.e. fulfilling the relation x2 + y 2 ≤ 1)
is compared to the total number N of points and the fraction will give us an
approximate value of π:
Nc (N )
π(N ) = 4
N
Of course, the more points we consider, the better the approximation will become.
In fact, the error is ∆ = π(N ) − π ∝ √1N and thus really does decrease with the
number N of points. This is easy to understand. Imagine you chose just two
points, one of which is lying inside the quarter circle, the other outside. This
will give you π(2) = 2, a rather atrocious approximation to 3.14159265... but if
you pick 10 points, they will start to approximate the real value much better. For
CHAPTER 4. MONTE CARLO METHODS 53
N = 10, 000 for instance you may find that Nc = 7, 854 giving π(10, 000) = 3.1416.
It is however not obvious from the start that the error should decrease ∝ √1N which
is why we shall look into this in a minute.
We have changed our way of sampling by using the distribution function p(x),
reducing the requirement on g(x). This manifests itself in the summand above.
One could state that p(x) helps us to pick our sampling points according to their
importance (e.g. select more points close to a singularity) - in fact, this kind of
sampling is called importance sampling.
We thus see that while the error for each step is O((∆x)3 ), the cumulative error
is N times this or O((∆x)2 ) ∝ O(N −2 ).
We can now do the same again for d dimensions (i.e. the dimension of the do-
main is d-dimensional). The “intervals” will now be d dimensional, and the error
for each segment will be (∆x)d+2 with the sum over all “subintervals” giving us
1
N (∆x)d+2 but N ∝ (∆x) d so that the error will be ∝ N (∆x)
d+2
∝ (∆x)2 . The
error is thus independent of the dimension.
We can conclude that the error in conventional methods goes as (∆x)2 and given
− d1 2
1
that T ∝ N ∝ (∆x)d , we see that ∆x ∝ T and the error is ∝ (∆x)2 ∝ T − d .
where < g > stands for the sample mean of the integrand. The variance of the
function can then be estimated using
N
1 X
var(g) ≡ σ 2 = (g(xi )− < g >)2
N − 1 i=1
where the denominator is N − 1 as we want to obtain the unbiased estimate of
the variance. Using the central limit theorem, the variance of the estimate of the
integral can be estimated as
var(g) σ2
var(Q) = (b − a)2 = (b − a)2
N N
1
which for large N decreases like N . Thus, the error estimate is
p σ
δQ ≈ var(Q) = (b − a) √
N
We can now generalize this to multidimensional integrals:
ˆ b1 ˆ b2 ˆ bn
I= dx1 dx2 ... dxn f (x1 , ..., xn )
a1 a2 an
So far this does not seem to have too much to do with integration, we are simply
placing some spheres in a volume V and measuring some distance rij . Let us say
we are interested in the average distance between the centers of spheres in the
box then we need to consider the following integral to reach an analytical result:
ˆ ˆ
1 2 X
3 3
< rij >= rij d r1 ...d rN , where Z = d3 r1 ...d3 rN
Z N (N − 1) i<j
Let us stay with this formula for a moment and have a look at the different factors.
The first factor, Z1 , is a normalization factor. The following factor is of combina-
tory origin, in fact it stems from random drawing from a finite population without
replacement. We start out with N choices (the whole population) and pick one
sphere at random. There are only (N − 1) choices left for the second one (as it
cannot be the first one again). This gives a total number of N · (N − 1) possible
combinations for picking two spheres. As they are indistinguishable, there is an
additional factor of 12 and we thus divide by this whole combinatory expression.
Note that we would need to correct with a factor of 12 if the sum were over i 6= j
(since, in that case, we would have counted each volume twice) which was avoided
by simply summing over i < j.
• Make sure that the new sphere does not overlap with any pre-existing spheres
(see condition on rij ). If it does overlap, reject the position and try again
CHAPTER 4. MONTE CARLO METHODS 58
• Once all the spheres have been placed, calculate the distances rij .
We then use these distances rij to compute the average. This procedure will con-
verge and give a value that approximates the integral under the right conditions.
It is important to note that our result will of course depend on the number of
spheres positioned:
Imagine we had taken a ridiculously small number of spheres (let us say only
two!) in a rather large volume and we carried out the distance measurement.
There would not be much to average over and on top of that, due to the relative
liberty of positioning the two spheres in the volume, the distance (and with it the
average distance) would fluctuate wildly depending on the setup. If we repeat
this n times and average over it, the result will thus not converge as nicely as it
would with a relatively large number N of spheres where the space left would be
small. Placing many spheres in the volume would help the convergence but will
slow down the algorithm as with more spheres comes a higher rate of rejected
positions. For large N it is even possible that the last few spheres cannot be
placed at all! You’ll be able to analyze this in the exercises.
These two averages are connected by the Ergodic hypothesis. This hypothesis
states that for long periods of time, the time one particle spends in some region
Λ of phase space of microstates with the same energy is directly proportional to
the volume V (Λ) of that region. One can thus conclude that all the accessible
microstates are equiprobable (over a long period of time). In statistical analysis,
one often assumes that the time average Q̄t of some quantity Q and the ensemble
average < Q > are the same.
When we go from the “individual” probability (at equilibrium) peq (X) to give us
some specific X over to the “global” (overall) probability to give us just any X we
want to obtain probability 1 (normalization) :
X
peq (X) = 1
X
Now that we have a better grasp of the concept, let us formalize these ideas:
In analogy to the spin flip in the Ising model of ferromagnetism, we propose a
new configuration and define an acceptance probability which will make sure that
the model behaves the way we want. We denote the probability of acceptance of
a new configuration Y , starting from a configuration X, by A(X → Y ). In prac-
tice, we might be interested a bit more in the overall probability of a configuration
actually making it through these two steps; this probability is the product of the
transition probability T (X → Y ) and the acceptance probability A(X → Y ) and
is called the probability of a Markov chain:
W (X → Y ) = T (X → Y ) · A(X → Y )
If we are interested in the evolution of the probability p(X, t) to find X in time,
we can derive this with a logical gedankenexperiment: there are two processes
changing this probability:
• A configuration X is produced by coming from Y (this will contribute pos-
itively)
• A configuration X is destroyed by going to some other configuration (this
will decrease the probability)
finite, the state i does not need to have a finite expectation Mi = Exp [Ti ]. If however the state
is positively recurrent, Mi is finite.
CHAPTER 4. MONTE CARLO METHODS 62
dp(X, t) X X
= p(Y )W (Y → X) − p(X)W (X → Y )
dt Y Y
and the conditional probability, “a provided that t” (or in plain English, the
probability to accept a new configuration produced by t), is
P (a ∩ t) W (X → Y )
P (a|t) = =
P (t) T (X → Y )
CHAPTER 4. MONTE CARLO METHODS 63
where we are now able to identify our original A(X → Y ) easily as the conditional
probability P (a|t)!
Furthermore, for X X
ai = 1 , bi = 1
i i
we have
P
X bi =1
ai bi = (a1 +a2 +...)(b1 +b2 +...) = a1 b1 +a1 (1−b1 )+a2 b2 +a2 (1−b2 )+... = a1 +a2 +... = 1
ij
so for two independent events we get 1 again, and thus the expression is normal-
izable. When we apply this to the example at hand, we find
X
P (T (X → Y ))P (A(X → Z)) = 1
Y,Z
Y =Z
X X
= T (X → Y )A(X → Y ) = W (X → Y )
Y Y
Detailed Balance
Let us now consider a stationary state (i.e. the measure is time independent),
dp(X, t)
=0
dt
Note that all Markov processes reach a steady state. However, we want to model
the thermal equilibrium, so we use the Boltzmann distribution,
and we obtain
X X
peq (Y )W (Y → X) = peq (X)W (X → Y )
Y Y
and we thus find the detailed balance condition (which is a sufficient condi-
tion):
peq (Y )W (Y → X) = peq (X)W (X → Y ) (4.2)
Then, the steady state of the Markov process is the thermal equilibrium. We have
achieved this by using the Boltzmann distribution for p(X).
CHAPTER 4. MONTE CARLO METHODS 64
Glauber Dynamics
The detailed balance is a very broad condition permitting many approaches. An-
other such approach was proposed by Glauber (he later obtained the Nobel prize,
though not for this contribution but for his work in optics). His proposal for the
acceptance probability was
− k∆ET
e B
AG (X → Y ) = (4.3)
− k∆ET
1+e B
claim: The acceptance probability (4.3) as proposed by Glauber fulfills the de-
tailed balance condition (4.4).
proof:
CHAPTER 4. MONTE CARLO METHODS 65
• We can adapt the condition even further by recalling that (see Boltzmann
distribution)
peq (Y ) ∆E
−
= e kB T (4.6)
peq (X)
where the partition function ZT drops out. We can thus rewrite (4.5) by
dividing both sides by peq (X) to obtain
peq (Y ) ∆E
−
A(X → Y ) = A(Y → X) = e kB T A(Y → X) (4.7)
peq (X)
and we have thus proven that AG does in fact fulfill the detailed balance
condition.
The Glauber dynamics have some advantages over Metropolis once you go to low
temperatures because of the different formulation of the acceptance.
Literature
• M.H. Kalos and P.A. Whitlock: “Monte Carlo Methods” (Wiley-VCH, Berlin,
2008 )
• J.M. Hamersley and D.C. Handscomb: “Monte Carlo Methods” (Wiley and
Sons, N.Y., 1964)
CHAPTER 4. MONTE CARLO METHODS 66
• R.Y. Rubinstein: “Simulation and the Monte Carlo Method” (Wiley and
Sons, N.Y., 1981)
CHAPTER 4. MONTE CARLO METHODS 67
where Hi is a (usually homogeneous) external field and Jij are the (translation-
ally invariant) coupling constants. As the coupling constants are translationally
invariant, we may drop the indices and simply write J = Jij ∀i, j. The coupling
constant J is half the difference in energy between the two possibilities (alignment
and anti-alignment).
which can be generalized to the two-dimensional case; we can also add an external
field as in equation (4.8).
where we have introduced hi which is the approximate local field at site i, given
by X
hi = σj
nn of i
The sum is characteristic of this approximation; we are only summing over the
next neighbors (nn) j of i, in this example we are thus only interested in the local
fields of the next neighbors when determining hi . The notation nn for nearest
neighbor is used throughout this chapter.
Note that we evaluate the acceptance probability at each step; given that the
acceptance probability is very low, we need a lot of steps for something to change.
We will call a group of N steps a “sweep”.
Let us consider a magnetic system; we recall the definition of the magnetic sus-
ceptibility χ,
M = χH
where M is the magnetization of the material and H is the magnetic field strength.
We want to observe its evolution with the ambient temperature T . We find a
singularity at the critical temperature Tc , where the magnetic susceptibility χ
obeys a power law with critical exponent γ:
χ ∝ (T − Tc )−γ
As a side comment, note that the binary nature of this model makes it very
tempting for a bitwise model (packing 64 spins together). Furthermore, more
advanced algorithms actually do not consider locations individually but consider
clusters (if you would like to know more, please visit the lecture in the spring
semester).
CHAPTER 4. MONTE CARLO METHODS 69
We set EAA = EBB = 0 and EAB = 1. Then, the number of each species is
constant and our conservation law is hardwired in the model since we only consider
pairs of unequal particles (i.e. we can swap but not create/destroy particles).
What does this mean in the Ising language? Consider the magnetization:
N
1 X
M (T ) = lim h σi i
H→0 N
i=1
and note that (due to the constant number of atoms of each species) the number
of σi = +1 and σi = −1 is constant. To see this, let us divide the indices {i} into
two subsets:
so that
N
1 X
M (T ) = lim h σi i
H→0 N
i=1
1 X X
= lim h σi + σi i
H→0 N
i∈Na i∈Nb
1 X X
= lim h (+1) + (−1)i
H→0 N
i∈N a i∈N b
1
= lim (|Na | − |Nb |)
H→0 N
CHAPTER 4. MONTE CARLO METHODS 70
where |Na | is the number points with σi = +1 (Cu atoms) and |Nb | is the num-
ber of points with σi = −1 (Ni atoms). As the number of Cu and Ni atoms
is constant, the “magnetization” remains constant and we need new dynamics
(Kawasaki dynamics).
We thus only choose bonds that are on the A-B-boundary and calculate the
energy:
• Calculate ∆E for (A − B) → (B − A)
We see that this procedure is very similar to the previous one, just with the added
condition that the magnetization is constant.
4.7 Interfaces
We have mentioned that the Ising model is
not only used for ferromagnetism anymore but
has found applications in a variety of other ar-
eas.
Each point of the interface has a height h measured from the bottom (the average
height is denoted by h̄) and we can thus define the width W of the interface:
s
1 X
W = (hi − h̄)2
N i
where N denotes the length of the lattice. In the upcoming sections, we are going
to analyze a number of algorithms; we will be particularly interested in the width
and the height, as different additional conditions always carry with them a change
in the behavior of the width and the height (e.g. we limit the height difference
between neighboring positions). This is necessary as the interface will have to
vary depending on our simulation needs - a cancer tissue simulation will have to
look different from a simulation of a drop on a car windshield.
A special case is the flat surface, where all points at the interface have the same
height, hi = h̄ and thus W = 0. In general, the width W increases very quickly
with the temperature T , exhibiting a singularity at the critical temperature Tc . As
we get closer to Tc , the interface becomes more and more diffused and the system
starts to “ignore” the boundary conditions, placing “+” entries next to a boundary
where we had imposed “−”. The transition is known as “roughening transition”.
• t → ∞ : W ∝ Lξ =⇒ f (u → ∞) = const
CHAPTER 4. MONTE CARLO METHODS 72
• L → ∞ : W ∝ tβ =⇒ f (u → 0) ∝ uβ
where we have introduced the so-called growth exponent β = zξ . One can numer-
ically verify these laws by observing a data collapse (see the section on scaling
laws in the context of percolation).
The new term introduces stiffness and thus punishes curvature, so that partic-
ularly curved surfaces will suffer from this new term and will make the system
relax back to a flatter configuration.
where
(j − 1)(hL − h1 ) hL − h1
hj = h1 + and g=
L−1 L
We then use Kawasaki dynamics (conservation law)
and do not permit disconnected clusters of +1 (i.e.
isolated water droplets in the air). In Fig. 4.10
we see an example (L = 257, g = 0.001 af-
ter 5 × 107 MC updates averaged over 20 sam-
Figure 4.10: Shape of a drop
ples). We can then define the contact angle Θ,
with L = 257, g = 0.001 [2]
which is a function of the temperature and goes to
zero when approaching the critical temperature Tc .
CHAPTER 4. MONTE CARLO METHODS 73
• Fluid instabilities
• Electric breakdown
• Biological morphogenesis
1
The roughening exponent ξ is 2
and the growth exponent β is 14 , so the Family-
Vicsek scaling law is
√ t
W (L, t) = Lf ()
L2
From the result we can see that the spikes are much “smoother” and not as jagged
anymore as before. The height per column varies more smoothly as well. Nonethe-
less, the height per column still varies a lot, which we can further restrict by e.g.
requiring that it may only differ by a given number of particles. This is exactly
the idea behind the next algorithm we are going to look at.
The procedure then needs to reflect this latest change with an additional condi-
tion (which can lead to the rejection of a particle, if it does not meet the condition).
4.7.3 Growth
We have seen a handful of algorithms that
deal with how to grow patterns according to
a given set of rules, simulating e.g. can-
cer.
Of course not every algorithm is going to respect every single one of these symme-
tries (nor would we want them to!). Depending on the growth process we envision,
a given set of symmetries will need to be respected.
For a growth process respecting all five symmetries, the Edwards-Wilkinson (EW)
equation is fulfilled:
∂h(x, t)
= ν∇2 h + η(x, t)
∂t
where ν is the surface tension and η is the Gaussian white noise. The correspond-
ing coefficients from before are ξ = 21 and β = 14
∂h λ
= ν∆h + (∇h)2 + η(x, t)
∂t 2
This equation was first proposed by M. Kardar, G.
Parisi and Y.-C. Zhang (in 1986). We find ξ = 12 and
β = 31 .
Mφ=0
p ∝ (∇φ)η
• For η = 0 we find the Eden model (our blob with rough edges)
To see the evolution with η and see the breakdown:
We can identify the similar shape of the third blob with the Diffusion Limited Ag-
gregation, and the very first one with the Eden blob from Fig. 4.16.
s∗ ∈ S ∗ := {s ∈ S : F (s) ≤ F (t)∀t ∈ S}
Finding the solution will become increasingly difficult for large S, particularly
when e.g. |S| = n!.
CHAPTER 4. MONTE CARLO METHODS 79
We now look for the cheapest trip through all these cities in order to minimize
our costs (and maximize profits). The set S of solutions is given by
and the cost function (for a given order, characterized by the permutation π) is
n−1
X
F (π) = c(σπi , σπi+1 ) for π ∈ S
i=1
A quick word about permutations: Let us say we have 8 cities, then one possi-
ble permutation (the trivial one) is {1, 2, 3, 4, 5, 6, 7, 8}, and a second one may be
ω = {1, 8, 3, 5, 4, 2, 7, 6} (this describes the order of the cities on the trip). For the
second permutation, we have ω1 = 1, ω2 = 8, ω3 = 3 etc. so that the first three
summands in F (ω) will be c(σ1 , σ8 ) + c(σ8 , σ3 ) + c(σ3 , σ5 ).
Finding the best trajectory is a NP-complex problem, i.e. the time to solve grows
faster than any polynomial of n.
CHAPTER 4. MONTE CARLO METHODS 80
Instead of this “traditional” optimization algorithm (which falls prey to local min-
ima), we thus introduce the simulated annealing optimization algorithm:
• If F (σ 0 ) < F (σ) : replace σ := σ 0
• If F (σ 0 ) > F (σ) : replace σ := σ 0 with probability exp(− ∆F
T
) (where ∆F =
0
F (σ ) − F (σ) > 0)
This second step is referred to as “uphill” movement and does not exist in the
traditional formulation. The T appearing in the probability is a constant (e.g.
temperature). In the course of the algorithm we slowly let T go to zero in order
to find the global maximum.
Literature
• M.H. Kalos and P.A. Whitlock: “Monte Carlo Methods” (Wiley-VCH, Berlin,
2008 )
• J.M. Hamersley and D.C. Handscomb: “Monte Carlo Methods” (Wiley and
Sons, N.Y., 1964)
• R.Y. Rubinstein: “Simulation and the Monte Carlo Method” (Wiley and
Sons, N.Y., 1981)
Part II
83
Chapter 5
Solving Equations
f (x) = 0
84
CHAPTER 5. SOLVING EQUATIONS 85
If we think of x as the next value xn+1 of the iteration (and x0 as the previous
one, xn ), we obtain
f (xn )
xn+1 = xn − 0 (5.2)
f (xn )
Newton’s method can often converge impressively quickly (in a few steps), partic-
ularly if the iteration starts sufficiently close to root. The meaning of “sufficiently
close” and “impressively quick” depends on the problem at hand. When one se-
lects an initial value too far away from the root (not “sufficiently close“ enough)
Newton’s method can unfortunately fail to converge completely without the user
noticing it.
For an illustration of an iterative step of the Newton method see Fig. 5.1.
f (xn ) − f (xn−1 )
f 0 (xn ) ≈
xn − xn−1
The secant method requires two different start values x0 and x1 (as opposed to
only one initial value for the Newton method). The start values do not have to be
as close to the solution as in the Newton method but the secant method does not
converge as fast as the Newton method. For an illustration of the secant method
see Fig. 5.2.
CHAPTER 5. SOLVING EQUATIONS 86
The bisection method is very simple and robust - yet relatively slow. For an
illustration of the bisection method see Fig. 5.3.
We see that while the secant method retains the last two points, the false position
method only retains two points that contain the root. For an illustration of the
false position method see Fig. 5.4.
CHAPTER 5. SOLVING EQUATIONS 87
with ~ej the unit vector in the direction j. Insert this J into (5.3) and iterate.
√
hj should be chosen such that hj ≈ xj , where is the machine precision (e.g.
10−16 for a 64-bit computer)
There are also gradient methods such as the “steepest descent method” or the
“conjugate gradient method”, which we are not going to go into.
Chapter 6
First order ordinary differential equations (ODE) and initial value problems can
be written as
dy
= f (y, t) with y(t0 ) = y0 (6.1)
dt
If we want to solve an ODE numerically, we have to discretize time so that we
can advance in time steps of size ∆t.
6.1 Examples
We see examples of ODEs around us every day. The walls around us have slightly
radioactive material in them which obeys the equation of radioactive decay
dN
= −λN
dt
with the solution N = N0 e−λt . Another everyday example is the cooling of coffee
which obeys the equation
dT
= −γ(T − Troom )
dt
How do we solve such equations numerically? Let us look at some methods,
starting out with the Euler method.
89
CHAPTER 6. ORDINARY DIFFERENTIAL EQUATIONS 90
3. Advance linearly for ∆t with the derivative at the initial value as the slope:
4. Take the point reached in the previous step as new initial value and repeat
steps 2-3.
We consider only the first two terms of the Taylor expansion and drop all higher
order terms:
dy
y(t0 + ∆t) = y(t0 ) + ∆t · (t0 ) + O((∆t)2 ) = y(t0 ) + ∆t · f (y0 , t0 ) +O((∆t)2 )
dt | {z }
≡y(t1 )≡y1
This corresponds to a linearization around (t0 , y0 ). One time step (with tn+1 =
t0 + n · ∆t) in the Euler method corresponds to
yn+1 = yn + ∆t · f (tn , yn )
The error is thus accumulated additively over T, and we find for the whole interval
the global error
T
m · O((∆t)n ) = O((∆t)n ) = O((∆t)n−1 )
∆t
and we therefore say that the method is globally of order (n − 1). Let us now
apply this formalism to the Euler method.
The Runge-Kutta methods are a generalization of the Euler method, but they
achieve the same accuracy as the Euler method for much larger time steps. There-
fore, the Runge-Kutta methods are numerically less expensive (yet more compli-
cated to implement).
Formally, the Runge-Kutta methods are derived using a Taylor expansion for
y(t + ∆t) keeping all terms up to order (∆t)q :
(∆t) dy (∆t)2 d2 y
y(t + ∆t) = y(t) + + · 2 + O((∆t)3 )
1! dt 2! dt
We can now formulate the iteration recipe for the 2nd order Runge-Kutta method:
1. Perform an Euler step of size ∆t
2
, starting at the initial value yi (t0 ):
1 1
yi t + ∆t = yi (t) + ∆tf [yi (t), t]
2 2
This is not the most commonly used Runge-Kutta method though. Most appli-
cations using Runge-Kutta have an implementation of the 4th order Runge-Kutta
method.
1. Define 4 coefficients:
k1 = f (yn , tn )
f yn + 12 ∆t · k1 , tn + 12 ∆t
k2 =
f yn + 12 ∆t · k2 , tn + 12 ∆t
k3 =
k4 = f (yn + ∆t · k3 , tn + ∆t)
2. Calculate the next step using a weighted sum of the defined coefficients:
1 1 1 1
yn+1 = yn + ∆t · k1 + k2 + k3 + k4 + O((∆t)5 ) (6.8)
6 3 3 6
As you can see, the weighting factors are chosen in such a way that the sum
of them is 1: 61 + 13 + 31 + 16 = 1
This method is globally of order 4 and locally of order 5. The selection of the
weighting factors is not unique (see section 6.3.4).
with
i−1
X
ki = f (yn + ∆t · βij kj , tn + ∆tαi ) and α1 = 0
j=1
We can conclude that this method uses multiple evaluation points for the function
f , leading to a more accurate computation. One might wonder how the weights
and the coefficients can be determined. These are described in the Butcher array1 :
α2 β2,1
α3 β3,1 β3,2
.. .. ..
. . .
αq βq,1 βq,2 ... βq,q−1
ω1 ω2 ... ωq−1 ωq
As you can see, all the parameters of the general Runge-Kutta method are found
in this handy table (called Butcher array or Runge-Kutta table).
Let us remain with this array for a second and consider an example for illus-
tration: RK4 with q = 4. We know that α1 = 0 (from before) and we recall that
in the case of q = 4 we have:
1
• ω1 = 6
1
• ω2 = 3
1
• ω3 = 3
1
• ω4 = 6
0
1 1
2 2
1 1
2
0 2
1 0 0 1
1 1 1 1
6 3 3 6
The Runge Kutta method of stage 4 is of order 4. However, for higher stages, the
order does not necessarily correspond to the stage (this is the reason RK is only
commonly used up to order 4).
1
Note that in implicit methods, the coefficient matrix βij is not necessarily lower triangular
CHAPTER 6. ORDINARY DIFFERENTIAL EQUATIONS 95
If we can find such coefficients, the order of the Runge-Kutta method is at least
p.
Example: q = p = 1
This should lead to the Euler method. There is only one weighting factor, which
obviously must be 1:
Example: q = p = 2
1 df
ω1 k1 + ω2 k2 = fn + ∆t (6.12)
2 dt n
with
∂f ∂f ∂f ∂y
= + ·
∂t n ∂t n ∂y n ∂t n
The subscript n means the evaluation at the point (yn , tn ). Now insert the coeffi-
cients retrieved from (6.9):
k1 = f (yn , tn ) = fn
We can define rules for the weighting factors to derive their values:
CHAPTER 6. ORDINARY DIFFERENTIAL EQUATIONS 96
• The first rule holds for all Runge-Kutta methods: the sum of the weighting
factors must be 1.
ω1 + ω2 = 1
• We obtain
∂f the second rule by comparing the coefficients in (6.12): we notice
1
that ∂t n shows up with a prefactor of 2 . In order to get the same factor
on the left hand side, we require
1
ω 2 · α2 =
2
We have found three rules for four parameters. Therefore, the selection of param-
eters fulfilling all conditions is not unique. However, all choices deliver a method
of the demanded order, by construction.
However, that is not all that can be done with errors: Imagine we knew the exact
error (i.e. the difference between our computed result and the true result). We
would then be able to solve the problem exactly after only one step! Unfortunately,
we cannot calculate the real error, but we can try to estimate it and adapt our
method using the estimated error. The predictor-corrector method discussed in
this section will implement this idea to improve the previously discussed methods.
where Φ denotes the evolution operator of the method. By inserting (6.15) into
(6.14) we get
2δ
y(t + ∆t) = y2 + p+1 + O((∆t)p+2 ) (6.16)
2 −2
which is a better method of getting the next point, because the error is one order
higher than before.
• We use large time steps in domains where the solution varies only slightly
(i.e. the error is small)
• We use small time steps in domains where the solution varies a lot (i.e. the
error is large)
CHAPTER 6. ORDINARY DIFFERENTIAL EQUATIONS 98
First, we define the largest error that we want to accept, δexpected and we then
measure the real error δmeasured . The time step can then be defined as
1
p+1
δexpected
∆tnew = ∆told (6.17)
δmeasured
because δ ∝ (∆t)p+1
y c (t + ∆t) = y p + c0 δ
c 2 p
d2 y
dy
2
(t + ∆t) = + c2 δ
dt dt2
3 c 3 p
dy dy
3
(t + ∆t) = + c3 δ
dt dt3
with the so called Gear coefficients
3 3 1
c0 = , c2 = , c3 =
8 4 6
These are obtained in a similar way to the RK coefficients in 6.3.4 by requiring the
method to be of a certain order. There are also higher order predictor-corrector
methods, but the complexity increases very quickly. To get an impression of the
ensuing complexity, let us quickly look at the 5th order predictor-corrector method:
Of course, what we know so far is still true even for the 5th order; We have
d~r0
~r1 = (δt)
dt
2
1 2 d ~r0
~r2 = (δt)
2 dt2
... n
1 n d ~r0
~rn = (δt)
n! dtn
and the predictor is then given by
p
~r0 (t + δt) 1 1 1 1 1 1 ~r0 (t)
~r1p (t + δt) 0 1 2 3 4 5 ~r1 (t)
p
~r2 (t + δt) 0 0 1 3 6 10
~r2 (t)
~r3 (t + δt) =
p
0 0 0 1 4 10
~r3 (t)
p
~r4 (t + δt) 0 0 0 0 1 5 ~r4 (t)
~r5p (t + δt) 0 0 0 0 0 1 ~r5 (t)
d2 r
= f (r) ⇒ r2c = 2f (r0p ) ⇒ ∆r = r2c − r2p
dt2
The corrector is
c p
~r0 (t + δt) ~r0 (t + δt) c0
~r1c (t + δt) ~r1p (t + δt) c1
~r2 (t + δt) ~r2p (t + δt) c2
c
~r3 (t + δt) ~r3 (t + δt) + c3 · ∆~r
c = p
~r4 (t + δt) ~r4p (t + δt) c4
c
and we see that we need more coeffcients. (Please note that the dot product is to
be interpreted as a multiplication which pulls the ∆~r vector into each entry of the
Gear coefficient vector, as we are dealing with vectors with vector entries). These
Gear coefficients are found in the following table:
As we can see from this example of a 5th order PC method, the complexity in-
creases impressively fast.
CHAPTER 6. ORDINARY DIFFERENTIAL EQUATIONS 101
• If we choose the time step to be small, the computation will become need-
lessly slow
• If we choose the time step to be large, the errors will result from approxi-
mations
If we choose the time step “just right”, then the errors are acceptable while the
speed does not needlessly suffer.
We see that Adams-Moulton approximates the solution very well while Euler with
a step size of 18 oscillates in a way that is in no way characteristic of the solution.
Even worse, Euler with a step size of 14 leaves the range of the graph for good.
If we have a system
~y 0 (t) = f~(~y (t), t)
then the system is called stiff if the Jacobi matrix has at least one large negative
eigenvalue. We then need to solve with an implicit method to avoid instabilities.
CHAPTER 6. ORDINARY DIFFERENTIAL EQUATIONS 103
Literature
• G.E. Forsythe, M.A. Malcolm and C.B. Moler, “Computer Methods for
Mathematical Computations” (Prentice Hall, Englewood Cliffs, NJ, 1977),
Chapter 6
with the solution v(x, y) = f (x) as in this example v(x, y) has no y-dependence.
Keeping this rather trivial example in mind, we would like to find a more general
expression to characterize partial differential equations so that we are able to work
with just about any PDE.
104
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 105
b(x, t)2
a(x, t)c(x, t) − >0 (7.1)
4
2. A PDE is parabolic, if
b(x, t)2
a(x, t)c(x, t) − =0 (7.2)
4
3. A PDE is hyperbolic, if
b(x, t)2
a(x, t)c(x, t) − <0 (7.3)
4
Let us apply this knowledge to a couple of examples.
To illustrate this point, let us try to identify the Poisson and the Laplace equation:
∆Φ = 0, ∇n Φ(x)|Γ = Ψ0
~ ∇~
∇( ~ u(~x)) + (1 − ν)∆~u(~x) = 0 (7.4)
where ~u(x) = (u1 (x1 , ..., xn ), ..., un (x1 , ..., xn )) is a vector of displacements and ν
is the Poisson ratio, which describes how much the material gets thinner in two
dimensions if you stretch it in the third one.
∂ 2 u(~x, t)
= cp 2 ∆u(~x, t) (7.5)
∂t2
with the initial condition
u(~x, t0 ) = ũ0 (~x)
The fixed constant cp corresponds to the propagation speed of the wave, e.g. the
speed of sound for acoustic waves. We see that when we consider the coefficients
in the general form of a PDE, only the following coefficients are non-zero:
As all other coefficients are zero, we see that we may arbitrarily choose the sign
of a and c, respecting that they appear on opposite sides of the equation and thus
have opposite signs. The prefactor a(x, t) (prefactor of ∆u) is minus the square
of the propagation speed of the wave and the prefactor c(x, t) is one, so we obtain
(b(~x, t))2
a(~x, t)c(~x, t) − = −c2 < 0
4
and we have proven that the wave equation really is hyperbolic.
While the equations give great solutions that accurately describe systems, one
needs to take into consideration one of the major disadvantages: they are very
hard to solve, particularly for bigger systems.
The Navier-Stokes equations in vector form for an incompressible fluid and con-
stant viscosity (as well as no other body forces) are
∂~v ~ ~ + µ∆~v , ~v=0
ρ + ~v ∇ · ~v = −∇p ∇~ (7.6)
∂t
~ v = 0 expresses the fact that we are looking at a zero divergence
The condition ∇~
field; as you may remember from electrodynamics, a vector field ~u satisfying
~ u = 0 may be written as ~u = ∇
∇~ ~ ∧A ~ (since ∇
~ · ~u = ∇
~ · (∇
~ ∧ A)
~ = 0) and thus
has neither sources nor sinks (such as the magnetic field for which there are no
magnetic monopoles). In the context of fluid motion, the condition ∇~ ~u = 0
corresponds to mass conservation (further details are found in section 7.7.4).
Later on in this chapter we shall come back to the Navier Stokes equations, but
first we need to look a bit more into how to solve PDEs on a computer.
∂Φ Φ(xn+1 ) − Φ(xn )
= + O(∆x) (two-point formula) (7.7)
∂x ∆x
Φ(xn ) − Φ(xn−1 )
= + O(∆x) (two-point formula) (7.8)
∆x
Φ(xn+1 ) − Φ(xn−1 )
= + O((∆x)2 ) (three-point formula) (7.9)
2∆x
One can conclude that the accuracy increases if more points are taken. One can
even go so far as to use more than three points to improve the accuracy further.
∂ 2Φ
∂ ∂Φ (7.7) ∂ Φ(xn+1 ) − Φ(xn )
= = + O(∆x)
∂x2 ∂x ∂x ∂x ∆x
(7.8) 1 Φ(xn+1 ) − Φ(xn ) Φ(xn ) − Φ(xn−1 )
= − + O((∆x)2 )
∆x ∆x ∆x
Φ(xn+1 ) + Φ(xn−1 ) − 2Φ(xn )
= + O((∆x)2 )
(∆x)2
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 110
Where the ∆ on the LHS denotes the Laplacian whereas on the RHS, ∆ stands
for the error. The expression can be seen as a “pattern” that is used on the grid,
which creates the value of the derivative at the center point by adding up all the
neighbors and subtracting 4 times the value of the center point.
where we need to subtract the center element six times as there are six neighbors
(for the sake of readability, the (∆x)2 has been multiplied over to the LHS).
∆Φ(~x) = 4πρ(~x)).
First, we would like to analyze the one-dimensional case with Dirichlet boundary
conditions. The Poisson equation in one dimension is
∂ 2Φ
= ρ(x) (7.13)
∂x2
In order to solve this equation, we have to discretize the one-dimensional space; to
this end, we pick N points on a given interval: xn with n = 1, . . . , N . As a short
hand, we shall use Φn for Φ(xn ). If we insert the 1D-Poisson equation (7.13) into
the definition of the second derivative (7.10) and multiply with (∆x)2 , we get the
discretized equation:
Φn+1 + Φn−1 − 2Φn = (∆x)2 ρ(xn ) (7.14)
The Dirichlet boundary conditions are incorporated with
Φ0 = c0 and ΦN = c1 .
This discretized equation is a set of (N − 1) coupled linear equations, which can
be written as a matrix in the following way (with ρ(x) ≡ 0):
−2 1 0 ··· 0 Φ1
c0
.. .
1 −2 1 . .. 0
0 ...
... ... .. ..
0 ·
. = − . (7.15)
. .
0
.. .. 1 −2 1
0 ··· 0 1 −2 Φ N −1 c 1
We see that this boils down to solving a system of linear equations. The system
can be described by
AΦ~ = ~b
Furthermore, independent of the system size, we notice that each row and column
contains only five non-zero matrix elements (see e.g. (7.17)), and is thus not too
“crowded” - a sparse matrix. We have seen that in order to find the solution Φ∗
we need to invert this matrix; this is done via the LU decomposition.
We have seen that after discretizing a PDE, one is left with a system of linear
equations; therefore, we need to have a closer look at how to solve such systems.
Now that we have decomposed A into three different matrices, let us reap the
benefits of it!
Let us start out with the formal definition of the error; quite trivially, the er-
ror at a given time step t is the difference between the exact solution A−1~b and
the approximate solution Φ(t) we have obtained at that time step:
We thus see that from this simple definition (and a bit of plug and play) we have
derived an expression that we can rewrite as
~δ(t + 1) = −Λ~δ(t) (7.22)
with the evolution operator Λ of the error (note that Λ is a matrix). The evolution
operator establishes a link between the error at one time step and the next (and
consequently between the current one and the previous one). We can simply
identify Λ in the previous calculation and find
Λ = D−1 (U + L)
After n time steps, the error will be the product of evolution operators Λ and the
initial “distance”; One can immediately draw some conclusions from this finding:
• As we want to get closer to the solution, the error has to decrease. Conse-
quently, the largest eigenvalue λ of Λ needs to be smaller than one, |λ| < 1.
Generally speaking, λ satisfies 0 < |λ| < 1.
• The smaller the largest absolute eigenvalue λ is, the faster the method will
converge.
If we consider enough time steps n, we may write the approximate solution as the
sum of the exact solution with an error:
~n ≈ Φ
Φ ~ ∗ + λn ·~c (7.23)
Of course one issue has not been addressed yet - how do we find λ in the first
place? Given that we pick up one factor of λ at each time step, we simply think
of λ as the ratio between two time steps and thus conclude that
~ + 1) − Φ(n)k
kΦ(n ~ λn+1 − λn
≈ n =λ (7.24)
~
kΦ(n) ~ − 1)k
− Φ(n λ − λn−1
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 115
We have mentioned that there is a real error δ and that there is a second error
δ 0 (which was defined in (7.21) ). Let us try to find a link between the two. We
start out by using the approximation (7.23) in the definition of the error:
~ ∗ − Φ(n)||
||Φ ~ ~∗ −Φ
(7.23) ||Φ ~ ∗ − λn · ~c|| ||~c|| n
δ(n) = ≈ = λ
~
||Φ(n)|| ~
||Φ(n)|| ~
||Φ(n)||
~ + 1) − Φ(n)||
||Φ(n ~ ~ ∗ + λn+1 · ~c − Φ
(7.23) ||Φ ~ ∗ − λn · ~c|| ||~c|| n
0
δ (n+1) ≡ ≈ = λ |λ−1|
~
||Φ(n)|| ~
||Φ(n)|| ~
||Φ(n)||
| {z }
δ(n)
~
||Φ(n) ~ − 1)|| ||Φ(n
− Φ(n ~ + 1) − Φ(n)||
~
1−λ= −
~
||Φ(n) ~ − 1)|| ||Φ(n)
− Φ(n ~ ~ − 1)||
− Φ(n
| {z } | {z }
1 λ
~ + 1) − Φ(n)||
||Φ(n ~ ~
||Φ(n) ~ − 1)||
− Φ(n
δ(n) ≈ (7.26)
~ ~ ~ ~ ~
||Φ(n)|| ||Φ(n) − Φ(n − 1)|| − ||Φ(n + 1) − Φ(n)||
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 116
Now that we understand the error, let us apply the Jacobi method to our example,
the Poisson equation (7.12). We consider the case of a two dimensional grid and
start out with any Φij (0). To get from one iteration step n to the next, the
procedure is as follows
1
Φij (n + 1) = (Φi+1,j (n) + Φi−1,j (n) + Φi,j+1 (n) + Φi,j−1 (n)) − bi,j (7.27)
4
and the exact solution is given by
1 ∗
Φ∗i,j = Φi+1,j + Φ∗i−1,j + Φ∗i,j+1 + Φ∗i,j−1 − bi,j
4
What is crucial in formula (7.27) is its recursive character - we have to save
the result at time step n to compute the next result, we cannot simply over-
write its values! It is this characteristic property of the Jacobi method which we
will want to correct in the next method (while improving the error, of course).
While this may seem somewhat weird at first sight, given that for most elements,
the computation will include already updated entries and some that are not up-
dated yet, it does offer the advantage of reduced memory requirements.
Let us formalize the discussion a bit. We decompose our matrix A in the same
way as before (see (7.19) ) but we combine the elements in a different way:
When we look at the error (and carry out the same calculation as for the Jacobi
method) we find that the error evolution operator is given by
Λ = (D + U )−1 L
In a nutshell: We have found a method that not only reduces memory require-
ments (by eliminating the need for a backup) but also converges faster. How can
we improve this further?
~r = A~δ = A(A−1~b − Φ)
~ = ~b − AΦ
~ (7.30)
Clearly, we do not have to invert the matrix A to get the residual. That is precisely
why we use it instead of the error. If the residual is small, the error is also going
to be small, so we can minimize the functional
~ =Φ~∗
T −1 0 if Φ
J = ~r A ~r = (7.31)
> 0 otherwise
Let us denote by Φi the ith approximation of the solution and let us define
~ i + αi d~i
~ i+1 = Φ
Φ
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 119
~ i being the start value or the value of the last iteration, d~i the direction of
with Φ
the step and αi the step length. If we insert this into (7.32), we obtain
d~ti r~i
ᾱi =
d~t Ad~i
i
Of course ᾱi is to be calculated for each step. The most difficult part of the
gradient methods is the computation of the direction of the step. Consequently,
gradient methods are classified by this feature.
2. Evaluate
~ui = A~ri
and store the result (we need it twice). Calculate the length of the step:
~ri2
αi =
~ri~ui
3. Advance αi in the direction of d~i (which is the same as ~ri ) and compute the
value of the function at this point:
~ i+1 = Φ
Φ ~ i + αi~ri
The vector ~ui is the temporary stored product A~ri so that we need to compute
it only once per step since this is the most time consuming part of the algorithm
and scales with N 2 , where N is the number of equations to be solved. If A is
sparse, this matrix-vector product is of order N .
While this method is already very promising, we still want to improve it as the
situation as in Fig. 7.5 is somewhat unsettling and inefficient.
This can be achieved if we take the new direction conjugate to all previous ones
using the Gram-Schmidt orthogonalization process:
i−1 ~ T
X dj A~ri
d~i = ~ri − d~j (7.34)
j=1 d~ T Ad~j
j
Then, all directions d~i are conjugate to each other (with respect to A acting as a
“metric”):
d~iT Ad~j = δij
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 121
It needs to be noted at this point that the conjugate gradient method, and gradient
methods in general, are only a valuable option for positive definite and symmetric
matrices A.
1. Initialize with some vector Φ~ 1 and compute the first residual. Then, take
the residual as the direction of your first step:
~r1 = ~b − AΦ
~ 1, d~1 = ~r1
ri T d~i
αi = c~
5. Update the residual for the error estimation and for the next step:
~ri+1 = ~b − AΦ
~ i+1
7. Repeat steps 2 to 6.
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 122
However, this method does not always converge and can become unstable. The
procedure is as follows:
1. Initialize:
r~1 = ~b − AΦ~ , d~1 = r~1
˜
r~˜1 = ~b − At Φ
~ , d~1 = r~˜1
2. Iterate:
˜
~ri+1 = ~ri − αi Ad~i , ~r˜i+1 = ~r˜i − αi AT d~i , α = c~riT ~ri
˜
d~i+1 = ~ri + α̃i d~i , d~i+1 = ~r˜i + α̃i d~i , α̃ = c̃~riT ~ri
˜
with c = (d~Ti Ad~i )−1 and c̃ = (d~T Ad~i )−1
i
3. Stop as soon as
n
X
~riT ~ri < ⇒ ~n = Φ
Φ ~1 + αi d~i
i
7.5.3 Preconditioning
When using one of the previous methods to solve a system of linear equations, one
may notice poor performance because the methods converge very slowly. This
is the case if the matrix is badly conditioned: The diagonal elements are almost
equal to the sum of the other elements on their row. The solution to this problem
is called preconditioning.
The idea is simple: We find a matrix P −1 which is cheap to compute and de-
livers a good approximation of the inverse of the matrix of our problem. (while
the idea is simple, the process of finding such a matrix is really not!). We then
solve the preconditioned system obtained by a multiplication from the left:
P −1 A Φ ~ = P −1~b
(7.35)
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 123
1
The group of splitting methods follows the scheme
Ax = b ⇒ 0 = −Ax + b ⇒ 0 = −(A + P − P )x + b
so
P x = (P − A)x + b
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 124
If we divide a given area into very few points, we are going to get a bad res-
olution but the algorithm will finish quickly. For a very fine grid, the algorithm
may take ages but the result will be beautiful.
The strategy is to solve the equation for the error on the coarsest grid.
~rn = ~bn − AΦ
~n , ~δn = A−1~rn
~rˆn = R~rn
4. Find the error of the original lattice by using the extension operator P:
~δn+1 = P ~δˆn+1
The operator P approximates the original lattice from the coarser one that
we reached using R.
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 125
The general idea can thus be seen quite easily - we are jumping back and forth
between the complex system and the easier system with P and R
We solve the equations (using e.g. Gauss elimination if the system is small enough)
on the coarser lattice and then reproduce the original matrix out of the smaller
one, using the extension operator P (e.g. an interpolation). We can go back and
forth several times to reduce a huge system to a system that is solvable by Gauss
elimination. In this case, the error of the method is only dependent on the quality
of the restriction and extension operators!
We note that
RP ~rˆ = I ~rˆ , PR~r = I~r (7.38)
Let us consider an example of such restriction and extension operators:
• The restriction operator R takes in each direction every second entry (overall
thus one entry out of four) and calculates the matrix entry of the coarser
grid by adding up the site’s value plus the values of its neighbors. The
coarser grid has half the side length of the original one. We can write this
operator explicitly:
The nearest neighbors (nn) are weighed twice as much as the next nearest
neighbors (nnn). This is due to the fact that the diagonal entries are counted
in four “coarser” sites while the nn only contribute to two such sites.
The operators P and R fulfill one rather interesting condition, but to be able
to stomach it well we need to first talk about function spaces. Let us pick any
function living on the original grid and denote it by u(x, y). Obviously, a function
living on the original grid will take its arguments from the original grid so the
arguments are x and y (i.e. the coordinates of the original grid).
If we pick a second function living on the coarser grid and denote it by v̂(x̂, ŷ)
(using ˆ to refer to elements on the coarser grid), we see that it will take its
arguments from coordinates of the coarser grid, i.e. x̂, ŷ and not from the original
grid (i.e. x, y).
While we already know that we can change between the coarser grid and the
original grid with R and P, there is a special relation that applies to functions
living on these two grids: If we consider two functions u(x, y) (on the original grid)
and v̂(x̂, ŷ) (on the coarser grid)as introduced, we can show with a given scalar
product that the extension operator and the restriction operator are adjoint:
X X
P v̂(x̂, ŷ) · u(x, y) = h2 v̂(x̂, ŷ) · Ru(x, y)
x,y x̂,ŷ
Here, h denotes the scaling factor of the finer matrix to the coarser matrix which
is given by the coefficient of the respective number of rows. In our example h is
2.
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 127
d2 Φ
(x) = −4πρ(x)
dx2
with the Dirichlet boundary condition
Φ(x)|Γ = 0
Earlier on, we solved this equation by discretizing space, which is what we would
like to avoid. Instead, we try to expand the field Φ in terms of localized basis
functions ui (x):
∞
X N
X
Φ(x) = ai ui (x) ≈ ΦN (x) = ai ui (x) (7.41)
i=1 i=1
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 128
We approximate the exact solution Φ(x) with ΦN (x), which is the superposition
of a finite number of basis functions (instead of an infinite number as in the exact
solution). Each basis function has a coefficient ai . We can obtain the expansion
coefficients ai from (7.41) by introducing so-called “weight functions” wj (x):
N ˆ L ˆ L
X d2 u i
− ai 2 (x)wj (x)dx = 4π ρ(x)wj (x)dx , j ∈ {1, ..., N } (7.42)
i=1 0 dx 0
The simplest case is the so-called Galerkin method where we simply pick the
weight functions to be the basis functions, i.e. wj (x) = uj (x).
where we have used partial integration, and the vector bj can be read off as
ˆ L
bj (x) = 4π ρ(x)wj (x)dx (7.44)
0
Let us consider an interval [0, L] on which we are trying to solve the Poisson
equation. If we have
Φ(0) = Φ0 , Φ(L) = Φ1 (7.47)
we can use the decomposition
N
!
1 X
ΦN (x) = Φ0 (L − x) + Φi x ai ui (x)
L i=1
We are going to look into basis functions more in depth in section 7.6.7.
Picard Iteration
The Picard iteration consists of three simple steps:
d2 Φ 1
Φ0 (x) (x) = −4πρ(x)
dx2
• Iterate:
d2 Φn+1
Φn (x) (x) = −4πρ(x)
dx2
Φ(~r) ≈ c1 + c2 x + c3 y
or approximation by a paraboloid
Φ(~r) ≈ c1 + c2 x + c3 y + c4 x2 + c5 xy + c6 y 2
In the case of the paraboloid fit, we can have smooth transitions between elements
(which is not possible for the linear fit for non-trivial cases).
where we have split up the functional into a volume contribution and a surface
contribution (represented by the integral over G and Γ, respectively). This defi-
nition of E will be motivated later on.
The first step towards minimization of the functional is the determination of its
variation δE:
ˆ ˆ ˆ
δE = (∇Φδ∇Φ + aΦδΦ + bδΦ) dxdy + (aΦδΦ + βδΦ) ds
G Γ
Of course we can use Green’s theorem to modify the first term in δE (both u and
v can be identified with Φ). We obtain
ˆ ˆ ˆ
∂Φ
δE = (−∆Φ + aΦ + b) δΦdxdy + aΦ + β + δΦds = 0
G Γ ∂n
x = x1 + (x2 − x1 )ξ + (x3 − x1 )η
y = y1 + (y2 − y1 )ξ + (y3 − y1 )η
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 132
Of course we need to know how the new variables depend on the previous ones:
∂ξ y3 − y1 ∂ξ x3 − x1
= , =−
∂x D ∂y D
∂η y2 − y1 ∂η x2 − x1
= , =
∂x D ∂y D
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 133
with determinant
∂x ∂y ∂x ∂y
det(J) = − = (x2 − x1 )(y3 − y1 ) − (x3 − x1 )(y2 − y1 ) = D
∂ξ ∂η ∂η ∂ξ
We also have to transform the integration area; let us call the transformed inte-
gration area T . With this transformation, we have all ingredients to carry out the
integration with the new variables:
ˆ ˆ ˆ ˆ
f (x, y)dxdy = f˜(ξ, η)det(J)dξdη
Gj T
Let us now apply this to the example at hand instead of a general function f (x, y):
ˆ ˆ ˆ ˆ
2 2
c1 Φ2ξ + 2c2 Φξ Φη + c3 Φ2η dηdξ
Φx + Φy dxdy = (7.50)
Gj T
with the basis functions ui and their coefficients ai . However, the computer neither
has infinite memory nor infinite computing speed, so we have to select a finite
number of basis functions:
N
X
ΦN (x) = ai ui (x)
i=1
The basis functions ui are known and defined for all elements, so we only have to
compute their coefficients ai .
In the one-dimensional case, the linear basis functions are hat functions (as in
the introductory example in 7.6.2.2); these are 1 on the element on which they
are defined and 0 on every other element.
A clearer example is the two-dimensional case, where we divide the domain into
triangles (same size not required). As we have seen in the previous sections, these
triangles can be transformed back to the so called standard element, whose cor-
ners are located at (0,0), (0,1) and (1,0). The basis functions are defined on this
triangle and then transformed back to the original triangle for computation (see
previous section on coordinate transformation).
Let us start out by defining the basis functions on the standard element. In
the linear case, each basis function has value 1 in one corner and value 0 in the
other two. We can thus think of the following three basis functions:
N1 = 1 − ξ − η
N2 = ξ
N3 = η
where we have used the previously mentioned convention that the axes are called
ξ and η to distinguish them from the axes of the original triangle (with axes x
and y). A graphical representation of the linear basis functions is given in Fig.
7.10.
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 135
Instead of using linear basis functions, one may also use quadratic basis func-
tions. One then has six points on each triangle. Again, each basis function has
value 1 in one of the points and zero in all others, so we find the following six
basis functions:
N1 = (1 − ξ − η)(1 − 2ξ − 2η)
N2 = ξ(2ξ − 1)
N3 = η(2η − 1)
N4 = 4ξ(1 − ξ − η) (7.52)
N5 = 4ξη
N6 = 4η(1 − ξ − η)
We have used two notations in this section; On the one hand we introduced
the prefactors ai in the decomposition of the field Φ with basis functions ui ; on
the other, we just called the basis functions Ni (with prefactors ϕi ). In the latter
notation, we often use a short hand: we introduce the vectors N ~ and ϕ ~ , whose
~
ith components are the ith basis function (for N ) or the ith coefficient (for ϕ~ ). In
two dimensions we thus write
6
X
Φ(ξ, η) = ϕi Ni (ξ, η) = ϕ
~N~ (ξ, η)
i=1
with
ϕ
~ = (ϕ1 , ..., ϕ6 ) , ~ = (N1 , ..., N6 )
N
The functions Ni are again those of Fig. 7.11. The basis functions also depend
on the lattice (i.e. they look different for other lattices such as a square lattice).
Figure 7.10: The three linear basis functions on the standard element [2]
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 136
Figure 7.11: The six quadratic basis functions on the standard element [2]
= ϕ ~ T ~ ξN
N ~ ξt dξdη ϕ
~
T
| {z }
S1
where we have introduced the matrices S1 ,S2 and S3 on the standard triangle.
Let us weight the energy integrals Ii with the respective coefficients ci from the
coordinate transformation (see (7.51) in 7.6.6). We see in (7.50) that this is
ˆ ˆ
c1 Φ2ξ + 2c2 Φξ Φη + c3 Φ2η dξdη
c1 I1 + c2 I2 + c3 I3 =
ˆ ˆT
= (∇Φ)2 dxdy =: ϕ ~ T Sϕ
~
Gj
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 137
S = c1 S1 + c2 S2 + c3 S3 (7.53)
We thus see that the energy integral has a contribution from both the mass and
the rigidity matrix
X ˆ ˆ X
0
(∇Φ)2 + aΦ2 dxdy = ~ jT (Sj + Mj ) ϕ
E = ϕ ~j
elements j Gj elements j
So far we have not considered all terms of E yet (we still have to introduce the
so-called field term which we shall do in section 7.6.9), so the current expression
is only the “reduced energy integral” E 0 not yet the energy integral E as we know it.
Aj = Sj + Mj
or shorter
E0 = Φ~ T AΦ ~
where we have introduced the vector Φ, ~ which is a vector with vector entries. The
~ is ϕ
j-th element of Φ ~ j , the coefficient vector for the element j. One often simply
writes
~ = (~
Φ ϕj ) (7.54)
Furthermore, we introduced the matrix A which is the more general form of the
per-element Aj :
A = ⊗j Aj = ⊗j (Sj + Mj )
As previously mentioned, the expression we have obtained so far is still missing
another term, the so-called field term.
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 138
Very similarly to before, we have thus found a second contribution (the field term)
to the energy integral:
~ Φ
E = ΦA ~ + ~bΦ
~ with ~b = (~bj )
We now have found the complete expression for the energy integral, where the
first part is the contribution found in the previous section and the second part is
the field term.
∆Φ = aΦ + b
is a minimum of
X ˆ ˆ
(∇Φ)2 + aΦ2 + bΦ dxdy
E=
elements j Gj
When we stare at this equation for a bit, we recognize that there might be a
κ∆t 1
problem if the prefactor Cρ(∆x)2 of T̃ij (t) is 4 , as in that case we get a contribution
−T (xi,j , t) (from the last summand in T̃ij (t)) which cancels out the leading con-
tribution; even worse, if the prefactor is larger than 41 , the temperature will start
to jump between positive and negative new values and become unstable. This
behavior is characteristic for a parabolic equation. For stability’s sake we thus
need to avoid
κ∆t 1
2
≥
Cρ(∆x) 4
we notice that T (~x, t+∆t) appears on the RHS as well. This is suboptimal at best
as we would like to only have this term appear on the LHS. As we are dealing with
an implicit equation, we cannot solve it. We remedy this situation by discretizing
the Laplace operator.
First, we define
(using the notation previously introduced in (7.54) ) and the discretized Laplace
operator O
κ∆t
OT (xn , t) = T (xn+1 , t)+T (xn−1 , t)+T (xn+L , t)+T (xn−L , t)−4T (xn , t)
Cρ∆x2
Note that we have included the prefactors of the heat equation in the definition.
Then, the Crank-Nicolson formula becomes
1 ∆t
T (~x, t+∆t) = T (~x, t)+ OT (~x, t)+OT (~x, t+∆t) + W (~x, t)+W (~x, t+∆t)
2 2Cρ
where the factor of 21 stems from the averaging over T . One then pulls this to the
other side of the equation so that the RHS only contains values at time t and the
LHS only contains values at time (t + ∆t):
~ ~ ∆t ~ ~
(2 · I − O)T (t + ∆t) = (2 · I + O)T (t) + W (t) + W (t + ∆t)
Cρ
where I is the unity operator. We can then only solve the equation by inverting
the operator (2 · I − O); we already know how to carry out inversions as we have
done it already for elliptic problems. The inverted operator is
B = (2 · I − O)−1
space with opposite signs; a popular example of a hyperbolic equation is the wave
equation. s
2
∂ y k
2
= c2 ∇2 y with c =
∂t ρ
The classical solution is to go to Fourier space (where we find frequencies/modes).
We can use a finite difference scheme with finite time steps by discretizing the time
derivatives:
y(xn , tk+1 ) + y(xn , tk−1 ) − 2y(xn , tk )
≈ c2 ∇2 y(xn , tk )
∆t2
When we insert the discretized Laplacian and separate functions of (tk+1 ), we find
The Navier-Stokes equations deal with constant energy (T const) so we still need
to conserve mass and momentum. These two conservation laws can be found in
the Navier-Stokes equations, and we shall try to find out how they enter and how
the equations resemble Newton’s equation.
These are the equations of motion for an incompressible fluid. Let us look at the
LHS of (7.55): We see that we find the full time derivative of the velocity field:
∂~v ~ v
+ (~v ∇)~
∂t
|{z} | {z }
B
A
• B: The second contribution is the convective part. This term arises when
the velocity field is convected with a fluid, i.e. when mass points take the
velocity vectors with them. This contribution is non-linear.
• C: The first contribution stems from the force arising from a pressure gra-
dient; this is the driving force.
So far, we have only talked about the velocity; clearly, aside from the velocity field
~v another field makes an appearance in the Navier-Stokes equations: the pressure
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 143
field p. We thus have 4 unknowns (vx , vy , vz , p) but only three equations that we
have discussed so far. The fourth equation is the condition
~v=0
∇~
which expresses the fact that we are looking at incompressible fluids. This equa-
tion is not just a “sidekick”, it is central as it expresses mass conservation. We
thus have four equations for four unknowns. Before continuing, we still need initial
values and the values on the boundaries:
• The large viscosity limit (or small system limit, small velocity limit, small
Reynolds number limit): In this first case, we obtain the Stokes equation
which describes a Stokes flow (typical for biological systems). It is a linear
~ v≈0
equation, and neglects term B, i.e. (~v ∇)~
As the attentive reader might have guessed, we are not going to consider the sec-
ond limit.
CFD has an impressive spectrum of methods to offer, in fact there are well over
100 methods to solve this kind of equations.
Instead of looking at every single one, let us pick just one, the penalty scheme,
and try to solve our equations with it.
Penalty Scheme
We have to solve (7.55) and (7.56) simultaneously. The second equation will be
treated as a “penalty” (nomen est omen).
Fortunately, the RHS does not depend on the next time step. Furthermore, we
recognize the Poisson equation: We can find pk+1 from velocities at earlier time
steps alone. To accomplish this, one needs boundary conditions for the pressure
which one obtains by projecting the Navier-Stokes equations on the boundary,
which must be done numerically.
One places the pressures at the center of the cell (with lattice spacing h) and
the velocity components at the centers of the sides of the cell (see Fig. 7.12).
The velocity in x direction (vx ) is found on the left and right sides of a given
cell i, j (on the left vx,i−1/2,j and on the right vx,i+1/2,j ) while the velocity in y
direction (vy ) is located on the top and bottom sides of a given cell i, j (on the
top vy,i,j+1/2 , on the bottom vy,i,j−1/2 ). This is illustrated in Fig. 7.13, where the
color code indicates whether the entry corresponds to vx (orange) or vy (green).
Furthermore, we see in the given examples of the velocities that the indices are
adapted. The position in both directions is indicated with respect to the lattice
spacing h, i.e. if we move from cell i, j over to the right by h, we arrive at the
cell (i + 1), j; the side separating the two positions obviously has the coordinates
(i + 12 ), j.
The pressure locations are referred to by their indices i, j. Let us consider the
pressure gradient:
~ 1
(∇p) 1 = (pi+1,j − pi,j )
x,i+ ,j
2 h
We see that the pressure gradient is defined on the sides of the cells (unlike the
pressure itself!) as a function of the adjacent pressures pi+1,j and pi,j .
If we consider the gradient of this expression, we are going to move on the lattice
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 146
again,
1
∇2 pi,j = (pi+1,j + pi−1,j + pi,j+1 + pi,j−1 − 4pi,j )
h2
and we are in the center of a cell again. When we consider
~ v∗ = 1 v∗ ∗ ∗ ∗
∇~ i,j x,i+1/2,j − vx,i−1/2,j + vy,i,j+1/2 − vy,i,j−1/2
h
we see that this expression also comes to lie in the center of a cell (just like a
pressure entry). Similarly, we have
~ v∗
∇~
∇2 pk+1 =
∆t
We can thus conclude that the pressure pk+1 is solved in the cell centers.
However, if we consider
~ k+1 − µ∇2~vk − (~vk · ∇)~
~vk+1 = ~vk + ∆t −∇p ~ vk
we can conclude that the equation for the velocity components is solved on the
sides.
CHAPTER 7. PARTIAL DIFFERENTIAL EQUATIONS 147
Going back to the original equation, there is still one contribution that we have not
~ v . If we take its first entry (~v ∇)v
mentioned so far: (~v ∇)~ ~ x , we have to discretize
the following expression:
~ x = vx ∂ vx + vy ∂ vx
(~v · ∇)v (7.59)
| ∂x
{z } | ∂y {z }
≡E ≡F
We discretize (7.59) step by step, starting out with the x coordinate (correspond-
ing to E in (7.59)):
x
x ∂v
x
1 x x
v = vi+3/2,j · vi+3/2,j − vi−1/2,j
∂x
i+1/2,j 2h
Of course we can do the very same for the y component (i.e. F in (7.59))
x
y ∂v 1 y
y y y
v = v + vi,j−1/2 + vi+1,j+1/2 + vi+1,j−1/2
∂y i+1/2,j 4 i,j+1/2
1 x x
· vi+1/2,j+1 − vi+1/2,j−1
2h
1
The prefactor of 4
stems from the fact that we are averaging over all four y com-
ponents.
Let us summarize the position of the entries we have encountered on our odyssey
around the lattice:
Figure 7.14: Stochastic rules for collisions (respecting mass and momentum con-
servation) [9]
Aside from academic interest, lattice methods have also found applications in
the industry. Car manufactures are for instance interested in the calculation of
the air flow around cars. Another less commercial application is illustrated in Fig.
7.15.
Lattice gas automata are particularly popular when one faces messy boundary
conditions; obviously, this includes a lot of applications (e.g. the petroleum in-
dustry is very interested in how to force oil out of rocks).
Figure 7.15: Air flow around a given object (dinosaur in this example) [15]
• Sedimentation
• Raising of a bubble
Of course this list is not exhaustive - there are many more applications (in fact
the range of applications is quite impressive).
Bibliography
[2] Of unknown source (if you know the source, please let us know!)
[8] robodesign.ro
[11] Herrmann H.J., Landau D.P., Stauffer D., New universality class for ki-
netic gelation, Phys. Rev. Lett. 49, 412-415 (1982)
150
BIBLIOGRAPHY 151
[19] http://www.stephenwolfram.com/