-
Notifications
You must be signed in to change notification settings - Fork 0
/
activityCoefficientModels.py
120 lines (98 loc) · 4.98 KB
/
activityCoefficientModels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#------------------------------------------------------------------------------------------------------------
#
#
# __ __ ____ _____ ______ _ _____ ______ ____ _____
# | \/ |/ __ \| __ \| ____| | / ____| | ____/ __ \| __ \
# | \ / | | | | | | | |__ | | | (___ | |__ | | | | |__) |
# | |\/| | | | | | | | __| | | \___ \ | __|| | | | _ /
# | | | | |__| | |__| | |____| |____ ____) | | | | |__| | | \ \
# |_| |_|\____/|_____/|______|______|_____/ |_| \____/|_| \_\
# _____ _______ _______ _______ _________ __
# /\ / ____|__ __|_ _\ \ / /_ _|__ __\ \ / /
# / \ | | | | | | \ \ / / | | | | \ \_/ /
# / /\ \| | | | | | \ \/ / | | | | \ /
# / ____ \ |____ | | _| |_ \ / _| |_ | | | |
# /_/ \_\_____| |_| |_____| \/ |_____| |_| |_|
# _____ ____ ______ ______ ______ _____ _____ _____ ______ _ _ _______
# / ____/ __ \| ____| ____| ____|_ _/ ____|_ _| ____| \ | |__ __|
# | | | | | | |__ | |__ | |__ | || | | | | |__ | \| | | |
# | | | | | | __| | __| | __| | || | | | | __| | . ` | | |
# | |___| |__| | |____| | | | _| || |____ _| |_| |____| |\ | | |
# \_____\____/|______|_| |_| |_____\_____|_____|______|_| \_| |_|
#
#
#
#------------------------------------------------------------------------------------------------------------
#
# Technische Universiteit Delft - TUDelft (2022)
#
# Master of Science in Chemical Engineering
#
# This code was developed and tested by ELIA FERRETTI
#
# You can redistribute the code and/or modify it
# Whenever the code is used to produce any publication or document,
# reference to this work and author should be reported
# No warranty of fitness for a particular purpose is offered
# The user must assume the entire risk of using this code
#
#------------------------------------------------------------------------------------------------------------
#
# student name: ELIA FERRETTI
# e-mail: [email protected]
# LinkedIn: https://www.linkedin.com/in/elia-ferretti/
# GitHub: https://github.com/eliaferretti
# Instagram: @eliaferretti
#
#------------------------------------------------------------------------------------------------------------
#import needed library
import numpy as np
def activityCoefficient_WILSON(i,x,W):
N = len(x)
alpha = 0
gamma = 0
for j in range(0,N):
alpha = alpha + x[j]*W[i,j]
for k in range(0,N):
beta = 0
for j in range(0,N):
beta = beta + x[j]*W[k,j]
gamma = gamma + x[k]*W[k,i]/beta
gamma = np.exp( - np.log(alpha) + 1 - gamma )
return gamma
def activityCoefficient_NRTL(i,x,G,tau):
N = len(x)
alpha = 0
beta = 0
phi = 0
for j in range(0,N):
alpha = alpha + tau[j,i]*G[j,i]*x[j]
beta = beta + G[j,i]*x[j]
for j in range(0,N):
gamma = 0; delta = 0; epsilon = 0
for k in range(0,N):
gamma = gamma + G[k,j]*x[k]
delta= delta + x[k]*tau[k,j]*G[k,j]
epsilon = epsilon + x[k]*G[k,j]
phi = phi + x[j]*G[i,j]/gamma*( tau[i,j] - delta/epsilon )
gamma = np.exp( alpha/beta + phi )
return gamma
def activityCoefficient_UNIQUAC(i,x,tau,z,r,q):
N = len(x)
I = z/2*(r-q) - (r - 1)
alpha = 0; beta = 0; gamma = 0; delta = 0; rho = 0
for j in range(0,N):
alpha += q[j]*x[j]
beta += r[j]*x[j]
gamma += x[j]*I[j]
theta = q*x/alpha
phi = r*x/beta
for j in range(0,N):
epsilon = 0
for k in range(0,N):
epsilon += theta[k]*tau[k,j]
delta += theta[j]*tau[j,i]
rho += theta[j]*tau[i,j]/epsilon
logGamma_C = np.log(r[i]/beta) + z/2*q[i]*np.log(q[i]*beta/r[i]/alpha) + I[i] - r[i]/beta*gamma
logGamma_R = q[i]*( 1 - np.log(delta) - rho )
return np.exp(logGamma_C + logGamma_R)