NASA Polynomials Without the FORTRAN Headache: Meet pyglenn
Four decades ago, engineers at NASA Glenn Research Center codified the thermodynamic behavior of thousands of chemical species for their Chemical Equilibrium with Applications (CEA) code. Those empirical polynomials remain the gold standard for combustion simulations, jet engine design, and rocket propellant modeling. Yet, working with that data today often feels like an archaeology expedition.…
In the early 1980s, NASA engineers at the Glenn Research Center created a set of mathematical equations to describe the behavior of various chemical compounds under different temperature conditions. These equations, known as polynomials, are crucial for simulating combustion reactions in jet engines and rockets. However, the data is stored in an outdated format that is difficult to use with modern programming languages and tools.
A new Python library called pyglenn aims to simplify the process of working with this thermodynamic data. Developed by Dr. Reginaldo G. Leão Jr. and released under the MIT license, pyglenn provides an easy-to-use interface for accessing the NASA Glenn thermodynamic catalog. The library wraps the entire dataset in an embedded SQLite database and provides a fully typed Python API for accessing the data.
One of the main advantages of pyglenn is that it addresses a common issue with the original NASA dataset: the use of an outdated reference constant for the universal gas constant, R. The original data was calibrated using a value of R = 8.314510 J/(mol ⋅ K) from the CODATA 1986 reference. However, modern scientific calculations often use a more precise value of R = 8.31446261815324 J/(mol ⋅ K). This difference can lead to small but significant errors in high-temperature calculations.
pyglenn solves this problem by including the historical reference constant directly in its database metadata. This ensures that calculations using pyglenn remain consistent with the original NASA dataset while also allowing for modern, precise calculations when needed. Additionally, pyglenn ships with a pre-built database file containing data for 2,035 chemical species and 3,795 temperature intervals, making it easy to get started with minimal setup.
To use pyglenn, you simply need to install it using a package manager like pip or conda. Once installed, you can import the ThermochemicalCalculator class and start evaluating thermodynamic properties for various chemical species at different temperatures. For example, to calculate the heat capacity of oxygen gas at 1000 K, you can use the following Python code:
from pyglenn import ThermochemicalCalculator
with ThermochemicalCalculator() as calculator:
heat_capacity = calculator.get_heat_capacity("O2", 1000)
print(f"Heat capacity of O2 at 1000 K: {heat_capacity} J/(mol*K)")
This code snippet demonstrates the simplicity and ease of use provided by pyglenn. The library's fully typed API ensures that your code is self-documenting and less prone to errors. By providing a modern, fully typed interface to the NASA Glenn thermodynamic data, pyglenn makes it possible for scientists and engineers to work with this valuable resource in a more efficient and reliable manner.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.