z[0], Z)) # Calc both lnphi Zmin = np.min(Z) Zmax = np.max(Z) ln_phi_z, Z = pr.checkG(b_i, a_mix, b_mix, sum_xiAij, Z, z) d = ln_phi_z + np.log(z) G_R.append(np.dot(d, z)) x_1.append(z[0]) lnphi_x1.append(ln_phi_z[0]) lnphi_x2.append(ln_phi_z[1]) # Plot higher G root as dotted line if Z == Zmin: ln_phi_max = pr.ln_phi_calc(b_i, a_mix, b_mix, sum_xiAij, Zmax) d1 = ln_phi_max + np.log(z) G_R2.append(np.dot(d1, z)) x_1_2.append(z[0]) lnphi_x1_2.append(ln_phi_max[0]) lnphi_x2_2.append(ln_phi_max[1]) elif Z == Zmax and Zmin > 0: ln_phi_min = pr.ln_phi_calc(b_i, a_mix, b_mix, sum_xiAij, Zmin) d1 = ln_phi_min + np.log(z) G_R2.append(np.dot(d1, z)) x_1_2.append(z[0]) lnphi_x1_2.append(ln_phi_min[0]) lnphi_x2_2.append(ln_phi_min[1]) else:
sum_x_min = 0.736707 #0.001 sum_x_max = 0.736707 #10. num_sum_x = 1 X = [] y = [] for a_mix in np.linspace(a_mix_min, a_mix_max, num_a_mix): for b_mix in np.linspace(b_mix_min, b_mix_max, num_b_mix): # Check if single root Z = pr.Z_roots_calc(a_mix, b_mix) if len(Z) > 1: continue else: for b_i in np.linspace(b_i_min, b_i_max, num_b_i): for sum_xjAij in np.linspace(sum_x_min, sum_x_max, num_sum_x): # Get lnphi lnphi = pr.ln_phi_calc(b_i, a_mix, b_mix, sum_xjAij, Z) # Store X.append(a_mix) y.append(lnphi) plt.plot(X, y, 'ro') plt.xlabel('a_mix') plt.ylabel('lnphi') plt.title('Lnphi vs a_mix, all else constant') plt.show() print(X) print(y)
print('{} %'.format(itx / num_P * 100)) for T in np.linspace(T_min, T_max, num_T): Tr = T / Tc # Get all ai, bi values a_i, b_i = pr.aibi(P, T, w, Pr, Tr, Pc, Tc) # Get Vw mixing, part with BIPs and square roots Am = pr.Vw(Nc, a_i, BIP) for x[0] in np.linspace(x_nC4_min, x_nC4_max, num_x_nC4): x[1] = 1 - x[0] sum_xiAij = pr.sum_a_interations(Nc, x, Am) a_mix = pr.am(x, sum_xiAij) b_mix = pr.bm(x, b_i) # All EOS variables defined, solve EOS Z = pr.Z_roots_calc(a_mix, b_mix) #todo get this to reject multiple positive real roots. # If more than one root, get ln_phi and root which correspond to lowest Gibbs energy if len(Z) > 1 and min(Z) > 0: #print('2 positive real roots at P = {} bar, T = {} K.'.format(P,T)) continue else: Z = max(Z) ln_phi_x = pr.ln_phi_calc(b_i, a_mix, b_mix, sum_xiAij, Z) data_writer(datafilename, a_mix, b_mix, b_i[1], sum_xiAij[1], ln_phi_x[1])
sum_x_min = 0.001 sum_x_max = 10. num_sum_x = 100 for itx, a_mix in enumerate(np.linspace(a_mix_min, a_mix_max, num_a_mix)): print('{} %'.format(itx / num_a_mix * 100)) # Approximate progress for b_mix in np.linspace(b_mix_min, b_mix_max, num_b_mix): # Calc Z Z = pr.Z_roots_calc(a_mix, b_mix) if len(Z) > 1 and (0 < max(Z) < 0.3074 ): # Is this needed? Has not happened yet. print('Zmax in [0, 0.3074]') # Liquid root if 0 < min(Z) < 0.3074: for b_i in np.linspace(b_i_min, b_i_max, num_b_i): for sum_xjAij in np.linspace(sum_x_min, sum_x_max, num_sum_x): lnphi = pr.ln_phi_calc(b_i, a_mix, b_mix, sum_xjAij, min(Z)) data_writer(datafilename[0], a_mix, b_mix, b_i, sum_xjAij, lnphi) # Vapor root if 0.3074 < max(Z): for b_i in np.linspace(b_i_min, b_i_max, num_b_i): for sum_xjAij in np.linspace(sum_x_min, sum_x_max, num_sum_x): lnphi = pr.ln_phi_calc(b_i, a_mix, b_mix, sum_xjAij, max(Z)) data_writer(datafilename[1], a_mix, b_mix, b_i, sum_xjAij, lnphi)