Working with auxi's Ideal Gas Models

Purpose

The purpose of this example is to introduce and demonstrate the idealgas model classes in auxi's material physical property tools package.

Background

The idealgas models provide tools to calculate material physical properties of ideal gases by making use of gas states variables such as temperature, pressure and compostion. It is important to keep in mind that a gas behaves ideally at high temperatures and low pressures.

Items Covered

The following items in auxi are discussed and demonstrated in this example:

  • auxi.tools.materialphysicalproperties.idealgas.BetaT
  • auxi.tools.materialphysicalproperties.idealgas.RhoT
  • auxi.tools.materialphysicalproperties.idealgas.RhoTP
  • auxi.tools.materialphysicalproperties.idealgas.RhoTPx

Example Scope

In this example we will address the following aspects:

  1. Using the BetaT model
  2. Using the RhoT model
  3. Using the RhoTP model
  4. Using the RhoTPx model

In [ ]:
# import some tools to use in this example
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

Demonstrations

Using the BetaT model

This model describes the variation in the thermal expansion coefficient of an ideal gas as a function of temperature.

Calculating BetaT for a Single Temperature

As a basic example, let's calculate the thermal expansion coefficient at a single temperature:


In [ ]:
# import the model class
from auxi.tools.materialphysicalproperties.idealgas import BetaT

# create a model object
βT = BetaT()

# define the state of the gas
T = 500.0  # [K]

# calculate the gas density 
β = βT(T=T)
print ("β =", β, βT.units)

Calculating BetaT for Mutliple Temperatures

Now to show the potensial of this model, let's calculate at multiple temperatures and plot it.


In [ ]:
# calculate the gas density
Ts = list(range(400, 1550, 50))  # [K]
β = [βT(T=T) for T in Ts]

# plot a graph
plt.plot(Ts, β, "bo", alpha = 0.5)
plt.xlabel('$T$ [K]')
plt.ylabel('$%s$ [%s]' % (βT.display_symbol, βT.units))
plt.show()

Using the RhoT model

This model describes the variation in density of an ideal gas as a function of temperature.

Calculating RhoT at a Single Temperature

As a basic example let's calculate the density at a single temperature:


In [ ]:
# import the molar mass function
from auxi.tools.chemistry.stoichiometry import molar_mass as mm

# import the model class
from auxi.tools.materialphysicalproperties.idealgas import RhoT

# create a model object
# Since the model only calculates as a function temperature, we need to specify
# pressure and average molar mass when we create it.
ρT = RhoT(molar_mass=mm('CO2'), P=101325.0)

# define the state of the gas
T = 500.0  # [K]

# calculate the gas density
ρ = ρT.calculate(T=T)
print(ρT.symbol, "=", ρ, ρT.units)

Calculating RhoT for Mutliple temperatures

Now to show the potensial of this model, let's calculate at mutliple temperatures and plot it.


In [ ]:
# calculate the gas density
Ts = list(range(400, 1550, 50))  # [K]
ρs = [ρT(T=T) for T in Ts]

# plot a graph
plt.plot(Ts, ρs, "bo", alpha = 0.7)
plt.xlabel('$T$ [K]')
plt.ylabel('$%s$ [%s]' % (ρT.display_symbol, ρT.units))
plt.show()

Using the RhoTP model

This model describes the variation in density of an ideal gas as a function of temperature and pressure.

Calculating RhoTP at a Single Temperature and Pressure

As a basic example, let's calculate the density at a single temperature and pressure:


In [ ]:
# import the model class
from auxi.tools.materialphysicalproperties.idealgas import RhoTP

# create a model object
# Since the model only calculates as a function of temperature and pressure,
# we need to specify an average molar mass when we create it.
ρTP = RhoTP(mm('CO2'))

# define the state of the gas
T = 500.0  # [K]
P = 101325.0  # [Pa]

# calculate the gas density
ρ = ρTP.calculate(T=T,P=P)
print(ρTP.symbol, "=", ρ, ρTP.units)

Calculating RhoTP at Mutliple Pressures

Now to show the potensial of this model, let's calculate at mutliple pressures and plot it.


In [ ]:
# define the state of the gas
T = 700.0  # [K]
Ps = np.linspace(0.5*101325, 5*101325)  # [Pa]

# calculate the gas density
ρs = [ρTP(T=T, P=P) for P in Ps]

# plot a graph
plt.plot(Ps, ρs, "bo", alpha = 0.7)
plt.xlabel('$P$ [Pa]')
plt.ylabel('$%s$ [%s]' % (ρTP.display_symbol, ρTP.units))
plt.show()

RhoTPx model

This model describes the variation in density of an ideal gas as a function of temperature, pressure, and molar composition.

Calculating RhoTP at a Single Gas State

As a basic example lets calculate the density at a single temperature, pressure and molar compostion for a mixture of two gases:


In [ ]:
# import the model class
from auxi.tools.materialphysicalproperties.idealgas import RhoTPx

# create a model object
ρTPx = RhoTPx()

# define the state of the gas
T = 700.0  # [K]
P = 101325.0  # [Pa]
x = {'H2':0.5, 'Ar':0.5}  # [mole fraction]

# calculate the gas density
ρ = ρTPx(T=700, P=101000, x=x)
print(ρTPx.symbol, "=", ρ, ρTPx.units)

Calculating RhoTP as a Function of Composition

Now let's calculate the density at a single temperature and pressure, for a range of molar compostions for a mixture of two gases:


In [ ]:
# define the state of the gas
T = 700.0  # [K]
P = 101325.0  # [Pa]
xs_h2 = np.arange(0,1.1,0.1)  # [mole fraction H2]

# calculate density as a function of composition for a binary Ar-H2 gas mixture
ρs = [ρTPx(T=700, P=101325 ,x={'Ar':1-x, 'H2':x}) for x in xs_h2]

# plot a graph
plt.plot(xs_h2, ρs, "bo", alpha = 0.7)
plt.xlim((0,1))
plt.xlabel('$x_{H_2}$ [mol]')
plt.ylabel('$%s$ [%s]' % (ρTPx.display_symbol, ρTPx.units))
plt.show()