Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P_from_to and P_to_from are erroneously zero in DC power flow #41

Closed
GabrielKS opened this issue Jul 15, 2024 · 5 comments
Closed

P_from_to and P_to_from are erroneously zero in DC power flow #41

GabrielKS opened this issue Jul 15, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@GabrielKS
Copy link
Contributor

In a power flow output, P_from_to is the active power flowing through the line at its from bus and P_to_from is the active power flowing through the line at its to bus. These are not necessarily the same magnitude due to line losses, but they should at least be comparable in magnitude. In the results of an AC power flow, this holds:
AC power flow screenshot (correct behavior)
but in the results of a DC power flow, one of the P values for each row seems to be zero:
DC power flow screenshot (incorrect behavior)

@rodrigomha
Copy link
Collaborator

rodrigomha commented Aug 6, 2024

I'm confused about this implementation. Here is the code that writes this in the DataFrame:

for i in 1:length(branches)

# get flows on each line
    P_from_to_vect = zeros(length(branches))
    Q_from_to_vect = zeros(length(branches))
    P_to_from_vect = zeros(length(branches))
    Q_to_from_vect = zeros(length(branches))
    for i in 1:length(branches)
        if branch_flow_values[i] >= 0
            P_from_to_vect[i] = branch_flow_values[i]
            P_to_from_vect[i] = 0
        else
            P_from_to_vect[i] = 0
            P_to_from_vect[i] = branch_flow_values[i]
        end
    end

Based on this implementation, if the solution is positive for the branch, it assigns the proper value to the from_to (probably correct). However if the solution is negative, it's assigned the same value to the to_from (probably incorrect). I'm guessing that in the solution of the DC PowerFlow, the solution is always for from_to, so in this case what it needs to happen is the following:

# get flows on each line
    P_from_to_vect = zeros(length(branches))
    Q_from_to_vect = zeros(length(branches))
    P_to_from_vect = zeros(length(branches))
    Q_to_from_vect = zeros(length(branches))
    for i in 1:length(branches)
        if branch_flow_values[i] >= 0
            P_from_to_vect[i] = branch_flow_values[i]
            P_to_from_vect[i] = 0
        else
            P_from_to_vect[i] = 0
            P_to_from_vect[i] = -branch_flow_values[i]
        end
    end

so the flows are always positive with the correct direction.

@jd-lara jd-lara added the bug Something isn't working label Aug 6, 2024
@rodrigomha
Copy link
Collaborator

I'm confused about this implementation. Here is the code that writes this in the DataFrame:

for i in 1:length(branches)

# get flows on each line
    P_from_to_vect = zeros(length(branches))
    Q_from_to_vect = zeros(length(branches))
    P_to_from_vect = zeros(length(branches))
    Q_to_from_vect = zeros(length(branches))
    for i in 1:length(branches)
        if branch_flow_values[i] >= 0
            P_from_to_vect[i] = branch_flow_values[i]
            P_to_from_vect[i] = 0
        else
            P_from_to_vect[i] = 0
            P_to_from_vect[i] = branch_flow_values[i]
        end
    end

Based on this implementation, if the solution is positive for the branch, it assigns the proper value to the from_to (probably correct). However if the solution is negative, it's assigned the same value to the to_from (probably incorrect). I'm guessing that in the solution of the DC PowerFlow, the solution is always for from_to, so in this case what it needs to happen is the following:

# get flows on each line
    P_from_to_vect = zeros(length(branches))
    Q_from_to_vect = zeros(length(branches))
    P_to_from_vect = zeros(length(branches))
    Q_to_from_vect = zeros(length(branches))
    for i in 1:length(branches)
        if branch_flow_values[i] >= 0
            P_from_to_vect[i] = branch_flow_values[i]
            P_to_from_vect[i] = 0
        else
            P_from_to_vect[i] = 0
            P_to_from_vect[i] = -branch_flow_values[i]
        end
    end

so the flows are always positive with the correct direction.

If we want to add both directions, doing this:

for i in 1:length(branches)
            P_from_to_vect[i] = branch_flow_values[i]
            P_to_from_vect[i] = -branch_flow_values[i]
end

will suffice

@jd-lara
Copy link
Member

jd-lara commented Aug 6, 2024

Yeah, it seems this the post processing code isn't implemented correctly.

@jd-lara
Copy link
Member

jd-lara commented Aug 6, 2024

Let's resolve it to have the P_from_to = -P_to_from and report it like that.

@rodrigomha
Copy link
Collaborator

Closed via #45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants