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 eq(V): return abs(Psat.vdw(T, a_eq, b, V, 0) - P)
def V_root(V): return Psat.vdw(T, a_eq, b_eq, V, 0) - P
def V_root(V): return Psat.vdw(T, a_eq, b_eq, V, 0)-P
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))