Note
You can download this example as a Jupyter notebook or start it in interactive mode.
Multi-Link usage: CHP with fixed heat-power ratio#
This notebook if a demonstration of Link with multiple outputs: Combined-Heat-and-Power (CHP) with fixed heat-power ratio
For a CHP with a more complicated heat-power feasible operational area, see the power-to-gas example
This example demonstrates a Link component with more than one bus output (“bus2” in this case). In general links can have many output buses.
In this example a CHP must be heat-following because there is no other supply of heat to the bus “Frankfurt heat”.
[1]:
import pypsa, numpy as np
ERROR 1: PROJ: proj_create_from_database: Open of /home/docs/checkouts/readthedocs.org/user_builds/pypsa/conda/latest/share/proj failed
[2]:
network = pypsa.Network()
network.add("Bus", "Frankfurt", carrier="AC")
network.add("Load", "Frankfurt", bus="Frankfurt", p_set=5)
network.add("Bus", "Frankfurt heat", carrier="heat")
network.add("Load", "Frankfurt heat", bus="Frankfurt heat", p_set=3)
network.add("Bus", "Frankfurt gas", carrier="gas")
network.add("Store", "Frankfurt gas", e_initial=1e6, e_nom=1e6, bus="Frankfurt gas")
network.add(
"Link",
"OCGT",
bus0="Frankfurt gas",
bus1="Frankfurt",
p_nom_extendable=True,
capital_cost=600,
efficiency=0.4,
)
network.add(
"Link",
"CHP",
bus0="Frankfurt gas",
bus1="Frankfurt",
bus2="Frankfurt heat",
p_nom_extendable=True,
capital_cost=1400,
efficiency=0.3,
efficiency2=0.3,
)
[3]:
network.optimize();
WARNING:pypsa.components:The following links have bus2 which are not defined:
Index(['OCGT'], dtype='object', name='Link')
WARNING:pypsa.components:The following links have bus2 which are not defined:
Index(['OCGT'], dtype='object', name='Link')
INFO:linopy.model: Solve problem using Glpk solver
INFO:linopy.io: Writing time: 0.04s
INFO:linopy.solvers:GLPSOL--GLPK LP/MIP Solver 5.0
Parameter(s) specified in the command line:
--lp /tmp/linopy-problem-98jn2e2d.lp --output /tmp/linopy-solve-b4as5buv.sol
Reading problem data from '/tmp/linopy-problem-98jn2e2d.lp'...
12 rows, 6 columns, 18 non-zeros
68 lines were read
GLPK Simplex Optimizer 5.0
12 rows, 6 columns, 18 non-zeros
Preprocessing...
~ 0: obj = 1.700000000e+04 infeas = 0.000e+00
OPTIMAL SOLUTION FOUND BY LP PREPROCESSOR
Time used: 0.0 secs
Memory used: 0.0 Mb (39693 bytes)
Writing basic solution to '/tmp/linopy-solve-b4as5buv.sol'...
INFO:linopy.constants: Optimization successful:
Status: ok
Termination condition: optimal
Solution: 6 primals, 12 duals
Objective: 1.70e+04
Solver model: not available
Solver message: optimal
/home/docs/checkouts/readthedocs.org/user_builds/pypsa/conda/latest/lib/python3.11/site-packages/pypsa/optimization/optimize.py:357: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.
The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.
For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.
n.df(c)[attr + "_opt"].update(df)
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Link-ext-p-lower, Link-ext-p-upper, Store-fix-e-lower, Store-fix-e-upper, Store-energy_balance were not assigned to the network.
[4]:
network.loads_t.p
[4]:
Load | Frankfurt | Frankfurt heat |
---|---|---|
snapshot | ||
now | 5.0 | 3.0 |
[5]:
network.links_t.p0
[5]:
Link | OCGT | CHP |
---|---|---|
snapshot | ||
now | 5.0 | 10.0 |
[6]:
network.links_t.p1
[6]:
Link | OCGT | CHP |
---|---|---|
snapshot | ||
now | -2.0 | -3.0 |
[7]:
network.links_t.p2
[7]:
Link | OCGT | CHP |
---|---|---|
snapshot | ||
now | 0.0 | -3.0 |