def report_f_pure(data,options,title,print_options): n = len(data[0]) f = np.array(menus.flatten(data[0])) x = np.array(menus.flatten(data[1])) rho = np.array(menus.flatten(data[2])) header = str(';%s\n' % ';'.join(rho)) savedir = str('../output/%s' %title) with open(savedir,'w') as file: file.write(header) for i in range(0,n): lin1 = [str(round(rho[i],9)),str(round(f[i],9))] lin = ('%s\n' % ';'.join(lin1)) file.write(lin)
def bCPA(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') bCPAs = [] for row in readCSV: bCPA = float(row[9]) #bCPA parameter #Organize read values to respective lists bCPAs.append(bCPA) #Finding specific bCPAs bCPAs = menus.flatten(bCPAs) bCPA_ID = [] #Organizing and fingind specific bCPA parameters for i in comp: bCPA_ID.append(bCPAs[i - 1]) return bCPA_ID
def omega(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') omegas = [] for row in readCSV: omega = float(row[4]) #acentric factor #Organize read values to respective lists omegas.append(omega) #Finding specific omegas omegas = menus.flatten(omegas) omega_ID = [] #Organizing and fingind specific acentric factors for i in comp: omega_ID.append(omegas[i - 1]) return omega_ID
def Pc(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') Pcs = [] for row in readCSV: Pc = float(row[3]) #Critical pressure #Organize read values to respective lists Pcs.append(Pc) #Finding specific Pcs Pcs = menus.flatten(Pcs) Pc_ID = [] #Organizing and fingind specific critical pressures for i in comp: Pc_ID.append(Pcs[i - 1]) return Pc_ID
def phi(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') phis = [] for row in readCSV: phi = float(row[14]) #phi parameter #Organize read values to respective lists phis.append(phi) #Finding specific phis phis = menus.flatten(phis) phi_ID = [] #Organizing and fingind specific phi parameters for i in comp: phi_ID.append(phis[i - 1]) return phi_ID
def Tc(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') Tcs = [] for row in readCSV: Tc = float(row[2]) #Critical Temperature #Organize read values to respective lists Tcs.append(Tc) #Finding specific Tcs Tcs = menus.flatten(Tcs) Tc_ID = [] #Organizing and fingind specific critical temperatures for i in comp: Tc_ID.append(Tcs[i - 1]) return Tc_ID
def beta(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') betas = [] for row in readCSV: beta = float(row[12]) #beta parameter #Organize read values to respective lists betas.append(beta) #Finding specific betas betas = menus.flatten(betas) beta_ID = [] #Organizing and fingind specific beta parameters for i in comp: beta_ID.append(betas[i - 1]) return beta_ID
def L(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') Ls = [] for row in readCSV: L = float(row[13]) #L parameter #Organize read values to respective lists Ls.append(L) #Finding specific Ls Ls = menus.flatten(Ls) L_ID = [] #Organizing and fingind specific L parameters for i in comp: L_ID.append(Ls[i - 1]) return L_ID
def c1(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') c1s = [] for row in readCSV: c1 = float(row[10]) #c1 parameter #Organize read values to respective lists c1s.append(c1) #Finding specific c1s c1s = menus.flatten(c1s) c1_ID = [] #Organizing and fingind specific c1 parameters for i in comp: c1_ID.append(c1s[i - 1]) return c1_ID
def en(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') ens = [] for row in readCSV: en = float(row[11]) #en parameter #Organize read values to respective lists ens.append(en) #Finding specific ens ens = menus.flatten(ens) en_ID = [] #Organizing and fingind specific en parameters for i in comp: en_ID.append(ens[i - 1]) return en_ID
def a0(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') a0s = [] for row in readCSV: a0 = float(row[8]) #a0 parameter #Organize read values to respective lists a0s.append(a0) #Finding specific a0s a0s = menus.flatten(a0s) a0_ID = [] #Organizing and fingind specific a0 parameters for i in comp: a0_ID.append(a0s[i - 1]) return a0_ID
def C_antoine(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') Cs = [] for row in readCSV: C = float(row[7]) #C antoine parameter #Organize read values to respective lists Cs.append(C) #Finding specific Cs Cs = menus.flatten(Cs) C_ID = [] #Organizing and fingind specific C antoine parameters for i in comp: C_ID.append(Cs[i - 1]) return C_ID
def B_antoine(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') Bs = [] for row in readCSV: B = float(row[6]) #B antoine parameter #Organize read values to respective lists Bs.append(B) #Finding specific Bs Bs = menus.flatten(Bs) B_ID = [] #Organizing and fingind specific B antoine parameters for i in comp: B_ID.append(Bs[i - 1]) return B_ID
def A_antoine(ID): comp = menus.flatten(ID) with open('properties.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=';') As = [] for row in readCSV: A = float(row[5]) #A antoine parameter #Organize read values to respective lists As.append(A) #Finding specific As As = menus.flatten(As) A_ID = [] #Organizing and fingind specific A antoine parameters for i in comp: A_ID.append(As[i - 1]) return A_ID
def cubic_v_roots(coef,R,T,P): V = [] coef = menus.flatten(coef) coef = np.array(coef) alfa = coef[0] beta = coef[1] gama = coef[2] #Newton Raphson to find first root #Initial guess V1 = R*T/P tol = 1e-10 err = tol+1 i = 1 stop = 1.0 while err>tol or i<3: V1old = V1 F = V1**3+alfa*V1**2+beta*V1+gama dF = 3*V1**2+2*alfa*V1+beta V1 = V1 - stop*F/dF err = abs((V1-V1old)/V1) i = i+1 if i>50: stop = stop/1.1 i = 1 #Solve quadratic equation to find other roots delta = (alfa+V1)**2-4*1*(V1**2+alfa*V1+beta) if delta>0: V2 = (-(alfa+V1)+(delta)**0.5)/2 V3 = (-(alfa+V1)-(delta)**0.5)/2 else: V2 = V1 V3 = V1 V.append(V1) V.append(V2) V.append(V3) return V
def calc_entropy(T,f,P,avdw,rho,h,IDs): f0 = np.array(menus.flatten(f[0])) f1 = np.array(menus.flatten(f[1])) f2 = np.array(menus.flatten(f[2])) T0 = np.array(menus.flatten(T[0])) T1 = np.array(menus.flatten(T[1])) T2 = np.array(menus.flatten(T[2])) rho0 = np.array(menus.flatten(rho[0])) rho1 = np.array(menus.flatten(rho[1])) rho2 = np.array(menus.flatten(rho[2])) P0 = np.array(menus.flatten(P[0])) P1 = np.array(menus.flatten(P[1])) P2 = np.array(menus.flatten(P[2])) avdw0 = np.array(menus.flatten(avdw[0])) V0 = 1/rho0 V1 = 1/rho1 V2 = 1/rho2 A0 = f0/rho0 #MPa.m3/mol A1 = f1/rho1 A2 = f2/rho2 F0 = A0/(R*T0) F1 = A1/(R*T1) F2 = A2/(R*T2) n = len(P1[0]) #Derivatives d2AdT2 = (A2 - 2*A1 + A0)/(h**2) d2FdT2 = (F2 - 2*F1 + F0)/(h**2) dAdT = (A2 - A0)/(2*h) dFdT = (F2 - F0)/(2*h) S_A = -dAdT*1.0e6 # converting from MPa.m3/(mol.K) = 1e-6 J/(mol.K) to J/(mol.K) S_F = -dFdT # 1/K S_F = -dAdT/R # converting from MPa.m3/(mol.K) to adimensional rho = rho[0][0][0] S_A = S_A[0] S_F = S_F[0] A0 = A0[0]*1.0e6 # converting from MPa.m3/mol = 1e-6 J/mol to J/mol f0 = f0[0]*1.0e6 # converting from MPa = 1e-6 J/m3 to J/m3 avdw0 = avdw0[0]*1.0e6 # converting from MPa = 1e-6 J/m3 to J/m3 S_data = [] S_data.append(rho) S_data.append(S_A) S_data.append(S_F) S_data.append(A0) S_data.append(f0) S_data.append(avdw0) return S_data
def report_renorm_bin(rhov,x0v,fm,nx,nd,MR,IDs,EoS): rep = [] x = x0v x1 = np.array(menus.flatten(x)) x2 = 1.0-x1 rhob = rhov[0] xb = np.empty((2)) f2d = np.empty((nx,nd)) rho = np.empty((nx,nd)) dfdrhob = np.empty((nx,nd)) dfdx1 = np.empty((nx,nd)) dfdx2 = np.empty((nx,nd)) rho1 = np.empty((nx,nd)) rho2 = np.empty((nx,nd)) u1mat = np.empty((nx,nd)) u2mat = np.empty((nx,nd)) bmix = np.empty((nx)) b = eos.b_calc(IDs,EoS) b1 = b[0] b2 = b[1] for i in range(0,nx): xb[0] = x1[i] xb[1] = x2[i] bmix[i] = eos.bmix_calc(MR,b,xb) for i in range(0,nx): f = np.array(fm[i]) for j in range(0,nd): f2d[i][j] = f[j] rho[i][j] = rhob[j]/bmix[i] for i in range(0,nx): for j in range(0,nd): rho1[i][j] = x1[i]*rho[i][j] rho2[i][j] = x2[i]*rho[i][j] for i in range(0,nx): dfdrhob[i][0] = (f2d[i][1]-f2d[i][0])/(rhob[1]-rhob[0]) for j in range(1,nd-1): dfdrhob[i][j] = (f2d[i][j+1]-f2d[i][j-1])/(rhob[j+1]-rhob[j-1]) dfdrhob[i][nd-1] = (f2d[i][nd-1]-f2d[i][nd-2])/(rhob[nd-1]-rhob[nd-2]) for i in range(0,nx-1): for j in range(0,nd): if i!=0: dfdx1[i][j] = (f2d[i+1][j]-f2d[i-1][j])/(x1[i+1]-x1[i-1]) else: dfdx1[0][j] = (f2d[1][j]-f2d[0][j])/(x1[1]-x1[0]) dfdx1[nx-1][j] = (f2d[nx-1][j]-f2d[nx-2][j])/(x1[nx-1]-x1[nx-2]) for i in range(0,nx-1): for j in range(0,nd): if i!=0: dfdx2[i][j] = (f2d[i+1][j]-f2d[i-1][j])/(x2[i+1]-x2[i-1]) else: dfdx2[0][j] = (f2d[1][j]-f2d[0][j])/(x2[1]-x2[0]) dfdx2[nx-1][j] = (f2d[nx-1][j]-f2d[nx-2][j])/(x2[nx-1]-x2[nx-2]) for i in range(0,nx): for j in range(0,nd): u1mat[i][j] = dfdrhob[i][j]*b1+dfdx2[i][j]*(0-rho2[i][j])/(rho[i][j]*rho[i][j]) u2mat[i][j] = dfdrhob[i][j]*b2+dfdx1[i][j]*(0-rho1[i][j])/(rho[i][j]*rho[i][j]) u1res_mat = RectBivariateSpline(x,rhob,u1mat) u2res_mat = RectBivariateSpline(x,rhob,u2mat) u1mat_r = [] u2mat_r = [] for i in range(0,nx): u1mat_r.append(u1mat[i]) u2mat_r.append(u2mat[i]) title = 'ren_f.tmp' savedir = str('%s' %title) with open(savedir,'w') as file: dv = str("") for j in range(0,nd): d1 = str(round(rhob[j],9)) dv = dv+';'+d1 file.write(dv) file.write('\n') for i in range(0,nx): x = str(round(x0v[i],9)) f = fm[i] lin1 = x for j in range(0,nd): f1 = str(round(f[j],9)) lin1 = lin1+';'+f1 file.write(lin1) file.write('\n') title = 'u1.tmp' savedir = str('%s' %title) with open(savedir,'w') as file: dv = str("") for j in range(0,nd): d1 = str(round(rhob[j],9)) dv = dv+';'+d1 file.write(dv) file.write('\n') for i in range(0,nx): x = str(round(x0v[i],9)) u = u1mat_r[i] lin1 = x for j in range(0,nd): u1 = str(round(u[j],9)) lin1 = lin1+';'+u1 file.write(lin1) file.write('\n') title = 'u2.tmp' savedir = str('%s' %title) with open(savedir,'w') as file: dv = str("") for j in range(0,nd): d1 = str(round(rhob[j],9)) dv = dv+';'+d1 file.write(dv) file.write('\n') for i in range(0,nx): x = str(round(x0v[i],9)) u = u2mat_r[i] lin1 = x for j in range(0,nd): u2 = str(round(u[j],9)) lin1 = lin1+';'+u2 file.write(lin1) file.write('\n') rep.append(u1res_mat) rep.append(u2res_mat) return rep
def volume_renorm(phase, xint, Pint, bmix, R, T, r_data): Pspln = r_data[5] rho = r_data[3][0] x = np.array(menus.flatten(r_data[1])) nd = len(rho) nx = x.shape[0] Pvec = np.empty((nd)) Pfvec = np.empty((nd)) dPdrho = np.empty((nd)) flag = False inflex = False while flag!=True: #Interpolate specific pressure Pvint = Pspln(xint,0.0001) Pvec[0] = Pvint Pfvec[0] = Pvec[0] - Pint for i in range(1,nd-1): rhoint = float(i)/nd Pvint = Pspln(xint,rhoint) #print i,rhoint,Pvint Pvec[i] = Pvint Pfvec[i] = Pvec[i] - Pint dPdrho[i] = (Pvec[i+1] - Pvec[i-1])/(float(i+1)/nd-float(i-1)/nd) if inflex==False and dPdrho[i]<0: inflex=True Pvint = Pspln(xint,int(nd-1)) Pvec[nd-1] = Pvint Pfvec[nd-1] = Pvec[nd-1] - Pint dPdrho[0] = (Pvec[1] - Pvec[0])/(float(1)/nd-float(0)/nd) dPdrho[nd-1] = (Pvec[nd-1] - Pvec[nd-2])/(float(nd-1)/nd-float(nd-2)/nd) #Bracketing the real densities at given P #print rho #print Pvec #print Pfvec #NEW P_fvec_spl = splrep(rho,Pfvec,k=3) #Cubic Spline Representation Pfvec = splev(rho,P_fvec_spl,der=0) #NEW #plt.plot(rho,Pvec) #plt.ylim(-15,15) #plt.show() max1 = 2 min1 = int(0.90*nd) #it was 0.90 before max2 = max1+2 min2 = min1-2 #raw_input('before') while Pfvec[max1]*Pfvec[max2]>0:# and max2<len(Pfvec): #max2 = max2+int(nd/200) max2 = max2+1 #print 'max',max2 #raw_input('max') if max2-int(nd/100)<0: max1 = 0 #print 'max1',max1 else: #max1 = max2-int(nd/100) max1 = max2-4 #print 'else',max1 while Pfvec[min1]*Pfvec[min2]>0 and min2>0: #min2 = min2-int(nd/200) min2 = min2-1 #print 'min',min2 #raw_input('min') #min1 = min2+int(nd/100) min1 = min2+4 #print 'int',Pint,xint,phase #print 'falsi_spline',rho[max1],rho[max2],rho[min1],rho[min2] #print 'falsi_pressures',Pfvec[max1],Pfvec[max2],Pfvec[min1],Pfvec[min2] #Calculate coexistence densities in interpolated isotherm for given P rho_vap = numerical.falsi_spline(rho, Pfvec, rho[max1], rho[max2], 1e-5) #print 'rho_vap',rho_vap rho_liq = numerical.falsi_spline(rho, Pfvec, rho[min2], rho[min1], 1e-5) #print 'rho_liq',rho_liq #raw_input('...') if inflex==True and abs(rho_vap-rho_liq)<1e-5: Pint=Pint/2 if inflex==True and abs(rho_vap-rho_liq)>1e-5: flag=True if xint>0.05: flag=True #Select desired density if phase<0: rho_out = rho_liq if phase>0: rho_out = rho_vap V = 1/(rho_out/bmix) V_out = [] V_out.append(V) V_out.append(0) return V_out