-
Notifications
You must be signed in to change notification settings - Fork 45
/
Asymmetric.jl
176 lines (154 loc) · 5.43 KB
/
Asymmetric.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
struct AsymmetricMixingParam <: EoSParam
gamma_T::PairParam{Float64}
gamma_v::PairParam{Float64}
beta_T::PairParam{Float64}
beta_v::PairParam{Float64}
end
@newmodelsimple AsymmetricMixing MixingRule AsymmetricMixingParam
"""
AsymmetricMixing <: MultiFluidDepartureModel
AsymmetricMixing(components;
userlocations = String[],
verbose = false)
## Input parameters
- `beta_v`: Pair Parameter (`Float64`) - binary interaction parameter (no units)
- `gamma_v`: Pair Parameter (`Float64`) - binary interaction parameter (no units)
- `beta_T`: Pair Parameter (`Float64`) - binary interaction parameter (no units)
- `gamma_T`: Pair Parameter (`Float64`) - binary interaction parameter (no units)
## Description
Asymmetric mixing rule for MultiParameter EoS models:
```
τ = T̄/T
δ = V̄/V
V̄ = ∑xᵢxⱼ * βᵛᵢⱼ * γᵛᵢⱼ * (xᵢ + xⱼ)/(xᵢ*βᵛᵢⱼ^2 + xⱼ) * Vᵣᵢⱼ
T̄ = ∑xᵢxⱼ * βᵛᵢⱼ * γᵀᵢⱼ * (xᵢ + xⱼ)/(xᵢ*βᵀᵢⱼ^2 + xⱼ) * Tᵣᵢⱼ
Vᵣᵢⱼ = 0.125*(∛Vcᵢ + ∛Vcⱼ)^3
Tᵣᵢⱼ = √(Tcᵢ*Tcⱼ)
```
With the asymmetry present in the β parameters:
```
βᵛᵢⱼ = 1/βᵛⱼᵢ
βᵀᵢⱼ = 1/βᵀⱼᵢ
```
If there is no data present, the parameters can be estimated:
- Linear estimation:
```
βᵛᵢⱼ = βᵛᵢⱼ = 1
γᵛᵢⱼ = 4*(Vcᵢ + Vcⱼ)/(∛Vcᵢ + ∛Vcⱼ)^3
γᵀᵢⱼ = 0.5*(Tcᵢ + Tcⱼ)/√(Tcᵢ*Tcⱼ)
```
- Lorentz-Berthelot Estimation:
```
βᵛᵢⱼ = βᵛᵢⱼ = γᵛᵢⱼ = γᵀᵢⱼ = 1
```
## References
1. R. Klimeck, Ph.D. dissertation, Ruhr-Universit¨at Bochum, 2000
"""
AsymmetricMixing
default_locations(::Type{AsymmetricMixing}) = ["Empiric/mixing/AsymmetricMixing/asymmetric_mixing_unlike.csv"]
default_references(::Type{AsymmetricMixing}) = ["Klimeck, Ph.D. dissertation"]
default_getparams_arguments(::Type{AsymmetricMixing},userlocations,verbose) = ParamOptions(;userlocations,verbose,asymmetricparams = ["beta_v","beta_T"])
function transform_params(::Type{AsymmetricMixing},params)
beta_v = params["beta_v"]
beta_T = params["beta_T"]
mirror_pair!(beta_T,inv)
mirror_pair!(beta_v,inv)
return params
end
function recombine_mixing!(model::MultiFluid,mixing::AsymmetricMixing,estimate)
Vc = model.params.Vc.values
Tc = model.params.Tc.values
n = length(model)
γT = mixing.params.gamma_T
γv = mixing.params.gamma_v
βT = mixing.params.beta_T
βv = mixing.params.beta_v
for i in 1:n
for j in 1:n
i == j && continue
if γT.ismissingvalues[i,j]
estimate == :off && __error_estimate_multifluid(i,j)
if estimate == :lb
γT[i,j] = 1.0
elseif estimate == :linear
γT[i,j] = 0.5*(Tc[i]+Tc[j])/sqrt(Tc[i]*Tc[j])
else
throw(error("invalid estimate $estimate"))
end
end
if γv.ismissingvalues[i,j]
estimate == :off && __error_estimate_multifluid(i,j)
if estimate == :lb
γT[i,j] = 1.0
elseif estimate == :linear
γv[i,j] = 0.25*(Vc[i]+Vc[j])/(cbrt(Vc[i])+cbrt(Vc[j])^3)
else
throw(error("invalid estimate $estimate"))
end
end
if βT.ismissingvalues[i,j]
estimate == :off && __error_estimate_multifluid(i,j)
βT[i,j] = 1.0
end
if βv.ismissingvalues[i,j]
estimate == :off && __error_estimate_multifluid(i,j)
βv[i,j] = 1.0
end
end
end
end
function __error_estimate_multifluid(i,j)
throw(error("estimate was set to off, but there are missing values at ($i),($j). you can pass estimate_mixing = :lb or estimate_mixing = :linear to calculate mixing values."))
end
function v_scale(model::MultiFluid,z,mixing::AsymmetricMixing,∑z)
vc = model.params.Vc.values
res = mixing_rule_asymmetric(
mix_mean3,
_gerg_asymmetric_mix_rule,
z,
vc,
mixing.params.gamma_v.values,
mixing.params.beta_v.values,
)
return res/(∑z*∑z)
end
function T_scale(model::MultiFluid,z,mixing::AsymmetricMixing,∑z)
Tc = model.params.Tc.values
#isone(length(z)) && return only(Tc)
return mixing_rule_asymmetric(
mix_geomean,
_gerg_asymmetric_mix_rule,
z,
Tc,
mixing.params.gamma_T.values,
mixing.params.beta_T.values,
)/(∑z*∑z)
end
"""
mixing_rule_asymmetric(op, op_asym, x, p, A, A_asym)
returns an efficient implementation of:
` sum(A[i,j] * x[i] * x[j] * op(p[i],p[j]) * op_asym(x[i],x[j],A_asym[i,j])) for i = 1:n , j = 1:n)`
where `op(p[i],p[j]) == op(p[j],p[i])` , op_asym doesn't follow this symmetry.
"""
function mixing_rule_asymmetric(op, op_asym, x, p, A, A_asym)
N = length(x)
checkbounds(A, N, N)
checkbounds(A_asym, N, N)
@boundscheck checkbounds(p, N)
@inbounds begin
res1 = zero(eltype(x))
for i = 1:N
xi = x[i]
xi != 0 && begin
p_i = p[i]
res1 += p_i * xi^2
for j = 1:i - 1
res1 += 2*xi*x[j]*op(p_i, p[j])*A[i, j]*op_asym(xi, x[j], A_asym[i, j])
end
end
end
end
return res1
end
_gerg_asymmetric_mix_rule(xi, xj, b) = b * (xi + xj) / (xi * b^2 + xj)
export AsymmetricMixing