{ "cells": [ { "cell_type": "code", "execution_count": 19, "id": "51bd3ee9-400e-4ee1-ae81-3781c4acf453", "metadata": {}, "outputs": [], "source": [ "#!/usr/bin/env python\n", "# coding: utf-8\n", "\n", "# In[1]:\n", "\n", "\n", "import numpy as np\n", "from scipy.optimize import minimize\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "\n", "\n", "# #### Theory\n", "\n", "# ![image.png](attachment:image.png)\n", "\n", "# #### Preliminary Calculation\n", "\n", "# In[2]:" ] }, { "cell_type": "code", "execution_count": 20, "id": "90be5fde-d54c-48d5-9cfc-fb76d02a2ce8", "metadata": {}, "outputs": [], "source": [ "PmmHg = 440.8 \n", "TC = 9.158144271\n", "zis = [0.66,0.135,0.162,0.043]" ] }, { "cell_type": "code", "execution_count": 21, "id": "ba673fb5-82b6-4ca4-98eb-36bef06cf96c", "metadata": {}, "outputs": [], "source": [ "def AntoinePsat(coeff,TC):\n", " A,B,C = coeff\n", " return 10**(A-B/(TC + C))" ] }, { "cell_type": "code", "execution_count": 22, "id": "2ddecd48-5434-40ec-af2c-ae372e7cd9e3", "metadata": {}, "outputs": [], "source": [ "coeffs = [[7.94917,1657.462,227.02],\n", " [7.5788,863.35,273.15],\n", " [6.49454,255.6784,266.55],\n", " [6.69147,319.0117,266.7]]\n" ] }, { "cell_type": "code", "execution_count": 23, "id": "67f34a74-e710-45a3-b96d-c87b95df1883", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[8.537355065914953, 33160.18044351948, 369137.6636043228, 342796.30727095477]" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"\"\" Calculate Psats \"\"\"\n", "Psats = [AntoinePsat(coeff,TC) for coeff in coeffs]\n", "Psats " ] }, { "cell_type": "code", "execution_count": 24, "id": "2668abbd-1477-43ee-9936-f52ec9000d36", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1.93678654e-02, 7.52272696e+01, 8.37426642e+02, 7.77668574e+02])" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"\"\" Calculate Kis\"\"\"\n", "Kis = np.divide(Psats,PmmHg)\n", "Kis\n" ] }, { "cell_type": "code", "execution_count": 25, "id": "d3523741-f974-4bb2-acd5-606f3cbcb574", "metadata": {}, "outputs": [], "source": [ "# define the mass balance\n", "def vapor_phase_mass_balance(V,zis):\n", " \"\"\"\n", " Equation 10.17 SVA\n", " \"\"\"\n", " return np.abs(1-sum([(zi*Ki)/(1+V*(Ki-1)) for zi,Ki in list(zip(zis,Kis))]))\n", "\n", "# minimize vapor_phase_mass_balance to solve for V\n", "\n", "F_vapor_phase_mass_balance = lambda x : vapor_phase_mass_balance(x,zis)\n", "res = minimize(F_vapor_phase_mass_balance, x0 = 0.5 ,method='Nelder-Mead', tol=1e-6)\n", "\n", "\n", "# evaluate L and V\n", "if res.success:\n", " V,L = res.x[0],1-res.x[0]\n", "else:\n", " print('Did not converge')\n", " raise\n" ] }, { "cell_type": "code", "execution_count": 26, "id": "7bbf9028-887f-410f-b404-2a7d2ae11b1c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0.019254965906916017,\n", " 0.38406230477729975,\n", " 0.4715420278978388,\n", " 0.12514042283686558]" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"\"\" evaluate yis\"\"\"\n", "yis = [(zi*Ki)/(1+V*(Ki-1)) for zi,Ki in list(zip(zis,Kis))]\n", "yis" ] }, { "cell_type": "code", "execution_count": 27, "id": "24958634-7976-4350-98b3-7111567a359d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0.9941707831334012,\n", " 0.0051053601543027535,\n", " 0.0005630845789828888,\n", " 0.00016091742301905547]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"\"\" evaluate xis\"\"\"\n", "xis = [yi/Ki for yi,Ki in list(zip(yis,Kis))]\n", "xis" ] }, { "cell_type": "code", "execution_count": 28, "id": "b082d83b-1f2f-4013-812c-14f0d2eccbb9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0.65339999728938, 0.6534)" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L*xis[0],1*zis[0]*0.99" ] }, { "cell_type": "code", "execution_count": 29, "id": "346bfd1a-1421-4d15-aa5a-9bf1331605da", "metadata": {}, "outputs": [], "source": [ "zis = [0.66,0.135,0.162,0.043]" ] }, { "cell_type": "code", "execution_count": 30, "id": "2ee4387f-e366-4643-bbd6-7483e7977fb3", "metadata": {}, "outputs": [], "source": [ "def calcT98(TC,zis):\n", " \"\"\" Calculate Psats \"\"\"\n", " Psats = [AntoinePsat(coeff,TC) for coeff in coeffs]\n", "\n", " \"\"\" Calculate Kis\"\"\"\n", " Kis = np.divide(Psats,PmmHg)\n", " \n", " \"\"\" solve for the vapor fraction,V\"\"\"\n", " F_vapor_phase_mass_balance = lambda x : vapor_phase_mass_balance(x,zis)\n", " res = minimize(F_vapor_phase_mass_balance, x0 = 0.5 ,method='Nelder-Mead', tol=1e-6)\n", " \n", " # evaluate L and V\n", " if res.success:\n", " V,L = res.x[0],1-res.x[0]\n", " else:\n", " print('Did not converge')\n", " raise\n", " \n", " \"\"\" evaluate yis\"\"\"\n", " yis = [(zi*Ki)/(1+V*(Ki-1)) for zi,Ki in list(zip(zis,Kis))]\n", " \n", " \"\"\" evaluate xis\"\"\"\n", " xis = [yi/Ki for yi,Ki in list(zip(yis,Kis))]\n", " \n", " return [np.abs(L*xis[0] - (1*zis[0]*0.98)),yis[0]]\n", " \n", "\n", "F_calcT98 = lambda x : calcT98(x,zis)[0]" ] }, { "cell_type": "code", "execution_count": 31, "id": "4c67cb7d-9041-4d3c-8e1b-67775d20510d", "metadata": {}, "outputs": [], "source": [ "T98 = minimize(F_calcT98, x0 = 10 ,method='Nelder-Mead', tol=1e-6)" ] }, { "cell_type": "code", "execution_count": 32, "id": "2ab69a19-7bf0-48f5-a61c-b9023127d53b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "19.905107498168945" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "T98 = T98.x[0]\n", "T98" ] }, { "cell_type": "code", "execution_count": 33, "id": "51f22d53-8f85-4103-8ab6-63b693946b3c", "metadata": {}, "outputs": [], "source": [ "# #### Effect of Composition to T98\n", "\n", "# In[15]:\n", "\n", "\n", "\"\"\"water_to_carbondioxide_mass_ratios\"\"\" \n", "r1s = np.linspace(0.05,2,11)\n", "\"\"\"wetcarbondioxide_to_air_mole_ratios\"\"\"\n", "r2s = 1-np.linspace(0.00,0.40,11) " ] }, { "cell_type": "code", "execution_count": 34, "id": "4f7b6eee-9b90-4016-83bb-b05bebc3e769", "metadata": {}, "outputs": [], "source": [ "r1 = r1s[0]\n", "r2 = r2s[0]" ] }, { "cell_type": "code", "execution_count": 35, "id": "5a475a55-7ef5-4c72-96ce-a07dfc6ff273", "metadata": {}, "outputs": [], "source": [ "results = []\n", "\n", "for r1 in r1s:\n", " for r2 in r2s:\n", "\n", " mCO2 = 1\n", " mwater = r1*mCO2\n", "\n", " nCO2 = mCO2/ 44.01\n", " nwater = mwater / 18.01528\n", "\n", " z1_pure = nwater / (nwater + nCO2)\n", " z2_pure = nCO2 / (nwater + nCO2)\n", "\n", " zs = [ r2*z1_pure,\n", " r2*z2_pure,\n", " 0.79*(1 - r2*z1_pure - r2*z2_pure),\n", " 0.21*(1 - r2*z1_pure - r2*z2_pure)]\n", "\n", " zijs = [np.round(z,3) for z in zs]\n", "\n", "\n", " \"\"\"define a lambda funtion at the calculated zijs\"\"\"\n", " F_calcT98 = lambda x : calcT98(x,zijs)[0]\n", " \"\"\"solve for T98\"\"\"\n", " T98 = minimize(F_calcT98, x0 = 50 ,method='Nelder-Mead', tol=1e-6) \n", "\n", " \"\"\"append the result and the calculation parameter levels\"\"\"\n", " results.append({'zH2O' : zijs[0],\n", " 'zCO2' : zijs[1],\n", " 'zN2' : zijs[2],\n", " 'zO2' : zijs[3],\n", " 'r1' : r1,\n", " 'r2' : 1-r2,\n", " 'yH2O' : calcT98(T98.x[0],zijs)[1],\n", " 'T98' : T98.x[0]})" ] }, { "cell_type": "code", "execution_count": 36, "id": "f666ddb2-00fb-4ef2-b63f-9e6b433fc311", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
zH2OzCO2zN2zO2r1r2yH2OT98
00.1090.891-0.000-0.0000.050.000.002403-19.445789
10.1040.8560.0320.0080.050.040.002280-20.161733
20.1000.8200.0630.0170.050.080.002182-20.759943
30.0960.7840.0950.0250.050.120.002085-21.381680
40.0910.7490.1260.0340.050.160.001966-22.193559
\n", "
" ], "text/plain": [ " zH2O zCO2 zN2 zO2 r1 r2 yH2O T98\n", "0 0.109 0.891 -0.000 -0.000 0.05 0.00 0.002403 -19.445789\n", "1 0.104 0.856 0.032 0.008 0.05 0.04 0.002280 -20.161733\n", "2 0.100 0.820 0.063 0.017 0.05 0.08 0.002182 -20.759943\n", "3 0.096 0.784 0.095 0.025 0.05 0.12 0.002085 -21.381680\n", "4 0.091 0.749 0.126 0.034 0.05 0.16 0.001966 -22.193559" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results = pd.DataFrame(results)\n", "results.head()" ] }, { "cell_type": "code", "execution_count": 37, "id": "9e120445-4d0d-4aee-8edb-7826ff67710c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
r20.000.040.080.120.160.200.240.280.320.360.40
r1
0.0500.0024030.0022800.0021820.0020850.0019660.0018710.0017770.0016610.0015680.0014770.001364
0.2450.0118110.0110610.0103480.0096690.0090620.0084410.0078460.0072770.0067310.0062080.005706
0.4400.0213810.0196160.0180750.0165860.0152140.0139450.0128210.0117220.0106960.0097800.008878
0.6350.0310560.0280060.0252110.0228290.0206940.0186940.0169550.0153710.0138630.0125350.011310
0.8300.0409170.0360930.0320090.0285000.0255550.0228660.0204860.0183630.0164580.0147970.013230
1.0250.0508900.0439650.0383260.0337810.0297910.0264770.0234940.0209640.0186440.0165790.014788
1.2200.0609270.0516960.0444380.0385650.0337050.0296120.0261140.0230890.0204440.0181120.016040
1.4150.0712020.0592470.0501840.0430500.0372750.0323580.0283550.0249340.0219740.0193880.017109
1.6100.0812140.0662340.0555730.0471180.0404170.0349650.0304370.0266140.0233410.0205050.018025
1.8050.0917410.0736640.0605150.0507170.0433080.0371780.0322910.0280750.0245000.0215140.018836
2.0000.1023580.0803870.0653970.0541600.0458270.0392200.0338450.0293830.0255130.0223050.019526
\n", "
" ], "text/plain": [ "r2 0.00 0.04 0.08 0.12 0.16 0.20 0.24 \\\n", "r1 \n", "0.050 0.002403 0.002280 0.002182 0.002085 0.001966 0.001871 0.001777 \n", "0.245 0.011811 0.011061 0.010348 0.009669 0.009062 0.008441 0.007846 \n", "0.440 0.021381 0.019616 0.018075 0.016586 0.015214 0.013945 0.012821 \n", "0.635 0.031056 0.028006 0.025211 0.022829 0.020694 0.018694 0.016955 \n", "0.830 0.040917 0.036093 0.032009 0.028500 0.025555 0.022866 0.020486 \n", "1.025 0.050890 0.043965 0.038326 0.033781 0.029791 0.026477 0.023494 \n", "1.220 0.060927 0.051696 0.044438 0.038565 0.033705 0.029612 0.026114 \n", "1.415 0.071202 0.059247 0.050184 0.043050 0.037275 0.032358 0.028355 \n", "1.610 0.081214 0.066234 0.055573 0.047118 0.040417 0.034965 0.030437 \n", "1.805 0.091741 0.073664 0.060515 0.050717 0.043308 0.037178 0.032291 \n", "2.000 0.102358 0.080387 0.065397 0.054160 0.045827 0.039220 0.033845 \n", "\n", "r2 0.28 0.32 0.36 0.40 \n", "r1 \n", "0.050 0.001661 0.001568 0.001477 0.001364 \n", "0.245 0.007277 0.006731 0.006208 0.005706 \n", "0.440 0.011722 0.010696 0.009780 0.008878 \n", "0.635 0.015371 0.013863 0.012535 0.011310 \n", "0.830 0.018363 0.016458 0.014797 0.013230 \n", "1.025 0.020964 0.018644 0.016579 0.014788 \n", "1.220 0.023089 0.020444 0.018112 0.016040 \n", "1.415 0.024934 0.021974 0.019388 0.017109 \n", "1.610 0.026614 0.023341 0.020505 0.018025 \n", "1.805 0.028075 0.024500 0.021514 0.018836 \n", "2.000 0.029383 0.025513 0.022305 0.019526 " ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df=results.pivot('r1','r2','yH2O')\n", "df" ] }, { "cell_type": "code", "execution_count": 38, "id": "1dcb241f-de8d-4dac-b8f1-b261629428c1", "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'plt' is not defined", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[1;32mC:\\Users\\SHAHLA~1\\AppData\\Local\\Temp/ipykernel_24248/944468034.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfigure\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdpi\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m100\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mX\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mY\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mZ\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmeshgrid\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mY\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mNameError\u001b[0m: name 'plt' is not defined" ] } ], "source": [ "plt.figure(dpi=100)\n", "X=df.columns.values\n", "Y=df.index.values\n", "Z=df.values\n", "x,y=np.meshgrid(X, Y)\n", "plt.contourf(x, y, Z) #the NAN will be plotted as white spaces\n", "plt.colorbar(label = 'y$_{water}$')\n", "plt.xlabel('mole air / (mole CO$_2$ + H$_2$O)')\n", "plt.ylabel('mass H$_2$O / mass CO$_2$')" ] }, { "cell_type": "code", "execution_count": null, "id": "3e1d8849-7598-442f-a80b-95daa51a11ba", "metadata": {}, "outputs": [], "source": [ "df=results.pivot('r1','r2','T98')\n", "df" ] }, { "cell_type": "code", "execution_count": null, "id": "c97006bc-911e-40ca-8c0c-271c1c530431", "metadata": {}, "outputs": [], "source": [ "plt.figure(dpi=100)\n", "X=df.columns.values\n", "Y=df.index.values\n", "Z=df.values\n", "x,y=np.meshgrid(X, Y)\n", "plt.contourf(x, y, Z) #the NAN will be plotted as white spaces\n", "plt.colorbar(label = 'T$_{98}$,[°C]')\n", "plt.xlabel('mole air / (mole CO$_2$ + H$_2$O)')\n", "plt.ylabel('mass H$_2$O / mass CO$_2$')\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "20dec83e-56a6-4100-8730-8e497e6400f1", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "ce2f975b-555e-4a04-a9e6-356628c3b55b", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "00e8aa52-6251-40fe-b1f0-db91080f7472", "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.9.5" } }, "nbformat": 4, "nbformat_minor": 5 }