Skip to content

Commit

Permalink
introduce getsites, inhabilitate static optimization, fix #171 + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
longemen3000 committed Apr 18, 2023
1 parent 4181658 commit 6ee2786
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/models/SAFT/SAFTgammaMie/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ function p_scale(model::SAFTgammaMieModel,z=SA[1.0])
return 1/val
end

getsites(model::SAFTgammaMieModel) = model.vrmodel.sites

function a_res(model::SAFTgammaMieModel, V, T, z)
_data = @f(data)
dgc,X,vrdata = _data
Expand Down
31 changes: 21 additions & 10 deletions src/models/SAFT/association.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ function dense_assoc_site_matrix(model,V,T,z,data=nothing)
else
delta = @f(Δ,data)
end
_sites = model.sites.n_sites
sitesparam = getsites(model)
_sites = sitesparam.n_sites
p = _sites.p
ρ = N_A/V

Expand All @@ -189,7 +190,7 @@ function dense_assoc_site_matrix(model,V,T,z,data=nothing)
= delta.values
TT = eltype(_Δ)

_n = model.sites.n_sites.v
_n = sitesparam.n_sites.v

nn = length(_n)
K = zeros(TT,nn,nn)
Expand Down Expand Up @@ -268,7 +269,8 @@ function X(model::EoSModel, V, T, z,data = nothing)
isone(nn) && return X_exact1(model,V,T,z,data)
options = assoc_options(model)
K = assoc_site_matrix(model,V,T,z,data)
idxs = model.sites.n_sites.p
sitesparam = getsites(model)
idxs = sitesparam.n_sites.p
Xsol = assoc_matrix_solve(K,options)
return PackedVofV(idxs,Xsol)
end
Expand Down Expand Up @@ -327,14 +329,15 @@ function X_exact1(model,V,T,z,data=nothing)
= @f(Δ,i,j,a,b,data)
end
_1 = one(eltype(_Δ))
idxs = model.sites.n_sites.p
n = length(model.sites.n_sites.v)
sitesparam = getsites(model)
idxs = sitesparam.n_sites.p
n = length(sitesparam.n_sites.v)
ρ = N_A/V
zi = z[i]
zj = z[j]
ni = model.sites.n_sites[i]
ni = sitesparam.n_sites[i]
na = ni[a]
nj = model.sites.n_sites[j]
nj = sitesparam.n_sites[j]
nb = nj[b]
ρ = N_A/V
kia = na*zi*ρ*
Expand All @@ -355,7 +358,8 @@ function pack_X_exact1(z,xia,xjb,i,j,a,b,n,idxs)
_X[i][a] = xia
return _X
end

#=
#Disabled. see #171
function pack_X_exact1(z::SingleComp,xia,xjb,i,j,a,b,n,idxs)
if (i,a) == (j,b)
Xsol = SA[xia,xia]
Expand All @@ -366,11 +370,18 @@ function pack_X_exact1(z::SingleComp,xia,xjb,i,j,a,b,n,idxs)
end
_X = PackedVofV(idxs,Xsol)
return _X
end
end =#


#helper function to get the sites. in almost all cases, this is model.sites
#but SAFTgammaMie uses model.vrmodel.sites instead

getsites(model) = model.sites

function a_assoc_impl(model::Union{SAFTModel,CPAModel}, V, T, z,X_)
_0 = zero(first(X_.v))
n = model.sites.n_sites
sites = getsites(model)
n = sites.n_sites
res = _0
resᵢₐ = _0
for i @comps
Expand Down
15 changes: 14 additions & 1 deletion test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,20 @@ end
@test model2 isa Clapeyron.EoSModel
end

end
@testset "#171" begin
#=
This is a problem that occurs in an intersection between split_model and cross-association sites
a single component model created from scratch don't have any cross association sites,
but a single component model created from split_model does have those sites.
we neet to check if the results of both are equal.
=#
model = SAFTgammaMie(["water","acetone"])
model_split = split_model(model)[2]
model_pure = SAFTgammaMie(["acetone"])
res_pure = Clapeyron.eos(model_pure,1.013e6,298.15) #works
res_split = Clapeyron.eos(model_split,1.013e6,298.15) #should work
@test res_pure res_split
end
@printline
if Base.VERSION >= v"1.8" #for some reason, it segfaults on julia 1.6
@testset "ambiguities" begin
Expand Down

0 comments on commit 6ee2786

Please sign in to comment.