1 | from oemof import solph |
||
2 | |||
3 | |||
4 | View Code Duplication | def results_opex(): |
|
0 ignored issues
–
show
Duplication
introduced
by
![]() |
|||
5 | |||
6 | date_time_index = solph.create_time_index(2025, number=4) |
||
7 | |||
8 | # create the energysystem and assign the time index |
||
9 | energysystem = solph.EnergySystem( |
||
10 | timeindex=date_time_index, infer_last_interval=True |
||
11 | ) |
||
12 | |||
13 | el_bus = solph.buses.Bus("el_bus") |
||
14 | heat_bus = solph.buses.Bus("heat_bus") |
||
15 | |||
16 | energysystem.add(el_bus, heat_bus) |
||
17 | |||
18 | source = solph.components.Source( |
||
19 | "source", |
||
20 | outputs={ |
||
21 | el_bus: solph.flows.Flow(variable_costs=[10, 15, 20, 30, 15]) |
||
22 | }, |
||
23 | ) |
||
24 | |||
25 | demand = solph.components.Sink( |
||
26 | "heat_demand", |
||
27 | inputs={ |
||
28 | heat_bus: solph.flows.Flow(fix=[15, 42, 3, 9, 12], nominal_value=1) |
||
29 | }, |
||
30 | ) |
||
31 | |||
32 | hp = solph.components.Converter( |
||
33 | "heat_pump", |
||
34 | inputs={el_bus: solph.flows.Flow()}, |
||
35 | outputs={heat_bus: solph.flows.Flow()}, |
||
36 | conversion_factors={el_bus: 1 / 3}, |
||
37 | ) |
||
38 | |||
39 | energysystem.add(source, demand, hp) |
||
40 | |||
41 | energysystem_model = solph.Model(energysystem) |
||
42 | |||
43 | energysystem_model.solve(solver="cbc", solve_kwargs={"tee": True}) |
||
44 | |||
45 | results = solph.Results(energysystem_model) |
||
46 | |||
47 | assert results.to_df("variable_costs").iloc[:, 2].values == [ |
||
48 | 50, |
||
49 | 210, |
||
50 | 20, |
||
51 | 90, |
||
52 | 60, |
||
53 | ] |
||
54 | |||
55 | |||
56 | View Code Duplication | def results_capex(): |
|
0 ignored issues
–
show
|
|||
57 | |||
58 | date_time_index = solph.create_time_index(2025, number=4) |
||
59 | |||
60 | # create the energysystem and assign the time index |
||
61 | energysystem = solph.EnergySystem( |
||
62 | timeindex=date_time_index, infer_last_interval=True |
||
63 | ) |
||
64 | |||
65 | el_bus = solph.buses.Bus("el_bus") |
||
66 | heat_bus = solph.buses.Bus("heat_bus") |
||
67 | |||
68 | energysystem.add(el_bus, heat_bus) |
||
69 | |||
70 | source = solph.components.Source( |
||
71 | "source", |
||
72 | outputs={el_bus: solph.flows.Flow()}, |
||
73 | ) |
||
74 | |||
75 | demand = solph.components.Sink( |
||
76 | "heat_demand", |
||
77 | inputs={ |
||
78 | heat_bus: solph.flows.Flow(fix=[15, 42, 3, 9, 12], nominal_value=1) |
||
79 | }, |
||
80 | ) |
||
81 | |||
82 | hp = solph.components.Converter( |
||
83 | "heat_pump", |
||
84 | inputs={el_bus: solph.flows.Flow()}, |
||
85 | outputs={ |
||
86 | heat_bus: solph.flows.Flow( |
||
87 | solph.Investment(ep_costs=100, fixed_costs=200) |
||
88 | ) |
||
89 | }, |
||
90 | conversion_factors={el_bus: 1 / 3}, |
||
91 | ) |
||
92 | |||
93 | energysystem.add(source, demand, hp) |
||
94 | |||
95 | energysystem_model = solph.Model(energysystem) |
||
96 | |||
97 | energysystem_model.solve(solver="cbc", solve_kwargs={"tee": True}) |
||
98 | |||
99 | results = solph.Results(energysystem_model) |
||
100 | |||
101 | assert results.to_df("investment_costs").iloc[0, 0] == 42 * 100 + 200 |
||
102 | |||
103 | |||
104 | def results_storage(): |
||
105 | date_time_index = solph.create_time_index(2025, number=4) |
||
106 | |||
107 | # create the energysystem and assign the time index |
||
108 | energysystem = solph.EnergySystem( |
||
109 | timeindex=date_time_index, infer_last_interval=True |
||
110 | ) |
||
111 | |||
112 | bus = solph.buses.Bus("bus") |
||
113 | energysystem.add(bus) |
||
114 | |||
115 | source = solph.components.Source( |
||
116 | "source", |
||
117 | outputs={ |
||
118 | bus: solph.flows.Flow(fix=[20, 20, 10, 0, 0], nominal_value=1) |
||
119 | }, |
||
120 | ) |
||
121 | |||
122 | demand = solph.components.Sink( |
||
123 | "demand", |
||
124 | inputs={bus: solph.flows.Flow(fix=10, nominal_value=1)}, |
||
125 | ) |
||
126 | |||
127 | storage = solph.components.GenericStorage( |
||
128 | "storage", |
||
129 | inputs={bus: solph.flows.Flow(solph.Investment(ep_costs=10))}, |
||
130 | outputs={bus: solph.flows.Flow()}, |
||
131 | nominal_capacity=solph.Investment(ep_costs=100), |
||
132 | ) |
||
133 | energysystem.add(source, demand, storage) |
||
134 | |||
135 | energysystem_model = solph.Model(energysystem) |
||
136 | |||
137 | energysystem_model.solve(solver="cbc", solve_kwargs={"tee": True}) |
||
138 | |||
139 | results = solph.Results(energysystem_model) |
||
140 | |||
141 | assert results.to_df("investment_costs").iloc[0, 0] == 100 |
||
142 | assert results.to_df("investment_costs").iloc[0, 1] == 2000 |
||
143 |