Skip to content

Commit

Permalink
update print functions and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcosovic committed Jul 2, 2024
1 parent a79b86c commit c1adbb0
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 52 deletions.
4 changes: 2 additions & 2 deletions docs/src/api/setupPrint.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ using JuliaGrid

---

## Print Power System Data
## [Print Power System Data](@id PrintPowerSystemDataAPI)
```@docs
printBusData
printBranchData
Expand All @@ -74,7 +74,7 @@ printGeneratorData

---

## Print Power System Summary
## [Print Power System Summary](@id PrintPowerSystemSummaryAPI)
```@docs
printBusSummary
printBranchSummary
Expand Down
58 changes: 27 additions & 31 deletions docs/src/manual/acPowerFlow.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,29 +256,6 @@ In these examples, the algorithms run until the specified number of iterations i

---

##### Print Results
Users have the option to print the results in the REPL using any units that have been configured, such as:
```@example ACPowerFlowSolution
@voltage(pu, deg, V)
printBusData(system, analysis)
```

Next, users can easily customize the print results for specific buses, for example:
```julia
printBusData(system, analysis; label = "Bus 1", header = true)
printBusData(system, analysis; label = "Bus 2")
printBusData(system, analysis; label = "Bus 3", footer = true)
```

Users can also redirect print output to a file. For example, data can be saved in a text file as follows:
```julia
open("bus_data.txt", "w") do file
printBusData(system, analysis, file)
end
```

---

##### Breaking the Iterative Process
We can terminate the iterative process using the [`mismatch!`](@ref mismatch!(::PowerSystem, ::ACPowerFlow{NewtonRaphson})) function. The following code shows an example of how to use the function to break out of the iteration loop:
```@example ACPowerFlowSolution
Expand Down Expand Up @@ -336,6 +313,29 @@ end

---

##### Print Results
Users have the option to print the results in the REPL using any units that have been configured, such as:
```@example ACPowerFlowSolution
@voltage(pu, deg, V)
printBusData(system, analysis)
```

Next, users can easily customize the print results for specific buses, for example:
```julia
printBusData(system, analysis; label = "Bus 1", header = true)
printBusData(system, analysis; label = "Bus 2")
printBusData(system, analysis; label = "Bus 3", footer = true)
```

Users can also redirect print output to a file. For example, data can be saved in a text file as follows:
```julia
open("bus_data.txt", "w") do file
printBusData(system, analysis, file)
end
```

---

## [Power System Update](@id ACPowerSystemAlterationManual)
After establishing the `PowerSystem` type using the [`powerSystem`](@ref powerSystem) function and configuring the AC model with [`acModel!`](@ref acModel!), users gain the capability to incorporate new branches and generators. Furthermore, they can adjust buses, branches, and generators.

Expand Down Expand Up @@ -558,10 +558,13 @@ print(system.bus.label, analysis.power.injection.active)
print(system.branch.label, analysis.current.to.angle)
```

!!! note "Info"
To better understand the powers and currents associated with buses, branches, and generators that are obtained by the [`power!`](@ref power!(::PowerSystem, ::ACPowerFlow)) and [`current!`](@ref current!(::PowerSystem, ::AC)) functions, we suggest referring to the tutorials on [AC Power Flow Analysis](@ref ACPowerFlowTutorials).

---

##### Print Results
Users can utilize any of the print functions mentioned in the [Print API Section](@ref setupPrintAPI) to print results. For example, to create a bus summary with the desired units, users can use the following function:
Users can utilize any of the print functions outlined in the [Print Power System Data](@ref PrintPowerSystemDataAPI) or [Print Power System Summary](@ref PrintPowerSystemSummaryAPI). For example, to create a bus summary with the desired units, users can use the following function:
```@example ComputationPowersCurrentsLosses
@voltage(pu, deg, V)
@power(MW, MVAr, pu)
Expand All @@ -571,13 +574,6 @@ printBusSummary(system, analysis)

---

!!! note "Info"
To better understand the powers and currents associated with buses, branches, and generators that are obtained by the [`power!`](@ref power!(::PowerSystem, ::ACPowerFlow)) and [`current!`](@ref current!(::PowerSystem, ::AC)) functions, we suggest referring to the tutorials on [AC Power Flow Analysis](@ref ACPowerFlowTutorials).

To compute specific quantities for particular components, rather than calculating powers or currents for all components, users can utilize one of the functions provided below.

---

##### Active and Reactive Power Injection
To calculate the active and reactive power injection associated with a specific bus, the function can be used:
```@repl ComputationPowersCurrentsLosses
Expand Down
36 changes: 28 additions & 8 deletions docs/src/manual/dcPowerFlow.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,29 @@ nothing # hide

---

##### Print Results
Users have the option to print the results in the REPL using any units that have been configured, such as:
```@example DCPowerFlowSolution
@voltage(pu, deg, V)
printBusData(system, analysis)
```

Next, users can easily customize the print results for specific buses, for example:
```julia
printBusData(system, analysis; label = "Bus 1", header = true)
printBusData(system, analysis; label = "Bus 2")
printBusData(system, analysis; label = "Bus 3", footer = true)
```

Users can also redirect print output to a file. For example, data can be saved in a text file as follows:
```julia
open("bus_data.txt", "w") do file
printBusData(system, analysis, file)
end
```

---

## [Power System Update](@id DCPowerSystemAlterationManual)
After establishing the `PowerSystem` type using the [`powerSystem`](@ref powerSystem) function and configuring the DC model with [`dcModel!`](@ref dcModel!), users gain the capability to incorporate new branches and generators. Furthermore, they can adjust buses, branches, and generators.

Expand Down Expand Up @@ -282,14 +305,18 @@ print(system.bus.label, system.base.power.value * analysis.power.injection.activ
print(system.branch.label, system.base.power.value * analysis.power.from.active)
```

!!! note "Info"
To better understand the powers associated with buses, branches, and generators that are calculated by the [`power!`](@ref power!(::PowerSystem, ::DCPowerFlow)) function, we suggest referring to the tutorials on [DC Power Flow Analysis](@ref DCPowerAnalysisTutorials).

---

##### Print Results
Users can utilize any of the print functions mentioned in the [Print API Section](@ref setupPrintAPI) to print results. For example, users have the option to print the results in the REPL using any units that have been configured, such as:
Users can utilize any of the print functions outlined in the [Print Power System Data](@ref PrintPowerSystemDataAPI) or [Print Power System Summary](@ref PrintPowerSystemSummaryAPI). For example, users have the option to print the results in the REPL using any units that have been configured, such as:
```@example ComputationPowersCurrentsLosses
@voltage(pu, deg, V)
@power(MW, pu, pu)
printBusData(system, analysis)
@default(unit) # hide
```

Next, users can easily customize the print results for specific buses, for example:
Expand All @@ -308,13 +335,6 @@ end

---

!!! note "Info"
To better understand the powers associated with buses, branches, and generators that are calculated by the [`power!`](@ref power!(::PowerSystem, ::DCPowerFlow)) function, we suggest referring to the tutorials on [DC Power Flow Analysis](@ref DCPowerAnalysisTutorials).

To compute specific quantities for particular components, rather than calculating powers or currents for all components, users can utilize one of the provided functions below.

---

##### Active Power Injection
To calculate active power injection associated with a specific bus, the function can be used:
```@repl ComputationPowersCurrentsLosses
Expand Down
101 changes: 90 additions & 11 deletions src/print/measurement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
label, header, footer, width)
The function prints data related to voltmeters. Optionally, an `IO` may be passed as the
last argument to redirect the output.
last argument to redirect the output. Users can also omit the `Analysis` type to print
only data related to the `Measurement` type.
# Keywords
The following keywords control the printed data:
Expand Down Expand Up @@ -39,12 +40,26 @@ printVoltmeterData(system, device, analysis; label = 6, width)
printVoltmeterData(system, device, analysis; label = 8, width, footer = true)
```
"""
function printVoltmeterData(system::PowerSystem, device::Measurement, io::IO = stdout;
label::L = missing, header::B = missing, footer::Bool = false,
width::Dict{String, Int64} = Dict{String, Int64}())

voltage = Polar(Float64[], Float64[])

_printVoltmeterData(system, device, voltage, io, label, header, footer, width)
end

function printVoltmeterData(system::PowerSystem, device::Measurement, analysis::AC, io::IO = stdout;
label::L = missing, header::B = missing, footer::Bool = false,
width::Dict{String, Int64} = Dict{String, Int64}())

_printVoltmeterData(system, device, analysis.voltage, io, label, header, footer, width)
end

function _printVoltmeterData(system::PowerSystem, device::Measurement, voltage::Polar, io::IO,
label::L, header::B, footer::Bool, width::Dict{String, Int64})

voltmeter = device.voltmeter
voltage = analysis.voltage

format = formatVoltmeterData(system, voltmeter, voltage, label, width)
labels, header = toggleLabelHeader(label, voltmeter, voltmeter.label, header, "voltmeter")
Expand Down Expand Up @@ -98,7 +113,8 @@ end
label, header, footer, width)
The function prints data related to ammeters. Optionally, an `IO` may be passed as the
last argument to redirect the output.
last argument to redirect the output. Users can also omit the `Analysis` type to print
only data related to the `Measurement` type.
# Keywords
The following keywords control the printed data:
Expand Down Expand Up @@ -134,12 +150,26 @@ printAmmeterData(system, device, analysis; label = "From 4", width)
printAmmeterData(system, device, analysis; label = "From 6", width, footer = true)
```
"""
function printAmmeterData(system::PowerSystem, device::Measurement, io::IO = stdout;
label::L = missing, header::B = missing, footer::Bool = false,
width::Dict{String, Int64} = Dict{String, Int64}())

current = ACCurrent(Polar(Float64[], Float64[]), Polar(Float64[], Float64[]), Polar(Float64[], Float64[]), Polar(Float64[], Float64[]))

_printAmmeterData(system, device, current, io, label, header, footer, width)
end

function printAmmeterData(system::PowerSystem, device::Measurement, analysis::AC, io::IO = stdout;
label::L = missing, header::B = missing, footer::Bool = false,
width::Dict{String, Int64} = Dict{String, Int64}())

_printAmmeterData(system, device, analysis.current, io, label, header, footer, width)
end

function _printAmmeterData(system::PowerSystem, device::Measurement, current::ACCurrent, io::IO,
label::L, header::B, footer::Bool, width::Dict{String, Int64})

ammeter = device.ammeter
current = analysis.current

format = formatAmmeterData(system, ammeter, current, label, width)
labels, header = toggleLabelHeader(label, ammeter, ammeter.label, header, "ammeter")
Expand Down Expand Up @@ -205,7 +235,8 @@ end
label, header, footer, width)
The function prints data related to wattmeters. Optionally, an `IO` may be passed as the
last argument to redirect the output.
last argument to redirect the output. Users can also omit the `Analysis` type to print
only data related to the `Measurement` type.
# Keywords
The following keywords control the printed data:
Expand Down Expand Up @@ -241,12 +272,28 @@ printWattmeterData(system, device, analysis; label = 5, width)
printWattmeterData(system, device, analysis; label = 9, width, footer = true)
```
"""
function printWattmeterData(system::PowerSystem, device::Measurement, io::IO = stdout;
label::L = missing, header::B = missing, footer::Bool = false,
width::Dict{String, Int64} = Dict{String, Int64}())

power = ACPower(Cartesian(Float64[], Float64[]), Cartesian(Float64[], Float64[]), Cartesian(Float64[], Float64[]),
Cartesian(Float64[], Float64[]), Cartesian(Float64[], Float64[]), Cartesian(Float64[], Float64[]),
Cartesian(Float64[], Float64[]), nothing)

_printWattmeterData(system, device, power, io, label, header, footer, width)
end

function printWattmeterData(system::PowerSystem, device::Measurement, analysis::AC, io::IO = stdout;
label::L = missing, header::B = missing, footer::Bool = false,
width::Dict{String, Int64} = Dict{String, Int64}())

_printWattmeterData(system, device, analysis.power, io, label, header, footer, width)
end

function _printWattmeterData(system::PowerSystem, device::Measurement, power::ACPower, io::IO,
label::L, header::B, footer::Bool, width::Dict{String, Int64})

wattmeter = device.wattmeter
power = analysis.power

scale = printScale(system, prefix)
format = formatWattmeterData(system, wattmeter, power, scale, label, width)
Expand Down Expand Up @@ -289,7 +336,8 @@ end
label, header, footer, width)
The function prints data related to varmeters. Optionally, an `IO` may be passed as the
last argument to redirect the output.
last argument to redirect the output. Users can also omit the `Analysis` type to print
only data related to the `Measurement` type.
# Keywords
The following keywords control the printed data:
Expand Down Expand Up @@ -325,12 +373,28 @@ printVarmeterData(system, device, analysis; label = 5, width)
printVarmeterData(system, device, analysis; label = 9, width, footer = true)
```
"""
function printVarmeterData(system::PowerSystem, device::Measurement, io::IO = stdout;
label::L = missing, header::B = missing, footer::Bool = false,
width::Dict{String, Int64} = Dict{String, Int64}())

power = ACPower(Cartesian(Float64[], Float64[]), Cartesian(Float64[], Float64[]), Cartesian(Float64[], Float64[]),
Cartesian(Float64[], Float64[]), Cartesian(Float64[], Float64[]), Cartesian(Float64[], Float64[]),
Cartesian(Float64[], Float64[]), nothing)

_printVarmeterData(system, device, power, io, label, header, footer, width)
end

function printVarmeterData(system::PowerSystem, device::Measurement, analysis::AC, io::IO = stdout;
label::L = missing, header::B = missing, footer::Bool = false,
width::Dict{String, Int64} = Dict{String, Int64}())

_printVarmeterData(system, device, analysis.power, io, label, header, footer, width)
end

function _printVarmeterData(system::PowerSystem, device::Measurement, power::ACPower, io::IO,
label::L, header::B, footer::Bool, width::Dict{String, Int64})

varmeter = device.varmeter
power = analysis.power

scale = printScale(system, prefix)
format = formatVarmeterData(system, varmeter, power, scale, label, width)
Expand Down Expand Up @@ -374,7 +438,8 @@ end
label, header, footer, width)
The function prints data related to PMUs. Optionally, an `IO` may be passed as the last
argument to redirect the output.
argument to redirect the output. Users can also omit the `Analysis` type to print
only data related to the `Measurement` type.
# Keywords
The following keywords control the printed data:
Expand Down Expand Up @@ -410,13 +475,27 @@ printPmuData(system, device, analysis; label = "From 4", width)
printPmuData(system, device, analysis; label = "From 6", width, footer = true)
```
"""
function printPmuData(system::PowerSystem, device::Measurement, io::IO = stdout;
label::L = missing, header::B = missing, footer::Bool = false,
width::Dict{String, Int64} = Dict{String, Int64}())

voltage = Polar(Float64[], Float64[])
current = ACCurrent(Polar(Float64[], Float64[]), Polar(Float64[], Float64[]), Polar(Float64[], Float64[]), Polar(Float64[], Float64[]))

_printPmuData(system, device, voltage, current, io, label, header, footer, width)
end

function printPmuData(system::PowerSystem, device::Measurement, analysis::AC, io::IO = stdout;
label::L = missing, header::B = missing, footer::Bool = false,
width::Dict{String, Int64} = Dict{String, Int64}())

_printPmuData(system, device, analysis.voltage, analysis.current, io, label, header, footer, width)
end

function _printPmuData(system::PowerSystem, device::Measurement, voltage::Polar, current::ACCurrent, io::IO,
label, header, footer, width::Dict{String, Int64})

pmu = device.pmu
voltage = analysis.voltage
current = analysis.current

scale = printScale(system, prefix)
formatV, formatθ, formatI, formatψ = formatPmuData(system, pmu, voltage, current, scale, label, width)
Expand Down

0 comments on commit c1adbb0

Please sign in to comment.