Sandpile Model for Self-Organized Criticality

The sandpile model, or Bak–Tang–Wiesenfeld sandpile, was developed to demonstrate how a simple system can bring itself to a critical state without the need for careful tuning.
June 23, 2017—Leo McElroy

Setting Up the Model

Our model involves placing sand on a table and adding grains one by one as we observe collapses. Let’s start by making our table.
We begin by picking our table size:
In[]:=
gridSize:=8
Now let’s generate a matrix to represent our table:
In[]:=
sandTable=Table[0,{i,1,gridSize},{j,1,gridSize}];​​ArrayPlot[sandTable,MeshTrue]
Out[]=
Let’s seed the table with a blanket of sand that can be stacked one to four grains high in each cell.
Let’s represent height with colors so blue corresponds to one grain, green to two grains, yellow to three grains and red to four grains:
In[]:=
heightColors={1.Blue,2.Green,3.Yellow,4.Red}
Out[]=
1.
,2.
,3.
,4.

Now let’s blanket the table with sand at random heights:
In[]:=
sandTable=Table[N@RandomInteger[{1,4}],{i,1,gridSize},{j,1,gridSize}];​​ArrayPlot[sandTable,ColorRulesheightColors,MeshTrue]
Out[]=
Next we will place a grain of sand in a random cell on the table. If that cell gets taller than four grains of sand, it will topple, losing four grains and giving one grain to each neighbor that shares an edge.
First we select a cell. We will distinguish this cell with a white dot:
In[]:=
xy={RandomChoice[Range[1,gridSize]],RandomChoice[Range[1,gridSize]]}​​printArray:=ArrayPlot[sandTable,ColorRules->heightColors,MeshTrue,Epilog{White,Disk[{xy[[2]]-.5,gridSize-xy[[1]]+.5},.2]}]​​printArray
Out[]=
{8,8}
Out[]=
Now we will add a grain of sand to the cell we selected. If this made the cell larger than five grains tall, then the cell will topple and cause an avalanche:
In[]:=
addGrain[xy_List]:=sandTable=ReplacePart[sandTable,{xy[[1]],xy[[2]]}sandTable[[xy[[1]],xy[[2]]]]+1];​​addGrain[xy];​​printArray
Out[]=

Avalanches and Moving Sand

Running the Model

Analyzing the Data and Power Law Distribution

1/f
Noise

So Where Is the Criticality?

AUTHORSHIP INFORMATION
Leo McElroy
6/23/17