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.


Notice of Blackbaud Data Breach

We want to notify the community of a data security incident involving a third-party service provider, Blackbaud Inc., with whom we contract. The University of Dallas takes the protection and proper use of your personal information very seriously, and we are contacting you to explain the incident.

+ Read More

UD Announces Partnership with Leading Canadian University

A new partnership will provide MBA and Master of Management graduates of UWindsor's Odette School of Business (OSB) an opportunity to gain cybersecurity skills and certification through the University of Dallas' Satish & Yasmin Gupta College of Business. The OSB is the first Canadian university to partner with UD's Gupta College of Business.

+ Read More

A Record-Setting North Texas Giving Day

After calculating totals from yesterday's North Texas Giving Day (NTGD), the University of Dallas will retain its unofficial title as the most generous university in North Texas. UD ranked first among all colleges and universities, and sixth among nearly 400 schools, for both total funds raised and number of gifts received, thanks to the generosity of our community.

+ Read More