def dG_RT(T, P_bar, x1, Tc_1, Pc_bar_1, m_1, Tc_2, Pc_bar_2, m_2, Go1, Go2): Pc_1 = Pc_bar_1 * 100 Pc_2 = Pc_bar_2 * 100 P = P_bar * 100 x2 = 1 - x1 b1 = (R * Tc_1) / (8 * Pc_1) b2 = (R * Tc_2) / (8 * Pc_2) bmix = b_mix(x1, x2, b1, b2) a1 = Psat.a(T, Tc_1, Pc_1, m_1) a2 = Psat.a(T, Tc_2, Pc_2, m_2) amix = a_mix(x1, x2, a1, a2) Volumes_1 = Volume_solve(T, P_bar, Pc_bar_1, Tc_1, m_1) Volumes_2 = Volume_solve(T, P_bar, Pc_bar_2, Tc_2, m_2) #Liquid phase: V_l_1 = Volumes_1[0] V_l_2 = Volumes_2[0] if x1 != 0 and x1 != 1: Gi = (x1 * numpy.log(x1) + x2 * numpy.log(x2)) + (Go1 * x1 + Go2 * x2) / (R * T) else: Gi = 0 if V_l_1 != 0 or V_l_2 != 0: Vmix_l = lin_mix(x1, x2, V_l_1, V_l_2) deltaV_l = delta_V(x1, x2, V_l_1, V_l_2) dG_l = P * deltaV_l / (R * T) + x1 * (numpy.log( (V_l_1 - b1) / (Vmix_l - bmix))) + x2 * (numpy.log( (V_l_2 - b2) / (Vmix_l - bmix))) + x1 * (a1 / (R * T * V_l_1)) + x2 * ( a2 / (R * T * V_l_2)) - amix / (R * T * Vmix_l) else: dG_l = 0 #Vapour Phase: V_v_1 = Volumes_1[1] V_v_2 = Volumes_2[1] if V_v_1 != 0 or V_v_2 != 0: Vmix_v = lin_mix(x1, x2, V_v_1, V_v_2) deltaV_v = delta_V(x1, x2, V_v_1, V_v_2) dG_v = P * deltaV_v / (R * T) + x1 * (numpy.log( (V_v_1 - b1) / (Vmix_v - bmix))) + x2 * (numpy.log( (V_v_2 - b2) / (Vmix_v - bmix))) + x1 * (a1 / (R * T * V_v_1)) + x2 * ( a2 / (R * T * V_v_2)) - amix / (R * T * Vmix_v) else: dG_v = 0 return dG_l + dG_v + Gi
def dG_RT(T, P_bar, x1, Tc_1, Pc_bar_1, m_1, Tc_2, Pc_bar_2, m_2, Go1, Go2): Pc_1 = Pc_bar_1*100 Pc_2 = Pc_bar_2*100 P = P_bar*100 x2 = 1- x1 b1 = (R*Tc_1)/(8*Pc_1) b2 = (R*Tc_2)/(8*Pc_2) bmix = b_mix(x1, x2, b1, b2) a1 = Psat.a(T, Tc_1, Pc_1, m_1) a2 = Psat.a(T, Tc_2, Pc_2, m_2) amix = a_mix(x1, x2, a1, a2) Volumes_1 = Volume_solve(T, P_bar, Pc_bar_1, Tc_1, m_1) Volumes_2 = Volume_solve(T, P_bar, Pc_bar_2, Tc_2, m_2) #Liquid phase: V_l_1 = Volumes_1[0] V_l_2 = Volumes_2[0] if x1 != 0 and x1 != 1: Gi = (x1*numpy.log(x1) + x2*numpy.log(x2))+(Go1*x1 + Go2*x2)/(R*T) else: Gi = 0 if V_l_1 != 0 or V_l_2 != 0: Vmix_l = lin_mix(x1, x2, V_l_1, V_l_2) deltaV_l = delta_V(x1, x2, V_l_1, V_l_2) dG_l = P*deltaV_l/(R*T) + x1*(numpy.log((V_l_1 - b1)/(Vmix_l - bmix))) + x2*(numpy.log((V_l_2 - b2)/(Vmix_l - bmix))) + x1*(a1/(R*T*V_l_1)) + x2*(a2/(R*T*V_l_2)) - amix/(R*T*Vmix_l) else: dG_l = 0 #Vapour Phase: V_v_1 = Volumes_1[1] V_v_2 = Volumes_2[1] if V_v_1 != 0 or V_v_2 != 0: Vmix_v = lin_mix(x1, x2, V_v_1, V_v_2) deltaV_v = delta_V(x1, x2, V_v_1, V_v_2) dG_v = P*deltaV_v/(R*T) + x1*(numpy.log((V_v_1 - b1)/(Vmix_v - bmix))) + x2*(numpy.log((V_v_2 - b2)/(Vmix_v - bmix))) + x1*(a1/(R*T*V_v_1)) + x2*(a2/(R*T*V_v_2)) - amix/(R*T*Vmix_v) else: dG_v = 0 return dG_l+ dG_v+ Gi
def Volume_solve(T, P_bar, Pc_bar, Tc, m): Pc = Pc_bar * 100 P = P_bar * 100 calc = Psat.Psat(T, Tc, Pc_bar, m) P_sat_bar = calc[0] P_sat = P_sat_bar * 100 a_eq = Psat.a(T, Tc, Pc, m) b_eq = (R * Tc) / (8 * Pc) def V_root(V): return Psat.vdw(T, a_eq, b_eq, V, 0) - P if P > P_sat: V_guess = calc[1] * 0.95 V_root = sc_o.fsolve(V_root, V_guess) return [V_root[0], 0] elif P < P_sat: V_guess = calc[2] * 1.05 V_root = sc_o.fsolve(V_root, V_guess) return [0, V_root[0]] else: return [calc[1], calc[2]]
def calculate_and_plot(self, event): self.T_slider_label.SetLabel('Isotherm Temperature = ' + str(self.T_slider.GetValue()) + ' K') Tc = 0 Pc = 0 m = 0 T = float(self.T_slider.GetValue()) T_Text = str(self.T_slider.GetValue()) Tc_text = self.Tc_input.GetValue() Pc_text = self.Pc_input.GetValue() m_text = self.m_input.GetValue() if (Tc_text != '') and (Pc_text != '') and (m_text != ''): Tc = float(Tc_text) Pc = float(Pc_text)*100 m = float(m_text) # Bereken aCrit if (Tc != 0) and (Pc != 0) and (m != 0): R = Psat.R ac = (27*R*R*Tc*Tc)/(64*Pc) b = (R*Tc)/(8*Pc) calc = Psat.Psat(T, Tc, Pc/100, m) Psatval = calc[0] self.ac_label = str(round(ac,4)) self.b_label = str(round(b,4)) if np.isreal(Psatval): self.Psat_label = str(round(Psatval,4)) else: self.Psat_label = Psatval self.ac_val.SetLabel('ac = ' + self.ac_label) self.b_val.SetLabel('b = ' + self.b_label) self.m_val.SetLabel('m = ' + m_text) self.P_sat.SetLabel('Psat = '+ self.Psat_label) #Calculate datapoints for vdw EOS Data = np.zeros((1001)) Line_Data = np.zeros((1001)) for k in range(0,1001): Data[k] = 100000*((0.1**(10-0.01*k))) + b+0.01 Value = max([min([Psat.vdw(T,Psat.a(T, Tc, Pc, m),b , Data[k],0)/100, 100]), -1000]) V_l = calc[1] V_v = calc[2] if Data[k] < V_l or Data[k] > V_v: Line_Data[k] = Value else: Line_Data[k] = Psatval Plot_Data1 = np.vstack((Data, Line_Data)).T Isotherm = PolyLine(Plot_Data1, legend= 'Isotherm, T = ' + T_Text, colour='blue') self.canvas.Draw(PlotGraphics([Isotherm], '', ' V', 'P')) self.canvas.setLogScale((True, False))
def G_RT_main(T, P_bar, x1,Tc_1, Pc_1_bar, m_1, Tc_2, Pc_2_bar, m_2): Pc_1 = Pc_1_bar*100 Pc_2 = Pc_2_bar*100 P = P_bar*100 x2 = 1-x1 a_1 = Psat.a(T, Tc_1, Pc_1, m_1) a_2 = Psat.a(T, Tc_2, Pc_2, m_2) b_1 = (R*Tc_1)/(8*Pc_1) b_2 = (R*Tc_2)/(8*Pc_2) amix = a_mix(a_1, a_2, x1) bmix = b_mix(b_1, b_2, x1) volumes = dV(T, P_bar, x1, Tc_1, Pc_1_bar, Tc_2, Pc_2_bar, m_1, m_2) delta_V = volumes[0] V_i = [volumes[1], volumes[2]] Vmix = volumes[3] term_1 = P*delta_V[0]/R*T term_2_1 = numpy.log((V_i[0]-b_1)/(Vmix-bmix)) term_2_2 = numpy.log((V_i[1]-b_2)/(Vmix-bmix)) term_2 = x1*term_2_1 + x2*term_2_2 term_3_1 = a_1/(R*T*V_i[0]) term_3_2 = a_2/(R*T*V_i[1]) term_3 = x1*term_3_1 + x2*term_3_2 term_4 = -amix/(R*T*Vmix) terms = [term_1, term_2, term_3, term_4] return sum(terms)
def V_single(T, Tc, P_bar, Pc_bar, m): Pc = Pc_bar*100 P = P_bar*100 calc = Psat.Psat(T, Tc, Pc_bar, m) sat_P = calc[0]*100 a_eq = Psat.a(T, Tc, Pc, m) b = (R*Tc)/(8*Pc) def eq(V): return abs(Psat.vdw(T, a_eq, b, V, 0) - P) if P > sat_P: V_id_l = sc_o.fsolve(eq, [0.99*calc[1]]) return [V_id_l] elif P < sat_P: V_id_v = sc_o.fsolve(eq, [1.01*calc[2]]) return [V_id_v] else: V_id_l = calc[1] V_id_v = calc[2] return [V_id_l, V_id_v]
def Volume_solve(T, P_bar, Pc_bar, Tc, m): Pc = Pc_bar*100 P = P_bar*100 calc = Psat.Psat(T, Tc, Pc_bar, m) P_sat_bar = calc[0] P_sat = P_sat_bar*100 a_eq = Psat.a(T, Tc, Pc, m) b_eq = (R*Tc)/(8*Pc) def V_root(V): return Psat.vdw(T, a_eq, b_eq, V, 0)-P if P > P_sat: V_guess = calc[1]*0.95 V_root = sc_o.fsolve(V_root,V_guess) return [V_root[0], 0] elif P < P_sat: V_guess = calc[2]*1.05 V_root = sc_o.fsolve(V_root,V_guess) return [0, V_root[0]] else: return[calc[1], calc[2]]
def calculate_and_plot(self, event): self.T_slider_label.SetLabel('Isotherm Temperature = ' + str(self.T_slider.GetValue()) + ' K') Tc = 0 Pc = 0 m = 0 T = float(self.T_slider.GetValue()) T_Text = str(self.T_slider.GetValue()) Tc_text = self.Tc_input.GetValue() Pc_text = self.Pc_input.GetValue() m_text = self.m_input.GetValue() if (Tc_text != '') and (Pc_text != '') and (m_text != ''): Tc = float(Tc_text) Pc = float(Pc_text) * 100 m = float(m_text) # Bereken aCrit if (Tc != 0) and (Pc != 0) and (m != 0): R = Psat.R ac = (27 * R * R * Tc * Tc) / (64 * Pc) b = (R * Tc) / (8 * Pc) calc = Psat.Psat(T, Tc, Pc / 100, m) Psatval = calc[0] self.ac_label = str(round(ac, 4)) self.b_label = str(round(b, 4)) if np.isreal(Psatval): self.Psat_label = str(round(Psatval, 4)) else: self.Psat_label = Psatval self.ac_val.SetLabel('ac = ' + self.ac_label) self.b_val.SetLabel('b = ' + self.b_label) self.m_val.SetLabel('m = ' + m_text) self.P_sat.SetLabel('Psat = ' + self.Psat_label) #Calculate datapoints for vdw EOS Data = np.zeros((1001)) Line_Data = np.zeros((1001)) for k in range(0, 1001): Data[k] = 100000 * ((0.1**(10 - 0.01 * k))) + b + 0.01 Value = max([ min([ Psat.vdw(T, Psat.a(T, Tc, Pc, m), b, Data[k], 0) / 100, 100 ]), -1000 ]) V_l = calc[1] V_v = calc[2] if Data[k] < V_l or Data[k] > V_v: Line_Data[k] = Value else: Line_Data[k] = Psatval Plot_Data1 = np.vstack((Data, Line_Data)).T Isotherm = PolyLine(Plot_Data1, legend='Isotherm, T = ' + T_Text, colour='blue') self.canvas.Draw(PlotGraphics([Isotherm], '', ' V', 'P')) self.canvas.setLogScale((True, False))