Main Data History
Show Index Toggle 0 comments
  •  Quick Edit
  • Ideal Gas Law Simulation Report

    Simulating the Relationship Between Pressure and Other Variables in a 3D Environment

    Luke Carlson
    Trevor Day School
    March 11, 2013


    The Ideal Gas Law describes the characteristics of ideal gas in a container. Often written as \(PV=nRT\), this law displays the relationship between Pressure, Volume, Temperature, moles of the particle, and the universal gas constant in a system. The Ideal Gas Law can be derived from combining three other gas laws: Boyle’s Law, Charles’s Law, and Avogadro’s Law.

    Boyle’s Law postulates that in a system with uniform temperature, the pressure of an ideal gas is inversely proportional with volume of the gas. Thus, the pressure times the volume is equal to a constant value in the system, often shown as \(PV = k\) (where k is the constant). Since the constant is the same no matter the circumstances in the system, the law can be used to relate changes in pressure or volume as \(P_{1}V_{1} = P_{2}V_{2}\) (where 1 indicates the initial and 2 is the final state).

    Charles’s Law states that in a system with uniform pressure, the temperature is inversely proportional to the volume of the container holding the ideal gas (\(V \propto T\)). Since this law applies to any variation in volume or temperature, it can be written as \(\frac{V_{1}}{T_{1}} = \frac{V_{2}}{T_{2}}\)

    Avogadro’s Law declares that in a system with a constant temperature and pressure, equivalent volumes of the same ideal gas will contain an equal number of particles. Mathematically, the relationship can be shown using \(\frac{V}{n} = k\) (where k is the constant in the system).

    These three laws can be combined mathematically to create \(\frac{PV}{Tn} = R\) (R is a constant in the system). When rearranged, this creates \(PV=nRT\) or the Ideal Gas Law.


    In this lab, I set out to create a 3D simulation of ideal gas particles in a cubic container in order to experimentally determine the pressure of the gas based on given circumstances. From there, I planned to explore the relationship between pressure and volume as well as pressure and number of particles.To produce an sumlation, a replication of a real world circumstance using programming, of a gas particle it is first necessary to understand exactly how particles affect the pressure of a system. Pressure is the amount of force over a specific area, also written as \(Pressure=F/A\). Force can also be described as change in momentum over change in time: \(F = \frac{\Delta p}{\Delta t}\). The change momentum of a single particle equals its mass multiplied by its change in velocity: \({\Delta p} = m\Delta v\). Since there is more than one particle in a system, the entire change in momentum is the combined change in velocities of each particle that hits the specified area. Thus, the following formula can be used to determine total force:

      \(F = \frac{2m * \displaystyle\sum\limits_{i=1}^n v}{\Delta t}\) Where \(n\) is the number of collisions and \(v\) is the velocity of the particle hitting the wall. Since the change in velocity is double the initial velocity, the 2 can be placed outside the summation along with the mass.

    Once the force has been computed using the momentum of the particles, the pressure can then be determined with the initial formula \(P = F/A\).


    Increasing the number of particles in the simulation will yield a greater pressure. Furthermore, increasing the volume of a container will decrease the pressure in the system.


    To create my simulation, I used Processing, which is an open source program designed for programming visual projects. Processing uses a form of the Java programming language

    Computing Pressure

    I began constructing my simulation with ’3D Balls Bouncing’, a project from Open Processing, as a base. Starting off with a system that could already handle 3D collisions of small objects inside a container was necessary [see Failed Methods]. From there, I created small spheres with the properties of an ideal gas. Their speed was roughly determined on a Maxwell-Boltzman distribution and assuming that the most probable speed (\(V_{p}\)) would occur the most often (calculated using the formula \(V_{p} = \sqrt{\frac{2kT}{m}}\). Next, I focused on one wall in the container and tracked each time a particle collided with the area. I could then compute the change in momentum over the area since I had the masses and velocities of the particles. The simulation did not keep track of total time since initiation, which is equivalent to time, but I knew that aspects of the code were executed every frame. The project ran at a fixed number of frames per second (60) so I designed this formula to figured out the change in time: \(total\ time (seconds) = \frac{total\ frames}{frames\ per\ second}\).

    I inserted that data into this formula \(F = \frac{2m * \displaystyle\sum\limits_{i=0}^n v}{\Delta t}\) (see Introduction) to find the total force on the wall. To obtain the pressure, I just divided the answer by the area of the wall.

    Testing Pressure vs. Number of Particles

    Now that I was able to compute the pressure, I could test my hypothesis by increasing the number of particles in the system and analyzing the pressure readings. I started off with 5 particles and then tried 10, 15, and 20, 50 and 100 particles. I calculated the total pressure of each system once every 5 seconds for 20 seconds.

    Assessing the Relationship Between Pressure and Volume

    The next step of my experiment involved manipulating the volume of the container while keeping the number of particles constant. In order to do so, I altered one line of code in the box Class:

    int boxsize = 300;

    This variable alters the dimensions of the box (currently 300x300x300 pixels). I changed the boxsize to 400, 500, and 600, and calculated the pressure every 5 seconds for 20 seconds.

    Since the simulation could not handle a large number of particles, I

    Failed Methods

    I originally designed my own 3D collision system but it was less efficient so a computer could not render as many particles in the simulation. I knew that my approximation for pressure would be further off and I also realized that it would be too time consuming to focus on designing the base of the system when I could use open source alternatives.