Skip to content

Commit 86ce13e

Browse files
committed
tp_flash seems to work (with initial points)
1 parent f3a0939 commit 86ce13e

File tree

4 files changed

+54
-23
lines changed

4 files changed

+54
-23
lines changed

src/methods/property_solvers/multicomponent/tp_flash/electrolyte_flash.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function tp_flash_michelsen(model::ElectrolyteModel, p, T, z, method = MichelsenTPFlash(),reduced = false)
1+
function tp_flash_michelsen(model::ESElectrolyteModel, p, T, z, method = MichelsenTPFlash(),reduced = false)
22

33
equilibrium = method.equilibrium
44
K0 = method.K0
@@ -329,7 +329,7 @@ function rachfordrice(K, z, Z; β0=nothing, ψ0=nothing, non_inx=FillArrays.Fill
329329
end
330330
end
331331

332-
function michelsen_optimization_of!(g,H,model::ElectrolyteModel,p,T,z,caches,ny_var_and_ψ,gz)
332+
function michelsen_optimization_of!(g,H,model::ESElectrolyteModel,p,T,z,caches,ny_var_and_ψ,gz)
333333
ny_var = @view ny_var_and_ψ[1:end-1]
334334
ψ = ny_var[end]
335335

src/models/Electrolytes/ISElectrolyte.jl

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,13 @@ Rgas(model::ISElectrolyteIdealWrapper) = Rgas(model.model)
5353

5454
function eos_impl(model::ISElectrolyteWrapper,V,T,z)
5555
w = to_ion(model.salt,z)
56-
∑z = sum(z)
57-
return ∑z*Rgas(model)*T*eos_impl(model,V,T,w)
56+
return eos_impl(model.model,V,T,w)
5857
end
5958

6059
function tp_flash_K0!(K,model::ISElectrolyteModel,p,T,z)
61-
neutral = zeros(Bool,length(model))
62-
r = eachrow(model.salt.mat)
63-
for i in 1:length(model)
64-
if count(!iszero,r[i]) == 1
65-
neutral[i] = true
66-
end
67-
end
60+
neutral = ones(Bool,length(model))
61+
isalts = model.salt.isalts
62+
neutral[isalts] .= false
6863
pures = split_model(model,neutral)
6964
psat = first.(extended_saturation_pressure.(pures,T))
7065
K .= 0
@@ -79,3 +74,27 @@ function each_split_model(model::ISElectrolyteWrapper,I_salt)
7974
end
8075

8176
export ISElectrolyteWrapper
77+
78+
function volume_impl(model::ISElectrolyteWrapper, p, T, z, phase, threaded, vol0)
79+
w = to_ion(model.salt,z)
80+
return volume(model.model, p, T, w, phase=phase, threaded=threaded, vol0=vol0)
81+
end
82+
83+
function lb_volume(model::ISElectrolyteWrapper,T,z)
84+
w = to_ion(model.salt,z)
85+
return lb_volume(model.model,T,w)
86+
end
87+
88+
function mw(model::ISElectrolyteWrapper)
89+
return mw(model.neutralmodel)
90+
end
91+
92+
function p_scale(model::ISElectrolyteWrapper,z)
93+
w = to_ion(model.salt,z)
94+
return p_scale(model.model,w)
95+
end
96+
97+
function T_scale(model::ISElectrolyteWrapper,z)
98+
w = to_ion(model.salt,z)
99+
return T_scale(model.model,w)
100+
end

src/models/Electrolytes/SaltParam.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ struct SaltParam <: ClapeyronParam
22
explicit_solvent::Bool
33
explicit_components::Vector{String} #neutrals + ions
44
implicit_components::Vector{String} #neutrals + salts (ion)
5+
isalts::Vector{Int} #Indices of the salts
56
mat::Matrix{Float64} #used to calculate z(ion) -> z(salt)
67
F::LU{Float64, Matrix{Float64}, Vector{Int64}} #used to calculate z(salt) -> z(ion)
78
end
@@ -12,6 +13,7 @@ function explicit_salt_param(comps,salts,Z)
1213
nions = length(Z)
1314
implicit_components = Vector{String}(undef,nions - 1)
1415
mat = zeros(nions,nions)
16+
isalts = Int[]
1517
nneutral = count(iszero,Z)
1618
#we suppose that first there are nneutral neutral components, followed by nions - nneutral ions
1719
for i in 1:nneutral
@@ -25,6 +27,7 @@ function explicit_salt_param(comps,salts,Z)
2527
salt = salts[k]
2628
salt_component = first(salt)
2729
implicit_components[i] = first(salt)
30+
push!(isalts,i)
2831
pairings = last(salt)
2932
ri = rr[i]
3033
for ion_vals in pairings
@@ -40,8 +43,10 @@ function explicit_salt_param(comps,salts,Z)
4043
∑ri = count(!iszero,ri)
4144
ri ./= ∑ri
4245
end
43-
rr[end] .= Z
44-
return SaltParam(explicit_solvent,explicit_components,implicit_components,mat,lu(mat))
46+
if nneutral < nions
47+
rr[end] .= Z
48+
end
49+
return SaltParam(explicit_solvent,explicit_components,implicit_components,isalts,mat,lu(mat))
4550
end
4651

4752
function SaltParam(model::ESElectrolyteModel)
@@ -64,7 +69,7 @@ function to_salt(m::SaltParam,z)
6469
end
6570

6671
function to_ion(m::SaltParam,z)
67-
if size(m.mat,1) == length(z)
72+
if length(m.isalts) == 0
6873
zz = similar(z)
6974
zz .= z
7075
else
@@ -95,7 +100,16 @@ function IS_each_split_model(salt::SaltParam,I_salt)
95100
I_salt_plus_charge = vcat(I_salt,nions)
96101
mm = m[I_salt_plus_charge,I_ion_int]
97102
end
98-
split_salt = SaltParam(false,salt.explicit_components[I_ion_int],salt.implicit_components[I_salt],mm,lu(mm))
103+
104+
isalts = Int[]
105+
for i in 1:length(salt.isalts)
106+
si = salt.isalts[i]
107+
if salt.isalts[i] in I_salt
108+
push!(isalts,si)
109+
end
110+
end
111+
112+
split_salt = SaltParam(false,salt.explicit_components[I_ion_int],salt.implicit_components[I_salt],isalts,mm,lu(mm))
99113
return split_salt,I_ion_int
100114
end
101115

src/models/Electrolytes/electrolytes.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,32 +357,30 @@ function a_res(ionmodel::IonModel, V, T, z, iondata, neutralmodel, neutral_data)
357357
return a_res(ionmodel, V, T, z, iondata)
358358
end
359359

360-
function lb_volume(model::ElectrolyteModel,T,z)
360+
function lb_volume(model::ESElectrolyteModel,T,z)
361361
return lb_volume(model.neutralmodel,T,z)
362362
end
363363

364-
function x0_volume_liquid(model::ElectrolyteModel,p,T,z)
364+
function x0_volume_liquid(model::ESElectrolyteModel,p,T,z)
365365
return x0_volume_liquid(model.neutralmodel,p,T,z)*1.15
366366
end
367367

368-
function x0_volume_gas(model::ElectrolyteModel,p,T,z)
368+
function x0_volume_gas(model::ESElectrolyteModel,p,T,z)
369369
return x0_volume_gas(model.neutralmodel,p,T,z)
370370
end
371371

372-
function mw(model::ElectrolyteModel)
372+
function mw(model::ESElectrolyteModel)
373373
return mw(model.neutralmodel)
374374
end
375375

376-
function p_scale(model::ElectrolyteModel,z)
376+
function p_scale(model::ESElectrolyteModel,z)
377377
return p_scale(model.neutralmodel,z)
378378
end
379379

380-
function T_scale(model::ElectrolyteModel,z)
380+
function T_scale(model::ESElectrolyteModel,z)
381381
return T_scale(model.neutralmodel,z)
382382
end
383383

384-
385-
386384
function debye_length(model::ESElectrolyteModel,V,T,z,ϵ_r = @f(dielectric_constant),∑z = sum(z))
387385
Z = model.charge
388386
return debye_length(V,T,z,ϵ_r,Z)

0 commit comments

Comments
 (0)