Skip to content

Commit f3a0939

Browse files
committed
splitting kind of works
1 parent 316d0ad commit f3a0939

File tree

3 files changed

+79
-21
lines changed

3 files changed

+79
-21
lines changed

src/models/Electrolytes/ESElectrolyte.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
include("equations.jl")
2-
3-
41

52
struct ESElectrolyte{T<:IdealModel,c<:EoSModel,i<:IonModel} <: ESElectrolyteModel
63
components::Array{String,1}
@@ -157,8 +154,13 @@ function Base.show(io::IO,mime::MIME"text/plain",model::ESElectrolyteModel)
157154
show_reference_state(io,model;space = true)
158155
end
159156

160-
161-
include("stability.jl")
157+
#=
158+
struct ESElectrolyteWrapper{M} <: ESElectrolyteModel
159+
components::Vector{String}
160+
charge::Vector{Int64}
161+
model::M
162+
salt::SaltParam
163+
end=#
162164

163165
export dielectric_constant, ESElectrolyte
164166

src/models/Electrolytes/ISElectrolyte.jl

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1+
2+
3+
4+
struct ISElectrolite{T<:IdealModel,c<:EoSModel,i<:IonModel} <: ISElectrolyteModel
5+
components::Array{String,1}
6+
idealmodel::T
7+
neutralmodel::c
8+
ionmodel::i
9+
references::Array{String,1}
10+
end
11+
12+
113
struct ISElectrolyteWrapper{M} <: ISElectrolyteModel
214
components::Vector{String}
315
model::M
416
salt::SaltParam
517
end
618

7-
struct ESElectrolyteWrapper{M} <: ESElectrolyteModel
19+
struct ISElectrolyteIdealWrapper{M} <: IdealModel
820
components::Vector{String}
9-
charge::Vector{Int64}
1021
model::M
1122
salt::SaltParam
1223
end
1324

14-
struct ISElectrolite{T<:IdealModel,c<:EoSModel,i<:IonModel} <: ISElectrolyteModel
15-
components::Array{String,1}
16-
idealmodel::T
17-
neutralmodel::c
18-
ionmodel::i
19-
references::Array{String,1}
20-
end
21-
2225
function ISElectrolyteWrapper(model::ESElectrolyteModel)
2326
salt = SaltParam(model)
2427
components = salt.implicit_components
@@ -30,13 +33,29 @@ function a_res(model::ISElectrolyteWrapper, V, T, z)
3033
return a_res(model.model,V,T,w)
3134
end
3235

36+
#=
3337
function a_res(model::ESElectrolyteWrapper, V, T, z)
3438
w = to_salt(model.salt,z)
3539
return a_res(model.model,V,T,w)
40+
end =#
41+
42+
function idealmodel(model::ISElectrolyteWrapper)
43+
return ISElectrolyteIdealWrapper(model.components,idealmodel(model.model),model.salt)
44+
end
45+
46+
function a_ideal(model::ISElectrolyteIdealWrapper,V,T,z)
47+
w = to_ion(model.salt,z)
48+
return a_ideal(model.model,V,T,w)
3649
end
3750

38-
idealmodel(model::ISElectrolyteWrapper) = idealmodel(model.model)
39-
idealmodel(model::ESElectrolyteWrapper) = idealmodel(model.model)
51+
Rgas(model::ISElectrolyteWrapper) = Rgas(model.model)
52+
Rgas(model::ISElectrolyteIdealWrapper) = Rgas(model.model)
53+
54+
function eos_impl(model::ISElectrolyteWrapper,V,T,z)
55+
w = to_ion(model.salt,z)
56+
∑z = sum(z)
57+
return ∑z*Rgas(model)*T*eos_impl(model,V,T,w)
58+
end
4059

4160
function tp_flash_K0!(K,model::ISElectrolyteModel,p,T,z)
4261
neutral = zeros(Bool,length(model))
@@ -54,4 +73,9 @@ function tp_flash_K0!(K,model::ISElectrolyteModel,p,T,z)
5473
return K
5574
end
5675

57-
export ISElectrolyteWrapper
76+
function each_split_model(model::ISElectrolyteWrapper,I_salt)
77+
salt_i,I_ion = IS_each_split_model(model.salt,I_salt)
78+
return ISElectrolyteWrapper(model.components[I_salt],each_split_model(model.model,I_ion),salt_i)
79+
end
80+
81+
export ISElectrolyteWrapper

src/models/Electrolytes/SaltParam.jl

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function explicit_salt_param(comps,salts,Z)
3030
for ion_vals in pairings
3131
ion_i,ni = first(ion_vals),last(ion_vals)
3232
ki = findfirst(isequal(ion_i),comps)
33-
33+
3434
if !isnothing(ki)
3535
ri[ki] = 1/ni
3636
else
@@ -63,8 +63,40 @@ function to_salt(m::SaltParam,z)
6363
return res
6464
end
6565

66-
function to_ion(m::SaltParam,z)
67-
zz = vcat(z,zero(eltype(z)))
66+
function to_ion(m::SaltParam,z)
67+
if size(m.mat,1) == length(z)
68+
zz = similar(z)
69+
zz .= z
70+
else
71+
zz = vcat(z,zero(eltype(z)))
72+
end
6873
ldiv!(m.F,zz)
6974
return zz
7075
end
76+
77+
#from a vector of salts, split a SaltParam, returns a salt param and the ion indices
78+
function IS_each_split_model(salt::SaltParam,I_salt)
79+
nions = length(salt.explicit_components)
80+
m = salt.mat
81+
I_ion_bool = Vector{Bool}(undef,nions)
82+
rr = eachrow(m)
83+
for i in 1:length(rr)-1
84+
if in(i,I_salt)
85+
rri = rr[i]
86+
for k in 1:nions
87+
I_ion_bool[k] = !iszero(rri[k])
88+
end
89+
end
90+
end
91+
I_ion_int = findall(I_ion_bool)
92+
if length(I_ion_int) == length(I_salt)
93+
mm = m[I_salt,I_ion_int]
94+
else
95+
I_salt_plus_charge = vcat(I_salt,nions)
96+
mm = m[I_salt_plus_charge,I_ion_int]
97+
end
98+
split_salt = SaltParam(false,salt.explicit_components[I_ion_int],salt.implicit_components[I_salt],mm,lu(mm))
99+
return split_salt,I_ion_int
100+
end
101+
102+
export SaltParam

0 commit comments

Comments
 (0)