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 vdw_residual(params, x, data): T = params['T'].value m = params['m'].value Tc = params['Tc'].value Pc = params['Pc'].value x_range = numpy.size(x, axis=0) model_data = numpy.zeros(x_range) for k in range(x_range): calc = Psat.Psat(x[k], Tc, Pc, m) model_data[k] = calc[0]*100 return (model_data-data)/abs(model_data)
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 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))