Skip to content

Commit

Permalink
fix ismissingvalues handling in group_sum #173
Browse files Browse the repository at this point in the history
  • Loading branch information
longemen3000 committed Apr 19, 2023
1 parent 1abc433 commit e964aaf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/database/combiningrules/group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,22 @@ end

function group_sum!(out::SingleParameter,groups::GroupParameter,param::SingleParameter)
_group_sum!(out.values,groups,param)
out.ismissingvalues .= param.ismissingvalues
v = groups.n_flattenedgroups
missingvals_comps = out.ismissingvalues
missingvals_gc = param.ismissingvalues
#173
gc = length(groups.flattenedgroups)
comps = length(out.values)
for i in 1:comps
is_missing_i = false
vi = v[i]
for j in 1:gc
if v[i] != 0 #if the group count is nonzero, then reduce the ismissing values
is_missing_i = is_missing_i | missingvals_gc[j]
end
end
missingvals_comps[i] = is_missing_i
end
return out
end

Expand All @@ -45,9 +60,10 @@ function group_sum(groups::GroupParameter,param::SingleParameter)
out = SingleParam(param.name,
groups.components,
zeros(float(eltype(param.values)),gc),
param.ismissingvalues,
fill(false,gc),
param.sources,
param.sourcecsvs)
@show gc
return group_sum!(out,groups,param)
end

Expand Down
5 changes: 5 additions & 0 deletions test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ end
structgc_split = Clapeyron.split_model(model_structgc)
@test structgc_split[1].groups.n_intergroups[1] == [0 1; 1 0]
@test structgc_split[2].groups.n_intergroups[1] == [0 2; 2 5]

#from notebooks, #173
nb_test = SAFTgammaMie(["methane","nitrogen","carbon dioxide","ethane","propane","butane","isobutane",
"pentane","isopentane","hexane","heptane","octane"])
@test length(split_model(nb_test)) == 12
end

@testset "single component error" begin
Expand Down

0 comments on commit e964aaf

Please sign in to comment.