The Ideal Gas Law

Many of you have taken a chemistry or physics class that has talked about the relationship between volume and pressure. How was this relationship discovered? By taking lots of data, and fitting a mathematical model to it. Essentially, by regression.

Animation of Gases

Let's look at the following StarLogo simulations of an ideal gas.

gas-law2.slogo gas-law3.slogo

Each molecule of gas is represented as a turtle. The red walls define the volume of the container. Molecules bounce off the sides of the container, and we can count the number of impacts per unit time. "Pressure" we will define as an emergent phenomenon (remember that topic?) from the average number of impacts per unit time.

Let's collect some data by running this system in the following conditions. All of these are with about 500 particles.

With ideal-gas2.slogo (your data)
volumemean impacts
10 
20 
30 
40 
50 
60 
70 
80 
90 

With ideal-gas3.slogo (your data)
volumemean impacts
  
  
  
  
5625 

With ideal-gas3.slogo (my data)
volumemean impacts
6767253
17644471
27043602
36003146
46242823
56252538

With Gas3.mox
volumemean impacts
  
  
46682753
56252519

Everyone take a different value and we'll collect data in parallel. Then, we'll plot the data and analyze it.

Reviewing the Code

The underlying StarLogo model is that all the turtles are updated "in parallel" (but probably sequentially) at each timestep. You program a simulation by saying what the turtles do at each timestep. You do that by writing turtle procedures. You can also program the interface by writing observer procedures.

Question: Is StarLogo a Continuous Process simulation or a Discrete Event Simulation?

You can look at both sets of procedures by choosing Windows / Control Center. Let's look at the Observer procedures first, and then the Turtle procedures.

You can look up the commands, syntax and so forth of the StarLogo language by clicking on the button at that web site.

Extend Model (lab)

The StarLogo simulation crashes sometimes. It's also slow sometimes (almost entirely due to the graphics, which are nice but not essential). The following Extend model is incomplete, but can handle a lot more data.

gas.mox

Spend some time studying this model and understanding what it's doing.

When you feel you understand the model:

Here are two solutions:

gas2.mox
gas3.mox

There's a lot to observe here.

  1. This work is licensed under a Creative Commons License
  2. Creative Commons License
  3. Viewable With Any
Browser
  4. Valid HTML 4.01!
  5. Valid CSS!