Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Simpler implementation of the CHP template and addon with build_priority #2

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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