Skip to content

Commit

Permalink
Merge pull request #2 from daschw/chp-priority
Browse files Browse the repository at this point in the history
feat: Simpler implementation of the CHP template and addon with build_priority
  • Loading branch information
sstroemer authored Aug 19, 2024
2 parents bec6931 + 32c3d52 commit 76a828c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
29 changes: 7 additions & 22 deletions assets/addons/CHP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 1 addition & 5 deletions assets/templates/CHP.iesopt.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ components:
outputs: {electricity: <power_out>, co2: <co2_out>}
conversion: 1 <fuel> -> <efficiency> electricity + <fuel_co2_emission_factor> co2
capacity: <p_max> out:electricity
addon: chp_addon
config:
cm: <power_ratio>
cv: <power_loss_ratio>
linked: <self>.heat
build_priority: 1 # this component will be built before the heat component with default priority 0

heat:
type: Unit
Expand Down

0 comments on commit 76a828c

Please sign in to comment.