{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial\n", "\n", "This tutorial will guide you in the basic use of ThermoState. The ThermoState\n", "package is designed to ease the evaluation of thermodynamic properties for\n", "common substances used in Mechanical Engineering courses. Rather than looking up\n", "the information in a table and interpolating, we can input properties for the\n", "states directly, and all unknown values are automatically calculated." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "ThermoState uses [CoolProp](http://www.coolprop.org/) and [Pint](https://pint.readthedocs.io) to enable easy property evaluation in any unit system. The first thing we need to do is import the parts of ThermoState that we will use. This adds them to the set of local variables" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [], "source": [ "from thermostate import State, Q_, units" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pint and Units\n", "\n", "Now that the interface has been imported, we can create some properties. For instance, let's say we're given the pressure and temperature properties for water, and asked to determine the specific volume. First, let's create variables that set the pressure and temperature. We will use the Pint `Quantity` function, which we have called `Q_`. The syntax for the `Q_` function is `Q_(value, 'units')`." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": true }, "outputs": [], "source": [ "p_1 = Q_(101325, \"Pa\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can use whatever units we'd like, Pint supports a wide variety of units." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "scrolled": true }, "outputs": [], "source": [ "p_1 = Q_(1.01325, \"bar\")\n", "p_1 = Q_(14.7, \"psi\")\n", "p_1 = Q_(1.0, \"atm\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Another way to specify the units is to use the `units` class that we imported. This class has a number of attributes (text following a period) that can be used to create a quantity with units by multiplying a number with the unit. \n", "\n", "```python\n", "units.degR\n", "# ^^^^\n", "# This is the attribute\n", "```\n", "\n", "Let's set the temperature now. The available units of temperature are `degF` (`fahrenheit`), `degR` (`rankine`), `degC` (`celsius`), and `K` (`kelvin`)." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "scrolled": true }, "outputs": [], "source": [ "T_1 = 460 * units.degR\n", "T_1 = 25 * units.degC\n", "T_1 = 75 * units.degF\n", "T_1 = 400 * units.K" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The two ways of creating the units are equivalent. The following cell should print `True` to demonstrate this." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Q_(101325, \"Pa\") == 1.0 * units.atm" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note the convention we are using here: the variables are named with the property, followed by an underscore, then the number of the state. In this case, we are setting properties for state 1, hence `T_1` and `p_1`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ThermoState\n", "\n", "Now that we have defined two properties with units, let's define a state. First, we create a variable to hold the `State` and tell ThermoState what substance we want to use with that state. The available substances are:\n", "\n", "* `water`\n", "* `air`\n", "* `R134a`\n", "* `R22`\n", "* `propane`\n", "* `ammonia`\n", "* `isobutane`\n", "* `carbondioxide`\n", "* `oxygen`\n", "* `nitrogen`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that the name of the substance is case-insensitive (it doesn't matter whether you use lower case or upper case). It is often easiest to set the name of the substance in a variable, like:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "substance = \"water\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we need to create the `State` and assign values for the properties. Properties of the state are set as arguments to the `State` class, and they must always be set in pairs, we cannot set a single property at a time. The syntax is\n", "\n", " st = State(substance, property_1=value, property_2=value)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "