Description
This lab is not an official assignment and should not be submitted to the 6.009 server. Instead use this lab as a self-test to see if you have sufficient Python background to take 6.009 without a struggle. Follow the instructions below and judge for yourself how hard the lab was to complete. If it takes more than a couple of hours to complete the assignment, we strongly recommend that you first complete a subject that provides a thorough introduction to programming in Python, e.g., 6.0001. This lab assumes you have Python 3.5 or later installed on your machine. Please use the Chrome web browser. Introduction Have you watched a film lately? Beautifully complex simulations are everywhere: explosions, wreckage, ocean storms, sparks, and volcanoes, just to name a few. Simulations are tremendously useful: given an initial condition and a set of rules, we can straightforwardly use a computer to evolve the initial condition according to those rules, often giving rise to vastly complex behavior, more complex than we could animate manually, or even understand analytically. In science and engineering, simulations are often used to study high-order effects of rules such as the laws of physics. Enforcing conservation of energy in a particle model of light yields photo-realistic images (slowly). Applying what little we know of hydrodynamics to 3D models lets us study boat hulls in a variety of weather conditions. We also use simulations to predict the weather, crime, outcomes of sports matches, and nearly everything else one could quantify. These simulations are often computationally complex, requiring a deep understanding of numeric precision, and make simplifying assumptions grounded in mathematics. Early forms of simulation, cellular automata, sidestepped issues of precision and exponential complexity by discretizing (treating as integer values) time, space, motion, and anything else playing a role in the simulation. Perhaps the most well known of these cellular automaton simulations is Conway’s Game of Life, which uses only two trivial rules to govern “life” in a square grid. In this lab, you will implement a surprisingly capable cellular automaton simulation of a twodimensional gas represented by an upright square lattice, inspired by the PhD work of Brian Wylie in the late 80s. In this simple 2-dimensional world, time is partitioned into discrete “steps”, gas particles occupy discrete locations within the lattice, traveling at unit speeds in exactly one of the four directions: up, left, down, or right. While the real world is of course much
more complex, this very simple universe is quite sufficient to give rise to some interesting and complex behavior. In fact, simulations very much like this one were applied to early rocket propulsion systems. The
6.009
representation
of
a
gas Our gases are conceptually a 2-dimensional array of cells in row-major order. For each gas, we’ll specify the number of rows as the height and the number of columns as the width . In Python, it’s best to number the rows from 0 to height-1 and the columns from 0 to width-1 . With this convention the indices for a 3×4 ( height =3, width =4) 2D array are
0,0 0,1 0,2 0,3 1,0 1,1 1,2 1,3 2,0 2,1 2,2 2,3
Since Python doesn’t have 2D arrays, we’ll use a list of cells, listed in left-to-right, top-tobottom order. So the list representation of the 3×4 2D array would be
[