## Percolation Threshold on a Square Lattice

Manfred Schroeder touches on the topic of percolation a number of times in his encyclopaedic book on fractals (Schroeder, M. (1991) Fractals, Chaos, Power Laws: Minutes from an Infinite Paradise. Percolation has numerous practical applications, the most interesting of which (from my perspective) is the flow of hot water through ground coffee! The problem of percolation can be posed as follows: suppose that a liquid is poured onto a solid block of some substance. If the substance is porous then it is possible for the liquid to seep through the pores and make it all the way to the bottom of the block. Whether or not this happens is determined by the connectivity of the pores within the substance. If it is extremely porous then it is very likely that there will be an open path of pores connecting the top to the bottom and the liquid will flow freely. If, on the other hand, the porosity is low then such a path may not exist. Evidently there is a critical porosity threshold which divides these two regimes.

This situation can be modelled on a regular lattice where each of the lattice sites is either occupied (with probability p) or vacant (with probability 1-p). This is known as the site percolation problem. The related bond percolation problem can be posed in terms of whether or not the edges between neighbouring sites are open or closed. As we will see there is a well defined range of p (centred on a threshold value p_{c}) for which the probability of percolation decreases rapidly from one to zero.

The percolation problem has been studied on a menagerie of lattice types but we will focus on the simplest, the square lattice.

# Creating the Lattice

First we will load a few handy libraries and set up some constants.

Next a function to generate and populate a lattice, which takes as arguments the width of the lattice and the occupation probability.

# Visualising the Lattice

In the text representation of the lattice the occuppied sites are represented by a 1, while a 0 indicates a vacant site.

A graphical representation makes things a lot clearer.

# Flow Through the Lattice

Now we need to check for flow through the lattice. We will use a recursive depth first search. Everything goes into a single function. The first argument is the grid. The second and third (optional) arguments are the row and column indices for a particular cell in the grid. If the latter arguments are omitted then the function loops through each of the cells in the top row of the grid. If a particular cell is specified, and it is not already occupied, then it is marked as being part of a flow path. The function then recursively considers each of the nearest neighbour cells.

The flow path can then be visualised.

The grid on the left does not percolate while the one on the right does.

# Checking for Percolation

Finally we can determine whether a given grid percolates by checking whether or not the flow makes it to the bottom of the grid.

# Finding the Percolation Threshold

Finding the percolation threshold is a little numerically intensive, so it makes sense to take advantage of parallel execution.

We define some parameters for the calculation: the dimensions of the lattice and the number of replicates for each value of the occupation probability, p.

Although we will be considering the full range of possible values for p, it makes sense to focus our attention on those values closer to the threshold. For each value of p we randomly generate a number of grids and check whether or not each one percolates.

Summary statistics are then compiled to give the percolation probability as a function of p.

A logistic model is fitted to these data and the threshold value for p is estimated.

That compares pretty well with the reference results for the 4^{4} square lattice.

Finally, all of this is put together in a plot.