diff --git a/scripts/add_extra_components.py b/scripts/add_extra_components.py index 02810f479..e8b789326 100644 --- a/scripts/add_extra_components.py +++ b/scripts/add_extra_components.py @@ -266,13 +266,10 @@ def attach_hydrogen_pipelines(n, costs, config): ) # setup pipelines as bidirectional and lossy - lossy_bidirectional_links(n,"H2 pipeline") + lossy_bidirectional_links(n, "H2 pipeline") -def lossy_bidirectional_links( - n: pypsa.components.Network, - carrier: str - ): +def lossy_bidirectional_links(n: pypsa.components.Network, carrier: str): "Split bidirectional links into two unidirectional links to include transmission losses." @@ -280,10 +277,8 @@ def lossy_bidirectional_links( if carrier_i.empty: return - - logger.info( - f"Splitting bidirectional links with the carrier {carrier}" - ) + + logger.info(f"Splitting bidirectional links with the carrier {carrier}") n.links.loc[carrier_i, "p_min_pu"] = 0 diff --git a/scripts/solve_network.py b/scripts/solve_network.py index e586a539d..5eef12ebf 100755 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -854,13 +854,10 @@ def add_existing(n): n.generators.loc[tech_index, tech] = existing_res -def add_lossy_bidirectional_link_constraints( - n: pypsa.components.Network - ) -> None: - - ''' +def add_lossy_bidirectional_link_constraints(n: pypsa.components.Network) -> None: + """ Ensures that the two links simulating a bidirectional_link are extended the same amount. - ''' + """ if not n.links.p_nom_extendable.any() or "reversed" not in n.links.columns: return @@ -887,10 +884,10 @@ def get_backward_i(forward_i): backward_i = get_backward_i(forward_i) lhs = linexpr( - (1, get_var(n,"Link", "p_nom")[backward_i].to_numpy()), - (-1, get_var(n,"Link", "p_nom")[forward_i].to_numpy()) + (1, get_var(n, "Link", "p_nom")[backward_i].to_numpy()), + (-1, get_var(n, "Link", "p_nom")[forward_i].to_numpy()), ) - + define_constraints(n, lhs, "=", 0, "Link-bidirectional_sync")