Skip to content

Commit

Permalink
Fixes in response to review
Browse files Browse the repository at this point in the history
  • Loading branch information
brynpickering committed Oct 30, 2023
1 parent b9a5652 commit e9fc66c
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 3 deletions.
4 changes: 4 additions & 0 deletions doc/_static/custom_math/annual_energy_balance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
# annual_flow_max (if summing over technologies and/or nodes)
# flow_max_group (if summing over technologies and/or nodes)

# helper functions used
# inheritance (where)
# sum (expression)

constraints:
annual_energy_balance_per_tech_and_node:
description: Limit total technology annual energy production at each possible deployment site.
Expand Down
3 changes: 3 additions & 0 deletions doc/_static/custom_math/chp_htp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
# power_to_heat_ratio
# boiler_eff

# helper functions used
# reduce_carrier_dim (expression)

constraints:
# Extraction turbine constraints
# ~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# demand_share_limit.
# decide_demand_share <- Link supply technologies to the demand technology they are going to be a share of.

# helper functions used
# sum (expression)
# select_from_lookup_arrays (expression)

variables:
demand_share_per_timestep_decision:
description: Relative share of demand that a given technology must meet per node.
Expand Down
4 changes: 4 additions & 0 deletions doc/_static/custom_math/fuel_dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
# fuel_distributor_costs
# allow_fuel_distribution <- lookup array with a value of `True` for each carrier where you want to track its distribution

# helper functions used
# any (where)
# sum (expression)

variables:
fuel_distributor:
description: >
Expand Down
3 changes: 3 additions & 0 deletions doc/_static/custom_math/max_time_varying.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# flow_cap_max_relative_per_ts
# storage_max_relative_per_ts

# helper functions used
# reduce_carrier_dim (expression)

constraints:
max_time_varying_flow_cap:
description: Limit flow out in each hour according to a time varying fractional limit that is multiplied by the technology flow cap. This represents, for instance, the impact of outdoor temperature on the maximum output of a technology relative to its rated max output.
Expand Down
10 changes: 9 additions & 1 deletion doc/_static/custom_math/net_import_share.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
# Imports of transmission technologies are defined by `flow_out` (outflow from a transmission technology that originated in a remote node).
# We assume that transmission technologies `test_transmission_elec` and `test_transmission_heat` have been defined.

# New top-level parameters:
# net_import_share

# helper functions used
# defined (where)
# sum (expression)
# get_transmission_techs (expression)

constraints:
net_import_share_max:
description: Limit upper bound on electricity imports within nodes as a share of all electricity flows at each node.
Expand Down Expand Up @@ -39,7 +47,7 @@ constraints:
slices:
transmission_techs:
- expression: get_transmission_techs(test_transmission_heat)
node_group: # The subset of nodes for which to limit heat imports
node_group: # The subset of nodes in which to limit heat imports
- expression: "[a, c]"
carrier: # The carrier for which to limit imports
- expression: heat
3 changes: 3 additions & 0 deletions doc/_static/custom_math/piecewise_linear_efficiency.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# flow_eff_piecewise_slopes (defining the new parameter `pieces`)
# flow_eff_piecewise_intercept (defining the new parameter `pieces`)

# helper functions used
# reduce_carrier_dim (expression)

variables:
available_flow_cap:
description: Flow capacity that will be set to zero if the technology is not operating in a given timestep and will be set to the value of the decision variable `flow_cap` otherwise.
Expand Down
4 changes: 4 additions & 0 deletions doc/_static/custom_math/share_all_timesteps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# demand_share_equals
# supply_share_equals

# helper functions used
# sum (expression)
# reduce_carrier_dim (expression)

constraints:
demand_share_equals_per_tech:
description: Set the total outflow of certain technologies which produce the `power` carrier to a share of total demand inflow.
Expand Down
4 changes: 4 additions & 0 deletions doc/_static/custom_math/share_per_timestep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# demand_share_per_timestep_equals
# supply_share_per_timestep_equals

# helper functions used
# sum (expression)
# reduce_carrier_dim (expression)

constraints:
demand_share_per_timestep_equals_per_tech:
description: Set the per-timestep outflow of certain technologies which produce the `power` carrier to a share of demand inflow.
Expand Down
4 changes: 4 additions & 0 deletions doc/_static/custom_math/uptime_downtime_limits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# downtime_periods (from CSV as a timeseries)
# uptime_limit

# helper functions used
# sum (expression)
# reduce_carrier_dim (expression)

constraints:
annual_capacity_factor_min:
description: Limit the lower bound of annual technology operation as a fraction of annual operation at maximum capacity.
Expand Down
30 changes: 28 additions & 2 deletions src/calliope/backend/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,37 @@ def _instr(dim: str) -> str:
def _listify(
self, vals: Union[list[str], str], expand_link_techs: bool = False
) -> list[str]:
"""Force a string to a list of length one if not already provided as a list.
Args:
vals (Union[list[str], str]): Values (or single value) to force to a list.
expand_link_techs (bool, optional):
If True, search resulting list for any transmission tech names and expand them to their link names.
Defaults to False.
Returns:
list[str]: Input forced to a list.
"""
if not isinstance(vals, list):
vals = [vals]
if expand_link_techs:
vals = self._expand_link_techs(vals)
return vals

def _expand_link_techs(self, vals: list[str]) -> list[str]:
"""Expand list of technology names to link tech names.
This searches the names provided and tries to match them up with auto-generated link names, which are the transmission tech name + remote node name
(e.g., `ac_transmission` -> [`ac_transmission:A`, `ac_transmission:B`]).
It will match any provided name with any name in the techs that starts with that name followed by a colon (`:`).
Args:
vals (list[str]): List of techs which could include general transmission tech names.
Returns:
list[str]: Expanded list, including all non-transmission tech names and transmission tech names replaced with link names.
"""
to_remove = []
to_add = []
for val in vals:
Expand Down Expand Up @@ -296,6 +320,8 @@ def as_array(
dim_names = list(dims.keys())
dims_with_list_vals = {
dim: self._listify(vals, expand_link_techs=True)
if dim == "techs"
else self._listify(vals, expand_link_techs=False)
for dim, vals in dims.items()
}
definition_matrix = self._kwargs["model_data"].definition_matrix
Expand Down Expand Up @@ -342,8 +368,8 @@ def _latex_substring(
elif how == "any":
# Using vee for "collective-or"
tex_how = "vee"

vals = self._listify(vals, expand_link_techs=True)
expand_link_techs = True if dim == "techs" else False
vals = self._listify(vals, expand_link_techs=expand_link_techs)
within_singular = within.removesuffix("s")
dim_singular = dim.removesuffix("s")
selection = rf"\text{{{dim_singular}}} \in \text{{[{','.join(vals)}]}}"
Expand Down

0 comments on commit e9fc66c

Please sign in to comment.