def test_S0g_all_values(): tot3 = sum([abs(S0g(i, method='YAWS')) for i in Hfg_S0g_YAWS_data.index[pd.notnull(Hfg_S0g_YAWS_data['S0g'])]]) assert_close(tot3, 2691892.382999995) tot4 = sum([abs(S0g(i, method='CRC')) for i in CRC_standard_data.index[pd.notnull(CRC_standard_data['S0g'])]]) assert_close(tot4, 141558.30000000008)
def test_HeatCapacityLiquid_integrals(): from thermo.heat_capacity import ( CRCSTD, COOLPROP, DADGOSTAR_SHAW, ROWLINSON_POLING, ROWLINSON_BONDI, ZABRANSKY_SPLINE, ZABRANSKY_QUASIPOLYNOMIAL, ZABRANSKY_SPLINE_SAT, ZABRANSKY_QUASIPOLYNOMIAL_SAT, ZABRANSKY_QUASIPOLYNOMIAL_C, ZABRANSKY_SPLINE_C) tol = HeatCapacityLiquid(CASRN='108-88-3', MW=92.13842, Tc=591.75, omega=0.257, Cpgm=115.30398669098454, similarity_variable=0.16279853724428964) propylbenzene = HeatCapacityLiquid(MW=120.19158, CASRN='103-65-1', Tc=638.35) ctp = HeatCapacityLiquid(MW=118.58462, CASRN='96-43-5') dH = tol.calculate_integral(200, 300, CRCSTD) assert_close(dH, 15730) dH = tol.calculate_integral(200, 300, COOLPROP) assert_close(dH, 14501.714588188637) dH = tol.calculate_integral(200, 300, DADGOSTAR_SHAW) assert_close(dH, 14395.231307169146) dH = tol.calculate_integral(200, 300, ROWLINSON_POLING) assert_close(dH, 17332.447330329327) dH = tol.calculate_integral(200, 300, ROWLINSON_BONDI) assert_close(dH, 17161.367460370562) dH = tol.calculate_integral(200, 300, ZABRANSKY_SPLINE_C) assert_close(dH, 14588.050659771678) # Test over different coefficient sets dH = tol.calculate_integral(200, 500, ZABRANSKY_SPLINE_SAT) assert_close(dH, 52806.422778119224) dH = tol.calculate_integral(200, 300, ZABRANSKY_SPLINE_SAT) assert_close(dH, 14588.10920744596) dH = tol.calculate_integral(200, 300, ZABRANSKY_QUASIPOLYNOMIAL_C) assert_close(dH, 14662.031376528757) dH = propylbenzene.calculate_integral(200, 300, ZABRANSKY_QUASIPOLYNOMIAL) assert_close(dH, 19863.944414041936) dH = propylbenzene.calculate_integral(200, 300, ZABRANSKY_SPLINE) assert_close(dH, 19865.186385942456) dH = ctp.calculate_integral(200, 300, ZABRANSKY_QUASIPOLYNOMIAL_SAT) assert_close(dH, 13437.28621249451) # Entropy integrals dS = tol.calculate_integral_over_T(200, 300, CRCSTD) assert_close(dS, 63.779661505414275) dS = tol.calculate_integral_over_T(200, 300, COOLPROP) assert_close(dS, 58.50970500781979) dS = tol.calculate_integral_over_T(200, 300, DADGOSTAR_SHAW) assert_close(dS, 57.78686119989654) dS = tol.calculate_integral_over_T(200, 300, ROWLINSON_POLING) assert_close(dS, 70.42885653432398) dS = tol.calculate_integral_over_T(200, 300, ROWLINSON_BONDI) assert_close(dS, 69.73750128980184) dS = tol.calculate_integral_over_T(200, 300, ZABRANSKY_SPLINE_C) assert_close(dS, 58.866392640147374) dS = tol.calculate_integral_over_T(200, 300, ZABRANSKY_QUASIPOLYNOMIAL_C) assert_close(dS, 59.16999297436473) dS = tol.calculate_integral_over_T(200, 300, ZABRANSKY_SPLINE_SAT) assert_close(dS, 58.86648035527116) dS = tol.calculate_integral_over_T(200, 500, ZABRANSKY_SPLINE_SAT) assert_close(dS, 154.94766581118256) dS = propylbenzene.calculate_integral_over_T(200, 300, ZABRANSKY_QUASIPOLYNOMIAL) assert_close(dS, 80.13493128839104) dS = propylbenzene.calculate_integral_over_T(200, 300, ZABRANSKY_SPLINE) assert_close(dS, 80.13636874689294) dS = ctp.calculate_integral_over_T(200, 300, ZABRANSKY_QUASIPOLYNOMIAL_SAT) assert_close(dS, 54.34708465297109)
def test_volume_solutions_sympy(): Vs = volume_solutions_sympy(0.01, 1e-05, 2.5405184201558786e-05, 5.081036840311757e-05, -6.454233843151321e-10, 0.3872747173781095) Vs = [complex(v) for v in Vs] assert_close(Vs[0].real, 2.540546e-05, rtol=1e-5) assert_close(Vs[1].real, 4.660380256021831, rtol=1e-5) assert_close(Vs[2].real, 8309.802187086572, rtol=1e-5)
def test_core_dimensionless(): Re = Reynolds(2.5, 0.25, 1.1613, 1.9E-5) assert_close(Re, 38200.65789473684) Re = Reynolds(2.5, 0.25, nu=1.636e-05) assert_close(Re, 38202.93398533008) with pytest.raises(Exception): Reynolds(2.5, 0.25, 1.1613) PeH = Peclet_heat(1.5, 2, 1000., 4000., 0.6) assert_close(PeH, 20000000.0) PeH = Peclet_heat(1.5, 2., alpha=1E-7) assert_close(PeH, 30000000.0) with pytest.raises(Exception): Peclet_heat(1.5, 2, 1000., 4000.) PeM = Peclet_mass(1.5, 2., 1E-9) assert_close(PeM, 3000000000) FH1 = Fourier_heat(1.5, 2., 1000., 4000., 0.6) FH2 = Fourier_heat(1.5, 2, alpha=1E-7) assert_close1d([FH1, FH2], [5.625e-08, 3.75e-08]) with pytest.raises(Exception): Fourier_heat(1.5, 2, 1000., 4000.) FHM = Fourier_mass(1.5, 2.0, 1E-9) assert_close(FHM, 3.7500000000000005e-10) GZh1 = Graetz_heat(1.5, 0.25, 5., 800., 2200., 0.6) GZh2 = Graetz_heat(1.5, 0.25, 5, alpha=1E-7) assert_close1d([GZh1, GZh2], [55000.0, 187500.0]) with pytest.raises(Exception): Graetz_heat(1.5, 0.25, 5, 800., 2200.) Sc1 = Schmidt(D=2E-6, mu=4.61E-6, rho=800.) Sc2 = Schmidt(D=1E-9, nu=6E-7) assert_close1d([Sc1, Sc2], [0.00288125, 600.]) with pytest.raises(Exception): Schmidt(D=2E-6, mu=4.61E-6) Le1 = Lewis(D=22.6E-6, alpha=19.1E-6) Le2 = Lewis(D=22.6E-6, rho=800., k=.2, Cp=2200.) assert_close1d([Le1, Le2], [0.8451327433628318, 0.00502815768302494]) with pytest.raises(Exception): Lewis(D=22.6E-6, rho=800., k=.2) We = Weber(0.18, 0.001, 900., 0.01) assert_close(We, 2.916) Ma = Mach(33., 330.) assert_close(Ma, 0.1) Kn = Knudsen(1e-10, .001) assert_close(Kn, 1e-07) Pr1 = Prandtl(Cp=1637., k=0.010, mu=4.61E-6) Pr2 = Prandtl(Cp=1637., k=0.010, nu=6.4E-7, rho=7.1) Pr3 = Prandtl(nu=6.3E-7, alpha=9E-7) assert_close1d([Pr1, Pr2, Pr3], [0.754657, 0.7438528, 0.7]) with pytest.raises(Exception): Prandtl(Cp=1637., k=0.010) Gr1 = Grashof(L=0.9144, beta=0.000933, T1=178.2, rho=1.1613, mu=1.9E-5) Gr2 = Grashof(L=0.9144, beta=0.000933, T1=378.2, T2=200., nu=1.636e-05) assert_close1d([Gr1, Gr2], [4656936556.178915, 4657491516.530312]) with pytest.raises(Exception): Grashof(L=0.9144, beta=0.000933, T1=178.2, rho=1.1613) Bo1 = Bond(1000., 1.2, .0589, 2.) assert_close(Bo1, 665187.2339558573) Ra1 = Rayleigh(1.2, 4.6E9) assert_close(Ra1, 5520000000) Fr1 = Froude(1.83, 2., 1.63) Fr2 = Froude(1.83, L=2., squared=True) assert_close1d([Fr1, Fr2], [1.0135432593877318, 0.17074638128208924]) St = Strouhal(8., 2., 4.) assert_close(St, 4.0) Nu1 = Nusselt(1000., 1.2, 300.) Nu2 = Nusselt(10000., .01, 4000.) assert_close1d([Nu1, Nu2], [4.0, 0.025]) Sh = Sherwood(1000., 1.2, 300.) assert_close(Sh, 4.0) Bi1 = Biot(1000., 1.2, 300.) Bi2 = Biot(10000., .01, 4000.) assert_close1d([Bi1, Bi2], [4.0, 0.025]) St1 = Stanton(5000., 5., 800., 2000.) assert_close(St1, 0.000625) Eu1 = Euler(1E5, 1000., 4.) assert_close(Eu1, 6.25) Ca1 = Cavitation(2E5, 1E4, 1000., 10.) assert_close(Ca1, 3.8) Ec1 = Eckert(10., 2000., 25.) assert_close(Ec1, 0.002) Ja1 = Jakob(4000., 2E6, 10.) assert_close(Ja1, 0.02) Po1 = Power_number(P=180., L=0.01, N=2.5, rho=800.) assert_close(Po1, 144000000) Cd1 = Drag(1000., 0.0001, 5., 2000.) assert_close(Cd1, 400) Ca1 = Capillary(1.2, 0.01, .1) assert_close(Ca1, 0.12) Ar1 = Archimedes(0.002, 0.2804, 2699.37, 4E-5) Ar2 = Archimedes(0.002, 2., 3000., 1E-3) assert_close1d([Ar1, Ar2], [37109.575890227665, 470.4053872]) Oh1 = Ohnesorge(1E-4, 1000., 1E-3, 1E-1) assert_close(Oh1, 0.01) Su = Suratman(1E-4, 1000., 1E-3, 1E-1) assert_close(Su, 10000.0) BeL1 = Bejan_L(1E4, 1., 1E-3, 1E-6) assert_close(BeL1, 10000000000000) Bep1 = Bejan_p(1E4, 1., 1E-3, 1E-6) assert_close(Bep1, 10000000000000) Bo = Boiling(300., 3000., 800000.) assert_close(Bo, 1.25e-05) e_D1 = relative_roughness(0.0254) e_D2 = relative_roughness(0.5, 1E-4) assert_close1d([e_D1, e_D2], [5.9842519685039374e-05, 0.0002]) Co = Confinement(0.001, 1077, 76.5, 4.27E-3) assert_close(Co, 0.6596978265315191) De = Dean(10000., 0.1, 0.4) assert_close(De, 5000.0) Stk = Stokes_number(V=0.9, Dp=1E-5, D=1E-3, rhop=1000., mu=1E-5) assert_close(Stk, 0.5) Hg = Hagen(Re=2610., fd=1.935235) assert_close(Hg, 6591507.17175) # Where fd was obtained from: def Hagen2(rho, D, mu): return rho * D**3 / mu**2 correct = Hagen2(rho=992., mu=653E-6, D=6.568E-3) * 10000 guess = Hagen(Re=2610., fd=1.935235) assert_close(correct, guess) Fr = Froude_densimetric(1.83, L=2., rho2=1.2, rho1=800., g=9.81) assert_close(Fr, 0.4134543386272418) Fr = Froude_densimetric(1.83, L=2., rho2=1.2, rho1=800, g=9.81, heavy=False) assert_close(Fr, 0.016013017679205096) Mo = Morton(1077.0, 76.5, 4.27E-3, 0.023) assert_close(Mo, 2.311183104430743e-07)
def test_HeatCapacitySolid_integrals(): from thermo.heat_capacity import LASTOVKA_S, PERRY151, CRCSTD # Enthalpy integrals NaCl = HeatCapacitySolid(CASRN='7647-14-5', similarity_variable=0.0342215, MW=58.442769) dH1 = NaCl.calculate_integral(100, 150, LASTOVKA_S) assert_close(dH1, 401.58058175282446) dH2 = NaCl.calculate_integral(100, 150, CRCSTD) assert_close(dH2, 2525.0) # 50*50.5 dH3 = NaCl.calculate_integral(100, 150, PERRY151) assert_close(dH3, 2367.097999999999) # Tabular integration - not great NaCl = HeatCapacitySolid(CASRN='7647-14-5', similarity_variable=0.0342215, MW=58.442769) Ts = [200, 300, 400, 500, 600] Cps = [ 12.965044960703908, 20.206353934945987, 28.261467986645872, 37.14292010552292, 46.85389719453655 ] NaCl.add_tabular_data(Ts=Ts, properties=Cps, name='stuff') dH4 = NaCl.calculate_integral(200, 300, 'stuff') assert_close(dH4, 1651.8556007162392, rtol=1E-5) # Entropy integrals NaCl = HeatCapacitySolid(CASRN='7647-14-5', similarity_variable=0.0342215, MW=58.442769) dS1 = NaCl.calculate_integral_over_T(100, 150, LASTOVKA_S) assert_close(dS1, 3.213071341895563) dS2 = NaCl.calculate_integral_over_T(100, 150, PERRY151) assert_close(dS2, 19.183508272982) dS3 = NaCl.calculate_integral_over_T(100, 150, CRCSTD) assert_close(dS3, 20.4759879594623) NaCl = HeatCapacitySolid(CASRN='7647-14-5', similarity_variable=0.0342215, MW=58.442769) Ts = [200, 300, 400, 500, 600] Cps = [ 12.965044960703908, 20.206353934945987, 28.261467986645872, 37.14292010552292, 46.85389719453655 ] NaCl.add_tabular_data(Ts=Ts, properties=Cps, name='stuff') dS4 = NaCl.calculate_integral_over_T(100, 150, 'stuff') assert_close(dS4, 3.00533159156869)
def test_h_kinetic(): h = h_kinetic(300.0, 1E5, 18.02, 2441674.0) assert_close(h, 30788845.562480535, rtol=1e-5)
def test_fahrenheit_to_celcius(): assert_close(F2C(32.), 0) assert_close1d([F2C(32)], [0])
def test_TRC_Antoine_extended(): # Tetrafluoromethane, coefficients from [1]_, at 180 K: Psat = TRC_Antoine_extended(180.0, 227.51, -120., 8.95894, 510.595, -15.95, 2.41377, -93.74, 7425.9) assert_close(Psat, 706317.0898414153) # Test x is restricted to 0 Psat = TRC_Antoine_extended(120.0, 227.51, -120., 8.95894, 510.595, -15.95, 2.41377, -93.74, 7425.9) assert_close(Psat, 11265.018958511126) # Confirm that at low x, reverts to the Antoine expression assert_close(TRC_Antoine_extended(T=100.0, Tc=227.51, to=-120., A=8.95894, B=510.595, C=-15.95, n=2.41377, E=-93.74, F=7425.9), Antoine(T=100.0, A=8.95894, B=510.595, C=-15.95), rtol=1e-13) dPsat_dT_numerical = derivative(TRC_Antoine_extended, 180.0, dx=1e-3, args=(227.51, -120., 8.95894, 510.595, -15.95, 2.41377, -93.74, 7425.9)) dPsat_dT_analytical = dTRC_Antoine_extended_dT(180.0, 227.51, -120., 8.95894, 510.595, -15.95, 2.41377, -93.74, 7425.9) assert_close(dPsat_dT_analytical, 31219.606126382252, rtol=1e-13) assert_close(dPsat_dT_numerical, dPsat_dT_analytical, rtol=1e-8) for T in (0.0, 1e-150, 1e-200, 1e-250, 1e-300, 1e-100, 1e-400, 1e-308, 1e-307): assert dTRC_Antoine_extended_dT(T, 227.51, -120., 8.95894, 510.595, -15.95, 2.41377, -93.74, 7425.9) == 0.0 d2Psat_dT2_numerical = derivative(dTRC_Antoine_extended_dT, 180.0, dx=1e-3, args=(227.51, -120., 8.95894, 510.595, -15.95, 2.41377, -93.74, 7425.9)) d2Psat_dT2_analytical = d2TRC_Antoine_extended_dT2(180.0, 227.51, -120., 8.95894, 510.595, -15.95, 2.41377, -93.74, 7425.9) assert_close(d2Psat_dT2_analytical, 1022.5503689444175, rtol=1e-13) assert_close(d2Psat_dT2_numerical, d2Psat_dT2_analytical, rtol=1e-8) for T in (0.0, 1e-150, 1e-200, 1e-250, 1e-300, 1e-100, 1e-400, 1e-308, 1e-307): assert d2TRC_Antoine_extended_dT2(T, 227.51, -120., 8.95894, 510.595, -15.95, 2.41377, -93.74, 7425.9) == 0.0
def test_Antoine(): # Methane, coefficients from [1]_, at 100 K: Psat = Antoine(100.0, 8.7687, 395.744, -6.469) assert_close(Psat, 34478.367349639906) # Tetrafluoromethane, coefficients from [1]_, at 180 K Psat = Antoine(180, A=8.95894, B=510.595, C=-15.95) assert_close(Psat, 702271.0518579542) # Oxygen at 94.91 K, with coefficients from [3]_ in units of °C, mmHg, log10, # showing the conversion of coefficients A (mmHg to Pa) and C (°C to K) Psat = Antoine(94.91, 6.83706 + 2.1249, 339.2095, 268.70 - 273.15) assert_close(Psat, 162978.88655572367) # Extremely low temperature checks Psat = Antoine(T=60, A=3.45604 + 5, B=1044.038, C=-53.893) assert Psat < 1e-100 assert Psat > 0.0 assert Antoine(T=53, A=3.45604 + 5, B=1044.038, C=-53.893) == 0.0 assert Antoine(T=53.893, A=3.45604 + 5, B=1044.038, C=-53.893) == 0.0 assert Antoine(T=50, A=3.45604 + 5, B=1044.038, C=-53.893) == 0.0 dPsat_dT = dAntoine_dT(100.0, 8.7687, 395.744, -6.469) assert_close(dPsat_dT, 3591.4147747481156, rtol=1e-13) assert_close(dPsat_dT, derivative(Antoine, 100.0, dx=100 * 1e-7, args=(8.7687, 395.744, -6.469)), rtol=1e-9) # Extremely low temperature derivative check assert dAntoine_dT(5, 8.7687, 395.744, -6.469) == 0.0 d2Psat_dT = d2Antoine_dT2(100, 8.7687, 395.744, -6.469) d2Psat_dT_num = derivative(dAntoine_dT, 100.0, dx=.01, args=(8.7687, 395.744, -6.469)) assert_close(d2Psat_dT, 297.30093799054947, rtol=1e-13) assert_close(d2Psat_dT, d2Psat_dT_num, rtol=1e-7) # Low T values for T in (0, 1e-10, 1e-100, 10, 53, 53.893, 54): assert 0 == d2Antoine_dT2(T=T, A=3.45604 + 5, B=1044.038, C=-53.893)
def test_Hfg_API_TDB_data_fuzz(): tot = sum([abs(Hfg(i, method='API_TDB_G')) for i in Hfg_API_TDB_data.index]) assert_close(tot, 101711260.0)
def test_Hfs(): assert_close(Hfs('101-81-5'), 71500) assert_close(Hfs('101-81-5', method='CRC'), 71500) assert ['CRC'] == Hfs_methods('101-81-5')
def test_entropy_formation(): Sf = entropy_formation(Hf=-74520.0, Gf=-50490.0) assert_close(Sf, -80.59701492537314) Sf = entropy_formation(Hf=-241818, Gf=-228572) assert_close(Sf, -44.427301693778304)
def test_S0l(): assert_close(S0l('7439-97-6'), 75.9) # Lithium assert_close(S0l('7439-97-6', method='CRC'), 75.9) methods = S0l_methods('7439-97-6') assert methods == ['CRC']
def test_S0s(): assert_close(S0s('7439-93-2'), 29.1) # Lithium assert_close(S0s('7439-93-2', method='CRC'), 29.1) methods = S0s_methods('7439-93-2') assert methods == ['CRC']
def test_Rizk(): V1 = Rizk(0.25, 100E-6, 1.2, 0.078) assert_close(V1, 9.8833092829357)
def test_boiling_critical_relation(): P = boiling_critical_relation(347.2, 409.3, 617.1, 36E5) assert_close(P, 15209.467273093938)
def test_Schade(): V1 = Schade(mp=1., rhop=1000., dp=1E-3, rhog=1.2, D=0.1) assert_close(V1, 13.697415809497912)
def test_Lee_Kesler(): # Example from [2]_; ethylbenzene at 347.2 K. # Their result is 0.132 bar. P = Lee_Kesler(347.2, 617.1, 36E5, 0.299) assert_close(P, 13078.694162949312)
def test_core_misc2(): mu1 = nu_mu_converter(998., nu=1.0E-6) nu1 = nu_mu_converter(998., mu=0.000998) assert_close1d([mu1, nu1], [0.000998, 1E-6]) with pytest.raises(Exception): nu_mu_converter(990) with pytest.raises(Exception): nu_mu_converter(990, 0.000998, 1E-6) g1 = gravity(55., 1E4) assert_close(g1, 9.784151976863571) K = K_from_f(fd=0.018, L=100., D=.3) assert_close(K, 6.0) K = K_from_L_equiv(240.) assert_close(K, 3.6) L_D = L_equiv_from_K(3.6) assert_close(L_D, 240.) L = L_from_K(K=6., fd=0.018, D=.3) assert_close(L, 100) dP = dP_from_K(K=10., rho=1000., V=3.) assert_close(dP, 45000) head = head_from_K(K=10., V=1.5) assert_close(head, 1.1471807396001694) head = head_from_P(P=98066.5, rho=1000.) assert_close(head, 10.0) P = P_from_head(head=5., rho=800.) assert_close(P, 39226.6) fd = f_from_K(K=0.6, L=100., D=.3) assert_close(fd, 0.0018, rtol=1e-13)
def test_Ambrose_Walton(): # Example from [2]_; ethylbenzene at 347.25 K. # Their result is 0.1329 bar. Psat = Ambrose_Walton(347.25, 617.15, 36.09E5, 0.304) assert_close(Psat, 13278.878504306222)
def test_core_misc(): alpha = thermal_diffusivity(0.02, 1., 1000.) assert_close(alpha, 2e-05) c = c_ideal_gas(1.4, 303., 28.96) assert_close(c, 348.9820361755092, rtol=1e-05)
def test_Edalat(): # No check data, but gives the same results as the other CSP relationships Psat = Edalat(347.2, 617.1, 36E5, 0.299) assert_close(Psat, 13461.273080743307)
def test_HeatCapacityGas_integrals(): # Enthalpy integrals EtOH = HeatCapacityGas(CASRN='64-17-5', similarity_variable=0.1953615, MW=46.06844) dH1 = EtOH.calculate_integral( 200, 300, 'TRC Thermodynamics of Organic Compounds in the Gas State (1994)') assert_close(dH1, 5828.905647337944) dH2 = EtOH.calculate_integral(200, 300, 'Poling et al. (2001)') assert_close(dH2, 5851.1980281476) dH3 = EtOH.calculate_integral(200, 300, 'Poling et al. (2001) constant') assert_close(dH3, 6520.999999999999) dH4 = EtOH.calculate_integral( 200, 300, 'CRC Standard Thermodynamic Properties of Chemical Substances') assert_close(dH4, 6559.999999999999) dH4 = EtOH.calculate_integral(200, 300, 'Lastovka and Shaw (2013)') assert_close(dH4, 6183.016942750752, rtol=1e-5) dH5 = EtOH.calculate_integral(200, 300, 'COOLPROP') assert_close(dH5, 5838.118293585357, rtol=5e-5) dH = EtOH.calculate_integral(200, 300, 'VDI Heat Atlas') assert_close(dH, 6610.821140000002) # Entropy integrals dS = EtOH.calculate_integral_over_T(200, 300, 'Poling et al. (2001)') assert_close(dS, 23.5341074921551) dS = EtOH.calculate_integral_over_T(200, 300, 'Poling et al. (2001) constant') assert_close(dS, 26.4403796997334) dS = EtOH.calculate_integral_over_T( 200, 300, 'TRC Thermodynamics of Organic Compounds in the Gas State (1994)') assert_close(dS, 23.4427894111345) dS = EtOH.calculate_integral_over_T( 200, 300, 'CRC Standard Thermodynamic Properties of Chemical Substances') assert_close(dS, 26.59851109189558) dS = EtOH.calculate_integral_over_T(200, 300, 'COOLPROP') assert_close(dS, 23.487556909586853, rtol=1e-5) dS = EtOH.calculate_integral_over_T(200, 300, 'Lastovka and Shaw (2013)') assert_close(dS, 24.86700348570956, rtol=1e-5) dS = EtOH.calculate_integral_over_T(200, 300, 'VDI Heat Atlas') assert_close(dS, 26.590569427910076)
def test_Sanjari(): P = Sanjari(347.2, 617.1, 36E5, 0.299) assert_close(P, 13651.916109552498) Ts_dat = [ 125.45, 126.54775, 127.6455, 128.74325, 129.841, 130.93875, 132.0365, 133.13425, 134.232, 135.32975, 136.4275, 137.52525, 138.623, 139.72075, 140.8185, 141.91625, 143.014, 144.11175, 145.2095, 146.30725, 147.405, 148.50275, 149.6005, 150.69825, 151.796, 152.89375, 153.9915, 155.08925, 156.187, 157.28475, 158.3825, 159.48025, 160.578, 161.67575, 162.7735, 163.87125, 164.969, 166.06675, 167.1645, 168.26225, 169.36, 170.45775, 171.5555, 172.65325, 173.751, 174.84875, 175.9465, 177.04425, 178.142, 179.23975, 180.3375, 181.43525, 182.533, 183.63075, 184.7285, 185.82625, 186.924, 188.02175, 189.1195, 190.21725, 191.315, 192.41275, 193.5105, 194.60825, 195.706, 196.80375, 197.9015, 198.99925, 200.097, 201.19475, 202.2925, 203.39025, 204.488, 205.58575, 206.6835, 207.78125, 208.879, 209.97675, 211.0745, 212.17225, 213.27, 214.36775, 215.4655, 216.56325, 217.661, 218.75875, 219.8565, 220.95425, 222.052, 223.14975, 224.2475, 225.34525, 226.443, 227.54075, 228.6385, 229.73625, 230.834, 231.93175, 233.0295, 234.12725, 235.225, 236.32275, 237.4205, 238.51825, 239.616, 240.71375, 241.8115, 242.90925, 244.007, 245.10475, 246.2025, 247.30025, 248.398, 249.49575, 250.5935, 251.69125, 252.789, 253.88675, 254.9845, 256.08225, 257.18, 258.27775, 259.3755, 260.47325, 261.571, 262.66875, 263.7665, 264.86425, 265.962, 267.05975, 268.1575, 269.25525, 270.353, 271.45075, 272.5485, 273.64625, 274.744, 275.84175, 276.9395, 278.03725, 279.135, 280.23275, 281.3305, 282.42825, 283.526, 284.62375, 285.7215, 286.81925, 287.917, 289.01475, 290.1125, 291.21025, 292.308, 293.40575, 294.5035, 295.60125, 296.699, 297.79675, 298.8945, 299.99225, 301.09, 302.18775, 303.2855, 304.38325, 305.481, 306.57875, 307.6765, 308.77425, 309.872, 310.96975, 312.0675, 313.16525, 314.263, 315.36075, 316.4585, 317.55625, 318.654, 319.75175, 320.8495, 321.94725, 323.045, 324.14275, 325.2405, 326.33825, 327.436, 328.53375, 329.6315, 330.72925, 331.827, 332.92475, 334.0225, 335.12025, 336.218, 337.31575, 338.4135, 339.51125, 340.609, 341.70675, 342.8045, 343.90225 ] Ps_dat = [ 2.01857353521E-006, 0.000002517, 3.12468960653E-006, 3.86254620966E-006, 4.75480477553E-006, 5.82952636953E-006, 7.11906108993E-006, 8.66057817586E-006, 1.04966307916E-005, 1.2675775303E-005, 1.52532334366E-005, 1.82916090268E-005, 2.18616534529E-005, 2.60430842891E-005, 3.0925458133E-005, 3.66090963473E-005, 4.32060629106E-005, 5.08412011933E-005, 5.96532246339E-005, 6.97958540095E-005, 0.000081439, 9.47700963623E-005, 0.0001099952, 0.0001273406, 0.0001470541, 0.0001694061, 0.000194692, 0.0002232326, 0.0002553766, 0.0002915015, 0.0003320157, 0.00037736, 0.0004280092, 0.0004844737, 0.0005473018, 0.0006170807, 0.0006944384, 0.0007800461, 0.0008746188, 0.0009789181, 0.0010937533, 0.0012199834, 0.0013585185, 0.0015103219, 0.0016764114, 0.0018578609, 0.0020558023, 0.0022714268, 0.0025059864, 0.0027607955, 0.0030372323, 0.0033367399, 0.0036608279, 0.0040110736, 0.0043891231, 0.0047966926, 0.0052355691, 0.0057076118, 0.0062147529, 0.0067589985, 0.0073424292, 0.0079672011, 0.0086355463, 0.0093497735, 0.0101122685, 0.0109254949, 0.011791994, 0.0127143855, 0.0136953675, 0.0147377169, 0.0158442892, 0.0170180188, 0.0182619187, 0.0195790806, 0.0209726748, 0.0224459497, 0.0240022316, 0.0256449245, 0.0273775098, 0.0292035452, 0.0311266652, 0.0331505797, 0.0352790737, 0.0375160069, 0.0398653126, 0.0423309973, 0.0449171398, 0.0476278905, 0.0504674705, 0.0534401708, 0.0565503513, 0.0598024404, 0.0632009333, 0.0667503919, 0.0704554433, 0.074320779, 0.078351154, 0.0825513859, 0.0869263538, 0.0914809975, 0.0962203163, 0.1011493683, 0.1062732693, 0.111597192, 0.1171263649, 0.1228660716, 0.1288216497, 0.1349984903, 0.1414020366, 0.1480377837, 0.1549112773, 0.1620281134, 0.1693939372, 0.1770144428, 0.1848953722, 0.1930425148, 0.2014617071, 0.2101588319, 0.219139818, 0.2284106396, 0.2379773164, 0.2478459127, 0.2580225378, 0.2685133453, 0.2793245335, 0.2904623449, 0.3019330665, 0.3137430302, 0.3258986125, 0.3384062351, 0.3512723653, 0.3645035164, 0.3781062484, 0.3920871688, 0.4064529329, 0.4212102456, 0.4363658616, 0.4519265872, 0.4678992814, 0.4842908574, 0.5011082844, 0.5183585892, 0.5360488584, 0.5541862404, 0.5727779482, 0.5918312616, 0.6113535304, 0.6313521773, 0.6518347014, 0.6728086819, 0.6942817823, 0.7162617546, 0.7387564438, 0.7617737937, 0.785321852, 0.8094087764, 0.8340428416, 0.8592324462, 0.8849861205, 0.9113125351, 0.9382205104, 0.9657190263, 0.9938172336, 1.0225244661, 1.0518502533, 1.0818043358, 1.1123966802, 1.1436374973, 1.1755372609, 1.2081067294, 1.2413569686, 1.2752993784, 1.3099457208, 1.3453081525, 1.3813992602, 1.4182321006, 1.4558202448, 1.4941778289, 1.5333196103, 1.573261032, 1.614018295, 1.6556084416, 1.6980494505, 1.7413603456, 1.7855613233, 1.8306738995, 1.8767210817, 1.9237275734, 1.9717200158, 2.0207272795, 2.0707808186, 2.1219151068, 2.1741681851, 2.2275823605, 2.2822051216, 2.338090372, 2.3953001459, 2.4539070606, 2.5139977584, 2.575676075 ] AARD_calc = sum([ abs(Sanjari(T, 345.0, 26.40E5, 0.3170) - P * 1E6) / (P * 1E6) for T, P in zip(Ts_dat, Ps_dat) ]) / len(Ts_dat) assert_close(AARD_calc, 0.006445800342803334) # Supposed to be 1.387 %, small difference # Functions are identical- data simply must be different. # Or different method sof calculating AARD. No worries. AARD_calc = sum([ abs(Lee_Kesler(T, 345.0, 26.40E5, 0.3170) - P * 1E6) / (P * 1E6) for T, P in zip(Ts_dat, Ps_dat) ]) / len(Ts_dat) assert_close(AARD_calc, 0.01370923047231833) # Supposed to be 0.785 %, small difference; plus formula matches AARD_calc = sum([ abs(Ambrose_Walton(T, 345.0, 26.40E5, 0.3170) - P * 1E6) / (P * 1E6) for T, P in zip(Ts_dat, Ps_dat) ]) / len(Ts_dat) assert_close(AARD_calc, 0.00841629399152493)
def test_HeatCapacityGas(): EtOH = HeatCapacityGas(CASRN='64-17-5', similarity_variable=0.1953615, MW=46.06844) assert eval(str(EtOH)) == EtOH json_repr = EtOH.as_JSON() assert 'kwargs' not in json_repr new = HeatCapacityGas.from_JSON(json_repr) assert new == EtOH methods = list(EtOH.all_methods) methods.remove(VDI_TABULAR) Cps_calc = [] for i in methods: EtOH.method = i Cps_calc.append(EtOH.T_dependent_property(305)) assert_close1d(sorted(Cps_calc), sorted([ 66.35085001015844, 66.40063819791762, 66.25918325111196, 71.07236200126606, 65.6, 65.21 ]), rtol=1e-5) # VDI interpolation, treat separately due to change in behavior of scipy in 0.19 assert_close(EtOH.calculate(305, VDI_TABULAR), 74.6763493522965, rtol=1E-4) EtOH.extrapolation = None for i in [TRCIG, POLING, CRCSTD, COOLPROP, POLING_CONST, VDI_TABULAR]: EtOH.method = i assert EtOH.T_dependent_property(5000) is None with pytest.raises(Exception): EtOH.test_method_validity('BADMETHOD', 300) assert False == EtOH.test_property_validity(-1) assert False == EtOH.test_property_validity(1.01E4) Ts = [200, 250, 300, 400, 450] props = [1.2, 1.3, 1.4, 1.5, 1.6] EtOH.add_tabular_data(Ts=Ts, properties=props, name='test_set') assert_close(1.35441088517, EtOH.T_dependent_property(275), rtol=2E-4) assert None == EtOH.T_dependent_property(5000) new = HeatCapacityGas.from_JSON(EtOH.as_JSON()) assert new == EtOH # Case where the limits were nans obj = HeatCapacityGas(CASRN='7440-37-1', MW=39.948, similarity_variable=0.025032542304996495) assert not isnan(obj.Tmax) assert not isnan(obj.Tmin) assert not isnan(obj.POLING_Tmin) assert not isnan(obj.POLING_Tmax) new = HeatCapacityGas.from_JSON(obj.as_JSON()) assert new == obj # flash not converge due to melting P obj = HeatCapacityGas(CASRN='106-97-8') assert eval(str(obj)) == obj new = HeatCapacityGas.from_JSON(obj.as_JSON()) assert new == obj assert_close(obj.calculate(134.895, COOLPROP), 64.30715649610785) # flash not converge at high P obj = HeatCapacityGas(CASRN='306-83-2') assert eval(str(obj)) == obj new = HeatCapacityGas.from_JSON(obj.as_JSON()) assert new == obj assert_close(obj.calculate(obj.T_limits[COOLPROP][0], COOLPROP), 72.45489837498226, rtol=1e-7)
def test_Psat_IAPWS(): Psat = Psat_IAPWS(300.) assert_close(Psat, 3536.5894130130105, rtol=1e-12) Psat = Psat_IAPWS(500.) assert_close(Psat, 2638897.7562732217, rtol=1e-12) Psat = Psat_IAPWS(600.) assert_close(Psat, 12344314.578376647, rtol=1e-12) # Points obtained with CoolProp assert_close(dPsat_IAPWS_dT(300.0), 207.88388134164325327, rtol=5e-15) assert_close(dPsat_IAPWS_dT(500.0), 49008.859762957346618, rtol=5e-15) assert_close(dPsat_IAPWS_dT(600.0), 160315.50500711359916, rtol=5e-15) assert_close(dPsat_IAPWS_dT(100.0), -0.094715356431800557785, rtol=5e-15)
def test_DDBST_example(): # One good numerical example - acetone, chloroform, methanol T = 331.42 N = 3 Vs_ddbst = [74.04, 80.67, 40.73] as_ddbst = [[0, 375.2835, 31.1208], [-1722.58, 0, -1140.79], [747.217, 3596.17, 0.0]] bs_ddbst = [[0, -3.78434, -0.67704], [6.405502, 0, 2.59359], [-0.256645, -6.2234, 0]] cs_ddbst = [[0.0, 7.91073e-3, 8.68371e-4], [-7.47788e-3, 0.0, 3.1e-5], [-1.24796e-3, 3e-5, 0.0]] dis = eis = fis = [[0.0] * N for _ in range(N)] params = Wilson.from_DDBST_as_matrix(Vs=Vs_ddbst, ais=as_ddbst, bis=bs_ddbst, cis=cs_ddbst, dis=dis, eis=eis, fis=fis, unit_conversion=False) A_expect = [[0.0, 3.870101271243586, 0.07939943395502425], [-6.491263271243587, 0.0, -3.276991837288562], [0.8542855660449756, 6.906801837288562, 0.0]] B_expect = [[0.0, -375.2835, -31.1208], [1722.58, 0.0, 1140.79], [-747.217, -3596.17, -0.0]] D_expect = [[-0.0, -0.00791073, -0.000868371], [0.00747788, -0.0, -3.1e-05], [0.00124796, -3e-05, -0.0]] C_expect = E_expect = F_expect = [[0.0] * N for _ in range(N)] assert_close2d(params[0], A_expect, rtol=1e-12, atol=0) assert_close2d(params[1], B_expect, rtol=1e-12, atol=0) assert_close2d(params[2], C_expect, rtol=1e-12, atol=0) assert_close2d(params[3], D_expect, rtol=1e-12, atol=0) assert_close2d(params[4], E_expect, rtol=1e-12, atol=0) assert_close2d(params[5], F_expect, rtol=1e-12, atol=0) xs = [0.229, 0.175, 0.596] GE = Wilson(T=T, xs=xs, ABCDEF=params) # Test __repr__ contains the needed information assert eval(str(GE)).GE() == GE.GE() gammas_expect = [1.223393433488855, 1.1009459024701462, 1.2052899281172034] assert_close1d(GE.gammas(), gammas_expect, rtol=1e-12) assert_close1d(GibbsExcess.gammas(GE), gammas_expect) lambdas = GE.lambdas() lambdas_expect = [[1.0, 1.1229699812593041, 0.7391181616283594], [3.2694762162029805, 1.0, 1.1674967844769508], [0.37280197780931773, 0.019179096486191153, 1.0]] assert_close2d(lambdas, lambdas_expect, rtol=1e-12) dlambdas_dT = GE.dlambdas_dT() dlambdas_dT_expect = [[0.0, -0.005046703220379676, -0.0004324140595259853], [-0.026825598419319092, 0.0, -0.012161812924715213], [0.003001348681882189, 0.0006273541924400231, 0.0]] assert_close2d(dlambdas_dT, dlambdas_dT_expect) dT = T * 1e-8 dlambdas_dT_numerical = (np.array(GE.to_T_xs(T + dT, xs).lambdas()) - GE.to_T_xs(T, xs).lambdas()) / dT assert_close2d(dlambdas_dT, dlambdas_dT_numerical, rtol=1e-7) d2lambdas_dT2 = GE.d2lambdas_dT2() d2lambdas_dT2_expect = [ [0.0, -4.73530781420922e-07, -1.0107624477842068e-06], [0.000529522489227112, 0.0, 0.0001998633344112975], [8.85872572550323e-06, 1.6731622007033546e-05, 0.0] ] assert_close2d(d2lambdas_dT2, d2lambdas_dT2_expect, rtol=1e-12) d2lambdas_dT2_numerical = (np.array(GE.to_T_xs(T + dT, xs).dlambdas_dT()) - GE.to_T_xs(T, xs).dlambdas_dT()) / dT assert_close2d(d2lambdas_dT2, d2lambdas_dT2_numerical, rtol=2e-5) d3lambdas_dT3 = GE.d3lambdas_dT3() d3lambdas_dT3_expect = [ [0.0, 4.1982403087995867e-07, 1.3509359183777608e-08], [-1.2223067176509094e-05, 0.0, -4.268843384910971e-06], [-3.6571009680721684e-08, 3.3369718709496133e-07, 0.0] ] assert_close2d(d3lambdas_dT3, d3lambdas_dT3_expect, rtol=1e-12) d3lambdas_dT3_numerical = ( np.array(GE.to_T_xs(T + dT, xs).d2lambdas_dT2()) - GE.to_T_xs(T, xs).d2lambdas_dT2()) / dT assert_close2d(d3lambdas_dT3, d3lambdas_dT3_numerical, rtol=1e-7) # Gammas assert_allclose(GE.GE(), 480.2639266306882, rtol=1e-12) gammas = GE.gammas() GE_from_gammas = R * T * sum(xi * log(gamma) for xi, gamma in zip(xs, gammas)) assert_close(GE_from_gammas, GE.GE(), rtol=1e-12) # dGE dT dGE_dT_numerical = ( (np.array(GE.to_T_xs(T + dT, xs).GE()) - np.array(GE.GE())) / dT) dGE_dT_analytical = GE.dGE_dT() assert_close(dGE_dT_analytical, 4.355962766232997, rtol=1e-12) assert_close(dGE_dT_numerical, dGE_dT_analytical) # d2GE dT2 d2GE_dT2_numerical = ( (np.array(GE.to_T_xs(T + dT, xs).dGE_dT()) - np.array(GE.dGE_dT())) / dT) d2GE_dT2_analytical = GE.d2GE_dT2() assert_close(d2GE_dT2_analytical, -0.02913038452501723, rtol=1e-12) assert_close(d2GE_dT2_analytical, d2GE_dT2_numerical, rtol=1e-8) # d3GE dT3 d3GE_dT3_numerical = ((np.array(GE.to_T_xs(T + dT, xs).d2GE_dT2()) - np.array(GE.d2GE_dT2())) / dT) d3GE_dT3_analytical = GE.d3GE_dT3() assert_close(d3GE_dT3_analytical, -0.00019988744724590656, rtol=1e-12) assert_close(d3GE_dT3_numerical, d3GE_dT3_analytical, rtol=1e-7) # d2GE_dTdxs def dGE_dT_diff(xs): return GE.to_T_xs(T, xs).dGE_dT() d2GE_dTdxs_numerical = jacobian(dGE_dT_diff, xs, perturbation=1e-7) d2GE_dTdxs_analytical = GE.d2GE_dTdxs() d2GE_dTdxs_expect = [ -10.187806161151178, 13.956324059647034, -6.825249918548414 ] assert_close1d(d2GE_dTdxs_analytical, d2GE_dTdxs_expect, rtol=1e-12) assert_close1d(d2GE_dTdxs_numerical, d2GE_dTdxs_analytical, rtol=1e-7) # dGE_dxs def dGE_dx_diff(xs): return GE.to_T_xs(T, xs).GE() dGE_dxs_numerical = jacobian(dGE_dx_diff, xs, perturbation=1e-7) dGE_dxs_analytical = GE.dGE_dxs() dGE_dxs_expect = [ -2199.97589893946, -2490.5759162306463, -2241.05706053718 ] assert_close1d(dGE_dxs_analytical, dGE_dxs_expect, rtol=1e-12) assert_close1d(dGE_dxs_analytical, dGE_dxs_numerical, rtol=1e-7) # d2GE_dxixjs d2GE_dxixjs_numerical = hessian(dGE_dx_diff, xs, perturbation=1e-5) d2GE_dxixjs_analytical = GE.d2GE_dxixjs() d2GE_dxixjs_expect = [ [-3070.205333938506, -7565.029777297412, -1222.5200812237945], [-7565.029777297412, -2156.7810946064815, -1083.4743126696396], [-1222.5200812237945, -1083.4743126696396, -3835.5941234746824] ] assert_close2d(d2GE_dxixjs_analytical, d2GE_dxixjs_expect, rtol=1e-12) assert_close2d(d2GE_dxixjs_analytical, d2GE_dxixjs_numerical, rtol=1e-4) # d3GE_dxixjxks - very limited accuracy. def d2GE_dxixj_diff(xs): return GE.to_T_xs(T, xs).dGE_dxs() d3GE_dxixjxks_numerical = hessian(d2GE_dxixj_diff, xs, perturbation=2e-5, scalar=False) d3GE_dxixjxks_analytical = GE.d3GE_dxixjxks() d3GE_dxixjxks_expect = [ [[614.0681113650099, 14845.66663517824, 556.3625424156468], [14845.66663517824, 8308.935636377626, 4549.175136703878], [556.3625424156469, 4549.175136703878, 501.6902853815983]], [[14845.66663517824, 8308.935636377626, 4549.175136703878], [8308.935636377626, 173.08338078843053, 375.4114802651511], [4549.175136703877, 375.411480265151, -40.24127966770044]], [[556.3625424156469, 4549.175136703877, 501.6902853815977], [4549.175136703877, 375.411480265151, -40.241279667700574], [501.6902853815964, -40.24127966770071, 6254.612872590844]] ] assert_close3d(d3GE_dxixjxks_analytical, d3GE_dxixjxks_expect, rtol=1e-12) assert_close3d(d3GE_dxixjxks_numerical, d3GE_dxixjxks_analytical, rtol=1e-3) ### TEST WHICH ARE COMMON TO ALL GibbsExcess classes HE_expected = -963.3892533542517 HE_analytical = GE.HE() assert_allclose(HE_expected, HE_analytical, rtol=1e-12) def diff_for_HE(T): return GE.to_T_xs(T, xs).GE() / T HE_numerical = -derivative(diff_for_HE, T, order=13) * T**2 assert_close(HE_analytical, HE_numerical, rtol=1e-12) SE_expected = -4.355962766232997 SE_analytical = GE.SE() assert_allclose(SE_expected, SE_analytical, rtol=1e-12) SE_check = (GE.HE() - GE.GE()) / T assert_close(SE_analytical, SE_check, rtol=1e-12) def diff_for_Cp(T): return GE.to_T_xs(T, xs).HE() Cp_expected = 9.65439203928121 Cp_analytical = GE.CpE() assert_close(Cp_expected, Cp_analytical, rtol=1e-12) Cp_numerical = derivative(diff_for_Cp, T, order=13) assert_close(Cp_numerical, Cp_analytical, rtol=1e-12) def diff_for_dS_dT(T): return GE.to_T_xs(T, xs).SE() dS_dT_expected = 0.02913038452501723 dS_dT_analytical = GE.dSE_dT() assert_close(dS_dT_expected, dS_dT_analytical, rtol=1e-12) dS_dT_numerical = derivative(diff_for_dS_dT, T, order=9) assert_close(dS_dT_analytical, dS_dT_numerical, rtol=1e-12) def diff_for_dHE_dx(xs): return GE.to_T_xs(T, xs).HE() dHE_dx_expected = [ 1176.4668189892636, -7115.980836078867, 20.96726746813556 ] dHE_dx_analytical = GE.dHE_dxs() assert_close1d(dHE_dx_expected, dHE_dx_analytical, rtol=1e-12) dHE_dx_numerical = jacobian(diff_for_dHE_dx, xs, perturbation=5e-7) assert_close1d(dHE_dx_expected, dHE_dx_numerical, rtol=4e-6) def diff_for_dHE_dn(xs): xs = normalize(xs) return GE.to_T_xs(T, xs).HE() dHE_dn_expected = [ 2139.856072343515, -6152.591582724615, 984.3565208223869 ] dHE_dn_analytical = GE.dHE_dns() assert_close1d(dHE_dn_expected, dHE_dn_analytical, rtol=1e-12) dHE_dn_numerical = jacobian(diff_for_dHE_dn, xs, perturbation=5e-7) assert_close1d(dHE_dn_expected, dHE_dn_numerical, rtol=1e-6) def diff_for_dnHE_dn(xs): nt = sum(xs) xs = normalize(xs) return nt * GE.to_T_xs(T, xs).HE() dnHE_dn_expected = [ 1176.4668189892634, -7115.980836078867, 20.967267468135258 ] dnHE_dn_analytical = GE.dnHE_dns() assert_close1d(dnHE_dn_expected, dnHE_dn_analytical, rtol=1e-12) dnHE_dn_numerical = jacobian(diff_for_dnHE_dn, xs, perturbation=5e-7) assert_close1d(dnHE_dn_analytical, dnHE_dn_numerical, rtol=2e-6) def diff_for_dSE_dx(xs): return GE.to_T_xs(T, xs).SE() dSE_dx_expected = [ 10.187806161151178, -13.956324059647036, 6.825249918548415 ] dSE_dx_analytical = GE.dSE_dxs() assert_close1d(dSE_dx_expected, dSE_dx_analytical, rtol=1e-12) dSE_dx_numerical = jacobian(diff_for_dSE_dx, xs, perturbation=5e-7) assert_close1d(dSE_dx_expected, dSE_dx_numerical, rtol=4e-6) def diff_for_dSE_dns(xs): xs = normalize(xs) return GE.to_T_xs(T, xs).SE() dSE_dns_expected = [ 6.2293063092309335, -17.91482391156728, 2.8667500666281707 ] dSE_dns_analytical = GE.dSE_dns() assert_close1d(dSE_dns_expected, dSE_dns_analytical, rtol=1e-12) dSE_dns_numerical = jacobian(diff_for_dSE_dns, xs, perturbation=5e-7) assert_close1d(dSE_dns_expected, dSE_dns_numerical, rtol=1e-6) def diff_for_dnSE_dn(xs): nt = sum(xs) xs = normalize(xs) return nt * GE.to_T_xs(T, xs).SE() dnSE_dn_expected = [ 1.8733435429979384, -22.270786677800274, -1.489212699604825 ] dnSE_dn_analytical = GE.dnSE_dns() assert_close1d(dnSE_dn_expected, dnSE_dn_analytical, rtol=1e-12) dnSE_dn_numerical = jacobian(diff_for_dnSE_dn, xs, perturbation=5e-7) assert_close1d(dnSE_dn_analytical, dnSE_dn_numerical, rtol=2e-6) def diff_for_dGE_dn(xs): xs = normalize(xs) return GE.to_T_xs(T, xs).GE() dGE_dn_expected = [75.3393753381988, -215.2606419529875, 34.25821374047882] dGE_dn_analytical = GE.dGE_dns() assert_close1d(dGE_dn_expected, dGE_dn_analytical, rtol=1e-12) dGE_dn_numerical = jacobian(diff_for_dGE_dn, xs, perturbation=5e-7) assert_close1d(dGE_dn_expected, dGE_dn_numerical, rtol=1e-5) def diff_for_dnGE_dn(xs): nt = sum(xs) xs = normalize(xs) return nt * GE.to_T_xs(T, xs).GE() dnGE_dn_expected = [ 555.6033019688871, 265.0032846777008, 514.5221403711671 ] dnGE_dn_analytical = GE.dnGE_dns() assert_close1d(dnGE_dn_expected, dnGE_dn_analytical, rtol=1e-12) dnGE_dn_numerical = jacobian(diff_for_dnGE_dn, xs, perturbation=5e-7) assert_close1d(dnGE_dn_analytical, dnGE_dn_numerical, rtol=2e-6) lambdas = GE.lambdas() def gammas_to_diff(xs): xs = normalize(xs) return np.array(Wilson_gammas(xs, lambdas)) dgammas_dns_analytical = GE.dgammas_dns() dgammas_dn_numerical = jacobian(gammas_to_diff, xs, scalar=False) dgammas_dn_expect = [ [-0.13968444275751782, -2.135249914756224, 0.6806316652245148], [-1.9215360979146614, 0.23923983797040177, 0.668061736204089], [0.6705598284218852, 0.7313784266789759, -0.47239836472723573] ] assert_close2d(dgammas_dns_analytical, dgammas_dn_numerical, rtol=1e-5) assert_close2d(dgammas_dns_analytical, dgammas_dn_expect, rtol=1e-11) '''# Using numdifftools, the result was confirmed to the four last decimal places (rtol=12-13). from numdifftools import Jacobian (Jacobian(gammas_to_diff, step=1e-6, order=37)(xs)/dgammas_dns_analytical).tolist() ''' dgammas_dT_numerical = ( (np.array(GE.to_T_xs(T + dT, xs).gammas()) - np.array(GE.gammas())) / dT) dgammas_dT_analytical = GE.dgammas_dT() dgammas_dT_expect = [ -0.001575992756074107, 0.008578456201039092, -2.7672076632932624e-05 ] assert_close1d(dgammas_dT_analytical, dgammas_dT_expect, rtol=1e-12) assert_close1d(dgammas_dT_numerical, dgammas_dT_analytical, rtol=2e-6) d2GE_dTdns_expect = [ -6.229306309230934, 17.91482391156728, -2.8667500666281702 ] d2GE_dTdns_analytical = GE.d2GE_dTdns() d2GE_dTdns_numerical = ( (np.array(GE.to_T_xs(T + dT, xs).dGE_dns()) - np.array(GE.dGE_dns())) / dT) assert_close1d(d2GE_dTdns_expect, d2GE_dTdns_analytical, rtol=1e-12) assert_close1d(d2GE_dTdns_analytical, d2GE_dTdns_numerical, rtol=1e-7) d2nGE_dTdns_expect = [ -1.8733435429979375, 22.270786677800274, 1.4892126996048267 ] d2nGE_dTdns_analytical = GE.d2nGE_dTdns() d2nGE_dTdns_numerical = ((np.array(GE.to_T_xs(T + dT, xs).dnGE_dns()) - np.array(GE.dnGE_dns())) / dT) assert_close1d(d2nGE_dTdns_expect, d2nGE_dTdns_analytical, rtol=1e-12) assert_close1d(d2nGE_dTdns_analytical, d2nGE_dTdns_numerical, rtol=1e-6) def to_diff_dnGE2_dninj(ns): nt = sum(ns) xs = normalize(ns) return nt * GE.to_T_xs(T, xs).GE() d2nGE_dninjs_numerical = hessian(to_diff_dnGE2_dninj, xs, perturbation=4e-5) d2nGE_dninjs_analytical = GE.d2nGE_dninjs() d2nGE_dninjs_expect = [ [-314.62613303015996, -4809.450576389065, 1533.0591196845521], [-4809.450576389066, 598.7981063018656, 1672.104888238707], [1533.0591196845517, 1672.1048882387074, -1080.0149225663358] ] assert_close2d(d2nGE_dninjs_analytical, d2nGE_dninjs_expect, rtol=1e-12) assert_close2d(d2nGE_dninjs_numerical, d2nGE_dninjs_analytical, rtol=1e-4)
def test_Psub_Clapeyron(): Psub = Psub_Clapeyron(250.0, Tt=273.15, Pt=611.0, Hsub_t=51100.0) assert_close(Psub, 76.06457150831804)
def test_REFPROP(): sigma = REFPROP_sigma(298.15, 647.096, -0.1306, 2.471, 0.2151, 1.233) assert_close(sigma, 0.07205503890847453)
def test_PR_water_K_value(): K = PR_water_K_value(300, 1e5, 568.7, 2490000.0) assert_close(K, 76131.19143239626)