def getZfromPT(self, _P: float, _T: float): a = 1.0 b = np.real(self._numf_a0(_P, _T)) c = np.real(self._numf_a1(_P, _T)) d = np.real(self._numf_a2(_P, _T)) roots = np.asarray(solve_cubic(a, b, c, d)) real_values = roots[roots > 0] return real_values
def bi(self, i): zeta_c = (0.32903 - 0.076799 * self.mix[i].omega + 0.0211947 * self.mix[i].omega**2) r = np.atleast_1d( solve_cubic(1, 2 - 3 * zeta_c, 3 * zeta_c**2, -zeta_c**3)) omega_b = np.min(r[r >= 0]) return omega_b * (R_IG * self.mix[i].Tc) / self.mix[i].Pc
def _calc_a_and_b(T: float, Tc: float, Pc: float, w: float): Bc = 0.25989 + w * (-0.0217 + 0.00375 * w) bs = solve_cubic(6.0 * w + 1.0, 3.0, 3.0, -1.0, x0=Bc) Bc = np.min([x for x in bs if x > 0]) zeta_c = 1.0 / (3.0 * (1.0 + w * Bc)) omega_b = Bc * zeta_c omega_a = (1.0 - zeta_c * (1.0 - Bc)) ** 3 b = omega_b * R_IG * Tc / Pc a = omega_a * (R_IG * Tc) ** 2 / Pc return a, b
def getZfromPT(self, P, T, y): A = self.thetam(y, T) * P / (R_IG * T)**2 B = self.bm(y) * P / (R_IG * T) _a = 1.0 _b = -(1.0 - B) _c = A - 3 * B * B - 2.0 * B _d = -(A * B - B * B - B**3) roots = np.asarray(solve_cubic(_a, _b, _c, _d)) real_values = roots[roots > 0] return real_values
def getZfromPT(self, P, T, y): A = self.thetam(y, T) * P / (R_IG * T)**2 B = self.bm(y) * P / (R_IG * T) a = 1.0 b = -1.0 c = A - B * (1 + B) d = -A * B roots = np.asarray(solve_cubic(a, b, c, d)) real_values = roots[roots > 0] return real_values
def _calc_a_b_c(i: int, T: float, substances): w = substances[i].omega Pc = substances[i].Pc Tc = substances[i].Tc zeta_c = 0.32903 - 0.076799 * w + 0.0211947 * w ** 2 omega_c = 1.0 - 3.0 * zeta_c c = omega_c * R_IG * Tc / Pc r = np.atleast_1d(solve_cubic(1, 2 - 3 * zeta_c, 3 * zeta_c ** 2, -zeta_c ** 3)) omega_b = np.min(r[r >= 0]) omega_a = ( 3 * zeta_c ** 2 + 3 * (1 - 2 * zeta_c) * omega_b + omega_b ** 2 + 1 - 3 * zeta_c ) a = omega_a * (R_IG * Tc) ** 2 / Pc b = omega_b * (R_IG * Tc) / Pc return a, b, c
def thetai(self, i, T): F = 0.452413 + 1.30982 * self.mix[i].omega - 0.295937 * self.mix[ i].omega**2 zeta_c = (0.32903 - 0.076799 * self.mix[i].omega + 0.0211947 * self.mix[i].omega**2) r = np.atleast_1d( solve_cubic(1, 2 - 3 * zeta_c, 3 * zeta_c**2, -zeta_c**3)) omega_b = np.min(r[r >= 0]) omega_a = (3 * zeta_c**2 + 3 * (1 - 2 * zeta_c) * omega_b + omega_b**2 + 1 - 3 * zeta_c) alpha = (1 + F * (1 - (T / self.mix[i].Tc)**0.5))**2 return alpha * omega_a * (R_IG * self.mix[i].Tc)**2 / self.mix[i].Pc
def getZfromPT(self, P, T, y): b = self.bm(y) theta = self.thetam(y, T) delta = b _Bl = b * P / (R_IG * T) _deltal = delta * P / (R_IG * T) _thetal = theta * P / (R_IG * T)**2 _epsilonl = 0 a = 1.0 b = _deltal - _Bl - 1 c = _thetal + _epsilonl - _deltal * (_Bl + 1) d = -(_epsilonl * (_Bl + 1) + _thetal * _Bl) roots = np.asarray(solve_cubic(a, b, c, d)) real_values = roots[roots > 0] return real_values
def _getZfromPT_helper( b: float, theta: float, delta: float, epsilon: float, T: float, P: float, R_IG: float, ): Bl = b * P / (R_IG * T) deltal = delta * P / (R_IG * T) epsilonl = epsilon * np.power(P / (R_IG * T), 2) thetal = theta * P / np.power(R_IG * T, 2) _b = deltal - Bl - 1.0 _c = thetal + epsilonl - deltal * (1.0 + Bl) _d = -(epsilonl * (Bl + 1.0) + Bl * thetal) roots = np.array(solve_cubic(1.0, _b, _c, _d)) real_values = roots[roots >= 0] return real_values
def getZfromPT(self, P, T, y): b = self.bm(y) theta = self.thetam(y, T) delta = 0 epsilon = 0 _Bl = b * P / (R_IG * T) _deltal = delta * P / (R_IG * T) _thetal = theta * P / (R_IG * T)**2 _epsilonl = epsilon * (P / (R_IG * T))**2 # coefficients Z**3 + a0*Z**2 + a1*Z + a2 = 0 _a0 = _deltal - _Bl - 1 _a1 = _thetal + _epsilonl - _deltal * (_Bl + 1) _a2 = -(_epsilonl * (_Bl + 1) + _thetal * _Bl) roots = np.asarray(solve_cubic(1.0, _a0, _a1, _a2)) real_values = roots[roots > 0] return real_values
def getZfromPT(self, P, T, y): A = self.thetam(y, T) * P / (R_IG * T)**2 B = self.bm(y) * P / (R_IG * T) c = self.cm(y) b = self.bm(y) delta = b + 2 * c epsilon = c * (b + c) theta = self.thetam(y, T) _Bl = b * P / (R_IG * T) _deltal = delta * P / (R_IG * T) _thetal = theta * P / (R_IG * T)**2 _epsilonl = epsilon * (P / (R_IG * T))**2 a = 1.0 b = _deltal - _Bl - 1 c = _thetal + _epsilonl - _deltal * (_Bl + 1) d = -(_epsilonl * (_Bl + 1) + _thetal * _Bl) roots = np.asarray(solve_cubic(a, b, c, d)) real_values = roots[roots > 0] return real_values
def _initialize(self): if self.eosValue == "van_der_waals_1890": thetas = [] self.b = 0 for i in range(self.n): self.b += (0.125 / (self.Pcs[i] / (R_IG * self.Tcs[i]))) * self.y[i] thetas.append(0.42188 * (R_IG * self.Tcs[i])**2 / self.Pcs[i]) self._calculate_theta_mixture(thetas) self.delta = 0.0 self.epsilon = 0.0 elif self.eosValue == "redlich_and_kwong_1949": thetas = [] self.b = 0 for i in range(self.n): self.b += (0.08664 / (self.Pcs[i] / (R_IG * self.Tcs[i]))) * self.y[i] thetas.append( (0.42748 * (R_IG * self.Tcs[i])**2 / self.Pcs[i]) / (self.T / self.Tcs[i])**0.5) self._calculate_theta_mixture(thetas) self.delta = self.b self.epsilon = 0.0 elif self.eosValue == "wilson_1964": thetas = [] self.b = 0 for i in range(self.n): self.b += (0.08664 / (self.Pcs[i] / (R_IG * self.Tcs[i]))) * self.y[i] a = 0.42748 * (R_IG * self.Tcs[i])**2 / self.Pcs[i] alpha = (self.T / self.Tcs[i]) * (1 + (1.57 + 1.62 * self.omegas[i]) * (1.0 / (self.T / self.Tcs[i]) - 1.0)) thetas.append(a * alpha) self._calculate_theta_mixture(thetas) self.delta = self.b self.epsilon = 0.0 elif self.eosValue == "soave_1972": thetas = [] self.b = 0 for i in range(self.n): self.b += (0.08664 / (self.Pcs[i] / (R_IG * self.Tcs[i]))) * self.y[i] a = 0.42748 * (R_IG * self.Tcs[i])**2 / self.Pcs[i] alpha = (1.0 + (0.48 + 1.574 * self.omegas[i] - 0.176 * self.omegas[i]**2) * (1.0 - (self.T / self.Tcs[i])**0.5))**2 thetas.append(a * alpha) self._calculate_theta_mixture(thetas) self.delta = self.b self.epsilon = 0.0 elif self.eosValue == "peng_and_robinson_1976": thetas = [] self.b = 0 for i in range(self.n): self.b += self.y[i] * (0.07780 / (self.Pcs[i] / (R_IG * self.Tcs[i]))) self.symb_bm += (self.symb_ys[i]) * (0.07780 / (self.Pcs[i] / (R_IG * self.Tcs[i]))) _tmpthetas = ((1.0 + (0.37464 + 1.54226 * self.omegas[i] - 0.2699 * self.omegas[i]**2) * (1.0 - (self.T / self.Tcs[i])**0.5))** 2) * (0.45724 * (R_IG * self.Tcs[i])**2 / self.Pcs[i]) thetas.append(_tmpthetas) self._calculate_theta_mixture(thetas) self._symb_calculate_theta_mixture(thetas) self.delta = 2 * self.b self.symb_deltam = 2 * self.symb_bm self.epsilon = -self.b * self.b self.symb_epsilonm = -self.symb_bm**2 elif self.eosValue == "peneloux_et_al_1982": thetas = [] self.b = 0 c = 0 for i in range(self.n): a = 0.42748 * (R_IG * self.Tcs[i])**2 / self.Pcs[i] c += (0.40768 * (R_IG * self.Tcs[i] / self.Pcs[i]) * (0.00385 + 0.08775 * self.omegas[i])) * self.y[i] self.b += (0.08664 / (self.Pcs[i] / (R_IG * self.Tcs[i]))) * self.y[i] alpha = (1.0 + (0.48 + 1.574 * self.omegas[i] - 0.176 * self.omegas[i]**2) * (1.0 - (self.T / self.Tcs[i])**0.5))**2 thetas.append(a * alpha) self.b = self.b - c self._calculate_theta_mixture(thetas) self.delta = self.b + 2 * c self.epsilon = c * (self.b + c) elif self.eosValue == "patel_and_teja_1982": thetas = [] self.b = 0 c = 0 for i in range(self.n): F = 0.45241 + 1.30982 * self.omegas[ i] - 0.295937 * self.omegas[i]**2 zeta_c = (0.32903 - 0.076799 * self.omegas[i] + 0.0211947 * self.omegas[i]**2) r = np.atleast_1d( solve_cubic(1, 2 - 3 * zeta_c, 3 * zeta_c**2, -zeta_c**3)) omega_b = np.min(r[r >= 0]) omega_c = 1 - 3 * zeta_c omega_a = (3 * zeta_c**2 + 3 * (1 - 2 * zeta_c) * omega_b + omega_b**2 + 1 - 3 * zeta_c) c += self.y[i] * omega_c * R_IG * self.Tcs[i] / self.Pcs[i] self.b += self.y[i] * omega_b * R_IG * self.Tcs[i] / self.Pcs[i] alpha = (1 + F * (1 - (self.T / self.Tcs[i])**0.5))**2 a = omega_a * (R_IG * self.Tcs[i])**2 / self.Pcs[i] thetas.append(a * alpha) self._calculate_theta_mixture(thetas) self.delta = self.b + c self.epsilon = -self.b * c elif self.eosValue == "adachi_et_al_1983": thetas = [] self.b = 0 c = 0 b1, b2, b3 = 0, 0, 0 for i in range(self.n): b1 += self.y[i] * (R_IG * self.Tcs[i] * (0.08974 - 0.03452 * self.omegas[i] + 0.00330 * self.omegas[i]**2) / self.Pcs[i]) b2 += self.y[i] * (R_IG * self.Tcs[i] * (0.03686 + 0.00405 * self.omegas[i] - 0.01073 * self.omegas[i]**2 + 0.00157 * self.omegas[i]**3) / self.Pcs[i]) b3 += self.y[i] * (R_IG * self.Tcs[i] * (0.154 + 0.14122 * self.omegas[i] - 0.00272 * self.omegas[i]**2 - 0.00484 * self.omegas[i]**3) / self.Pcs[i]) a = ((R_IG * self.Tcs[i])**2 * (0.44869 + 0.04024 * self.omegas[i] + 0.01111 * self.omegas[i]**2 - 0.00576 * self.omegas[i]**3) / self.Pcs[i]) alpha = (1 + (0.407 + 1.3787 * self.omegas[i] - 0.2933 * self.omegas[i]**2) * (1.0 - (self.T / self.Tcs[i])**0.5))**2 thetas.append(a * alpha) self.b = b1 self._calculate_theta_mixture(thetas) self.delta = b3 - b2 self.epsilon = -b2 * b3 elif self.eosValue == "soave_1984": thetas = [] self.b = 0 self.epsilon = 0 for i in range(self.n): self.b += (0.08333 / (self.Pcs[i] / (R_IG * self.Tcs[i]))) * self.y[i] self.epsilon += (0.001736 / (self.Pcs[i] / (R_IG * self.Tcs[i]))**2 * self.y[i]) a = 0.42188 * (R_IG * self.Tcs[i])**2 / self.Pcs[i] alpha = ( 1.0 + (0.4998 + 1.5928 * self.omegas[i] - 0.19563 * self.omegas[i]**2 + 0.025 * self.omegas[i]**3) * (1.0 - (self.T / self.Tcs[i])**0.5))**2 thetas.append(a * alpha) self._calculate_theta_mixture(thetas) self.delta = self.b elif self.eosValue == "adachi_et_al_1985": thetas = [] self.b = 0 c = 0 for i in range(self.n): a = ((R_IG * self.Tcs[i])**2 * (0.43711 + 0.02366 * self.omegas[i] + 0.10538 * self.omegas[i]**2 + 0.10164 * self.omegas[i]**3) / self.Pcs[i]) self.b += self.y[i] * ( (R_IG * self.Tcs[i]) * (0.08779 - 0.02181 * self.omegas[i] - 0.06708 * self.omegas[i]**2 + 0.10617 * self.omegas[i]**3) / self.Pcs[i]) c += self.y[i] * ((R_IG * self.Tcs[i]) * (0.0506 + 0.04184 * self.omegas[i] + 0.16413 * self.omegas[i]**2 - 0.03975 * self.omegas[i]**3) / self.Pcs[i]) alpha = ( 1 + (0.4406 + 1.7039 * self.omegas[i] - 1.729 * self.omegas[i]**2 + 0.9929 * self.omegas[i]**3) * (1 - (self.T / self.Tcs[i])**0.5))**2 thetas.append(a * alpha) self._calculate_theta_mixture(thetas) self.delta = 2 * c self.epsilon = -c**2 elif self.eosValue == "stryjek_and_vera_1986": thetas = [] self.b = 0 for i in range(self.n): self.b += self.y[i] * (0.07780 / (self.Pcs[i] / (R_IG * self.Tcs[i]))) self.symb_bm += (self.symb_ys[i]) * (0.07780 / (self.Pcs[i] / (R_IG * self.Tcs[i]))) k0 = (0.378893 + 1.48971530 * self.omegas[i] - 0.17131848 * self.omegas[i]**2 + 0.0196554 * self.omegas[i]**3) k1 = 0 name = self.mix.substances[i].Name if name == "hexadecane": k1 = 0.02665 elif name == "hexane": k1 = 0.05104 elif name == "cyclohexane": k1 = 0.07023 elif name == "methane": k1 = -0.00159 elif name == "benzene": k1 = 0.07019 Tr = self.T / self.Tcs[i] k = k0 + k1 * (1 + Tr) * (0.7 - Tr) _tmpthetas = ((1.0 + (k) * (1.0 - (self.T / self.Tcs[i])**0.5)) **2) * (0.45724 * (R_IG * self.Tcs[i])**2 / self.Pcs[i]) thetas.append(_tmpthetas) self._calculate_theta_mixture(thetas) self._symb_calculate_theta_mixture(thetas) self.delta = 2 * self.b self.symb_deltam = 2 * self.symb_bm self.epsilon = -self.b * self.b self.symb_epsilonm = -self.symb_bm**2 elif self.eosValue == "twu_et_al_1995": thetas = [] self.b = 0 for i in range(self.n): self.b += (self.y[i] * (R_IG * self.Tcs[i]) * 0.0777960739039 / self.Pcs[i]) a = (R_IG * self.Tcs[i])**2 * 0.457235528921 / self.Pcs[i] alpha0 = (self.T / self.Tcs[i])**( -0.171813) * 2.718281828459045235360**( 0.125283 * (1 - (self.T / self.Tcs[i])**1.77634)) alpha1 = (self.T / self.Tcs[i])**( -0.607352) * 2.718281828459045235360**( 0.511614 * (1 - (self.T / self.Tcs[i])**2.20517)) alpha = alpha0 + self.omegas[i] * (alpha1 - alpha0) thetas.append(a * alpha) self._calculate_theta_mixture(thetas) self.delta = self.b * 2 self.epsilon = -self.b**2 elif self.eosValue == "ahlers_gmehling_2001": thetas = [] self.b = 0 c = 0 for i in range(self.n): a = 0.45724 * (R_IG * self.Tcs[i])**2 / self.Pcs[i] alpha = (1.0 + (0.37464 + 1.54226 * self.omegas[i] - 0.2699 * self.omegas[i]**2) * (1.0 - (self.T / self.Tcs[i])**0.5))**2 gamma = 246.78 * self.Zcs[i]**2 - 107.21 * self.Zcs[i] + 12.67 n = -74.458 * self.Zcs[i] + 26.966 beta = 0.35 / (0.35 + (n * np.abs( (self.T / self.Tcs[i]) - alpha))**gamma) cc = ((0.3074 - self.Zcs[i]) * R_IG * (self.T / self.Tcs[i]) / self.Pcs[i]) c += (cc * beta) * self.y[i] self.b += self.y[i] * 0.07780 / (self.Pcs[i] / (R_IG * self.Tcs[i])) thetas.append(a * alpha) self._calculate_theta_mixture(thetas) self.b = self.b - c self.delta = self.b * 2 self.epsilon = -self.b * self.b + 4 * self.b * c - 2 * c**2 elif self.eosValue == "gasem_et_al_pr_2001": thetas = [] self.b = 0 for i in range(self.n): a = 0.45724 * (R_IG * self.Tcs[i])**2 / self.Pcs[i] self.b += self.y[i] * 0.07780 / (self.Pcs[i] / (R_IG * self.Tcs[i])) alpha = (1.0 + (0.386590 + 1.50226 * self.omegas[i] - 0.1687 * self.omegas[i]**2) * (1.0 - (self.T / self.Tcs[i])**0.5))**2 thetas.append(a * alpha) self._calculate_theta_mixture(thetas) self.delta = 2 * self.b self.epsilon = -self.b**2 elif self.eosValue == "gasem_et_al_twu_2001": thetas = [] self.b = 0 for i in range(self.n): a = 0.45724 * (R_IG * self.Tcs[i])**2 / self.Pcs[i] self.b += self.y[i] * 0.07780 / (self.Pcs[i] / (R_IG * self.Tcs[i])) alpha0 = (self.T / self.Tcs[i])**( -0.207176) * 2.718281828459045235360**( 0.092099 * (1 - (self.T / self.Tcs[i])**1.94800)) alpha1 = (self.T / self.Tcs[i])**( -0.502297) * 2.718281828459045235360**( 0.603486 * (1 - (self.T / self.Tcs[i])**2.09626)) alpha = alpha0 + self.omegas[i] * (alpha1 - alpha0) thetas.append(a * alpha) self._calculate_theta_mixture(thetas) self.delta = 2 * self.b self.epsilon = -self.b**2 elif self.eosValue == "gasem_et_al_2001": thetas = [] self.b = 0 for i in range(self.n): a = 0.45724 * (R_IG * self.Tcs[i])**2 / self.Pcs[i] self.b += self.y[i] * 0.07780 / (self.Pcs[i] / (R_IG * self.Tcs[i])) A = 2.0 B = 0.836 C = 0.134 D = 0.508 E = -0.0467 Tr = self.T / self.Tcs[i] w = self.omegas[i] alpha = 2.718281828459045235360**((A + B * Tr) * (1.0 - Tr**(C + w * (D + E * w)))) thetas.append(a * alpha) self._calculate_theta_mixture(thetas) self.delta = 2 * self.b self.epsilon = -self.b**2 else: raise ValueError( "Equation of state doesn't exists in the current database")