Skip to content

Commit 8608e5d

Browse files
committed
Fix missing investments in transmission modes in the Investment overview
1 parent e01c962 commit 8608e5d

2 files changed

Lines changed: 39 additions & 19 deletions

File tree

ext/EMGExt/EMGExt.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ Map types to header symbols for saving results.
189189
"""
190190
EMGUI._type_to_header(::Type{<:TransmissionMode}) = :element
191191

192+
"""
193+
EMGUI.get_inv_objs(obj::Transmission)
194+
195+
Get the objects for which investment information should be stored for a given `Transmission`.
196+
This includes obj itself but also its modes.
197+
"""
198+
EMGUI.get_inv_objs(obj::Transmission) = [obj, modes(obj)...]
199+
192200
############################################################################################
193201
## From info_axis_utils.jl
194202
"""

src/utils_GUI/GUI_utils.jl

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,15 @@ get_values(vals::JuMP.Containers.DenseAxisArray, ts::Vector) = Array(value.(vals
501501
get_values(vals::DataFrame, ts::Vector) = vals[in.(vals.t, Ref(ts)), :val]
502502
get_values(vals::TimeProfile, ts::Vector) = vals[ts]
503503

504+
"""
505+
get_inv_objs(obj::AbstractElement)
506+
507+
Get the objects for which investment information should be stored for a given `AbstractElement`.
508+
By default, this is just the element itself, but for some elements (e.g., `Transmission`) it can
509+
be relevant to also store the investment information of related objects (e.g., its modes).
510+
"""
511+
get_inv_objs(obj::AbstractElement) = [obj]
512+
504513
"""
505514
get_investment_times(gui::GUI, max_inst::Float64)
506515
@@ -516,29 +525,32 @@ function get_investment_times(gui::GUI, max_inst::Float64)
516525
period_labels = get_var(gui, :periods_labels)
517526
model = get_model(gui)
518527
for component get_root_design(gui)
519-
element = get_element(component)
528+
# Ensure to include both the component itself and its modes (in case of a transmission) when checking for investments
529+
elements = get_inv_objs(get_element(component))
520530
investment_times = String[]
521531
investment_capex = Float64[]
522-
for (i, t) enumerate(𝒯ᴵⁿᵛ)
523-
for investment_indicator investment_indicators # important not to use shorthand loop syntax here due to the break command (exiting both loops in that case)
524-
sym = Symbol(investment_indicator)
525-
if haskey(model, sym) &&
526-
!isempty(model[sym]) &&
527-
element axes(model[sym])[1]
528-
val = value(model[sym][element, t])
529-
if val > get_var(gui, :tol) * max_inst
530-
capex::Float64 = 0.0
531-
for capex_field capex_fields
532-
capex_key = Symbol(capex_field[1])
533-
if haskey(model, capex_key) &&
534-
element axes(model[capex_key])[1]
535-
capex += value(model[capex_key][element, t])
532+
for element elements
533+
for (i, t) enumerate(𝒯ᴵⁿᵛ)
534+
for investment_indicator investment_indicators # important not to use shorthand loop syntax here due to the break command (exiting both loops in that case)
535+
sym = Symbol(investment_indicator)
536+
if haskey(model, sym) &&
537+
!isempty(model[sym]) &&
538+
element axes(model[sym])[1]
539+
val = value(model[sym][element, t])
540+
if val > get_var(gui, :tol) * max_inst
541+
capex::Float64 = 0.0
542+
for capex_field capex_fields
543+
capex_key = Symbol(capex_field[1])
544+
if haskey(model, capex_key) &&
545+
element axes(model[capex_key])[1]
546+
capex += value(model[capex_key][element, t])
547+
end
536548
end
549+
t_str = split(period_labels[i], " ")[1]
550+
push!(investment_times, t_str)
551+
push!(investment_capex, capex)
552+
break # Do not add the capex again for other elements in investment_indicators
537553
end
538-
t_str = split(period_labels[i], " ")[1]
539-
push!(investment_times, t_str)
540-
push!(investment_capex, capex)
541-
break # Do not add the capex again for other elements in investment_indicators
542554
end
543555
end
544556
end

0 commit comments

Comments
 (0)