{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4941b17f",
   "metadata": {},
   "source": [
    "# Ideal-gas properties \n",
    "\n",
    "See the appendix of https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=933725 for the mathematical representations. They can be summarized like so:\n",
    "\n",
    "$\n",
    "u_{\\rm ig} = RT\\left((1/T)\\left(\\frac{\\partial\\alpha_{\\rm ig}}{\\partial(1/T)}\\right)_{\\delta}\\right) = RT\\left(\\tau\\left(\\frac{\\partial\\alpha_{\\rm ig}}{\\partial\\tau}\\right)_{\\delta}\\right)\n",
    "$\n",
    "\n",
    "$\n",
    "h_{\\rm ig} = RT\\left(1+(1/T)\\left(\\frac{\\partial\\alpha_{\\rm ig}}{\\partial(1/T)}\\right)_{\\delta}\\right) = RT\\left(1+\\tau\\left(\\frac{\\partial\\alpha_{\\rm ig}}{\\partial\\tau}\\right)_{\\delta}\\right)\n",
    "$\n",
    "\n",
    "$\n",
    "s_{\\rm ig} = R\\left((1/T)\\left(\\frac{\\partial\\alpha_{\\rm ig}}{\\partial(1/T)}\\right)_{\\delta}-\\alpha_{\\rm ig}\\right) = R\\left(\\tau\\left(\\frac{\\partial\\alpha_{\\rm ig}}{\\partial\\tau}\\right)_{\\delta}-\\alpha_{\\rm ig}\\right)\n",
    "$\n",
    "\n",
    "The precise reference state used in Table A-22 of Moran and Shapiro is unknown, but they are based on the gas tables from the 1950s at the then National Bureau of Standards (now NIST). According to [a summary report from one year later](https://www.govinfo.gov/content/pkg/GOVPUB-C13-89baf9f9b4a43e5f25820bd51b0f3f11/pdf/GOVPUB-C13-89baf9f9b4a43e5f25820bd51b0f3f11.pdf), the enthalpy and Gibbs energy (and therefore also the entropy because $g=h-Ts$) are set to 0 at 0 K. This differs to the reference state used in [the pseudo-pure Air EOS](https://coolprop.org/fluid_properties/fluids/Air.html#fluid-air), but the offset is identical, as shown here:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "73e08117",
   "metadata": {},
   "outputs": [],
   "source": [
    "import CoolProp.CoolProp as CP"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3b3722e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "T: 200 u: 268.7943717754444 h: 326.2041971329565 s: 3.4799573598766878 deltau: 126.2343717754444 deltah: 126.2341971329565 deltas: 2.1843673598766875\n",
      "T: 440 u: 441.7087305389626 h: 568.010346325489 s: 4.274344979641025 deltau: 126.40873053896257 deltah: 126.40034632548895 deltas: 2.1856449796410256\n",
      "T: 740 u: 670.468780219468 h: 882.8851340422626 s: 4.818538217796705 deltau: 126.44878021946806 deltah: 126.44513404226257 deltas: 2.1857382177967053\n"
     ]
    }
   ],
   "source": [
    "# Some check values from Moran & Shapiro, 6th edition, Table A-22\n",
    "Ts = [200, 440, 740]\n",
    "hs = [199.97, 441.61, 756.44]\n",
    "ss = [1.29559, 2.08870, 2.63280]\n",
    "us = [142.56, 315.30, 544.02]\n",
    "\n",
    "for T, h0, s0, u0 in zip(Ts, hs, ss, us):\n",
    "    AS = CP.AbstractState(\"HEOS\", \"Air\")\n",
    "    AS.update(CP.PT_INPUTS, 101325, T)\n",
    "    R = AS.gas_constant()/AS.molar_mass()\n",
    "    RT = R*T\n",
    "    ucalc_kJkg = RT*(AS.tau()*AS.dalpha0_dTau())/1000 # kJ/kg\n",
    "    hcalc_kJkg = RT*(1+AS.tau()*AS.dalpha0_dTau())/1000 # kJ/kg\n",
    "    scalc_kJkgK = R*(AS.tau()*AS.dalpha0_dTau()-AS.alpha0())/1000 # kJ/kg\n",
    "    print('T:', T, 'u:', ucalc_kJkg, 'h:', hcalc_kJkg, 's:', scalc_kJkgK, 'deltau:', ucalc_kJkg-u0, 'deltah:', hcalc_kJkg-h0, 'deltas:', scalc_kJkgK-s0)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py313",
   "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.13.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
