NetLogo banner

 Contact Us

 Modeling Commons

 User Manuals:


NetLogo Models Library:
Sample Models/Chemistry & Physics/GasLab

(back to the library)

GasLab Gravity Box

[screen shot]

If you download the NetLogo application, this model is included. (You can also run this model in your browser, but we don't recommend it; details here.)


This model simulates the effect of gravity on gas particles. It is very similar to GasLab Atmosphere, but with a "ceiling" over the gas, so particles can never escape.

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.

This model is part of the Connected Mathematics "Making Sense of Complex Phenomena" Modeling Project.


The particles are modeled as hard balls with no internal energy except that which is due to their motion. Collisions between particles are elastic. Particles are colored according to speed --- blue for slow, green for medium, and red for high speeds.

Coloring of the particles is with respect to one speed (10). Particles with a speed less than 5 are blue, ones that are more than 15 are red, while all in those in-between are green.

The exact way two particles collide is as follows: 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. 3. A random axis is chosen, as if they are two balls that hit each other and this axis is the line connecting their centers. 4. They exchange momentum and energy along that axis, according to the conservation of momentum and energy. This calculation is done in the center of mass system. 5. Each particle is assigned its new velocity, energy, and heading. 6. If a particle finds itself on or very close to a wall of the container, it "bounces" --- that is, reflects its direction and keeps its same speed.

In this model the particles behave exactly as in the basic Gas in a Box model except for now gravity acts on the particles. Every particle is given additional velocity downward during each tick, as it would get in a gravitational field. The particles bounce off the "ground" as well as the ceiling.


Initial settings: - GRAVITY: strength of the gravitational acceleration - NUMBER-OF-PARTICLES: number of gas particles - INIT-PARTICLE-SPEED: initial speed of each particle - PARTICLE-MASS: mass of each particle

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

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

Monitors: - FAST, MEDIUM, SLOW: numbers of particles with different speeds: fast (red), medium (green), and slow (blue). - AVERAGE SPEED: average speed of the particles. - AVERAGE ENERGY: average energy of the particles.

Plots: - 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, calculated as m*(v^2)/2. - HEIGHT VS. TEMPERATURE: shows the temperature of the particles at each 'layer' of the box. - DENSITY HISTOGRAM: shows the number of particles at each 'layer' of the box, i.e. its local density. - AGGREGATE TEMPERATURE: shows the aggregate sum of the HEIGHT VS. TEMPERATURE plot for the entire model run.


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?

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 is the shape of the path of individual particles?

What happens to the aggregate temperature plot over time? Is the temperature uniform over the box?


What happens when gravity is increased or decreased?

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

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.

Try making gravity negative.

Varying model parameters such as NUMBER and GRAVITY, what do you observe about the aggregate temperature graph? Can you explain these results? How would you square these results with a) the fact that "hot air rises" in a room and b) that it is colder as you go higher in elevation?


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? Do the different masses tend to have different average heights? What does this suggest about the composition of an atmosphere?

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, Gas in a Box and GasLab 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 or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

Please cite the NetLogo software as:


Copyright 2002 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 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.

(back to the NetLogo Models Library)