Skip to content

Commit

Permalink
Add properties to get the line series and shunt currents
Browse files Browse the repository at this point in the history
Fixes #99

The `Line` class gained two new properties:
1. `res_series_currents`: An array of currents in the series components of the line
2. `res_shunt_currents`: A 2-tuple of arrays of currents in the shunt components from
   each side of the line

The `ElectricalNetwork` now has a `res_lines` property that replaces `res_lines_losses`.
The new property contains all columns from `res_branches` in addition to the columns
`series_losses` and `series_current`. The columns `shunt_losses` and `total_losses` have
been removed but can be easily computed.
```py
df = en.res_lines
total_losses = df["power1"] + df["power2"]
shunt_losses = total_losses - df["series_losses"]
```

In addition, the shunt currents can be computed with:
```py
shunt_currents1 = df["current1"] - df["series_current"]
shunt_currents2 = df["series_current"] + df["current2"]
```

The detailed shunt losses/currents always remain accessible on the line element itself.
  • Loading branch information
alihamdan committed Jul 27, 2023
1 parent 3dde16b commit a5af0d9
Show file tree
Hide file tree
Showing 10 changed files with 1,021 additions and 85 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
// Jupyter
// Jupyter Notebook
"jupyter.notebookFileRoot": "${workspaceFolder}",
"notebook.formatOnSave.enabled": true,
"notebook.codeActionsOnSave": {
"source.organizeImports.ruff": true,
},

// Python
"python.analysis.diagnosticSeverityOverrides": {
Expand Down
4 changes: 4 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

**In development**

* [GH99](https://github.com/RoseauTechnologies/Roseau_Load_Flow/issues/99) Add `Line.res_series_currents`
and `Line.res_shunt_currents` properties to get the currents in the series and shunt components
of lines. Also added `ElectricalNetwork.res_lines` that contains the series losses and currents
of all the lines in the network. The property `ElectricalNetwork.res_lines_losses` was removed.
* [GH100](https://github.com/RoseauTechnologies/Roseau_Load_Flow/issues/100) Fix the `Yz` transformers
* [PR97](https://github.com/RoseauTechnologies/Roseau_Load_Flow/pull/97) Add the model section to the documentation
* [PR96](https://github.com/RoseauTechnologies/Roseau_Load_Flow/pull/96)
Expand Down
37 changes: 29 additions & 8 deletions doc/models/Line/ShuntLine.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,33 @@ en.res_branches[["current2"]].transform([np.abs, ft.partial(np.angle, deg=True)]
# | ('line', 'c') | 5.68434e-14 | 0 |
# | ('line', 'n') | 20.6273 | -12.625 |

# The losses of the line can also be accessed. One can remark that there are shunt losses
en.res_lines_losses
# | | 'series_losses' | 'shunt_losses' | 'total_losses' |
# |:--------------|-------------------------:|---------------------:|------------------:|
# | ('line', 'a') | 171.841+57.2802j | -1.59017-26.6385j | 170.251+ 30.6417j |
# | ('line', 'b') | 38.1291+12.7097j | 1.01834-28.5657j | 39.1474 -15.856j |
# | ('line', 'c') | 0.00107497+0.000358324j | 3.69511-27.4104j | 3.69618-27.41j |
# | ('line', 'n') | 127.574 +42.5246j | 0.0351686+0.0139828j | 127.609+42.5385j |
# The currents in the series components of the line
en.res_lines[["series_current"]].transform([np.abs, ft.partial(np.angle, deg=True)])
# | | ('series_current', 'absolute') | ('series_current', 'angle') |
# |:--------------|---------------------------------:|------------------------------:|
# | ('line', 'a') | 23.9333 | 15.5496 |
# | ('line', 'b') | 11.2737 | -104.796 |
# | ('line', 'c') | 0.0598601 | -157.579 |
# | ('line', 'n') | 20.6215 | 167.376 |

# The losses of the series components of line can also be accessed
en.res_lines[["series_losses"]].transform([np.real, np.imag])
# | | ('series_losses', 'real') | ('series_losses', 'imag') |
# |:--------------|----------------------------:|----------------------------:|
# | ('line', 'a') | 171.841 | 57.2802 |
# | ('line', 'b') | 38.1291 | 12.7097 |
# | ('line', 'c') | 0.00107497 | 0.000358324 |
# | ('line', 'n') | 127.574 | 42.5246 |

# The shunt losses can be computed. Notice that the shunt losses are not null for the shunt line.
res_lines = en.res_lines
total_losses = res_lines["power1"] + res_lines["power2"] # total = series + shunt
shunt_losses = total_losses - res_lines["series_losses"]
shunt_losses.to_frame("shunt_losses").transform([np.real, np.imag])
# | | ('shunt_losses', 'real') | ('shunt_losses', 'imag') |
# |:--------------|---------------------------:|---------------------------:|
# | ('line', 'a') | -1.59017 | -26.6385 |
# | ('line', 'b') | 1.01834 | -28.5657 |
# | ('line', 'c') | 3.69511 | -27.4104 |
# | ('line', 'n') | 0.0351686 | 0.0139828 |
```
32 changes: 24 additions & 8 deletions doc/models/Line/SimplifiedLine.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,30 @@ en.res_branches[["current2"]].transform([np.abs, ft.partial(np.angle, deg=True)]
# | ('line', 'c') | 0 | 0 |
# | ('line', 'n') | 20.628 | -11.5242 |

# The two currents are equal in magnitude and opposite in phase, as expected
# The currents in the series components of the line
en.res_lines[["series_current"]].transform([np.abs, ft.partial(np.angle, deg=True)])
# | | ('series_current', 'absolute') | ('series_current', 'angle') |
# |:--------------|---------------------------------:|------------------------------:|
# | ('line', 'a') | 24.1958 | 16.4456 |
# | ('line', 'b') | 11.3722 | -105.263 |
# | ('line', 'c') | 0 | 0 |
# | ('line', 'n') | 20.628 | 168.476 |

# All currents are equal in magnitude for a simplified lines as no current escapes to the ground.
# The current from bus 2 has an opposite direction to the current from bus 1 as expected.

# The losses of the line can also be accessed. One can remark that there are no shunt losses
en.res_lines_losses
# | | 'series_losses' | 'shunt_losses' | 'total_losses' |
# |:--------------|-----------------------:|---------------:|----------------------:|
# | ('line', 'a') | 204.904 -2.66329e-15 | 0j | 204.904 -2.66329e-15 |
# | ('line', 'b') | 45.2646 -8.96306e-16 | 0j | 45.2646 -8.96306e-16 |
# | ('line', 'c') | 0j | 0j | 0j |
# | ('line', 'n') | 148.93 + 6.11606e-15 | 0j | 148.93 + 6.11606e-15 |
en.res_lines[["series_losses"]].transform([np.real, np.imag])
# | | ('series_losses', 'real') | ('series_losses', 'imag') |
# |:--------------|----------------------------:|----------------------------:|
# | ('line', 'a') | 204.904 | -2.66329e-15 |
# | ('line', 'b') | 45.2646 | -8.96306e-16 |
# | ('line', 'c') | 0 | 0 |
# | ('line', 'n') | 148.93 | 7.62657e-16 |

# With a simplified model, all the losses are caused by the series impedance of the line
res_lines = en.res_lines
total_losses = res_lines["power1"] + res_lines["power2"] # total = series + shunt
np.allclose(total_losses, res_lines["series_losses"])
# True
```
Loading

0 comments on commit a5af0d9

Please sign in to comment.