Skip to content
Draft
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
217 changes: 217 additions & 0 deletions examples/script_topup_heat/top_heat_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
from pathlib import Path

import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from oemof.network import graph
from oemof.solph import Flow
from oemof.solph.components import Sink
from oemof.solph.components import Source
from oemof.tools.logger import define_logging

from oemof.eesyplan import CarrierBus
from oemof.eesyplan import Demand
from oemof.eesyplan import EnergySystem
from oemof.eesyplan import HeatPump
from oemof.eesyplan import Project
from oemof.eesyplan import ThermalStorage
from oemof.eesyplan import optimise
from oemof.eesyplan.components.converters.AuxiliaryHeat import (
AuxiliaryHeatSplit,
)
from oemof.eesyplan.components.production.commodity import Commodity
from oemof.eesyplan.components.transport.heat import HeatingNetwork
from oemof.eesyplan.components.transport.heat import HeatingPipe
from oemof.eesyplan.importer.cop import calculate_cop_simple
from oemof.eesyplan.postprocessing.balance import nodes_io
from oemof.eesyplan.postprocessing.graphs import sankey


def simple_script():
# Read data file
heat = pd.Series([9, 9, 3, 3, 7, 7, 2, 2, 5, 5, 4, 4, 8, 8, 2, 2])

project = Project(name="test", lifetime=20, tax=0, discount_factor=0)

# ####################### initialize the energy system ####################
energy_system = EnergySystem(2023, number=len(heat))

# ######################### create energysystem components ################

bus_electricity = CarrierBus(
name="electricity bus", carrier="electricity", balanced=True
)
energy_system.add(bus_electricity)

energy_system.add(
Commodity(
name="electricity",
variable_cost=2,
bus_out=bus_electricity,
)
)

ht_east = HeatingNetwork(
name="HeatingNetwork - East",
)

ht_west = HeatingNetwork(name="HeatingNetwork - West")
energy_system.add(ht_east, ht_west)
# bus_storage_heat = Bus(label="bus_storage_heat")

# energy_system.add(bus_heat)

# sources
energy_system.add(
Source(label="Source", outputs={ht_west: Flow(variable_costs=1000)})
)

energy_system.add(
Source(
label="Hochtemperatur Abwärme",
outputs={
ht_west: Flow(
nominal_capacity=2,
fix=heat,
variable_costs=1,
)
},
)
)

energy_system.add(
Sink(label="Sink", inputs={ht_west: Flow(variable_costs=1)})
)

energy_system.add(
HeatingPipe(
name="HeatPipe",
bus_1_heat=ht_west,
bus_2_heat=ht_east,
# absolute_losses=0,
relative_losses=0.0,
)
)

my_storage = ThermalStorage(
name="HeatStorage",
bus_in_heat=ht_east,
age_installed=0,
installed_capacity=1000,
capex_var=3.0,
opex_fix=0.0,
opex_var=0.0,
lifetime=30.0,
optimize_cap=False,
soc_max=1,
soc_min=0,
theoretical_time_charge=1.0,
theoretical_time_discharge=1.0,
efficiency_charge=1,
efficiency_discharge=1,
project_data=project,
thermal_losses_relative=0.000,
thermal_losses_absolute=0,
thermal_losses_absolute_investment=0,
)
energy_system.add(my_storage)

t_in = [10] * len(heat)
t_out = [90] * len(heat)
t_supply = [100] * len(heat)

topheatbus = CarrierBus(name="TopHeatBus", carrier="heat_supply")
energy_system.add(topheatbus)

# top_pipe = HeatingPipe(
# name="HeatPipeWP",
# bus_1_heat=topheatbus,
# bus_2_heat=ht_east,
# relative_losses=0.0,
# return_pipe=False
# )
# energy_system.add(top_pipe)

heat_pump = HeatPump(
name="HeatPump",
project_data=project,
installed_capacity=5,
bus_out_heat=topheatbus,
bus_in_electricity=bus_electricity,
cop=calculate_cop_simple(
temperature_source=20,
temperature_supply=t_supply,
quality_factor=0.55,
),
)

energy_system.add(heat_pump)
print(heat_pump.cop)

energy_system.add(
AuxiliaryHeatSplit(
name="HeatSplit",
node_in_heat=my_storage,
node_in_heat_auxiliary=topheatbus,
node_out_heat=ht_east,
project_data=project,
temp_in_low=t_in,
temp_out_low=t_out,
temp_supply=t_supply,
)
)

# demands (electricity/heat)
energy_system.add(
Demand(
name="demand_heat",
bus_in=ht_west,
input_timeseries=np.roll(heat, 2) * 2,
)
)

graph.create_nx_graph(energy_system, filename="testgraph.graphml")
return optimise(energy_system), energy_system


def hide_and_rename(df, depth=0):
filtered = df.loc[
:,
[
column
for column in df.columns
if any(
level.depth == depth
for level in (
column if isinstance(column, tuple) else (column,)
)
)
],
]

for n in range(df.columns.nlevels):
filtered.rename(
columns={
obj: obj.parent
for c in filtered.columns
for obj in [(c if isinstance(c, tuple) else (c,))[n]]
if obj.parent is not None
},
level=n,
inplace=True,
)
return filtered


if __name__ == "__main__":
define_logging()
res, es = simple_script()
flows = hide_and_rename(res["flow"])
print(nodes_io(flows).sum().sort_index())
print(res["storage_losses"].sum())
print(res["storage_content"].plot())
print(flows.sum())
print(flows)
flows.loc[:, (flows.sum() > 0.1)].plot()
fig = sankey(flows, es=es)
plt.show()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ examples = []
importer = ["pyproj"]
test = [
"pytest",
"tespy",
"coverage",
"pvlib",
"demandlib",
Expand Down
83 changes: 83 additions & 0 deletions src/oemof/eesyplan/components/converters/AuxiliaryHeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import numpy as np
from oemof.solph import Flow
from oemof.solph.components import Converter

from oemof.eesyplan.investment import _create_invest_if_wanted


class AuxiliaryHeatSplit(Converter):
def __init__(
self,
name,
node_in_heat,
node_in_heat_auxiliary,
node_out_heat,
project_data,
temp_in_low,
temp_out_low,
temp_supply,
age_installed=0,
installed_capacity=0,
capex_var=1000,
opex_fix=10,
opex_var=0,
lifetime=20,
optimize_cap=True,
maximum_capacity=float("+inf"),
):
"""
self,
name,
bus_in_fuel,
bus_out_electricity,
project_data,
efficiency=0.3,
age_installed=0,
installed_capacity=0,
capex_var=1000,
capex_fix=0,
opex_fix=10,
opex_var=0,
lifetime=20,
optimize_cap=True,
maximum_capacity=float("+inf"),
"""
nv = _create_invest_if_wanted(
optimise_cap=optimize_cap,
capex_var=capex_var,
opex_fix=opex_fix,
lifetime=lifetime,
age_installed=age_installed,
existing_capacity=installed_capacity,
maximum_capacity=maximum_capacity,
project_data=project_data,
)
inputs = {
node_in_heat: Flow(),
node_in_heat_auxiliary: Flow(),
}
outputs = {
node_out_heat: Flow(
nominal_capacity=nv,
variable_costs=opex_var,
)
}

temp_supply = np.array(temp_supply)
temp_out_low = np.array(temp_out_low)
temp_in_low = np.array(temp_in_low)

energy_top = (temp_supply - temp_out_low) / (
temp_out_low - temp_in_low
)
energy_total = energy_top + 1

super().__init__(
label=name,
inputs=inputs,
outputs=outputs,
conversion_factors={
node_in_heat: 1 / energy_total,
node_in_heat_auxiliary: energy_top / energy_total,
},
)
27 changes: 12 additions & 15 deletions src/oemof/eesyplan/components/converters/HeatPump.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ class HeatPump(Converter):
def __init__(
self,
name,
bus_in_heat,
project_data,
installed_capacity,
bus_in_electricity,
bus_out_heat,
project_data,
bus_in_heat=None,
age_installed=0,
installed_capacity=0,
capex_fix=1000,
capex_var=1000,
opex_var=0.01,
opex_fix=10,
Expand Down Expand Up @@ -50,9 +49,6 @@ def __init__(
Number of years the asset has already been in operation.
installed_capacity : float, default=0
Already existing installed capacity.
capex_fix : float, default=1000
Specific investment costs of the asset related to the
installed capacity (CAPEX).
capex_var : float, default=1000
Specific investment costs of the asset related to the
installed capacity (CAPEX).
Expand All @@ -77,14 +73,13 @@ def __init__(
Examples
--------
>>> from oemof.eesyplan import Project
>>> from oemof.solph import Bus
>>> el_bus = Bus(label="electricity_bus")
>>> ambient_heat_bus = Bus(label="ambient_heat_bus")
>>> heat_bus = Bus(label="heat_bus")
>>> from oemof.eesyplan import CarrierBus
>>> el_bus = CarrierBus(name="electricity_bus")
>>> ambient_heat_bus = CarrierBus(name="ambient_heat_bus")
>>> heat_bus = CarrierBus(name="heat_bus")
>>> my_heat_pump = HeatPump(
... name="air_source_heat_pump",
... bus_in_electricity=el_bus,
... bus_in_heat=ambient_heat_bus,
... bus_out_heat=heat_bus,
... installed_capacity=15,
... cop=3.5,
Expand Down Expand Up @@ -122,7 +117,7 @@ def __init__(
project_data=project_data,
)

inputs = {bus_in_heat: Flow(), bus_in_electricity: Flow()}
inputs = {bus_in_electricity: Flow()}

outputs = {
bus_out_heat: Flow(
Expand All @@ -133,9 +128,12 @@ def __init__(

conversion_factors = {
bus_in_electricity: 1 / cop,
bus_in_heat: (cop - 1) / cop,
}

if bus_in_heat is not None:
conversion_factors[bus_in_heat] = (cop - 1) / cop
inputs[bus_in_heat] = Flow()

super().__init__(
label=name,
outputs=outputs,
Expand All @@ -146,7 +144,6 @@ def __init__(
self.name = name
self.age_installed = age_installed
self.installed_capacity = installed_capacity
self.capex_fix = capex_fix
self.capex_var = capex_var
self.opex_var = opex_var
self.opex_fix = opex_fix
Expand Down
Loading
Loading