Some questions about how to write the correct codes in order to calculate the power generation dispatch by the transmission lines

41 views
Skip to first unread message

Chen Wang

unread,
Jan 2, 2024, 8:42:48 AM1/2/24
to Switch Model
Dear Matthias Fripp and other SWITCH contributors,
          Long time no see, everyone. Happy New Year to all of you! My name is WangChen and I am a postgraduate from China. I have learned SWITCH model for a long time and I really want to use it for my research. Now, I have met some difficulties about the extension work that is to calculate the power generation dispatch from all the transmission lines in each period. I have tried to write the corresponding codes in switch_model.transmission.transport.dispatch module to calculate the power generation dispatch from all the transmission lines in each period( Please see the Figure 1). However, when I run the SWITCH, there was always the same error  "Index '('Anhui', 'Anhui', '2025.01.22.00')' is not valid for indexed component 'DispatchTx'"( Please see the Figure 2). I have known what the error means which is that the "zone_from" is the same as "zone_to". But I couldn't find the solutions to this error. So could give me some advice on this error? I really want to search for the solution! Thank you so so much! Good luck! Best wishes!
Yours sincerely,
WangChen

微信图片_20240102214108.png
Figure 1
微信图片_20240102214146.png
Figure 2

Matthias Fripp

unread,
Jan 3, 2024, 7:41:03 PM1/3/24
to switch...@googlegroups.com

Hi Wang Chen,

 

It looks like you are trying to calculate the total MWh of power moved across all transmission lines during each period. I think the main problem you are running into is that you are not correctly identifying the available transmission lines. The indexed set m.TX_CONNECTIONS_TO_ZONE[z] tells you all the other zones that can send power to zone z. If you access m.TX_CONNECTIONS_TO_ZONE without the index, you get a list of all the zones that have any connections to them, and if you cross it with itself. So your calculation tries to calculate power flow from every zone to all other zones, even if they are not connected.

 

I think for your purpose, something like this may work better:

 

mod.TotalTransmissionUsage = Expression(

    mod.PERIODS,

    rule = lambda m, p: sum(

        m.DispatchTx[zone_from, zone_to, tp] * m.tp_weight[tp]

        for (zone_from, zone_to) in m.DIRECTIONAL_TX

        for tp in m.TPS_IN_PERIOD[p]

    )

)

 

This calculates the total amount of power sent into all connections throughout the system. If you want to calculate the total coming out of all connections (net of losses), you should multiply by m.trans_efficiency[m.trans_d_line[zone_from, zone_to]] before m.tp_weight. Or you could split the difference by multiplying by (1 + m.trans_efficiency[m.trans_d_line[zone_from, zone_to]])/2.

 

There’s another issue that is trickier to deal with. If there is surplus power (e.g., during times of renewable curtailment), Switch may sometimes send power on loops throughout the system unnecessarily. This doesn’t have any effect except increasing transmission losses, but it can make it look like more transmission is being used than is really the case. You could use a different calculation to try to work around that, like this:

 

mod.NetTransmissionUsage = Expression(

    mod.PERIODS,

    rule = lambda m, p: 0.5 * sum(

        abs(m.TXPowerNet[z, tp]) * m.tp_weight[tp]

        for z in m.LOAD_ZONES

        for tp in m.TPS_IN_PERIOD[p]

    )

)

 

This version calculates the net flow into or out of each zone and sums the absolute value of that across all zones. Then it multiplies by 0.5, since net outflow from one zone is inflow to another zone (minus losses), and we don’t want to count it twice. This also ends up averaging between the injections to a line and withdrawals from a line, which are the same minus losses. This version uses the abs() function, which is non-linear, so you can’t use it in a constraint or cost function, but it should work OK for reporting.

 

This version may not be completely satisfactory either, because if 1 MWh is sent from zone 1 to zone 2 and then on to zone 3, it will only be counted as 1 MWh of flow, not 2 MWh (1 MWh from zone 1 to zone 2 and 1 MWh from zone 2 to zone 3).

 

Another option would be to use the first method I showed (summing DispatchTx across all paths), but add a post-optimization cleanup stage (similar to switch_model.hawaii.smooth_dispatch) that minimizes loop flows before doing the final calculations.

 

You may also want to consider reporting MWh-km flows instead of MWh (you could get that by multiplying by m.trans_length_km [m.trans_d_line[zone_from, zone_to]]).

 

Let me know if you have more questions or need help with any of these.

 

Also, by the way, it’s easier if you paste the code from your editor directly into the email, rather than pasting an image. Those can be hard to read, search or convert back into runnable code.

 

Matthias

 

Figure 1

Figure 2

--
You received this message because you are subscribed to the Google Groups "Switch Model" group.
To unsubscribe from this group and stop receiving emails from it, send an email to switch-model...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/switch-model/5f0dd5b6-c663-488a-bdd0-2291c305c404n%40googlegroups.com.

Chen Wang

unread,
Jan 6, 2024, 7:51:01 AM1/6/24
to Switch Model
Hi Prof. Matthias Fripp,
     I replied to your letter just now, but it looks like it's not a reply to all the members but only to you, so I didn't see my reply on the google forum. May I ask if you received my reply? Please let me know if you didn't get it and I'll send it to you again.
Yours sincerely,
Wang Chen

Reply all
Reply to author
Forward
0 new messages