-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathmodWS.jl
executable file
·114 lines (93 loc) · 3.78 KB
/
modWS.jl
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
abstract type modWSRuleModel <: WSRuleModel end
struct modWSRule{γ} <: WSRuleModel
components::Array{String,1}
activity::γ
references::Array{String,1}
end
"""
modWSRule{γ} <: WSRuleModel
modWSRule(components;
activity = Wilson,
userlocations = String[],
activity_userlocations = String[],
verbose::Bool=false)
## Input Parameters
None
## Input models
- `activity`: Activity Model
## Description
modified Wong-Sandler Mixing Rule.
```
aᵢⱼ = √(aᵢaⱼ)(1 - kᵢⱼ)
bᵢⱼ = (bᵢ + bⱼ)/2
c̄ = ∑cᵢxᵢ
B̄ = Σxᵢxⱼ(bᵢⱼ - aᵢⱼ√(αᵢαⱼ)/RT)
b̄ = B̄/(1 - gᴱ/λRT - Σxᵢaᵢαᵢ/bᵢRT)
ā = RT(b̄ - B̄)
for Redlich-Kwong:
λ = log(2) (0.6931471805599453)
for Peng-Robinson:
λ = 1/(2√(2))log((2+√(2))/(2-√(2))) (0.6232252401402305)
```
`λ` is a coefficient indicating the relation between `gᴱ` and `gᴱ(cubic)` at infinite pressure. see [1] for more information. it can be customized by defining `WS_λ(::WSRuleModel,::CubicModel,z)`
## Model Construction Examples
```
# Using the default database
mixing = modWSRule(["water","carbon dioxide"]) #default: Wilson Activity Coefficient.
mixing = modWSRule(["water","carbon dioxide"],activity = NRTL) #passing another Activity Coefficient Model.
mixing = modWSRule([("ethane",["CH3" => 2]),("butane",["CH2" => 2,"CH3" => 2])],activity = UNIFAC) #passing a GC Activity Coefficient Model.
# Passing a prebuilt model
act_model = NRTL(["water","ethanol"],userlocations = (a = [0.0 3.458; -0.801 0.0],b = [0.0 -586.1; 246.2 0.0], c = [0.0 0.3; 0.3 0.0]))
mixing = modWSRule(["water","ethanol"],activity = act_model)
# Using user-provided parameters
# Passing files or folders
mixing = modWSRule(["water","ethanol"]; activity = NRTL, activity_userlocations = ["path/to/my/db","nrtl_ge.csv"])
# Passing parameters directly
mixing = modWSRule(["water","ethanol"];
activity = NRTL,
userlocations = (a = [0.0 3.458; -0.801 0.0],
b = [0.0 -586.1; 246.2 0.0],
c = [0.0 0.3; 0.3 0.0])
)
```
## References
1. Wong, D. S. H., & Sandler, S. I. (1992). A theoretically correct mixing rule for cubic equations of state. AIChE journal. American Institute of Chemical Engineers, 38(5), 671–680. [doi:10.1002/aic.690380505](https://doi.org/10.1002/aic.690380505)
2. Orbey, H., & Sandler, S. I. (1995). Reformulation of Wong-Sandler mixing rule for cubic equations of state. AIChE journal. American Institute of Chemical Engineers, 41(3), 683–690. [doi:10.1002/aic.690410325](https://doi.org/10.1002/aic.690410325)
"""
modWSRule
export modWSRule
function modWSRule(components; activity = Wilson, userlocations = String[],activity_userlocations = String[], verbose::Bool=false)
_activity = init_mixing_act(activity,components,activity_userlocations,verbose)
references = ["10.1002/aic.690380505","10.1002/aic.690410325"]
model = modWSRule(format_components(components), _activity,references)
return model
end
function mixing_rule(model::ABCubicModel,V,T,z,mixing_model::modWSRuleModel,α,a,b,c)
λ = WS_λ(mixing_model,model,z)
n = sum(z)
invn = (one(n)/n)
RT⁻¹ = 1/(R̄*T)
B̄ = zero(T+V+first(z))
Σab = B̄
for i in @comps
zi = z[i]
αi = α[i]
ai = a[i,i]*αi
bi = b[i,i]
B̄ += zi*zi*(bi-ai*RT⁻¹)
Σab += zi*ai/bi
for j in 1:(i-1)
αj = α[j]
bij = b[i,j]
aij = a[i,j]*sqrt(αi*αj)
B̄ += 2*zi*z[j]*(bij-aij*RT⁻¹)
end
end
Σab = Σab*invn
B̄ = B̄*invn*invn
Aᴱ = excess_gibbs_free_energy(mixing_model.activity,1e5,T,z)*invn
b̄ = B̄/(1 + (Aᴱ/λ - Σab)*RT⁻¹)
ā = b̄*(Σab-Aᴱ/λ)
c̄ = dot(z,c)*invn
return ā,b̄,c̄
end