{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "68f54355-fbac-427c-a59e-144d30650330",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import cantera as ct\n",
    "from scipy.optimize import fsolve"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6a67102c-dca6-4f56-8b98-d33389bfb264",
   "metadata": {},
   "outputs": [],
   "source": [
    "gas = ct.Solution('gri30.yaml')\n",
    "\n",
    "Xr = 'CH4:1, O2:2,  N2:7.52'\n",
    "Xp = 'CO2:1, H2O:2, N2:7.52'\n",
    "Tr = 298.15\n",
    "\n",
    "gas.TPX = Tr, 101325, Xr\n",
    "hr = gas.h\n",
    "\n",
    "#--------------\n",
    "\n",
    "def F(Tad):\n",
    "    gas.TPX = Tad[0], 101325, Xp\n",
    "    hp = gas.h\n",
    "    return np.array([hr - hp])\n",
    "\n",
    "Tguess = np.array([2000.0])\n",
    "Tad = fsolve(F, Tguess)[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "ca0f2553-1f51-4c03-8f67-0b6857237917",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2325.5981297539656"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Tad"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "051c135e-a5fc-4ceb-a736-42de83f2fde3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2224.6173595315477"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gas.TPX = Tr, 101325, Xr\n",
    "gas.equilibrate('HP')\n",
    "gas.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "6f8aa257-a0e5-4f55-992b-b3f2252621fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-256579.71591916055, -7090192.1652931655)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gas.h, gas.enthalpy_mole"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0359f190-a135-4d8c-8138-f3ddfe322467",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
