<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Gas Mixtures
Step1:  To inspect the gas mixture contidions, we can use Pandas Dataframe contained in gas_mixture
Step2:  Note that the gas_mixture dataframe contains the information of the mixture
Step3:  One can also define the mixture defining some pure substances as moles and some as mass
Step4:  Note that gas_mix and gas_mix3 are equivalent.
Perfect Air as a mixture
In this example we will create a gas mixture following the air composition (as a perfect mix of oxygen, nitrogen, argon and carbon dioxide) and we will compare it to the 'Air' substance from PerfectIdelGas.
Note that Air is an available gas at the Nasa Glenn coefficients and is therefore available as a PerfectIdealGas and as SemiperfectIdeal.
Thus there is no need to declare Air as a gas mixture from pyTurb. However, for the sake of clarity, we will compare both mixtures.
From the PerfectIdealGas class
Step5:  And now, applying a mixture of molar quantities (per unit mole)
Step6:  Therefore, the mixture is composed of
Step7:  Where the gas constant, heat capacity at constant pressure, heat capacity at constant volume and the heat capacity ratio are
Step8:  Semiperfect Gas Mixture
Following the last example, a Semi Perfect model can be used by just changing the gas_model option
<ASSISTANT_TASK:>
Python Code:
from pyturb.gas_models import GasMixture
gas_mix = GasMixture(gas_model='Perfect')
gas_mix.add_gas('O2', mass=0.5)
gas_mix.add_gas('H2', mass=0.5)
Explanation: Gas Mixtures: Perfect and Semiperfect Models
This Notebook is an example about how to declare and use Gas Mixtures with pyTurb. Gas Mixtures in pyTurb are treated as a combination of different gases of pyTurb:
- PerfectIdealGas: Ideal Equation of State ($pv=R_gT$) and constant $c_p$, $c_v$, $\gamma_g$
- SemiperfectIdealGas: Ideal Equation of State and $c_p\left(T\right)$, $c_v\left(T\right)$, $\gamma_g\left(T\right)$ as a function of temperature
The Gas Mixture class and the rest of the gas models can be found at the following folder:
pyturb
gas_models
thermo_prop
PerfectIdealGas
SemiperfectIdealGas
GasMixture
python
from pyturb.gas_models import GasMixture
from pyturb.gas_models import PerfectIdealGas
from pyturb.gas_models import SemiperfectIdealGas
from pyturb.gas_models import GasMixture
When the GasMixture object is imported the gas model must be selected: The mixture can be treated as a Perfect Gas or Semiperfect Gas. Note that both options are ideal gases (the ideal equation of state $pv=R_gT$ is available). Thus:
If the gas is Perfect: $c_v, c_p, \gamma_g \equiv constant$
If the gas is Semiperfect: $c_v(T), c_p(T), \gamma_g(T) \equiv f(T)$
To choose one of the gas models simply specify it when creating the Gas Mixture object:
python
gas_mix_perfect = GasMixture(gas_model='Perfect')
gas_mix_semiperfect = GasMixture(gas_model='Semiperfect')
Note that 'gas_model' options are not case sensitive e.g. Semi-perfect, semiperfect or Semiperfect yield the same result.
A gas mixture can be defined adding the gas species that conform the mixture. For that purpose, the method add_gas can be used:
python
gas_mix = GasMixture()
gas_mix.add_gas(species, moles=quantity)
gas_mix.add_gas(species, mass=quantity)
Note that the gas species (pure substance) specified in species must be available as a PerfectIdealGas or SemiperfectIdealGas. The gas availability can be checked using the is_available function at ThermoProperties.
When using add_gas, the quantity of the gas to be added must be specified. This can be done by introducing the moles or the mass of the gas. For example, if a mixture of $1.5mol$ of $Ar$ and $3mol$ of $He$ is intended:
python
gas_mix = GasMixture(gas_model='Perfect')
gas_mix.add_gas('Ar', moles=1.5)
gas_mix.add_gas('He', moles=3.5)
Whilst a mix of $500g$ of $O_2$ and $500g$ of $H_2$ would be:
python
gas_mix = GasMixture(gas_model='Perfect')
gas_mix.add_gas('O2', mass=0.5)
gas_mix.add_gas('H2', mass=0.5)
Finally, the gas mixture provides the same outputs of a PerfectIdealGas or SemiperfectIdealGas, plus the molar and mass fractions:
- Gas properties: Ru, Rg, Mg, cp, cp_molar, cv, cv_molar, gamma
- Gas enthalpies, moles and mass: h0, h0_molar, mg, Ng
- Mixture condition: Molar fraction, mass fraction
Gas Mixture example:
Let's create a mixture Perfect Gases, with $500g$ of $O_2$ and $500g$ of $H_2$
End of explanation
gas_mix.mixture_gases
Explanation: To inspect the gas mixture contidions, we can use Pandas Dataframe contained in gas_mixture:
End of explanation
gas_mix2 = GasMixture(gas_model='Perfect')
gas_mix2.add_gas('O2', moles=0.5)
gas_mix2.add_gas('H2', moles=0.5)
gas_mix2.mixture_gases
Explanation: Note that the gas_mixture dataframe contains the information of the mixture: amount of moles, amount of mass, molar and mass fractions and the objects containing the pure subtance information.
It is also possible to create a gas mixtures defining moles:
End of explanation
gas_mix3 = GasMixture(gas_model='Perfect')
gas_mix3.add_gas('O2', mass=0.5)
gas_mix3.add_gas('H2', moles=0.121227)
gas_mix3.mixture_gases
Explanation: One can also define the mixture defining some pure substances as moles and some as mass:
End of explanation
from pyturb.gas_models import PerfectIdealGas
air_perfgas = PerfectIdealGas('Air')
print(air_perfgas.thermo_prop)
Explanation: Note that gas_mix and gas_mix3 are equivalent.
Perfect Air as a mixture
In this example we will create a gas mixture following the air composition (as a perfect mix of oxygen, nitrogen, argon and carbon dioxide) and we will compare it to the 'Air' substance from PerfectIdelGas.
Note that Air is an available gas at the Nasa Glenn coefficients and is therefore available as a PerfectIdealGas and as SemiperfectIdeal.
Thus there is no need to declare Air as a gas mixture from pyTurb. However, for the sake of clarity, we will compare both mixtures.
From the PerfectIdealGas class:
End of explanation
pyturb_mix = GasMixture('Perfect')
pyturb_mix.add_gas('O2', 0.209476)
pyturb_mix.add_gas('N2', 0.78084)
pyturb_mix.add_gas('Ar', 0.009365)
pyturb_mix.add_gas('CO2', 0.000319)
Explanation: And now, applying a mixture of molar quantities (per unit mole):
- Diatomic Oxygen: $O_2$ 20.9476\%
- Diatomic nitrogen: $N_2$ 78.0840\%
- Argon: $Ar$ 0.9365\%
- Carbon dioxide: $CO_2$ 0.0319\%
End of explanation
pyturb_mix.mixture_gases
Explanation: Therefore, the mixture is composed of:
End of explanation
print('pyTurb air mixture: Rair={0:6.1f}J/kg/K;  cp={1:6.1f} J/kg/K;  cv={2:6.1f} J/kg/K;  gamma={3:4.1f}'.format(pyturb_mix.Rg, pyturb_mix.cp(), pyturb_mix.cv(), pyturb_mix.gamma()))
print('Perfect air:        Rair={0:6.1f}J/kg/K;  cp={1:6.1f} J/kg/K;  cv={2:6.1f} J/kg/K;  gamma={3:4.1f}'.format(air_perfgas.Rg, air_perfgas.cp(), air_perfgas.cv(), air_perfgas.gamma()))
Explanation: Where the gas constant, heat capacity at constant pressure, heat capacity at constant volume and the heat capacity ratio are:
End of explanation
# Objective temperature:
T = 1500 #K
# Gas mixture:
pyturb_mix_sp = GasMixture('Semiperfect')
pyturb_mix_sp.add_gas('O2', 0.209476)
pyturb_mix_sp.add_gas('N2', 0.78084)
pyturb_mix_sp.add_gas('Ar', 0.009365)
pyturb_mix_sp.add_gas('CO2', 0.000319)
print('pyTurb air mixture: Rair={0:6.1f}J/kg/K;  cp={1:6.1f} J/kg/K;  cv={2:6.1f} J/kg/K;  gamma={3:4.1f}'.format(pyturb_mix_sp.Rg, pyturb_mix_sp.cp(T), pyturb_mix_sp.cv(T), pyturb_mix_sp.gamma(T)))
Explanation: Semiperfect Gas Mixture
Following the last example, a Semi Perfect model can be used by just changing the gas_model option:
End of explanation
<END_TASK>