Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Jupyter notebook n-d-M.ipynb

60 views
Kernel: Python 3
import numpy as np from numpy import exp, log, abs import matplotlib.pyplot as plt def M(SG, t): T=t+273.15 return 42.965*exp(2.097E-4*T-7.78712*SG+2.08476E-3*T*SG)*(T**1.26007)*(SG**4.98308) def ndM(n,d,M,S=0): w = (d - 0.851) - 1.11*(n - 1.475) v = 2.51*(n - 1.475) - (d - 0.851) if v > 0: a, b = 430, 0.055 else: a, b = 670, 0.080 if w > 0: CR = 820*w - 3*S + 10000/M RT = 1.33 + 0.146*M*(w - 0.005*S) else: CR = 1440*w - 3*S + 10600/M RT = 1.33 + 0.180*M*(w - 0.005*S) RA = 0.44 + b*v*M RN = RT - RA CA = a*v + 3660/M CN = CR - CA CP = 100 - CR return CP,CN,CA, RT,RA,RN def TBPs(x, A, B, To): To+=273.15 T=To*(A/B*log(1/(1-x)))**(1/B)+To return T-273.15 TBP = np.vectorize(TBPs)
x = np.arange(0, 1, 0.01); #y = [TBP(xx, 0.0125, 1.80881, 525) for xx in x] y1 = TBP(x, 0.5, 1.8, 50) y2 = TBP(x, 0.5, 3.0, 50) #plt.xkcd() plt.grid() plt.xlabel("vol. %") plt.ylabel("t, °C") plt.plot(x*100, y1)+plt.plot(x*100, y2)
[<matplotlib.lines.Line2D at 0x7fc27201e320>, <matplotlib.lines.Line2D at 0x7fc271df8b38>]
Image in a Jupyter notebook
Ant_db=[ ["C5H12", 309.22, 9.159361, 2451.885, -41.136], ["C6H14", 341.88, 9.213541, 2696.039, -48.833], ["C7H16", 371.57, 9.256922, 2910.258, -56.718], ["C8H18", 398.82, 9.327197, 3123.134, -63.515], ["C9H20", 423.97, 9.379719, 3311.186, -70.456], ["C10H22", 447.3, 9.368137, 3442.756, -79.292], ["C11H24", 469.08, 9.433921, 3614.068, -85.450], ["C12H26", 489.48, 9.493213, 3774.559, -91.310], ["C13H28", 508.63, 9.515341, 3892.912, -98.930], ["C14H30", 526.76, 9.527867, 4008.524, -105.430], ["C15H32", 543.83, 9.552251, 4121.512, -111.770], ["C16H34", 559.98, 9.563948, 4214.905, -118.700], ["C17H36", 574.56, 9.53086, 4294.551, -123.950], ["C18H38", 588.3, 9.502999, 4361.787, -129.850], ["C19H40", 602.34, 9.533163, 4450.436, -135.550], ["C20H42", 616.84, 9.848387, 4680.465, -141.050], ["Циклопентан", 322.38, 9.366525, 2653.900, -38.640], ["Метилциклопентан",344.98,9.629388, 2983.098, -34.760], ["Этилциклопентан",376.59, 9.219735, 2978.882, -53.030], ["Циклогексан", 353.93, 9.049205, 2723.438, -52.532], ["Метилциклогексан",374.09, 9.169631, 2972.564, -49.449], ["Бензол", 353.24, 9.176331, 2726.813, -55.578], ["Толуол", 383.79, 9.32646, 3056.958, -55.525], ["Этилбензол", 409.36, 9.368321, 3259.931, -60.850], ["Пропилбензол", 432.35, 9.38681, 3434.996, -65.900], ["Бутилбензол", 456.42, 9.448543, 3627.654, -71.950], ["о-Ксилол", 417.59, 9.43574, 3358.795, -61.109], ["м-Ксилол", 412.34, 9.533877, 3381.814, -57.030], ["п-Ксилол", 411.53, 9.451974, 3331.454, -58.523] ] def ant(t, A, B, C): """Уравнение Антуана для расчета давления насыщенного пара (бар)""" return exp(A-B/(t+273.15+C)) antl = np.vectorize(lambda t, n: ant(t, Ant_db[n][2], Ant_db[n][3], Ant_db[n][4]), excluded=["A", "B", "C"]) #antl = lambda t, n: ant(t, Ant_db[n][2], Ant_db[n][3], Ant_db[n][4]) def bt(t, n1, n2, x): """Расчет давления насыщенного при температуре t пара двухкомпонентной смеси жидкостей n1 и n2 по состава x""" return x*antl(t, n1)+(1-x)*antl(t, n2)
from scipy import optimize P = 1.01325 while True: n1,n2=np.random.choice(len(Ant_db),2) if abs(Ant_db[n1][1]-Ant_db[n2][1])>10: break xi=np.linspace(0, 1, 201) print(Ant_db[n1][1], Ant_db[n2][1]) # Температуры кипения (Bubble Point) bp=np.array([optimize.fsolve(lambda t: bt(t, n1, n2, x)-P, Ant_db[n1][1]*x+(1-x)*Ant_db[n2][1]) for x in xi]).flatten() yi=xi*antl(bp, n1)/P plt.grid() plt.xlim([0,100]) plt.xlabel("Mol. %% %s"%(Ant_db[n1][0])) plt.ylabel("t, °C") plt.title("%s - %s"%(Ant_db[n2][0], Ant_db[n1][0])) plt.plot(xi*100, bp)+plt.plot(yi*100, bp) plt.
469.08 374.09
[<matplotlib.lines.Line2D at 0x7f2173f71c18>, <matplotlib.lines.Line2D at 0x7f216988da58>]
Image in a Jupyter notebook
bp[-1]
183.27354476658181
def f(x): return x**3 y = 2.0 a, b = 0.0, 2.0 xmin, rmin = a, (f(a)-y)**2 for s in range(30): for i in range(1,11): x = a + i*(b-a)/10.0 r = (f(x)-y)**2 if r<rmin: xmin, rmin = x, r a, b = xmin-(b-a)/10.0, xmin+(b-a)/10.0 print(xmin)
2**(1/3.0)
bt(, n1, n2, x)-P
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-10-c070dbc47821> in <module>() ----> 1 bt(t, n1, n2, x)-P NameError: name 't' is not defined
yi.reshape()
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-41-2982e7b2205e> in <module>() ----> 1 yi.reshape() TypeError: function takes exactly 1 argument (0 given)
antl(bp,1).flatten()*xi
array([ 0. , 0.21057646, 0.41025249, 0.59968927, 0.77951167, 0.95030918, 1.112637 , 1.26701726, 1.41394036, 1.55386632, 1.68722625, 1.81442379, 1.93583658, 2.05181768, 2.16269701, 2.26878273, 2.37036259, 2.46770519, 2.56106125, 2.65066475, 2.73673407, 2.81947304, 2.89907191, 2.97570832, 3.04954816, 3.12074638, 3.18944778, 3.25578769, 3.31989268, 3.38188115, 3.44186389, 3.49994466, 3.55622068, 3.61078303, 3.66371716, 3.71510323, 3.7650165 , 3.81352766, 3.86070316, 3.90660546, 3.95129338, 3.99482225, 4.03724422, 4.07860845, 4.11896129, 4.15834649, 4.19680536, 4.23437693, 4.27109811, 4.3070038 , 4.34212702, 4.37649907, 4.4101496 , 4.4431067 , 4.47539704, 4.50704592, 4.53807738, 4.56851426, 4.59837826, 4.62769003, 4.65646923, 4.68473458, 4.7125039 , 4.73979418, 4.76662164, 4.79300174, 4.81894924, 4.84447824, 4.86960222, 4.89433405, 4.91868605, 4.94267002, 4.96629722, 4.98957847, 5.01252413, 5.03514412, 5.05744796, 5.07944478, 5.10114334, 5.12255207, 5.14367904, 5.16453202, 5.18511849, 5.20544562, 5.22552032, 5.24534925, 5.2649388 , 5.28429514, 5.30342422, 5.32233177, 5.34102329, 5.35950412, 5.3777794 , 5.39585409, 5.41373298, 5.43142068, 5.44892167, 5.46624027, 5.48338064, 5.50034684, 5.51714275, 5.53377216, 5.55023873, 5.566546 , 5.58269739, 5.59869622, 5.61454573, 5.63024901, 5.64580911, 5.66122895, 5.67651137, 5.69165915, 5.70667495, 5.72156138, 5.73632097, 5.75095616, 5.76546935, 5.77986285, 5.79413891, 5.80829971, 5.82234739, 5.83628402, 5.85011161, 5.86383212, 5.87744746, 5.89095949, 5.90437 , 5.91768077, 5.93089352, 5.9440099 , 5.95703155, 5.96996006, 5.98279698, 5.99554381, 6.00820202, 6.02077306, 6.03325832, 6.04565918, 6.05797695, 6.07021296, 6.08236846, 6.09444471, 6.1064429 , 6.11836424, 6.13020987, 6.14198093, 6.15367852, 6.16530373, 6.17685761, 6.18834119, 6.19975548, 6.21110148, 6.22238015, 6.23359244, 6.24473926, 6.25582154, 6.26684015, 6.27779597, 6.28868983, 6.29952259, 6.31029505, 6.32100801, 6.33166225, 6.34225855, 6.35279765, 6.36328029, 6.37370719, 6.38407906, 6.3943966 , 6.40466048, 6.41487137, 6.42502993, 6.43513679, 6.4451926 , 6.45519797, 6.4651535 , 6.47505979, 6.48491742, 6.49472697, 6.50448901, 6.51420407, 6.52387272, 6.53349548, 6.54307287, 6.55260542, 6.56209362, 6.57153797, 6.58093896, 6.59029707, 6.59961278, 6.60888654, 6.61811881, 6.62731004, 6.63646067, 6.64557113, 6.65464185, 6.66367325, 6.67266573, 6.68161971, 6.69053559, 6.69941374])
Ant_db={ "C5H12": [309.22, 9.159361, 2451.885, -41.136], "C6H14": [341.88, 9.213541, 2696.039, -48.833], "C7H16": [371.57, 9.256922, 2910.258, -56.718], "C8H18": [398.82, 9.327197, 3123.134, -63.515], "C9H20": [423.97, 9.379719, 3311.186, -70.456], "C10H22": [447.3, 9.368137, 3442.756, -79.292], "C11H24": [469.08, 9.433921, 3614.068, -85.450], "C12H26": [489.48, 9.493213, 3774.559, -91.310], "C13H28": [508.63, 9.515341, 3892.912, -98.930], "C14H30": [526.76, 9.527867, 4008.524, -105.430], "C15H32": [543.83, 9.552251, 4121.512, -111.770], "C16H34": [559.98, 9.563948, 4214.905, -118.700], "C17H36": [574.56, 9.53086, 4294.551, -123.950], "C18H38": [588.3, 9.502999, 4361.787, -129.850], "C19H40": [602.34, 9.533163, 4450.436, -135.550], "C20H42": [616.84, 9.848387, 4680.465, -141.050], "Циклопентан": [322.38, 9.366525, 2653.900, -38.640], "Метилциклопентан": [344.98, 9.629388, 2983.098, -34.760], "Этилциклопентан": [376.59, 9.219735, 2978.882, -53.030], "Циклогексан": [353.93, 9.049205, 2723.438, -52.532], "Метилциклогексан": [374.09, 9.169631, 2972.564, -49.449], "Бензол": [353.24, 9.176331, 2726.813, -55.578], "Толуол": [383.79, 9.32646, 3056.958, -55.525], "Этилбензол": [409.36, 9.368321, 3259.931, -60.850], "Пропилбензол": [432.35, 9.38681, 3434.996, -65.900], "Бутилбензол": [456.42, 9.448543, 3627.654, -71.950], "о-Ксилол": [417.59, 9.43574, 3358.795, -61.109], "м-Ксилол": [412.34, 9.533877, 3381.814, -57.030], "п-Ксилол": [411.53, 9.451974, 3331.454, -58.523] } np.random.choice(list(Ant_db.keys()))
'C9H20'