{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Gas Example" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Python imports\n", "import os\n", "import sys\n", "sys.path.append(\"..\")\n", "\n", "# Flight-Mech imports\n", "from flight_mech.gas import MonoatomicPerfectGas, DiatomicPerfectGas, GasMixture" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Monoatomic perfect gas\n", "\n", "Let us define a monoatomic perfect gas such as helium and check its properties." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "density [kg.m-3] 0.17622323083183306\n", "sound velocity [m.s-1] 972.507132526508\n" ] } ], "source": [ "helium = MonoatomicPerfectGas(\"helium\",molar_mass=4e-3)\n", "helium.pressure = 1e5 # Pa\n", "helium.temperature = 273 # K\n", "\n", "print(\"density [kg.m-3]\", helium.density)\n", "print(\"sound velocity [m.s-1]\", helium.sound_velocity)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Diatomic perfect gas\n", "\n", "It is also possible to define a gas using its chemical formula. In that case, it is not necessary to provide a molar mass. Let us try with O2." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Cp [J.K-1] 909.4511895598583\n", "Cv [J.K-1] 649.6079925427559\n" ] } ], "source": [ "oxygen = DiatomicPerfectGas(\"O2\", pressure=1e5, temperature=293)\n", "\n", "print(\"Cp [J.K-1]\", oxygen.Cp)\n", "print(\"Cv [J.K-1]\", oxygen.Cv)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Gas mixture\n", "\n", "If you need to study a gas mixture, you can either provide its molar mass directly or define it using the gas mixture class. Let us try with air." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "density [kg.m-3] 1.2261252357914747\n", "sound velocity [m.s-1] 338.0352369810981\n" ] } ], "source": [ "oxygen = DiatomicPerfectGas(\"O2\")\n", "nitrogen = DiatomicPerfectGas(\"N2\")\n", "gas_model_dict = {\n", " \"O2\": oxygen,\n", " \"N2\": nitrogen\n", "}\n", "gas_molar_fraction_dict = {\n", " \"O2\": 0.21,\n", " \"N2\": 0.79\n", "}\n", "\n", "air = GasMixture(gas_model_dict, gas_molar_fraction_dict)\n", "air.temperature = 283\n", "air.P = 1e5\n", "\n", "print(\"density [kg.m-3]\", air.density)\n", "print(\"sound velocity [m.s-1]\", air.sound_velocity)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After defining a gas, you can change the temperature or pressure to compute its properties in other conditions." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "density [kg.m-3] 0.4626579223053165\n" ] } ], "source": [ "air.T = 750 # K\n", "\n", "print(\"density [kg.m-3]\", air.density)" ] } ], "metadata": { "kernelspec": { "display_name": "venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" } }, "nbformat": 4, "nbformat_minor": 2 }