Skip to content

Commit

Permalink
Fix #78
Browse files Browse the repository at this point in the history
  • Loading branch information
VEZY committed Jul 18, 2024
1 parent db45685 commit 8a13cb7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/dependencies/dependency_graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ Return a NamedTuple with the variables and their default values.
The `vars_mapping` is a dictionary with the organ type as key and a dictionary as value. It is
computed from the user mapping like so:
```julia
full_vars_mapping = Dict(first(mod) => Dict(get_mapping(last(mod))) for mod in mapping)
```
"""
function variables_multiscale(node, organ, vars_mapping, st=NamedTuple())
node_vars = variables(node) # e.g. (inputs = (:var1=-Inf, :var2=-Inf), outputs = (:var3=-Inf,))
Expand All @@ -127,11 +123,18 @@ function variables_multiscale(node, organ, vars_mapping, st=NamedTuple())
if haskey(vars_mapping[organ], var)
organ_mapped, organ_mapped_var = _node_mapping(vars_mapping[organ][var])
push!(vars_, var => MappedVar(organ_mapped, var, organ_mapped_var, default))
#* We still check if the variable also exists wrapped in PreviousTimeStep, because one model could use the current
#* values, and another one the previous values.
if haskey(vars_mapping[organ], PreviousTimeStep(var, node.process))
organ_mapped, organ_mapped_var = _node_mapping(vars_mapping[organ][PreviousTimeStep(var, node.process)])
push!(vars_, var => MappedVar(organ_mapped, PreviousTimeStep(var, node.process), organ_mapped_var, default))
end
elseif haskey(vars_mapping[organ], PreviousTimeStep(var, node.process))
# The variable is mapped to the previous time step:
# If not found in the current time step, we check if the variable is mapped to the previous time step:
organ_mapped, organ_mapped_var = _node_mapping(vars_mapping[organ][PreviousTimeStep(var, node.process)])
push!(vars_, var => MappedVar(organ_mapped, PreviousTimeStep(var, node.process), organ_mapped_var, default))
else
# Else we take the default value:
push!(vars_, var => default)
end
end
Expand Down
3 changes: 2 additions & 1 deletion src/mtg/MultiScaleModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ struct MultiScaleModel{T<:AbstractModel,V<:AbstractVector{Pair{A,Union{Pair{S,Sy
process_ = process(model)
unfolded_mapping = Pair{Union{Symbol,PreviousTimeStep},Union{Pair{String,Symbol},Vector{Pair{String,Symbol}}}}[]
for i in mapping
push!(unfolded_mapping, _get_var(Pair(i.first, i.second), process_))
push!(unfolded_mapping, _get_var(isa(i, PreviousTimeStep) ? i : Pair(i.first, i.second), process_))
# Note: We are using Pair(i.first, i.second) to make sure the Pair is specialized enough, because sometimes the vector in the mapping made the Pair not specialized enough e.g. [:v1 => "S" => :v2,:v3 => "S"] makes the pairs `Pair{Symbol, Any}`.
end

new{T,typeof(unfolded_mapping)}(model, unfolded_mapping)
Expand Down

0 comments on commit 8a13cb7

Please sign in to comment.