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.


University Welcomes Leading Catholic Intellectual to Campus

On Friday, Sept. 13, the university community welcomed George Weigel, distinguished senior fellow of the Ethics and Public Policy Center and the father of two UD alumnae. Celebrated for his two-volume biography of St. John Paul II and many other intellectual contributions, Weigel presented an exploration of the current Catholic situation in light of a new interpretation of the past 250 years of the church's interaction with social, cultural, economic and political modernity.

+ Read More

Recent DBA Alumnus Begins Tenure-Track Position at UNI

Gabe Dickey, DBA '19, recently successfully defended his dissertation, titled "Exploring the Human Side of Audit Quality: Team Engagement and Partner Leadership Behaviors," for UD's Doctor of Business Administration. Dickey has spent his career in the accounting profession, the vast majority as a certified public accountant working in auditing. He began UD's DBA program three years ago, drawn in by his interest in broader business issues and the program's practitioner-oriented focus.

+ Read More

Longtime Campus Safety Officer Sworn In to UDPD

Carlos Tijerina came to UD as a Campus Safety officer 23 years ago. He has loved the camaraderie of the CSO, but it has always been his dream to become a police officer. Then, a little over a year ago, UD finally got a police department. On Sept. 10, Tijerina was sworn in by President Thomas Hibbs as an official part of the UDPD team.

+ Read More