From 32c3d52de0c51774b6af8757e82342ff72eb28fd Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 19 Aug 2024 12:50:50 +0200 Subject: [PATCH] feat: Simpler implementation of the CHP template and addon with build_priority --- assets/addons/CHP.jl | 29 ++++++----------------- assets/templates/CHP.iesopt.template.yaml | 6 +---- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/assets/addons/CHP.jl b/assets/addons/CHP.jl index f5ac028..b8f576c 100644 --- a/assets/addons/CHP.jl +++ b/assets/addons/CHP.jl @@ -2,29 +2,14 @@ module Addon_CHP import IESopt -function build(comp::IESopt._CoreComponent) - model = comp.model - linked_unit = IESopt.component(model, comp.config["linked"]) - - # Check if linked Unit is already initialized, if not it will be the one to handle everything. - (linked_unit.init_state[] != :initialized) && return - - # Prepare the "heat" and "power" components (for easy access). - if occursin("power", comp.name) - comp_power = comp - comp_heat = linked_unit - elseif occursin("heat", comp.name) - comp_power = linked_unit - comp_heat = comp - else - @error "[Addon_CHP] Encountered unknown heat<>power setup" name = comp.name - return false - end +function build(comp_heat::IESopt._CoreComponent) + model = comp_heat.model + comp_power = IESopt.component(model, comp_heat.config["linked"]) # Get all needed objects / parameters. T = model.ext[:iesopt].model.T - cm = comp.config["cm"] - cv = comp.config["cv"] + cm = comp_heat.config["cm"] + cv = comp_heat.config["cv"] # Extract P_max from the "power component" if comp_power.capacity_carrier.carrier.name != "electricity" @@ -36,12 +21,12 @@ function build(comp::IESopt._CoreComponent) # Construct the backpressure constraint. # `c_m \cdot heat_t <= power_t` - comp.ext["constr_addon_CHP_backpressure"] = + comp_heat.ext["constr_addon_CHP_backpressure"] = IESopt.@constraint(model, [t = T], cm * comp_heat.exp.out_heat[t] <= comp_power.exp.out_electricity[t]) # Construct the isofuel constraint. # `power_t <= p_max - c_v \cdot heat_t` - comp.ext["constr_addon_CHP_isofuel"] = + comp_heat.ext["constr_addon_CHP_isofuel"] = IESopt.@constraint(model, [t = T], comp_power.exp.out_electricity[t] <= p_max - cv * comp_heat.exp.out_heat[t]) @info "[Addon_CHP] Finished constructing constraints" diff --git a/assets/templates/CHP.iesopt.template.yaml b/assets/templates/CHP.iesopt.template.yaml index e126e41..f13896e 100644 --- a/assets/templates/CHP.iesopt.template.yaml +++ b/assets/templates/CHP.iesopt.template.yaml @@ -36,11 +36,7 @@ components: outputs: {electricity: , co2: } conversion: 1 -> electricity + co2 capacity: out:electricity - addon: chp_addon - config: - cm: - cv: - linked: .heat + build_priority: 1 # this component will be built before the heat component with default priority 0 heat: type: Unit