You are on page 1of 2

# -*- coding: utf-8 -*-

"""
Created on Sun Oct 1 15:22:09 2023

@author: Farlán
"""

import numpy as np
import pandas as pd
import EOSfunctions as fn
# import EOSfunctionsF2 as fn
from scipy.optimize import least_squares

exp = pd.read_excel('ethanol-water.xlsx', header = 2, usecols=('A:C'))


Temp = np.array(exp.loc[:,'T (°C)'])
Temp = Temp + 273.15
x1 = np.array(exp.loc[:,'x(1)']) #ethanol molar fraction in liquid
y1 = np.array(exp.loc[:,'y(1)']) #ethanol molar fraction in vapor
#
data = pd.read_excel('Properties of Pure Species.xlsx', header = 4, usecols =
'B:H')

substances = np.array([45, 85]) #etanol-agua


prop = np.zeros((len(substances), len(data.loc[0])))

for i in range(len(substances)):
prop[i, :] = data.loc[substances[i]]

P = 1 #bar

def regress_kij(kij, P, T, x1, y1, prop, EOS):

phi_l = np.zeros((len(T), 2))


phi_v = np.zeros((len(T), 2))

mkij= np.array([[0, kij], [kij, 0]], dtype = object)

for el in range(len(T)):
x = np.array([x1[el], 1-x1[el]])
y = np.array([y1[el], 1-y1[el]])

phi_v[el] = fn.phis(P, T[el], y, prop, EOS, 'vap', kij = mkij )

phi_l[el] = fn.phis(P, T[el], x, prop, EOS, 'liq', kij = mkij )

ObFun = sum(np.abs(x1 * phi_l[:, 0] - y1 * phi_v[:, 0] ) + np.abs((1-x1) *


phi_l[:, 1] - (1 - y1) * phi_v[:, 1] ))
#
return ObFun

x0 = 0
kij_ad = least_squares(regress_kij, x0, args=(P, Temp, x1, y1, prop,'SRK'))
print('kij ajustado', kij_ad.x[0])

You might also like