@@ -106,16 +106,14 @@ def add_capacity_limits(
106106
107107def add_power_limits (n , investment_year , limits_power_max ):
108108 """
109- " Restricts the maximum inflow/ outflow of electricity from/to a country.
109+ Restricts the maximum inflow and outflow of electricity from/to a country separately .
110110 """
111111 for ct in limits_power_max :
112112 if investment_year not in limits_power_max [ct ].keys ():
113113 continue
114-
115114 limit = 1e3 * limits_power_max [ct ][investment_year ] / 10
116-
117115 logger .info (
118- f"Adding constraint on electricity import/ export from/to { ct } to be < { limit } MW"
116+ f"Adding constraints on electricity import and export from/to { ct } to be < { limit * 10 } MW each "
119117 )
120118 incoming_line = n .lines .index [
121119 (n .lines .carrier == "AC" )
@@ -127,7 +125,6 @@ def add_power_limits(n, investment_year, limits_power_max):
127125 & (n .lines .bus0 .str [:2 ] == ct )
128126 & (n .lines .bus1 .str [:2 ] != ct )
129127 ]
130-
131128 incoming_link = n .links .index [
132129 (n .links .carrier == "DC" )
133130 & (n .links .bus0 .str [:2 ] != ct )
@@ -139,29 +136,25 @@ def add_power_limits(n, investment_year, limits_power_max):
139136 & (n .links .bus1 .str [:2 ] != ct )
140137 ]
141138
142- # iterate over snapshots - otherwise exporting of postnetwork fails since
143- # the constraints are time dependent
139+ # iterate over snapshots
144140 for t in n .snapshots :
145141 incoming_line_p = n .model ["Line-s" ].loc [t , incoming_line ]
146142 outgoing_line_p = n .model ["Line-s" ].loc [t , outgoing_line ]
147143 incoming_link_p = n .model ["Link-p" ].loc [t , incoming_link ]
148144 outgoing_link_p = n .model ["Link-p" ].loc [t , outgoing_link ]
149145
150- lhs = (
151- incoming_link_p .sum ()
152- - outgoing_link_p .sum ()
153- + incoming_line_p .sum ()
154- - outgoing_line_p .sum ()
155- ) / 10
156- # divide by 10 to avoid numerical issues
146+ # Total inflow (imports) - only positive flows into the country
147+ inflow_lhs = (incoming_link_p .sum () + incoming_line_p .sum ()) / 10
157148
158- cname_upper = f"Power-import-limit- { ct } - { t } "
159- cname_lower = f"Power-export-limit- { ct } - { t } "
149+ # Total outflow (exports) - only positive flows out of the country
150+ outflow_lhs = ( outgoing_link_p . sum () + outgoing_line_p . sum ()) / 10
160151
161- n .model .add_constraints (lhs <= limit , name = cname_upper )
162- n .model .add_constraints (lhs >= - limit , name = cname_lower )
152+ # Separate constraints for inflow and outflow
153+ cname_inflow = f"Power-inflow-limit-{ ct } -{ t } "
154+ cname_outflow = f"Power-outflow-limit-{ ct } -{ t } "
163155
164- # not adding to network as the shadow prices are not needed
156+ n .model .add_constraints (inflow_lhs <= limit , name = cname_inflow )
157+ n .model .add_constraints (outflow_lhs <= limit , name = cname_outflow )
165158
166159
167160def h2_import_limits (n , investment_year , limits_volume_max ):
0 commit comments