Defining piecewise linear constraints¶
In this tutorial, we use the national scale example model to implement a piecewise linear constraint. This constraint will represent a non-linear relationship between capacity and cost per unit capacity of Concentrating Solar Power (CSP).
In [1]:
Copied!
import numpy as np
import plotly.express as px
import calliope
from calliope.io import read_rich_yaml
calliope.set_log_verbosity("INFO", include_solver_output=False)
import numpy as np
import plotly.express as px
import calliope
from calliope.io import read_rich_yaml
calliope.set_log_verbosity("INFO", include_solver_output=False)
Model setup¶
Defining our piecewise curve¶
In the base national scale model, the CSP has a maximum rated capacity of 10,000 kW and a cost to invest in that capacity of 1000 USD / kW.
In our updated model, the cost to invest in capacity will vary from 5000 USD / kW to 500 USD / kW as the CSP capacity increases:
In [2]:
Copied!
capacity_steps = [0, 2500, 5000, 7500, 10000]
cost_steps = [0, 3.75e6, 6e6, 7.5e6, 8e6]
cost_per_cap = np.nan_to_num(np.divide(cost_steps, capacity_steps)).astype(int)
fig = px.line(
x=capacity_steps,
y=cost_steps,
labels={"x": "Capacity (kW)", "y": "Investment cost (USD)"},
markers="o",
range_y=[0, 10e6],
text=[f"{i} USD/kW" for i in cost_per_cap],
)
fig.update_traces(textposition="top center")
fig.show()
capacity_steps = [0, 2500, 5000, 7500, 10000]
cost_steps = [0, 3.75e6, 6e6, 7.5e6, 8e6]
cost_per_cap = np.nan_to_num(np.divide(cost_steps, capacity_steps)).astype(int)
fig = px.line(
x=capacity_steps,
y=cost_steps,
labels={"x": "Capacity (kW)", "y": "Investment cost (USD)"},
markers="o",
range_y=[0, 10e6],
text=[f"{i} USD/kW" for i in cost_per_cap],
)
fig.update_traces(textposition="top center")
fig.show()
[2025-03-14 18:56:48] WARNING /tmp/ipykernel_3151/173276940.py:4: RuntimeWarning: invalid value encountered in divide cost_per_cap = np.nan_to_num(np.divide(cost_steps, capacity_steps)).astype(int)