Skip to content

Commit

Permalink
polishing syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mcosovic committed Aug 27, 2024
1 parent e1b153d commit e05398b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 38 deletions.
21 changes: 10 additions & 11 deletions src/print/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ function printBranchConstraint(system::PowerSystem, analysis::ACOptimalPowerFlow
end

if haskey(constraint.flow.from, i) && is_valid(analysis.method.jump, constraint.flow.from[i])
if !((system.branch.flow.type[i] == 1 || system.branch.flow.type[i] == 3) && system.branch.flow.minFromBus[i] < 0)
printf(io, pfmt, _show, _width, system.branch.flow.minFromBus, i, scaleFlowFrom, "From-Bus $flow Minimum")
else
if system.branch.flow.minFromBus[i] < 0 && system.branch.flow.type[i] != 2
printf(io, pfmt, _show, _width, 0.0, "From-Bus $flow Minimum")
else
printf(io, pfmt, _show, _width, system.branch.flow.minFromBus, i, scaleFlowFrom, "From-Bus $flow Minimum")
end
printf(io, pfmt, _show, _width, constraint.flow.from, i, scaleFlowFrom, "From-Bus $flow Solution")
printf(io, pfmt, _show, _width, system.branch.flow.maxFromBus, i, scaleFlowFrom, "From-Bus $flow Maximum")
Expand All @@ -495,12 +495,11 @@ function printBranchConstraint(system::PowerSystem, analysis::ACOptimalPowerFlow
end

if haskey(constraint.flow.to, i) && is_valid(analysis.method.jump, constraint.flow.to[i])
if !((system.branch.flow.type[i] == 1 || system.branch.flow.type[i] == 3) && system.branch.flow.minToBus[i] < 0)
printf(io, pfmt, _show, _width, system.branch.flow.minToBus, i, scaleFlowTo, "To-Bus $flow Minimum")
else
if system.branch.flow.minToBus[i] < 0 && system.branch.flow.type[i] != 2
printf(io, pfmt, _show, _width, 0.0, "To-Bus $flow Minimum")
else
printf(io, pfmt, _show, _width, system.branch.flow.minToBus, i, scaleFlowTo, "To-Bus $flow Minimum")
end

printf(io, pfmt, _show, _width, constraint.flow.to, i, scaleFlowTo, "To-Bus $flow Solution")
printf(io, pfmt, _show, _width, system.branch.flow.maxToBus, i, scaleFlowTo, "To-Bus $flow Maximum")
printf(io, pfmt, _show, _width, dual.flow.to, i, scaleFlowTo, "To-Bus $flow Dual")
Expand Down Expand Up @@ -640,7 +639,7 @@ function formatBranchConstraint(system::PowerSystem, analysis::ACOptimalPowerFlo
end

if haskey(constraint.flow.from, i) && is_valid(analysis.method.jump, constraint.flow.from[i])
if !((system.branch.flow.type[i] == 1 || system.branch.flow.type[i] == 3) && system.branch.flow.minFromBus[i] < 0)
if !(system.branch.flow.minFromBus[i] < 0 && system.branch.flow.type[i] != 2)
fmax(fmt, width, show, system.branch.flow.minFromBus, i, scaleFlowFrom, "From-Bus $flow Minimum")
end
fmax(fmt, width, show, value(constraint.flow.from[i]) * scaleFlowFrom, "From-Bus $flow Solution")
Expand All @@ -651,7 +650,7 @@ function formatBranchConstraint(system::PowerSystem, analysis::ACOptimalPowerFlo
end

if haskey(constraint.flow.to, i) && is_valid(analysis.method.jump, constraint.flow.to[i])
if !((system.branch.flow.type[i] == 1 || system.branch.flow.type[i] == 3) && system.branch.flow.minToBus[i] < 0)
if !(system.branch.flow.minToBus[i] < 0 && system.branch.flow.type[i] != 2)
fmax(fmt, width, show, system.branch.flow.minToBus, i, scaleFlowTo, "To-Bus $flow Minimum")
end
fmax(fmt, width, show, value(constraint.flow.to[i]) * scaleFlowTo, "To-Bus $flow Solution")
Expand Down Expand Up @@ -695,7 +694,7 @@ function formatBranchConstraint(system::PowerSystem, analysis::ACOptimalPowerFlo
end

if haskey(constraint.flow.from, i) && is_valid(analysis.method.jump, constraint.flow.from[i])
if !((system.branch.flow.type[i] == 1 || system.branch.flow.type[i] == 3) && system.branch.flow.minFromBus[i] < 0)
if !(system.branch.flow.minFromBus[i] < 0 && system.branch.flow.type[i] != 2)
minmaxValue(show, system.branch.flow.minFromBus, i, scaleFlowFrom, Fmin, "From-Bus $flow Minimum")
end
minmaxPrimal(show, constraint.flow.from[i], scaleFlowFrom, Fopt, "From-Bus $flow Solution")
Expand All @@ -704,7 +703,7 @@ function formatBranchConstraint(system::PowerSystem, analysis::ACOptimalPowerFlo
end

if haskey(constraint.flow.to, i) && is_valid(analysis.method.jump, constraint.flow.to[i])
if !((system.branch.flow.type[i] == 1 || system.branch.flow.type[i] == 3) && system.branch.flow.minFromBus[i] < 0)
if !(system.branch.flow.minToBus[i] < 0 && system.branch.flow.type[i] != 2)
minmaxValue(show, system.branch.flow.minToBus, i, scaleFlowTo, Tmin, "To-Bus $flow Minimum")
end
minmaxPrimal(show, constraint.flow.to[i], scaleFlowTo, Topt, "To-Bus $flow Solution")
Expand Down
30 changes: 4 additions & 26 deletions src/print/measurement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,12 @@ function _printVoltmeterData(system::PowerSystem, device::Measurement, voltage::

printTitle(io, maxLine, delimiter, title, header, style, "Voltmeter Data")

scale = 1.0
@inbounds for (label, i) in labels
printing = printHeader(io, hfmt, width, show, heading, subheading, unit, delimiter, header, style, repeat, printing, maxLine, i)

indexBus = voltmeter.layout.index[i]
if prefix.voltageMagnitude != 0.0
scale = scaleVoltage(system.base.voltage, prefix, indexBus)
end

printf(io, pfmt, show, width, label, "Label")
printDevice(io, pfmt, hfmt, width, show, voltmeter.magnitude, voltage.magnitude, scale, i, indexBus, type)
printDevice(io, pfmt, hfmt, width, show, voltmeter.magnitude, voltage.magnitude, scaleVoltage(prefix, system.base.voltage, indexBus), i, indexBus, type)

@printf io "\n"
end
Expand All @@ -109,15 +104,9 @@ function formatVoltmeterData(system::PowerSystem, voltmeter::Voltmeter, voltage:
labels = toggleLabel(label, voltmeter, voltmeter.label, "voltmeter")

if style
scale = 1.0
@inbounds for (label, i) in labels
indexBus = voltmeter.layout.index[i]

if prefix.voltageMagnitude != 0.0
scale = scaleVoltage(system.base.voltage, prefix, indexBus)
end

formatDevice(fmt, width, show, minval, maxval, label, voltmeter.magnitude, voltage.magnitude, scale, i, indexBus, type)
formatDevice(fmt, width, show, minval, maxval, label, voltmeter.magnitude, voltage.magnitude, scaleVoltage(prefix, system.base.voltage, indexBus), i, indexBus, type)
end
formatDevice(fmt, width, show, minval, maxval)
end
Expand Down Expand Up @@ -248,7 +237,6 @@ function formatAmmeterData(system::PowerSystem, ammeter::Ammeter, current::ACCur
scale = 1.0
@inbounds for (label, i) in labels
indexBranch = ammeter.layout.index[i]

if prefix.currentMagnitude != 0.0
if ammeter.layout.from[i]
scale = scaleCurrent(system, prefix, system.branch.layout.from[indexBranch])
Expand Down Expand Up @@ -606,20 +594,15 @@ function _printPmuData(system::PowerSystem, device::Measurement, voltage::Polar,

printTitle(io, maxLine, delimiter, title, header, style, "PMU Data")

scaleV = 1.0
cnt = 1
@inbounds for (label, i) in labels
if pmu.layout.bus[i]
printingV = printHeader(io, hfmt, widthV, showV, headingV, subheadingV, unitV, delimiter, header, style, repeat, printingV, maxLine, cnt)

indexBus = pmu.layout.index[i]
if prefix.voltageMagnitude != 0.0
scaleV = scaleVoltage(system.base.voltage, prefix, indexBus)
end

printf(io, pfmt, showV, widthV, label, "Label")

printDevice(io, pfmt, hfmt, widthV, showV, pmu.magnitude, voltage.magnitude, scaleV, i, indexBus, "Voltage Magnitude")
printDevice(io, pfmt, hfmt, widthV, showV, pmu.magnitude, voltage.magnitude, scaleVoltage(prefix, system.base.voltage, indexBus), i, indexBus, "Voltage Magnitude")
printDevice(io, pfmt, hfmt, widthV, showV, pmu.angle, voltage.angle, scale["θ"], i, indexBus, "Voltage Angle")

@printf io "\n"
Expand Down Expand Up @@ -688,17 +671,12 @@ function formatPmuData(system::PowerSystem, pmu::PMU, voltage::Polar, current::A
labels = toggleLabel(label, pmu, pmu.label, "pmu")

if style
scaleV = 1.0
scaleI = 1.0
@inbounds for (label, i) in labels
indexBusBranch = pmu.layout.index[i]

if pmu.layout.bus[i]
if prefix.voltageMagnitude != 0.0
scaleV = scaleVoltage(system.base.voltage, prefix, indexBusBranch)
end

formatDevice(fmtV, widthV, showV, minV, maxV, label, pmu.magnitude, voltage.magnitude, scaleV, i, indexBusBranch, "Voltage Magnitude")
formatDevice(fmtV, widthV, showV, minV, maxV, label, pmu.magnitude, voltage.magnitude, scaleVoltage(prefix, system.base.voltage, indexBusBranch), i, indexBusBranch, "Voltage Magnitude")
formatDevice(fmtV, widthV, showV, minθ, maxθ, label, pmu.angle, voltage.angle, scale["θ"], i, indexBusBranch, "Voltage Angle")
else
if prefix.currentMagnitude != 0.0
Expand Down
1 change: 0 additions & 1 deletion src/print/powerSystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ function formatBusData(system::PowerSystem, analysis::AC, label::L, scale::Dict{
end
fminmax(fmt, width, show, voltage.angle, scale["θ"], "Voltage Angle")


if prefix.currentMagnitude == 0.0
fmax(fmt, width, show, current.injection.magnitude, 1.0, "Current Injection Magnitude")
else
Expand Down

0 comments on commit e05398b

Please sign in to comment.