# Sandpile 3D

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

### WHAT IS IT?

This model illustrates a phenomenon known as self-organized criticality. The world is filled with sand organized in columns. Falling sand stacks on top of the sand that is already there. Eventually a column will fall over because it gets too high, and the sand will spill into the surrounding area. This is called a cascade. When a falling column causes other columns to fall, the series of cascades is called an avalanche. The size of an avalanche is the number of cascades that occur from one grain of sand falling.

### HOW IT WORKS

Initially the world is either empty or full, at each step of the model a grain of sand drops from the top of the world. The sand continues to fall until it hits another grain of sand; at that point it rests where it is and checks to see if it is the fourth grain of sand in the current pile. If it is it causes a cascade, which distributes the four grains of sand in the current pile in the four cardinal directions. These grains of sand then in turn check to see if they make their new sandpile taller than three grains, if they do then they cascade as well. If a particle of sand goes over the edge of the world then it disappears forever.

### HOW TO USE IT

SETUP EMPTY initializes the model with no sand in it.

SETUP FULL initializes the model with all the piles at random heights but below the threshold of four.

GO ONCE will add one particle of sand to the world.

GO will continue adding particles of sand at random locations.

### THINGS TO NOTICE

The graph illustrates the relationship between the logarithm of the size of cascades and the logarithm of the frequency of their occurrence. Per Bak and others pointed out that in this model this graph would eventually become a straight line. A straight line on a log-log graph is indicative of a power law, which means that the relationship between the x and y axes is of the form y = A^Bx. The fact that this power law occurs regardless of the starting circumstances and despite the fact that the process is random is what Per Bak called self-organized criticality.

### THINGS TO TRY

Slow down the model using the speed slider to watch the avalanches occur.

Try using SETUP EMPTY and SETUP FULL; is the resultant pattern any different?

Can you explain why the graph is not a perfectly straight line?

### EXTENDING THE MODEL

The particles are currently colored by their depth in the sandpile. What if you colored them based on whether or not they were involved in an avalanche recently?

What if you make the limit on high the sandpiles can go larger than four? How about eight or twelve?

### NETLOGO FEATURES

This model makes use of the fact that you can set the origin of a 3D model anywhere you want. It also creates its own logarithmic graph.

### RELATED MODELS

There is a 2D version of this model in the Community Models called SANDPILE.

### CREDITS AND REFERENCES

Self organized criticality was originally investigated by Per Bak and collaborators. The basis for this model is in Per Bak's book "How Nature Works".

### HOW TO CITE

If you mention this model in an academic publication, we ask that you include these citations for the model itself and for the NetLogo software:

- Wilensky, U. (2006). NetLogo Sandpile 3D model. http://ccl.northwestern.edu/netlogo/models/Sandpile3D. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

- Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

In other publications, please use:

- Copyright 2006 Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/Sandpile3D for terms of use.

### COPYRIGHT NOTICE

Copyright 2006 Uri Wilensky. All rights reserved.

Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed:

a) this copyright notice is included.

b) this model will not be redistributed for profit without permission from Uri Wilensky. Contact Uri Wilensky for appropriate licenses for redistribution for profit.

## Comments and Questions

globals [ cascade-count cascade-list ] ;; ;; Setup Procedures ;; to setup ca set-default-shape turtles "circle" setxyz (max-pxcor * 2) (max-pycor * 2) (max-pzcor * 1.5) facexyz 0 0 (min-pzcor) set cascade-list [] set cascade-count 0 end ;; fill up the world with sand piles ;; each column should have between 0 and 3 grains of sand. to fill-world ask patches with [ pzcor = min-pzcor ] [ let number-of-grains random 4 sprout number-of-grains [ set pitch -90 set heading 0 while [ any? other turtles-here ] [ set zcor zcor + 1 ] set color brown + zcor ] ] end ;; ;; Runtime Procedures ;; to go ask one-of patches with [pzcor = max-pzcor] [ sprout 1 [ set pitch -90 set heading 0 set color brown fall ] ] tick end ;; have any grains of sand that can fall, fall to fall ;; turtle procedure while [ (not any? turtles-on patch-ahead 1) and (zcor > min-pzcor) ] [ fd 1 display ] trigger-cascade set color brown + zcor end to trigger-cascade ;; have any sand which should cascade set cascade-count 0 while [any? turtles with [zcor >= (min-pzcor + 3)]] [ cascade display ] update-plot end ;; distribute the current sand pile to the neighboring sand piles to cascade ;; ask one of the grains of sands that needs to cascade to cascade ask one-of turtles with [ zcor >= (min-pzcor + 3) and not any? turtles-at 0 0 1 ] [ ;; update the cascade-count set cascade-count cascade-count + 1 ;; we really don't want all the turtles in the column just the top four. let turtles-in-column turtles with [xcor = [xcor] of myself and ycor = [ycor] of myself and zcor >= (([zcor] of myself) - 3)] ask turtles-in-column [ set pitch 0 ;; make sure each of the grains of sand ;; go in four different directions. set heading 90 * (zcor mod 4) ;; if it falls off the edge remove it ifelse out-of-bounds? [ die ] [ set zcor min-pzcor fd 1 let my-column turtles with [ xcor = [xcor] of myself and ycor = [ycor] of myself ] let top-turtle max-one-of my-column [ zcor ] ;; if we are not the top turtle then move to the top of the pile if top-turtle != self [ set zcor [zcor] of top-turtle + 1 ] set color brown + zcor ] ] ] end to-report out-of-bounds? ;; turtle reporter let p patch-ahead 1 report (abs( [pxcor] of p - xcor ) > 1 or abs( [pycor] of p - ycor ) > 1) end ;; ;; Plotting Procedures ;; to update-plot ;; Check to see if we have anything to plot this turn if cascade-count > 0 [ ;; clear the old line plot-pen-reset ;; put the current count on the list of all counts set cascade-list fput cascade-count cascade-list ;; create a list of -1's as long as size of the greatest cascade let log-histogram n-values (max cascade-list + 1) [-1] ;; foreach element of the list calculate the frequency with which it occurred foreach cascade-list [ let old-value item ?1 log-histogram if old-value = -1 [ set old-value 0 ] set log-histogram replace-item ?1 log-histogram (old-value + 1) ] ;; take the log of that frequency set log-histogram map [safe-log ?] log-histogram ;; now determine the log of that value and plot the relationship let counter 1 foreach log-histogram [ if (?1 >= 0) [ plotxy (log (counter - 1) 10) ?1 ] set counter counter + 1 ] ] end ;; a special reporter so we do not ask for the log of -1 to-report safe-log [input] ifelse input = -1 [ report -1 ] [ report log input 10 ] end ; Copyright 2006 Uri Wilensky. All rights reserved. ; The full copyright notice is in the Information tab.

There are 3 versions of this model.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

Sandpile 3D.png | preview | Preview for 'Sandpile 3D' | about 6 years ago, by Uri Wilensky | Download |

This model does not have any ancestors.

This model does not have any descendants.