Thermodynamics - Comparison of Gas Laws

162 days ago by DorkeyDear

# Variables P = var('P'); # Pressure (Pa) SV = var('v', latex_name='\overline{v}'); # Specific Volume (m^3 / kg) T = var('T'); # Temperature (K) # Constants MW = 0.04401; # Molar Weight (kg / mol) R = 188.9; # Specific Gas Constant (J / kg / K) R = R / MW; # Molar Specific Gas Constant (J / mol / K) a = 0.364; #0.07132 # (J * m^3 / mol^2) b = 4.267E-5; # (m^3 / mol) a0 = 0.07132; b0 = 0.07235; c0 = 660000; A0 = 507.2836; B0 = 0.10476; A = A0 * (1 - a0 / v); B = B0 * (1 - b0 / v); # none to self: answers may be in molar units, not per mass; need to double check # note to self: need to check what material this is for, so reasonable ranges of P and T for where these laws are applicable I can use; currently P from 0.5 - 100 atm (only 10 atm in plots), and T from 200 to 400 K (-73.15 to 126.85 ºC) 
       
# Gas Laws # Ideal Gas Law IGL = P * SV == R * T; show(IGL); # van der Waals Equation of State VDW = (P + a / SV^2) * (v - b) == R * T; show(VDW); # Beattie-Bridgeman Equation of State BB = P == R * T / v^2 * (1 - c0 / (v * T^3)) * (v + B) - A / v^2; show(BB); 
       
\newcommand{\Bold}[1]{\mathbf{#1}}P \overline{v} = 4292.20631674619 \, T
\newcommand{\Bold}[1]{\mathbf{#1}}{\left(\overline{v} - 0.0000426700000000000\right)} {\left(P + \frac{0.364000000000000}{\overline{v}^{2}}\right)} = 4292.20631674619 \, T
\newcommand{\Bold}[1]{\mathbf{#1}}P = -\frac{4292.20631674619 \, {\left(\frac{660000}{T^{3} \overline{v}} - 1\right)} {\left(\overline{v} - \frac{0.00757938600000000}{\overline{v}} + 0.104760000000000\right)} T}{\overline{v}^{2}} - \frac{-\frac{36.1794663520000}{\overline{v}} + 507.283600000000}{\overline{v}^{2}}
\newcommand{\Bold}[1]{\mathbf{#1}}P \overline{v} = 4292.20631674619 \, T
\newcommand{\Bold}[1]{\mathbf{#1}}{\left(\overline{v} - 0.0000426700000000000\right)} {\left(P + \frac{0.364000000000000}{\overline{v}^{2}}\right)} = 4292.20631674619 \, T
\newcommand{\Bold}[1]{\mathbf{#1}}P = -\frac{4292.20631674619 \, {\left(\frac{660000}{T^{3} \overline{v}} - 1\right)} {\left(\overline{v} - \frac{0.00757938600000000}{\overline{v}} + 0.104760000000000\right)} T}{\overline{v}^{2}} - \frac{-\frac{36.1794663520000}{\overline{v}} + 507.283600000000}{\overline{v}^{2}}
# Preparation for plotting pIGL = implicit_plot3d(IGL, (P, 0.5*100E3, 10*100E3), (T, 200, 400), (SV, 0, 35), color='red' ); pVDW = implicit_plot3d(VDW, (P, 0.5*100E3, 10*100E3), (T, 200, 400), (SV, 0, 35), color='green'); pBB = implicit_plot3d(BB, (P, 0.5*100E3, 10*100E3), (T, 200, 400), (SV, 0, 35), color='blue' ); 
       
# Plotting Ideal Gas Law show(pIGL); 
       
# Plotting van der Waals Equation of State show(pVDW); 
       
# Plotting Beattie-Bridgeman Equation of State show(pBB); 
       
# Combining all plots for comparison purposes show(pIGL + pVDW + pBB); 
       
import numpy # Pressure and temperature sweeps Parray = numpy.linspace(0.5 * 100E3, 100 * 100E3, 5) Tarray = numpy.linspace(200, 400, 5) # Table header Table = [['Pressure\n(MPa)', 'Temperature\n(ºC)', 'Specific Volume\nIdeal Gas Law\n(kg/m^3)', 'Specific Volume\nvan der Waals\n(kg/m^3)', 'Specific Volume\nBeattie-Bridgeman\n(kg/m^3)']] # Table generating for Pelem in Parray: for Telem in Tarray: SV_IGL = IGL.substitute({P: Pelem, T: Telem}).find_root(0, 35) SV_VDW = VDW.substitute({P: Pelem, T: Telem}).find_root(0, 35) SV_BB = BB.substitute({P: Pelem, T: Telem}).find_root(0, 35) Table += [[round(Pelem / 1000000.0, 6), round(Telem - 273.15, 6), round(SV_IGL, 6), round(SV_VDW, 6), round(SV_BB, 6)]] # Display the table html.table(Table, header=True) 
       
Pressure (MPa) Temperature (ºC) Specific Volume Ideal Gas Law (kg/m^3) Specific Volume van der Waals (kg/m^3) Specific Volume Beattie-Bridgeman (kg/m^3)
0.05 -73.15 17.168825 17.168868 17.18953
0.05 -23.15 21.461032 21.461074 21.522348
0.05 26.85 25.753238 25.75328 25.832524
0.05 76.85 30.045444 30.045487 30.133908
0.05 126.85 34.337651 34.337693 34.431296
2.5375 -73.15 0.338302 0.338344 0.31268
2.5375 -23.15 0.422877 0.42292 0.457459
2.5375 26.85 0.507453 0.507495 0.563771
2.5375 76.85 0.592028 0.592071 0.659694
2.5375 126.85 0.676604 0.676646 0.751175
5.025 -73.15 0.170834 0.170876 0.045803
5.025 -23.15 0.213543 0.213585 0.228277
5.025 26.85 0.256251 0.256294 0.297611
5.025 76.85 0.29896 0.299002 0.353143
5.025 126.85 0.341668 0.341711 0.403653
7.5125 -73.15 0.114268 0.114311 0.044676
7.5125 -23.15 0.142835 0.142878 0.036938
7.5125 26.85 0.171403 0.171445 0.200552
7.5125 76.85 0.19997 0.200012 0.243762
7.5125 126.85 0.228537 0.228579 0.280921
10.0 -73.15 0.085844 0.085886 0.043747
10.0 -23.15 0.107305 0.107347 0.036117
10.0 26.85 0.128766 0.128809 0.145794
10.0 76.85 0.150227 0.15027 0.185049
10.0 126.85 0.171688 0.171731 0.216063
Pressure (MPa) Temperature (ºC) Specific Volume Ideal Gas Law (kg/m^3) Specific Volume van der Waals (kg/m^3) Specific Volume Beattie-Bridgeman (kg/m^3)
0.05 -73.15 17.168825 17.168868 17.18953
0.05 -23.15 21.461032 21.461074 21.522348
0.05 26.85 25.753238 25.75328 25.832524
0.05 76.85 30.045444 30.045487 30.133908
0.05 126.85 34.337651 34.337693 34.431296
2.5375 -73.15 0.338302 0.338344 0.31268
2.5375 -23.15 0.422877 0.42292 0.457459
2.5375 26.85 0.507453 0.507495 0.563771
2.5375 76.85 0.592028 0.592071 0.659694
2.5375 126.85 0.676604 0.676646 0.751175
5.025 -73.15 0.170834 0.170876 0.045803
5.025 -23.15 0.213543 0.213585 0.228277
5.025 26.85 0.256251 0.256294 0.297611
5.025 76.85 0.29896 0.299002 0.353143
5.025 126.85 0.341668 0.341711 0.403653
7.5125 -73.15 0.114268 0.114311 0.044676
7.5125 -23.15 0.142835 0.142878 0.036938
7.5125 26.85 0.171403 0.171445 0.200552
7.5125 76.85 0.19997 0.200012 0.243762
7.5125 126.85 0.228537 0.228579 0.280921
10.0 -73.15 0.085844 0.085886 0.043747
10.0 -23.15 0.107305 0.107347 0.036117
10.0 26.85 0.128766 0.128809 0.145794
10.0 76.85 0.150227 0.15027 0.185049
10.0 126.85 0.171688 0.171731 0.216063