GasLab Atmosphere

GasLab Atmosphere preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)


(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 217 times • Downloaded 65 times • Run 1 time
Download the 'GasLab Atmosphere' modelDownload this modelEmbed this model

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


This model is one in a series of GasLab models. They use the same basic rules for simulating the behavior of gases. Each model integrates different features in order to highlight different aspects of gas behavior.

The basic principle of the models is that gas particles are assumed to have two elementary actions: they move and they collide --- either with other particles or with any other objects such as walls.

In this model, a gaseous atmosphere is placed above the surface of a "planet", represented by a yellow line at the bottom of the world.


The basic principle of all GasLab models is the following algorithm (for more details, see the model "GasLab Gas in a Box"):

1) A particle moves in a straight line without changing its speed, unless it collides with another particle or bounces off the wall.
2) Two particles "collide" if they find themselves on the same patch (NetLogo's View is composed of a grid of small squares called patches). In this model, two particles are aimed so that they will collide at the origin.
3) An angle of collision for the particles is chosen, as if they were two solid balls that hit, and this angle describes the direction of the line connecting their centers.
4) The particles exchange momentum and energy only along this line, conforming to the conservation of momentum and energy for elastic collisions.
5) Each particle is assigned its new speed, heading and energy.
6) If a particle finds itself on or very close to the surface of the planet, it "bounces" --- that is, reflects its direction and keeps its same speed.

In this model, the effect of gravity is calculated as follows: every particle is given additional velocity downward during each clock tick, as it would get in a gravitational field. The particles bounce off the "ground". They disappear if they reach the top of the world, as if they had escaped the planet's gravitational field. The percentage of lost particles is shown in the PERCENT LOST PARTICLES monitor.


Initial settings:

  • NUMBER-OF-PARTICLES: number of gas particles
  • INIT-PARTICLE-SPEED: initial speed of each particle
  • PARTICLE-MASS: mass of each particle
  • GRAVITY-ACCELERATION: value of the gravitational acceleration

The SETUP button will set the initial conditions. The GO button will run the simulation.

Other settings:

  • COLLIDE?: Turns collisions between particles on and off.
  • TRACE?: Traces the path of one of the particles.


  • AVERAGE SPEED: average speed of the particles.
  • PERCENT FAST, PERCENT MEDIUM, PERCENT SLOW: percentage of particles with different speeds - fast (red), medium (green), and slow (blue).
  • PERCENT LOST PARTICLES: percentage of particles that have disappeared at the top edge of the world.
  • CLOCK (inside the View): number of ticks that have run.


  • SPEED COUNTS: plots the number of particles in each range of speed.
  • SPEED HISTOGRAM: speed distribution of all the particles. The gray line is the average value, and the black line is the initial average.
  • ENERGY HISTOGRAM: distribution of energies of all the particles, using m*(v^2)/2.
  • DENSITY HISTOGRAM: shows the number of particles at each 'layer' of the atmosphere, i.e. its local density.
  • ENERGY VS. HEIGHT: shows the mean energy of the particles at each "layer" of the atmosphere.


Try to predict what the view will look like after a while, and why.

Watch the gray path of one particle. What can you say about its motion? Turn COLLIDE? off and see if there are any differences.

Watch the change in density distribution as the model runs.

As the model runs, what happens to the average speed and kinetic energy of the particles? If they gain energy, where does it come from? What happens to the speed and energy distributions?


What happens when gravity is increased or decreased?

Change the initial number, speed and mass. What happens to the density distribution?

What factors affect how many particles escape this planet?

Does this model come to some sort of equilibrium? How can you tell when it has been reached?

Try and find out if the distribution of the particles in this model is the same as what is predicted by conventional physical laws. Is this consistent, for instance, with the fact that high-altitude places have lower pressure ( and thus lower density of air)? Why are they colder?

Try making gravity negative.


Find a way to plot the relative "temperature" of the gas as a function of distance from the planet.

Try this model with particles of different masses. You could color each mass differently to be able to see where they go. Are their distributions different? Which ones escape most easily? What does this suggest about the composition of an atmosphere?

The fact that particles escape when they reach a certain height isn't completely realistic, especially in the case when the particle was about to turn back towards the planet. Improve the model by allowing particles that have "escaped" to re-enter the atmosphere once gravity pulls them back down. How does this change the behavior of the model? Keeping track of actual losses (particles which reached the escape velocity of the planet) would be interesting. Under what conditions will particles reach escape velocity at all?

Make the "planet" into a central point instead of a flat plane.

This basic model could be used to explore other situations where freely moving particles have forces on them --- e.g. a centrifuge or charged particles (ions) in an electrical field.


Because of the influence of gravity, the particles follow curved paths. Since NetLogo models time in discrete steps, these curved paths must be approximated with a series of short straight lines. This is the source of a slight inaccuracy where the particles gradually lose energy if the model runs for a long time. The effect is as though the collisions with the ground were slightly inelastic. The inaccuracy can be reduced by increasing vsplit, but the model will run slower.


This model is part of the GasLab suite and curriculum.
See, in particular, the models "Gas in a Box" and "Gravity Box", which is a modified version of the "Atmosphere" model, with a ceiling on the atmosphere.


This model was developed as part of the GasLab curriculum ( and has also been incorporated into the Connected Chemistry curriculum (


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


Copyright 1997 Uri Wilensky.


This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at

This model was created as part of the project: CONNECTED MATHEMATICS: MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL MODELS (OBPML). The project gratefully acknowledges the support of the National Science Foundation (Applications of Advanced Technologies Program) -- grant numbers RED #9552950 and REC #9632612.

This model was converted to NetLogo as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227. Converted from StarLogoT to NetLogo, 2002.

Comments and Questions

Click to Run Model

  tick-delta                          ;; how much we advance the tick counter this time through
  max-tick-delta                      ;; the largest tick-delta is allowed to be
  avg-speed-init avg-energy-init      ;; initial averages
  avg-speed avg-energy                ;; current averages
  fast medium slow lost-particles     ;; current counts
  percent-medium percent-slow         ;; percentage of current counts
  percent-fast percent-lost-particles ;; percentage of current counts

breed [ particles particle ]
breed [ flashes flash ]

flashes-own [birthday]

  speed mass energy          ;; particle info

to setup
  set-default-shape particles "circle"
  set-default-shape flashes "plane"
  set max-tick-delta 0.1073
  ;; make floor
  ask patches with [ pycor = min-pycor ]
    [ set pcolor yellow ]
  set avg-speed-init avg-speed
  set avg-energy-init avg-energy
  set tracer one-of turtles

to go
  ask particles [ bounce ]
  ask particles [ move ]
  if not any? particles [stop]  ;; particles can die when they float too high
  ask particles
  [ if collide? [check-for-collision] ]
  if tracer = nobody
  [ set tracer one-of turtles ]
  ifelse trace?
  [ ask tracer [ pen-down ] ]
  [ ask tracer [ pen-up ] ]
  tick-advance tick-delta
  if floor ticks > floor (ticks - tick-delta)

  ask flashes with [ticks - birthday > 0.4]
    [ die ]

to update-variables
  set lost-particles (number-of-particles - count particles)
  set percent-lost-particles (lost-particles / number-of-particles) * 100
  set medium count particles with [color = green]
  set slow count particles with [color = blue]
  set fast count particles with [color = red]
  set percent-medium (medium / (number-of-particles - lost-particles)) * 100
  set percent-slow (slow / (number-of-particles - lost-particles)) * 100
  set percent-fast (fast / (number-of-particles - lost-particles)) * 100
  set avg-speed  mean [speed] of particles
  set avg-energy  mean [energy] of particles

to calculate-tick-delta
  ;; tick-delta is calculated in such way that even the fastest
  ;; particle will jump at most 1 patch length in a tick. As
  ;; particles jump (speed * tick-delta) at every tick, making
  ;; tick length the inverse of the speed of the fastest particle
  ;; (1/max speed) assures that. Having each particle advance at most
  ;; one patch-length is necessary for it not to "jump over" a wall
  ;; or another particle.
  ifelse any? particles with [speed > 0]
    [ set tick-delta min list (1 / (ceiling max [speed] of particles)) max-tick-delta ]
    [ set tick-delta max-tick-delta ]

to bounce  ;; particle procedure
  ;; get the coordinates of the patch we'll be on if we go forward 1
  let new-patch patch-ahead 1
  ;; if we're not about to hit a wall, we don't need to do any further checks
  if new-patch = nobody or [pcolor] of new-patch != yellow
    [ stop ]

  let new-px [pxcor] of new-patch
  let new-py [pycor] of new-patch
  ;; if hitting the bottom, reflect heading around y axis
  if (new-py = min-pycor )
    [ set heading (180 - heading)]

  ask patch new-px new-py
  [ sprout-flashes 1 [
      set color pcolor - 2
      set birthday ticks
      set heading 0

to move  ;; particle procedure
  ;; In other GasLab models, we use "jump speed * tick-delta" to move the
  ;; turtle the right distance along its current heading.  In this
  ;; model, though, the particles are affected by gravity as well, so we
  ;; need to offset the turtle vertically by an additional amount.  The
  ;; easiest way to do this is to use "setxy" instead of "jump".
  ;; Trigonometry tells us that "jump speed * tick-delta" is equivalent to:
  ;;   setxy (xcor + dx * speed * tick-delta)
  ;;         (ycor + dy * speed * tick-delta)
  ;; so to take gravity into account we just need to alter ycor
  ;; by an additional amount given by the classical physics equation:
  ;;   y(t) = 0.5*a*t^2 + v*t + y(t-1)
  ;; but taking tick-delta into account, since tick-delta is a multiplier of t.
  let xdiff dx * speed * tick-delta
  let ydiff dy * speed * tick-delta - gravity-acceleration * (0.5 * (tick-delta ^ 2))
  if patch-at xdiff ydiff = nobody [ die ]
  setxy (xcor + xdiff) (ycor + ydiff)

to factor-gravity  ;; turtle procedure
  let vx (dx * speed)
  let vy (dy * speed) - (gravity-acceleration * tick-delta)
  set speed sqrt ((vy ^ 2) + (vx ^ 2))
  set heading atan vx vy

to check-for-collision  ;; particle procedure
  ;; Here we impose a rule that collisions only take place when there
  ;; are exactly two particles per patch.

  if count other particles-here = 1
    ;; the following conditions are imposed on collision candidates:
    ;;   1. they must have a lower who number than my own, because collision
    ;;      code is asymmetrical: it must always happen from the point of view
    ;;      of just one particle.
    ;;   2. they must not be the same particle that we last collided with on
    ;;      this patch, so that we have a chance to leave the patch after we've
    ;;      collided with someone.
    let candidate one-of other particles-here with
      [who < [who] of myself and myself != last-collision]
    ;; we also only collide if one of us has non-zero speed. It's useless
    ;; (and incorrect, actually) for two particles with zero speed to collide.
    if (candidate != nobody) and (speed > 0 or [speed] of candidate > 0)
      collide-with candidate
      set last-collision candidate
      ask candidate [ set last-collision myself ]

;; implements a collision with another particle.
;; The two particles colliding are self and other-particle, and while the
;; collision is performed from the point of view of self, both particles are
;; modified to reflect its effects. This is somewhat complicated, so I'll
;; give a general outline here:
;;   1. Do initial setup, and determine the heading between particle centers
;;      (call it theta).
;;   2. Convert the representation of the velocity of each particle from
;;      speed/heading to a theta-based vector whose first component is the
;;      particle's speed along theta, and whose second component is the speed
;;      perpendicular to theta.
;;   3. Modify the velocity vectors to reflect the effects of the collision.
;;      This involves:
;;        a. computing the velocity of the center of mass of the whole system
;;           along direction theta
;;        b. updating the along-theta components of the two velocity vectors.
;;   4. Convert from the theta-based vector representation of velocity back to
;;      the usual speed/heading representation for each particle.
;;   5. Perform final cleanup and update derived quantities.

to collide-with [ other-particle ] ;; particle procedure
  ;; local copies of other-particle's relevant quantities:
  ;; mass2 speed2 heading2
  ;; quantities used in the collision itself
  ;; theta   ;; heading of vector from my center to the center of other-particle.
  ;; v1t     ;; velocity of self along direction theta
  ;; v1l     ;; velocity of self perpendicular to theta
  ;; v2t v2l ;; velocity of other-particle, represented in the same way
  ;; vcm     ;; velocity of the center of mass of the colliding particles,
             ;;   along direction theta

  ;;; PHASE 1: initial setup

  ;; for convenience, grab some quantities from other-particle
  let mass2 [mass] of other-particle
  let speed2 [speed] of other-particle
  let heading2 [heading] of other-particle

  ;; since particles are modeled as zero-size points, theta isn't meaningfully
  ;; defined. we can assign it randomly without affecting the model's outcome.
  let theta (random-float 360)

  ;;; PHASE 2: convert velocities to theta-based vector representation

  ;; now convert my velocity from speed/heading representation to components
  ;; along theta and perpendicular to theta
  let v1t (speed * cos (theta - heading))
  let v1l (speed * sin (theta - heading))

  ;; do the same for other-particle
  let v2t (speed2 * cos (theta - heading2))
  let v2l (speed2 * sin (theta - heading2))

  ;;; PHASE 3: manipulate vectors to implement collision

  ;; compute the velocity of the system's center of mass along theta
  let vcm (((mass * v1t) + (mass2 * v2t)) / (mass + mass2) )

  ;; now compute the new velocity for each particle along direction theta.
  ;; velocity perpendicular to theta is unaffected by a collision along theta,
  ;; so the next two lines actually implement the collision itself, in the
  ;; sense that the effects of the collision are exactly the following changes
  ;; in particle velocity.
  set v1t (2 * vcm - v1t)
  set v2t (2 * vcm - v2t)

  ;;; PHASE 4: convert back to normal speed/heading

  ;; now convert my velocity vector into my new speed and heading
  set speed sqrt ((v1t ^ 2) + (v1l ^ 2))
  set energy (0.5 * mass * (speed ^ 2))
  ;; if the magnitude of the velocity vector is 0, atan is undefined. but
  ;; speed will be 0, so heading is irrelevant anyway. therefore, in that
  ;; case we'll just leave it unmodified.
  if v1l != 0 or v1t != 0
    [ set heading (theta - (atan v1l v1t)) ]

  ;; and do the same for other-particle
  ask other-particle [
    set speed sqrt ((v2t ^ 2) + (v2l ^ 2))
    set energy (0.5 * mass * (speed ^ 2))
    if v2l != 0 or v2t != 0
      [ set heading (theta - (atan v2l v2t)) ]

  ;; PHASE 5: final updates

  ;; now recolor, since color is based on quantities that may have changed
  ask other-particle
    [ recolor ]

to recolor  ;; particle procedure
  ifelse speed < (0.5 * init-particle-speed)
    set color blue
    ifelse speed > (1.5 * init-particle-speed)
      [ set color red ]
      [ set color green ]

;;; drawing procedures

;; creates initial particles

to make-particles
  create-particles number-of-particles

to setup-particle  ;; particle procedure
  set speed init-particle-speed
  set mass particle-mass
  set energy (0.5 * mass * (speed ^ 2))
  set last-collision nobody

to-report last-n [n the-list]
  ifelse n >= length the-list
    [ report the-list ]
    [ report last-n n butfirst the-list ]

;; place particle at random location inside the box.

to random-position ;; particle procedure
  setxy random-xcor random-float ( ( world-height  - 1 ) / 2 ) + 1

to draw-graph
  let n min-pycor
  repeat (max-pycor / 2)
  [ let x particles with [ (pycor >= n) and (pycor < (n + 4)) ]
    ifelse count x = 0
     [ plot 0 ]
     [ plot mean [energy] of x ]
    set n n + 4

;; histogram procedure

to draw-vert-line [ xval ]
  plotxy xval plot-y-min
  plotxy xval plot-y-max

; Copyright 1997 Uri Wilensky.
; See Info tab for full copyright and license.

There are 15 versions of this model.

Uploaded by When Description Download
Uri Wilensky about 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 11 years ago Updated version tag Download this version
Uri Wilensky over 11 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky over 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky about 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky about 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky about 14 years ago GasLab Atmosphere Download this version

Attached files

File Type Description Last updated
GasLab Atmosphere.png preview Preview for 'GasLab Atmosphere' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.