Energy of a Two-Gas System

Author: Michael Hoff
Date: October 21, 2014


This paper presents a computational program designed to simulate a two-gas system in Visual Python. Similar to the well-known "Particles in a Box", this simulation aims to illustrate the energies of two initially separated gases of different temperatures as they mix together and proceed toward equilibrium. The program uses Kinetic Gas Theory, the simple Euler method, and basic probability to calculate the energy of each gas based on the kinetic energies of its constituent particles, as well as the kinetic energy exchanges in collisions between individual particles. The results are qualitatively accurate, but precision could be improved with a smaller time-step, which was beyond the computing capabilities available in this experiment.


The goal of this project was to simulate the energy of a system composed of two gases of differing initial temperatures as they mix together and proceed toward equilibrium. To do this, the simple Euler method was used, treating each gas as a collection of individual particles with discrete velocities and confined to a box. This being achieved, the results were compared to the logical conclusion reached by applying the laws of thermodynamics.

Theoretical Background:

This project could be viewed as a specific instance of the classic "Particles in a Box" situation: within a box (i.e., a three-dimensional infinite potential well), two gases of different temperatures are initially separated, with the hot gas in one half of the box and the cold gas in the other half. As per Kinetic Gas Theory, the average speed of the particles of each gas are determined by the gas' temperature:

K = mv2 = 3/2 kT              v = (3kT/m)1/2

such that the particles composing the hot gas are moving substantially faster than those composing the cold gas. At t = 0, the barrier separating the two gases from each other is removed, allowing the gases to mix and their respective particles to collide. Through these collisions, energy and momentum are exchanged, with the overall trend being a transfer of energy from the fast-moving hot particles to the slow-moving cold particles. Over time, the energy difference between the two gases diminishes, until this difference finally disappears at equilibrium. The total energy of the two-gas system, however, ought to remain constant.

Computational Methods:

The program, written in Visual Python, simulates this scenario by treating each gas particle individually, and updating its position by the simple Euler method.

In order for both energy and momentum to be conserved, the following two equations must be simultaneously satisfied when a hot and a cold gas particle collide:

p: m1v1i + m2v2i = m1v1f + m2v2f
E: m1v1i2 + m2v2i2 = m1v1f2 + m2v2f2.

Since we are confining our attention to a system in which the hot and cold gas particles have the same mass, these equations simplify to:

p: v1i + v2i = v1f + v2f
E: v1i2 + v2i2 = v1f2 + v2f2

This is analogous to the following general system of two equations with four unknowns:

A + B = C + D
A2 + B2 = C2 + D2

Assuming all terms are non-zero, this system can only be satisfied if A = C and B = D, or if
A = D and B = C. That is to say, each collision between a pair of gas particles can only conserve both energy and momentum if each particle either maintains its initial velocity or swaps velocities with the other particle, with both of these possible outcomes being of statistically equal probability. Therefore, for each collision between a given pair of particles, the program chooses one of these two possible outcomes at random. In this way, the energy of the two systems will begin to equalize over time. Finally, the program continuously computes the total energies of each system based on the velocities of its constituent particles.

Results and Analysis:

In order to produce realistic results, the simulation should consider as many gas particles in the system as possible. This makes the program computationally intensive, and it is impossible to run for an extended period on a basic machine, unless the time-step is considerably larger than is optimal for the simple Euler method. Nevertheless, the program still yields good results, with the two gases approaching each other in temperature, and the total temperature of the system remaining nearly constant. The energy of each gas is very small (on the order of 10-20 Joules), but that is to be expected for a gas of less than one hundred particles.


Figure 1: Energy of the hot gas (red), energy of the cold gas (blue), and total energy of the
system (white), vs. time.

From a visual perspective, the program is also able to keep up with and accurately model the visual system itself, providing a useful illustration of and insight into its physical properties:


Figure 2: A three-dimensional visualization of the system, as it
approaches equilibrium; the particles of the hot gas (red)
are mixing with and subsequently colliding with the particles
of the cold gas (blue), thus imparting to them a portion of their
kinetic energy.


The primary issue with the program's performance was that the total energy of the system dipped initially. This was likely due to some lost energy when the particles were first beginning to interact and the gap between their respective energies was greatest. The culprit behind this problem is almost certainly the small time-step: if the system could be analyzed every milli- or even micro-second rather than every whole second there would be a substantially smaller window in which energy fragments could disappear. However, after this initial dip, the total energy does flat-line, and remains constant for the rest of the simulation even before the system reaches equilibrium. More importantly, the simulation shows the two gases approaching each other in energy, entering into a state with only a small energy difference between them, undergoing minor fluctuations, and ultimately seeing those fluctuations diminish asymptotically. The algorithm itself performed well; moving forward, perhaps more precise results could be obtained if the program were run on a more powerful machine, thus enabling a longer run-time and a smaller time-step.


UD in Service: Ph.D. Students Share 'Confessions' in South Irving

UD students not only read St. Augustine's Confessions in Rome, traveling to Ostia to marvel at the place in which, according to Book IX, St. Augustine and his mother, St. Monica, had a joint mystical vision of God -- they also travel 4.4 miles from the Irving campus to read the text with residents of South Irving.

+ Read More

How to Build a Shortwave Radio

As you know if you’ve read even some of our first UD Reads book, "All the Light We Cannot See," it’s possible to build a radio from random, scavenged parts, as long as you can find the necessary random, scavenged parts, as Werner does in the book. This is also essentially what Assistant Professor and Department Chair of Physics Jacob Moldenhauer did as well: He scavenged parts from the Physics Department, and built a radio.

+ Read More

Thomas S. Hibbs Appointed President of University of Dallas

The University of Dallas Board of Trustees announced today that it has unanimously selected Thomas S. Hibbs, Ph.D., BA '82 MA '83, to serve as the university's ninth president. The first alumnus of UD to be president, Hibbs has served as dean of the Honors College and distinguished professor of ethics and culture at Baylor University since 2003.

+ Read More