Skip to content

Commit b59d118

Browse files
committed
add pereira composition generator to tpd
1 parent 86ce13e commit b59d118

File tree

3 files changed

+88
-23
lines changed

3 files changed

+88
-23
lines changed

src/methods/property_solvers/stability/tpd.jl

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ function _tpd(model,p,T,z,cache = tpd_cache(model,p,T,z),break_first = false,lle
327327

328328
#create a list of what test composition strategies we use
329329
tpd_strategies = tpd_plan(model,z,isliquidz,lle,id_test,K_test,pure_test)
330-
330+
verbose && @info "bulk composition d(z) vector: $dz"
331331
for strategy in tpd_strategies
332332
w,phasew,skip = tpd_test_composition!(strategy,cond,w_test,K,dz,verbose)
333333
skip && continue
@@ -382,6 +382,8 @@ function tpd_plan(model,z,is_liquidz,lle,id_test,K_test,pure_test)
382382
end
383383
end
384384
end
385+
386+
385387
return plan
386388
end
387389

@@ -404,8 +406,8 @@ function tpd_test_composition!(strategy,conds,w_test,K,dz,verbose)
404406
w_test ./= sum(w_test)
405407
elseif plan == :pure
406408
z_pure!(w_test,ix)
407-
elseif plan == :electrolyte_balanced
408-
z_electrolyte_balanced!(model,w_test,z,ixx)
409+
elseif plan == :pereira
410+
z_pereira!(w_test,z,ixx)
409411
elseif is_k_plan && !skip_k
410412
if all(iszero,K)
411413
K .= tp_flash_K0(model,p,T,z)
@@ -455,8 +457,8 @@ function tpd_print_strategy(strategy)
455457

456458
elseif plan == :pure
457459
res = "Strategy: pure initial point, test phase: $phase"
458-
elseif plan == :electrolyte_balanced
459-
res = "Strategy: electrolyte-constrainted composition"
460+
elseif plan == :pereira
461+
res = "Strategy: Pereira composition generator"
460462
else
461463
res = ""
462464
end
@@ -504,19 +506,36 @@ function z_pure!(K,i)
504506
K
505507
end
506508

507-
function z_electrolyte_balanced!(model,w_test,z,ixx)
508-
isolv,ielec,ic = ixx
509+
function z_pereira!(w,z,ixx)
510+
i,b,_ = ixx
511+
n = length(z)
512+
@assert n != i
509513

510-
Z = model.charge
511-
Zx = Z[ic]
512-
w_test .= 0
513-
for i in 1:length(model)
514-
isolv == i && (w_test[i] = z[i])
515-
ielec == i && (w_test[i] = z[i])
514+
515+
lb = eps(eltype(w))*1e2
516+
ub = 1.0 - lb
517+
518+
for j = 1:n
519+
if (j == i)
520+
if b > 0
521+
w[j] = 0.5*z[i]
522+
else
523+
w[j] = z[i] + 0.5*(1.0 - z[i])
524+
end
525+
else
526+
if b > 0
527+
w[j] = (1.0 - 0.5*z[i])/(n-1)
528+
else
529+
w[j] = (1.0 - (z[i] + 0.5*(1.0 - z[i])))/(n-1)
530+
end
531+
end
516532
end
517-
Zw = dot(Z,w_test)
518-
w_test[ic] = - Zw/Zx
519-
w_test ./= sum(w_test)
533+
534+
w .= clamp.(w,lb,ub)
535+
sumw = sum(w)
536+
w ./= sumw
537+
return w
538+
520539
end
521540

522541
function z_norm(z,w)
@@ -637,7 +656,6 @@ function K0_lle_init(model::EoSModel, p, T, z)
637656
return K
638657
end
639658

640-
641659
"""
642660
643661

src/models/Electrolytes/ISElectrolyte.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ end
5151
Rgas(model::ISElectrolyteWrapper) = Rgas(model.model)
5252
Rgas(model::ISElectrolyteIdealWrapper) = Rgas(model.model)
5353

54+
#=
5455
function eos_impl(model::ISElectrolyteWrapper,V,T,z)
5556
w = to_ion(model.salt,z)
5657
return eos_impl(model.model,V,T,w)
57-
end
58+
end=#
5859

5960
function tp_flash_K0!(K,model::ISElectrolyteModel,p,T,z)
6061
neutral = ones(Bool,length(model))
@@ -73,8 +74,6 @@ function each_split_model(model::ISElectrolyteWrapper,I_salt)
7374
return ISElectrolyteWrapper(model.components[I_salt],each_split_model(model.model,I_ion),salt_i)
7475
end
7576

76-
export ISElectrolyteWrapper
77-
7877
function volume_impl(model::ISElectrolyteWrapper, p, T, z, phase, threaded, vol0)
7978
w = to_ion(model.salt,z)
8079
return volume(model.model, p, T, w, phase=phase, threaded=threaded, vol0=vol0)
@@ -97,4 +96,6 @@ end
9796
function T_scale(model::ISElectrolyteWrapper,z)
9897
w = to_ion(model.salt,z)
9998
return T_scale(model.model,w)
100-
end
99+
end
100+
101+
export ISElectrolyteWrapper

src/models/Electrolytes/stability.jl

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,49 @@
1-
function tpd_plan(model::ElectrolyteModel,z,is_liquidz,lle,id_test,K_test,pure_test)
1+
function tpd_plan(model::ISElectrolyteModel,z,is_liquidz,lle,id_test,K_test,pure_test)
2+
plan = Tuple{Symbol,Symbol,NTuple{3,Int}}[]
3+
nc = length(model)
4+
neutral = ones(Bool,length(model))
5+
isalts = model.salt.isalts
6+
neutral[isalts] .= false
7+
8+
if is_liquidz && id_test && !lle && iszero(length(isalts))
9+
push!(plan,(:ideal_gas,:vapour,0))
10+
end
11+
12+
ids = sortperm(z)
13+
if is_liquidz
14+
for i in 1:nc
15+
#idx_solvent = ids[i]
16+
#if neutral[idx_solvent]
17+
# push!(plan,(:pure,:liquid,(idx_solvent,0,0)))
18+
#end
19+
if i != nc
20+
push!(plan,(:pereira,:liquid,(i,-1,0)))
21+
push!(plan,(:pereira,:liquid,(i,1,0)))
22+
end
23+
end
24+
if !lle
25+
for i in 1:nc
26+
!iszero(ZZ[i]) && push!(plan,(:pure,:vapour,(ids[i],0,0)))
27+
end
28+
end
29+
else
30+
for i in 1:nc
31+
#idx_solvent = ids[i]
32+
#if neutral[idx_solvent]
33+
# push!(plan,(:pure,:liquid,(idx_solvent,0,0)))
34+
#end
35+
36+
if i != nc
37+
push!(plan,(:pereira,:liquid,(i,-1,0)))
38+
push!(plan,(:pereira,:liquid,(i,1,0)))
39+
end
40+
end
41+
end
42+
return plan
43+
end
44+
45+
#=
46+
function tpd_plan(model::ESElectrolyteModel,z,is_liquidz,lle,id_test,K_test,pure_test)
247
plan = Tuple{Symbol,Symbol,NTuple{3,Int}}[]
348
449
if is_liquidz && id_test && !lle
@@ -59,4 +104,5 @@ function tpd_plan(model::ElectrolyteModel,z,is_liquidz,lle,id_test,K_test,pure_t
59104
end
60105
end
61106
return plan
62-
end
107+
end
108+
=#

0 commit comments

Comments
 (0)