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.
- You can adjust the volume (as a percentage of the whole field) using
the slider and the "setup" button.
- The "single-step" button runs the simulation for just one time step,
deltat, so each turtle takes one step forward in its current
direction. Note that deltat is approximately 1/300, since the average
velocity of molecules at room temperature is 300 meters per second.
- The "go for 5" button runs the simulation for that many time units.
This takes a while!
- The "report-results" button prints the
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)
| volume | mean impacts |
| 10 | |
| 20 | |
| 30 | |
| 40 | |
| 50 | |
| 60 | |
| 70 | |
| 80 | |
| 90 | |
With ideal-gas3.slogo (your data)
| volume | mean impacts |
| | |
| | |
| | |
| | |
| 5625 | |
With ideal-gas3.slogo (my data)
| volume | mean impacts |
| 676 | 7253 |
| 1764 | 4471 |
| 2704 | 3602 |
| 3600 | 3146 |
| 4624 | 2823 |
| 5625 | 2538 |
With Gas3.mox
| volume | mean impacts |
| | |
| | |
| 4668 | 2753 |
| 5625 | 2519 |
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.
- This model makes lots of use of attributes (much like the turtle
variables). The "info" block records certain attributes of the items that
pass through it. Run the simulation once and take a look. This
model uses the following attributes
- id: this numbers each item. It's not necessary, but it's convenient
for certain observations
- xcoor: this is the x coordinate of the particle
- ycoor: this is the y coordinate of the particle
- heading: the direction (in radians) where the particle is going
- The "value" attribute of an item is a special attribute: you can
think of it as the "multiplicity" of the item: how many separate items
this one stands for. Certain blocks, such as queues, turn a single item
with a value of N into N items with a value of 1. Run the simulation with
animation to see.
- What is the purpose of the first queue? Try removing it to see.
- What is the purpose of the "delay" block? Try removing it to see.
- Does the histogram of x coordinates seem right? What do you expect?
Uniform? Non-uniform?
- Does the histogram of x,y coordinates seem right?
- Increase the number of items to 100. What other things need to change?
- Look at the changed histograms. Do they seem better or worse?
- Look at the DE Eqn blocks and understand what they're doing. It can
help to have a known constant heading (instead of a random value) to check
the computations.
When you feel you understand the model:
- Think about how to have the items bounce off the walls.
- Think about how to count the number of impacts
- Increase the number of items to give ourselves some good data.
Here are two solutions:
gas2.mox
gas3.mox
There's a lot to observe here.
- Additional attributes:
- The weird "data storage" setting in the Plotter window for the "x hits"
- Blocks to count impacts (x and y are done separately)
- Blocks to reflect particles that hit the walls
-
This work is licensed under a Creative Commons
License
-