Skip to content

Commit

Permalink
fix SL mixing rules, add a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
longemen3000 committed Apr 7, 2022
1 parent 27df406 commit acc2fe5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/models/LatticeFluid/SanchezLacombe/SanchezLacombe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ end
@registermodel SanchezLacombe
const SL = SanchezLacombe


function SanchezLacombe(components;
idealmodel=BasicIdeal,
mixing = SLk0k1lMixingRule,
Expand All @@ -47,6 +46,7 @@ function SanchezLacombe(components;
end

include("mixing/SLk0k1lrule.jl")
include("mixing/SLKrule.jl")

function a_res(model::SanchezLacombe,V,T,z=SA[1.0])
Σz = sum(z)
Expand All @@ -63,10 +63,8 @@ function a_res(model::SanchezLacombe,V,T,z=SA[1.0])
end

function lb_volume(model::SanchezLacombe,z=SA[1.0])
Σz = sum(z)
r = model.params.segment.values
v = model.params.vol.diagvalues
= dot(z,r)
#v_r,ε_r = mix_vε(model,0.0,0.0,z,model.mixing,r̄,Σz)
return sum(r[i]*z[i]*v[i] for i in @comps)
end
Expand Down Expand Up @@ -109,7 +107,7 @@ function x0_sat_pure(model::SanchezLacombe,T,z=SA[1.0])
Tr = T/Ts
nan = zero(Tr)/zero(Tr)
Tr > 1 && return [nan,nan]
Tstar = Tr*PropaneRef_consts.T_c
Tstar = Tr*369.89
rhov = _propaneref_rhovsat(Tstar)
vv = 1/rhov
psat = pressure(model,vv,T)
Expand All @@ -118,7 +116,7 @@ function x0_sat_pure(model::SanchezLacombe,T,z=SA[1.0])
if isnan(vl)
vv = nan
end
return [log10(vl),log10(vv)]
return (log10(vl),log10(vv))
end

export SL,SanchezLacombe,SLk0k1lMixingRule
export SL,SanchezLacombe,SLk0k1lMixingRule
44 changes: 44 additions & 0 deletions src/models/LatticeFluid/SanchezLacombe/mixing/SLKrule.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
struct SLKRule <: SLMixingRule
components::Vector{String}
k::PairParam{Float64}
end

@registermodel SLKRule

function sl_mix(unmixed_vol,unmixed_epsilon,mixmodel::SLKRule)
#dont mind the function names, it performs the correct mixing
premixed_vol= epsilon_LorentzBerthelot(unmixed_vol)
premixed_epsilon = sigma_LorentzBerthelot(unmixed_epsilon)
return premixed_vol,premixed_epsilon
end

function SLKRule(components; userlocations=String[], verbose=false)
params = getparams(components, ["LatticeFluid/SanchezLacombe/mixing/k0k1l_unlike.csv"]; userlocations=userlocations, verbose=verbose)
k = params["k0"]
model = SLKRule(components,k)
return model
end

function mix_vε(model::SanchezLacombe,V,T,z,mix::SLKRule,r̄,Σz)
v = model.params.vol.values
ε = model.params.epsilon.values
isone(length(z)) && return (only(v),only(ε))
r = model.params.segment.values
k = mix.k.values
r̄inv = one(r̄)/
ϕ = @. r* z* r̄inv/Σz
v_r = zero(V+T+first(z))
ε_r = v_r
Σz2 = 1/(Σz*Σz)
for i in @comps
for j in @comps
ϕi = ϕ[i]
ϕj = ϕ[j]
ϕiϕj = ϕi*ϕj
v_r += ϕiϕj*v[i,j]
εij = ε[i,j]*(1-k[i,j])
ε_r += ϕiϕj*εij
end
end
return v_r,ε_r
end
9 changes: 5 additions & 4 deletions src/models/LatticeFluid/SanchezLacombe/mixing/SLk0k1lrule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function SLk0k1lMixingRule(components; userlocations=String[], verbose=false)
k0 = params["k0"]
k1 = params["k1"]
l = params["l"]
model = SLk0k1lMixingRule(components,k0,k1,l)
model = SLk0k1lMixingRule(components,k0,k1,l)
return model
end

Expand All @@ -24,13 +24,14 @@ function sl_mix(unmixed_vol,unmixed_epsilon,mixmodel::SLk0k1lMixingRule)
end

function mix_vε(model::SanchezLacombe,V,T,z,mix::SLk0k1lMixingRule,r̄,Σz)
r = model.params.segment.values
ε = model.params.epsilon.values
v = model.params.vol.values
isone(length(z)) && return (only(v),only(ε))
r = model.params.segment.values
k0 = mix.k0.values
k1 = mix.k1.values
ε = model.params.epsilon.values
r̄inv = one(r̄)/
ϕ = @. r* z* r̄inv/Σz
ϕ = @. r* z* r̄inv/Σz
v_r = zero(V+T+first(z))
ε_r = v_r
Σz2 = 1/(Σz*Σz)
Expand Down
4 changes: 2 additions & 2 deletions src/models/LatticeFluid/SanchezLacombe/mixing/mixing.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abstract type SLMixingRule end
abstract type SLMixingRule <: EoSModel end

function init_model(model::SLMixingRule,components,userlocations,verbose)
return model
Expand All @@ -8,4 +8,4 @@ function init_model(model::Type{<:SLMixingRule},components,userlocations,verbose
verbose && @info("""Now creating Sanchez-Lacombe mixing rule:
$model""")
return model(components;userlocations,verbose)
end
end

0 comments on commit acc2fe5

Please sign in to comment.